commit 5109024
delthas
·
2021-07-14 20:44:03 +0000 UTC
parent b680d6c
Make buffers indexed, and refer to indexes with /BUFFER Fixes: #29
2 files changed,
+16,
-1
+7,
-0
1@@ -2,6 +2,7 @@ package senpai
2
3 import (
4 "fmt"
5+ "strconv"
6 "strings"
7 "time"
8
9@@ -478,6 +479,12 @@ func (app *App) handleInput(buffer, content string) error {
10
11 func commandDoBuffer(app *App, buffer string, args []string) error {
12 name := args[0]
13+ i, err := strconv.Atoi(name)
14+ if err == nil {
15+ if app.win.JumpBufferIndex(i) {
16+ return nil
17+ }
18+ }
19 if !app.win.JumpBuffer(args[0]) {
20 return fmt.Errorf("none of the buffers match %q", name)
21 }
+9,
-1
1@@ -1,6 +1,8 @@
2 package ui
3
4 import (
5+ "fmt"
6+ "math"
7 "strings"
8 "time"
9
10@@ -396,6 +398,7 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
11 screen.SetContent(x0+width, y, 0x2502, nil, st)
12 }
13
14+ indexPadding := 1 + int(math.Ceil(math.Log10(float64(len(bs.list)))))
15 for i, b := range bs.list {
16 st = tcell.StyleDefault
17 x := x0
18@@ -408,7 +411,12 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
19 if i == bs.clicked {
20 st = st.Reverse(true)
21 }
22- title := truncate(b.title, width, "\u2026")
23+ indexText := fmt.Sprintf("%d:", i)
24+ for ; x < x0+indexPadding-len(indexText); x++ {
25+ screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
26+ }
27+ printString(screen, &x, y, Styled(indexText, st.Foreground(tcell.ColorGrey)))
28+ title := truncate(b.title, width-(x-x0), "\u2026")
29 printString(screen, &x, y, Styled(title, st))
30 if 0 < b.highlights {
31 st = st.Foreground(tcell.ColorRed).Reverse(true)