Mercurial > topfetch++
diff 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 |
line wrap: on
line diff
--- a/main.cpp Sun Oct 04 14:33:37 2026 -0500 +++ b/main.cpp Sun Oct 04 14:59:57 2026 -0500 @@ -189,6 +189,7 @@ std::string override; if (argc >= 3 && std::string(argv[1]) == "--logo") override = argv[2]; + const Distro distro = readDistro(); const Logo logo = pickLogo(distro, override); const std::string hostname = readHostname(); @@ -211,6 +212,18 @@ double cpuPercent = 0.0; if (totalChange > 0) cpuPercent = 100.0 * (now.busy - prev.busy) / totalChange; prev = now; + std::string cpuColor; + if (cpuPercent >= 80) { + cpuColor = "\033[31m"; + } + else if (cpuPercent >= 50) { + cpuColor = "\033[33m"; + } + else { + cpuColor = "\033[32m"; + } + + std::ostringstream uptimeLine, memLine, cpuLine; uptimeLine << "Uptime: "; @@ -230,7 +243,7 @@ } cpuLine << std::fixed << std::setprecision(1) - << "CPU: " << cpuPercent << " %"; + << "CPU: " << cpuColor << cpuPercent << " %"; std::vector<std::string> info = { "OS: " + distro.pretty,
