main 6af0a61

gpu.go RawHistoryFolder

1package models
2
3import (
4	"strings"
5
6	"github.com/bnema/archup/internal/domain/system"
7)
8
9// GPUOption represents a selectable GPU driver option.
10type GPUOption struct {
11	Label   string
12	Vendor  system.GPUVendor
13	Drivers []string
14}
15
16// GPUModelImpl holds GPU selection state.
17type GPUModelImpl struct {
18	detected *system.GPU
19	options  []GPUOption
20	selected int
21}
22
23// NewGPUModel creates a new GPU selection model.
24func NewGPUModel() *GPUModelImpl {
25	options := []GPUOption{
26		{
27			Label:   "AMD",
28			Vendor:  system.GPUVendorAMD,
29			Drivers: []string{"mesa", "vulkan-radeon", "libva-mesa-driver", "mesa-vdpau"},
30		},
31		{
32			Label:   "Intel",
33			Vendor:  system.GPUVendorIntel,
34			Drivers: []string{"mesa", "vulkan-intel", "intel-media-driver"},
35		},
36		{
37			Label:   "NVIDIA (open)",
38			Vendor:  system.GPUVendorNVIDIA,
39			Drivers: []string{"nvidia-open", "nvidia-utils", "libva-nvidia-driver"},
40		},
41		{
42			Label:   "None / VM",
43			Vendor:  system.GPUVendorUnknown,
44			Drivers: []string{},
45		},
46	}
47
48	return &GPUModelImpl{
49		options:  options,
50		selected: 0,
51	}
52}
53
54// SetDetectedGPU sets the detected GPU and aligns selection.
55func (gm *GPUModelImpl) SetDetectedGPU(gpu *system.GPU) {
56	gm.detected = gpu
57	if gpu == nil {
58		return
59	}
60	if isVirtualGPUModel(gpu.Model()) || gpu.Vendor() == system.GPUVendorUnknown {
61		gm.selectUnknown()
62		return
63	}
64	for i, option := range gm.options {
65		if option.Vendor == gpu.Vendor() {
66			gm.selected = i
67			return
68		}
69	}
70}
71
72func (gm *GPUModelImpl) selectUnknown() {
73	for i, option := range gm.options {
74		if option.Vendor == system.GPUVendorUnknown {
75			gm.selected = i
76			return
77		}
78	}
79}
80
81func isVirtualGPUModel(model string) bool {
82	lower := strings.ToLower(model)
83	virtualMarkers := []string{
84		"virtualbox",
85		"vmware",
86		"qxl",
87		"virtio",
88		"bochs",
89		"hyper-v",
90		"microsoft",
91		"svga",
92	}
93	for _, marker := range virtualMarkers {
94		if strings.Contains(lower, marker) {
95			return true
96		}
97	}
98	return false
99}
100
101// DetectedGPU returns the detected GPU.
102func (gm *GPUModelImpl) DetectedGPU() *system.GPU {
103	return gm.detected
104}
105
106// Options returns the selectable options.
107func (gm *GPUModelImpl) Options() []GPUOption {
108	return gm.options
109}
110
111// SelectedIndex returns the current selection index.
112func (gm *GPUModelImpl) SelectedIndex() int {
113	return gm.selected
114}
115
116// SelectedOption returns the currently selected option.
117func (gm *GPUModelImpl) SelectedOption() GPUOption {
118	if gm.selected < 0 || gm.selected >= len(gm.options) {
119		return gm.options[0]
120	}
121	return gm.options[gm.selected]
122}
123
124// MoveUp moves selection up.
125func (gm *GPUModelImpl) MoveUp() {
126	if gm.selected == 0 {
127		gm.selected = len(gm.options) - 1
128		return
129	}
130	gm.selected--
131}
132
133// MoveDown moves selection down.
134func (gm *GPUModelImpl) MoveDown() {
135	gm.selected = (gm.selected + 1) % len(gm.options)
136}

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