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 */
210 TTYC_EL
, /* clr_eol, ce */
211 TTYC_EL1
, /* clr_bol, cb */
212 TTYC_ENACS
, /* ena_acs, eA */
213 TTYC_FSL
, /* from_status_line, fsl */
214 TTYC_HOME
, /* cursor_home, ho */
215 TTYC_HPA
, /* column_address, ch */
216 TTYC_ICH
, /* parm_ich, IC */
217 TTYC_ICH1
, /* insert_character, ic */
218 TTYC_IL
, /* parm_insert_line, IL */
219 TTYC_IL1
, /* insert_line, il */
220 TTYC_INVIS
, /* enter_secure_mode, mk */
221 TTYC_IS1
, /* init_1string, i1 */
222 TTYC_IS2
, /* init_2string, i2 */
223 TTYC_IS3
, /* init_3string, i3 */
224 TTYC_KCBT
, /* key_btab, kB */
225 TTYC_KCUB1
, /* key_left, kl */
226 TTYC_KCUD1
, /* key_down, kd */
227 TTYC_KCUF1
, /* key_right, kr */
228 TTYC_KCUU1
, /* key_up, ku */
235 TTYC_KDCH1
, /* key_dc, kD */
242 TTYC_KEND
, /* key_end, ke */
249 TTYC_KF1
, /* key_f1, k1 */
250 TTYC_KF10
, /* key_f10, k; */
251 TTYC_KF11
, /* key_f11, F1 */
252 TTYC_KF12
, /* key_f12, F2 */
253 TTYC_KF13
, /* key_f13, F3 */
254 TTYC_KF14
, /* key_f14, F4 */
255 TTYC_KF15
, /* key_f15, F5 */
256 TTYC_KF16
, /* key_f16, F6 */
257 TTYC_KF17
, /* key_f17, F7 */
258 TTYC_KF18
, /* key_f18, F8 */
259 TTYC_KF19
, /* key_f19, F9 */
260 TTYC_KF2
, /* key_f2, k2 */
261 TTYC_KF20
, /* key_f20, F10 */
262 TTYC_KF3
, /* key_f3, k3 */
263 TTYC_KF4
, /* key_f4, k4 */
264 TTYC_KF5
, /* key_f5, k5 */
265 TTYC_KF6
, /* key_f6, k6 */
266 TTYC_KF7
, /* key_f7, k7 */
267 TTYC_KF8
, /* key_f8, k8 */
268 TTYC_KF9
, /* key_f9, k9 */
275 TTYC_KHOME
, /* key_home, kh */
282 TTYC_KICH1
, /* key_ic, kI */
289 TTYC_KMOUS
, /* key_mouse, Km */
290 TTYC_KNP
, /* key_npage, kN */
297 TTYC_KPP
, /* key_ppage, kP */
316 TTYC_MS
, /* modify xterm(1) selection */
317 TTYC_OP
, /* orig_pair, op */
318 TTYC_REV
, /* enter_reverse_mode, mr */
319 TTYC_RI
, /* scroll_reverse, sr */
320 TTYC_RMACS
, /* exit_alt_charset_mode */
321 TTYC_RMCUP
, /* exit_ca_mode, te */
322 TTYC_RMIR
, /* exit_insert_mode, ei */
323 TTYC_RMKX
, /* keypad_local, ke */
324 TTYC_SETAB
, /* set_a_background, AB */
325 TTYC_SETAF
, /* set_a_foreground, AF */
326 TTYC_SGR0
, /* exit_attribute_mode, me */
327 TTYC_SITM
, /* enter_italics_mode, it */
328 TTYC_SMACS
, /* enter_alt_charset_mode, as */
329 TTYC_SMCUP
, /* enter_ca_mode, ti */
330 TTYC_SMIR
, /* enter_insert_mode, im */
331 TTYC_SMKX
, /* keypad_xmit, ks */
332 TTYC_SMSO
, /* enter_standout_mode, so */
333 TTYC_SMUL
, /* enter_underline_mode, us */
334 TTYC_TSL
, /* to_status_line, tsl */
335 TTYC_VPA
, /* row_address, cv */
336 TTYC_XENL
, /* eat_newline_glitch, xn */
337 TTYC_XT
, /* xterm(1)-compatible title, XT */
339 #define NTTYCODE (TTYC_XT + 1)
351 enum tty_code_type type
;
359 /* Entry in terminal code table. */
360 struct tty_term_code_entry
{
361 enum tty_code_code code
;
362 enum tty_code_type type
;
394 * Don't forget to bump PROTOCOL_VERSION if any of these change!
396 struct msg_command_data
{
397 pid_t pid
; /* PID from $TMUX or -1 */
398 int idx
; /* index from $TMUX or -1 */
401 char argv
[COMMAND_LENGTH
];
404 struct msg_identify_data
{
405 char cwd
[MAXPATHLEN
];
407 char term
[TERMINAL_LENGTH
];
409 #define IDENTIFY_UTF8 0x1
410 #define IDENTIFY_256COLOURS 0x2
411 #define IDENTIFY_88COLOURS 0x4
415 struct msg_lock_data
{
416 char cmd
[COMMAND_LENGTH
];
419 struct msg_environ_data
{
420 char var
[ENVIRON_LENGTH
];
423 struct msg_shell_data
{
424 char shell
[MAXPATHLEN
];
427 struct msg_exit_data
{
431 /* Mode key commands. */
437 MODEKEYEDIT_BACKSPACE
,
439 MODEKEYEDIT_COMPLETE
,
440 MODEKEYEDIT_CURSORLEFT
,
441 MODEKEYEDIT_CURSORRIGHT
,
443 MODEKEYEDIT_DELETELINE
,
444 MODEKEYEDIT_DELETETOENDOFLINE
,
445 MODEKEYEDIT_DELETEWORD
,
446 MODEKEYEDIT_ENDOFLINE
,
448 MODEKEYEDIT_HISTORYDOWN
,
449 MODEKEYEDIT_HISTORYUP
,
450 MODEKEYEDIT_NEXTSPACE
,
451 MODEKEYEDIT_NEXTSPACEEND
,
452 MODEKEYEDIT_NEXTWORD
,
453 MODEKEYEDIT_NEXTWORDEND
,
455 MODEKEYEDIT_PREVIOUSSPACE
,
456 MODEKEYEDIT_PREVIOUSWORD
,
457 MODEKEYEDIT_STARTOFLINE
,
458 MODEKEYEDIT_SWITCHMODE
,
459 MODEKEYEDIT_SWITCHMODEAPPEND
,
460 MODEKEYEDIT_TRANSPOSECHARS
,
462 /* Menu (choice) keys. */
463 MODEKEYCHOICE_CANCEL
,
464 MODEKEYCHOICE_CHOOSE
,
466 MODEKEYCHOICE_PAGEDOWN
,
467 MODEKEYCHOICE_PAGEUP
,
468 MODEKEYCHOICE_SCROLLDOWN
,
469 MODEKEYCHOICE_SCROLLUP
,
473 MODEKEYCOPY_BACKTOINDENTATION
,
474 MODEKEYCOPY_BOTTOMLINE
,
476 MODEKEYCOPY_CLEARSELECTION
,
477 MODEKEYCOPY_COPYLINE
,
478 MODEKEYCOPY_COPYENDOFLINE
,
479 MODEKEYCOPY_COPYSELECTION
,
481 MODEKEYCOPY_ENDOFLINE
,
482 MODEKEYCOPY_GOTOLINE
,
483 MODEKEYCOPY_HALFPAGEDOWN
,
484 MODEKEYCOPY_HALFPAGEUP
,
485 MODEKEYCOPY_HISTORYBOTTOM
,
486 MODEKEYCOPY_HISTORYTOP
,
488 MODEKEYCOPY_JUMPAGAIN
,
489 MODEKEYCOPY_JUMPREVERSE
,
490 MODEKEYCOPY_JUMPBACK
,
492 MODEKEYCOPY_JUMPTOBACK
,
494 MODEKEYCOPY_MIDDLELINE
,
495 MODEKEYCOPY_NEXTPAGE
,
496 MODEKEYCOPY_NEXTSPACE
,
497 MODEKEYCOPY_NEXTSPACEEND
,
498 MODEKEYCOPY_NEXTWORD
,
499 MODEKEYCOPY_NEXTWORDEND
,
500 MODEKEYCOPY_PREVIOUSPAGE
,
501 MODEKEYCOPY_PREVIOUSSPACE
,
502 MODEKEYCOPY_PREVIOUSWORD
,
503 MODEKEYCOPY_RECTANGLETOGGLE
,
505 MODEKEYCOPY_SCROLLDOWN
,
506 MODEKEYCOPY_SCROLLUP
,
507 MODEKEYCOPY_SEARCHAGAIN
,
508 MODEKEYCOPY_SEARCHDOWN
,
509 MODEKEYCOPY_SEARCHREVERSE
,
510 MODEKEYCOPY_SEARCHUP
,
511 MODEKEYCOPY_SELECTLINE
,
512 MODEKEYCOPY_STARTNUMBERPREFIX
,
513 MODEKEYCOPY_STARTOFLINE
,
514 MODEKEYCOPY_STARTSELECTION
,
519 /* Entry in the default mode key tables. */
520 struct mode_key_entry
{
524 * Editing mode for vi: 0 is edit mode, keys not in the table are
525 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table
526 * are returned as MODEKEY_NONE. This is also matched on, allowing some
527 * keys to be bound in edit mode.
530 enum mode_key_cmd cmd
;
533 /* Data required while mode keys are in use. */
534 struct mode_key_data
{
535 struct mode_key_tree
*tree
;
538 #define MODEKEY_EMACS 0
541 /* Binding between a key and a command. */
542 struct mode_key_binding
{
546 enum mode_key_cmd cmd
;
548 RB_ENTRY(mode_key_binding
) entry
;
550 RB_HEAD(mode_key_tree
, mode_key_binding
);
552 /* Command to string mapping. */
553 struct mode_key_cmdstr
{
554 enum mode_key_cmd cmd
;
558 /* Named mode key table description. */
559 struct mode_key_table
{
561 const struct mode_key_cmdstr
*cmdstr
;
562 struct mode_key_tree
*tree
;
563 const struct mode_key_entry
*table
; /* default entries */
567 #define MODE_CURSOR 0x1
568 #define MODE_INSERT 0x2
569 #define MODE_KCURSOR 0x4
570 #define MODE_KKEYPAD 0x8 /* set = application, clear = number */
571 #define MODE_WRAP 0x10 /* whether lines wrap */
572 #define MODE_MOUSE_STANDARD 0x20
573 #define MODE_MOUSE_BUTTON 0x40
574 #define MODE_MOUSE_ANY 0x80
575 #define MODE_MOUSE_UTF8 0x100
577 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY)
580 * A single UTF-8 character.
582 * The data member in this must be UTF8_SIZE to allow screen_write_copy to
583 * reinject stored UTF-8 data back into screen_write_cell after combining (ugh
587 u_char data
[UTF8_SIZE
];
596 #if defined(DEBUG) && \
597 ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
598 (defined(__GNUC__) && __GNUC__ >= 3))
599 #define GRID_DEBUG(gd, fmt, ...) log_debug2("%s: (sx=%u, sy=%u, hsize=%u) " \
600 fmt, __func__, (gd)->sx, (gd)->sy, (gd)->hsize, ## __VA_ARGS__)
602 #define GRID_DEBUG(...)
605 /* Grid attributes. */
606 #define GRID_ATTR_BRIGHT 0x1
607 #define GRID_ATTR_DIM 0x2
608 #define GRID_ATTR_UNDERSCORE 0x4
609 #define GRID_ATTR_BLINK 0x8
610 #define GRID_ATTR_REVERSE 0x10
611 #define GRID_ATTR_HIDDEN 0x20
612 #define GRID_ATTR_ITALICS 0x40
613 #define GRID_ATTR_CHARSET 0x80 /* alternative character set */
616 #define GRID_FLAG_FG256 0x1
617 #define GRID_FLAG_BG256 0x2
618 #define GRID_FLAG_PADDING 0x4
619 #define GRID_FLAG_UTF8 0x8
621 /* Grid line flags. */
622 #define GRID_LINE_WRAPPED 0x1
624 /* Grid cell data. */
633 /* Grid cell UTF-8 data. Used instead of data in grid_cell for UTF-8 cells. */
636 u_char data
[UTF8_SIZE
];
642 struct grid_cell
*celldata
;
645 struct grid_utf8
*utf8data
;
650 /* Entire grid of cells. */
653 #define GRID_HISTORY 0x1 /* scroll lines into history */
661 struct grid_line
*linedata
;
664 /* Option data structures. */
665 struct options_entry
{
677 RB_ENTRY(options_entry
) entry
;
681 RB_HEAD(options_tree
, options_entry
) tree
;
682 struct options
*parent
;
692 struct bufferevent
*event
;
694 void (*callbackfn
)(struct job
*);
695 void (*freefn
)(void *);
698 LIST_ENTRY(job
) lentry
;
700 LIST_HEAD(joblist
, job
);
702 /* Screen selection. */
713 struct grid_cell cell
;
716 /* Virtual screen. */
720 struct grid
*grid
; /* grid data */
722 u_int cx
; /* cursor x */
723 u_int cy
; /* cursor y */
725 u_int cstyle
; /* cursor style */
726 char *ccolour
; /* cursor colour string */
728 u_int rupper
; /* scroll region top */
729 u_int rlower
; /* scroll region bottom */
735 struct screen_sel sel
;
738 /* Screen write context. */
739 struct screen_write_ctx
{
740 struct window_pane
*wp
;
745 #define screen_size_x(s) ((s)->grid->sx)
746 #define screen_size_y(s) ((s)->grid->sy)
747 #define screen_hsize(s) ((s)->grid->hsize)
748 #define screen_hlimit(s) ((s)->grid->hlimit)
750 /* Input parser context. */
752 struct window_pane
*wp
;
753 struct screen_write_ctx ctx
;
755 struct grid_cell cell
;
757 struct grid_cell old_cell
;
761 u_char interm_buf
[4];
764 u_char param_buf
[64];
767 u_char input_buf
[256];
770 int param_list
[24]; /* -1 not present */
771 u_int param_list_len
;
773 struct utf8_data utf8data
;
777 #define INPUT_DISCARD 0x1
779 const struct input_state
*state
;
783 * Window mode. Windows can be in several modes and this is used to call the
784 * right function to handle input and output.
790 struct screen
*(*init
)(struct window_pane
*);
791 void (*free
)(struct window_pane
*);
792 void (*resize
)(struct window_pane
*, u_int
, u_int
);
793 void (*key
)(struct window_pane
*, struct session
*, int);
794 void (*mouse
)(struct window_pane
*,
795 struct session
*, struct mouse_event
*);
796 void (*timer
)(struct window_pane
*);
799 /* Child window structure. */
803 struct window
*window
;
804 struct layout_cell
*layout_cell
;
813 #define PANE_REDRAW 0x1
820 char tty
[TTY_NAME_MAX
];
823 struct bufferevent
*event
;
825 struct input_ctx ictx
;
828 struct bufferevent
*pipe_event
;
831 struct screen
*screen
;
834 /* Saved in alternative screen mode. */
837 struct grid
*saved_grid
;
838 struct grid_cell saved_cell
;
840 const struct window_mode
*mode
;
843 TAILQ_ENTRY(window_pane
) entry
;
844 RB_ENTRY(window_pane
) tree_entry
;
846 TAILQ_HEAD(window_panes
, window_pane
);
847 RB_HEAD(window_pane_tree
, window_pane
);
849 /* Window structure. */
852 struct event name_timer
;
853 struct timeval silence_timer
;
855 struct window_pane
*active
;
856 struct window_pane
*last
;
857 struct window_panes panes
;
860 struct layout_cell
*layout_root
;
866 #define WINDOW_BELL 0x1
867 #define WINDOW_ACTIVITY 0x2
868 #define WINDOW_REDRAW 0x4
869 #define WINDOW_SILENCE 0x8
871 struct options options
;
875 ARRAY_DECL(windows
, struct window
*);
877 /* Entry on local window list. */
880 struct window
*window
;
883 struct grid_cell status_cell
;
887 #define WINLINK_BELL 0x1
888 #define WINLINK_ACTIVITY 0x2
889 #define WINLINK_CONTENT 0x4
890 #define WINLINK_SILENCE 0x8
891 #define WINLINK_ALERTFLAGS \
892 (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_CONTENT|WINLINK_SILENCE)
894 RB_ENTRY(winlink
) entry
;
895 TAILQ_ENTRY(winlink
) sentry
;
897 RB_HEAD(winlinks
, winlink
);
898 TAILQ_HEAD(winlink_stack
, winlink
);
900 /* Layout direction. */
907 /* Layout cells queue. */
908 TAILQ_HEAD(layout_cells
, layout_cell
);
912 enum layout_type type
;
914 struct layout_cell
*parent
;
922 struct window_pane
*wp
;
923 struct layout_cells cells
;
925 TAILQ_ENTRY(layout_cell
) entry
;
929 struct paste_buffer
{
933 ARRAY_DECL(paste_stack
, struct paste_buffer
*);
935 /* Environment variable. */
936 struct environ_entry
{
940 RB_ENTRY(environ_entry
) entry
;
942 RB_HEAD(environ
, environ_entry
);
944 /* Client session. */
945 struct session_group
{
946 TAILQ_HEAD(, session
) sessions
;
948 TAILQ_ENTRY(session_group
) entry
;
950 TAILQ_HEAD(session_groups
, session_group
);
958 struct timeval creation_time
;
959 struct timeval activity_time
;
964 struct winlink
*curw
;
965 struct winlink_stack lastw
;
966 struct winlinks windows
;
968 struct options options
;
970 #define SESSION_UNATTACHED 0x1 /* not attached to any clients */
975 struct environ environ
;
981 TAILQ_ENTRY(session
) gentry
;
982 RB_ENTRY(session
) entry
;
984 RB_HEAD(sessions
, session
);
985 ARRAY_DECL(sessionslist
, struct session
*);
987 /* TTY information. */
992 struct tty_key
*left
;
993 struct tty_key
*right
;
995 struct tty_key
*next
;
1002 char acs
[UCHAR_MAX
+ 1][2];
1004 struct tty_code codes
[NTTYCODE
];
1006 #define TERM_256COLOURS 0x1
1007 #define TERM_88COLOURS 0x2
1008 #define TERM_EARLYWRAP 0x4
1011 LIST_ENTRY(tty_term
) entry
;
1013 LIST_HEAD(tty_terms
, tty_term
);
1032 struct tty_term
*term
;
1035 struct bufferevent
*event
;
1041 struct grid_cell cell
;
1043 #define TTY_NOCURSOR 0x1
1044 #define TTY_FREEZE 0x2
1045 #define TTY_ESCAPE 0x4
1046 #define TTY_UTF8 0x8
1047 #define TTY_STARTED 0x10
1048 #define TTY_OPENED 0x20
1049 #define TTY_BACKOFF 0x40
1054 void (*key_callback
)(int, struct mouse_event
*, void *);
1056 struct event key_timer
;
1057 struct tty_key
*key_tree
;
1060 /* TTY command context and function pointer. */
1062 struct window_pane
*wp
;
1064 const struct grid_cell
*cell
;
1065 const struct grid_utf8
*utf8
;
1071 * Cursor and region position before the screen was updated - this is
1072 * where the command should be applied; the values in the screen have
1073 * already been updated.
1081 /* Saved last cell on line. */
1082 struct grid_cell last_cell
;
1083 struct grid_utf8 last_utf8
;
1088 * xterm mouse mode is fairly silly. Buttons are in the bottom two
1089 * bits: 0 button 1; 1 button 2; 2 button 3; 3 buttons released.
1091 * Bit 3 is shift; bit 4 is meta; bit 5 control.
1093 * Bit 6 is added for mouse buttons 4 and 5.
1096 struct mouse_event
{
1102 #define MOUSE_BUTTON 3
1103 #define MOUSE_DRAG 32
1105 #define MOUSE_RESIZE_PANE 128 /* marker for resizing */
1110 /* Saved message entry. */
1111 struct message_entry
{
1116 /* Status output data from a job. */
1121 RB_ENTRY(status_out
) entry
;
1123 RB_HEAD(status_out_tree
, status_out
);
1125 /* Client connection. */
1127 struct imsgbuf ibuf
;
1131 struct timeval creation_time
;
1132 struct timeval activity_time
;
1134 struct environ environ
;
1143 void (*stdin_callback
)(struct client
*, void *);
1144 struct bufferevent
*stdin_event
;
1147 struct bufferevent
*stdout_event
;
1150 struct bufferevent
*stderr_event
;
1152 struct event repeat_timer
;
1154 struct status_out_tree status_old
;
1155 struct status_out_tree status_new
;
1156 struct timeval status_timer
;
1157 struct screen status
;
1159 #define CLIENT_TERMINAL 0x1
1160 #define CLIENT_PREFIX 0x2
1161 #define CLIENT_EXIT 0x4
1162 #define CLIENT_REDRAW 0x8
1163 #define CLIENT_STATUS 0x10
1164 #define CLIENT_REPEAT 0x20 /* allow command to repeat within repeat time */
1165 #define CLIENT_SUSPENDED 0x40
1166 #define CLIENT_BAD 0x80
1167 #define CLIENT_IDENTIFY 0x100
1168 #define CLIENT_DEAD 0x200
1169 #define CLIENT_BORDERS 0x400
1170 #define CLIENT_READONLY 0x800
1171 #define CLIENT_REDRAWWINDOW 0x1000
1174 struct event identify_timer
;
1176 char *message_string
;
1177 struct event message_timer
;
1178 ARRAY_DECL(, struct message_entry
) message_log
;
1180 char *prompt_string
;
1181 char *prompt_buffer
;
1182 size_t prompt_index
;
1183 int (*prompt_callbackfn
)(void *, const char *);
1184 void (*prompt_freefn
)(void *);
1186 u_int prompt_hindex
;
1188 #define PROMPT_SINGLE 0x1
1191 struct mode_key_data prompt_mdata
;
1193 struct session
*session
;
1194 struct session
*last_session
;
1196 struct mouse_event last_mouse
;
1200 ARRAY_DECL(clients
, struct client
*);
1202 /* Parsed arguments. */
1205 char *values
[SCHAR_MAX
]; /* XXX This is awfully big. */
1211 /* Key/command line command. */
1214 * curclient is the client where this command was executed if inside
1215 * tmux. This is NULL if the command came from the command-line.
1217 * cmdclient is the client which sent the MSG_COMMAND to the server, if
1218 * any. This is NULL unless the command came from the command-line.
1220 * cmdclient and curclient may both be NULL if the command is in the
1221 * configuration file.
1223 struct client
*curclient
;
1224 struct client
*cmdclient
;
1226 struct msg_command_data
*msgdata
;
1228 /* gcc2 doesn't understand attributes on function pointers... */
1229 #if defined(__GNUC__) && __GNUC__ >= 3
1230 void printflike2 (*print
)(struct cmd_ctx
*, const char *, ...);
1231 void printflike2 (*info
)(struct cmd_ctx
*, const char *, ...);
1232 void printflike2 (*error
)(struct cmd_ctx
*, const char *, ...);
1234 void (*print
)(struct cmd_ctx
*, const char *, ...);
1235 void (*info
)(struct cmd_ctx
*, const char *, ...);
1236 void (*error
)(struct cmd_ctx
*, const char *, ...);
1241 const struct cmd_entry
*entry
;
1244 TAILQ_ENTRY(cmd
) qentry
;
1248 TAILQ_HEAD(, cmd
) list
;
1255 const char *args_template
;
1261 #define CMD_STARTSERVER 0x1
1262 #define CMD_CANTNEST 0x2
1263 #define CMD_SENDENVIRON 0x4
1264 #define CMD_READONLY 0x8
1267 void (*key_binding
)(struct cmd
*, int);
1268 int (*check
)(struct args
*);
1269 int (*exec
)(struct cmd
*, struct cmd_ctx
*);
1273 struct key_binding
{
1275 struct cmd_list
*cmdlist
;
1278 RB_ENTRY(key_binding
) entry
;
1280 RB_HEAD(key_bindings
, key_binding
);
1283 * Option table entries. The option table is the user-visible part of the
1284 * option, as opposed to the internal options (struct option) which are just
1287 enum options_table_type
{
1288 OPTIONS_TABLE_STRING
,
1289 OPTIONS_TABLE_NUMBER
,
1291 OPTIONS_TABLE_COLOUR
,
1292 OPTIONS_TABLE_ATTRIBUTES
,
1294 OPTIONS_TABLE_CHOICE
1297 struct options_table_entry
{
1299 enum options_table_type type
;
1303 const char **choices
;
1305 const char *default_str
;
1306 long long default_num
;
1309 /* Tree of format entries. */
1310 struct format_entry
{
1314 RB_ENTRY(format_entry
) entry
;
1316 RB_HEAD(format_tree
, format_entry
);
1318 /* List of configuration causes. */
1319 ARRAY_DECL(causelist
, char *);
1321 /* Common command usages. */
1322 #define CMD_TARGET_PANE_USAGE "[-t target-pane]"
1323 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]"
1324 #define CMD_TARGET_SESSION_USAGE "[-t target-session]"
1325 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]"
1326 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]"
1327 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]"
1328 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]"
1329 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]"
1330 #define CMD_BUFFER_USAGE "[-b buffer-index]"
1333 extern struct options global_options
;
1334 extern struct options global_s_options
;
1335 extern struct options global_w_options
;
1336 extern struct environ global_environ
;
1337 extern struct event_base
*ev_base
;
1338 extern char *cfg_file
;
1339 extern char *shell_cmd
;
1340 extern int debug_level
;
1341 extern time_t start_time
;
1342 extern char socket_path
[MAXPATHLEN
];
1343 extern int login_shell
;
1344 extern char *environ_path
;
1345 extern pid_t environ_pid
;
1346 extern int environ_idx
;
1347 void logfile(const char *);
1348 const char *getshell(void);
1349 int checkshell(const char *);
1350 int areshell(const char *);
1351 const char* get_full_path(const char *, const char *);
1352 void setblocking(int, int);
1353 __dead
void shell_exec(const char *, const char *);
1356 extern int cfg_finished
;
1357 extern struct causelist cfg_causes
;
1358 void printflike2
cfg_add_cause(struct causelist
*, const char *, ...);
1359 int load_cfg(const char *, struct cmd_ctx
*, struct causelist
*);
1362 int format_cmp(struct format_entry
*, struct format_entry
*);
1363 RB_PROTOTYPE(format_tree
, format_entry
, entry
, format_cmp
);
1364 struct format_tree
*format_create(void);
1365 void format_free(struct format_tree
*);
1367 struct format_tree
*, const char *, const char *, ...);
1368 const char *format_find(struct format_tree
*, const char *);
1369 char *format_expand(struct format_tree
*, const char *);
1370 void format_session(struct format_tree
*, struct session
*);
1371 void format_client(struct format_tree
*, struct client
*);
1372 void format_winlink(
1373 struct format_tree
*, struct session
*, struct winlink
*);
1374 void format_window_pane(struct format_tree
*, struct window_pane
*);
1377 extern const struct mode_key_table mode_key_tables
[];
1378 extern struct mode_key_tree mode_key_tree_vi_edit
;
1379 extern struct mode_key_tree mode_key_tree_vi_choice
;
1380 extern struct mode_key_tree mode_key_tree_vi_copy
;
1381 extern struct mode_key_tree mode_key_tree_emacs_edit
;
1382 extern struct mode_key_tree mode_key_tree_emacs_choice
;
1383 extern struct mode_key_tree mode_key_tree_emacs_copy
;
1384 int mode_key_cmp(struct mode_key_binding
*, struct mode_key_binding
*);
1385 RB_PROTOTYPE(mode_key_tree
, mode_key_binding
, entry
, mode_key_cmp
);
1386 const char *mode_key_tostring(const struct mode_key_cmdstr
*,
1388 enum mode_key_cmd
mode_key_fromstring(const struct mode_key_cmdstr
*,
1390 const struct mode_key_table
*mode_key_findtable(const char *);
1391 void mode_key_init_trees(void);
1392 void mode_key_init(struct mode_key_data
*, struct mode_key_tree
*);
1393 enum mode_key_cmd
mode_key_lookup(struct mode_key_data
*, int);
1396 int options_cmp(struct options_entry
*, struct options_entry
*);
1397 RB_PROTOTYPE(options_tree
, options_entry
, entry
, options_cmp
);
1398 void options_init(struct options
*, struct options
*);
1399 void options_free(struct options
*);
1400 struct options_entry
*options_find1(struct options
*, const char *);
1401 struct options_entry
*options_find(struct options
*, const char *);
1402 void options_remove(struct options
*, const char *);
1403 struct options_entry
*printflike3
options_set_string(
1404 struct options
*, const char *, const char *, ...);
1405 char *options_get_string(struct options
*, const char *);
1406 struct options_entry
*options_set_number(
1407 struct options
*, const char *, long long);
1408 long long options_get_number(struct options
*, const char *);
1410 /* options-table.c */
1411 extern const struct options_table_entry server_options_table
[];
1412 extern const struct options_table_entry session_options_table
[];
1413 extern const struct options_table_entry window_options_table
[];
1414 void options_table_populate_tree(
1415 const struct options_table_entry
*, struct options
*);
1416 const char *options_table_print_entry(
1417 const struct options_table_entry
*, struct options_entry
*);
1420 extern struct joblist all_jobs
;
1421 struct job
*job_run(
1422 const char *, void (*)(struct job
*), void (*)(void *), void *);
1423 void job_free(struct job
*);
1424 void job_died(struct job
*, int);
1427 int environ_cmp(struct environ_entry
*, struct environ_entry
*);
1428 RB_PROTOTYPE(environ
, environ_entry
, entry
, environ_cmp
);
1429 void environ_init(struct environ
*);
1430 void environ_free(struct environ
*);
1431 void environ_copy(struct environ
*, struct environ
*);
1432 struct environ_entry
*environ_find(struct environ
*, const char *);
1433 void environ_set(struct environ
*, const char *, const char *);
1434 void environ_put(struct environ
*, const char *);
1435 void environ_unset(struct environ
*, const char *);
1436 void environ_update(const char *, struct environ
*, struct environ
*);
1437 void environ_push(struct environ
*);
1440 void tty_raw(struct tty
*, const char *);
1441 void tty_attributes(struct tty
*, const struct grid_cell
*);
1442 void tty_reset(struct tty
*);
1443 void tty_region_pane(struct tty
*, const struct tty_ctx
*, u_int
, u_int
);
1444 void tty_region(struct tty
*, u_int
, u_int
);
1445 void tty_cursor_pane(struct tty
*, const struct tty_ctx
*, u_int
, u_int
);
1446 void tty_cursor(struct tty
*, u_int
, u_int
);
1447 void tty_putcode(struct tty
*, enum tty_code_code
);
1448 void tty_putcode1(struct tty
*, enum tty_code_code
, int);
1449 void tty_putcode2(struct tty
*, enum tty_code_code
, int, int);
1450 void tty_putcode_ptr1(struct tty
*, enum tty_code_code
, const void *);
1451 void tty_putcode_ptr2(struct tty
*, enum tty_code_code
, const void *, const void *);
1452 void tty_puts(struct tty
*, const char *);
1453 void tty_putc(struct tty
*, u_char
);
1454 void tty_pututf8(struct tty
*, const struct grid_utf8
*);
1455 void tty_init(struct tty
*, int, char *);
1456 int tty_resize(struct tty
*);
1457 void tty_start_tty(struct tty
*);
1458 void tty_stop_tty(struct tty
*);
1459 void tty_set_title(struct tty
*, const char *);
1460 void tty_update_mode(struct tty
*, int, struct screen
*);
1461 void tty_force_cursor_colour(struct tty
*, const char *);
1462 void tty_draw_line(struct tty
*, struct screen
*, u_int
, u_int
, u_int
);
1463 int tty_open(struct tty
*, const char *, char **);
1464 void tty_close(struct tty
*);
1465 void tty_free(struct tty
*);
1466 void tty_write(void (*)(
1467 struct tty
*, const struct tty_ctx
*), const struct tty_ctx
*);
1468 void tty_cmd_alignmenttest(struct tty
*, const struct tty_ctx
*);
1469 void tty_cmd_cell(struct tty
*, const struct tty_ctx
*);
1470 void tty_cmd_clearendofline(struct tty
*, const struct tty_ctx
*);
1471 void tty_cmd_clearendofscreen(struct tty
*, const struct tty_ctx
*);
1472 void tty_cmd_clearline(struct tty
*, const struct tty_ctx
*);
1473 void tty_cmd_clearscreen(struct tty
*, const struct tty_ctx
*);
1474 void tty_cmd_clearstartofline(struct tty
*, const struct tty_ctx
*);
1475 void tty_cmd_clearstartofscreen(struct tty
*, const struct tty_ctx
*);
1476 void tty_cmd_deletecharacter(struct tty
*, const struct tty_ctx
*);
1477 void tty_cmd_deleteline(struct tty
*, const struct tty_ctx
*);
1478 void tty_cmd_erasecharacter(struct tty
*, const struct tty_ctx
*);
1479 void tty_cmd_insertcharacter(struct tty
*, const struct tty_ctx
*);
1480 void tty_cmd_insertline(struct tty
*, const struct tty_ctx
*);
1481 void tty_cmd_linefeed(struct tty
*, const struct tty_ctx
*);
1482 void tty_cmd_utf8character(struct tty
*, const struct tty_ctx
*);
1483 void tty_cmd_reverseindex(struct tty
*, const struct tty_ctx
*);
1484 void tty_cmd_setselection(struct tty
*, const struct tty_ctx
*);
1485 void tty_cmd_rawstring(struct tty
*, const struct tty_ctx
*);
1486 void tty_bell(struct tty
*);
1489 extern struct tty_terms tty_terms
;
1490 extern const struct tty_term_code_entry tty_term_codes
[NTTYCODE
];
1491 struct tty_term
*tty_term_find(char *, int, const char *, char **);
1492 void tty_term_free(struct tty_term
*);
1493 int tty_term_has(struct tty_term
*, enum tty_code_code
);
1494 const char *tty_term_string(struct tty_term
*, enum tty_code_code
);
1495 const char *tty_term_string1(struct tty_term
*, enum tty_code_code
, int);
1496 const char *tty_term_string2(
1497 struct tty_term
*, enum tty_code_code
, int, int);
1498 const char *tty_term_ptr1(
1499 struct tty_term
*, enum tty_code_code
, const void *);
1500 const char *tty_term_ptr2(
1501 struct tty_term
*, enum tty_code_code
, const void *, const void *);
1502 int tty_term_number(struct tty_term
*, enum tty_code_code
);
1503 int tty_term_flag(struct tty_term
*, enum tty_code_code
);
1506 const char *tty_acs_get(struct tty
*, u_char
);
1509 void tty_keys_init(struct tty
*);
1510 void tty_keys_free(struct tty
*);
1511 int tty_keys_next(struct tty
*);
1514 struct paste_buffer
*paste_walk_stack(struct paste_stack
*, u_int
*);
1515 struct paste_buffer
*paste_get_top(struct paste_stack
*);
1516 struct paste_buffer
*paste_get_index(struct paste_stack
*, u_int
);
1517 int paste_free_top(struct paste_stack
*);
1518 int paste_free_index(struct paste_stack
*, u_int
);
1519 void paste_add(struct paste_stack
*, char *, size_t, u_int
);
1520 int paste_replace(struct paste_stack
*, u_int
, char *, size_t);
1521 char *paste_print(struct paste_buffer
*, size_t);
1524 extern const char clock_table
[14][5][5];
1525 void clock_draw(struct screen_write_ctx
*, int, int);
1528 struct args
*args_create(int, ...);
1529 struct args
*args_parse(const char *, int, char **);
1530 void args_free(struct args
*);
1531 size_t args_print(struct args
*, char *, size_t);
1532 int args_has(struct args
*, u_char
);
1533 void args_set(struct args
*, u_char
, const char *);
1534 const char *args_get(struct args
*, u_char
);
1535 long long args_strtonum(
1536 struct args
*, u_char
, long long, long long, char **);
1539 int cmd_pack_argv(int, char **, char *, size_t);
1540 int cmd_unpack_argv(char *, size_t, int, char ***);
1541 char **cmd_copy_argv(int, char *const *);
1542 void cmd_free_argv(int, char **);
1543 struct cmd
*cmd_parse(int, char **, char **);
1544 int cmd_exec(struct cmd
*, struct cmd_ctx
*);
1545 void cmd_free(struct cmd
*);
1546 size_t cmd_print(struct cmd
*, char *, size_t);
1547 struct session
*cmd_current_session(struct cmd_ctx
*, int);
1548 struct client
*cmd_current_client(struct cmd_ctx
*);
1549 struct client
*cmd_find_client(struct cmd_ctx
*, const char *);
1550 struct session
*cmd_find_session(struct cmd_ctx
*, const char *, int);
1551 struct winlink
*cmd_find_window(
1552 struct cmd_ctx
*, const char *, struct session
**);
1554 struct cmd_ctx
*, const char *, struct session
**);
1555 struct winlink
*cmd_find_pane(struct cmd_ctx
*,
1556 const char *, struct session
**, struct window_pane
**);
1557 char *cmd_template_replace(char *, const char *, int);
1558 const char *cmd_get_default_path(struct cmd_ctx
*ctx
);
1559 extern const struct cmd_entry
*cmd_table
[];
1560 extern const struct cmd_entry cmd_attach_session_entry
;
1561 extern const struct cmd_entry cmd_bind_key_entry
;
1562 extern const struct cmd_entry cmd_break_pane_entry
;
1563 extern const struct cmd_entry cmd_capture_pane_entry
;
1564 extern const struct cmd_entry cmd_choose_buffer_entry
;
1565 extern const struct cmd_entry cmd_choose_client_entry
;
1566 extern const struct cmd_entry cmd_choose_session_entry
;
1567 extern const struct cmd_entry cmd_choose_window_entry
;
1568 extern const struct cmd_entry cmd_clear_history_entry
;
1569 extern const struct cmd_entry cmd_clock_mode_entry
;
1570 extern const struct cmd_entry cmd_command_prompt_entry
;
1571 extern const struct cmd_entry cmd_confirm_before_entry
;
1572 extern const struct cmd_entry cmd_copy_mode_entry
;
1573 extern const struct cmd_entry cmd_delete_buffer_entry
;
1574 extern const struct cmd_entry cmd_detach_client_entry
;
1575 extern const struct cmd_entry cmd_display_message_entry
;
1576 extern const struct cmd_entry cmd_display_panes_entry
;
1577 extern const struct cmd_entry cmd_down_pane_entry
;
1578 extern const struct cmd_entry cmd_find_window_entry
;
1579 extern const struct cmd_entry cmd_has_session_entry
;
1580 extern const struct cmd_entry cmd_if_shell_entry
;
1581 extern const struct cmd_entry cmd_join_pane_entry
;
1582 extern const struct cmd_entry cmd_kill_pane_entry
;
1583 extern const struct cmd_entry cmd_kill_server_entry
;
1584 extern const struct cmd_entry cmd_kill_session_entry
;
1585 extern const struct cmd_entry cmd_kill_window_entry
;
1586 extern const struct cmd_entry cmd_last_pane_entry
;
1587 extern const struct cmd_entry cmd_last_window_entry
;
1588 extern const struct cmd_entry cmd_link_window_entry
;
1589 extern const struct cmd_entry cmd_list_buffers_entry
;
1590 extern const struct cmd_entry cmd_list_clients_entry
;
1591 extern const struct cmd_entry cmd_list_commands_entry
;
1592 extern const struct cmd_entry cmd_list_keys_entry
;
1593 extern const struct cmd_entry cmd_list_panes_entry
;
1594 extern const struct cmd_entry cmd_list_sessions_entry
;
1595 extern const struct cmd_entry cmd_list_windows_entry
;
1596 extern const struct cmd_entry cmd_load_buffer_entry
;
1597 extern const struct cmd_entry cmd_lock_client_entry
;
1598 extern const struct cmd_entry cmd_lock_server_entry
;
1599 extern const struct cmd_entry cmd_lock_session_entry
;
1600 extern const struct cmd_entry cmd_move_window_entry
;
1601 extern const struct cmd_entry cmd_new_session_entry
;
1602 extern const struct cmd_entry cmd_new_window_entry
;
1603 extern const struct cmd_entry cmd_next_layout_entry
;
1604 extern const struct cmd_entry cmd_next_window_entry
;
1605 extern const struct cmd_entry cmd_paste_buffer_entry
;
1606 extern const struct cmd_entry cmd_pipe_pane_entry
;
1607 extern const struct cmd_entry cmd_previous_layout_entry
;
1608 extern const struct cmd_entry cmd_previous_window_entry
;
1609 extern const struct cmd_entry cmd_refresh_client_entry
;
1610 extern const struct cmd_entry cmd_rename_session_entry
;
1611 extern const struct cmd_entry cmd_rename_window_entry
;
1612 extern const struct cmd_entry cmd_resize_pane_entry
;
1613 extern const struct cmd_entry cmd_respawn_pane_entry
;
1614 extern const struct cmd_entry cmd_respawn_window_entry
;
1615 extern const struct cmd_entry cmd_rotate_window_entry
;
1616 extern const struct cmd_entry cmd_run_shell_entry
;
1617 extern const struct cmd_entry cmd_save_buffer_entry
;
1618 extern const struct cmd_entry cmd_select_layout_entry
;
1619 extern const struct cmd_entry cmd_select_pane_entry
;
1620 extern const struct cmd_entry cmd_select_window_entry
;
1621 extern const struct cmd_entry cmd_send_keys_entry
;
1622 extern const struct cmd_entry cmd_send_prefix_entry
;
1623 extern const struct cmd_entry cmd_server_info_entry
;
1624 extern const struct cmd_entry cmd_set_buffer_entry
;
1625 extern const struct cmd_entry cmd_set_environment_entry
;
1626 extern const struct cmd_entry cmd_set_option_entry
;
1627 extern const struct cmd_entry cmd_set_window_option_entry
;
1628 extern const struct cmd_entry cmd_show_buffer_entry
;
1629 extern const struct cmd_entry cmd_show_environment_entry
;
1630 extern const struct cmd_entry cmd_show_messages_entry
;
1631 extern const struct cmd_entry cmd_show_options_entry
;
1632 extern const struct cmd_entry cmd_show_window_options_entry
;
1633 extern const struct cmd_entry cmd_source_file_entry
;
1634 extern const struct cmd_entry cmd_split_window_entry
;
1635 extern const struct cmd_entry cmd_start_server_entry
;
1636 extern const struct cmd_entry cmd_suspend_client_entry
;
1637 extern const struct cmd_entry cmd_swap_pane_entry
;
1638 extern const struct cmd_entry cmd_swap_window_entry
;
1639 extern const struct cmd_entry cmd_switch_client_entry
;
1640 extern const struct cmd_entry cmd_unbind_key_entry
;
1641 extern const struct cmd_entry cmd_unlink_window_entry
;
1642 extern const struct cmd_entry cmd_up_pane_entry
;
1645 struct cmd_list
*cmd_list_parse(int, char **, char **);
1646 int cmd_list_exec(struct cmd_list
*, struct cmd_ctx
*);
1647 void cmd_list_free(struct cmd_list
*);
1648 size_t cmd_list_print(struct cmd_list
*, char *, size_t);
1651 int cmd_string_parse(const char *, struct cmd_list
**, char **);
1654 int client_main(int, char **, int);
1656 /* key-bindings.c */
1657 extern struct key_bindings key_bindings
;
1658 int key_bindings_cmp(struct key_binding
*, struct key_binding
*);
1659 RB_PROTOTYPE(key_bindings
, key_binding
, entry
, key_bindings_cmp
);
1660 struct key_binding
*key_bindings_lookup(int);
1661 void key_bindings_add(int, int, struct cmd_list
*);
1662 void key_bindings_remove(int);
1663 void key_bindings_clean(void);
1664 void key_bindings_init(void);
1665 void key_bindings_dispatch(struct key_binding
*, struct client
*);
1666 void printflike2
key_bindings_error(struct cmd_ctx
*, const char *, ...);
1667 void printflike2
key_bindings_print(struct cmd_ctx
*, const char *, ...);
1668 void printflike2
key_bindings_info(struct cmd_ctx
*, const char *, ...);
1671 int key_string_lookup_string(const char *);
1672 const char *key_string_lookup_key(int);
1675 extern struct clients clients
;
1676 extern struct clients dead_clients
;
1677 extern struct paste_stack global_buffers
;
1678 int server_start(void);
1679 void server_update_socket(void);
1681 /* server-client.c */
1682 void server_client_create(int);
1683 void server_client_lost(struct client
*);
1684 void server_client_callback(int, short, void *);
1685 void server_client_status_timer(void);
1686 void server_client_loop(void);
1688 /* server-window.c */
1689 void server_window_loop(void);
1692 void server_fill_environ(struct session
*, struct environ
*);
1693 void server_write_client(
1694 struct client
*, enum msgtype
, const void *, size_t);
1695 void server_write_session(
1696 struct session
*, enum msgtype
, const void *, size_t);
1697 void server_redraw_client(struct client
*);
1698 void server_status_client(struct client
*);
1699 void server_redraw_session(struct session
*);
1700 void server_redraw_session_group(struct session
*);
1701 void server_status_session(struct session
*);
1702 void server_status_session_group(struct session
*);
1703 void server_redraw_window(struct window
*);
1704 void server_redraw_window_borders(struct window
*);
1705 void server_status_window(struct window
*);
1706 void server_lock(void);
1707 void server_lock_session(struct session
*);
1708 void server_lock_client(struct client
*);
1709 int server_unlock(const char *);
1710 void server_kill_window(struct window
*);
1711 int server_link_window(struct session
*,
1712 struct winlink
*, struct session
*, int, int, int, char **);
1713 void server_unlink_window(struct session
*, struct winlink
*);
1714 void server_destroy_pane(struct window_pane
*);
1715 void server_destroy_session_group(struct session
*);
1716 void server_destroy_session(struct session
*);
1717 void server_check_unattached (void);
1718 void server_set_identify(struct client
*);
1719 void server_clear_identify(struct client
*);
1720 void server_update_event(struct client
*);
1723 int status_out_cmp(struct status_out
*, struct status_out
*);
1724 RB_PROTOTYPE(status_out_tree
, status_out
, entry
, status_out_cmp
);
1725 void status_free_jobs(struct status_out_tree
*);
1726 void status_update_jobs(struct client
*);
1727 void status_set_window_at(struct client
*, u_int
);
1728 int status_redraw(struct client
*);
1729 char *status_replace(struct client
*, struct session
*,
1730 struct winlink
*, struct window_pane
*, const char *, time_t, int);
1731 void printflike2
status_message_set(struct client
*, const char *, ...);
1732 void status_message_clear(struct client
*);
1733 int status_message_redraw(struct client
*);
1734 void status_prompt_set(struct client
*, const char *, const char *,
1735 int (*)(void *, const char *), void (*)(void *), void *, int);
1736 void status_prompt_clear(struct client
*);
1737 int status_prompt_redraw(struct client
*);
1738 void status_prompt_key(struct client
*, int);
1739 void status_prompt_update(struct client
*, const char *, const char *);
1742 void recalculate_sizes(void);
1745 void input_init(struct window_pane
*);
1746 void input_free(struct window_pane
*);
1747 void input_parse(struct window_pane
*);
1750 void input_key(struct window_pane
*, int);
1751 void input_mouse(struct window_pane
*, struct mouse_event
*);
1754 char *xterm_keys_lookup(int);
1755 int xterm_keys_find(const char *, size_t, size_t *, int *);
1758 void colour_set_fg(struct grid_cell
*, int);
1759 void colour_set_bg(struct grid_cell
*, int);
1760 const char *colour_tostring(int);
1761 int colour_fromstring(const char *);
1762 u_char
colour_256to16(u_char
);
1763 u_char
colour_256to88(u_char
);
1766 const char *attributes_tostring(u_char
);
1767 int attributes_fromstring(const char *);
1770 extern const struct grid_cell grid_default_cell
;
1771 struct grid
*grid_create(u_int
, u_int
, u_int
);
1772 void grid_destroy(struct grid
*);
1773 int grid_compare(struct grid
*, struct grid
*);
1774 void grid_collect_history(struct grid
*);
1775 void grid_scroll_history(struct grid
*);
1776 void grid_scroll_history_region(struct grid
*, u_int
, u_int
);
1777 void grid_expand_line(struct grid
*, u_int
, u_int
);
1778 void grid_expand_line_utf8(struct grid
*, u_int
, u_int
);
1779 const struct grid_cell
*grid_peek_cell(struct grid
*, u_int
, u_int
);
1780 struct grid_cell
*grid_get_cell(struct grid
*, u_int
, u_int
);
1781 void grid_set_cell(struct grid
*, u_int
, u_int
, const struct grid_cell
*);
1782 const struct grid_utf8
*grid_peek_utf8(struct grid
*, u_int
, u_int
);
1783 struct grid_utf8
*grid_get_utf8(struct grid
*, u_int
, u_int
);
1784 void grid_set_utf8(struct grid
*, u_int
, u_int
, const struct grid_utf8
*);
1785 void grid_clear(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1786 void grid_clear_lines(struct grid
*, u_int
, u_int
);
1787 void grid_move_lines(struct grid
*, u_int
, u_int
, u_int
);
1788 void grid_move_cells(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1789 char *grid_string_cells(struct grid
*, u_int
, u_int
, u_int
);
1790 void grid_duplicate_lines(
1791 struct grid
*, u_int
, struct grid
*, u_int
, u_int
);
1794 size_t grid_utf8_size(const struct grid_utf8
*);
1795 size_t grid_utf8_copy(const struct grid_utf8
*, char *, size_t);
1796 void grid_utf8_set(struct grid_utf8
*, const struct utf8_data
*);
1797 int grid_utf8_append(struct grid_utf8
*, const struct utf8_data
*);
1798 int grid_utf8_compare(const struct grid_utf8
*, const struct grid_utf8
*);
1801 const struct grid_cell
*grid_view_peek_cell(struct grid
*, u_int
, u_int
);
1802 struct grid_cell
*grid_view_get_cell(struct grid
*, u_int
, u_int
);
1803 void grid_view_set_cell(
1804 struct grid
*, u_int
, u_int
, const struct grid_cell
*);
1805 const struct grid_utf8
*grid_view_peek_utf8(struct grid
*, u_int
, u_int
);
1806 struct grid_utf8
*grid_view_get_utf8(struct grid
*, u_int
, u_int
);
1807 void grid_view_set_utf8(
1808 struct grid
*, u_int
, u_int
, const struct grid_utf8
*);
1809 void grid_view_clear_history(struct grid
*);
1810 void grid_view_clear(struct grid
*, u_int
, u_int
, u_int
, u_int
);
1811 void grid_view_scroll_region_up(struct grid
*, u_int
, u_int
);
1812 void grid_view_scroll_region_down(struct grid
*, u_int
, u_int
);
1813 void grid_view_insert_lines(struct grid
*, u_int
, u_int
);
1814 void grid_view_insert_lines_region(struct grid
*, u_int
, u_int
, u_int
);
1815 void grid_view_delete_lines(struct grid
*, u_int
, u_int
);
1816 void grid_view_delete_lines_region(struct grid
*, u_int
, u_int
, u_int
);
1817 void grid_view_insert_cells(struct grid
*, u_int
, u_int
, u_int
);
1818 void grid_view_delete_cells(struct grid
*, u_int
, u_int
, u_int
);
1819 char *grid_view_string_cells(struct grid
*, u_int
, u_int
, u_int
);
1821 /* screen-write.c */
1822 void screen_write_start(
1823 struct screen_write_ctx
*, struct window_pane
*, struct screen
*);
1824 void screen_write_stop(struct screen_write_ctx
*);
1825 void screen_write_reset(struct screen_write_ctx
*);
1826 size_t printflike2
screen_write_cstrlen(int, const char *, ...);
1827 void printflike5
screen_write_cnputs(struct screen_write_ctx
*,
1828 ssize_t
, struct grid_cell
*, int, const char *, ...);
1829 size_t printflike2
screen_write_strlen(int, const char *, ...);
1830 void printflike3
screen_write_puts(struct screen_write_ctx
*,
1831 struct grid_cell
*, const char *, ...);
1832 void printflike5
screen_write_nputs(struct screen_write_ctx
*,
1833 ssize_t
, struct grid_cell
*, int, const char *, ...);
1834 void screen_write_vnputs(struct screen_write_ctx
*,
1835 ssize_t
, struct grid_cell
*, int, const char *, va_list);
1836 void screen_write_parsestyle(
1837 struct grid_cell
*, struct grid_cell
*, const char *);
1838 void screen_write_putc(
1839 struct screen_write_ctx
*, struct grid_cell
*, u_char
);
1840 void screen_write_copy(struct screen_write_ctx
*,
1841 struct screen
*, u_int
, u_int
, u_int
, u_int
);
1842 void screen_write_backspace(struct screen_write_ctx
*);
1843 void screen_write_cursorup(struct screen_write_ctx
*, u_int
);
1844 void screen_write_cursordown(struct screen_write_ctx
*, u_int
);
1845 void screen_write_cursorright(struct screen_write_ctx
*, u_int
);
1846 void screen_write_cursorleft(struct screen_write_ctx
*, u_int
);
1847 void screen_write_alignmenttest(struct screen_write_ctx
*);
1848 void screen_write_insertcharacter(struct screen_write_ctx
*, u_int
);
1849 void screen_write_deletecharacter(struct screen_write_ctx
*, u_int
);
1850 void screen_write_insertline(struct screen_write_ctx
*, u_int
);
1851 void screen_write_deleteline(struct screen_write_ctx
*, u_int
);
1852 void screen_write_clearline(struct screen_write_ctx
*);
1853 void screen_write_clearendofline(struct screen_write_ctx
*);
1854 void screen_write_clearstartofline(struct screen_write_ctx
*);
1855 void screen_write_cursormove(struct screen_write_ctx
*, u_int
, u_int
);
1856 void screen_write_cursormode(struct screen_write_ctx
*, int);
1857 void screen_write_reverseindex(struct screen_write_ctx
*);
1858 void screen_write_scrollregion(struct screen_write_ctx
*, u_int
, u_int
);
1859 void screen_write_insertmode(struct screen_write_ctx
*, int);
1860 void screen_write_utf8mousemode(struct screen_write_ctx
*, int);
1861 void screen_write_mousemode_on(struct screen_write_ctx
*, int);
1862 void screen_write_mousemode_off(struct screen_write_ctx
*);
1863 void screen_write_linefeed(struct screen_write_ctx
*, int);
1864 void screen_write_linefeedscreen(struct screen_write_ctx
*, int);
1865 void screen_write_carriagereturn(struct screen_write_ctx
*);
1866 void screen_write_kcursormode(struct screen_write_ctx
*, int);
1867 void screen_write_kkeypadmode(struct screen_write_ctx
*, int);
1868 void screen_write_clearendofscreen(struct screen_write_ctx
*);
1869 void screen_write_clearstartofscreen(struct screen_write_ctx
*);
1870 void screen_write_clearscreen(struct screen_write_ctx
*);
1871 void screen_write_clearhistory(struct screen_write_ctx
*);
1872 void screen_write_cell(struct screen_write_ctx
*,
1873 const struct grid_cell
*, const struct utf8_data
*);
1874 void screen_write_setselection(struct screen_write_ctx
*, u_char
*, u_int
);
1875 void screen_write_rawstring(struct screen_write_ctx
*, u_char
*, u_int
);
1877 /* screen-redraw.c */
1878 void screen_redraw_screen(struct client
*, int, int);
1879 void screen_redraw_pane(struct client
*, struct window_pane
*);
1882 void screen_init(struct screen
*, u_int
, u_int
, u_int
);
1883 void screen_reinit(struct screen
*);
1884 void screen_free(struct screen
*);
1885 void screen_reset_tabs(struct screen
*);
1886 void screen_set_cursor_style(struct screen
*, u_int
);
1887 void screen_set_cursor_colour(struct screen
*, const char *);
1888 void screen_set_title(struct screen
*, const char *);
1889 void screen_resize(struct screen
*, u_int
, u_int
);
1890 void screen_set_selection(struct screen
*,
1891 u_int
, u_int
, u_int
, u_int
, u_int
, struct grid_cell
*);
1892 void screen_clear_selection(struct screen
*);
1893 int screen_check_selection(struct screen
*, u_int
, u_int
);
1896 extern struct windows windows
;
1897 extern struct window_pane_tree all_window_panes
;
1898 int winlink_cmp(struct winlink
*, struct winlink
*);
1899 RB_PROTOTYPE(winlinks
, winlink
, entry
, winlink_cmp
);
1900 int window_pane_cmp(struct window_pane
*, struct window_pane
*);
1901 RB_PROTOTYPE(window_pane_tree
, window_pane
, tree_entry
, window_pane_cmp
);
1902 struct winlink
*winlink_find_by_index(struct winlinks
*, int);
1903 struct winlink
*winlink_find_by_window(struct winlinks
*, struct window
*);
1904 int winlink_next_index(struct winlinks
*, int);
1905 u_int
winlink_count(struct winlinks
*);
1906 struct winlink
*winlink_add(struct winlinks
*, int);
1907 void winlink_set_window(struct winlink
*, struct window
*);
1908 void winlink_remove(struct winlinks
*, struct winlink
*);
1909 struct winlink
*winlink_next(struct winlink
*);
1910 struct winlink
*winlink_previous(struct winlink
*);
1911 struct winlink
*winlink_next_by_number(struct winlink
*, struct session
*,
1913 struct winlink
*winlink_previous_by_number(struct winlink
*, struct session
*,
1915 void winlink_stack_push(struct winlink_stack
*, struct winlink
*);
1916 void winlink_stack_remove(struct winlink_stack
*, struct winlink
*);
1917 int window_index(struct window
*, u_int
*);
1918 struct window
*window_create1(u_int
, u_int
);
1919 struct window
*window_create(const char *, const char *, const char *,
1920 const char *, struct environ
*, struct termios
*,
1921 u_int
, u_int
, u_int
, char **);
1922 void window_destroy(struct window
*);
1923 struct window_pane
*window_get_active_at(struct window
*, u_int
, u_int
);
1924 void window_set_active_at(struct window
*, u_int
, u_int
);
1925 struct window_pane
*window_find_string(struct window
*, const char *);
1926 void window_set_active_pane(struct window
*, struct window_pane
*);
1927 struct window_pane
*window_add_pane(struct window
*, u_int
);
1928 void window_resize(struct window
*, u_int
, u_int
);
1929 void window_remove_pane(struct window
*, struct window_pane
*);
1930 struct window_pane
*window_pane_at_index(struct window
*, u_int
);
1931 struct window_pane
*window_pane_next_by_number(struct window
*,
1932 struct window_pane
*, u_int
);
1933 struct window_pane
*window_pane_previous_by_number(struct window
*,
1934 struct window_pane
*, u_int
);
1935 int window_pane_index(struct window_pane
*, u_int
*);
1936 u_int
window_count_panes(struct window
*);
1937 void window_destroy_panes(struct window
*);
1938 struct window_pane
*window_pane_find_by_id(u_int
);
1939 struct window_pane
*window_pane_create(struct window
*, u_int
, u_int
, u_int
);
1940 void window_pane_destroy(struct window_pane
*);
1941 int window_pane_spawn(struct window_pane
*, const char *,
1942 const char *, const char *, struct environ
*,
1943 struct termios
*, char **);
1944 void window_pane_resize(struct window_pane
*, u_int
, u_int
);
1945 void window_pane_alternate_on(
1946 struct window_pane
*, struct grid_cell
*);
1947 void window_pane_alternate_off(
1948 struct window_pane
*, struct grid_cell
*);
1949 int window_pane_set_mode(
1950 struct window_pane
*, const struct window_mode
*);
1951 void window_pane_reset_mode(struct window_pane
*);
1952 void window_pane_key(struct window_pane
*, struct session
*, int);
1953 void window_pane_mouse(struct window_pane
*,
1954 struct session
*, struct mouse_event
*);
1955 int window_pane_visible(struct window_pane
*);
1956 char *window_pane_search(
1957 struct window_pane
*, const char *, u_int
*);
1958 char *window_printable_flags(struct session
*, struct winlink
*);
1960 struct window_pane
*window_pane_find_up(struct window_pane
*);
1961 struct window_pane
*window_pane_find_down(struct window_pane
*);
1962 struct window_pane
*window_pane_find_left(struct window_pane
*);
1963 struct window_pane
*window_pane_find_right(struct window_pane
*);
1966 u_int
layout_count_cells(struct layout_cell
*);
1967 struct layout_cell
*layout_create_cell(struct layout_cell
*);
1968 void layout_free_cell(struct layout_cell
*);
1969 void layout_print_cell(struct layout_cell
*, const char *, u_int
);
1970 void layout_destroy_cell(struct layout_cell
*, struct layout_cell
**);
1971 void layout_set_size(
1972 struct layout_cell
*, u_int
, u_int
, u_int
, u_int
);
1973 void layout_make_leaf(
1974 struct layout_cell
*, struct window_pane
*);
1975 void layout_make_node(struct layout_cell
*, enum layout_type
);
1976 void layout_fix_offsets(struct layout_cell
*);
1977 void layout_fix_panes(struct window
*, u_int
, u_int
);
1978 u_int
layout_resize_check(struct layout_cell
*, enum layout_type
);
1979 void layout_resize_adjust(
1980 struct layout_cell
*, enum layout_type
, int);
1981 void layout_init(struct window
*);
1982 void layout_free(struct window
*);
1983 void layout_resize(struct window
*, u_int
, u_int
);
1984 void layout_resize_pane(
1985 struct window_pane
*, enum layout_type
, int);
1986 void layout_resize_pane_mouse(
1987 struct client
*c
, struct mouse_event
*mouse
);
1988 void layout_assign_pane(struct layout_cell
*, struct window_pane
*);
1989 struct layout_cell
*layout_split_pane(
1990 struct window_pane
*, enum layout_type
, int);
1991 void layout_close_pane(struct window_pane
*);
1993 /* layout-custom.c */
1994 char *layout_dump(struct window
*);
1995 int layout_parse(struct window
*, const char *);
1998 const char *layout_set_name(u_int
);
1999 int layout_set_lookup(const char *);
2000 u_int
layout_set_select(struct window
*, u_int
);
2001 u_int
layout_set_next(struct window
*);
2002 u_int
layout_set_previous(struct window
*);
2003 void layout_set_active_changed(struct window
*);
2005 /* window-clock.c */
2006 extern const struct window_mode window_clock_mode
;
2009 extern const struct window_mode window_copy_mode
;
2010 void window_copy_init_from_pane(struct window_pane
*);
2011 void window_copy_init_for_output(struct window_pane
*);
2012 void window_copy_add(struct window_pane
*, const char *, ...);
2013 void window_copy_vadd(struct window_pane
*, const char *, va_list);
2014 void window_copy_pageup(struct window_pane
*);
2016 /* window-choose.c */
2017 extern const struct window_mode window_choose_mode
;
2018 void window_choose_vadd(
2019 struct window_pane
*, int, const char *, va_list);
2020 void printflike3
window_choose_add(
2021 struct window_pane
*, int, const char *, ...);
2022 void window_choose_ready(struct window_pane
*,
2023 u_int
, void (*)(void *, int), void (*)(void *), void *);
2026 void queue_window_name(struct window
*);
2027 char *default_window_name(struct window
*);
2030 void set_signals(void(*)(int, short, void *));
2031 void clear_signals(int);
2034 extern struct sessions sessions
;
2035 extern struct sessions dead_sessions
;
2036 extern struct session_groups session_groups
;
2037 int session_cmp(struct session
*, struct session
*);
2038 RB_PROTOTYPE(sessions
, session
, entry
, session_cmp
);
2039 int session_alive(struct session
*);
2040 struct session
*session_find(const char *);
2041 struct session
*session_find_by_index(u_int
);
2042 struct session
*session_create(const char *, const char *, const char *,
2043 struct environ
*, struct termios
*, int, u_int
, u_int
,
2045 void session_destroy(struct session
*);
2046 int session_check_name(const char *);
2047 void session_update_activity(struct session
*);
2048 struct session
*session_next_session(struct session
*);
2049 struct session
*session_previous_session(struct session
*);
2050 struct winlink
*session_new(struct session
*,
2051 const char *, const char *, const char *, int, char **);
2052 struct winlink
*session_attach(
2053 struct session
*, struct window
*, int, char **);
2054 int session_detach(struct session
*, struct winlink
*);
2055 struct winlink
* session_has(struct session
*, struct window
*);
2056 int session_next(struct session
*, int);
2057 int session_previous(struct session
*, int);
2058 int session_select(struct session
*, int);
2059 int session_last(struct session
*);
2060 struct session_group
*session_group_find(struct session
*);
2061 u_int
session_group_index(struct session_group
*);
2062 void session_group_add(struct session
*, struct session
*);
2063 void session_group_remove(struct session
*);
2064 void session_group_synchronize_to(struct session
*);
2065 void session_group_synchronize_from(struct session
*);
2066 void session_group_synchronize1(struct session
*, struct session
*);
2069 void utf8_build(void);
2070 int utf8_open(struct utf8_data
*, u_char
);
2071 int utf8_append(struct utf8_data
*, u_char
);
2072 u_int
utf8_combine(const struct utf8_data
*);
2073 u_int
utf8_split2(u_int
, u_char
*);
2076 char *get_proc_name(int, char *);
2077 char *get_proc_cwd(pid_t
);
2080 void log_open_tty(int);
2081 void log_open_file(int, const char *);
2082 void log_close(void);
2083 void printflike1
log_warn(const char *, ...);
2084 void printflike1
log_warnx(const char *, ...);
2085 void printflike1
log_info(const char *, ...);
2086 void printflike1
log_debug(const char *, ...);
2087 void printflike1
log_debug2(const char *, ...);
2088 __dead
void printflike1
log_fatal(const char *, ...);
2089 __dead
void printflike1
log_fatalx(const char *, ...);
2092 char *xstrdup(const char *);
2093 void *xcalloc(size_t, size_t);
2094 void *xmalloc(size_t);
2095 void *xrealloc(void *, size_t, size_t);
2097 int printflike2
xasprintf(char **, const char *, ...);
2098 int xvasprintf(char **, const char *, va_list);
2099 int printflike3
xsnprintf(char *, size_t, const char *, ...);
2100 int xvsnprintf(char *, size_t, const char *, va_list);