add curses entry point for scripts (archival, ghidra import, plots, queries, cleanup)
This commit is contained in:
92
scripts/TUI.pm
Normal file
92
scripts/TUI.pm
Normal file
@ -0,0 +1,92 @@
|
||||
package TUI;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use diagnostics;
|
||||
|
||||
use Curses::UI;
|
||||
|
||||
# Singleton
|
||||
my $_cui;
|
||||
|
||||
sub init_cui {
|
||||
if ( !defined $_cui ) {
|
||||
$_cui = new Curses::UI(
|
||||
-color_support => 1,
|
||||
|
||||
# -clear_on_exit => 1,
|
||||
);
|
||||
}
|
||||
|
||||
return $_cui;
|
||||
}
|
||||
|
||||
sub select_from_list {
|
||||
my ( $title, $multiselect, @items ) = @_;
|
||||
die "No items to choose from" unless @items;
|
||||
|
||||
my @values = $multiselect ? ( '__ALL__', @items ) : @items;
|
||||
my %labels =
|
||||
$multiselect
|
||||
? ( '__ALL__' => '[ALL]', map { $_ => $_ } @items, )
|
||||
: map { $_ => $_ } @items;
|
||||
|
||||
my @selection;
|
||||
|
||||
my $cui = init_cui();
|
||||
|
||||
my $win = $cui->add( 'root', 'Window', );
|
||||
|
||||
my $listbox = $win->add(
|
||||
'item_list',
|
||||
'Listbox',
|
||||
-title => $title,
|
||||
-border => 1,
|
||||
-values => \@values,
|
||||
-labels => \%labels,
|
||||
-multi => $multiselect == 1,
|
||||
-radio => $multiselect == 0,
|
||||
-padbottom => 1,
|
||||
|
||||
);
|
||||
|
||||
$win->add(
|
||||
'info', 'Label',
|
||||
-y => -1,
|
||||
-text => "Space/Enter = toggle, c = confirm, q = quit",
|
||||
);
|
||||
|
||||
$listbox->clear_binding('loose-focus');
|
||||
|
||||
$listbox->set_binding(
|
||||
sub {
|
||||
my @picked = $listbox->get;
|
||||
if ( $multiselect && grep { $_ eq '__ALL__' } @picked ) {
|
||||
@selection = @items;
|
||||
}
|
||||
else {
|
||||
@selection = @picked;
|
||||
}
|
||||
$cui->mainloopExit;
|
||||
},
|
||||
'c',
|
||||
);
|
||||
|
||||
$listbox->set_binding(
|
||||
sub {
|
||||
@selection = ();
|
||||
$cui->mainloopExit;
|
||||
},
|
||||
'q',
|
||||
);
|
||||
|
||||
$listbox->focus;
|
||||
$cui->mainloop;
|
||||
|
||||
$cui->leave_curses;
|
||||
$cui->delete('root');
|
||||
|
||||
return @selection;
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user