Skip to content

Commit 3581a62

Browse files
committed
added help menu on h or ? click
1 parent c41465d commit 3581a62

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

main.go

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,17 @@ func (e *EventThrottler) Notify() {
7878
}
7979

8080
var (
81-
cpu1Gauge, cpu2Gauge, gpuGauge, aneGauge *w.Gauge
82-
TotalPowerChart *w.BarChart
83-
memoryGauge *w.Gauge
84-
modelText, PowerChart, NetworkInfo, ProcessInfo *w.Paragraph
85-
grid *ui.Grid
86-
powerValues []float64
87-
lastUpdateTime time.Time
88-
stderrLogger = log.New(os.Stderr, "", 0)
89-
currentGridLayout = "default"
90-
updateInterval = 1000
81+
cpu1Gauge, cpu2Gauge, gpuGauge, aneGauge *w.Gauge
82+
TotalPowerChart *w.BarChart
83+
memoryGauge *w.Gauge
84+
modelText, PowerChart, NetworkInfo, ProcessInfo, helpText *w.Paragraph
85+
grid *ui.Grid
86+
powerValues []float64
87+
lastUpdateTime time.Time
88+
stderrLogger = log.New(os.Stderr, "", 0)
89+
currentGridLayout = "default"
90+
showHelp = false
91+
updateInterval = 1000
9192
)
9293

9394
var (
@@ -106,6 +107,8 @@ func setupUI() {
106107
appleSiliconModel := getSOCInfo()
107108
modelText = w.NewParagraph()
108109
modelText.Title = "Apple Silicon"
110+
helpText = w.NewParagraph()
111+
helpText.Title = "Help Menu"
109112
modelName, ok := appleSiliconModel["name"].(string)
110113
if !ok {
111114
modelName = "Unknown Model"
@@ -129,6 +132,12 @@ func setupUI() {
129132
pCoreCount,
130133
gpuCoreCount,
131134
)
135+
helpText.Text = "- r: Refresh the UI data manually\n" +
136+
"- l: Toggle the main display's layout\n" +
137+
"- h: Toggle this help menu\n" +
138+
"- ?: Toggle this help menu\n" +
139+
"- q: Quit the application\n" +
140+
"- <C-c>: Quit the application"
132141
stderrLogger.Printf("Model: %s\nE-Core Count: %d\nP-Core Count: %d\nGPU Core Count: %s",
133142
modelName,
134143
eCoreCount,
@@ -206,6 +215,7 @@ func switchGridLayout() {
206215
newGrid.Set(
207216
ui.NewRow(1.0/2, // This row now takes half the height of the grid
208217
ui.NewCol(1.0/2, ui.NewRow(1.0, cpu1Gauge)), // ui.NewCol(1.0, ui.NewRow(1.0, cpu2Gauge))),
218+
209219
ui.NewCol(1.0/2, ui.NewRow(1.0, cpu2Gauge)), // ProcessInfo spans this entire column
210220
),
211221
ui.NewRow(1.0/4,
@@ -248,6 +258,32 @@ func switchGridLayout() {
248258
}
249259
}
250260

261+
func toggleHelpMenu() {
262+
if !showHelp {
263+
newGrid := ui.NewGrid()
264+
newGrid.Set(
265+
ui.NewRow(1.0,
266+
ui.NewCol(1.0, helpText),
267+
),
268+
)
269+
termWidth, termHeight := ui.TerminalDimensions()
270+
helpTextGridWidth := termWidth / 3
271+
helpTextGridHeight := termHeight / 2
272+
x := (termWidth - helpTextGridWidth) / 2
273+
y := (termHeight - helpTextGridHeight) / 2
274+
newGrid.SetRect(x, y, x + helpTextGridWidth, y + helpTextGridHeight)
275+
grid = newGrid
276+
showHelp = !showHelp
277+
} else {
278+
currentGridLayout = map[bool]string{
279+
true: "alternative",
280+
false: "default",
281+
}[currentGridLayout == "default"]
282+
switchGridLayout()
283+
showHelp = !showHelp
284+
}
285+
}
286+
251287
func StderrToLogfile(logfile *os.File) {
252288
syscall.Dup2(int(logfile.Fd()), 2)
253289
}
@@ -431,6 +467,12 @@ func main() {
431467
ui.Clear()
432468
switchGridLayout()
433469
ui.Render(grid)
470+
case "h", "?": // "h" or "?" to open help menu
471+
termWidth, termHeight := ui.TerminalDimensions()
472+
grid.SetRect(0, 0, termWidth, termHeight)
473+
ui.Clear()
474+
toggleHelpMenu()
475+
ui.Render(grid)
434476
}
435477
case <-done:
436478
ui.Close()

0 commit comments

Comments
 (0)