When I use the less
command in my Mac Terminal I'm shown a 23 row slice of the specified file. If I move down the file, then scroll up in the terminal window, I don't see any file content before the current slice. Instead, I see the commands I typed before using less
.
I would like to use this or a similar effect to create an ascii game interface that shows only the current screen, with no history. I would draw my frames on screen and change only the text or options within those frames. This is very common in older systems that ran mostly or entirely in a command line environment.
Is there a Python module that offers this? Is it an effect that I can or should implement myself?
Here are some example screen elements that could benefit from this effect.
+-------------------------------------------------------------------+
| |
| Dialog dialog dialog dialog dialog dialog dialog dialog dialog |
| dialog dialog dialog dialog dialog dialog dialog dialog dialog |
| dialog dialog dialog dialog dialog dialog dialog dialog dialog |
| dialog dialog dialog dialog dialog dialog dialog dialog dialog |
| dialog dialog dialog dialog. |
| |
| |
| |
+--------------------+---------------+------------------------------+
| Attack | South | HP/Max MP/Max |
| > Cast Magic | - | Tom: 120/120 60/91 |
| Use Item | New | > Dick: 27/133 47/47 |
| Tactics | Schwartzton | Harry: 87/104 16/113 |
+--------------------+---------------+------------------------------+
I've been struggling with this issue too. I wanted a simple cross platform solution, so I extended asciimatics to provide a set of widgets to create form-based UIs like this. For example:
The resulting code should be quite concise and work on any modern OS (including Windows, Linux and OSX) without installing extra native libraries. As you can see from the contact list sample the standard widgets are easy to lay out and should provide most of your needs.
I would suggest looking into the curses
module. It's an interface to the ncurses
library, which is used for exactly this purpose (I believe many terminal applications are written in it). The documentation is quite decent, and there are several nice tutorials that should also set you in the right direction.
(Either that or liberal use of \r
.) I would strongly suggest the curses
module, since it should provide more flexibility for what you're looking to do.
EDIT: If you're interested in creating a cross-platform application, keep in mind that the curses
module is only available on *nix systems. Per the documentation:
No one has made a Windows port of the curses module.
That tutorial recommends this library for use on Windows, although if the dates on the download page are any indication, it has not been updated in a fair amount of time. You could look into this module, which looks considerably more recent.
What you're talking about is curses
. It is a Python module that interfaces with ncurses. The best tutorial that I've found for using curses
is this one: http://www.dev-explorer.com/articles/python-with-curses
Some popular programs that use curses (albeit from another language) are aptitude and nano.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With