shithub: hell

Download patch

ref: 1823d7ad99fdd2decf2c264b62b3e2e18e4e5dc7
parent: cb5d7368b2b14d55607819d8899401e0944bdfae
author: penny <penny@limitedideas.org>
date: Tue Oct 7 15:20:26 EDT 2025

templater renders indexes

--- a/main.go
+++ b/main.go
@@ -245,7 +245,7 @@
 				hc.PrintObjectProperties(debugItem)
 				return
 			}
-			formatter := &StatusFormatter{hc: hc, status: postItem, postContext: hc.ctxref}
+			formatter := &StatusFormatter{hc: hc, status: postItem, postContext: hc.ctxref, localindex: index}
 			templater := newStatusTemplateRenderer(formatter)
 
 			//Commands require status indexes
@@ -258,7 +258,7 @@
 				if index == "" {
 					index = lastindex
 				}
-				line, _ := templater.render(fmt.Sprintf("%s> $standard_status\n$detail_line", index))
+				line, _ := templater.render("$standard_status\n$detail_line")
 				fmt.Print(line)
 				return
 			case "like":
@@ -266,7 +266,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					line, _ := templater.render(fmt.Sprintf("Favourited: %s> $standard_status", index))
+					line, _ := templater.render("Favourited: $standard_status")
 					fmt.Print(line)
 				}
 				return
@@ -275,7 +275,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					line, _ := templater.render(fmt.Sprintf("Bookmarked: %s> $username $content $media_descriptions\n", index))
+					line, _ := templater.render("Bookmarked: $index $username $content $media_descriptions\n")
 					fmt.Print(line)
 				}
 				return
@@ -289,7 +289,7 @@
 				if err != nil {
 					printMastodonErr(err)
 				} else {
-					line, _ := templater.render(fmt.Sprintf("Unbookmarked: %s> $username $content $media_descriptions\n", index))
+					line, _ := templater.render("Unbookmarked: $index $username $content $media_descriptions\n")
 					fmt.Print(line)
 				}
 				return
@@ -496,7 +496,7 @@
 					fmt.Printf("Error unfiltering post: %v\n", err)
 					return
 				}
-				line, _ := templater.render(fmt.Sprintf("Unfiltered: %s> $username $content $media_descriptions\n", index))
+				line, _ := templater.render("Unfiltered: %s> $username $content $media_descriptions\n")
 				fmt.Print(line)
 
 				return
--- a/mastodon.go
+++ b/mastodon.go
@@ -186,10 +186,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.prefix + ref.ref)
+		plaintext = fmt.Sprintf("$username Reblogged $index $boostuser $boostcontent $boosted_media_descriptions")
 	} else {
 		selectedPost = post
-		plaintext = fmt.Sprintf("%s> $standard_status", ref.prefix + ref.ref)
+		plaintext = fmt.Sprintf("$standard_status")
 	}
 	formatter := &StatusFormatter{hc: hc, status: post, postContext: &ref}
 	templater := newStatusTemplateRenderer(formatter)
@@ -249,7 +249,7 @@
 				templater := newStatusTemplateRenderer(formatter)
 				if hc.isPaused {
 					hc.actionBuffer = append(hc.actionBuffer, func() {
-						line, _ := templater.render(fmt.Sprintf("$username EDITED: %s> $content $media_descriptions\n", hc.homeref.ref + hc.homeref.prefix))
+						line, _ := templater.render(fmt.Sprintf("$username EDITED: $index $content $media_descriptions\n"))
 						fmt.Print(line)
 					})
 					justIncrementPostref(hc.homeref, post.Status)
@@ -256,7 +256,7 @@
 					idmap[post.Status.ID] = post.Status
 					return
 				}
-				line, _ := templater.render(fmt.Sprintf("$username EDITED: %s> $content $media_descriptions\n", hc.homeref.ref + hc.homeref.prefix))
+				line, _ := templater.render(fmt.Sprintf("$username EDITED: $index $content $media_descriptions\n"))
 				fmt.Print(line)
 				justIncrementPostref(hc.homeref, post.Status)
 				idmap[post.Status.ID] = post.Status
--- a/renderer.go
+++ b/renderer.go
@@ -15,6 +15,9 @@
 	hc          *Hellclient
 	status      *mastodon.Status
 	postContext *postref
+	notif       *mastodon.Notification
+	// Index for posts that aren't using the ref in postref
+	localindex  string
 }
 
 // Returns the rendered content of a status's rt
@@ -21,13 +24,12 @@
 func (st *StatusFormatter) reblogContent() string {
 	currentpost := st.status
 	defer func(){st.status = currentpost}()
-	st.status = st.status.Reblog
-	return st.statusContent()
+	return st.statusContent(st.status.Reblog)
 }
 
 // Returns the rendered content of a status
-func (st *StatusFormatter) statusContent() string {
-	renderedPost, plaintexts := st.hc.renderStatus(st.status.Content, st.postContext.ref)
+func (st *StatusFormatter) statusContent(status *mastodon.Status) string {
+	renderedPost, plaintexts := st.hc.renderStatus(status.Content, st.postContext.ref)
 	for key, plaintext := range plaintexts {
 		renderedPost = strings.Replace(renderedPost, key, plaintext, 1)
 	}
@@ -80,7 +82,36 @@
 	}
 	return sb.String()
 }
+// Stringer for current index
+type indexString struct {
+	*StatusFormatter
+}
 
+func (is *indexString) String() string {
+	if is.localindex != "" {
+		return fmt.Sprintf("%s>", is.localindex)
+	}
+	return fmt.Sprintf("%s%s>", is.postContext.prefix, is.postContext.ref)
+}
+
+// Stringer for user who caused a notification
+type notificationUser struct {
+	*StatusFormatter
+}
+
+func (nu *notificationUser) String() string {
+	return fmt.Sprintf("[%s]", nu.notif.Account.Acct)
+}
+
+// Stringer for type of notification
+type notificationType struct {
+	*StatusFormatter
+}
+
+func (nt *notificationType) String() string {
+	return fmt.Sprintf("[%s]", nt.notif.Type)
+}
+
 // Status content stringer
 type statusContent struct {
 	*StatusFormatter
@@ -87,7 +118,7 @@
 }
 
 func (cf *statusContent) String() string {
-	return cf.statusContent()
+	return cf.statusContent(cf.status)
 }
 
 // Status boost content stringer
--- a/templater.go
+++ b/templater.go
@@ -27,6 +27,9 @@
 			{key: "boostuser", stringer: &boostedusername{sf}},
 			{key: "boostcontent", stringer: &boostContent{sf}},
 			{key: "boosted_media_descriptions", stringer: &boostMediaDescriptions{sf}},
+			{key: "notif_user", stringer: &notificationUser{sf}},
+			{key: "notif_type", stringer: &notificationType{sf}},
+			{key: "index", stringer: &indexString{sf}},
 		},
 	}
 	// macro templates
@@ -65,6 +68,16 @@
 }
 
 func (ss *standardStatus) String() string {
-	line, _ := ss.renderRaw("$username $content $media_descriptions")
+	line, _ := ss.renderRaw("$index $username $content $media_descriptions")
+	return line
+}
+
+// Renders a standard notification line
+type standardNotification struct {
+	*templateRenderer
+}
+
+func (sn *standardNotification) String() string {
+	line, _ := sn.renderRaw("$notif_user $notif_type $standard_status")
 	return line
 }
--