summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-12-21 22:30:32 +0100
committerhut <hut@lavabit.com>2010-12-21 22:30:32 +0100
commita5cd2deeb4cda0ab941365cbd207115cc27f8f3e (patch)
treec79e637e99722a5a78858be8985be51028610c39
parent32944f0554eafe0b091967a7669bf25d704f68bb (diff)
downloadranger-a5cd2deeb4cda0ab941365cbd207115cc27f8f3e.tar.gz
widgets.console: Fixed position of cursor with unicode chars (py3)
-rw-r--r--ranger/ext/utfwidth.py4
-rw-r--r--ranger/gui/widgets/console.py6
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))
='#n166'>166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304