CursesWidgets

 view release on metacpan or  search on metacpan

test.pl  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Simple script that demonstrates the uses of Curses::Widgetss
#
# $Id: test.pl,v 1.104 2002/11/14 01:36:48 corliss Exp corliss $
#

use strict;
use Curses;
use Curses::Widgets;  # Included to import select_colour & scankey
use Curses::Widgets::TextField;
use Curses::Widgets::ButtonSet;
use Curses::Widgets::ProgressBar;
use Curses::Widgets::TextMemo;
use Curses::Widgets::ListBox;
use Curses::Widgets::Calendar;
use Curses::Widgets::ComboBox;
use Curses::Widgets::Menu;
use Curses::Widgets::Label;

#####################################################################
#
# Set up the environment
#
#####################################################################

my ($mwh, $key, $i, $p);
my (@widgets, @descriptions);

#####################################################################
#
# Program Logic starts here
#
#####################################################################

# Unless specifically noted, most functions are provided by the Curses
# package, *not* Curses::Widgets.  See the pod for Curses for more
# information on the functions.  Additional information is available
# with the (n)Curses man pages (section 3), if you have them.
$mwh = new Curses;
noecho();
halfdelay(5);
$mwh->keypad(1);
$mwh->syncok(1);
curs_set(0);
leaveok(1);

# Draw the main window, and wait for a key press (the scankey
# function is imported from the Curses::Widgets module)
main_win();
comment_box(<< '__EOF__');
Welcome to the Curses::Widgets Test Script!

Press any key to begin.
__EOF__
$key = scankey($mwh);


# Create each of the widgets beforehand
$widgets[0] = Curses::Widgets::Menu->new({
  FOREGROUND  => 'white',
  BACKGROUND  => 'green',
  BORDER      => 1,
  CURSORPOS => [qw(File)],
  MENUS       => {
    MENUORDER   => [qw(File Help)],
    File        => {
      ITEMORDER => [qw(Open Save Exit)],
      Open      => sub { 1 },
      Save      => sub { 1 },
      Exit      => sub { exit 0 },
      },
    Help        => {
      ITEMORDER => [qw(Help About)],
      Help      => sub { 1 },
      About     => sub { 1 },
      },
    },
  
  });
$descriptions[0] = << '__EOF__';
Curses::Widgets::Menu -- Menus

Use the arrow keys to navigate, and <ESC> to exit a menu without selecting anything.  Use <TAB> to move to the next widget.
__EOF__

$widgets[1] = Curses::Widgets::ButtonSet->new({
  Y           => 2,
  X           => 2,
  FOREGROUND  => 'white',
  BACKGROUND  => 'black',
  BORDER      => 0,
  LABELS      => [ qw( OK CANCEL HELP ) ],
  LENGTH      => 8,
  HORIZONTAL  => 1,
  });
$descriptions[1] = << '__EOF__';
Curses::Widgets::ButtonSet -- Horizontal set without borders.

Use the arrow keys to navigate among the buttons, and press <RETURN> or <TAB> to move to the next widget (set).
__EOF__

$widgets[2] = Curses::Widgets::ButtonSet->new({
  Y           => 3,
  X           => 1,
  FOREGROUND  => 'white',
  BACKGROUND  => 'blue',
  BORDER      => 1,
  LABELS      => [ qw( Button1 Button2 Button3 Quit ) ],
  LENGTH      => 9,
  HORIZONTAL  => 0,
  });
$descriptions[2] = << '__EOF__';
Curses::Widgets::ButtonSet -- Vertical set with borders.

Use the arrow keys to navigate among the buttons, and press <RETURN> or <TAB> to move to the next widget (set).
__EOF__

$widgets[3] = Curses::Widgets::TextField->new({
  Y           => 4,
  X           => 14,
  COLUMNS     => 20,
  MAXLENGTH   => 30,
  FOREGROUND  => 'green',
  BACKGROUND  => 'blue',
  VALUE       => 'Test Value',
  BORDERCOL   => 'black',
  BORDER      => 1,
  CAPTION     => 'Test Field',
  CAPTIONCOL  => 'yellow',
  });
$descriptions[3] = << '__EOF__';
Curses::Widgets::TextField -- Text field with a border and caption.

Press <RETURN> or <TAB> to move to the next widget (set).
__EOF__

$widgets[4] = Curses::Widgets::ProgressBar->new({
  Y           => 7,
  X           => 14,
  LENGTH      => 20,
  FOREGROUND  => 'yellow',



( run in 0.651 second using v1.01-cache-2.11-cpan-39bf76dae61 )