shithub: hell

Download patch

ref: 416dfe4f871a317f87a9e266604d3cad729f9b9b
parent: 35959699c979b584314702e7d6f27c6cebf25c69
author: penny <penny@limitedideas.org>
date: Sun Aug 10 14:33:37 EDT 2025

Add a pause buffer to hellclient object and output messages there

--- a/hellclient.go
+++ b/hellclient.go
@@ -4,6 +4,7 @@
 	"io"
 	"strings"
 	"sync"
+	"fmt"
 
 	"github.com/chzyer/readline"
 	"github.com/mattn/go-mastodon"
@@ -15,13 +16,14 @@
 )
 
 type Hellclient struct {
+	//if you're gonna touch or read anything here lock the mutex with hc.lock()
 	isPaused bool
 	rl       *readline.Instance
 	block    sync.Mutex
 
-	//Only use these in one routine at a time unless you add a mutex
-	homeMap  map[string]*mastodon.Status
-	debugMap map[string]interface{}
+	homeMap      map[string]*mastodon.Status
+	debugMap     map[string]interface{}
+	actionBuffer []func()
 }
 
 func NewHellclient() (*Hellclient, error) {
@@ -46,11 +48,23 @@
 func (hc *Hellclient) pause(on bool) {
 	hc.isPaused = on
 	hc.updatePrompt()
+	hc.printPauseBuffer()
 }
 
 func (hc *Hellclient) togglepause() {
 	hc.isPaused = !hc.isPaused
 	hc.updatePrompt()
+	hc.printPauseBuffer()
+}
+
+func (hc *Hellclient) printPauseBuffer() {
+	if(!hc.isPaused) {
+		fmt.Println("Output resumed")
+		for _, action := range hc.actionBuffer {
+			action()
+		}
+		hc.actionBuffer = nil
+	}
 }
 
 func (hc *Hellclient) lock() {
--- a/main.go
+++ b/main.go
@@ -71,7 +71,7 @@
 				}
 				return
 			}
-			
+
 			hc.lock()
 			defer hc.unlock()
 
@@ -254,6 +254,6 @@
 			default:
 				fmt.Printf("Unimplemented command \"%v\"?\"\n", command)
 			}
-		} ()
+		}()
 	}
 }
--- a/mastodon.go
+++ b/mastodon.go
@@ -243,9 +243,7 @@
 	postref := "a"
 	plaintext := ""
 	idmap := make(map[mastodon.ID]*mastodon.Status)
-	isPaused := false
-	var actionBuffer []func()
-
+	
 	// Enter a loop to continuously listen for events from the event channel.
 	for {
 		select {
@@ -257,31 +255,14 @@
 				return // Exit the function
 			}
 			func() {
-				func() {
-					hc.lock()
-					defer hc.unlock()
-					newPauseState := hc.isPaused
-					if newPauseState == isPaused {
-						return
-					}
-					isPaused = newPauseState
-
-					if !isPaused {
-						fmt.Println("Output resumed")
-						for _, action := range actionBuffer {
-							action()
-						}
-						actionBuffer = nil
-					}
-				}()
 				hc.lock()
 				defer hc.unlock()
 				switch post := event.(type) {
 				case *mastodon.UpdateEvent:
-					if isPaused {
+					if hc.isPaused {
 						currentPostRef := postref
-						capturedPost := *post
-						actionBuffer = append(actionBuffer, func() {
+						capturedPost := post
+						hc.actionBuffer = append(hc.actionBuffer, func() {
 							capturedPost.Status = printPost(currentPostRef, capturedPost.Status)
 						})
 					} else {
@@ -292,10 +273,10 @@
 					postref = IncrementString(postref)
 
 				case *mastodon.UpdateEditEvent:
-					if isPaused {
+					if hc.isPaused {
 						currentPostRef := postref
 						capturedPost := post
-						actionBuffer = append(actionBuffer, func() {
+						hc.actionBuffer = append(hc.actionBuffer, func() {
 							fmt.Println(formatEdit(capturedPost.Status, currentPostRef))
 						})
 					} else {
@@ -310,8 +291,8 @@
 					//didn't have this in the cache
 					if !ok {
 						capturedID := post.ID
-						if isPaused {
-							actionBuffer = append(actionBuffer, func() {
+						if hc.isPaused {
+							hc.actionBuffer = append(hc.actionBuffer, func() {
 								fmt.Printf("Deleted: ID %v\n", capturedID)
 							})
 						} else {
@@ -319,8 +300,8 @@
 						}
 						return
 					}
-					if isPaused {
-						actionBuffer = append(actionBuffer, func() {
+					if hc.isPaused {
+						hc.actionBuffer = append(hc.actionBuffer, func() {
 							printPostDetailed("", deleted, "Deleted:")
 						})
 					} else {
@@ -331,8 +312,8 @@
 				case *mastodon.NotificationEvent:
 					if post.Notification.Status == nil {
 						notification := fmt.Sprintf("Notification [%v] from <%v>\n", post.Notification.Type, post.Notification.Account.Acct)
-						if isPaused {
-							actionBuffer = append(actionBuffer, func() {
+						if hc.isPaused {
+							hc.actionBuffer = append(hc.actionBuffer, func() {
 								fmt.Printf(hyphenate(notification))
 							})
 						} else {
@@ -342,8 +323,8 @@
 					}
 					_, plaintext = RenderPostPlaintext(post.Notification.Status, postref, "")
 					notification := fmt.Sprintf("Notification [%v] from <%v>: %v\n", post.Notification.Type, post.Notification.Account.Acct, plaintext)
-					if isPaused {
-						actionBuffer = append(actionBuffer, func() {
+					if hc.isPaused {
+						hc.actionBuffer = append(hc.actionBuffer, func() {
 							fmt.Printf(hyphenate(notification))
 						})
 					} else {
@@ -354,8 +335,8 @@
 				default:
 					// Catch any other unexpected event types.
 					unhandledEvent := event
-					if isPaused {
-						actionBuffer = append(actionBuffer, func() {
+					if hc.isPaused {
+						hc.actionBuffer = append(hc.actionBuffer, func() {
 							fmt.Printf("Unhandled event: %T\n", unhandledEvent)
 						})
 					} else {
--