textbox: fix gather for unicode
This commit is contained in:
parent
0a746a1e28
commit
ca72c4683e
|
@ -1,6 +1,5 @@
|
||||||
TODO
|
TODO
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
bug: can't input unicode
|
|
||||||
bug: xterm is borked
|
bug: xterm is borked
|
||||||
dumb rendering mode per site
|
dumb rendering mode per site
|
||||||
well, preferences per site maybe?
|
well, preferences per site maybe?
|
||||||
|
|
|
@ -11,6 +11,7 @@ This version fixes a few quirks of the standard module, namely:
|
||||||
|
|
||||||
- Discard multi-lines mode: only one line is supported.
|
- Discard multi-lines mode: only one line is supported.
|
||||||
- Moving in line more reasonably: no more going alone rightward.
|
- Moving in line more reasonably: no more going alone rightward.
|
||||||
|
- Handle Unicode
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import curses
|
import curses
|
||||||
|
@ -89,14 +90,23 @@ class Textbox:
|
||||||
if backx is not None:
|
if backx is not None:
|
||||||
self.win.move(0, backx)
|
self.win.move(0, backx)
|
||||||
|
|
||||||
|
COMMAND_KEYS = (curses.KEY_LEFT, curses.KEY_RIGHT, curses.KEY_BACKSPACE)
|
||||||
|
|
||||||
def do_command(self, ch):
|
def do_command(self, ch):
|
||||||
"""Process a single editing command."""
|
"""Process a single editing command."""
|
||||||
self._update_maxx()
|
self._update_maxx()
|
||||||
_, x = self.win.getyx()
|
_, x = self.win.getyx()
|
||||||
if curses.ascii.isprint(ch):
|
if curses.ascii.iscntrl(ch) or ch in self.COMMAND_KEYS:
|
||||||
|
return self.do_control(ch, x)
|
||||||
if x < self.maxx:
|
if x < self.maxx:
|
||||||
|
curses.ungetch(ch)
|
||||||
|
ch = self.win.get_wch()
|
||||||
self._insert_printable_char(ch)
|
self._insert_printable_char(ch)
|
||||||
elif ch == curses.ascii.NL:
|
return 1
|
||||||
|
|
||||||
|
def do_control(self, ch, x):
|
||||||
|
"""Process a control character."""
|
||||||
|
if ch == curses.ascii.NL:
|
||||||
return 0
|
return 0
|
||||||
elif ch == curses.ascii.SOH: # ^a
|
elif ch == curses.ascii.SOH: # ^a
|
||||||
self.win.move(0, 0)
|
self.win.move(0, 0)
|
||||||
|
@ -135,12 +145,11 @@ class Textbox:
|
||||||
"""Collect and return the contents of the window."""
|
"""Collect and return the contents of the window."""
|
||||||
result = ""
|
result = ""
|
||||||
self._update_maxx()
|
self._update_maxx()
|
||||||
self.win.move(0, 0)
|
|
||||||
stop = self._end_of_line()
|
stop = self._end_of_line()
|
||||||
for x in range(self.maxx + 1):
|
for x in range(self.maxx + 1):
|
||||||
if self.stripspaces and x > stop:
|
if self.stripspaces and x > stop:
|
||||||
break
|
break
|
||||||
result = result + chr(curses.ascii.ascii(self.win.inch(0, x)))
|
result += chr(self.win.inch(0, x))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def edit(self, validate=None):
|
def edit(self, validate=None):
|
||||||
|
|
Reference in a new issue