diff options
| author | troido <troido@protonmail.com> | 2019-09-16 22:12:29 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2019-09-16 22:12:29 +0200 |
| commit | a0e86c082e8565a48ef14319ee3197abb71e533f (patch) | |
| tree | 895dd2a36fc3f3a98c63f64ab48a86d2fe0ec97a | |
| parent | 32f1eddbc840a96ad3d713c138fa29012dd5006d (diff) | |
replaced curses.wrapper by its code
| -rw-r--r-- | asciifarm/client/main.py | 36 | ||||
| -rw-r--r-- | asciifarm/client/parseargs.py | 1 |
2 files changed, 31 insertions, 6 deletions
diff --git a/asciifarm/client/main.py b/asciifarm/client/main.py index f6cf7e3..c00b592 100644 --- a/asciifarm/client/main.py +++ b/asciifarm/client/main.py @@ -26,7 +26,29 @@ def main(argv=None): os.environ.setdefault("ESCDELAY", "25") - def start(stdscr): + try: + # Initialize curses + stdscr = curses.initscr() + + # Turn off echoing of keys, and enter cbreak mode, + # where no buffering is performed on keyboard input + curses.noecho() + curses.cbreak() + + # In keypad mode, escape sequences for special keys + # (like the cursor keys) will be interpreted and + # a special value like curses.KEY_LEFT will be returned + stdscr.keypad(1) + + # Start color, too. Harmless if the terminal doesn't have + # color; user can test with has_color() later on. The try/catch + # works around a minor bit of over-conscientiousness in the curses + # module -- the error return from C start_color() is ignorable. + try: + curses.start_color() + except: + pass + display = Display(stdscr, characters, colours) client = Client(stdscr, display, name, connection, keybindings, logfile) try: @@ -36,12 +58,16 @@ def main(argv=None): except Exception as e: # throw the execption outside ncurses # so the cleanup can happen first - nonlocal error error = e - nonlocal closeMessage closeMessage = client.closeMessage - - curses.wrapper(start) + finally: + # Set everything back to normal + if 'stdscr' in locals(): + stdscr.keypad(0) + curses.echo() + curses.nocbreak() + curses.endwin() + if error is not None: raise error diff --git a/asciifarm/client/parseargs.py b/asciifarm/client/parseargs.py index a229192..9a73adf 100644 --- a/asciifarm/client/parseargs.py +++ b/asciifarm/client/parseargs.py @@ -6,7 +6,6 @@ import json import os import os.path -from .start import main as clientmain from . import loaders |
