Bug 35681: Use ::Bootstrap version of FromANSI

With the next iteration of HTML::FromANSI::Tiny we can add our own subclass
to map ANSI strings to Bootstrap classes.

This patch adds a local lib HTML::FromANSI::Tiny::Bootstrap module to
do said mapping and then uses it in the installer.

Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Martin Renvoize 2024-01-10 10:51:27 +00:00 committed by Katrin Fischer
parent 99e9c85fc0
commit 38613bbf3b
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834
2 changed files with 62 additions and 4 deletions

View file

@ -23,7 +23,7 @@ use diagnostics;
use C4::InstallAuth qw( get_template_and_user );
use CGI qw ( -utf8 );
use POSIX;
use HTML::FromANSI::Tiny;
use HTML::FromANSI::Tiny::Bootstrap;
use C4::Context;
use C4::Output qw( output_html_with_http_headers );
@ -568,14 +568,17 @@ sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir
sub colorize {
my ($report) = @_;
my $h = HTML::FromANSI::Tiny->new(
auto_reverse => 0, background => 'white', foreground => 'black',
inline_style => 1, no_plain_tags => 1
my $h = HTML::FromANSI::Tiny::Bootstrap->new(
auto_reverse => 0,
background => 'white',
foreground => 'black',
no_plain_tags => 1
);
my @states = ( 'success', 'error' );
for my $state (@states) {
for my $result ( @{ $report->{$state} } ) {
#@{ $result->{output} } = map { s/^\t+//; $h->html($_) } @{ $result->{output} };
for my $output ( @{ $result->{output} } ) {
$output = $h->html($output);

View file

@ -0,0 +1,55 @@
use strict;
use warnings;
package HTML::FromANSI::Tiny::Bootstrap;
use parent qw(HTML::FromANSI::Tiny);
=head1 NAME
HTML::FromANSI::Tiny::Bootstrap - Convert ANSI colored text to HTML with Bootstrap classes
=head1 DESCRIPTION
HTML::FromANSI::Tiny::Bootstrap is a module that extends HTML::FromANSI::Tiny to convert ANSI colored text to HTML with Bootstrap classes. It provides a mapping between ANSI color attributes and Bootstrap classes.
=cut
our %ATTR_TO_CLASS = (
black => 'text-primary',
red => 'text-danger',
green => 'text-success',
yellow => 'text-warning',
blue => 'text-info',
magenta => '',
cyan => '',
white => 'text-muted',
on_black => 'bg-primary',
on_red => 'bg-danger',
on_green => 'bg-success',
on_yellow => 'bg-warning',
on_blue => 'bg-info',
on_magenta => '',
on_cyan => '',
on_white => '',
);
=head1 METHODS
=head2 attr_to_class($attr)
Converts an ANSI color attribute to the corresponding Bootstrap class.
=cut
sub attr_to_class {
$ATTR_TO_CLASS{ $_[1] } || $_[1];
}
=head1 AUTHOR
Martin Renvoize <martin.renvoize@ptfs-europe.com>
=cut
1;