Skip to content

Commit 2bdc27a

Browse files
committed
shortened code & reverted README to say under 1,000 lines of code
1 parent adf6c30 commit 2bdc27a

File tree

2 files changed

+20
-45
lines changed

2 files changed

+20
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
## Features
1515

16-
- Apple Silicon Monitor Top written in Go Lang (Around 1,000 lines of code)
16+
- Apple Silicon Monitor Top written in Go Lang (Under 1,000 lines of code)
1717
- Real-time CPU and GPU power usage display.
1818
- Detailed metrics for different CPU clusters (E-Cores and P-Cores).
1919
- Memory usage and swap information.

main.go

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ var (
105105

106106
func 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\nE-Core Count: %d\nP-Core Count: %d\nGPU 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

193169
func setupGrid() {
@@ -258,7 +234,8 @@ func switchGridLayout() {
258234
}
259235

260236
func 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

Comments
 (0)