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