diff options
author | ed <ed@FreeBSD.org> | 2009-11-11 08:20:19 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2009-11-11 08:20:19 +0000 |
commit | fcc8740e5f98d5a779e7925466919cb22d750137 (patch) | |
tree | 0727d54b551a5437ffd2abdee66ef48b4016605c /sys/teken/teken.c | |
parent | 74d077dc934272cd3839f573aeeb27a6c77c4273 (diff) | |
download | FreeBSD-src-fcc8740e5f98d5a779e7925466919cb22d750137.zip FreeBSD-src-fcc8740e5f98d5a779e7925466919cb22d750137.tar.gz |
Allow Syscons terminal emulators to provide function key strings.
xterm and cons25 have some incompatibilities when it comes to escape
sequences for special keys, such as F1 to F12, home, end, etc. Add a new
te_fkeystr() that can be used to override the strings.
scterm-sck won't do anything with this, but scterm-teken will use
teken_get_sequences() to obtain the proper sequence.
Diffstat (limited to 'sys/teken/teken.c')
-rw-r--r-- | sys/teken/teken.c | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/sys/teken/teken.c b/sys/teken/teken.c index 81b8ac0..d50edc8 100644 --- a/sys/teken/teken.c +++ b/sys/teken/teken.c @@ -49,14 +49,15 @@ static FILE *df; #endif /* __FreeBSD__ && _KERNEL */ /* Private flags for t_stateflags. */ -#define TS_FIRSTDIGIT 0x01 /* First numeric digit in escape sequence. */ -#define TS_INSERT 0x02 /* Insert mode. */ -#define TS_AUTOWRAP 0x04 /* Autowrap. */ -#define TS_ORIGIN 0x08 /* Origin mode. */ -#define TS_WRAPPED 0x10 /* Next character should be printed on col 0. */ -#define TS_8BIT 0x20 /* UTF-8 disabled. */ -#define TS_CONS25 0x40 /* cons25 emulation. */ -#define TS_INSTRING 0x80 /* Inside string. */ +#define TS_FIRSTDIGIT 0x0001 /* First numeric digit in escape sequence. */ +#define TS_INSERT 0x0002 /* Insert mode. */ +#define TS_AUTOWRAP 0x0004 /* Autowrap. */ +#define TS_ORIGIN 0x0008 /* Origin mode. */ +#define TS_WRAPPED 0x0010 /* Next character should be printed on col 0. */ +#define TS_8BIT 0x0020 /* UTF-8 disabled. */ +#define TS_CONS25 0x0040 /* cons25 emulation. */ +#define TS_INSTRING 0x0080 /* Inside string. */ +#define TS_CURSORKEYS 0x0100 /* Cursor keys mode. */ /* Character that blanks a cell. */ #define BLANK ' ' @@ -479,4 +480,64 @@ teken_256to8(teken_color_t c) } } +static const char * const special_strings_cons25[] = { + [TKEY_UP] = "\x1B[A", [TKEY_DOWN] = "\x1B[B", + [TKEY_LEFT] = "\x1B[D", [TKEY_RIGHT] = "\x1B[C", + + [TKEY_INSERT] = "\x1B[L", [TKEY_DELETE] = "\x7F", + [TKEY_HOME] = "\x1B[H", [TKEY_END] = "\x1B[F", + [TKEY_PAGE_UP] = "\x1B[I", [TKEY_PAGE_DOWN] = "\x1B[G", + + [TKEY_F1] = "\x1B[M", [TKEY_F2] = "\x1B[N", + [TKEY_F3] = "\x1B[O", [TKEY_F4] = "\x1B[P", + [TKEY_F5] = "\x1B[Q", [TKEY_F6] = "\x1B[R", + [TKEY_F7] = "\x1B[S", [TKEY_F8] = "\x1B[T", + [TKEY_F9] = "\x1B[U", [TKEY_F10] = "\x1B[V", + [TKEY_F11] = "\x1B[W", [TKEY_F12] = "\x1B[X", +}; + +static const char * const special_strings_ckeys[] = { + [TKEY_UP] = "\x1BOA", [TKEY_DOWN] = "\x1BOB", + [TKEY_LEFT] = "\x1BOD", [TKEY_RIGHT] = "\x1BOC", + + [TKEY_HOME] = "\x1BOH", [TKEY_END] = "\x1BOF", +}; + +static const char * const special_strings_normal[] = { + [TKEY_UP] = "\x1B[A", [TKEY_DOWN] = "\x1B[B", + [TKEY_LEFT] = "\x1B[D", [TKEY_RIGHT] = "\x1B[C", + + [TKEY_INSERT] = "\x1B[2~", [TKEY_DELETE] = "\x1B[3~", + [TKEY_HOME] = "\x1B[H", [TKEY_END] = "\x1B[F", + [TKEY_PAGE_UP] = "\x1B[5~", [TKEY_PAGE_DOWN] = "\x1B[6~", + + [TKEY_F1] = "\x1BOP", [TKEY_F2] = "\x1BOQ", + [TKEY_F3] = "\x1BOR", [TKEY_F4] = "\x1BOS", + [TKEY_F5] = "\x1B[15~", [TKEY_F6] = "\x1B[17~", + [TKEY_F7] = "\x1B[18~", [TKEY_F8] = "\x1B[19~", + [TKEY_F9] = "\x1B[20~", [TKEY_F10] = "\x1B[21~", + [TKEY_F11] = "\x1B[23~", [TKEY_F12] = "\x1B[24~", +}; + +const char * +teken_get_sequence(teken_t *t, unsigned int k) +{ + + /* Cons25 mode. */ + if (t->t_stateflags & TS_CONS25 && + k < sizeof special_strings_cons25 / sizeof(char *)) + return (special_strings_cons25[k]); + + /* Cursor keys mode. */ + if (t->t_stateflags & TS_CURSORKEYS && + k < sizeof special_strings_ckeys / sizeof(char *)) + return (special_strings_ckeys[k]); + + /* Default xterm sequences. */ + if (k < sizeof special_strings_normal / sizeof(char *)) + return (special_strings_normal[k]); + + return (NULL); +} + #include "teken_state.h" |