4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
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.
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.
22 #define PROTOCOL_VERSION 6
24 #include <sys/param.h>
26 #include <sys/queue.h>
30 #include <bitstring.h>
43 extern char *__progname
;
44 extern char **environ
;
46 /* Default configuration files. */
47 #define DEFAULT_CFG ".tmux.conf"
48 #define SYSTEM_CFG "/etc/tmux.conf"
50 /* Default prompt history length. */
51 #define PROMPT_HISTORY 100
54 * Minimum layout cell size, NOT including separator line. The scroll region
55 * cannot be one line in height so this must be at least two.
57 #define PANE_MINIMUM 2
59 /* Automatic name refresh interval, in milliseconds. */
60 #define NAME_INTERVAL 500
62 /* Maximum data to buffer for output before suspending writing to a tty. */
63 #define BACKOFF_THRESHOLD 16384
66 * Maximum sizes of strings in message data. Don't forget to bump
67 * PROTOCOL_VERSION if any of these change!
69 #define COMMAND_LENGTH 2048 /* packed argv size */
70 #define TERMINAL_LENGTH 128 /* length of TERM environment variable */
71 #define ENVIRON_LENGTH 1024 /* environment variable length */
74 * UTF-8 data size. This must be big enough to hold combined characters as well
80 #define fatal(msg) log_fatal("%s: %s", __func__, msg);
81 #define fatalx(msg) log_fatalx("%s: %s", __func__, msg);
83 /* Definition to shut gcc up about unused arguments. */
84 #define unused __attribute__ ((unused))
86 /* Attribute to make gcc check printf-like arguments. */
87 #define printflike1 __attribute__ ((format (printf, 1, 2)))
88 #define printflike2 __attribute__ ((format (printf, 2, 3)))
89 #define printflike3 __attribute__ ((format (printf, 3, 4)))
90 #define printflike4 __attribute__ ((format (printf, 4, 5)))
91 #define printflike5 __attribute__ ((format (printf, 5, 6)))
93 /* Number of items in array. */
95 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
98 /* Bell option values. */
101 #define BELL_CURRENT 2
103 /* Special key codes. */
104 #define KEYC_NONE 0xfff
105 #define KEYC_BASE 0x1000
107 /* Key modifier bits. */
108 #define KEYC_ESCAPE 0x2000
109 #define KEYC_CTRL 0x4000
110 #define KEYC_SHIFT 0x8000
111 #define KEYC_PREFIX 0x10000
113 /* Mask to obtain key w/o modifiers. */
114 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX)
115 #define KEYC_MASK_KEY (~KEYC_MASK_MOD)
117 /* Other key codes. */
120 KEYC_MOUSE
= KEYC_BASE
,
160 /* Numeric keypad. */
182 TTYC_ACSC
, /* acs_chars, ac */
183 TTYC_BEL
, /* bell, bl */
184 TTYC_BLINK
, /* enter_blink_mode, mb */
185 TTYC_BOLD
, /* enter_bold_mode, md */
186 TTYC_CC
, /* set colour cursor, Cc */
187 TTYC_CIVIS
, /* cursor_invisible, vi */
188 TTYC_CLEAR
, /* clear_screen, cl */
189 TTYC_CNORM
, /* cursor_normal, ve */
190 TTYC_COLORS
, /* max_colors, Co */
191 TTYC_CR
, /* restore cursor colour, Cr */
192 TTYC_CS1
, /* set cursor style, Cs */
193 TTYC_CSR
, /* change_scroll_region, cs */
194 TTYC_CSR1
, /* reset cursor style, Csr */
195 TTYC_CUB
, /* parm_left_cursor, LE */
196 TTYC_CUB1
, /* cursor_left, le */
197 TTYC_CUD
, /* parm_down_cursor, DO */
198 TTYC_CUD1
, /* cursor_down, do */
199 TTYC_CUF
, /* parm_right_cursor, RI */
200 TTYC_CUF1
, /* cursor_right, nd */
201 TTYC_CUP
, /* cursor_address, cm */
202 TTYC_CUU
, /* parm_up_cursor, UP */
203 TTYC_CUU1
, /* cursor_up, up */
204 TTYC_DCH
, /* parm_dch, DC */
205 TTYC_DCH1
, /* delete_character, dc */
206 TTYC_DIM
, /* enter_dim_mode, mh */
207 TTYC_DL
, /* parm_delete_line, DL */
208 TTYC_DL1
, /* delete_line, dl */
209 TTYC_EL
, /* clr_eol, ce */
210 TTYC_EL1
, /* clr_bol, cb */
211 TTYC_ENACS
, /* ena_acs, eA */
212 TTYC_FSL
, /* from_status_line, fsl */
213 TTYC_HOME
, /* cursor_home, ho */
214 TTYC_HPA
, /* column_address, ch */
215 TTYC_ICH
, /* parm_ich, IC */
216 TTYC_ICH1
, /* insert_character, ic */
217 TTYC_IL
, /* parm_insert_line, IL */
218 TTYC_IL1
, /* insert_line, il */
219 TTYC_INVIS
, /* enter_secure_mode, mk */
220 TTYC_IS1
, /* init_1string, i1 */
221 TTYC_IS2
, /* init_2string, i2 */
222 TTYC_IS3
, /* init_3string, i3 */
223 TTYC_KCBT
, /* key_btab, kB */
224 TTYC_KCUB1
, /* key_left, kl */
225 TTYC_KCUD1
, /* key_down, kd */
226 TTYC_KCUF1
, /* key_right, kr */
227 TTYC_KCUU1
, /* key_up, ku */
234 TTYC_KDCH1
, /* key_dc, kD */
241 TTYC_KEND
, /* key_end, ke */
248 TTYC_KF1
, /* key_f1, k1 */
249 TTYC_KF10
, /* key_f10, k; */
250 TTYC_KF11
, /* key_f11, F1 */
251 TTYC_KF12
, /* key_f12, F2 */
252 TTYC_KF13
, /* key_f13, F3 */
253 TTYC_KF14
, /* key_f14, F4 */
254 TTYC_KF15
, /* key_f15, F5 */
255 TTYC_KF16
, /* key_f16, F6 */
256 TTYC_KF17
, /* key_f17, F7 */
257 TTYC_KF18
, /* key_f18, F8 */
258 TTYC_KF19
, /* key_f19, F9 */
259 TTYC_KF2
, /* key_f2, k2 */
260 TTYC_KF20
, /* key_f20, F10 */
261 TTYC_KF3
, /* key_f3, k3 */
262 TTYC_KF4
, /* key_f4, k4 */
263 TTYC_KF5
, /* key_f5, k5 */
264 TTYC_KF6
, /* key_f6, k6 */
265 TTYC_KF7
, /* key_f7, k7 */
266 TTYC_KF8
, /* key_f8, k8 */
267 TTYC_KF9
, /* key_f9, k9 */
274 TTYC_KHOME
, /* key_home, kh */
281 TTYC_KICH1
, /* key_ic, kI */
288 TTYC_KMOUS
, /* key_mouse, Km */
289 TTYC_KNP
, /* key_npage, kN */
296 TTYC_KPP
, /* key_ppage, kP */
315 TTYC_MS
, /* modify xterm(1) selection */
316 TTYC_OP
, /* orig_pair, op */
317 TTYC_REV
, /* enter_reverse_mode, mr */
318 TTYC_RI
, /* scroll_reverse, sr */
319 TTYC_RMACS
, /* exit_alt_charset_mode */
320 TTYC_RMCUP
, /* exit_ca_mode, te */
321 TTYC_RMIR
, /* exit_insert_mode, ei */
322 TTYC_RMKX
, /* keypad_local, ke */
323 TTYC_SETAB
, /* set_a_background, AB */
324 TTYC_SETAF
, /* set_a_foreground, AF */
325 TTYC_SGR0
, /* exit_attribute_mode, me */
326 TTYC_SITM
, /* enter_italics_mode, it */
327 TTYC_SMACS
, /* enter_alt_charset_mode, as */
328 TTYC_SMCUP
, /* enter_ca_mode, ti */
329 TTYC_SMIR
, /* enter_insert_mode, im */
330 TTYC_SMKX
, /* keypad_xmit, ks */
331 TTYC_SMSO
, /* enter_standout_mode, so */
332 TTYC_SMUL
, /* enter_underline_mode, us */
333 TTYC_TSL
, /* to_status_line, tsl */
334 TTYC_VPA
, /* row_address, cv */
335 TTYC_XENL
, /* eat_newline_glitch, xn */
336 TTYC_XT
, /* xterm(1)-compatible title, XT */
338 #define NTTYCODE (TTYC_XT + 1)
350 enum tty_code_type type
;
358 /* Entry in terminal code table. */
359 struct tty_term_code_entry
{
360 enum tty_code_code code
;
361 enum tty_code_type type
;
393 * Don't forget to bump PROTOCOL_VERSION if any of these change!
395 struct msg_command_data
{
396 pid_t pid
; /* PID from $TMUX or -1 */
397 int idx
; /* index from $TMUX or -1 */
400 char argv
[COMMAND_LENGTH
];
403 struct msg_identify_data
{
404 char cwd
[MAXPATHLEN
];
406 char term
[TERMINAL_LENGTH
];
408 #define IDENTIFY_UTF8 0x1
409 #define IDENTIFY_256COLOURS 0x2
410 #define IDENTIFY_88COLOURS 0x4
414 struct msg_lock_data
{
415 char cmd
[COMMAND_LENGTH
];
418 struct msg_environ_data
{
419 char var
[ENVIRON_LENGTH
];
422 struct msg_shell_data
{
423 char shell
[MAXPATHLEN
];
426 struct msg_exit_data
{
430 /* Mode key commands. */
436 MODEKEYEDIT_BACKSPACE
,
438 MODEKEYEDIT_COMPLETE
,
439 MODEKEYEDIT_CURSORLEFT
,
440 MODEKEYEDIT_CURSORRIGHT
,
442 MODEKEYEDIT_DELETELINE
,
443 MODEKEYEDIT_DELETETOENDOFLINE
,
444 MODEKEYEDIT_ENDOFLINE
,
446 MODEKEYEDIT_HISTORYDOWN
,
447 MODEKEYEDIT_HISTORYUP
,
449 MODEKEYEDIT_STARTOFLINE
,
450 MODEKEYEDIT_SWITCHMODE
,
451 MODEKEYEDIT_SWITCHMODEAPPEND
,
452 MODEKEYEDIT_TRANSPOSECHARS
,
454 /* Menu (choice) keys. */
455 MODEKEYCHOICE_CANCEL
,
456 MODEKEYCHOICE_CHOOSE
,
458 MODEKEYCHOICE_PAGEDOWN
,
459 MODEKEYCHOICE_PAGEUP
,
460 MODEKEYCHOICE_SCROLLDOWN
,
461 MODEKEYCHOICE_SCROLLUP
,
465 MODEKEYCOPY_BACKTOINDENTATION
,
466 MODEKEYCOPY_BOTTOMLINE
,
468 MODEKEYCOPY_CLEARSELECTION
,
469 MODEKEYCOPY_COPYLINE
,
470 MODEKEYCOPY_COPYENDOFLINE
,
471 MODEKEYCOPY_COPYSELECTION
,
473 MODEKEYCOPY_ENDOFLINE
,
474 MODEKEYCOPY_GOTOLINE
,
475 MODEKEYCOPY_HALFPAGEDOWN
,
476 MODEKEYCOPY_HALFPAGEUP
,
477 MODEKEYCOPY_HISTORYBOTTOM
,
478 MODEKEYCOPY_HISTORYTOP
,
480 MODEKEYCOPY_JUMPAGAIN
,
481 MODEKEYCOPY_JUMPREVERSE
,
482 MODEKEYCOPY_JUMPBACK
,
484 MODEKEYCOPY_MIDDLELINE
,
485 MODEKEYCOPY_NEXTPAGE
,
486 MODEKEYCOPY_NEXTSPACE
,
487 MODEKEYCOPY_NEXTSPACEEND
,
488 MODEKEYCOPY_NEXTWORD
,
489 MODEKEYCOPY_NEXTWORDEND
,
490 MODEKEYCOPY_PREVIOUSPAGE
,
491 MODEKEYCOPY_PREVIOUSSPACE
,
492 MODEKEYCOPY_PREVIOUSWORD
,
493 MODEKEYCOPY_RECTANGLETOGGLE
,
495 MODEKEYCOPY_SCROLLDOWN
,
496 MODEKEYCOPY_SCROLLUP
,
497 MODEKEYCOPY_SEARCHAGAIN
,
498 MODEKEYCOPY_SEARCHDOWN
,
499 MODEKEYCOPY_SEARCHREVERSE
,
500 MODEKEYCOPY_SEARCHUP
,
501 MODEKEYCOPY_SELECTLINE
,
502 MODEKEYCOPY_STARTNUMBERPREFIX
,
503 MODEKEYCOPY_STARTOFLINE
,
504 MODEKEYCOPY_STARTSELECTION
,
509 /* Entry in the default mode key tables. */
510 struct mode_key_entry
{
514 * Editing mode for vi: 0 is edit mode, keys not in the table are
515 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table
516 * are returned as MODEKEY_NONE. This is also matched on, allowing some
517 * keys to be bound in edit mode.
520 enum mode_key_cmd cmd
;
523 /* Data required while mode keys are in use. */
524 struct mode_key_data
{
525 struct mode_key_tree
*tree
;
528 #define MODEKEY_EMACS 0
531 /* Binding between a key and a command. */
532 struct mode_key_binding
{
536 enum mode_key_cmd cmd
;
538 SPLAY_ENTRY(mode_key_binding
) entry
;
540 SPLAY_HEAD(mode_key_tree
, mode_key_binding
);
542 /* Command to string mapping. */
543 struct mode_key_cmdstr
{
544 enum mode_key_cmd cmd
;
548 /* Named mode key table description. */
549 struct mode_key_table
{
551 const struct mode_key_cmdstr
*cmdstr
;
552 struct mode_key_tree
*tree
;
553 const struct mode_key_entry
*table
; /* default entries */
557 #define MODE_CURSOR 0x1
558 #define MODE_INSERT 0x2
559 #define MODE_KCURSOR 0x4
560 #define MODE_KKEYPAD 0x8 /* set = application, clear = number */
561 #define MODE_WRAP 0x10 /* whether lines wrap */
562 #define MODE_MOUSE_STANDARD 0x20
563 #define MODE_MOUSE_BUTTON 0x40
564 #define MODE_MOUSE_ANY 0x80
565 #define MODE_MOUSE_UTF8 0x100
567 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
570 * A single UTF-8 character.
572 * The data member in this must be UTF8_SIZE to allow screen_write_copy to
573 * reinject stored UTF-8 data back into screen_write_cell after combining (ugh
577 u_char data
[UTF8_SIZE
];
586 #if defined(DEBUG) && \
587 ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
588 (defined(__GNUC__) && __GNUC__ >= 3))
589 #define GRID_DEBUG(gd, fmt, ...) log_debug2("%s: (sx=%u, sy=%u, hsize=%u) " \
590 fmt, __func__, (gd)->sx, (gd)->sy, (gd)->hsize, ## __VA_ARGS__)
592 #define GRID_DEBUG(...)
595 /* Grid attributes. */
596 #define GRID_ATTR_BRIGHT 0x1
597 #define GRID_ATTR_DIM 0x2
598 #define GRID_ATTR_UNDERSCORE 0x4
599 #define GRID_ATTR_BLINK 0x8
600 #define GRID_ATTR_REVERSE 0x10
601 #define GRID_ATTR_HIDDEN 0x20
602 #define GRID_ATTR_ITALICS 0x40
603 #define GRID_ATTR_CHARSET 0x80 /* alternative character set */
606 #define GRID_FLAG_FG256 0x1
607 #define GRID_FLAG_BG256 0x2
608 #define GRID_FLAG_PADDING 0x4
609 #define GRID_FLAG_UTF8 0x8
611 /* Grid line flags. */
612 #define GRID_LINE_WRAPPED 0x1
614 /* Grid cell data. */
623 /* Grid cell UTF-8 data. Used instead of data in grid_cell for UTF-8 cells. */
626 u_char data
[UTF8_SIZE
];
632 struct grid_cell
*celldata
;
635 struct grid_utf8
*utf8data
;
640 /* Entire grid of cells. */
643 #define GRID_HISTORY 0x1 /* scroll lines into history */
651 struct grid_line
*linedata
;
654 /* Option data structures. */
655 struct options_entry
{
668 void (*freefn
)(void *);
670 SPLAY_ENTRY(options_entry
) entry
;
674 SPLAY_HEAD(options_tree
, options_entry
) tree
;
675 struct options
*parent
;
678 /* Key list for prefix option. */
679 ARRAY_DECL(keylist
, int);
688 struct bufferevent
*event
;
690 void (*callbackfn
)(struct job
*);
691 void (*freefn
)(void *);
694 LIST_ENTRY(job
) lentry
;
696 LIST_HEAD(joblist
, job
);
698 /* Screen selection. */
709 struct grid_cell cell
;
712 /* Virtual screen. */
716 struct grid
*grid
; /* grid data */
718 u_int cx
; /* cursor x */
719 u_int cy
; /* cursor y */
721 u_int cstyle
; /* cursor style */
722 char *ccolour
; /* cursor colour string */
724 u_int rupper
; /* scroll region top */
725 u_int rlower
; /* scroll region bottom */
731 struct screen_sel sel
;
734 /* Screen write context. */
735 struct screen_write_ctx
{
736 struct window_pane
*wp
;
741 #define screen_size_x(s) ((s)->grid->sx)
742 #define screen_size_y(s) ((s)->grid->sy)
743 #define screen_hsize(s) ((s)->grid->hsize)
744 #define screen_hlimit(s) ((s)->grid->hlimit)
746 /* Input parser context. */
748 struct window_pane
*wp
;
749 struct screen_write_ctx ctx
;
751 struct grid_cell cell
;
753 struct grid_cell old_cell
;
757 u_char interm_buf
[4];
760 u_char param_buf
[64];
763 u_char input_buf
[256];
766 int param_list
[24]; /* -1 not present */
767 u_int param_list_len
;
769 struct utf8_data utf8data
;
773 #define INPUT_DISCARD 0x1
775 const struct input_state
*state
;
779 * Window mode. Windows can be in several modes and this is used to call the
780 * right function to handle input and output.
786 struct screen
*(*init
)(struct window_pane
*);
787 void (*free
)(struct window_pane
*);
788 void (*resize
)(struct window_pane
*, u_int
, u_int
);
789 void (*key
)(struct window_pane
*, struct session
*, int);
790 void (*mouse
)(struct window_pane
*,
791 struct session
*, struct mouse_event
*);
792 void (*timer
)(struct window_pane
*);
795 /* Child window structure. */
799 struct window
*window
;
800 struct layout_cell
*layout_cell
;
809 #define PANE_REDRAW 0x1
816 char tty
[TTY_NAME_MAX
];
819 struct bufferevent
*event
;
821 struct input_ctx ictx
;
824 struct bufferevent
*pipe_event
;
827 struct screen
*screen
;
830 /* Saved in alternative screen mode. */
833 struct grid
*saved_grid
;
834 struct grid_cell saved_cell
;
836 const struct window_mode
*mode
;
839 TAILQ_ENTRY(window_pane
) entry
;
840 RB_ENTRY(window_pane
) tree_entry
;
842 TAILQ_HEAD(window_panes
, window_pane
);
843 RB_HEAD(window_pane_tree
, window_pane
);
845 /* Window structure. */
848 struct event name_timer
;
849 struct timeval silence_timer
;
851 struct window_pane
*active
;
852 struct window_pane
*last
;
853 struct window_panes panes
;
856 struct layout_cell
*layout_root
;
862 #define WINDOW_BELL 0x1
863 #define WINDOW_ACTIVITY 0x2
864 #define WINDOW_REDRAW 0x4
865 #define WINDOW_SILENCE 0x8
867 struct options options
;
871 ARRAY_DECL(windows
, struct window
*);
873 /* Entry on local window list. */
876 struct window
*window
;
879 struct grid_cell status_cell
;
883 #define WINLINK_BELL 0x1
884 #define WINLINK_ACTIVITY 0x2
885 #define WINLINK_CONTENT 0x4
886 #define WINLINK_SILENCE 0x8
887 #define WINLINK_ALERTFLAGS \
888 (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT|WINLINK_SILENCE)
890 RB_ENTRY(winlink
) entry
;
891 TAILQ_ENTRY(winlink
) sentry
;
893 RB_HEAD(winlinks
, winlink
);
894 TAILQ_HEAD(winlink_stack
, winlink
);
896 /* Layout direction. */
903 /* Layout cells queue. */
904 TAILQ_HEAD(layout_cells
, layout_cell
);
908 enum layout_type type
;
910 struct layout_cell
*parent
;
918 struct window_pane
*wp
;
919 struct layout_cells cells
;
921 TAILQ_ENTRY(layout_cell
) entry
;
925 struct paste_buffer
{
929 ARRAY_DECL(paste_stack
, struct paste_buffer
*);
931 /* Environment variable. */
932 struct environ_entry
{
936 RB_ENTRY(environ_entry
) entry
;
938 RB_HEAD(environ
, environ_entry
);
940 /* Client session. */
941 struct session_group
{
942 TAILQ_HEAD(, session
) sessions
;
944 TAILQ_ENTRY(session_group
) entry
;
946 TAILQ_HEAD(session_groups
, session_group
);
954 struct timeval creation_time
;
955 struct timeval activity_time
;
960 struct winlink
*curw
;
961 struct winlink_stack lastw
;
962 struct winlinks windows
;
964 struct options options
;
966 #define SESSION_UNATTACHED 0x1 /* not attached to any clients */
971 struct environ environ
;
977 TAILQ_ENTRY(session
) gentry
;
978 RB_ENTRY(session
) entry
;
980 RB_HEAD(sessions
, session
);
981 ARRAY_DECL(sessionslist
, struct session
*);
983 /* TTY information. */
988 struct tty_key
*left
;
989 struct tty_key
*right
;
991 struct tty_key
*next
;
998 char acs
[UCHAR_MAX
+ 1][2];
1000 struct tty_code codes
[NTTYCODE
];
1002 #define TERM_256COLOURS 0x1
1003 #define TERM_88COLOURS 0x2
1004 #define TERM_EARLYWRAP 0x4
1007 LIST_ENTRY(tty_term
) entry
;
1009 LIST_HEAD(tty_terms
, tty_term
);
1028 struct tty_term
*term
;
1031 struct bufferevent
*event
;
1037 struct grid_cell cell
;
1039 #define TTY_NOCURSOR 0x1
1040 #define TTY_FREEZE 0x2
1041 #define TTY_ESCAPE 0x4
1042 #define TTY_UTF8 0x8
1043 #define TTY_STARTED 0x10
1044 #define TTY_OPENED 0x20
1045 #define TTY_BACKOFF 0x40
1050 void (*key_callback
)(int, struct mouse_event
*, void *);
1052 struct event key_timer
;
1053 struct tty_key
*key_tree
;
1056 /* TTY command context and function pointer. */
1058 struct window_pane
*wp
;
1060 const struct grid_cell
*cell
;
1061 const struct grid_utf8
*utf8
;
1067 * Cursor and region position before the screen was updated - this is
1068 * where the command should be applied; the values in the screen have
1069 * already been updated.
1077 /* Saved last cell on line. */
1078 struct grid_cell last_cell
;
1079 struct grid_utf8 last_utf8
;
1084 * xterm mouse mode is fairly silly. Buttons are in the bottom two
1085 * bits: 0 button 1; 1 button 2; 2 button 3; 3 buttons released.
1087 * Bit 3 is shift; bit 4 is meta; bit 5 control.
1089 * Bit 6 is added for mouse buttons 4 and 5.
1092 struct mouse_event
{
1098 #define MOUSE_BUTTON 3
1099 #define MOUSE_DRAG 32
1101 #define MOUSE_RESIZE_PANE 128 /* marker for resizing */
1106 /* Saved message entry. */
1107 struct message_entry
{
1112 /* Status output data from a job. */
1117 RB_ENTRY(status_out
) entry
;
1119 RB_HEAD(status_out_tree
, status_out
);
1121 /* Client connection. */
1123 struct imsgbuf ibuf
;
1127 struct timeval creation_time
;
1128 struct timeval activity_time
;
1130 struct environ environ
;
1139 void (*stdin_callback
)(struct client
*, void *);
1140 struct bufferevent
*stdin_event
;
1143 struct bufferevent
*stdout_event
;
1146 struct bufferevent
*stderr_event
;
1148 struct event repeat_timer
;
1150 struct status_out_tree status_old
;
1151 struct status_out_tree status_new
;
1152 struct timeval status_timer
;
1153 struct screen status
;
1155 #define CLIENT_TERMINAL 0x1
1156 #define CLIENT_PREFIX 0x2
1157 #define CLIENT_EXIT 0x4
1158 #define CLIENT_REDRAW 0x8
1159 #define CLIENT_STATUS 0x10
1160 #define CLIENT_REPEAT 0x20 /* allow command to repeat within repeat time */
1161 #define CLIENT_SUSPENDED 0x40
1162 #define CLIENT_BAD 0x80
1163 #define CLIENT_IDENTIFY 0x100
1164 #define CLIENT_DEAD 0x200
1165 #define CLIENT_BORDERS 0x400
1166 #define CLIENT_READONLY 0x800
1167 #define CLIENT_BACKOFF 0x1000
1168 #define CLIENT_REDRAWWINDOW 0x2000
1171 struct event identify_timer
;
1173 char *message_string
;
1174 struct event message_timer
;
1175 ARRAY_DECL(, struct message_entry
) message_log
;
1177 char *prompt_string
;
1178 char *prompt_buffer
;
1179 size_t prompt_index
;
1180 int (*prompt_callbackfn
)(void *, const char *);
1181 void (*prompt_freefn
)(void *);
1183 u_int prompt_hindex
;
1185 #define PROMPT_SINGLE 0x1
1188 struct mode_key_data prompt_mdata
;
1190 struct session
*session
;
1191 struct session
*last_session
;
1193 struct mouse_event last_mouse
;
1197 ARRAY_DECL(clients
, struct client
*);
1199 /* Parsed arguments. */
1202 char *values
[SCHAR_MAX
]; /* XXX This is awfully big. */
1208 /* Key/command line command. */
1211 * curclient is the client where this command was executed if inside
1212 * tmux. This is NULL if the command came from the command-line.
1214 * cmdclient is the client which sent the MSG_COMMAND to the server, if
1215 * any. This is NULL unless the command came from the command-line.
1217 * cmdclient and curclient may both be NULL if the command is in the
1218 * configuration file.
1220 struct client
*curclient
;
1221 struct client
*cmdclient
;
1223 struct msg_command_data
*msgdata
;
1225 /* gcc2 doesn't understand attributes on function pointers... */
1226 #if defined(__GNUC__) && __GNUC__ >= 3
1227 void printflike2 (*print
)(struct cmd_ctx
*, const char *, ...);
1228 void printflike2 (*info
)(struct cmd_ctx
*, const char *, ...);
1229 void printflike2 (*error
)(struct cmd_ctx
*, const char *, ...);
1231 void (*print
)(struct cmd_ctx
*, const char *, ...);
1232 void (*info
)(struct cmd_ctx
*, const char *, ...);
1233 void (*error
)(struct cmd_ctx
*, const char *, ...);
1238 const struct cmd_entry
*entry
;
1241 TAILQ_ENTRY(cmd
) qentry
;
1245 TAILQ_HEAD(, cmd
) list
;
1252 const char *args_template
;
1258 #define CMD_STARTSERVER 0x1
1259 #define CMD_CANTNEST 0x2
1260 #define CMD_SENDENVIRON 0x4
1261 #define CMD_READONLY 0x8
1264 void (*key_binding
)(struct cmd
*, int);
1265 int (*check
)(struct args
*);
1266 int (*exec
)(struct cmd
*, struct cmd_ctx
*);
1270 struct key_binding
{
1272 struct cmd_list
*cmdlist
;
1275 SPLAY_ENTRY(key_binding
) entry
;
1277 SPLAY_HEAD(key_bindings
, key_binding
);
1280 * Option table entries. The option table is the user-visible part of the
1281 * option, as opposed to the internal options (struct option) which are just
1284 enum options_table_type
{
1285 OPTIONS_TABLE_STRING
,
1286 OPTIONS_TABLE_NUMBER
,
1288 OPTIONS_TABLE_COLOUR
,
1289 OPTIONS_TABLE_ATTRIBUTES
,
1291 OPTIONS_TABLE_CHOICE
1294 struct options_table_entry
{
1296 enum options_table_type type
;
1300 const char **choices
;
1302 const char *default_str
;
1303 long long default_num
;
1306 /* Tree of format entries. */
1307 struct format_entry
{
1311 RB_ENTRY(format_entry
) entry
;
1313 RB_HEAD(format_tree
, format_entry
);
1315 /* List of configuration causes. */
1316 ARRAY_DECL(causelist
, char *);
1318 /* Common command usages. */
1319 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1320 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1321 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1322 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1323 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1324 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1325 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1326 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1327 #define CMD_BUFFER_USAGE "[-b buffer-index]"
1330 extern struct options global_options
;
1331 extern struct options global_s_options
;
1332 extern struct options global_w_options
;
1333 extern struct environ global_environ
;
1334 extern struct event_base
*ev_base
;
1335 extern char *cfg_file
;
1336 extern char *shell_cmd
;
1337 extern int debug_level
;
1338 extern time_t start_time
;
1339 extern char socket_path
[MAXPATHLEN
];
1340 extern int login_shell
;
1341 extern char *environ_path
;
1342 extern pid_t environ_pid
;
1343 extern int environ_idx
;
1344 void logfile(const char *);
1345 const char *getshell(void);
1346 int checkshell(const char *);
1347 int areshell(const char *);
1348 void setblocking(int, int);
1349 __dead
void shell_exec(const char *, const char *);
1352 extern int cfg_finished
;
1353 extern struct causelist cfg_causes
;
1354 void printflike2
cfg_add_cause(struct causelist
*, const char *, ...);
1355 int load_cfg(const char *, struct cmd_ctx
*, struct causelist
*);
1358 int format_cmp(struct format_entry
*, struct format_entry
*);
1359 RB_PROTOTYPE(format_tree
, format_entry
, entry
, format_cmp
);
1360 struct format_tree
*format_create(void);
1361 void format_free(struct format_tree
*);
1363 struct format_tree
*, const char *, const char *, ...);
1364 const char *format_find(struct format_tree
*, const char *);
1365 char *format_expand(struct format_tree
*, const char *);
1366 void format_session(struct format_tree
*, struct session
*);
1367 void format_winlink(
1368 struct format_tree
*, struct session
*, struct winlink
*);
1369 void format_window_pane(struct format_tree
*, struct window_pane
*);
1372 extern const struct mode_key_table mode_key_tables
[];
1373 extern struct mode_key_tree mode_key_tree_vi_edit
;
1374 extern struct mode_key_tree mode_key_tree_vi_choice
;
1375 extern struct mode_key_tree mode_key_tree_vi_copy
;
1376 extern struct mode_key_tree mode_key_tree_emacs_edit
;
1377 extern struct mode_key_tree mode_key_tree_emacs_choice
;
1378 extern struct mode_key_tree mode_key_tree_emacs_copy
;
1379 int mode_key_cmp(struct mode_key_binding
*, struct mode_key_binding
*);
1380 SPLAY_PROTOTYPE(mode_key_tree
, mode_key_binding
, entry
, mode_key_cmp
);
1381 const char *mode_key_tostring(const struct mode_key_cmdstr
*,
1383 enum mode_key_cmd
mode_key_fromstring(const struct mode_key_cmdstr
*,
1385 const struct mode_key_table
*mode_key_findtable(const char *);
1386 void mode_key_init_trees(void);
1387 void mode_key_init(struct mode_key_data
*, struct mode_key_tree
*);
1388 enum mode_key_cmd
mode_key_lookup(struct mode_key_data
*, int);
1391 int options_cmp(struct options_entry
*, struct options_entry
*);
1392 SPLAY_PROTOTYPE(options_tree
, options_entry
, entry
, options_cmp
);
1393 void options_init(struct options
*, struct options
*);
1394 void options_free(struct options
*);
1395 struct options_entry
*options_find1(struct options
*, const char *);
1396 struct options_entry
*options_find(struct options
*, const char *);
1397 void options_remove(struct options
*, const char *);
1398 struct options_entry
*printflike3
options_set_string(
1399 struct options
*, const char *, const char *, ...);
1400 char *options_get_string(struct options
*, const char *);
1401 struct options_entry
*options_set_number(
1402 struct options
*, const char *, long long);
1403 long long options_get_number(struct options
*, const char *);
1404 struct options_entry
*options_set_data(
1405 struct options
*, const char *, void *, void (*)(void *));
1406 void *options_get_data(struct options
*, const char *);
1408 /* options-table.c */
1409 extern const struct options_table_entry server_options_table
[];
1410 extern const struct options_table_entry session_options_table
[];
1411 extern const struct options_table_entry window_options_table
[];
1412 void options_table_populate_tree(
1413 const struct options_table_entry
*, struct options
*);
1414 const char *options_table_print_entry(
1415 const struct options_table_entry
*, struct options_entry
*);
1418 extern struct joblist all_jobs
;
1419 struct job
*job_run(
1420 const char *, void (*)(struct job
*), void (*)(void *), void *);
1421 void job_free(struct job
*);
1422 void job_died(struct job
*, int);
1425 int environ_cmp(struct environ_entry
*, struct environ_entry
*);
1426 RB_PROTOTYPE(environ
, environ_entry
, entry
, environ_cmp
);
1427 void environ_init(struct environ
*);
1428 void environ_free(struct environ
*);
1429 void environ_copy(struct environ
*, struct environ
*);
1430 struct environ_entry
*environ_find(struct environ
*, const char *);
1431 void environ_set(struct environ
*, const char *, const char *);
1432 void environ_put(struct environ
*, const char *);
1433 void environ_unset(struct environ
*, const char *);
1434 void environ_update(const char *, struct environ
*, struct environ
*);
1435 void environ_push(struct environ
*);
1438 void tty_raw(struct tty
*, const char *);
1439 void tty_attributes(struct tty
*, const struct grid_cell
*);
1440 void tty_reset(struct tty
*);
1441 void tty_region_pane(struct tty
*, const struct tty_ctx
*, u_int
, u_int
);
1442 void tty_region(struct tty
*, u_int
, u_int
);
1443 void tty_cursor_pane(struct tty
*, const struct tty_ctx
*, u_int
, u_int
);
1444 void tty_cursor(struct tty
*, u_int
, u_int
);
1445 void tty_putcode(struct tty
*, enum tty_code_code
);
1446 void tty_putcode1(struct tty
*, enum tty_code_code
, int);
1447 void tty_putcode2(struct tty
*, enum tty_code_code
, int, int);
1448 void tty_putcode_ptr1(struct tty
*, enum tty_code_code
, const void *);
1449 void tty_putcode_ptr2(struct tty
*, enum tty_code_code
, const void *, const void *);
1450 void tty_puts(struct tty
*, const char *);
1451 void tty_putc(struct tty
*, u_char
);
1452 void tty_pututf8(struct tty
*, const struct grid_utf8
*);
1453 void tty_init(struct tty
*, int, char *);
1454 int tty_resize(struct tty
*);
1455 void tty_start_tty(struct tty
*);
1456 void tty_stop_tty(struct tty
*);
1457 void tty_set_title(struct tty
*, const char *);
1458 void tty_update_mode(struct tty
*, int, struct screen
*);
1459 void tty_force_cursor_colour(struct tty
*, const char *);
1460 void tty_draw_line(struct tty
*, struct screen
*, u_int
, u_int
, u_int
);
1461 int tty_open(struct tty
*, const char *, char **);
1462 void tty_close(struct tty
*);
1463 void tty_free(struct tty
*);
1464 void tty_write(void (*)(
1465 struct tty
*, const struct tty_ctx
*), const struct tty_ctx
*);
1466 void tty_cmd_alignmenttest(struct tty
*, const struct tty_ctx
*);
1467 void tty_cmd_cell(struct tty
*, const struct tty_ctx
*);
1468 void tty_cmd_clearendofline(struct tty
*, const struct tty_ctx
*);
1469 void tty_cmd_clearendofscreen(struct tty
*, const struct tty_ctx
*);
1470 void tty_cmd_clearline(struct tty
*, const struct tty_ctx
*);
1471 void tty_cmd_clearscreen(struct tty
*, const struct tty_ctx
*);
1472 void tty_cmd_clearstartofline(struct tty
*, const struct tty_ctx
*);
1473 void tty_cmd_clearstartofscreen(struct tty
*, const struct tty_ctx
*);
1474 void tty_cmd_deletecharacter(struct tty
*, const struct tty_ctx
*);
1475 void tty_cmd_deleteline(struct tty
*, const struct tty_ctx
*);
1476 void tty_cmd_erasecharacter(struct tty
*, const struct tty_ctx
*);
1477 void tty_cmd_insertcharacter(struct tty
*, const struct tty_ctx
*);
1478 void tty_cmd_insertline(struct tty
*, const struct tty_ctx
*);
1479 void tty_cmd_linefeed(struct tty
*, const struct tty_ctx
*);
1480 void tty_cmd_utf8character(struct tty
*, const struct tty_ctx
*);
1481 void tty_cmd_reverseindex(struct tty
*, const struct tty_ctx
*);
1482 void tty_cmd_setselection(struct tty
*, const struct tty_ctx
*);
1483 void tty_cmd_rawstring(struct tty
*, const struct tty_ctx
*);
1484 void tty_bell(struct tty
*);
1487 extern struct tty_terms tty_terms
;
1488 extern const struct tty_term_code_entry tty_term_codes
[NTTYCODE
];
1489 struct tty_term
*tty_term_find(char *, int, const char *, char **);
1490 void tty_term_free(struct tty_term
*);
1491 int tty_term_has(struct tty_term
*, enum tty_code_code
);
1492 const char *tty_term_string(struct tty_term
*, enum tty_code_code
);
1493 const char *tty_term_string1(struct tty_term
*, enum tty_code_code
, int);
1494 const char *tty_term_string2(
1495 struct tty_term
*, enum tty_code_code
, int, int);
1496 const char *tty_term_ptr1(
1497 struct tty_term
*, enum tty_code_code
, const void *);
1498 const char *tty_term_ptr2(
1499 struct tty_term
*, enum tty_code_code
, const void *, const void *);
1500 int tty_term_number(struct tty_term
*, enum tty_code_code
);
1501 int tty_term_flag(struct tty_term
*, enum tty_code_code
);
1504 const char *tty_acs_get(struct tty
*, u_char
);
1507 void tty_keys_init(struct tty
*);
1508 void tty_keys_free(struct tty
*);
1509 int tty_keys_next(struct tty
*);
1512 struct paste_buffer
*paste_walk_stack(struct paste_stack
*, u_int
*);
1513 struct paste_buffer
*paste_get_top(struct paste_stack
*);
1514 struct paste_buffer
*paste_get_index(struct paste_stack
*, u_int
);
1515 int paste_free_top(struct paste_stack
*);
1516 int paste_free_index(struct paste_stack
*, u_int
);
1517 void paste_add(struct paste_stack
*, char *, size_t, u_int
);
1518 int paste_replace(struct paste_stack
*, u_int
, char *, size_t);
1519 char *paste_print(struct paste_buffer
*, size_t);
1522 extern const char clock_table
[14][5][5];
1523 void clock_draw(struct screen_write_ctx
*, int, int);
1526 struct args
*args_create(int, ...);
1527 struct args
*args_parse(const char *, int, char **);
1528 void args_free(struct args
*);
1529 size_t args_print(struct args
*, char *, size_t);
1530 int args_has(struct args
*, u_char
);
1531 void args_set(struct args
*, u_char
, const char *);
1532 const char *args_get(struct args
*, u_char
);
1533 long long args_strtonum(
1534 struct args
*, u_char
, long long, long long, char **);
1537 int cmd_pack_argv(int, char **, char *, size_t);
1538 int cmd_unpack_argv(char *, size_t, int, char ***);
1539 char **cmd_copy_argv(int, char *const *);
1540 void cmd_free_argv(int, char **);
1541 struct cmd
*cmd_parse(int, char **, char **);
1542 int cmd_exec(struct cmd
*, struct cmd_ctx
*);
1543 void cmd_free(struct cmd
*);
1544 size_t cmd_print(struct cmd
*, char *, size_t);
1545 struct session
*cmd_current_session(struct cmd_ctx
*, int);
1546 struct client
*cmd_current_client(struct cmd_ctx
*);
1547 struct client
*cmd_find_client(struct cmd_ctx
*, const char *);
1548 struct session
*cmd_find_session(struct cmd_ctx
*, const char *, int);
1549 struct winlink
*cmd_find_window(
1550 struct cmd_ctx
*, const char *, struct session
**);
1552 struct cmd_ctx
*, const char *, struct session
**);
1553 struct winlink
*cmd_find_pane(struct cmd_ctx
*,
1554 const char *, struct session
**, struct window_pane
**);
1555 char *cmd_template_replace(char *, const char *, int);
1556 extern const struct cmd_entry
*cmd_table
[];
1557 extern const struct cmd_entry cmd_attach_session_entry
;
1558 extern const struct cmd_entry cmd_bind_key_entry
;
1559 extern const struct cmd_entry cmd_break_pane_entry
;
1560 extern const struct cmd_entry cmd_capture_pane_entry
;
1561 extern const struct cmd_entry cmd_choose_buffer_entry
;
1562 extern const struct cmd_entry cmd_choose_client_entry
;
1563 extern const struct cmd_entry cmd_choose_session_entry
;
1564 extern const struct cmd_entry cmd_choose_window_entry
;
1565 extern const struct cmd_entry cmd_clear_history_entry
;
1566 extern const struct cmd_entry cmd_clock_mode_entry
;
1567 extern const struct cmd_entry cmd_command_prompt_entry
;
1568 extern const struct cmd_entry cmd_confirm_before_entry
;
1569 extern const struct cmd_entry cmd_copy_mode_entry
;
1570 extern const struct cmd_entry cmd_delete_buffer_entry
;
1571 extern const struct cmd_entry cmd_detach_client_entry
;
1572 extern const struct cmd_entry cmd_display_message_entry
;
1573 extern const struct cmd_entry cmd_display_panes_entry
;
1574 extern const struct cmd_entry cmd_down_pane_entry
;
1575 extern const struct cmd_entry cmd_find_window_entry
;
1576 extern const struct cmd_entry cmd_has_session_entry
;
1577 extern const struct cmd_entry cmd_if_shell_entry
;
1578 extern const struct cmd_entry cmd_join_pane_entry
;
1579 extern const struct cmd_entry cmd_kill_pane_entry
;
1580 extern const struct cmd_entry cmd_kill_server_entry
;
1581 extern const struct cmd_entry cmd_kill_session_entry
;
1582 extern const struct cmd_entry cmd_kill_window_entry
;
1583 extern const struct cmd_entry cmd_last_pane_entry
;
1584 extern const struct cmd_entry cmd_last_window_entry
;
1585 extern const struct cmd_entry cmd_link_window_entry
;
1586 extern const struct cmd_entry cmd_list_buffers_entry
;
1587 extern const struct cmd_entry cmd_list_clients_entry
;
1588 extern const struct cmd_entry cmd_list_commands_entry
;
1589 extern const struct cmd_entry cmd_list_keys_entry
;
1590 extern const struct cmd_entry cmd_list_panes_entry
;
1591 extern const struct cmd_entry cmd_list_sessions_entry
;
1592 extern const struct cmd_entry cmd_list_windows_entry
;
1593 extern const struct cmd_entry cmd_load_buffer_entry
;
1594 extern const struct cmd_entry cmd_lock_client_entry
;
1595 extern const struct cmd_entry cmd_lock_server_entry
;
1596 extern const struct cmd_entry cmd_lock_session_entry
;
1597 extern const struct cmd_entry cmd_move_window_entry
;
1598 extern const struct cmd_entry cmd_new_session_entry
;
1599 extern const struct cmd_entry cmd_new_window_entry
;
1600 extern const struct cmd_entry cmd_next_layout_entry
;
1601 extern const struct cmd_entry cmd_next_window_entry
;
1602 extern const struct cmd_entry cmd_paste_buffer_entry
;
1603 extern const struct cmd_entry cmd_pipe_pane_entry
;
1604 extern const struct cmd_entry cmd_previous_layout_entry
;
1605 extern const struct cmd_entry cmd_previous_window_entry
;
1606 extern const struct cmd_entry cmd_refresh_client_entry
;
1607 extern const struct cmd_entry cmd_rename_session_entry
;
1608 extern const struct cmd_entry cmd_rename_window_entry
;
1609 extern const struct cmd_entry cmd_resize_pane_entry
;
1610 extern const struct cmd_entry cmd_respawn_pane_entry
;
1611 extern const struct cmd_entry cmd_respawn_window_entry
;
1612 extern const struct cmd_entry cmd_rotate_window_entry
;
1613 extern const struct cmd_entry cmd_run_shell_entry
;
1614 extern const struct cmd_entry cmd_save_buffer_entry
;
1615 extern const struct cmd_entry cmd_select_layout_entry
;
1616 extern const struct cmd_entry cmd_select_pane_entry
;
1617 extern const struct cmd_entry cmd_select_window_entry
;
1618 extern const struct cmd_entry cmd_send_keys_entry
;
1619 extern const struct cmd_entry cmd_send_prefix_entry
;
1620 extern const struct cmd_entry cmd_server_info_entry
;
1621 extern const struct cmd_entry cmd_set_buffer_entry
;
1622 extern const struct cmd_entry cmd_set_environment_entry
;
1623 extern const struct cmd_entry cmd_set_option_entry
;
1624 extern const struct cmd_entry cmd_set_window_option_entry
;
1625 extern const struct cmd_entry cmd_show_buffer_entry
;
1626 extern const struct cmd_entry cmd_show_environment_entry
;
1627 extern const struct cmd_entry cmd_show_messages_entry
;
1628 extern const struct cmd_entry cmd_show_options_entry
;
1629 extern const struct cmd_entry cmd_show_window_options_entry
;
1630 extern const struct cmd_entry cmd_source_file_entry
;
1631 extern const struct cmd_entry cmd_split_window_entry
;
1632 extern const struct cmd_entry cmd_start_server_entry
;
1633 extern const struct cmd_entry cmd_suspend_client_entry
;
1634 extern const struct cmd_entry cmd_swap_pane_entry
;
1635 extern const struct cmd_entry cmd_swap_window_entry
;
1636 extern const struct cmd_entry cmd_switch_client_entry
;
1637 extern const struct cmd_entry cmd_unbind_key_entry
;
1638 extern const struct cmd_entry cmd_unlink_window_entry
;
1639 extern const struct cmd_entry cmd_up_pane_entry
;
1642 struct cmd_list
*cmd_list_parse(int, char **, char **);
1643 int cmd_list_exec(struct cmd_list
*, struct cmd_ctx
*);
1644 void cmd_list_free(struct cmd_list
*);
1645 size_t cmd_list_print(struct cmd_list
*, char *, size_t);
1648 int cmd_string_parse(const char *, struct cmd_list
**, char **);
1651 int client_main(int, char **, int);
1653 /* key-bindings.c */
1654 extern struct key_bindings key_bindings
;
1655 int key_bindings_cmp(struct key_binding
*, struct key_binding
*);
1656 SPLAY_PROTOTYPE(key_bindings
, key_binding
, entry
, key_bindings_cmp
);
1657 struct key_binding
*key_bindings_lookup(int);
1658 void key_bindings_add(int, int, struct cmd_list
*);
1659 void key_bindings_remove(int);
1660 void key_bindings_clean(void);
1661 void key_bindings_init(void);
1662 void key_bindings_dispatch(struct key_binding
*, struct client
*);
1663 void printflike2
key_bindings_error(struct cmd_ctx
*, const char *, ...);
1664 void printflike2
key_bindings_print(struct cmd_ctx
*, const char *, ...);
1665 void printflike2
key_bindings_info(struct cmd_ctx
*, const char *, ...);
1668 int key_string_lookup_string(const char *);
1669 const char *key_string_lookup_key(int);
1672 extern struct clients clients
;
1673 extern struct clients dead_clients
;
1674 extern struct paste_stack global_buffers
;
1675 int server_start(void);
1676 void server_update_socket(void);
1678 /* server-client.c */
1679 void server_client_create(int);
1680 void server_client_lost(struct client
*);
1681 void server_client_callback(int, short, void *);
1682 void server_client_status_timer(void);
1683 void server_client_loop(void);
1685 /* server-window.c */
1686 void server_window_loop(void);
1689 void server_fill_environ(struct session
*, struct environ
*);
1690 void server_write_client(
1691 struct client
*, enum msgtype
, const void *, size_t);
1692 void server_write_session(
1693 struct session
*, enum msgtype
, const void *, size_t);
1694 void server_redraw_client(struct client
*);
1695 void server_status_client(struct client
*);
1696 void server_redraw_session(struct session
*);
1697 void server_redraw_session_group(struct session
*);
1698 void server_status_session(struct session
*);
1699 void server_status_session_group(struct session
*);
1700 void server_redraw_window(struct window
*);
1701 void server_redraw_window_borders(struct window
*);
1702 void server_status_window(struct window
*);
1703 void server_lock(void);
1704 void server_lock_session(struct session
*);
1705 void server_lock_client(struct client
*);
1706 int server_unlock(const char *);
1707 void server_kill_window(struct window
*);
1708 int server_link_window(struct session
*,
1709 struct winlink
*, struct session
*, int, int, int, char **);
1710 void server_unlink_window(struct session
*, struct winlink
*);
1711 void server_destroy_pane(struct window_pane
*);
1712 void server_destroy_session_group(struct session
*);
1713 void server_destroy_session(struct session
*);
1714 void server_check_unattached (void);
1715 void server_set_identify(struct client
*);
1716 void server_clear_identify(struct client
*);
1717 void server_update_event(struct client
*);
1720 int status_out_cmp(struct status_out
*, struct status_out
*);
1721 RB_PROTOTYPE(status_out_tree
, status_out
, entry
, status_out_cmp
);
1722 void status_free_jobs(struct status_out_tree
*);
1723 void status_update_jobs(struct client
*);
1724 void status_set_window_at(struct client
*, u_int
);
1725 int status_redraw(struct client
*);
1726 char *status_replace(struct client
*, struct session
*,
1727 struct winlink
*, struct window_pane
*, const char *, time_t, int);
1728 void printflike2
status_message_set(struct client
*, const char *, ...);
1729 void status_message_clear(struct client
*);
1730 int status_message_redraw(struct client
*);
1731 void status_prompt_set(struct client
*, const char *, const char *,
1732 int (*)(void *, const char *), void (*)(void *), void *, int);
1733 void status_prompt_clear(struct client
*);
1734 int status_prompt_redraw(struct client
*);
1735 void status_prompt_key(struct client
*, int);
1736 void status_prompt_update(struct client
*, const char *, const char *);
1739 void recalculate_sizes(void);
1742 void input_init(struct window_pane
*);
1743 void input_free(struct window_pane
*);
1744 void input_parse(struct window_pane
*);
1747 void input_key(struct window_pane
*, int);
1748 void input_mouse(struct window_pane
*, struct mouse_event
*);
1751 char *xterm_keys_lookup(int);
1752 int xterm_keys_find(const char *, size_t, size_t *, int *);
1755 void colour_set_fg(struct grid_cell
*, int);
1756 void colour_set_bg(struct grid_cell
*, int);
1757 const char *colour_tostring(int);
1758 int colour_fromstring(const char *);
1759 u_char
colour_256to16(u_char
);
1760 u_char
colour_256to88(u_char
);
1763 const char *attributes_tostring(u_char
);
1764 int attributes_fromstring(const char *);
1767 extern const struct grid_cell grid_default_cell
;
1768 struct grid
*grid_create(u_int
, u_int
, u_int
);
1769 void grid_destroy(struct grid
*);
1770 int grid_compare(struct grid
*, struct grid
*);
1771 void grid_collect_history(struct grid
*);
1772 void grid_scroll_history(struct grid
*);
1773 void grid_scroll_history_region(struct grid
*, u_int
, u_int
);
1774 void grid_expand_line(struct grid
*, u_int
, u_int
);
1775 void grid_expand_line_utf8(struct grid
*, u_int
, u_int
);
1776 const struct grid_cell
*grid_peek_cell(struct grid
*, u_int
, u_int
);
1777 struct grid_cell
*grid_get_cell(struct grid
*, u_int
, u_int
);
1778 void grid_set_cell(struct grid
*, u_int
, u_int
, const struct grid_cell
*);
1779 const struct grid_utf8
*grid_peek_utf8(struct grid
*, u_int
, u_int
);
1780 struct grid_utf8
*grid_get_utf8(struct grid
*, u_int
, u_int
);
1781 void grid_set_utf8(struct grid
*, u_int
, u_int
, const struct grid_utf8
*);
1782 void grid_clear(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1783 void grid_clear_lines(struct grid
*, u_int
, u_int
);
1784 void grid_move_lines(struct grid
*, u_int
, u_int
, u_int
);
1785 void grid_move_cells(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1786 char *grid_string_cells(struct grid
*, u_int
, u_int
, u_int
);
1787 void grid_duplicate_lines(
1788 struct grid
*, u_int
, struct grid
*, u_int
, u_int
);
1791 size_t grid_utf8_size(const struct grid_utf8
*);
1792 size_t grid_utf8_copy(const struct grid_utf8
*, char *, size_t);
1793 void grid_utf8_set(struct grid_utf8
*, const struct utf8_data
*);
1794 int grid_utf8_append(struct grid_utf8
*, const struct utf8_data
*);
1795 int grid_utf8_compare(const struct grid_utf8
*, const struct grid_utf8
*);
1798 const struct grid_cell
*grid_view_peek_cell(struct grid
*, u_int
, u_int
);
1799 struct grid_cell
*grid_view_get_cell(struct grid
*, u_int
, u_int
);
1800 void grid_view_set_cell(
1801 struct grid
*, u_int
, u_int
, const struct grid_cell
*);
1802 const struct grid_utf8
*grid_view_peek_utf8(struct grid
*, u_int
, u_int
);
1803 struct grid_utf8
*grid_view_get_utf8(struct grid
*, u_int
, u_int
);
1804 void grid_view_set_utf8(
1805 struct grid
*, u_int
, u_int
, const struct grid_utf8
*);
1806 void grid_view_clear_history(struct grid
*);
1807 void grid_view_clear(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1808 void grid_view_scroll_region_up(struct grid
*, u_int
, u_int
);
1809 void grid_view_scroll_region_down(struct grid
*, u_int
, u_int
);
1810 void grid_view_insert_lines(struct grid
*, u_int
, u_int
);
1811 void grid_view_insert_lines_region(struct grid
*, u_int
, u_int
, u_int
);
1812 void grid_view_delete_lines(struct grid
*, u_int
, u_int
);
1813 void grid_view_delete_lines_region(struct grid
*, u_int
, u_int
, u_int
);
1814 void grid_view_insert_cells(struct grid
*, u_int
, u_int
, u_int
);
1815 void grid_view_delete_cells(struct grid
*, u_int
, u_int
, u_int
);
1816 char *grid_view_string_cells(struct grid
*, u_int
, u_int
, u_int
);
1818 /* screen-write.c */
1819 void screen_write_start(
1820 struct screen_write_ctx
*, struct window_pane
*, struct screen
*);
1821 void screen_write_stop(struct screen_write_ctx
*);
1822 size_t printflike2
screen_write_cstrlen(int, const char *, ...);
1823 void printflike5
screen_write_cnputs(struct screen_write_ctx
*,
1824 ssize_t
, struct grid_cell
*, int, const char *, ...);
1825 size_t printflike2
screen_write_strlen(int, const char *, ...);
1826 void printflike3
screen_write_puts(struct screen_write_ctx
*,
1827 struct grid_cell
*, const char *, ...);
1828 void printflike5
screen_write_nputs(struct screen_write_ctx
*,
1829 ssize_t
, struct grid_cell
*, int, const char *, ...);
1830 void screen_write_vnputs(struct screen_write_ctx
*,
1831 ssize_t
, struct grid_cell
*, int, const char *, va_list);
1832 void screen_write_parsestyle(
1833 struct grid_cell
*, struct grid_cell
*, const char *);
1834 void screen_write_putc(
1835 struct screen_write_ctx
*, struct grid_cell
*, u_char
);
1836 void screen_write_copy(struct screen_write_ctx
*,
1837 struct screen
*, u_int
, u_int
, u_int
, u_int
);
1838 void screen_write_backspace(struct screen_write_ctx
*);
1839 void screen_write_cursorup(struct screen_write_ctx
*, u_int
);
1840 void screen_write_cursordown(struct screen_write_ctx
*, u_int
);
1841 void screen_write_cursorright(struct screen_write_ctx
*, u_int
);
1842 void screen_write_cursorleft(struct screen_write_ctx
*, u_int
);
1843 void screen_write_alignmenttest(struct screen_write_ctx
*);
1844 void screen_write_insertcharacter(struct screen_write_ctx
*, u_int
);
1845 void screen_write_deletecharacter(struct screen_write_ctx
*, u_int
);
1846 void screen_write_insertline(struct screen_write_ctx
*, u_int
);
1847 void screen_write_deleteline(struct screen_write_ctx
*, u_int
);
1848 void screen_write_clearline(struct screen_write_ctx
*);
1849 void screen_write_clearendofline(struct screen_write_ctx
*);
1850 void screen_write_clearstartofline(struct screen_write_ctx
*);
1851 void screen_write_cursormove(struct screen_write_ctx
*, u_int
, u_int
);
1852 void screen_write_cursormode(struct screen_write_ctx
*, int);
1853 void screen_write_reverseindex(struct screen_write_ctx
*);
1854 void screen_write_scrollregion(struct screen_write_ctx
*, u_int
, u_int
);
1855 void screen_write_insertmode(struct screen_write_ctx
*, int);
1856 void screen_write_utf8mousemode(struct screen_write_ctx
*, int);
1857 void screen_write_mousemode_on(struct screen_write_ctx
*, int);
1858 void screen_write_mousemode_off(struct screen_write_ctx
*);
1859 void screen_write_linefeed(struct screen_write_ctx
*, int);
1860 void screen_write_linefeedscreen(struct screen_write_ctx
*, int);
1861 void screen_write_carriagereturn(struct screen_write_ctx
*);
1862 void screen_write_kcursormode(struct screen_write_ctx
*, int);
1863 void screen_write_kkeypadmode(struct screen_write_ctx
*, int);
1864 void screen_write_clearendofscreen(struct screen_write_ctx
*);
1865 void screen_write_clearstartofscreen(struct screen_write_ctx
*);
1866 void screen_write_clearscreen(struct screen_write_ctx
*);
1867 void screen_write_cell(struct screen_write_ctx
*,
1868 const struct grid_cell
*, const struct utf8_data
*);
1869 void screen_write_setselection(struct screen_write_ctx
*, u_char
*, u_int
);
1870 void screen_write_rawstring(struct screen_write_ctx
*, u_char
*, u_int
);
1872 /* screen-redraw.c */
1873 void screen_redraw_screen(struct client
*, int, int);
1874 void screen_redraw_pane(struct client
*, struct window_pane
*);
1877 void screen_init(struct screen
*, u_int
, u_int
, u_int
);
1878 void screen_reinit(struct screen
*);
1879 void screen_free(struct screen
*);
1880 void screen_reset_tabs(struct screen
*);
1881 void screen_set_cursor_style(struct screen
*, u_int
);
1882 void screen_set_cursor_colour(struct screen
*, const char *);
1883 void screen_set_title(struct screen
*, const char *);
1884 void screen_resize(struct screen
*, u_int
, u_int
);
1885 void screen_set_selection(struct screen
*,
1886 u_int
, u_int
, u_int
, u_int
, u_int
, struct grid_cell
*);
1887 void screen_clear_selection(struct screen
*);
1888 int screen_check_selection(struct screen
*, u_int
, u_int
);
1891 extern struct windows windows
;
1892 extern struct window_pane_tree all_window_panes
;
1893 int winlink_cmp(struct winlink
*, struct winlink
*);
1894 RB_PROTOTYPE(winlinks
, winlink
, entry
, winlink_cmp
);
1895 int window_pane_cmp(struct window_pane
*, struct window_pane
*);
1896 RB_PROTOTYPE(window_pane_tree
, window_pane
, tree_entry
, window_pane_cmp
);
1897 struct winlink
*winlink_find_by_index(struct winlinks
*, int);
1898 struct winlink
*winlink_find_by_window(struct winlinks
*, struct window
*);
1899 int winlink_next_index(struct winlinks
*, int);
1900 u_int
winlink_count(struct winlinks
*);
1901 struct winlink
*winlink_add(struct winlinks
*, int);
1902 void winlink_set_window(struct winlink
*, struct window
*);
1903 void winlink_remove(struct winlinks
*, struct winlink
*);
1904 struct winlink
*winlink_next(struct winlink
*);
1905 struct winlink
*winlink_previous(struct winlink
*);
1906 struct winlink
*winlink_next_by_number(struct winlink
*, struct session
*,
1908 struct winlink
*winlink_previous_by_number(struct winlink
*, struct session
*,
1910 void winlink_stack_push(struct winlink_stack
*, struct winlink
*);
1911 void winlink_stack_remove(struct winlink_stack
*, struct winlink
*);
1912 int window_index(struct window
*, u_int
*);
1913 struct window
*window_create1(u_int
, u_int
);
1914 struct window
*window_create(const char *, const char *, const char *,
1915 const char *, struct environ
*, struct termios
*,
1916 u_int
, u_int
, u_int
, char **);
1917 void window_destroy(struct window
*);
1918 struct window_pane
*window_get_active_at(struct window
*, u_int
, u_int
);
1919 void window_set_active_at(struct window
*, u_int
, u_int
);
1920 struct window_pane
*window_find_string(struct window
*, const char *);
1921 void window_set_active_pane(struct window
*, struct window_pane
*);
1922 struct window_pane
*window_add_pane(struct window
*, u_int
);
1923 void window_resize(struct window
*, u_int
, u_int
);
1924 void window_remove_pane(struct window
*, struct window_pane
*);
1925 struct window_pane
*window_pane_at_index(struct window
*, u_int
);
1926 struct window_pane
*window_pane_next_by_number(struct window
*,
1927 struct window_pane
*, u_int
);
1928 struct window_pane
*window_pane_previous_by_number(struct window
*,
1929 struct window_pane
*, u_int
);
1930 u_int
window_pane_index(struct window
*, struct window_pane
*);
1931 u_int
window_count_panes(struct window
*);
1932 void window_destroy_panes(struct window
*);
1933 struct window_pane
*window_pane_find_by_id(u_int
);
1934 struct window_pane
*window_pane_create(struct window
*, u_int
, u_int
, u_int
);
1935 void window_pane_destroy(struct window_pane
*);
1936 int window_pane_spawn(struct window_pane
*, const char *,
1937 const char *, const char *, struct environ
*,
1938 struct termios
*, char **);
1939 void window_pane_resize(struct window_pane
*, u_int
, u_int
);
1940 void window_pane_alternate_on(
1941 struct window_pane
*, struct grid_cell
*);
1942 void window_pane_alternate_off(
1943 struct window_pane
*, struct grid_cell
*);
1944 int window_pane_set_mode(
1945 struct window_pane
*, const struct window_mode
*);
1946 void window_pane_reset_mode(struct window_pane
*);
1947 void window_pane_key(struct window_pane
*, struct session
*, int);
1948 void window_pane_mouse(struct window_pane
*,
1949 struct session
*, struct mouse_event
*);
1950 int window_pane_visible(struct window_pane
*);
1951 char *window_pane_search(
1952 struct window_pane
*, const char *, u_int
*);
1953 char *window_printable_flags(struct session
*, struct winlink
*);
1955 struct window_pane
*window_pane_find_up(struct window_pane
*);
1956 struct window_pane
*window_pane_find_down(struct window_pane
*);
1957 struct window_pane
*window_pane_find_left(struct window_pane
*);
1958 struct window_pane
*window_pane_find_right(struct window_pane
*);
1961 u_int
layout_count_cells(struct layout_cell
*);
1962 struct layout_cell
*layout_create_cell(struct layout_cell
*);
1963 void layout_free_cell(struct layout_cell
*);
1964 void layout_print_cell(struct layout_cell
*, const char *, u_int
);
1965 void layout_destroy_cell(struct layout_cell
*, struct layout_cell
**);
1966 void layout_set_size(
1967 struct layout_cell
*, u_int
, u_int
, u_int
, u_int
);
1968 void layout_make_leaf(
1969 struct layout_cell
*, struct window_pane
*);
1970 void layout_make_node(struct layout_cell
*, enum layout_type
);
1971 void layout_fix_offsets(struct layout_cell
*);
1972 void layout_fix_panes(struct window
*, u_int
, u_int
);
1973 u_int
layout_resize_check(struct layout_cell
*, enum layout_type
);
1974 void layout_resize_adjust(
1975 struct layout_cell
*, enum layout_type
, int);
1976 void layout_init(struct window
*);
1977 void layout_free(struct window
*);
1978 void layout_resize(struct window
*, u_int
, u_int
);
1979 void layout_resize_pane(
1980 struct window_pane
*, enum layout_type
, int);
1981 void layout_resize_pane_mouse(
1982 struct client
*c
, struct mouse_event
*mouse
);
1983 void layout_assign_pane(struct layout_cell
*, struct window_pane
*);
1984 struct layout_cell
*layout_split_pane(
1985 struct window_pane
*, enum layout_type
, int);
1986 void layout_close_pane(struct window_pane
*);
1988 /* layout-custom.c */
1989 char *layout_dump(struct window
*);
1990 int layout_parse(struct window
*, const char *);
1993 const char *layout_set_name(u_int
);
1994 int layout_set_lookup(const char *);
1995 u_int
layout_set_select(struct window
*, u_int
);
1996 u_int
layout_set_next(struct window
*);
1997 u_int
layout_set_previous(struct window
*);
1998 void layout_set_active_changed(struct window
*);
2000 /* window-clock.c */
2001 extern const struct window_mode window_clock_mode
;
2004 extern const struct window_mode window_copy_mode
;
2005 void window_copy_init_from_pane(struct window_pane
*);
2006 void window_copy_init_for_output(struct window_pane
*);
2007 void window_copy_add(struct window_pane
*, const char *, ...);
2008 void window_copy_vadd(struct window_pane
*, const char *, va_list);
2009 void window_copy_pageup(struct window_pane
*);
2011 /* window-choose.c */
2012 extern const struct window_mode window_choose_mode
;
2013 void window_choose_vadd(
2014 struct window_pane
*, int, const char *, va_list);
2015 void printflike3
window_choose_add(
2016 struct window_pane
*, int, const char *, ...);
2017 void window_choose_ready(struct window_pane
*,
2018 u_int
, void (*)(void *, int), void (*)(void *), void *);
2021 void queue_window_name(struct window
*);
2022 char *default_window_name(struct window
*);
2025 void set_signals(void(*)(int, short, void *));
2026 void clear_signals(int);
2029 extern struct sessions sessions
;
2030 extern struct sessions dead_sessions
;
2031 extern struct session_groups session_groups
;
2032 int session_cmp(struct session
*, struct session
*);
2033 RB_PROTOTYPE(sessions
, session
, entry
, session_cmp
);
2034 int session_alive(struct session
*);
2035 struct session
*session_find(const char *);
2036 struct session
*session_find_by_index(u_int
);
2037 struct session
*session_create(const char *, const char *, const char *,
2038 struct environ
*, struct termios
*, int, u_int
, u_int
,
2040 void session_destroy(struct session
*);
2041 int session_check_name(const char *);
2042 void session_update_activity(struct session
*);
2043 struct session
*session_next_session(struct session
*);
2044 struct session
*session_previous_session(struct session
*);
2045 struct winlink
*session_new(struct session
*,
2046 const char *, const char *, const char *, int, char **);
2047 struct winlink
*session_attach(
2048 struct session
*, struct window
*, int, char **);
2049 int session_detach(struct session
*, struct winlink
*);
2050 struct winlink
* session_has(struct session
*, struct window
*);
2051 int session_next(struct session
*, int);
2052 int session_previous(struct session
*, int);
2053 int session_select(struct session
*, int);
2054 int session_last(struct session
*);
2055 struct session_group
*session_group_find(struct session
*);
2056 u_int
session_group_index(struct session_group
*);
2057 void session_group_add(struct session
*, struct session
*);
2058 void session_group_remove(struct session
*);
2059 void session_group_synchronize_to(struct session
*);
2060 void session_group_synchronize_from(struct session
*);
2061 void session_group_synchronize1(struct session
*, struct session
*);
2064 void utf8_build(void);
2065 int utf8_open(struct utf8_data
*, u_char
);
2066 int utf8_append(struct utf8_data
*, u_char
);
2067 u_int
utf8_combine(const struct utf8_data
*);
2068 u_int
utf8_split2(u_int
, u_char
*);
2071 char *get_proc_name(int, char *);
2074 void log_open_tty(int);
2075 void log_open_file(int, const char *);
2076 void log_close(void);
2077 void printflike1
log_warn(const char *, ...);
2078 void printflike1
log_warnx(const char *, ...);
2079 void printflike1
log_info(const char *, ...);
2080 void printflike1
log_debug(const char *, ...);
2081 void printflike1
log_debug2(const char *, ...);
2082 __dead
void printflike1
log_fatal(const char *, ...);
2083 __dead
void printflike1
log_fatalx(const char *, ...);
2086 char *xstrdup(const char *);
2087 void *xcalloc(size_t, size_t);
2088 void *xmalloc(size_t);
2089 void *xrealloc(void *, size_t, size_t);
2091 int printflike2
xasprintf(char **, const char *, ...);
2092 int xvasprintf(char **, const char *, va_list);
2093 int printflike3
xsnprintf(char *, size_t, const char *, ...);
2094 int xvsnprintf(char *, size_t, const char *, va_list);