| 1 | package Acme::Matrix::Cmd; | ||
| 2 | |||
| 3 | use Rope::Cmd; | ||
| 4 | use Coerce::Types::Standard qw/Int Bool JSON/; | ||
| 5 | use Acme::Matrix; | ||
| 6 | use Ascii::Text; | ||
| 7 | |||
| 8 | colors ( | ||
| 9 | title => 'bright_green', | ||
| 10 | abstract => 'green', | ||
| 11 | options_title => 'bright_green', | ||
| 12 | options => 'bright_green', | ||
| 13 | options_description => 'green' | ||
| 14 | ); | ||
| 15 | |||
| 16 | title(Ascii::Text->new(font => 'Boomer', align => 'center')->stringify('MATRIX', 1)); | ||
| 17 | |||
| 18 | abstract('script for generating heavenly digital rain'); | ||
| 19 | |||
| 20 | option delay => ( | ||
| 21 | type => Int, | ||
| 22 | description => 'delay to render a line in ms', | ||
| 23 | option_alias => 'd', | ||
| 24 | value => 10 | ||
| 25 | ); | ||
| 26 | |||
| 27 | option spacing => ( | ||
| 28 | type => Int, | ||
| 29 | description => 'spacing between characters', | ||
| 30 | option_alias => 's', | ||
| 31 | value => 2 | ||
| 32 | ); | ||
| 33 | |||
| 34 | option words => ( | ||
| 35 | type => JSON->by('decode'), | ||
| 36 | coerce_type => 1, | ||
| 37 | description => 'words to use in the matrix rain', | ||
| 38 | option_alias => 'w' | ||
| 39 | ); | ||
| 40 | |||
| 41 | option chars => ( | ||
| 42 | type => JSON->by('decode'), | ||
| 43 | coerce_type => 1, | ||
| 44 | description => 'chars to use in the matrix rain', | ||
| 45 | option_alias => 'c' | ||
| 46 | ); | ||
| 47 | |||
| 48 | sub callback { | ||
| 49 | my ($self) = @_; | ||
| 50 | |||
| 51 | my @words; | ||
| 52 | if ($self->words){ | ||
| 53 | if ( ! ref $self->words->[0]) { | ||
| 54 | for (@{$self->words}) { | ||
| 55 | push @words, [split //, $_]; | ||
| 56 | } | ||
| 57 | } else { | ||
| 58 | push @words, @{$self->words}; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | Acme::Matrix->start( | ||
| 63 | delay => $self->delay, | ||
| 64 | spacing => $self->spacing, | ||
| 65 | (scalar @words ? (words => \@words) : ()), | ||
| 66 | ($self->chars ? (chars => $self->chars) : ()) | ||
| 67 | ); | ||
| 68 | } | ||
| 69 | |||
| 70 | 1; | ||
| 71 |