shithub: hell

Download patch

ref: 4a4ffec0868b56ce4dcea82999d7ba6fd9f01e91
parent: f1cb9ed4a5302ab898dddcf9f87cf9664fc948a6
author: penny <penny@limitedideas.org>
date: Sat Nov 1 15:13:59 EDT 2025

port bookmarks, /read, /notice

--- a/commands.go
+++ b/commands.go
@@ -2,9 +2,9 @@
 
 import (
 	"fmt"
+	"runtime/debug"
 	"strings"
 	"time"
-	"runtime/debug"
 
 	mastodon "codeberg.org/penny64/hellclient-go-mastodon"
 )
@@ -109,9 +109,8 @@
 	hc          *Hellclient
 	lastindex   string
 	lastaccount *mastodon.Account
-	commands []string
-	cmdmap map[string]cmder
-	
+	commands    []string
+	cmdmap      map[string]cmder
 }
 
 func (loader *cmdloader) init(cmds []cmder) {
@@ -128,11 +127,11 @@
 // Return loaded account if index was empty
 // Load lastaccount if it exists or try to look one up, return account or nil
 func (data *cmddata) lookupAccount(loader *cmdloader) *mastodon.Account {
-	
+
 	if data.found_index {
 		return data.account
 	}
-	if data.index == ""  && data.account != nil {
+	if data.index == "" && data.account != nil {
 		return data.account
 	}
 
@@ -143,7 +142,7 @@
 			return nil
 		}
 	}
-	
+
 	loader.lastaccount = account
 	loader.lastindex = ""
 	return account
@@ -196,10 +195,10 @@
 		command:      command,
 		content:      content,
 		raw_argument: arguments,
-		dot_index: dot_index,
-		found_index: foundindex,
-		index: index,
-		cmd_found: found,
+		dot_index:    dot_index,
+		found_index:  foundindex,
+		index:        index,
+		cmd_found:    found,
 	}
 	if loader.lastaccount != nil {
 		cmdctx.account = loader.lastaccount
@@ -223,7 +222,7 @@
 	cmd_found    bool
 	content      string
 	found_index  bool
-	dot_index bool
+	dot_index    bool
 	index        string
 }
 
@@ -245,7 +244,7 @@
 
 // return an error message if cmddata matches cmders flags
 func (cmd *cmd) checkReqs() (err error) {
-	if(cmd.cmder.flags()&free !=0) {
+	if cmd.cmder.flags()&free != 0 {
 		return nil
 	}
 	if (cmd.cmder.flags()&status != 0) && (cmd.cmder.flags()&account != 0) {
@@ -312,7 +311,7 @@
 	account := data.lookupAccount(cmd.cmdloader)
 	if account == nil {
 		return fmt.Sprintf("Account lookup failed.\n")
-		}
+	}
 	return fmt.Sprint(hc.formatAccount(account))
 }
 
@@ -431,10 +430,10 @@
 }
 
 type basiccmd struct {
-	hc *Hellclient
-	bname string
+	hc     *Hellclient
+	bname  string
 	bflags cmdflag
-	doer func(*cmddata) string
+	doer   func(*cmddata) string
 }
 
 func (cmd *basiccmd) flags() cmdflag {
@@ -486,7 +485,7 @@
 	cmd.doer = func(data *cmddata) string {
 		if hc.page != nil {
 			hc.page.Next()
-			return fmt.Sprint(hc.page.String())
+			return hc.page.String()
 		}
 		return fmt.Sprintf("No page loaded")
 	}
@@ -500,7 +499,7 @@
 	cmd.bflags = free
 	cmd.doer = func(data *cmddata) string {
 		if hc.page != nil {
-			return fmt.Sprint(hc.page.String())
+			return hc.page.String()
 		}
 		return fmt.Sprintf("No page loaded")
 	}
@@ -507,7 +506,68 @@
 	return cmd
 }
 
