shithub: hell

Download patch

ref: 764442ad56237aeacbf324adb574ce1ee3344283
parent: b343e7124f74b60d9ca6595dad1678177a95308d
author: penny <penny@limitedideas.org>
date: Fri Oct 3 16:32:29 EDT 2025

Attachment support + fix pau fix prompt for pause

--- a/commands.go
+++ b/commands.go
@@ -4,7 +4,7 @@
 	"strings"
 )
 
-var commands = []string{"examine", "reply", "like", "thread", "open", "prev", "download", "dm", "rt", "parent", "children", "rm", "mark", "unmark", "account", "import", "pause", "resume", "url", "fpost", "ufpost", "edit", "notice", "stats", "next", "view", "bookmarks", "follow", "unfollow", "likes", "help", "reload"}
+var commands = []string{"examine", "reply", "like", "thread", "open", "prev", "download", "dm", "rt", "parent", "children", "rm", "mark", "unmark", "account", "import", "pause", "resume", "url", "fpost", "ufpost", "edit", "notice", "stats", "next", "view", "bookmarks", "follow", "unfollow", "likes", "help", "reload", "attach"}
 
 func processInput(input string) (command string, arguments string, found bool) {
 
--- a/dispatch.go
+++ b/dispatch.go
@@ -129,8 +129,18 @@
 	}
 }
 
-func (hc *Hellclient) dispatchStatus(status string, visibility string) {
-	hc.dispatch <- postStatus(status, visibility)
+func (hc *Hellclient) dispatchStatus(poststring string, visibility string) {
+	status := postStatus(poststring, visibility)
+	if hc.attacher.enqueuedAttachments() == 0 {
+		hc.dispatch <- status
+		return
+	}
+	for item := range hc.attacher.attachments {
+		status.MediaIDs = append(status.MediaIDs, hc.attacher.attachments[item].ID)
+	}
+	hc.attacher.attachments = nil
+	hc.prompt.UpdatePrompt()
+	hc.dispatch <- status
 }
 
 func (hc *Hellclient) dispatchReply(posttext string, replyto mastodon.ID, postItem *mastodon.Status) {
--- a/filehandler.go
+++ b/filehandler.go
@@ -9,15 +9,13 @@
 	"os/exec"
 	"path"
 	"path/filepath"
+	"context"
 
 	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 	"github.com/google/shlex"
 )
 
-func loadAttachment(path string) {
-	path = expandDir(path)
-	fmt.Println(path)
-}
+
 func openItemInOS(command string, url string) {
 	cmdstring := fmt.Sprintf(command, url)
 	cmdargv, err := shlex.Split(cmdstring)
@@ -140,4 +138,35 @@
 	}
 
 	return file, nil
+}
+
+type StatusAttachmentHolder struct {
+	*Hellclient
+	attachments []*mastodon.Attachment
+}
+
+// Return a byte array and error given a filepath
+// Expands ~ and environmental variables
+func loadFile(path string) (*[]byte, error) {
+	path = expandDir(path)
+	data, err := os.ReadFile(path)
+	if err != nil {
+		return nil, fmt.Errorf("read error: %s: %s", path, err)
+	}
+	return &data, nil
+}
+
+// Upload media by path to the mastodon server
+func (sam *StatusAttachmentHolder) uploadAttachment(path string) error {
+	file, err := loadFile(path)
+	if err != nil {
+		return err
+	}
+	attachment, err := sam.client.UploadMediaFromBytes(context.Background(), *file)
+	sam.attachments = append(sam.attachments, attachment)
+	return err
+}
+
+func (sam *StatusAttachmentHolder) enqueuedAttachments() int {
+	return len(sam.attachments)
 }
--- a/hellclient.go
+++ b/hellclient.go
@@ -27,6 +27,7 @@
 	isPaused      bool
 	rl            *readline.Instance
 	prompt        *PromptBar
+	attacher      *StatusAttachmentHolder
 	client        *mastodon.Client
 	currentuser   *mastodon.Account
 	dispatch      chan *mastodon.Toot
@@ -167,10 +168,14 @@
 	}
 
 	prompt := &PromptBar{prompt: "Hell> ", rl: rl}
+	
+	attacher := &StatusAttachmentHolder{Hellclient: &hc}
 
 	prompt.items = []PromptItem{
 		&NotificationCounter{Hellclient: &hc},
 		&MultiLineIndicator{Hellclient: &hc},
+		&PauseIndicator{Hellclient: &hc},
+		attacher,
 	}
 
 	debugMap := make(map[string]any)
@@ -191,6 +196,7 @@
 		preferences: prefs,
 		stats:       &Stats{},
 		configPath:  configpath,
+		attacher:    attacher,
 	}
 	return &hc, nil
 }
--- a/main.go
+++ b/main.go
@@ -98,6 +98,13 @@
 
 			//Contextual commands that need to handle their own requirements
 			switch command {
+			case "attach":
+				err := hc.attacher.uploadAttachment(arguments)
+				if err != nil {
+					fmt.Printf("Upload error: %s\n", err)
+				}
+				hc.prompt.UpdatePrompt()
+				return
 			case "help":
 				fmt.Println(hyphenate(helpString(hc.configPath)))
 				return
--- a/prompt.go
+++ b/prompt.go
@@ -64,3 +64,30 @@
 	}
 	return "", false, nil
 }
+
+type PauseIndicator struct {
+	*Hellclient
+}
+
+func (pi *PauseIndicator) Update() (string, bool, error) {
+	if pi.isPaused {
+		return "STREAM PAUSED", true, nil
+	}
+	return "", false, nil
+}
+
+// Display when you have attachments ready to post
+func (sam *StatusAttachmentHolder) Update() (string, bool, error) {
+	if len(sam.attachments) < 1 {
+		return "", false, nil
+	}
+	var sb strings.Builder
+	
+	sb.WriteString("ATTACHED:[")
+	for item := range sam.attachments {
+		sb.WriteString(sam.attachments[item].Type)
+		sb.WriteString(" ")
+	}
+	sb.WriteString("]")
+	return sb.String(), true, nil
+}
--