Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

OO Curses Messes Up Console on Exit

by dvergin (Monsignor)
on Jan 20, 2003 at 04:15 UTC ( [id://228280]=perlquestion: print w/replies, xml ) Need Help??

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

I have a command line tool that needs to be take on a spiffed-up UI. So I figured this would be a good time to get to know Curses.

The following script works as desired. It clears the screen, displays "foo" in the appropriate place. And then restores the console screen as it was before the program ran.

#!/usr/bin/perl -w use strict; use Curses; initscr(); addstr(10, 10, "foo"); refresh(); sleep 2; endwin();
On the other hand, this next script is less well-behaved. After displaying "foo" and waiting 2 seconds, it complains "Curses function 'endwin' called with too many arguments at ./curses.pl line 10." and then leaves the console session in what I would describe as no_echo, no_eol mode (blindly typing 'ls -l' gives me a dir listing with no eol chars).
#!/usr/bin/perl -w use strict; use Curses; initscr(); # omit this line for same result my $win = new Curses; #$win->initscr(); # including this causes no display $win->addstr(10, 10, 'foo'); $win->refresh(); sleep 2; $win->endwin();
I would be glad for...
  • An explanation of why script #2 is messing up
  • A clue as to how to fix it
  • A reference to some docs that really explain the various Curses functions and how to use this module's OO style properly. (I have read 'perldoc Curses' and 'man Curses' as well as several Googled pages and just get the run-around.)
TIA,
David

Replies are listed 'Best First'.
Re: OO Curses Messes Up Console on Exit
by Paladin (Vicar) on Jan 20, 2003 at 05:15 UTC

    When I was messing around with Curses, I used the C docs, the Perl docs, and mostly just played around and tested things.

    One thing I used that was handy was:

    END { endwin(); }
    at the top of my script, so if the script died for some reason (ie. SIGINT, die, etc.) instead of finishing properly endwin() would still be called and not mess up my display.
Re: OO Curses Messes Up Console on Exit
by jepri (Parson) on Jan 20, 2003 at 04:57 UTC
    Change $win->endwin(); to endwin();

    The curses library itself is not OO, but the perl wrapper is. Clearly the two aren't sitting quite right.

    update: There are no good docs for curses. You kinda have to guess a lot. Reading the examples is about the best way to do it. And you have it easy - the C docs are much worse.

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://228280]
Approved by ibanix
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (2)
As of 2024-04-26 05:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found