use strict;
use warnings;
use experimental 'signatures';

our $VERSION = '0.1'; # e45306dc728cce6
our %IRSSI = (
    authors     => 'Nei',
    contact     => 'Nei @ anti@conference.jabber.teamidiot.de',
    url         => "http://anti.teamidiot.de/",
    name        => 'monospace',
    description => 'Remove the monospace formatting character inverted-Q.',
    license     => 'ISC',
   );
die "This script requires Irssi 1.4 or later"
    if (Irssi::parse_special('$abiversion')||0) < 37;

Irssi::settings_add_str('lookandfeel', 'monospace_color', '%#');

my $mono;
my $reset;
my $reset2;

sub reread {
    my $setting = Irssi::settings_get_str('monospace_color');
    $mono = Irssi::format_string_expand($setting);
    $reset2 = Irssi::format_string_expand('%n');
    if ($setting =~ /^%[FU89_I#]$/ || $setting !~ /%/) {
	$reset = $mono;
    } else {
	$reset = $reset2;
	$reset2 = '';
    }
}

reread();

Irssi::signal_add 'setup changed' => 'reread';

Irssi::signal_add 'gui render line text'
    => sub ($dest, $str, $meta) {
	$$str =~ s/\cQ(.*?)(\cQ|\cO|$)/$mono$1$reset${ $2 eq "\cO" ? \$reset2 : \'' }/g;
    }
;
