Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Strange Curses behaviour

by duncs (Beadle)
on Nov 02, 2015 at 14:06 UTC ( #1146715=perlquestion: print w/replies, xml ) Need Help??
duncs has asked for the wisdom of the Perl Monks concerning the following question:

I am seeing "strange" behaviour when trying to grab user input within Curses v1.32.

I have created a small window and put some text in it, then drawn a box around the window - this works fine until I add the code to get input from the user, after which the box is no longer drawn.

I have seen this on Debian Jessie, Debian Lenny and RHEL-6.

Below is a small code example displaying this behaviour. If you run this code without args a box is drawn around the window. Provide an arg to the script so user input is sought and the box is no longer drawn around the window.

Any Curses guru's shed any light on this for me?

#!/usr/bin/perl use strict; use warnings; use Curses; END{ endwin(); }; initscr; curs_set(0); clear(); noecho(); halfdelay(30); my $win1 = Curses->new( 7, 30, 5, 5); $win1->box(ACS_VLINE, ACS_HLINE); my $char = -1; while(1) { $win1->addstr( 2, 2, scalar(localtime)); $win1->addstr( 4, 10, "Char: $char "); $win1->refresh; if(!@ARGV) { sleep 3; } else { $char = getch(); } }

Thanks

Duncs

Replies are listed 'Best First'.
Re: Strange Curses behaviour
by Anonymous Monk on Nov 02, 2015 at 19:53 UTC
    #!/usr/bin/perl # http://perlmonks.org/?node_id=1146715 use strict; use warnings; use Curses; END{ endwin(); }; initscr; curs_set(0); clear(); noecho(); halfdelay(30); my $win1 = Curses->new( 7, 30, 5, 5); refresh(); ########################### Curses seems to need this line $win1->box(ACS_VLINE, ACS_HLINE); my $char = -1; while(1) { $win1->addstr( 2, 2, scalar(localtime)); $win1->addstr( 4, 10, "Char: $char "); $win1->refresh; if(!@ARGV) { sleep 3; } else { $char = getch(); } }

      Thank you - this has fixed my issue, although I don't understand why :)

      Using refresh on the window itself exhibits the same behaviour, as though this needs a global screen refresh before doing anything else.

      Thanks

      Duncs

Re: Strange Curses behaviour
by thmsdrew (Scribe) on Nov 02, 2015 at 18:42 UTC

    I believe you want to use getc. I don't think getch is a thing in Perl.

      I don't think getch is a thing in Perl.

      It exists in Curses though.

      Cheers, Sören

      Créateur des bugs mobiles - let loose once, run everywhere.
      (hooked on the Perl Programming language)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1146715]
Front-paged by Arunbear
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2018-07-16 01:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (330 votes). Check out past polls.

    Notices?