summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxim Ivanov <ulidtko@gmail.com>2019-12-15 22:10:18 +0200
committerGitHub <noreply@github.com>2019-12-15 22:10:18 +0200
commit294aaabfcc3d47737f70608598023c0ab511ede4 (patch)
tree03acc3139a15939d5622cf80ec6d9ef56bfa7915
parent6dbfe50ca90afdbbc5b234f63f22cd442888f71a (diff)
parent519676ded5774a134dec2b2f99b10b4f108afbd1 (diff)
downloadurwid-294aaabfcc3d47737f70608598023c0ab511ede4.tar.gz
Merge pull request #385 from ulidtko/master
Terminal: use UTF-8 by default.
-rw-r--r--urwid/vterm.py36
1 files changed, 11 insertions, 25 deletions
diff --git a/urwid/vterm.py b/urwid/vterm.py
index cc95b45..7af348a 100644
--- a/urwid/vterm.py
+++ b/urwid/vterm.py
@@ -1319,6 +1319,7 @@ class TermCanvas(Canvas):
return [self.cols()]*self.rows()
return self.content()
+
class Terminal(Widget):
_selectable = True
_sizing = frozenset([BOX])
@@ -1326,7 +1327,7 @@ class Terminal(Widget):
signals = ['closed', 'beep', 'leds', 'title']
def __init__(self, command, env=None, main_loop=None, escape_sequence=None,
- encoding='ascii'):
+ encoding='utf-8'):
"""
A terminal emulator within a widget.
@@ -1346,10 +1347,9 @@ class Terminal(Widget):
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.
+ keypresses in Unicode are encoded into raw bytes. UTF-8 is used by default.
+ Set this to the encoding of your terminal if you need to transmit
+ characters to the spawned process in non-UTF8 encoding.
Applies to Python 3.x only.
.. note::
@@ -1359,22 +1359,13 @@ class Terminal(Widget):
``utf8`` with ``urwid.set_encoding("utf8")``. See
:ref:`text-encodings` for more details.
"""
- self.__super.__init__()
+ Widget.__init__(self)
- if escape_sequence is None:
- self.escape_sequence = "ctrl a"
- else:
- self.escape_sequence = escape_sequence
+ self.escape_sequence = escape_sequence or "ctrl a"
- if env is None:
- self.env = dict(os.environ)
- else:
- self.env = dict(env)
+ self.env = dict(env or os.environ)
- if command is None:
- self.command = [self.env.get('SHELL', '/bin/sh')]
- else:
- self.command = command
+ self.command = command or [self.env.get('SHELL', '/bin/sh')]
self.encoding = encoding
@@ -1525,18 +1516,13 @@ class Terminal(Widget):
def add_watch(self):
if self.main_loop is None:
return
-
self.main_loop.watch_file(self.master, self.feed)
def remove_watch(self):
if self.main_loop is None:
return
-
self.main_loop.remove_watch_file(self.master)
- def selectable(self):
- return True
-
def wait_and_feed(self, timeout=1.0):
while True:
try:
@@ -1553,14 +1539,14 @@ class Terminal(Widget):
try:
data = os.read(self.master, 4096)
except OSError as e:
- if e.errno == 5: # End Of File
+ if e.errno == 5: # EIO, child terminated
data = EOF
elif e.errno == errno.EWOULDBLOCK: # empty buffer
return
else:
raise
- if data == EOF: # EOF on BSD
+ if data == EOF:
self.terminate()
self._emit('closed')
return