v0.1.88 14ffdb6

ext_panel_dialog.go RawHistoryFolder

1package modes
2
3import (
4	"fmt"
5	"strings"
6
7	"github.com/mattn/go-runewidth"
8
9	"github.com/patriceckhart/zot/internal/tui"
10)
11
12type extPanelDialog struct {
13	active bool
14	ext    string
15	id     string
16	title  string
17	lines  []string
18	footer string
19}
20
21func newExtPanelDialog() *extPanelDialog { return &extPanelDialog{} }
22
23func (d *extPanelDialog) Active() bool { return d != nil && d.active }
24
25func (d *extPanelDialog) Open(ext, id, title string, lines []string, footer string) {
26	d.active = true
27	d.ext = ext
28	d.id = id
29	d.title = title
30	d.lines = append([]string(nil), lines...)
31	d.footer = footer
32}
33
34func (d *extPanelDialog) Update(title string, lines []string, footer string) {
35	if !d.active {
36		return
37	}
38	if title != "" {
39		d.title = title
40	}
41	d.lines = append(d.lines[:0], lines...)
42	d.footer = footer
43}
44
45func (d *extPanelDialog) Close() {
46	d.active = false
47	d.ext = ""
48	d.id = ""
49	d.title = ""
50	d.lines = nil
51	d.footer = ""
52}
53
54func (d *extPanelDialog) Render(th tui.Theme, width int) []string {
55	if !d.Active() {
56		return nil
57	}
58	title := d.title
59	if title == "" {
60		title = d.ext
61	}
62	out := []string{frameHeaderColor(th, title, width, th.Accent)}
63	for _, l := range d.lines {
64		plain := stripANSIBytes(l)
65		trimmed := strings.TrimLeft(plain, " ")
66		// Selection markers, in order of precedence:
67		//   "▸ " / "● "  visible glyph the user sees
68		//   "\u200b"      invisible zero-width-space sentinel for
69		//                 extensions that want the row highlight
70		//                 without rendering an arrow
71		selected := strings.HasPrefix(trimmed, "▸ ") ||
72			strings.HasPrefix(trimmed, "● ") ||
73			strings.HasPrefix(trimmed, "\u200b")
74		out = append(out, styleExtPanelLine(th, l, plain, width, selected))
75	}
76	if strings.TrimSpace(d.footer) != "" {
77		out = append(out, "")
78		out = append(out, th.FG256(th.Muted, d.footer))
79	}
80	out = append(out, frameRuleColor(th, width, th.Accent))
81	return out
82}
83
84func styleExtPanelLine(th tui.Theme, raw string, plain string, width int, selected bool) string {
85	if selected {
86		if visible := runewidth.StringWidth(plain); visible < width {
87			plain += strings.Repeat(" ", width-visible)
88		}
89		base := fmt.Sprintf("\x1b[38;5;%dm\x1b[48;5;%dm", th.SelectionFG, th.SelectionBG)
90		green := fmt.Sprintf("\x1b[38;5;%dm\x1b[48;5;%dm", th.Tool, th.SelectionBG)
91		return base + strings.ReplaceAll(plain, "✓", green+"✓"+base) + "\x1b[0m"
92	}
93	if raw != plain {
94		return raw + "\x1b[0m"
95	}
96	styled := th.FG256(th.Muted, plain)
97	styled = strings.ReplaceAll(styled, "✓", th.FG256(th.Tool, "✓"))
98	return styled
99}

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 476

↑↓ moveenter openesc close