diff options
author | Alexey Yerin <yyp@disroot.org> | 2021-04-27 15:58:36 +0300 |
---|---|---|
committer | Hubert Hirtz <hubert@hirtz.pm> | 2021-04-27 16:39:06 +0200 |
commit | c7eceaa8da3cfcc008d8b89849bc44145d054f68 (patch) | |
tree | 839102108833003ee13aa57458b0a5979db03662 | |
parent | senpai.5: fix typo (diff) |
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.
-rw-r--r-- | commands.go | 17 | ||||
-rw-r--r-- | doc/senpai.1.scd | 3 | ||||
-rw-r--r-- | ui/ui.go | 12 |
3 files changed, 32 insertions, 0 deletions
diff --git a/commands.go b/commands.go index b3c2d14..6be50ed 100644 --- a/commands.go +++ b/commands.go @@ -100,6 +100,14 @@ func init() { Desc: "show or set the topic of the current channel", Handle: commandDoTopic, }, + "BUFFER": { + AllowHome: true, + MinArgs: 1, + MaxArgs: 1, + Usage: "<name>", + Desc: "switch to the buffer containing a substring", + Handle: commandDoBuffer, + }, } } @@ -375,3 +383,12 @@ func (app *App) handleInput(buffer, content string) error { return cmd.Handle(app, buffer, args) } + +func commandDoBuffer(app *App, buffer string, args []string) error { + name := args[0] + if !app.win.JumpBuffer(args[0]) { + return fmt.Errorf("none of the buffers match %q", name) + } + + return nil +} diff --git a/doc/senpai.1.scd b/doc/senpai.1.scd index b2e05fd..3aecb3a 100644 --- a/doc/senpai.1.scd +++ b/doc/senpai.1.scd @@ -140,6 +140,9 @@ _name_ is matched case-insensitively. It can be one of the following: *QUOTE* <raw message> Send _raw message_ verbatim. +*BUFFER* <name> + Switch to the buffer containing _name_. + # SEE ALSO *senpai*(5) @@ -1,6 +1,7 @@ package ui import ( + "strings" "sync/atomic" "time" @@ -140,6 +141,17 @@ func (ui *UI) AddLines(buffer string, lines []Line) { ui.bs.AddLines(buffer, lines) } +func (ui *UI) JumpBuffer(sub string) bool { + for i, b := range ui.bs.list { + if strings.Contains(b.title, sub) { + ui.bs.To(i) + return true + } + } + + return false +} + func (ui *UI) SetStatus(status string) { ui.status = status } |