teken.h revision 197115
1188824Simp/*- 2188824Simp * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3188824Simp * All rights reserved. 4188824Simp * 5188824Simp * Redistribution and use in source and binary forms, with or without 6188824Simp * modification, are permitted provided that the following conditions 7188824Simp * are met: 8188824Simp * 1. Redistributions of source code must retain the above copyright 9188824Simp * notice, this list of conditions and the following disclaimer. 10188824Simp * 2. Redistributions in binary form must reproduce the above copyright 11188824Simp * notice, this list of conditions and the following disclaimer in the 12188824Simp * documentation and/or other materials provided with the distribution. 13188824Simp * 14188824Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15188824Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16188824Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17188824Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18188824Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19188824Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20188824Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21188824Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22188824Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23188824Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24188824Simp * SUCH DAMAGE. 25188824Simp * 26188824Simp * $FreeBSD: head/sys/teken/teken.h 197115 2009-09-12 10:34:34Z ed $ 27188824Simp */ 28188824Simp 29188824Simp#ifndef _TEKEN_H_ 30188824Simp#define _TEKEN_H_ 31188824Simp 32188824Simp/* 33188824Simp * libteken: terminal emulation library. 34188824Simp * 35188824Simp * This library converts an UTF-8 stream of bytes to terminal drawing 36188824Simp * commands. 37188824Simp * 38188824Simp * Configuration switches: 39188824Simp * - TEKEN_XTERM: Enable xterm-style emulation, instead of cons25. 40188824Simp */ 41188824Simp 42188824Simp#if defined(__FreeBSD__) && defined(_KERNEL) 43188824Simp#include "opt_teken.h" 44188824Simp#endif /* __FreeBSD__ && _KERNEL */ 45188824Simp 46188824Simptypedef uint32_t teken_char_t; 47188824Simptypedef unsigned short teken_unit_t; 48188824Simptypedef unsigned char teken_format_t; 49188824Simp#define TF_BOLD 0x01 50188824Simp#define TF_UNDERLINE 0x02 51188824Simp#define TF_BLINK 0x04 52188824Simp#define TF_REVERSE 0x08 53188824Simptypedef unsigned char teken_color_t; 54188824Simp#define TC_BLACK 0 55188824Simp#define TC_RED 1 56188824Simp#define TC_GREEN 2 57188824Simp#define TC_BROWN 3 58188824Simp#define TC_BLUE 4 59188824Simp#define TC_MAGENTA 5 60188824Simp#define TC_CYAN 6 61188824Simp#define TC_WHITE 7 62188824Simp#define TC_NCOLORS 8 63188824Simp 64188824Simptypedef struct { 65188824Simp teken_unit_t tp_row; 66188824Simp teken_unit_t tp_col; 67188824Simp} teken_pos_t; 68188824Simptypedef struct { 69188824Simp teken_pos_t tr_begin; 70188824Simp teken_pos_t tr_end; 71188824Simp} teken_rect_t; 72188824Simptypedef struct { 73188824Simp teken_format_t ta_format; 74188824Simp teken_color_t ta_fgcolor; 75188824Simp teken_color_t ta_bgcolor; 76188824Simp} teken_attr_t; 77188824Simptypedef struct { 78188824Simp teken_unit_t ts_begin; 79188824Simp teken_unit_t ts_end; 80188824Simp} teken_span_t; 81188824Simp 82188824Simptypedef struct __teken teken_t; 83188824Simp 84188824Simptypedef void teken_state_t(teken_t *, teken_char_t); 85188824Simp 86188824Simp/* 87188824Simp * Drawing routines supplied by the user. 88188824Simp */ 89188824Simp 90188824Simptypedef void tf_bell_t(void *); 91188824Simptypedef void tf_cursor_t(void *, const teken_pos_t *); 92188824Simptypedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t, 93188824Simp const teken_attr_t *); 94188824Simptypedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t, 95188824Simp const teken_attr_t *); 96188824Simptypedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *); 97188824Simptypedef void tf_param_t(void *, int, unsigned int); 98188824Simp#define TP_SHOWCURSOR 0 99188824Simp#define TP_CURSORKEYS 1 100188824Simp#define TP_KEYPADAPP 2 101188824Simp#define TP_AUTOREPEAT 3 102188824Simp#define TP_SWITCHVT 4 103188824Simp#define TP_132COLS 5 104188824Simp#define TP_SETBELLPD 6 105188824Simp#define TP_SETBELLPD_PITCH(pd) ((pd) >> 16) 106188824Simp#define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff) 107188824Simptypedef void tf_respond_t(void *, const void *, size_t); 108188824Simp 109188824Simptypedef struct { 110188824Simp tf_bell_t *tf_bell; 111188824Simp tf_cursor_t *tf_cursor; 112188824Simp tf_putchar_t *tf_putchar; 113188824Simp tf_fill_t *tf_fill; 114188824Simp tf_copy_t *tf_copy; 115188824Simp tf_param_t *tf_param; 116188824Simp tf_respond_t *tf_respond; 117188824Simp} teken_funcs_t; 118188824Simp 119188824Simp#ifdef TEKEN_XTERM 120188824Simptypedef teken_char_t teken_scs_t(teken_char_t); 121188824Simp#endif /* TEKEN_XTERM */ 122188824Simp 123188824Simp/* 124188824Simp * Terminal state. 125188824Simp */ 126188824Simp 127188824Simpstruct __teken { 128188824Simp const teken_funcs_t *t_funcs; 129188824Simp void *t_softc; 130188824Simp 131188824Simp teken_state_t *t_nextstate; 132188824Simp unsigned int t_stateflags; 133188824Simp 134188824Simp#define T_NUMSIZE 8 135188824Simp unsigned int t_nums[T_NUMSIZE]; 136188824Simp unsigned int t_curnum; 137188824Simp 138188824Simp teken_pos_t t_cursor; 139188824Simp teken_attr_t t_curattr; 140188824Simp teken_pos_t t_saved_cursor; 141188824Simp teken_attr_t t_saved_curattr; 142188824Simp 143188824Simp teken_attr_t t_defattr; 144188824Simp teken_pos_t t_winsize; 145188824Simp 146188824Simp /* For DECSTBM. */ 147188824Simp teken_span_t t_scrollreg; 148188824Simp /* For DECOM. */ 149188824Simp teken_span_t t_originreg; 150188824Simp 151188824Simp#define T_NUMCOL 160 152188824Simp unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)]; 153188824Simp 154188824Simp int t_utf8_left; 155188824Simp teken_char_t t_utf8_partial; 156188824Simp 157188824Simp#ifdef TEKEN_XTERM 158188824Simp unsigned int t_curscs; 159188824Simp teken_scs_t *t_saved_curscs; 160188824Simp teken_scs_t *t_scs[2]; 161188824Simp#endif /* TEKEN_XTERM */ 162188824Simp}; 163188824Simp 164188824Simp/* Initialize teken structure. */ 165188824Simpvoid teken_init(teken_t *, const teken_funcs_t *, void *); 166188824Simp 167188824Simp/* Deliver character input. */ 168188824Simpvoid teken_input(teken_t *, const void *, size_t); 169188824Simp 170188824Simp/* Get/set teken attributes. */ 171188824Simpconst teken_attr_t *teken_get_curattr(teken_t *); 172188824Simpconst teken_attr_t *teken_get_defattr(teken_t *); 173188824Simpvoid teken_set_cursor(teken_t *, const teken_pos_t *); 174188824Simpvoid teken_set_curattr(teken_t *, const teken_attr_t *); 175188824Simpvoid teken_set_defattr(teken_t *, const teken_attr_t *); 176188824Simpvoid teken_set_winsize(teken_t *, const teken_pos_t *); 177188824Simp 178188824Simp/* Legacy features. */ 179188824Simpvoid teken_set_8bit(teken_t *); 180188824Simp 181188824Simp#endif /* !_TEKEN_H_ */ 182188824Simp