Start work on unicode input kitten
This commit is contained in:
parent
bf5b0070c1
commit
ef9a24932f
@ -137,7 +137,7 @@ class Loop:
|
||||
self.iov_limit = os.sysconf('SC_IOV_MAX') - 1
|
||||
except Exception:
|
||||
self.iov_limit = 255
|
||||
self.parse_input_from_terminal = partial(parse_input_from_terminal, self._on_text, self._on_dcs, self._on_csi, self.on_osc, self._on_pm, self._on_apc)
|
||||
self.parse_input_from_terminal = partial(parse_input_from_terminal, self._on_text, self._on_dcs, self._on_csi, self._on_osc, self._on_pm, self._on_apc)
|
||||
self.ebs_pat = re.compile('([\177\r\x03\x04])')
|
||||
self.in_bracketed_paste = False
|
||||
self.sanitize_bracketed_paste = bool(sanitize_bracketed_paste)
|
||||
@ -202,6 +202,9 @@ class Loop:
|
||||
def _on_pm(self, pm):
|
||||
pass
|
||||
|
||||
def _on_osc(self, osc):
|
||||
pass
|
||||
|
||||
def _on_apc(self, apc):
|
||||
if apc.startswith('K'):
|
||||
try:
|
||||
@ -272,6 +275,12 @@ class Loop:
|
||||
def wakeup(self):
|
||||
self._wakeup_write(b'1')
|
||||
|
||||
def _modify_output_selector(self, waiting_for_write):
|
||||
if waiting_for_write:
|
||||
self.sel.register(self.output_fd, selectors.EVENT_WRITE)
|
||||
else:
|
||||
self.sel.unregister(self.output_fd)
|
||||
|
||||
def loop(self, handler):
|
||||
select = self.sel.select
|
||||
tb = None
|
||||
@ -288,10 +297,7 @@ class Loop:
|
||||
break
|
||||
if has_data_to_write != waiting_for_write:
|
||||
waiting_for_write = has_data_to_write
|
||||
self.sel.modify(
|
||||
self.output_fd, selectors.EVENT_WRITE
|
||||
if waiting_for_write else 0, self._write_ready
|
||||
)
|
||||
self._modify_output_selector(waiting_for_write)
|
||||
events = select()
|
||||
for key, mask in events:
|
||||
try:
|
||||
@ -316,10 +322,7 @@ class Loop:
|
||||
break
|
||||
if has_data_to_write != waiting_for_write:
|
||||
waiting_for_write = has_data_to_write
|
||||
self.sel.modify(
|
||||
self.output_fd, selectors.EVENT_WRITE
|
||||
if waiting_for_write else 0, self._write_ready
|
||||
)
|
||||
self._modify_output_selector(waiting_for_write)
|
||||
events = select()
|
||||
for key, mask in events:
|
||||
key.data(handler)
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
from kitty.terminfo import string_capabilities
|
||||
|
||||
S7C1T = b'\033 F'
|
||||
SAVE_CURSOR = b'\0337'
|
||||
RESTORE_CURSOR = b'\0338'
|
||||
@ -40,6 +42,10 @@ def reset_mode(which):
|
||||
return '\033[{}{}l'.format(private, num).encode('ascii')
|
||||
|
||||
|
||||
def clear_screen():
|
||||
return string_capabilities['clear'].replace(r'\E', '\033').encode('ascii')
|
||||
|
||||
|
||||
def init_state(alternate_screen=True):
|
||||
ans = (
|
||||
S7C1T + SAVE_CURSOR + SAVE_PRIVATE_MODE_VALUES + reset_mode('LNM') +
|
||||
@ -53,6 +59,7 @@ def init_state(alternate_screen=True):
|
||||
)
|
||||
if alternate_screen:
|
||||
ans += set_mode('ALTERNATE_SCREEN')
|
||||
ans += clear_screen()
|
||||
return ans
|
||||
|
||||
|
||||
|
||||
0
kittens/unicode_input/__init__.py
Normal file
0
kittens/unicode_input/__init__.py
Normal file
27
kittens/unicode_input/main.py
Normal file
27
kittens/unicode_input/main.py
Normal file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import sys
|
||||
|
||||
from ..tui.handler import Handler
|
||||
from ..tui.loop import Loop
|
||||
|
||||
|
||||
class UnicodeInput(Handler):
|
||||
|
||||
def initialize(self, *args):
|
||||
Handler.initialize(self, *args)
|
||||
self.write('Testing 123...')
|
||||
|
||||
def on_interrupt(self):
|
||||
self.quit_loop(1)
|
||||
|
||||
def on_eot(self):
|
||||
self.quit_loop(1)
|
||||
|
||||
|
||||
def main(args=sys.argv):
|
||||
loop = Loop()
|
||||
handler = UnicodeInput()
|
||||
loop.loop(handler)
|
||||
Loading…
x
Reference in New Issue
Block a user