teken.h revision 197117
1234285Sdim/*- 2234285Sdim * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3234285Sdim * All rights reserved. 4234285Sdim * 5234285Sdim * Redistribution and use in source and binary forms, with or without 6234285Sdim * modification, are permitted provided that the following conditions 7234285Sdim * are met: 8234285Sdim * 1. Redistributions of source code must retain the above copyright 9234285Sdim * notice, this list of conditions and the following disclaimer. 10234285Sdim * 2. Redistributions in binary form must reproduce the above copyright 11234285Sdim * notice, this list of conditions and the following disclaimer in the 12234285Sdim * documentation and/or other materials provided with the distribution. 13234285Sdim * 14251662Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15251662Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16234285Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17251662Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18251662Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19251662Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20234285Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21234285Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22234285Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23234285Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24234285Sdim * SUCH DAMAGE. 25234285Sdim * 26234285Sdim * $FreeBSD: head/sys/teken/teken.h 197117 2009-09-12 12:44:21Z ed $ 27239462Sdim */ 28234285Sdim 29234285Sdim#ifndef _TEKEN_H_ 30234285Sdim#define _TEKEN_H_ 31234285Sdim 32234285Sdim/* 33234285Sdim * libteken: terminal emulation library. 34234285Sdim * 35234285Sdim * This library converts an UTF-8 stream of bytes to terminal drawing 36234285Sdim * commands. 37234285Sdim */ 38234285Sdim 39234285Sdimtypedef uint32_t teken_char_t; 40234285Sdimtypedef unsigned short teken_unit_t; 41234285Sdimtypedef unsigned char teken_format_t; 42234285Sdim#define TF_BOLD 0x01 43239462Sdim#define TF_UNDERLINE 0x02 44234285Sdim#define TF_BLINK 0x04 45234285Sdim#define TF_REVERSE 0x08 46234285Sdimtypedef unsigned char teken_color_t; 47234285Sdim#define TC_BLACK 0 48234285Sdim#define TC_RED 1 49234285Sdim#define TC_GREEN 2 50234285Sdim#define TC_BROWN 3 51234285Sdim#define TC_BLUE 4 52234285Sdim#define TC_MAGENTA 5 53234285Sdim#define TC_CYAN 6 54234285Sdim#define TC_WHITE 7 55234285Sdim#define TC_NCOLORS 8 56234285Sdim 57234285Sdimtypedef struct { 58234285Sdim teken_unit_t tp_row; 59234285Sdim teken_unit_t tp_col; 60239462Sdim} teken_pos_t; 61239462Sdimtypedef struct { 62239462Sdim teken_pos_t tr_begin; 63239462Sdim teken_pos_t tr_end; 64239462Sdim} teken_rect_t; 65234285Sdimtypedef struct { 66234285Sdim teken_format_t ta_format; 67234285Sdim teken_color_t ta_fgcolor; 68234285Sdim teken_color_t ta_bgcolor; 69234285Sdim} teken_attr_t; 70234285Sdimtypedef struct { 71239462Sdim teken_unit_t ts_begin; 72239462Sdim teken_unit_t ts_end; 73239462Sdim} teken_span_t; 74239462Sdim 75239462Sdimtypedef struct __teken teken_t; 76234285Sdim 77234285Sdimtypedef void teken_state_t(teken_t *, teken_char_t); 78234285Sdim 79234285Sdim/* 80234285Sdim * Drawing routines supplied by the user. 81234285Sdim */ 82234285Sdim 83234285Sdimtypedef void tf_bell_t(void *); 84234285Sdimtypedef void tf_cursor_t(void *, const teken_pos_t *); 85239462Sdimtypedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t, 86239462Sdim const teken_attr_t *); 87234285Sdimtypedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t, 88239462Sdim const teken_attr_t *); 89239462Sdimtypedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *); 90234285Sdimtypedef void tf_param_t(void *, int, unsigned int); 91239462Sdim#define TP_SHOWCURSOR 0 92239462Sdim#define TP_CURSORKEYS 1 93234285Sdim#define TP_KEYPADAPP 2 94239462Sdim#define TP_AUTOREPEAT 3 95239462Sdim#define TP_SWITCHVT 4 96234285Sdim#define TP_132COLS 5 97239462Sdim#define TP_SETBELLPD 6 98239462Sdim#define TP_SETBELLPD_PITCH(pd) ((pd) >> 16) 99234285Sdim#define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff) 100234285Sdimtypedef void tf_respond_t(void *, const void *, size_t); 101234285Sdim 102239462Sdimtypedef struct { 103239462Sdim tf_bell_t *tf_bell; 104234285Sdim tf_cursor_t *tf_cursor; 105234285Sdim tf_putchar_t *tf_putchar; 106234285Sdim tf_fill_t *tf_fill; 107234285Sdim tf_copy_t *tf_copy; 108 tf_param_t *tf_param; 109 tf_respond_t *tf_respond; 110} teken_funcs_t; 111 112typedef teken_char_t teken_scs_t(teken_char_t); 113 114/* 115 * Terminal state. 116 */ 117 118struct __teken { 119 const teken_funcs_t *t_funcs; 120 void *t_softc; 121 122 teken_state_t *t_nextstate; 123 unsigned int t_stateflags; 124 125#define T_NUMSIZE 8 126 unsigned int t_nums[T_NUMSIZE]; 127 unsigned int t_curnum; 128 129 teken_pos_t t_cursor; 130 teken_attr_t t_curattr; 131 teken_pos_t t_saved_cursor; 132 teken_attr_t t_saved_curattr; 133 134 teken_attr_t t_defattr; 135 teken_pos_t t_winsize; 136 137 /* For DECSTBM. */ 138 teken_span_t t_scrollreg; 139 /* For DECOM. */ 140 teken_span_t t_originreg; 141 142#define T_NUMCOL 160 143 unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)]; 144 145 unsigned int t_utf8_left; 146 teken_char_t t_utf8_partial; 147 148 unsigned int t_curscs; 149 teken_scs_t *t_saved_curscs; 150 teken_scs_t *t_scs[2]; 151}; 152 153/* Initialize teken structure. */ 154void teken_init(teken_t *, const teken_funcs_t *, void *); 155 156/* Deliver character input. */ 157void teken_input(teken_t *, const void *, size_t); 158 159/* Get/set teken attributes. */ 160const teken_pos_t *teken_get_cursor(teken_t *); 161const teken_attr_t *teken_get_curattr(teken_t *); 162const teken_attr_t *teken_get_defattr(teken_t *); 163void teken_get_defattr_cons25(teken_t *, int *, int *); 164const teken_pos_t *teken_get_winsize(teken_t *); 165void teken_set_cursor(teken_t *, const teken_pos_t *); 166void teken_set_curattr(teken_t *, const teken_attr_t *); 167void teken_set_defattr(teken_t *, const teken_attr_t *); 168void teken_set_winsize(teken_t *, const teken_pos_t *); 169 170/* Legacy features. */ 171void teken_set_8bit(teken_t *); 172void teken_set_cons25(teken_t *); 173 174#endif /* !_TEKEN_H_ */ 175