1 --- dml-0.1.6/src/pi.h.old 2007-10-05 09:37:17.000000000 +0200
2 +++ dml-0.1.6/src/pi.h 2007-10-05 10:12:18.000000000 +0200
4 PI_COMMON_DATA(pi_input);
8 + int top, cur, cur_utf8, blen;
13 void pi_frame(int x, int y, int w, int h);
15 unsigned char *pi_putch_utf8(unsigned char *c);
16 +int pi_strlen(char *c);
17 +char *pi_bskip_char(char *begin, char *c);
18 +char *pi_skip_char(char *c, char *end);
19 void pi_addstr(const char *c);
20 void pi_addstrn(const char *c, int n);
21 void pi_addstrn_fill(const char *c, int n);
22 --- dml-0.1.6/src/input.c.old 2007-10-05 09:26:45.000000000 +0200
23 +++ dml-0.1.6/src/input.c 2007-10-05 11:36:12.000000000 +0200
26 void pi_input_draw(struct pi_input *self)
28 - int i, n, w, a = 0, x, y;
30 + int i, n, n2, w, a = 0, x, y;
32 pi_locate((struct pi_object*)self, &x, &y);
34 if ((self->buf[0] == 0) || (self->pass==1)) {
36 pi_is_active((struct pi_object*)self) ?
37 pi_color_input_hl : pi_color_input);
38 if (self->buf[0] == 0)
39 - self->top = self->cur = 0;
40 + self->top = self->cur = self->cur_utf8 = 0;
50 n = strlen(self->buf);
51 + n2 = pi_strlen(self->buf);
56 + if (self->cur_utf8 > n2)
57 + self->cur_utf8 = n2;
64 pi_color(pi_color_input_arrow);
74 pi_color_input_deadly :
75 pi_color_input_hl : pi_color_input);
95 pi_color(self->ghosted ? pi_color_input_ghosted :
96 pi_is_active((struct pi_object*)self) ?
97 pi_color_input_hl : pi_color_input);
104 - pi_goto(x + self->cur - self->top + (self->top != 0), y);
105 + pi_goto(x + self->cur_utf8 - self->top + (self->top != 0), y);
108 void pi_input_kill(struct pi_input *self)
109 @@ -105,36 +110,48 @@
111 void pi_input_key(struct pi_input *self, int key)
118 /* p is char under cursor */
119 p = self->buf + self->cur;
125 + if (self->cur_utf8 > 0) {
127 + p = pi_bskip_char(self->buf, p);
128 + self->cur = p - self->buf;
136 + p = pi_skip_char(p, p + 7);
137 + self->cur = p - self->buf;
145 + p2 = pi_bskip_char(self->buf, p);
146 + self->cur = p2 - self->buf;
148 + memmove(p2, p, strlen(p2));
152 - memmove(p, p + 1, strlen(p));
154 + p2 = pi_skip_char(p, p + 7);
155 + memmove(p, p2, strlen(p));
161 + self->cur = self->cur_utf8 = 0;
164 self->cur = strlen(self->buf);
165 + self->cur_utf8 = pi_strlen(self->buf);
168 if ((key == '\n') && (self->res != 0))
169 @@ -152,24 +169,31 @@
170 p = self->buf + self->cur;
171 memmove(p + 1, p, strlen(p) + 1);
177 pi_object_key((struct pi_object*)self, key);
182 if (self->cur > (int)strlen(self->buf))
183 - self->cur = strlen(self->buf);
185 + self->cur = strlen(self->buf);
186 + if (self->cur_utf8 > (int)pi_strlen(self->buf))
187 + self->cur_utf8 = pi_strlen(self->buf);
190 if (self->top > self->cur)
191 self->top = self->cur;
193 - if (self->cur - self->top > self->pos.w - 2)
194 - self->top = self->cur - self->pos.w + 2;
195 - else if (self->cur - self->top == self->pos.w - 2 &&
197 + if (self->cur_utf8 < 0)
198 + self->cur_utf8 = 0;
199 + if (self->top > self->cur_utf8)
200 + self->top = self->cur_utf8;
202 + if (self->cur_utf8 - self->top > self->pos.w - 2)
203 + self->top = self->cur_utf8 - self->pos.w + 2;
204 + else if (self->cur_utf8 - self->top == self->pos.w - 2 &&
205 self->buf[self->cur])
208 --- dml-0.1.6/src/slang.c.old 2007-10-05 09:38:02.000000000 +0200
209 +++ dml-0.1.6/src/slang.c 2007-10-05 11:35:38.000000000 +0200
214 +int pi_strlen(char *c)
216 + return pi_utf8 ? SLutf8_strlen(c, 0) : strlen(c);
219 +char *pi_bskip_char(char *begin, char *c)
221 + return pi_utf8 ? SLutf8_bskip_char(begin, c) : --c;
224 +char *pi_skip_char(char *c, char *end)
226 + return pi_utf8 ? SLutf8_skip_char(c, end) : ++c;
229 void pi_addstr(const char *c)
231 SLsmg_write_string((char*)c);