diff options
author | Tamas Nepusz <ntamas@gmail.com> | 2019-06-18 11:22:51 +0200 |
---|---|---|
committer | Tamas Nepusz <ntamas@gmail.com> | 2019-06-18 11:22:51 +0200 |
commit | 331df4505050b51051c7c29de70f1c84f86ed661 (patch) | |
tree | a5298bb303cd029dc717d33ffc2e578abe4ae684 | |
parent | 06986ccdbfa2645a8a075ebfb35b217bdc602a95 (diff) | |
download | urwid-331df4505050b51051c7c29de70f1c84f86ed661.tar.gz |
added support for input encoding in Terminal widget
-rwxr-xr-x | examples/terminal.py | 3 | ||||
-rw-r--r-- | urwid/vterm.py | 14 |
2 files changed, 14 insertions, 3 deletions
diff --git a/examples/terminal.py b/examples/terminal.py index ff30a93..c50656a 100755 --- a/examples/terminal.py +++ b/examples/terminal.py @@ -22,7 +22,8 @@ import urwid def main(): - term = urwid.Terminal(None) + urwid.set_encoding('utf8') + term = urwid.Terminal(None, encoding='utf-8') mainframe = urwid.LineBox( urwid.Pile([ diff --git a/urwid/vterm.py b/urwid/vterm.py index 4e424d9..05d0c83 100644 --- a/urwid/vterm.py +++ b/urwid/vterm.py @@ -1325,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. @@ -1343,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__() @@ -1361,6 +1369,8 @@ class Terminal(Widget): else: self.command = command + self.encoding = encoding + self.keygrab = False self.last_key = None @@ -1624,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) |