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