-func (hc *Hellclient) newCmdArray() ([]cmder) {
+func (hc *Hellclient) bookmarkscmd() cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = "bookmarks"
+	cmd.bflags = free
+	cmd.doer = func(data *cmddata) string {
+		hc.pause(true)
+		hc.page = &Page{}
+		getter := &BasicStatusGetter{getter: hc.client.GetBookmarks}
+		hc.page.loader = &StatusPages{hc: hc, getter: getter}
+		return hc.page.String()
+	}
+	return cmd
+}
+
+func (hc *Hellclient) readcmd() cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = "read"
+	cmd.bflags = free
+	cmd.doer = func(data *cmddata) string {
+		defer hc.prompt.UpdatePrompt()
+		notifications, err := hc.GetUnreadNotifications()
+		if err != nil {
+			return fmt.Sprintf("%s\n", err)
+		}
+		if len(notifications) > 0 {
+			err = hc.SetNotificationsRead(notifications[len(notifications)-1].ID)
+			if err != nil {
+				return fmt.Sprintf("%s\n", err)
+			}
+		}
+		return ""
+	}
+	return cmd
+}
+
+func (hc *Hellclient) noticecmd() cmder {
+	cmd := &basiccmd{}
+	cmd.hc = hc
+	cmd.bname = "notice"
+	cmd.bflags = free
+	cmd.doer = func(data *cmddata) string {
+		defer hc.prompt.UpdatePrompt()
+		defer hc.pause(true)
+		notifications, err := hc.GetUnreadNotifications()
+		if len(notifications) > 0 {
+			hc.PrintNotifications(notifications)
+			err = hc.SetNotificationsRead(notifications[len(notifications)-1].ID)
+			if err != nil {
+				return fmt.Sprintf("%s\n", err)
+			}
+			return ""
+		}
+		hc.page = &Page{}
+		hc.page.loader = &NotificationPages{hc: hc}
+		return hc.page.String()
+	}
+	return cmd
+}
+
+func (hc *Hellclient) newCmdArray() []cmder {
 	cmdarray := []cmder{
 		&profilecmd{hc, hc.cmdload},
 		&dmcmd{hc},
@@ -520,6 +580,9 @@
 		hc.prevcmd(),
 		hc.nextcmd(),
 		hc.pagecmd(),
+		hc.bookmarkscmd(),
+		hc.readcmd(),
+		hc.noticecmd(),
 	}
 	return cmdarray
 }
--- a/main.go
+++ b/main.go
@@ -124,52 +124,7 @@
 
 			//Contextual commands that need to handle their own requirements
 			switch command {
-			case "bookmarks":
-				hc.pause(true)
-				hc.page = &Page{}
-				getter := &BasicStatusGetter{getter: hc.client.GetBookmarks}
-				hc.page.loader = &StatusPages{hc: hc, getter: getter}
-				fmt.Print(hc.page.String())
-				return
-			case "likes":
-				hc.pause(true)
-				hc.page = &Page{}
-				getter := &BasicStatusGetter{getter: hc.client.GetFavourites}
-				hc.page.loader = &StatusPages{hc: hc, getter: getter}
-				fmt.Print(hc.page.String())
-				return
-			case "read":
-				defer hc.prompt.UpdatePrompt()
-				notifications, err := hc.GetUnreadNotifications()
-				if err != nil {
-					fmt.Print(err)
-				}
-				if len(notifications) > 0 {
-					err = hc.SetNotificationsRead(notifications[len(notifications)-1].ID)
-					if err != nil {
-						fmt.Print(err)
-					}
-				}
-				return
-			case "notice":
-				defer hc.prompt.UpdatePrompt()
-				defer hc.pause(true)
-				notifications, err := hc.GetUnreadNotifications()
-				if len(notifications) > 0 {
-					hc.PrintNotifications(notifications)
-					err = hc.SetNotificationsRead(notifications[len(notifications)-1].ID)
-					if err != nil {
-						fmt.Print(err)
-					}
-					return
-				}
-				hc.page = &Page{}
-				hc.page.loader = &NotificationPages{hc: hc}
-				fmt.Print(hc.page.String())
-				if err != nil {
-					fmt.Print(err)
-				}
-				return
+			
 			case "pause":
 				hc.togglepause()
 				return
--