revbank/plugins/help
Juerd Waalboer 7247862dcc Space saving measures in help output
Underline parameters, shorten instructions.
2017-04-24 22:17:11 +02:00

42 lines
1 KiB
Perl
Executable file

#!perl
HELP "help" => "The stuff you're looking at right now :)";
use List::Util qw(max);
my $bold = "\e[1m";
my $underline = "\e[4m";
my $off = "\e[0m";
sub command :Tab(help,wtf,omgwtfbbq) {
my ($self, $cart, $command) = @_;
return NEXT if $command !~ /^(?:help|wtf|omgwtfbbq)$/;
say "\n${bold}Valid commands:${off}";
my $width = max(map length s/[<>]//rg, keys %::HELP);
for my $command (sort keys %::HELP) {
my $display = $command;
my $length = length $display =~ s/[<>]//rg;
$display =~ s/</$underline/g;
$display =~ s/>/$off/g;
# Because of markup codes, a simple %-42s doesn't work.
$display .= " " x ($width - $length);
say sprintf " %s %s", $display, $::HELP{$command};
}
print <<"END";
${bold}Simple usage: ${off} press <Enter> after a command for follow-up prompts
${bold}Advanced usage:${off} pass space separated arguments to parameters
Complete each transaction with ${underline}account${off} (i.e. enter your name).
END
return ACCEPT;
}