| | 298 | |
| | 299 | =item highlight_perl6_ansi |
| | 300 | |
| | 301 | This is same as C<highlight_perl6_full> when --ansi-text is used. |
| | 302 | No more javascript tree viewer or anything fancy. |
| | 303 | Only nodes that have a color are printed. Not optimal but works ;-) |
| | 304 | =cut |
| | 305 | sub highlight_perl6_ansi { |
| | 306 | my $str = ""; |
| | 307 | my %colors = (); |
| | 308 | |
| | 309 | my $ANSI = "STD_syntax_highlight.ansi"; |
| | 310 | open ANSI_FILE, $ANSI |
| | 311 | or die "Could not open $ANSI: $OS_ERROR\n"; |
| | 312 | my $line; |
| | 313 | while($line = <ANSI_FILE>) { |
| | 314 | if($line =~ /^(\w+)=(.+)$/) { |
| | 315 | $colors{$1} = $2; |
| | 316 | } |
| | 317 | } |
| | 318 | close ANSI_FILE; |
| | 319 | |
| | 320 | local *spit_ansi_text = sub { |
| | 321 | my ($i, $buffer, $rule, $tree) = @ARG; |
| | 322 | if($rule) { |
| | 323 | my $color = $colors{$rule}; |
| | 324 | $str .= (color $color) . $buffer. (color 'reset'); |
| | 325 | } else { |
| | 326 | $str .= $buffer; |
| | 327 | } |
| | 328 | }; |
| | 329 | |
| | 330 | redspans_traverse(\&spit_ansi_text,%colors); |
| | 331 | |
| | 332 | $str; |
| | 333 | } |
| | 334 | |
| 346 | | =item highlight_perl6_ansi |
| 347 | | |
| 348 | | This is same as C<highlight_perl6_full> when --ansi-text is used. |
| 349 | | No more javascript tree viewer or anything fancy. |
| 350 | | Only nodes that have a color are printed. Not optimal but works ;-) |
| 351 | | =cut |
| 352 | | sub highlight_perl6_ansi { |
| 353 | | my $str = ""; |
| 354 | | my %colors = (); |
| 355 | | |
| 356 | | my $ANSI = "STD_syntax_highlight.ansi"; |
| 357 | | open ANSI_FILE, $ANSI |
| 358 | | or die "Could not open $ANSI: $OS_ERROR\n"; |
| 359 | | my $line; |
| 360 | | while($line = <ANSI_FILE>) { |
| 361 | | if($line =~ /^(\w+)=(.+)$/) { |
| 362 | | $colors{$1} = $2; |
| 363 | | } |
| 364 | | } |
| 365 | | close ANSI_FILE; |
| 366 | | |
| 367 | | local *spit_ansi_text = sub { |
| 368 | | my ($i, $buffer, $rule, $tree) = @ARG; |
| 369 | | if($rule) { |
| 370 | | my $color = $colors{$rule}; |
| 371 | | $str .= (color $color) . $buffer. (color 'reset'); |
| 372 | | } else { |
| 373 | | $str .= $buffer; |
| 374 | | } |
| 375 | | }; |
| 376 | | |
| 377 | | redspans_traverse(\&spit_ansi_text,%colors); |
| 378 | | |
| 379 | | $str; |
| 380 | | } |
| 381 | | |