Curses, foiled again (part 1)by strredwolf (Chaplain)
|on Jul 17, 2011 at 16:02 UTC||Need Help??|
If many monks here know, there's been a bit of a problem with the Curses module. It's not that it's good, it's more like it's not well documented -- in terms of "I'm new to Curses/NCurses! What do I do?!?"
Now, I hear a ton of monks say "For the love of Larry, 'perldoc Curses'!!!" To those heathens, read the doc and tell me how to actually use it. You can't. It only describes that it's a wrapper around Curses/NCurses!
Then another ton say "'man curses', you fool!" to which I smack them upside the head, because the Curses module attempts to make things saner than just the C library!.
Unfortunately, something has been lost in the translation. For instance, take the getch() routine. In C, it returns an integer ranging from -1 (ERR) to at least 511 (for special keys such as up, down, left, right, home, end, etc). In Perl, -1 and anything over 255 are returned as that integer; everything else is returned as a character! I had to dig through the source code to find that quirk out!
And thus, after two nights of wracking my brain and raging against the machine, I have this lovely example done on the way to create a replacement to Sirc's ssfe C screen handler.
The gist of this example is this: I'm accepting basic input (BS/DEL works), and on the ENTER key send the bottom buffer up to the top.
You'll note that I don't use POE. I looked at POE, and it looked rather complicated for what I was trying to do. I was also looking at AnyEvent as well, but for something to hack together, a good old IO::Select loop felt much more comfortable.
I'll clean this up a bit and comment it up more in future posts.
Information doesn't want to be free. It wants to be feline.