Mercurial > topfetch++
comparison main.cpp @ 3:f7c837561bfa default tip
color CPU by load
| author | Yasuri <yasuri@charliesmp.net> |
|---|---|
| date | Sun, 04 Oct 2026 14:59:57 -0500 |
| parents | 841975e638f2 |
| children |
comparison
equal
deleted
inserted
replaced
| 2:4034cee64a58 | 3:f7c837561bfa |
|---|---|
| 187 | 187 |
| 188 int main(int argc, char** argv) { | 188 int main(int argc, char** argv) { |
| 189 std::string override; | 189 std::string override; |
| 190 if (argc >= 3 && std::string(argv[1]) == "--logo") override = argv[2]; | 190 if (argc >= 3 && std::string(argv[1]) == "--logo") override = argv[2]; |
| 191 | 191 |
| 192 | |
| 192 const Distro distro = readDistro(); | 193 const Distro distro = readDistro(); |
| 193 const Logo logo = pickLogo(distro, override); | 194 const Logo logo = pickLogo(distro, override); |
| 194 const std::string hostname = readHostname(); | 195 const std::string hostname = readHostname(); |
| 195 const std::string kernver = readVersion(); | 196 const std::string kernver = readVersion(); |
| 196 | 197 |
| 209 | 210 |
| 210 long totalChange = now.total - prev.total; | 211 long totalChange = now.total - prev.total; |
| 211 double cpuPercent = 0.0; | 212 double cpuPercent = 0.0; |
| 212 if (totalChange > 0) cpuPercent = 100.0 * (now.busy - prev.busy) / totalChange; | 213 if (totalChange > 0) cpuPercent = 100.0 * (now.busy - prev.busy) / totalChange; |
| 213 prev = now; | 214 prev = now; |
| 215 std::string cpuColor; | |
| 216 if (cpuPercent >= 80) { | |
| 217 cpuColor = "\033[31m"; | |
| 218 } | |
| 219 else if (cpuPercent >= 50) { | |
| 220 cpuColor = "\033[33m"; | |
| 221 } | |
| 222 else { | |
| 223 cpuColor = "\033[32m"; | |
| 224 } | |
| 225 | |
| 226 | |
| 214 | 227 |
| 215 std::ostringstream uptimeLine, memLine, cpuLine; | 228 std::ostringstream uptimeLine, memLine, cpuLine; |
| 216 uptimeLine << "Uptime: "; | 229 uptimeLine << "Uptime: "; |
| 217 if (up < 0) { | 230 if (up < 0) { |
| 218 uptimeLine << "Unknown"; | 231 uptimeLine << "Unknown"; |
| 228 memLine << (m.total - m.available) / kbToGb << " GB / " | 241 memLine << (m.total - m.available) / kbToGb << " GB / " |
| 229 << m.total / kbToGb << " GB"; | 242 << m.total / kbToGb << " GB"; |
| 230 } | 243 } |
| 231 | 244 |
| 232 cpuLine << std::fixed << std::setprecision(1) | 245 cpuLine << std::fixed << std::setprecision(1) |
| 233 << "CPU: " << cpuPercent << " %"; | 246 << "CPU: " << cpuColor << cpuPercent << " %"; |
| 234 | 247 |
| 235 std::vector<std::string> info = { | 248 std::vector<std::string> info = { |
| 236 "OS: " + distro.pretty, | 249 "OS: " + distro.pretty, |
| 237 "Hostname: " + hostname, | 250 "Hostname: " + hostname, |
| 238 "Kernel: " + kernver, | 251 "Kernel: " + kernver, |
