Basic unicode input works

This commit is contained in:
Kovid Goyal
2018-02-08 22:16:39 +05:30
parent ac02e053ee
commit 194454715f
4 changed files with 99 additions and 2 deletions

View File

@@ -34,3 +34,7 @@ class Handler:
if isinstance(data, str):
data = data.encode('utf-8')
self.write_buf.append(data)
def print(self, *args, sep=' ', end='\r\n'):
data = sep.join(map(str, args)) + end
self.write(data)

View File

@@ -303,8 +303,14 @@ class Loop:
signal.signal(signal.SIGTERM, self._on_sigterm)
signal.signal(signal.SIGINT, self._on_sigint)
handler.write_buf = []
handler.initialize(screen_size(), self.quit, self.wakeup)
keep_going = True
try:
handler.initialize(screen_size(), self.quit, self.wakeup)
except Exception:
import traceback
tb = traceback.format_exc()
self.return_code = 1
keep_going = False
while keep_going:
has_data_to_write = bool(handler.write_buf)
if not has_data_to_write and not self.read_allowed:

View File

@@ -46,6 +46,28 @@ def clear_screen():
return string_capabilities['clear'].replace(r'\E', '\033').encode('ascii')
def set_window_title(value):
return ('\033]2;' + value.replace('\033', '').replace('\x9c', '') + '\033\\').encode('utf-8')
def set_line_wrapping(yes_or_no):
return (set_mode if yes_or_no else reset_mode)('DECAWM')
STANDARD_COLORS = {name: i for i, name in enumerate(
'black red green yellow blue magenta cyan gray'.split())}
def colored(text, color, intense=False):
if isinstance(color, str):
e = (90 if intense else 30) + STANDARD_COLORS[color]
elif isinstance(color, int):
e = '38:5:{}'.format(max(0, min(color, 255)))
else:
e = '38:2:{}:{}:{}'.format(*color)
return '\033[{}m{}\033[39m'.format(e, text)
def init_state(alternate_screen=True):
ans = (
S7C1T + SAVE_CURSOR + SAVE_PRIVATE_MODE_VALUES + reset_mode('LNM') +