ref: a6a992e09b31f9ef1b9b2e9bf21b23ac007621c9
parent: 0337b9f6b26328acb220bba9f9e68a1c8f19d5f8
author: penny <penny@limitedideas.org>
date: Sun Oct 5 15:28:02 EDT 2025
convert stream to new render method
--- a/mastodon.go
+++ b/mastodon.go
@@ -227,34 +227,15 @@
fmt.Printf("\r%v\n", err)}
-func (hc *Hellclient) printPostS(ref postref, post *mastodon.Status) *mastodon.Status {- return hc.printPostDetailed(ref.prefix+ref.ref, post, "")
-}
-
-func (hc *Hellclient) printPost(postref string, post *mastodon.Status) *mastodon.Status {- return hc.printPostDetailed(postref, post, "")
-}
-
-func (hc *Hellclient) printPostDetailed(postref string, post *mastodon.Status, prefix string) *mastodon.Status {- post, plaintext := hc.RenderPostPlaintext(post, postref, prefix)
- fmt.Println(hyphenate(plaintext))
- return post
-}
-
-func (hc *Hellclient) renderPostS(ref postref, post *mastodon.Status) string {- _, plaintext := hc.RenderPostPlaintext(post, ref.prefix+ref.ref, "")
- return hyphenate(plaintext)
-}
-
-func (hc *Hellclient) RenderPostPlaintext(post *mastodon.Status, ref postref, prefix string) (selectedPost *mastodon.Status, plaintext string) {+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) } else {selectedPost = post
- plaintext = fmt.Sprintf("%s> $user $content $media_descriptions", ref.ref)+ plaintext = fmt.Sprintf("%s> $username $content $media_descriptions", ref.ref)}
- formatter := &StatusFormatter{hc: hc, status: post,}+ formatter := &StatusFormatter{hc: hc, status: post, postContext: &ref}templater := newStatusTemplateRenderer(formatter)
plaintext, _ = templater.render(plaintext)
return selectedPost, plaintext
@@ -289,10 +270,11 @@
//Tell the timeline marker updater the most recent post
readchan <- &post.Status.ID
if hc.isPaused {- currentPostRef := hc.homeref.ref
+ currentPostRef := *hc.homeref
capturedPost := post
hc.actionBuffer = append(hc.actionBuffer, func() {- capturedPost.Status = hc.printPost(currentPostRef, capturedPost.Status)
+ _, plaintext := hc.RenderPostPlaintext(capturedPost.Status, currentPostRef)
+ fmt.Print(plaintext)
})
justIncrementPostref(hc.homeref, post.Status)
idmap[post.Status.ID] = post.Status
@@ -322,7 +304,7 @@
return
case *mastodon.DeleteEvent:
- deleted, ok := idmap[post.ID]
+ _, ok := idmap[post.ID]
//didn't have this in the cache
if !ok {capturedID := post.ID
@@ -337,10 +319,10 @@
}
if hc.isPaused { hc.actionBuffer = append(hc.actionBuffer, func() {- hc.printPostDetailed("", deleted, "Deleted:")+ //hc.printPostDetailed("", deleted, "Deleted:")})
} else {- hc.printPostDetailed("", deleted, "Deleted:")+ //hc.printPostDetailed("", deleted, "Deleted:")}
return
--- a/notifications.go
+++ b/notifications.go
@@ -103,7 +103,7 @@
continue
}
- _, plaintext := hc.RenderPostPlaintext(Notification.Status, hc.ctxref.ref, "")
+ _, plaintext := hc.RenderPostPlaintext(Notification.Status, *hc.ctxref)
printstatus(Notification, plaintext)
saveRef(hc.ctxref.postmap, Notification.Status, hc.ctxref.ref)
--- a/references.go
+++ b/references.go
@@ -32,7 +32,8 @@
// print and increment a status given a postref struct
func (hc *Hellclient) printAndIncrement(ref *postref, post *mastodon.Status) (returnPost *mastodon.Status) {- returnPost = hc.printPostS(*ref, post)
+ returnPost, plaintext := hc.RenderPostPlaintext(post, *ref)
+ fmt.Print(plaintext)
IncrementRef(ref, post)
ref.ref = IncrementString(ref.ref)
return
@@ -39,7 +40,8 @@
}
func (hc *Hellclient) renderAndIncrement(ref *postref, post *mastodon.Status) string {- plaintext := hc.renderPostS(*ref, post)
+ post, plaintext := hc.RenderPostPlaintext(post, *ref)
+ fmt.Print(plaintext)
IncrementRef(ref, post)
ref.ref = IncrementString(ref.ref)
return plaintext
--- a/renderer.go
+++ b/renderer.go
@@ -27,7 +27,7 @@
// Returns the rendered content of a status
func (st *StatusFormatter) statusContent() string {- renderedPost, plaintexts := st.hc.renderStatus(st.status.Content, "")
+ renderedPost, plaintexts := st.hc.renderStatus(st.status.Content, st.postContext.ref)
for key, plaintext := range plaintexts {renderedPost = strings.Replace(renderedPost, key, plaintext, 1)
}
@@ -47,6 +47,9 @@
continue
}
sb.WriteString("🖼️")+ }
+ if len(status.MediaAttachments) > 0 {+ sb.WriteString("\n")}
return sb.String()
}
--- a/templater.go
+++ b/templater.go
@@ -36,7 +36,7 @@
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
--
⑨