Skip to content

Commit ecb08df

Browse files
committed
colorize_lines.pl 4.0.2: fix formatting if a color reset is present (weechat#457)
1 parent 5c0472c commit ecb08df

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

perl/colorize_lines.pl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020

2121
# history:
22+
# 4.0.2: fix formatting if a color reset is present (#457)
2223
# 4.0.1: fix display of multiline messages
2324
# 4.0: add compatibility with XDG directories (WeeChat >= 3.2)
2425
# 3.9: add compatibility with new weechat_print modifier data (WeeChat >= 2.9)
@@ -89,7 +90,7 @@
8990

9091
use strict;
9192
my $PRGNAME = "colorize_lines";
92-
my $VERSION = "4.0.1";
93+
my $VERSION = "4.0.2";
9394
my $AUTHOR = "Nils Görs <weechatter\@arcor.de>";
9495
my $LICENCE = "GPL3";
9596
my $DESCR = "Colorize users' text in chat area with their nick color, including highlights";
@@ -200,7 +201,11 @@ sub colorize_cb
200201
return $string if ($config{own_lines} eq "off") && not ($channel_color) && ( $config{alternate_color} eq "" );
201202

202203
$color = weechat::color($config{own_lines_color});
203-
$color = weechat::color("chat_nick_self") if ($config{own_lines_color} eq "");
204+
205+
# "chat_nick_self" colors are fixed (\03115) and cannot have the "keep attribute"
206+
# code set, so translate it to weechat's colors
207+
$color = weechat::color(weechat::config_string(weechat::config_get("weechat.color.chat_nick_self"))) if ($config{own_lines_color} eq "");
208+
204209
$color = $channel_color if ($channel_color) && ($config{own_lines} eq "off");
205210

206211
$color = get_alternate_color($buf_ptr,$alternate_last,$alternate_color1,$alternate_color2) if ( $config{alternate_color} ne "" ) &&
@@ -275,6 +280,19 @@ sub colorize_cb
275280
}
276281
######################################## inject colors and go!
277282

283+
# color doesn't have a "keep attribute", so replace its code to keep them
284+
# when there's a reset color code (\031\034) in the line
285+
my $keep_attr = "|";
286+
if ($color !~ /\Q$keep_attr\E/) {
287+
$color =~ s/
288+
\o{031}
289+
(?> [F*] | F@ | \*@)
290+
[*!\/_%.]?+
291+
\K
292+
(\d{2,5}+)
293+
/${keep_attr}$1/x;
294+
}
295+
278296
my $out = "";
279297
if ($action) {
280298
# remove the first color reset - after * nick

0 commit comments

Comments
 (0)