Simplify and fix SGR sequence removal

This commit is contained in:
speedie 2023-07-04 23:10:06 +02:00
parent cc8c3e988c
commit 7492eed0cf
3 changed files with 10 additions and 6 deletions

View file

@ -89,7 +89,7 @@ void moveup(Arg *arg) {
void complete(Arg *arg) {
if (hideitem) return;
strncpy(tx.text, sel->clntext, sizeof tx.text - 1);
strncpy(tx.text, sel->text, sizeof tx.text - 1);
tx.text[sizeof tx.text - 1] = '\0';
sp.cursor = strlen(tx.text);

View file

@ -40,6 +40,7 @@ void drawhighlights(struct item *item, int x, int y, int w, int p, const char *i
int drawitemtext(struct item *item, int x, int y, int w) {
char buffer[MAXITEMLENGTH]; // buffer containing item text
char *ttext;
int leftpadding = sp.lrpad / 2; // padding
int wr, rd; // character
int fg = 7; // foreground
@ -136,6 +137,9 @@ int drawitemtext(struct item *item, int x, int y, int w) {
}
#endif
ttext = malloc(sizeof(buffer));
ttext[0] = '\0';
// parse item text
for (wr = 0, rd = 0; item->text[rd]; rd++) {
if (item->text[rd] == '' && item->text[rd + 1] == '[') {
@ -151,6 +155,8 @@ int drawitemtext(struct item *item, int x, int y, int w) {
draw_text(draw, x, y, MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga);
drawhighlights(item, x, y, MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding, leftpadding, isrtl ? fribidi_text : buffer);
strcat(ttext, buffer);
// position and width
x += MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding;
w -= MIN(w, TEXTW(buffer) - sp.lrpad) + leftpadding;
@ -264,16 +270,15 @@ int drawitemtext(struct item *item, int x, int y, int w) {
}
buffer[wr] = '\0';
strcat(ttext, buffer);
item->text = ttext; // set item text to one without SGR sequences
// now draw any non-colored text
apply_fribidi(buffer);
int r = draw_text(draw, x, y, w, sp.bh, leftpadding, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False, fgcol, bgcol, fga, bga);
if (!hidehighlight) drawhighlights(item, x, y, w, leftpadding, buffer);
// copy current buffer to item->clntext instead of item->text, this way SGR sequences aren't drawn
item->clntext = malloc(sizeof(buffer));
memcpy(item->clntext, buffer, sizeof(buffer));
if (!hidepowerline && powerlineitems && selitem) {
if (itempwlstyle == 2) {
draw_circle(draw, r, y, sp.plw, sp.bh, 1, col_menu, bgcol, alpha_menu, bga);

View file

@ -104,7 +104,6 @@ enum {
struct item {
char *text;
char *clntext;
char *image;
char *ex;
struct item *left, *right;