1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2 
3 /*
4  * !! Notice !!
5  * Don't provide any methods modifying vt_model_t and vt_logs_t states
6  * unless these are logicalized in advance.
7  */
8 
9 #ifndef __VT_TERM_H__
10 #define __VT_TERM_H__
11 
12 #include <pobl/bl_def.h> /* USE_WIN32API */
13 
14 #include "vt_pty.h"
15 #include "vt_parser.h"
16 #include "vt_screen.h"
17 
18 typedef struct vt_term {
19   /*
20    * private
21    */
22   vt_pty_t *pty;
23   vt_pty_event_listener_t *pty_listener; /* pool until pty opened. */
24 
25   vt_parser_t *parser;
26   vt_screen_t *screen;
27 
28   /*
29    * private
30    */
31   char *icon_path;
32   char *uri;
33   char *bidi_separators;
34 
35   /* vt_bidi_mode_t */ int8_t bidi_mode;
36   /* vt_vertical_mode_t */ int8_t vertical_mode;
37 
38   int8_t use_ctl;
39   int8_t use_dynamic_comb;
40   int8_t use_ot_layout;
41 
42   int8_t is_attached;
43 #ifdef OPEN_PTY_ASYNC
44   int8_t return_special_pid;
45 #endif
46 
47   void *user_data;
48 
49 } vt_term_t;
50 
51 /* XXX */
52 extern void (*vt_term_pty_closed_event)(vt_term_t *);
53 
54 #if defined(__ANDROID__) && defined(USE_LIBSSH2)
55 /* XXX */
56 extern int start_with_local_pty;
57 #endif
58 
59 #define vt_term_init vt_parser_init
60 
61 void vt_term_final(void);
62 
63 vt_term_t *vt_term_new(const char *term_type, u_int cols, u_int rows, u_int tab_size,
64                        u_int log_size, vt_char_encoding_t encoding, int is_auto_encoding,
65                        int use_auto_detect, int logging_vt_seq, vt_unicode_policy_t policy,
66                        u_int col_size_a, int use_char_combining, int use_multi_col_char,
67                        int use_ctl, vt_bidi_mode_t bidi_mode, const char *bidi_separators,
68                        int use_dynamic_comb, vt_bs_mode_t bs_mode, vt_vertical_mode_t vertical_mode,
69                        int use_local_echo, const char *win_name, const char *icon_name,
70                        int use_ansi_colors, vt_alt_color_mode_t alt_color_mode, int use_ot_layout,
71                        vt_cursor_style_t cursor_style, int ignore_broadcasted_chars);
72 
73 void vt_term_destroy(vt_term_t *term);
74 
75 void vt_term_zombie(vt_term_t *term);
76 
77 int vt_term_open_pty(vt_term_t *term, const char *cmd_path, char **argv, char **env,
78                      const char *host, const char *work_dir, const char *pass, const char *pubkey,
79                      const char *privkey, u_int width_pix, u_int height_pix);
80 
81 int vt_term_plug_pty(vt_term_t *term, vt_pty_t *pty);
82 
83 #define vt_term_pty_is_opened(term) ((term)->pty != NULL)
84 
85 int vt_term_attach(vt_term_t *term, vt_xterm_event_listener_t *xterm_listener,
86                    vt_config_event_listener_t *config_listener,
87                    vt_screen_event_listener_t *screen_listener,
88                    vt_pty_event_listener_t *pty_listner);
89 
90 int vt_term_detach(vt_term_t *term);
91 
92 #define vt_term_is_attached(term) ((term)->is_attached)
93 
94 #define vt_term_is_sending_data(term) vt_parser_is_sending_data((term)->parser)
95 
96 #define vt_term_is_zmodem_ready(term) vt_parser_is_zmodem_ready((term)->parser)
97 
98 #define vt_term_parse_vt100_sequence(term) vt_parse_vt100_sequence((term)->parser)
99 
100 #define vt_term_reset_pending_vt100_sequence(term) vt_reset_pending_vt100_sequence((term)->parser)
101 
102 #define vt_term_response_config(term, key, value, to_menu) \
103   vt_response_config((term)->pty, key, value, to_menu)
104 
105 #define vt_term_change_encoding(term, encoding) \
106   vt_parser_change_encoding((term)->parser, encoding)
107 
108 #define vt_term_get_encoding(term) vt_parser_get_encoding((term)->parser)
109 
110 #define vt_term_set_use_ctl(term, flag) ((term)->use_ctl = (flag))
111 
112 #define vt_term_is_using_ctl(term) ((term)->use_ctl)
113 
114 #define vt_term_set_bidi_mode(term, mode) ((term)->bidi_mode = (mode))
115 
116 #define vt_term_get_bidi_mode(term) ((term)->bidi_mode)
117 
118 void vt_term_set_use_ot_layout(vt_term_t *term, int flag);
119 
120 #define vt_term_is_using_ot_layout(term) ((term)->use_ot_layout)
121 
122 #define vt_term_set_vertical_mode(term, mode) ((term)->vertical_mode = (mode))
123 
124 #define vt_term_get_vertical_mode(term) ((term)->vertical_mode)
125 
126 #define vt_term_set_use_dynamic_comb(term, use) ((term)->use_dynamic_comb = (use))
127 
128 #define vt_term_is_using_dynamic_comb(term) ((term)->use_dynamic_comb)
129 
130 #define vt_term_convert_to(term, dst, len, _parser) \
131   vt_parser_convert_to((term)->parser, dst, len, _parser)
132 
133 #define vt_term_init_encoding_conv(term) vt_init_encoding_conv((term)->parser)
134 
135 int vt_term_get_master_fd(vt_term_t *term);
136 
137 int vt_term_get_slave_fd(vt_term_t *term);
138 
139 char *vt_term_get_slave_name(vt_term_t *term);
140 
141 pid_t vt_term_get_child_pid(vt_term_t *term);
142 
143 pid_t vt_term_get_pty_mode(vt_term_t *term);
144 
145 size_t vt_term_write(vt_term_t *term, u_char *buf, size_t len);
146 
147 #define vt_term_write_modified_key(term, key, modcode) \
148   ((term)->pty ? vt_parser_write_modified_key((term)->parser, key, modcode) : 0)
149 
150 #define vt_term_write_special_key(term, key, modcode, is_numlock) \
151   ((term)->pty ? vt_parser_write_special_key((term)->parser, key, modcode, is_numlock) : 0)
152 
153 /* Must be called in visual context. */
154 #define vt_term_write_loopback(term, buf, len) \
155   vt_parser_write_loopback((term)->parser, buf, len)
156 
157 /* Must be called in visual context. */
158 #define vt_term_show_message(term, msg) vt_parser_show_message((term)->parser, msg)
159 
160 #if 1 /* defined(__ANDROID__) || defined(__APPLE__) || defined(USE_SDL2) */
161 /* Must be called in visual context. */
162 #define vt_term_preedit(term, buf, len) vt_parser_preedit((term)->parser, buf, len)
163 #endif
164 
165 int vt_term_resize(vt_term_t *term, u_int cols, u_int rows, u_int width_pix, u_int height_pix);
166 
167 #define vt_term_cursor_col(term) vt_screen_cursor_col((term)->screen)
168 
169 #define vt_term_cursor_char_index(term) vt_screen_cursor_char_index((term)->screen)
170 
171 #define vt_term_cursor_row(term) vt_screen_cursor_row((term)->screen)
172 
173 #define vt_term_cursor_row_in_screen(term) vt_screen_cursor_row_in_screen((term)->screen)
174 
175 int vt_term_unhighlight_cursor(vt_term_t *term, int revert_visual);
176 
177 #define vt_term_get_cols(term) vt_screen_get_cols((term)->screen)
178 
179 #define vt_term_get_rows(term) vt_screen_get_rows((term)->screen)
180 
181 #define vt_term_get_logical_cols(term) vt_screen_get_logical_cols((term)->screen)
182 
183 #define vt_term_get_logical_rows(term) vt_screen_get_logical_rows((term)->screen)
184 
185 #define vt_term_get_log_size(term) vt_screen_get_log_size((term)->screen)
186 
187 #define vt_term_change_log_size(term, log_size) vt_screen_change_log_size((term)->screen, log_size)
188 
189 #define vt_term_unlimit_log_size(term) vt_screen_unlimit_log_size((term)->screen)
190 
191 #define vt_term_log_size_is_unlimited(term) vt_screen_log_size_is_unlimited((term)->screen)
192 
193 #define vt_term_get_num_logged_lines(term) vt_screen_get_num_logged_lines((term)->screen)
194 
195 #define vt_term_convert_scr_row_to_abs(term, row) \
196   vt_screen_convert_scr_row_to_abs((term)->screen, row)
197 
198 #define vt_term_get_line(term, row) vt_screen_get_line(term->screen, row)
199 
200 #define vt_term_get_line_in_screen(term, row) vt_screen_get_line_in_screen((term)->screen, row)
201 
202 #define vt_term_get_cursor_line(term) vt_screen_get_cursor_line((term)->screen)
203 
204 #if 0
205 void vt_term_set_modified_region(vt_term_t *term, int beg_char_index, int beg_row, u_int nchars,
206                                  u_int nrows);
207 
208 void vt_term_set_modified_region_in_screen(vt_term_t *term, int beg_char_index, int beg_row,
209                                            u_int nchars, u_int nrows);
210 #endif
211 
212 void vt_term_set_modified_lines(vt_term_t *term, int beg, int end);
213 
214 void vt_term_set_modified_lines_in_screen(vt_term_t *term, int beg, int end);
215 
216 void vt_term_set_modified_all_lines_in_screen(vt_term_t *term);
217 
218 void vt_term_updated_all(vt_term_t *term);
219 
220 int vt_term_update_special_visual(vt_term_t *term);
221 
222 #define vt_term_has_logical_visual(term) \
223   vt_screen_has_logical_visual((term)->screen)
224 
225 #define vt_term_is_backscrolling(term) vt_screen_is_backscrolling((term)->screen)
226 
227 int vt_term_enter_backscroll_mode(vt_term_t *term);
228 
229 #define vt_term_exit_backscroll_mode(term) vt_exit_backscroll_mode((term)->screen)
230 
231 #define vt_term_backscroll_to(term, row) vt_screen_backscroll_to((term)->screen, row)
232 
233 #define vt_term_backscroll_upward(term, size) vt_screen_backscroll_upward((term)->screen, size)
234 
235 #define vt_term_backscroll_downward(term, size) vt_screen_backscroll_downward((term)->screen, size)
236 
237 #define vt_term_backscroll_upward_to_mark(term, row) \
238   vt_screen_backscroll_upward_to_mark((term)->screen, row)
239 
240 #define vt_term_backscroll_downward_to_mark(term, row) \
241   vt_screen_backscroll_downward_to_mark((term)->screen, row)
242 
243 #define vt_term_reverse_color(term, beg_char_index, beg_row, end_char_index, end_row, is_rect) \
244   vt_screen_reverse_color((term)->screen, beg_char_index, beg_row, end_char_index, end_row, is_rect)
245 
246 #define vt_term_restore_color(term, beg_char_index, beg_row, end_char_index, end_row, is_rect) \
247   vt_screen_restore_color((term)->screen, beg_char_index, beg_row, end_char_index, end_row, is_rect)
248 
249 #define vt_term_copy_region(term, chars, num_chars, beg_char_index, beg_row, end_char_index, \
250                             end_row, is_rect)                                                   \
251   vt_screen_copy_region((term)->screen, chars, num_chars, beg_char_index, beg_row,           \
252                         end_char_index, end_row, is_rect)
253 
254 #define vt_term_get_region_size(term, beg_char_index, beg_row, end_char_index, end_row, is_rect) \
255   vt_screen_get_region_size((term)->screen, beg_char_index, beg_row, end_char_index, end_row,    \
256                             is_rect)
257 
258 #define vt_term_get_line_region(term, beg_row, end_char_index, end_row, base_row) \
259   vt_screen_get_line_region((term)->screen, beg_row, end_char_index, end_row, base_row)
260 
261 #define vt_term_get_word_region(term, beg_char_index, beg_row, end_char_index, end_row,       \
262                                 base_char_index, base_row)                                    \
263   vt_screen_get_word_region((term)->screen, beg_char_index, beg_row, end_char_index, end_row, \
264                             base_char_index, base_row)
265 
266 #define vt_term_get_bce_ch(term) vt_screen_get_bce_ch((term)->screen)
267 
268 #define vt_term_write_content(term, fd, conv, clear_at_end, area) \
269   vt_screen_write_content(term->screen, fd, conv, clear_at_end, area)
270 
271 #define vt_term_cursor_is_rtl(term) vt_screen_cursor_is_rtl((term)->screen)
272 
273 #define vt_term_set_use_multi_col_char(term, flag) \
274   vt_parser_set_use_multi_col_char((term)->parser, flag)
275 
276 #define vt_term_is_using_multi_col_char(term) \
277   vt_parser_is_using_multi_col_char((term)->parser)
278 
279 #define vt_term_get_mouse_report_mode(term) vt_parser_get_mouse_report_mode((term)->parser)
280 
281 #define vt_term_want_focus_event(term) vt_parser_want_focus_event((term)->parser)
282 
283 #define vt_term_set_alt_color_mode(term, mode) \
284   vt_parser_set_alt_color_mode((term)->parser, mode)
285 
286 #define vt_term_get_alt_color_mode(term) vt_parser_get_alt_color_mode((term)->parser)
287 
288 #define vt_term_is_broadcasting(term) vt_parser_is_broadcasting((term)->parser)
289 
290 void vt_term_set_icon_path(vt_term_t *term, const char *path);
291 
292 #define vt_term_window_name(term) vt_get_window_name((term)->parser)
293 
294 #define vt_term_icon_name(term) vt_get_icon_name((term)->parser)
295 
296 #define vt_term_icon_path(term) ((term)->icon_path)
297 
298 #define vt_term_get_uri(term) ((term)->uri)
299 
300 #define vt_term_is_bracketed_paste_mode(term) \
301   vt_parser_is_bracketed_paste_mode((term)->parser)
302 
303 #define vt_term_set_unicode_policy(term, policy) \
304   vt_parser_set_unicode_policy((term)->parser, policy)
305 
306 #define vt_term_get_unicode_policy(term) vt_parser_get_unicode_policy((term)->parser)
307 
308 void vt_term_set_bidi_separators(vt_term_t *term, const char *bidi_separators);
309 
310 #define vt_term_get_cmd_line(term) vt_pty_get_cmd_line((term)->pty)
311 
312 #define vt_term_start_config_menu(term, cmd_path, x, y, display) \
313   vt_start_config_menu((term)->pty, cmd_path, x, y, display)
314 
315 #define vt_term_has_pending_sequence(term) vt_parser_has_pending_sequence((term)->parser)
316 
317 int vt_term_get_config(vt_term_t *term, vt_term_t *output, char *key, int to_menu, int *flag);
318 
319 int vt_term_set_config(vt_term_t *term, char *key, char *value);
320 
321 #define vt_term_exec_cmd(term, cmd) vt_parser_exec_cmd((term)->parser, cmd)
322 
323 #define vt_term_reset(term, level) vt_parser_reset((term)->parser, level)
324 
325 #define vt_term_report_mouse_tracking(term, col, row, button, is_released, key_state,             \
326                                       button_state)                                               \
327   vt_parser_report_mouse_tracking((term)->parser, col, row, button, is_released, key_state, \
328                                         button_state)
329 
330 #define vt_term_search_init(term, char_index, row, match) \
331   vt_screen_search_init((term)->screen, char_index, row, match)
332 
333 #define vt_term_search_final(term) vt_screen_search_final((term)->screen)
334 
335 #define vt_term_search_reset_position(term) vt_screen_search_reset_position((term)->screen)
336 
337 #define vt_term_search_find(term, beg_char_index, beg_row, end_char_index, end_row, regex,       \
338                             backward)                                                            \
339   vt_screen_search_find((term)->screen, beg_char_index, beg_row, end_char_index, end_row, regex, \
340                         backward)
341 
342 #define vt_term_blink(term) vt_screen_blink((term)->screen)
343 
344 #define vt_term_has_status_line(term) vt_screen_has_status_line((term)->screen)
345 
346 #define vt_term_get_user_data(term, key) ((term)->user_data)
347 
348 #define vt_term_set_user_data(term, key, val) ((term)->user_data = (val))
349 
350 #define vt_term_select_drcs(term) vt_parser_select_drcs((term)->parser)
351 
352 #define vt_term_is_visible_cursor(term) vt_parser_is_visible_cursor((term)->parser)
353 
354 #define vt_term_get_cursor_style(term) vt_parser_get_cursor_style((term)->parser)
355 
356 #define vt_term_get_hide_pointer_mode(term) vt_parser_get_hide_pointer_mode((term)->parser)
357 
358 #endif
359