Warn when someone leaves without paying.

This commit is contained in:
Juerd Waalboer 2014-01-10 21:17:43 +01:00
parent 71817a0783
commit 8f84891b0c
3 changed files with 66 additions and 9 deletions

28
plugins/idle Executable file
View file

@ -0,0 +1,28 @@
#!perl
my $timeout = 10;
sub command { NEXT }
sub hook_prompt_idle {
my ($class, $cart, $plugin, $seconds, $readline) = @_;
if ($seconds >= $timeout and $cart->size and not $plugin) {
$readline->ding;
return if $seconds > $timeout; # text only once
my $text = $readline->copy_text;
my $point = $readline->{point};
$readline->save_prompt;
$readline->replace_line("");
$readline->redisplay;
print "\e[33;2;1mTransaction incomplete.\e[0m Enter username to pay/finish or 'abort' to abort.\n";
$readline->restore_prompt;
$readline->replace_line($text);
$readline->{point} = $point;
$readline->redisplay;
}
}

40
revbank
View file

@ -2,8 +2,9 @@
use strict;
use attributes;
use Term::ReadLine;
use IO::Select;
use List::Util ();
use Term::ReadLine;
use RevBank::Plugins;
use RevBank::Global;
use RevBank::Messages;
@ -20,19 +21,47 @@ $| = 1;
my $readline = Term::ReadLine->new($0);
$readline->ornaments('me,md,,');
my $select = IO::Select->new;
$select->add(\*STDIN);
my $cart = RevBank::Cart->new;
sub prompt {
my ($prompt, @completions) = @_;
my ($prompt, $plugins, @completions) = @_;
$prompt =~ s/$/: /;
$prompt =~ s/\?: $/? /;
my @matches;
$readline->Attribs->{completion_entry_function} = sub {
my ($word, $state) = @_;
my ($word, $state) = @_;
@matches = grep /^\Q$word\E/i, @completions if $state == 0;
return shift @matches;
};
my $input = $readline->readline($prompt);
my $done;
my $input;
$readline->callback_handler_install($prompt, sub {
$done = 1;
$input = shift;
$readline->callback_handler_remove;
});
my $begin = my $time = time;
while (not $done) {
$readline->callback_read_char if $select->can_read(.05);
if (time > $time) {
$time = time;
call_hooks(
"prompt_idle",
$cart,
(@$plugins > 1 ? undef : $plugins->[0]), # >1 plugin = main loop
$time - $begin,
$readline,
);
}
}
print "\e[0m";
defined $input or return;
@ -47,7 +76,6 @@ RevBank::Plugins->load;
call_hooks("startup");
my $cart = RevBank::Cart->new;
my $old_cart_size = 0;
my @words;
@ -99,7 +127,7 @@ OUTER: for (;;) {
delete $completions{abort};
}
my $input = prompt $prompt, keys %completions;
my $input = prompt $prompt, \@plugins, keys %completions;
call_hooks "input", $cart, $input, $split_input;

View file

@ -6,12 +6,13 @@ log # first, so that the registrations of other plugins are logged
sigint
restart
help
idle
undo
give
take
#nyan # fun, but not compatible with dumb terminals
#pfand # makes little sense in a self service environment
#stock
nyan # fun, but not compatible with dumb terminals
pfand # makes little sense in a self service environment
stock
# Then, plugins that apply heuristics