Skip to content

Commit

Permalink
Fixed colors and unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
vti committed Dec 6, 2010
1 parent ee9693c commit a5cbd3b
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions showmetheshell
Expand Up @@ -6,15 +6,15 @@ use warnings;
use FindBin;

BEGIN {
use lib 'lib';
use lib "$FindBin::Bin/contrib/protocol-websocket/lib";
use lib "$FindBin::Bin/contrib/event_reactor/lib";
use lib "$FindBin::Bin/contrib/reanimator/lib";
}

use lib 'lib';

#use constant DEBUG => !!$ENV{SHOWMETHESHELL_DEBUG};
my $ESCAPE = pack('C', 0x1B);

use Encode;
use JSON;
use ReAnimator;
use Terminal;
Expand All @@ -32,6 +32,10 @@ ReAnimator->new(
on_row_changed => sub {
my ($self, $row, $text) = @_;

$text = Encode::decode_utf8($text);

$text =~ s/$ESCAPE\[(.*?)m/&_insert_color($1)/ge;

$client->send_message(
JSON->new->encode(
{type => 'row', row => $row, text => $text}
Expand Down Expand Up @@ -75,3 +79,52 @@ ReAnimator->new(
);
}
)->listen->start;

sub _insert_color {
my $color = shift;

my %colors = (
0 => 'reset',
1 => 'bright',
2 => 'dim',
4 => 'underscore',
5 => 'blink',
7 => 'reverse',
8 => 'hidden',

# Foreground Colours
30 => 'fg-black',
31 => 'fg-red',
32 => 'fg-green',
33 => 'fg-yellow',
34 => 'fg-blue',
35 => 'fg-magenta',
36 => 'fg-cyan',
37 => 'fg-white',

# Background Colours
40 => 'bg-black',
41 => 'bg-red',
42 => 'bg-green',
43 => 'bg-yellow',
44 => 'bg-blue',
45 => 'bg-magenta',
46 => 'bg-cyan',
47 => 'bg-white',
);

my @attrs = split ';' => $color;

my $string = '';
foreach my $attr (@attrs) {
if (my $class = $colors{$attr}) {
$string .= '</span>' if $class eq 'reset';

$string .= qq/<span class="$class">/;

$string .= '</span>' if $class eq 'reset';
}
}

return $string;
}

0 comments on commit a5cbd3b

Please sign in to comment.