mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-27 23:30:47 +01:00
Percent: clamps bar width to 0% ~ 100%
This commit is contained in:
+2
-1
@@ -22,7 +22,8 @@ Bugfixes:
|
||||
* Fixed `/boot` being hidden by default on Haiku, where it is the system volume. (Disk, Haiku)
|
||||
* Improved Snapdragon X1/X2 model name detection on Linux. (#2625, CPU, Linux)
|
||||
* Fixed the Android build failing with `GL/gl.h` not found, because the NDK ships the EGL headers that turned OpenGL detection on but not the desktop GL headers it includes. (OpenGL, Android)
|
||||
* Fixed MAC address reporting 20:00:00:00:00:00 on macOS 27. (LocalIP, Apple)
|
||||
* Fixed MAC address reporting `20:00:00:00:00:00` on macOS 27. (LocalIP, Apple)
|
||||
* Fixed assertion failure when percentage exceeds 100 (Percent)
|
||||
|
||||
Logos:
|
||||
* Added filled Artix logo (#2631)
|
||||
|
||||
@@ -88,8 +88,11 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConf
|
||||
|
||||
FFPercentageTypeFlags percentType = config.type == 0 ? options->percentType : config.type;
|
||||
|
||||
uint8_t blocksPercent = (uint8_t) (percent / 100.0 * options->barWidth + 0.5);
|
||||
assert(blocksPercent <= options->barWidth);
|
||||
uint8_t blocksPercent = 0;
|
||||
if (percent > 0) {
|
||||
double blocks = percent / 100.0 * options->barWidth + 0.5;
|
||||
blocksPercent = (uint8_t) (blocks >= options->barWidth ? options->barWidth : blocks);
|
||||
}
|
||||
|
||||
bool autoColorElapsed = ffStrbufIgnCaseEqualS(&options->barColorElapsed, "auto");
|
||||
|
||||
|
||||
@@ -180,6 +180,17 @@ int main(void) {
|
||||
VERIFY_BAR(14, config, "[ ■--------- ]");
|
||||
VERIFY_BAR(15, config, "[ ■■-------- ]");
|
||||
|
||||
// A value above 100 saturates the bar. That is reachable from real data: the load average is
|
||||
// normalized against the number of cores, so it exceeds 100% as soon as the load does.
|
||||
VERIFY_BAR(101, config, "[ ■■■■■■■■■■ ]");
|
||||
VERIFY_BAR(150, config, "[ ■■■■■■■■■■ ]");
|
||||
|
||||
// Narrowing to `uint8_t` before clamping would wrap around here and silently render 4 blocks
|
||||
VERIFY_BAR(2600, config, "[ ■■■■■■■■■■ ]");
|
||||
|
||||
// A negative value fills nothing
|
||||
VERIFY_BAR(-60, config, "[ ---------- ]");
|
||||
|
||||
options->barWidth = 4;
|
||||
VERIFY_BAR(0, config, "[ ---- ]");
|
||||
VERIFY_BAR(25, config, "[ ■--- ]");
|
||||
|
||||
Reference in New Issue
Block a user