diff --git a/lib/RevBank/Plugins.pm b/lib/RevBank/Plugins.pm index 4676217..c5710d2 100644 --- a/lib/RevBank/Plugins.pm +++ b/lib/RevBank/Plugins.pm @@ -18,11 +18,13 @@ sub _read_file($fn) { readline *ARGV; } -sub call_hooks($hook, @args) { +sub call_hooks { + my $hook = shift; my $method = "hook_$hook"; + for my $class (@plugins) { if ($class->can($method)) { - my ($rv, @message) = $class->$method(@args); + my ($rv, @message) = $class->$method(@_); if (defined $rv and ref $rv) { main::abort(@message) if $rv == ABORT; diff --git a/plugins/statiegeld b/plugins/statiegeld index 09dae8a..dfe1a40 100644 --- a/plugins/statiegeld +++ b/plugins/statiegeld @@ -101,18 +101,25 @@ sub hook_added_entry ($class, $cart, $entry, @) { } } -sub hook_prompt($class, $cart, $prompt, @) { +sub hook_prompt { # ($class, $cart, $prompt), but via @_ for mutable alias $S or return; - # Assumption: only the main prompt will have fewer than 3 \w characters - print "++ Scan product for deposit return ++\n" if $prompt !~ /\w{3,}/; + my $statiegeld_prompt = "\x01\e[33;1m\x02+>\x01\e[0m\x02"; # yellow "+>" + + if ($_[2] eq "" or $_[2] eq $statiegeld_prompt) { + # Assumption: only the main prompt will have fewer than 3 \w characters + print "\e[33;1mScan products for deposit return.\e[0m\n" if not $_[1]->size; + } + $_[2] =~ s/^$/$statiegeld_prompt/; } sub hook_input($class, $cart, $input, $split_input, @) { $S or return; - # Hijack 'help' command so it never reaches the 'help' plugin. + # Extra newline before new "Scan products for ..." line. + print "\n" if $input eq "" and $split_input; + # Hijack 'help' command so it never reaches the 'help' plugin. if ($split_input and $input eq "help") { print <<"END"; diff --git a/revbank b/revbank index 8919ffa..286e882 100755 --- a/revbank +++ b/revbank @@ -51,7 +51,7 @@ my $cart = RevBank::Cart->new; sub prompt($prompt, $plugins, $completions) { if ($prompt) { - $prompt =~ s/$/:/ if $prompt !~ /[?>]$/; + $prompt =~ s/$/:/ if $prompt !~ /[?>](?:\x01[^\x02]*\x02)?$/; $prompt .= " "; } else { # \x01...\x02 = zero width markers for readline