Skip to content

Commit 39d372a

Browse files
alphapradsBenBE
authored andcommitted
Implement different display types for bar meters
Allow bar meters to enable "sub-pixel" rendering. Bar meter styles can be changed in setup (F2) under Display Options. Co-Authored-By: Benny Baumann <[email protected]>
1 parent d698e87 commit 39d372a

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

DisplayOptionsPanel.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
203203
Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
204204
Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60));
205205
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));
206+
207+
#ifdef HAVE_LIBNCURSESW
208+
if(CRT_utf8)
209+
Panel_add(super, (Object*) NumberItem_newByRef("Bar Type (0 - default)", &(settings->barType), 0, 0, 6));
210+
#endif
211+
206212
#ifdef HAVE_LIBHWLOC
207213
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
208214
#endif

Meter.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
8686

8787
static const char BarMeterMode_characters[] = "|#*@$%&.";
8888

89+
#ifdef HAVE_LIBNCURSESW
90+
const wchar_t* bars[8] = {
91+
L"|",
92+
L"#",
93+
L"⣿⡀⡄⡆⡇⣇⣧⣷",
94+
L"█░░▒▒▓▓█",
95+
L"█▏▎▍▌▋▊▉",
96+
L"█▁▂▃▄▅▆▇",
97+
L"█▌▌▌▌███",
98+
};
99+
#endif
100+
89101
static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
90102
assert(x >= 0);
91103
assert(w <= INT_MAX - x);
@@ -149,6 +161,14 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
149161
assert(startPos + w <= RichString_sizeVal(bar));
150162

151163
int blockSizes[10];
164+
#ifdef HAVE_LIBNCURSESW
165+
Settings* settings = this->host->settings;
166+
assert(settings->barType < ( sizeof(bars) / sizeof(wchar_t*) ));
167+
assert(settings->barType >= 0);
168+
const wchar_t* currBar = bars[settings->barType];
169+
int barLen = (int)wcslen(currBar);
170+
int extraWidth = 0;
171+
#endif
152172

153173
// First draw in the bar[] buffer...
154174
int offset = 0;
@@ -158,19 +178,36 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
158178
value = MINIMUM(value, this->total);
159179
blockSizes[i] = ceil((value / this->total) * w);
160180
blockSizes[i] = MINIMUM(blockSizes[i], w - offset);
181+
182+
#ifdef HAVE_LIBNCURSESW
183+
extraWidth = (int)ceil((value / this->total) * w * barLen) % barLen;
184+
#endif
161185
} else {
162186
blockSizes[i] = 0;
163187
}
164188
int nextOffset = offset + blockSizes[i];
165-
for (int j = offset; j < nextOffset; j++)
189+
for (int j = offset; j < nextOffset; j++) {
166190
if (RichString_getCharVal(bar, startPos + j) == ' ') {
167191
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
168192
assert(i < strlen(BarMeterMode_characters));
169193
RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]);
170-
} else {
194+
}
195+
#ifdef HAVE_LIBNCURSESW
196+
else if(CRT_utf8 && settings->barType) {
197+
RichString_setChar(&bar, startPos + j, currBar[0]);
198+
}
199+
#endif
200+
else {
171201
RichString_setChar(&bar, startPos + j, '|');
172202
}
173203
}
204+
}
205+
#ifdef HAVE_LIBNCURSESW
206+
if(CRT_utf8 && offset != nextOffset && CRT_colorScheme != COLORSCHEME_MONOCHROME){
207+
RichString_setChar(&bar, startPos+nextOffset-1, currBar[extraWidth]);
208+
}
209+
#endif
210+
174211
offset = nextOffset;
175212
}
176213

Settings.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ static bool Settings_read(Settings* this, const char* fileName, const Machine* h
516516
didReadMeters = true;
517517
} else if (String_eq(option[0], "hide_function_bar")) {
518518
this->hideFunctionBar = atoi(option[1]);
519+
#ifdef HAVE_LIBNCURSESW
520+
} else if (String_eq(option[0], "bar_type")) {
521+
// this->barType = min(BARS_LENGTH, max(0,atoi(option[1])));
522+
this->barType = atoi(option[1]);
523+
#endif
519524
#ifdef HAVE_LIBHWLOC
520525
} else if (String_eq(option[0], "topology_affinity")) {
521526
this->topologyAffinity = !!atoi(option[1]);
@@ -714,6 +719,9 @@ int Settings_write(const Settings* this, bool onCrash) {
714719
#endif
715720
printSettingInteger("delay", (int) this->delay);
716721
printSettingInteger("hide_function_bar", (int) this->hideFunctionBar);
722+
#ifdef HAVE_LIBNCURSESW
723+
printSettingInteger("bar_type", (int) this->barType);
724+
#endif
717725
#ifdef HAVE_LIBHWLOC
718726
printSettingInteger("topology_affinity", this->topologyAffinity);
719727
#endif
@@ -821,6 +829,11 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
821829
this->showMergedCommand = false;
822830
this->hideFunctionBar = 0;
823831
this->headerMargin = true;
832+
833+
#ifdef HAVE_LIBNCURSESW
834+
this->barType = 0;
835+
#endif
836+
824837
#ifdef HAVE_LIBHWLOC
825838
this->topologyAffinity = false;
826839
#endif

Settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ typedef struct Settings_ {
106106
bool enableMouse;
107107
#endif
108108
int hideFunctionBar; // 0 - off, 1 - on ESC until next input, 2 - permanently
109+
#ifdef HAVE_LIBNCURSESW
110+
int barType;
111+
#endif
109112
#ifdef HAVE_LIBHWLOC
110113
bool topologyAffinity;
111114
#endif

0 commit comments

Comments
 (0)