shithub: hell

Download patch

ref: ab45dd40f8e15d02e8746dade0103951d8e35a6f
parent: 70df97139bfcc188fea0840653f114454b02e55e
parent: 3d5b43335f4e5caaf825f646b94db99ef3caf8f7
author: penny64 <penny64@noreply.codeberg.org>
date: Thu Oct 9 16:20:48 EDT 2025

Merge pull request 'remove_hc_in_statusrender' (#9) from remove_hc_in_statusrender into main

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

--- a/hellclient.go
+++ b/hellclient.go
@@ -20,6 +20,7 @@
 	prefix  string
 	ref     string
 	postmap map[string]*mastodon.Status
+	urlmap  map[string][]string
 }
 
 type Hellclient struct {
@@ -44,7 +45,6 @@
 	homeref *postref
 	//Contextual indexes for commands
 	ctxref       *postref
-	urlMap       map[string][]string
 	debugMap     map[string]any
 	actionBuffer []func()
 
@@ -155,16 +155,20 @@
 	}()
 
 	homeMap := make(map[string]*mastodon.Status)
+	urlMap := make(map[string][]string)
 
 	ctxref := &postref{
 		prefix:  "?",
 		ref:     "a",
 		postmap: homeMap,
+		urlmap:  urlMap,
+		
 	}
 
 	homeref := &postref{
 		ref:     "a",
 		postmap: homeMap,
+		urlmap:  urlMap,
 	}
 
 	prompt := &PromptBar{prompt: "Hell> ", rl: rl}
@@ -179,7 +183,6 @@
 	}
 
 	debugMap := make(map[string]any)
-	urlMap := make(map[string][]string)
 	prefs := &account.Preferences
 	hc = Hellclient{rl: rl,
 		homeMap:     homeMap,
@@ -188,7 +191,6 @@
 		prompt:      prompt,
 		debugMap:    debugMap,
 		isPaused:    false,
-		urlMap:      urlMap,
 		client:      client,
 		currentuser: currentuser,
 		dispatch:    dispatch,
--- a/main.go
+++ b/main.go
@@ -245,7 +245,7 @@
 				hc.PrintObjectProperties(debugItem)
 				return
 			}
-			formatter := &StatusFormatter{hc: hc, status: postItem, postContext: hc.ctxref, localindex: index}
+			formatter := &StatusFormatter{prefs: hc.preferences, status: postItem, postContext: hc.ctxref, localindex: index}
 			templater := newStatusTemplateRenderer(formatter)
 
 			//Commands require status indexes
@@ -303,11 +303,11 @@
 				if err != nil {
 					urlindex = 1
 				}
-				if urlindex > len(hc.urlMap[index]) {
+				if urlindex > len(hc.homeref.urlmap[index]) {
 					fmt.Printf("Bad url index\n")
 					return
 				}
-				openItemInOS(hc.preferences.Browser, hc.urlMap[index][urlindex-1])
+				openItemInOS(hc.preferences.Browser, hc.homeref.urlmap[index][urlindex-1])
 				return
 			case "view":
 				err := hc.previewPostImages(postItem, hc.preferences.ImageViewer)
--- a/mastodon.go
+++ b/mastodon.go
@@ -191,7 +191,7 @@
 		selectedPost = post
 		plaintext = fmt.Sprintf("$standard_status")
 	}
-	formatter := &StatusFormatter{hc: hc, status: post, postContext: &ref}
+	formatter := &StatusFormatter{prefs: hc.preferences, status: post, postContext: &ref}
 	templater := newStatusTemplateRenderer(formatter)
 	plaintext, _ = templater.render(plaintext)
 	return selectedPost, plaintext
@@ -245,7 +245,7 @@
 				hc.stats.slock.Lock()
 				hc.stats.IncomingStatuses++
 				hc.stats.slock.Unlock()
