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