libt3window
/home/gertjan/projects/tilde/window/src/terminal.h
00001 /* Copyright (C) 2011-2012 G.P. Halkes
00002    This program is free software: you can redistribute it and/or modify
00003    it under the terms of the GNU General Public License version 3, as
00004    published by the Free Software Foundation.
00005 
00006    This program is distributed in the hope that it will be useful,
00007    but WITHOUT ANY WARRANTY; without even the implied warranty of
00008    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00009    GNU General Public License for more details.
00010 
00011    You should have received a copy of the GNU General Public License
00012    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00013 */
00014 #ifndef T3_TERMINAL_H
00015 #define T3_TERMINAL_H
00016 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 #include <limits.h>
00027 #include <t3window/window_api.h>
00028 
00046 #define T3_WINDOW_VERSION 0
00047 
00048 /* Although it doesn't make a lot of sense to put this function in either this
00049    file or in window.h, there is a good reason to put it in here: because
00050    window.h includes terminal.h, this function (and the macro) will always
00051    be available, regardless of which files the user includes. */
00052 T3_WINDOW_API long t3_window_get_version(void);
00062 #if INT_MAX < 2147483647L
00063 typedef long t3_attr_t;
00064 #else
00065 typedef int t3_attr_t;
00066 #endif
00067 
00072 typedef struct {
00073         t3_attr_t highlights; 
00074         int colors; 
00075         int pairs; 
00076         int cap_flags; 
00077 } t3_term_caps_t;
00078 
00080 #define T3_TERM_CAP_FG (1 << 0)
00081 
00082 #define T3_TERM_CAP_BG (1 << 1)
00083 
00084 #define T3_TERM_CAP_CP (1 << 2)
00085 
00091 typedef void (*t3_attr_user_callback_t)(const char *str, int length, int width, t3_attr_t attr);
00092 
00101 #define T3_ATTR_USER ((t3_attr_t) (1L << 0))
00102 
00103 #define T3_ATTR_UNDERLINE ((t3_attr_t) (1L << 1))
00104 
00105 #define T3_ATTR_BOLD ((t3_attr_t) (1L << 2))
00106 
00107 #define T3_ATTR_REVERSE ((t3_attr_t) (1L << 3))
00108 
00109 #define T3_ATTR_BLINK ((t3_attr_t) (1L << 4))
00110 
00111 #define T3_ATTR_DIM ((t3_attr_t) (1L << 5))
00112 
00113 #define T3_ATTR_ACS ((t3_attr_t) (1L << 6))
00114 
00119 #define T3_ATTR_FALLBACK_ACS ((t3_attr_t) (1L << 7))
00120 
00122 #define T3_ATTR_COLOR_SHIFT 8
00123 
00124 #define T3_ATTR_FG(x) (((((t3_attr_t) (x)) & 0xff) + 1) << T3_ATTR_COLOR_SHIFT)
00125 
00126 #define T3_ATTR_BG(x) (((((t3_attr_t) (x)) & 0xff) + 1) << (T3_ATTR_COLOR_SHIFT + 9))
00127 
00128 #define T3_ATTR_FG_MASK (0x1ff << T3_ATTR_COLOR_SHIFT)
00129 
00130 #define T3_ATTR_BG_MASK (0x1ff << (T3_ATTR_COLOR_SHIFT + 9))
00131 
00133 #define T3_ATTR_FG_UNSPEC ((t3_attr_t) 0L)
00134 
00135 #define T3_ATTR_FG_DEFAULT (((t3_attr_t) 257) << (T3_ATTR_COLOR_SHIFT))
00136 
00137 #define T3_ATTR_FG_BLACK T3_ATTR_FG(0)
00138 
00139 #define T3_ATTR_FG_RED T3_ATTR_FG(1)
00140 
00141 #define T3_ATTR_FG_GREEN T3_ATTR_FG(2)
00142 
00143 #define T3_ATTR_FG_YELLOW T3_ATTR_FG(3)
00144 
00145 #define T3_ATTR_FG_BLUE T3_ATTR_FG(4)
00146 
00147 #define T3_ATTR_FG_MAGENTA T3_ATTR_FG(5)
00148 
00149 #define T3_ATTR_FG_CYAN T3_ATTR_FG(6)
00150 
00151 #define T3_ATTR_FG_WHITE T3_ATTR_FG(7)
00152 
00154 #define T3_ATTR_BG_UNSPEC ((t3_attr_t) 0L)
00155 
00156 #define T3_ATTR_BG_DEFAULT (((t3_attr_t) 257) << (T3_ATTR_COLOR_SHIFT + 9))
00157 
00158 #define T3_ATTR_BG_BLACK T3_ATTR_BG(0)
00159 
00160 #define T3_ATTR_BG_RED T3_ATTR_BG(1)
00161 
00162 #define T3_ATTR_BG_GREEN T3_ATTR_BG(2)
00163 
00164 #define T3_ATTR_BG_YELLOW T3_ATTR_BG(3)
00165 
00166 #define T3_ATTR_BG_BLUE T3_ATTR_BG(4)
00167 
00168 #define T3_ATTR_BG_MAGENTA T3_ATTR_BG(5)
00169 
00170 #define T3_ATTR_BG_CYAN T3_ATTR_BG(6)
00171 
00172 #define T3_ATTR_BG_WHITE T3_ATTR_BG(7)
00173 
00176 enum {
00177         T3_ACS_TTEE = 'w', 
00178         T3_ACS_RTEE = 'u', 
00179         T3_ACS_LTEE = 't', 
00180         T3_ACS_BTEE = 'v', 
00181         T3_ACS_ULCORNER = 'l', 
00182         T3_ACS_URCORNER = 'k', 
00183         T3_ACS_LLCORNER = 'm', 
00184         T3_ACS_LRCORNER = 'j', 
00185         T3_ACS_HLINE = 'q', 
00186         T3_ACS_VLINE = 'x', 
00187         T3_ACS_UARROW = '-', 
00188         T3_ACS_DARROW = '.', 
00189         T3_ACS_LARROW = ',', 
00190         T3_ACS_RARROW = '+', 
00191         T3_ACS_BOARD = 'h', 
00192         T3_ACS_CKBOARD = 'a', 
00193         T3_ACS_BULLET = '~', 
00194         T3_ACS_DIAMOND = '`', 
00195         T3_ACS_BLOCK = '0' 
00196         /* FIXME: add all the different known ACS chars */
00197 };
00198 
00199 #define T3_TERM_KEY_CTRL (1<<0)
00200 #define T3_TERM_KEY_META (1<<1)
00201 #define T3_TERM_KEY_SHIFT (1<<2)
00202 
00203 #include "window_errors.h"
00204 
00208 #define T3_ERR_NOT_A_TTY (-64)
00209 
00210 #define T3_ERR_TIMEOUT (-63)
00211 
00212 #define T3_ERR_NO_SIZE_INFO (-62)
00213 
00214 #define T3_ERR_NONPRINT (-61)
00215 
00216 #define T3_ERR_CHARSET_ERROR (-60)
00217 
00218 #define T3_WARN_UPDATE_TERMINAL (-1)
00219 
00221 T3_WINDOW_API const char *t3_window_strerror(int error);
00222 
00225 T3_WINDOW_API int t3_term_init(int fd, const char *term);
00226 T3_WINDOW_API void t3_term_deinit(void);
00227 T3_WINDOW_API void t3_term_restore(void);
00228 T3_WINDOW_API const char *t3_term_get_codeset(void);
00229 T3_WINDOW_API int t3_term_get_keychar(int msec);
00230 T3_WINDOW_API void t3_term_set_cursor(int y, int x);
00231 T3_WINDOW_API void t3_term_hide_cursor(void);
00232 T3_WINDOW_API void t3_term_show_cursor(void);
00233 T3_WINDOW_API void t3_term_get_size(int *height, int *width);
00234 T3_WINDOW_API t3_bool t3_term_resize(void);
00235 T3_WINDOW_API void t3_term_update_cursor(void);
00236 T3_WINDOW_API void t3_term_update(void);
00237 T3_WINDOW_API void t3_term_redraw(void);
00238 T3_WINDOW_API void t3_term_set_attrs(t3_attr_t new_attrs);
00239 T3_WINDOW_API void t3_term_set_user_callback(t3_attr_user_callback_t callback);
00240 T3_WINDOW_API int t3_term_get_keychar(int msec);
00241 T3_WINDOW_API int t3_term_unget_keychar(int c);
00242 T3_WINDOW_API void t3_term_putp(const char *str);
00243 T3_WINDOW_API t3_bool t3_term_acs_available(int idx);
00244 
00245 T3_WINDOW_API int t3_term_strwidth(const char *str);
00246 
00247 T3_WINDOW_API t3_attr_t t3_term_combine_attrs(t3_attr_t a, t3_attr_t b);
00248 T3_WINDOW_API t3_attr_t t3_term_get_ncv(void);
00249 
00250 T3_WINDOW_API void t3_term_disable_ansi_optimization(void);
00251 
00253 T3_WINDOW_API t3_bool t3_term_can_draw(const char *str, size_t str_len);
00254 T3_WINDOW_API void t3_term_set_replacement_char(int c);
00255 T3_WINDOW_API t3_bool t3_term_putc(char c);
00256 T3_WINDOW_API t3_bool t3_term_puts(const char *s);
00257 T3_WINDOW_API t3_bool t3_term_putn(const char *s, size_t n);
00258 
00267 #define t3_term_get_caps(caps) t3_term_get_caps_internal((caps), T3_WINDOW_VERSION)
00268 
00269 T3_WINDOW_API void t3_term_get_caps_internal(t3_term_caps_t *caps, int version);
00270 T3_WINDOW_API int t3_term_get_modifiers_hack(void);
00271 
00272 #ifdef __cplusplus
00273 } /* extern "C" */
00274 #endif
00275 
00276 #endif
 All Data Structures Variables