main 6af0a61

disk.go RawHistoryFolder

1package models
2
3import legacysystem "github.com/bnema/archup/internal/system"
4
5// DiskOption represents a selectable disk option.
6type DiskOption struct {
7	Label string
8	Path  string
9	Size  string
10	Model string
11}
12
13// DiskModelImpl holds disk selection state.
14type DiskModelImpl struct {
15	disks    []legacysystem.Disk
16	options  []DiskOption
17	selected int
18	err      error
19}
20
21// NewDiskModel creates a new disk selection model.
22func NewDiskModel() *DiskModelImpl {
23	return &DiskModelImpl{
24		options:  []DiskOption{},
25		selected: 0,
26	}
27}
28
29// SetDisks populates the disk options from detected disks.
30func (dm *DiskModelImpl) SetDisks(disks []legacysystem.Disk) {
31	dm.disks = disks
32	dm.options = make([]DiskOption, 0, len(disks))
33
34	for _, disk := range disks {
35		label := disk.Path + " (" + disk.Size + ")"
36		if disk.Model != "" {
37			label += " " + disk.Model
38		}
39		if disk.Serial != "" {
40			label += " [" + disk.Serial + "]"
41		}
42		if disk.Vendor != "" && disk.Model == "" {
43			label += " " + disk.Vendor
44		}
45
46		dm.options = append(dm.options, DiskOption{
47			Label: label,
48			Path:  disk.Path,
49			Size:  disk.Size,
50			Model: disk.Model,
51		})
52	}
53}
54
55// SetError sets an error that occurred during disk detection.
56func (dm *DiskModelImpl) SetError(err error) {
57	dm.err = err
58}
59
60// Error returns any error from disk detection.
61func (dm *DiskModelImpl) Error() error {
62	return dm.err
63}
64
65// Options returns the selectable disk options.
66func (dm *DiskModelImpl) Options() []DiskOption {
67	return dm.options
68}
69
70// SelectedIndex returns the current selection index.
71func (dm *DiskModelImpl) SelectedIndex() int {
72	return dm.selected
73}
74
75// SelectedOption returns the currently selected disk option.
76func (dm *DiskModelImpl) SelectedOption() DiskOption {
77	if len(dm.options) == 0 {
78		return DiskOption{Label: "No disks found", Path: ""}
79	}
80	if dm.selected < 0 || dm.selected >= len(dm.options) {
81		return dm.options[0]
82	}
83	return dm.options[dm.selected]
84}
85
86// MoveUp moves selection up.
87func (dm *DiskModelImpl) MoveUp() {
88	if len(dm.options) == 0 {
89		return
90	}
91	if dm.selected == 0 {
92		dm.selected = len(dm.options) - 1
93		return
94	}
95	dm.selected--
96}
97
98// MoveDown moves selection down.
99func (dm *DiskModelImpl) MoveDown() {
100	if len(dm.options) == 0 {
101		return
102	}
103	dm.selected = (dm.selected + 1) % len(dm.options)
104}
105
106// HasDisks returns true if any disks were detected.
107func (dm *DiskModelImpl) HasDisks() bool {
108	return len(dm.options) > 0
109}

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 0

    ↑↓ moveenter openesc close