]>
Commit | Line | Data |
---|---|---|
c7c4199b | 1 | Index: src/perl/textui/TextUI.xs |
2 | =================================================================== | |
3 | --- src/perl/textui/TextUI.xs (revision 4874) | |
4 | +++ src/perl/textui/TextUI.xs (working copy) | |
5 | @@ -123,6 +123,14 @@ | |
6 | CODE: | |
7 | gui_entry_set_text(active_entry, str); | |
8 | ||
9 | +void | |
10 | +gui_input_color(pos, len, color) | |
11 | + int pos | |
12 | + int len | |
13 | + int color | |
14 | +CODE: | |
15 | + gui_entry_set_color(active_entry, pos, len, color); | |
16 | + | |
17 | int | |
18 | gui_input_get_pos() | |
19 | CODE: | |
20 | Index: src/fe-text/gui-entry.c | |
21 | =================================================================== | |
22 | --- src/fe-text/gui-entry.c (revision 4874) | |
23 | +++ src/fe-text/gui-entry.c (working copy) | |
24 | @@ -64,6 +64,8 @@ | |
25 | entry->text_alloc = nearest_power(entry->text_alloc+grow_size); | |
26 | entry->text = g_realloc(entry->text, | |
27 | sizeof(unichar) * entry->text_alloc); | |
28 | + entry->colors = g_realloc(entry->colors, | |
29 | + sizeof(int) * entry->text_alloc); | |
30 | } | |
31 | ||
32 | GUI_ENTRY_REC *gui_entry_create(int xpos, int ypos, int width, int utf8) | |
33 | @@ -73,11 +75,12 @@ | |
34 | rec = g_new0(GUI_ENTRY_REC, 1); | |
35 | rec->xpos = xpos; | |
36 | rec->ypos = ypos; | |
37 | - rec->width = width; | |
38 | - rec->text_alloc = 1024; | |
39 | + rec->width = width; | |
40 | + rec->text_alloc = 1024; | |
41 | rec->text = g_new(unichar, rec->text_alloc); | |
42 | - rec->text[0] = '\0'; | |
43 | - rec->utf8 = utf8; | |
44 | + rec->colors = g_new(int, rec->text_alloc); | |
45 | + rec->text[0] = '\0'; | |
46 | + rec->utf8 = utf8; | |
47 | return rec; | |
48 | } | |
49 | ||
50 | @@ -88,7 +91,8 @@ | |
51 | if (active_entry == entry) | |
52 | gui_entry_set_active(NULL); | |
53 | ||
54 | - g_free(entry->text); | |
55 | + g_free(entry->text); | |
56 | + g_free(entry->colors); | |
57 | g_free(entry->prompt); | |
58 | g_free(entry); | |
59 | } | |
bb14f27a | 60 | @@ -227,7 +231,7 @@ |
c7c4199b | 61 | static void gui_entry_draw_from(GUI_ENTRY_REC *entry, int pos) |
62 | { | |
bb14f27a | 63 | int i; |
c7c4199b | 64 | - int xpos, end_xpos; |
c7c4199b | 65 | + int xpos, end_xpos, color; |
66 | ||
67 | xpos = entry->xpos + entry->promptlen + | |
68 | pos2scrpos(entry, pos + entry->scrstart) - | |
bb14f27a | 69 | @@ -237,11 +242,13 @@ |
c7c4199b | 70 | if (xpos > end_xpos) |
71 | return; | |
72 | ||
73 | + color = ATTR_RESET; | |
74 | term_set_color(root_window, ATTR_RESET); | |
75 | term_move(root_window, xpos, entry->ypos); | |
76 | ||
bb14f27a JR |
77 | for (i = entry->scrstart + pos; i < entry->text_len; i++) { |
78 | unichar c = entry->text[i]; | |
79 | + int cc = entry->colors[i]; | |
80 | ||
c7c4199b | 81 | if (entry->hidden) |
82 | xpos++; | |
c7c4199b | 83 | @@ -255,6 +263,11 @@ |
84 | if (xpos > end_xpos) | |
85 | break; | |
86 | ||
bb14f27a JR |
87 | + if (cc != color) { |
88 | + term_set_color(root_window, cc); | |
89 | + color = cc; | |
c7c4199b | 90 | + } |
91 | + | |
92 | if (entry->hidden) | |
93 | term_addch(root_window, ' '); | |
94 | else if (unichar_isprint(*p)) | |
95 | @@ -262,7 +275,7 @@ | |
96 | else { | |
97 | term_set_color(root_window, ATTR_RESET|ATTR_REVERSE); | |
bb14f27a | 98 | term_addch(root_window, (c & 127)+'A'-1); |
c7c4199b | 99 | - term_set_color(root_window, ATTR_RESET); |
100 | + term_set_color(root_window, color); | |
101 | } | |
102 | } | |
103 | ||
104 | @@ -456,6 +469,10 @@ | |
105 | g_memmove(entry->text + entry->pos + len, entry->text + entry->pos, | |
106 | (entry->text_len-entry->pos + 1) * sizeof(unichar)); | |
107 | ||
108 | + /* make space for the color */ | |
109 | + g_memmove(entry->colors + entry->pos + len, entry->colors + entry->pos, | |
110 | + (entry->text_len-entry->pos) * sizeof(int)); | |
111 | + | |
112 | if (!entry->utf8) { | |
113 | if (term_type == TERM_TYPE_BIG5) { | |
114 | chr = entry->text[entry->pos + len]; | |
115 | @@ -470,6 +487,10 @@ | |
116 | utf8_to_utf16(str, entry->text+entry->pos); | |
117 | entry->text[entry->pos+len] = chr; | |
118 | } | |
119 | + | |
120 | + for (i = 0; i < len; i++) { | |
121 | + entry->colors[entry->pos + i] = ATTR_RESET; | |
122 | + } | |
123 | ||
124 | entry->text_len += len; | |
125 | entry->pos += len; | |
126 | @@ -495,8 +516,13 @@ | |
127 | /* make space for the string */ | |
128 | g_memmove(entry->text + entry->pos + 1, entry->text + entry->pos, | |
129 | (entry->text_len-entry->pos + 1) * sizeof(unichar)); | |
130 | - | |
131 | + | |
132 | + g_memmove(entry->colors + entry->pos + 1, entry->colors + entry->pos, | |
133 | + (entry->text_len-entry->pos) * sizeof(int)); | |
134 | + | |
135 | + | |
136 | entry->text[entry->pos] = chr; | |
137 | + entry->colors[entry->pos] = ATTR_RESET; | |
138 | entry->text_len++; | |
139 | entry->pos++; | |
140 | ||
141 | @@ -571,8 +597,11 @@ | |
142 | w = cell_width(entry->text + entry->pos - size, entry->pos - size + 1)-1; | |
143 | ||
144 | g_memmove(entry->text + entry->pos - size, entry->text + entry->pos, | |
145 | - (entry->text_len-entry->pos+1) * sizeof(unichar)); | |
146 | - | |
147 | + (entry->text_len-entry->pos+1) * sizeof(unichar)); | |
148 | + | |
149 | + g_memmove(entry->colors+ entry->pos - size, entry->colors + entry->pos, | |
150 | + (entry->text_len-entry->pos) * sizeof(int)); | |
151 | + | |
152 | entry->pos -= size; | |
153 | entry->text_len -= size; | |
154 | ||
155 | @@ -592,8 +621,11 @@ | |
156 | mk_wcwidth(entry->text[entry->pos+size]) == 0) size++; | |
157 | ||
158 | g_memmove(entry->text + entry->pos, entry->text + entry->pos + size, | |
159 | - (entry->text_len-entry->pos-size+1) * sizeof(unichar)); | |
160 | - | |
161 | + (entry->text_len-entry->pos-size+1) * sizeof(unichar)); | |
162 | + | |
163 | + g_memmove(entry->colors + entry->pos, entry->colors + entry->pos + size, | |
164 | + (entry->text_len-entry->pos-size) * sizeof(int)); | |
165 | + | |
166 | entry->text_len -= size; | |
167 | ||
168 | gui_entry_redraw_from(entry, entry->pos); | |
169 | @@ -655,6 +687,7 @@ | |
170 | void gui_entry_transpose_chars(GUI_ENTRY_REC *entry) | |
171 | { | |
172 | unichar chr; | |
173 | + int color; | |
174 | ||
175 | if (entry->pos == 0 || entry->text_len < 2) | |
176 | return; | |
177 | @@ -666,7 +699,11 @@ | |
178 | chr = entry->text[entry->pos]; | |
179 | entry->text[entry->pos] = entry->text[entry->pos-1]; | |
180 | entry->text[entry->pos-1] = chr; | |
181 | - | |
182 | + | |
183 | + color = entry->colors[entry->pos]; | |
184 | + entry->colors[entry->pos] = entry->colors[entry->pos-1]; | |
185 | + entry->colors[entry->pos-1] = color; | |
186 | + | |
187 | entry->pos++; | |
188 | ||
189 | gui_entry_redraw_from(entry, entry->pos-2); | |
190 | @@ -703,31 +740,50 @@ | |
191 | /* do wordswap if any found */ | |
192 | if (spos1 < epos1 && epos1 < spos2 && spos2 < epos2) { | |
193 | unichar *first, *sep, *second; | |
194 | + int *first_color, *sep_color, *second_color; | |
195 | int i; | |
196 | ||
197 | first = (unichar *) g_malloc( (epos1 - spos1) * sizeof(unichar) ); | |
198 | sep = (unichar *) g_malloc( (spos2 - epos1) * sizeof(unichar) ); | |
199 | second = (unichar *) g_malloc( (epos2 - spos2) * sizeof(unichar) ); | |
200 | ||
201 | - for (i = spos1; i < epos1; i++) | |
202 | + first_color = (int *) g_malloc( (epos1 - spos1) * sizeof(int) ); | |
203 | + sep_color = (int *) g_malloc( (spos2 - epos1) * sizeof(int) ); | |
204 | + second_color = (int *) g_malloc( (epos2 - spos2) * sizeof(int) ); | |
205 | + | |
206 | + for (i = spos1; i < epos1; i++) { | |
207 | first[i-spos1] = entry->text[i]; | |
208 | - for (i = epos1; i < spos2; i++) | |
209 | + first_color[i-spos1] = entry->colors[i]; | |
210 | + } | |
211 | + for (i = epos1; i < spos2; i++) { | |
212 | sep[i-epos1] = entry->text[i]; | |
213 | - for (i = spos2; i < epos2; i++) | |
214 | + sep_color[i-epos1] = entry->colors[i]; | |
215 | + } | |
216 | + for (i = spos2; i < epos2; i++) { | |
217 | second[i-spos2] = entry->text[i]; | |
218 | + second_color[i-spos2] = entry->colors[i]; | |
219 | + } | |
220 | ||
221 | entry->pos = spos1; | |
222 | - for (i = 0; i < epos2-spos2; i++) | |
223 | + for (i = 0; i < epos2-spos2; i++) { | |
224 | entry->text[entry->pos++] = second[i]; | |
225 | - for (i = 0; i < spos2-epos1; i++) | |
226 | + entry->colors[entry->pos++] = second_color[i]; | |
227 | + } | |
228 | + for (i = 0; i < spos2-epos1; i++) { | |
229 | entry->text[entry->pos++] = sep[i]; | |
230 | - for (i = 0; i < epos1-spos1; i++) | |
231 | + entry->colors[entry->pos++] = sep_color[i]; | |
232 | + } | |
233 | + for (i = 0; i < epos1-spos1; i++) { | |
234 | entry->text[entry->pos++] = first[i]; | |
235 | - | |
236 | + entry->colors[entry->pos++] = first_color[i]; | |
237 | + } | |
238 | + | |
239 | g_free(first); | |
240 | g_free(sep); | |
241 | g_free(second); | |
242 | - | |
243 | + g_free(first_color); | |
244 | + g_free(sep_color); | |
245 | + g_free(second_color); | |
246 | } | |
247 | ||
248 | gui_entry_redraw_from(entry, spos1); | |
249 | @@ -895,3 +951,31 @@ | |
250 | gui_entry_fix_cursor(entry); | |
251 | gui_entry_draw(entry); | |
252 | } | |
253 | + | |
254 | +void gui_entry_set_color(GUI_ENTRY_REC *entry, int pos, int len, int color) | |
255 | +{ | |
256 | + int i, end, update = 0; | |
257 | + | |
258 | + g_return_if_fail(entry != NULL); | |
259 | + | |
260 | + if (pos > entry->text_len) | |
261 | + return; | |
262 | + | |
263 | + end = pos + len; | |
264 | + | |
265 | + if (end > entry->text_len) | |
266 | + end = entry->text_len; | |
267 | + | |
268 | + for (i = pos; i < end; i++) { | |
269 | + if (entry->colors[i] != color) { | |
270 | + entry->colors[i] = color; | |
271 | + update = 1; | |
272 | + } | |
273 | + } | |
274 | + | |
275 | + if (update) { | |
276 | + gui_entry_redraw_from(entry, pos); | |
277 | + gui_entry_fix_cursor(entry); | |
278 | + gui_entry_draw(entry); | |
279 | + } | |
280 | +} | |
281 | Index: src/fe-text/gui-entry.h | |
282 | =================================================================== | |
283 | --- src/fe-text/gui-entry.h (revision 4874) | |
284 | +++ src/fe-text/gui-entry.h (working copy) | |
285 | @@ -4,6 +4,7 @@ | |
286 | typedef struct { | |
287 | int text_len, text_alloc; /* as shorts, not chars */ | |
288 | unichar *text; | |
289 | + int *colors; | |
290 | ||
291 | int cutbuffer_len; | |
292 | unichar *cutbuffer; | |
293 | @@ -60,4 +61,6 @@ | |
294 | ||
295 | void gui_entry_redraw(GUI_ENTRY_REC *entry); | |
296 | ||
297 | +void gui_entry_set_color(GUI_ENTRY_REC *entry, int pos, int len, int color); | |
298 | + | |
299 | #endif |