From adaaf378182e3e303e46c1071f048befe6ddd06d Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 2 Oct 2011 14:23:24 +0200 Subject: widgets.console: increased efficience --- ranger/ext/widestring.py | 8 -------- ranger/gui/widgets/console.py | 20 ++++++++++++-------- 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): -- cgit 1.4.1-2-gfad0 artik/mu/plain/046tangle.cc?h=main&id=d1bd0439220356d764a6ef0ae16e7256d72f7f7e'>plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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