summaryrefslogtreecommitdiffstats
path: root/sys/teken
diff options
context:
space:
mode:
Diffstat (limited to 'sys/teken')
-rw-r--r--sys/teken/teken.c77
-rw-r--r--sys/teken/teken.h40
-rw-r--r--sys/teken/teken_subr.h4
3 files changed, 104 insertions, 17 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"
diff --git a/sys/teken/teken.h b/sys/teken/teken.h
index 22b5745..e129d47 100644
--- a/sys/teken/teken.h
+++ b/sys/teken/teken.h
@@ -89,15 +89,14 @@ typedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t,
typedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *);
typedef void tf_param_t(void *, int, unsigned int);
#define TP_SHOWCURSOR 0
-#define TP_CURSORKEYS 1
-#define TP_KEYPADAPP 2
-#define TP_AUTOREPEAT 3
-#define TP_SWITCHVT 4
-#define TP_132COLS 5
-#define TP_SETBELLPD 6
+#define TP_KEYPADAPP 1
+#define TP_AUTOREPEAT 2
+#define TP_SWITCHVT 3
+#define TP_132COLS 4
+#define TP_SETBELLPD 5
#define TP_SETBELLPD_PITCH(pd) ((pd) >> 16)
#define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff)
-#define TP_MOUSE 7
+#define TP_MOUSE 6
typedef void tf_respond_t(void *, const void *, size_t);
typedef struct {
@@ -168,6 +167,33 @@ void teken_set_curattr(teken_t *, const teken_attr_t *);
void teken_set_defattr(teken_t *, const teken_attr_t *);
void teken_set_winsize(teken_t *, const teken_pos_t *);
+/* Key input escape sequences. */
+#define TKEY_UP 0x00
+#define TKEY_DOWN 0x01
+#define TKEY_LEFT 0x02
+#define TKEY_RIGHT 0x03
+
+#define TKEY_INSERT 0x04
+#define TKEY_DELETE 0x05
+#define TKEY_HOME 0x06
+#define TKEY_END 0x07
+#define TKEY_PAGE_UP 0x08
+#define TKEY_PAGE_DOWN 0x09
+
+#define TKEY_F1 0x0a
+#define TKEY_F2 0x0b
+#define TKEY_F3 0x0c
+#define TKEY_F4 0x0d
+#define TKEY_F5 0x0e
+#define TKEY_F6 0x0f
+#define TKEY_F7 0x10
+#define TKEY_F8 0x11
+#define TKEY_F9 0x12
+#define TKEY_F10 0x13
+#define TKEY_F11 0x14
+#define TKEY_F12 0x15
+const char *teken_get_sequence(teken_t *, unsigned int);
+
/* Legacy features. */
void teken_set_8bit(teken_t *);
void teken_set_cons25(teken_t *);
diff --git a/sys/teken/teken_subr.h b/sys/teken/teken_subr.h
index 4caa500..6bad71e 100644
--- a/sys/teken/teken_subr.h
+++ b/sys/teken/teken_subr.h
@@ -903,7 +903,7 @@ teken_subr_reset_dec_mode(teken_t *t, unsigned int cmd)
switch (cmd) {
case 1: /* Cursor keys mode. */
- teken_funcs_param(t, TP_CURSORKEYS, 0);
+ t->t_stateflags &= ~TS_CURSORKEYS;
break;
case 2: /* DECANM: ANSI/VT52 mode. */
teken_printf("DECRST VT52\n");
@@ -1052,7 +1052,7 @@ teken_subr_set_dec_mode(teken_t *t, unsigned int cmd)
switch (cmd) {
case 1: /* Cursor keys mode. */
- teken_funcs_param(t, TP_CURSORKEYS, 1);
+ t->t_stateflags |= TS_CURSORKEYS;
break;
case 2: /* DECANM: ANSI/VT52 mode. */
teken_printf("DECSET VT52\n");
OpenPOWER on IntegriCloud