cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Show the keys that finish a vim sequence, and size completions to fit

Dami committed 116aa5e
After d or g, the context line lists what may follow (d cut rows, t next
sheet); the command line's completion box is as wide as its entries.
commit
116aa5efb01bc908948f9a62362ebe54ba869b35
parent
67089f72a65bfcb7c31a992ac5282fe0a70a32bf
author
Dami <dami.etoile@gmail.com>
2 files changed, +37 -3
Minternal/ui/cmdline.go3++-
Minternal/ui/vim.go37++++++++++++++++++++++++++++--
M internal/ui/cmdline.go +2 -1
M internal/ui/vim.go +35 -2
@@ -1,6 +1,7 @@
11 package ui22 33 import (4+ "slices"45 "strconv"56 "strings"67
@@ -250,10 +251,11 @@ var vimMotions = map[string]motion{
250251 }251252 252253 // vimLine is the context line while a sequence is being typed (the keys253-// so far, as vim's showcmd) or in VISUAL mode (what applies).254+// so far, as vim's showcmd, and the keys that finish it) or in VISUAL255+// mode (what applies).254256 func (m *Model) vimLine() string {255257 if p := m.vim.pending(); p != "" {256- return m.th.Key.Render(p) + m.th.Muted.Render(" ") + m.th.KeyHints("Esc", "cancel")258+ return m.th.Key.Render(p) + " " + m.th.KeyHints(append(m.vimNext(), "Esc", "cancel")...)257259 }258260 if m.vim.visual == visualRows {259261 return m.th.KeyHints("d", "delete rows", "y", "copy rows", "o", "other end", ":", "command", "Esc", "back")
@@ -261,6 +263,37 @@ func (m *Model) vimLine() string {
261263 return m.th.KeyHints("d", "delete", "y", "copy", "p", "paste", "o", "other corner", "V", "rows", "Esc", "back")262264 }263265 266+// vimNext lists the keys that finish the sequence begun, and what they267+// do, as pairs for KeyHints: after d, "d" and "cut rows".268+func (m *Model) vimNext() []string {269+ if m.vim.keys == "" {270+ return nil // just a count: anything may follow271+ }272+ table := vimNormal273+ if m.visual() != visualNone {274+ table = vimVisual275+ }276+ var seqs []string277+ for seq := range table {278+ if len(seq) > len(m.vim.keys) && strings.HasPrefix(seq, m.vim.keys) {279+ seqs = append(seqs, seq)280+ }281+ }282+ if m.vim.keys == "g" {283+ seqs = append(seqs, "gg")284+ }285+ slices.Sort(seqs)286+ var out []string287+ for _, seq := range seqs {288+ what := "first row"289+ if b, ok := table[seq]; ok {290+ what = strings.ToLower(commands[b.id].title)291+ }292+ out = append(out, seq[len(m.vim.keys):], what)293+ }294+ return out295+}296+264297 // startVisual selects from the active cell: cells, or whole rows.265298 func (m *Model) startVisual(kind visualKind) {266299 if m.visual() == visualNone {