@@ -105,9 +105,8 @@ var (
105105
106106func setupUI () {
107107 appleSiliconModel := getSOCInfo ()
108- modelText = w .NewParagraph ()
108+ modelText , helpText = w . NewParagraph (), w .NewParagraph ()
109109 modelText .Title = "Apple Silicon"
110- helpText = w .NewParagraph ()
111110 helpText .Title = "Help Menu"
112111 modelName , ok := appleSiliconModel ["name" ].(string )
113112 if ! ok {
@@ -132,47 +131,28 @@ func setupUI() {
132131 pCoreCount ,
133132 gpuCoreCount ,
134133 )
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"
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"
141135 stderrLogger .Printf ("Model: %s\n E-Core Count: %d\n P-Core Count: %d\n GPU Core Count: %s" ,
142136 modelName ,
143137 eCoreCount ,
144138 pCoreCount ,
145139 gpuCoreCount ,
146140 )
147141
148- cpu1Gauge = w .NewGauge ()
149- cpu1Gauge .Title = "E-CPU Usage"
150- cpu1Gauge .Percent = 0
151- cpu1Gauge .BarColor = ui .ColorGreen
152-
153- cpu2Gauge = w .NewGauge ()
154- cpu2Gauge .Title = "P-CPU Usage"
155- cpu2Gauge .Percent = 0
156- cpu2Gauge .BarColor = ui .ColorYellow
157-
158- gpuGauge = w .NewGauge ()
159- gpuGauge .Title = "GPU Usage"
160- gpuGauge .Percent = 0
161- gpuGauge .BarColor = ui .ColorMagenta
162-
163- aneGauge = w .NewGauge ()
164- aneGauge .Title = "ANE"
165- aneGauge .Percent = 0
166- aneGauge .BarColor = ui .ColorBlue
167-
168- PowerChart = w .NewParagraph ()
169- PowerChart .Title = "Power Usage"
170-
171- NetworkInfo = w .NewParagraph ()
172- 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 ]
173153
174- ProcessInfo = w .NewParagraph ()
175- 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"
176156
177157 TotalPowerChart = w .NewBarChart ()
178158 TotalPowerChart .Title = "~ W Total Power"
@@ -184,10 +164,6 @@ func setupUI() {
184164 TotalPowerChart .NumFormatter = func (num float64 ) string {
185165 return ""
186166 }
187- memoryGauge = w .NewGauge ()
188- memoryGauge .Title = "Memory Usage"
189- memoryGauge .Percent = 0
190- memoryGauge .BarColor = ui .ColorCyan
191167}
192168
193169func setupGrid () {
@@ -258,7 +234,8 @@ func switchGridLayout() {
258234}
259235
260236func toggleHelpMenu () {
261- if ! showHelp {
237+ showHelp = ! showHelp
238+ if showHelp {
262239 newGrid := ui .NewGrid ()
263240 newGrid .Set (
264241 ui .NewRow (1.0 ,
@@ -270,16 +247,14 @@ func toggleHelpMenu() {
270247 helpTextGridHeight := termHeight / 2
271248 x := (termWidth - helpTextGridWidth ) / 2
272249 y := (termHeight - helpTextGridHeight ) / 2
273- newGrid .SetRect (x , y , x + helpTextGridWidth , y + helpTextGridHeight )
250+ newGrid .SetRect (x , y , x + helpTextGridWidth , y + helpTextGridHeight )
274251 grid = newGrid
275- showHelp = ! showHelp
276252 } else {
277253 currentGridLayout = map [bool ]string {
278- true : "alternative" ,
254+ true : "alternative" ,
279255 false : "default" ,
280256 }[currentGridLayout == "default" ]
281257 switchGridLayout ()
282- showHelp = ! showHelp
283258 }
284259}
285260
0 commit comments