summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Göttsche <cgzones@googlemail.com>2020-12-04 16:11:21 +0100
committerBenBE <BenBE@geshi.org>2020-12-05 20:01:10 +0100
commit5f528b7455ddabc1b6c30365491704358e653798 (patch)
treed117ebe2cda4b407e854133e00a88f508e2b329c
parent641fd2c4ad81ee993c4b054d2d04075a08bc1413 (diff)
Meter: fix bar coloring without wide ncurses support
attrset() seems to not work with mvaddchnstr()
-rw-r--r--Meter.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/Meter.c b/Meter.c
index b4795499..06723745 100644
--- a/Meter.c
+++ b/Meter.c
@@ -185,19 +185,18 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
attrset(CRT_colors[BAR_BORDER]);
mvaddch(y, x, '[');
mvaddch(y, x + w, ']');
+ attrset(CRT_colors[RESET_COLOR]);
w--;
x++;
- if (w < 1) {
- attrset(CRT_colors[RESET_COLOR]);
+ if (w < 1)
return;
- }
// The text in the bar is right aligned;
// calculate needed padding and generate leading spaces
const int textLen = mbstowcs(NULL, buffer, 0);
- const int padding = MAXIMUM(w - textLen, 0);
+ const int padding = CLAMP(w - textLen, 0, w);
RichString_begin(bar);
RichString_appendChr(&bar, ' ', padding);
@@ -233,13 +232,13 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// ...then print the buffer.
offset = 0;
for (uint8_t i = 0; i < this->curItems; i++) {
- attrset(CRT_colors[Meter_attributes(this)[i]]);
+ RichString_setAttrn(&bar, CRT_colors[Meter_attributes(this)[i]], offset, offset + blockSizes[i] - 1);
RichString_printoffnVal(bar, y, x + offset, offset, blockSizes[i]);
offset += blockSizes[i];
offset = CLAMP(offset, 0, w);
}
if (offset < w) {
- attrset(CRT_colors[BAR_SHADOW]);
+ RichString_setAttrn(&bar, CRT_colors[BAR_SHADOW], offset, w - 1);
RichString_printoffnVal(bar, y, x + offset, offset, w - offset);
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy