play.pl: change -fmt args separator and fix warnings

This commit is contained in:
wowaname 2016-10-21 20:29:31 +00:00
parent 84d82e0558
commit 9b109be00e
1 changed files with 5 additions and 3 deletions

View File

@ -13,11 +13,12 @@ our (%queue, %timer);
if (weechat::register($SCRIPT_NAME, $SCRIPT_AUTHOR, $SCRIPT_VERSION,
$SCRIPT_LICENCE, $SCRIPT_DESC, '', '')) {
weechat::hook_command('play', 'Play ASCII art',
qq([-delay ms] [-find] [-pipe "command"] [-fmt "text"] filename\n-stop),
qq([-delay ms] [-find] [-pipe "command"] [-fmt "list"] filename\n-stop),
"-delay: delay in milliseconds between lines\n".
"-find: list matching files, don't play\n".
"-pipe: pipe output into command\n".
"-fmt: treat file as a format string and replace with text\n".
"-fmt: treat file as a format string and replace with arguments in\n".
" list. Arguments are separated by semicolons (;)\n".
"filename: file to play. Supports wildcards. By default, searches\n".
" subdirectories as well unless '/' is found in the filename\n".
"-stop: stop currently playing file in buffer",
@ -114,7 +115,8 @@ sub cmd_play {
if ($path and open FH, "<", $path) {
my @lines;
while (<FH>) {
$_ = sprintf $_, split ' ', $fmt if $fmt;
no warnings; # sprintf barks if there's nothing to replace
$_ = sprintf $_, split ';', $fmt if $fmt;
push @lines, s/[\r\n]*$//r
}
close FH;