mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
RichString_appendChr: add parameter to set attributes
Allows to set attributes when padding process fields in non-wide ncurses mode. Closes: #475
This commit is contained in:
parent
78b993dbb4
commit
5fde0e0127
2
Meter.c
2
Meter.c
@ -201,7 +201,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
|
||||
// The text in the bar is right aligned;
|
||||
// Pad with maximal spaces and then calculate needed starting position offset
|
||||
RichString_begin(bar);
|
||||
RichString_appendChr(&bar, ' ', w);
|
||||
RichString_appendChr(&bar, 0, ' ', w);
|
||||
RichString_appendWide(&bar, 0, buffer);
|
||||
int startPos = RichString_sizeVal(bar) - w;
|
||||
if (startPos > w) {
|
||||
|
@ -246,7 +246,7 @@ void Process_outputRate(RichString* str, char* buffer, size_t n, double rate, in
|
||||
|
||||
void Process_printLeftAlignedField(RichString* str, int attr, const char* content, unsigned int width) {
|
||||
int c = RichString_appendnWide(str, attr, content, MINIMUM(width, strlen(content)));
|
||||
RichString_appendChr(str, ' ', width + 1 - c);
|
||||
RichString_appendChr(str, attr, ' ', width + 1 - c);
|
||||
}
|
||||
|
||||
void Process_writeField(const Process* this, RichString* str, ProcessField field) {
|
||||
|
27
RichString.c
27
RichString.c
@ -80,6 +80,15 @@ inline void RichString_setAttrn(RichString* this, int attrs, int start, int char
|
||||
}
|
||||
}
|
||||
|
||||
void RichString_appendChr(RichString* this, int attrs, char c, int count) {
|
||||
int from = this->chlen;
|
||||
int newLen = from + count;
|
||||
RichString_setLen(this, newLen);
|
||||
for (int i = from; i < newLen; i++) {
|
||||
this->chptr[i] = (CharType) { .attr = attrs, .chars = { c, 0 } };
|
||||
}
|
||||
}
|
||||
|
||||
int RichString_findChar(const RichString* this, char c, int start) {
|
||||
const wchar_t wc = btowc(c);
|
||||
const cchar_t* ch = this->chptr + start;
|
||||
@ -115,6 +124,15 @@ void RichString_setAttrn(RichString* this, int attrs, int start, int charcount)
|
||||
}
|
||||
}
|
||||
|
||||
void RichString_appendChr(RichString* this, int attrs, char c, int count) {
|
||||
int from = this->chlen;
|
||||
int newLen = from + count;
|
||||
RichString_setLen(this, newLen);
|
||||
for (int i = from; i < newLen; i++) {
|
||||
this->chptr[i] = c | attrs;
|
||||
}
|
||||
}
|
||||
|
||||
int RichString_findChar(const RichString* this, char c, int start) {
|
||||
const chtype* ch = this->chptr + start;
|
||||
for (int i = start; i < this->chlen; i++) {
|
||||
@ -134,15 +152,6 @@ void RichString_prune(RichString* this) {
|
||||
this->chptr = this->chstr;
|
||||
}
|
||||
|
||||
void RichString_appendChr(RichString* this, char c, int count) {
|
||||
int from = this->chlen;
|
||||
int newLen = from + count;
|
||||
RichString_setLen(this, newLen);
|
||||
for (int i = from; i < newLen; i++) {
|
||||
RichString_setChar(this, i, c);
|
||||
}
|
||||
}
|
||||
|
||||
void RichString_setAttr(RichString* this, int attrs) {
|
||||
RichString_setAttrn(this, attrs, 0, this->chlen);
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ void RichString_prune(RichString* this);
|
||||
|
||||
void RichString_setAttr(RichString* this, int attrs);
|
||||
|
||||
void RichString_appendChr(RichString* this, char c, int count);
|
||||
void RichString_appendChr(RichString* this, int attrs, char c, int count);
|
||||
|
||||
int RichString_appendWide(RichString* this, int attrs, const char* data);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user