1 #ifndef EL__TERMINAL_TERMINAL_H
2 #define EL__TERMINAL_TERMINAL_H
4 #include "config/options.h"
5 #include "terminal/event.h"
6 #include "util/lists.h"
10 struct terminal_screen
;
11 struct terminal_interlink
;
14 /** The terminal type, meaningful for frames (lines) drawing. */
24 /** This is a bitmask describing the environment we are living in,
25 * terminal-wise. We can then conditionally use various features available
26 * in such an environment. */
28 /** This basically means that we can use the text i/o :). Always set. */
30 /** We are running in a xterm-compatible box in some windowing
33 /** We are running under a screen. */
35 /** We are running in a OS/2 VIO terminal. */
37 /** BeOS text terminal. */
39 /** We live in a TWIN text-mode windowing environment. */
41 /** Microsoft Windows cmdline thing. */
43 /** Match all terminal environments */
47 enum term_redrawing_state
{
48 TREDRAW_READY
= 0, /**< Can redraw */
49 TREDRAW_BUSY
= 1, /**< Redrawing already in progress */
50 TREDRAW_DELAYED
= 2, /**< Do not redraw for now */
53 /** This is one of the axis of ELinks' user interaction. struct terminal
54 * defines the terminal ELinks is running on --- each ELinks instance has
55 * one. It contains the basic terminal attributes, the settings associated
56 * with this terminal, screen content (and more abstract description of what
57 * is currently displayed on it) etc. It also maintains some runtime
58 * information about the actual ELinks instance owning this terminal.
60 * @todo TODO: Regroup the following into logical chunks. --pasky */
62 LIST_HEAD(struct terminal
); /*!< ::terminals is the sentinel. */
64 /** This is (at least partially) a stack of all the windows living in
65 * this terminal. A window can be wide range of stuff, from a menu box
66 * through classical dialog window to a tab. See terminal/window.h for
69 * Tabs are special windows, though, and you never want to display them
70 * all, but only one of them. ALWAYS check inactive_tab() during
71 * iterations through this list (unless it is really useless or you
72 * are sure what are you doing) to make sure that you don't distribute
73 * events etc to inactive tabs.
75 * The stack is top-down, thus @c .next is the stack's top, the
76 * current window; and @c .prev is the bottom, covered by others.
77 * - Dialogs or active menus are at the top.
78 * - Next come all tabs (window.type == ::WINDOW_TAB). The tab
79 * listed leftmost in the tab bar is at the top, and the tab
80 * listed rightmost is at the bottom; but #current_tab controls
81 * which tab is actually displayed.
82 * - If the main menu is inactive, then it is at the very bottom,
83 * hidden under the tabs.
84 * Call assert_window_stacking() to verify this.
86 * @todo FIXME: Tabs violate the stack nature of this list, they
87 * appear there randomly but always in the order in which they were
88 * inserted there. Eventually, they should all live at the stack
89 * bottom, with the actual tab living on the VERY bottom. --pasky
91 * Keeping the current tab at the very bottom would require storing
92 * tab numbers explicitly, rather than computing them from the
93 * stack order as is done now. Also, what should be done with the
94 * inactive main menu? --KON */
95 LIST_OF(struct window
) windows
;
97 /** The specification of terminal in terms of terminal options. */
100 /** This is the terminal's current title, as perhaps displayed
101 * somewhere in the X window frame or so. */
102 unsigned char *title
;
104 /** This is the screen. See terminal/screen.h */
105 struct terminal_screen
*screen
;
107 /** This is for displaying main menu */
108 struct menu
*main_menu
;
110 /** These are pipes for communication with the ELinks instance owning
112 * @see struct itrm */
115 /** This indicates that the terminal is blocked, that is nothing should
116 * be drawn on it etc. Typically an external program is running on it
117 * right now. This is a file descriptor. */
120 /** Terminal dimensions. */
123 /** Indicates whether we are currently in the process of redrawing the
124 * stuff being displayed on the terminal. It is typically used to
125 * prevent redrawing inside of redrawing. */
126 enum term_redrawing_state redrawing
;
128 /** Indicates the master terminal, that is the terminal under
129 * supervision of the master ELinks instance (the one doing all the
130 * work and even maintaining these structures ;-). */
131 unsigned int master
:1;
134 /** Indicates whether the charset of the terminal is UTF-8. */
135 unsigned int utf8_cp
:1;
137 /** Indicates whether UTF-8 I/O is used. Forced on if the
138 * UTF-8 charset is selected. (bug 827) */
139 unsigned int utf8_io
:1;
140 #endif /* CONFIG_UTF8 */
142 /** The current tab number. */
146 /** Current length of leds part of status bar. */
150 /** The type of environment this terminal lives in. */
151 enum term_env_type environment
;
153 /** The current working directory for this terminal / ELinks instance. */
154 unsigned char cwd
[MAX_CWD_LEN
];
156 /** For communication between instances */
157 struct terminal_interlink
*interlink
;
159 /* Data for textarea_edit(). */
162 struct term_event_mouse prev_mouse_event
;
164 /** Terminal pixel resolution */
168 /** Per-terminal image cache
169 * This is an ugly hack that will go away again soon. */
170 unsigned char *imgfiles
[MAX_IMAGES
];
174 #define do_not_ignore_next_mouse_event(term) \
175 memset(&(term)->prev_mouse_event, 0, sizeof((term)->prev_mouse_event))
177 /** We keep track about all the terminals in this list.
178 * The list is sorted so that terminals.next is the terminal
179 * from which ELinks most recently got an event. But please
180 * call get_default_terminal() for that. */
181 extern LIST_OF(struct terminal
) terminals
;
184 extern const unsigned char frame_dumb
[];
186 struct terminal
*init_term(int, int);
187 void destroy_terminal(struct terminal
*);
188 void redraw_terminal(struct terminal
*term
);
189 void redraw_terminal_cls(struct terminal
*term
);
190 void cls_redraw_all_terminals(void);
191 struct terminal
*get_default_terminal(void);
192 int get_terminal_codepage(const struct terminal
*);
194 void redraw_all_terminals(void);
195 void destroy_all_terminals(void);
196 void exec_thread(unsigned char *, int);
197 void close_handle(void *);
199 #ifdef CONFIG_FASTMEM
200 #define assert_terminal_ptr_not_dangling(suspect) ((void) 0)
201 #else /* assert() does something */
202 void assert_terminal_ptr_not_dangling(const struct terminal
*);
205 /** Operations that can be requested with do_terminal_function() in
206 * the master and then executed with dispatch_special() in a slave.
207 * The interlink protocol passes these values as one byte in a
208 * null-terminated string, so zero cannot be used. */
212 TERM_FN_TITLE_CODEPAGE
= 3,
215 TERM_FN_IMG_DRAW
= 4, // imgid x y imgfile w h
216 TERM_FN_IMG_HIDE_REG
= 5, // x y w h
217 TERM_FN_IMG_SYNC
= 6,
221 /** How to execute a program in a terminal. These values are used in
222 * the interlink protocol and must fit in one byte. */
224 /** Execute in the background. ELinks keeps using the terminal
225 * and the program should not use it. */
228 /** Execute in the foreground. The program may use the terminal.
229 * ELinks will redraw when the program exits. */
232 /** Execute in the background and in a new process group. */
236 void exec_on_terminal(struct terminal
*, unsigned char *, unsigned char *, enum term_exec
);
237 void exec_shell(struct terminal
*term
);
239 int set_terminal_title(struct terminal
*, unsigned char *);
240 void do_terminal_function(struct terminal
*, unsigned char, unsigned char *);
242 int check_terminal_pipes(void);
243 void close_terminal_pipes(void);
244 struct terminal
*attach_terminal(int in
, int out
, int ctl
, void *info
, int len
);
246 extern struct module terminal_module
;
248 #endif /* EL__TERMINAL_TERMINAL_H */