Lines Matching +full:- +full:t

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
60 #define TS_8BIT 0x0020 /* UTF-8 disabled. */
80 teken_funcs_bell(const teken_t *t) in teken_funcs_bell() argument
83 teken_assert(t->t_funcs->tf_bell != NULL); in teken_funcs_bell()
84 t->t_funcs->tf_bell(t->t_softc); in teken_funcs_bell()
88 teken_funcs_cursor(const teken_t *t) in teken_funcs_cursor() argument
91 teken_assert(t->t_cursor.tp_row < t->t_winsize.tp_row); in teken_funcs_cursor()
92 teken_assert(t->t_cursor.tp_col < t->t_winsize.tp_col); in teken_funcs_cursor()
94 teken_assert(t->t_funcs->tf_cursor != NULL); in teken_funcs_cursor()
95 t->t_funcs->tf_cursor(t->t_softc, &t->t_cursor); in teken_funcs_cursor()
99 teken_funcs_putchar(const teken_t *t, const teken_pos_t *p, teken_char_t c, in teken_funcs_putchar() argument
103 teken_assert(p->tp_row < t->t_winsize.tp_row); in teken_funcs_putchar()
104 teken_assert(p->tp_col < t->t_winsize.tp_col); in teken_funcs_putchar()
106 teken_assert(t->t_funcs->tf_putchar != NULL); in teken_funcs_putchar()
107 t->t_funcs->tf_putchar(t->t_softc, p, c, a); in teken_funcs_putchar()
111 teken_funcs_fill(const teken_t *t, const teken_rect_t *r, in teken_funcs_fill() argument
115 teken_assert(r->tr_end.tp_row > r->tr_begin.tp_row); in teken_funcs_fill()
116 teken_assert(r->tr_end.tp_row <= t->t_winsize.tp_row); in teken_funcs_fill()
117 teken_assert(r->tr_end.tp_col > r->tr_begin.tp_col); in teken_funcs_fill()
118 teken_assert(r->tr_end.tp_col <= t->t_winsize.tp_col); in teken_funcs_fill()
120 teken_assert(t->t_funcs->tf_fill != NULL); in teken_funcs_fill()
121 t->t_funcs->tf_fill(t->t_softc, r, c, a); in teken_funcs_fill()
125 teken_funcs_copy(const teken_t *t, const teken_rect_t *r, const teken_pos_t *p) in teken_funcs_copy() argument
128 teken_assert(r->tr_end.tp_row > r->tr_begin.tp_row); in teken_funcs_copy()
129 teken_assert(r->tr_end.tp_row <= t->t_winsize.tp_row); in teken_funcs_copy()
130 teken_assert(r->tr_end.tp_col > r->tr_begin.tp_col); in teken_funcs_copy()
131 teken_assert(r->tr_end.tp_col <= t->t_winsize.tp_col); in teken_funcs_copy()
132 teken_assert(p->tp_row + (r->tr_end.tp_row - r->tr_begin.tp_row) <= t->t_winsize.tp_row); in teken_funcs_copy()
133 teken_assert(p->tp_col + (r->tr_end.tp_col - r->tr_begin.tp_col) <= t->t_winsize.tp_col); in teken_funcs_copy()
135 teken_assert(t->t_funcs->tf_copy != NULL); in teken_funcs_copy()
136 t->t_funcs->tf_copy(t->t_softc, r, p); in teken_funcs_copy()
140 teken_funcs_pre_input(const teken_t *t) in teken_funcs_pre_input() argument
143 if (t->t_funcs->tf_pre_input != NULL) in teken_funcs_pre_input()
144 t->t_funcs->tf_pre_input(t->t_softc); in teken_funcs_pre_input()
148 teken_funcs_post_input(const teken_t *t) in teken_funcs_post_input() argument
151 if (t->t_funcs->tf_post_input != NULL) in teken_funcs_post_input()
152 t->t_funcs->tf_post_input(t->t_softc); in teken_funcs_post_input()
156 teken_funcs_param(const teken_t *t, int cmd, unsigned int value) in teken_funcs_param() argument
159 teken_assert(t->t_funcs->tf_param != NULL); in teken_funcs_param()
160 t->t_funcs->tf_param(t->t_softc, cmd, value); in teken_funcs_param()
164 teken_funcs_respond(const teken_t *t, const void *buf, size_t len) in teken_funcs_respond() argument
167 teken_assert(t->t_funcs->tf_respond != NULL); in teken_funcs_respond()
168 t->t_funcs->tf_respond(t->t_softc, buf, len); in teken_funcs_respond()
179 teken_init(teken_t *t, const teken_funcs_t *tf, void *softc) in teken_init() argument
183 t->t_funcs = tf; in teken_init()
184 t->t_softc = softc; in teken_init()
186 t->t_nextstate = teken_state_init; in teken_init()
187 t->t_stateflags = 0; in teken_init()
188 t->t_utf8_left = 0; in teken_init()
190 t->t_defattr.ta_format = 0; in teken_init()
191 t->t_defattr.ta_fgcolor = TC_WHITE; in teken_init()
192 t->t_defattr.ta_bgcolor = TC_BLACK; in teken_init()
193 teken_subr_do_reset(t); in teken_init()
195 teken_set_winsize(t, &tp); in teken_init()
199 teken_input_char(teken_t *t, teken_char_t c) in teken_input_char() argument
207 if (t->t_stateflags & TS_INSTRING) { in teken_input_char()
210 t->t_stateflags &= ~TS_INSTRING; in teken_input_char()
213 t->t_stateflags &= ~TS_INSTRING; in teken_input_char()
224 teken_subr_bell(t); in teken_input_char()
227 teken_subr_backspace(t); in teken_input_char()
231 teken_subr_newline(t); in teken_input_char()
234 teken_subr_newpage(t); in teken_input_char()
237 if (t->t_stateflags & TS_CONS25) in teken_input_char()
238 t->t_nextstate(t, c); in teken_input_char()
240 t->t_curscs = 1; in teken_input_char()
243 if (t->t_stateflags & TS_CONS25) in teken_input_char()
244 t->t_nextstate(t, c); in teken_input_char()
246 t->t_curscs = 0; in teken_input_char()
249 teken_subr_carriage_return(t); in teken_input_char()
251 case '\t': in teken_input_char()
252 teken_subr_horizontal_tab(t); in teken_input_char()
255 t->t_nextstate(t, c); in teken_input_char()
259 /* Post-processing assertions. */ in teken_input_char()
260 teken_assert(t->t_cursor.tp_row >= t->t_originreg.ts_begin); in teken_input_char()
261 teken_assert(t->t_cursor.tp_row < t->t_originreg.ts_end); in teken_input_char()
262 teken_assert(t->t_cursor.tp_row < t->t_winsize.tp_row); in teken_input_char()
263 teken_assert(t->t_cursor.tp_col < t->t_winsize.tp_col); in teken_input_char()
264 teken_assert(t->t_saved_cursor.tp_row < t->t_winsize.tp_row); in teken_input_char()
265 teken_assert(t->t_saved_cursor.tp_col < t->t_winsize.tp_col); in teken_input_char()
266 teken_assert(t->t_scrollreg.ts_end <= t->t_winsize.tp_row); in teken_input_char()
267 teken_assert(t->t_scrollreg.ts_begin < t->t_scrollreg.ts_end); in teken_input_char()
269 teken_assert((t->t_originreg.ts_begin == t->t_scrollreg.ts_begin && in teken_input_char()
270 t->t_originreg.ts_end == t->t_scrollreg.ts_end) || in teken_input_char()
271 (t->t_originreg.ts_begin == 0 && in teken_input_char()
272 t->t_originreg.ts_end == t->t_winsize.tp_row)); in teken_input_char()
276 teken_input_byte(teken_t *t, unsigned char c) in teken_input_byte() argument
280 * UTF-8 handling. in teken_input_byte()
282 if ((c & 0x80) == 0x00 || t->t_stateflags & TS_8BIT) { in teken_input_byte()
283 /* One-byte sequence. */ in teken_input_byte()
284 t->t_utf8_left = 0; in teken_input_byte()
285 teken_input_char(t, c); in teken_input_byte()
287 /* Two-byte sequence. */ in teken_input_byte()
288 t->t_utf8_left = 1; in teken_input_byte()
289 t->t_utf8_partial = c & 0x1f; in teken_input_byte()
291 /* Three-byte sequence. */ in teken_input_byte()
292 t->t_utf8_left = 2; in teken_input_byte()
293 t->t_utf8_partial = c & 0x0f; in teken_input_byte()
295 /* Four-byte sequence. */ in teken_input_byte()
296 t->t_utf8_left = 3; in teken_input_byte()
297 t->t_utf8_partial = c & 0x07; in teken_input_byte()
299 if (t->t_utf8_left == 0) in teken_input_byte()
301 t->t_utf8_left--; in teken_input_byte()
302 t->t_utf8_partial = (t->t_utf8_partial << 6) | (c & 0x3f); in teken_input_byte()
303 if (t->t_utf8_left == 0) { in teken_input_byte()
304 teken_printf("Got UTF-8 char %x\n", t->t_utf8_partial); in teken_input_byte()
305 teken_input_char(t, t->t_utf8_partial); in teken_input_byte()
311 teken_input(teken_t *t, const void *buf, size_t len) in teken_input() argument
315 teken_funcs_pre_input(t); in teken_input()
316 while (len-- > 0) in teken_input()
317 teken_input_byte(t, *c++); in teken_input()
318 teken_funcs_post_input(t); in teken_input()
322 teken_get_cursor(const teken_t *t) in teken_get_cursor() argument
325 return (&t->t_cursor); in teken_get_cursor()
329 teken_set_cursor(teken_t *t, const teken_pos_t *p) in teken_set_cursor() argument
333 teken_assert(p->tp_row < t->t_winsize.tp_row); in teken_set_cursor()
334 teken_assert(p->tp_col < t->t_winsize.tp_col); in teken_set_cursor()
336 t->t_cursor = *p; in teken_set_cursor()
340 teken_get_curattr(const teken_t *t) in teken_get_curattr() argument
343 return (&t->t_curattr); in teken_get_curattr()
347 teken_set_curattr(teken_t *t, const teken_attr_t *a) in teken_set_curattr() argument
350 t->t_curattr = *a; in teken_set_curattr()
354 teken_get_defattr(const teken_t *t) in teken_get_defattr() argument
357 return (&t->t_defattr); in teken_get_defattr()
361 teken_set_defattr(teken_t *t, const teken_attr_t *a) in teken_set_defattr() argument
364 t->t_curattr = t->t_saved_curattr = t->t_defattr = *a; in teken_set_defattr()
368 teken_get_winsize(const teken_t *t) in teken_get_winsize() argument
371 return (&t->t_winsize); in teken_get_winsize()
375 teken_trim_cursor_pos(teken_t *t, const teken_pos_t *new) in teken_trim_cursor_pos() argument
379 cur = &t->t_winsize; in teken_trim_cursor_pos()
381 if (cur->tp_row < new->tp_row || cur->tp_col < new->tp_col) in teken_trim_cursor_pos()
383 if (t->t_cursor.tp_row >= new->tp_row) in teken_trim_cursor_pos()
384 t->t_cursor.tp_row = new->tp_row - 1; in teken_trim_cursor_pos()
385 if (t->t_cursor.tp_col >= new->tp_col) in teken_trim_cursor_pos()
386 t->t_cursor.tp_col = new->tp_col - 1; in teken_trim_cursor_pos()
390 teken_set_winsize(teken_t *t, const teken_pos_t *p) in teken_set_winsize() argument
393 teken_trim_cursor_pos(t, p); in teken_set_winsize()
394 t->t_winsize = *p; in teken_set_winsize()
395 teken_subr_do_reset(t); in teken_set_winsize()
399 teken_set_winsize_noreset(teken_t *t, const teken_pos_t *p) in teken_set_winsize_noreset() argument
402 teken_trim_cursor_pos(t, p); in teken_set_winsize_noreset()
403 t->t_winsize = *p; in teken_set_winsize_noreset()
404 teken_subr_do_resize(t); in teken_set_winsize_noreset()
408 teken_set_8bit(teken_t *t) in teken_set_8bit() argument
411 t->t_stateflags |= TS_8BIT; in teken_set_8bit()
415 teken_set_cons25(teken_t *t) in teken_set_cons25() argument
418 t->t_stateflags |= TS_CONS25; in teken_set_cons25()
422 teken_set_cons25keys(teken_t *t) in teken_set_cons25keys() argument
425 t->t_stateflags |= TS_CONS25KEYS; in teken_set_cons25keys()
433 teken_state_switch(teken_t *t, teken_state_t *s) in teken_state_switch() argument
436 t->t_nextstate = s; in teken_state_switch()
437 t->t_curnum = 0; in teken_state_switch()
438 t->t_stateflags |= TS_FIRSTDIGIT; in teken_state_switch()
442 teken_state_numbers(teken_t *t, teken_char_t c) in teken_state_numbers() argument
445 teken_assert(t->t_curnum < T_NUMSIZE); in teken_state_numbers()
448 if (t->t_stateflags & TS_FIRSTDIGIT) { in teken_state_numbers()
450 t->t_stateflags &= ~TS_FIRSTDIGIT; in teken_state_numbers()
451 t->t_nums[t->t_curnum] = c - '0'; in teken_state_numbers()
452 } else if (t->t_nums[t->t_curnum] < UINT_MAX / 100) { in teken_state_numbers()
463 t->t_nums[t->t_curnum] = in teken_state_numbers()
464 t->t_nums[t->t_curnum] * 10 + c - '0'; in teken_state_numbers()
468 if (t->t_stateflags & TS_FIRSTDIGIT) in teken_state_numbers()
469 t->t_nums[t->t_curnum] = 0; in teken_state_numbers()
472 if (++t->t_curnum == T_NUMSIZE) { in teken_state_numbers()
473 teken_state_switch(t, teken_state_init); in teken_state_numbers()
477 t->t_stateflags |= TS_FIRSTDIGIT; in teken_state_numbers()
480 if (t->t_stateflags & TS_FIRSTDIGIT && t->t_curnum > 0) { in teken_state_numbers()
482 t->t_nums[t->t_curnum] = 0; in teken_state_numbers()
483 t->t_curnum++; in teken_state_numbers()
484 } else if ((t->t_stateflags & TS_FIRSTDIGIT) == 0) { in teken_state_numbers()
486 t->t_curnum++; in teken_state_numbers()
511 * The xterm-256 color map has steps of 0x28 (in the range 0-0xff), except
512 * for the first step which is 0x5f. Scale to the range 0-6 by dividing
513 * by 0x28 and rounding down. The range of 0-5 cannot represent the
517 * - if all components are equal, the result is black for (0, 0, 0) and
519 * - subtract the smallest component from all components
520 * - if this gives only one nonzero component, then that is the color
521 * - else if one component is 2 or more larger than the other nonzero one,
523 * - else there are 2 nonzero components. The color is that of a small
526 * (DeepSkyBlue4), but we map both to cyan since we can't represent
703 [TKEY_F7] = "\x1B[S", [TKEY_F8] = "\x1B[T",
732 teken_get_sequence(const teken_t *t, unsigned int k) in teken_get_sequence() argument
736 if ((t->t_stateflags & (TS_CONS25 | TS_CONS25KEYS)) == in teken_get_sequence()
738 return (NULL); /* Don't override good kbd(4) strings. */ in teken_get_sequence()
739 if (t->t_stateflags & TS_CONS25 && in teken_get_sequence()
744 if (t->t_stateflags & TS_CURSORKEYS && in teken_get_sequence()