# I'm probably trashing this for now since kretch is implimenting
# colorizing as filters.  It's still here if I ever need it though

sub owl::set_color($$$;$$) {
    my ($fg, $bg, $class, $instance, $recipient) = @_;
    my %color_hash;
    $color_hash{foreground} = $fg if $fg;
    $color_hash{background} = $bg if $bg;
    $color_hash{class} = $class if $class;
    $color_hash{instance} = $instance if $instance;
    $color_hash{recipient} = $recipient if $recipient;
    push @owl::color_list, \%color_hash;
}

sub owl::colorize($) {
    my ($text) = @_;
    my $regexp;
    foreach my $color_hash (@owl::color_list) {
        if ((!($regexp = $color_hash->{class}) ||
             $owl::class =~ m/$regexp/) &&
            (!($regexp = $color_hash->{instance}) ||
             $owl::instance =~ m/$regexp/) &&
            (!($regexp = $color_hash->{recipient}) ||
             $owl::recipient =~ m/$regexp/))
        {
            $text = '@color('. $color_hash->{foreground} .")$text"
                if $color_hash->{foreground};
            $text = '@bgcolor('. $color_hash->{background} .")$text"
                if $color_hash->{background};
            return $text;
        }
    }
    return $text;
}

sub owl::clear_color_settings() {
    @owl::color_list = ();
}

# Example of how I was using the package:
#  sub owl::load_colors() {
#    owl::clear_color_settings();
#    owl::set_color('green', 0, '^sipb');
#  }
#  owl::load_colors();

1;
