Skip to content

Commit

Permalink
Coloring console output
Browse files Browse the repository at this point in the history
  • Loading branch information
cho45 committed Feb 20, 2014
1 parent 67d7cb6 commit 95b7e83
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ requires 'Getopt::Long';
requires 'Plack::Loader';
requires 'Pod::Usage';
requires 'Starlet';
requires 'HTML::FromANSI::Tiny';

on 'develop' => sub {
requires 'Locale::Maketext::Extract::Plugin::Xslate', 'v0.0.2';
Expand Down
12 changes: 9 additions & 3 deletions lib/Ukigumo/Server/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ use utf8;

package Ukigumo::Server::Util;
use Text::Xslate::Util qw(html_escape mark_raw);
use HTML::FromANSI::Tiny;

my $ansi = HTML::FromANSI::Tiny->new(
auto_reverse => 1, background => 'white', foreground => 'black',
);

# 行頭に行ごとのリンクをつけるの術
sub make_line_link {
my $src = shift;
my @lines = map { html_escape($_) } split /\r?\n/, $src;

my @lines = split /\r?\n/, $src;
my $num = 1;
my $html = '';
my $html = $ansi->style_tag;
for my $line (@lines) {
$html .= qq{<a href="#L$num" id="L$num" class="line-anchor">_</a>&nbsp;<span>};
$html .= html_escape($line) . "</span>\n";
$html .= $ansi->html($line) . "</span>\n";
$num++;
}
return mark_raw($html);
Expand Down

0 comments on commit 95b7e83

Please sign in to comment.