@@ -78,16 +78,17 @@ func (e *EventThrottler) Notify() {
78
78
}
79
79
80
80
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
91
92
)
92
93
93
94
var (
@@ -104,8 +105,9 @@ var (
104
105
105
106
func setupUI () {
106
107
appleSiliconModel := getSOCInfo ()
107
- modelText = w .NewParagraph ()
108
+ modelText , helpText = w . NewParagraph (), w .NewParagraph ()
108
109
modelText .Title = "Apple Silicon"
110
+ helpText .Title = "Help Menu"
109
111
modelName , ok := appleSiliconModel ["name" ].(string )
110
112
if ! ok {
111
113
modelName = "Unknown Model"
@@ -129,41 +131,28 @@ func setupUI() {
129
131
pCoreCount ,
130
132
gpuCoreCount ,
131
133
)
134
+ helpText .Text = "- r: Refresh the UI data manually\n - l: Toggle the main display's layout\n - h: Toggle this help menu\n - ?: Toggle this help menu\n - q: Quit the application\n - <C-c>: Quit the application"
132
135
stderrLogger .Printf ("Model: %s\n E-Core Count: %d\n P-Core Count: %d\n GPU Core Count: %s" ,
133
136
modelName ,
134
137
eCoreCount ,
135
138
pCoreCount ,
136
139
gpuCoreCount ,
137
140
)
138
141
139
- cpu1Gauge = w .NewGauge ()
140
- cpu1Gauge .Title = "E-CPU Usage"
141
- cpu1Gauge .Percent = 0
142
- cpu1Gauge .BarColor = ui .ColorGreen
143
-
144
- cpu2Gauge = w .NewGauge ()
145
- cpu2Gauge .Title = "P-CPU Usage"
146
- cpu2Gauge .Percent = 0
147
- cpu2Gauge .BarColor = ui .ColorYellow
148
-
149
- gpuGauge = w .NewGauge ()
150
- gpuGauge .Title = "GPU Usage"
151
- gpuGauge .Percent = 0
152
- gpuGauge .BarColor = ui .ColorMagenta
153
-
154
- aneGauge = w .NewGauge ()
155
- aneGauge .Title = "ANE"
156
- aneGauge .Percent = 0
157
- aneGauge .BarColor = ui .ColorBlue
158
-
159
- PowerChart = w .NewParagraph ()
160
- PowerChart .Title = "Power Usage"
161
-
162
- NetworkInfo = w .NewParagraph ()
163
- NetworkInfo .Title = "Network & Disk Info"
142
+ gauges := []* w.Gauge {
143
+ w .NewGauge (), w .NewGauge (), w .NewGauge (), w .NewGauge (), w .NewGauge (),
144
+ }
145
+ titles := []string {"E-CPU Usage" , "P-CPU Usage" , "GPU Usage" , "ANE" , "Memory Usage" }
146
+ colors := []ui.Color {ui .ColorGreen , ui .ColorYellow , ui .ColorMagenta , ui .ColorBlue , ui .ColorCyan }
147
+ for i , gauge := range gauges {
148
+ gauge .Percent = 0
149
+ gauge .Title = titles [i ]
150
+ gauge .BarColor = colors [i ]
151
+ }
152
+ cpu1Gauge , cpu2Gauge , gpuGauge , aneGauge , memoryGauge = gauges [0 ], gauges [1 ], gauges [2 ], gauges [3 ], gauges [4 ]
164
153
165
- ProcessInfo = w .NewParagraph ()
166
- ProcessInfo .Title = "Process Info"
154
+ PowerChart , NetworkInfo , ProcessInfo = w . NewParagraph (), w . NewParagraph (), w .NewParagraph ()
155
+ PowerChart . Title , NetworkInfo . Title , ProcessInfo .Title = "Power Usage" , "Network & Disk Info" , "Process Info"
167
156
168
157
TotalPowerChart = w .NewBarChart ()
169
158
TotalPowerChart .Title = "~ W Total Power"
@@ -175,10 +164,6 @@ func setupUI() {
175
164
TotalPowerChart .NumFormatter = func (num float64 ) string {
176
165
return ""
177
166
}
178
- memoryGauge = w .NewGauge ()
179
- memoryGauge .Title = "Memory Usage"
180
- memoryGauge .Percent = 0
181
- memoryGauge .BarColor = ui .ColorCyan
182
167
}
183
168
184
169
func setupGrid () {
@@ -248,6 +233,31 @@ func switchGridLayout() {
248
233
}
249
234
}
250
235
236
+ func toggleHelpMenu () {
237
+ showHelp = ! showHelp
238
+ if showHelp {
239
+ newGrid := ui .NewGrid ()
240
+ newGrid .Set (
241
+ ui .NewRow (1.0 ,
242
+ ui .NewCol (1.0 , helpText ),
243
+ ),
244
+ )
245
+ termWidth , termHeight := ui .TerminalDimensions ()
246
+ helpTextGridWidth := termWidth / 3
247
+ helpTextGridHeight := termHeight / 2
248
+ x := (termWidth - helpTextGridWidth ) / 2
249
+ y := (termHeight - helpTextGridHeight ) / 2
250
+ newGrid .SetRect (x , y , x + helpTextGridWidth , y + helpTextGridHeight )
251
+ grid = newGrid
252
+ } else {
253
+ currentGridLayout = map [bool ]string {
254
+ true : "alternative" ,
255
+ false : "default" ,
256
+ }[currentGridLayout == "default" ]
257
+ switchGridLayout ()
258
+ }
259
+ }
260
+
251
261
func StderrToLogfile (logfile * os.File ) {
252
262
syscall .Dup2 (int (logfile .Fd ()), 2 )
253
263
}
@@ -431,6 +441,12 @@ func main() {
431
441
ui .Clear ()
432
442
switchGridLayout ()
433
443
ui .Render (grid )
444
+ case "h" , "?" : // "h" or "?" to open help menu
445
+ termWidth , termHeight := ui .TerminalDimensions ()
446
+ grid .SetRect (0 , 0 , termWidth , termHeight )
447
+ ui .Clear ()
448
+ toggleHelpMenu ()
449
+ ui .Render (grid )
434
450
}
435
451
case <- done :
436
452
ui .Close ()
0 commit comments