Meter: fix bar coloring without wide ncurses support

attrset() seems to not work with mvaddchnstr()
This commit is contained in:
Christian Göttsche 2020-12-04 16:11:21 +01:00 committed by BenBE
parent 641fd2c4ad
commit 5f528b7455
1 changed files with 5 additions and 6 deletions

11
Meter.c
View File

@ -185,19 +185,18 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
attrset(CRT_colors[BAR_BORDER]); attrset(CRT_colors[BAR_BORDER]);
mvaddch(y, x, '['); mvaddch(y, x, '[');
mvaddch(y, x + w, ']'); mvaddch(y, x + w, ']');
attrset(CRT_colors[RESET_COLOR]);
w--; w--;
x++; x++;
if (w < 1) { if (w < 1)
attrset(CRT_colors[RESET_COLOR]);
return; return;
}
// The text in the bar is right aligned; // The text in the bar is right aligned;
// calculate needed padding and generate leading spaces // calculate needed padding and generate leading spaces
const int textLen = mbstowcs(NULL, buffer, 0); 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_begin(bar);
RichString_appendChr(&bar, ' ', padding); RichString_appendChr(&bar, ' ', padding);
@ -233,13 +232,13 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
// ...then print the buffer. // ...then print the buffer.
offset = 0; offset = 0;
for (uint8_t i = 0; i < this->curItems; i++) { 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]); RichString_printoffnVal(bar, y, x + offset, offset, blockSizes[i]);
offset += blockSizes[i]; offset += blockSizes[i];
offset = CLAMP(offset, 0, w); offset = CLAMP(offset, 0, w);
} }
if (offset < 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); RichString_printoffnVal(bar, y, x + offset, offset, w - offset);
} }