diff options
author | hut <hut@lavabit.com> | 2010-12-21 22:30:32 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-12-21 22:30:32 +0100 |
commit | a5cd2deeb4cda0ab941365cbd207115cc27f8f3e (patch) | |
tree | c79e637e99722a5a78858be8985be51028610c39 | |
parent | 32944f0554eafe0b091967a7669bf25d704f68bb (diff) | |
download | ranger-a5cd2deeb4cda0ab941365cbd207115cc27f8f3e.tar.gz |
widgets.console: Fixed position of cursor with unicode chars (py3)
-rw-r--r-- | ranger/ext/utfwidth.py | 4 | ||||
-rw-r--r-- | ranger/gui/widgets/console.py | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/ranger/ext/utfwidth.py b/ranger/ext/utfwidth.py index a506c676..0976fee1 100644 --- a/ranger/ext/utfwidth.py +++ b/ranger/ext/utfwidth.py @@ -58,9 +58,13 @@ def utf_byte_length(string): return 4 return 1 # invalid + def utf_char_width(string): """Return the width of a single character""" u = _utf_char_to_int(string) + return utf_char_width_(u) + +def utf_char_width_(u): if u < 0x1100: return NARROW # Hangul Jamo init. constonants diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py index b3b0a94d..5fdfa4f5 100644 --- a/ranger/gui/widgets/console.py +++ b/ranger/gui/widgets/console.py @@ -25,7 +25,7 @@ from collections import deque from . import Widget from ranger.container.keymap import CommandArgs from ranger.ext.direction import Direction -from ranger.ext.utfwidth import uwid, uchars +from ranger.ext.utfwidth import uwid, uchars, utf_char_width_ from ranger.container import History from ranger.container.history import HistoryEmptyException import ranger @@ -85,11 +85,13 @@ class Console(Widget): self.addstr(self.line[overflow:]) else: self.addstr(self.line) + self.addstr(self.displayed_line) def finalize(self): try: if self.fm.py3: - xpos = self.pos + len(self.prompt) + xpos = sum(utf_char_width_(ord(c)) for c in self.line[0:self.pos]) \ + + len(self.prompt) else: xpos = uwid(self.line[0:self.pos]) + len(self.prompt) self.fm.ui.win.move(self.y, self.x + min(self.wid-1, xpos)) |