From bfba780e112bc47a6be037393aef53a6f326c740 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 2 Jan 2024 15:56:12 +0000 Subject: [PATCH] Bug 35681: Allow for ANSI color in database updates This patch adds support for colored output in database updates. Signed-off-by: Pedro Amorim Signed-off-by: David Nind --- installer/install.pl | 22 +++++++++++++++++++ .../prog/en/modules/installer/step3.tt | 8 +++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/installer/install.pl b/installer/install.pl index 8f53d212a2..07e93371df 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -23,6 +23,7 @@ use diagnostics; use C4::InstallAuth qw( get_template_and_user ); use CGI qw ( -utf8 ); use POSIX; +use HTML::FromANSI::Tiny; use C4::Context; use C4::Output qw( output_html_with_http_headers ); @@ -413,6 +414,7 @@ elsif ( $step && $step == 3 ) { my $fh; open( $fh, "<:encoding(utf-8)", $logfilepath ) or die "Cannot open log file $logfilepath: $!"; + my @report = <$fh>; close $fh; if (@report) { @@ -449,6 +451,8 @@ elsif ( $step && $step == 3 ) { my $atomic_update_files = get_atomic_updates; my $atomic_update_report = run_atomic_updates( $atomic_update_files ); + colorize($report); + colorize($atomic_update_report); $template->param( success => $report->{success}, error => $report->{error}, @@ -550,3 +554,21 @@ sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir } return $fn; } + +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 @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); + } + } + } +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt index 3198cddd9d..92a3547659 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt @@ -367,7 +367,7 @@
    [% FOR s IN success %] [% FOR o IN s.output %] -
  • [% o | html %]
  • +
  • [% o | $raw %]
  • [% IF s.output.size > 1 %] [% IF loop.first %]
      [% ELSIF loop.last %]
    [% END %] [% END %] @@ -381,7 +381,7 @@
      [% FOR s IN atomic_updates.success %] [% FOR o IN s.output %] -
    • [% o | html %]
    • +
    • [% o | $raw %]
    • [% IF s.output.size > 1 %] [% IF loop.first %]
        [% ELSIF loop.last %]
      [% END %] [% END %] @@ -409,7 +409,7 @@
    • [% o | html %]
      - ERROR: [% e.error | html %] + ERROR: [% e.error | $raw %] [% IF e.output.size > 1 %] [% IF loop.first %]
        [% ELSIF loop.last %]
      [% END %] @@ -429,7 +429,7 @@
    • [% o | html %]
      - ERROR: [% e.error | html %] + ERROR: [% e.error | $raw %] [% IF e.output.size > 1 %] [% IF loop.first %]
        [% ELSIF loop.last %]
      [% END %] -- 2.30.2