xref: /openbsd-src/usr.bin/tmux/tmux.h (revision 7c0ec4b8992567abb1e1536622dc789a9a39d9f1)
1 /* $OpenBSD: tmux.h,v 1.1226 2024/08/27 07:49:07 nicm Exp $ */
2 
3 /*
4  * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef TMUX_H
20 #define TMUX_H
21 
22 #include <sys/time.h>
23 #include <sys/queue.h>
24 #include <sys/tree.h>
25 
26 #include <bitstring.h>
27 #include <event.h>
28 #include <limits.h>
29 #include <stdarg.h>
30 #include <stdint.h>
31 #include <stdio.h>
32 #include <termios.h>
33 #include <wchar.h>
34 
35 #include "tmux-protocol.h"
36 #include "xmalloc.h"
37 
38 extern char   **environ;
39 
40 struct args;
41 struct args_command_state;
42 struct client;
43 struct cmd;
44 struct cmd_find_state;
45 struct cmdq_item;
46 struct cmdq_list;
47 struct cmdq_state;
48 struct cmds;
49 struct control_state;
50 struct environ;
51 struct format_job_tree;
52 struct format_tree;
53 struct hyperlinks_uri;
54 struct hyperlinks;
55 struct input_ctx;
56 struct job;
57 struct menu_data;
58 struct mode_tree_data;
59 struct mouse_event;
60 struct options;
61 struct options_array_item;
62 struct options_entry;
63 struct screen_write_citem;
64 struct screen_write_cline;
65 struct screen_write_ctx;
66 struct session;
67 struct tty_ctx;
68 struct tty_code;
69 struct tty_key;
70 struct tmuxpeer;
71 struct tmuxproc;
72 struct winlink;
73 
74 /* Default configuration files and socket paths. */
75 #ifndef TMUX_CONF
76 #define TMUX_CONF "/etc/tmux.conf:~/.tmux.conf"
77 #endif
78 #ifndef TMUX_SOCK
79 #define TMUX_SOCK "$TMUX_TMPDIR:" _PATH_TMP
80 #endif
81 #ifndef TMUX_TERM
82 #define TMUX_TERM "screen"
83 #endif
84 
85 /* Minimum layout cell size, NOT including border lines. */
86 #define PANE_MINIMUM 1
87 
88 /* Minimum and maximum window size. */
89 #define WINDOW_MINIMUM PANE_MINIMUM
90 #define WINDOW_MAXIMUM 10000
91 
92 /* Automatic name refresh interval, in microseconds. Must be < 1 second. */
93 #define NAME_INTERVAL 500000
94 
95 /* Default pixel cell sizes. */
96 #define DEFAULT_XPIXEL 16
97 #define DEFAULT_YPIXEL 32
98 
99 /* Attribute to make GCC check printf-like arguments. */
100 #define printflike(a, b) __attribute__ ((format (printf, a, b)))
101 
102 /* Number of items in array. */
103 #ifndef nitems
104 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
105 #endif
106 
107 /* Alert option values. */
108 #define ALERT_NONE 0
109 #define ALERT_ANY 1
110 #define ALERT_CURRENT 2
111 #define ALERT_OTHER 3
112 
113 /* Visual option values. */
114 #define VISUAL_OFF 0
115 #define VISUAL_ON 1
116 #define VISUAL_BOTH 2
117 
118 /* No key or unknown key. */
119 #define KEYC_NONE            0x000ff000000000ULL
120 #define KEYC_UNKNOWN         0x000fe000000000ULL
121 
122 /*
123  * Base for special (that is, not Unicode) keys. An enum must be at most a
124  * signed int, so these are based in the highest Unicode PUA.
125  */
126 #define KEYC_BASE            0x0000000010e000ULL
127 #define KEYC_USER            0x0000000010f000ULL
128 #define KEYC_USER_END	     (KEYC_USER + KEYC_NUSER)
129 
130 /* Key modifier bits. */
131 #define KEYC_META            0x00100000000000ULL
132 #define KEYC_CTRL            0x00200000000000ULL
133 #define KEYC_SHIFT           0x00400000000000ULL
134 
135 /* Key flag bits. */
136 #define KEYC_LITERAL	     0x01000000000000ULL
137 #define KEYC_KEYPAD	     0x02000000000000ULL
138 #define KEYC_CURSOR	     0x04000000000000ULL
139 #define KEYC_IMPLIED_META    0x08000000000000ULL
140 #define KEYC_BUILD_MODIFIERS 0x10000000000000ULL
141 #define KEYC_VI		     0x20000000000000ULL
142 #define KEYC_SENT	     0x40000000000000ULL
143 
144 /* Masks for key bits. */
145 #define KEYC_MASK_MODIFIERS  0x00f00000000000ULL
146 #define KEYC_MASK_FLAGS      0xff000000000000ULL
147 #define KEYC_MASK_KEY        0x000fffffffffffULL
148 
149 /* Available user keys. */
150 #define KEYC_NUSER 1000
151 
152 /* Is this a mouse key? */
153 #define KEYC_IS_MOUSE(key) \
154 	(((key) & KEYC_MASK_KEY) >= KEYC_MOUSE && \
155 	 ((key) & KEYC_MASK_KEY) < KEYC_BSPACE)
156 
157 /* Is this a Unicode key? */
158 #define KEYC_IS_UNICODE(key) \
159 	(((key) & KEYC_MASK_KEY) > 0x7f && \
160 	 (((key) & KEYC_MASK_KEY) < KEYC_BASE || \
161 	  ((key) & KEYC_MASK_KEY) >= KEYC_BASE_END) && \
162 	 (((key) & KEYC_MASK_KEY) < KEYC_USER || \
163 	  ((key) & KEYC_MASK_KEY) >= KEYC_USER_END))
164 
165 /* Multiple click timeout. */
166 #define KEYC_CLICK_TIMEOUT 300
167 
168 /* Mouse key codes. */
169 #define KEYC_MOUSE_KEY(name)					\
170 	KEYC_ ## name ## _PANE,					\
171 	KEYC_ ## name ## _STATUS,				\
172 	KEYC_ ## name ## _STATUS_LEFT,				\
173 	KEYC_ ## name ## _STATUS_RIGHT,				\
174 	KEYC_ ## name ## _STATUS_DEFAULT,			\
175 	KEYC_ ## name ## _BORDER
176 #define KEYC_MOUSE_STRING(name, s)				\
177 	{ #s "Pane", KEYC_ ## name ## _PANE },			\
178 	{ #s "Status", KEYC_ ## name ## _STATUS },		\
179 	{ #s "StatusLeft", KEYC_ ## name ## _STATUS_LEFT },	\
180 	{ #s "StatusRight", KEYC_ ## name ## _STATUS_RIGHT },	\
181 	{ #s "StatusDefault", KEYC_ ## name ## _STATUS_DEFAULT }, \
182 	{ #s "Border", KEYC_ ## name ## _BORDER }
183 
184 /*
185  * A single key. This can be ASCII or Unicode or one of the keys between
186  * KEYC_BASE and KEYC_BASE_END.
187  */
188 typedef unsigned long long key_code;
189 
190 /* C0 control characters */
191 enum {
192 	C0_NUL,
193 	C0_SOH,
194 	C0_STX,
195 	C0_ETX,
196 	C0_EOT,
197 	C0_ENQ,
198 	C0_ASC,
199 	C0_BEL,
200 	C0_BS,
201 	C0_HT,
202 	C0_LF,
203 	C0_VT,
204 	C0_FF,
205 	C0_CR,
206 	C0_SO,
207 	C0_SI,
208 	C0_DLE,
209 	C0_DC1,
210 	C0_DC2,
211 	C0_DC3,
212 	C0_DC4,
213 	C0_NAK,
214 	C0_SYN,
215 	C0_ETB,
216 	C0_CAN,
217 	C0_EM,
218 	C0_SUB,
219 	C0_ESC,
220 	C0_FS,
221 	C0_GS,
222 	C0_RS,
223 	C0_US
224 };
225 
226 /* Special key codes. */
227 enum {
228 	/* Focus events. */
229 	KEYC_FOCUS_IN = KEYC_BASE,
230 	KEYC_FOCUS_OUT,
231 
232 	/* "Any" key, used if not found in key table. */
233 	KEYC_ANY,
234 
235 	/* Paste brackets. */
236 	KEYC_PASTE_START,
237 	KEYC_PASTE_END,
238 
239 	/* Mouse keys. */
240 	KEYC_MOUSE, /* unclassified mouse event */
241 	KEYC_DRAGGING, /* dragging in progress */
242 	KEYC_DOUBLECLICK, /* double click complete */
243 	KEYC_MOUSE_KEY(MOUSEMOVE),
244 	KEYC_MOUSE_KEY(MOUSEDOWN1),
245 	KEYC_MOUSE_KEY(MOUSEDOWN2),
246 	KEYC_MOUSE_KEY(MOUSEDOWN3),
247 	KEYC_MOUSE_KEY(MOUSEDOWN6),
248 	KEYC_MOUSE_KEY(MOUSEDOWN7),
249 	KEYC_MOUSE_KEY(MOUSEDOWN8),
250 	KEYC_MOUSE_KEY(MOUSEDOWN9),
251 	KEYC_MOUSE_KEY(MOUSEDOWN10),
252 	KEYC_MOUSE_KEY(MOUSEDOWN11),
253 	KEYC_MOUSE_KEY(MOUSEUP1),
254 	KEYC_MOUSE_KEY(MOUSEUP2),
255 	KEYC_MOUSE_KEY(MOUSEUP3),
256 	KEYC_MOUSE_KEY(MOUSEUP6),
257 	KEYC_MOUSE_KEY(MOUSEUP7),
258 	KEYC_MOUSE_KEY(MOUSEUP8),
259 	KEYC_MOUSE_KEY(MOUSEUP9),
260 	KEYC_MOUSE_KEY(MOUSEUP10),
261 	KEYC_MOUSE_KEY(MOUSEUP11),
262 	KEYC_MOUSE_KEY(MOUSEDRAG1),
263 	KEYC_MOUSE_KEY(MOUSEDRAG2),
264 	KEYC_MOUSE_KEY(MOUSEDRAG3),
265 	KEYC_MOUSE_KEY(MOUSEDRAG6),
266 	KEYC_MOUSE_KEY(MOUSEDRAG7),
267 	KEYC_MOUSE_KEY(MOUSEDRAG8),
268 	KEYC_MOUSE_KEY(MOUSEDRAG9),
269 	KEYC_MOUSE_KEY(MOUSEDRAG10),
270 	KEYC_MOUSE_KEY(MOUSEDRAG11),
271 	KEYC_MOUSE_KEY(MOUSEDRAGEND1),
272 	KEYC_MOUSE_KEY(MOUSEDRAGEND2),
273 	KEYC_MOUSE_KEY(MOUSEDRAGEND3),
274 	KEYC_MOUSE_KEY(MOUSEDRAGEND6),
275 	KEYC_MOUSE_KEY(MOUSEDRAGEND7),
276 	KEYC_MOUSE_KEY(MOUSEDRAGEND8),
277 	KEYC_MOUSE_KEY(MOUSEDRAGEND9),
278 	KEYC_MOUSE_KEY(MOUSEDRAGEND10),
279 	KEYC_MOUSE_KEY(MOUSEDRAGEND11),
280 	KEYC_MOUSE_KEY(WHEELUP),
281 	KEYC_MOUSE_KEY(WHEELDOWN),
282 	KEYC_MOUSE_KEY(SECONDCLICK1),
283 	KEYC_MOUSE_KEY(SECONDCLICK2),
284 	KEYC_MOUSE_KEY(SECONDCLICK3),
285 	KEYC_MOUSE_KEY(SECONDCLICK6),
286 	KEYC_MOUSE_KEY(SECONDCLICK7),
287 	KEYC_MOUSE_KEY(SECONDCLICK8),
288 	KEYC_MOUSE_KEY(SECONDCLICK9),
289 	KEYC_MOUSE_KEY(SECONDCLICK10),
290 	KEYC_MOUSE_KEY(SECONDCLICK11),
291 	KEYC_MOUSE_KEY(DOUBLECLICK1),
292 	KEYC_MOUSE_KEY(DOUBLECLICK2),
293 	KEYC_MOUSE_KEY(DOUBLECLICK3),
294 	KEYC_MOUSE_KEY(DOUBLECLICK6),
295 	KEYC_MOUSE_KEY(DOUBLECLICK7),
296 	KEYC_MOUSE_KEY(DOUBLECLICK8),
297 	KEYC_MOUSE_KEY(DOUBLECLICK9),
298 	KEYC_MOUSE_KEY(DOUBLECLICK10),
299 	KEYC_MOUSE_KEY(DOUBLECLICK11),
300 	KEYC_MOUSE_KEY(TRIPLECLICK1),
301 	KEYC_MOUSE_KEY(TRIPLECLICK2),
302 	KEYC_MOUSE_KEY(TRIPLECLICK3),
303 	KEYC_MOUSE_KEY(TRIPLECLICK6),
304 	KEYC_MOUSE_KEY(TRIPLECLICK7),
305 	KEYC_MOUSE_KEY(TRIPLECLICK8),
306 	KEYC_MOUSE_KEY(TRIPLECLICK9),
307 	KEYC_MOUSE_KEY(TRIPLECLICK10),
308 	KEYC_MOUSE_KEY(TRIPLECLICK11),
309 
310 	/* Backspace key. */
311 	KEYC_BSPACE,
312 
313 	/* Function keys. */
314 	KEYC_F1,
315 	KEYC_F2,
316 	KEYC_F3,
317 	KEYC_F4,
318 	KEYC_F5,
319 	KEYC_F6,
320 	KEYC_F7,
321 	KEYC_F8,
322 	KEYC_F9,
323 	KEYC_F10,
324 	KEYC_F11,
325 	KEYC_F12,
326 	KEYC_IC,
327 	KEYC_DC,
328 	KEYC_HOME,
329 	KEYC_END,
330 	KEYC_NPAGE,
331 	KEYC_PPAGE,
332 	KEYC_BTAB,
333 
334 	/* Arrow keys. */
335 	KEYC_UP,
336 	KEYC_DOWN,
337 	KEYC_LEFT,
338 	KEYC_RIGHT,
339 
340 	/* Numeric keypad. */
341 	KEYC_KP_SLASH,
342 	KEYC_KP_STAR,
343 	KEYC_KP_MINUS,
344 	KEYC_KP_SEVEN,
345 	KEYC_KP_EIGHT,
346 	KEYC_KP_NINE,
347 	KEYC_KP_PLUS,
348 	KEYC_KP_FOUR,
349 	KEYC_KP_FIVE,
350 	KEYC_KP_SIX,
351 	KEYC_KP_ONE,
352 	KEYC_KP_TWO,
353 	KEYC_KP_THREE,
354 	KEYC_KP_ENTER,
355 	KEYC_KP_ZERO,
356 	KEYC_KP_PERIOD,
357 
358 	/* End of special keys. */
359 	KEYC_BASE_END
360 };
361 
362 /* Termcap codes. */
363 enum tty_code_code {
364 	TTYC_ACSC,
365 	TTYC_AM,
366 	TTYC_AX,
367 	TTYC_BCE,
368 	TTYC_BEL,
369 	TTYC_BIDI,
370 	TTYC_BLINK,
371 	TTYC_BOLD,
372 	TTYC_CIVIS,
373 	TTYC_CLEAR,
374 	TTYC_CLMG,
375 	TTYC_CMG,
376 	TTYC_CNORM,
377 	TTYC_COLORS,
378 	TTYC_CR,
379 	TTYC_CS,
380 	TTYC_CSR,
381 	TTYC_CUB,
382 	TTYC_CUB1,
383 	TTYC_CUD,
384 	TTYC_CUD1,
385 	TTYC_CUF,
386 	TTYC_CUF1,
387 	TTYC_CUP,
388 	TTYC_CUU,
389 	TTYC_CUU1,
390 	TTYC_CVVIS,
391 	TTYC_DCH,
392 	TTYC_DCH1,
393 	TTYC_DIM,
394 	TTYC_DL,
395 	TTYC_DL1,
396 	TTYC_DSBP,
397 	TTYC_DSEKS,
398 	TTYC_DSFCS,
399 	TTYC_DSMG,
400 	TTYC_E3,
401 	TTYC_ECH,
402 	TTYC_ED,
403 	TTYC_EL,
404 	TTYC_EL1,
405 	TTYC_ENACS,
406 	TTYC_ENBP,
407 	TTYC_ENEKS,
408 	TTYC_ENFCS,
409 	TTYC_ENMG,
410 	TTYC_FSL,
411 	TTYC_HLS,
412 	TTYC_HOME,
413 	TTYC_HPA,
414 	TTYC_ICH,
415 	TTYC_ICH1,
416 	TTYC_IL,
417 	TTYC_IL1,
418 	TTYC_INDN,
419 	TTYC_INVIS,
420 	TTYC_KCBT,
421 	TTYC_KCUB1,
422 	TTYC_KCUD1,
423 	TTYC_KCUF1,
424 	TTYC_KCUU1,
425 	TTYC_KDC2,
426 	TTYC_KDC3,
427 	TTYC_KDC4,
428 	TTYC_KDC5,
429 	TTYC_KDC6,
430 	TTYC_KDC7,
431 	TTYC_KDCH1,
432 	TTYC_KDN2,
433 	TTYC_KDN3,
434 	TTYC_KDN4,
435 	TTYC_KDN5,
436 	TTYC_KDN6,
437 	TTYC_KDN7,
438 	TTYC_KEND,
439 	TTYC_KEND2,
440 	TTYC_KEND3,
441 	TTYC_KEND4,
442 	TTYC_KEND5,
443 	TTYC_KEND6,
444 	TTYC_KEND7,
445 	TTYC_KF1,
446 	TTYC_KF10,
447 	TTYC_KF11,
448 	TTYC_KF12,
449 	TTYC_KF13,
450 	TTYC_KF14,
451 	TTYC_KF15,
452 	TTYC_KF16,
453 	TTYC_KF17,
454 	TTYC_KF18,
455 	TTYC_KF19,
456 	TTYC_KF2,
457 	TTYC_KF20,
458 	TTYC_KF21,
459 	TTYC_KF22,
460 	TTYC_KF23,
461 	TTYC_KF24,
462 	TTYC_KF25,
463 	TTYC_KF26,
464 	TTYC_KF27,
465 	TTYC_KF28,
466 	TTYC_KF29,
467 	TTYC_KF3,
468 	TTYC_KF30,
469 	TTYC_KF31,
470 	TTYC_KF32,
471 	TTYC_KF33,
472 	TTYC_KF34,
473 	TTYC_KF35,
474 	TTYC_KF36,
475 	TTYC_KF37,
476 	TTYC_KF38,
477 	TTYC_KF39,
478 	TTYC_KF4,
479 	TTYC_KF40,
480 	TTYC_KF41,
481 	TTYC_KF42,
482 	TTYC_KF43,
483 	TTYC_KF44,
484 	TTYC_KF45,
485 	TTYC_KF46,
486 	TTYC_KF47,
487 	TTYC_KF48,
488 	TTYC_KF49,
489 	TTYC_KF5,
490 	TTYC_KF50,
491 	TTYC_KF51,
492 	TTYC_KF52,
493 	TTYC_KF53,
494 	TTYC_KF54,
495 	TTYC_KF55,
496 	TTYC_KF56,
497 	TTYC_KF57,
498 	TTYC_KF58,
499 	TTYC_KF59,
500 	TTYC_KF6,
501 	TTYC_KF60,
502 	TTYC_KF61,
503 	TTYC_KF62,
504 	TTYC_KF63,
505 	TTYC_KF7,
506 	TTYC_KF8,
507 	TTYC_KF9,
508 	TTYC_KHOM2,
509 	TTYC_KHOM3,
510 	TTYC_KHOM4,
511 	TTYC_KHOM5,
512 	TTYC_KHOM6,
513 	TTYC_KHOM7,
514 	TTYC_KHOME,
515 	TTYC_KIC2,
516 	TTYC_KIC3,
517 	TTYC_KIC4,
518 	TTYC_KIC5,
519 	TTYC_KIC6,
520 	TTYC_KIC7,
521 	TTYC_KICH1,
522 	TTYC_KIND,
523 	TTYC_KLFT2,
524 	TTYC_KLFT3,
525 	TTYC_KLFT4,
526 	TTYC_KLFT5,
527 	TTYC_KLFT6,
528 	TTYC_KLFT7,
529 	TTYC_KMOUS,
530 	TTYC_KNP,
531 	TTYC_KNXT2,
532 	TTYC_KNXT3,
533 	TTYC_KNXT4,
534 	TTYC_KNXT5,
535 	TTYC_KNXT6,
536 	TTYC_KNXT7,
537 	TTYC_KPP,
538 	TTYC_KPRV2,
539 	TTYC_KPRV3,
540 	TTYC_KPRV4,
541 	TTYC_KPRV5,
542 	TTYC_KPRV6,
543 	TTYC_KPRV7,
544 	TTYC_KRI,
545 	TTYC_KRIT2,
546 	TTYC_KRIT3,
547 	TTYC_KRIT4,
548 	TTYC_KRIT5,
549 	TTYC_KRIT6,
550 	TTYC_KRIT7,
551 	TTYC_KUP2,
552 	TTYC_KUP3,
553 	TTYC_KUP4,
554 	TTYC_KUP5,
555 	TTYC_KUP6,
556 	TTYC_KUP7,
557 	TTYC_MS,
558 	TTYC_NOBR,
559 	TTYC_OL,
560 	TTYC_OP,
561 	TTYC_RECT,
562 	TTYC_REV,
563 	TTYC_RGB,
564 	TTYC_RI,
565 	TTYC_RIN,
566 	TTYC_RMACS,
567 	TTYC_RMCUP,
568 	TTYC_RMKX,
569 	TTYC_SE,
570 	TTYC_SETAB,
571 	TTYC_SETAF,
572 	TTYC_SETAL,
573 	TTYC_SETRGBB,
574 	TTYC_SETRGBF,
575 	TTYC_SETULC,
576 	TTYC_SETULC1,
577 	TTYC_SGR0,
578 	TTYC_SITM,
579 	TTYC_SMACS,
580 	TTYC_SMCUP,
581 	TTYC_SMKX,
582 	TTYC_SMOL,
583 	TTYC_SMSO,
584 	TTYC_SMUL,
585 	TTYC_SMULX,
586 	TTYC_SMXX,
587 	TTYC_SXL,
588 	TTYC_SS,
589 	TTYC_SWD,
590 	TTYC_SYNC,
591 	TTYC_TC,
592 	TTYC_TSL,
593 	TTYC_U8,
594 	TTYC_VPA,
595 	TTYC_XT
596 };
597 
598 /* Character classes. */
599 #define WHITESPACE " "
600 
601 /* Mode keys. */
602 #define MODEKEY_EMACS 0
603 #define MODEKEY_VI 1
604 
605 /* Modes. */
606 #define MODE_CURSOR 0x1
607 #define MODE_INSERT 0x2
608 #define MODE_KCURSOR 0x4
609 #define MODE_KKEYPAD 0x8
610 #define MODE_WRAP 0x10
611 #define MODE_MOUSE_STANDARD 0x20
612 #define MODE_MOUSE_BUTTON 0x40
613 #define MODE_CURSOR_BLINKING 0x80
614 #define MODE_MOUSE_UTF8 0x100
615 #define MODE_MOUSE_SGR 0x200
616 #define MODE_BRACKETPASTE 0x400
617 #define MODE_FOCUSON 0x800
618 #define MODE_MOUSE_ALL 0x1000
619 #define MODE_ORIGIN 0x2000
620 #define MODE_CRLF 0x4000
621 #define MODE_KEYS_EXTENDED 0x8000
622 #define MODE_CURSOR_VERY_VISIBLE 0x10000
623 #define MODE_CURSOR_BLINKING_SET 0x20000
624 #define MODE_KEYS_EXTENDED_2 0x40000
625 
626 #define ALL_MODES 0xffffff
627 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
628 #define MOTION_MOUSE_MODES (MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)
629 #define CURSOR_MODES (MODE_CURSOR|MODE_CURSOR_BLINKING|MODE_CURSOR_VERY_VISIBLE)
630 #define EXTENDED_KEY_MODES (MODE_KEYS_EXTENDED|MODE_KEYS_EXTENDED_2)
631 
632 /* Mouse protocol constants. */
633 #define MOUSE_PARAM_MAX 0xff
634 #define MOUSE_PARAM_UTF8_MAX 0x7ff
635 #define MOUSE_PARAM_BTN_OFF 0x20
636 #define MOUSE_PARAM_POS_OFF 0x21
637 
638 /* A single UTF-8 character. */
639 typedef u_int utf8_char;
640 
641 /*
642  * An expanded UTF-8 character. UTF8_SIZE must be big enough to hold combining
643  * characters as well. It can't be more than 32 bytes without changes to how
644  * characters are stored.
645  */
646 #define UTF8_SIZE 21
647 struct utf8_data {
648 	u_char	data[UTF8_SIZE];
649 
650 	u_char	have;
651 	u_char	size;
652 
653 	u_char	width;	/* 0xff if invalid */
654 };
655 enum utf8_state {
656 	UTF8_MORE,
657 	UTF8_DONE,
658 	UTF8_ERROR
659 };
660 
661 /* Colour flags. */
662 #define COLOUR_FLAG_256 0x01000000
663 #define COLOUR_FLAG_RGB 0x02000000
664 
665 /* Special colours. */
666 #define COLOUR_DEFAULT(c) ((c) == 8 || (c) == 9)
667 
668 /* Replacement palette. */
669 struct colour_palette {
670 	int	 fg;
671 	int	 bg;
672 
673 	int	*palette;
674 	int	*default_palette;
675 };
676 
677 /* Grid attributes. Anything above 0xff is stored in an extended cell. */
678 #define GRID_ATTR_BRIGHT 0x1
679 #define GRID_ATTR_DIM 0x2
680 #define GRID_ATTR_UNDERSCORE 0x4
681 #define GRID_ATTR_BLINK 0x8
682 #define GRID_ATTR_REVERSE 0x10
683 #define GRID_ATTR_HIDDEN 0x20
684 #define GRID_ATTR_ITALICS 0x40
685 #define GRID_ATTR_CHARSET 0x80	/* alternative character set */
686 #define GRID_ATTR_STRIKETHROUGH 0x100
687 #define GRID_ATTR_UNDERSCORE_2 0x200
688 #define GRID_ATTR_UNDERSCORE_3 0x400
689 #define GRID_ATTR_UNDERSCORE_4 0x800
690 #define GRID_ATTR_UNDERSCORE_5 0x1000
691 #define GRID_ATTR_OVERLINE 0x2000
692 
693 /* All underscore attributes. */
694 #define GRID_ATTR_ALL_UNDERSCORE \
695 	(GRID_ATTR_UNDERSCORE|	 \
696 	 GRID_ATTR_UNDERSCORE_2| \
697 	 GRID_ATTR_UNDERSCORE_3| \
698 	 GRID_ATTR_UNDERSCORE_4| \
699 	 GRID_ATTR_UNDERSCORE_5)
700 
701 /* Grid flags. */
702 #define GRID_FLAG_FG256 0x1
703 #define GRID_FLAG_BG256 0x2
704 #define GRID_FLAG_PADDING 0x4
705 #define GRID_FLAG_EXTENDED 0x8
706 #define GRID_FLAG_SELECTED 0x10
707 #define GRID_FLAG_NOPALETTE 0x20
708 #define GRID_FLAG_CLEARED 0x40
709 
710 /* Grid line flags. */
711 #define GRID_LINE_WRAPPED 0x1
712 #define GRID_LINE_EXTENDED 0x2
713 #define GRID_LINE_DEAD 0x4
714 #define GRID_LINE_START_PROMPT 0x8
715 #define GRID_LINE_START_OUTPUT 0x10
716 
717 /* Grid string flags. */
718 #define GRID_STRING_WITH_SEQUENCES 0x1
719 #define GRID_STRING_ESCAPE_SEQUENCES 0x2
720 #define GRID_STRING_TRIM_SPACES 0x4
721 #define GRID_STRING_USED_ONLY 0x8
722 #define GRID_STRING_EMPTY_CELLS 0x10
723 
724 /* Cell positions. */
725 #define CELL_INSIDE 0
726 #define CELL_TOPBOTTOM 1
727 #define CELL_LEFTRIGHT 2
728 #define CELL_TOPLEFT 3
729 #define CELL_TOPRIGHT 4
730 #define CELL_BOTTOMLEFT 5
731 #define CELL_BOTTOMRIGHT 6
732 #define CELL_TOPJOIN 7
733 #define CELL_BOTTOMJOIN 8
734 #define CELL_LEFTJOIN 9
735 #define CELL_RIGHTJOIN 10
736 #define CELL_JOIN 11
737 #define CELL_OUTSIDE 12
738 
739 /* Cell borders. */
740 #define CELL_BORDERS " xqlkmjwvtun~"
741 #define SIMPLE_BORDERS " |-+++++++++."
742 #define PADDED_BORDERS "             "
743 
744 /* Grid cell data. */
745 struct grid_cell {
746 	struct utf8_data	data;
747 	u_short			attr;
748 	u_char			flags;
749 	int			fg;
750 	int			bg;
751 	int			us;
752 	u_int			link;
753 };
754 
755 /* Grid extended cell entry. */
756 struct grid_extd_entry {
757 	utf8_char		data;
758 	u_short			attr;
759 	u_char			flags;
760 	int			fg;
761 	int			bg;
762 	int			us;
763 	u_int			link;
764 } __packed;
765 
766 /* Grid cell entry. */
767 struct grid_cell_entry {
768 	union {
769 		u_int		offset;
770 		struct {
771 			u_char	attr;
772 			u_char	fg;
773 			u_char	bg;
774 			u_char	data;
775 		} data;
776 	};
777 	u_char			flags;
778 } __packed;
779 
780 /* Grid line. */
781 struct grid_line {
782 	struct grid_cell_entry	*celldata;
783 	u_int			 cellused;
784 	u_int			 cellsize;
785 
786 	struct grid_extd_entry	*extddata;
787 	u_int			 extdsize;
788 
789 	int			 flags;
790 	time_t			 time;
791 };
792 
793 /* Entire grid of cells. */
794 struct grid {
795 	int			 flags;
796 #define GRID_HISTORY 0x1 /* scroll lines into history */
797 
798 	u_int			 sx;
799 	u_int			 sy;
800 
801 	u_int			 hscrolled;
802 	u_int			 hsize;
803 	u_int			 hlimit;
804 
805 	struct grid_line	*linedata;
806 };
807 
808 /* Virtual cursor in a grid. */
809 struct grid_reader {
810 	struct grid	*gd;
811 	u_int		 cx;
812 	u_int		 cy;
813 };
814 
815 /* Style alignment. */
816 enum style_align {
817 	STYLE_ALIGN_DEFAULT,
818 	STYLE_ALIGN_LEFT,
819 	STYLE_ALIGN_CENTRE,
820 	STYLE_ALIGN_RIGHT,
821 	STYLE_ALIGN_ABSOLUTE_CENTRE
822 };
823 
824 /* Style list. */
825 enum style_list {
826 	STYLE_LIST_OFF,
827 	STYLE_LIST_ON,
828 	STYLE_LIST_FOCUS,
829 	STYLE_LIST_LEFT_MARKER,
830 	STYLE_LIST_RIGHT_MARKER,
831 };
832 
833 /* Style range. */
834 enum style_range_type {
835 	STYLE_RANGE_NONE,
836 	STYLE_RANGE_LEFT,
837 	STYLE_RANGE_RIGHT,
838 	STYLE_RANGE_PANE,
839 	STYLE_RANGE_WINDOW,
840 	STYLE_RANGE_SESSION,
841 	STYLE_RANGE_USER
842 };
843 struct style_range {
844 	enum style_range_type	 type;
845 	u_int			 argument;
846 	char			 string[16];
847 
848 	u_int			 start;
849 	u_int			 end; /* not included */
850 
851 	TAILQ_ENTRY(style_range) entry;
852 };
853 TAILQ_HEAD(style_ranges, style_range);
854 
855 /* Style default. */
856 enum style_default_type {
857 	STYLE_DEFAULT_BASE,
858 	STYLE_DEFAULT_PUSH,
859 	STYLE_DEFAULT_POP
860 };
861 
862 /* Style option. */
863 struct style {
864 	struct grid_cell	gc;
865 	int			ignore;
866 
867 	int			fill;
868 	enum style_align	align;
869 	enum style_list		list;
870 
871 	enum style_range_type	range_type;
872 	u_int			range_argument;
873 	char			range_string[16];
874 
875 	enum style_default_type	default_type;
876 };
877 
878 /* Cursor style. */
879 enum screen_cursor_style {
880 	SCREEN_CURSOR_DEFAULT,
881 	SCREEN_CURSOR_BLOCK,
882 	SCREEN_CURSOR_UNDERLINE,
883 	SCREEN_CURSOR_BAR
884 };
885 
886 /* Virtual screen. */
887 struct screen_sel;
888 struct screen_titles;
889 struct screen {
890 	char				*title;
891 	char *path;
892 	struct screen_titles		*titles;
893 
894 	struct grid			*grid;	  /* grid data */
895 
896 	u_int				 cx;	  /* cursor x */
897 	u_int				 cy;	  /* cursor y */
898 
899 	enum screen_cursor_style	 cstyle;  /* cursor style */
900 	enum screen_cursor_style	 default_cstyle;
901 	int				 ccolour; /* cursor colour */
902 	int				 default_ccolour;
903 
904 	u_int				 rupper;  /* scroll region top */
905 	u_int				 rlower;  /* scroll region bottom */
906 
907 	int				 mode;
908 	int				 default_mode;
909 
910 	u_int				 saved_cx;
911 	u_int				 saved_cy;
912 	struct grid			*saved_grid;
913 	struct grid_cell		 saved_cell;
914 	int				 saved_flags;
915 
916 	bitstr_t			*tabs;
917 	struct screen_sel		*sel;
918 
919 	struct screen_write_cline	*write_list;
920 
921 	struct hyperlinks		*hyperlinks;
922 };
923 
924 /* Screen write context. */
925 typedef void (*screen_write_init_ctx_cb)(struct screen_write_ctx *,
926     struct tty_ctx *);
927 struct screen_write_ctx {
928 	struct window_pane		*wp;
929 	struct screen			*s;
930 
931 	int				 flags;
932 #define SCREEN_WRITE_SYNC 0x1
933 
934 	screen_write_init_ctx_cb	 init_ctx_cb;
935 	void				*arg;
936 
937 	struct screen_write_citem	*item;
938 	u_int				 scrolled;
939 	u_int				 bg;
940 };
941 
942 /* Box border lines option. */
943 enum box_lines {
944 	BOX_LINES_DEFAULT = -1,
945 	BOX_LINES_SINGLE,
946 	BOX_LINES_DOUBLE,
947 	BOX_LINES_HEAVY,
948 	BOX_LINES_SIMPLE,
949 	BOX_LINES_ROUNDED,
950 	BOX_LINES_PADDED,
951 	BOX_LINES_NONE
952 };
953 
954 /* Pane border lines option. */
955 enum pane_lines {
956 	PANE_LINES_SINGLE,
957 	PANE_LINES_DOUBLE,
958 	PANE_LINES_HEAVY,
959 	PANE_LINES_SIMPLE,
960 	PANE_LINES_NUMBER
961 };
962 
963 /* Pane border indicator option. */
964 #define PANE_BORDER_OFF 0
965 #define PANE_BORDER_COLOUR 1
966 #define PANE_BORDER_ARROWS 2
967 #define PANE_BORDER_BOTH 3
968 
969 /* Mode returned by window_pane_mode function. */
970 #define WINDOW_PANE_NO_MODE 0
971 #define WINDOW_PANE_COPY_MODE 1
972 #define WINDOW_PANE_VIEW_MODE 2
973 
974 /* Screen redraw context. */
975 struct screen_redraw_ctx {
976 	struct client	*c;
977 
978 	u_int		 statuslines;
979 	int		 statustop;
980 
981 	int		 pane_status;
982 	enum pane_lines	 pane_lines;
983 
984 	struct grid_cell no_pane_gc;
985 	int		 no_pane_gc_set;
986 
987 	u_int		 sx;
988 	u_int		 sy;
989 	u_int		 ox;
990 	u_int		 oy;
991 };
992 
993 /* Screen size. */
994 #define screen_size_x(s) ((s)->grid->sx)
995 #define screen_size_y(s) ((s)->grid->sy)
996 #define screen_hsize(s) ((s)->grid->hsize)
997 #define screen_hlimit(s) ((s)->grid->hlimit)
998 
999 /* Menu. */
1000 struct menu_item {
1001 	const char	*name;
1002 	key_code	 key;
1003 	const char	*command;
1004 };
1005 struct menu {
1006 	const char		*title;
1007 	struct menu_item	*items;
1008 	u_int			 count;
1009 	u_int			 width;
1010 };
1011 typedef void (*menu_choice_cb)(struct menu *, u_int, key_code, void *);
1012 
1013 /*
1014  * Window mode. Windows can be in several modes and this is used to call the
1015  * right function to handle input and output.
1016  */
1017 struct window_mode_entry;
1018 struct window_mode {
1019 	const char	*name;
1020 	const char	*default_format;
1021 
1022 	struct screen	*(*init)(struct window_mode_entry *,
1023 			     struct cmd_find_state *, struct args *);
1024 	void		 (*free)(struct window_mode_entry *);
1025 	void		 (*resize)(struct window_mode_entry *, u_int, u_int);
1026 	void		 (*update)(struct window_mode_entry *);
1027 	void		 (*key)(struct window_mode_entry *, struct client *,
1028 			     struct session *, struct winlink *, key_code,
1029 			     struct mouse_event *);
1030 
1031 	const char	*(*key_table)(struct window_mode_entry *);
1032 	void		 (*command)(struct window_mode_entry *, struct client *,
1033 			     struct session *, struct winlink *, struct args *,
1034 			     struct mouse_event *);
1035 	void		 (*formats)(struct window_mode_entry *,
1036 			     struct format_tree *);
1037 };
1038 
1039 /* Active window mode. */
1040 struct window_mode_entry {
1041 	struct window_pane		*wp;
1042 	struct window_pane		*swp;
1043 
1044 	const struct window_mode	*mode;
1045 	void				*data;
1046 
1047 	struct screen			*screen;
1048 	u_int				 prefix;
1049 
1050 	TAILQ_ENTRY(window_mode_entry)	 entry;
1051 };
1052 
1053 /* Offsets into pane buffer. */
1054 struct window_pane_offset {
1055 	size_t	used;
1056 };
1057 
1058 /* Queued pane resize. */
1059 struct window_pane_resize {
1060 	u_int				sx;
1061 	u_int				sy;
1062 
1063 	u_int				osx;
1064 	u_int				osy;
1065 
1066 	TAILQ_ENTRY(window_pane_resize)	entry;
1067 };
1068 TAILQ_HEAD(window_pane_resizes, window_pane_resize);
1069 
1070 /* Child window structure. */
1071 struct window_pane {
1072 	u_int		 id;
1073 	u_int		 active_point;
1074 
1075 	struct window	*window;
1076 	struct options	*options;
1077 
1078 	struct layout_cell *layout_cell;
1079 	struct layout_cell *saved_layout_cell;
1080 
1081 	u_int		 sx;
1082 	u_int		 sy;
1083 
1084 	u_int		 xoff;
1085 	u_int		 yoff;
1086 
1087 	int		 flags;
1088 #define PANE_REDRAW 0x1
1089 #define PANE_DROP 0x2
1090 #define PANE_FOCUSED 0x4
1091 #define PANE_VISITED 0x8
1092 /* 0x10 unused */
1093 /* 0x20 unused */
1094 #define PANE_INPUTOFF 0x40
1095 #define PANE_CHANGED 0x80
1096 #define PANE_EXITED 0x100
1097 #define PANE_STATUSREADY 0x200
1098 #define PANE_STATUSDRAWN 0x400
1099 #define PANE_EMPTY 0x800
1100 #define PANE_STYLECHANGED 0x1000
1101 #define PANE_UNSEENCHANGES 0x2000
1102 
1103 	int		 argc;
1104 	char	       **argv;
1105 	char		*shell;
1106 	char		*cwd;
1107 
1108 	pid_t		 pid;
1109 	char		 tty[TTY_NAME_MAX];
1110 	int		 status;
1111 	struct timeval	 dead_time;
1112 
1113 	int		 fd;
1114 	struct bufferevent *event;
1115 
1116 	struct window_pane_offset offset;
1117 	size_t		 base_offset;
1118 
1119 	struct window_pane_resizes resize_queue;
1120 	struct event	 resize_timer;
1121 
1122 	struct input_ctx *ictx;
1123 
1124 	struct grid_cell cached_gc;
1125 	struct grid_cell cached_active_gc;
1126 	struct colour_palette palette;
1127 
1128 	int		 pipe_fd;
1129 	struct bufferevent *pipe_event;
1130 	struct window_pane_offset pipe_offset;
1131 
1132 	struct screen	*screen;
1133 	struct screen	 base;
1134 
1135 	struct screen	 status_screen;
1136 	size_t		 status_size;
1137 
1138 	TAILQ_HEAD(, window_mode_entry) modes;
1139 
1140 	char		*searchstr;
1141 	int		 searchregex;
1142 
1143 	int		 border_gc_set;
1144 	struct grid_cell border_gc;
1145 
1146 	int		 control_bg;
1147 	int		 control_fg;
1148 
1149 	TAILQ_ENTRY(window_pane) entry;  /* link in list of all panes */
1150 	TAILQ_ENTRY(window_pane) sentry; /* link in list of last visited */
1151 	RB_ENTRY(window_pane) tree_entry;
1152 };
1153 TAILQ_HEAD(window_panes, window_pane);
1154 RB_HEAD(window_pane_tree, window_pane);
1155 
1156 /* Window structure. */
1157 struct window {
1158 	u_int			 id;
1159 	void			*latest;
1160 
1161 	char			*name;
1162 	struct event		 name_event;
1163 	struct timeval		 name_time;
1164 
1165 	struct event		 alerts_timer;
1166 	struct event		 offset_timer;
1167 
1168 	struct timeval		 activity_time;
1169 
1170 	struct window_pane	*active;
1171 	struct window_panes 	 last_panes;
1172 	struct window_panes	 panes;
1173 
1174 	int			 lastlayout;
1175 	struct layout_cell	*layout_root;
1176 	struct layout_cell	*saved_layout_root;
1177 	char			*old_layout;
1178 
1179 	u_int			 sx;
1180 	u_int			 sy;
1181 	u_int			 manual_sx;
1182 	u_int			 manual_sy;
1183 	u_int			 xpixel;
1184 	u_int			 ypixel;
1185 
1186 	u_int			 new_sx;
1187 	u_int			 new_sy;
1188 	u_int			 new_xpixel;
1189 	u_int			 new_ypixel;
1190 
1191 	struct utf8_data	*fill_character;
1192 	int			 flags;
1193 #define WINDOW_BELL 0x1
1194 #define WINDOW_ACTIVITY 0x2
1195 #define WINDOW_SILENCE 0x4
1196 #define WINDOW_ZOOMED 0x8
1197 #define WINDOW_WASZOOMED 0x10
1198 #define WINDOW_RESIZE 0x20
1199 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
1200 
1201 	int			 alerts_queued;
1202 	TAILQ_ENTRY(window)	 alerts_entry;
1203 
1204 	struct options		*options;
1205 
1206 	u_int			 references;
1207 	TAILQ_HEAD(, winlink)	 winlinks;
1208 
1209 	RB_ENTRY(window)	 entry;
1210 };
1211 RB_HEAD(windows, window);
1212 
1213 /* Entry on local window list. */
1214 struct winlink {
1215 	int		 idx;
1216 	struct session	*session;
1217 	struct window	*window;
1218 
1219 	int		 flags;
1220 #define WINLINK_BELL 0x1
1221 #define WINLINK_ACTIVITY 0x2
1222 #define WINLINK_SILENCE 0x4
1223 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE)
1224 #define WINLINK_VISITED 0x8
1225 
1226 	RB_ENTRY(winlink) entry;
1227 	TAILQ_ENTRY(winlink) wentry;
1228 	TAILQ_ENTRY(winlink) sentry;
1229 };
1230 RB_HEAD(winlinks, winlink);
1231 TAILQ_HEAD(winlink_stack, winlink);
1232 
1233 /* Window size option. */
1234 #define WINDOW_SIZE_LARGEST 0
1235 #define WINDOW_SIZE_SMALLEST 1
1236 #define WINDOW_SIZE_MANUAL 2
1237 #define WINDOW_SIZE_LATEST 3
1238 
1239 /* Pane border status option. */
1240 #define PANE_STATUS_OFF 0
1241 #define PANE_STATUS_TOP 1
1242 #define PANE_STATUS_BOTTOM 2
1243 
1244 /* Layout direction. */
1245 enum layout_type {
1246 	LAYOUT_LEFTRIGHT,
1247 	LAYOUT_TOPBOTTOM,
1248 	LAYOUT_WINDOWPANE
1249 };
1250 
1251 /* Layout cells queue. */
1252 TAILQ_HEAD(layout_cells, layout_cell);
1253 
1254 /* Layout cell. */
1255 struct layout_cell {
1256 	enum layout_type type;
1257 
1258 	struct layout_cell *parent;
1259 
1260 	u_int		 sx;
1261 	u_int		 sy;
1262 
1263 	u_int		 xoff;
1264 	u_int		 yoff;
1265 
1266 	struct window_pane *wp;
1267 	struct layout_cells cells;
1268 
1269 	TAILQ_ENTRY(layout_cell) entry;
1270 };
1271 
1272 /* Environment variable. */
1273 struct environ_entry {
1274 	char		*name;
1275 	char		*value;
1276 
1277 	int		 flags;
1278 #define ENVIRON_HIDDEN 0x1
1279 
1280 	RB_ENTRY(environ_entry) entry;
1281 };
1282 
1283 /* Client session. */
1284 struct session_group {
1285 	const char		*name;
1286 	TAILQ_HEAD(, session)	 sessions;
1287 
1288 	RB_ENTRY(session_group)	 entry;
1289 };
1290 RB_HEAD(session_groups, session_group);
1291 
1292 struct session {
1293 	u_int		 id;
1294 
1295 	char		*name;
1296 	const char	*cwd;
1297 
1298 	struct timeval	 creation_time;
1299 	struct timeval	 last_attached_time;
1300 	struct timeval	 activity_time;
1301 	struct timeval	 last_activity_time;
1302 
1303 	struct event	 lock_timer;
1304 
1305 	struct winlink	*curw;
1306 	struct winlink_stack lastw;
1307 	struct winlinks	 windows;
1308 
1309 	int		 statusat;
1310 	u_int		 statuslines;
1311 
1312 	struct options	*options;
1313 
1314 #define SESSION_PASTING 0x1
1315 #define SESSION_ALERTED 0x2
1316 	int		 flags;
1317 
1318 	u_int		 attached;
1319 
1320 	struct termios	*tio;
1321 
1322 	struct environ	*environ;
1323 
1324 	int		 references;
1325 
1326 	TAILQ_ENTRY(session) gentry;
1327 	RB_ENTRY(session)    entry;
1328 };
1329 RB_HEAD(sessions, session);
1330 
1331 /* Mouse button masks. */
1332 #define MOUSE_MASK_BUTTONS 195
1333 #define MOUSE_MASK_SHIFT 4
1334 #define MOUSE_MASK_META 8
1335 #define MOUSE_MASK_CTRL 16
1336 #define MOUSE_MASK_DRAG 32
1337 #define MOUSE_MASK_MODIFIERS (MOUSE_MASK_SHIFT|MOUSE_MASK_META|MOUSE_MASK_CTRL)
1338 
1339 /* Mouse wheel type. */
1340 #define MOUSE_WHEEL_UP 64
1341 #define MOUSE_WHEEL_DOWN 65
1342 
1343 /* Mouse button type. */
1344 #define MOUSE_BUTTON_1 0
1345 #define MOUSE_BUTTON_2 1
1346 #define MOUSE_BUTTON_3 2
1347 #define MOUSE_BUTTON_6 66
1348 #define MOUSE_BUTTON_7 67
1349 #define MOUSE_BUTTON_8 128
1350 #define MOUSE_BUTTON_9 129
1351 #define MOUSE_BUTTON_10 130
1352 #define MOUSE_BUTTON_11 131
1353 
1354 /* Mouse helpers. */
1355 #define MOUSE_BUTTONS(b) ((b) & MOUSE_MASK_BUTTONS)
1356 #define MOUSE_WHEEL(b) \
1357 	(((b) & MOUSE_MASK_BUTTONS) == MOUSE_WHEEL_UP || \
1358 	 ((b) & MOUSE_MASK_BUTTONS) == MOUSE_WHEEL_DOWN)
1359 #define MOUSE_DRAG(b) ((b) & MOUSE_MASK_DRAG)
1360 #define MOUSE_RELEASE(b) (((b) & MOUSE_MASK_BUTTONS) == 3)
1361 
1362 /* Mouse input. */
1363 struct mouse_event {
1364 	int		valid;
1365 	int		ignore;
1366 
1367 	key_code	key;
1368 
1369 	int		statusat;
1370 	u_int		statuslines;
1371 
1372 	u_int		x;
1373 	u_int		y;
1374 	u_int		b;
1375 
1376 	u_int		lx;
1377 	u_int		ly;
1378 	u_int		lb;
1379 
1380 	u_int		ox;
1381 	u_int		oy;
1382 
1383 	int		s;
1384 	int		w;
1385 	int		wp;
1386 
1387 	u_int		sgr_type;
1388 	u_int		sgr_b;
1389 };
1390 
1391 /* Key event. */
1392 struct key_event {
1393 	key_code		key;
1394 	struct mouse_event	m;
1395 };
1396 
1397 /* Terminal definition. */
1398 struct tty_term {
1399 	char		*name;
1400 	struct tty	*tty;
1401 	int		 features;
1402 
1403 	char		 acs[UCHAR_MAX + 1][2];
1404 
1405 	struct tty_code	*codes;
1406 
1407 #define TERM_256COLOURS 0x1
1408 #define TERM_NOAM 0x2
1409 #define TERM_DECSLRM 0x4
1410 #define TERM_DECFRA 0x8
1411 #define TERM_RGBCOLOURS 0x10
1412 #define TERM_VT100LIKE 0x20
1413 #define TERM_SIXEL 0x40
1414 	int		 flags;
1415 
1416 	LIST_ENTRY(tty_term) entry;
1417 };
1418 LIST_HEAD(tty_terms, tty_term);
1419 
1420 /* Client terminal. */
1421 struct tty {
1422 	struct client	*client;
1423 	struct event	 start_timer;
1424 	struct event	 clipboard_timer;
1425 	time_t		 last_requests;
1426 
1427 	u_int		 sx;
1428 	u_int		 sy;
1429 	u_int		 xpixel;
1430 	u_int		 ypixel;
1431 
1432 	u_int		 cx;
1433 	u_int		 cy;
1434 	enum screen_cursor_style cstyle;
1435 	int		 ccolour;
1436 
1437 	int		 oflag;
1438 	u_int		 oox;
1439 	u_int		 ooy;
1440 	u_int		 osx;
1441 	u_int		 osy;
1442 
1443 	int		 mode;
1444 	int              fg;
1445 	int              bg;
1446 
1447 	u_int		 rlower;
1448 	u_int		 rupper;
1449 
1450 	u_int		 rleft;
1451 	u_int		 rright;
1452 
1453 	struct event	 event_in;
1454 	struct evbuffer	*in;
1455 	struct event	 event_out;
1456 	struct evbuffer	*out;
1457 	struct event	 timer;
1458 	size_t		 discarded;
1459 
1460 	struct termios	 tio;
1461 
1462 	struct grid_cell cell;
1463 	struct grid_cell last_cell;
1464 
1465 #define TTY_NOCURSOR 0x1
1466 #define TTY_FREEZE 0x2
1467 #define TTY_TIMER 0x4
1468 #define TTY_NOBLOCK 0x8
1469 #define TTY_STARTED 0x10
1470 #define TTY_OPENED 0x20
1471 #define TTY_OSC52QUERY 0x40
1472 #define TTY_BLOCK 0x80
1473 #define TTY_HAVEDA 0x100 /* Primary DA. */
1474 #define TTY_HAVEXDA 0x200
1475 #define TTY_SYNCING 0x400
1476 #define TTY_HAVEDA2 0x800 /* Secondary DA. */
1477 #define TTY_ALL_REQUEST_FLAGS \
1478 	(TTY_HAVEDA|TTY_HAVEDA2|TTY_HAVEXDA)
1479 	int		 flags;
1480 
1481 	struct tty_term	*term;
1482 
1483 	u_int		 mouse_last_x;
1484 	u_int		 mouse_last_y;
1485 	u_int		 mouse_last_b;
1486 	int		 mouse_drag_flag;
1487 	void		(*mouse_drag_update)(struct client *,
1488 			    struct mouse_event *);
1489 	void		(*mouse_drag_release)(struct client *,
1490 			    struct mouse_event *);
1491 
1492 	struct event	 key_timer;
1493 	struct tty_key	*key_tree;
1494 };
1495 
1496 /* Terminal command context. */
1497 typedef void (*tty_ctx_redraw_cb)(const struct tty_ctx *);
1498 typedef int (*tty_ctx_set_client_cb)(struct tty_ctx *, struct client *);
1499 struct tty_ctx {
1500 	struct screen		*s;
1501 
1502 	tty_ctx_redraw_cb	 redraw_cb;
1503 	tty_ctx_set_client_cb	 set_client_cb;
1504 	void			*arg;
1505 
1506 	const struct grid_cell	*cell;
1507 	int			 wrapped;
1508 
1509 	u_int			 num;
1510 	void			*ptr;
1511 	void			*ptr2;
1512 
1513 	/*
1514 	 * Whether this command should be sent even when the pane is not
1515 	 * visible (used for a passthrough sequence when allow-passthrough is
1516 	 * "all").
1517 	 */
1518 	int			 allow_invisible_panes;
1519 
1520 	/*
1521 	 * Cursor and region position before the screen was updated - this is
1522 	 * where the command should be applied; the values in the screen have
1523 	 * already been updated.
1524 	 */
1525 	u_int			 ocx;
1526 	u_int			 ocy;
1527 
1528 	u_int			 orupper;
1529 	u_int			 orlower;
1530 
1531 	/* Target region (usually pane) offset and size. */
1532 	u_int			 xoff;
1533 	u_int			 yoff;
1534 	u_int			 rxoff;
1535 	u_int			 ryoff;
1536 	u_int			 sx;
1537 	u_int			 sy;
1538 
1539 	/* The background colour used for clearing (erasing). */
1540 	u_int			 bg;
1541 
1542 	/* The default colours and palette. */
1543 	struct grid_cell	 defaults;
1544 	struct colour_palette	*palette;
1545 
1546 	/* Containing region (usually window) offset and size. */
1547 	int			 bigger;
1548 	u_int			 wox;
1549 	u_int			 woy;
1550 	u_int			 wsx;
1551 	u_int			 wsy;
1552 };
1553 
1554 /* Saved message entry. */
1555 struct message_entry {
1556 	char				*msg;
1557 	u_int				 msg_num;
1558 	struct timeval			 msg_time;
1559 
1560 	TAILQ_ENTRY(message_entry)	 entry;
1561 };
1562 TAILQ_HEAD(message_list, message_entry);
1563 
1564 /* Argument type. */
1565 enum args_type {
1566 	ARGS_NONE,
1567 	ARGS_STRING,
1568 	ARGS_COMMANDS
1569 };
1570 
1571 /* Argument value. */
1572 struct args_value {
1573 	enum args_type		 type;
1574 	union {
1575 		char		*string;
1576 		struct cmd_list	*cmdlist;
1577 	};
1578 	char			*cached;
1579 	TAILQ_ENTRY(args_value)	 entry;
1580 };
1581 
1582 /* Arguments set. */
1583 struct args_entry;
1584 RB_HEAD(args_tree, args_entry);
1585 
1586 /* Arguments parsing type. */
1587 enum args_parse_type {
1588 	ARGS_PARSE_INVALID,
1589 	ARGS_PARSE_STRING,
1590 	ARGS_PARSE_COMMANDS_OR_STRING,
1591 	ARGS_PARSE_COMMANDS
1592 };
1593 
1594 /* Arguments parsing state. */
1595 typedef enum args_parse_type (*args_parse_cb)(struct args *, u_int, char **);
1596 struct args_parse {
1597 	const char	*template;
1598 	int		 lower;
1599 	int		 upper;
1600 	args_parse_cb	 cb;
1601 };
1602 
1603 /* Command find structures. */
1604 enum cmd_find_type {
1605 	CMD_FIND_PANE,
1606 	CMD_FIND_WINDOW,
1607 	CMD_FIND_SESSION,
1608 };
1609 struct cmd_find_state {
1610 	int			 flags;
1611 	struct cmd_find_state	*current;
1612 
1613 	struct session		*s;
1614 	struct winlink		*wl;
1615 	struct window		*w;
1616 	struct window_pane	*wp;
1617 	int			 idx;
1618 };
1619 
1620 /* Command find flags. */
1621 #define CMD_FIND_PREFER_UNATTACHED 0x1
1622 #define CMD_FIND_QUIET 0x2
1623 #define CMD_FIND_WINDOW_INDEX 0x4
1624 #define CMD_FIND_DEFAULT_MARKED 0x8
1625 #define CMD_FIND_EXACT_SESSION 0x10
1626 #define CMD_FIND_EXACT_WINDOW 0x20
1627 #define CMD_FIND_CANFAIL 0x40
1628 
1629 /* List of commands. */
1630 struct cmd_list {
1631 	int		 references;
1632 	u_int		 group;
1633 	struct cmds	*list;
1634 };
1635 
1636 /* Command return values. */
1637 enum cmd_retval {
1638 	CMD_RETURN_ERROR = -1,
1639 	CMD_RETURN_NORMAL = 0,
1640 	CMD_RETURN_WAIT,
1641 	CMD_RETURN_STOP
1642 };
1643 
1644 /* Command parse result. */
1645 enum cmd_parse_status {
1646 	CMD_PARSE_ERROR,
1647 	CMD_PARSE_SUCCESS
1648 };
1649 struct cmd_parse_result {
1650 	enum cmd_parse_status	 status;
1651 	struct cmd_list		*cmdlist;
1652 	char			*error;
1653 };
1654 struct cmd_parse_input {
1655 	int			 flags;
1656 #define CMD_PARSE_QUIET 0x1
1657 #define CMD_PARSE_PARSEONLY 0x2
1658 #define CMD_PARSE_NOALIAS 0x4
1659 #define CMD_PARSE_VERBOSE 0x8
1660 #define CMD_PARSE_ONEGROUP 0x10
1661 
1662 	const char		*file;
1663 	u_int			 line;
1664 
1665 	struct cmdq_item	*item;
1666 	struct client		*c;
1667 	struct cmd_find_state	 fs;
1668 };
1669 
1670 /* Command queue flags. */
1671 #define CMDQ_STATE_REPEAT 0x1
1672 #define CMDQ_STATE_CONTROL 0x2
1673 #define CMDQ_STATE_NOHOOKS 0x4
1674 
1675 /* Command queue callback. */
1676 typedef enum cmd_retval (*cmdq_cb) (struct cmdq_item *, void *);
1677 
1678 /* Command definition flag. */
1679 struct cmd_entry_flag {
1680 	char			 flag;
1681 	enum cmd_find_type	 type;
1682 	int			 flags;
1683 };
1684 
1685 /* Command definition. */
1686 struct cmd_entry {
1687 	const char		*name;
1688 	const char		*alias;
1689 
1690 	struct args_parse	 args;
1691 	const char		*usage;
1692 
1693 	struct cmd_entry_flag	 source;
1694 	struct cmd_entry_flag	 target;
1695 
1696 #define CMD_STARTSERVER 0x1
1697 #define CMD_READONLY 0x2
1698 #define CMD_AFTERHOOK 0x4
1699 #define CMD_CLIENT_CFLAG 0x8
1700 #define CMD_CLIENT_TFLAG 0x10
1701 #define CMD_CLIENT_CANFAIL 0x20
1702 	int		 flags;
1703 
1704 	enum cmd_retval	 (*exec)(struct cmd *, struct cmdq_item *);
1705 };
1706 
1707 /* Status line. */
1708 #define STATUS_LINES_LIMIT 5
1709 struct status_line_entry {
1710 	char			*expanded;
1711 	struct style_ranges	 ranges;
1712 };
1713 struct status_line {
1714 	struct event		 timer;
1715 
1716 	struct screen		 screen;
1717 	struct screen		*active;
1718 	int			 references;
1719 
1720 	struct grid_cell	 style;
1721 	struct status_line_entry entries[STATUS_LINES_LIMIT];
1722 };
1723 
1724 /* Prompt type. */
1725 #define PROMPT_NTYPES 4
1726 enum prompt_type {
1727 	PROMPT_TYPE_COMMAND,
1728 	PROMPT_TYPE_SEARCH,
1729 	PROMPT_TYPE_TARGET,
1730 	PROMPT_TYPE_WINDOW_TARGET,
1731 	PROMPT_TYPE_INVALID = 0xff
1732 };
1733 
1734 /* File in client. */
1735 typedef void (*client_file_cb) (struct client *, const char *, int, int,
1736     struct evbuffer *, void *);
1737 struct client_file {
1738 	struct client			*c;
1739 	struct tmuxpeer			*peer;
1740 	struct client_files		*tree;
1741 	int				 references;
1742 	int				 stream;
1743 
1744 	char				*path;
1745 	struct evbuffer			*buffer;
1746 	struct bufferevent		*event;
1747 
1748 	int				 fd;
1749 	int				 error;
1750 	int				 closed;
1751 
1752 	client_file_cb			 cb;
1753 	void				*data;
1754 
1755 	RB_ENTRY(client_file)		 entry;
1756 };
1757 RB_HEAD(client_files, client_file);
1758 
1759 /* Client window. */
1760 struct client_window {
1761 	u_int			 window;
1762 	struct window_pane	*pane;
1763 
1764 	u_int			 sx;
1765 	u_int			 sy;
1766 
1767 	RB_ENTRY(client_window)	 entry;
1768 };
1769 RB_HEAD(client_windows, client_window);
1770 
1771 /* Visible areas not obstructed by overlays. */
1772 #define OVERLAY_MAX_RANGES 3
1773 struct overlay_ranges {
1774 	u_int	px[OVERLAY_MAX_RANGES];
1775 	u_int	nx[OVERLAY_MAX_RANGES];
1776 };
1777 
1778 /* Client connection. */
1779 typedef int (*prompt_input_cb)(struct client *, void *, const char *, int);
1780 typedef void (*prompt_free_cb)(void *);
1781 typedef void (*overlay_check_cb)(struct client*, void *, u_int, u_int, u_int,
1782 	    struct overlay_ranges *);
1783 typedef struct screen *(*overlay_mode_cb)(struct client *, void *, u_int *,
1784 	    u_int *);
1785 typedef void (*overlay_draw_cb)(struct client *, void *,
1786 	    struct screen_redraw_ctx *);
1787 typedef int (*overlay_key_cb)(struct client *, void *, struct key_event *);
1788 typedef void (*overlay_free_cb)(struct client *, void *);
1789 typedef void (*overlay_resize_cb)(struct client *, void *);
1790 struct client {
1791 	const char		*name;
1792 	struct tmuxpeer		*peer;
1793 	struct cmdq_list	*queue;
1794 
1795 	struct client_windows	 windows;
1796 
1797 	struct control_state	*control_state;
1798 	u_int			 pause_age;
1799 
1800 	pid_t			 pid;
1801 	int			 fd;
1802 	int			 out_fd;
1803 	struct event		 event;
1804 	int			 retval;
1805 
1806 	struct timeval		 creation_time;
1807 	struct timeval		 activity_time;
1808 
1809 	struct environ		*environ;
1810 	struct format_job_tree	*jobs;
1811 
1812 	char			*title;
1813 	char			*path;
1814 	const char		*cwd;
1815 
1816 	char			*term_name;
1817 	int			 term_features;
1818 	char			*term_type;
1819 	char		       **term_caps;
1820 	u_int			 term_ncaps;
1821 
1822 	char			*ttyname;
1823 	struct tty		 tty;
1824 
1825 	size_t			 written;
1826 	size_t			 discarded;
1827 	size_t			 redraw;
1828 
1829 	struct event		 repeat_timer;
1830 
1831 	struct event		 click_timer;
1832 	u_int			 click_button;
1833 	struct mouse_event	 click_event;
1834 
1835 	struct status_line	 status;
1836 
1837 #define CLIENT_TERMINAL 0x1
1838 #define CLIENT_LOGIN 0x2
1839 #define CLIENT_EXIT 0x4
1840 #define CLIENT_REDRAWWINDOW 0x8
1841 #define CLIENT_REDRAWSTATUS 0x10
1842 #define CLIENT_REPEAT 0x20
1843 #define CLIENT_SUSPENDED 0x40
1844 #define CLIENT_ATTACHED 0x80
1845 #define CLIENT_EXITED 0x100
1846 #define CLIENT_DEAD 0x200
1847 #define CLIENT_REDRAWBORDERS 0x400
1848 #define CLIENT_READONLY 0x800
1849 #define CLIENT_NOSTARTSERVER 0x1000
1850 #define CLIENT_CONTROL 0x2000
1851 #define CLIENT_CONTROLCONTROL 0x4000
1852 #define CLIENT_FOCUSED 0x8000
1853 #define CLIENT_UTF8 0x10000
1854 #define CLIENT_IGNORESIZE 0x20000
1855 #define CLIENT_IDENTIFIED 0x40000
1856 #define CLIENT_STATUSFORCE 0x80000
1857 #define CLIENT_DOUBLECLICK 0x100000
1858 #define CLIENT_TRIPLECLICK 0x200000
1859 #define CLIENT_SIZECHANGED 0x400000
1860 #define CLIENT_STATUSOFF 0x800000
1861 #define CLIENT_REDRAWSTATUSALWAYS 0x1000000
1862 #define CLIENT_REDRAWOVERLAY 0x2000000
1863 #define CLIENT_CONTROL_NOOUTPUT 0x4000000
1864 #define CLIENT_DEFAULTSOCKET 0x8000000
1865 #define CLIENT_STARTSERVER 0x10000000
1866 #define CLIENT_REDRAWPANES 0x20000000
1867 #define CLIENT_NOFORK 0x40000000
1868 #define CLIENT_ACTIVEPANE 0x80000000ULL
1869 #define CLIENT_CONTROL_PAUSEAFTER 0x100000000ULL
1870 #define CLIENT_CONTROL_WAITEXIT 0x200000000ULL
1871 #define CLIENT_WINDOWSIZECHANGED 0x400000000ULL
1872 #define CLIENT_CLIPBOARDBUFFER 0x800000000ULL
1873 #define CLIENT_BRACKETPASTING 0x1000000000ULL
1874 #define CLIENT_ALLREDRAWFLAGS		\
1875 	(CLIENT_REDRAWWINDOW|		\
1876 	 CLIENT_REDRAWSTATUS|		\
1877 	 CLIENT_REDRAWSTATUSALWAYS|	\
1878 	 CLIENT_REDRAWBORDERS|		\
1879 	 CLIENT_REDRAWOVERLAY|		\
1880 	 CLIENT_REDRAWPANES)
1881 #define CLIENT_UNATTACHEDFLAGS	\
1882 	(CLIENT_DEAD|		\
1883 	 CLIENT_SUSPENDED|	\
1884 	 CLIENT_EXIT)
1885 #define CLIENT_NODETACHFLAGS	\
1886 	(CLIENT_DEAD|		\
1887 	 CLIENT_EXIT)
1888 #define CLIENT_NOSIZEFLAGS	\
1889 	(CLIENT_DEAD|		\
1890 	 CLIENT_SUSPENDED|	\
1891 	 CLIENT_EXIT)
1892 	uint64_t		 flags;
1893 
1894 	enum {
1895 		CLIENT_EXIT_RETURN,
1896 		CLIENT_EXIT_SHUTDOWN,
1897 		CLIENT_EXIT_DETACH
1898 	}			 exit_type;
1899 	enum msgtype		 exit_msgtype;
1900 	char			*exit_session;
1901 	char			*exit_message;
1902 
1903 	struct key_table	*keytable;
1904 
1905 	uint64_t		 redraw_panes;
1906 
1907 	int			 message_ignore_keys;
1908 	int			 message_ignore_styles;
1909 	char			*message_string;
1910 	struct event		 message_timer;
1911 
1912 	char			*prompt_string;
1913 	struct utf8_data	*prompt_buffer;
1914 	char			*prompt_last;
1915 	size_t			 prompt_index;
1916 	prompt_input_cb		 prompt_inputcb;
1917 	prompt_free_cb		 prompt_freecb;
1918 	void			*prompt_data;
1919 	u_int			 prompt_hindex[PROMPT_NTYPES];
1920 	enum {
1921 		PROMPT_ENTRY,
1922 		PROMPT_COMMAND
1923 	}			 prompt_mode;
1924 	struct utf8_data	*prompt_saved;
1925 #define PROMPT_SINGLE 0x1
1926 #define PROMPT_NUMERIC 0x2
1927 #define PROMPT_INCREMENTAL 0x4
1928 #define PROMPT_NOFORMAT 0x8
1929 #define PROMPT_KEY 0x10
1930 	int			 prompt_flags;
1931 	enum prompt_type	 prompt_type;
1932 	int			 prompt_cursor;
1933 
1934 	struct session		*session;
1935 	struct session		*last_session;
1936 
1937 	int			 references;
1938 
1939 	void			*pan_window;
1940 	u_int			 pan_ox;
1941 	u_int			 pan_oy;
1942 
1943 	overlay_check_cb	 overlay_check;
1944 	overlay_mode_cb		 overlay_mode;
1945 	overlay_draw_cb		 overlay_draw;
1946 	overlay_key_cb		 overlay_key;
1947 	overlay_free_cb		 overlay_free;
1948 	overlay_resize_cb	 overlay_resize;
1949 	void			*overlay_data;
1950 	struct event		 overlay_timer;
1951 
1952 	struct client_files	 files;
1953 
1954 	u_int			*clipboard_panes;
1955 	u_int			 clipboard_npanes;
1956 
1957 	TAILQ_ENTRY(client)	 entry;
1958 };
1959 TAILQ_HEAD(clients, client);
1960 
1961 /* Control mode subscription type. */
1962 enum control_sub_type {
1963 	CONTROL_SUB_SESSION,
1964 	CONTROL_SUB_PANE,
1965 	CONTROL_SUB_ALL_PANES,
1966 	CONTROL_SUB_WINDOW,
1967 	CONTROL_SUB_ALL_WINDOWS
1968 };
1969 
1970 /* Key binding and key table. */
1971 struct key_binding {
1972 	key_code		 key;
1973 	struct cmd_list		*cmdlist;
1974 	const char		*note;
1975 
1976 	int			 flags;
1977 #define KEY_BINDING_REPEAT 0x1
1978 
1979 	RB_ENTRY(key_binding)	 entry;
1980 };
1981 RB_HEAD(key_bindings, key_binding);
1982 
1983 struct key_table {
1984 	const char		*name;
1985 	struct key_bindings	 key_bindings;
1986 	struct key_bindings	 default_key_bindings;
1987 
1988 	u_int			 references;
1989 
1990 	RB_ENTRY(key_table)	 entry;
1991 };
1992 RB_HEAD(key_tables, key_table);
1993 
1994 /* Option data. */
1995 RB_HEAD(options_array, options_array_item);
1996 union options_value {
1997 	char			*string;
1998 	long long		 number;
1999 	struct style		 style;
2000 	struct options_array	 array;
2001 	struct cmd_list		*cmdlist;
2002 };
2003 
2004 /* Option table entries. */
2005 enum options_table_type {
2006 	OPTIONS_TABLE_STRING,
2007 	OPTIONS_TABLE_NUMBER,
2008 	OPTIONS_TABLE_KEY,
2009 	OPTIONS_TABLE_COLOUR,
2010 	OPTIONS_TABLE_FLAG,
2011 	OPTIONS_TABLE_CHOICE,
2012 	OPTIONS_TABLE_COMMAND
2013 };
2014 
2015 #define OPTIONS_TABLE_NONE 0
2016 #define OPTIONS_TABLE_SERVER 0x1
2017 #define OPTIONS_TABLE_SESSION 0x2
2018 #define OPTIONS_TABLE_WINDOW 0x4
2019 #define OPTIONS_TABLE_PANE 0x8
2020 
2021 #define OPTIONS_TABLE_IS_ARRAY 0x1
2022 #define OPTIONS_TABLE_IS_HOOK 0x2
2023 #define OPTIONS_TABLE_IS_STYLE 0x4
2024 
2025 struct options_table_entry {
2026 	const char		 *name;
2027 	const char		 *alternative_name;
2028 	enum options_table_type	  type;
2029 	int			  scope;
2030 	int			  flags;
2031 
2032 	u_int			  minimum;
2033 	u_int			  maximum;
2034 	const char		**choices;
2035 
2036 	const char		 *default_str;
2037 	long long		  default_num;
2038 	const char		**default_arr;
2039 
2040 	const char		 *separator;
2041 	const char		 *pattern;
2042 
2043 	const char		 *text;
2044 	const char		 *unit;
2045 };
2046 
2047 struct options_name_map {
2048 	const char		*from;
2049 	const char		*to;
2050 };
2051 
2052 /* Common command usages. */
2053 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
2054 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
2055 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
2056 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
2057 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
2058 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
2059 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
2060 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
2061 #define CMD_BUFFER_USAGE "[-b buffer-name]"
2062 
2063 /* Spawn common context. */
2064 struct spawn_context {
2065 	struct cmdq_item	 *item;
2066 
2067 	struct session		 *s;
2068 	struct winlink		 *wl;
2069 	struct client		 *tc;
2070 
2071 	struct window_pane	 *wp0;
2072 	struct layout_cell	 *lc;
2073 
2074 	const char		 *name;
2075 	char			**argv;
2076 	int			  argc;
2077 	struct environ		 *environ;
2078 
2079 	int			  idx;
2080 	const char		 *cwd;
2081 
2082 	int			  flags;
2083 #define SPAWN_KILL 0x1
2084 #define SPAWN_DETACHED 0x2
2085 #define SPAWN_RESPAWN 0x4
2086 #define SPAWN_BEFORE 0x8
2087 #define SPAWN_NONOTIFY 0x10
2088 #define SPAWN_FULLSIZE 0x20
2089 #define SPAWN_EMPTY 0x40
2090 #define SPAWN_ZOOM 0x80
2091 };
2092 
2093 /* Mode tree sort order. */
2094 struct mode_tree_sort_criteria {
2095 	u_int	field;
2096 	int	reversed;
2097 };
2098 
2099 /* tmux.c */
2100 extern struct options	*global_options;
2101 extern struct options	*global_s_options;
2102 extern struct options	*global_w_options;
2103 extern struct environ	*global_environ;
2104 extern struct timeval	 start_time;
2105 extern const char	*socket_path;
2106 extern const char	*shell_command;
2107 extern int		 ptm_fd;
2108 extern const char	*shell_command;
2109 int		 checkshell(const char *);
2110 void		 setblocking(int, int);
2111 char 		*shell_argv0(const char *, int);
2112 uint64_t	 get_timer(void);
2113 const char	*sig2name(int);
2114 const char	*find_cwd(void);
2115 const char	*find_home(void);
2116 const char	*getversion(void);
2117 
2118 /* proc.c */
2119 struct imsg;
2120 int	proc_send(struct tmuxpeer *, enum msgtype, int, const void *, size_t);
2121 struct tmuxproc *proc_start(const char *);
2122 void	proc_loop(struct tmuxproc *, int (*)(void));
2123 void	proc_exit(struct tmuxproc *);
2124 void	proc_set_signals(struct tmuxproc *, void(*)(int));
2125 void	proc_clear_signals(struct tmuxproc *, int);
2126 struct tmuxpeer *proc_add_peer(struct tmuxproc *, int,
2127 	    void (*)(struct imsg *, void *), void *);
2128 void	proc_remove_peer(struct tmuxpeer *);
2129 void	proc_kill_peer(struct tmuxpeer *);
2130 void	proc_flush_peer(struct tmuxpeer *);
2131 void	proc_toggle_log(struct tmuxproc *);
2132 pid_t	proc_fork_and_daemon(int *);
2133 uid_t	proc_get_peer_uid(struct tmuxpeer *);
2134 
2135 /* cfg.c */
2136 extern int cfg_finished;
2137 extern struct client *cfg_client;
2138 extern char **cfg_files;
2139 extern u_int cfg_nfiles;
2140 extern int cfg_quiet;
2141 void	start_cfg(void);
2142 int	load_cfg(const char *, struct client *, struct cmdq_item *,
2143             struct cmd_find_state *, int, struct cmdq_item **);
2144 int	load_cfg_from_buffer(const void *, size_t, const char *,
2145   	    struct client *, struct cmdq_item *, struct cmd_find_state *,
2146 	    int, struct cmdq_item **);
2147 void printflike(1, 2) cfg_add_cause(const char *, ...);
2148 void	cfg_print_causes(struct cmdq_item *);
2149 void	cfg_show_causes(struct session *);
2150 
2151 /* paste.c */
2152 struct paste_buffer;
2153 const char	*paste_buffer_name(struct paste_buffer *);
2154 u_int		 paste_buffer_order(struct paste_buffer *);
2155 time_t		 paste_buffer_created(struct paste_buffer *);
2156 const char	*paste_buffer_data(struct paste_buffer *, size_t *);
2157 struct paste_buffer *paste_walk(struct paste_buffer *);
2158 int		 paste_is_empty(void);
2159 struct paste_buffer *paste_get_top(const char **);
2160 struct paste_buffer *paste_get_name(const char *);
2161 void		 paste_free(struct paste_buffer *);
2162 void		 paste_add(const char *, char *, size_t);
2163 int		 paste_rename(const char *, const char *, char **);
2164 int		 paste_set(char *, size_t, const char *, char **);
2165 void		 paste_replace(struct paste_buffer *, char *, size_t);
2166 char		*paste_make_sample(struct paste_buffer *);
2167 
2168 /* format.c */
2169 #define FORMAT_STATUS 0x1
2170 #define FORMAT_FORCE 0x2
2171 #define FORMAT_NOJOBS 0x4
2172 #define FORMAT_VERBOSE 0x8
2173 #define FORMAT_NONE 0
2174 #define FORMAT_PANE 0x80000000U
2175 #define FORMAT_WINDOW 0x40000000U
2176 struct format_tree;
2177 struct format_modifier;
2178 typedef void *(*format_cb)(struct format_tree *);
2179 void		 format_tidy_jobs(void);
2180 const char	*format_skip(const char *, const char *);
2181 int		 format_true(const char *);
2182 struct format_tree *format_create(struct client *, struct cmdq_item *, int,
2183 		     int);
2184 void		 format_free(struct format_tree *);
2185 void		 format_merge(struct format_tree *, struct format_tree *);
2186 struct window_pane *format_get_pane(struct format_tree *);
2187 void printflike(3, 4) format_add(struct format_tree *, const char *,
2188 		     const char *, ...);
2189 void		 format_add_tv(struct format_tree *, const char *,
2190 		     struct timeval *);
2191 void		 format_add_cb(struct format_tree *, const char *, format_cb);
2192 void		 format_log_debug(struct format_tree *, const char *);
2193 void		 format_each(struct format_tree *, void (*)(const char *,
2194 		     const char *, void *), void *);
2195 char		*format_pretty_time(time_t, int);
2196 char		*format_expand_time(struct format_tree *, const char *);
2197 char		*format_expand(struct format_tree *, const char *);
2198 char		*format_single(struct cmdq_item *, const char *,
2199 		     struct client *, struct session *, struct winlink *,
2200 		     struct window_pane *);
2201 char		*format_single_from_state(struct cmdq_item *, const char *,
2202 		    struct client *, struct cmd_find_state *);
2203 char		*format_single_from_target(struct cmdq_item *, const char *);
2204 struct format_tree *format_create_defaults(struct cmdq_item *, struct client *,
2205 		     struct session *, struct winlink *, struct window_pane *);
2206 struct format_tree *format_create_from_state(struct cmdq_item *,
2207 		     struct client *, struct cmd_find_state *);
2208 struct format_tree *format_create_from_target(struct cmdq_item *);
2209 void		 format_defaults(struct format_tree *, struct client *,
2210 		     struct session *, struct winlink *, struct window_pane *);
2211 void		 format_defaults_window(struct format_tree *, struct window *);
2212 void		 format_defaults_pane(struct format_tree *,
2213 		     struct window_pane *);
2214 void		 format_defaults_paste_buffer(struct format_tree *,
2215 		     struct paste_buffer *);
2216 void		 format_lost_client(struct client *);
2217 char		*format_grid_word(struct grid *, u_int, u_int);
2218 char		*format_grid_hyperlink(struct grid *, u_int, u_int,
2219 		     struct screen *);
2220 char		*format_grid_line(struct grid *, u_int);
2221 
2222 /* format-draw.c */
2223 void		 format_draw(struct screen_write_ctx *,
2224 		     const struct grid_cell *, u_int, const char *,
2225 		     struct style_ranges *, int);
2226 u_int		 format_width(const char *);
2227 char		*format_trim_left(const char *, u_int);
2228 char		*format_trim_right(const char *, u_int);
2229 
2230 /* notify.c */
2231 void	notify_hook(struct cmdq_item *, const char *);
2232 void	notify_client(const char *, struct client *);
2233 void	notify_session(const char *, struct session *);
2234 void	notify_winlink(const char *, struct winlink *);
2235 void	notify_session_window(const char *, struct session *, struct window *);
2236 void	notify_window(const char *, struct window *);
2237 void	notify_pane(const char *, struct window_pane *);
2238 void	notify_paste_buffer(const char *, int);
2239 
2240 /* options.c */
2241 struct options	*options_create(struct options *);
2242 void		 options_free(struct options *);
2243 struct options	*options_get_parent(struct options *);
2244 void		 options_set_parent(struct options *, struct options *);
2245 struct options_entry *options_first(struct options *);
2246 struct options_entry *options_next(struct options_entry *);
2247 struct options_entry *options_empty(struct options *,
2248 		     const struct options_table_entry *);
2249 struct options_entry *options_default(struct options *,
2250 		     const struct options_table_entry *);
2251 char		*options_default_to_string(const struct options_table_entry *);
2252 const char	*options_name(struct options_entry *);
2253 struct options	*options_owner(struct options_entry *);
2254 const struct options_table_entry *options_table_entry(struct options_entry *);
2255 struct options_entry *options_get_only(struct options *, const char *);
2256 struct options_entry *options_get(struct options *, const char *);
2257 void		 options_array_clear(struct options_entry *);
2258 union options_value *options_array_get(struct options_entry *, u_int);
2259 int		 options_array_set(struct options_entry *, u_int, const char *,
2260 		     int, char **);
2261 int		 options_array_assign(struct options_entry *, const char *,
2262 		     char **);
2263 struct options_array_item *options_array_first(struct options_entry *);
2264 struct options_array_item *options_array_next(struct options_array_item *);
2265 u_int		 options_array_item_index(struct options_array_item *);
2266 union options_value *options_array_item_value(struct options_array_item *);
2267 int		 options_is_array(struct options_entry *);
2268 int		 options_is_string(struct options_entry *);
2269 char		*options_to_string(struct options_entry *, int, int);
2270 char		*options_parse(const char *, int *);
2271 struct options_entry *options_parse_get(struct options *, const char *, int *,
2272 		     int);
2273 char		*options_match(const char *, int *, int *);
2274 struct options_entry *options_match_get(struct options *, const char *, int *,
2275 		     int, int *);
2276 const char	*options_get_string(struct options *, const char *);
2277 long long	 options_get_number(struct options *, const char *);
2278 struct options_entry * printflike(4, 5) options_set_string(struct options *,
2279 		     const char *, int, const char *, ...);
2280 struct options_entry *options_set_number(struct options *, const char *,
2281 		     long long);
2282 int		 options_scope_from_name(struct args *, int,
2283 		     const char *, struct cmd_find_state *, struct options **,
2284 		     char **);
2285 int		 options_scope_from_flags(struct args *, int,
2286 		     struct cmd_find_state *, struct options **, char **);
2287 struct style	*options_string_to_style(struct options *, const char *,
2288 		     struct format_tree *);
2289 int		 options_from_string(struct options *,
2290 		     const struct options_table_entry *, const char *,
2291 		     const char *, int, char **);
2292 int	 	 options_find_choice(const struct options_table_entry *,
2293 		     const char *, char **);
2294 void		 options_push_changes(const char *);
2295 int		 options_remove_or_default(struct options_entry *, int,
2296 		     char **);
2297 
2298 /* options-table.c */
2299 extern const struct options_table_entry	options_table[];
2300 extern const struct options_name_map	options_other_names[];
2301 
2302 /* job.c */
2303 typedef void (*job_update_cb) (struct job *);
2304 typedef void (*job_complete_cb) (struct job *);
2305 typedef void (*job_free_cb) (void *);
2306 #define JOB_NOWAIT 0x1
2307 #define JOB_KEEPWRITE 0x2
2308 #define JOB_PTY 0x4
2309 struct job	*job_run(const char *, int, char **, struct environ *,
2310 		     struct session *, const char *, job_update_cb,
2311 		     job_complete_cb, job_free_cb, void *, int, int, int);
2312 void		 job_free(struct job *);
2313 int		 job_transfer(struct job *, pid_t *, char *, size_t);
2314 void		 job_resize(struct job *, u_int, u_int);
2315 void		 job_check_died(pid_t, int);
2316 int		 job_get_status(struct job *);
2317 void		*job_get_data(struct job *);
2318 struct bufferevent *job_get_event(struct job *);
2319 void		 job_kill_all(void);
2320 int		 job_still_running(void);
2321 void		 job_print_summary(struct cmdq_item *, int);
2322 
2323 /* environ.c */
2324 struct environ *environ_create(void);
2325 void	environ_free(struct environ *);
2326 struct environ_entry *environ_first(struct environ *);
2327 struct environ_entry *environ_next(struct environ_entry *);
2328 void	environ_copy(struct environ *, struct environ *);
2329 struct environ_entry *environ_find(struct environ *, const char *);
2330 void printflike(4, 5) environ_set(struct environ *, const char *, int,
2331 	    const char *, ...);
2332 void	environ_clear(struct environ *, const char *);
2333 void	environ_put(struct environ *, const char *, int);
2334 void	environ_unset(struct environ *, const char *);
2335 void	environ_update(struct options *, struct environ *, struct environ *);
2336 void	environ_push(struct environ *);
2337 void printflike(2, 3) environ_log(struct environ *, const char *, ...);
2338 struct environ *environ_for_session(struct session *, int);
2339 
2340 /* tty.c */
2341 void	tty_create_log(void);
2342 int	tty_window_bigger(struct tty *);
2343 int	tty_window_offset(struct tty *, u_int *, u_int *, u_int *, u_int *);
2344 void	tty_update_window_offset(struct window *);
2345 void	tty_update_client_offset(struct client *);
2346 void	tty_raw(struct tty *, const char *);
2347 void	tty_attributes(struct tty *, const struct grid_cell *,
2348 	    const struct grid_cell *, struct colour_palette *,
2349 	    struct hyperlinks *);
2350 void	tty_reset(struct tty *);
2351 void	tty_region_off(struct tty *);
2352 void	tty_margin_off(struct tty *);
2353 void	tty_cursor(struct tty *, u_int, u_int);
2354 void	tty_clipboard_query(struct tty *);
2355 void	tty_putcode(struct tty *, enum tty_code_code);
2356 void	tty_putcode_i(struct tty *, enum tty_code_code, int);
2357 void	tty_putcode_ii(struct tty *, enum tty_code_code, int, int);
2358 void	tty_putcode_iii(struct tty *, enum tty_code_code, int, int, int);
2359 void	tty_putcode_s(struct tty *, enum tty_code_code, const char *);
2360 void	tty_putcode_ss(struct tty *, enum tty_code_code, const char *,
2361 	    const char *);
2362 void	tty_puts(struct tty *, const char *);
2363 void	tty_putc(struct tty *, u_char);
2364 void	tty_putn(struct tty *, const void *, size_t, u_int);
2365 void	tty_cell(struct tty *, const struct grid_cell *,
2366 	    const struct grid_cell *, struct colour_palette *,
2367 	    struct hyperlinks *);
2368 int	tty_init(struct tty *, struct client *);
2369 void	tty_resize(struct tty *);
2370 void	tty_set_size(struct tty *, u_int, u_int, u_int, u_int);
2371 void	tty_start_tty(struct tty *);
2372 void	tty_send_requests(struct tty *);
2373 void	tty_repeat_requests(struct tty *);
2374 void	tty_stop_tty(struct tty *);
2375 void	tty_set_title(struct tty *, const char *);
2376 void	tty_set_path(struct tty *, const char *);
2377 void	tty_update_mode(struct tty *, int, struct screen *);
2378 void	tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
2379 	    u_int, u_int, const struct grid_cell *, struct colour_palette *);
2380 void	tty_sync_start(struct tty *);
2381 void	tty_sync_end(struct tty *);
2382 int	tty_open(struct tty *, char **);
2383 void	tty_close(struct tty *);
2384 void	tty_free(struct tty *);
2385 void	tty_update_features(struct tty *);
2386 void	tty_set_selection(struct tty *, const char *, const char *, size_t);
2387 void	tty_write(void (*)(struct tty *, const struct tty_ctx *),
2388 	    struct tty_ctx *);
2389 void	tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
2390 void	tty_cmd_cell(struct tty *, const struct tty_ctx *);
2391 void	tty_cmd_cells(struct tty *, const struct tty_ctx *);
2392 void	tty_cmd_clearendofline(struct tty *, const struct tty_ctx *);
2393 void	tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *);
2394 void	tty_cmd_clearline(struct tty *, const struct tty_ctx *);
2395 void	tty_cmd_clearscreen(struct tty *, const struct tty_ctx *);
2396 void	tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *);
2397 void	tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *);
2398 void	tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *);
2399 void	tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *);
2400 void	tty_cmd_deleteline(struct tty *, const struct tty_ctx *);
2401 void	tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *);
2402 void	tty_cmd_insertline(struct tty *, const struct tty_ctx *);
2403 void	tty_cmd_linefeed(struct tty *, const struct tty_ctx *);
2404 void	tty_cmd_scrollup(struct tty *, const struct tty_ctx *);
2405 void	tty_cmd_scrolldown(struct tty *, const struct tty_ctx *);
2406 void	tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
2407 void	tty_cmd_setselection(struct tty *, const struct tty_ctx *);
2408 void	tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
2409 void	tty_cmd_syncstart(struct tty *, const struct tty_ctx *);
2410 void	tty_default_colours(struct grid_cell *, struct window_pane *);
2411 
2412 /* tty-term.c */
2413 extern struct tty_terms tty_terms;
2414 u_int		 tty_term_ncodes(void);
2415 void		 tty_term_apply(struct tty_term *, const char *, int);
2416 void		 tty_term_apply_overrides(struct tty_term *);
2417 struct tty_term *tty_term_create(struct tty *, char *, char **, u_int, int *,
2418 		     char **);
2419 void		 tty_term_free(struct tty_term *);
2420 int		 tty_term_read_list(const char *, int, char ***, u_int *,
2421 		     char **);
2422 void		 tty_term_free_list(char **, u_int);
2423 int		 tty_term_has(struct tty_term *, enum tty_code_code);
2424 const char	*tty_term_string(struct tty_term *, enum tty_code_code);
2425 const char	*tty_term_string_i(struct tty_term *, enum tty_code_code, int);
2426 const char	*tty_term_string_ii(struct tty_term *, enum tty_code_code, int,
2427 		     int);
2428 const char	*tty_term_string_iii(struct tty_term *, enum tty_code_code, int,
2429 		     int, int);
2430 const char	*tty_term_string_s(struct tty_term *, enum tty_code_code,
2431 		     const char *);
2432 const char	*tty_term_string_ss(struct tty_term *, enum tty_code_code,
2433 		     const char *, const char *);
2434 int		 tty_term_number(struct tty_term *, enum tty_code_code);
2435 int		 tty_term_flag(struct tty_term *, enum tty_code_code);
2436 const char	*tty_term_describe(struct tty_term *, enum tty_code_code);
2437 
2438 /* tty-features.c */
2439 void		 tty_add_features(int *, const char *, const char *);
2440 const char	*tty_get_features(int);
2441 int		 tty_apply_features(struct tty_term *, int);
2442 void		 tty_default_features(int *, const char *, u_int);
2443 
2444 /* tty-acs.c */
2445 int		 tty_acs_needed(struct tty *);
2446 const char	*tty_acs_get(struct tty *, u_char);
2447 int		 tty_acs_reverse_get(struct tty *, const char *, size_t);
2448 const struct utf8_data *tty_acs_double_borders(int);
2449 const struct utf8_data *tty_acs_heavy_borders(int);
2450 const struct utf8_data *tty_acs_rounded_borders(int);
2451 
2452 /* tty-keys.c */
2453 void		tty_keys_build(struct tty *);
2454 void		tty_keys_free(struct tty *);
2455 int		tty_keys_next(struct tty *);
2456 int		tty_keys_colours(struct tty *, const char *, size_t, size_t *,
2457 		     int *, int *);
2458 
2459 /* arguments.c */
2460 void		 args_set(struct args *, u_char, struct args_value *, int);
2461 struct args 	*args_create(void);
2462 struct args	*args_parse(const struct args_parse *, struct args_value *,
2463 		     u_int, char **);
2464 struct args	*args_copy(struct args *, int, char **);
2465 void		 args_to_vector(struct args *, int *, char ***);
2466 struct args_value *args_from_vector(int, char **);
2467 void		 args_free_value(struct args_value *);
2468 void		 args_free_values(struct args_value *, u_int);
2469 void		 args_free(struct args *);
2470 char		*args_print(struct args *);
2471 char		*args_escape(const char *);
2472 int		 args_has(struct args *, u_char);
2473 const char	*args_get(struct args *, u_char);
2474 u_char		 args_first(struct args *, struct args_entry **);
2475 u_char		 args_next(struct args_entry **);
2476 u_int		 args_count(struct args *);
2477 struct args_value *args_values(struct args *);
2478 struct args_value *args_value(struct args *, u_int);
2479 const char	*args_string(struct args *, u_int);
2480 struct cmd_list	*args_make_commands_now(struct cmd *, struct cmdq_item *,
2481 		     u_int, int);
2482 struct args_command_state *args_make_commands_prepare(struct cmd *,
2483 		     struct cmdq_item *, u_int, const char *, int, int);
2484 struct cmd_list *args_make_commands(struct args_command_state *, int, char **,
2485 		     char **);
2486 void		 args_make_commands_free(struct args_command_state *);
2487 char		*args_make_commands_get_command(struct args_command_state *);
2488 struct args_value *args_first_value(struct args *, u_char);
2489 struct args_value *args_next_value(struct args_value *);
2490 long long	 args_strtonum(struct args *, u_char, long long, long long,
2491 		     char **);
2492 long long	 args_strtonum_and_expand(struct args *, u_char, long long,
2493 		     long long, struct cmdq_item *, char **);
2494 long long	 args_percentage(struct args *, u_char, long long,
2495 		     long long, long long, char **);
2496 long long	 args_string_percentage(const char *, long long, long long,
2497 		     long long, char **);
2498 long long	 args_percentage_and_expand(struct args *, u_char, long long,
2499 		     long long, long long, struct cmdq_item *, char **);
2500 long long	 args_string_percentage_and_expand(const char *, long long,
2501 		     long long, long long, struct cmdq_item *, char **);
2502 
2503 /* cmd-find.c */
2504 int		 cmd_find_target(struct cmd_find_state *, struct cmdq_item *,
2505 		     const char *, enum cmd_find_type, int);
2506 struct client	*cmd_find_best_client(struct session *);
2507 struct client	*cmd_find_client(struct cmdq_item *, const char *, int);
2508 void		 cmd_find_clear_state(struct cmd_find_state *, int);
2509 int		 cmd_find_empty_state(struct cmd_find_state *);
2510 int		 cmd_find_valid_state(struct cmd_find_state *);
2511 void		 cmd_find_copy_state(struct cmd_find_state *,
2512 		     struct cmd_find_state *);
2513 void		 cmd_find_from_session(struct cmd_find_state *,
2514 		     struct session *, int);
2515 void		 cmd_find_from_winlink(struct cmd_find_state *,
2516 		     struct winlink *, int);
2517 int		 cmd_find_from_session_window(struct cmd_find_state *,
2518 		     struct session *, struct window *, int);
2519 int		 cmd_find_from_window(struct cmd_find_state *, struct window *,
2520 		     int);
2521 void		 cmd_find_from_winlink_pane(struct cmd_find_state *,
2522 		     struct winlink *, struct window_pane *, int);
2523 int		 cmd_find_from_pane(struct cmd_find_state *,
2524 		     struct window_pane *, int);
2525 int		 cmd_find_from_client(struct cmd_find_state *, struct client *,
2526 		     int);
2527 int		 cmd_find_from_mouse(struct cmd_find_state *,
2528 		     struct mouse_event *, int);
2529 int		 cmd_find_from_nothing(struct cmd_find_state *, int);
2530 
2531 /* cmd.c */
2532 extern const struct cmd_entry *cmd_table[];
2533 void printflike(3, 4) cmd_log_argv(int, char **, const char *, ...);
2534 void		 cmd_prepend_argv(int *, char ***, const char *);
2535 void		 cmd_append_argv(int *, char ***, const char *);
2536 int		 cmd_pack_argv(int, char **, char *, size_t);
2537 int		 cmd_unpack_argv(char *, size_t, int, char ***);
2538 char	       **cmd_copy_argv(int, char **);
2539 void		 cmd_free_argv(int, char **);
2540 char		*cmd_stringify_argv(int, char **);
2541 char		*cmd_get_alias(const char *);
2542 const struct cmd_entry *cmd_get_entry(struct cmd *);
2543 struct args	*cmd_get_args(struct cmd *);
2544 u_int		 cmd_get_group(struct cmd *);
2545 void		 cmd_get_source(struct cmd *, const char **, u_int *);
2546 struct cmd	*cmd_parse(struct args_value *, u_int, const char *, u_int,
2547 		     char **);
2548 struct cmd	*cmd_copy(struct cmd *, int, char **);
2549 void		 cmd_free(struct cmd *);
2550 char		*cmd_print(struct cmd *);
2551 struct cmd_list	*cmd_list_new(void);
2552 struct cmd_list	*cmd_list_copy(struct cmd_list *, int, char **);
2553 void		 cmd_list_append(struct cmd_list *, struct cmd *);
2554 void		 cmd_list_append_all(struct cmd_list *, struct cmd_list *);
2555 void		 cmd_list_move(struct cmd_list *, struct cmd_list *);
2556 void		 cmd_list_free(struct cmd_list *);
2557 char		*cmd_list_print(struct cmd_list *, int);
2558 struct cmd	*cmd_list_first(struct cmd_list *);
2559 struct cmd	*cmd_list_next(struct cmd *);
2560 int		 cmd_list_all_have(struct cmd_list *, int);
2561 int		 cmd_list_any_have(struct cmd_list *, int);
2562 int		 cmd_mouse_at(struct window_pane *, struct mouse_event *,
2563 		     u_int *, u_int *, int);
2564 struct winlink	*cmd_mouse_window(struct mouse_event *, struct session **);
2565 struct window_pane *cmd_mouse_pane(struct mouse_event *, struct session **,
2566 		     struct winlink **);
2567 char		*cmd_template_replace(const char *, const char *, int);
2568 
2569 /* cmd-attach-session.c */
2570 enum cmd_retval	 cmd_attach_session(struct cmdq_item *, const char *, int, int,
2571 		     int, const char *, int, const char *);
2572 
2573 /* cmd-parse.c */
2574 struct cmd_parse_result *cmd_parse_from_file(FILE *, struct cmd_parse_input *);
2575 struct cmd_parse_result *cmd_parse_from_string(const char *,
2576 		     struct cmd_parse_input *);
2577 enum cmd_parse_status cmd_parse_and_insert(const char *,
2578 		     struct cmd_parse_input *, struct cmdq_item *,
2579 		     struct cmdq_state *, char **);
2580 enum cmd_parse_status cmd_parse_and_append(const char *,
2581 		     struct cmd_parse_input *, struct client *,
2582 		     struct cmdq_state *, char **);
2583 struct cmd_parse_result *cmd_parse_from_buffer(const void *, size_t,
2584 		     struct cmd_parse_input *);
2585 struct cmd_parse_result *cmd_parse_from_arguments(struct args_value *, u_int,
2586 		     struct cmd_parse_input *);
2587 
2588 /* cmd-queue.c */
2589 struct cmdq_state *cmdq_new_state(struct cmd_find_state *, struct key_event *,
2590 		     int);
2591 struct cmdq_state *cmdq_link_state(struct cmdq_state *);
2592 struct cmdq_state *cmdq_copy_state(struct cmdq_state *,
2593 		     struct cmd_find_state *);
2594 void		  cmdq_free_state(struct cmdq_state *);
2595 void printflike(3, 4) cmdq_add_format(struct cmdq_state *, const char *,
2596 		     const char *, ...);
2597 void		  cmdq_add_formats(struct cmdq_state *, struct format_tree *);
2598 void		  cmdq_merge_formats(struct cmdq_item *, struct format_tree *);
2599 struct cmdq_list *cmdq_new(void);
2600 void cmdq_free(struct cmdq_list *);
2601 const char	 *cmdq_get_name(struct cmdq_item *);
2602 struct client	 *cmdq_get_client(struct cmdq_item *);
2603 struct client	 *cmdq_get_target_client(struct cmdq_item *);
2604 struct cmdq_state *cmdq_get_state(struct cmdq_item *);
2605 struct cmd_find_state *cmdq_get_target(struct cmdq_item *);
2606 struct cmd_find_state *cmdq_get_source(struct cmdq_item *);
2607 struct key_event *cmdq_get_event(struct cmdq_item *);
2608 struct cmd_find_state *cmdq_get_current(struct cmdq_item *);
2609 int		  cmdq_get_flags(struct cmdq_item *);
2610 struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmdq_state *);
2611 #define cmdq_get_callback(cb, data) cmdq_get_callback1(#cb, cb, data)
2612 struct cmdq_item *cmdq_get_callback1(const char *, cmdq_cb, void *);
2613 struct cmdq_item *cmdq_get_error(const char *);
2614 struct cmdq_item *cmdq_insert_after(struct cmdq_item *, struct cmdq_item *);
2615 struct cmdq_item *cmdq_append(struct client *, struct cmdq_item *);
2616 void printflike(4, 5) cmdq_insert_hook(struct session *, struct cmdq_item *,
2617 		     struct cmd_find_state *, const char *, ...);
2618 void		 cmdq_continue(struct cmdq_item *);
2619 u_int		 cmdq_next(struct client *);
2620 struct cmdq_item *cmdq_running(struct client *);
2621 void		 cmdq_guard(struct cmdq_item *, const char *, int);
2622 void printflike(2, 3) cmdq_print(struct cmdq_item *, const char *, ...);
2623 void 		 cmdq_print_data(struct cmdq_item *, int, struct evbuffer *);
2624 void printflike(2, 3) cmdq_error(struct cmdq_item *, const char *, ...);
2625 
2626 /* cmd-wait-for.c */
2627 void	cmd_wait_for_flush(void);
2628 
2629 /* client.c */
2630 int	client_main(struct event_base *, int, char **, uint64_t, int);
2631 
2632 /* key-bindings.c */
2633 struct key_table *key_bindings_get_table(const char *, int);
2634 struct key_table *key_bindings_first_table(void);
2635 struct key_table *key_bindings_next_table(struct key_table *);
2636 void	 key_bindings_unref_table(struct key_table *);
2637 struct key_binding *key_bindings_get(struct key_table *, key_code);
2638 struct key_binding *key_bindings_get_default(struct key_table *, key_code);
2639 struct key_binding *key_bindings_first(struct key_table *);
2640 struct key_binding *key_bindings_next(struct key_table *, struct key_binding *);
2641 void	 key_bindings_add(const char *, key_code, const char *, int,
2642 	     struct cmd_list *);
2643 void	 key_bindings_remove(const char *, key_code);
2644 void	 key_bindings_reset(const char *, key_code);
2645 void	 key_bindings_remove_table(const char *);
2646 void	 key_bindings_reset_table(const char *);
2647 void	 key_bindings_init(void);
2648 struct cmdq_item *key_bindings_dispatch(struct key_binding *,
2649 	     struct cmdq_item *, struct client *, struct key_event *,
2650 	     struct cmd_find_state *);
2651 
2652 /* key-string.c */
2653 key_code	 key_string_lookup_string(const char *);
2654 const char	*key_string_lookup_key(key_code, int);
2655 
2656 /* alerts.c */
2657 void	alerts_reset_all(void);
2658 void	alerts_queue(struct window *, int);
2659 void	alerts_check_session(struct session *);
2660 
2661 /* file.c */
2662 int	 file_cmp(struct client_file *, struct client_file *);
2663 RB_PROTOTYPE(client_files, client_file, entry, file_cmp);
2664 struct client_file *file_create_with_peer(struct tmuxpeer *,
2665 	    struct client_files *, int, client_file_cb, void *);
2666 struct client_file *file_create_with_client(struct client *, int,
2667 	    client_file_cb, void *);
2668 void	 file_free(struct client_file *);
2669 void	 file_fire_done(struct client_file *);
2670 void	 file_fire_read(struct client_file *);
2671 int	 file_can_print(struct client *);
2672 void printflike(2, 3) file_print(struct client *, const char *, ...);
2673 void printflike(2, 0) file_vprint(struct client *, const char *, va_list);
2674 void	 file_print_buffer(struct client *, void *, size_t);
2675 void printflike(2, 3) file_error(struct client *, const char *, ...);
2676 void	 file_write(struct client *, const char *, int, const void *, size_t,
2677 	     client_file_cb, void *);
2678 struct client_file *file_read(struct client *, const char *, client_file_cb,
2679 	     void *);
2680 void	 file_cancel(struct client_file *);
2681 void	 file_push(struct client_file *);
2682 int	 file_write_left(struct client_files *);
2683 void	 file_write_open(struct client_files *, struct tmuxpeer *,
2684 	     struct imsg *, int, int, client_file_cb, void *);
2685 void	 file_write_data(struct client_files *, struct imsg *);
2686 void	 file_write_close(struct client_files *, struct imsg *);
2687 void	 file_read_open(struct client_files *, struct tmuxpeer *, struct imsg *,
2688 	     int, int, client_file_cb, void *);
2689 void	 file_write_ready(struct client_files *, struct imsg *);
2690 void	 file_read_data(struct client_files *, struct imsg *);
2691 void	 file_read_done(struct client_files *, struct imsg *);
2692 void	 file_read_cancel(struct client_files *, struct imsg *);
2693 
2694 /* server.c */
2695 extern struct tmuxproc *server_proc;
2696 extern struct clients clients;
2697 extern struct cmd_find_state marked_pane;
2698 extern struct message_list message_log;
2699 extern time_t current_time;
2700 void	 server_set_marked(struct session *, struct winlink *,
2701 	     struct window_pane *);
2702 void	 server_clear_marked(void);
2703 int	 server_is_marked(struct session *, struct winlink *,
2704 	     struct window_pane *);
2705 int	 server_check_marked(void);
2706 int	 server_start(struct tmuxproc *, uint64_t, struct event_base *, int,
2707 	     char *);
2708 void	 server_update_socket(void);
2709 void	 server_add_accept(int);
2710 void printflike(1, 2) server_add_message(const char *, ...);
2711 int	 server_create_socket(uint64_t, char **);
2712 
2713 /* server-client.c */
2714 RB_PROTOTYPE(client_windows, client_window, entry, server_client_window_cmp);
2715 u_int	 server_client_how_many(void);
2716 void	 server_client_set_overlay(struct client *, u_int, overlay_check_cb,
2717 	     overlay_mode_cb, overlay_draw_cb, overlay_key_cb,
2718 	     overlay_free_cb, overlay_resize_cb, void *);
2719 void	 server_client_clear_overlay(struct client *);
2720 void	 server_client_overlay_range(u_int, u_int, u_int, u_int, u_int, u_int,
2721 	     u_int, struct overlay_ranges *);
2722 void	 server_client_set_key_table(struct client *, const char *);
2723 const char *server_client_get_key_table(struct client *);
2724 int	 server_client_check_nested(struct client *);
2725 int	 server_client_handle_key(struct client *, struct key_event *);
2726 struct client *server_client_create(int);
2727 int	 server_client_open(struct client *, char **);
2728 void	 server_client_unref(struct client *);
2729 void	 server_client_set_session(struct client *, struct session *);
2730 void	 server_client_lost(struct client *);
2731 void	 server_client_suspend(struct client *);
2732 void	 server_client_detach(struct client *, enum msgtype);
2733 void	 server_client_exec(struct client *, const char *);
2734 void	 server_client_loop(void);
2735 const char *server_client_get_cwd(struct client *, struct session *);
2736 void	 server_client_set_flags(struct client *, const char *);
2737 const char *server_client_get_flags(struct client *);
2738 struct client_window *server_client_get_client_window(struct client *, u_int);
2739 struct client_window *server_client_add_client_window(struct client *, u_int);
2740 struct window_pane *server_client_get_pane(struct client *);
2741 void	 server_client_set_pane(struct client *, struct window_pane *);
2742 void	 server_client_remove_pane(struct window_pane *);
2743 void	 server_client_print(struct client *, int, struct evbuffer *);
2744 
2745 /* server-fn.c */
2746 void	 server_redraw_client(struct client *);
2747 void	 server_status_client(struct client *);
2748 void	 server_redraw_session(struct session *);
2749 void	 server_redraw_session_group(struct session *);
2750 void	 server_status_session(struct session *);
2751 void	 server_status_session_group(struct session *);
2752 void	 server_redraw_window(struct window *);
2753 void	 server_redraw_window_borders(struct window *);
2754 void	 server_status_window(struct window *);
2755 void	 server_lock(void);
2756 void	 server_lock_session(struct session *);
2757 void	 server_lock_client(struct client *);
2758 void	 server_kill_pane(struct window_pane *);
2759 void	 server_kill_window(struct window *, int);
2760 void	 server_renumber_session(struct session *);
2761 void	 server_renumber_all(void);
2762 int	 server_link_window(struct session *,
2763 	     struct winlink *, struct session *, int, int, int, char **);
2764 void	 server_unlink_window(struct session *, struct winlink *);
2765 void	 server_destroy_pane(struct window_pane *, int);
2766 void	 server_destroy_session(struct session *);
2767 void	 server_check_unattached(void);
2768 void	 server_unzoom_window(struct window *);
2769 
2770 /* status.c */
2771 extern char	**status_prompt_hlist[];
2772 extern u_int	  status_prompt_hsize[];
2773 void	 status_timer_start(struct client *);
2774 void	 status_timer_start_all(void);
2775 void	 status_update_cache(struct session *);
2776 int	 status_at_line(struct client *);
2777 u_int	 status_line_size(struct client *);
2778 struct style_range *status_get_range(struct client *, u_int, u_int);
2779 void	 status_init(struct client *);
2780 void	 status_free(struct client *);
2781 int	 status_redraw(struct client *);
2782 void printflike(5, 6) status_message_set(struct client *, int, int, int,
2783 	     const char *, ...);
2784 void	 status_message_clear(struct client *);
2785 int	 status_message_redraw(struct client *);
2786 void	 status_prompt_set(struct client *, struct cmd_find_state *,
2787 	     const char *, const char *, prompt_input_cb, prompt_free_cb,
2788 	     void *, int, enum prompt_type);
2789 void	 status_prompt_clear(struct client *);
2790 int	 status_prompt_redraw(struct client *);
2791 int	 status_prompt_key(struct client *, key_code);
2792 void	 status_prompt_update(struct client *, const char *, const char *);
2793 void	 status_prompt_load_history(void);
2794 void	 status_prompt_save_history(void);
2795 const char *status_prompt_type_string(u_int);
2796 enum prompt_type status_prompt_type(const char *type);
2797 
2798 /* resize.c */
2799 void	 resize_window(struct window *, u_int, u_int, int, int);
2800 void	 default_window_size(struct client *, struct session *, struct window *,
2801 	     u_int *, u_int *, u_int *, u_int *, int);
2802 void	 recalculate_size(struct window *, int);
2803 void	 recalculate_sizes(void);
2804 void	 recalculate_sizes_now(int);
2805 
2806 /* input.c */
2807 struct input_ctx *input_init(struct window_pane *, struct bufferevent *,
2808 	     struct colour_palette *);
2809 void	 input_free(struct input_ctx *);
2810 void	 input_reset(struct input_ctx *, int);
2811 struct evbuffer *input_pending(struct input_ctx *);
2812 void	 input_parse_pane(struct window_pane *);
2813 void	 input_parse_buffer(struct window_pane *, u_char *, size_t);
2814 void	 input_parse_screen(struct input_ctx *, struct screen *,
2815 	     screen_write_init_ctx_cb, void *, u_char *, size_t);
2816 void	 input_reply_clipboard(struct bufferevent *, const char *, size_t,
2817 	     const char *);
2818 
2819 /* input-key.c */
2820 void	 input_key_build(void);
2821 int	 input_key_pane(struct window_pane *, key_code, struct mouse_event *);
2822 int	 input_key(struct screen *, struct bufferevent *, key_code);
2823 int	 input_key_get_mouse(struct screen *, struct mouse_event *, u_int,
2824 	     u_int, const char **, size_t *);
2825 
2826 /* colour.c */
2827 int	 colour_find_rgb(u_char, u_char, u_char);
2828 int	 colour_join_rgb(u_char, u_char, u_char);
2829 void	 colour_split_rgb(int, u_char *, u_char *, u_char *);
2830 int	 colour_force_rgb(int);
2831 const char *colour_tostring(int);
2832 int	 colour_fromstring(const char *s);
2833 int	 colour_256toRGB(int);
2834 int	 colour_256to16(int);
2835 int	 colour_byname(const char *);
2836 int	 colour_parseX11(const char *);
2837 void	 colour_palette_init(struct colour_palette *);
2838 void	 colour_palette_clear(struct colour_palette *);
2839 void	 colour_palette_free(struct colour_palette *);
2840 int	 colour_palette_get(struct colour_palette *, int);
2841 int	 colour_palette_set(struct colour_palette *, int, int);
2842 void	 colour_palette_from_option(struct colour_palette *, struct options *);
2843 
2844 /* attributes.c */
2845 const char *attributes_tostring(int);
2846 int	 attributes_fromstring(const char *);
2847 
2848 /* grid.c */
2849 extern const struct grid_cell grid_default_cell;
2850 void	 grid_empty_line(struct grid *, u_int, u_int);
2851 int	 grid_cells_equal(const struct grid_cell *, const struct grid_cell *);
2852 int	 grid_cells_look_equal(const struct grid_cell *,
2853 	     const struct grid_cell *);
2854 struct grid *grid_create(u_int, u_int, u_int);
2855 void	 grid_destroy(struct grid *);
2856 int	 grid_compare(struct grid *, struct grid *);
2857 void	 grid_collect_history(struct grid *);
2858 void	 grid_remove_history(struct grid *, u_int );
2859 void	 grid_scroll_history(struct grid *, u_int);
2860 void	 grid_scroll_history_region(struct grid *, u_int, u_int, u_int);
2861 void	 grid_clear_history(struct grid *);
2862 const struct grid_line *grid_peek_line(struct grid *, u_int);
2863 void	 grid_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2864 void	 grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *);
2865 void	 grid_set_padding(struct grid *, u_int, u_int);
2866 void	 grid_set_cells(struct grid *, u_int, u_int, const struct grid_cell *,
2867 	     const char *, size_t);
2868 struct grid_line *grid_get_line(struct grid *, u_int);
2869 void	 grid_adjust_lines(struct grid *, u_int);
2870 void	 grid_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2871 void	 grid_clear_lines(struct grid *, u_int, u_int, u_int);
2872 void	 grid_move_lines(struct grid *, u_int, u_int, u_int, u_int);
2873 void	 grid_move_cells(struct grid *, u_int, u_int, u_int, u_int, u_int);
2874 char	*grid_string_cells(struct grid *, u_int, u_int, u_int,
2875 	     struct grid_cell **, int, struct screen *);
2876 void	 grid_duplicate_lines(struct grid *, u_int, struct grid *, u_int,
2877 	     u_int);
2878 void	 grid_reflow(struct grid *, u_int);
2879 void	 grid_wrap_position(struct grid *, u_int, u_int, u_int *, u_int *);
2880 void	 grid_unwrap_position(struct grid *, u_int *, u_int *, u_int, u_int);
2881 u_int	 grid_line_length(struct grid *, u_int);
2882 
2883 /* grid-reader.c */
2884 void	 grid_reader_start(struct grid_reader *, struct grid *, u_int, u_int);
2885 void	 grid_reader_get_cursor(struct grid_reader *, u_int *, u_int *);
2886 u_int	 grid_reader_line_length(struct grid_reader *);
2887 int	 grid_reader_in_set(struct grid_reader *, const char *);
2888 void	 grid_reader_cursor_right(struct grid_reader *, int, int);
2889 void	 grid_reader_cursor_left(struct grid_reader *, int);
2890 void	 grid_reader_cursor_down(struct grid_reader *);
2891 void	 grid_reader_cursor_up(struct grid_reader *);
2892 void	 grid_reader_cursor_start_of_line(struct grid_reader *, int);
2893 void	 grid_reader_cursor_end_of_line(struct grid_reader *, int, int);
2894 void	 grid_reader_cursor_next_word(struct grid_reader *, const char *);
2895 void	 grid_reader_cursor_next_word_end(struct grid_reader *, const char *);
2896 void	 grid_reader_cursor_previous_word(struct grid_reader *, const char *,
2897 	     int, int);
2898 int	 grid_reader_cursor_jump(struct grid_reader *,
2899 	     const struct utf8_data *);
2900 int	 grid_reader_cursor_jump_back(struct grid_reader *,
2901 	     const struct utf8_data *);
2902 void	 grid_reader_cursor_back_to_indentation(struct grid_reader *);
2903 
2904 /* grid-view.c */
2905 void	 grid_view_get_cell(struct grid *, u_int, u_int, struct grid_cell *);
2906 void	 grid_view_set_cell(struct grid *, u_int, u_int,
2907 	     const struct grid_cell *);
2908 void	 grid_view_set_padding(struct grid *, u_int, u_int);
2909 void	 grid_view_set_cells(struct grid *, u_int, u_int,
2910 	     const struct grid_cell *, const char *, size_t);
2911 void	 grid_view_clear_history(struct grid *, u_int);
2912 void	 grid_view_clear(struct grid *, u_int, u_int, u_int, u_int, u_int);
2913 void	 grid_view_scroll_region_up(struct grid *, u_int, u_int, u_int);
2914 void	 grid_view_scroll_region_down(struct grid *, u_int, u_int, u_int);
2915 void	 grid_view_insert_lines(struct grid *, u_int, u_int, u_int);
2916 void	 grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int,
2917 	     u_int);
2918 void	 grid_view_delete_lines(struct grid *, u_int, u_int, u_int);
2919 void	 grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int,
2920 	     u_int);
2921 void	 grid_view_insert_cells(struct grid *, u_int, u_int, u_int, u_int);
2922 void	 grid_view_delete_cells(struct grid *, u_int, u_int, u_int, u_int);
2923 char	*grid_view_string_cells(struct grid *, u_int, u_int, u_int);
2924 
2925 /* screen-write.c */
2926 void	 screen_write_make_list(struct screen *);
2927 void	 screen_write_free_list(struct screen *);
2928 void	 screen_write_start_pane(struct screen_write_ctx *,
2929 	     struct window_pane *, struct screen *);
2930 void	 screen_write_start(struct screen_write_ctx *, struct screen *);
2931 void	 screen_write_start_callback(struct screen_write_ctx *, struct screen *,
2932 	     screen_write_init_ctx_cb, void *);
2933 void	 screen_write_stop(struct screen_write_ctx *);
2934 void	 screen_write_reset(struct screen_write_ctx *);
2935 size_t printflike(1, 2) screen_write_strlen(const char *, ...);
2936 int printflike(7, 8) screen_write_text(struct screen_write_ctx *, u_int, u_int,
2937 	     u_int, int, const struct grid_cell *, const char *, ...);
2938 void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
2939 	     const struct grid_cell *, const char *, ...);
2940 void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *,
2941 	     ssize_t, const struct grid_cell *, const char *, ...);
2942 void printflike(4, 0) screen_write_vnputs(struct screen_write_ctx *, ssize_t,
2943 	     const struct grid_cell *, const char *, va_list);
2944 void	 screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
2945 	     u_char);
2946 void	 screen_write_fast_copy(struct screen_write_ctx *, struct screen *,
2947 	     u_int, u_int, u_int, u_int);
2948 void	 screen_write_hline(struct screen_write_ctx *, u_int, int, int,
2949 	     enum box_lines, const struct grid_cell *);
2950 void	 screen_write_vline(struct screen_write_ctx *, u_int, int, int);
2951 void	 screen_write_menu(struct screen_write_ctx *, struct menu *, int,
2952 	     enum box_lines, const struct grid_cell *, const struct grid_cell *,
2953 	     const struct grid_cell *);
2954 void	 screen_write_box(struct screen_write_ctx *, u_int, u_int,
2955              enum box_lines, const struct grid_cell *, const char *);
2956 void	 screen_write_preview(struct screen_write_ctx *, struct screen *, u_int,
2957 	     u_int);
2958 void	 screen_write_backspace(struct screen_write_ctx *);
2959 void	 screen_write_mode_set(struct screen_write_ctx *, int);
2960 void	 screen_write_mode_clear(struct screen_write_ctx *, int);
2961 void	 screen_write_cursorup(struct screen_write_ctx *, u_int);
2962 void	 screen_write_cursordown(struct screen_write_ctx *, u_int);
2963 void	 screen_write_cursorright(struct screen_write_ctx *, u_int);
2964 void	 screen_write_cursorleft(struct screen_write_ctx *, u_int);
2965 void	 screen_write_alignmenttest(struct screen_write_ctx *);
2966 void	 screen_write_insertcharacter(struct screen_write_ctx *, u_int, u_int);
2967 void	 screen_write_deletecharacter(struct screen_write_ctx *, u_int, u_int);
2968 void	 screen_write_clearcharacter(struct screen_write_ctx *, u_int, u_int);
2969 void	 screen_write_insertline(struct screen_write_ctx *, u_int, u_int);
2970 void	 screen_write_deleteline(struct screen_write_ctx *, u_int, u_int);
2971 void	 screen_write_clearline(struct screen_write_ctx *, u_int);
2972 void	 screen_write_clearendofline(struct screen_write_ctx *, u_int);
2973 void	 screen_write_clearstartofline(struct screen_write_ctx *, u_int);
2974 void	 screen_write_cursormove(struct screen_write_ctx *, int, int, int);
2975 void	 screen_write_reverseindex(struct screen_write_ctx *, u_int);
2976 void	 screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
2977 void	 screen_write_linefeed(struct screen_write_ctx *, int, u_int);
2978 void	 screen_write_scrollup(struct screen_write_ctx *, u_int, u_int);
2979 void	 screen_write_scrolldown(struct screen_write_ctx *, u_int, u_int);
2980 void	 screen_write_carriagereturn(struct screen_write_ctx *);
2981 void	 screen_write_clearendofscreen(struct screen_write_ctx *, u_int);
2982 void	 screen_write_clearstartofscreen(struct screen_write_ctx *, u_int);
2983 void	 screen_write_clearscreen(struct screen_write_ctx *, u_int);
2984 void	 screen_write_clearhistory(struct screen_write_ctx *);
2985 void	 screen_write_fullredraw(struct screen_write_ctx *);
2986 void	 screen_write_collect_end(struct screen_write_ctx *);
2987 void	 screen_write_collect_add(struct screen_write_ctx *,
2988 	     const struct grid_cell *);
2989 void	 screen_write_cell(struct screen_write_ctx *, const struct grid_cell *);
2990 void	 screen_write_setselection(struct screen_write_ctx *, const char *,
2991 	     u_char *, u_int);
2992 void	 screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int,
2993 	     int);
2994 void	 screen_write_alternateon(struct screen_write_ctx *,
2995 	     struct grid_cell *, int);
2996 void	 screen_write_alternateoff(struct screen_write_ctx *,
2997 	     struct grid_cell *, int);
2998 
2999 /* screen-redraw.c */
3000 void	 screen_redraw_screen(struct client *);
3001 void	 screen_redraw_pane(struct client *, struct window_pane *);
3002 
3003 /* screen.c */
3004 void	 screen_init(struct screen *, u_int, u_int, u_int);
3005 void	 screen_reinit(struct screen *);
3006 void	 screen_free(struct screen *);
3007 void	 screen_reset_tabs(struct screen *);
3008 void	 screen_reset_hyperlinks(struct screen *);
3009 void	 screen_set_cursor_style(u_int, enum screen_cursor_style *, int *);
3010 void	 screen_set_cursor_colour(struct screen *, int);
3011 int	 screen_set_title(struct screen *, const char *);
3012 void	 screen_set_path(struct screen *, const char *);
3013 void	 screen_push_title(struct screen *);
3014 void	 screen_pop_title(struct screen *);
3015 void	 screen_resize(struct screen *, u_int, u_int, int);
3016 void	 screen_resize_cursor(struct screen *, u_int, u_int, int, int, int);
3017 void	 screen_set_selection(struct screen *, u_int, u_int, u_int, u_int,
3018 	     u_int, int, struct grid_cell *);
3019 void	 screen_clear_selection(struct screen *);
3020 void	 screen_hide_selection(struct screen *);
3021 int	 screen_check_selection(struct screen *, u_int, u_int);
3022 void	 screen_select_cell(struct screen *, struct grid_cell *,
3023 	     const struct grid_cell *);
3024 void	 screen_alternate_on(struct screen *, struct grid_cell *, int);
3025 void	 screen_alternate_off(struct screen *, struct grid_cell *, int);
3026 const char *screen_mode_to_string(int);
3027 
3028 /* window.c */
3029 extern struct windows windows;
3030 extern struct window_pane_tree all_window_panes;
3031 int		 window_cmp(struct window *, struct window *);
3032 RB_PROTOTYPE(windows, window, entry, window_cmp);
3033 int		 winlink_cmp(struct winlink *, struct winlink *);
3034 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp);
3035 int		 window_pane_cmp(struct window_pane *, struct window_pane *);
3036 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp);
3037 struct winlink	*winlink_find_by_index(struct winlinks *, int);
3038 struct winlink	*winlink_find_by_window(struct winlinks *, struct window *);
3039 struct winlink	*winlink_find_by_window_id(struct winlinks *, u_int);
3040 u_int		 winlink_count(struct winlinks *);
3041 struct winlink	*winlink_add(struct winlinks *, int);
3042 void		 winlink_set_window(struct winlink *, struct window *);
3043 void		 winlink_remove(struct winlinks *, struct winlink *);
3044 struct winlink	*winlink_next(struct winlink *);
3045 struct winlink	*winlink_previous(struct winlink *);
3046 struct winlink	*winlink_next_by_number(struct winlink *, struct session *,
3047 		     int);
3048 struct winlink	*winlink_previous_by_number(struct winlink *, struct session *,
3049 		     int);
3050 void		 winlink_stack_push(struct winlink_stack *, struct winlink *);
3051 void		 winlink_stack_remove(struct winlink_stack *, struct winlink *);
3052 struct window	*window_find_by_id_str(const char *);
3053 struct window	*window_find_by_id(u_int);
3054 void		 window_update_activity(struct window *);
3055 struct window	*window_create(u_int, u_int, u_int, u_int);
3056 void		 window_pane_set_event(struct window_pane *);
3057 struct window_pane *window_get_active_at(struct window *, u_int, u_int);
3058 struct window_pane *window_find_string(struct window *, const char *);
3059 int		 window_has_pane(struct window *, struct window_pane *);
3060 int		 window_set_active_pane(struct window *, struct window_pane *,
3061 		     int);
3062 void		 window_update_focus(struct window *);
3063 void		 window_pane_update_focus(struct window_pane *);
3064 void		 window_redraw_active_switch(struct window *,
3065 		     struct window_pane *);
3066 struct window_pane *window_add_pane(struct window *, struct window_pane *,
3067 		     u_int, int);
3068 void		 window_resize(struct window *, u_int, u_int, int, int);
3069 void		 window_pane_send_resize(struct window_pane *, u_int, u_int);
3070 int		 window_zoom(struct window_pane *);
3071 int		 window_unzoom(struct window *, int);
3072 int		 window_push_zoom(struct window *, int, int);
3073 int		 window_pop_zoom(struct window *);
3074 void		 window_lost_pane(struct window *, struct window_pane *);
3075 void		 window_remove_pane(struct window *, struct window_pane *);
3076 struct window_pane *window_pane_at_index(struct window *, u_int);
3077 struct window_pane *window_pane_next_by_number(struct window *,
3078 			struct window_pane *, u_int);
3079 struct window_pane *window_pane_previous_by_number(struct window *,
3080 			struct window_pane *, u_int);
3081 int		 window_pane_index(struct window_pane *, u_int *);
3082 u_int		 window_count_panes(struct window *);
3083 void		 window_destroy_panes(struct window *);
3084 struct window_pane *window_pane_find_by_id_str(const char *);
3085 struct window_pane *window_pane_find_by_id(u_int);
3086 int		 window_pane_destroy_ready(struct window_pane *);
3087 void		 window_pane_resize(struct window_pane *, u_int, u_int);
3088 int		 window_pane_set_mode(struct window_pane *,
3089 		     struct window_pane *, const struct window_mode *,
3090 		     struct cmd_find_state *, struct args *);
3091 void		 window_pane_reset_mode(struct window_pane *);
3092 void		 window_pane_reset_mode_all(struct window_pane *);
3093 int		 window_pane_key(struct window_pane *, struct client *,
3094 		     struct session *, struct winlink *, key_code,
3095 		     struct mouse_event *);
3096 int		 window_pane_visible(struct window_pane *);
3097 int		 window_pane_exited(struct window_pane *);
3098 u_int		 window_pane_search(struct window_pane *, const char *, int,
3099 		     int);
3100 const char	*window_printable_flags(struct winlink *, int);
3101 struct window_pane *window_pane_find_up(struct window_pane *);
3102 struct window_pane *window_pane_find_down(struct window_pane *);
3103 struct window_pane *window_pane_find_left(struct window_pane *);
3104 struct window_pane *window_pane_find_right(struct window_pane *);
3105 void		 window_pane_stack_push(struct window_panes *,
3106 		     struct window_pane *);
3107 void		 window_pane_stack_remove(struct window_panes *,
3108 		     struct window_pane *);
3109 void		 window_set_name(struct window *, const char *);
3110 void		 window_add_ref(struct window *, const char *);
3111 void		 window_remove_ref(struct window *, const char *);
3112 void		 winlink_clear_flags(struct winlink *);
3113 int		 winlink_shuffle_up(struct session *, struct winlink *, int);
3114 int		 window_pane_start_input(struct window_pane *,
3115 		     struct cmdq_item *, char **);
3116 void		*window_pane_get_new_data(struct window_pane *,
3117 		     struct window_pane_offset *, size_t *);
3118 void		 window_pane_update_used_data(struct window_pane *,
3119 		     struct window_pane_offset *, size_t);
3120 void		 window_set_fill_character(struct window *);
3121 void		 window_pane_default_cursor(struct window_pane *);
3122 int		 window_pane_mode(struct window_pane *);
3123 
3124 /* layout.c */
3125 u_int		 layout_count_cells(struct layout_cell *);
3126 struct layout_cell *layout_create_cell(struct layout_cell *);
3127 void		 layout_free_cell(struct layout_cell *);
3128 void		 layout_print_cell(struct layout_cell *, const char *, u_int);
3129 void		 layout_destroy_cell(struct window *, struct layout_cell *,
3130 		     struct layout_cell **);
3131 void		 layout_resize_layout(struct window *, struct layout_cell *,
3132 		     enum layout_type, int, int);
3133 struct layout_cell *layout_search_by_border(struct layout_cell *, u_int, u_int);
3134 void		 layout_set_size(struct layout_cell *, u_int, u_int, u_int,
3135 		     u_int);
3136 void		 layout_make_leaf(struct layout_cell *, struct window_pane *);
3137 void		 layout_make_node(struct layout_cell *, enum layout_type);
3138 void		 layout_fix_offsets(struct window *);
3139 void		 layout_fix_panes(struct window *, struct window_pane *);
3140 void		 layout_resize_adjust(struct window *, struct layout_cell *,
3141 		     enum layout_type, int);
3142 void		 layout_init(struct window *, struct window_pane *);
3143 void		 layout_free(struct window *);
3144 void		 layout_resize(struct window *, u_int, u_int);
3145 void		 layout_resize_pane(struct window_pane *, enum layout_type,
3146 		     int, int);
3147 void		 layout_resize_pane_to(struct window_pane *, enum layout_type,
3148 		     u_int);
3149 void		 layout_assign_pane(struct layout_cell *, struct window_pane *,
3150 		     int);
3151 struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
3152 		     int, int);
3153 void		 layout_close_pane(struct window_pane *);
3154 int		 layout_spread_cell(struct window *, struct layout_cell *);
3155 void		 layout_spread_out(struct window_pane *);
3156 
3157 /* layout-custom.c */
3158 char		*layout_dump(struct layout_cell *);
3159 int		 layout_parse(struct window *, const char *, char **);
3160 
3161 /* layout-set.c */
3162 int		 layout_set_lookup(const char *);
3163 u_int		 layout_set_select(struct window *, u_int);
3164 u_int		 layout_set_next(struct window *);
3165 u_int		 layout_set_previous(struct window *);
3166 
3167 /* mode-tree.c */
3168 typedef void (*mode_tree_build_cb)(void *, struct mode_tree_sort_criteria *,
3169 				   uint64_t *, const char *);
3170 typedef void (*mode_tree_draw_cb)(void *, void *, struct screen_write_ctx *,
3171 	     u_int, u_int);
3172 typedef int (*mode_tree_search_cb)(void *, void *, const char *);
3173 typedef void (*mode_tree_menu_cb)(void *, struct client *, key_code);
3174 typedef u_int (*mode_tree_height_cb)(void *, u_int);
3175 typedef key_code (*mode_tree_key_cb)(void *, void *, u_int);
3176 typedef void (*mode_tree_each_cb)(void *, void *, struct client *, key_code);
3177 u_int	 mode_tree_count_tagged(struct mode_tree_data *);
3178 void	*mode_tree_get_current(struct mode_tree_data *);
3179 const char *mode_tree_get_current_name(struct mode_tree_data *);
3180 void	 mode_tree_expand_current(struct mode_tree_data *);
3181 void	 mode_tree_collapse_current(struct mode_tree_data *);
3182 void	 mode_tree_expand(struct mode_tree_data *, uint64_t);
3183 int	 mode_tree_set_current(struct mode_tree_data *, uint64_t);
3184 void	 mode_tree_each_tagged(struct mode_tree_data *, mode_tree_each_cb,
3185 	     struct client *, key_code, int);
3186 void	 mode_tree_up(struct mode_tree_data *, int);
3187 int	 mode_tree_down(struct mode_tree_data *, int);
3188 struct mode_tree_data *mode_tree_start(struct window_pane *, struct args *,
3189 	     mode_tree_build_cb, mode_tree_draw_cb, mode_tree_search_cb,
3190 	     mode_tree_menu_cb, mode_tree_height_cb, mode_tree_key_cb, void *,
3191 	     const struct menu_item *, const char **, u_int, struct screen **);
3192 void	 mode_tree_zoom(struct mode_tree_data *, struct args *);
3193 void	 mode_tree_build(struct mode_tree_data *);
3194 void	 mode_tree_free(struct mode_tree_data *);
3195 void	 mode_tree_resize(struct mode_tree_data *, u_int, u_int);
3196 struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
3197 	     struct mode_tree_item *, void *, uint64_t, const char *,
3198 	     const char *, int);
3199 void	 mode_tree_draw_as_parent(struct mode_tree_item *);
3200 void	 mode_tree_no_tag(struct mode_tree_item *);
3201 void	 mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
3202 void	 mode_tree_draw(struct mode_tree_data *);
3203 int	 mode_tree_key(struct mode_tree_data *, struct client *, key_code *,
3204 	     struct mouse_event *, u_int *, u_int *);
3205 void	 mode_tree_run_command(struct client *, struct cmd_find_state *,
3206 	     const char *, const char *);
3207 
3208 /* window-buffer.c */
3209 extern const struct window_mode window_buffer_mode;
3210 
3211 /* window-tree.c */
3212 extern const struct window_mode window_tree_mode;
3213 
3214 /* window-clock.c */
3215 extern const struct window_mode window_clock_mode;
3216 extern const char window_clock_table[14][5][5];
3217 
3218 /* window-client.c */
3219 extern const struct window_mode window_client_mode;
3220 
3221 /* window-copy.c */
3222 extern const struct window_mode window_copy_mode;
3223 extern const struct window_mode window_view_mode;
3224 void printflike(3, 4) window_copy_add(struct window_pane *, int, const char *,
3225 		     ...);
3226 void printflike(3, 0) window_copy_vadd(struct window_pane *, int, const char *,
3227 		     va_list);
3228 void		 window_copy_pageup(struct window_pane *, int);
3229 void		 window_copy_pagedown(struct window_pane *, int, int);
3230 void		 window_copy_start_drag(struct client *, struct mouse_event *);
3231 char		*window_copy_get_word(struct window_pane *, u_int, u_int);
3232 char		*window_copy_get_line(struct window_pane *, u_int);
3233 
3234 /* window-option.c */
3235 extern const struct window_mode window_customize_mode;
3236 
3237 /* names.c */
3238 void	 check_window_name(struct window *);
3239 char	*default_window_name(struct window *);
3240 char	*parse_window_name(const char *);
3241 
3242 /* control.c */
3243 void	control_discard(struct client *);
3244 void	control_start(struct client *);
3245 void	control_ready(struct client *);
3246 void	control_stop(struct client *);
3247 void	control_set_pane_on(struct client *, struct window_pane *);
3248 void	control_set_pane_off(struct client *, struct window_pane *);
3249 void	control_continue_pane(struct client *, struct window_pane *);
3250 void	control_pause_pane(struct client *, struct window_pane *);
3251 struct window_pane_offset *control_pane_offset(struct client *,
3252 	   struct window_pane *, int *);
3253 void	control_reset_offsets(struct client *);
3254 void printflike(2, 3) control_write(struct client *, const char *, ...);
3255 void	control_write_output(struct client *, struct window_pane *);
3256 int	control_all_done(struct client *);
3257 void	control_add_sub(struct client *, const char *, enum control_sub_type,
3258     	   int, const char *);
3259 void	control_remove_sub(struct client *, const char *);
3260 
3261 /* control-notify.c */
3262 void	control_notify_pane_mode_changed(int);
3263 void	control_notify_window_layout_changed(struct window *);
3264 void	control_notify_window_pane_changed(struct window *);
3265 void	control_notify_window_unlinked(struct session *, struct window *);
3266 void	control_notify_window_linked(struct session *, struct window *);
3267 void	control_notify_window_renamed(struct window *);
3268 void	control_notify_client_session_changed(struct client *);
3269 void	control_notify_client_detached(struct client *);
3270 void	control_notify_session_renamed(struct session *);
3271 void	control_notify_session_created(struct session *);
3272 void	control_notify_session_closed(struct session *);
3273 void	control_notify_session_window_changed(struct session *);
3274 void	control_notify_paste_buffer_changed(const char *);
3275 void	control_notify_paste_buffer_deleted(const char *);
3276 
3277 /* session.c */
3278 extern struct sessions sessions;
3279 extern u_int next_session_id;
3280 int	session_cmp(struct session *, struct session *);
3281 RB_PROTOTYPE(sessions, session, entry, session_cmp);
3282 int		 session_alive(struct session *);
3283 struct session	*session_find(const char *);
3284 struct session	*session_find_by_id_str(const char *);
3285 struct session	*session_find_by_id(u_int);
3286 struct session	*session_create(const char *, const char *, const char *,
3287 		     struct environ *, struct options *, struct termios *);
3288 void		 session_destroy(struct session *, int,	 const char *);
3289 void		 session_add_ref(struct session *, const char *);
3290 void		 session_remove_ref(struct session *, const char *);
3291 char		*session_check_name(const char *);
3292 void		 session_update_activity(struct session *, struct timeval *);
3293 struct session	*session_next_session(struct session *);
3294 struct session	*session_previous_session(struct session *);
3295 struct winlink	*session_attach(struct session *, struct window *, int,
3296 		     char **);
3297 int		 session_detach(struct session *, struct winlink *);
3298 int		 session_has(struct session *, struct window *);
3299 int		 session_is_linked(struct session *, struct window *);
3300 int		 session_next(struct session *, int);
3301 int		 session_previous(struct session *, int);
3302 int		 session_select(struct session *, int);
3303 int		 session_last(struct session *);
3304 int		 session_set_current(struct session *, struct winlink *);
3305 struct session_group *session_group_contains(struct session *);
3306 struct session_group *session_group_find(const char *);
3307 struct session_group *session_group_new(const char *);
3308 void		 session_group_add(struct session_group *, struct session *);
3309 void		 session_group_synchronize_to(struct session *);
3310 void		 session_group_synchronize_from(struct session *);
3311 u_int		 session_group_count(struct session_group *);
3312 u_int		 session_group_attached_count(struct session_group *);
3313 void		 session_renumber_windows(struct session *);
3314 
3315 /* utf8.c */
3316 enum utf8_state	 utf8_towc (const struct utf8_data *, wchar_t *);
3317 enum utf8_state	 utf8_fromwc(wchar_t wc, struct utf8_data *);
3318 int		 utf8_in_table(wchar_t, const wchar_t *, u_int);
3319 utf8_char	 utf8_build_one(u_char);
3320 enum utf8_state	 utf8_from_data(const struct utf8_data *, utf8_char *);
3321 void		 utf8_to_data(utf8_char, struct utf8_data *);
3322 void		 utf8_set(struct utf8_data *, u_char);
3323 void		 utf8_copy(struct utf8_data *, const struct utf8_data *);
3324 enum utf8_state	 utf8_open(struct utf8_data *, u_char);
3325 enum utf8_state	 utf8_append(struct utf8_data *, u_char);
3326 int		 utf8_isvalid(const char *);
3327 int		 utf8_strvis(char *, const char *, size_t, int);
3328 int		 utf8_stravis(char **, const char *, int);
3329 int		 utf8_stravisx(char **, const char *, size_t, int);
3330 char		*utf8_sanitize(const char *);
3331 size_t		 utf8_strlen(const struct utf8_data *);
3332 u_int		 utf8_strwidth(const struct utf8_data *, ssize_t);
3333 struct utf8_data *utf8_fromcstr(const char *);
3334 char		*utf8_tocstr(struct utf8_data *);
3335 u_int		 utf8_cstrwidth(const char *);
3336 char		*utf8_padcstr(const char *, u_int);
3337 char		*utf8_rpadcstr(const char *, u_int);
3338 int		 utf8_cstrhas(const char *, const struct utf8_data *);
3339 
3340 /* utf8-combined.c */
3341 int		 utf8_has_zwj(const struct utf8_data *);
3342 int		 utf8_is_zwj(const struct utf8_data *);
3343 int		 utf8_is_vs(const struct utf8_data *);
3344 int		 utf8_is_modifier(const struct utf8_data *);
3345 
3346 /* procname.c */
3347 char   *get_proc_name(int, char *);
3348 char   *get_proc_cwd(int);
3349 
3350 /* log.c */
3351 void	log_add_level(void);
3352 int	log_get_level(void);
3353 void	log_open(const char *);
3354 void	log_toggle(const char *);
3355 void	log_close(void);
3356 void printflike(1, 2) log_debug(const char *, ...);
3357 __dead void printflike(1, 2) fatal(const char *, ...);
3358 __dead void printflike(1, 2) fatalx(const char *, ...);
3359 
3360 /* menu.c */
3361 #define MENU_NOMOUSE 0x1
3362 #define MENU_TAB 0x2
3363 #define MENU_STAYOPEN 0x4
3364 struct menu	*menu_create(const char *);
3365 void		 menu_add_items(struct menu *, const struct menu_item *,
3366 		    struct cmdq_item *, struct client *,
3367 		    struct cmd_find_state *);
3368 void		 menu_add_item(struct menu *, const struct menu_item *,
3369 		    struct cmdq_item *, struct client *,
3370 		    struct cmd_find_state *);
3371 void		 menu_free(struct menu *);
3372 struct menu_data *menu_prepare(struct menu *, int, int, struct cmdq_item *,
3373 		    u_int, u_int, struct client *, enum box_lines, const char *,
3374 		    const char *, const char *, struct cmd_find_state *,
3375 		    menu_choice_cb, void *);
3376 int		 menu_display(struct menu *, int, int, struct cmdq_item *,
3377 		    u_int, u_int, struct client *, enum box_lines, const char *,
3378 		    const char *, const char *, struct cmd_find_state *,
3379 		    menu_choice_cb, void *);
3380 struct screen	*menu_mode_cb(struct client *, void *, u_int *, u_int *);
3381 void		 menu_check_cb(struct client *, void *, u_int, u_int, u_int,
3382 		    struct overlay_ranges *);
3383 void		 menu_draw_cb(struct client *, void *,
3384 		    struct screen_redraw_ctx *);
3385 void		 menu_free_cb(struct client *, void *);
3386 int		 menu_key_cb(struct client *, void *, struct key_event *);
3387 
3388 /* popup.c */
3389 #define POPUP_CLOSEEXIT 0x1
3390 #define POPUP_CLOSEEXITZERO 0x2
3391 #define POPUP_INTERNAL 0x4
3392 typedef void (*popup_close_cb)(int, void *);
3393 typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
3394 int		 popup_display(int, enum box_lines, struct cmdq_item *, u_int,
3395                     u_int, u_int, u_int, struct environ *, const char *, int,
3396                     char **, const char *, const char *, struct client *,
3397                     struct session *, const char *, const char *,
3398                     popup_close_cb, void *);
3399 int		 popup_editor(struct client *, const char *, size_t,
3400 		    popup_finish_edit_cb, void *);
3401 
3402 /* style.c */
3403 int		 style_parse(struct style *,const struct grid_cell *,
3404 		     const char *);
3405 const char	*style_tostring(struct style *);
3406 void		 style_add(struct grid_cell *, struct options *,
3407 		     const char *, struct format_tree *);
3408 void		 style_apply(struct grid_cell *, struct options *,
3409 		     const char *, struct format_tree *);
3410 void		 style_set(struct style *, const struct grid_cell *);
3411 void		 style_copy(struct style *, struct style *);
3412 
3413 /* spawn.c */
3414 struct winlink	*spawn_window(struct spawn_context *, char **);
3415 struct window_pane *spawn_pane(struct spawn_context *, char **);
3416 
3417 /* regsub.c */
3418 char		*regsub(const char *, const char *, const char *, int);
3419 
3420 /* server-acl.c */
3421 void			 server_acl_init(void);
3422 struct server_acl_user	*server_acl_user_find(uid_t);
3423 void 			 server_acl_display(struct cmdq_item *);
3424 void			 server_acl_user_allow(uid_t);
3425 void			 server_acl_user_deny(uid_t);
3426 void			 server_acl_user_allow_write(uid_t);
3427 void			 server_acl_user_deny_write(uid_t);
3428 int			 server_acl_join(struct client *);
3429 uid_t			 server_acl_get_uid(struct server_acl_user *);
3430 
3431 /* hyperlink.c */
3432 u_int	 		 hyperlinks_put(struct hyperlinks *, const char *,
3433 			     const char *);
3434 int			 hyperlinks_get(struct hyperlinks *, u_int,
3435 			     const char **, const char **, const char **);
3436 struct hyperlinks	*hyperlinks_init(void);
3437 struct hyperlinks	*hyperlinks_copy(struct hyperlinks *);
3438 void			 hyperlinks_reset(struct hyperlinks *);
3439 void			 hyperlinks_free(struct hyperlinks *);
3440 
3441 #endif /* TMUX_H */
3442