perlassassin27 has asked for the wisdom of the Perl Monks concerning the following question:

i am trying to use curses and make a form of TUI but since for me the only curses library that does work is curses-UI and nt forms widgets or any other i am pigeon holed into trying to do it through this only. now i am trying to input a BUTTONbox in the widget for email which would open a question dialog asking for email. after this has been input i want the widget to show a text saying what is the email that has been input. i know its sort of complex way of doing it and but i think this could be user friendly.
my $EMAIL; $w{2}->add(undef, 'Buttonbox', -y => -7, -buttons => [ { -label => " [EMAIL] ", -value => 1, -onpress => sub { my $cui=shift()->root; $EMAIL = $cui->question("PLEASE ENTER +EMAIL:"); if ($EMAIL) { $w{2}->add( undef, 'Label', -y => -10, -text => "The email you entere +d is $EMAIL\n"); } else { $cui->dialog("Question cancelled."); } }, }, ], );
so when ever i run this the Email button does come but after input their is no text at all. so i curse and i am not able to wrap my head around it so... any Advice???

update: here is the runable code of the system:
#!/usr/bin/perl -w use strict; use warnings; use File::Temp qw( :POSIX ); use lib "../lib"; # make KEY_BTAB (shift-tab) working in XTerm # and also at the same time enable colors #$ENV{TERM} = "xterm-vt220" if ($ENV{TERM} eq 'xterm'); my $debug = 0; if (@ARGV and $ARGV[0] eq '-d') { my $fh = tmpfile(); open STDERR, ">&fh"; $debug = 1; } else { # We do not want STDERR to clutter our screen. my $fh = tmpfile(); open STDERR, ">&fh"; } use FindBin; use lib "$FindBin::RealBin/../lib"; use lib "$FindBin::RealBin/perllib"; use Curses::UI; # Create the root object. my $cui = new Curses::UI ( -clear_on_exit => 1, -debug => $debug, -color_support => 1, ); # Demo index my $current_demo = 2; # Demo windows my %w = (); # -------------------------------------------------------------------- +-- # Create the explanation window # -------------------------------------------------------------------- +-- my $w0 = $cui->add( 'w0', 'Window', -border => 1, -y => -1, -height => 3, -bfg => 'red', ); $w0->add('explain', 'Label', -text => "CTRL+B: Back CTRL+O: Options " . "CTRL+X: Menu CTRL+Q: Quit" ); # -------------------------------------------------------------------- +-- # Creating the windows for the front end # -------------------------------------------------------------------- +-- my %screens = ( '2' => 'Options page', ); my @screens = sort {$a<=>$b} keys %screens; my %args = ( -border => 1, -titlereverse => 1, -padtop => 0, -padbottom => 5, -ipad => 5, -bfg => 'red', ); while (my ($nr, $title) = each %screens) { my $id = "window_$nr"; $w{$nr} = $cui->add( $id, 'Window', -title => "Curses::UI demo: $title The APE Test($nr/" . @scree +ns . ")", %args,); $w{$nr}-> add( undef,'Label', -y => 0, -x => 5, -bfg => 'blue', -text => " _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + _ _ _ _ _ _ _ _ _ _ _ _ \n" . "|_ _| | | | | | _ _| | _ | | _ | | +_ _| |_ _| | _ _| | _ _| |_ _| \n" . " | | | |_| | | |_ _ | |_| | | |_| | | | +_ _ | | | |_ _ | |_ _ | | \n" . " | | | _ | | _ _| | _ | | _ _| | +_ _| | | | _ _| |_ _ | | | \n" . " | | | | | | | |_ _ | | | | | | | | +_ _ | | | |_ _ _ _| | | | \n" . " |_| |_| |_| |_ _ _| |_| |_| |_| |_ +_ _| |_| |_ _ _| |_ _ _| |_| \n" ); } ########################## ##### OPTIONS PAGE ##### ########################## my $EMAIL; $w{2}->add( undef, 'Label', -y => -10, -text => "Please add email address here below in the event that th +e results will be mailed to you(Optional)\n" ); my $temp; $w{2}->add(undef, 'Buttonbox', -y => -7, -buttons => [ { -label => " [EMAIL] ", -value => 1, -onpress => sub { my $cui=shift()->root; $EMAIL = $cui->question("PLEASE ENTER EMAIL:"); if ($EMAIL) { $w{2}->add( undef, 'Label', -y => -5, -text => "The email you entered is $EMAIL\ +n"); } else { $cui->dialog("Question cancelled."); } }, }, ], ); # -------------------------------------------------------------------- +-- # Setup bindings and focus # -------------------------------------------------------------------- +-- # Bind <CTRL+Q> to quit. $cui->set_binding( sub{ exit }, "\cQ" ); # Bind <CTRL+X> to menubar. $cui->set_binding( sub{ shift()->root->focus('menu') }, "\cX" ); sub goto_next_demo() { $current_demo++; $current_demo = @screens if $current_demo > @screens; $w{$current_demo}->focus; } $cui->set_binding( \&goto_next_demo, "\cN" ); sub goto_prev_demo() { $current_demo--; $current_demo = 1 if $current_demo < 1; $w{$current_demo}->focus; } $cui->set_binding( \&goto_prev_demo, "\cB" ); sub goto_Options() { $w{2}->focus; } $cui->set_binding( \&goto_Options, "\cO" ); $w{$current_demo}->focus; # -------------------------------------------------------------------- +-- # Get things rolling... # -------------------------------------------------------------------- +-- $cui->mainloop;
as i said before i am using Curses::UI only as i am not able to use the other other libraries probably due to fault of my own as i did include it but when i run them nothing happens even when i tried running the example scripts provided by cpan. i tried using this and it had come into my attention that what i want is that every time i press and enter an email i get a text message below stating what i had typed. after typing it the text message doesnt get display untill i dont press the button once again on top of that if i try changing it the email variable may change in the background but it would always display the same thing what i entered first for example:

