use Curses::UI;
my $cui = new Curses::UI( -color_support => 1);
$cui->{-read_timeout} = 0;
####
my $last = time;
while(1) {
$cui->do_one_event();
my $now = time;
if($last != $now) {
$last = $now;
foreach my $sensor (@sensors) {
my $newtext = int(rand(1000) * 100) / 100;
$sensor->text($newtext);
}
$cui->draw();
$cui->do_one_event();
} else {
sleep(0.01);
}
}
##
##
#!/usr/bin/perl -w
use strict;
use warnings;
use Time::HiRes qw[sleep];
use Curses::UI;
my $cui = new Curses::UI( -color_support => 1);
$cui->{-read_timeout} = 0;
my @menu = (
{ -label => 'File',
-submenu => [
{ -label => 'Exit ^Q', -value => \&exit_dialog }
]
},
);
my $menu = $cui->add(
'menu','Menubar',
-menu => \@menu,
-fg => "white",
-bg => "blue",
);
my $win1 = $cui->add(
'win1', 'Window',
-border => 1,
-y => 1,
-bfg => 'red',
);
sub exit_dialog()
{
my $return = $cui->dialog(
-message => "Do you really want to quit?",
-title => "Are you sure???",
-buttons => ['yes', 'no'],
);
exit(0) if $return;
}
my @labels;
my @sensors;
for(my $i = 1; $i <= 3; $i++) {
push @labels, $win1->add('label' . $i, 'Label',
-width => 14,
-height => 1,
-text => 'Sensor ' . $i . ' :',
-x => 4,
-y => 3 + $i,
);
push @sensors, $win1->add('sensordata' . $i, 'Label',
-width => 10,
-height => 1,
-text => '----------',
-x => 19,
-y => 3 + $i,
);
}
$cui->set_binding(sub {$menu->focus()}, "\cX");
$cui->set_binding( \&exit_dialog , "\cQ");
my $last = time;
while(1) {
$cui->do_one_event();
my $now = time;
if($last != $now) {
$last = $now;
foreach my $sensor (@sensors) {
my $newtext = int(rand(1000) * 100) / 100;
$sensor->text($newtext);
}
$cui->draw();
$cui->do_one_event();
} else {
sleep(0.01);
}
}