Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Add color support for display_format pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Mar 9, 2016
1 parent fbfad3b commit 9cda45e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"POSIX" : "0",
"Path::Tiny" : "0",
"String::ShellQuote" : "0",
"Term::ANSIColor" : "1.04",
"Time::Local" : "1.2100",
"perl" : "v5.14.0",
"strict" : "0",
Expand Down
2 changes: 2 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ my %WriteMakefileArgs = (
"POSIX" => 0,
"Path::Tiny" => 0,
"String::ShellQuote" => 0,
"Term::ANSIColor" => "1.04",
"Time::Local" => "1.2100",
"strict" => 0,
"warnings" => 0
Expand Down Expand Up @@ -77,6 +78,7 @@ my %FallbackPrereqs = (
"POSIX" => 0,
"Path::Tiny" => 0,
"String::ShellQuote" => 0,
"Term::ANSIColor" => "1.04",
"Test::More" => 0,
"Test::Output" => 0,
"Time::Local" => "1.2100",
Expand Down
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,4 @@ allow_dirty = lib/App/txtnix.pm
[ Prereqs ]
Mojolicious = 6.54
Time::Local = 1.2100
Term::ANSIColor = 1.04
20 changes: 19 additions & 1 deletion lib/App/txtnix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ has until => sub { Mojo::Date->new() };
has ca_file => sub { '/etc/ssl/certs/ca-certificates.crt' };
has show_new => sub { 0 };
has last_timeline => sub { 0 };
has use_colors => sub { 0 };
has colors => sub {
{
nick => 'red',
time => 'green',
mention => 'white on_magenta',
};
};

has [
qw( twturl pre_tweet_hook post_tweet_hook config force registry key_file cert_file )
Expand Down Expand Up @@ -87,6 +95,9 @@ sub new {
if ( $config->{following} ) {
$args->{following} = $config->{following};
}
if ( $config->{colors} ) {
$args->{colors} = $config->{colors};
}
}
for my $path (qw(twtfile cache_dir)) {
$args->{$path} = path( $args->{$path} ) if exists $args->{$path};
Expand Down Expand Up @@ -389,12 +400,17 @@ sub display_tweets {
Mojo::Template->new( vars => 1, encoding => 'UTF-8' )->parse($template);
for my $tweet (@tweets) {

if ( !$self->use_colors ) {
$ENV{ANSI_COLORS_DISABLED} = 0;
}

print {$fh} b(
$mt->process(
{
nick => $tweet->source->nick,
content => $self->collapse_mentions( $tweet->text || '' ),
time => $tweet->strftime( $self->time_format ),
color => $self->colors,
}
)
)->encode;
Expand Down Expand Up @@ -462,7 +478,9 @@ sub expand_mention {
__DATA__
@@ pretty.txt
* <%= $nick %> (<%= $time %>):
% use Term::ANSIColor;
* <%= colored($nick, $color->{nick}) %> (<%= colored($time, $color->{time}) %>):
% $content =~ s/(@\w+)/colored($1, $color->{mention})/ge;
%= $content . "\n"
@@ simple.txt
Expand Down

0 comments on commit 9cda45e

Please sign in to comment.