v0.1.70 25cb7d5

settings_dialog.go RawHistoryFolder

1package modes
2
3import (
4	"github.com/patriceckhart/zot/internal/tui"
5)
6
7type settingsDialog struct {
8	active bool
9	items  []settingsItem
10	cursor int
11}
12
13type settingsItem struct {
14	key      string
15	label    string
16	desc     string
17	value    bool
18	disabled bool
19	hint     string
20}
21
22type settingsAction struct {
23	Toggle bool
24	Key    string
25	Value  bool
26	Close  bool
27}
28
29func newSettingsDialog() *settingsDialog { return &settingsDialog{} }
30
31func (d *settingsDialog) Open(items []settingsItem) bool {
32	if len(items) == 0 {
33		return false
34	}
35	d.items = items
36	d.cursor = 0
37	d.active = true
38	return true
39}
40
41func (d *settingsDialog) Close()       { d.active = false }
42func (d *settingsDialog) Active() bool { return d != nil && d.active }
43
44func (d *settingsDialog) HandleKey(k tui.Key) settingsAction {
45	switch k.Kind {
46	case tui.KeyUp:
47		if d.cursor > 0 {
48			d.cursor--
49		}
50	case tui.KeyDown:
51		if d.cursor < len(d.items)-1 {
52			d.cursor++
53		}
54	case tui.KeyEsc:
55		d.Close()
56		return settingsAction{Close: true}
57	case tui.KeyEnter:
58		return d.toggleCurrent()
59	case tui.KeyRune:
60		if k.Rune == ' ' {
61			return d.toggleCurrent()
62		}
63	}
64	return settingsAction{}
65}
66
67func (d *settingsDialog) toggleCurrent() settingsAction {
68	if len(d.items) == 0 {
69		d.Close()
70		return settingsAction{Close: true}
71	}
72	it := d.items[d.cursor]
73	if it.disabled {
74		return settingsAction{}
75	}
76	it.value = !it.value
77	d.items[d.cursor] = it
78	return settingsAction{Toggle: true, Key: it.key, Value: it.value}
79}
80
81func (d *settingsDialog) Render(th tui.Theme, width int) []string {
82	if !d.Active() {
83		return nil
84	}
85	var lines []string
86	lines = append(lines, frameHeader(th, "settings", width))
87	lines = append(lines, th.FG256(th.Muted, "toggle with enter/space, esc to close:"))
88	for i, it := range d.items {
89		box := "[ ]"
90		if it.value {
91			box = "[x]"
92		}
93		plain := "  " + box + " " + it.label
94		if it.hint != "" {
95			plain += "  " + th.FG256(th.Muted, "("+it.hint+")")
96		}
97		if it.disabled {
98			lines = append(lines, th.FG256(th.Muted, plain))
99		} else if i == d.cursor {
100			lines = append(lines, th.PadHighlight(plain, width))
101		} else {
102			lines = append(lines, plain)
103		}
104		if it.desc != "" {
105			lines = append(lines, th.FG256(th.Muted, "      "+it.desc))
106		}
107	}
108	lines = append(lines, frameRule(th, width))
109	return lines
110}

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 1

Tags 477

↑↓ moveenter openesc close