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 would suggest looking into the
cursesmodule. It’s an interface to thencurseslibrary, 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 thecursesmodule, 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
cursesmodule is only available on *nix systems. Per the documentation: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.