Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Imported Upstream version 1.2

  • Loading branch information...
commit dda8e8e5944269d95e286afa20aa3ead27cef56b 1 parent 8fade26
@kfebert kfebert authored
Showing with 6,039 additions and 4,235 deletions.
  1. +58 −1 CHANGES
  2. +48 −10 FAQ
  3. +2 −2 GNUmakefile
  4. +2 −2 Makefile
  5. +6 −8 NOTES
  6. +55 −17 TODO
  7. +3 −1 array.h
  8. +21 −21 attributes.c
  9. +0 −55 buffer-poll.c
  10. +0 −139 buffer.c
  11. +37 −21 cfg.c
  12. +130 −96 client.c
  13. +6 −6 clock.c
  14. +11 −7 cmd-attach-session.c
  15. +5 −4 cmd-bind-key.c
  16. +10 −10 cmd-break-pane.c
  17. +83 −0 cmd-capture-pane.c
  18. +2 −2 cmd-choose-client.c
  19. +2 −2 cmd-choose-session.c
  20. +5 −5 cmd-choose-window.c
  21. +2 −2 cmd-clear-history.c
  22. +2 −2 cmd-clock-mode.c
  23. +2 −2 cmd-command-prompt.c
  24. +2 −2 cmd-confirm-before.c
  25. +3 −2 cmd-copy-buffer.c
  26. +5 −5 cmd-copy-mode.c
  27. +2 −2 cmd-delete-buffer.c
  28. +2 −2 cmd-detach-client.c
  29. +8 −5 cmd-display-message.c
  30. +2 −2 cmd-display-panes.c
  31. +3 −2 cmd-down-pane.c
  32. +2 −2 cmd-find-window.c
  33. +57 −52 cmd-generic.c
  34. +2 −2 cmd-has-session.c
  35. +2 −2 cmd-if-shell.c
  36. +256 −0 cmd-join-pane.c
  37. +3 −3 cmd-kill-pane.c
  38. +4 −3 cmd-kill-server.c
  39. +3 −3 cmd-kill-session.c
  40. +2 −2 cmd-kill-window.c
  41. +2 −2 cmd-last-window.c
  42. +4 −4 cmd-link-window.c
  43. +4 −4 cmd-list-buffers.c
  44. +3 −2 cmd-list-clients.c
  45. +3 −2 cmd-list-commands.c
  46. +12 −8 cmd-list-keys.c
  47. +5 −5 cmd-list-panes.c
  48. +3 −2 cmd-list-sessions.c
  49. +2 −2 cmd-list-windows.c
  50. +24 −5 cmd-list.c
  51. +30 −32 cmd-load-buffer.c
  52. +2 −2 cmd-lock-client.c
  53. +3 −2 cmd-lock-server.c
  54. +2 −2 cmd-lock-session.c
  55. +4 −4 cmd-move-window.c
  56. +30 −10 cmd-new-session.c
  57. +17 −18 cmd-new-window.c
  58. +2 −2 cmd-next-layout.c
  59. +4 −4 cmd-next-window.c
  60. +13 −13 cmd-paste-buffer.c
  61. +29 −13 cmd-pipe-pane.c
  62. +3 −3 cmd-previous-layout.c
  63. +4 −4 cmd-previous-window.c
  64. +2 −2 cmd-refresh-client.c
  65. +2 −2 cmd-rename-session.c
  66. +2 −2 cmd-rename-window.c
  67. +18 −20 cmd-resize-pane.c
  68. +5 −4 cmd-respawn-window.c
  69. +4 −4 cmd-rotate-window.c
  70. +24 −22 cmd-run-shell.c
  71. +3 −3 cmd-save-buffer.c
  72. +4 −4 cmd-select-layout.c
  73. +3 −2 cmd-select-pane.c
  74. +2 −2 cmd-select-prompt.c
  75. +2 −2 cmd-select-window.c
  76. +3 −3 cmd-send-keys.c
  77. +2 −2 cmd-send-prefix.c
  78. +9 −8 cmd-server-info.c
  79. +3 −3 cmd-set-buffer.c
  80. +5 −5 cmd-set-environment.c
  81. +361 −26 cmd-set-option.c
  82. +5 −128 cmd-set-window-option.c
  83. +7 −7 cmd-show-buffer.c
  84. +3 −3 cmd-show-environment.c
  85. +65 −0 cmd-show-messages.c
  86. +30 −11 cmd-show-options.c
  87. +5 −24 cmd-show-window-options.c
  88. +14 −7 cmd-source-file.c
  89. +26 −19 cmd-split-window.c
  90. +3 −2 cmd-start-server.c
  91. +23 −39 cmd-string.c
  92. +2 −2 cmd-suspend-client.c
  93. +9 −8 cmd-swap-pane.c
  94. +3 −3 cmd-swap-window.c
  95. +6 −4 cmd-switch-client.c
  96. +4 −3 cmd-unbind-key.c
  97. +4 −4 cmd-unlink-window.c
  98. +3 −2 cmd-up-pane.c
  99. +99 −36 cmd.c
  100. +1 −9 compat.h
  101. +0 −124 compat/bsd-poll.c
  102. +0 −59 compat/bsd-poll.h
  103. +16 −16 configure
  104. +10 −1 examples/n-marriott.conf
  105. +1 −3 examples/screen-keys.conf
  106. +13 −7 examples/tmux.vim
  107. +35 −0 examples/vim-keys.conf
  108. +96 −0 grid-utf8.c
  109. +4 −4 grid-view.c
  110. +21 −23 grid.c
  111. +48 −67 input-keys.c
  112. +34 −25 input.c
  113. +52 −13 job.c
  114. +27 −28 key-bindings.c
  115. +63 −23 key-string.c
  116. +15 −11 layout-set.c
  117. +169 −0 layout-string.c
  118. +41 −35 layout.c
  119. +2 −2 log.c
  120. +62 −26 mode-key.c
  121. +49 −51 names.c
  122. +0 −263 options-cmd.c
  123. +12 −20 osdep-openbsd.c
  124. +26 −4 paste.c
  125. +83 −43 screen-redraw.c
  126. +45 −49 screen-write.c
  127. +83 −22 screen.c
  128. +229 −242 server-client.c
  129. +77 −16 server-fn.c
  130. +0 −73 server-job.c
  131. +23 −135 server-window.c
  132. +301 −337 server.c
  133. +14 −15 session.c
  134. +471 −360 status.c
  135. +373 −84 tmux.1
  136. +243 −203 tmux.c
  137. +192 −192 tmux.h
  138. +412 −204 tty-keys.c
  139. +13 −24 tty-term.c
  140. +216 −129 tty.c
  141. +94 −12 window-choose.c
  142. +4 −4 window-clock.c
  143. +439 −148 window-copy.c
  144. +17 −4 window-more.c
  145. +56 −32 window.c
  146. +37 −24 xterm-keys.c
