Skip to content

Commit

Permalink
Checking in changes prior to tagging of version 0.06. Changelog diff is:
Browse files Browse the repository at this point in the history
  • Loading branch information
kentaro committed Mar 19, 2009
1 parent 1516f67 commit af7b4cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension Term::ANSIColor::Markup

0.06 Fri Mar 21 00:19:03 2009
- removed dependency on Term::ANSIColor.

0.05 Sun Mar 2 23:37:02 2009
- renamed from Term::ANSIColor::Tag to Term::ANSIColor::Markup

Expand Down
1 change: 0 additions & 1 deletion Makefile.PL
Expand Up @@ -5,7 +5,6 @@ author 'Kentaro Kuribayashi, <kentarok@cpan.org>',
license 'MIT';
all_from 'lib/Term/ANSIColor/Markup.pm';

requires 'Term::ANSIColor';
requires 'Class::Accessor::Lvalue::Fast';
requires 'HTML::Parser';

Expand Down
11 changes: 8 additions & 3 deletions lib/Term/ANSIColor/Markup.pm
Expand Up @@ -5,7 +5,7 @@ use warnings;
use Term::ANSIColor::Markup::Parser;
use base qw(Class::Accessor::Lvalue::Fast);

our $VERSION = '0.05';
our $VERSION = '0.06';

__PACKAGE__->mk_accessors(qw(parser text));

Expand Down Expand Up @@ -58,6 +58,10 @@ Term::ANSIColor::Markup - Colorize tagged strings for screen output
Term::ANSIColor::Markup provides a simple and friendly way to colorize
screen output; You can do it using HTML-like tags.
You can use the same names for tag names as ones L<Term::ANSIColor>
provides. See the documentation of Term::ANSIColor to get to know what
names you can use.
=head1 METHODS
=head2 new ()
Expand All @@ -79,7 +83,8 @@ Creates and returns a new Term::ANSIColor::Markup object.
Parses given C<$text>. If start tag and end tag aren't correspondent
with each other, this method croaks immediately.
Note that "<" and ">" must be escaped into "&lt;" and "&gt;".
Note that "<" and ">" which are not part of tags must be escaped into
"&lt;" and "&gt;".
=back
Expand All @@ -105,7 +110,7 @@ Returns parsed text in just one way.
=head1 REPOSITORY
http://github.com/kentaro/perl-term-ansicolor-tag/tree/master
https://github.com/kentaro/perl-term-ansicolor-markup/tree
=head1 SEE ALSO
Expand Down
30 changes: 24 additions & 6 deletions lib/Term/ANSIColor/Markup/Parser.pm
Expand Up @@ -7,9 +7,28 @@ use base qw(
Class::Accessor::Lvalue::Fast
);

use Term::ANSIColor;
# copied from Term::ANSIColor
our %TAGS = (
clear => 0,
reset => 0,
bold => 1,
dark => 2,
faint => 2,
underline => 4,
underscore => 4,
blink => 5,
reverse => 7,
concealed => 8,

use constant RESET => "\e[0m";
black => 30, on_black => 40,
red => 31, on_red => 41,
green => 32, on_green => 42,
yellow => 33, on_yellow => 43,
blue => 34, on_blue => 44,
magenta => 35, on_magenta => 45,
cyan => 36, on_cyan => 46,
white => 37, on_white => 47,
);

__PACKAGE__->mk_accessors(qw(result stack));

Expand Down Expand Up @@ -42,7 +61,7 @@ sub end {
if (my $color = $self->get_escape_sequence($tagname)) {
my $top = pop @{$self->stack};
croak "Invalid end tag was found: $text" if $top ne $tagname;
$self->result .= RESET;
$self->result .= $self->get_escape_sequence('reset');
if (scalar @{$self->stack}) {
$self->result .= $self->get_escape_sequence($self->stack->[-1]);
}
Expand All @@ -55,10 +74,9 @@ sub end {
sub get_escape_sequence {
my ($self, $name) = @_;
my $escape_sequence = '';
for my $key (keys %Term::ANSIColor::ATTRIBUTES) {
for my $key (keys %TAGS) {
if (lc $name eq lc $key) {
$escape_sequence = sprintf "\e[%dm",
$Term::ANSIColor::ATTRIBUTES{$key};
$escape_sequence = sprintf "\e[%dm", $TAGS{$key};
last;
}
}
Expand Down

0 comments on commit af7b4cd

Please sign in to comment.