summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorHubert Hirtz <hubert@hirtz.pm>2021-10-19 21:13:25 +0200
committerHubert Hirtz <hubert@hirtz.pm>2021-10-19 21:13:25 +0200
commitce78dab820c632550c7e767e4601d0d4d2e34de2 (patch)
treec14d06b0f2d44a6052e0c9d4daa294f7d61a641e /ui
parentDon't forget to close outgoing chan on debug (diff)
Only show buffer numbers when necessary
Saves space also removed non-edition related method IsCommand out of editor.go
Diffstat (limited to 'ui')
-rw-r--r--ui/buffers.go16
-rw-r--r--ui/editor.go9
-rw-r--r--ui/ui.go13
3 files changed, 22 insertions, 16 deletions
diff --git a/ui/buffers.go b/ui/buffers.go
index bf045ca..79d2cf6 100644
--- a/ui/buffers.go
+++ b/ui/buffers.go
@@ -191,6 +191,8 @@ type BufferList struct {
tlInnerWidth int
tlHeight int
+
+ showBufferNumbers bool
}
// NewBufferList returns a new BufferList.
@@ -223,6 +225,10 @@ func (bs *BufferList) To(i int) bool {
return false
}
+func (bs *BufferList) ShowBufferNumbers(enabled bool) {
+ bs.showBufferNumbers = enabled
+}
+
func (bs *BufferList) Next() {
bs.current = (bs.current + 1) % len(bs.list)
bs.list[bs.current].highlights = 0
@@ -386,11 +392,13 @@ func (bs *BufferList) DrawVerticalBufferList(screen tcell.Screen, x0, y0, width,
if i == bs.clicked {
st = st.Reverse(true)
}
- indexText := fmt.Sprintf("%d:", i)
- for ; x < x0+indexPadding-len(indexText); x++ {
- screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
+ if bs.showBufferNumbers {
+ indexText := fmt.Sprintf("%d:", i)
+ for ; x < x0+indexPadding-len(indexText); x++ {
+ screen.SetContent(x, y, ' ', nil, tcell.StyleDefault)
+ }
+ printString(screen, &x, y, Styled(indexText, st.Foreground(tcell.ColorGrey)))
}
- printString(screen, &x, y, Styled(indexText, st.Foreground(tcell.ColorGrey)))
title := truncate(b.title, width-(x-x0), "\u2026")
printString(screen, &x, y, Styled(title, st))
if 0 < b.highlights {
diff --git a/ui/editor.go b/ui/editor.go
index 5e3105b..f4bd247 100644
--- a/ui/editor.go
+++ b/ui/editor.go
@@ -63,12 +63,9 @@ func (e *Editor) Resize(width int) {
e.width = width
}
-func (e *Editor) IsCommand() bool {
- line := e.text[e.lineIdx]
-
- // Command can't start with two slashes because that's an escape for
- // a literal slash in the message
- return len(line) >= 1 && line[0] == '/' && !(len(line) >= 2 && line[1] == '/')
+// Content result must not be modified.
+func (e *Editor) Content() []rune {
+ return e.text[e.lineIdx]
}
func (e *Editor) TextLen() int {
diff --git a/ui/ui.go b/ui/ui.go
index 9926fe7..db1d8bd 100644
--- a/ui/ui.go
+++ b/ui/ui.go
@@ -112,6 +112,10 @@ func (ui *UI) GoToBufferNo(i int) {
}
}
+func (ui *UI) ShowBufferNumbers(enable bool) {
+ ui.bs.ShowBufferNumbers(enable)
+}
+
func (ui *UI) ScrollUp() {
ui.bs.ScrollUp(ui.bs.tlHeight / 2)
}
@@ -192,12 +196,9 @@ func (ui *UI) SetPrompt(prompt StyledString) {
ui.prompt = prompt
}
-func (ui *UI) InputIsCommand() bool {
- return ui.e.IsCommand()
-}
-
-func (ui *UI) InputLen() int {
- return ui.e.TextLen()
+// InputContent result must not be modified.
+func (ui *UI) InputContent() []rune {
+ return ui.e.Content()
}
func (ui *UI) InputRune(r rune) {