diff --git a/helpers.py b/helpers.py index 2b8354a..e2db2da 100644 --- a/helpers.py +++ b/helpers.py @@ -113,14 +113,6 @@ def argmax(d, all=False, value=None): return [k for k in list(d.keys()) if d[k] == d[maxarg]] return maxarg -def safe_str(obj): - ''' - Ugly hack to avoid Python complaining about encodings. - - Call this on any object to turn it into a string which is - (hopefully) safe for printing. - ''' - return obj def less(string): ''' @@ -131,6 +123,6 @@ def less(string): int_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) env = dict(os.environ) env['LESSSECURE'] = '1' - proc = subprocess.Popen('less', env=env, stdin=subprocess.PIPE) - proc.communicate(safe_str(string)) + proc = subprocess.Popen('less', env=env, encoding='utf-8', stdin=subprocess.PIPE) + proc.communicate(string) signal.signal(signal.SIGINT, int_handler) diff --git a/text_interface/buymenu.py b/text_interface/buymenu.py index 1f0fa24..31ec3aa 100644 --- a/text_interface/buymenu.py +++ b/text_interface/buymenu.py @@ -160,6 +160,10 @@ When finished, write an empty line to confirm the purchase.\n''' print(f'USER {t.user.name} HAS LOWER CREDIT THAN {conf.low_credit_warning_limit:d},', 'AND SHOULD CONSIDER PUTTING SOME MONEY IN THE BOX.') + # Superfast mode skips a linebreak for some reason. This looks ugly. + # TODO: Figure out why this happens, and fix it in a less hacky way. + if self.superfast_mode: + print("") return True def complete_input(self): diff --git a/text_interface/helpermenus.py b/text_interface/helpermenus.py index 3e0a7d1..f69e5fe 100644 --- a/text_interface/helpermenus.py +++ b/text_interface/helpermenus.py @@ -9,7 +9,7 @@ from select import select import conf from db import User, Session -from helpers import search_user, search_product, safe_str, guess_data_type, argmax +from helpers import search_user, search_product, guess_data_type, argmax from text_interface import context_commands, local_help_commands, help_commands, \ exit_commands @@ -118,11 +118,9 @@ class Menu(object): return result while True: try: - # result = None - # It is replaced either way if timeout: # assuming line buffering - sys.stdout.write(safe_str(prompt)) + sys.stdout.write(prompt) sys.stdout.flush() rlist, _, _ = select([sys.stdin], [], [], timeout) if not rlist: @@ -131,7 +129,7 @@ class Menu(object): else: result = input().strip() else: - result = input(safe_str(prompt)).strip() + result = input(prompt).strip() except EOFError: print('quit') self.exit_menu() @@ -207,6 +205,7 @@ class Menu(object): print('Please enter a valid choice.') def input_int(self, prompt=None, allowed_range=(None, None), null_allowed=False, default=None): + # TODO: Proper default handling if prompt is None: prompt = self.prompt while True: