Warn when someone leaves without paying.
This commit is contained in:
parent
71817a0783
commit
8f84891b0c
3 changed files with 66 additions and 9 deletions
28
plugins/idle
Executable file
28
plugins/idle
Executable 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
40
revbank
|
@ -2,8 +2,9 @@
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use attributes;
|
use attributes;
|
||||||
use Term::ReadLine;
|
use IO::Select;
|
||||||
use List::Util ();
|
use List::Util ();
|
||||||
|
use Term::ReadLine;
|
||||||
use RevBank::Plugins;
|
use RevBank::Plugins;
|
||||||
use RevBank::Global;
|
use RevBank::Global;
|
||||||
use RevBank::Messages;
|
use RevBank::Messages;
|
||||||
|
@ -20,19 +21,47 @@ $| = 1;
|
||||||
my $readline = Term::ReadLine->new($0);
|
my $readline = Term::ReadLine->new($0);
|
||||||
$readline->ornaments('me,md,,');
|
$readline->ornaments('me,md,,');
|
||||||
|
|
||||||
|
my $select = IO::Select->new;
|
||||||
|
$select->add(\*STDIN);
|
||||||
|
|
||||||
|
my $cart = RevBank::Cart->new;
|
||||||
|
|
||||||
sub prompt {
|
sub prompt {
|
||||||
my ($prompt, @completions) = @_;
|
my ($prompt, $plugins, @completions) = @_;
|
||||||
|
|
||||||
$prompt =~ s/$/: /;
|
$prompt =~ s/$/: /;
|
||||||
$prompt =~ s/\?: $/? /;
|
$prompt =~ s/\?: $/? /;
|
||||||
|
|
||||||
my @matches;
|
my @matches;
|
||||||
$readline->Attribs->{completion_entry_function} = sub {
|
$readline->Attribs->{completion_entry_function} = sub {
|
||||||
my ($word, $state) = @_;
|
my ($word, $state) = @_;
|
||||||
@matches = grep /^\Q$word\E/i, @completions if $state == 0;
|
@matches = grep /^\Q$word\E/i, @completions if $state == 0;
|
||||||
return shift @matches;
|
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";
|
print "\e[0m";
|
||||||
defined $input or return;
|
defined $input or return;
|
||||||
|
@ -47,7 +76,6 @@ RevBank::Plugins->load;
|
||||||
|
|
||||||
call_hooks("startup");
|
call_hooks("startup");
|
||||||
|
|
||||||
my $cart = RevBank::Cart->new;
|
|
||||||
my $old_cart_size = 0;
|
my $old_cart_size = 0;
|
||||||
|
|
||||||
my @words;
|
my @words;
|
||||||
|
@ -99,7 +127,7 @@ OUTER: for (;;) {
|
||||||
delete $completions{abort};
|
delete $completions{abort};
|
||||||
}
|
}
|
||||||
|
|
||||||
my $input = prompt $prompt, keys %completions;
|
my $input = prompt $prompt, \@plugins, keys %completions;
|
||||||
|
|
||||||
call_hooks "input", $cart, $input, $split_input;
|
call_hooks "input", $cart, $input, $split_input;
|
||||||
|
|
||||||
|
|
|
@ -6,12 +6,13 @@ log # first, so that the registrations of other plugins are logged
|
||||||
sigint
|
sigint
|
||||||
restart
|
restart
|
||||||
help
|
help
|
||||||
|
idle
|
||||||
undo
|
undo
|
||||||
give
|
give
|
||||||
take
|
take
|
||||||
#nyan # fun, but not compatible with dumb terminals
|
nyan # fun, but not compatible with dumb terminals
|
||||||
#pfand # makes little sense in a self service environment
|
pfand # makes little sense in a self service environment
|
||||||
#stock
|
stock
|
||||||
|
|
||||||
# Then, plugins that apply heuristics
|
# Then, plugins that apply heuristics
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue