v0.6.0 b250c5e

screen_cursor.go RawHistoryFolder

1package vt
2
3import (
4	"strconv"
5	"strings"
6
7	renderer "github.com/bnema/vev-vt/core"
8)
9
10type cursorState struct {
11	row          int
12	col          int
13	style        renderer.Style
14	originMode   bool
15	insertMode   bool
16	autoWrapMode bool
17	saved        bool
18}
19
20func (s *Screen) cursorReportRow() int {
21	if s.originMode {
22		return clamp(s.Row, s.cursorMinRow(), s.cursorMaxRow()) - s.cursorMinRow() + 1
23	}
24	return s.Row + 1
25}
26
27func (s *Screen) cursorMinRow() int {
28	if s.originMode {
29		return clamp(s.scrollTop, 0, s.frame.Height-1)
30	}
31	return 0
32}
33
34func (s *Screen) cursorMaxRow() int {
35	if s.originMode {
36		return clamp(s.scrollBottom, 0, s.frame.Height-1)
37	}
38	return max(s.frame.Height-1, 0)
39}
40
41func (s *Screen) addressedRow(row int) int {
42	if s.originMode {
43		return clamp(s.scrollTop+row-1, s.cursorMinRow(), s.cursorMaxRow())
44	}
45	return clamp(row-1, 0, s.frame.Height-1)
46}
47
48func (s *Screen) addressCursor(row, col int) {
49	s.Row = s.addressedRow(row)
50	s.Col = clamp(col-1, 0, s.frame.Width-1)
51}
52
53func (s *Screen) homeCursor() {
54	s.addressCursor(1, 1)
55}
56
57func (s *Screen) applyCursorStyle(params string) {
58	if strings.HasPrefix(params, ">") || !strings.HasSuffix(params, " ") {
59		return
60	}
61	styleParam := strings.TrimSuffix(params, " ")
62	style := 0
63	if styleParam != "" {
64		v, err := strconv.Atoi(styleParam)
65		if err != nil {
66			return
67		}
68		style = v
69	}
70	if style < 0 || style > 6 {
71		return
72	}
73	s.cursorStyle = style
74	s.cursorStyleSet = true
75}
76
77func (s *Screen) saveCursor() {
78	s.savedCursor = cursorState{
79		row: s.Row, col: s.Col, style: s.Style,
80		originMode: s.originMode, insertMode: s.insertMode,
81		autoWrapMode: s.autoWrapMode, saved: true,
82	}
83}
84
85func (s *Screen) restoreCursor() {
86	if !s.savedCursor.saved {
87		return
88	}
89	s.Row = clamp(s.savedCursor.row, 0, s.frame.Height-1)
90	s.Col = clamp(s.savedCursor.col, 0, s.frame.Width-1)
91	s.Style = s.savedCursor.style
92	s.originMode = s.savedCursor.originMode
93	s.insertMode = s.savedCursor.insertMode
94	s.autoWrapMode = s.savedCursor.autoWrapMode
95}

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 2

Tags 13

↑↓ moveenter openesc close