CursesApplication
view release on metacpan or search on metacpan
Application.pm view on Meta::CPAN
If either B<MINY> or B<MINX> is not satisfied, this method will return undef
instead of an object reference to Curses::Application.
Like Curses::Forms, all colour choices are passed to each form that doesn't
explicitly declare their own. Alternate namespaces are also passed.
=cut
sub _conf {
# This method creates the initial curses object and initialises
# both the curses and application configurable space.
#
# Usage: $self->_conf(%conf);
my $self = shift;
my %conf = (
TITLEBAR => 0,
STATUSBAR => 0,
FORMDEFS => {},
CAPTION => $0,
MINY => 24,
MINX => 80,
@_ );
my $mwh = new Curses;
my @required = qw(MAINFORM);
my ($y, $x, %forms, $code);
my ($my, $ml) = (0, 0);
my $err = 0;
my $main;
# Set some defaults
$self->{CONF} = {%conf};
$self->{FORMS} = {};
$self->{FORMDEFS} = {};
# Check for required arguments
foreach (@required) { $err = 1 unless exists $conf{$_} };
unless ($err == 0) {
carp ref($self), ": Required fields not passed";
return 0;
}
# Save the handle to stdscr
$self->{MWH} = $mwh;
pushwh($mwh);
# Get and store the max X and Y
$mwh->getmaxyx($y, $x);
$self->{MAX} = [$y, $x];
# Return an error if MINY and MINX aren't met
unless ($y >= $conf{MINY} && $x >= $conf{MINX}) {
carp ref($self), ": Minimum screen size not satisfied!";
return 0;
}
# Set up the session
noecho(); # Turn off input echoing
halfdelay(1); # Turn on partial blocking uncooked input
curs_set(0); # Turn off visible cursor
$mwh->keypad(1); # Turn on keypad support for special keys
$mwh->syncok(1); # Sync sub/derwins up to mainwin
# Read the forms from main
$code = join('', <main::DATA>);
close(main::DATA);
unless (eval $code) {
carp ref($self), ": Eval of main::DATA failed!";
return 0;
}
# Get geometry for the main form
$ml = $y;
$my = 0;
if ($conf{TITLEBAR}) {
--$ml;
++$my;
}
--$ml if $conf{STATUSBAR};
# Set size of MAINFORM
$main = (keys %{$conf{MAINFORM}})[0];
$forms{$conf{MAINFORM}{$main}} = {
%{$forms{$conf{MAINFORM}{$main}}},
Y => $my,
X => 0,
LINES => $ml,
COLUMNS => $x,
DERIVED => 1,
};
# Save the form defs, adjusting the colours, if neccessary
foreach (keys %forms) { $self->addFormDef($_, $forms{$_}) };
# Set the window foreground/background colours if specified
if ($conf{FOREGROUND} && $conf{BACKGROUND}) {
$mwh->bkgdset(COLOR_PAIR(
select_colour($conf{FOREGROUND}, $conf{BACKGROUND})));
}
# Make sure no errors are returned by the parent method
$err = 1 unless $self->SUPER::_conf(%conf);
# Initialise window
$self->_init($mwh);
return $err == 1 ? 0 : 1;
}
=head2 maxyx
($y, $x) = $app->maxyx;
Returns the maximum Y and X coordinates for the screen.
=cut
sub maxyx {
my $self = shift;
( run in 0.562 second using v1.01-cache-2.11-cpan-39bf76dae61 )