v0.1.31 853a089

telegram_dialog.go RawHistoryFolder

1package modes
2
3import (
4	"github.com/patriceckhart/zot/internal/tui"
5)
6
7// telegramDialog is the picker shown when the user runs `/telegram`
8// without an argument. Lists the three actions (connect, disconnect,
9// status) and routes the choice back to the Interactive via
10// telegramAction.
11//
12// Shape mirrors logoutDialog: a tiny list of rows with the cursor
13// moved by arrow keys and enter to pick, esc to cancel.
14type telegramDialog struct {
15	active bool
16	items  []telegramItem
17	cursor int
18}
19
20type telegramItem struct {
21	label  string
22	action string // "connect" | "disconnect" | "status"
23	hint   string // muted text shown after the label (e.g. "not configured", "active")
24}
25
26type telegramAction struct {
27	Select bool
28	Action string
29	Close  bool
30}
31
32func newTelegramDialog() *telegramDialog { return &telegramDialog{} }
33
34// Open shows the picker with items describing the current state.
35// items is rendered in order; the caller builds it so connect is
36// only offered when disconnected, and vice versa.
37func (d *telegramDialog) Open(items []telegramItem) bool {
38	if len(items) == 0 {
39		return false
40	}
41	d.items = items
42	d.cursor = 0
43	d.active = true
44	return true
45}
46
47// Close hides the dialog.
48func (d *telegramDialog) Close() { d.active = false }
49
50// Active reports whether the dialog is consuming input.
51func (d *telegramDialog) Active() bool { return d != nil && d.active }
52
53// HandleKey advances the selection or resolves the dialog.
54func (d *telegramDialog) HandleKey(k tui.Key) telegramAction {
55	switch k.Kind {
56	case tui.KeyUp:
57		if d.cursor > 0 {
58			d.cursor--
59		}
60	case tui.KeyDown:
61		if d.cursor < len(d.items)-1 {
62			d.cursor++
63		}
64	case tui.KeyEsc:
65		d.Close()
66		return telegramAction{Close: true}
67	case tui.KeyEnter:
68		if len(d.items) == 0 {
69			d.Close()
70			return telegramAction{Close: true}
71		}
72		it := d.items[d.cursor]
73		d.Close()
74		return telegramAction{Select: true, Action: it.action}
75	}
76	return telegramAction{}
77}
78
79// Render returns the dialog lines.
80func (d *telegramDialog) Render(th tui.Theme, width int) []string {
81	if !d.Active() {
82		return nil
83	}
84	var lines []string
85	lines = append(lines, frameHeader(th, "telegram", width))
86	lines = append(lines, th.FG256(th.Muted, "pick an action (\u2191/\u2193, enter, esc to cancel):"))
87	for i, it := range d.items {
88		plain := "  " + it.label
89		if it.hint != "" {
90			plain += "  " + th.FG256(th.Muted, "("+it.hint+")")
91		}
92		if i == d.cursor {
93			lines = append(lines, th.PadHighlight(plain, width))
94		} else {
95			lines = append(lines, th.FG256(th.Muted, plain))
96		}
97	}
98	lines = append(lines, frameRule(th, width))
99	return lines
100}

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