41 |
IS_NORM, |
IS_NORM, |
42 |
IS_ESC, |
IS_ESC, |
43 |
IS_CSI, |
IS_CSI, |
44 |
|
IS_CSI2, |
45 |
IS_ESC2, |
IS_ESC2, |
46 |
}; |
}; |
47 |
|
|
104 |
s->charset = &charset_8859_1; |
s->charset = &charset_8859_1; |
105 |
|
|
106 |
#ifndef CONFIG_CYGWIN |
#ifndef CONFIG_CYGWIN |
107 |
|
/* CG: Should also have a command line switch */ |
108 |
/* test UTF8 support by looking at the cursor position (idea from |
/* test UTF8 support by looking at the cursor position (idea from |
109 |
Ricardas Cepas <rch@pub.osf.lt>). Since uClibc actually tests |
Ricardas Cepas <rch@pub.osf.lt>). Since uClibc actually tests |
110 |
to ensure that the format string is a valid multibyte sequence |
to ensure that the format string is a valid multibyte sequence |
199 |
s->clip_y2 = s->height; |
s->clip_y2 = s->height; |
200 |
} |
} |
201 |
|
|
202 |
|
static void term_invalidate(void) |
203 |
|
{ |
204 |
|
tty_resize(0); |
205 |
|
} |
206 |
|
|
207 |
static void term_cursor_at(QEditScreen *s, int x1, int y1, int w, int h) |
static void term_cursor_at(QEditScreen *s, int x1, int y1, int w, int h) |
208 |
{ |
{ |
209 |
TTYState *ts = s->private; |
TTYState *ts = s->private; |
226 |
return 0; |
return 0; |
227 |
} |
} |
228 |
|
|
229 |
|
static int const csi_lookup[] = { |
230 |
|
KEY_NONE, /* 0 */ |
231 |
|
KEY_HOME, /* 1 */ |
232 |
|
KEY_INSERT, /* 2 */ |
233 |
|
KEY_DELETE, /* 3 */ |
234 |
|
KEY_END, /* 4 */ |
235 |
|
KEY_PAGEUP, /* 5 */ |
236 |
|
KEY_PAGEDOWN, /* 6 */ |
237 |
|
KEY_NONE, /* 7 */ |
238 |
|
KEY_NONE, /* 8 */ |
239 |
|
KEY_NONE, /* 9 */ |
240 |
|
KEY_NONE, /* 10 */ |
241 |
|
KEY_F1, /* 11 */ |
242 |
|
KEY_F2, /* 12 */ |
243 |
|
KEY_F3, /* 13 */ |
244 |
|
KEY_F4, /* 14 */ |
245 |
|
KEY_F5, /* 15 */ |
246 |
|
KEY_NONE, /* 16 */ |
247 |
|
KEY_F6, /* 17 */ |
248 |
|
KEY_F7, /* 18 */ |
249 |
|
KEY_F8, /* 19 */ |
250 |
|
KEY_F9, /* 20 */ |
251 |
|
KEY_F10, /* 21 */ |
252 |
|
KEY_NONE, /* 22 */ |
253 |
|
KEY_F11, /* 23 */ |
254 |
|
KEY_F12, /* 24 */ |
255 |
|
KEY_F13, /* 25 */ |
256 |
|
KEY_F14, /* 26 */ |
257 |
|
KEY_NONE, /* 27 */ |
258 |
|
KEY_F15, /* 28 */ |
259 |
|
KEY_F16, /* 29 */ |
260 |
|
KEY_NONE, /* 30 */ |
261 |
|
KEY_F17, /* 31 */ |
262 |
|
KEY_F18, /* 32 */ |
263 |
|
KEY_F19, /* 33 */ |
264 |
|
KEY_F20, /* 34 */ |
265 |
|
}; |
266 |
|
|
267 |
static void tty_read_handler(void *opaque) |
static void tty_read_handler(void *opaque) |
268 |
{ |
{ |
269 |
QEditScreen *s = opaque; |
QEditScreen *s = opaque; |
277 |
if (trace_buffer) { |
if (trace_buffer) { |
278 |
eb_write(trace_buffer, trace_buffer->total_size, |
eb_write(trace_buffer, trace_buffer->total_size, |
279 |
ts->buf + ts->utf8_index, 1); |
ts->buf + ts->utf8_index, 1); |
280 |
|
#if 0 |
281 |
|
ch = ts->buf[ts->utf8_index]; |
282 |
|
if (ch < 32 || ch == 127) |
283 |
|
fprintf(stderr, "got %d '^%c'\n", ch, ('@' + ch) & 127); |
284 |
|
else |
285 |
|
fprintf(stderr, "got %d '%c'\n", ch, ch); |
286 |
|
#endif |
287 |
} |
} |
288 |
|
|
289 |
/* charset handling */ |
/* charset handling */ |
309 |
goto the_end; |
goto the_end; |
310 |
break; |
break; |
311 |
case IS_ESC: |
case IS_ESC: |
312 |
|
if (ch == '\033') { |
313 |
|
/* cygwin A-right transmit ESC ESC[C ... */ |
314 |
|
goto the_end; |
315 |
|
} |
316 |
if (ch == '[') { |
if (ch == '[') { |
317 |
ts->input_state = IS_CSI; |
ts->input_state = IS_CSI; |
318 |
ts->input_param = 0; |
ts->input_param = 0; |
325 |
} |
} |
326 |
break; |
break; |
327 |
case IS_CSI: |
case IS_CSI: |
328 |
if (!isdigit(ch)) { |
if (isdigit(ch)) { |
329 |
ts->input_state = IS_NORM; |
ts->input_param = ts->input_param * 10 + ch - '0'; |
330 |
switch(ch) { |
break; |
331 |
case '~': |
} |
332 |
ch = KEY_ESC1(ts->input_param); |
ts->input_state = IS_NORM; |
333 |
goto the_end; |
switch(ch) { |
334 |
case 'H': |
case '[': |
335 |
ch = KEY_HOME; |
ts->input_state = IS_CSI2; |
336 |
goto the_end; |
break; |
337 |
case 'F': |
case '~': |
338 |
ch = KEY_END; |
if (ts->input_param < sizeof(csi_lookup)/sizeof(csi_lookup[0])) { |
339 |
goto the_end; |
ch = csi_lookup[ts->input_param]; |
|
case 'Z': |
|
|
ch = KEY_SHIFT_TAB; |
|
|
goto the_end; |
|
|
default: |
|
|
/* xterm CTRL-arrows */ |
|
|
if (ts->input_param == 5 && ch >= 'A' && ch <= 'D') |
|
|
ch += 'a' - 'A'; |
|
|
ch = KEY_ESC1(ch); |
|
340 |
goto the_end; |
goto the_end; |
341 |
} |
} |
342 |
} else { |
break; |
343 |
ts->input_param = ts->input_param * 10 + ch - '0'; |
/* All these for ansi|cygwin */ |
344 |
|
case 'A': ch = KEY_UP; goto the_end; // kcuu1 |
345 |
|
case 'B': ch = KEY_DOWN; goto the_end; // kcud1 |
346 |
|
case 'C': ch = KEY_RIGHT; goto the_end; // kcuf1 |
347 |
|
case 'D': ch = KEY_LEFT; goto the_end; // kcub1 |
348 |
|
case 'F': ch = KEY_END; goto the_end; // kend |
349 |
|
//case 'G': ch = KEY_CENTER; goto the_end; // kb2 |
350 |
|
case 'H': ch = KEY_HOME; goto the_end; // khome |
351 |
|
case 'L': ch = KEY_INSERT; goto the_end; // kich1 |
352 |
|
//case 'M': ch = KEY_MOUSE; goto the_end; // kmous |
353 |
|
case 'Z': ch = KEY_SHIFT_TAB; goto the_end; // kcbt |
354 |
|
default: |
355 |
|
#if 0 /* xterm CTRL-arrows */ |
356 |
|
if (ts->input_param == 5) { |
357 |
|
switch (ch) { |
358 |
|
case 'A': ch = KEY_CTRL_UP; goto the_end; |
359 |
|
case 'B': ch = KEY_CTRL_DOWN; goto the_end; |
360 |
|
case 'C': ch = KEY_CTRL_RIGHT; goto the_end; |
361 |
|
case 'D': ch = KEY_CTRL_LEFT; goto the_end; |
362 |
|
} |
363 |
|
} |
364 |
|
#endif |
365 |
|
break; |
366 |
} |
} |
367 |
break; |
break; |
368 |
case IS_ESC2: |
case IS_CSI2: |
369 |
/* xterm fn */ |
/* cygwin/linux terminal */ |
370 |
ts->input_state = IS_NORM; |
ts->input_state = IS_NORM; |
371 |
if (ch >= 'P' && ch <= 'S') { |
switch(ch) { |
372 |
ch = KEY_F1 + ch - 'P'; |
case 'A': ch = KEY_F1; goto the_end; |
373 |
the_end: |
case 'B': ch = KEY_F2; goto the_end; |
374 |
ev->key_event.type = QE_KEY_EVENT; |
case 'C': ch = KEY_F3; goto the_end; |
375 |
ev->key_event.key = ch; |
case 'D': ch = KEY_F4; goto the_end; |
376 |
qe_handle_event(ev); |
case 'E': ch = KEY_F5; goto the_end; |
377 |
} |
} |
378 |
break; |
break; |
379 |
|
case IS_ESC2: // "\EO" |
380 |
|
/* xterm/vt100 fn */ |
381 |
|
ts->input_state = IS_NORM; |
382 |
|
switch(ch) { |
383 |
|
case 'A': ch = KEY_UP; goto the_end; |
384 |
|
case 'B': ch = KEY_DOWN; goto the_end; |
385 |
|
case 'C': ch = KEY_RIGHT; goto the_end; |
386 |
|
case 'D': ch = KEY_LEFT; goto the_end; |
387 |
|
case 'P': ch = KEY_F1; goto the_end; |
388 |
|
case 'Q': ch = KEY_F2; goto the_end; |
389 |
|
case 'R': ch = KEY_F3; goto the_end; |
390 |
|
case 'S': ch = KEY_F4; goto the_end; |
391 |
|
case 't': ch = KEY_F5; goto the_end; |
392 |
|
case 'u': ch = KEY_F6; goto the_end; |
393 |
|
case 'v': ch = KEY_F7; goto the_end; |
394 |
|
case 'l': ch = KEY_F8; goto the_end; |
395 |
|
case 'w': ch = KEY_F9; goto the_end; |
396 |
|
case 'x': ch = KEY_F10; goto the_end; |
397 |
|
} |
398 |
|
break; |
399 |
|
the_end: |
400 |
|
ev->key_event.type = QE_KEY_EVENT; |
401 |
|
ev->key_event.key = ch; |
402 |
|
qe_handle_event(ev); |
403 |
|
break; |
404 |
} |
} |
405 |
} |
} |
406 |
|
|
672 |
term_set_clip, |
term_set_clip, |
673 |
NULL, /* no selection handling */ |
NULL, /* no selection handling */ |
674 |
NULL, /* no selection handling */ |
NULL, /* no selection handling */ |
675 |
|
term_invalidate, |
676 |
}; |
}; |
677 |
|
|
678 |
static int tty_init(void) |
static int tty_init(void) |