~taiite/public-inbox

senpai: ui: improve buffer number detection v1 PROPOSED

Kalyan Sriram: 1
 ui: improve buffer number detection

 1 files changed, 9 insertions(+), 1 deletions(-)
> On 15/12/2021 03:53, Kalyan Sriram wrote:
> > Improve show buffer numbers on "/buffer" command. Checks completion
> > against list of commands to avoid ambigious "/b" matching ("BUFFER" v.
> > "BAN"). Matches uppercase and mixed case i.e. "/BU" or "/bU".
> 
> I see, thanks for the patch. While I don't use neither buffer numbers
> nor /buffer myself, I expect typing "/b <number>" be the common
> practice, and this patch breaks it? What do you think?
Yes, typing /b is the common practice but unfortunately doesn't
currently work since the "BAN" command was introduced. /b brings up the
numbers, but once the user presses enter, the command complains saying
"b" is ambigious. Hence I thought this would be the least intrusive way
to fix that. What do you think? Is there a better way to address this?

Kalyan
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~taiite/public-inbox/patches/27402/mbox | git am -3
Learn more about email & git

[PATCH senpai] ui: improve buffer number detection Export this patch

Improve show buffer numbers on "/buffer" command. Checks completion
against list of commands to avoid ambigious "/b" matching ("BUFFER" v.
"BAN"). Matches uppercase and mixed case i.e. "/BU" or "/bU".
---
 window.go | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/window.go b/window.go
index 82941a1..87e4be4 100644
--- a/window.go
+++ b/window.go
@@ -83,7 +83,15 @@ func (app *App) setBufferNumbers() {
		}
	}
	command := string(input[1:commandEnd])
	showBufferNumbers := len(command) != 0 && strings.HasPrefix("buffer", command)

	var completed []string
	uCommand := strings.ToUpper(command)
	for name, _ := range commands {
		if strings.HasPrefix(name, uCommand) {
			completed = append(completed, name)
		}
	}
	showBufferNumbers := len(command) != 0 && len(completed) == 1 && completed[0] == "BUFFER"
	app.win.ShowBufferNumbers(showBufferNumbers)
}

-- 
2.34.1