@@ -78,16 +78,17 @@ func (e *EventThrottler) Notify() {
7878}
7979
8080var (
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
9394var (
@@ -104,8 +105,9 @@ var (
104105
105106func setupUI () {
106107 appleSiliconModel := getSOCInfo ()
107- modelText = w .NewParagraph ()
108+ modelText , helpText = w . NewParagraph (), w .NewParagraph ()
108109 modelText .Title = "Apple Silicon"
110+ helpText .Title = "Help Menu"
109111 modelName , ok := appleSiliconModel ["name" ].(string )
110112 if ! ok {
111113 modelName = "Unknown Model"
@@ -129,41 +131,28 @@ func setupUI() {
129131 pCoreCount ,
130132 gpuCoreCount ,
131133 )
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"
132135 stderrLogger .Printf ("Model: %s\n E-Core Count: %d\n P-Core Count: %d\n GPU Core Count: %s" ,
133136 modelName ,
134137 eCoreCount ,
135138 pCoreCount ,
136139 gpuCoreCount ,
137140 )
138141
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 ]
164153
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"
167156
168157 TotalPowerChart = w .NewBarChart ()
169158 TotalPowerChart .Title = "~ W Total Power"
@@ -175,10 +164,6 @@ func setupUI() {
175164 TotalPowerChart .NumFormatter = func (num float64 ) string {
176165 return ""
177166 }
178- memoryGauge = w .NewGauge ()
179- memoryGauge .Title = "Memory Usage"
180- memoryGauge .Percent = 0
181- memoryGauge .BarColor = ui .ColorCyan
182167}
183168
184169func setupGrid () {
@@ -248,6 +233,31 @@ func switchGridLayout() {
248233 }
249234}
250235
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+
251261func StderrToLogfile (logfile * os.File ) {
252262 syscall .Dup2 (int (logfile .Fd ()), 2 )
253263}
@@ -431,6 +441,12 @@ func main() {
431441 ui .Clear ()
432442 switchGridLayout ()
433443 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 )
434450 }
435451 case <- done :
436452 ui .Close ()
0 commit comments