1 /* $OpenBSD: tmux.h,v 1.465 2014/06/06 13:21:41 nicm Exp $ */ 2 3 /* 4 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER 15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef TMUX_H 20 #define TMUX_H 21 22 #define PROTOCOL_VERSION 8 23 24 #include <sys/param.h> 25 #include <sys/time.h> 26 #include <sys/queue.h> 27 #include <sys/tree.h> 28 #include <sys/uio.h> 29 30 #include <bitstring.h> 31 #include <event.h> 32 #include <getopt.h> 33 #include <imsg.h> 34 #include <limits.h> 35 #include <signal.h> 36 #include <stdarg.h> 37 #include <stdint.h> 38 #include <stdio.h> 39 #include <termios.h> 40 41 #include "array.h" 42 43 extern char *__progname; 44 extern char **environ; 45 46 /* Default global configuration file. */ 47 #define TMUX_CONF "/etc/tmux.conf" 48 49 /* Default prompt history length. */ 50 #define PROMPT_HISTORY 100 51 52 /* 53 * Minimum layout cell size, NOT including separator line. The scroll region 54 * cannot be one line in height so this must be at least two. 55 */ 56 #define PANE_MINIMUM 2 57 58 /* Automatic name refresh interval, in milliseconds. */ 59 #define NAME_INTERVAL 500 60 61 /* 62 * UTF-8 data size. This must be big enough to hold combined characters as well 63 * as single. 64 */ 65 #define UTF8_SIZE 9 66 67 /* Fatal errors. */ 68 #define fatal(msg) log_fatal("%s: %s", __func__, msg); 69 #define fatalx(msg) log_fatalx("%s: %s", __func__, msg); 70 71 /* Definition to shut gcc up about unused arguments. */ 72 #define unused __attribute__ ((unused)) 73 74 /* Attribute to make gcc check printf-like arguments. */ 75 #define printflike1 __attribute__ ((format (printf, 1, 2))) 76 #define printflike2 __attribute__ ((format (printf, 2, 3))) 77 #define printflike3 __attribute__ ((format (printf, 3, 4))) 78 #define printflike4 __attribute__ ((format (printf, 4, 5))) 79 #define printflike5 __attribute__ ((format (printf, 5, 6))) 80 81 /* Number of items in array. */ 82 #ifndef nitems 83 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 84 #endif 85 86 /* Default template for choose-buffer. */ 87 #define CHOOSE_BUFFER_TEMPLATE \ 88 "#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}" 89 90 /* Default template for choose-client. */ 91 #define CHOOSE_CLIENT_TEMPLATE \ 92 "#{client_tty}: #{session_name} " \ 93 "[#{client_width}x#{client_height} #{client_termname}]" \ 94 "#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \ 95 "(last used #{client_activity_string})" 96 97 /* Default templates for choose-tree. */ 98 #define CHOOSE_TREE_SESSION_TEMPLATE \ 99 "#{session_name}: #{session_windows} windows" \ 100 "#{?session_grouped, (group ,}" \ 101 "#{session_group}#{?session_grouped,),}" \ 102 "#{?session_attached, (attached),}" 103 #define CHOOSE_TREE_WINDOW_TEMPLATE \ 104 "#{window_index}: #{window_name}#{window_flags} " \ 105 "\"#{pane_title}\"" 106 107 /* Default template for display-message. */ 108 #define DISPLAY_MESSAGE_TEMPLATE \ 109 "[#{session_name}] #{window_index}:" \ 110 "#{window_name}, current pane #{pane_index} " \ 111 "- (%H:%M %d-%b-%y)" 112 113 /* Default template for find-window. */ 114 #define FIND_WINDOW_TEMPLATE \ 115 "#{window_index}: #{window_name} " \ 116 "[#{window_width}x#{window_height}] " \ 117 "(#{window_panes} panes) #{window_find_matches}" 118 119 /* Default template for list-buffers. */ 120 #define LIST_BUFFERS_TEMPLATE \ 121 "#{buffer_name}: #{buffer_size} bytes: " \ 122 "\"#{buffer_sample}\"" 123 124 /* Default template for list-clients. */ 125 #define LIST_CLIENTS_TEMPLATE \ 126 "#{client_tty}: #{session_name} " \ 127 "[#{client_width}x#{client_height} #{client_termname}]" \ 128 "#{?client_utf8, (utf8),} #{?client_readonly, (ro),}" 129 130 /* Default template for list-sessions. */ 131 #define LIST_SESSIONS_TEMPLATE \ 132 "#{session_name}: #{session_windows} windows " \ 133 "(created #{session_created_string}) " \ 134 "[#{session_width}x#{session_height}]" \ 135 "#{?session_grouped, (group ,}" \ 136 "#{session_group}#{?session_grouped,),}" \ 137 "#{?session_attached, (attached),}" 138 139 /* Default templates for list-windows. */ 140 #define LIST_WINDOWS_TEMPLATE \ 141 "#{window_index}: #{window_name}#{window_flags} " \ 142 "(#{window_panes} panes) " \ 143 "[#{window_width}x#{window_height}] " \ 144 "[layout #{window_layout}] #{window_id}" \ 145 "#{?window_active, (active),}"; 146 #define LIST_WINDOWS_WITH_SESSION_TEMPLATE \ 147 "#{session_name}:" \ 148 "#{window_index}: #{window_name}#{window_flags} " \ 149 "(#{window_panes} panes) " \ 150 "[#{window_width}x#{window_height}] " 151 152 /* Default templates for break-pane, new-window and split-window. */ 153 #define BREAK_PANE_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}" 154 #define NEW_SESSION_TEMPLATE "#{session_name}:" 155 #define NEW_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE 156 #define SPLIT_WINDOW_TEMPLATE BREAK_PANE_TEMPLATE 157 158 /* Bell option values. */ 159 #define BELL_NONE 0 160 #define BELL_ANY 1 161 #define BELL_CURRENT 2 162 163 /* Special key codes. */ 164 #define KEYC_NONE 0xfff 165 #define KEYC_BASE 0x1000 166 167 /* Key modifier bits. */ 168 #define KEYC_ESCAPE 0x2000 169 #define KEYC_CTRL 0x4000 170 #define KEYC_SHIFT 0x8000 171 #define KEYC_PREFIX 0x10000 172 173 /* Mask to obtain key w/o modifiers. */ 174 #define KEYC_MASK_MOD (KEYC_ESCAPE|KEYC_CTRL|KEYC_SHIFT|KEYC_PREFIX) 175 #define KEYC_MASK_KEY (~KEYC_MASK_MOD) 176 177 /* Other key codes. */ 178 enum key_code { 179 /* Mouse key. */ 180 KEYC_MOUSE = KEYC_BASE, 181 182 /* Backspace key. */ 183 KEYC_BSPACE, 184 185 /* Function keys. */ 186 KEYC_F1, 187 KEYC_F2, 188 KEYC_F3, 189 KEYC_F4, 190 KEYC_F5, 191 KEYC_F6, 192 KEYC_F7, 193 KEYC_F8, 194 KEYC_F9, 195 KEYC_F10, 196 KEYC_F11, 197 KEYC_F12, 198 KEYC_F13, 199 KEYC_F14, 200 KEYC_F15, 201 KEYC_F16, 202 KEYC_F17, 203 KEYC_F18, 204 KEYC_F19, 205 KEYC_F20, 206 KEYC_IC, 207 KEYC_DC, 208 KEYC_HOME, 209 KEYC_END, 210 KEYC_NPAGE, 211 KEYC_PPAGE, 212 KEYC_BTAB, 213 214 /* Arrow keys. */ 215 KEYC_UP, 216 KEYC_DOWN, 217 KEYC_LEFT, 218 KEYC_RIGHT, 219 220 /* Numeric keypad. */ 221 KEYC_KP_SLASH, 222 KEYC_KP_STAR, 223 KEYC_KP_MINUS, 224 KEYC_KP_SEVEN, 225 KEYC_KP_EIGHT, 226 KEYC_KP_NINE, 227 KEYC_KP_PLUS, 228 KEYC_KP_FOUR, 229 KEYC_KP_FIVE, 230 KEYC_KP_SIX, 231 KEYC_KP_ONE, 232 KEYC_KP_TWO, 233 KEYC_KP_THREE, 234 KEYC_KP_ENTER, 235 KEYC_KP_ZERO, 236 KEYC_KP_PERIOD, 237 238 KEYC_FOCUS_IN, 239 KEYC_FOCUS_OUT, 240 }; 241 242 /* Termcap codes. */ 243 enum tty_code_code { 244 TTYC_AX = 0, 245 TTYC_ACSC, /* acs_chars, ac */ 246 TTYC_BEL, /* bell, bl */ 247 TTYC_BLINK, /* enter_blink_mode, mb */ 248 TTYC_BOLD, /* enter_bold_mode, md */ 249 TTYC_CIVIS, /* cursor_invisible, vi */ 250 TTYC_CLEAR, /* clear_screen, cl */ 251 TTYC_CNORM, /* cursor_normal, ve */ 252 TTYC_COLORS, /* max_colors, Co */ 253 TTYC_CR, /* restore cursor colour, Cr */ 254 TTYC_CS, /* set cursor colour, Cs */ 255 TTYC_CSR, /* change_scroll_region, cs */ 256 TTYC_CUB, /* parm_left_cursor, LE */ 257 TTYC_CUB1, /* cursor_left, le */ 258 TTYC_CUD, /* parm_down_cursor, DO */ 259 TTYC_CUD1, /* cursor_down, do */ 260 TTYC_CUF, /* parm_right_cursor, RI */ 261 TTYC_CUF1, /* cursor_right, nd */ 262 TTYC_CUP, /* cursor_address, cm */ 263 TTYC_CUU, /* parm_up_cursor, UP */ 264 TTYC_CUU1, /* cursor_up, up */ 265 TTYC_DCH, /* parm_dch, DC */ 266 TTYC_DCH1, /* delete_character, dc */ 267 TTYC_DIM, /* enter_dim_mode, mh */ 268 TTYC_DL, /* parm_delete_line, DL */ 269 TTYC_DL1, /* delete_line, dl */ 270 TTYC_E3, 271 TTYC_ECH, /* erase_chars, ec */ 272 TTYC_EL, /* clr_eol, ce */ 273 TTYC_EL1, /* clr_bol, cb */ 274 TTYC_ENACS, /* ena_acs, eA */ 275 TTYC_FSL, /* from_status_line, fsl */ 276 TTYC_HOME, /* cursor_home, ho */ 277 TTYC_HPA, /* column_address, ch */ 278 TTYC_ICH, /* parm_ich, IC */ 279 TTYC_ICH1, /* insert_character, ic */ 280 TTYC_IL, /* parm_insert_line, IL */ 281 TTYC_IL1, /* insert_line, il */ 282 TTYC_INVIS, /* enter_secure_mode, mk */ 283 TTYC_IS1, /* init_1string, i1 */ 284 TTYC_IS2, /* init_2string, i2 */ 285 TTYC_IS3, /* init_3string, i3 */ 286 TTYC_KCBT, /* key_btab, kB */ 287 TTYC_KCUB1, /* key_left, kl */ 288 TTYC_KCUD1, /* key_down, kd */ 289 TTYC_KCUF1, /* key_right, kr */ 290 TTYC_KCUU1, /* key_up, ku */ 291 TTYC_KDC2, 292 TTYC_KDC3, 293 TTYC_KDC4, 294 TTYC_KDC5, 295 TTYC_KDC6, 296 TTYC_KDC7, 297 TTYC_KDCH1, /* key_dc, kD */ 298 TTYC_KDN2, 299 TTYC_KDN3, 300 TTYC_KDN4, 301 TTYC_KDN5, 302 TTYC_KDN6, 303 TTYC_KDN7, 304 TTYC_KEND, /* key_end, ke */ 305 TTYC_KEND2, 306 TTYC_KEND3, 307 TTYC_KEND4, 308 TTYC_KEND5, 309 TTYC_KEND6, 310 TTYC_KEND7, 311 TTYC_KF1, /* key_f1, k1 */ 312 TTYC_KF10, /* key_f10, k; */ 313 TTYC_KF11, /* key_f11, F1 */ 314 TTYC_KF12, /* key_f12, F2 */ 315 TTYC_KF13, /* key_f13, F3 */ 316 TTYC_KF14, /* key_f14, F4 */ 317 TTYC_KF15, /* key_f15, F5 */ 318 TTYC_KF16, /* key_f16, F6 */ 319 TTYC_KF17, /* key_f17, F7 */ 320 TTYC_KF18, /* key_f18, F8 */ 321 TTYC_KF19, /* key_f19, F9 */ 322 TTYC_KF2, /* key_f2, k2 */ 323 TTYC_KF20, /* key_f20, F10 */ 324 TTYC_KF3, /* key_f3, k3 */ 325 TTYC_KF4, /* key_f4, k4 */ 326 TTYC_KF5, /* key_f5, k5 */ 327 TTYC_KF6, /* key_f6, k6 */ 328 TTYC_KF7, /* key_f7, k7 */ 329 TTYC_KF8, /* key_f8, k8 */ 330 TTYC_KF9, /* key_f9, k9 */ 331 TTYC_KHOM2, 332 TTYC_KHOM3, 333 TTYC_KHOM4, 334 TTYC_KHOM5, 335 TTYC_KHOM6, 336 TTYC_KHOM7, 337 TTYC_KHOME, /* key_home, kh */ 338 TTYC_KIC2, 339 TTYC_KIC3, 340 TTYC_KIC4, 341 TTYC_KIC5, 342 TTYC_KIC6, 343 TTYC_KIC7, 344 TTYC_KICH1, /* key_ic, kI */ 345 TTYC_KLFT2, 346 TTYC_KLFT3, 347 TTYC_KLFT4, 348 TTYC_KLFT5, 349 TTYC_KLFT6, 350 TTYC_KLFT7, 351 TTYC_KMOUS, /* key_mouse, Km */ 352 TTYC_KNP, /* key_npage, kN */ 353 TTYC_KNXT2, 354 TTYC_KNXT3, 355 TTYC_KNXT4, 356 TTYC_KNXT5, 357 TTYC_KNXT6, 358 TTYC_KNXT7, 359 TTYC_KPP, /* key_ppage, kP */ 360 TTYC_KPRV2, 361 TTYC_KPRV3, 362 TTYC_KPRV4, 363 TTYC_KPRV5, 364 TTYC_KPRV6, 365 TTYC_KPRV7, 366 TTYC_KRIT2, 367 TTYC_KRIT3, 368 TTYC_KRIT4, 369 TTYC_KRIT5, 370 TTYC_KRIT6, 371 TTYC_KRIT7, 372 TTYC_KUP2, 373 TTYC_KUP3, 374 TTYC_KUP4, 375 TTYC_KUP5, 376 TTYC_KUP6, 377 TTYC_KUP7, 378 TTYC_MS, /* modify xterm(1) selection */ 379 TTYC_OP, /* orig_pair, op */ 380 TTYC_REV, /* enter_reverse_mode, mr */ 381 TTYC_RI, /* scroll_reverse, sr */ 382 TTYC_RMACS, /* exit_alt_charset_mode */ 383 TTYC_RMCUP, /* exit_ca_mode, te */ 384 TTYC_RMKX, /* keypad_local, ke */ 385 TTYC_SE, /* reset cursor style, Se */ 386 TTYC_SETAB, /* set_a_background, AB */ 387 TTYC_SETAF, /* set_a_foreground, AF */ 388 TTYC_SGR0, /* exit_attribute_mode, me */ 389 TTYC_SITM, /* enter_italics_mode, it */ 390 TTYC_SMACS, /* enter_alt_charset_mode, as */ 391 TTYC_SMCUP, /* enter_ca_mode, ti */ 392 TTYC_SMKX, /* keypad_xmit, ks */ 393 TTYC_SMSO, /* enter_standout_mode, so */ 394 TTYC_SMUL, /* enter_underline_mode, us */ 395 TTYC_SS, /* set cursor style, Ss */ 396 TTYC_TSL, /* to_status_line, tsl */ 397 TTYC_VPA, /* row_address, cv */ 398 TTYC_XENL, /* eat_newline_glitch, xn */ 399 TTYC_XT, /* xterm(1)-compatible title, XT */ 400 }; 401 #define NTTYCODE (TTYC_XT + 1) 402 403 /* Termcap types. */ 404 enum tty_code_type { 405 TTYCODE_NONE = 0, 406 TTYCODE_STRING, 407 TTYCODE_NUMBER, 408 TTYCODE_FLAG, 409 }; 410 411 /* Termcap code. */ 412 struct tty_code { 413 enum tty_code_type type; 414 union { 415 char *string; 416 int number; 417 int flag; 418 } value; 419 }; 420 421 /* Entry in terminal code table. */ 422 struct tty_term_code_entry { 423 enum tty_code_code code; 424 enum tty_code_type type; 425 const char *name; 426 }; 427 428 /* List of error causes. */ 429 ARRAY_DECL(causelist, char *); 430 431 /* Message codes. */ 432 enum msgtype { 433 MSG_VERSION = 12, 434 435 MSG_IDENTIFY_FLAGS = 100, 436 MSG_IDENTIFY_TERM, 437 MSG_IDENTIFY_TTYNAME, 438 MSG_IDENTIFY_CWD, 439 MSG_IDENTIFY_STDIN, 440 MSG_IDENTIFY_ENVIRON, 441 MSG_IDENTIFY_DONE, 442 443 MSG_COMMAND = 200, 444 MSG_DETACH, 445 MSG_DETACHKILL, 446 MSG_EXIT, 447 MSG_EXITED, 448 MSG_EXITING, 449 MSG_LOCK, 450 MSG_READY, 451 MSG_RESIZE, 452 MSG_SHELL, 453 MSG_SHUTDOWN, 454 MSG_STDERR, 455 MSG_STDIN, 456 MSG_STDOUT, 457 MSG_SUSPEND, 458 MSG_UNLOCK, 459 MSG_WAKEUP, 460 }; 461 462 /* 463 * Message data. 464 * 465 * Don't forget to bump PROTOCOL_VERSION if any of these change! 466 */ 467 struct msg_command_data { 468 int argc; 469 }; /* followed by packed argv */ 470 471 struct msg_stdin_data { 472 ssize_t size; 473 char data[BUFSIZ]; 474 }; 475 476 struct msg_stdout_data { 477 ssize_t size; 478 char data[BUFSIZ]; 479 }; 480 481 struct msg_stderr_data { 482 ssize_t size; 483 char data[BUFSIZ]; 484 }; 485 486 /* Mode key commands. */ 487 enum mode_key_cmd { 488 MODEKEY_NONE, 489 MODEKEY_OTHER, 490 491 /* Editing keys. */ 492 MODEKEYEDIT_BACKSPACE, 493 MODEKEYEDIT_CANCEL, 494 MODEKEYEDIT_COMPLETE, 495 MODEKEYEDIT_CURSORLEFT, 496 MODEKEYEDIT_CURSORRIGHT, 497 MODEKEYEDIT_DELETE, 498 MODEKEYEDIT_DELETELINE, 499 MODEKEYEDIT_DELETETOENDOFLINE, 500 MODEKEYEDIT_DELETEWORD, 501 MODEKEYEDIT_ENDOFLINE, 502 MODEKEYEDIT_ENTER, 503 MODEKEYEDIT_HISTORYDOWN, 504 MODEKEYEDIT_HISTORYUP, 505 MODEKEYEDIT_NEXTSPACE, 506 MODEKEYEDIT_NEXTSPACEEND, 507 MODEKEYEDIT_NEXTWORD, 508 MODEKEYEDIT_NEXTWORDEND, 509 MODEKEYEDIT_PASTE, 510 MODEKEYEDIT_PREVIOUSSPACE, 511 MODEKEYEDIT_PREVIOUSWORD, 512 MODEKEYEDIT_STARTOFLINE, 513 MODEKEYEDIT_SWITCHMODE, 514 MODEKEYEDIT_SWITCHMODEAPPEND, 515 MODEKEYEDIT_SWITCHMODEAPPENDLINE, 516 MODEKEYEDIT_SWITCHMODEBEGINLINE, 517 MODEKEYEDIT_SWITCHMODECHANGELINE, 518 MODEKEYEDIT_SWITCHMODESUBSTITUTE, 519 MODEKEYEDIT_SWITCHMODESUBSTITUTELINE, 520 MODEKEYEDIT_TRANSPOSECHARS, 521 522 /* Menu (choice) keys. */ 523 MODEKEYCHOICE_BACKSPACE, 524 MODEKEYCHOICE_BOTTOMLINE, 525 MODEKEYCHOICE_CANCEL, 526 MODEKEYCHOICE_CHOOSE, 527 MODEKEYCHOICE_DOWN, 528 MODEKEYCHOICE_ENDOFLIST, 529 MODEKEYCHOICE_PAGEDOWN, 530 MODEKEYCHOICE_PAGEUP, 531 MODEKEYCHOICE_SCROLLDOWN, 532 MODEKEYCHOICE_SCROLLUP, 533 MODEKEYCHOICE_STARTNUMBERPREFIX, 534 MODEKEYCHOICE_STARTOFLIST, 535 MODEKEYCHOICE_TOPLINE, 536 MODEKEYCHOICE_TREE_COLLAPSE, 537 MODEKEYCHOICE_TREE_COLLAPSE_ALL, 538 MODEKEYCHOICE_TREE_EXPAND, 539 MODEKEYCHOICE_TREE_EXPAND_ALL, 540 MODEKEYCHOICE_TREE_TOGGLE, 541 MODEKEYCHOICE_UP, 542 543 /* Copy keys. */ 544 MODEKEYCOPY_APPENDSELECTION, 545 MODEKEYCOPY_BACKTOINDENTATION, 546 MODEKEYCOPY_BOTTOMLINE, 547 MODEKEYCOPY_CANCEL, 548 MODEKEYCOPY_CLEARSELECTION, 549 MODEKEYCOPY_COPYPIPE, 550 MODEKEYCOPY_COPYLINE, 551 MODEKEYCOPY_COPYENDOFLINE, 552 MODEKEYCOPY_COPYSELECTION, 553 MODEKEYCOPY_DOWN, 554 MODEKEYCOPY_ENDOFLINE, 555 MODEKEYCOPY_GOTOLINE, 556 MODEKEYCOPY_HALFPAGEDOWN, 557 MODEKEYCOPY_HALFPAGEUP, 558 MODEKEYCOPY_HISTORYBOTTOM, 559 MODEKEYCOPY_HISTORYTOP, 560 MODEKEYCOPY_JUMP, 561 MODEKEYCOPY_JUMPAGAIN, 562 MODEKEYCOPY_JUMPREVERSE, 563 MODEKEYCOPY_JUMPBACK, 564 MODEKEYCOPY_JUMPTO, 565 MODEKEYCOPY_JUMPTOBACK, 566 MODEKEYCOPY_LEFT, 567 MODEKEYCOPY_MIDDLELINE, 568 MODEKEYCOPY_NEXTPAGE, 569 MODEKEYCOPY_NEXTSPACE, 570 MODEKEYCOPY_NEXTSPACEEND, 571 MODEKEYCOPY_NEXTWORD, 572 MODEKEYCOPY_NEXTWORDEND, 573 MODEKEYCOPY_OTHEREND, 574 MODEKEYCOPY_PREVIOUSPAGE, 575 MODEKEYCOPY_PREVIOUSSPACE, 576 MODEKEYCOPY_PREVIOUSWORD, 577 MODEKEYCOPY_RECTANGLETOGGLE, 578 MODEKEYCOPY_RIGHT, 579 MODEKEYCOPY_SCROLLDOWN, 580 MODEKEYCOPY_SCROLLUP, 581 MODEKEYCOPY_SEARCHAGAIN, 582 MODEKEYCOPY_SEARCHDOWN, 583 MODEKEYCOPY_SEARCHREVERSE, 584 MODEKEYCOPY_SEARCHUP, 585 MODEKEYCOPY_SELECTLINE, 586 MODEKEYCOPY_STARTNAMEDBUFFER, 587 MODEKEYCOPY_STARTNUMBERPREFIX, 588 MODEKEYCOPY_STARTOFLINE, 589 MODEKEYCOPY_STARTSELECTION, 590 MODEKEYCOPY_TOPLINE, 591 MODEKEYCOPY_UP, 592 }; 593 594 /* Entry in the default mode key tables. */ 595 struct mode_key_entry { 596 int key; 597 598 /* 599 * Editing mode for vi: 0 is edit mode, keys not in the table are 600 * returned as MODEKEY_OTHER; 1 is command mode, keys not in the table 601 * are returned as MODEKEY_NONE. This is also matched on, allowing some 602 * keys to be bound in edit mode. 603 */ 604 int mode; 605 enum mode_key_cmd cmd; 606 }; 607 608 /* Data required while mode keys are in use. */ 609 struct mode_key_data { 610 struct mode_key_tree *tree; 611 int mode; 612 }; 613 #define MODEKEY_EMACS 0 614 #define MODEKEY_VI 1 615 616 /* Binding between a key and a command. */ 617 struct mode_key_binding { 618 int key; 619 620 int mode; 621 enum mode_key_cmd cmd; 622 const char *arg; 623 624 RB_ENTRY(mode_key_binding) entry; 625 }; 626 RB_HEAD(mode_key_tree, mode_key_binding); 627 628 /* Command to string mapping. */ 629 struct mode_key_cmdstr { 630 enum mode_key_cmd cmd; 631 const char *name; 632 }; 633 634 /* Named mode key table description. */ 635 struct mode_key_table { 636 const char *name; 637 const struct mode_key_cmdstr *cmdstr; 638 struct mode_key_tree *tree; 639 const struct mode_key_entry *table; /* default entries */ 640 }; 641 642 /* Modes. */ 643 #define MODE_CURSOR 0x1 644 #define MODE_INSERT 0x2 645 #define MODE_KCURSOR 0x4 646 #define MODE_KKEYPAD 0x8 /* set = application, clear = number */ 647 #define MODE_WRAP 0x10 /* whether lines wrap */ 648 #define MODE_MOUSE_STANDARD 0x20 649 #define MODE_MOUSE_BUTTON 0x40 650 #define MODE_MOUSE_ANY 0x80 651 #define MODE_MOUSE_UTF8 0x100 652 #define MODE_MOUSE_SGR 0x200 653 #define MODE_BRACKETPASTE 0x400 654 #define MODE_FOCUSON 0x800 655 656 #define ALL_MOUSE_MODES (MODE_MOUSE_STANDARD|MODE_MOUSE_BUTTON|MODE_MOUSE_ANY) 657 658 /* A single UTF-8 character. */ 659 struct utf8_data { 660 u_char data[UTF8_SIZE]; 661 662 size_t have; 663 size_t size; 664 665 u_int width; 666 }; 667 668 /* Grid attributes. */ 669 #define GRID_ATTR_BRIGHT 0x1 670 #define GRID_ATTR_DIM 0x2 671 #define GRID_ATTR_UNDERSCORE 0x4 672 #define GRID_ATTR_BLINK 0x8 673 #define GRID_ATTR_REVERSE 0x10 674 #define GRID_ATTR_HIDDEN 0x20 675 #define GRID_ATTR_ITALICS 0x40 676 #define GRID_ATTR_CHARSET 0x80 /* alternative character set */ 677 678 /* Grid flags. */ 679 #define GRID_FLAG_FG256 0x1 680 #define GRID_FLAG_BG256 0x2 681 #define GRID_FLAG_PADDING 0x4 682 683 /* Grid line flags. */ 684 #define GRID_LINE_WRAPPED 0x1 685 686 /* Grid cell data. */ 687 struct grid_cell { 688 u_char attr; 689 u_char flags; 690 u_char fg; 691 u_char bg; 692 693 u_char xstate; /* top 4 bits width, bottom 4 bits size */ 694 u_char xdata[UTF8_SIZE]; 695 } __packed; 696 697 /* Grid line. */ 698 struct grid_line { 699 u_int cellsize; 700 struct grid_cell *celldata; 701 702 int flags; 703 } __packed; 704 705 /* Entire grid of cells. */ 706 struct grid { 707 int flags; 708 #define GRID_HISTORY 0x1 /* scroll lines into history */ 709 710 u_int sx; 711 u_int sy; 712 713 u_int hsize; 714 u_int hlimit; 715 716 struct grid_line *linedata; 717 }; 718 719 /* Option data structures. */ 720 struct options_entry { 721 char *name; 722 723 enum { 724 OPTIONS_STRING, 725 OPTIONS_NUMBER, 726 OPTIONS_STYLE 727 } type; 728 729 char *str; 730 long long num; 731 struct grid_cell style; 732 733 RB_ENTRY(options_entry) entry; 734 }; 735 736 struct options { 737 RB_HEAD(options_tree, options_entry) tree; 738 struct options *parent; 739 }; 740 741 /* Scheduled job. */ 742 struct job { 743 char *cmd; 744 pid_t pid; 745 int status; 746 747 int fd; 748 struct bufferevent *event; 749 750 void (*callbackfn)(struct job *); 751 void (*freefn)(void *); 752 void *data; 753 754 LIST_ENTRY(job) lentry; 755 }; 756 LIST_HEAD(joblist, job); 757 758 /* Screen selection. */ 759 struct screen_sel { 760 int flag; 761 int rectflag; 762 763 u_int sx; 764 u_int sy; 765 766 u_int ex; 767 u_int ey; 768 769 struct grid_cell cell; 770 }; 771 772 /* Virtual screen. */ 773 struct screen { 774 char *title; 775 776 struct grid *grid; /* grid data */ 777 778 u_int cx; /* cursor x */ 779 u_int cy; /* cursor y */ 780 781 u_int cstyle; /* cursor style */ 782 char *ccolour; /* cursor colour string */ 783 784 u_int rupper; /* scroll region top */ 785 u_int rlower; /* scroll region bottom */ 786 787 int mode; 788 789 bitstr_t *tabs; 790 791 struct screen_sel sel; 792 }; 793 794 /* Screen write context. */ 795 struct screen_write_ctx { 796 struct window_pane *wp; 797 struct screen *s; 798 }; 799 800 /* Screen size. */ 801 #define screen_size_x(s) ((s)->grid->sx) 802 #define screen_size_y(s) ((s)->grid->sy) 803 #define screen_hsize(s) ((s)->grid->hsize) 804 #define screen_hlimit(s) ((s)->grid->hlimit) 805 806 /* Input parser cell. */ 807 struct input_cell { 808 struct grid_cell cell; 809 int set; 810 int g0set; /* 1 if ACS */ 811 int g1set; /* 1 if ACS */ 812 }; 813 814 /* Input parser context. */ 815 struct input_ctx { 816 struct window_pane *wp; 817 struct screen_write_ctx ctx; 818 819 struct input_cell cell; 820 821 struct input_cell old_cell; 822 u_int old_cx; 823 u_int old_cy; 824 825 u_char interm_buf[4]; 826 size_t interm_len; 827 828 u_char param_buf[64]; 829 size_t param_len; 830 831 #define INPUT_BUF_START 32 832 #define INPUT_BUF_LIMIT 1048576 833 u_char *input_buf; 834 size_t input_len; 835 size_t input_space; 836 837 int param_list[24]; /* -1 not present */ 838 u_int param_list_len; 839 840 struct utf8_data utf8data; 841 842 int ch; 843 int flags; 844 #define INPUT_DISCARD 0x1 845 846 const struct input_state *state; 847 848 /* 849 * All input received since we were last in the ground state. Sent to 850 * control clients on connection. 851 */ 852 struct evbuffer *since_ground; 853 }; 854 855 /* 856 * Window mode. Windows can be in several modes and this is used to call the 857 * right function to handle input and output. 858 */ 859 struct session; 860 struct window; 861 struct mouse_event; 862 struct window_mode { 863 struct screen *(*init)(struct window_pane *); 864 void (*free)(struct window_pane *); 865 void (*resize)(struct window_pane *, u_int, u_int); 866 void (*key)(struct window_pane *, struct session *, int); 867 void (*mouse)(struct window_pane *, 868 struct session *, struct mouse_event *); 869 void (*timer)(struct window_pane *); 870 }; 871 872 /* Structures for choose mode. */ 873 struct window_choose_data { 874 struct client *start_client; 875 struct session *start_session; 876 877 u_int idx; 878 int type; 879 #define TREE_OTHER 0x0 880 #define TREE_WINDOW 0x1 881 #define TREE_SESSION 0x2 882 883 struct session *tree_session; /* session of items in tree */ 884 885 struct winlink *wl; 886 int pane_id; 887 888 char *ft_template; 889 struct format_tree *ft; 890 891 char *command; 892 }; 893 894 struct window_choose_mode_item { 895 struct window_choose_data *wcd; 896 char *name; 897 int pos; 898 int state; 899 #define TREE_EXPANDED 0x1 900 }; 901 902 /* Child window structure. */ 903 struct window_pane { 904 u_int id; 905 u_int active_point; 906 907 struct window *window; 908 909 struct layout_cell *layout_cell; 910 struct layout_cell *saved_layout_cell; 911 912 u_int sx; 913 u_int sy; 914 915 u_int xoff; 916 u_int yoff; 917 918 int flags; 919 #define PANE_REDRAW 0x1 920 #define PANE_DROP 0x2 921 #define PANE_FOCUSED 0x4 922 #define PANE_RESIZE 0x8 923 #define PANE_FOCUSPUSH 0x10 924 925 int argc; 926 char **argv; 927 char *shell; 928 int cwd; 929 930 pid_t pid; 931 char tty[TTY_NAME_MAX]; 932 933 u_int changes; 934 struct event changes_timer; 935 u_int changes_redraw; 936 937 int fd; 938 struct bufferevent *event; 939 940 struct input_ctx ictx; 941 942 int pipe_fd; 943 struct bufferevent *pipe_event; 944 size_t pipe_off; 945 946 struct screen *screen; 947 struct screen base; 948 949 /* Saved in alternative screen mode. */ 950 u_int saved_cx; 951 u_int saved_cy; 952 struct grid *saved_grid; 953 struct grid_cell saved_cell; 954 955 const struct window_mode *mode; 956 void *modedata; 957 958 TAILQ_ENTRY(window_pane) entry; 959 RB_ENTRY(window_pane) tree_entry; 960 }; 961 TAILQ_HEAD(window_panes, window_pane); 962 RB_HEAD(window_pane_tree, window_pane); 963 ARRAY_DECL(window_pane_list, struct window_pane *); 964 965 /* Window structure. */ 966 struct window { 967 u_int id; 968 char *name; 969 struct event name_timer; 970 struct timeval silence_timer; 971 972 struct window_pane *active; 973 struct window_pane *last; 974 struct window_panes panes; 975 976 int lastlayout; 977 struct layout_cell *layout_root; 978 struct layout_cell *saved_layout_root; 979 980 u_int sx; 981 u_int sy; 982 983 int flags; 984 #define WINDOW_BELL 0x1 985 #define WINDOW_ACTIVITY 0x2 986 #define WINDOW_REDRAW 0x4 987 #define WINDOW_SILENCE 0x8 988 #define WINDOW_ZOOMED 0x10 989 #define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE) 990 991 struct options options; 992 993 u_int references; 994 }; 995 ARRAY_DECL(windows, struct window *); 996 997 /* Entry on local window list. */ 998 struct winlink { 999 int idx; 1000 struct window *window; 1001 1002 size_t status_width; 1003 struct grid_cell status_cell; 1004 char *status_text; 1005 1006 int flags; 1007 #define WINLINK_BELL 0x1 1008 #define WINLINK_ACTIVITY 0x2 1009 #define WINLINK_SILENCE 0x4 1010 #define WINLINK_ALERTFLAGS (WINLINK_BELL|WINLINK_ACTIVITY|WINLINK_SILENCE) 1011 1012 RB_ENTRY(winlink) entry; 1013 TAILQ_ENTRY(winlink) sentry; 1014 }; 1015 RB_HEAD(winlinks, winlink); 1016 TAILQ_HEAD(winlink_stack, winlink); 1017 1018 /* Layout direction. */ 1019 enum layout_type { 1020 LAYOUT_LEFTRIGHT, 1021 LAYOUT_TOPBOTTOM, 1022 LAYOUT_WINDOWPANE 1023 }; 1024 1025 /* Layout cells queue. */ 1026 TAILQ_HEAD(layout_cells, layout_cell); 1027 1028 /* Layout cell. */ 1029 struct layout_cell { 1030 enum layout_type type; 1031 1032 struct layout_cell *parent; 1033 1034 u_int sx; 1035 u_int sy; 1036 1037 u_int xoff; 1038 u_int yoff; 1039 1040 struct window_pane *wp; 1041 struct layout_cells cells; 1042 1043 TAILQ_ENTRY(layout_cell) entry; 1044 }; 1045 1046 /* Paste buffer. */ 1047 struct paste_buffer { 1048 char *data; 1049 size_t size; 1050 1051 char *name; 1052 int automatic; 1053 u_int order; 1054 1055 RB_ENTRY(paste_buffer) name_entry; 1056 RB_ENTRY(paste_buffer) time_entry; 1057 }; 1058 1059 /* Environment variable. */ 1060 struct environ_entry { 1061 char *name; 1062 char *value; 1063 1064 RB_ENTRY(environ_entry) entry; 1065 }; 1066 RB_HEAD(environ, environ_entry); 1067 1068 /* Client session. */ 1069 struct session_group { 1070 TAILQ_HEAD(, session) sessions; 1071 1072 TAILQ_ENTRY(session_group) entry; 1073 }; 1074 TAILQ_HEAD(session_groups, session_group); 1075 1076 struct session { 1077 u_int id; 1078 1079 char *name; 1080 int cwd; 1081 1082 struct timeval creation_time; 1083 struct timeval activity_time; 1084 struct timeval last_activity_time; 1085 1086 u_int sx; 1087 u_int sy; 1088 1089 struct winlink *curw; 1090 struct winlink_stack lastw; 1091 struct winlinks windows; 1092 1093 struct options options; 1094 1095 #define SESSION_UNATTACHED 0x1 /* not attached to any clients */ 1096 int flags; 1097 1098 u_int attached; 1099 1100 struct termios *tio; 1101 1102 struct environ environ; 1103 1104 int references; 1105 1106 TAILQ_ENTRY(session) gentry; 1107 RB_ENTRY(session) entry; 1108 }; 1109 RB_HEAD(sessions, session); 1110 ARRAY_DECL(sessionslist, struct session *); 1111 1112 /* TTY information. */ 1113 struct tty_key { 1114 char ch; 1115 int key; 1116 1117 struct tty_key *left; 1118 struct tty_key *right; 1119 1120 struct tty_key *next; 1121 }; 1122 1123 struct tty_term { 1124 char *name; 1125 u_int references; 1126 1127 char acs[UCHAR_MAX + 1][2]; 1128 1129 struct tty_code codes[NTTYCODE]; 1130 1131 #define TERM_256COLOURS 0x1 1132 #define TERM_EARLYWRAP 0x2 1133 int flags; 1134 1135 LIST_ENTRY(tty_term) entry; 1136 }; 1137 LIST_HEAD(tty_terms, tty_term); 1138 1139 /* Mouse button masks. */ 1140 #define MOUSE_MASK_BUTTONS 3 1141 #define MOUSE_MASK_SHIFT 4 1142 #define MOUSE_MASK_META 8 1143 #define MOUSE_MASK_CTRL 16 1144 #define MOUSE_MASK_DRAG 32 1145 #define MOUSE_MASK_WHEEL 64 1146 1147 /* Mouse wheel states. */ 1148 #define MOUSE_WHEEL_UP 0 1149 #define MOUSE_WHEEL_DOWN 1 1150 1151 /* Mouse wheel multipler. */ 1152 #define MOUSE_WHEEL_SCALE 3 1153 1154 /* Mouse event bits. */ 1155 #define MOUSE_EVENT_DOWN 0x1 1156 #define MOUSE_EVENT_DRAG 0x2 1157 #define MOUSE_EVENT_UP 0x4 1158 #define MOUSE_EVENT_CLICK 0x8 1159 #define MOUSE_EVENT_WHEEL 0x10 1160 1161 /* Mouse flag bits. */ 1162 #define MOUSE_RESIZE_PANE 0x1 1163 1164 /* 1165 * Mouse input. When sent by xterm: 1166 * 1167 * - buttons are in the bottom two bits: 0 = b1; 1 = b2; 2 = b3; 3 = released 1168 * - bits 3, 4 and 5 are for keys 1169 * - bit 6 is set for dragging 1170 * - bit 7 for buttons 4 and 5 1171 * 1172 * With the SGR 1006 extension the released button becomes known. Store these 1173 * in separate fields and store the value converted to the old format in xb. 1174 */ 1175 struct mouse_event { 1176 u_int xb; 1177 1178 u_int x; 1179 u_int lx; 1180 u_int sx; 1181 1182 u_int y; 1183 u_int ly; 1184 u_int sy; 1185 1186 u_int sgr; /* whether the input arrived in SGR format */ 1187 u_int sgr_xb; /* only for SGR: the unmangled button */ 1188 u_int sgr_rel; /* only for SGR: if it is a release event */ 1189 1190 u_int button; 1191 u_int clicks; 1192 u_int scroll; 1193 1194 int wheel; 1195 int event; 1196 int flags; 1197 }; 1198 1199 struct tty { 1200 struct client *client; 1201 1202 char *path; 1203 u_int class; 1204 1205 u_int sx; 1206 u_int sy; 1207 1208 u_int cx; 1209 u_int cy; 1210 u_int cstyle; 1211 char *ccolour; 1212 1213 int mode; 1214 1215 u_int rlower; 1216 u_int rupper; 1217 1218 char *termname; 1219 struct tty_term *term; 1220 1221 int fd; 1222 struct bufferevent *event; 1223 1224 int log_fd; 1225 1226 struct termios tio; 1227 1228 struct grid_cell cell; 1229 1230 #define TTY_NOCURSOR 0x1 1231 #define TTY_FREEZE 0x2 1232 #define TTY_TIMER 0x4 1233 #define TTY_UTF8 0x8 1234 #define TTY_STARTED 0x10 1235 #define TTY_OPENED 0x20 1236 #define TTY_FOCUS 0x40 1237 int flags; 1238 1239 int term_flags; 1240 1241 struct mouse_event mouse; 1242 1243 struct event key_timer; 1244 struct tty_key *key_tree; 1245 }; 1246 1247 /* TTY command context and function pointer. */ 1248 struct tty_ctx { 1249 struct window_pane *wp; 1250 1251 const struct grid_cell *cell; 1252 1253 u_int num; 1254 void *ptr; 1255 1256 /* 1257 * Cursor and region position before the screen was updated - this is 1258 * where the command should be applied; the values in the screen have 1259 * already been updated. 1260 */ 1261 u_int ocx; 1262 u_int ocy; 1263 1264 u_int orupper; 1265 u_int orlower; 1266 1267 u_int xoff; 1268 u_int yoff; 1269 1270 /* Saved last cell on line. */ 1271 struct grid_cell last_cell; 1272 u_int last_width; 1273 }; 1274 1275 /* Saved message entry. */ 1276 struct message_entry { 1277 char *msg; 1278 time_t msg_time; 1279 }; 1280 1281 /* Status output data from a job. */ 1282 struct status_out { 1283 char *cmd; 1284 char *out; 1285 1286 RB_ENTRY(status_out) entry; 1287 }; 1288 RB_HEAD(status_out_tree, status_out); 1289 1290 /* Client connection. */ 1291 struct client { 1292 struct imsgbuf ibuf; 1293 1294 int fd; 1295 struct event event; 1296 int retval; 1297 1298 struct timeval creation_time; 1299 struct timeval activity_time; 1300 1301 struct environ environ; 1302 1303 char *title; 1304 int cwd; 1305 1306 char *term; 1307 char *ttyname; 1308 struct tty tty; 1309 1310 void (*stdin_callback)(struct client *, int, void *); 1311 void *stdin_callback_data; 1312 struct evbuffer *stdin_data; 1313 int stdin_closed; 1314 struct evbuffer *stdout_data; 1315 struct evbuffer *stderr_data; 1316 1317 struct event repeat_timer; 1318 1319 struct status_out_tree status_old; 1320 struct status_out_tree status_new; 1321 struct timeval status_timer; 1322 struct screen status; 1323 1324 #define CLIENT_TERMINAL 0x1 1325 #define CLIENT_PREFIX 0x2 1326 #define CLIENT_EXIT 0x4 1327 #define CLIENT_REDRAW 0x8 1328 #define CLIENT_STATUS 0x10 1329 #define CLIENT_REPEAT 0x20 1330 #define CLIENT_SUSPENDED 0x40 1331 #define CLIENT_BAD 0x80 1332 #define CLIENT_IDENTIFY 0x100 1333 #define CLIENT_DEAD 0x200 1334 #define CLIENT_BORDERS 0x400 1335 #define CLIENT_READONLY 0x800 1336 #define CLIENT_REDRAWWINDOW 0x1000 1337 #define CLIENT_CONTROL 0x2000 1338 #define CLIENT_CONTROLCONTROL 0x4000 1339 #define CLIENT_FOCUSED 0x8000 1340 #define CLIENT_UTF8 0x10000 1341 #define CLIENT_256COLOURS 0x20000 1342 #define CLIENT_IDENTIFIED 0x40000 1343 int flags; 1344 1345 struct event identify_timer; 1346 1347 char *message_string; 1348 struct event message_timer; 1349 ARRAY_DECL(, struct message_entry) message_log; 1350 1351 char *prompt_string; 1352 char *prompt_buffer; 1353 size_t prompt_index; 1354 int (*prompt_callbackfn)(void *, const char *); 1355 void (*prompt_freefn)(void *); 1356 void *prompt_data; 1357 u_int prompt_hindex; 1358 1359 #define PROMPT_SINGLE 0x1 1360 int prompt_flags; 1361 1362 struct mode_key_data prompt_mdata; 1363 1364 struct session *session; 1365 struct session *last_session; 1366 1367 int wlmouse; 1368 1369 struct cmd_q *cmdq; 1370 int references; 1371 }; 1372 ARRAY_DECL(clients, struct client *); 1373 1374 /* Parsed arguments structures. */ 1375 struct args_entry { 1376 u_char flag; 1377 char *value; 1378 RB_ENTRY(args_entry) entry; 1379 }; 1380 RB_HEAD(args_tree, args_entry); 1381 1382 struct args { 1383 struct args_tree tree; 1384 int argc; 1385 char **argv; 1386 }; 1387 1388 /* Command and list of commands. */ 1389 struct cmd { 1390 const struct cmd_entry *entry; 1391 struct args *args; 1392 1393 char *file; 1394 u_int line; 1395 1396 #define CMD_CONTROL 0x1 1397 int flags; 1398 1399 TAILQ_ENTRY(cmd) qentry; 1400 }; 1401 struct cmd_list { 1402 int references; 1403 TAILQ_HEAD(, cmd) list; 1404 }; 1405 1406 /* Command return values. */ 1407 enum cmd_retval { 1408 CMD_RETURN_ERROR = -1, 1409 CMD_RETURN_NORMAL = 0, 1410 CMD_RETURN_WAIT, 1411 CMD_RETURN_STOP 1412 }; 1413 1414 /* Command queue entry. */ 1415 struct cmd_q_item { 1416 struct cmd_list *cmdlist; 1417 TAILQ_ENTRY(cmd_q_item) qentry; 1418 }; 1419 TAILQ_HEAD(cmd_q_items, cmd_q_item); 1420 1421 /* Command queue. */ 1422 struct cmd_q { 1423 int references; 1424 int dead; 1425 1426 struct client *client; 1427 int client_exit; 1428 1429 struct cmd_q_items queue; 1430 struct cmd_q_item *item; 1431 struct cmd *cmd; 1432 1433 time_t time; 1434 u_int number; 1435 1436 void (*emptyfn)(struct cmd_q *); 1437 void *data; 1438 1439 TAILQ_ENTRY(cmd_q) waitentry; 1440 }; 1441 1442 /* Command definition. */ 1443 struct cmd_entry { 1444 const char *name; 1445 const char *alias; 1446 1447 const char *args_template; 1448 int args_lower; 1449 int args_upper; 1450 1451 const char *usage; 1452 1453 #define CMD_STARTSERVER 0x1 1454 #define CMD_CANTNEST 0x2 1455 #define CMD_READONLY 0x4 1456 int flags; 1457 1458 void (*key_binding)(struct cmd *, int); 1459 enum cmd_retval (*exec)(struct cmd *, struct cmd_q *); 1460 }; 1461 1462 /* Key binding. */ 1463 struct key_binding { 1464 int key; 1465 struct cmd_list *cmdlist; 1466 int can_repeat; 1467 1468 RB_ENTRY(key_binding) entry; 1469 }; 1470 RB_HEAD(key_bindings, key_binding); 1471 1472 /* 1473 * Option table entries. The option table is the user-visible part of the 1474 * option, as opposed to the internal options (struct option) which are just 1475 * number or string. 1476 */ 1477 enum options_table_type { 1478 OPTIONS_TABLE_STRING, 1479 OPTIONS_TABLE_NUMBER, 1480 OPTIONS_TABLE_KEY, 1481 OPTIONS_TABLE_COLOUR, 1482 OPTIONS_TABLE_ATTRIBUTES, 1483 OPTIONS_TABLE_FLAG, 1484 OPTIONS_TABLE_CHOICE, 1485 OPTIONS_TABLE_STYLE 1486 }; 1487 1488 struct options_table_entry { 1489 const char *name; 1490 enum options_table_type type; 1491 1492 u_int minimum; 1493 u_int maximum; 1494 const char **choices; 1495 1496 const char *default_str; 1497 long long default_num; 1498 1499 const char *style; 1500 }; 1501 1502 /* Tree of format entries. */ 1503 struct format_entry { 1504 char *key; 1505 char *value; 1506 1507 RB_ENTRY(format_entry) entry; 1508 }; 1509 RB_HEAD(format_tree, format_entry); 1510 1511 /* Common command usages. */ 1512 #define CMD_TARGET_PANE_USAGE "[-t target-pane]" 1513 #define CMD_TARGET_WINDOW_USAGE "[-t target-window]" 1514 #define CMD_TARGET_SESSION_USAGE "[-t target-session]" 1515 #define CMD_TARGET_CLIENT_USAGE "[-t target-client]" 1516 #define CMD_SRCDST_PANE_USAGE "[-s src-pane] [-t dst-pane]" 1517 #define CMD_SRCDST_WINDOW_USAGE "[-s src-window] [-t dst-window]" 1518 #define CMD_SRCDST_SESSION_USAGE "[-s src-session] [-t dst-session]" 1519 #define CMD_SRCDST_CLIENT_USAGE "[-s src-client] [-t dst-client]" 1520 #define CMD_BUFFER_USAGE "[-b buffer-name]" 1521 1522 /* tmux.c */ 1523 extern struct options global_options; 1524 extern struct options global_s_options; 1525 extern struct options global_w_options; 1526 extern struct environ global_environ; 1527 extern struct event_base *ev_base; 1528 extern char *cfg_file; 1529 extern char *shell_cmd; 1530 extern int debug_level; 1531 extern time_t start_time; 1532 extern char socket_path[MAXPATHLEN]; 1533 extern int login_shell; 1534 extern char *environ_path; 1535 void logfile(const char *); 1536 const char *getshell(void); 1537 int checkshell(const char *); 1538 int areshell(const char *); 1539 void setblocking(int, int); 1540 __dead void shell_exec(const char *, const char *); 1541 1542 /* cfg.c */ 1543 extern struct cmd_q *cfg_cmd_q; 1544 extern int cfg_finished; 1545 extern int cfg_references; 1546 extern struct causelist cfg_causes; 1547 extern struct client *cfg_client; 1548 int load_cfg(const char *, struct cmd_q *, char **); 1549 void cfg_default_done(struct cmd_q *); 1550 void cfg_show_causes(struct session *); 1551 1552 /* format.c */ 1553 int format_cmp(struct format_entry *, struct format_entry *); 1554 RB_PROTOTYPE(format_tree, format_entry, entry, format_cmp); 1555 struct format_tree *format_create(void); 1556 void format_free(struct format_tree *); 1557 void printflike3 format_add(struct format_tree *, const char *, const char *, 1558 ...); 1559 const char *format_find(struct format_tree *, const char *); 1560 char *format_expand(struct format_tree *, const char *); 1561 void format_session(struct format_tree *, struct session *); 1562 void format_client(struct format_tree *, struct client *); 1563 void format_window(struct format_tree *, struct window *); 1564 void format_winlink(struct format_tree *, struct session *, 1565 struct winlink *); 1566 void format_window_pane(struct format_tree *, 1567 struct window_pane *); 1568 void format_paste_buffer(struct format_tree *, 1569 struct paste_buffer *, int); 1570 1571 /* mode-key.c */ 1572 extern const struct mode_key_table mode_key_tables[]; 1573 extern struct mode_key_tree mode_key_tree_vi_edit; 1574 extern struct mode_key_tree mode_key_tree_vi_choice; 1575 extern struct mode_key_tree mode_key_tree_vi_copy; 1576 extern struct mode_key_tree mode_key_tree_emacs_edit; 1577 extern struct mode_key_tree mode_key_tree_emacs_choice; 1578 extern struct mode_key_tree mode_key_tree_emacs_copy; 1579 int mode_key_cmp(struct mode_key_binding *, struct mode_key_binding *); 1580 RB_PROTOTYPE(mode_key_tree, mode_key_binding, entry, mode_key_cmp); 1581 const char *mode_key_tostring(const struct mode_key_cmdstr *, 1582 enum mode_key_cmd); 1583 enum mode_key_cmd mode_key_fromstring(const struct mode_key_cmdstr *, 1584 const char *); 1585 const struct mode_key_table *mode_key_findtable(const char *); 1586 void mode_key_init_trees(void); 1587 void mode_key_init(struct mode_key_data *, struct mode_key_tree *); 1588 enum mode_key_cmd mode_key_lookup(struct mode_key_data *, int, const char **); 1589 1590 /* notify.c */ 1591 void notify_enable(void); 1592 void notify_disable(void); 1593 void notify_input(struct window_pane *, struct evbuffer *); 1594 void notify_window_layout_changed(struct window *); 1595 void notify_window_unlinked(struct session *, struct window *); 1596 void notify_window_linked(struct session *, struct window *); 1597 void notify_window_renamed(struct window *); 1598 void notify_attached_session_changed(struct client *); 1599 void notify_session_renamed(struct session *); 1600 void notify_session_created(struct session *); 1601 void notify_session_closed(struct session *); 1602 1603 /* options.c */ 1604 int options_cmp(struct options_entry *, struct options_entry *); 1605 RB_PROTOTYPE(options_tree, options_entry, entry, options_cmp); 1606 void options_init(struct options *, struct options *); 1607 void options_free(struct options *); 1608 struct options_entry *options_find1(struct options *, const char *); 1609 struct options_entry *options_find(struct options *, const char *); 1610 void options_remove(struct options *, const char *); 1611 struct options_entry *printflike3 options_set_string(struct options *, 1612 const char *, const char *, ...); 1613 char *options_get_string(struct options *, const char *); 1614 struct options_entry *options_set_number(struct options *, const char *, 1615 long long); 1616 long long options_get_number(struct options *, const char *); 1617 struct options_entry *options_set_style(struct options *, const char *, 1618 const char *, int); 1619 struct grid_cell *options_get_style(struct options *, const char *); 1620 1621 /* options-table.c */ 1622 extern const struct options_table_entry server_options_table[]; 1623 extern const struct options_table_entry session_options_table[]; 1624 extern const struct options_table_entry window_options_table[]; 1625 void options_table_populate_tree(const struct options_table_entry *, 1626 struct options *); 1627 const char *options_table_print_entry(const struct options_table_entry *, 1628 struct options_entry *, int); 1629 int options_table_find(const char *, const struct options_table_entry **, 1630 const struct options_table_entry **); 1631 1632 /* job.c */ 1633 extern struct joblist all_jobs; 1634 struct job *job_run(const char *, struct session *, 1635 void (*)(struct job *), void (*)(void *), void *); 1636 void job_free(struct job *); 1637 void job_died(struct job *, int); 1638 1639 /* environ.c */ 1640 int environ_cmp(struct environ_entry *, struct environ_entry *); 1641 RB_PROTOTYPE(environ, environ_entry, entry, environ_cmp); 1642 void environ_init(struct environ *); 1643 void environ_free(struct environ *); 1644 void environ_copy(struct environ *, struct environ *); 1645 struct environ_entry *environ_find(struct environ *, const char *); 1646 void environ_set(struct environ *, const char *, const char *); 1647 void environ_put(struct environ *, const char *); 1648 void environ_unset(struct environ *, const char *); 1649 void environ_update(const char *, struct environ *, struct environ *); 1650 void environ_push(struct environ *); 1651 1652 /* tty.c */ 1653 void tty_init_termios(int, struct termios *, struct bufferevent *); 1654 void tty_raw(struct tty *, const char *); 1655 void tty_attributes(struct tty *, const struct grid_cell *); 1656 void tty_reset(struct tty *); 1657 void tty_region_pane(struct tty *, const struct tty_ctx *, u_int, u_int); 1658 void tty_region(struct tty *, u_int, u_int); 1659 void tty_cursor_pane(struct tty *, const struct tty_ctx *, u_int, u_int); 1660 void tty_cursor(struct tty *, u_int, u_int); 1661 void tty_putcode(struct tty *, enum tty_code_code); 1662 void tty_putcode1(struct tty *, enum tty_code_code, int); 1663 void tty_putcode2(struct tty *, enum tty_code_code, int, int); 1664 void tty_putcode_ptr1(struct tty *, enum tty_code_code, const void *); 1665 void tty_putcode_ptr2(struct tty *, enum tty_code_code, const void *, 1666 const void *); 1667 void tty_puts(struct tty *, const char *); 1668 void tty_putc(struct tty *, u_char); 1669 void tty_putn(struct tty *, const void *, size_t, u_int); 1670 void tty_init(struct tty *, struct client *, int, char *); 1671 int tty_resize(struct tty *); 1672 int tty_set_size(struct tty *, u_int, u_int); 1673 void tty_set_class(struct tty *, u_int); 1674 void tty_start_tty(struct tty *); 1675 void tty_stop_tty(struct tty *); 1676 void tty_set_title(struct tty *, const char *); 1677 void tty_update_mode(struct tty *, int, struct screen *); 1678 void tty_force_cursor_colour(struct tty *, const char *); 1679 void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int); 1680 int tty_open(struct tty *, char **); 1681 void tty_close(struct tty *); 1682 void tty_free(struct tty *); 1683 void tty_write( 1684 void (*)(struct tty *, const struct tty_ctx *), struct tty_ctx *); 1685 void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *); 1686 void tty_cmd_cell(struct tty *, const struct tty_ctx *); 1687 void tty_cmd_clearendofline(struct tty *, const struct tty_ctx *); 1688 void tty_cmd_clearendofscreen(struct tty *, const struct tty_ctx *); 1689 void tty_cmd_clearline(struct tty *, const struct tty_ctx *); 1690 void tty_cmd_clearscreen(struct tty *, const struct tty_ctx *); 1691 void tty_cmd_clearstartofline(struct tty *, const struct tty_ctx *); 1692 void tty_cmd_clearstartofscreen(struct tty *, const struct tty_ctx *); 1693 void tty_cmd_deletecharacter(struct tty *, const struct tty_ctx *); 1694 void tty_cmd_clearcharacter(struct tty *, const struct tty_ctx *); 1695 void tty_cmd_deleteline(struct tty *, const struct tty_ctx *); 1696 void tty_cmd_erasecharacter(struct tty *, const struct tty_ctx *); 1697 void tty_cmd_insertcharacter(struct tty *, const struct tty_ctx *); 1698 void tty_cmd_insertline(struct tty *, const struct tty_ctx *); 1699 void tty_cmd_linefeed(struct tty *, const struct tty_ctx *); 1700 void tty_cmd_utf8character(struct tty *, const struct tty_ctx *); 1701 void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *); 1702 void tty_cmd_setselection(struct tty *, const struct tty_ctx *); 1703 void tty_cmd_rawstring(struct tty *, const struct tty_ctx *); 1704 void tty_bell(struct tty *); 1705 1706 /* tty-term.c */ 1707 extern struct tty_terms tty_terms; 1708 extern const struct tty_term_code_entry tty_term_codes[NTTYCODE]; 1709 struct tty_term *tty_term_find(char *, int, char **); 1710 void tty_term_free(struct tty_term *); 1711 int tty_term_has(struct tty_term *, enum tty_code_code); 1712 const char *tty_term_string(struct tty_term *, enum tty_code_code); 1713 const char *tty_term_string1(struct tty_term *, enum tty_code_code, int); 1714 const char *tty_term_string2( 1715 struct tty_term *, enum tty_code_code, int, int); 1716 const char *tty_term_ptr1( 1717 struct tty_term *, enum tty_code_code, const void *); 1718 const char *tty_term_ptr2(struct tty_term *, enum tty_code_code, 1719 const void *, const void *); 1720 int tty_term_number(struct tty_term *, enum tty_code_code); 1721 int tty_term_flag(struct tty_term *, enum tty_code_code); 1722 1723 /* tty-acs.c */ 1724 const char *tty_acs_get(struct tty *, u_char); 1725 1726 /* tty-keys.c */ 1727 void tty_keys_build(struct tty *); 1728 void tty_keys_free(struct tty *); 1729 int tty_keys_next(struct tty *); 1730 1731 /* paste.c */ 1732 struct paste_buffer *paste_walk(struct paste_buffer *); 1733 struct paste_buffer *paste_get_top(void); 1734 struct paste_buffer *paste_get_name(const char *); 1735 int paste_free_top(void); 1736 int paste_free_name(const char *); 1737 void paste_add(char *, size_t); 1738 int paste_rename(const char *, const char *, char **); 1739 int paste_set(char *, size_t, const char *, char **); 1740 char *paste_make_sample(struct paste_buffer *, int); 1741 void paste_send_pane(struct paste_buffer *, struct window_pane *, 1742 const char *, int); 1743 1744 /* arguments.c */ 1745 int args_cmp(struct args_entry *, struct args_entry *); 1746 RB_PROTOTYPE(args_tree, args_entry, entry, args_cmp); 1747 struct args *args_create(int, ...); 1748 struct args *args_parse(const char *, int, char **); 1749 void args_free(struct args *); 1750 size_t args_print(struct args *, char *, size_t); 1751 int args_has(struct args *, u_char); 1752 void args_set(struct args *, u_char, const char *); 1753 const char *args_get(struct args *, u_char); 1754 long long args_strtonum( 1755 struct args *, u_char, long long, long long, char **); 1756 1757 /* cmd.c */ 1758 int cmd_pack_argv(int, char **, char *, size_t); 1759 int cmd_unpack_argv(char *, size_t, int, char ***); 1760 char **cmd_copy_argv(int, char **); 1761 void cmd_free_argv(int, char **); 1762 char *cmd_stringify_argv(int, char **); 1763 struct cmd *cmd_parse(int, char **, const char *, u_int, char **); 1764 size_t cmd_print(struct cmd *, char *, size_t); 1765 struct session *cmd_current_session(struct cmd_q *, int); 1766 struct client *cmd_current_client(struct cmd_q *); 1767 struct client *cmd_find_client(struct cmd_q *, const char *, int); 1768 struct session *cmd_find_session(struct cmd_q *, const char *, int); 1769 struct winlink *cmd_find_window(struct cmd_q *, const char *, 1770 struct session **); 1771 int cmd_find_index(struct cmd_q *, const char *, 1772 struct session **); 1773 struct winlink *cmd_find_pane(struct cmd_q *, const char *, struct session **, 1774 struct window_pane **); 1775 char *cmd_template_replace(const char *, const char *, int); 1776 struct window *cmd_lookup_windowid(const char *); 1777 struct window_pane *cmd_lookup_paneid(const char *); 1778 extern const struct cmd_entry *cmd_table[]; 1779 extern const struct cmd_entry cmd_attach_session_entry; 1780 extern const struct cmd_entry cmd_bind_key_entry; 1781 extern const struct cmd_entry cmd_break_pane_entry; 1782 extern const struct cmd_entry cmd_capture_pane_entry; 1783 extern const struct cmd_entry cmd_choose_buffer_entry; 1784 extern const struct cmd_entry cmd_choose_client_entry; 1785 extern const struct cmd_entry cmd_choose_session_entry; 1786 extern const struct cmd_entry cmd_choose_tree_entry; 1787 extern const struct cmd_entry cmd_choose_window_entry; 1788 extern const struct cmd_entry cmd_clear_history_entry; 1789 extern const struct cmd_entry cmd_clock_mode_entry; 1790 extern const struct cmd_entry cmd_command_prompt_entry; 1791 extern const struct cmd_entry cmd_confirm_before_entry; 1792 extern const struct cmd_entry cmd_copy_mode_entry; 1793 extern const struct cmd_entry cmd_delete_buffer_entry; 1794 extern const struct cmd_entry cmd_detach_client_entry; 1795 extern const struct cmd_entry cmd_display_message_entry; 1796 extern const struct cmd_entry cmd_display_panes_entry; 1797 extern const struct cmd_entry cmd_down_pane_entry; 1798 extern const struct cmd_entry cmd_find_window_entry; 1799 extern const struct cmd_entry cmd_has_session_entry; 1800 extern const struct cmd_entry cmd_if_shell_entry; 1801 extern const struct cmd_entry cmd_join_pane_entry; 1802 extern const struct cmd_entry cmd_kill_pane_entry; 1803 extern const struct cmd_entry cmd_kill_server_entry; 1804 extern const struct cmd_entry cmd_kill_session_entry; 1805 extern const struct cmd_entry cmd_kill_window_entry; 1806 extern const struct cmd_entry cmd_last_pane_entry; 1807 extern const struct cmd_entry cmd_last_window_entry; 1808 extern const struct cmd_entry cmd_link_window_entry; 1809 extern const struct cmd_entry cmd_list_buffers_entry; 1810 extern const struct cmd_entry cmd_list_clients_entry; 1811 extern const struct cmd_entry cmd_list_commands_entry; 1812 extern const struct cmd_entry cmd_list_keys_entry; 1813 extern const struct cmd_entry cmd_list_panes_entry; 1814 extern const struct cmd_entry cmd_list_sessions_entry; 1815 extern const struct cmd_entry cmd_list_windows_entry; 1816 extern const struct cmd_entry cmd_load_buffer_entry; 1817 extern const struct cmd_entry cmd_lock_client_entry; 1818 extern const struct cmd_entry cmd_lock_server_entry; 1819 extern const struct cmd_entry cmd_lock_session_entry; 1820 extern const struct cmd_entry cmd_move_pane_entry; 1821 extern const struct cmd_entry cmd_move_window_entry; 1822 extern const struct cmd_entry cmd_new_session_entry; 1823 extern const struct cmd_entry cmd_new_window_entry; 1824 extern const struct cmd_entry cmd_next_layout_entry; 1825 extern const struct cmd_entry cmd_next_window_entry; 1826 extern const struct cmd_entry cmd_paste_buffer_entry; 1827 extern const struct cmd_entry cmd_pipe_pane_entry; 1828 extern const struct cmd_entry cmd_previous_layout_entry; 1829 extern const struct cmd_entry cmd_previous_window_entry; 1830 extern const struct cmd_entry cmd_refresh_client_entry; 1831 extern const struct cmd_entry cmd_rename_session_entry; 1832 extern const struct cmd_entry cmd_rename_window_entry; 1833 extern const struct cmd_entry cmd_resize_pane_entry; 1834 extern const struct cmd_entry cmd_respawn_pane_entry; 1835 extern const struct cmd_entry cmd_respawn_window_entry; 1836 extern const struct cmd_entry cmd_rotate_window_entry; 1837 extern const struct cmd_entry cmd_run_shell_entry; 1838 extern const struct cmd_entry cmd_save_buffer_entry; 1839 extern const struct cmd_entry cmd_select_layout_entry; 1840 extern const struct cmd_entry cmd_select_pane_entry; 1841 extern const struct cmd_entry cmd_select_window_entry; 1842 extern const struct cmd_entry cmd_send_keys_entry; 1843 extern const struct cmd_entry cmd_send_prefix_entry; 1844 extern const struct cmd_entry cmd_server_info_entry; 1845 extern const struct cmd_entry cmd_set_buffer_entry; 1846 extern const struct cmd_entry cmd_set_environment_entry; 1847 extern const struct cmd_entry cmd_set_option_entry; 1848 extern const struct cmd_entry cmd_set_window_option_entry; 1849 extern const struct cmd_entry cmd_show_buffer_entry; 1850 extern const struct cmd_entry cmd_show_environment_entry; 1851 extern const struct cmd_entry cmd_show_messages_entry; 1852 extern const struct cmd_entry cmd_show_options_entry; 1853 extern const struct cmd_entry cmd_show_window_options_entry; 1854 extern const struct cmd_entry cmd_source_file_entry; 1855 extern const struct cmd_entry cmd_split_window_entry; 1856 extern const struct cmd_entry cmd_start_server_entry; 1857 extern const struct cmd_entry cmd_suspend_client_entry; 1858 extern const struct cmd_entry cmd_swap_pane_entry; 1859 extern const struct cmd_entry cmd_swap_window_entry; 1860 extern const struct cmd_entry cmd_switch_client_entry; 1861 extern const struct cmd_entry cmd_unbind_key_entry; 1862 extern const struct cmd_entry cmd_unlink_window_entry; 1863 extern const struct cmd_entry cmd_up_pane_entry; 1864 extern const struct cmd_entry cmd_wait_for_entry; 1865 1866 /* cmd-attach-session.c */ 1867 enum cmd_retval cmd_attach_session(struct cmd_q *, const char *, int, int, 1868 const char *); 1869 1870 /* cmd-list.c */ 1871 struct cmd_list *cmd_list_parse(int, char **, const char *, u_int, char **); 1872 void cmd_list_free(struct cmd_list *); 1873 size_t cmd_list_print(struct cmd_list *, char *, size_t); 1874 1875 /* cmd-queue.c */ 1876 struct cmd_q *cmdq_new(struct client *); 1877 int cmdq_free(struct cmd_q *); 1878 void printflike2 cmdq_print(struct cmd_q *, const char *, ...); 1879 void printflike2 cmdq_error(struct cmd_q *, const char *, ...); 1880 int cmdq_guard(struct cmd_q *, const char *, int); 1881 void cmdq_run(struct cmd_q *, struct cmd_list *); 1882 void cmdq_append(struct cmd_q *, struct cmd_list *); 1883 int cmdq_continue(struct cmd_q *); 1884 void cmdq_flush(struct cmd_q *); 1885 1886 /* cmd-string.c */ 1887 int cmd_string_parse(const char *, struct cmd_list **, const char *, 1888 u_int, char **); 1889 1890 /* client.c */ 1891 int client_main(int, char **, int); 1892 1893 /* key-bindings.c */ 1894 extern struct key_bindings key_bindings; 1895 int key_bindings_cmp(struct key_binding *, struct key_binding *); 1896 RB_PROTOTYPE(key_bindings, key_binding, entry, key_bindings_cmp); 1897 struct key_binding *key_bindings_lookup(int); 1898 void key_bindings_add(int, int, struct cmd_list *); 1899 void key_bindings_remove(int); 1900 void key_bindings_init(void); 1901 void key_bindings_dispatch(struct key_binding *, struct client *); 1902 1903 /* key-string.c */ 1904 int key_string_lookup_string(const char *); 1905 const char *key_string_lookup_key(int); 1906 1907 /* server.c */ 1908 extern struct clients clients; 1909 extern struct clients dead_clients; 1910 int server_start(int, char *); 1911 void server_update_socket(void); 1912 void server_add_accept(int); 1913 1914 /* server-client.c */ 1915 void server_client_handle_key(struct client *, int); 1916 void server_client_create(int); 1917 int server_client_open(struct client *, char **); 1918 void server_client_lost(struct client *); 1919 void server_client_callback(int, short, void *); 1920 void server_client_status_timer(void); 1921 void server_client_loop(void); 1922 1923 /* server-window.c */ 1924 void server_window_loop(void); 1925 1926 /* server-fn.c */ 1927 void server_fill_environ(struct session *, struct environ *); 1928 void server_write_ready(struct client *); 1929 int server_write_client(struct client *, enum msgtype, const void *, 1930 size_t); 1931 void server_write_session(struct session *, enum msgtype, const void *, 1932 size_t); 1933 void server_redraw_client(struct client *); 1934 void server_status_client(struct client *); 1935 void server_redraw_session(struct session *); 1936 void server_redraw_session_group(struct session *); 1937 void server_status_session(struct session *); 1938 void server_status_session_group(struct session *); 1939 void server_redraw_window(struct window *); 1940 void server_redraw_window_borders(struct window *); 1941 void server_status_window(struct window *); 1942 void server_lock(void); 1943 void server_lock_session(struct session *); 1944 void server_lock_client(struct client *); 1945 int server_unlock(const char *); 1946 void server_kill_window(struct window *); 1947 int server_link_window(struct session *, 1948 struct winlink *, struct session *, int, int, int, char **); 1949 void server_unlink_window(struct session *, struct winlink *); 1950 void server_destroy_pane(struct window_pane *); 1951 void server_destroy_session_group(struct session *); 1952 void server_destroy_session(struct session *); 1953 void server_check_unattached(void); 1954 void server_set_identify(struct client *); 1955 void server_clear_identify(struct client *); 1956 void server_update_event(struct client *); 1957 void server_push_stdout(struct client *); 1958 void server_push_stderr(struct client *); 1959 int server_set_stdin_callback(struct client *, void (*)(struct client *, 1960 int, void *), void *, char **); 1961 void server_unzoom_window(struct window *); 1962 1963 /* status.c */ 1964 int status_out_cmp(struct status_out *, struct status_out *); 1965 RB_PROTOTYPE(status_out_tree, status_out, entry, status_out_cmp); 1966 int status_at_line(struct client *); 1967 void status_free_jobs(struct status_out_tree *); 1968 void status_update_jobs(struct client *); 1969 void status_set_window_at(struct client *, u_int); 1970 int status_redraw(struct client *); 1971 char *status_replace(struct client *, struct session *, 1972 struct winlink *, struct window_pane *, const char *, time_t, int); 1973 void printflike2 status_message_set(struct client *, const char *, ...); 1974 void status_message_clear(struct client *); 1975 int status_message_redraw(struct client *); 1976 void status_prompt_set(struct client *, const char *, const char *, 1977 int (*)(void *, const char *), void (*)(void *), void *, int); 1978 void status_prompt_clear(struct client *); 1979 int status_prompt_redraw(struct client *); 1980 void status_prompt_key(struct client *, int); 1981 void status_prompt_update(struct client *, const char *, const char *); 1982 1983 /* resize.c */ 1984 void recalculate_sizes(void); 1985 1986 /* input.c */ 1987 void input_init(struct window_pane *); 1988 void input_free(struct window_pane *); 1989 void input_parse(struct window_pane *); 1990 1991 /* input-key.c */ 1992 void input_key(struct window_pane *, int); 1993 void input_mouse(struct window_pane *, struct session *, 1994 struct mouse_event *); 1995 1996 /* xterm-keys.c */ 1997 char *xterm_keys_lookup(int); 1998 int xterm_keys_find(const char *, size_t, size_t *, int *); 1999 2000 /* colour.c */ 2001 void colour_set_fg(struct grid_cell *, int); 2002 void colour_set_bg(struct grid_cell *, int); 2003 const char *colour_tostring(int); 2004 int colour_fromstring(const char *); 2005 u_char colour_256to16(u_char); 2006 2007 /* attributes.c */ 2008 const char *attributes_tostring(u_char); 2009 int attributes_fromstring(const char *); 2010 2011 /* grid.c */ 2012 extern const struct grid_cell grid_default_cell; 2013 extern const struct grid_cell grid_marker_cell; 2014 struct grid *grid_create(u_int, u_int, u_int); 2015 void grid_destroy(struct grid *); 2016 int grid_compare(struct grid *, struct grid *); 2017 void grid_collect_history(struct grid *); 2018 void grid_scroll_history(struct grid *); 2019 void grid_scroll_history_region(struct grid *, u_int, u_int); 2020 void grid_expand_line(struct grid *, u_int, u_int); 2021 const struct grid_cell *grid_peek_cell(struct grid *, u_int, u_int); 2022 const struct grid_line *grid_peek_line(struct grid *, u_int); 2023 struct grid_cell *grid_get_cell(struct grid *, u_int, u_int); 2024 void grid_set_cell(struct grid *, u_int, u_int, const struct grid_cell *); 2025 void grid_clear(struct grid *, u_int, u_int, u_int, u_int); 2026 void grid_clear_lines(struct grid *, u_int, u_int); 2027 void grid_move_lines(struct grid *, u_int, u_int, u_int); 2028 void grid_move_cells(struct grid *, u_int, u_int, u_int, u_int); 2029 char *grid_string_cells(struct grid *, u_int, u_int, u_int, 2030 struct grid_cell **, int, int, int); 2031 void grid_duplicate_lines( 2032 struct grid *, u_int, struct grid *, u_int, u_int); 2033 u_int grid_reflow(struct grid *, struct grid *, u_int); 2034 2035 /* grid-cell.c */ 2036 u_int grid_cell_width(const struct grid_cell *); 2037 void grid_cell_get(const struct grid_cell *, struct utf8_data *); 2038 void grid_cell_set(struct grid_cell *, const struct utf8_data *); 2039 void grid_cell_one(struct grid_cell *, u_char); 2040 2041 /* grid-view.c */ 2042 const struct grid_cell *grid_view_peek_cell(struct grid *, u_int, u_int); 2043 struct grid_cell *grid_view_get_cell(struct grid *, u_int, u_int); 2044 void grid_view_set_cell( 2045 struct grid *, u_int, u_int, const struct grid_cell *); 2046 void grid_view_clear_history(struct grid *); 2047 void grid_view_clear(struct grid *, u_int, u_int, u_int, u_int); 2048 void grid_view_scroll_region_up(struct grid *, u_int, u_int); 2049 void grid_view_scroll_region_down(struct grid *, u_int, u_int); 2050 void grid_view_insert_lines(struct grid *, u_int, u_int); 2051 void grid_view_insert_lines_region(struct grid *, u_int, u_int, u_int); 2052 void grid_view_delete_lines(struct grid *, u_int, u_int); 2053 void grid_view_delete_lines_region(struct grid *, u_int, u_int, u_int); 2054 void grid_view_insert_cells(struct grid *, u_int, u_int, u_int); 2055 void grid_view_delete_cells(struct grid *, u_int, u_int, u_int); 2056 char *grid_view_string_cells(struct grid *, u_int, u_int, u_int); 2057 2058 /* screen-write.c */ 2059 void screen_write_start( 2060 struct screen_write_ctx *, struct window_pane *, struct screen *); 2061 void screen_write_stop(struct screen_write_ctx *); 2062 void screen_write_reset(struct screen_write_ctx *); 2063 size_t printflike2 screen_write_cstrlen(int, const char *, ...); 2064 void printflike5 screen_write_cnputs(struct screen_write_ctx *, 2065 ssize_t, struct grid_cell *, int, const char *, ...); 2066 size_t printflike2 screen_write_strlen(int, const char *, ...); 2067 void printflike3 screen_write_puts(struct screen_write_ctx *, 2068 struct grid_cell *, const char *, ...); 2069 void printflike5 screen_write_nputs(struct screen_write_ctx *, 2070 ssize_t, struct grid_cell *, int, const char *, ...); 2071 void screen_write_vnputs(struct screen_write_ctx *, 2072 ssize_t, struct grid_cell *, int, const char *, va_list); 2073 void screen_write_putc( 2074 struct screen_write_ctx *, struct grid_cell *, u_char); 2075 void screen_write_copy(struct screen_write_ctx *, 2076 struct screen *, u_int, u_int, u_int, u_int); 2077 void screen_write_backspace(struct screen_write_ctx *); 2078 void screen_write_mode_set(struct screen_write_ctx *, int); 2079 void screen_write_mode_clear(struct screen_write_ctx *, int); 2080 void screen_write_cursorup(struct screen_write_ctx *, u_int); 2081 void screen_write_cursordown(struct screen_write_ctx *, u_int); 2082 void screen_write_cursorright(struct screen_write_ctx *, u_int); 2083 void screen_write_cursorleft(struct screen_write_ctx *, u_int); 2084 void screen_write_alignmenttest(struct screen_write_ctx *); 2085 void screen_write_insertcharacter(struct screen_write_ctx *, u_int); 2086 void screen_write_deletecharacter(struct screen_write_ctx *, u_int); 2087 void screen_write_clearcharacter(struct screen_write_ctx *, u_int); 2088 void screen_write_insertline(struct screen_write_ctx *, u_int); 2089 void screen_write_deleteline(struct screen_write_ctx *, u_int); 2090 void screen_write_clearline(struct screen_write_ctx *); 2091 void screen_write_clearendofline(struct screen_write_ctx *); 2092 void screen_write_clearstartofline(struct screen_write_ctx *); 2093 void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int); 2094 void screen_write_reverseindex(struct screen_write_ctx *); 2095 void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); 2096 void screen_write_linefeed(struct screen_write_ctx *, int); 2097 void screen_write_linefeedscreen(struct screen_write_ctx *, int); 2098 void screen_write_carriagereturn(struct screen_write_ctx *); 2099 void screen_write_clearendofscreen(struct screen_write_ctx *); 2100 void screen_write_clearstartofscreen(struct screen_write_ctx *); 2101 void screen_write_clearscreen(struct screen_write_ctx *); 2102 void screen_write_clearhistory(struct screen_write_ctx *); 2103 void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *); 2104 void screen_write_setselection(struct screen_write_ctx *, u_char *, u_int); 2105 void screen_write_rawstring(struct screen_write_ctx *, u_char *, u_int); 2106 2107 /* screen-redraw.c */ 2108 void screen_redraw_screen(struct client *, int, int, int); 2109 void screen_redraw_pane(struct client *, struct window_pane *); 2110 2111 /* screen.c */ 2112 void screen_init(struct screen *, u_int, u_int, u_int); 2113 void screen_reinit(struct screen *); 2114 void screen_free(struct screen *); 2115 void screen_reset_tabs(struct screen *); 2116 void screen_set_cursor_style(struct screen *, u_int); 2117 void screen_set_cursor_colour(struct screen *, const char *); 2118 void screen_set_title(struct screen *, const char *); 2119 void screen_resize(struct screen *, u_int, u_int, int); 2120 void screen_set_selection(struct screen *, 2121 u_int, u_int, u_int, u_int, u_int, struct grid_cell *); 2122 void screen_clear_selection(struct screen *); 2123 int screen_check_selection(struct screen *, u_int, u_int); 2124 void screen_reflow(struct screen *, u_int); 2125 2126 /* window.c */ 2127 extern struct windows windows; 2128 extern struct window_pane_tree all_window_panes; 2129 int winlink_cmp(struct winlink *, struct winlink *); 2130 RB_PROTOTYPE(winlinks, winlink, entry, winlink_cmp); 2131 int window_pane_cmp(struct window_pane *, struct window_pane *); 2132 RB_PROTOTYPE(window_pane_tree, window_pane, tree_entry, window_pane_cmp); 2133 struct winlink *winlink_find_by_index(struct winlinks *, int); 2134 struct winlink *winlink_find_by_window(struct winlinks *, struct window *); 2135 struct winlink *winlink_find_by_window_id(struct winlinks *, u_int); 2136 int winlink_next_index(struct winlinks *, int); 2137 u_int winlink_count(struct winlinks *); 2138 struct winlink *winlink_add(struct winlinks *, int); 2139 void winlink_set_window(struct winlink *, struct window *); 2140 void winlink_remove(struct winlinks *, struct winlink *); 2141 struct winlink *winlink_next(struct winlink *); 2142 struct winlink *winlink_previous(struct winlink *); 2143 struct winlink *winlink_next_by_number(struct winlink *, struct session *, 2144 int); 2145 struct winlink *winlink_previous_by_number(struct winlink *, struct session *, 2146 int); 2147 void winlink_stack_push(struct winlink_stack *, struct winlink *); 2148 void winlink_stack_remove(struct winlink_stack *, struct winlink *); 2149 int window_index(struct window *, u_int *); 2150 struct window *window_find_by_id(u_int); 2151 struct window *window_create1(u_int, u_int); 2152 struct window *window_create(const char *, int, char **, const char *, 2153 const char *, int, struct environ *, struct termios *, 2154 u_int, u_int, u_int, char **); 2155 void window_destroy(struct window *); 2156 struct window_pane *window_get_active_at(struct window *, u_int, u_int); 2157 void window_set_active_at(struct window *, u_int, u_int); 2158 struct window_pane *window_find_string(struct window *, const char *); 2159 void window_set_active_pane(struct window *, struct window_pane *); 2160 struct window_pane *window_add_pane(struct window *, u_int); 2161 void window_resize(struct window *, u_int, u_int); 2162 int window_zoom(struct window_pane *); 2163 int window_unzoom(struct window *); 2164 void window_lost_pane(struct window *, struct window_pane *); 2165 void window_remove_pane(struct window *, struct window_pane *); 2166 struct window_pane *window_pane_at_index(struct window *, u_int); 2167 struct window_pane *window_pane_next_by_number(struct window *, 2168 struct window_pane *, u_int); 2169 struct window_pane *window_pane_previous_by_number(struct window *, 2170 struct window_pane *, u_int); 2171 int window_pane_index(struct window_pane *, u_int *); 2172 u_int window_count_panes(struct window *); 2173 void window_destroy_panes(struct window *); 2174 struct window_pane *window_pane_find_by_id(u_int); 2175 struct window_pane *window_pane_create(struct window *, u_int, u_int, u_int); 2176 void window_pane_destroy(struct window_pane *); 2177 void window_pane_timer_start(struct window_pane *); 2178 int window_pane_spawn(struct window_pane *, int, char **, 2179 const char *, const char *, int, struct environ *, 2180 struct termios *, char **); 2181 void window_pane_resize(struct window_pane *, u_int, u_int); 2182 void window_pane_alternate_on(struct window_pane *, 2183 struct grid_cell *, int); 2184 void window_pane_alternate_off(struct window_pane *, 2185 struct grid_cell *, int); 2186 int window_pane_set_mode( 2187 struct window_pane *, const struct window_mode *); 2188 void window_pane_reset_mode(struct window_pane *); 2189 void window_pane_key(struct window_pane *, struct session *, int); 2190 void window_pane_mouse(struct window_pane *, 2191 struct session *, struct mouse_event *); 2192 int window_pane_visible(struct window_pane *); 2193 char *window_pane_search( 2194 struct window_pane *, const char *, u_int *); 2195 char *window_printable_flags(struct session *, struct winlink *); 2196 struct window_pane *window_pane_find_up(struct window_pane *); 2197 struct window_pane *window_pane_find_down(struct window_pane *); 2198 struct window_pane *window_pane_find_left(struct window_pane *); 2199 struct window_pane *window_pane_find_right(struct window_pane *); 2200 void window_set_name(struct window *, const char *); 2201 void window_remove_ref(struct window *); 2202 void winlink_clear_flags(struct winlink *); 2203 2204 /* layout.c */ 2205 u_int layout_count_cells(struct layout_cell *); 2206 struct layout_cell *layout_create_cell(struct layout_cell *); 2207 void layout_free_cell(struct layout_cell *); 2208 void layout_print_cell(struct layout_cell *, const char *, u_int); 2209 void layout_destroy_cell(struct layout_cell *, struct layout_cell **); 2210 void layout_set_size( 2211 struct layout_cell *, u_int, u_int, u_int, u_int); 2212 void layout_make_leaf( 2213 struct layout_cell *, struct window_pane *); 2214 void layout_make_node(struct layout_cell *, enum layout_type); 2215 void layout_fix_offsets(struct layout_cell *); 2216 void layout_fix_panes(struct window *, u_int, u_int); 2217 u_int layout_resize_check(struct layout_cell *, enum layout_type); 2218 void layout_resize_adjust( 2219 struct layout_cell *, enum layout_type, int); 2220 void layout_init(struct window *, struct window_pane *); 2221 void layout_free(struct window *); 2222 void layout_resize(struct window *, u_int, u_int); 2223 void layout_resize_pane(struct window_pane *, enum layout_type, 2224 int); 2225 void layout_resize_pane_to(struct window_pane *, enum layout_type, 2226 u_int); 2227 void layout_resize_pane_mouse(struct client *); 2228 void layout_assign_pane(struct layout_cell *, struct window_pane *); 2229 struct layout_cell *layout_split_pane( 2230 struct window_pane *, enum layout_type, int, int); 2231 void layout_close_pane(struct window_pane *); 2232 2233 /* layout-custom.c */ 2234 char *layout_dump(struct window *); 2235 int layout_parse(struct window *, const char *); 2236 2237 /* layout-set.c */ 2238 const char *layout_set_name(u_int); 2239 int layout_set_lookup(const char *); 2240 u_int layout_set_select(struct window *, u_int); 2241 u_int layout_set_next(struct window *); 2242 u_int layout_set_previous(struct window *); 2243 void layout_set_active_changed(struct window *); 2244 2245 /* window-clock.c */ 2246 extern const struct window_mode window_clock_mode; 2247 extern const char window_clock_table[14][5][5]; 2248 2249 /* window-copy.c */ 2250 extern const struct window_mode window_copy_mode; 2251 void window_copy_init_from_pane(struct window_pane *); 2252 void window_copy_init_for_output(struct window_pane *); 2253 void printflike2 window_copy_add(struct window_pane *, const char *, ...); 2254 void window_copy_vadd(struct window_pane *, const char *, va_list); 2255 void window_copy_pageup(struct window_pane *); 2256 2257 /* window-choose.c */ 2258 extern const struct window_mode window_choose_mode; 2259 void window_choose_add(struct window_pane *, 2260 struct window_choose_data *); 2261 void window_choose_ready(struct window_pane *, 2262 u_int, void (*)(struct window_choose_data *)); 2263 struct window_choose_data *window_choose_data_create (int, 2264 struct client *, struct session *); 2265 void window_choose_data_free(struct window_choose_data *); 2266 void window_choose_data_run(struct window_choose_data *); 2267 struct window_choose_data *window_choose_add_window(struct window_pane *, 2268 struct client *, struct session *, struct winlink *, 2269 const char *, const char *, u_int); 2270 struct window_choose_data *window_choose_add_session(struct window_pane *, 2271 struct client *, struct session *, const char *, 2272 const char *, u_int); 2273 struct window_choose_data *window_choose_add_item(struct window_pane *, 2274 struct client *, struct winlink *, const char *, 2275 const char *, u_int); 2276 void window_choose_expand_all(struct window_pane *); 2277 void window_choose_collapse_all(struct window_pane *); 2278 void window_choose_set_current(struct window_pane *, u_int); 2279 2280 /* names.c */ 2281 void queue_window_name(struct window *); 2282 char *default_window_name(struct window *); 2283 char *format_window_name(struct window *); 2284 char *parse_window_name(const char *); 2285 2286 /* signal.c */ 2287 void set_signals(void(*)(int, short, void *)); 2288 void clear_signals(int); 2289 2290 /* control.c */ 2291 void control_callback(struct client *, int, void*); 2292 void printflike2 control_write(struct client *, const char *, ...); 2293 void control_write_buffer(struct client *, struct evbuffer *); 2294 2295 /* control-notify.c */ 2296 void control_notify_input(struct client *, struct window_pane *, 2297 struct evbuffer *); 2298 void control_notify_window_layout_changed(struct window *); 2299 void control_notify_window_unlinked(struct session *, struct window *); 2300 void control_notify_window_linked(struct session *, struct window *); 2301 void control_notify_window_renamed(struct window *); 2302 void control_notify_attached_session_changed(struct client *); 2303 void control_notify_session_renamed(struct session *); 2304 void control_notify_session_created(struct session *); 2305 void control_notify_session_close(struct session *); 2306 2307 /* session.c */ 2308 extern struct sessions sessions; 2309 extern struct sessions dead_sessions; 2310 extern struct session_groups session_groups; 2311 int session_cmp(struct session *, struct session *); 2312 RB_PROTOTYPE(sessions, session, entry, session_cmp); 2313 int session_alive(struct session *); 2314 struct session *session_find(const char *); 2315 struct session *session_find_by_id(u_int); 2316 struct session *session_create(const char *, int, char **, const char *, 2317 int, struct environ *, struct termios *, int, u_int, 2318 u_int, char **); 2319 void session_destroy(struct session *); 2320 int session_check_name(const char *); 2321 void session_update_activity(struct session *); 2322 struct session *session_next_session(struct session *); 2323 struct session *session_previous_session(struct session *); 2324 struct winlink *session_new(struct session *, const char *, int, char **, 2325 const char *, int, int, char **); 2326 struct winlink *session_attach(struct session *, struct window *, int, 2327 char **); 2328 int session_detach(struct session *, struct winlink *); 2329 struct winlink *session_has(struct session *, struct window *); 2330 int session_next(struct session *, int); 2331 int session_previous(struct session *, int); 2332 int session_select(struct session *, int); 2333 int session_last(struct session *); 2334 int session_set_current(struct session *, struct winlink *); 2335 struct session_group *session_group_find(struct session *); 2336 u_int session_group_index(struct session_group *); 2337 void session_group_add(struct session *, struct session *); 2338 void session_group_remove(struct session *); 2339 void session_group_synchronize_to(struct session *); 2340 void session_group_synchronize_from(struct session *); 2341 void session_group_synchronize1(struct session *, struct session *); 2342 void session_renumber_windows(struct session *); 2343 2344 /* utf8.c */ 2345 void utf8_build(void); 2346 void utf8_set(struct utf8_data *, u_char); 2347 int utf8_open(struct utf8_data *, u_char); 2348 int utf8_append(struct utf8_data *, u_char); 2349 u_int utf8_combine(const struct utf8_data *); 2350 u_int utf8_split2(u_int, u_char *); 2351 int utf8_strvis(char *, const char *, size_t, int); 2352 struct utf8_data *utf8_fromcstr(const char *); 2353 char *utf8_tocstr(struct utf8_data *); 2354 u_int utf8_cstrwidth(const char *); 2355 char *utf8_trimcstr(const char *, u_int); 2356 2357 /* procname.c */ 2358 char *get_proc_name(int, char *); 2359 2360 /* log.c */ 2361 void log_open(const char *); 2362 void log_close(void); 2363 void printflike1 log_debug(const char *, ...); 2364 __dead void printflike1 log_fatal(const char *, ...); 2365 __dead void printflike1 log_fatalx(const char *, ...); 2366 2367 /* xmalloc.c */ 2368 char *xstrdup(const char *); 2369 void *xcalloc(size_t, size_t); 2370 void *xmalloc(size_t); 2371 void *xrealloc(void *, size_t, size_t); 2372 int printflike2 xasprintf(char **, const char *, ...); 2373 int xvasprintf(char **, const char *, va_list); 2374 int printflike3 xsnprintf(char *, size_t, const char *, ...); 2375 int xvsnprintf(char *, size_t, const char *, va_list); 2376 2377 /* style.c */ 2378 int style_parse(const struct grid_cell *, 2379 struct grid_cell *, const char *); 2380 const char *style_tostring(struct grid_cell *); 2381 void style_update_new(struct options *, const char *, const char *); 2382 void style_update_old(struct options *, const char *, 2383 struct grid_cell *); 2384 void style_apply(struct grid_cell *, struct options *, 2385 const char *); 2386 void style_apply_update(struct grid_cell *, struct options *, 2387 const char *); 2388 2389 #endif /* TMUX_H */ 2390