in reply to Re^2: Handling ANSI Escape Sequences for Printing to Curses
in thread Handling ANSI Escape Sequences for Printing to Curses
my %esc2action = ( color('yellow') => sub { attron(COLOR_PAIR(1)) }, color('reset') => sub { attroff(COLOR_PAIR(1)) }, ); sub formatted_text { my ($win, $text) = @_; # tokenize text on escape sequences for my $token (split /(\e\[[^m]+?m)/, $text) { my $act = $esc2action{$token}; if ($act) { $act->(); } else { addstr($win, $token); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Handling ANSI Escape Sequences for Printing to Curses
by atancasis (Sexton) on Aug 01, 2010 at 05:14 UTC |