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

So, after patching and building Curses.pm for Perl-5.8, I finally came to the conclusion that nothing I could do was going to make Term::ANSIColor work within a Curses window. This, however, is a surmountable problem, as once I found my bug, I was able to do all the text colorization in my interactive section through curses. It offends my sense of neatness somewhat to be using cursrs color in the interactive part and Term::ANSIColor in the non-interactive part, but that's the price for having output in the non-interactive part of the program be persistent on the terminal after the program exits. My reading and writing threads are playing nicely, ICBM talks to the ICB server properly ... the only major technical problem that now appears to lie before me is another interaction issue, this time trying to get Term::ReadLine and Curses.pm to play nicely together. From there on, it's just glue code and parsing.

I want to have readline-based editing in my input window, while restricting its effects to that particular curses window (occupying the bottom four lines of the terminal). It doesn't appear I can do this with Term::ReadLine, because I don't know any way to tell Term::ReadLine that I want the term object created in the existing curses window object. However, actualization is falling short of the goal. I can't clear my input window after the user hits enter, because the text typed in readline isn't "in" the window, but on top of it; and while I want text in the input window to just scroll up into invisibility if it exceeds four lines, what actually happens is the area of typed text grows upward, scrolling my other two windows above it (the server output window and the status line) to be pushed upwards, whereupon curses loses track of where they're supposed to be.

(Another minor oddity is that Term::Readline silently eats the first character of everything I type and does not display it, though it's present in the buffer returned from $term->readline.)

I'm about ready to abandon Term::ReadLine and implement my own readline-like functions using Term::ReadKey. Before I set off on this venture, am I needlessly reinventing the wheel? Is there a better way to do this? Is there some provision in curses itself for interactive input, or some undocumented trick that I can use to tell Term::ReadLine it lives strictly in its assigned curses window, not in the terminal as a whole?

Replies are listed 'Best First'.
Re: On to ... Curses and Term::ReadLine
by bbfu (Curate) on May 08, 2003 at 18:26 UTC

    I've never used Curses, so unfortunately I can't help you there. But I wanted to mention that, before you abandon Term::ReadLine completely, it may be easier to simply modify Term::ReadLine::Perl, a Pure Perl implementation of Term::ReadLine, than to create your own from scratch. Again, however, I've never used Curses so it may turn out to be more trouble to modify than it's worth, especially if you need only a limited subset of features from your readline. But regardless, Term::ReadLine::Perl is probably a good place to start, even if just for a good idea how to re-implement it.

    bbfu
    Black flowers blossom
    Fearless on my breath

      I do indeed need only a limited feature set. Basically I need emacs-style input editing, history, and a somewhat specialized tab-completion.
      I'll look at Term::ReadLine::Perl and see if it does what I need or if it shows me how to do what I need. Thanks for the suggestion.