View
59 CHANGES
@@ -1,3 +1,60 @@
+CHANGES FROM 1.1 TO 1.2, 10 March 2010
+
+* Switch to libevent.
+* Emulate the ri (reverse index) capability, ergo allowing tmux to at least
+ start on Sun consoles (TERM=sun, or sun-color).
+* Assign each entry a number, or lowercase letter in choose mode, and accept
+ that as a shortcut key.
+* Permit top-bit-set characters to be entered in the status line.
+* Mark no-prefix keys with (no prefix), rather than [] in list-keys.
+* New command show-messages (alias showmsgs), and new session option
+ message-limit, to show a per-client log of status lines messages up to the
+ number defined by message-limit.
+* Do not interpret #() for display-message to avoid leaking commands.
+* New window options window-status-format, and window-status-current-format to
+ control the format of each window in the status line.
+* Add a -p flag to display-message to print the output, instead of displaying
+ it in the status line.
+* Emulate il1, dl1, ich1 to run with vt100 feature set.
+* New command capture-pane (alias capturep) to copy the entire pane contents
+ to a paste buffer.
+* Avoid duplicating code by adding a -w flag to set-option, and show-options to
+ set, and show window options. The commands set-window-option, and
+ show-window-options are now aliases.
+* Panes can now be referred to as top, bottom, top-left, etc.
+* Add server-wide options, which can be set with set-option -s, and shown with
+ show-options -s.
+* New server option quiet (like -q from the command line).
+* New server option escape-time to set the timeout used to detect if escapes
+ are alone, part of a function key, or meta sequence.
+* New session options pane-active-border-bg, pane-active-border-fg,
+ pane-border-bg, and pane-border-fg to set pane colours.
+* Make split-window accept a pane target, instead of a window.
+* New command join-pane (alias joinp) to split, and move an existing pane into
+ the space (the opposite of break-pane), thus simplifying calls to
+ split-window, followed by move-window.
+* Permit S- prefix on keys for shift when the terminal/terminfo supports them.
+* Window targets (-t flag) can now refer to the last window (!), next (+), and
+ previous (-) window by number.
+* Mode keys to jump to the bottom/top of history, end of the next word, scroll
+ up/down, and reverse search in copy mode.
+* New session option display-panes-active-colour to display the active pane in
+ a different colour with the display-panes command.
+* Read the socket path from $TMUX if it's present, and -L, and -S are not
+ given.
+* Vi-style mode keys B, W, and E to navigate between words in copy mode.
+* Start in more mode when configuration file errors are detected.
+* Rectangle copy support added.
+* If attach-session was specified with the -r flag, make the client read-only.
+* Per-window alternate-screen option.
+* Make load-buffer work with FIFOs.
+* New window option word-separators to set the characters considered as word
+ separators in copy mode.
+* Permit keys in copy mode to be prefixed by a repeat count, entered with [1-9]
+ in vi mode, or M-[1-9] in emacs mode.
+* utf8 improvements.
+* As usual, additional code reduction, bug fixes, and manpage enhancements.
+
CHANGES FROM 1.0 TO 1.1, 05 November 2009
* New run-shell (alias run) command to run an external command without a
@@ -1410,7 +1467,7 @@ The list of older changes is below.
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.301 2009/11/05 12:35:47 tcunha Exp $
+$Id: CHANGES,v 1.302 2010/03/10 15:18:11 tcunha Exp $
LocalWords: showw utf UTF fulvio ciriaco joshe OSC APC gettime abc DEF OA clr
LocalWords: rivo nurges lscm Erdely eol smysession mysession ek dstname RB ms
View
58 FAQ
@@ -1,5 +1,17 @@
tmux frequently asked questions
+******************************************************************************
+* PLEASE NOTE: most display problems are due to incorrect TERM! Before *
+* reporting problems make SURE that TERM settings are correct inside and *
+* outside tmux. *
+* *
+* Inside tmux TERM must be "screen" or similar (such as "screen-256color"). *
+* Don't bother reporting problems where it isn't! *
+* *
+* Outside, it must match your terminal: particularly, use "rxvt" for rxvt *
+* and derivatives. *
+******************************************************************************
+
* How is tmux different from GNU screen? What else does it offer?
tmux offers several advantages over screen:
@@ -26,8 +38,9 @@ There are still a few features screen includes that tmux omits:
* I found a bug! What do I do?
-Please send bug reports by email to nicm@users.sourceforge.net. Please
-include as much of the following information as possible:
+Please send bug reports by email to nicm@users.sourceforge.net or
+tmux-users@lists.sourceforge.net. Please include as much of the following
+information as possible:
- the version of tmux you are running;
- the operating system you are using and its version;
@@ -82,19 +95,17 @@ default) to the new key. For example:
* How do I use UTF-8?
-When running tmux in a UTF-8 capable terminal, two things must be done to
-enable support. UTF-8 must be turned on in tmux; this may be done separately
-for each tmux window or globally by setting the "utf8" flag:
-
- setw -g utf8 on
-
-As of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
+When running tmux in a UTF-8 capable terminal, UTF-8 must be turned on in tmux;
+as of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
be used to check if this is detected correctly; if not, the -u command-line
flag may be specified when creating or attaching a client to a tmux session:
$ tmux -u new
+Since the 1.0 release, tmux will turn on UTF-8 related options automatically
+(ie status-utf8, and utf8) if the above conditions are met.
+
* How do I use a 256 colour terminal?
Provided the underlying terminal supports 256 colours, it is usually sufficient
@@ -201,4 +212,31 @@ on the Window -> Translation configuration page. For example, change UTF-8 to
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
line drawing characters in the lower part of the same configuration page.
-$Id: FAQ,v 1.29 2009/08/08 20:46:26 nicm Exp $
+* What is the best way to display the load average? Why no #L?
+
+It isn't possible to get the load average portably in code and it is preferable
+not to add portability goop. The following works on at least Linux, *BSD and OS
+X:
+
+uptime|awk '{split(substr($0, index($0, "load")), a, ":"); print a[2]}'
+
+* How do I attach the same session to multiple clients but with a different
+ current window, like screen -x?
+
+One or more of the windows can be linked into multiple sessions manually with
+link-window, or a grouped session with all the windows can be created with
+new-session -t.
+
+* Ctrl and arrow keys doesn't work in putty! What do I do?
+
+putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for
+tmux to detect properly. To get ctrl keys right, change the terminfo settings
+so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux
+doesn't change the mode. For example with this line in .tmux.conf (assuming you
+have TERM set to xterm):
+
+set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"
+
+Note that this will only work in tmux 1.2 and above.
+
+$Id: FAQ,v 1.36 2010/02/04 21:01:59 nicm Exp $
View
4 GNUmakefile
@@ -1,4 +1,4 @@
-# $Id: GNUmakefile,v 1.120 2009/11/05 12:30:55 tcunha Exp $
+# $Id: GNUmakefile,v 1.122 2010/03/10 15:15:33 tcunha Exp $
#
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
#
@@ -17,7 +17,7 @@
.PHONY: clean
-VERSION= 1.1
+VERSION= 1.2
#FDEBUG= 1
View
4 Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.153 2009/11/05 12:30:55 tcunha Exp $
+# $Id: Makefile,v 1.155 2010/03/10 15:15:33 tcunha Exp $
#
# Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
#
@@ -18,7 +18,7 @@
.SUFFIXES: .c .o
.PHONY: clean
-VERSION= 1.1
+VERSION= 1.2
#FDEBUG= 1
View
14 NOTES
@@ -9,12 +9,10 @@ run on Solaris and AIX (although they haven't been tested in a while). It is
usable, although there remain a number of missing features and some remaining
bugs are expected.
-If upgrading from 1.0, PLEASE NOTE:
-- The internal locking mechanism has gone, so the set-password command and -U
- command line option have been removed.
-- The -d command line flag was dropped. It will now automatically detect the
- default colours by using op/AX. Nevertheless, if needed, the
- terminal-overrides session option can replace it.
+Since the 1.2 release that tmux depends on libevent. Download the stable
+version from:
+
+ http://www.monkey.org/~provos/libevent/
tmux consists of a server part and multiple clients. The server is created when
required and runs continuously unless killed by the user. Clients access the
@@ -51,7 +49,7 @@ are missing it may refuse to run, or not behave correctly.
tmux supports UTF-8. To use it, the utf8 option must be set on each window;
this may be turned on for all windows by setting it as a global option, see
tmux(1) and the FAQ file. As of 0.9, tmux attempts to autodetect a
-UTF-8-capable terminal by checking the LC_ALL, LC_CTYPE and LANG environment
+UTF-8 capable terminal by checking the LC_ALL, LC_CTYPE and LANG environment
variables. list-clients may be used to check if this is detected correctly; if
not, the -u command-line flag may be specified.
@@ -88,4 +86,4 @@ start. Please contact me with any queries.
-- Nicholas Marriott <nicm@users.sf.net>
-$Id: NOTES,v 1.51 2009/11/05 12:35:47 tcunha Exp $
+$Id: NOTES,v 1.53 2010/03/10 15:18:11 tcunha Exp $
View
72 TODO
@@ -38,8 +38,8 @@
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
$HOME/.tmux-session.conf
- get it passing all the vttest tests that don't require resizing the terminal
-- esc seq to set window title should be documented and should set
- automatic-rename
+- esc seq to set window name and title should be documented, and name variant
+ should clear automatic-rename
- way to set socket path from config file
- XXX once env stuff is in, default-path and VISUAL/EDITOR should be picked up
when session is started
@@ -56,9 +56,6 @@
- a way for force-width/height to apply to only one pane (how?)
- command to list what is actually running in each window with command line,
pid (need some adaption of the osdep code)
-- string option to change/remove the symbols (*-+ etc) in status line
- * or to set entire format, eg window-list-format '#N:#W#P' or something,
- then could use embedded colours
- support for bce
- it would be nice if the start/end line keys in copy mode were aware of
wrapped lines
@@ -68,7 +65,6 @@
for redraw
- handle resize better in copy mode
- way to copy stuff that is off screen due to resize
-- a way to address panes by name ("top-left") and position ("0,0")
- commands should be able to succeed or fail and have || or && for command
lists
- support the mouse wheel to scroll through history
@@ -78,20 +74,62 @@
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
the terminal - www/ruby-addressable; make regress
- copy mode needs a tidy/cleanup
-- things like display-message will leak job entries if #() is used
-- message log
-- an option to NOT remove message when key pressed
-- would be nice to be able to press 0-9a-zA-Z to select window in choose-window
- mode, also to start typing and it searches
-- the wrapping stuff should work when redrawn from scroll mode too (screen_write_copy)
- ability to save history (to buffer?)
- multiple keys could be done with tables, ie have prefixes go and instead
bind -n ^A prefix-table "default"
- where prefix-table sets command lookup table and sets prefix flag, then next key
- is looked up in that table
-- check fix UTF-8 and split-window? should be okay
+ where prefix-table sets command lookup table and sets prefix flag, then next
+ key is looked up in that table
- UTF-8 should be a pointer into a combined string buffer
- check irssi (term_charset) works with UTF-8
-- rectangle copy/paste
-- half page/up down are missing from key table
- support esc-esc to quit in modes
+- fix ctrl+F1-F4 output. to what?
+- look into xterm clearing its selection when scrolling etc
+- better utf8 support:
+ window names
+ prompt input
+ message display
+ copy and paste cursor and wide characters
+ ...?
+- option so that when session is destroyed, attach client to another session
+ rather than exiting
+- session history for client and last-session command
+- option to change status line colour when current window is in a mode?
+- option to move copy mode indicator into status line
+- list-buffer/show-buffer should display UTF-8
+- selection behaviour closer to vi in vi mode
+- live update: server started with -U connects to server, requests sessions and
+ windows, receives fds
+- convert status line history to be server global (anything else?)
+- something for -t "last window in session" so a session can be used as a stack
+- command to show a tree of sessions-windows-panes (active marked with *)
+- sort out inheriting config from shell on new sessions/windows:
+ should pick up default-path/termios/etc from client if possible,
+ else leave empty/default
+- define custom layouts
+- link panes into multiple windows
+- -h option to capture-pane to capture the history as well
+- bells should be passed between sessions with visual-bell etc
+- use screen-256color when started on 256 colour terminal??
+- if-shell/run-shell should block further command execution in the same command
+ sequence until its shell exits, to allow them to be used from the config file
+- better session sharing: create-socket command to create socket somewhere (-r
+ flag for readonly)
+- allow buffer to be specified when copying in copy mode
+- multiline status line
+- flag for absolute pane size to resize-pane
+- sanity check input to socket
+- stdin fd should be passed up to parent so load-buffer and others could use it
+ for nonattaching clients
+- environment should be set up for jobs
+- select-buffer command
+- fix jobs so they block in config file rather than executing at an arbitrary
+ future point -- need state stored in client so other clients can proceed
+- rectangle copy:
+ when selecting leftward, cursor should be inside block per emacs
+ key to rotate corner at which cursor is
+- double C-a should walk back over wrapped lines like C-e
+- support title stack, both internally and externally
+ http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
+- copy buffers should be global, limit can be server option, nuke copy-buffer
+ command
+- command to show status line information briefly when it is off
View
4 array.h
@@ -1,4 +1,4 @@
-/* $Id: array.h,v 1.9 2009/11/02 21:34:32 tcunha Exp $ */
+/* $Id: array.h,v 1.10 2010/02/08 18:29:32 tcunha Exp $ */
/*
* Copyright (c) 2006 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -19,6 +19,8 @@
#ifndef ARRAY_H
#define ARRAY_H
+#define ARRAY_INITIALIZER { NULL, 0, 0 }
+
#define ARRAY_DECL(n, c) \
struct n { \
c *list; \
View
42 attributes.c
@@ -1,4 +1,4 @@
-/* $Id: attributes.c,v 1.2 2009/06/25 15:25:45 nicm Exp $ */
+/* $Id: attributes.c,v 1.3 2009/11/28 14:46:23 tcunha Exp $ */
/*
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
@@ -23,29 +23,29 @@
#include "tmux.h"
const char *
-attributes_tostring(u_char ch)
+attributes_tostring(u_char attr)
{
static char buf[128];
- if (ch == 0)
+ if (attr == 0)
return ("default");
buf[0] = '\0';
- if (ch & GRID_ATTR_BRIGHT)
+ if (attr & GRID_ATTR_BRIGHT)
strlcat(buf, "bright,", sizeof (buf));
- if (ch & GRID_ATTR_DIM)
+ if (attr & GRID_ATTR_DIM)
strlcat(buf, "dim,", sizeof (buf));
- if (ch & GRID_ATTR_UNDERSCORE)
+ if (attr & GRID_ATTR_UNDERSCORE)
strlcat(buf, "underscore,", sizeof (buf));
- if (ch & GRID_ATTR_BLINK)
+ if (attr & GRID_ATTR_BLINK)
strlcat(buf, "blink,", sizeof (buf));
- if (ch & GRID_ATTR_REVERSE)
+ if (attr & GRID_ATTR_REVERSE)
strlcat(buf, "reverse,", sizeof (buf));
- if (ch & GRID_ATTR_HIDDEN)
+ if (attr & GRID_ATTR_HIDDEN)
strlcat(buf, "hidden,", sizeof (buf));
- if (ch & GRID_ATTR_ITALICS)
+ if (attr & GRID_ATTR_ITALICS)
strlcat(buf, "italics,", sizeof (buf));
- if (*buf)
+ if (*buf != '\0')
*(strrchr(buf, ',')) = '\0';
return (buf);
@@ -55,7 +55,7 @@ int
attributes_fromstring(const char *str)
{
const char delimiters[] = " ,|";
- u_char ch;
+ u_char attr;
size_t end;
if (*str == '\0' || strcspn(str, delimiters) == 0)
@@ -66,28 +66,28 @@ attributes_fromstring(const char *str)
if (strcasecmp(str, "default") == 0)
return (0);
- ch = 0;
+ attr = 0;
do {
end = strcspn(str, delimiters);
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
(end == 4 && strncasecmp(str, "bold", end) == 0))
- ch |= GRID_ATTR_BRIGHT;
+ attr |= GRID_ATTR_BRIGHT;
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
- ch |= GRID_ATTR_DIM;
+ attr |= GRID_ATTR_DIM;
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
- ch |= GRID_ATTR_UNDERSCORE;
+ attr |= GRID_ATTR_UNDERSCORE;
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
- ch |= GRID_ATTR_BLINK;
+ attr |= GRID_ATTR_BLINK;
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
- ch |= GRID_ATTR_REVERSE;
+ attr |= GRID_ATTR_REVERSE;
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
- ch |= GRID_ATTR_HIDDEN;
+ attr |= GRID_ATTR_HIDDEN;
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
- ch |= GRID_ATTR_ITALICS;
+ attr |= GRID_ATTR_ITALICS;
else
return (-1);
str += end + strspn(str + end, delimiters);
} while (*str != '\0');
- return (ch);
+ return (attr);
}
View
55 buffer-poll.c
@@ -1,55 +0,0 @@
-/* $Id: buffer-poll.c,v 1.18 2009/10/23 17:49:47 tcunha Exp $ */
-
-/*
- * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-
-#include <errno.h>
-#include <unistd.h>
-
-#include "tmux.h"
-
-/* Fill buffers from socket based on poll results. */
-int
-buffer_poll(int fd, int events, struct buffer *in, struct buffer *out)
-{
- ssize_t n;
-
- if (events & (POLLERR|POLLNVAL))
- return (-1);
- if (in != NULL && events & POLLIN) {
- buffer_ensure(in, BUFSIZ);
- n = read(fd, BUFFER_IN(in), BUFFER_FREE(in));
- if (n == 0)
- return (-1);
- if (n == -1) {
- if (errno != EINTR && errno != EAGAIN)
- return (-1);
- } else
- buffer_add(in, n);
- } else if (events & POLLHUP)
- return (-1);
- if (out != NULL && BUFFER_USED(out) > 0 && events & POLLOUT) {
- n = write(fd, BUFFER_OUT(out), BUFFER_USED(out));
- if (n == -1) {
- if (errno != EINTR && errno != EAGAIN)
- return (-1);
- } else
- buffer_remove(out, n);
- }
- return (0);
-}
View
139 buffer.c
@@ -1,139 +0,0 @@
-/* $Id: buffer.c,v 1.8 2009/08/21 21:09:13 tcunha Exp $ */
-
-/*
- * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-
-#include <string.h>
-
-#include "tmux.h"
-
-/* Create a buffer. */
-struct buffer *
-buffer_create(size_t size)
-{
- struct buffer *b;
-
- if (size == 0)
- fatalx("zero size");
-
- b = xcalloc(1, sizeof *b);
-
- b->base = xmalloc(size);
- b->space = size;
-
- return (b);
-}
-
-/* Destroy a buffer. */
-void
-buffer_destroy(struct buffer *b)
-{
- xfree(b->base);
- xfree(b);
-}
-
-/* Ensure free space for size in buffer. */
-void
-buffer_ensure(struct buffer *b, size_t size)
-{
- if (size == 0)
- fatalx("zero size");
-
- if (BUFFER_FREE(b) >= size)
- return;
-
- if (b->off > 0) {
- if (b->size > 0)
- memmove(b->base, b->base + b->off, b->size);
- b->off = 0;
- }
-
- if (SIZE_MAX - b->size < size)
- fatalx("size too big");
- while (b->space < b->size + size) {
- b->base = xrealloc(b->base, 2, b->space);
- b->space *= 2;
- }
-}
-
-/* Adjust buffer after data appended. */
-void
-buffer_add(struct buffer *b, size_t size)
-{
- if (size == 0)
- fatalx("zero size");
- if (size > b->space - b->size)
- fatalx("overflow");
-
- b->size += size;
-}
-
-/* Adjust buffer after data removed. */
-void
-buffer_remove(struct buffer *b, size_t size)
-{
- if (size == 0)
- fatalx("zero size");
- if (size > b->size)
- fatalx("underflow");
-
- b->size -= size;
- b->off += size;
-}
-
-/* Copy data into a buffer. */
-void
-buffer_write(struct buffer *b, const void *data, size_t size)
-{
- buffer_ensure(b, size);
- memcpy(BUFFER_IN(b), data, size);
- buffer_add(b, size);
-}
-
-/* Copy data out of a buffer. */
-void
-buffer_read(struct buffer *b, void *data, size_t size)
-{
- if (size == 0)
- fatalx("zero size");
- if (size > b->size)
- fatalx("underflow");
-
- memcpy(data, BUFFER_OUT(b), size);
- buffer_remove(b, size);
-}
-
-/* Store an 8-bit value. */
-void
-buffer_write8(struct buffer *b, uint8_t n)
-{
- buffer_ensure(b, 1);
- BUFFER_IN(b)[0] = n;
- b->size++;
-}
-
-/* Extract an 8-bit value. */
-uint8_t
-buffer_read8(struct buffer *b)
-{
- uint8_t n;
-
- n = BUFFER_OUT(b)[0];
- buffer_remove(b, 1);
- return (n);
-}
View
58 cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.23 2009/10/28 23:12:38 tcunha Exp $ */
+/* $Id: cfg.c,v 1.26 2010/02/08 18:29:32 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -33,13 +33,17 @@
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
-char *cfg_cause;
+char *cfg_cause;
+int cfg_finished;
+struct causelist cfg_causes = ARRAY_INITIALIZER;
+/* ARGSUSED */
void printflike2
cfg_print(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
{
}
+/* ARGSUSED */
void printflike2
cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
{
@@ -50,19 +54,36 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
va_end(ap);
}
+void printflike2
+cfg_add_cause(struct causelist *causes, const char *fmt, ...)
+{
+ char *cause;
+ va_list ap;
+
+ va_start(ap, fmt);
+ xvasprintf(&cause, fmt, ap);
+ va_end(ap);
+
+ ARRAY_ADD(causes, cause);
+}
+
+/*
+ * Load configuration file. Returns -1 for an error with a list of messages in
+ * causes. Note that causes and ncauses must be initialised by the caller!
+ */
int
-load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
+load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
{
FILE *f;
u_int n;
- char *buf, *line, *ptr;
+ char *buf, *line, *cause;
size_t len;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
if ((f = fopen(path, "rb")) == NULL) {
- xasprintf(cause, "%s: %s", path, strerror(errno));
- return (1);
+ cfg_add_cause(causes, "%s: %s", path, strerror(errno));
+ return (-1);
}
n = 0;
@@ -78,10 +99,12 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
}
n++;
- if (cmd_string_parse(buf, &cmdlist, cause) != 0) {
- if (*cause == NULL)
+ if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
+ if (cause == NULL)
continue;
- goto error;
+ cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
+ xfree(cause);
+ continue;
}
if (cmdlist == NULL)
continue;
@@ -105,23 +128,16 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
if (cfg_cause != NULL) {
- *cause = cfg_cause;
- goto error;
+ cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
+ xfree(cfg_cause);
+ continue;
}
}
if (line != NULL)
xfree(line);
fclose(f);
+ if (ARRAY_LENGTH(causes) != 0)
+ return (-1);
return (0);
-
-error:
- if (line != NULL)
- xfree(line);
- fclose(f);
-
- xasprintf(&ptr, "%s: %s at line %u", path, *cause, n);
- xfree(*cause);
- *cause = ptr;
- return (1);
}
View
226 client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.84 2009/11/02 21:41:16 tcunha Exp $ */
+/* $Id: client.c,v 1.90 2009/12/04 22:14:47 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,6 +24,7 @@
#include <sys/wait.h>
#include <errno.h>
+#include <event.h>
#include <fcntl.h>
#include <pwd.h>
#include <stdlib.h>
@@ -34,13 +35,17 @@
#include "tmux.h"
struct imsgbuf client_ibuf;
+struct event client_event;
const char *client_exitmsg;
+int client_exitval;
-void client_send_identify(int);
-void client_send_environ(void);
-void client_write_server(enum msgtype, void *, size_t);
-int client_dispatch(void);
-void client_suspend(void);
+void client_send_identify(int);
+void client_send_environ(void);
+void client_write_server(enum msgtype, void *, size_t);
+void client_update_event(void);
+void client_signal(int, short, void *);
+void client_callback(int, short, void *);
+int client_dispatch(void);
struct imsgbuf *
client_init(char *path, int cmdflags, int flags)
@@ -124,7 +129,7 @@ client_send_identify(int flags)
if (getcwd(data.cwd, sizeof data.cwd) == NULL)
*data.cwd = '\0';
-
+
term = getenv("TERM");
if (term == NULL ||
strlcpy(data.term, term, sizeof data.term) >= sizeof data.term)
@@ -142,7 +147,7 @@ client_send_environ(void)
struct msg_environ_data data;
char **var;
- for (var = environ; *var != NULL; var++) {
+ for (var = environ; *var != NULL; var++) {
if (strlcpy(data.var, *var, sizeof data.var) >= sizeof data.var)
continue;
client_write_server(MSG_ENVIRON, &data, sizeof data);
@@ -152,99 +157,140 @@ client_send_environ(void)
void
client_write_server(enum msgtype type, void *buf, size_t len)
{
- imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
+ imsg_compose(&client_ibuf, type, PROTOCOL_VERSION, -1, -1, buf, len);
+}
+
+void
+client_update_event(void)
+{
+ short events;
+
+ event_del(&client_event);
+ events = EV_READ;
+ if (client_ibuf.w.queued > 0)
+ events |= EV_WRITE;
+ event_set(&client_event, client_ibuf.fd, events, client_callback, NULL);
+ event_add(&client_event, NULL);
}
__dead void
client_main(void)
{
- struct pollfd pfd;
- int n, nfds;
-
- siginit();
+ struct event ev_sigcont, ev_sigterm, ev_sigwinch;
+ struct sigaction sigact;
logfile("client");
+ /* Note: event_init() has already been called. */
+
+ /* Set up signals. */
+ memset(&sigact, 0, sizeof sigact);
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_flags = SA_RESTART;
+ sigact.sa_handler = SIG_IGN;
+ if (sigaction(SIGINT, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ if (sigaction(SIGPIPE, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ if (sigaction(SIGUSR1, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ if (sigaction(SIGUSR2, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ if (sigaction(SIGTSTP, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+
+ signal_set(&ev_sigcont, SIGCONT, client_signal, NULL);
+ signal_add(&ev_sigcont, NULL);
+ signal_set(&ev_sigterm, SIGTERM, client_signal, NULL);
+ signal_add(&ev_sigterm, NULL);
+ signal_set(&ev_sigwinch, SIGWINCH, client_signal, NULL);
+ signal_add(&ev_sigwinch, NULL);
+
/*
* imsg_read in the first client poll loop (before the terminal has
- * been initialiased) may have read messages into the buffer after the
- * MSG_READY switched to here. Process anything outstanding now so poll
- * doesn't hang waiting for messages that have already arrived.
+ * been initialised) may have read messages into the buffer after the
+ * MSG_READY switched to here. Process anything outstanding now to
+ * avoid hanging waiting for messages that have already arrived.
*/
if (client_dispatch() != 0)
goto out;
- for (;;) {
- if (sigterm) {
- client_exitmsg = "terminated";
- client_write_server(MSG_EXITING, NULL, 0);
- }
- if (sigchld) {
- sigchld = 0;
- waitpid(WAIT_ANY, NULL, WNOHANG);
- continue;
- }
- if (sigwinch) {
- sigwinch = 0;
- client_write_server(MSG_RESIZE, NULL, 0);
- continue;
- }
- if (sigcont) {
- sigcont = 0;
- siginit();
- client_write_server(MSG_WAKEUP, NULL, 0);
- continue;
- }
+ /* Set the event and dispatch. */
+ client_update_event();
+ event_dispatch();
- pfd.fd = client_ibuf.fd;
- pfd.events = POLLIN;
- if (client_ibuf.w.queued > 0)
- pfd.events |= POLLOUT;
-
- if ((nfds = poll(&pfd, 1, INFTIM)) == -1) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- fatal("poll failed");
- }
- if (nfds == 0)
- continue;
+out:
+ /* Print the exit message, if any, and exit. */
+ if (client_exitmsg != NULL && !login_shell)
+ printf("[%s]\n", client_exitmsg);
+ exit(client_exitval);
+}
- if (pfd.revents & (POLLERR|POLLHUP|POLLNVAL))
- fatalx("socket error");
+/* ARGSUSED */
+void
+client_signal(int sig, unused short events, unused void *data)
+{
+ struct sigaction sigact;
+
+ switch (sig) {
+ case SIGTERM:
+ client_exitmsg = "terminated";
+ client_exitval = 1;
+ client_write_server(MSG_EXITING, NULL, 0);
+ break;
+ case SIGWINCH:
+ client_write_server(MSG_RESIZE, NULL, 0);
+ break;
+ case SIGCONT:
+ memset(&sigact, 0, sizeof sigact);
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_flags = SA_RESTART;
+ sigact.sa_handler = SIG_IGN;
+ if (sigaction(SIGTSTP, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ client_write_server(MSG_WAKEUP, NULL, 0);
+ break;
+ }
- if (pfd.revents & POLLIN) {
- if ((n = imsg_read(&client_ibuf)) == -1 || n == 0) {
- client_exitmsg = "lost server";
- break;
- }
- if (client_dispatch() != 0)
- break;
- }
+ client_update_event();
+}
- if (pfd.revents & POLLOUT) {
- if (msgbuf_write(&client_ibuf.w) < 0) {
- client_exitmsg = "lost server";
- break;
- }
+/* ARGSUSED */
+void
+client_callback(unused int fd, short events, unused void *data)
+{
+ ssize_t n;
+
+ if (events & EV_READ) {
+ if ((n = imsg_read(&client_ibuf)) == -1 || n == 0)
+ goto lost_server;
+ if (client_dispatch() != 0) {
+ event_loopexit(NULL);
+ return;
}
}
-out:
- /* Print the exit message, if any, and exit. */
- if (client_exitmsg != NULL) {
- if (!login_shell)
- printf("[%s]\n", client_exitmsg);
- exit(1);
+ if (events & EV_WRITE) {
+ if (msgbuf_write(&client_ibuf.w) < 0)
+ goto lost_server;
}
- exit(0);
+
+ client_update_event();
+ return;
+
+lost_server:
+ client_exitmsg = "lost server";
+ client_exitval = 1;
+ event_loopexit(NULL);
}
int
client_dispatch(void)
{
- struct imsg imsg;
- struct msg_lock_data lockdata;
- ssize_t n, datalen;
+ struct imsg imsg;
+ struct msg_lock_data lockdata;
+ struct sigaction sigact;
+ ssize_t n, datalen;
for (;;) {
if ((n = imsg_get(&client_ibuf, &imsg)) == -1)
@@ -253,6 +299,7 @@ client_dispatch(void)
return (0);
datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+ log_debug("client got %d", imsg.hdr.type);
switch (imsg.hdr.type) {
case MSG_DETACH:
if (datalen != 0)
@@ -280,18 +327,25 @@ client_dispatch(void)
client_write_server(MSG_EXITING, NULL, 0);
client_exitmsg = "server exited";
+ client_exitval = 1;
break;
case MSG_SUSPEND:
if (datalen != 0)
fatalx("bad MSG_SUSPEND size");
- client_suspend();
+ memset(&sigact, 0, sizeof sigact);
+ sigemptyset(&sigact.sa_mask);
+ sigact.sa_flags = SA_RESTART;
+ sigact.sa_handler = SIG_DFL;
+ if (sigaction(SIGTSTP, &sigact, NULL) != 0)
+ fatal("sigaction failed");
+ kill(getpid(), SIGTSTP);
break;
case MSG_LOCK:
if (datalen != sizeof lockdata)
fatalx("bad MSG_LOCK size");
memcpy(&lockdata, imsg.data, sizeof lockdata);
-
+
lockdata.cmd[(sizeof lockdata.cmd) - 1] = '\0';
system(lockdata.cmd);
client_write_server(MSG_UNLOCK, NULL, 0);
@@ -303,23 +357,3 @@ client_dispatch(void)
imsg_free(&imsg);
}
}
-
-void
-client_suspend(void)
-{
- struct sigaction act;
-
- memset(&act, 0, sizeof act);
- sigemptyset(&act.sa_mask);
- act.sa_flags = SA_RESTART;
-
- act.sa_handler = SIG_DFL;
- if (sigaction(SIGTSTP, &act, NULL) != 0)
- fatal("sigaction failed");
-
- act.sa_handler = sighandler;
- if (sigaction(SIGCONT, &act, NULL) != 0)
- fatal("sigaction failed");
-
- kill(getpid(), SIGTSTP);
-}
View
12 clock.c
@@ -1,4 +1,4 @@
-/* $Id: clock.c,v 1.7 2009/09/11 14:13:52 tcunha Exp $ */
+/* $Id: clock.c,v 1.9 2009/12/04 22:14:47 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -97,7 +97,7 @@ const char clock_table[14][5][5] = {
};
void
-clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
+clock_draw(struct screen_write_ctx *ctx, int colour, int style)
{
struct screen *s = ctx->s;
struct grid_cell gc;
@@ -134,13 +134,13 @@ clock_draw(struct screen_write_ctx *ctx, u_int colour, int style)
for (ptr = tim; *ptr != '\0'; ptr++) {
if (*ptr >= '0' && *ptr <= '9')
idx = *ptr - '0';
- else if (*ptr == ':')
+ else if (*ptr == ':')
idx = 10;
- else if (*ptr == 'A')
+ else if (*ptr == 'A')
idx = 11;
- else if (*ptr == 'P')
+ else if (*ptr == 'P')
idx = 12;
- else if (*ptr == 'M')
+ else if (*ptr == 'M')
idx = 13;
else {
x += 6;
View
18 cmd-attach-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-attach-session.c,v 1.32 2009/08/09 17:48:55 tcunha Exp $ */
+/* $Id: cmd-attach-session.c,v 1.36 2010/02/08 18:27:34 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -28,8 +28,8 @@ int cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
- "[-d] " CMD_TARGET_SESSION_USAGE,
- CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, CMD_CHFLAG('d'),
+ "[-dr] " CMD_TARGET_SESSION_USAGE,
+ CMD_CANTNEST|CMD_STARTSERVER|CMD_SENDENVIRON, "dr",
cmd_target_init,
cmd_target_parse,
cmd_attach_session_exec,
@@ -58,8 +58,8 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
if (ctx->cmdclient == NULL) {
- if (data->chflags & CMD_CHFLAG('d')) {
- /*
+ if (cmd_check_flag(data->chflags, 'd')) {
+ /*
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
*/
@@ -72,7 +72,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(c, MSG_DETACH, NULL, 0);
}
}
-
+
ctx->curclient->session = s;
server_redraw_client(ctx->curclient);
} else {
@@ -89,7 +89,10 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
- if (data->chflags & CMD_CHFLAG('d'))
+ if (cmd_check_flag(data->chflags, 'r'))
+ ctx->cmdclient->flags |= CLIENT_READONLY;
+
+ if (cmd_check_flag(data->chflags, 'd'))
server_write_session(s, MSG_DETACH, NULL, 0);
ctx->cmdclient->session = s;
@@ -101,6 +104,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(ctx->cmdclient);
}
recalculate_sizes();
+ server_update_socket();
return (1); /* 1 means don't tell command client to exit */
}
View
9 cmd-bind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-bind-key.c,v 1.25 2009/07/28 23:19:06 tcunha Exp $ */
+/* $Id: cmd-bind-key.c,v 1.28 2010/01/25 17:12:44 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -46,7 +46,7 @@ struct cmd_bind_key_data {
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
"[-cnr] [-t key-table] key command [arguments]",
- 0, 0,
+ 0, "",
NULL,
cmd_bind_key_parse,
cmd_bind_key_exec,
@@ -79,7 +79,8 @@ cmd_bind_key_parse(struct cmd *self, int argc, char **argv, char **cause)
data->can_repeat = 1;
break;
case 't':
- data->tablename = xstrdup(optarg);
+ if (data->tablename == NULL)
+ data->tablename = xstrdup(optarg);
break;
default:
goto usage;
@@ -152,7 +153,7 @@ cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx)
ctx->error(ctx, "unknown command: %s", data->modecmd);
return (-1);
}
-
+
mtmp.key = data->key & ~KEYC_PREFIX;
mtmp.mode = data->command_key ? 1 : 0;
if ((mbind = SPLAY_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
View
20 cmd-break-pane.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-break-pane.c,v 1.9 2009/10/11 23:38:16 tcunha Exp $ */
+/* $Id: cmd-break-pane.c,v 1.11 2009/12/04 22:14:47 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,7 +31,7 @@ int cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_break_pane_entry = {
"break-pane", "breakp",
CMD_TARGET_PANE_USAGE " [-d]",
- 0, CMD_CHFLAG('d'),
+ 0, "d",
cmd_target_init,
cmd_target_parse,
cmd_break_pane_exec,
@@ -64,18 +64,18 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
if (wl->window->active == NULL)
wl->window->active = TAILQ_NEXT(wp, entry);
}
- layout_close_pane(wp);
+ layout_close_pane(wp);
- w = wp->window = window_create1(s->sx, s->sy);
- TAILQ_INSERT_HEAD(&w->panes, wp, entry);
- w->active = wp;
- w->name = default_window_name(w);
+ w = wp->window = window_create1(s->sx, s->sy);
+ TAILQ_INSERT_HEAD(&w->panes, wp, entry);
+ w->active = wp;
+ w->name = default_window_name(w);
layout_init(w);
base_idx = options_get_number(&s->options, "base-index");
- wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
- if (!(data->chflags & CMD_CHFLAG('d')))
- session_select(s, wl->idx);
+ wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
+ if (!cmd_check_flag(data->chflags, 'd'))
+ session_select(s, wl->idx);
server_redraw_session(s);
server_status_session_group(s);
View
83 cmd-capture-pane.c
@@ -0,0 +1,83 @@
+/* $Id: cmd-capture-pane.c,v 1.3 2010/01/22 17:29:19 tcunha Exp $ */
+
+/*
+ * Copyright (c) 2009 Jonathan Alvarado <radobobo@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <string.h>
+
+#include "tmux.h"
+
+/*
+ * Write the entire contents of a pane to a buffer.
+ */
+
+int cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_capture_pane_entry = {
+ "capture-pane", "capturep",
+ CMD_BUFFER_PANE_USAGE,
+ 0, "",
+ cmd_buffer_init,
+ cmd_buffer_parse,
+ cmd_capture_pane_exec,
+ cmd_buffer_free,
+ cmd_buffer_print
+};
+
+int
+cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_buffer_data *data = self->data;
+ struct window_pane *wp;
+ char *buf, *line;
+ struct screen *s;
+ struct session *sess;
+ u_int i, limit;
+ size_t len, linelen;
+
+ if (cmd_find_pane(ctx, data->target, &sess, &wp) == NULL)
+ return (-1);
+ s = &wp->base;
+
+ buf = NULL;
+ len = 0;
+
+ for (i = 0; i < screen_size_y(s); i++) {
+ line = grid_view_string_cells(s->grid, 0, i, screen_size_x(s));
+ linelen = strlen(line);
+
+ buf = xrealloc(buf, 1, len + linelen + 1);
+ memcpy(buf + len, line, linelen);
+ len += linelen;
+ buf[len++] = '\n';
+
+ xfree(line);
+ }
+
+ limit = options_get_number(&sess->options, "buffer-limit");
+ if (data->buffer == -1) {
+ paste_add(&sess->buffers, buf, len, limit);
+ return (0);
+ }
+ if (paste_replace(&sess->buffers, data->buffer, buf, len) != 0) {
+ ctx->error(ctx, "no buffer %d", data->buffer);
+ xfree(buf);
+ return (-1);
+ }
+ return (0);
+}
View
4 cmd-choose-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-choose-client.c,v 1.3 2009/09/07 23:59:19 tcunha Exp $ */
+/* $Id: cmd-choose-client.c,v 1.4 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,7 +34,7 @@ void cmd_choose_client_free(void *);
const struct cmd_entry cmd_choose_client_entry = {
"choose-client", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_client_exec,
View
4 cmd-choose-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-choose-session.c,v 1.14 2009/10/11 23:38:16 tcunha Exp $ */
+/* $Id: cmd-choose-session.c,v 1.15 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,7 +34,7 @@ void cmd_choose_session_free(void *);
const struct cmd_entry cmd_choose_session_entry = {
"choose-session", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_session_exec,
View
10 cmd-choose-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-choose-window.c,v 1.18 2009/10/11 23:38:16 tcunha Exp $ */
+/* $Id: cmd-choose-window.c,v 1.20 2009/12/04 22:14:47 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,7 +34,7 @@ void cmd_choose_window_free(void *);
const struct cmd_entry cmd_choose_window_entry = {
"choose-window", NULL,
CMD_TARGET_WINDOW_USAGE " [template]",
- CMD_ARG01, 0,
+ CMD_ARG01, "",
cmd_target_init,
cmd_target_parse,
cmd_choose_window_exec,
@@ -116,10 +116,10 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cdata->client = ctx->curclient;
cdata->client->references++;
- window_choose_ready(wl->window->active,
+ window_choose_ready(wl->window->active,
cur, cmd_choose_window_callback, cmd_choose_window_free, cdata);
- return (0);
+ return (0);
}
void
@@ -133,7 +133,7 @@ cmd_choose_window_callback(void *data, int idx)
if (idx == -1)
return;
if (cdata->client->flags & CLIENT_DEAD)
- return;
+ return;
if (cdata->session->flags & SESSION_DEAD)
return;
if (cdata->client->session != cdata->session)
View
4 cmd-clear-history.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-clear-history.c,v 1.7 2009/07/30 21:04:40 tcunha Exp $ */
+/* $Id: cmd-clear-history.c,v 1.8 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_clear_history_entry = {
"clear-history", "clearhist",
CMD_TARGET_PANE_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_clear_history_exec,
View
4 cmd-clock-mode.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-clock-mode.c,v 1.6 2009/08/20 11:37:46 tcunha Exp $ */
+/* $Id: cmd-clock-mode.c,v 1.7 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
CMD_TARGET_PANE_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_clock_mode_exec,
View
4 cmd-command-prompt.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-command-prompt.c,v 1.26 2009/09/22 14:06:40 tcunha Exp $ */
+/* $Id: cmd-command-prompt.c,v 1.27 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -39,7 +39,7 @@ void cmd_command_prompt_cfree(void *);
const struct cmd_entry cmd_command_prompt_entry = {
"command-prompt", NULL,
CMD_TARGET_CLIENT_USAGE " [-p prompts] [template]",
- 0, 0,
+ 0, "",
cmd_command_prompt_init,
cmd_command_prompt_parse,
cmd_command_prompt_exec,
View
4 cmd-confirm-before.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-confirm-before.c,v 1.11 2009/08/24 16:24:18 tcunha Exp $ */
+/* $Id: cmd-confirm-before.c,v 1.12 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -34,7 +34,7 @@ void cmd_confirm_before_free(void *);
const struct cmd_entry cmd_confirm_before_entry = {
"confirm-before", "confirm",
CMD_TARGET_CLIENT_USAGE " command",
- CMD_ARG1, 0,
+ CMD_ARG1, "",
cmd_confirm_before_init,
cmd_target_parse,
cmd_confirm_before_exec,
View
5 cmd-copy-buffer.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-copy-buffer.c,v 1.5 2009/09/22 14:06:40 tcunha Exp $ */
+/* $Id: cmd-copy-buffer.c,v 1.7 2009/11/28 14:50:36 tcunha Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -43,7 +43,7 @@ struct cmd_copy_buffer_data {
const struct cmd_entry cmd_copy_buffer_entry = {
"copy-buffer", "copyb",
"[-a src-index] [-b dst-index] [-s src-session] [-t dst-session]",
- 0, 0,
+ 0, "",
cmd_copy_buffer_init,
cmd_copy_buffer_parse,
cmd_copy_buffer_exec,
@@ -51,6 +51,7 @@ const struct cmd_entry cmd_copy_buffer_entry = {
cmd_copy_buffer_print
};
+/* ARGSUSED */
void
cmd_copy_buffer_init(struct cmd *self, unused int arg)
{
View
10 cmd-copy-mode.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-copy-mode.c,v 1.24 2009/10/06 14:14:06 tcunha Exp $ */
+/* $Id: cmd-copy-mode.c,v 1.26 2010/01/05 23:50:22 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -30,12 +30,12 @@ int cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL,
"[-u] " CMD_TARGET_PANE_USAGE,
- 0, CMD_CHFLAG('u'),
+ 0, "u",
cmd_copy_mode_init,
cmd_target_parse,
cmd_copy_mode_exec,
cmd_target_free,
- NULL
+ cmd_target_print
};
void
@@ -48,7 +48,7 @@ cmd_copy_mode_init(struct cmd *self, int key)
switch (key) {
case KEYC_PPAGE:
- data->chflags |= CMD_CHFLAG('u');
+ cmd_set_flag(&data->chflags, 'u');
break;
}
}
@@ -63,7 +63,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
window_pane_set_mode(wp, &window_copy_mode);
- if (wp->mode == &window_copy_mode && data->chflags & CMD_CHFLAG('u'))
+ if (wp->mode == &window_copy_mode && cmd_check_flag(data->chflags, 'u'))
window_copy_pageup(wp);
return (0);
View
4 cmd-delete-buffer.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-delete-buffer.c,v 1.7 2009/07/28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-delete-buffer.c,v 1.8 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -31,7 +31,7 @@ int cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_delete_buffer_entry = {
"delete-buffer", "deleteb",
CMD_BUFFER_SESSION_USAGE,
- 0, 0,
+ 0, "",
cmd_buffer_init,
cmd_buffer_parse,
cmd_delete_buffer_exec,
View
4 cmd-detach-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-detach-client.c,v 1.9 2009/07/28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-detach-client.c,v 1.11 2010/02/08 18:27:34 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
CMD_TARGET_CLIENT_USAGE,
- 0, 0,
+ CMD_READONLY, "",
cmd_target_init,
cmd_target_parse,
cmd_detach_client_exec,
View
13 cmd-display-message.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-display-message.c,v 1.3 2009/10/11 23:55:26 tcunha Exp $ */
+/* $Id: cmd-display-message.c,v 1.7 2009/11/28 14:39:53 tcunha Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -30,8 +30,8 @@ int cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_message_entry = {
"display-message", "display",
- CMD_TARGET_CLIENT_USAGE " [message]",
- CMD_ARG01, 0,
+ "[-p] " CMD_TARGET_CLIENT_USAGE " [message]",
+ CMD_ARG01, "p",
cmd_target_init,
cmd_target_parse,
cmd_display_message_exec,
@@ -55,8 +55,11 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
else
template = data->arg;
- msg = status_replace(c, template, time(NULL));
- status_message_set(c, "%s", msg);
+ msg = status_replace(c, NULL, template, time(NULL), 0);
+ if (cmd_check_flag(data->chflags, 'p'))
+ ctx->print(ctx, "%s", msg);
+ else
+ status_message_set(c, "%s", msg);
xfree(msg);
return (0);
View
4 cmd-display-panes.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-display-panes.c,v 1.1 2009/08/31 22:30:15 tcunha Exp $ */
+/* $Id: cmd-display-panes.c,v 1.2 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_display_panes_entry = {
"display-panes", "displayp",
CMD_TARGET_CLIENT_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_display_panes_exec,
View
5 cmd-down-pane.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-down-pane.c,v 1.12 2009/07/28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-down-pane.c,v 1.14 2010/01/05 23:52:37 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_down_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_down_pane_entry = {
"down-pane", "downp",
CMD_TARGET_WINDOW_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_down_pane_exec,
@@ -54,6 +54,7 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_FIRST(&w->panes);
} while (!window_pane_visible(w->active));
server_status_window(wl->window);
+ server_redraw_window_borders(wl->window);
return (0);
}
View
4 cmd-find-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-find-window.c,v 1.13 2009/07/28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-find-window.c,v 1.14 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,7 +34,7 @@ void cmd_find_window_callback(void *, int);
const struct cmd_entry cmd_find_window_entry = {
"find-window", "findw",
CMD_TARGET_WINDOW_USAGE " match-string",
- CMD_ARG1, 0,
+ CMD_ARG1, "",
cmd_target_init,
cmd_target_parse,
cmd_find_window_exec,
View
109 cmd-generic.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-generic.c,v 1.34 2009/08/26 22:13:52 tcunha Exp $ */
+/* $Id: cmd-generic.c,v 1.38 2009/12/04 22:14:47 tcunha Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -23,8 +23,8 @@
#include "tmux.h"
-int cmd_getopt(int, char **, const char *, uint64_t);
-int cmd_flags(int, uint64_t, uint64_t *);
+int cmd_getopt(int, char **, const char *, const char *);
+int cmd_parse_flags(int, const char *, uint64_t *);
size_t cmd_print_flags(char *, size_t, size_t, uint64_t);
int cmd_fill_argument(int, char **, char **, int, char **);
@@ -36,54 +36,56 @@ cmd_prarg(char *buf, size_t len, const char *prefix, char *arg)
return (xsnprintf(buf, len, "%s%s", prefix, arg));
}
-/* Prepend flags from chflags onto flagstr and call getopt. */
+/* Append two flag strings together and call getopt. */
int
-cmd_getopt(int argc, char **argv, const char *flagstr, uint64_t chflags)
+cmd_getopt(int argc, char **argv, const char *flagstr, const char *chflagstr)
{
- u_char ch;
- char buf[128];
- size_t len, off;
-
- *buf = '\0';
+ char tmp[BUFSIZ];
- len = sizeof buf;
- off = 0;
+ if (strlcpy(tmp, flagstr, sizeof tmp) >= sizeof tmp)
+ fatalx("strlcpy overflow");
+ if (strlcat(tmp, chflagstr, sizeof tmp) >= sizeof tmp)
+ fatalx("strlcat overflow");
+ return (getopt(argc, argv, tmp));
+}
- for (ch = 0; ch < 26; ch++) {
- if (chflags & CMD_CHFLAG('a' + ch))
- off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
- if (chflags & CMD_CHFLAG('A' + ch))
- off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
- }
-
- strlcat(buf, flagstr, sizeof buf);
+/* Return if flag character is set. */
+int
+cmd_check_flag(uint64_t chflags, int flag)
+{
+ if (flag >= 'A' && flag <= 'Z')
+ flag = 26 + flag - 'A';
+ else if (flag >= 'a' && flag <= 'z')
+ flag = flag - 'a';
+ else
+ return (0);
+ return ((chflags & (1ULL << flag)) != 0);
+}
- return (getopt(argc, argv, buf));
+/* Set flag character. */
+void
+cmd_set_flag(uint64_t *chflags, int flag)
+{
+ if (flag >= 'A' && flag <= 'Z')
+ flag = 26 + flag - 'A';
+ else if (flag >= 'a' && flag <= 'z')
+ flag = flag - 'a';
+ else
+ return;
+ (*chflags) |= (1ULL << flag);
}
-/*
- * If this option is expected (in ichflags), set it in ochflags, otherwise
- * return -1.
- */
+/* If this option is expected, set it in chflags, otherwise return -1. */
int
-cmd_flags(int opt, uint64_t ichflags, uint64_t *ochflags)
+cmd_parse_flags(int opt, const char *chflagstr, uint64_t *chflags)
{
- u_char ch;
-
- for (ch = 0; ch < 26; ch++) {
- if (opt == 'a' + ch && ichflags & CMD_CHFLAG(opt)) {
- (*ochflags) |= CMD_CHFLAG(opt);
- return (0);
- }
- if (opt == 'A' + ch && ichflags & CMD_CHFLAG(opt)) {
- (*ochflags) |= CMD_CHFLAG(opt);
- return (0);
- }
- }
- return (-1);
+ if (strchr(chflagstr, opt) == NULL)
+ return (-1);
+ cmd_set_flag(chflags, opt);
+ return (0);
}
-/* Print the flags supported in chflags. */
+/* Print the flags present in chflags. */
size_t
cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
{
@@ -95,9 +97,9 @@ cmd_print_flags(char *buf, size_t len, size_t off, uint64_t chflags)
off += xsnprintf(buf + off, len - off, " -");
for (ch = 0; ch < 26; ch++) {
- if (chflags & CMD_CHFLAG('a' + ch))
+ if (cmd_check_flag(chflags, 'a' + ch))
off += xsnprintf(buf + off, len - off, "%c", 'a' + ch);
- if (chflags & CMD_CHFLAG('A' + ch))
+ if (cmd_check_flag(chflags, 'A' + ch))
off += xsnprintf(buf + off, len - off, "%c", 'A' + ch);
}
return (off - boff);
@@ -139,13 +141,14 @@ cmd_fill_argument(int flags, char **arg, char **arg2, int argc, char **argv)
if (argc == 2)
*arg2 = xstrdup(argv[1]);
return (0);
- }
+ }
if (argc != 0)
return (-1);
return (0);
}
+/* ARGSUSED */
void
cmd_target_init(struct cmd *self, unused int key)
{
@@ -170,7 +173,7 @@ cmd_target_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 't':
@@ -222,13 +225,14 @@ cmd_target_print(struct cmd *self, char *buf, size_t len)
off += cmd_print_flags(buf, len, off, data->chflags);
if (off < len && data->target != NULL)
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
- if (off < len && data->arg != NULL)
+ if (off < len && data->arg != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg);
- if (off < len && data->arg2 != NULL)
+ if (off < len && data->arg2 != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
return (off);
}
+/* ARGSUSED */
void
cmd_srcdst_init(struct cmd *self, unused int key)
{
@@ -253,7 +257,7 @@ cmd_srcdst_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "s:t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 's':
@@ -313,13 +317,14 @@ cmd_srcdst_print(struct cmd *self, char *buf, size_t len)
off += xsnprintf(buf + off, len - off, " -s %s", data->src);
if (off < len && data->dst != NULL)
off += xsnprintf(buf + off, len - off, " -t %s", data->dst);
- if (off < len && data->arg != NULL)
+ if (off < len && data->arg != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg);
- if (off < len && data->arg2 != NULL)
+ if (off < len && data->arg2 != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
return (off);
}
+/* ARGSUSED */
void
cmd_buffer_init(struct cmd *self, unused int key)
{
@@ -345,7 +350,7 @@ cmd_buffer_parse(struct cmd *self, int argc, char **argv, char **cause)
data = self->data;
while ((opt = cmd_getopt(argc, argv, "b:t:", entry->chflags)) != -1) {
- if (cmd_flags(opt, entry->chflags, &data->chflags) == 0)
+ if (cmd_parse_flags(opt, entry->chflags, &data->chflags) == 0)
continue;
switch (opt) {
case 'b':
@@ -410,9 +415,9 @@ cmd_buffer_print(struct cmd *self, char *buf, size_t len)
off += xsnprintf(buf + off, len - off, " -b %d", data->buffer);
if (off < len && data->target != NULL)
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
- if (off < len && data->arg != NULL)
+ if (off < len && data->arg != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg);
- if (off < len && data->arg2 != NULL)
+ if (off < len && data->arg2 != NULL)
off += cmd_prarg(buf + off, len - off, " ", data->arg2);
return (off);
}
View
4 cmd-has-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-has-session.c,v 1.14 2009/07/28 22:12:16 tcunha Exp $ */
+/* $Id: cmd-has-session.c,v 1.15 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -29,7 +29,7 @@ int cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
CMD_TARGET_SESSION_USAGE,
- 0, 0,
+ 0, "",
cmd_target_init,
cmd_target_parse,
cmd_has_session_exec,
View
4 cmd-if-shell.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-if-shell.c,v 1.7 2009/11/02 21:38:26 tcunha Exp $ */
+/* $Id: cmd-if-shell.c,v 1.8 2009/11/14 17:56:39 tcunha Exp $ */
/*
* Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org>
@@ -36,7 +36,7 @@ void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
"shell-command command",
- CMD_ARG2, 0,
+ CMD_ARG2, "",
cmd_target_init,
cmd_target_parse,
cmd_if_shell_exec,
View
256 cmd-join-pane.c
@@ -0,0 +1,256 @@
+/* $Id: cmd-join-pane.c,v 1.2 2010/01/08 16:34:17 tcunha Exp $ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "tmux.h"
+
+/*
+ * Join a pane into another (like split/swap/kill).
+ */
+
+int cmd_join_pane_parse(struct cmd *, int, char **, char **);
+int cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
+void cmd_join_pane_free(struct cmd *);
+void cmd_join_pane_init(struct cmd *, int);
+size_t cmd_join_pane_print(struct cmd *, char *, size_t);
+
+struct cmd_join_pane_data {
+ char *src;
+ char *dst;
+ int flag_detached;
+ int flag_horizontal;
+ int percentage;
+ int size;
+};
+
+const struct cmd_entry cmd_join_pane_entry = {
+ "join-pane", "joinp",
+ "[-dhv] [-p percentage|-l size] [-t src-pane] [-t dst-pane] [command]",
+ 0, "",
+ cmd_join_pane_init,
+ cmd_join_pane_parse,
+ cmd_join_pane_exec,
+ cmd_join_pane_free,
+ cmd_join_pane_print
+};
+
+void
+cmd_join_pane_init(struct cmd *self, int key)
+{
+ struct cmd_join_pane_data *data;
+
+ self->data = data = xmalloc(sizeof *data);
+ data->src = NULL;
+ data->dst = NULL;
+ data->flag_detached = 0;
+ data->flag_horizontal = 0;
+ data->percentage = -1;
+ data->size = -1;
+
+ switch (key) {
+ case '%':
+ data->flag_horizontal = 1;
+ break;
+ case '"':
+ data->flag_horizontal = 0;
+ break;
+ }
+}
+
+int
+cmd_join_pane_parse(struct cmd *self, int argc, char **argv, char **cause)
+{
+ struct cmd_join_pane_data *data;
+ int opt;
+ const char *errstr;
+
+ self->entry->init(self, KEYC_NONE);
+ data = self->data;
+
+ while ((opt = getopt(argc, argv, "dhl:p:s:t:v")) != -1) {
+ switch (opt) {
+ case 'd':
+ data->flag_detached = 1;
+ break;
+ case 'h':
+ data->flag_horizontal = 1;
+ break;
+ case 's':
+ if (data->src == NULL)
+ data->src = xstrdup(optarg);
+ break;
+ case 't':
+ if (data->dst == NULL)
+ data->dst = xstrdup(optarg);
+ break;
+ case 'l':
+ if (data->percentage != -1 || data->size != -1)
+ break;
+ data->size = strtonum(optarg, 1, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "size %s", errstr);
+ goto error;
+ }
+ break;
+ case 'p':
+ if (data->size != -1 || data->percentage != -1)
+ break;
+ data->percentage = strtonum(optarg, 1, 100, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "percentage %s", errstr);
+ goto error;
+ }
+ break;
+ case 'v':
+ data->flag_horizontal = 0;
+ break;
+ default:
+ goto usage;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc != 0)
+ goto usage;
+
+ return (0);
+
+usage:
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
+
+error:
+ self->entry->free(self);
+ return (-1);
+}
+
+int
+cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
+{
+ struct cmd_join_pane_data *data = self->data;
+ struct session *dst_s;
+ struct winlink *src_wl, *dst_wl;
+ struct window *src_w, *dst_w;
+ struct window_pane *src_wp, *dst_wp;
+ int size;
+ enum layout_type type;
+ struct layout_cell *lc;
+
+ if ((dst_wl = cmd_find_pane(ctx, data->dst, &dst_s, &dst_wp)) == NULL)
+ return (-1);
+ dst_w = dst_wl->window;
+
+ if ((src_wl = cmd_find_pane(ctx, data->src, NULL, &src_wp)) == NULL)
+ return (-1);
+ src_w = src_wl->window;
+
+ if (src_w == dst_w) {
+ ctx->error(ctx, "can't join a pane to its own window");
+ return (-1);
+ }
+
+ type = LAYOUT_TOPBOTTOM;
+ if (data->flag_horizontal)
+ type = LAYOUT_LEFTRIGHT;
+
+ size = -1;
+ if (data->size != -1)
+ size = data->size;
+ else if (data->percentage != -1) {
+ if (type == LAYOUT_TOPBOTTOM)
+ size = (dst_wp->sy * data->percentage) / 100;
+ else
+ size = (dst_wp->sx * data->percentage) / 100;
+ }