Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [
- TODO
- write code for these:
- Tkinter
- Verify that all code samples render at the same coordinates - double-check 0-indexed vs 1-indexed and x-y order
- Verify that all code samples work in 2.7 and 3.X, or that dual versions exist
- ]
- Q: How do I draw text anywhere I want on the console?
- You can draw text anywhere on the screen by positioning the cursor and then using `print` or `sys.stdout.write` as normal. How this can be done, varies on the OS you're using, and possibly on how you're trying to position the cursor.
- === `curses` (Linux & Mac) ===
- The built-in `curses` module has a method specifically for moving the cursor. Unfortunately, this module is not available on Windows.
- [TODO - insert `curses` code here]
- === ANSI escape sequences (Linux & Mac) ===
- Some consoles will interpret certain sequences of characters as a signal to change the properties of the console. One such property is the cursor's position. Unfortunately, The Windows command prompt is not one of those consoles.
- [TODO - insert ANSI escape sequences code here]
- === The win32 API (Windows) ===
- You can directly access the Windows handle of the console and call `SetConsoleCursorPosition` on it. If you have [pywin 32](https://sourceforge.net/projects/pywin32/) [installed](http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32), most of the heavy lifting is done for you:
- [TODO - insert pywin demo code here]
- But if you refuse to use a third-party library, you can use `ctypes` to interface with `windll` directly:
- [TODO - insert ctypes demo code here]
- === Third Party Libraries (any OS) ===
- [`colorama`](https://pypi.python.org/pypi/colorama) implements ANSI escape sequences for Windows:
- [TODO - insert colorama demo code here]
- And [`unicurses`](https://sourceforge.net/projects/pyunicurses/) implements `curses` for Windows*.
- [TODO - insert unicurses demo code here]
- These may be preferable if you want your code to execute on any OS, without having to write any OS-specific code yourself.
- === Escape Sequences `"\r"` or `"\b"` (any OS, limited functionality) ===
- This is the easiest approach of the bunch, but it can only move the cursor farther left on the line it is already on - you can't move up!
- `"\r"`, the carriage return escape sequence, moves the cursor to the leftmost column.
- [TODO - insert carriage return code here]
- `"\b"` moves the cursor one space to the left.
- [TODO - insert backspace code here]
- This is primarily useful for creating countdown timers or loading bars.
- [TODO - countdown timer / loading bar demo]
- === Writing Your Own GUI ===
- [TODO - write this section]
- [TODO - figure out if markup engine has a footnote feature]
- *requires [pdcurses.dll](https://sourceforge.net/projects/pdcurses/files/pdcurses/) in the current working directory.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement