summary refs log tree commit diff stats
path: root/ranger
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 /ranger
parentfd24310233f24fe164343ab44171172543f40cd5 (diff)
downloadranger-adaaf378182e3e303e46c1071f048befe6ddd06d.tar.gz
widgets.console: increased efficience
Diffstat (limited to 'ranger')
-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):
'>46 47 48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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