main 6af0a61

amd_pstate.go RawHistoryFolder

1package models
2
3import legacysystem "github.com/bnema/archup/internal/system"
4
5// AMDPStateOption represents a selectable AMD P-State mode.
6type AMDPStateOption struct {
7	Mode        legacysystem.AMDPStateMode
8	Label       string
9	Recommended bool
10}
11
12// AMDPStateModelImpl holds AMD P-State selection state.
13type AMDPStateModelImpl struct {
14	cpuInfo  *legacysystem.CPUInfo
15	options  []AMDPStateOption
16	selected int
17}
18
19// NewAMDPStateModel creates a new AMD P-State selection model.
20func NewAMDPStateModel() *AMDPStateModelImpl {
21	return &AMDPStateModelImpl{
22		options:  []AMDPStateOption{},
23		selected: 0,
24	}
25}
26
27// SetCPUInfo sets CPU info and rebuilds options.
28func (am *AMDPStateModelImpl) SetCPUInfo(info *legacysystem.CPUInfo) {
29	am.cpuInfo = info
30	am.options = []AMDPStateOption{}
31	am.selected = 0
32
33	if info == nil {
34		return
35	}
36
37	for _, mode := range info.AMDPStateModes {
38		desc := legacysystem.GetPStateModeDescription(mode)
39		label := string(mode)
40		if desc != "" {
41			label = label + " - " + desc
42		}
43		option := AMDPStateOption{
44			Mode:        mode,
45			Label:       label,
46			Recommended: mode == info.RecommendedPStateMode,
47		}
48		am.options = append(am.options, option)
49	}
50
51	for i, option := range am.options {
52		if option.Recommended {
53			am.selected = i
54			break
55		}
56	}
57}
58
59// CPUInfo returns detected CPU info.
60func (am *AMDPStateModelImpl) CPUInfo() *legacysystem.CPUInfo {
61	return am.cpuInfo
62}
63
64// Options returns the selectable options.
65func (am *AMDPStateModelImpl) Options() []AMDPStateOption {
66	return am.options
67}
68
69// SelectedIndex returns the current selection index.
70func (am *AMDPStateModelImpl) SelectedIndex() int {
71	return am.selected
72}
73
74// SelectedOption returns the currently selected option.
75func (am *AMDPStateModelImpl) SelectedOption() AMDPStateOption {
76	if len(am.options) == 0 {
77		return AMDPStateOption{}
78	}
79	if am.selected < 0 || am.selected >= len(am.options) {
80		return am.options[0]
81	}
82	return am.options[am.selected]
83}
84
85// MoveUp moves selection up.
86func (am *AMDPStateModelImpl) MoveUp() {
87	if len(am.options) == 0 {
88		return
89	}
90	if am.selected == 0 {
91		am.selected = len(am.options) - 1
92		return
93	}
94	am.selected--
95}
96
97// MoveDown moves selection down.
98func (am *AMDPStateModelImpl) MoveDown() {
99	if len(am.options) == 0 {
100		return
101	}
102	am.selected = (am.selected + 1) % len(am.options)
103}
104
105// ShouldPrompt returns true if AMD P-State selection should be shown.
106func (am *AMDPStateModelImpl) ShouldPrompt() bool {
107	if am.cpuInfo == nil {
108		return false
109	}
110	if am.cpuInfo.Vendor != legacysystem.CPUVendorAMD {
111		return false
112	}
113	return len(am.options) > 0
114}

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