Add database import action to menu
This commit is contained in:
@@ -4,7 +4,9 @@ use strict;
|
||||
use warnings;
|
||||
use diagnostics;
|
||||
|
||||
use Curses;
|
||||
use Curses::UI;
|
||||
use Curses::UI::Common;
|
||||
|
||||
# Singleton
|
||||
my $_cui;
|
||||
@@ -125,4 +127,60 @@ sub select_from_list {
|
||||
return @selection;
|
||||
}
|
||||
|
||||
# Returns the entered string or undef when cancelled
|
||||
sub read_string {
|
||||
my ( $title, $default ) = @_;
|
||||
|
||||
my $value;
|
||||
|
||||
my $cui = init_cui();
|
||||
my $win = $cui->add( 'root', 'Window', );
|
||||
|
||||
my $entry;
|
||||
$entry = $win->add(
|
||||
'string_entry',
|
||||
'TextEntry',
|
||||
-title => $title,
|
||||
-border => 1,
|
||||
-text => ( defined $default ? $default : '' ),
|
||||
);
|
||||
|
||||
$win->add(
|
||||
'info', 'Label',
|
||||
-y => -1,
|
||||
-text => "Enter = confirm, Esc = cancel",
|
||||
);
|
||||
|
||||
# Set cursor to the end
|
||||
$entry->pos( length $entry->get() );
|
||||
|
||||
# Enter would otherwise just leave the entry
|
||||
$entry->clear_binding('loose-focus');
|
||||
|
||||
$entry->set_binding(
|
||||
sub {
|
||||
$value = $entry->get();
|
||||
$value =~ s/^\s+|\s+$//g;
|
||||
$cui->mainloopExit();
|
||||
},
|
||||
KEY_ENTER(),
|
||||
);
|
||||
|
||||
$entry->set_binding(
|
||||
sub {
|
||||
$value = undef;
|
||||
$cui->mainloopExit();
|
||||
},
|
||||
CUI_ESCAPE(),
|
||||
);
|
||||
|
||||
$entry->focus();
|
||||
$cui->mainloop();
|
||||
|
||||
$cui->leave_curses();
|
||||
$cui->delete('root');
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
Reference in New Issue
Block a user