ref: afe2f385e4848787de1a5832b71e5d019995d03c
parent: b5b6aaac6d27bf63b19361fe6ca728fb65ed1d04
author: penny <penny@limitedideas.org>
date: Thu Aug 14 22:51:53 EDT 2025
Port to ergochat readline
--- a/hellclient.go
+++ b/hellclient.go
@@ -5,7 +5,7 @@
"strings"
"sync"
- "github.com/chzyer/readline"
+ "github.com/ergochat/readline"
"github.com/mattn/go-mastodon"
)
@@ -19,6 +19,7 @@
isPaused bool
rl *readline.Instance
client *mastodon.Client
+ account *mastodon.Account
block sync.Mutex
homeMap map[string]*mastodon.Status
@@ -29,12 +30,13 @@
func NewHellclient() (*Hellclient, error) { rl, err := readline.New("Hell> ")+ rl.CaptureExitSignal()
if err != nil {- return nil, error
+ return nil, err
}
- client, err := initClient(account)
+ account, err := loadConfig()
if err != nil {- return nil, error
+ return nil, err
}
client := initClient(account)
homeMap := make(map[string]*mastodon.Status)
--- a/main.go
+++ b/main.go
@@ -13,15 +13,6 @@
)
func main() {- account, err := loadConfig()
- if err != nil {- fmt.Printf("Error: %v\n", err)- return
- }
-
- client := initClient(account)
-
-
hc, err := NewHellclient()
rl := hc.rl
client := hc.client
@@ -42,6 +33,7 @@
homeMap := hc.homeMap
debugMap := hc.debugMap
postref := "a"
+ interupted := false //use this to check if we were interupted last turn
var recentpost *mastodon.Status
currentUser, err := client.GetAccountCurrentUser(context.Background())
@@ -56,13 +48,21 @@
for { func() {line, err := rl.Readline()
+ //If we get an interupt error, we'll return to read the next line
+ //If the next line is empty, exit the program
+ //If it isn't empty, we were just clearing the line
+ if interupted {+ if(len(line) == 0) {+ os.Exit(0)
+ } else {+ interupted = false
+ return
+ }
+ }
if err != nil { if err == EOF || err == ErrInterrupt {- if(len(line) == 0) {- os.Exit(0)
- } else {- return
- }
+ interupted = true
+ return
}
if err != nil { fmt.Println("Error:", err)--
⑨