Skip to content

Instantly share code, notes, and snippets.

@monsieurp
Last active August 25, 2021 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monsieurp/feee8de14fc564ecae5c19f94175aa11 to your computer and use it in GitHub Desktop.
Save monsieurp/feee8de14fc564ecae5c19f94175aa11 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use warnings;
use autodie;
use strict;
use feature qw#say#;
use Curses::UI;
use File::Find;
use vars qw#*name#;
*name = *File::Find::name;
local @INC = @INC;
pop @INC if $INC[-1] eq '.';
my @searchdirs = ();
my $searchpath = shift @ARGV;
if ($searchpath && -d $searchpath) {
push @searchdirs, $searchpath;
} else {
push @searchdirs, grep { -d $_ } @INC;
}
my @dotpms = ();
File::Find::find(\&wanted, @searchdirs);
sub wanted {
-f _ &&
/^.*\.pm$/s
&& push @dotpms, "$name\n";
}
my $cui = Curses::UI->new(
-color_support => 1,
-clear_on_exit => 1,
-mouse_support => 1
);
sub exit_dialog {
my $return = $cui->dialog(
-title => 'Quit CursesPodReader?',
-message => 'Do you really want to quit?',
-tfg => 'red',
-fg => 'red',
-buttons => [
{ -label => '[ Yes ]' },
{ -label => '[ No ]' }
]
);
exit(0) if $return eq 0;
}
my $main = $cui->add( 'main', 'Window' );
my $header = $main->add(
'header', 'Label',
-text => 'CursesPodReader',
-textalignment => 'left',
-bold => 1,
-fg => 'white',
-bg => 'blue',
-y => 0,
-width => -1,
-paddingspaces => 1,
);
my $main_window = $cui->add(
'main_window', 'Window',
-padtop => 2,
-padbottom => 3
);
my $top_label = $main_window->add(
'top_label', 'Label',
-text => 'Please select a Perl module in the list below to read documentation from:',
-padleft => 1,
-fg => 'blue',
-width => -1
);
my $main_listbox = $main_window->add(
'main_listbox', 'Listbox',
-y => 2,
-padleft => 1,
-padright => 1,
-padbottom => 2,
-fg => 'blue',
-bg => 'black',
-wraparound => 1,
-values => \@dotpms
);
$main_window->add(
'read_box', 'Buttonbox',
-y => -1,
-padleft => 1,
-buttonalignment => 'left',
-fg => 'blue',
-buttons => [
{
-label => '[ Read ]',
-onpress => sub {
my $pm = $main_listbox->get();
return if !defined $pm;
chomp $pm;
my @perldoc = ('perldoc', $pm);
$cui->leave_curses();
system (@perldoc);
$cui->reset_curses();
$main_listbox->focus();
}
}
]
);
my $footer = $main->add(
'footer', 'Label',
-text => '[Ctrl+q] Quit',
-textalignment => 'left',
-bold => 1,
-bg => 'black',
-fg => 'white',
-y => -1,
-width => -1,
-paddingspaces => 1,
);
$top_label->draw();
$header->draw();
$footer->draw();
$main_window->draw();
$main_window->focus();
$cui->set_binding( \&exit_dialog, "\cQ" );
$cui->mainloop;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment