libt3window
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules
terminal.h
1 /* Copyright (C) 2011-2012 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_TERMINAL_H
15 #define T3_TERMINAL_H
16 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #include <limits.h>
27 #include <t3window/window_api.h>
28 
46 #define T3_WINDOW_VERSION 0
47 
48 /* Although it doesn't make a lot of sense to put this function in either this
49  file or in window.h, there is a good reason to put it in here: because
50  window.h includes terminal.h, this function (and the macro) will always
51  be available, regardless of which files the user includes. */
52 T3_WINDOW_API long t3_window_get_version(void);
62 #if INT_MAX < 2147483647L
63 typedef long t3_attr_t;
64 #else
65 typedef int t3_attr_t;
66 #endif
67 
72 typedef struct {
73  t3_attr_t highlights;
74  int colors;
75  int pairs;
76  int cap_flags;
78 
80 #define T3_TERM_CAP_FG (1 << 0)
81 
82 #define T3_TERM_CAP_BG (1 << 1)
83 
84 #define T3_TERM_CAP_CP (1 << 2)
85 
91 typedef void (*t3_attr_user_callback_t)(const char *str, int length, int width, t3_attr_t attr);
92 
101 #define T3_ATTR_USER ((t3_attr_t) (1L << 0))
102 
103 #define T3_ATTR_UNDERLINE ((t3_attr_t) (1L << 1))
104 
105 #define T3_ATTR_BOLD ((t3_attr_t) (1L << 2))
106 
107 #define T3_ATTR_REVERSE ((t3_attr_t) (1L << 3))
108 
109 #define T3_ATTR_BLINK ((t3_attr_t) (1L << 4))
110 
111 #define T3_ATTR_DIM ((t3_attr_t) (1L << 5))
112 
113 #define T3_ATTR_ACS ((t3_attr_t) (1L << 6))
114 
119 #define T3_ATTR_FALLBACK_ACS ((t3_attr_t) (1L << 7))
120 
122 #define T3_ATTR_COLOR_SHIFT 8
123 
124 #define T3_ATTR_FG(x) (((((t3_attr_t) (x)) & 0xff) + 1) << T3_ATTR_COLOR_SHIFT)
125 
126 #define T3_ATTR_BG(x) (((((t3_attr_t) (x)) & 0xff) + 1) << (T3_ATTR_COLOR_SHIFT + 9))
127 
128 #define T3_ATTR_FG_MASK (0x1ff << T3_ATTR_COLOR_SHIFT)
129 
130 #define T3_ATTR_BG_MASK (0x1ff << (T3_ATTR_COLOR_SHIFT + 9))
131 
133 #define T3_ATTR_FG_UNSPEC ((t3_attr_t) 0L)
134 
135 #define T3_ATTR_FG_DEFAULT (((t3_attr_t) 257) << (T3_ATTR_COLOR_SHIFT))
136 
137 #define T3_ATTR_FG_BLACK T3_ATTR_FG(0)
138 
139 #define T3_ATTR_FG_RED T3_ATTR_FG(1)
140 
141 #define T3_ATTR_FG_GREEN T3_ATTR_FG(2)
142 
143 #define T3_ATTR_FG_YELLOW T3_ATTR_FG(3)
144 
145 #define T3_ATTR_FG_BLUE T3_ATTR_FG(4)
146 
147 #define T3_ATTR_FG_MAGENTA T3_ATTR_FG(5)
148 
149 #define T3_ATTR_FG_CYAN T3_ATTR_FG(6)
150 
151 #define T3_ATTR_FG_WHITE T3_ATTR_FG(7)
152 
154 #define T3_ATTR_BG_UNSPEC ((t3_attr_t) 0L)
155 
156 #define T3_ATTR_BG_DEFAULT (((t3_attr_t) 257) << (T3_ATTR_COLOR_SHIFT + 9))
157 
158 #define T3_ATTR_BG_BLACK T3_ATTR_BG(0)
159 
160 #define T3_ATTR_BG_RED T3_ATTR_BG(1)
161 
162 #define T3_ATTR_BG_GREEN T3_ATTR_BG(2)
163 
164 #define T3_ATTR_BG_YELLOW T3_ATTR_BG(3)
165 
166 #define T3_ATTR_BG_BLUE T3_ATTR_BG(4)
167 
168 #define T3_ATTR_BG_MAGENTA T3_ATTR_BG(5)
169 
170 #define T3_ATTR_BG_CYAN T3_ATTR_BG(6)
171 
172 #define T3_ATTR_BG_WHITE T3_ATTR_BG(7)
173 
176 enum {
177  T3_ACS_TTEE = 'w',
178  T3_ACS_RTEE = 'u',
179  T3_ACS_LTEE = 't',
180  T3_ACS_BTEE = 'v',
185  T3_ACS_HLINE = 'q',
186  T3_ACS_VLINE = 'x',
191  T3_ACS_BOARD = 'h',
196  /* FIXME: add all the different known ACS chars */
197 };
198 
199 #define T3_TERM_KEY_CTRL (1<<0)
200 #define T3_TERM_KEY_META (1<<1)
201 #define T3_TERM_KEY_SHIFT (1<<2)
202 
203 #include "window_errors.h"
204 
208 #define T3_ERR_NOT_A_TTY (-64)
209 
210 #define T3_ERR_TIMEOUT (-63)
211 
212 #define T3_ERR_NO_SIZE_INFO (-62)
213 
214 #define T3_ERR_NONPRINT (-61)
215 
216 #define T3_ERR_CHARSET_ERROR (-60)
217 
218 #define T3_WARN_UPDATE_TERMINAL (-1)
219 
221 T3_WINDOW_API const char *t3_window_strerror(int error);
222 
225 T3_WINDOW_API int t3_term_init(int fd, const char *term);
226 T3_WINDOW_API void t3_term_deinit(void);
227 T3_WINDOW_API void t3_term_restore(void);
228 T3_WINDOW_API const char *t3_term_get_codeset(void);
229 T3_WINDOW_API int t3_term_get_keychar(int msec);
230 T3_WINDOW_API void t3_term_set_cursor(int y, int x);
231 T3_WINDOW_API void t3_term_hide_cursor(void);
232 T3_WINDOW_API void t3_term_show_cursor(void);
233 T3_WINDOW_API void t3_term_get_size(int *height, int *width);
234 T3_WINDOW_API t3_bool t3_term_resize(void);
235 T3_WINDOW_API void t3_term_update_cursor(void);
236 T3_WINDOW_API void t3_term_update(void);
237 T3_WINDOW_API void t3_term_redraw(void);
238 T3_WINDOW_API void t3_term_set_attrs(t3_attr_t new_attrs);
239 T3_WINDOW_API void t3_term_set_user_callback(t3_attr_user_callback_t callback);
240 T3_WINDOW_API int t3_term_get_keychar(int msec);
241 T3_WINDOW_API int t3_term_unget_keychar(int c);
242 T3_WINDOW_API void t3_term_putp(const char *str);
243 T3_WINDOW_API t3_bool t3_term_acs_available(int idx);
244 
245 T3_WINDOW_API int t3_term_strwidth(const char *str);
246 
247 T3_WINDOW_API t3_attr_t t3_term_combine_attrs(t3_attr_t a, t3_attr_t b);
248 T3_WINDOW_API t3_attr_t t3_term_get_ncv(void);
249 
250 T3_WINDOW_API void t3_term_disable_ansi_optimization(void);
251 
253 T3_WINDOW_API t3_bool t3_term_can_draw(const char *str, size_t str_len);
254 T3_WINDOW_API void t3_term_set_replacement_char(int c);
255 T3_WINDOW_API t3_bool t3_term_putc(char c);
256 T3_WINDOW_API t3_bool t3_term_puts(const char *s);
257 T3_WINDOW_API t3_bool t3_term_putn(const char *s, size_t n);
258 
267 #define t3_term_get_caps(caps) t3_term_get_caps_internal((caps), T3_WINDOW_VERSION)
268 
269 T3_WINDOW_API void t3_term_get_caps_internal(t3_term_caps_t *caps, int version);
270 T3_WINDOW_API int t3_term_get_modifiers_hack(void);
271 
272 #ifdef __cplusplus
273 } /* extern "C" */
274 #endif
275 
276 #endif
Vertical line.
Definition: terminal.h:186
long t3_window_get_version(void)
Get the value of T3_WINDOW_VERSION corresponding to the actually used library.
Definition: misc.c:35
Arrow pointing up.
Definition: terminal.h:187
int t3_term_get_keychar(int msec)
Get a key char from stdin with timeout.
Definition: input.c:230
void t3_term_putp(const char *str)
Send a terminal control string to the terminal, with correct padding.
Definition: terminal.c:808
Board of squares.
Definition: terminal.h:191
void t3_term_get_size(int *height, int *width)
Retrieve the terminal size.
Definition: terminal.c:287
Lower left corner.
Definition: terminal.h:183
Data structure to store information about the capabilities of the terminal.
Definition: terminal.h:72
Bullet.
Definition: terminal.h:193
Solid block.
Definition: terminal.h:195
Tee pointing left.
Definition: terminal.h:178
Checker board pattern (stipple).
Definition: terminal.h:192
Tee pointing right.
Definition: terminal.h:179
void t3_term_hide_cursor(void)
Hide the cursor.
Definition: terminal.c:269
Upper left corner.
Definition: terminal.h:181
Upper right corner.
Definition: terminal.h:182
Arrow pointing left.
Definition: terminal.h:189
t3_attr_t highlights
The supported attributes other then color attributes.
Definition: terminal.h:73
char t3_bool
A boolean type that does not clash with C++ or C99 bool.
Definition: window_api.h:47
void t3_term_show_cursor(void)
Show the cursor.
Definition: terminal.c:277
void t3_term_set_cursor(int y, int x)
Move cursor.
Definition: terminal.c:259
void t3_term_set_replacement_char(int c)
Set the replacement character used for undrawable characters.
Definition: convert_output.c:393
void t3_term_get_caps_internal(t3_term_caps_t *caps, int version)
Get the terminal capabilities.
Definition: terminal.c:892
t3_bool t3_term_resize(void)
Handle resizing of the terminal.
Definition: terminal.c:302
Arrow pointing down.
Definition: terminal.h:188
const char * t3_window_strerror(int error)
Get a string description for an error code.
Definition: misc.c:43
Diamond.
Definition: terminal.h:194
void t3_term_set_attrs(t3_attr_t new_attrs)
Set terminal drawing attributes.
Definition: terminal.c:540
int colors
The maximum number of supported colors, or 0 if color is not supported.
Definition: terminal.h:74
int t3_term_strwidth(const char *str)
Calculate the cell width of a string.
Definition: terminal.c:820
t3_attr_t t3_term_combine_attrs(t3_attr_t a, t3_attr_t b)
Combine attributes, with priority.
Definition: terminal.c:858
Tee pointing up.
Definition: terminal.h:180
int t3_term_unget_keychar(int c)
Push a char back for later retrieval with t3_term_get_keychar.
Definition: input.c:268
void(* t3_attr_user_callback_t)(const char *str, int length, int width, t3_attr_t attr)
User callback type.
Definition: terminal.h:91
int pairs
The maximum number of color pairs that are supported by this terminal, or 0 if color is not supported...
Definition: terminal.h:75
void t3_term_update(void)
Update the terminal, drawing all changes since last refresh.
Definition: terminal.c:581
t3_bool t3_term_acs_available(int idx)
Check if a character is available in the alternate character set (internal use mostly).
Definition: terminal.c:844
int t3_term_get_modifiers_hack(void)
Retrieve the state of the modifiers using terminal specific hacks.
Definition: terminal.c:942
int cap_flags
A bitmask of T3_TERM_CAP_* flags indicating capabilities of the terminal.
Definition: terminal.h:76
void t3_term_redraw(void)
Redraw the entire terminal from scratch.
Definition: terminal.c:789
Horizontal line.
Definition: terminal.h:185
Arrow pointing right.
Definition: terminal.h:190
t3_bool t3_term_puts(const char *s)
Add a string to the output buffer.
Definition: convert_output.c:134
Lower right corner.
Definition: terminal.h:184
void t3_term_update_cursor(void)
Update the cursor, not drawing anything.
Definition: terminal.c:552
t3_bool t3_term_putn(const char *s, size_t n)
Add a string to the output buffer.
Definition: convert_output.c:151
void t3_term_set_user_callback(t3_attr_user_callback_t callback)
Set callback for drawing characters with T3_ATTR_USER attribute.
Definition: terminal.c:547
Tee pointing down.
Definition: terminal.h:177
t3_attr_t t3_term_get_ncv(void)
Get the set of non-color video attributes.
Definition: terminal.c:877
t3_bool t3_term_putc(char c)
Add a charater to the output buffer.
Definition: convert_output.c:110
long t3_attr_t
Type to hold attributes used for terminal display.
Definition: terminal.h:63
t3_bool t3_term_can_draw(const char *str, size_t str_len)
These are implemented in convert_output.c.
Definition: convert_output.c:288
const char * t3_term_get_codeset(void)
Get the string describing the current character set used by the library.
Definition: terminal.c:248