commit c7eceaa

Alexey Yerin  ·  2021-04-27 12:58:36 +0000 UTC
parent 2d6db1f
Add BUFFER command to jump to the matching buffer

Is is very useful when you have joined a bunch of channels and scrolling
with Ctrl+n/Ctrl+p is quite inefficient.
3 files changed,  +32, -0
+17, -0
 1@@ -100,6 +100,14 @@ func init() {
 2 			Desc:    "show or set the topic of the current channel",
 3 			Handle:  commandDoTopic,
 4 		},
 5+		"BUFFER": {
 6+			AllowHome: true,
 7+			MinArgs:   1,
 8+			MaxArgs:   1,
 9+			Usage:     "<name>",
10+			Desc:      "switch to the buffer containing a substring",
11+			Handle:    commandDoBuffer,
12+		},
13 	}
14 }
15 
16@@ -375,3 +383,12 @@ func (app *App) handleInput(buffer, content string) error {
17 
18 	return cmd.Handle(app, buffer, args)
19 }
20+
21+func commandDoBuffer(app *App, buffer string, args []string) error {
22+	name := args[0]
23+	if !app.win.JumpBuffer(args[0]) {
24+		return fmt.Errorf("none of the buffers match %q", name)
25+	}
26+
27+	return nil
28+}
+3, -0
 1@@ -140,6 +140,9 @@ _name_ is matched case-insensitively.  It can be one of the following:
 2 *QUOTE* <raw message>
 3 	Send _raw message_ verbatim.
 4 
 5+*BUFFER* <name>
 6+	Switch to the buffer containing _name_.
 7+
 8 # SEE ALSO
 9 
10 *senpai*(5)
+12, -0
 1@@ -1,6 +1,7 @@
 2 package ui
 3 
 4 import (
 5+	"strings"
 6 	"sync/atomic"
 7 	"time"
 8 
 9@@ -140,6 +141,17 @@ func (ui *UI) AddLines(buffer string, lines []Line) {
10 	ui.bs.AddLines(buffer, lines)
11 }
12 
13+func (ui *UI) JumpBuffer(sub string) bool {
14+	for i, b := range ui.bs.list {
15+		if strings.Contains(b.title, sub) {
16+			ui.bs.To(i)
17+			return true
18+		}
19+	}
20+
21+	return false
22+}
23+
24 func (ui *UI) SetStatus(status string) {
25 	ui.status = status
26 }