shithub: hell

Download patch

ref: 918985cbc5ff46956d83d761abd4df67be67cf68
parent: 3e8f569b8cd631f999757ce37e8d72076f64860c
parent: bc47f7bf1176b75ddd044c3ca296ee024b87d631
author: penny64 <penny64@noreply.codeberg.org>
date: Mon Oct 6 02:12:01 EDT 2025

Merge pull request 'more rendering normalization' (#7) from convert_to_templates into main

Reviewed-on: https://codeberg.org/penny64/hellclient/pulls/7

--- a/format.go
+++ b/format.go
@@ -6,27 +6,25 @@
 	"golang.org/x/term"
 )
 
-func hyphenate(input string) string {
+func hyphenate(input string) (string, bool) {
 	width, _, _ := term.GetSize(int(0))
 	return hyphenateWithWidth(input, width)
 }
 
-func hyphenateWithWidth(input string, width int) string {
+func hyphenateWithWidth(input string, width int) (string, bool) {
 	var remainder = []rune(input)
 	var result []rune
 
 	if width < 2 {
-		return input
+		return input, false
 	}
 
 	longline := false
-	if len(remainder) > width {
-		longline = true
-	}
 
 	for len(remainder) > width {
 		if strings.HasPrefix(string(remainder), "\n") {
 			result = append(result, '\n')
+			longline = true
 			remainder = remainder[1:]
 			continue
 		}
@@ -50,6 +48,7 @@
 		if breakPos > 0 {
 			result = append(result, remainder[:breakPos]...)
 			result = append(result, '\n')
+			longline = true
 			remainder = remainder[breakPos+1:]
 			continue
 		}
@@ -57,10 +56,12 @@
 		if remainder[width-1] == ' ' {
 			result = append(result, remainder[:width-1]...)
 			result = append(result, '\n')
+			longline = true
 			remainder = remainder[width:] // Consume the space
 		} else if remainder[width-1] == '-' {
 			result = append(result, remainder[:width]...)
 			result = append(result, '\n')
+			longline = true
 			remainder = remainder[width:] // Consume the hyphen
 		} else if remainder[width-1] != ' ' {
 			result = append(result, remainder[:width-1]...)
@@ -78,11 +79,8 @@
 	if strings.HasSuffix(string(result), "\n") {
 		result = result[:len(result)-1]
 	}
-	//Put a newline at the end if status takes multiple lines
-	if longline {
-		result = append(result, '\n')
-	}
-	return string(result)
+	//Put an extra newline at the end if status takes multiple lines
+	return string(result), longline
 }
 
 func countEmoji(runes []rune) int {
--- a/mastodon.go
+++ b/mastodon.go
@@ -175,33 +175,33 @@
 			sb.WriteString("Follow request pending\n")
 		}
 	}
-
-	return hyphenate(sb.String())
+	accountstring, _ := hyphenate(sb.String())
+	return accountstring
 }
 
 // Spaces before prefixes (no space if you're not passing a prefix)
 func (hc *Hellclient) formatReblog(post *mastodon.Status, index string) string {
 	reblogString := fmt.Sprintf(" <%s> Reblogged", post.Account.Username)
-	return hyphenate(hc.formatStatusDetailed(post.Reblog, index, reblogString))
+	return hc.formatStatusDetailed(post.Reblog, index, reblogString)
 }
 
 func (hc *Hellclient) formatWithPrefix(post *mastodon.Status, index string, prefix string) string {
 	postString := fmt.Sprintf("%s %s>", prefix, index)
-	return hyphenate(hc.formatStatusDetailed(post, "", postString))
+	return hc.formatStatusDetailed(post, "", postString)
 }
 func (hc *Hellclient) formatFavorite(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Favorited: %s", index)
-	return hyphenate(hc.formatStatusDetailed(post, "", favString))
+	return hc.formatStatusDetailed(post, "", favString)
 }
 
 func (hc *Hellclient) formatBookmark(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Bookmarked: %s", index)
-	return hyphenate(hc.formatStatusDetailed(post, "", favString))
+	return hc.formatStatusDetailed(post, "", favString)
 }
 
 func (hc *Hellclient) formatUnbookmark(post *mastodon.Status, index string) string {
 	favString := fmt.Sprintf("Unbookmarked: %s", index)
-	return hyphenate(hc.formatStatusDetailed(post, "", favString))
+	return hc.formatStatusDetailed(post, "", favString)
 }
 
 func (hc *Hellclient) formatStatus(post *mastodon.Status, index string) string {
@@ -220,7 +220,7 @@
 
 func (hc *Hellclient) formatEdit(post *mastodon.Status, index string) string {
 	editString := fmt.Sprintf(" <%s> EDITED:", post.Account.Username)
-	return hyphenate(hc.formatStatusDetailed(post, index, editString))
+	return hc.formatStatusDetailed(post, index, editString)
 }
 
 func printMastodonErr(err error) {
@@ -230,10 +230,10 @@
 func (hc *Hellclient) RenderPostPlaintext(post *mastodon.Status, ref postref) (selectedPost *mastodon.Status, plaintext string) {
 	if post.Reblog != nil {
 		selectedPost = post.Reblog
-		plaintext = fmt.Sprintf("$username Reblogged %s> $boostuser $boostcontent $boosted_media_descriptions", ref.ref)
+		plaintext = fmt.Sprintf("$username Reblogged %s> $boostuser $boostcontent $boosted_media_descriptions", ref.prefix + ref.ref)
 	} else {
 		selectedPost = post
-		plaintext = fmt.Sprintf("%s> $username $content $media_descriptions", ref.ref)
+		plaintext = fmt.Sprintf("%s> $username $content $media_descriptions", ref.prefix + ref.ref)
 	}
 	formatter := &StatusFormatter{hc: hc, status: post, postContext: &ref}
 	templater := newStatusTemplateRenderer(formatter)
--- a/notifications.go
+++ b/notifications.go
@@ -71,13 +71,16 @@
 func (hc *Hellclient) RenderNotificationsArray(notifications []*mastodon.Notification) []string {
 	var noticeTexts []string
 	status := func(Notification *mastodon.Notification, plaintext string) {
-		notification := fmt.Sprintf("[%s] from <%s>: %s\n", Notification.Type, Notification.Account.Acct, plaintext)
-		noticeTexts = append(noticeTexts, hyphenate(notification))
+		notification := fmt.Sprintf("[%s] from <%s>: %s", Notification.Type, Notification.Account.Acct, plaintext)
+		notification, _ = hyphenate(notification)
+		
+		noticeTexts = append(noticeTexts, notification)
 	}
 
 	other := func(Notification *mastodon.Notification) {
-		notification := fmt.Sprintf("[%s] from <%s>\n", Notification.Type, Notification.Account.Acct)
-		noticeTexts = append(noticeTexts, hyphenate(notification))
+		notification := fmt.Sprintf("[%s] from <%s>", Notification.Type, Notification.Account.Acct)
+		notification, _ = hyphenate(notification)
+		noticeTexts = append(noticeTexts, notification)
 	}
 
 	hc.PrintNotificationsCustom(notifications, status, other)
--- a/pages.go
+++ b/pages.go
@@ -157,7 +157,7 @@
 		fmt.Printf("Couldn't load status page: %s\n", err)
 	}
 	for i := range statuses {
-		item := makePageItem(statusData.hc.renderAndIncrement(statusData.hc.ctxref, statuses[i]))
+		item := makePageItem(statusData.hc.renderAndIncrement(statusData.hc.ctxref, statuses[i]) + "\n")
 		itemArray = append(itemArray, item)
 	}
 	return &itemArray
@@ -188,7 +188,7 @@
 	noticeArray := noticeData.hc.RenderNotificationsArray(notices)
 	var itemArray []PageItem
 	for i := range noticeArray {
-		item := makePageItem(noticeArray[i] + "\n")
+		item := makePageItem(noticeArray[i])
 		itemArray = append(itemArray, item)
 	}
 	noticeData.page.MinID = ""
--- a/references.go
+++ b/references.go
@@ -43,7 +43,8 @@
 	post, plaintext := hc.RenderPostPlaintext(post, *ref)
 	IncrementRef(ref, post)
 	ref.ref = IncrementString(ref.ref)
-	return hyphenate(plaintext)
+	plaintext, _ = hyphenate(plaintext)
+	return plaintext
 }
 
 func printAndIncrementDetailed(ref *postref, post *mastodon.Status, format func(*mastodon.Status, string) string) {
--- a/renderer.go
+++ b/renderer.go
@@ -43,13 +43,10 @@
 	}
 	for _, item := range status.MediaAttachments {
 		if item.Description != "" {
-			sb.WriteString(fmt.Sprintf("\n🖼️[%s]", item.Description))
+			sb.WriteString(fmt.Sprintf("\n🖼️ [%s]", item.Description))
 			continue
 		}
 		sb.WriteString("🖼️")
-	}
-	if len(status.MediaAttachments) > 0 {
-		sb.WriteString("\n")
 	}
 	return sb.String()
 }
--- a/templater.go
+++ b/templater.go
@@ -36,8 +36,11 @@
 				return tr.tempdefs[item].stringer.String()
 			}
 		}
-		return fmt.Sprintf("%%KEY_NOT_FOUND:%s", key)
+		return fmt.Sprintf("[%%KEY_NOT_FOUND:%s]", key)
 	}
-
-	return hyphenate(os.Expand(template, expandMap)), nil
+	template, long := hyphenate(os.Expand(template, expandMap))
+	if long {
+		return template + "\n\n", nil
+	}
+	return template + "\n", nil
 }
--