libt3window
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Modules
internal.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_INTERNAL_H
15 #define T3_INTERNAL_H
16 
17 #include <limits.h>
18 #ifdef HAS_SELECT_H
19 #include <sys/select.h>
20 #else
21 #include <sys/time.h>
22 #include <sys/types.h>
23 #endif
24 #include <stdint.h>
25 
26 #include "window_api.h"
27 
28 #define WIDTH_TO_META(_w) (((_w) & 3) << CHAR_BIT)
29 
30 #define WIDTH_MASK (3 << CHAR_BIT)
31 #define META_MASK (~((1 << CHAR_BIT) - 1))
32 
33 #define BASIC_ATTRS (T3_ATTR_UNDERLINE | T3_ATTR_BOLD | T3_ATTR_REVERSE | T3_ATTR_BLINK | T3_ATTR_DIM | T3_ATTR_ACS)
34 
35 #define INITIAL_ALLOC 80
36 
37 #define _T3_BLOCK_SIZE_TO_WIDTH(x) ((int)((x & 1) + 1))
38 
39 typedef struct {
40  char *data; /* Data bytes. */
41  int start; /* Offset of data bytes in screen cells from the edge of the t3_window_t. */
42  int width; /* Width in cells of the the data. */
43  int length; /* Length in bytes. */
44  int allocated; /* Allocated number of bytes. */
45 } line_data_t;
46 
47 struct t3_window_t {
48  int x, y; /* X and Y coordinates of the t3_window_t. These may be relative to parent, depending on relation. */
49  int paint_x, paint_y; /* Drawing cursor */
50  int width, height; /* Height and width of the t3_window_t */
51  int depth; /* Depth in stack. Higher values are deeper and thus obscured by Windows with lower depth. */
52  int relation; /* Relation of this t3_window_t to parent. See window.h for values. */
53  int cached_pos_line;
54  int cached_pos;
55  int cached_pos_width;
56  t3_attr_t default_attrs; /* Default attributes to be combined with drawing attributes.
57  Mostly useful for background specification. */
58  t3_bool shown; /* Indicates whether this t3_window_t is visible. */
59  line_data_t *lines; /* The contents of the t3_window_t. */
60  t3_window_t *parent; /* t3_window_t used for clipping. */
61  t3_window_t *anchor; /* t3_window_t for relative placment. */
62  t3_window_t *restrictw; /* t3_window_t for restricting the placement of the window. [restrict is seen as keyword by clang :-(]*/
63 
64  /* Pointers for linking into depth sorted list. */
65  t3_window_t *next;
66  t3_window_t *prev;
67 
68  t3_window_t *head;
69  t3_window_t *tail;
70 };
71 
72 T3_WINDOW_LOCAL t3_bool _t3_win_refresh_term_line(int line);
73 T3_WINDOW_LOCAL int _t3_term_get_default_acs(int idx);
74 T3_WINDOW_LOCAL void _t3_remove_window(t3_window_t *win);
75 
76 T3_WINDOW_LOCAL extern t3_window_t *_t3_terminal_window;
77 
78 enum {
79  _T3_TERM_UNKNOWN,
80  _T3_TERM_UTF8,
81  _T3_TERM_GB18030,
82  _T3_TERM_SINGLE_BYTE, /* Generic single byte encoding. Pray that LC_CTYPE has been set correctly. */
83  _T3_TERM_CJK, /* One of the CJK encodings has been detected. More detection required. */
84  _T3_TERM_CJK_SHIFT_JIS,
85  _T3_TERM_GBK
86 };
87 
88 enum {
89  _T3_MODHACK_NONE,
90  _T3_MODHACK_LINUX
91 };
92 
93 typedef enum {
94  _T3_ACS_AUTO,
95  _T3_ACS_ASCII,
96  _T3_ACS_UTF8
97 } t3_acs_override_t;
98 
99 T3_WINDOW_LOCAL extern int _t3_term_encoding, _t3_term_combining, _t3_term_double_width;
100 T3_WINDOW_LOCAL extern char _t3_current_charset[80];
101 T3_WINDOW_LOCAL extern long _t3_detection_needs_finishing;
102 T3_WINDOW_LOCAL extern int _t3_terminal_in_fd;
103 T3_WINDOW_LOCAL extern int _t3_terminal_out_fd;
104 T3_WINDOW_LOCAL extern fd_set _t3_inset;
105 
106 T3_WINDOW_LOCAL extern char *_t3_cup,
107  *_t3_sc,
108  *_t3_rc,
109  *_t3_clear,
110  *_t3_home,
111  *_t3_vpa,
112  *_t3_hpa,
113  *_t3_cud,
114  *_t3_cud1,
115  *_t3_cuf,
116  *_t3_cuf1,
117  *_t3_civis,
118  *_t3_cnorm,
119  *_t3_sgr,
120  *_t3_setaf,
121  *_t3_setab,
122  *_t3_op,
123  *_t3_smacs,
124  *_t3_rmacs,
125  *_t3_sgr0,
126  *_t3_smul,
127  *_t3_rmul,
128  *_t3_rev,
129  *_t3_bold,
130  *_t3_blink,
131  *_t3_dim,
132  *_t3_setf,
133  *_t3_setb,
134  *_t3_el,
135  *_t3_scp;
136 T3_WINDOW_LOCAL extern int _t3_lines, _t3_columns;
137 T3_WINDOW_LOCAL extern const char *_t3_default_alternate_chars[256];
138 T3_WINDOW_LOCAL extern t3_attr_t _t3_attrs, _t3_ansi_attrs, _t3_reset_required_mask;
139 T3_WINDOW_LOCAL extern t3_attr_t _t3_ncv;
140 T3_WINDOW_LOCAL extern t3_bool _t3_bce;
141 T3_WINDOW_LOCAL extern int _t3_colors, _t3_pairs;
142 T3_WINDOW_LOCAL extern char _t3_alternate_chars[256];
143 T3_WINDOW_LOCAL extern line_data_t _t3_old_data;
144 T3_WINDOW_LOCAL extern t3_bool _t3_show_cursor;
145 T3_WINDOW_LOCAL extern int _t3_cursor_y, _t3_cursor_x;
146 T3_WINDOW_LOCAL extern t3_acs_override_t _t3_acs_override;
147 
148 T3_WINDOW_LOCAL void _t3_do_cup(int line, int col);
149 T3_WINDOW_LOCAL void _t3_set_alternate_chars_defaults(void);
150 T3_WINDOW_LOCAL void _t3_set_attrs(t3_attr_t new_attrs);
151 
152 T3_WINDOW_LOCAL extern t3_window_t *_t3_head, *_t3_tail;
153 T3_WINDOW_LOCAL t3_bool _t3_win_is_shown(t3_window_t *win);
154 T3_WINDOW_LOCAL t3_attr_t _t3_term_sanitize_attrs(t3_attr_t attrs);
155 
156 T3_WINDOW_LOCAL int _t3_map_attr(t3_attr_t attr);
157 T3_WINDOW_LOCAL t3_attr_t _t3_get_attr(int idx);
158 T3_WINDOW_LOCAL void _t3_init_attr_map(void);
159 T3_WINDOW_LOCAL void _t3_free_attr_map(void);
160 
161 #define _t3_get_value(s, size) (((s)[0] & 0x80) ? _t3_get_value_int(s, size) : (uint32_t) (*(size) = 1, (s)[0]))
162 T3_WINDOW_LOCAL uint32_t _t3_get_value_int(const char *s, size_t *size);
163 T3_WINDOW_LOCAL size_t _t3_put_value(uint32_t c, char *dst);
164 T3_WINDOW_LOCAL int _t3_modifier_hack;
165 #endif
size_t _t3_put_value(uint32_t c, char *dst)
Write a UTF-8 encoded value.
Definition: window_paint.c:243
uint32_t _t3_get_value_int(const char *s, size_t *size)
Get the first UTF-8 value encoded in a string.
Definition: window_paint.c:173
t3_bool _t3_win_is_shown(t3_window_t *win)
Check whether a window is show, both by the direct setting of the shown flag, as well as the parents...
Definition: window.c:263
char t3_bool
A boolean type that does not clash with C++ or C99 bool.
Definition: window_api.h:47
An opaque struct representing a window which can be shown on the terminal.
Definition: internal.h:47
void _t3_do_cup(int line, int col)
Move cursor to screen position.
Definition: terminal.c:207
fd_set _t3_inset
File-descriptor set used for select in t3_term_get_keychar.
Definition: input.c:47
long t3_attr_t
Type to hold attributes used for terminal display.
Definition: terminal.h:63