if i enter email@address.com at first
after pressing ok it would not show anything until i press d button again

and if enter another address like email247@address.com
it would just show email@address.com.com
so am confused wat to do....pls help...

Replies are listed 'Best First'.
Re: Difficulty with Curses
by perlassassin27 (Novice) on Feb 28, 2011 at 19:50 UTC
    i have updated the starting post to include a runable code as well

      It works, just add a name for the label and call 'draw' on it:

      my $lbl = $w{2}->add( undef, 'Label', -y => -5, -text => "The email you entered is $EMAIL\n" ); $lbl->draw;

      Regards, Stefan

        thanks stefan but one of the problem still persists
        its just that when i change it from perl247@assassin.com to perl@assassin.com it would display something like:
        perl@assassin.com.com
Re: Difficulty with Curses
by vkon (Curate) on Feb 26, 2011 at 19:14 UTC
    what module you're using?
    Better yet, show us code that works (does not work as you expected) so we could try it
Re: Difficulty with Curses
by Anonymous Monk on Feb 26, 2011 at 00:14 UTC
    any Advice???

    1) post complete self contained code, not fragments 2) curses are obsolete arcana, try a real GUI? :)

      I don't think that was a helpful reply.

      I would agree with the first point about posting complete bits of code, but perlassassin27 is new and only joined today, so (s)he may not know the eticate here, and in any case it is not always possible or post complete programs due to their length or because they are trade secrets. Instead he posted a fragment where he thought the bug was, which is a sensible thing to do.

      As for curses being obsolete, I can't agree. You don't know what environment perlassassin27 is programming for, and you don't know if he is writing a new program or maintaining an existing one. Perhaps he is maintaining point of sale software that needs to run on 20 year old terminals? In a situation like that, curses is the best form of GUI possible.

      Overall, not a nice way to welcome a new Initiate to the monastery.

        so (s)he may not know the eticate here

        Part of the welcoming process is to point out the lessons of How do I post a question effectively?.

        Since perlassassin27 clearly knows a few of them, that is, he used code tags correctly (Markup in the Monastery) and used a decent node title ( How do I compose an effective node title?), he was only missing the 3rd part of the trinity, runnable code :)

        and in any case it is not always possible or post complete programs due to their length or because they are trade secrets. Instead he posted a fragment where he thought the bug was, which is a sensible thing to do.

        I think its time you check out How do I post a question effectively? :)

        The key to asking a question the smart way, is whittling down your code to a minimal, runnable, self contained program, which uses strict/warnings (and any required modules), and demonstrates the problem.

        Quite often, while preparing this minimal program, the answer presents itself, like a present from yourself; your own gift horse :)

        As for curses being obsolete, I can't agree.

        I think you mean to use "don't" instead of "can't", can means having the ability.

        You don't know what environment perlassassin27 is programming for, and you don't know if he is writing a new program or maintaining an existing one.

        So how is it a problem that I suggest maybe he reconsider using Curses?

        Perhaps he is maintaining point of sale software that needs to run on 20 year old terminals? In a situation like that, curses is the best form of GUI possible.

        Perhaps not. I've seen 20yo POS terminals for Windows 3.0 and unix, both non-terminal.

        Overall, not a nice way to welcome a new Initiate to the monastery.

        How rude. At least I stayed on topic for this thread, and I actually tried to help the O.P.