1 /*
2  * TSM - Main internal header
3  *
4  * Copyright (c) 2011-2013 David Herrmann <dh.herrmann@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #ifndef TSM_LIBTSM_INT_H
27 #define TSM_LIBTSM_INT_H
28 
29 #include <stdlib.h>
30 
31 #define SHL_EXPORT __attribute__((visibility("default")))
32 
33 /* max combined-symbol length */
34 #define TSM_UCS4_MAXLEN 10
35 
36 /* symbols */
37 
38 struct tsm_symbol_table;
39 
40 extern const tsm_symbol_t tsm_symbol_default;
41 
42 int tsm_symbol_table_new(struct tsm_symbol_table **out);
43 void tsm_symbol_table_ref(struct tsm_symbol_table *tbl);
44 void tsm_symbol_table_unref(struct tsm_symbol_table *tbl);
45 
46 tsm_symbol_t tsm_symbol_make(uint32_t ucs4);
47 tsm_symbol_t tsm_symbol_append(struct tsm_symbol_table *tbl,
48 			       tsm_symbol_t sym, uint32_t ucs4);
49 const uint32_t *tsm_symbol_get(struct tsm_symbol_table *tbl,
50 			       tsm_symbol_t *sym, size_t *size);
51 unsigned int tsm_symbol_get_width(struct tsm_symbol_table *tbl,
52 				  tsm_symbol_t sym);
53 
54 /* utf8 state machine */
55 
56 struct tsm_utf8_mach;
57 
58 enum tsm_utf8_mach_state {
59 	TSM_UTF8_START,
60 	TSM_UTF8_ACCEPT,
61 	TSM_UTF8_REJECT,
62 	TSM_UTF8_EXPECT1,
63 	TSM_UTF8_EXPECT2,
64 	TSM_UTF8_EXPECT3,
65 };
66 
67 int tsm_utf8_mach_new(struct tsm_utf8_mach **out);
68 void tsm_utf8_mach_free(struct tsm_utf8_mach *mach);
69 
70 int tsm_utf8_mach_feed(struct tsm_utf8_mach *mach, char c);
71 uint32_t tsm_utf8_mach_get(struct tsm_utf8_mach *mach);
72 void tsm_utf8_mach_reset(struct tsm_utf8_mach *mach);
73 
74 /* TSM screen */
75 
76 void tsm_screen_set_opts(struct tsm_screen *scr, unsigned int opts);
77 void tsm_screen_reset_opts(struct tsm_screen *scr, unsigned int opts);
78 unsigned int tsm_screen_get_opts(struct tsm_screen *scr);
79 
80 /* available character sets */
81 
82 typedef tsm_symbol_t tsm_vte_charset[96];
83 
84 extern tsm_vte_charset tsm_vte_unicode_lower;
85 extern tsm_vte_charset tsm_vte_unicode_upper;
86 extern tsm_vte_charset tsm_vte_dec_supplemental_graphics;
87 extern tsm_vte_charset tsm_vte_dec_special_graphics;
88 
89 struct cell {
90 	tsm_symbol_t ch;
91 	unsigned int width;
92 	struct tui_screen_attr attr;
93 	tsm_age_t age;
94 };
95 
96 struct line {
97 	struct line *next;
98 	struct line *prev;
99 
100 	unsigned int size;
101 	struct cell *cells;
102 	uint64_t sb_id;
103 	tsm_age_t age;
104 };
105 
106 #define SELECTION_TOP -1
107 struct selection_pos {
108 	struct line *line;
109 	unsigned int x;
110 	int y;
111 };
112 
113 struct tsm_screen {
114 	size_t ref;
115 	unsigned int flags;
116 	struct tsm_symbol_table *sym_table;
117 
118 	/* default attributes for new cells */
119 	struct tui_screen_attr def_attr;
120 
121 	/* ageing */
122 	tsm_age_t age_cnt;
123 	unsigned int age_reset : 1;
124 
125 	/* current buffer */
126 	unsigned int size_x;
127 	unsigned int size_y;
128 	unsigned int margin_top;
129 	unsigned int margin_bottom;
130 	unsigned int line_num;
131 	struct line **lines;
132 	struct line **main_lines;
133 	struct line **alt_lines;
134 	tsm_age_t age;
135 	int vanguard;
136 
137 	/* scroll-back buffer */
138 	unsigned int sb_count;		/* number of lines in sb */
139 	struct line *sb_first;		/* first line; was moved first */
140 	struct line *sb_last;		/* last line; was moved last*/
141 	unsigned int sb_max;		/* max-limit of lines in sb */
142 	struct line *sb_pos;		/* current position in sb or NULL */
143 	uint64_t sb_last_id;		/* last id given to sb-line */
144 
145 	/* cursor */
146 	unsigned int cursor_x;
147 	unsigned int cursor_y;
148 
149 	/* tab ruler */
150 	bool *tab_ruler;
151 
152 	/* selection */
153 	bool sel_active;
154 	struct selection_pos sel_start;
155 	struct selection_pos sel_end;
156 };
157 
158 
159 #endif /* TSM_LIBTSM_INT_H */
160