2 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * libteken: terminal emulation library.
35 * This library converts an UTF-8 stream of bytes to terminal drawing
38 * Configuration switches:
39 * - TEKEN_UTF8: Enable/disable UTF-8 handling.
40 * - TEKEN_XTERM: Enable xterm-style emulation, instead of cons25.
43 #if defined(__FreeBSD__) && defined(_KERNEL)
44 #include "opt_teken.h"
45 #endif /* __FreeBSD__ && _KERNEL */
48 typedef uint32_t teken_char_t;
49 #else /* !TEKEN_UTF8 */
50 typedef unsigned char teken_char_t;
51 #endif /* TEKEN_UTF8 */
52 typedef unsigned short teken_unit_t;
53 typedef unsigned char teken_format_t;
55 #define TF_UNDERLINE 0x02
57 typedef unsigned char teken_color_t;
77 teken_format_t ta_format;
78 teken_color_t ta_fgcolor;
79 teken_color_t ta_bgcolor;
82 teken_unit_t ts_begin;
86 typedef struct __teken teken_t;
88 typedef void teken_state_t(teken_t *, teken_char_t);
91 * Drawing routines supplied by the user.
94 typedef void tf_bell_t(void *);
95 typedef void tf_cursor_t(void *, const teken_pos_t *);
96 typedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t,
97 const teken_attr_t *);
98 typedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t,
99 const teken_attr_t *);
100 typedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *);
101 typedef void tf_param_t(void *, int, unsigned int);
102 #define TP_SHOWCURSOR 0
103 #define TP_CURSORKEYS 1
104 #define TP_KEYPADAPP 2
105 #define TP_AUTOREPEAT 3
106 #define TP_SWITCHVT 4
108 #define TP_SETBELLPD 6
109 #define TP_SETBELLPD_PITCH(pd) ((pd) >> 16)
110 #define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff)
111 typedef void tf_respond_t(void *, const void *, size_t);
115 tf_cursor_t *tf_cursor;
116 tf_putchar_t *tf_putchar;
119 tf_param_t *tf_param;
120 tf_respond_t *tf_respond;
123 #if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
124 typedef teken_char_t teken_scs_t(teken_char_t);
125 #endif /* TEKEN_XTERM && TEKEN_UTF8 */
132 const teken_funcs_t *t_funcs;
135 teken_state_t *t_nextstate;
136 unsigned int t_stateflags;
139 unsigned int t_nums[T_NUMSIZE];
140 unsigned int t_curnum;
142 teken_pos_t t_cursor;
143 teken_attr_t t_curattr;
144 teken_pos_t t_saved_cursor;
145 teken_attr_t t_saved_curattr;
147 teken_attr_t t_defattr;
148 teken_pos_t t_winsize;
151 teken_span_t t_scrollreg;
153 teken_span_t t_originreg;
156 unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)];
159 unsigned int t_utf8_left;
160 teken_char_t t_utf8_partial;
161 #endif /* TEKEN_UTF8 */
163 #if defined(TEKEN_XTERM) && defined(TEKEN_UTF8)
164 unsigned int t_curscs;
165 teken_scs_t *t_saved_curscs;
166 teken_scs_t *t_scs[2];
167 #endif /* TEKEN_XTERM && TEKEN_UTF8 */
170 /* Initialize teken structure. */
171 void teken_init(teken_t *, const teken_funcs_t *, void *);
173 /* Deliver character input. */
174 void teken_input(teken_t *, const void *, size_t);
176 /* Get/set teken attributes. */
177 const teken_attr_t *teken_get_curattr(teken_t *);
178 const teken_attr_t *teken_get_defattr(teken_t *);
179 void teken_set_cursor(teken_t *, const teken_pos_t *);
180 void teken_set_curattr(teken_t *, const teken_attr_t *);
181 void teken_set_defattr(teken_t *, const teken_attr_t *);
182 void teken_set_winsize(teken_t *, const teken_pos_t *);
184 #endif /* !_TEKEN_H_ */