summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-10-20 17:33:10 +0200
committerHubert Hirtz <hubert@hirtz.pm>2021-10-24 12:57:24 +0200
commit9fb4378753ddec61a504a0dec403f40d6def7e90 (patch)
tree32955930be2d97614f3ec6290f67d0556769a16e /cmd
parentRemove draft file (diff)
Support for soju.im/bouncer-networks
This patch also disable the highlight on reconnect. This might be an issue (the user would want to know when senpai is online again?), but with multiple connections, it's bothersome to have to unread all of them on start (it wasn't a problem with only one connection since it was read instantly). Now, lastbuffer.txt also contains the network ID, otherwise the user might end up on another buffer with the same name. This patch does not extend /r to support multiple networks (it will send the message to the latest query, whatever the current displayed network is).
Diffstat (limited to 'cmd')
-rw-r--r--cmd/senpai/main.go21
1 files changed, 14 insertions, 7 deletions
diff --git a/cmd/senpai/main.go b/cmd/senpai/main.go
index e41d8db..dc2493e 100644
--- a/cmd/senpai/main.go
+++ b/cmd/senpai/main.go
@@ -43,19 +43,21 @@ func main() {
cfg.Debug = cfg.Debug || debug
- lastBuffer := getLastBuffer()
-
- app, err := senpai.NewApp(cfg, lastBuffer)
+ app, err := senpai.NewApp(cfg)
if err != nil {
panic(err)
}
+ lastNetID, lastBuffer := getLastBuffer()
+ app.SwitchToBuffer(lastNetID, lastBuffer)
+
app.Run()
app.Close()
// Write last buffer on close
lastBufferPath := getLastBufferPath()
- err = os.WriteFile(lastBufferPath, []byte(app.CurrentBuffer()), 0666)
+ lastNetID, lastBuffer = app.CurrentBuffer()
+ err = os.WriteFile(lastBufferPath, []byte(fmt.Sprintf("%s %s", lastNetID, lastBuffer)), 0666)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to write last buffer at %q: %s\n", lastBufferPath, err)
}
@@ -76,11 +78,16 @@ func getLastBufferPath() string {
return lastBufferPath
}
-func getLastBuffer() string {
+func getLastBuffer() (netID, buffer string) {
buf, err := ioutil.ReadFile(getLastBufferPath())
if err != nil {
- return ""
+ return "", ""
+ }
+
+ fields := strings.SplitN(string(buf), " ", 2)
+ if len(fields) < 2 {
+ return "", ""
}
- return strings.TrimSpace(string(buf))
+ return fields[0], fields[1]
}