resume_input.go RawHistoryFolder

1package client
2
3import (
4	"bytes"
5	"time"
6
7	"github.com/bnema/vev/internal/usecase/keys/kittykey"
8)
9
10const resumeEscapeLimit = 256
11
12// resumeEscapeDelay is how long a lone Esc stays undecided before it counts
13// as a cancel rather than the start of an escape sequence.
14const resumeEscapeDelay = 50 * time.Millisecond
15
16// resumeInputDecoder retains only an undecided escape prefix. Held bytes stay
17// in their original terminal encoding; paste content is never a cancel key.
18type resumeInputDecoder struct {
19	prefix []byte
20	paste  bool
21}
22
23func (d *resumeInputDecoder) feed(data []byte) (held []byte, cancel bool) {
24	for _, b := range data {
25		if len(d.prefix) == 0 {
26			if b == 0x1b {
27				d.prefix = append(d.prefix, b)
28				continue
29			}
30			if b == 3 && !d.paste {
31				return held, true
32			}
33			held = append(held, b)
34			continue
35		}
36		if b == 0x1b || (b < 0x20 && !d.paste) {
37			held = append(held, d.prefix...)
38			d.prefix = d.prefix[:0]
39			if b == 3 {
40				return held, true
41			}
42			if b == 0x1b {
43				d.prefix = append(d.prefix, b)
44			} else {
45				held = append(held, b)
46			}
47			continue
48		}
49		d.prefix = append(d.prefix, b)
50		if d.paste {
51			end := []byte("\x1b[201~")
52			if bytes.Equal(d.prefix, end) {
53				d.paste = false
54			} else if bytes.HasPrefix(end, d.prefix) {
55				continue
56			}
57		} else {
58			start := []byte("\x1b[200~")
59			if bytes.Equal(d.prefix, start) {
60				d.paste = true
61			} else if bytes.HasPrefix(start, d.prefix) {
62				continue
63			} else {
64				_, n, ok, partial := kittykey.Parse(d.prefix)
65				if ok {
66					translated := kittykey.Translate(d.prefix[:n], 0)
67					if len(translated) == 1 && (translated[0] == 3 || translated[0] == 0x1b) {
68						return held, true
69					}
70				} else if partial && len(d.prefix) < resumeEscapeLimit {
71					continue
72				} else if len(d.prefix) >= 2 && (d.prefix[1] == '[' || d.prefix[1] == 'O') && b >= 0x20 && b < 0x40 && len(d.prefix) < resumeEscapeLimit {
73					continue
74				}
75			}
76		}
77		held = append(held, d.prefix...)
78		d.prefix = d.prefix[:0]
79	}
80	return held, false
81}
82
83// undecided reports whether an escape prefix is still waiting for more bytes.
84func (d *resumeInputDecoder) undecided() bool {
85	return len(d.prefix) != 0
86}
87
88func (d *resumeInputDecoder) loneEscape() bool {
89	return !d.paste && bytes.Equal(d.prefix, []byte{0x1b})
90}
91
92func (d *resumeInputDecoder) flush() []byte {
93	data := d.prefix
94	d.prefix = nil
95	return data
96}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 12

Tags 11

↑↓ moveenter openesc close