Skip to content

Commit e739352

Browse files
rustedustedBenBE
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 e739352

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-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)", (int*)&(settings->barType), 0, 0, BAR_METER_NUM_STYLES-1));
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: 38 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[BAR_METER_NUM_STYLES] = {
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,35 @@ 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+
if(j==nextOffset-1){
198+
RichString_setChar(&bar, startPos+nextOffset-1, currBar[extraWidth]);
199+
} else {
200+
RichString_setChar(&bar, startPos + j, currBar[0]);
201+
}
202+
}
203+
#endif
204+
else {
171205
RichString_setChar(&bar, startPos + j, '|');
172206
}
173207
}
208+
}
209+
174210
offset = nextOffset;
175211
}
176212

MeterMode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ typedef unsigned int MeterModeId;
2626
(1 << LED_METERMODE) | \
2727
0) // Avoids edits when updating
2828

29+
#define BAR_METER_NUM_STYLES 7
2930
#endif

Settings.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Released under the GNU GPLv2+, see the COPYING file
55
in the source distribution for its full text.
66
*/
77

8+
#include "MeterMode.h"
89
#include "config.h" // IWYU pragma: keep
910

1011
#include "Settings.h"
@@ -516,6 +517,13 @@ static bool Settings_read(Settings* this, const char* fileName, const Machine* h
516517
didReadMeters = true;
517518
} else if (String_eq(option[0], "hide_function_bar")) {
518519
this->hideFunctionBar = atoi(option[1]);
520+
#ifdef HAVE_LIBNCURSESW
521+
} else if (String_eq(option[0], "bar_type")) {
522+
long value = strtol(option[1], NULL, 10);
523+
if (value < 0 || value > BAR_METER_NUM_STYLES)
524+
value = 0;
525+
this->barType = (unsigned int)value;
526+
#endif
519527
#ifdef HAVE_LIBHWLOC
520528
} else if (String_eq(option[0], "topology_affinity")) {
521529
this->topologyAffinity = !!atoi(option[1]);
@@ -714,6 +722,9 @@ int Settings_write(const Settings* this, bool onCrash) {
714722
#endif
715723
printSettingInteger("delay", (int) this->delay);
716724
printSettingInteger("hide_function_bar", (int) this->hideFunctionBar);
725+
#ifdef HAVE_LIBNCURSESW
726+
printSettingInteger("bar_type", (int) this->barType);
727+
#endif
717728
#ifdef HAVE_LIBHWLOC
718729
printSettingInteger("topology_affinity", this->topologyAffinity);
719730
#endif
@@ -821,6 +832,11 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
821832
this->showMergedCommand = false;
822833
this->hideFunctionBar = 0;
823834
this->headerMargin = true;
835+
836+
#ifdef HAVE_LIBNCURSESW
837+
this->barType = 0;
838+
#endif
839+
824840
#ifdef HAVE_LIBHWLOC
825841
this->topologyAffinity = false;
826842
#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+
unsigned int barType;
111+
#endif
109112
#ifdef HAVE_LIBHWLOC
110113
bool topologyAffinity;
111114
#endif

0 commit comments

Comments
 (0)