3

This is quite a complex question, but I'm hoping there may be a library to quickly accomplish what I'm looking to do.

The best way for me to start to explain this is with an example of desired output:

+------------------------------------------------+
| TESTAPP v0.1 (C) Test Company          Running |
| ---------------------------------------------- |
| info: This is a logged message.                |
| input: user typed "hello"                      |
| info: This is a logged message.                |
| debug: option 1 code 2 value 3                 |
| info: The debug line was just printed.         |
| --Status: [Opts 1] [Codes 5] [Values 11]    -- |
| > about to press enter...                      |
+------------------------------------------------+

Parts:

+------------------------------------------------+
| TITLE BAR -- TITLE BAR -- TITLE BAR -- TITLE   |
| ...                                            |
| ...                                            |
| ...scrolling log area...                       |
| ...                                            |
| ...                                            |
| ...                                            |
| STATUS BAR -- STATUS BAR -- STATUS BAR --      |
| > INPUT LINE -- INPUT LINE -- INPUT LINE     < |
+------------------------------------------------+

Here's the key points:

  • A Python program that will go full-screen after launch.
  • The topmost line will be a title bar, that might contain some updateable areas.
  • The line right below the title bar could be a separator (Not necessarily required)
  • The bottommost line will be an input line.
  • The line directly above the input line will be a status line, which would be updated frequently.
  • A line above the status line may be used as a separator, but not necessarily required.
  • The remaining lines in the center of the screen would be a scrolling history view. The application will write lines to this area, and after the area is full the earliest lines will scroll off-screen.
  • A scroll-back buffer would be nice, but is not absolutely essential.
  • Color output would be desirable for the status and title bars, but simple inversion would be acceptable.
  • The input line should support readline-style history and so on.
  • Also, it needs to push and scroll to the left rather than wrapping, so the whole UI doesn't get pushed off-screen if the user types too much text.

Example:

| info: The debug line was just printed.         |
| --Status: [Opts 1] [Codes 5] [Values 11]    -- |
| > ...men to come to the aid of their country._ |
+------------------------------------------------+

Basically, I'm writing a server that I want to be controllable at the console. The simple method of simply putting the server on a thread and starting a raw_input loop means that output from the server to the console easily interrupts the input of text.

For an even more concise example, think irssi or epicII.

I could in theory code all of this myself using the curses library and a LOT of work, but it feels to me that there may be some sort of library, or at least some shortcut, to accomplishing this. I'm not too familiar with the curses library to begin with. Unless there's a really good concise quick-start guide out there, I feel like I'd end up spending more time understanding curses that I have on writing the actual server code. :-)

tshepang
  • 12,111
  • 21
  • 91
  • 136
fdmillion
  • 4,823
  • 7
  • 45
  • 82

1 Answers1

2

Whats wrong with pycurses ? Its just a wrapper around ncurses. Saves reinventing the wheel. More than a few examples out there and additional widgets etc

e.g

In answer to your question there are more than a few libraries that can do that:

A few previous questions that may help:

If you can keep your display code in a separate class it should make it easier if you need to move to having a gui. You might want to look at tkinter as well.

Community
  • 1
  • 1
lxx
  • 1,326
  • 20
  • 30
  • could also use pygame and make testing fun ;-) http://programarcadegames.com/ http://www.pygame.org/ – lxx Feb 25 '14 at 07:01
  • Also book chapter on pycurses http://heather.cs.ucdavis.edu/~matloff/Python/PLN/PyCurses.tex – lxx Feb 25 '14 at 07:06
  • Using the ncurses panels library to define the 3 areas will make your life easier http://docs.python.org/2/library/curses.panel.html – Craig Feb 25 '14 at 14:36