From c3162bec586619de935ac1d9801e4332cead9969 Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Wed, 5 Jun 2019 13:20:44 +0200 Subject: menuconfig: Only decode curses.erasechar() on Python 3 Avoids turning it into a Unicode string on Python 2, which gets messy when strings are compared. --- menuconfig.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'menuconfig.py') diff --git a/menuconfig.py b/menuconfig.py index c5ea23d..40689e8 100755 --- a/menuconfig.py +++ b/menuconfig.py @@ -957,10 +957,12 @@ def _init(): # Looking for this in addition to KEY_BACKSPACE (which is unreliable) makes # backspace work with TERM=vt100. That makes it likely to work in sane # environments. - # - # erasechar() returns a 'bytes' object. Since we use get_wch(), we need to - # decode it. Just give up and avoid crashing if it can't be decoded. - _ERASE_CHAR = curses.erasechar().decode("utf-8", "ignore") + _ERASE_CHAR = curses.erasechar() + if sys.version_info[0] >= 3: + # erasechar() returns a one-byte bytes object on Python 3. This sets + # _ERASE_CHAR to a blank string if it can't be decoded, which should be + # harmless. + _ERASE_CHAR = _ERASE_CHAR.decode("utf-8", "ignore") _init_styles() -- cgit v1.2.3