summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-02 14:23:24 +0200
committerhut <hut@lavabit.com>2011-10-02 14:23:24 +0200
commitadaaf378182e3e303e46c1071f048befe6ddd06d (patch)
tree85ae40ca0e1b993cd2b528c6125e5c52f8d67476
parentfd24310233f24fe164343ab44171172543f40cd5 (diff)
downloadranger-adaaf378182e3e303e46c1071f048befe6ddd06d.tar.gz
widgets.console: increased efficience
-rw-r--r--ranger/ext/widestring.py8
-rw-r--r--ranger/gui/widgets/console.py20
2 files changed, 12 insertions, 16 deletions
diff --git a/ranger/ext/widestring.py b/ranger/ext/widestring.py
index a17e7649..8986be61 100644
--- a/ranger/ext/widestring.py
+++ b/ranger/ext/widestring.py
@@ -30,14 +30,6 @@ def uwid(string):
 	return sum(utf_char_width(c) for c in string)
 
 
-def uchars(string):
-	"""Return a list of characters in a string"""
-	if not PY3:
-		string = string.decode('utf-8', 'ignore')
-		return [c.encode('utf-8', 'ignore') for c in string]
-	return list(string)
-
-
 def utf_char_width(string):
 	"""Return the width of a single character"""
 	if east_asian_width(string) in WIDE_SYMBOLS:
diff --git a/ranger/gui/widgets/console.py b/ranger/gui/widgets/console.py
index ecf6f557..127bd7ad 100644
--- a/ranger/gui/widgets/console.py
+++ b/ranger/gui/widgets/console.py
@@ -24,7 +24,7 @@ from collections import deque
 
 from . import Widget
 from ranger.ext.direction import Direction
-from ranger.ext.widestring import uwid, uchars
+from ranger.ext.widestring import uwid
 from ranger.container import History
 from ranger.container.history import HistoryEmptyException
 import ranger
@@ -214,14 +214,18 @@ class Console(Widget):
 						maximum=len(self.line) + 1,
 						current=self.pos)
 			else:
-				uc = uchars(self.line)
-				upos = len(uchars(self.line[:self.pos]))
+				if self.fm.py3:
+					uc = list(self.line)
+					upos = len(self.line[:self.pos])
+				else:
+					uc = list(self.line.decode('utf-8', 'ignore'))
+					upos = len(self.line[:self.pos].decode('utf-8', 'ignore'))
 				newupos = direction.move(
 						direction=direction.right(),
 						minimum=0,
 						maximum=len(uc) + 1,
 						current=upos)
-				self.pos = len(''.join(uc[:newupos]))
+				self.pos = len(''.join(uc[:newupos]).encode('utf-8', 'ignore'))
 
 	def delete_rest(self, direction):
 		self.tab_deque = None
@@ -279,11 +283,11 @@ class Console(Widget):
 			self.pos = len(left_part)
 			self.line = left_part + self.line[self.pos + 1:]
 		else:
-			uc = uchars(self.line)
-			upos = len(uchars(self.line[:self.pos])) + mod
-			left_part = ''.join(uc[:upos])
+			uc = list(self.line.decode('utf-8', 'ignore'))
+			upos = len(self.line[:self.pos].decode('utf-8', 'ignore')) + mod
+			left_part = ''.join(uc[:upos]).encode('utf-8', 'ignore')
 			self.pos = len(left_part)
-			self.line = left_part + ''.join(uc[upos+1:])
+			self.line = left_part + ''.join(uc[upos+1:]).encode('utf-8', 'ignore')
 		self.on_line_change()
 
 	def execute(self, cmd=None):