diff --git a/stty.py b/stty.py new file mode 100644 index 0000000..912834c --- /dev/null +++ b/stty.py @@ -0,0 +1,12 @@ +import subprocess + +def stty(raw=None, echo=None): + args = ['stty'] + + if raw is not None: + args.append('raw' if raw else '-raw') + + if echo is not None: + args.append('echo' if echo else '-echo') + + subprocess.run(args) diff --git a/worm.py b/worm.py index 268f785..de31a40 100755 --- a/worm.py +++ b/worm.py @@ -10,6 +10,7 @@ import os import argparse import json import info +import stty from blessings import Terminal @@ -211,15 +212,15 @@ except (FileNotFoundError, IsFullScreen): try: with term.fullscreen(): - os.system('stty raw -echo') + stty.stty(raw=True, echo=False) draw_frame() while True: if do_help: for info in (info_1, info_2): - os.system('stty -raw') + stty.stty(raw=False) print(info, end='') sys.stdout.flush() - os.system('stty raw') + stty.stty(raw=True) k = await_keys('cC') if k in '': @@ -241,7 +242,7 @@ except RanIntoSomethingError: os.unlink(gamesave_path) except FileNotFoundError: pass - os.system('stty -raw echo') + stty.stty(raw=False, echo=True) print('', end='\r\n') if size + 1 >= (height-3) * (width-1): print('You won!', end='\r\n') @@ -250,4 +251,4 @@ except RanIntoSomethingError: print(f'Your final score was {score}', end='\r\n') print('', end='\r\n') finally: - os.system('stty -raw echo') + stty.stty(raw=False, echo=True)