use of 'dialog' command with perl under linux


dialog.pl perl script
El propósito del código es facilitar la aparición de programas perl con un decente interface en modo texto. El comando dialog se encarga de ello, escribiendo los resultados en STDERR, que redirigimos a un fichero del cual leer.



#!/usr/bin/perl $base="dialog --backtitle \"test\.0\.2\" --"; ($textodef, $altodef, $anchodef,$restodef) = ("",12,60,""); $|=1; &dodo ("clear"); $t = "Fundamental data"; $d= "Type in as you like:"; $dat = &dodo ("inputbox \"$d\" 10 50"); print "\r I get this ->$dat \n\a"; sleep 1; $t="Other data\.\.\."; $dat = &dodo ("textbox dialog\.pl 30 70"); $t= "This is the end\.\.\."; $d= "I hope this helps you.\n Improve it, repost, and help me.\n\n Email me at \ gamo\@telecable.es \n\n homepage avaible on www.telecable.es/personales/gamo\n"; $dat = &dodo ("msgbox \"$d\" 20 60"); $t= "last\, but not least\.\.\."; $d= "\nDid you like it\?"; $dat = &dodo ("yesno \"$d\" 7 40"); if ($dat == -666) { $bla="NOOOP"; } elsif ($dat == -69) { $bla="FIFTH_ENMENDMENT"; } #Why this don't work? else { $bla = "YUUUUP"; } $t= "Don't worry. Who cares much about\?"; $d= "Try another free method from this list"; $a= "ncurses with gnu C"; $b= "Curses-1.0.2 in perl"; $c= "maybe libreadline-*.gz module\?"; $dat = &dodo ("menu \"$d\" 14 55 4 1 \"$a\" 2 \"$b\" 3 \"$c\" "); $t="-"; #ugh $d= "choose only one item with space"; $elect = &dodo ("radiolist \"$d\" 12 40 5 1 a off 2 b on 3 c off 4 d off 5 e off"); $d= "choose various items with space"; @ops = &dodo ("checklist \"$d\" 12 40 5 1 a off 2 b off 3 c off 4 d off 5 e off"); $d="OK\, you typed $bla. to like/dislike question\n and prefered menu option was $dat \n \ in the election process you vote $elect and finally\n in the multiple options you get @ops \n \ and that's all what I wanted yesterday to know\!\n Plea, send me improvements\n\a Goodbye\!"; $dat = &dodo ("infobox \"$d\" 12 62"); sub dodo() { my ($comand, $text, $alto, $ancho, $rest) = @_; my ($res, $result)=0; if (defined($t)){ $title="title \"$t\" --"; } if (defined($text)){ $text=$textodef; } if (defined($alto)){ $alto=$altodef; } if (defined($ancho)){ $ancho=$anchodef; } if (defined($rest)){ $rest=$restodef; } $orden = $base.$title.$comand." ".$text." ".$alto.$ancho.$rest; open(STDERR, ">/tmp/dialogout") || die "CANNOT SAVE /tmp/dialogout"; $res = system ($orden); $res = $res/256; #any question? |-) close STDERR; # personalized rulez -> infrecuent values if ( $res == 1){ return -666; # NO or explicit CANCEL }elsif ($res == -1){ return -69; # ESCape }else{ open(IN, "/tmp/dialogout") || die "CANNOT READ /tmp/dialogout (!)"; $result = ; # chomp() not needed close IN; return $result; } } __END__


Back