| 1 | #!/usr/bin/perl -w | ||
| 2 | # | ||
| 3 | # Jan 2016 M.Eckardt, imunixx GmbH <Matthias.Eckardt@imunixx.de> | ||
| 4 | # SDG | ||
| 5 | ############################################################################ | ||
| 6 | use strict; | ||
| 7 | use Script::Toolbox qw(:all); | ||
| 8 | use Script::Toolbox::TableO; | ||
| 9 | ############################################################################ | ||
| 10 | my $O = { | ||
| 11 | 'file' => { 'mod' => '=s', 'desc' => 'Get a file name.', 'mand' => 1, 'default' => '/bin/cat', }, | ||
| 12 | }; | ||
| 13 | ############################################################################ | ||
| 14 | ############ generate prototypes with the following line ################### | ||
| 15 | # :r! echo $(grep '^sub' queue_blocking.pl | sed -e 's/$/;/') | fold -s -80 | ||
| 16 | ############################################################################ | ||
| 17 | ############################################################################ | ||
| 18 | #$SIG{'INT'} = 'sigExit'; | ||
| 19 | #$SIG{'HUP'} = 'sigExit'; | ||
| 20 | #$SIG{'QUIT'}= 'sigExit'; | ||
| 21 | #$SIG{'TERM'}= 'sigExit'; | ||
| 22 | ############################################################################ | ||
| 23 | #------------------------------------------------------------------------------ | ||
| 24 | # Signal handler. | ||
| 25 | #------------------------------------------------------------------------------ | ||
| 26 | #sub sigExit($) | ||
| 27 | #{ | ||
| 28 | # my ($sig) = @_; | ||
| 29 | # Exit( 1, "program aborted by signal SIG$sig." ); | ||
| 30 | #} | ||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | #------------------------------------------------------------------------------ | ||
| 35 | #------------------------------------------------------------------------------ | ||
| 36 | sub main | ||
| 37 | { | ||
| 38 | my ($self) = @_; | ||
| 39 | my $o = Script::Toolbox->new( $O ); | ||
| 40 | |||
| 41 | my $m = Script::Toolbox::Util::Menues->new({'SubMenue2'=>[{'label'=>'test','value'=>10}]}); | ||
| 42 | $m->addMenue({'MainMenue'=>[{'label'=>'test1', 'value'=>1 }, | ||
| 43 | {'label'=>'test2', 'value'=>'readOnly','readOnly'=>1}, | ||
| 44 | {'label'=>'test3', 'value'=>30,}, | ||
| 45 | {'label'=>'test4',}, | ||
| 46 | {'label'=>'test5',}, | ||
| 47 | {'label'=>'test6',}, | ||
| 48 | {'label'=>'test7',}, | ||
| 49 | {'label'=>'test8',}, | ||
| 50 | {'label'=>'test9',}, | ||
| 51 | {'label'=>'test10', 'value'=>30,}, | ||
| 52 | {'label'=>'Untermenue 1', 'jump'=>'SubMenue1'}, | ||
| 53 | {'label'=>'Untermenue 2', 'jump'=>'SubMenue2'}, | ||
| 54 | {'label'=>'InvalidSubMenue', 'jump'=>'SubMenueX'} | ||
| 55 | ]}); | ||
| 56 | $m->addMenue({'SubMenue1'=>[{'label'=>'SubMenue1 Test','value'=>40}]}); | ||
| 57 | $m->addOption('MainMenue', {'label'=>'Untermenue 2 via addOption()', 'jump'=>'SubMenue2'}); | ||
| 58 | |||
| 59 | $m->setAutoHeader(); | ||
| 60 | $m->setFooter('MainMenue', 'Test:Autoheader, ininite run'); | ||
| 61 | my $r = $m->run('MainMenue',-1); | ||
| 62 | |||
| 63 | printf "\n%s\n", '-' x 20; | ||
| 64 | my $v = $m->getMatching('MainMenue','test','label','value'); | ||
| 65 | printf "Values of Labels /test/ : %s\n", join ' ', @{$v}; | ||
| 66 | $v = $m->getMatching('MainMenue','(1|3)','number','value'); | ||
| 67 | printf "Values of Numbers /(1|3)/: %s\n", join ' ', @{$v}; | ||
| 68 | $v = $m->getMatching('MainMenue','\d+','value','label'); | ||
| 69 | printf "Labels of Values /%s/ : %s\n", '\d+', join ' ', @{$v}; | ||
| 70 | printf "\n%s\n", '-' x 20; | ||
| 71 | |||
| 72 | $m->setFooter('MainMenue', 'Test:Autoheader, single run with reaction code'); | ||
| 73 | while( $m->run('MainMenue')) { | ||
| 74 | if( $m->currNumber('MainMenue') == 2 ) { | ||
| 75 | my $v = $m->currValue('MainMenue'); | ||
| 76 | my $nv= $v == 0 ? 1 : 0; | ||
| 77 | my $lb= $nv == 0 ? 'test1-off' : 'test1-on'; | ||
| 78 | $m->setCurrValue('MainMenue',$nv); | ||
| 79 | $m->setCurrLabel('MainMenue',$lb); | ||
| 80 | |||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | # my $t = Table([ 'Util-Table', | ||
| 85 | # [ '--H1--', '--H2--', '--H3--'], | ||
| 86 | # [ '11:11:11', 33.456, 'cc ' ], | ||
| 87 | # [ '12:23:00', 2222222, 3 ], | ||
| 88 | # [ '11:11', 222, 3333333333333333 ]]); | ||
| 89 | # print join "\n", @{$t}; | ||
| 90 | # | ||
| 91 | # $t = $o->Table([ 'Util-Table as Script::Toolbox Object', | ||
| 92 | # [ '--H1--', '--H2--', '--H3--'], | ||
| 93 | # [ '11:11:11', 33.456, 'cc ' ], | ||
| 94 | # [ '12:23:00', 2222222, 3 ], | ||
| 95 | # [ '11:11', 222, 3333333333333333 ]]); | ||
| 96 | # print join "\n", @{$t}; | ||
| 97 | # | ||
| 98 | # my $T = Script::Toolbox::TableO->new([ 'TableO', | ||
| 99 | # [ '--H1--', '--H2--', '--H3--'], | ||
| 100 | # [ '11:11:11', 33.456, 'cc ' ], | ||
| 101 | # [ '12:23:00', 2222222, 3 ], | ||
| 102 | # [ '11:11', 222, 3333333333333333 ]]); | ||
| 103 | # print $T->asString("\n\n"); | ||
| 104 | # return; | ||
| 105 | } | ||
| 106 | main(); | ||
| 107 | |||
| 108 | ############################################################################ | ||
| 109 | 1; | ||
| 110 | __END__ |