#!/usr/bin/perl
our $VERSION = '0.054';
use strict;

use Syntax::Highlight::Engine::Kate;
use Term::ExtendedColor qw(:attributes);
use Getopt::Long qw(GetOptions);
use Pod::Usage qw(pod2usage);

my $language = 'perl';
GetOptions(
  'l|language:s' => \$language,
  'h|help'       => sub { pod2usage(verbose => 1)   and exit 0; },
  'm|man'        => sub { pod2usage(verbose => 3)   and exit 0; },
  'v|version'    => sub { print "skate v$VERSION\n" and exit 0; },
);


my $hl = new Syntax::Highlight::Engine::Kate(
  language      => ucfirst(lc($language)),

  substitutions => {
    '.'   => bold('.'),
    ','   => bold(','),
    '?'   => bold('?'),
    '!'   => fg('red1', bold('!')),
    '('   => fg(250, bold('(')),
    ')'   => fg(250, bold(')')),
    '='   => bold('='),
    '>'   => bold('>'),
    '<'   => bold('<'),
  },

  format_table  => {
      Alert        => [ fg(148), clear() ],
      BaseN        => [ fg(196), clear() ],
      BString      => [ fg(100), clear() ],
      Char         => [ fg(111), clear() ],
      Comment      => [ fg(137). italic(), clear() ],
      DataType     => [ fg(148), clear() ],
      DecVal       => [ fg(240), clear() ],
      Error        => [ fg(160), clear() ],
      Float        => [ fg(135). bold(), clear() ],
      Function     => [ fg(202), clear() ],
      IString      => [ fg(179), clear() ],
      Keyword      => [ fg(244). bold(), clear() ],
      Normal       => [      "", ""      ],
      Operator     => [ fg(148), clear() ],
      Others       => [ fg(225), clear() ],
      RegionMarker => [ fg(246), clear() ],
      Reserved     => [ fg(178), clear() ],
      String       => [ fg(143), clear() ],
      Variable     => [ fg(148), clear() ],
      Warning      => [ fg(160), clear() ],
  },
);

my($file, $fh) = (shift, undef);

if( (!defined($file)) or ($file eq '-') ) {
  $fh = \*STDIN;
}
else {
  open($fh, '<', $file) or die("Cannot open '$file': $!\n");
}

while(my $line = <$fh>) {
  print $hl->highlightText($line);
};


__END__


=pod

=head1 NAME

skate - cat with Kate syntax highlighting

=head1 USAGE

  skate [OPTION]... [FILE]...

=head1 DESCRIPTION

B<skate> uses the syntax definitions from the Kate editor and extended colors to
view source code in proper color in the terminal.

=head1 OPTIONS

  -l,   --language    language definition

  -h,   --help        show the help and exit
  -v,   --version     show version info and exit
  -m,   --man         show the manual and exit

=head1 PREREQUISITIES

The L<Term::ExtendedColor> and L<Syntax::Highlight::Engine::Kate> Perl modules.

A terminal that support 256 colors.

Code to skate!

=head1 REPORTING BUGS

Report bugs and/or feature requests on rt.cpan.org, the repository issue tracker
or directly to L<magnus@trapd00r.se>

=head1 AUTHOR

  Magnus Woldrich
  CPAN ID: WOLDRICH
  magnus@trapd00r.se
  http://japh.se

=head1 CONTRIBUTORS

None required yet.

=head1 COPYRIGHT

Copyright 2011 B<THIS APPLICATION>s L</AUTHOR> and L</CONTRIBUTORS> as listed
above.

=head1 LICENSE

This program is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.

=head1 SEE ALSO

L<Syntax::Highlight::Engine::Kate>, L<Term::ExtendedColor>

=cut

# vim: set ts=2 et sw=2:
