irssi icon indicating copy to clipboard operation
irssi copied to clipboard

hilight-text improperly restores previous color

Open Zannick opened this issue 11 years ago • 5 comments

The hilight algorithm inserts color control codes to turn the desired text into the hilight color. Unfortunately, in retrieving what it thinks is the previous color control code, it ignores several codes (such as ^o (15) which resets colors, similar to the control sequence ^dg which is properly handled). Thus, when in the presence of another script or a specially-formatted message (eg. from a bot that reports commits to a repo, giving different colors for username, branch, message, etc), it restores the previously used color.

ie.

^c5color^o plain Zannick should be plain becomes ^c5color^o plain ^c8Zannick^c5 should be plain where "should be plain" is colored red

Examples (where a script colors other users' nicks and irssi hilights mine): http://imgur.com/MdgxbMX,0SN8TuO

A simplistic way to fix this for ^o would be to expand the else case in strip_real_length (which is where irssi finds the last color control code) to something like

if (IS_COLOR_CODE(*str)) {
  *last_color_pos = (int)(str-start);
  *last_color_len = 1;
} else {
  [previous stuff...]
}

though this will still be wrong in the general case, since some of the control characters (eg. ^b ^f ^g ^v ^7) are toggles (and they do not remove the color from the hilight, either).

I'd suggest something more complicated where the toggles are tracked, and then hilight-text adds a ^o followed by the appropriate control characters: ^bbold Zannick still bold -> ^bbold ^c8Zannick^o^b still bold

(On the other hand, I fixed this for myself simply by adding a case to handle specifically ^o.)

Zannick avatar Jul 13 '14 00:07 Zannick

Is #31 related?

incognico avatar Jul 14 '14 06:07 incognico

Looks very similar, yeah. Without knowledge of the color codes being used there, I can't say what's going on, but this bug probably factors into it.

Zannick avatar Jul 14 '14 06:07 Zannick

(original report by Zannick @ FS#911)

ailin-nemui avatar Jul 14 '14 14:07 ailin-nemui

Within scripts, is there a way to get the current color codes? It would be useful to get the current color codes, make the color/style changes, and then restore the color codes (cc @kot0dama).

hloeung avatar Dec 02 '22 05:12 hloeung

Within scripts, is there a way to get the current color codes? It would be useful to get the current color codes, make the color/style changes, and then restore the color codes (cc @kot0dama).

I think there would be a way with gui print text signal, I'm close to being able to apply foreground and background color after a color change we do in the script. But then I'm not sure how to use $fg and $bg values in such a callback.

kot0dama avatar Dec 02 '22 15:12 kot0dama