diff options
Diffstat (limited to 'urwid/vterm.py')
-rw-r--r-- | urwid/vterm.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/urwid/vterm.py b/urwid/vterm.py index 0c91ca5..05d0c83 100644 --- a/urwid/vterm.py +++ b/urwid/vterm.py @@ -47,6 +47,7 @@ from urwid.widget import Widget, BOX from urwid.display_common import AttrSpec, RealTerminal, _BASIC_COLORS from urwid.compat import ord2, chr2, B, bytes, PYTHON3, xrange +EOF = B('') ESC = chr(27) KEY_TRANSLATIONS = { @@ -1324,7 +1325,8 @@ class Terminal(Widget): signals = ['closed', 'beep', 'leds', 'title'] - def __init__(self, command, env=None, main_loop=None, escape_sequence=None): + def __init__(self, command, env=None, main_loop=None, escape_sequence=None, + encoding='ascii'): """ A terminal emulator within a widget. @@ -1342,6 +1344,13 @@ class Terminal(Widget): 'escape_sequence' is the urwid key symbol which should be used to break out of the terminal widget. If it's not specified, "ctrl a" is used. + + 'encoding' specifies the encoding that is being used when local + keypresses in Unicode are encoded into raw bytes. The default encoding + is 'ascii' for backwards compatibility with urwid versions <= 2.0.1. + Set this to the encoding of your terminal (typically 'utf8') if you + want to be able to transmit non-ASCII characters to the spawned process. + Applies to Python 3.x only. """ self.__super.__init__() @@ -1360,6 +1369,8 @@ class Terminal(Widget): else: self.command = command + self.encoding = encoding + self.keygrab = False self.last_key = None @@ -1530,19 +1541,19 @@ class Terminal(Widget): self.feed() def feed(self): - data = '' + data = EOF try: data = os.read(self.master, 4096) except OSError as e: if e.errno == 5: # End Of File - data = '' + data = EOF elif e.errno == errno.EWOULDBLOCK: # empty buffer return else: raise - if data == '': # EOF on BSD + if data == EOF: # EOF on BSD self.terminate() self._emit('closed') return @@ -1623,6 +1634,6 @@ class Terminal(Widget): key += "\x0a" if PYTHON3: - key = key.encode('ascii') + key = key.encode(self.encoding, 'ignore') os.write(self.master, key) |