shithub: hell

Download patch

ref: 864489632f86f20b956dd148ab7f4aeac2bb0e3a
parent: d8cc2a99ea090771b634a825858d204092aa3672
author: penny <penny@limitedideas.org>
date: Fri Oct 3 13:56:42 EDT 2025

Create status bar rendering system

--- a/edit.go
+++ b/edit.go
@@ -1,9 +1,9 @@
 package main
 
 import (
+	"bytes"
 	"errors"
 	"strings"
-	"bytes"
 
 	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"golang.org/x/net/html"
@@ -35,7 +35,7 @@
 			}
 		}
 	}
-	
+
 	//Rip off the HTML body the parser made for us
 	for node := range doc.Descendants() {
 		if node.Data == "body" {
--- a/hellclient.go
+++ b/hellclient.go
@@ -2,10 +2,8 @@
 
 import (
 	"context"
-	"fmt"
 	"io"
 	"os"
-	"strings"
 	"sync"
 	"time"
 
@@ -28,6 +26,7 @@
 	//if you're gonna touch or read anything here lock the mutex with hc.lock()
 	isPaused      bool
 	rl            *readline.Instance
+	prompt        *PromptBar
 	client        *mastodon.Client
 	currentuser   *mastodon.Account
 	dispatch      chan *mastodon.Toot
@@ -77,7 +76,7 @@
 		FuncFilterInputRune: func(r rune) (rune, bool) {
 			if r == readline.CharCtrlJ {
 				hc.multiLineMode = !hc.multiLineMode
-				hc.updatePrompt()
+				hc.prompt.UpdatePrompt()
 				return r, false
 			}
 			if r == readline.CharInterrupt {
@@ -127,7 +126,7 @@
 
 	defer func() {
 		//Got some stuff to do when we're done
-		hc.updatePrompt()
+		hc.prompt.UpdatePrompt()
 		//start up post dispatcher
 		go hc.clientDispatch()
 
@@ -166,7 +165,14 @@
 		ref:     "a",
 		postmap: homeMap,
 	}
+	
+	prompt := &PromptBar{prompt: "Hell> ", rl: rl}
 
+	prompt.items = []PromptItem{
+		&NotificationCounter{Hellclient: &hc},
+		&MultiLineIndicator{Hellclient: &hc},
+	}
+
 	debugMap := make(map[string]any)
 	urlMap := make(map[string][]string)
 	prefs := &account.Preferences
@@ -174,6 +180,7 @@
 		homeMap:     homeMap,
 		ctxref:      ctxref,
 		homeref:     homeref,
+		prompt:      prompt,
 		debugMap:    debugMap,
 		isPaused:    false,
 		urlMap:      urlMap,
@@ -188,33 +195,16 @@
 	return &hc, nil
 }
 
-func (hc *Hellclient) updatePrompt() {
-	var sb strings.Builder
 
-	unread, err := hc.client.GetUnreadNotifications(context.Background(), nil, nil, 0)
-	if err == nil {
-		sb.WriteString(fmt.Sprintf("ur:%v ", unread.Count))
-	}
-	if hc.multiLineMode {
-		sb.WriteString("MULTI-LINE ")
-	}
-	if hc.isPaused {
-		sb.WriteString("STREAMING PAUSED ")
-	}
-
-	sb.WriteString("Hell> ")
-	hc.rl.SetPrompt(sb.String())
-}
-
 func (hc *Hellclient) pause(on bool) {
 	hc.isPaused = on
-	hc.updatePrompt()
+	hc.prompt.UpdatePrompt()
 	hc.printPauseBuffer()
 }
 
 func (hc *Hellclient) togglepause() {
 	hc.isPaused = !hc.isPaused
-	hc.updatePrompt()
+	hc.prompt.UpdatePrompt()
 	hc.printPauseBuffer()
 }
 
--- a/main.go
+++ b/main.go
@@ -151,7 +151,7 @@
 				fmt.Print(hc.page.String())
 				return
 			case "notice":
-				defer hc.updatePrompt()
+				defer hc.prompt.UpdatePrompt()
 				defer hc.pause(true)
 				notifications, err := hc.GetUnreadNotifications()
 				if len(notifications) > 0 {
--- a/mastodon.go
+++ b/mastodon.go
@@ -427,7 +427,7 @@
 				return
 
 			case *mastodon.NotificationEvent:
-				hc.updatePrompt()
+				hc.prompt.UpdatePrompt()
 				if post.Notification.Status == nil {
 					if hc.isPaused {
 						hc.actionBuffer = append(hc.actionBuffer, func() {
--- a/pages.go
+++ b/pages.go
@@ -37,6 +37,7 @@
 	client *mastodon.Client
 	loaded bool
 }
+
 // Thread status getter
 // The API doesn't take a limit for this so we ignore the limit
 func (getter *ThreadStatusGetter) Get(limit int) ([]*mastodon.Status, error) {
--