shithub: hell

Download patch

ref: 5b1c32f9feba920e2d0a568de897bcbd0d64f4b9
parent: 416169ab2ea220f6396a557bc3dad0f1566552cf
author: penny <penny@limitedideas.org>
date: Fri Oct 3 20:57:54 EDT 2025

add a /detatch command and document it

--- 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", "attach"}
+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", "detach"}
 
 func processInput(input string) (command string, arguments string, found bool) {
 
--- a/config.go
+++ b/config.go
@@ -65,7 +65,7 @@
 		prefs.MediaImport = defaultprefs.MediaImport
 		fixed = true
 	}
-	
+
 	if prefs.FilePicker == "" {
 		prefs.FilePicker = defaultprefs.FilePicker
 		fixed = true
--- a/dispatch.go
+++ b/dispatch.go
@@ -131,14 +131,9 @@
 
 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.consumeAttachments() {
+		status.MediaIDs = append(status.MediaIDs, item.ID)
 	}
-	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
 }
--- a/filehandler.go
+++ b/filehandler.go
@@ -187,6 +187,15 @@
 	return nil
 }
 
+func (sam *StatusAttachmentHolder) clearAttachments() {
+	sam.attachments = nil
+}
+
+func (sam *StatusAttachmentHolder) consumeAttachments() []*mastodon.Attachment {
+	defer sam.clearAttachments()
+	return sam.attachments
+}
+
 func (sam *StatusAttachmentHolder) enqueuedAttachments() int {
 	return len(sam.attachments)
 }
--- a/help.go
+++ b/help.go
@@ -21,10 +21,13 @@
   /attach [file path]          Loads file for attaching to status.
                                Opens the configured graphical file picker if no path is given.
                                
+  /detach                      Clears loaded but unposted attachments.
   /dm <content>                Create a status with direct visibility (e.g. a dm).
   /rt <index>                  Boost a status by index.
   /parent <index>              View parent of status by index.
-  /rm [index]                  Delete status by index, deletes most recent post without an argument.
+  /rm [index]                  Delete status by index
+                               Deletes most recent post without an argument.
+                               
   /mark <index>                Bookmark status by index.
   /unmark <index>              Unbookmark status.
   /account [index] [account]   View account details and status, either by index or name.
--- a/main.go
+++ b/main.go
@@ -98,6 +98,10 @@
 
 			//Contextual commands that need to handle their own requirements
 			switch command {
+			case "detach":
+				hc.attacher.clearAttachments()
+				hc.prompt.UpdatePrompt()
+				return
 			case "attach":
 				if arguments == "" {
 					arguments, err = pickFilename(hc.preferences.FilePicker)
--