Skip to content

Commit 584ccc7

Browse files
alphapradsBenBE
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 <BenBE@geshi.org>
1 parent d698e87 commit 584ccc7

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

DisplayOptionsPanel.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ 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+
Panel_add(super, (Object*) NumberItem_newByRef("Bar Type (0-6)", &(settings->barType), 0, 0, 6));
209+
#endif
210+
206211
#ifdef HAVE_LIBHWLOC
207212
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
208213
#endif

Meter.c

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ in the source distribution for its full text.
1313
#include <float.h>
1414
#include <limits.h> // IWYU pragma: keep
1515
#include <math.h>
16+
#include <stdio.h>
1617
#include <stdlib.h>
1718
#include <string.h>
19+
#include <wchar.h>
1820

1921
#include "CRT.h"
2022
#include "Macros.h"
@@ -86,6 +88,18 @@ static void TextMeterMode_draw(Meter* this, int x, int y, int w) {
8688

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

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

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

153175
// First draw in the bar[] buffer...
154176
int offset = 0;
@@ -158,19 +180,37 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
158180
value = MINIMUM(value, this->total);
159181
blockSizes[i] = ceil((value / this->total) * w);
160182
blockSizes[i] = MINIMUM(blockSizes[i], w - offset);
183+
184+
#ifdef HAVE_LIBNCURSESW
185+
extraWidth = (int)ceil((value / this->total) * w * barLen) % barLen;
186+
#endif
161187
} else {
162188
blockSizes[i] = 0;
163189
}
164190
int nextOffset = offset + blockSizes[i];
165-
for (int j = offset; j < nextOffset; j++)
191+
for (int j = offset; j < nextOffset; j++) {
166192
if (RichString_getCharVal(bar, startPos + j) == ' ') {
167193
if (CRT_colorScheme == COLORSCHEME_MONOCHROME) {
168194
assert(i < strlen(BarMeterMode_characters));
169195
RichString_setChar(&bar, startPos + j, BarMeterMode_characters[i]);
170-
} else {
196+
}
197+
#ifdef HAVE_LIBNCURSESW
198+
else if(CRT_utf8 && settings->barType) {
199+
RichString_setChar(&bar, startPos + j, currBar[0]);
200+
dprintf(10, "libncurses: %d\n", HAVE_LIBNCURSESW);
201+
}
202+
#endif
203+
else {
171204
RichString_setChar(&bar, startPos + j, '|');
172205
}
173206
}
207+
}
208+
#ifdef HAVE_LIBNCURSESW
209+
if(CRT_utf8 && offset != nextOffset && CRT_colorScheme != COLORSCHEME_MONOCHROME){
210+
RichString_setChar(&bar, startPos+nextOffset-1, currBar[extraWidth]);
211+
}
212+
#endif
213+
174214
offset = nextOffset;
175215
}
176216

Settings.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,10 @@ 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 = atoi(option[1]);
522+
#endif
519523
#ifdef HAVE_LIBHWLOC
520524
} else if (String_eq(option[0], "topology_affinity")) {
521525
this->topologyAffinity = !!atoi(option[1]);
@@ -714,6 +718,9 @@ int Settings_write(const Settings* this, bool onCrash) {
714718
#endif
715719
printSettingInteger("delay", (int) this->delay);
716720
printSettingInteger("hide_function_bar", (int) this->hideFunctionBar);
721+
#ifdef HAVE_LIBNCURSESW
722+
printSettingInteger("bar_type", (int) this->barType);
723+
#endif
717724
#ifdef HAVE_LIBHWLOC
718725
printSettingInteger("topology_affinity", this->topologyAffinity);
719726
#endif
@@ -821,6 +828,10 @@ Settings* Settings_new(const Machine* host, Hashtable* dynamicMeters, Hashtable*
821828
this->showMergedCommand = false;
822829
this->hideFunctionBar = 0;
823830
this->headerMargin = true;
831+
832+
#ifdef HAVE_LIBNCURSESW
833+
this->barType = 0;
834+
#endif
824835
#ifdef HAVE_LIBHWLOC
825836
this->topologyAffinity = false;
826837
#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)