diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index 8fa347294..a569ff9eb 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -156,6 +156,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges))); Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60)); Panel_add(super, (Object*) NumberItem_newByRef("Hide main function bar (0 - off, 1 - on ESC until next input, 2 - permanently)", &(settings->hideFunctionBar), 0, 0, 2)); + Panel_add(super, (Object*) NumberItem_newByRef("Bar Type (0-7)", &(settings->barType), 0, 0, 7)); #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); #endif diff --git a/Meter.c b/Meter.c index 4463a90a0..00311a579 100644 --- a/Meter.c +++ b/Meter.c @@ -13,6 +13,7 @@ in the source distribution for its full text. #include #include #include +#include #include "CRT.h" #include "Macros.h" @@ -70,6 +71,17 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) { static const char BarMeterMode_characters[] = "|#*@$%&."; +static const wchar_t* bars[8] = { + L" ||||||||", + L" ########", + L"⠀⡀⡄⡆⡇⣇⣧⣷⣿", + L" ░░▒▒▓▓██", + L" ▏▎▍▌▋▊▉█", + L" ▁▂▃▄▅▆▇█", + L" ▌▌▌▌████", + L" ▔🮂🮃▀🮄🮅🮆█" +}; + static void BarMeterMode_draw(Meter* this, int x, int y, int w) { // Draw the caption const char* caption = Meter_getCaption(this); @@ -120,14 +132,27 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { assert(startPos <= w); assert(startPos + w <= RichString_sizeVal(bar)); + const Settings* settings = this->host->settings; int blockSizes[10]; // First draw in the bar[] buffer... int offset = 0; + const wchar_t* barChars = &bars[settings->barType][1]; + const size_t barLen = wcslen(barChars); + const uint8_t wsub = w * barLen; + for (uint8_t i = 0; i < this->curItems; i++) { double value = this->values[i]; + int actualWidth = 0; + + // ignore extremely small values + if ((value / this->total) * wsub < 0.5) { + blockSizes[i] = 0; + continue; + } if (isPositive(value) && this->total > 0.0) { value = MINIMUM(value, this->total); + actualWidth = ceil((value / this->total) * wsub); blockSizes[i] = ceil((value / this->total) * w); } else { blockSizes[i] = 0; @@ -135,15 +160,22 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { int nextOffset = offset + blockSizes[i]; // (Control against invalid values) nextOffset = CLAMP(nextOffset, 0, w); - for (int j = offset; j < nextOffset; j++) + + for (int j = offset; j < nextOffset; j++){ if (RichString_getCharVal(bar, startPos + j) == ' ') { if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { assert(i < strlen(BarMeterMode_characters)); RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]); + } else if (settings->barType) { + RichString_setChar(&bar, startPos + j, bars[settings->barType][8]); } else { RichString_setChar(&bar, startPos + j, '|'); } } + } + + RichString_setChar(&bar, startPos + nextOffset-1, barChars[actualWidth % barLen]); + offset = nextOffset; } diff --git a/Settings.h b/Settings.h index 5d17fb346..389453333 100644 --- a/Settings.h +++ b/Settings.h @@ -111,6 +111,8 @@ typedef struct Settings_ { bool changed; uint64_t lastUpdate; + + int barType; } Settings; #define Settings_cpuId(settings, cpu) ((settings)->countCPUsFromOne ? (cpu)+1 : (cpu))