-				formatter := &StatusFormatter{hc: hc, status: post.Status, postContext: hc.homeref}
+				formatter := &StatusFormatter{prefs: hc.preferences, status: post.Status, postContext: hc.homeref}
 				templater := newStatusTemplateRenderer(formatter)
 				if hc.isPaused {
 					hc.actionBuffer = append(hc.actionBuffer, func() {
@@ -276,7 +276,7 @@
 					}
 					return
 				}
-				formatter := &StatusFormatter{hc: hc, status: deleted, postContext: hc.homeref}
+				formatter := &StatusFormatter{prefs: hc.preferences, status: deleted, postContext: hc.homeref}
 				templater := newStatusTemplateRenderer(formatter)
 				if hc.isPaused {
 					hc.actionBuffer = append(hc.actionBuffer, func() {
--- a/notifications.go
+++ b/notifications.go
@@ -58,7 +58,7 @@
 
 func (hc *Hellclient) RenderNotificationsArray(notifications []*mastodon.Notification) []string {
 	var noticeTexts []string
-	formatter := &StatusFormatter{hc: hc, postContext: hc.ctxref}
+	formatter := &StatusFormatter{prefs: hc.preferences, postContext: hc.ctxref}
 	templater := newStatusTemplateRenderer(formatter)
 	for item := range notifications {
 		formatter.notif = notifications[item]
--- a/pages.go
+++ b/pages.go
@@ -156,7 +156,7 @@
 	if err != nil {
 		fmt.Printf("Couldn't load status page: %s\n", err)
 	}
-	formatter := &StatusFormatter{hc: statusData.hc, postContext: statusData.hc.ctxref}
+	formatter := &StatusFormatter{prefs: statusData.hc.preferences, postContext: statusData.hc.ctxref}
 	templater := newStatusTemplateRenderer(formatter)
 	for i := range statuses {
 		formatter.status = statuses[i]
--- a/renderer.go
+++ b/renderer.go
@@ -12,10 +12,10 @@
 )
 
 type StatusFormatter struct {
-	hc          *Hellclient
 	status      *mastodon.Status
 	postContext *postref
 	notif       *mastodon.Notification
+	prefs       *Hellprefs
 	// Index for posts that aren't using the ref in postref
 	localindex string
 }
@@ -29,7 +29,7 @@
 
 // Returns the rendered content of a status
 func (st *StatusFormatter) statusContent(status *mastodon.Status) string {
-	renderedPost, plaintexts := st.hc.renderStatus(status.Content, st.postContext.ref)
+	renderedPost, plaintexts := st.postContext.renderStatus(status.Content, st.postContext.ref)
 	for key, plaintext := range plaintexts {
 		renderedPost = strings.Replace(renderedPost, key, plaintext, 1)
 	}
@@ -40,7 +40,7 @@
 func (st *StatusFormatter) mediaDescriptions(reblog bool) string {
 	var sb strings.Builder
 	status := st.status
-	mediaTag := st.hc.preferences.MediaTag
+	mediaTag := st.prefs.MediaTag
 	if reblog {
 		status = status.Reblog
 	}
@@ -181,7 +181,7 @@
 	return usr.username()
 }
 
-func (hc *Hellclient) renderStatus(content string, index string) (string, map[string]string) {
+func (pr *postref) renderStatus(content string, index string) (string, map[string]string) {
 	doc, err := html.Parse(strings.NewReader(content))
 	if err != nil {
 		fmt.Printf("Failed to parse status\n")
@@ -189,13 +189,13 @@
 	}
 
 	//clear out the url map
-	hc.urlMap[index] = []string{}
+	pr.urlmap[index] = []string{}
 	preformats := make(map[string]string)
 
 	for node := range doc.Descendants() {
 		if (node.Data == "pre" || node.Data == "") && node.FirstChild != nil {
-			preformats[fmt.Sprintf("%p%p", hc, node.FirstChild)] = node.FirstChild.Data
-			node.FirstChild.Data = fmt.Sprintf("%p%p", hc, node.FirstChild)
+			preformats[fmt.Sprintf("%p%p", pr, node.FirstChild)] = node.FirstChild.Data
+			node.FirstChild.Data = fmt.Sprintf("%p%p", pr, node.FirstChild)
 		}
 		if node.Data == "a" && node.Type == html.ElementNode {
 			ismention := false
@@ -218,10 +218,10 @@
 				}
 			}
 			if !ismention {
-				hc.urlMap[index] = append(hc.urlMap[index], href)
+				pr.urlmap[index] = append(pr.urlmap[index], href)
 				refnode := &html.Node{
 					Type: html.TextNode,
-					Data: fmt.Sprintf(" [%v]", len(hc.urlMap[index]))}
+					Data: fmt.Sprintf(" [%v]", len(pr.urlmap[index]))}
 				if node.Parent != nil {
 					node.Parent.InsertBefore(refnode, node.NextSibling)
 				}
--- a/renderer_test.go
+++ b/renderer_test.go
@@ -37,13 +37,10 @@
 	}
 	for _, param := range parameters {
 		sf := &StatusFormatter{
-			hc: &Hellclient{
-				urlMap: make(map[string][]string), // Initialize urlMap to avoid nil map assignment
-			},
 			status: &mastodon.Status{
 				Content: param.post,
 			},
-			postContext: &postref{ref: "1"},
+			postContext: &postref{ref: "1", urlmap: make(map[string][]string)},
 		}
 		rendered := sf.statusContent(sf.status)
 		if rendered != param.expected {
--