App-Greple-wordle
view release on metacpan or search on metacpan
- change --try option to --trial
0.11 2022-05-03T00:36:16Z
- show help message
0.10 2022-03-10T07:47:21Z
- implement filter command pipeline
- show prompt
0.09 2022-03-08T08:38:52Z
- fixed bugs in 0.08
* option --random did not make random answer
* wrong cursor movement
0.08 2022-03-08T01:05:18Z
- use oo interface to keep game status
lib/App/Greple/wordle.pm view on Meta::CPAN
$app->series == 0 ? '' : sprintf("%d-", $app->series),
$app->index);
}
######################################################################
my $app = __PACKAGE__->new or die;
my $game;
my $interactive;
sub prompt {
sprintf '%d: ', $game->attempt + 1;
}
sub initialize {
my($mod, $argv) = @_;
$app->parseopt($argv)->setup;
$game = App::Greple::wordle::game->new(answer => $app->answer);
push @$argv, $app->patterns;
if ($interactive = -t STDIN) {
push @$argv, '--interactive', ('/dev/stdin') x $app->total;
select->autoflush;
say $app->title;
print prompt();
}
}
sub respond {
local $_ = $_;
my $chomped = chomp;
print ansi_code("{CHA}{CUU}") if $chomped;
print ansi_code(sprintf("{CHA(%d)}",
max(11, vwidth($_) + length(prompt()) + 2)));
print s/(?<=.)\z/\n/r for @_;
}
sub show_answer {
say colorize('#6aaa64', uc $game->answer);
}
sub show_result {
printf "\n%s %d/%d\n\n", $app->title, $game->attempt, $app->trial;
say $game->result;
lib/App/Greple/wordle.pm view on Meta::CPAN
show_result if $app->result;
exit 0;
}
if (length) {
if ($game->attempt >= $app->trial) {
show_answer;
exit 1;
}
$app->keymap and respond $game->keymap;
}
print prompt();
}
1;
__DATA__
mode function
define GREEN #6aaa64
define YELLOW #c9b458
( run in 0.728 second using v1.01-cache-2.11-cpan-6aa56a78535 )