From c7eceaa8da3cfcc008d8b89849bc44145d054f68 Mon Sep 17 00:00:00 2001 From: Alexey Yerin Date: Tue, 27 Apr 2021 15:58:36 +0300 Subject: 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. --- commands.go | 17 +++++++++++++++++ doc/senpai.1.scd | 3 +++ ui/ui.go | 12 ++++++++++++ 3 files changed, 32 insertions(+) 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: "", + 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* Send _raw message_ verbatim. +*BUFFER* + Switch to the buffer containing _name_. + # SEE ALSO *senpai*(5) diff --git a/ui/ui.go b/ui/ui.go index 50ddab5..9ab9024 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -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 } -- cgit v1.2.3