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 #ifdef CONFIG_SCRIPTING_SPIDERMONKEY
65 struct JSObject
*jsobject
; /* Instance of terminal_class */
66 struct JSObject
*session_array_jsobject
; /* Instance of session_array_class */
69 /** This is (at least partially) a stack of all the windows living in
70 * this terminal. A window can be wide range of stuff, from a menu box
71 * through classical dialog window to a tab. See terminal/window.h for
74 * Tabs are special windows, though, and you never want to display them
75 * all, but only one of them. ALWAYS check inactive_tab() during
76 * iterations through this list (unless it is really useless or you
77 * are sure what are you doing) to make sure that you don't distribute
78 * events etc to inactive tabs.
80 * The stack is top-down, thus @c .next is the stack's top, the
81 * current window; and @c .prev is the bottom, covered by others.
82 * - Dialogs or active menus are at the top.
83 * - Next come all tabs (window.type == ::WINDOW_TAB). The tab
84 * listed leftmost in the tab bar is at the top, and the tab
85 * listed rightmost is at the bottom; but #current_tab controls
86 * which tab is actually displayed.
87 * - If the main menu is inactive, then it is at the very bottom,
88 * hidden under the tabs.
89 * Call assert_window_stacking() to verify this.
91 * @todo FIXME: Tabs violate the stack nature of this list, they
92 * appear there randomly but always in the order in which they were
93 * inserted there. Eventually, they should all live at the stack
94 * bottom, with the actual tab living on the VERY bottom. --pasky
96 * Keeping the current tab at the very bottom would require storing
97 * tab numbers explicitly, rather than computing them from the
98 * stack order as is done now. Also, what should be done with the
99 * inactive main menu? --KON */
100 LIST_OF(struct window
) windows
;
102 /** The specification of terminal in terms of terminal options. */
105 /** This is the terminal's current title, as perhaps displayed
106 * somewhere in the X window frame or so. */
107 unsigned char *title
;
109 /** This is the screen. See terminal/screen.h */
110 struct terminal_screen
*screen
;
112 /** This is for displaying main menu */
113 struct menu
*main_menu
;
115 /** These are pipes for communication with the ELinks instance owning
117 * @see struct itrm */
120 /** This indicates that the terminal is blocked, that is nothing should
121 * be drawn on it etc. Typically an external program is running on it
122 * right now. This is a file descriptor. */
125 /** Terminal dimensions. */
128 /** Indicates whether we are currently in the process of redrawing the
129 * stuff being displayed on the terminal. It is typically used to
130 * prevent redrawing inside of redrawing. */
131 enum term_redrawing_state redrawing
;
133 /** Indicates the master terminal, that is the terminal under
134 * supervision of the master ELinks instance (the one doing all the
135 * work and even maintaining these structures ;-). */
136 unsigned int master
:1;
139 /** Indicates whether the charset of the terminal is UTF-8. */
140 unsigned int utf8_cp
:1;
142 /** Indicates whether UTF-8 I/O is used. Forced on if the
143 * UTF-8 charset is selected. (bug 827) */
144 unsigned int utf8_io
:1;
145 #endif /* CONFIG_UTF8 */
147 /** The current tab number. */
151 /** Current length of leds part of status bar. */
155 /** The type of environment this terminal lives in. */
156 enum term_env_type environment
;
158 /** The current working directory for this terminal / ELinks instance. */
159 unsigned char cwd
[MAX_CWD_LEN
];
161 /** For communication between instances */
162 struct terminal_interlink
*interlink
;
164 /* Data for textarea_edit(). */
167 struct term_event_mouse prev_mouse_event
;
170 #define do_not_ignore_next_mouse_event(term) \
171 memset(&(term)->prev_mouse_event, 0, sizeof((term)->prev_mouse_event))
173 /** We keep track about all the terminals in this list.
174 * The list is sorted so that terminals.next is the terminal
175 * from which ELinks most recently got an event. But please
176 * call get_default_terminal() for that. */
177 extern LIST_OF(struct terminal
) terminals
;
180 extern const unsigned char frame_dumb
[];
182 struct terminal
*init_term(int, int);
183 void destroy_terminal(struct terminal
*);
184 void redraw_terminal(struct terminal
*term
);
185 void redraw_terminal_cls(struct terminal
*term
);
186 void cls_redraw_all_terminals(void);
187 struct terminal
*get_default_terminal(void);
188 int get_terminal_codepage(const struct terminal
*);
190 void redraw_all_terminals(void);
191 void destroy_all_terminals(void);
192 void exec_thread(unsigned char *, int);
193 void close_handle(void *);
195 #ifdef CONFIG_FASTMEM
196 #define assert_terminal_ptr_not_dangling(suspect) ((void) 0)
197 #else /* assert() does something */
198 void assert_terminal_ptr_not_dangling(const struct terminal
*);
201 /** Operations that can be requested with do_terminal_function() in
202 * the master and then executed with dispatch_special() in a slave.
203 * The interlink protocol passes these values as one byte in a
204 * null-terminated string, so zero cannot be used. */
208 TERM_FN_TITLE_CODEPAGE
= 3
211 /** How to execute a program in a terminal. These values are used in
212 * the interlink protocol and must fit in one byte. */
214 /** Execute in the background. ELinks keeps using the terminal
215 * and the program should not use it. */
218 /** Execute in the foreground. The program may use the terminal.
219 * ELinks will redraw when the program exits. */
222 /** Execute in the background and in a new process group. */
226 void exec_on_terminal(struct terminal
*, unsigned char *, unsigned char *, enum term_exec
);
227 void exec_shell(struct terminal
*term
);
229 int set_terminal_title(struct terminal
*, unsigned char *);
230 void do_terminal_function(struct terminal
*, unsigned char, unsigned char *);
232 int check_terminal_pipes(void);
233 void close_terminal_pipes(void);
234 struct terminal
*attach_terminal(int in
, int out
, int ctl
, void *info
, int len
);
236 extern struct module terminal_module
;
238 #endif /* EL__TERMINAL_TERMINAL_H */