[wip] Initial stab on inline images support, with many problems
[elinks/images.git] / src / terminal / terminal.h
blob7b71660e991d0b7eb4032449b3af4c9f940d2bf2
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"
8 struct module;
9 struct option;
10 struct terminal_screen;
11 struct terminal_interlink;
14 /** The terminal type, meaningful for frames (lines) drawing. */
15 enum term_mode_type {
16 TERM_DUMB = 0,
17 TERM_VT100,
18 TERM_LINUX,
19 TERM_KOI8,
20 TERM_FREEBSD,
21 TERM_FBTERM,
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. */
27 enum term_env_type {
28 /** This basically means that we can use the text i/o :). Always set. */
29 ENV_CONSOLE = 1,
30 /** We are running in a xterm-compatible box in some windowing
31 * environment. */
32 ENV_XWIN = 2,
33 /** We are running under a screen. */
34 ENV_SCREEN = 4,
35 /** We are running in a OS/2 VIO terminal. */
36 ENV_OS2VIO = 8,
37 /** BeOS text terminal. */
38 ENV_BE = 16,
39 /** We live in a TWIN text-mode windowing environment. */
40 ENV_TWIN = 32,
41 /** Microsoft Windows cmdline thing. */
42 ENV_WIN32 = 64,
43 /** Match all terminal environments */
44 ENV_ANY = ~0,
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 */
61 struct terminal {
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
67 * more on windows.
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. */
98 struct option *spec;
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
111 * this terminal.
112 * @see struct itrm */
113 int fdin, fdout;
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. */
118 int blocked;
120 /** Terminal dimensions. */
121 int width, height;
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;
133 #ifdef CONFIG_UTF8
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. */
143 int current_tab;
145 #ifdef CONFIG_LEDS
146 /** Current length of leds part of status bar. */
147 int leds_length;
148 #endif
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(). */
160 void *textarea_data;
162 struct term_event_mouse prev_mouse_event;
164 /** Terminal pixel resolution */
165 int xres, yres;
167 #ifdef CONFIG_IMAGES
168 /** Per-terminal image cache
169 * This is an ugly hack that will go away again soon. */
170 unsigned char *imgfiles[MAX_IMAGES];
171 #endif
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 *);
203 #endif
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. */
209 enum {
210 TERM_FN_TITLE = 1,
211 TERM_FN_RESIZE = 2,
212 TERM_FN_TITLE_CODEPAGE = 3,
214 #ifdef CONFIG_IMAGES
215 TERM_FN_IMG_DRAW = 4, // imgid x y imgfile w h
216 TERM_FN_IMG_MOVE = 5, // imgid x y
217 TERM_FN_IMG_HIDE = 6, // imgid
218 TERM_FN_IMG_HIDE_REG = 7, // x y w h
219 TERM_FN_IMG_SYNC = 8,
220 #endif
223 /** How to execute a program in a terminal. These values are used in
224 * the interlink protocol and must fit in one byte. */
225 enum term_exec {
226 /** Execute in the background. ELinks keeps using the terminal
227 * and the program should not use it. */
228 TERM_EXEC_BG = 0,
230 /** Execute in the foreground. The program may use the terminal.
231 * ELinks will redraw when the program exits. */
232 TERM_EXEC_FG = 1,
234 /** Execute in the background and in a new process group. */
235 TERM_EXEC_NEWWIN = 2
238 void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, enum term_exec);
239 void exec_shell(struct terminal *term);
241 int set_terminal_title(struct terminal *, unsigned char *);
242 void do_terminal_function(struct terminal *, unsigned char, unsigned char *);
244 int check_terminal_pipes(void);
245 void close_terminal_pipes(void);
246 struct terminal *attach_terminal(int in, int out, int ctl, void *info, int len);
248 extern struct module terminal_module;
250 #endif /* EL__TERMINAL_TERMINAL_H */