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

I'm looking to create an interactive console application with Perl. What I'm really looking for is something similar to a less screen, but where a user could input commands to perform certain functions, and where output could continually be updated on their screen. For instance, they might want to filter the output by pressing "f" and typing in a regex. They might wish to manipulate or filter the output in other ways.

A simple example would be printing information to the screen, and updating it every 5 seconds. I've seen other users emulated this by clearing the console and re-printing the information. What I don't like about this, is that all it does is scroll x amount of blank lines down and re-print the information. So that if you looked at the command prompt history, you would see the information printed and a bunch of blank lines many, many times.

If possible I want it to be like less, where it opens up an interactive screen, yet once the user quits the command prompt history does not show anything. In other words the information stayed exclusively in the less session, and there was no trace of it once the user quit the program. Please let me know if there is a way to do this, or even a module.

Thanks!

Replies are listed 'Best First'.
Re: Interactive "Less Screen" Possible?
by jethro (Monsignor) on Aug 24, 2011 at 01:35 UTC

    One option is the library curses aka ncurses. There seem to be a few CPAN modules to get access to this C library, see Curses.

      Thanks. Is anyone aware of a way to use Term::Cap to "repaint" the screen without scrolling? Basically creating an environment similar to less, where once I quit the information printed is gone with the interactive screen.
Re: Interactive "Less Screen" Possible?
by Marshall (Canon) on Aug 24, 2011 at 17:28 UTC
    A simple example would be printing information to the screen, and updating it every 5 seconds. I've seen other users emulated this by clearing the console and re-printing the information.
    Yes, Perl can do that, you just have to open a pipe to 'more' or 'less' for output. I think that this will be helpful albeit tedious to work thru.. A Good "less" Man Page.

    It is also possible to use Tk or other Graphical application libraries to get even finer control.

    Basically, you are on the right track. If it is possible to do it in 'C', it is possible to do it in Perl. But for this application, I suspect that a scrollable GUI window with text lines will be easier to implement than fiddling around with "less" or "more" screen oriented command characters.