teken.h revision 196786
133965Sjdp/*- 278828Sobrien * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3130561Sobrien * All rights reserved. 459343Sobrien * 533965Sjdp * Redistribution and use in source and binary forms, with or without 633965Sjdp * modification, are permitted provided that the following conditions 733965Sjdp * are met: 833965Sjdp * 1. Redistributions of source code must retain the above copyright 933965Sjdp * notice, this list of conditions and the following disclaimer. 10130561Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1133965Sjdp * notice, this list of conditions and the following disclaimer in the 12130561Sobrien * documentation and/or other materials provided with the distribution. 13130561Sobrien * 14130561Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15130561Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1633965Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17130561Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18130561Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19130561Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20130561Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2133965Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22130561Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23130561Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24130561Sobrien * SUCH DAMAGE. 2533965Sjdp * 2633965Sjdp * $FreeBSD: head/sys/teken/teken.h 196786 2009-09-03 16:31:11Z ed $ 2733965Sjdp */ 2833965Sjdp 2933965Sjdp#ifndef _TEKEN_H_ 30130561Sobrien#define _TEKEN_H_ 3133965Sjdp 3233965Sjdp/* 3359343Sobrien * libteken: terminal emulation library. 3433965Sjdp * 35130561Sobrien * This library converts an UTF-8 stream of bytes to terminal drawing 3633965Sjdp * commands. 3759343Sobrien * 38130561Sobrien * Configuration switches: 3933965Sjdp * - TEKEN_UTF8: Enable/disable UTF-8 handling. 4059343Sobrien * - TEKEN_XTERM: Enable xterm-style emulation, instead of cons25. 41130561Sobrien */ 4233965Sjdp 4359343Sobrien#if defined(__FreeBSD__) && defined(_KERNEL) 44130561Sobrien#include "opt_teken.h" 4533965Sjdp#endif /* __FreeBSD__ && _KERNEL */ 4659343Sobrien 47130561Sobrien#ifdef TEKEN_UTF8 4833965Sjdptypedef uint32_t teken_char_t; 4959343Sobrien#else /* !TEKEN_UTF8 */ 50130561Sobrientypedef unsigned char teken_char_t; 51130561Sobrien#endif /* TEKEN_UTF8 */ 52130561Sobrientypedef unsigned short teken_unit_t; 5333965Sjdptypedef unsigned char teken_format_t; 5459343Sobrien#define TF_BOLD 0x01 55130561Sobrien#define TF_UNDERLINE 0x02 56130561Sobrien#define TF_BLINK 0x04 57130561Sobrien#define TF_REVERSE 0x08 5833965Sjdptypedef unsigned char teken_color_t; 5959343Sobrien#define TC_BLACK 0 6033965Sjdp#define TC_RED 1 61130561Sobrien#define TC_GREEN 2 62130561Sobrien#define TC_BROWN 3 63130561Sobrien#define TC_BLUE 4 64130561Sobrien#define TC_MAGENTA 5 65130561Sobrien#define TC_CYAN 6 66130561Sobrien#define TC_WHITE 7 67130561Sobrien#define TC_NCOLORS 8 68130561Sobrien 69130561Sobrientypedef struct { 70130561Sobrien teken_unit_t tp_row; 71130561Sobrien teken_unit_t tp_col; 72130561Sobrien} teken_pos_t; 73130561Sobrientypedef struct { 74130561Sobrien teken_pos_t tr_begin; 75130561Sobrien teken_pos_t tr_end; 76130561Sobrien} teken_rect_t; 77130561Sobrientypedef struct { 78130561Sobrien teken_format_t ta_format; 7933965Sjdp teken_color_t ta_fgcolor; 80130561Sobrien teken_color_t ta_bgcolor; 8133965Sjdp} teken_attr_t; 8259343Sobrientypedef struct { 8359343Sobrien teken_unit_t ts_begin; 8459343Sobrien teken_unit_t ts_end; 8577298Sobrien} teken_span_t; 8633965Sjdp 8759343Sobrientypedef struct __teken teken_t; 8859343Sobrien 8959343Sobrientypedef void teken_state_t(teken_t *, teken_char_t); 9059343Sobrien 9159343Sobrien/* 92130561Sobrien * Drawing routines supplied by the user. 93130561Sobrien */ 9459343Sobrien 9559343Sobrientypedef void tf_bell_t(void *); 9633965Sjdptypedef void tf_cursor_t(void *, const teken_pos_t *); 9777298Sobrientypedef void tf_putchar_t(void *, const teken_pos_t *, teken_char_t, 98104834Sobrien const teken_attr_t *); 9977298Sobrientypedef void tf_fill_t(void *, const teken_rect_t *, teken_char_t, 10033965Sjdp const teken_attr_t *); 101130561Sobrientypedef void tf_copy_t(void *, const teken_rect_t *, const teken_pos_t *); 102130561Sobrientypedef void tf_param_t(void *, int, unsigned int); 103130561Sobrien#define TP_SHOWCURSOR 0 104130561Sobrien#define TP_CURSORKEYS 1 105130561Sobrien#define TP_KEYPADAPP 2 106130561Sobrien#define TP_AUTOREPEAT 3 107130561Sobrien#define TP_SWITCHVT 4 108130561Sobrien#define TP_132COLS 5 109130561Sobrien#define TP_SETBELLPD 6 110130561Sobrien#define TP_SETBELLPD_PITCH(pd) ((pd) >> 16) 111130561Sobrien#define TP_SETBELLPD_DURATION(pd) ((pd) & 0xffff) 11233965Sjdptypedef void tf_respond_t(void *, const void *, size_t); 113130561Sobrien 11433965Sjdptypedef struct { 115130561Sobrien tf_bell_t *tf_bell; 116130561Sobrien tf_cursor_t *tf_cursor; 117130561Sobrien tf_putchar_t *tf_putchar; 118130561Sobrien tf_fill_t *tf_fill; 119130561Sobrien tf_copy_t *tf_copy; 120130561Sobrien tf_param_t *tf_param; 12133965Sjdp tf_respond_t *tf_respond; 122130561Sobrien} teken_funcs_t; 123130561Sobrien 124130561Sobrien#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8) 125130561Sobrientypedef teken_char_t teken_scs_t(teken_char_t); 126130561Sobrien#endif /* TEKEN_XTERM && TEKEN_UTF8 */ 127130561Sobrien 128130561Sobrien/* 129130561Sobrien * Terminal state. 130130561Sobrien */ 131130561Sobrien 132130561Sobrienstruct __teken { 133130561Sobrien const teken_funcs_t *t_funcs; 134130561Sobrien void *t_softc; 135130561Sobrien 136130561Sobrien teken_state_t *t_nextstate; 137130561Sobrien unsigned int t_stateflags; 138130561Sobrien 139130561Sobrien#define T_NUMSIZE 8 140130561Sobrien unsigned int t_nums[T_NUMSIZE]; 141130561Sobrien unsigned int t_curnum; 142130561Sobrien 143130561Sobrien teken_pos_t t_cursor; 144130561Sobrien teken_attr_t t_curattr; 145130561Sobrien teken_pos_t t_saved_cursor; 146130561Sobrien teken_attr_t t_saved_curattr; 147130561Sobrien 148130561Sobrien teken_attr_t t_defattr; 149130561Sobrien teken_pos_t t_winsize; 15033965Sjdp 151130561Sobrien /* For DECSTBM. */ 152130561Sobrien teken_span_t t_scrollreg; 153130561Sobrien /* For DECOM. */ 154130561Sobrien teken_span_t t_originreg; 155130561Sobrien 156130561Sobrien#define T_NUMCOL 160 157130561Sobrien unsigned int t_tabstops[T_NUMCOL / (sizeof(unsigned int) * 8)]; 158130561Sobrien 159130561Sobrien#ifdef TEKEN_UTF8 160130561Sobrien unsigned int t_utf8_left; 161130561Sobrien teken_char_t t_utf8_partial; 162130561Sobrien#endif /* TEKEN_UTF8 */ 163130561Sobrien 164130561Sobrien#if defined(TEKEN_XTERM) && defined(TEKEN_UTF8) 165130561Sobrien unsigned int t_curscs; 166130561Sobrien teken_scs_t *t_saved_curscs; 167130561Sobrien teken_scs_t *t_scs[2]; 168130561Sobrien#endif /* TEKEN_XTERM && TEKEN_UTF8 */ 169130561Sobrien}; 170130561Sobrien 171130561Sobrien/* Initialize teken structure. */ 172130561Sobrienvoid teken_init(teken_t *, const teken_funcs_t *, void *); 173130561Sobrien 174130561Sobrien/* Deliver character input. */ 175130561Sobrienvoid teken_input(teken_t *, const void *, size_t); 176130561Sobrien 177130561Sobrien/* Get/set teken attributes. */ 178130561Sobrienconst teken_attr_t *teken_get_curattr(teken_t *); 179130561Sobrienconst teken_attr_t *teken_get_defattr(teken_t *); 180130561Sobrienvoid teken_set_cursor(teken_t *, const teken_pos_t *); 181130561Sobrienvoid teken_set_curattr(teken_t *, const teken_attr_t *); 182130561Sobrienvoid teken_set_defattr(teken_t *, const teken_attr_t *); 183130561Sobrienvoid teken_set_winsize(teken_t *, const teken_pos_t *); 18459343Sobrien 18533965Sjdp#endif /* !_TEKEN_H_ */ 18633965Sjdp