266 Commits
Author SHA1 Message Date
Thomas Adam 1b083aa0fd Update CHANGES and configure.ac for 1.8 release. 2013-03-26 20:19:04 +00:00
Thomas 399a15b9fc Merge branch 'obsd-master' 2013-03-26 16:59:37 +00:00
Nicholas Marriott dfac36b6c3 Only accept partial keys if the timer has not expired, fixes infinite
loop when Escape is pressed the wrong number of times.
2013-03-26 14:14:08 +00:00
Nicholas Marriott 771d7db3a6 Fix compiler warnings, missing #include. From Thomas Adam. 2013-03-26 10:54:48 +00:00
Thomas 00af2df102 Merge branch 'obsd-master' 2013-03-25 16:30:37 +00:00
Nicholas Marriott be390c1991 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-25 16:13:22 +00:00
Nicholas Marriott 2fd0cb7600 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
Conflicts:
	TODO
	cmd-queue.c
	cmd-server-info.c
	cmd-wait-for.c
	tmux.1
2013-03-25 16:11:22 +00:00
Thomas Adam 5f5d413408 Remove compat/vis.h from cmd-save-buffer.
The include for compat.h in tmux.h takes care of this.

BUG-ID:  N/A
2013-03-25 16:09:34 +00:00
Nicholas Marriott 972da2d498 Try to establish client for run-shell and if-shell if no -t. 2013-03-25 16:04:07 +00:00
Nicholas Marriott e44bd9f750 Revert the command-prefix change which breaks sequences of commands. 2013-03-25 15:59:57 +00:00
Nicholas Marriott 777edd0269 Add to TODO. 2013-03-25 15:47:16 +00:00
Nicholas Marriott 855d6fe1fe Add to TODO. 2013-03-25 15:47:10 +00:00
Nicholas Marriott b625ad6d8b Use -std=gnu99 not c99 with GCC. 2013-03-25 15:33:23 +00:00
Thomas Adam 97b5df35b1 Portability fix-ups
* Ammend the Makefile to include newer commands.
* "compat/vis.h" versus <vis.h>
* Removal of cmd-send-prefix.c and cmd-show-buffer.c
* osdep-* for processes.

BUG-ID:  N/A
2013-03-25 15:32:02 +00:00
Thomas Adam 7a87c7eff6 Fixup Makefile 2013-03-25 15:00:56 +00:00
Thomas Adam f90eb43fcb Merge branch 'obsd-master' 2013-03-25 14:59:29 +00:00
Nicholas Marriott a09d8e88fc Use -std=gnu99 not c99 with GCC. 2013-03-25 12:16:03 +00:00
Nicholas Marriott b5fda7ad2a Spacing, warning nits. 2013-03-25 12:00:30 +00:00
Nicholas Marriott 58bb6f8c56 Set pane resize flag when needed. 2013-03-25 11:55:01 +00:00
Nicholas Marriott 673eb160d4 Sort includes and fix spaces. 2013-03-25 11:53:54 +00:00
Nicholas Marriott e97e0d7e54 Man page fixes. 2013-03-25 11:49:54 +00:00
Nicholas Marriott 4119c476aa b comes before t. 2013-03-25 11:46:28 +00:00
Nicholas Marriott e2295014d9 Process ^[ as meta when a partial key is found. 2013-03-25 11:44:16 +00:00
Nicholas Marriott 43fb9835fa Add -P and -F to new-session. 2013-03-25 11:44:00 +00:00
Nicholas Marriott 599dd2a560 Create a new context when copying instead of using the input
context. The input context may not exist yet. Fixes crash when copying
from config file errors.
2013-03-25 11:43:33 +00:00
Nicholas Marriott d28a39d01d Extend jobs to support writing and use that for copy-pipe instead of
popen, from Chris Johnsen.
2013-03-25 11:43:01 +00:00
Nicholas Marriott 270d90ce1e Handle empty pending output (not a failure) and add \n. From George
Nachman.
2013-03-25 11:42:19 +00:00
Nicholas Marriott 0c969a7dfd Handle no client better in display-message. 2013-03-25 11:42:01 +00:00
Nicholas Marriott 111d993e75 When only two panes in a window, only draw half the separating line as
active.
2013-03-25 11:41:49 +00:00
Nicholas Marriott 0ef24f9912 Only send end guard if begin was sent, from George Nachman. 2013-03-25 11:41:16 +00:00
Nicholas Marriott 87fe1c0b0e Include prefix on ids, from George Nachman. 2013-03-25 11:40:54 +00:00
Nicholas Marriott 114d822d27 Don't zoom windows with one pane, from Romain Francoise. 2013-03-25 11:39:11 +00:00
Nicholas Marriott 88b92df849 We ignore SIGWINCH until ready, so send a MSG_RESIZE immediately when
becoming ready.
2013-03-25 11:38:57 +00:00
Nicholas Marriott e4c0730bf1 Use single stdout and stderr for control clients. 2013-03-25 11:36:59 +00:00
Nicholas Marriott 8a40e10d55 Add time and a command count to control mode guards, based on code from
George Nachman.
2013-03-25 11:35:55 +00:00
Nicholas Marriott e0961dfdf4 Fix handling of short (< 4 character) checksums and a bug with parsing
old-style custom layouts. Based on fix from Chris Johnsen.
2013-03-25 11:35:30 +00:00
Nicholas Marriott 446fb0cb9c Do not redraw panes if invisible. 2013-03-25 10:12:01 +00:00
Nicholas Marriott 6fee3e9e4b Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.
2013-03-25 10:11:45 +00:00
Nicholas Marriott 748acdc77c Add wait-for -L and -U for lock and unlock, from Thiago Padilha. 2013-03-25 10:09:35 +00:00
Nicholas Marriott 410a3abbef Add a wait-for command which blocks a client on a named channel until it
is woken up again (with wait-for -S). From Thiago Padilha.
2013-03-25 10:09:05 +00:00
Nicholas Marriott 304336a591 Allow lastgc to be NULL in grid_string_cells so find-window doesn't
crash, problem reported by eugene everson.
2013-03-25 10:07:40 +00:00
Nicholas Marriott 35452b3e55 Do not leak command in formats, from Romain Francoise. 2013-03-25 10:07:21 +00:00
Nicholas Marriott ebd9c615c8 Add some additional debug logging. 2013-03-25 10:06:13 +00:00
Nicholas Marriott e9cef8bf30 Continue the parent cmdq after sourcing a file. 2013-03-25 10:05:58 +00:00
Nicholas Marriott e85f764f23 Preserve trailing spaces with capture-pane -J, from George Nachman. 2013-03-25 10:05:35 +00:00
Nicholas Marriott e2e85650ac tty.path can be NULL, don't dereference it. From George Nachman. 2013-03-25 10:04:44 +00:00
Nicholas Marriott 2c14a771a8 Remove some unused/unnecessary control notifications, from George Nachman. 2013-03-25 10:04:23 +00:00
Nicholas Marriott d39b1a87a5 Add -q flags to shut up errors to capture-pane and show-options, from
George Nachman.
2013-03-25 10:04:04 +00:00
Nicholas Marriott 62db3c8efe Send DSC 1000p at the beginning of a -CC client's lifetime and ST and
the end, from George Nachman.
2013-03-25 10:03:24 +00:00
Nicholas Marriott efa06643b0 Remove previous. 2013-03-25 10:03:00 +00:00
Nicholas Marriott 14fad6a5cc Add -A flag to new-session to make it behave like attach-session if the
session exists. If -A is used, -D behaves like -d to attach-session.
2013-03-24 09:58:40 +00:00
Nicholas Marriott c71844de63 Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.
2013-03-24 09:57:59 +00:00
Nicholas Marriott a05b8c4143 Add a -o option to set-option to prevent setting an option already set,
from Thiago Padilha.
2013-03-24 09:55:02 +00:00
Nicholas Marriott 20636d956d Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.
2013-03-24 09:54:10 +00:00
Nicholas Marriott 66edb3392b Expand format variables in the run-shell and if-shell shell commands,
from Thiago Padilha.
2013-03-24 09:33:35 +00:00
Nicholas Marriott 86adcd4b26 Add pane_tabs format to format_window_pane based on code from George
Nachman.
2013-03-24 09:29:40 +00:00
Nicholas Marriott a60687f9ba Handle focus events from the terminal, from Aaron Jensen. 2013-03-24 09:28:59 +00:00
Nicholas Marriott bb8457b166 Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.
2013-03-24 09:27:19 +00:00
Nicholas Marriott 3eae71b5b2 Do pane resize ioctls once at the end of the server loop rather than
immediately.
2013-03-24 09:25:04 +00:00
Nicholas Marriott 8094e82287 Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".
2013-03-24 09:21:27 +00:00
Nicholas Marriott 1ec4354998 Add support for focus notifications when tmux pane changes, based on
work by Aaron Jensen.
2013-03-24 09:18:16 +00:00
Nicholas Marriott ac1fe83596 Couple of fixes pointed out by jmc. 2013-03-22 18:45:36 +00:00
Nicholas Marriott c7d1849e1c Process ^[ as meta when a partial key is found. 2013-03-22 17:02:12 +00:00
Nicholas Marriott 7f191c7951 Add -P and -F to new-session. 2013-03-22 17:01:15 +00:00
Nicholas Marriott 702ab8bab0 Add a load of miscellaneous pane formats, from George Nachman. 2013-03-22 16:03:35 +00:00
Nicholas Marriott eaaeb28cda Add session_set_current helper function, extracted from a diff from
Aaron Jensen.
2013-03-22 16:00:26 +00:00
Nicholas Marriott 295d86911e Add -C and -J to capture pane to escape control sequences and to join
wrapped line, based on a diff from George Nachman.
2013-03-22 15:56:11 +00:00
Nicholas Marriott c519f9a84c evbuffer_readline returns allocated storage, don't leak it. 2013-03-22 15:55:22 +00:00
Nicholas Marriott 2243cfbe75 Need to set clients in context before changing their reference count. 2013-03-22 15:54:29 +00:00
Nicholas Marriott d644e5143f Fix so capture-pane/save-buffer can work in control clients, from George
Nachman.
2013-03-22 15:53:24 +00:00
Nicholas Marriott 58932295fc Add copy-pipe mode command to copy selection and also pipe to a command. 2013-03-22 15:52:40 +00:00
Nicholas Marriott 8478895eeb Add -e flag to capture-pane to include embedded ANSI SGR escape
sequences, from George Nachman.
2013-03-22 15:51:54 +00:00
Nicholas Marriott 8a6fbfa148 Don't use a target-client for stdout, just always cmdclient. 2013-03-22 15:51:15 +00:00
Nicholas Marriott a1722d5c2e Remove unnecessary initializers of cmd_ctx. 2013-03-22 15:50:42 +00:00
Nicholas Marriott 0ff9275ad7 load_cfg can actually use the same context now they are reference counted. 2013-03-22 15:50:13 +00:00
Nicholas Marriott d1e6ce2672 Add functions to allocate and free command contexts rather than doing it
all on the stack.
2013-03-22 15:49:55 +00:00
Nicholas Marriott 0ccd84d2ef Instead of skipping del_curterm on FreeBSD < 7, skip it on ncurses < 5.7. It
looks like 5.6 on Linux has the problem too. Reported by Myles Dear.
2013-03-22 15:36:45 +00:00
Nicholas Marriott 29613f2f31 Prevent lock on control clients, not on others. 2013-03-22 10:42:55 +00:00
Nicholas Marriott 8c545bbfa8 Don't try to print unterminated strings when loading configuration file. 2013-03-22 10:41:57 +00:00
Nicholas Marriott f19836550b Unbreak line wrapping. 2013-03-22 10:41:01 +00:00
Nicholas Marriott 79f5fe6f5b Use tty_raw on stop, not tty_puts. 2013-03-22 10:40:22 +00:00
Nicholas Marriott 2f5fa4ee9d Don't hang when clearing line in choose mode now that the cursor stays
at the end with wrap.
2013-03-22 10:38:33 +00:00
Nicholas Marriott db66d85176 Fix double space in sessions template. 2013-03-22 10:38:13 +00:00
Nicholas Marriott f0efa576e0 Add resize-pane -x and -y for absolute pane size (much requested). 2013-03-22 10:37:39 +00:00
Nicholas Marriott ad5df9bc2f Implement DECAWM (SM/RM 7) using existing MODE_WRAP flag. 2013-03-22 10:36:53 +00:00
Nicholas Marriott 22a2949bd2 Correctly handle UTF8 mouse option being toggled, from Egmont Koblinger. 2013-03-22 10:34:46 +00:00
Nicholas Marriott 67b4d5b609 Support the latest theory for mouse input, this is enabled/disabled with
SM/RM 1006 and is similar in style to SGR input: \033[<b;x;yM or
\033[b;x;ym. From Egmont Koblinger.
2013-03-22 10:33:50 +00:00
Nicholas Marriott ad760b3bf7 Add client_session and client_last_session formats. 2013-03-22 10:32:36 +00:00
Nicholas Marriott 8d59b189cc No more lint means no more ARGSUSED. 2013-03-22 10:31:22 +00:00
Nicholas Marriott 306a3b8d80 In terminals with XT, turn on modifyOtherKeys=1 with the escape sequence
and handle the most common set. Pass them through if xterm-keys is on.
2013-03-22 10:30:04 +00:00
Nicholas Marriott 041a911c43 Create a new context when copying instead of using the input context. The input
context may not exist yet.
2013-03-21 23:57:21 +00:00
Nicholas Marriott 10682b9e7e Instead of loads of little screen_write_*_on and off functions which
just change mode flags, just have screen_write_mode_set and
screen_write_mode_clear.
2013-03-21 18:47:56 +00:00
Nicholas Marriott c5504af4a6 Add various checks to turn off bits that can't work in control mode
(such as lock).
2013-03-21 18:47:01 +00:00
Nicholas Marriott 49ac5b5fe0 Do not include status line in size calculations in control mode. 2013-03-21 18:46:12 +00:00
Nicholas Marriott d4785fe798 Don't set key KEYC_NONE on xterm_keys_find match()
When calling xterm_keys_find(); if we get a complete match, don't set
the key to unknown before calling the action to complete the binding;
otherwise non-prefixed bindings will not work.

From Thomas Adam
2013-03-21 18:45:38 +00:00
Nicholas Marriott 3d24c75d0f Include the \033 in the key tree and adjust key matching for this change. 2013-03-21 18:44:47 +00:00
Nicholas Marriott 78543cce30 Support capture-pane -p to send to stdout. 2013-03-21 18:43:34 +00:00
Jason McIntyre 55bf2ecc68 tweak previous; ok nicm 2013-03-21 17:42:36 +00:00
Nicholas Marriott 51ac2a3202 Fix a couple of memory leaks, from Romain Francoise. 2013-03-21 16:54:37 +00:00
Nicholas Marriott 48291f0eeb Make choose-tree actually work again. 2013-03-21 16:53:12 +00:00
Nicholas Marriott d5139d1401 Fix a comment for new key table names. 2013-03-21 16:52:02 +00:00
Nicholas Marriott 3665be7c44 Tidy by splitting default key tables into two. 2013-03-21 16:50:22 +00:00
Nicholas Marriott 801d64a16e Add -c to refresh-client to set client size in control mode, based on
code from George Nachman.
2013-03-21 16:49:37 +00:00
Nicholas Marriott dd46c95e23 Aargh. Spaces -> tabs. 2013-03-21 16:25:08 +00:00
Nicholas Marriott 4920306486 Clarify choose-tree entry in man page. 2013-03-21 16:23:46 +00:00
Nicholas Marriott 66414029a1 Run session command before window in choose-tree. 2013-03-21 16:23:07 +00:00
Nicholas Marriott 51d989f5df Do not crash when calling choose-tree with a command that changes the mode. 2013-03-21 16:22:48 +00:00
Nicholas Marriott c982279950 Fix constness of cmd_template_replace, window_choose_add_item and
window_choose_add_window.
2013-03-21 16:19:25 +00:00
Nicholas Marriott 0c0953f3bd Add user options, prefixed with @. May be set to any arbitrary string. 2013-03-21 16:17:01 +00:00
Nicholas Marriott 69fe5ca567 Add -v to set and setw to show only option value. 2013-03-21 16:15:52 +00:00
Nicholas Marriott 63b4fd5cac Add a format client_prefix which is 1 if prefix key has been
pressed, used for example #{?client_prefix,X,Y}. Also a few extra
server_client_status needed.
2013-03-21 16:14:09 +00:00
Nicholas Marriott dd76497ab0 Show alias in lscm output. 2013-03-21 16:12:50 +00:00
Nicholas Marriott 9b7e18f166 Rework reflow code so it does not do so much allocation which should be
faster with large histories.
2013-03-21 16:12:10 +00:00
Nicholas Marriott 180faf73af Allow choose commands to be used outside tmux, so long as at least one
client is attached.
2013-03-21 16:09:59 +00:00
Nicholas Marriott 6ddb06d372 Extend jobs to support writing and use that for copy-pipe instead of popen,
from Chris Johnsen.
2013-03-21 14:24:33 +00:00
Nicholas Marriott 69d97f6d4b Handle empty pending output (not a failure) and add \n. From George Nachman. 2013-03-19 09:34:00 +00:00
Nicholas Marriott f5de847a0c Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-17 23:45:19 +00:00
Nicholas Marriott 6bdc947f6b Handle no client better in display-message. 2013-03-14 16:02:33 +00:00
Nicholas Marriott 919bde7cb1 When only two panes in a window, only draw half the separating line as active. 2013-03-14 12:08:26 +00:00
Nicholas Marriott 3d974b7267 Don't let display-message crash if no client, from George Nachman. 2013-03-14 07:31:20 +00:00
Nicholas Marriott c5ad47ee7c Only send end guard if begin was sent, from George Nachman. 2013-03-13 07:31:36 +00:00
Nicholas Marriott 4d38b6d1fa Include prefix on ids, from George Nachman. 2013-03-13 07:28:12 +00:00
Nicholas Marriott 9e879b4aab Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-12 22:49:56 +00:00
Nicholas Marriott 99934bf998 Write escaped output in control mode rather than hex, from George Nachman. 2013-03-12 22:48:58 +00:00
Nicholas Marriott 8840f2d629 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-12 14:59:27 +00:00
Nicholas Marriott d32a546d6e Clarify zoom/unzoom, from Romain Francoise. 2013-03-12 14:58:48 +00:00
Nicholas Marriott 8aa40ec1c7 Don't zoom windows with one pane, from Romain Francoise. 2013-03-12 12:18:52 +00:00
Nicholas Marriott 543420ccd2 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-11 21:31:46 +00:00
Nicholas Marriott 064022548b We ignore SIGWINCH until ready, so send a MSG_RESIZE immediately when becoming
ready.
2013-03-11 21:30:48 +00:00
Nicholas Marriott 7c00950967 Don't add prefix to %output pane id. 2013-03-11 15:28:34 +00:00
Nicholas Marriott b5516771d3 Clean up capture-pane and add -P option to dump pending output, based on code
from George Nachman.
2013-03-11 13:47:29 +00:00
Nicholas Marriott 7b4084a15a Document control mode in the manpage, from George Nachman. 2013-03-11 13:06:30 +00:00
Nicholas Marriott 412ac6bc3a Use single stdout and stderr for control clients. 2013-03-11 09:46:18 +00:00
Nicholas Marriott a6ad44f111 Fix if-shell and run-shell if there are no sessions. Batted around through
several people, finished off by Chris Johnsen.
2013-03-11 09:43:56 +00:00
Nicholas Marriott 97620bb5be Add a home and end as modified by xterm in keypad mode, from Chris Johnsen. 2013-03-11 09:37:52 +00:00
Nicholas Marriott 49ed75d883 Fix a warning. 2013-03-11 09:37:16 +00:00
Nicholas Marriott c41d92d27a Add time and a command count to control mode guards, based on code from George
Nachman.
2013-03-11 09:35:44 +00:00
Nicholas Marriott a060aa2bf0 Fix handling of short (< 4 character) checksums and a bug with parsing
old-style custom layouts. Based on fix from Chris Johnsen.
2013-03-10 23:41:59 +00:00
Nicholas Marriott 2ac6501698 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-09 21:33:28 +00:00
Nicholas Marriott 06ac399ce6 Zoom script is no longer needed. 2013-03-09 21:32:47 +00:00
Nicholas Marriott dde5d49a5e Do not redraw panes if invisible. 2013-03-09 17:29:22 +00:00
Nicholas Marriott 89d3f13945 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-07 10:09:13 +00:00
Nicholas Marriott f47a063841 Rename session idx to session id throughout and add $ prefix to targets to use
it, extended from a diff from George Nachman.
2013-03-07 10:07:22 +00:00
Nicholas Marriott e964ff70e6 Fix --disable-static, reported by Shea Levy. 2013-03-06 14:58:48 +00:00
Nicholas Marriott bc3580fa06 Add wait-for -L and -U for lock and unlock, from Thiago Padilha. 2013-03-06 11:00:55 +00:00
Nicholas Marriott 7fd4d49d56 Add a wait-for command which blocks a client on a named channel until it is
wokrn up again (with wait-for -S). From Thiago Padilha.
2013-03-06 09:57:26 +00:00
Nicholas Marriott ec75f9d1a3 Allow lastgc to be NULL in grid_string_cells so find-window doesn't crash,
problem reported by eugene everson.
2013-03-06 09:56:31 +00:00
Nicholas Marriott 6405fceee2 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-03-05 20:02:47 +00:00
Nicholas Marriott f9e46a373f Do not leak command in formats, from Romain Francoise. 2013-03-05 20:01:16 +00:00
Nicholas Marriott d05debbe19 Unzoom on last-pane and fix a typo, from Romain Francoise. 2013-03-05 18:00:14 +00:00
Nicholas Marriott f8c86a9515 Add some additional debug logging. 2013-03-05 17:17:59 +00:00
Nicholas Marriott 2c9cddd876 Continue the parent cmdq after sourcing a file. 2013-03-05 17:14:19 +00:00
Nicholas Marriott aaeee34c32 Preserve trailing spaces with capture-pane -J, from George Nachman. 2013-03-04 11:03:03 +00:00
Nicholas Marriott 70397e4a95 Print %%error not %%end guard on error, from George Nachman. 2013-03-04 09:09:07 +00:00
Nicholas Marriott 43d904dbf3 tty.path can be NULL, don't dereference it. From George Nachman. 2013-03-04 09:02:32 +00:00
Nicholas Marriott 1da64bf786 Remove some unused/unnecessary control notifications, from George Nachman. 2013-03-04 09:01:30 +00:00
Nicholas Marriott 1cb1fb5bd4 Add -q flags to shut up errors to capture-pane and show-options, from George
Nachman.
2013-03-04 09:00:24 +00:00
Nicholas Marriott 208881a735 Send DSC 1000p at the beginning of a -CC client's lifetime and ST and the end,
from George Nachman..
2013-03-04 08:52:41 +00:00
Thomas Adam a2f52d4224 Remove previous 2013-02-25 18:25:37 +00:00
Thomas Adam 2ccb67cae4 Plug small memory leak in run-shell
Don't potentially leak the command to run were it to fail.
2013-02-25 07:33:21 +00:00
Nicholas Marriott b2a61348dd Add -a to capture-pane to capture alternate screen, from George Nachman. 2013-02-24 07:52:03 +00:00
Nicholas Marriott 234f6d27c1 Use \\ not \ for escaping \. 2013-02-24 07:49:54 +00:00
Nicholas Marriott f339cfd315 Add -A flag to new-session to make it behave like attach-session if the session
exists. If -A is used, -D behaves like -d to attach-session.
2013-02-24 00:43:28 +00:00
Nicholas Marriott c5239c5984 Add resize-pane -Z to temporary zoom the active pane to occupy the full window
or unzoom (restored to the normal layout) if it already zoomed, bound to C-b z
by default. The pane is unzoomed on pretty much any excuse whatsoever.

We considered making this a new layout but the requirements are quite different
from layouts so decided it is better as a special case. Each current layout
cell is saved, a temporary one-cell layout generated and all except the active
pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen and
Thiago Padilha for testing an earlier version.
2013-02-24 00:25:03 +00:00
Nicholas Marriott be13479f09 Add a -o option to set-option to prevent setting an option already set, from
Thiago Padilha.
2013-02-23 23:22:03 +00:00
Nicholas Marriott 69a8d64716 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code
Conflicts:
	cmd-if-shell.c
	cmd-run-shell.c
	tmux.1
2013-02-23 22:42:49 +00:00
Nicholas Marriott 3964309c67 Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent commands. This
allows run-shell and if-shell to be synchronous which has been much requested.

Each client has a default command queue and commands are consumed one at a time
from it. A command may suspend execution from the queue by returning
CMD_RETURN_WAIT and then resume it by calling cmd_continue() - for example
run-shell does this from the callback that is fired after the job is freed.

When the command queue becomes empty, command clients are automatically exited
(unless attaching). A callback is also fired - this is used for nested commands
in, for example, if-shell which can block execution of the client's cmdq until
a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the old
curclient/cmdclient distinction - a cmdq is bound to one client (or none if in
the configuration file), this is a command client if c->session is NULL
otherwise an attached client.
2013-02-23 22:25:58 +00:00
Nicholas Marriott 243244d285 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-23 19:26:12 +00:00
Nicholas Marriott 497b27dafb Expand format variables in the run-shell and if-shell shell commands, from
Thiago Padilha.
2013-02-23 19:24:42 +00:00
Nicholas Marriott ca6d9f799e Tidy TODO and nuke stuff that is done in some form or not going to happen. 2013-02-23 15:52:56 +00:00
Nicholas Marriott f1aa5f6a1d Add to TODO. 2013-02-23 15:43:13 +00:00
Nicholas Marriott dc50de782a The visit -> Visit 2013-02-23 15:15:20 +00:00
Nicholas Marriott 2e85eeea37 www Project Page -> SourceForge Page 2013-02-23 14:51:56 +00:00
Nicholas Marriott 357da035b9 Merge send-prefix into send-keys. 2013-02-23 14:41:07 +00:00
Nicholas Marriott 5aa54c863d Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-23 14:23:59 +00:00
Nicholas Marriott 42735d446e Merge show-buffer into save-buffer. 2013-02-23 14:23:35 +00:00
Nicholas Marriott 57eb334d5b Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-23 13:03:47 +00:00
Nicholas Marriott 5f904aa350 Add pane_tags format to format_window_pane based on code from George Nachman. 2013-02-23 13:02:52 +00:00
Nicholas Marriott ee0f8adfac Handle focus events from the terminal, from Aaron Jensen. 2013-02-23 10:01:34 +00:00
Nicholas Marriott 1ed37385c6 Use -O2 without debugging. 2013-02-22 23:37:55 +00:00
Nicholas Marriott 3a2e9d805a Fix error reporting for client commands by adding a flag to cmd_find_client to
tell it whether or not to show errors, sometimes it's needed and sometimes not.
2013-02-22 23:04:53 +00:00
Nicholas Marriott 911ef4e69a Allow display-message with no curclient. 2013-02-22 22:57:26 +00:00
Nicholas Marriott 1994ae4640 Missing PANE_RESIZE define. 2013-02-22 21:47:34 +00:00
Nicholas Marriott dbd8e47846 Do pane resize ioctls once at the end of the server loop rather than
immediately.
2013-02-22 21:35:29 +00:00
Nicholas Marriott ce7bf1083e Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-22 16:25:50 +00:00
Nicholas Marriott 1db4ec6e63 Add pane_current_command format. 2013-02-22 16:25:21 +00:00
Nicholas Marriott 1c82cf7660 Remove a couple of FAQ bits that are out of date and not frequent. 2013-02-22 14:53:00 +00:00
Nicholas Marriott e43fc6f08a Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-22 14:32:33 +00:00
Nicholas Marriott 31407b70e0 Add option command-prefix which is automatically prepended to any command
(apart from a naked default-shell). The default is "exec ".
2013-02-22 14:31:38 +00:00
Nicholas Marriott 7d3c1016ce Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-22 07:25:38 +00:00
Nicholas Marriott 4c9f9438ff Add support for focus notifications when tmux pane changes, based on work by
Aaron Jensen.
2013-02-22 07:23:11 +00:00
Nicholas Marriott 374dae6635 Add a load of miscellaneous pane formats, from George Nachman. 2013-02-21 19:44:27 +00:00
Nicholas Marriott 8c50f625b0 Add session_set_current helper function, extracted from a diff from Aaron
Jensen.
2013-02-21 16:54:13 +00:00
Nicholas Marriott 6fc96978c2 Add to TODO. 2013-02-21 16:43:04 +00:00
Nicholas Marriott 8e3767e344 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-21 09:37:06 +00:00
Nicholas Marriott b8b5631d9d Add -C and -J to capture pane to escape control sequences and to join wrapped
line, based on a diff from George Nachman.
2013-02-21 09:35:01 +00:00
Nicholas Marriott c577b47cd5 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-20 23:16:53 +00:00
Nicholas Marriott cb6f36655e evbuffer_readline returns allocated storage, don't leak it. 2013-02-20 23:15:21 +00:00
Nicholas Marriott 7905f4600d Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-20 14:58:23 +00:00
Nicholas Marriott 41c39e9bd9 Remove stray blank line. 2013-02-20 13:01:59 +00:00
Nicholas Marriott f81d723264 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-20 10:59:02 +00:00
Nicholas Marriott afd5e978cf Need to set clients in context before changing their reference count. 2013-02-20 10:25:15 +00:00
Nicholas Marriott e68b9abd04 Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-20 10:20:44 +00:00
Nicholas Marriott e487b87f6f Clear last attributes after reset in string_cells, from George Nachman. 2013-02-20 09:34:21 +00:00
Nicholas Marriott 1e20153b6e Fix so capture-pane/save-buffer can work in control clients, from George
Nachman.
2013-02-20 09:32:52 +00:00
Nicholas Marriott 4621a52183 Include ML and IRC in the text. 2013-02-20 00:16:00 +00:00
Nicholas Marriott e90a742db8 Tweak bold link. 2013-02-20 00:06:01 +00:00
Nicholas Marriott b219d54503 Simplify main www page. 2013-02-20 00:03:59 +00:00
Nicholas Marriott 3108d80b7e Move NOTES->README, move Vim syntax file documentation to the file itself and
otherwise tweak some bits.
2013-02-19 23:31:04 +00:00
Nicholas Marriott 8a7d463b87 Prevent lock on control clients, not on others. 2013-02-19 21:11:32 +00:00
Nicholas Marriott c3859d1df1 Add copy-pipe mode command to copy selection and also pipe to a command. 2013-02-19 17:49:53 +00:00
Nicholas Marriott 5a5e285be8 Don't try to print unterminated strings when loading configuration file. 2013-02-19 17:28:21 +00:00
Nicholas Marriott 4d1d4d6e8e Add -e flag to capture-pane to include embedded ANSI SGR escape sequences, from
George Nachman.
2013-02-19 09:55:02 +00:00
Nicholas Marriott a96dd1932a Don't use a target-client for stdout, just always cmdclient. 2013-02-19 09:51:04 +00:00
Nicholas Marriott 693244795c Remove unnecessary initializers of cmd_ctx. 2013-02-18 23:38:57 +00:00
Nicholas Marriott 255a4f8ce3 load_cfg can actually use the same context now they are reference counted. 2013-02-18 23:35:54 +00:00
Nicholas Marriott e2b26d910c Unbreak line wrapping. 2013-02-18 23:31:23 +00:00
Nicholas Marriott 293e331d69 Add functions to allocate and free command contexts rather than doing it all on
the stack.
2013-02-18 23:20:21 +00:00
Nicholas Marriott 2a91025581 Use tty_raw on stop, not tty_puts. 2013-02-18 17:35:53 +00:00
Nicholas Marriott 37d34b6b83 Don't hang when clearing line in choose mode now that the cursor stays at the
end with wrap.
2013-02-18 17:23:08 +00:00
Nicholas Marriott 44452823b7 Fix double space in sessions template. 2013-02-18 17:12:58 +00:00
Nicholas Marriott e4bb87032e Add resize-pane -x and -y for absolute pane size. 2013-02-18 17:00:35 +00:00
Nicholas Marriott a6c4c2cca0 Implement DECAWM (SM/RM 7) using existing MODE_WRAP flag. 2013-02-18 15:57:46 +00:00
Nicholas Marriott ba3b8ccc1d Correctly turn handle UTF8 mouse option being toggled, from Egmont Koblinger. 2013-02-18 15:03:50 +00:00
Nicholas Marriott e5eee7de0c Support the latest theory for mouse input, this is enabled/disabled with SM/RM
1006 and is similar in style to SGR input: \033[<b;x;yM or \033[b;x;ym. From
Egmont Koblinger.
2013-02-18 14:52:27 +00:00
Nicholas Marriott d8261019f1 Add client_session and client_last_session formats. 2013-02-18 14:23:40 +00:00
Nicholas Marriott 9d165df18a No more lint means no more ARGSUSED. 2013-02-17 23:15:38 +00:00
Nicholas Marriott 7d1a8f7e9e Remove stray test code which would convert abc to x. 2013-02-17 23:05:57 +00:00
Nicholas Marriott 8df3ec612a In terminals with XT, turn on modifyOtherKeys=1 with the escape sequence and
handle the most common set. Pass them through if xterm-keys is on.
2013-02-17 22:56:12 +00:00
Nicholas Marriott 4c91c153cb I strongly suspect it is possible for tmux to block on detach in tty_raw, so
make the fd blocking again much later and have tty_raw just retry the write a
few times.
2013-02-17 22:28:11 +00:00
Nicholas Marriott cf2c0237f4 Instead of loads of little screen_write_*_on and off functions which just
change mode flags, just have screen_write_mode_set and screen_write_mode_clear.
2013-02-17 10:43:35 +00:00
Nicholas Marriott 3d9fd1c7f2 Add various checks to turn off bits that can't work in control mode (such as
lock).
2013-02-17 10:12:55 +00:00
Nicholas Marriott d1e8fb33da Merge branch 'master' of ssh://git.code.sf.net/p/tmux/tmux-code 2013-02-17 10:04:59 +00:00
Nicholas Marriott 1e3a4f2331 Do not include status line in size calculations in control mode. 2013-02-17 10:04:26 +00:00
Thomas Adam 2ac1d46f46 Don't set key KEYC_NONE on xterm_keys_find match()
When calling xterm_keys_find(); if we get a complete match, don't set the
key to unknown before calling the action to complete the binding; otherwise
non-prefixed bindings will not work.
2013-02-16 21:04:48 +00:00
Nicholas Marriott 77a2174685 Fix a couple of memory leaks, from Romain Francoise. 2013-02-16 19:35:49 +00:00
Nicholas Marriott 3e270af17a Don't omit half the default table (!= not ==). 2013-02-16 13:29:40 +00:00
Nicholas Marriott 10db7ec51b Include the \033 in the key tree and adjust key matching for this change. 2013-02-16 13:21:14 +00:00
Nicholas Marriott 4f01bfc4bc Make choose-tree actually work again. 2013-02-15 12:57:13 +00:00
Nicholas Marriott 1d591ada76 Support capture-pane -p to send to stdout. 2013-02-15 09:31:45 +00:00
Nicholas Marriott 2bdc59fac8 Fix a comment for new key table names. 2013-02-15 02:38:15 +00:00
Nicholas Marriott 784a74df0b Fix function parameter to tty_keys_free. 2013-02-15 02:18:38 +00:00
Nicholas Marriott 82355d2f2d Tidy by splitting default key tables into two. 2013-02-15 02:16:41 +00:00
Nicholas Marriott 97a99d8718 Add -c to refresh-client to set client size in control mode, based on code from
George Nachman.
2013-02-15 01:54:48 +00:00
Nicholas Marriott 755d4863c8 Spaces -> tabs. 2013-02-14 12:22:14 +00:00
Nicholas Marriott 28544391f5 Do not leak formats in status_replace. 2013-02-14 12:20:17 +00:00
Nicholas Marriott 931b0103cd Clarify choose-tree entry in man page. 2013-02-13 11:07:21 +00:00
Nicholas Marriott 6e03b50771 Run session command before window in choose-tree. 2013-02-13 11:05:10 +00:00
Nicholas Marriott 362c460767 Do not crash when calling choose-tree with a command that changes the mode. 2013-02-13 11:01:26 +00:00
Nicholas Marriott f4c815a1d9 Fix constness again, sigh. 2013-02-13 10:41:12 +00:00
Nicholas Marriott fc6f08d5b7 No more need for freefn. 2013-02-13 10:27:49 +00:00
Nicholas Marriott 68e370574a Fix constness of window_choose_add_item and _window. 2013-02-13 10:25:37 +00:00
Nicholas Marriott 544c80d715 Fix constness of cmd_template_replace. 2013-02-13 10:19:43 +00:00
Nicholas Marriott 36fe146a74 Fix choose-tree usage. 2013-02-13 09:55:37 +00:00
Nicholas Marriott caa29af2a9 Add user options, prefixed with @. May be set to any arbitrary string. 2013-02-13 09:54:24 +00:00
Nicholas Marriott 0f31d231db Return error for --foo when using compat/getopt.c. 2013-02-12 20:36:22 +00:00
Nicholas Marriott 102cb77435 Add -v to set and setw to show only option value. 2013-02-12 20:12:10 +00:00
Nicholas Marriott 7360ff4496 Use proc_pidinfo on Darwin for process name too, from OZAKI Kiichi. 2013-02-12 09:40:22 +00:00
Nicholas Marriott a6fd92bd8d Remove stray change accidentally committed. 2013-02-10 19:15:49 +00:00
Nicholas Marriott 06ac4b628d Add a format client_prefix which is 1 if prefix key has been pressed, used for
example #{?client_prefix,X,Y}. Also a few extra server_client_status needed.
2013-02-10 18:58:05 +00:00
Nicholas Marriott 6c53a1ed68 Allow formats in status options. 2013-02-10 18:53:25 +00:00
Nicholas Marriott 6ad2c5c40f Show alias in lscm output. 2013-02-10 18:26:22 +00:00
Nicholas Marriott 99cc0015f8 Rework reflow code so it does not do so much allocation which should be faster
with large histories.
2013-02-10 18:15:30 +00:00
Nicholas Marriott f1ce95915c Allow choose commands to be used outside tmux, so long as at least one client
is attached.
2013-02-10 17:52:51 +00:00
Nicholas Marriott aadc87f5a7 Remove free callback for window_choose_data objects. 2013-02-10 17:36:58 +00:00
Nicholas Marriott 4d382ae8e6 Miscellaneous tidying of choose API, including:
- rename client and session to start_client and start_session in
  window_choose_data struct. also add TREE_OTHER define and reorder the
  struct
- rename window_choose_ctx to window_choose_data_run
- don't pass a cmd_ctx into window_choose_create (will let it use a
  different client later). instead take type, session, client
- add window_choose_data_free and use it to dispose of wcd rather than
  each cmd-*.c doing it individually
- change so ref counting is done by wcd_add and wcd_free rather than
  callers. this means 1 ref for each item but what of it :-)
- also add a ref to tree_session - not sure if this is needed?
- all the callbacks except choose-client and find-window are the same so
  remove them and add window_choose_default_callback
- reorder/rename some other bits and pieces for tidyness
2013-02-10 17:32:58 +00:00
126 changed files with 4280 additions and 2817 deletions
+51
View File
@@ -1,3 +1,54 @@
CHANGES FROM 1.7 to 1.8, 26 March 2013
Incompatible Changes
====================
* layout redo/undo has been removed.
Normal Changes
==============
* Add halfpage up/down bindings to copy mode.
* Session choosing fixed to work with unattached sessions.
* New window options window-status-last-{attr,bg,fg} to denote the last
window which was active.
* Scrolling in copy-mode now scrolls the region without moving the mouse
cursor.
* run-shell learnt '-t' to specify the pane to use when displaying output.
* Support for middle-click pasting.
* choose-tree learns '-u' to start uncollapsed.
* select-window learnt '-T; to toggle to the last window if it's already
current.
* New session option 'assume-paste-time' for pasting text versus key-binding
actions.
* choose-* commands now work outside of an attached client.
* Aliases are now shown for list-commands command.
* Status learns about formats.
* Free-form options can be set with set-option if prepended with an '@'
sign.
* capture-pane learnt '-p' to send to stdout, and '-e' for capturing escape
sequences, and '-a' to capture the alternate screen, and '-P' to dump
pending output.
* Many new formats added (client_session, client_last_session, etc.)
* Control mode, which is a way for a client to send tmux commands.
Currently more useful to users of iterm2.
* resize-pane learnt '-x' and '-y' for absolute pane sizing.
* Config file loading now reports errors from all files which are loaded via
the 'source-file' command.
* 'copy-pipe' mode command to copy selection and pipe the selection to a
command.
* Changes panes can now emit focus notifications for certain applications
which use those.
* run-shell and if-shell now accept format placeholders.
* resize-pane learnt '-Z' for zooming a pane temporarily.
* new-session learnt '-A' to make it behave like attach-session.
* set-option learnt '-o' to prevent setting an option which is already set.
* capture-pane and show-options learns '-q' to silence errors.
* New command 'wait-for' which blocks a client until woken up again.
* Resizing panes will now reflow the text inside them.
* Lots and lots of bug fixes, fixing memory-leaks, etc.
* Various manpage improvements.
CHANGES FROM 1.6 to 1.7, 13 October 2012
* tmux configuration files now support line-continuation with a "\" at the
-45
View File
@@ -326,51 +326,6 @@ lock(1) or vlock(1)) by using the following:
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
* How can I open a new window in the same directory as the current window?
One option is to just run "TMUX= tmux" in the window. However, this only works if no
command is running, so that you can input the command.
A workaround is to let tmux know about the current path through an environment
variable. To do so, use the following command:
[ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD
Which sets TMUXPWD_i (where i is the number of the current window) to the path
of the current directory. This command can be added to PS1, for example:
PS1='$([ -n "$TMUX" ] && tmux setenv TMUXPWD_$(tmux display -p "#I") $PWD)\h$ '
When a new window is created, the shell should be asked to change
directory. You can define a new binding (for example, if using GNU bash):
bind-key C-c run-shell 'tmux neww "cd $(tmux display -p "\$TMUXPWD_#I"); exec bash"'
This solution will work even if a command is currently running in the terminal,
but it will not work from a window that has just been swapped with another
because TMUXPWD_i will not be updated after a swap. However, once a new prompt
is displayed, TMUXPWD_i is updated properly.
* tmux doesn't start with "daemon failed"
tmux shows something similar to this when started:
fatal: server_start: daemon failed: No such file or directory
fatal: main_dispatch: imsg_read failed
A possible reason is that /dev/null is not a character device or is otherwise
inaccessible.
Check with:
file /dev/null
ls -l /dev/null
If it is not a character device or has incorrect permissions, it can typically
be recreated with:
cd /dev && rm null && ./MAKEDEV null
* vim displays reverse video instead of italics, while less displays italics
(or just regular text) instead of reverse. What's wrong?
+7 -5
View File
@@ -6,7 +6,7 @@ dist_man1_MANS = tmux.1
# Distribution tarball options.
EXTRA_DIST = \
CHANGES FAQ NOTES TODO examples compat \
CHANGES FAQ README TODO examples compat \
array.h compat.h tmux.h osdep-*.c
dist-hook:
grep "^#found_debug=" configure
@@ -24,15 +24,17 @@ endif
# Set flags for gcc. gcc4 whines abouts silly stuff so it needs slightly
# different flags.
if IS_GCC
CFLAGS += -std=c99
CFLAGS += -std=gnu99
if IS_DEBUG
CFLAGS += -g -ggdb -O0
CFLAGS += -O0 -g
CFLAGS += -Wno-long-long -Wall -W -Wnested-externs -Wformat=2
CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
CFLAGS += -Wdeclaration-after-statement
CPPFLAGS += -DDEBUG
else
CFLAGS += -O2
endif
if IS_GCC4
CPPFLAGS += -iquote. -I/usr/local/include
@@ -102,6 +104,7 @@ dist_tmux_SOURCES = \
cmd-new-window.c \
cmd-paste-buffer.c \
cmd-pipe-pane.c \
cmd-queue.c \
cmd-refresh-client.c \
cmd-rename-session.c \
cmd-rename-window.c \
@@ -115,12 +118,10 @@ dist_tmux_SOURCES = \
cmd-select-pane.c \
cmd-select-window.c \
cmd-send-keys.c \
cmd-send-prefix.c \
cmd-server-info.c \
cmd-set-buffer.c \
cmd-set-environment.c \
cmd-set-option.c \
cmd-show-buffer.c \
cmd-show-environment.c \
cmd-show-messages.c \
cmd-show-options.c \
@@ -134,6 +135,7 @@ dist_tmux_SOURCES = \
cmd-switch-client.c \
cmd-unbind-key.c \
cmd-unlink-window.c \
cmd-wait-for.c \
cmd.c \
colour.c \
control.c \
+8 -20
View File
@@ -16,15 +16,16 @@ To build tmux from a release tarball, do:
$ ./configure && make
$ sudo make install
To get and build the latest version control checkout:
To get and build the latest from version control:
$ git clone git://tmux.git.sourceforge.net/gitroot/tmux/tmux
$ git clone git://git.code.sf.net/p/tmux/tmux-code tmux
$ cd tmux
$ sh autogen.sh
$ ./configure && make
For more information see https://sourceforge.net/scm/?type=git&group_id=200378
and http://git-scm.com.
and http://git-scm.com. Patches should be sent by email to the mailing list at
tmux-users@lists.sourceforge.net.
For documentation on using tmux, see the tmux.1 manpage. It can be viewed from
the source tree with:
@@ -34,25 +35,13 @@ the source tree with:
Some common questions are answered in the FAQ file and a more extensive (but
slightly out of date) guide is available in the OpenBSD FAQ at
http://www.openbsd.org/faq/faq7.html#tmux. A rough todo list is in the TODO
file.
A Vim syntax file is available in the examples directory. To install it:
- Drop the file in the syntax directory into runtimepath (such as
~/.vim/syntax/tmux.vim).
- Make the filetype recognisable by adding the following to filetype.vim
(~/.vim/filetype.vim):
augroup filetypedetect
au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
augroup END
- Switch on syntax highlighting by adding "syntax enable" to .vimrc.
file and some example configurations and a Vim syntax file are in the examples
directory.
For debugging, running tmux with -v or -vv will generate server and client log
files in the current directory.
tmux mailing lists are available. The visit:
tmux mailing lists are available. Visit:
https://sourceforge.net/mail/?group_id=200378
@@ -64,8 +53,7 @@ welcome. Please send by email to:
This file and the CHANGES, FAQ and TODO files are licensed under the ISC
license. Files under examples/ remain copyright their authors unless otherwise
stated in the file but permission has been received to distribute them with
tmux. All other files have a license and copyright notice at their
start.
tmux. All other files have a license and copyright notice at their start.
-- Nicholas Marriott <nicm@users.sf.net>
+1 -1
View File
@@ -138,7 +138,7 @@ Release tmux for next version
don't have debugging enabled, otherwise make(1) aborts when
preparing the distribution.
2. Update and commit NOTES and CHANGES. The former should be checked for
2. Update and commit README and CHANGES. The former should be checked for
anything outdated and updated with a list of things that might break
upgrades and the latter should mention all the major changes since
the last version.
+20 -43
View File
@@ -30,40 +30,30 @@ TMUX UI ISSUES
to avoid quoting
- make command sequences more usable: don't require space after ;, handle
errors better
- attach should have a flag to create session if it doesn't exist
- choice and more mode would be better per client than per window?
- hooks to which commands may be attached, for example: tmux add-hook
"new-session" if-shell "[ -e $HOME/.tmux-session.conf ]" source-file
$HOME/.tmux-session.conf
- way to set socket path from config file
- what about utmp etc? can tmux update it like screen? setgid?
- warts on current naming:
- display-time but message-fg/bg/attr
- list-* vs show-*
- server-info
- up-pane/down-pane/swap-pane -U/swap-pane -D vs next-*/previous-*
- split-window -> split-pane??
- 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)
- some way to force a screen to use the entire terminal even if it is forced
to be smaller by other clients. pan smaller terminal? (like screen F)
-- idea of a "view" onto a window, need base x/y offsets for redraw
- handle resize better in copy mode
- way to copy stuff that is off screen due to resize
- commands should be able to succeed or fail and have || or && for command
lists
- some way to KEEP a command running continually and just use its LAST line of
- some way to keep a command running continually and just use its last line of
output
- UTF-8 to a non-UTF-8 terminal should not be able to balls up
the terminal - www/ruby-addressable; make regress
- support esc-esc to quit in modes
- fix ctrl+F1-F4 output. to what?
- better utf8 support: window names, prompt input, message display
- 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
@@ -76,14 +66,11 @@ TMUX UI ISSUES
- better session sharing: create-socket command to create socket somewhere (-r
flag for readonly)
- multiline status line (no?)
- flag for absolute pane size to resize-pane
- sanity check input to socket
- support title stack, both internally and externally
http://docs.freebsd.org/cgi/getmsg.cgi?fetch=1149299+0+archive/2010/freebsd-questions/20100207.freebsd-questions
- command to show status line information briefly when it is off
- some way to pad # stuff with spaces, #!2T maybe
- a binding to "scroll down and exit at bottom" copy mode
- some way to pass keystrokes in copy mode through to underlying window
- some way to pass keystrokes in copy mode through to underlying window. why?
- last window update time and # replacement for it for display-message
- find-window across sessions - other ways to make session handling easier?
- ' and " should be parsed the same (eg "\e" vs '\e') in config and command
@@ -92,44 +79,29 @@ TMUX UI ISSUES
- audit of escape sequence support vs xterm
- support binding keys to mouse (mouse-select-pane -> mouse-keys or something,
mouse click == select-pane -t %%, mouse scroll up == copy-mode)
- something for -t "last window in session" so a session can be used as a stack
- synchronous commands - client sends cmd and blocks, neww/splitw saves client
ptr then when program inside died, sends MSG_SOMETHING with wait status to
client
- bind commands to key sequences? -- make it so ALL keys go through a table,
first an implicit table in which C-b is the only default binding to a
command that says "next key from $othertable" and so on. means -n can
go away as well
- monitor, bell etc should monitor /all/ panes in the window not just one
- a history of commands that can be reversed (reverse member of each command,
and a buffer) info() when changing to same window
and a buffer)
- info() when changing to same window
- way to add dest for break-pane; maybe some easier way to unbreak-pane
- case insensitive searching
- incremental searching in copy mode.
- configurable borders and empty space filler for when panes < window?
- mouse-select-pane will screw up with !MODE_MOUSE_STANDARD (it sets the
flag on w/o checking the others before calling tty_update_mode)
- 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
- pass shell commands as argv rather than strings, allow them to be specified
in commands without quotes
- numeric prefix in copy mode should be paste buffer for C-w
- named buffers and allow gaps in the stack
- get rid of separate UTF-8 cell stuff: add 1 byte to cell and store BMP as
uint16_t+3 bits of flags. anything <=0xffff is Unicode, higher are used to
build tree of combined characters/non-BMP (LRU dropped when full)
- entry in FAQ about what to do when someone does mkdir /tmp/tmux-1000
- monitor-activity is broken in several ways with multiple clients
- monitor-activity should be more powerful (eg set a region)
- maybe a way to put pane names instead of window names in status line
- support for borderless panes
- run-shell/if-shell should support status_replace stuff
- wait-pane command or another way to make it synchronous/wait for command to
finish
- wait-for command 20130222153957.GY6782@yelena.nicm.ath.cx
- last-pane across sessions
- attach should take a pane and select it as well as attaching
- panes should have names like windows
- command-prompt doesn't work if made read-only. why?
- option to quote format eg #{session_name:quoted}
@@ -144,16 +116,14 @@ TMUX UI ISSUES
- way to tag a layout as a number/name
- optimize pane redraws, 20120318184853.GK10965@yelena.nicm.ath.cx
- support multibyte key strings
- allow commands to be executed when certaing patterns in a screen
- allow commands to be executed when certain patterns in a screen
are clicked on with the mouse
- flag to make next/previous commands skip a window
- way to do tmux command/run-shell from mode keys
- send command to all windows
- choose-pane command
- Augment choose-tree to do this? TA to investigate.
- choose-mode and copy-mode are very similar. Perhaps make choose-mode a
subset of copy-mode in that it inherits key-bindings and other traits but
not all.
- choose-pane command (augment choose-tree to do this?)
- choose-mode and copy-mode are very similar. Perhaps make choose-mode a subset
of copy-mode in that it inherits key-bindings and other traits but not all
- add -c for new-session like new-window
- flag to choose-* for sort order (eg sort windows/sessions/clients by last
used time) - perhaps using formats (but what about numeric sort)?
@@ -161,6 +131,16 @@ TMUX UI ISSUES
with each option having a type (window or session), then options on window,
on session, and global. for window options we look window->session->global,
and for session we look session->global
- maybe keep last layout + size around and if size reverts just put it back
- way to set hints/limits about pane size for resizing
- revamp layouts: they are too complicated, should be more closely integrated,
should support hints, layout sets should just be a special case of custom
layouts, and we should support panes that are not attached to a cell at
all. this could be the time to introduce panelink to replace layout_cell
- run-shell/if-shell should support formats
- attach should take a pane and select it as well as attaching
- attach should have a flag to create session if it doesn't exist. or better
new a flag to attach it
TERMINAL ISSUES
================
@@ -169,10 +149,7 @@ TERMINAL ISSUES
- clear window title on exit (see using xterm title stack)
- get it passing all the vttest tests that don't require resizing the terminal
- support for bce
- use screen-256color when started on 256 colour terminal??
- if-shell/run-shell should block further command execution in the same command
- possibly support rxvt-unicode extended mouse input (1015)
- wrap/no wrap esc seq DEC CSI ? 7 h/l
- use screen-256color when started on 256 colour terminal?
* We need a tmux terminfo entry to document the extensions we are using in
upstream terminfo. Must NOT change (only add or remove) anything from
TERM=screen so we can fallback!
+42 -105
View File
@@ -27,79 +27,33 @@
#include "tmux.h"
/*
* Config file parser. Pretty quick and simple, each line is parsed into a
* argv array and executed as a command.
*/
void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
char *cfg_cause;
struct cmd_q *cfg_cmd_q;
int cfg_finished;
int cfg_references;
int cfg_references;
struct causelist cfg_causes;
/* 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, ...)
{
va_list ap;
va_start(ap, fmt);
xvasprintf(&cfg_cause, fmt, ap);
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 must be initialised by the caller!
*/
enum cmd_retval
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
int
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
{
FILE *f;
u_int n;
char *buf, *copy, *line, *cause;
u_int n, found;
char *buf, *copy, *line, *cause1, *msg;
size_t len, oldlen;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
enum cmd_retval retval;
log_debug("loading %s", path);
if ((f = fopen(path, "rb")) == NULL) {
cfg_add_cause(causes, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
xasprintf(cause, "%s: %s", path, strerror(errno));
return (-1);
}
cfg_references++;
n = 0;
n = found = 0;
line = NULL;
retval = CMD_RETURN_NORMAL;
while ((buf = fgetln(f, &len))) {
/* Trim \n. */
if (buf[len - 1] == '\n')
len--;
log_debug ("%s: %s", path, buf);
log_debug("%s: %.*s", path, (int)len, buf);
/* Current line is the continuation of the previous one. */
if (line != NULL) {
@@ -131,68 +85,52 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
buf = copy;
while (isspace((u_char)*buf))
buf++;
if (*buf == '\0')
continue;
if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
if (*buf == '\0') {
free(copy);
if (cause == NULL)
continue;
}
/* Parse and run the command. */
if (cmd_string_parse(buf, &cmdlist, path, n, &cause1) != 0) {
free(copy);
if (cause1 == NULL)
continue;
cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
free(cause);
xasprintf(&msg, "%s:%u: %s", path, n, cause1);
ARRAY_ADD(&cfg_causes, msg);
free(cause1);
continue;
}
free(copy);
if (cmdlist == NULL)
continue;
if (ctxin == NULL) {
ctx.msgdata = NULL;
ctx.curclient = NULL;
ctx.cmdclient = NULL;
} else {
ctx.msgdata = ctxin->msgdata;
ctx.curclient = ctxin->curclient;
ctx.cmdclient = ctxin->cmdclient;
}
ctx.error = cfg_error;
ctx.print = cfg_print;
ctx.info = cfg_print;
cfg_cause = NULL;
switch (cmd_list_exec(cmdlist, &ctx)) {
case CMD_RETURN_YIELD:
if (retval != CMD_RETURN_ATTACH)
retval = CMD_RETURN_YIELD;
break;
case CMD_RETURN_ATTACH:
retval = CMD_RETURN_ATTACH;
break;
case CMD_RETURN_ERROR:
case CMD_RETURN_NORMAL:
break;
}
cmdq_append(cmdq, cmdlist);
cmd_list_free(cmdlist);
if (cfg_cause != NULL) {
cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
free(cfg_cause);
}
found++;
}
if (line != NULL) {
cfg_add_cause(causes,
"%s: %d: line continuation at end of file", path, n);
if (line != NULL)
free(line);
}
fclose(f);
cfg_references--;
return (retval);
return (found);
}
void
show_cfg_causes(struct session *s)
cfg_default_done(unused struct cmd_q *cmdq)
{
if (--cfg_references != 0)
return;
cfg_finished = 1;
if (!RB_EMPTY(&sessions))
cfg_show_causes(RB_MIN(sessions, &sessions));
cmdq_free(cfg_cmd_q);
cfg_cmd_q = NULL;
}
void
cfg_show_causes(struct session *s)
{
struct window_pane *wp;
char *cause;
@@ -200,7 +138,6 @@ show_cfg_causes(struct session *s)
if (s == NULL || ARRAY_EMPTY(&cfg_causes))
return;
wp = s->curw->window->active;
window_pane_set_mode(wp, &window_copy_mode);
+13 -7
View File
@@ -188,7 +188,8 @@ client_main(int argc, char **argv, int flags)
* later in server) but it is necessary to get the start server
* flag.
*/
if ((cmdlist = cmd_list_parse(argc, argv, &cause)) == NULL) {
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
if (cmdlist == NULL) {
fprintf(stderr, "%s\n", cause);
return (1);
}
@@ -269,7 +270,7 @@ client_main(int argc, char **argv, int flags)
if (msg == MSG_COMMAND) {
/* Fill in command line arguments. */
cmddata.pid = environ_pid;
cmddata.idx = environ_idx;
cmddata.session_id = environ_session_id;
/* Prepare command for server. */
cmddata.argc = argc;
@@ -295,8 +296,16 @@ client_main(int argc, char **argv, int flags)
ppid = getppid();
if (client_exittype == MSG_DETACHKILL && ppid > 1)
kill(ppid, SIGHUP);
} else if (flags & IDENTIFY_TERMIOS)
} else if (flags & IDENTIFY_TERMIOS) {
if (flags & IDENTIFY_CONTROL) {
if (client_exitreason != CLIENT_EXIT_NONE)
printf("%%exit %s\n", client_exit_message());
else
printf("%%exit\n");
printf("\033\\");
}
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
}
setblocking(STDIN_FILENO, 1);
return (client_exitval);
}
@@ -364,7 +373,6 @@ client_update_event(void)
}
/* Callback to handle signals in the client. */
/* ARGSUSED */
void
client_signal(int sig, unused short events, unused void *data)
{
@@ -411,7 +419,6 @@ client_signal(int sig, unused short events, unused void *data)
}
/* Callback for client imsg read events. */
/* ARGSUSED */
void
client_callback(unused int fd, short events, void *data)
{
@@ -446,7 +453,6 @@ lost_server:
}
/* Callback for client stdin read events. */
/* ARGSUSED */
void
client_stdin_callback(unused int fd, unused short events, unused void *data1)
{
@@ -518,6 +524,7 @@ client_dispatch_wait(void *data)
event_del(&client_stdin);
client_attached = 1;
client_write_server(MSG_RESIZE, NULL, 0);
break;
case MSG_STDIN:
if (datalen != 0)
@@ -575,7 +582,6 @@ client_dispatch_wait(void *data)
}
/* Dispatch imsgs in attached state (after MSG_READY). */
/* ARGSUSED */
int
client_dispatch_attached(void)
{
+34 -25
View File
@@ -26,7 +26,7 @@
* Attach existing session to the current terminal.
*/
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_attach_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_attach_session_entry = {
"attach-session", "attach",
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_attach_session_entry = {
};
enum cmd_retval
cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_attach_session(struct cmd_q *cmdq, const char* tflag, int dflag, int rflag)
{
struct args *args = self->args;
struct session *s;
struct client *c;
const char *update;
@@ -49,18 +48,18 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
u_int i;
if (RB_EMPTY(&sessions)) {
ctx->error(ctx, "no sessions");
cmdq_error(cmdq, "no sessions");
return (CMD_RETURN_ERROR);
}
if ((s = cmd_find_session(ctx, args_get(args, 't'), 1)) == NULL)
if ((s = cmd_find_session(cmdq, tflag, 1)) == NULL)
return (CMD_RETURN_ERROR);
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
if (cmdq->client == NULL)
return (CMD_RETURN_NORMAL);
if (ctx->cmdclient == NULL) {
if (args_has(self->args, 'd')) {
if (cmdq->client->session != NULL) {
if (dflag) {
/*
* Can't use server_write_session in case attaching to
* the same session as currently attached to.
@@ -69,43 +68,53 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session != s)
continue;
if (c == ctx->curclient)
if (c == cmdq->client)
continue;
server_write_client(c, MSG_DETACH, NULL, 0);
}
}
ctx->curclient->session = s;
notify_attached_session_changed(ctx->curclient);
cmdq->client->session = s;
notify_attached_session_changed(cmdq->client);
session_update_activity(s);
server_redraw_client(ctx->curclient);
server_redraw_client(cmdq->client);
s->curw->flags &= ~WINLINK_ALERTFLAGS;
} else {
if (server_client_open(ctx->cmdclient, s, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
if (server_client_open(cmdq->client, s, &cause) != 0) {
cmdq_error(cmdq, "open terminal failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'r'))
ctx->cmdclient->flags |= CLIENT_READONLY;
if (rflag)
cmdq->client->flags |= CLIENT_READONLY;
if (args_has(self->args, 'd'))
if (dflag)
server_write_session(s, MSG_DETACH, NULL, 0);
ctx->cmdclient->session = s;
notify_attached_session_changed(ctx->cmdclient);
session_update_activity(s);
server_write_ready(ctx->cmdclient);
update = options_get_string(&s->options, "update-environment");
environ_update(update, &ctx->cmdclient->environ, &s->environ);
environ_update(update, &cmdq->client->environ, &s->environ);
server_redraw_client(ctx->cmdclient);
cmdq->client->session = s;
notify_attached_session_changed(cmdq->client);
session_update_activity(s);
server_redraw_client(cmdq->client);
s->curw->flags &= ~WINLINK_ALERTFLAGS;
server_write_ready(cmdq->client);
cmdq->client_exit = 0;
}
recalculate_sizes();
server_update_socket();
return (CMD_RETURN_ATTACH);
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_attach_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
return (cmd_attach_session(cmdq, args_get(args, 't'),
args_has(args, 'd'), args_has(args, 'r')));
}
+33 -18
View File
@@ -28,9 +28,9 @@
*/
enum cmd_retval cmd_bind_key_check(struct args *);
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_ctx *, int);
enum cmd_retval cmd_bind_key_table(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_bind_key_entry = {
"bind-key", "bind",
@@ -46,7 +46,7 @@ enum cmd_retval
cmd_bind_key_check(struct args *args)
{
if (args_has(args, 't')) {
if (args->argc != 2)
if (args->argc != 2 && args->argc != 3)
return (CMD_RETURN_ERROR);
} else {
if (args->argc < 2)
@@ -56,7 +56,7 @@ cmd_bind_key_check(struct args *args)
}
enum cmd_retval
cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_bind_key_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
char *cause;
@@ -65,16 +65,17 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE) {
ctx->error(ctx, "unknown key: %s", args->argv[0]);
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (args_has(args, 't'))
return (cmd_bind_key_table(self, ctx, key));
return (cmd_bind_key_table(self, cmdq, key));
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, &cause);
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
&cause);
if (cmdlist == NULL) {
ctx->error(ctx, "%s", cause);
cmdq_error(cmdq, "%s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -86,36 +87,50 @@ cmd_bind_key_exec(struct cmd *self, struct cmd_ctx *ctx)
}
enum cmd_retval
cmd_bind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
cmd_bind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
{
struct args *args = self->args;
const char *tablename;
const struct mode_key_table *mtab;
struct mode_key_binding *mbind, mtmp;
enum mode_key_cmd cmd;
const char *arg;
tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) {
ctx->error(ctx, "unknown key table: %s", tablename);
cmdq_error(cmdq, "unknown key table: %s", tablename);
return (CMD_RETURN_ERROR);
}
cmd = mode_key_fromstring(mtab->cmdstr, args->argv[1]);
if (cmd == MODEKEY_NONE) {
ctx->error(ctx, "unknown command: %s", args->argv[1]);
cmdq_error(cmdq, "unknown command: %s", args->argv[1]);
return (CMD_RETURN_ERROR);
}
if (cmd != MODEKEYCOPY_COPYPIPE) {
if (args->argc != 2) {
cmdq_error(cmdq, "no argument allowed");
return (CMD_RETURN_ERROR);
}
arg = NULL;
} else {
if (args->argc != 3) {
cmdq_error(cmdq, "no argument given");
return (CMD_RETURN_ERROR);
}
arg = args->argv[2];
}
mtmp.key = key;
mtmp.mode = !!args_has(args, 'c');
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) != NULL) {
mbind->cmd = cmd;
return (CMD_RETURN_NORMAL);
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
mbind = xmalloc(sizeof *mbind);
mbind->key = mtmp.key;
mbind->mode = mtmp.mode;
RB_INSERT(mode_key_tree, mtab->tree, mbind);
}
mbind = xmalloc(sizeof *mbind);
mbind->key = mtmp.key;
mbind->mode = mtmp.mode;
mbind->cmd = cmd;
RB_INSERT(mode_key_tree, mtab->tree, mbind);
mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
return (CMD_RETURN_NORMAL);
}
+9 -8
View File
@@ -26,7 +26,7 @@
* Break pane off into a window.
*/
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_break_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_break_pane_entry = {
"break-pane", "breakp",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_break_pane_entry = {
};
enum cmd_retval
cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -54,15 +54,17 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *template;
char *cp;
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
if (window_count_panes(wl->window) == 1) {
ctx->error(ctx, "can't break with only one pane");
cmdq_error(cmdq, "can't break with only one pane");
return (CMD_RETURN_ERROR);
}
w = wl->window;
server_unzoom_window(w);
TAILQ_REMOVE(&w->panes, wp, entry);
if (wp == w->active) {
w->active = w->last;
@@ -82,7 +84,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
name = default_window_name(w);
window_set_name(w, name);
free(name);
layout_init(w);
layout_init(w, wp);
base_idx = options_get_number(&s->options, "base-index");
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
@@ -93,19 +95,18 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
server_status_session_group(s);
if (args_has(args, 'P')) {
if ((template = args_get(args, 'F')) == NULL)
template = BREAK_PANE_TEMPLATE;
ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL)
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
cmdq_print(cmdq, "%s", cp);
free(cp);
format_free(ft);
+135 -42
View File
@@ -24,15 +24,21 @@
#include "tmux.h"
/*
* Write the entire contents of a pane to a buffer.
* Write the entire contents of a pane to a buffer or stdout.
*/
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *);
char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
char *cmd_capture_pane_pending(struct args *, struct window_pane *,
size_t *);
char *cmd_capture_pane_history(struct args *, struct cmd_q *,
struct window_pane *, size_t *);
const struct cmd_entry cmd_capture_pane_entry = {
"capture-pane", "capturep",
"b:E:S:t:", 0, 0,
"[-b buffer-index] [-E end-line] [-S start-line] "
"ab:CeE:JpPqS:t:", 0, 0,
"[-aCeJpPq] [-b buffer-index] [-E end-line] [-S start-line]"
CMD_TARGET_PANE_USAGE,
0,
NULL,
@@ -40,25 +46,69 @@ const struct cmd_entry cmd_capture_pane_entry = {
cmd_capture_pane_exec
};
enum cmd_retval
cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
char *
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
{
buf = xrealloc(buf, 1, *len + linelen + 1);
memcpy(buf + *len, line, linelen);
*len += linelen;
return (buf);
}
char *
cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
size_t *len)
{
char *buf, *line, tmp[5];
size_t linelen;
u_int i;
if (wp->ictx.since_ground == NULL)
return (xstrdup(""));
line = EVBUFFER_DATA(wp->ictx.since_ground);
linelen = EVBUFFER_LENGTH(wp->ictx.since_ground);
buf = xstrdup("");
if (args_has(args, 'C')) {
for (i = 0; i < linelen; i++) {
if (line[i] >= ' ') {
tmp[0] = line[i];
tmp[1] = '\0';
} else
xsnprintf(tmp, sizeof tmp, "\\%03o", line[i]);
buf = cmd_capture_pane_append(buf, len, tmp,
strlen(tmp));
}
} else
buf = cmd_capture_pane_append(buf, len, line, linelen);
return (buf);
}
char *
cmd_capture_pane_history(struct args *args, struct cmd_q *cmdq,
struct window_pane *wp, size_t *len)
{
struct args *args = self->args;
struct window_pane *wp;
char *buf, *line, *cause;
struct screen *s;
struct grid *gd;
int buffer, n;
u_int i, limit, top, bottom, tmp;
size_t len, linelen;
const struct grid_line *gl;
struct grid_cell *gc = NULL;
int n, with_codes, escape_c0, join_lines;
u_int i, sx, top, bottom, tmp;
char *cause, *buf, *line;
size_t linelen;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
s = &wp->base;
gd = s->grid;
buf = NULL;
len = 0;
sx = screen_size_x(&wp->base);
if (args_has(args, 'a')) {
gd = wp->saved_grid;
if (gd == NULL) {
if (!args_has(args, 'q')) {
cmdq_error(cmdq, "no alternate screen");
return (NULL);
}
return (xstrdup(""));
}
} else
gd = wp->base.grid;
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
if (cause != NULL) {
@@ -88,37 +138,80 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
top = tmp;
}
with_codes = args_has(args, 'e');
escape_c0 = args_has(args, 'C');
join_lines = args_has(args, 'J');
buf = NULL;
for (i = top; i <= bottom; i++) {
line = grid_string_cells(s->grid, 0, i, screen_size_x(s));
linelen = strlen(line);
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
escape_c0, !join_lines);
linelen = strlen(line);
buf = xrealloc(buf, 1, len + linelen + 1);
memcpy(buf + len, line, linelen);
len += linelen;
buf[len++] = '\n';
buf = cmd_capture_pane_append(buf, len, line, linelen);
free(line);
gl = grid_peek_line(gd, i);
if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED))
buf[(*len)++] = '\n';
free(line);
}
return (buf);
}
limit = options_get_number(&global_options, "buffer-limit");
enum cmd_retval
cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct window_pane *wp;
char *buf, *cause;
int buffer;
u_int limit;
size_t len;
if (!args_has(args, 'b')) {
paste_add(&global_buffers, buf, len, limit);
return (CMD_RETURN_NORMAL);
}
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
free(buf);
free(cause);
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
}
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
free(buf);
len = 0;
if (args_has(args, 'P'))
buf = cmd_capture_pane_pending(args, wp, &len);
else
buf = cmd_capture_pane_history(args, cmdq, wp, &len);
if (buf == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'p')) {
c = cmdq->client;
if (c == NULL ||
(c->session != NULL && !(c->flags & CLIENT_CONTROL))) {
cmdq_error(cmdq, "can't write to stdout");
return (CMD_RETURN_ERROR);
}
evbuffer_add(c->stdout_data, buf, len);
if (args_has(args, 'P') && len > 0)
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
limit = options_get_number(&global_options, "buffer-limit");
if (!args_has(args, 'b')) {
paste_add(&global_buffers, buf, len, limit);
return (CMD_RETURN_NORMAL);
}
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
cmdq_error(cmdq, "buffer %s", cause);
free(buf);
free(cause);
return (CMD_RETURN_ERROR);
}
if (paste_replace(&global_buffers, buffer, buf, len) != 0) {
cmdq_error(cmdq, "no buffer %d", buffer);
free(buf);
return (CMD_RETURN_ERROR);
}
}
return (CMD_RETURN_NORMAL);
+8 -38
View File
@@ -27,10 +27,7 @@
* Enter choice mode to choose a buffer.
*/
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_buffer_callback(struct window_choose_data *);
void cmd_choose_buffer_free(struct window_choose_data *);
enum cmd_retval cmd_choose_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_buffer_entry = {
"choose-buffer", NULL,
@@ -43,9 +40,10 @@ const struct cmd_entry cmd_choose_buffer_entry = {
};
enum cmd_retval
cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_choose_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct window_choose_data *cdata;
struct winlink *wl;
struct paste_buffer *pb;
@@ -53,15 +51,15 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *template;
u_int idx;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
if ((template = args_get(args, 'F')) == NULL)
template = CHOOSE_BUFFER_TEMPLATE;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (paste_get_top(&global_buffers) == NULL)
@@ -77,9 +75,8 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
idx = 0;
while ((pb = paste_walk_stack(&global_buffers, &idx)) != NULL) {
cdata = window_choose_data_create(ctx);
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
cdata->idx = idx - 1;
cdata->client->references++;
cdata->ft_template = xstrdup(template);
format_add(cdata->ft, "line", "%u", idx - 1);
@@ -93,34 +90,7 @@ cmd_choose_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
}
free(action);
window_choose_ready(wl->window->active,
0, cmd_choose_buffer_callback, cmd_choose_buffer_free);
window_choose_ready(wl->window->active, 0, NULL);
return (CMD_RETURN_NORMAL);
}
void
cmd_choose_buffer_callback(struct window_choose_data *cdata)
{
if (cdata == NULL)
return;
if (cdata->client->flags & CLIENT_DEAD)
return;
window_choose_ctx(cdata);
}
void
cmd_choose_buffer_free(struct window_choose_data *data)
{
struct window_choose_data *cdata = data;
if (cdata == NULL)
return;
cdata->client->references--;
free(cdata->command);
free(cdata->ft_template);
free(cdata);
}
+18 -33
View File
@@ -27,10 +27,9 @@
* Enter choice mode to choose a client.
*/
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_choose_client_exec(struct cmd *, struct cmd_q *);
void cmd_choose_client_callback(struct window_choose_data *);
void cmd_choose_client_free(struct window_choose_data *);
const struct cmd_entry cmd_choose_client_entry = {
"choose-client", NULL,
@@ -47,22 +46,23 @@ struct cmd_choose_client_data {
};
enum cmd_retval
cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_choose_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct client *c1;
struct window_choose_data *cdata;
struct winlink *wl;
struct client *c;
const char *template;
char *action;
u_int i, idx, cur;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -78,30 +78,29 @@ cmd_choose_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cur = idx = 0;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
c1 = ARRAY_ITEM(&clients, i);
if (c1 == NULL || c1->session == NULL || c1->tty.path == NULL)
continue;
if (c == ctx->curclient)
if (c1 == cmdq->client)
cur = idx;
idx++;
cdata = window_choose_data_create(ctx);
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
cdata->idx = i;
cdata->client->references++;
cdata->ft_template = xstrdup(template);
format_add(cdata->ft, "line", "%u", i);
format_session(cdata->ft, c->session);
format_client(cdata->ft, c);
format_session(cdata->ft, c1->session);
format_client(cdata->ft, c1);
cdata->command = cmd_template_replace(action, c->tty.path, 1);
cdata->command = cmd_template_replace(action, c1->tty.path, 1);
window_choose_add(wl->window->active, cdata);
}
free(action);
window_choose_ready(wl->window->active,
cur, cmd_choose_client_callback, cmd_choose_client_free);
window_choose_ready(wl->window->active, cur,
cmd_choose_client_callback);
return (CMD_RETURN_NORMAL);
}
@@ -113,7 +112,7 @@ cmd_choose_client_callback(struct window_choose_data *cdata)
if (cdata == NULL)
return;
if (cdata->client->flags & CLIENT_DEAD)
if (cdata->start_client->flags & CLIENT_DEAD)
return;
if (cdata->idx > ARRAY_LENGTH(&clients) - 1)
@@ -122,19 +121,5 @@ cmd_choose_client_callback(struct window_choose_data *cdata)
if (c == NULL || c->session == NULL)
return;
window_choose_ctx(cdata);
}
void
cmd_choose_client_free(struct window_choose_data *cdata)
{
if (cdata == NULL)
return;
cdata->client->references--;
free(cdata->ft_template);
free(cdata->command);
format_free(cdata->ft);
free(cdata);
window_choose_data_run(cdata);
}
+8 -33
View File
@@ -31,10 +31,7 @@
* Enter choose mode to choose a custom list.
*/
enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_list_callback(struct window_choose_data *);
void cmd_choose_list_free(struct window_choose_data *);
enum cmd_retval cmd_choose_list_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_list_entry = {
"choose-list", NULL,
@@ -47,23 +44,24 @@ const struct cmd_entry cmd_choose_list_entry = {
};
enum cmd_retval
cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_choose_list_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct winlink *wl;
const char *list1;
char *template, *item, *copy, *list;
u_int idx;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
if ((list1 = args_get(args, 'l')) == NULL)
return (CMD_RETURN_ERROR);
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -80,7 +78,7 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
{
if (*item == '\0') /* no empty entries */
continue;
window_choose_add_item(wl->window->active, ctx, wl, item,
window_choose_add_item(wl->window->active, c, wl, item,
template, idx);
idx++;
}
@@ -92,32 +90,9 @@ cmd_choose_list_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_ERROR);
}
window_choose_ready(wl->window->active, 0, cmd_choose_list_callback,
cmd_choose_list_free);
window_choose_ready(wl->window->active, 0, NULL);
free(template);
return (CMD_RETURN_NORMAL);
}
void
cmd_choose_list_callback(struct window_choose_data *cdata)
{
if (cdata == NULL || (cdata->client->flags & CLIENT_DEAD))
return;
window_choose_ctx(cdata);
}
void
cmd_choose_list_free(struct window_choose_data *cdata)
{
cdata->session->references--;
cdata->client->references--;
free(cdata->ft_template);
free(cdata->command);
format_free(cdata->ft);
free(cdata);
}
+15 -40
View File
@@ -32,15 +32,12 @@
* Enter choice mode to choose a session and/or window.
*/
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_ctx *);
void cmd_choose_tree_callback(struct window_choose_data *);
void cmd_choose_tree_free(struct window_choose_data *);
enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_choose_tree_entry = {
"choose-tree", NULL,
"S:W:swub:c:t:", 0, 1,
"[-swu] [-b session-template] [-c window template] [-S format] " \
"[-suw] [-b session-template] [-c window template] [-S format] " \
"[-W format] " CMD_TARGET_WINDOW_USAGE,
0,
NULL,
@@ -69,11 +66,12 @@ const struct cmd_entry cmd_choose_window_entry = {
};
enum cmd_retval
cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_choose_tree_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl, *wm;
struct session *s, *s2;
struct client *c;
struct window_choose_data *wcd = NULL;
const char *ses_template, *win_template;
char *final_win_action, *cur_win_template;
@@ -86,14 +84,15 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
ses_template = win_template = NULL;
ses_action = win_action = NULL;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
s = ctx->curclient->session;
if ((s = c->session) == NULL)
return (CMD_RETURN_ERROR);
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
@@ -175,7 +174,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmd_ctx *ctx)
}
wcd = window_choose_add_session(wl->window->active,
ctx, s2, ses_template, (char *)ses_action, idx_ses);
c, s2, ses_template, ses_action, idx_ses);
/* If we're just choosing sessions, skip choosing windows. */
if (sflag && !wflag) {
@@ -204,8 +203,9 @@ windows_only:
cur_win = idx_ses;
}
xasprintf(&final_win_action, "%s ; %s", win_action,
wcd ? wcd->command : "");
xasprintf(&final_win_action, "%s %s %s",
wcd != NULL ? wcd->command : "",
wcd != NULL ? ";" : "", win_action);
if (win_ses != win_max)
cur_win_template = final_win_template_middle;
@@ -213,7 +213,7 @@ windows_only:
cur_win_template = final_win_template_last;
window_choose_add_window(wl->window->active,
ctx, s2, wm, cur_win_template,
c, s2, wm, cur_win_template,
final_win_action,
(wflag && !sflag) ? win_ses : idx_ses);
@@ -230,35 +230,10 @@ windows_only:
free(final_win_template_middle);
free(final_win_template_last);
window_choose_ready(wl->window->active, cur_win,
cmd_choose_tree_callback, cmd_choose_tree_free);
window_choose_ready(wl->window->active, cur_win, NULL);
if (args_has(args, 'u'))
window_choose_expand_all(wl->window->active);
return (CMD_RETURN_NORMAL);
}
void
cmd_choose_tree_callback(struct window_choose_data *cdata)
{
if (cdata == NULL)
return;
if (cdata->client->flags & CLIENT_DEAD)
return;
window_choose_ctx(cdata);
}
void
cmd_choose_tree_free(struct window_choose_data *cdata)
{
cdata->session->references--;
cdata->client->references--;
free(cdata->ft_template);
free(cdata->command);
format_free(cdata->ft);
free(cdata);
}
+3 -3
View File
@@ -24,7 +24,7 @@
* Clear pane history.
*/
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_clear_history_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_clear_history_entry = {
"clear-history", "clearhist",
@@ -37,13 +37,13 @@ const struct cmd_entry cmd_clear_history_entry = {
};
enum cmd_retval
cmd_clear_history_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_clear_history_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct window_pane *wp;
struct grid *gd;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
gd = wp->base.grid;
+3 -3
View File
@@ -24,7 +24,7 @@
* Enter clock mode.
*/
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_clock_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_clock_mode_entry = {
"clock-mode", NULL,
@@ -37,12 +37,12 @@ const struct cmd_entry cmd_clock_mode_entry = {
};
enum cmd_retval
cmd_clock_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_clock_mode_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct window_pane *wp;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
window_pane_set_mode(wp, &window_clock_mode);
+5 -15
View File
@@ -31,7 +31,7 @@
void cmd_command_prompt_key_binding(struct cmd *, int);
int cmd_command_prompt_check(struct args *);
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_command_prompt_exec(struct cmd *, struct cmd_q *);
int cmd_command_prompt_callback(void *, const char *);
void cmd_command_prompt_free(void *);
@@ -85,7 +85,7 @@ cmd_command_prompt_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *inputs, *prompts;
@@ -94,7 +94,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_ctx *ctx)
char *prompt, *ptr, *input = NULL;
size_t n;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (c->prompt_string != NULL)
@@ -150,7 +150,6 @@ cmd_command_prompt_callback(void *data, const char *s)
struct cmd_command_prompt_cdata *cdata = data;
struct client *c = cdata->c;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
char *cause, *new_template, *prompt, *ptr;
char *input = NULL;
@@ -175,7 +174,7 @@ cmd_command_prompt_callback(void *data, const char *s)
return (1);
}
if (cmd_string_parse(new_template, &cmdlist, &cause) != 0) {
if (cmd_string_parse(new_template, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(c, "%s", cause);
@@ -184,16 +183,7 @@ cmd_command_prompt_callback(void *data, const char *s)
return (0);
}
ctx.msgdata = NULL;
ctx.curclient = c;
ctx.error = key_bindings_error;
ctx.print = key_bindings_print;
ctx.info = key_bindings_info;
ctx.cmdclient = NULL;
cmd_list_exec(cmdlist, &ctx);
cmdq_run(c->cmdq, cmdlist);
cmd_list_free(cmdlist);
if (c->prompt_callbackfn != (void *) &cmd_command_prompt_callback)
+20 -27
View File
@@ -27,7 +27,7 @@
*/
void cmd_confirm_before_key_binding(struct cmd *, int);
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_confirm_before_exec(struct cmd *, struct cmd_q *);
int cmd_confirm_before_callback(void *, const char *);
void cmd_confirm_before_free(void *);
@@ -43,8 +43,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
};
struct cmd_confirm_before_data {
struct client *c;
char *cmd;
struct client *client;
};
void
@@ -66,7 +66,7 @@ cmd_confirm_before_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_confirm_before_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct cmd_confirm_before_data *cdata;
@@ -74,12 +74,7 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
char *cmd, *copy, *new_prompt, *ptr;
const char *prompt;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
return (CMD_RETURN_ERROR);
}
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if ((prompt = args_get(args, 'p')) != NULL)
@@ -93,48 +88,43 @@ cmd_confirm_before_exec(struct cmd *self, struct cmd_ctx *ctx)
cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]);
cdata->c = c;
status_prompt_set(cdata->c, new_prompt, NULL,
cdata->client = c;
cdata->client->references++;
status_prompt_set(c, new_prompt, NULL,
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
PROMPT_SINGLE);
free(new_prompt);
return (CMD_RETURN_YIELD);
return (CMD_RETURN_NORMAL);
}
int
cmd_confirm_before_callback(void *data, const char *s)
{
struct cmd_confirm_before_data *cdata = data;
struct client *c = cdata->c;
struct client *c = cdata->client;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
char *cause;
if (c->flags & CLIENT_DEAD)
return (0);
if (s == NULL || *s == '\0')
return (0);
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
return (0);
if (cmd_string_parse(cdata->cmd, &cmdlist, &cause) != 0) {
if (cmd_string_parse(cdata->cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
*cause = toupper((u_char) *cause);
status_message_set(c, "%s", cause);
cmdq_error(c->cmdq, "%s", cause);
free(cause);
}
return (0);
}
ctx.msgdata = NULL;
ctx.curclient = c;
ctx.error = key_bindings_error;
ctx.print = key_bindings_print;
ctx.info = key_bindings_info;
ctx.cmdclient = NULL;
cmd_list_exec(cmdlist, &ctx);
cmdq_run(c->cmdq, cmdlist);
cmd_list_free(cmdlist);
return (0);
@@ -144,6 +134,9 @@ void
cmd_confirm_before_free(void *data)
{
struct cmd_confirm_before_data *cdata = data;
struct client *c = cdata->client;
c->references--;
free(cdata->cmd);
free(cdata);
+3 -3
View File
@@ -25,7 +25,7 @@
*/
void cmd_copy_mode_key_binding(struct cmd *, int);
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_copy_mode_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_copy_mode_entry = {
"copy-mode", NULL,
@@ -46,12 +46,12 @@ cmd_copy_mode_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_copy_mode_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct window_pane *wp;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
+4 -4
View File
@@ -26,7 +26,7 @@
* Delete a paste buffer.
*/
enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_delete_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_delete_buffer_entry = {
"delete-buffer", "deleteb",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_delete_buffer_entry = {
};
enum cmd_retval
cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_delete_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
char *cause;
@@ -52,13 +52,13 @@ cmd_delete_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (paste_free_index(&global_buffers, buffer) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
+5 -5
View File
@@ -24,7 +24,7 @@
* Detach a client.
*/
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_detach_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_detach_client_entry = {
"detach-client", "detach",
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_detach_client_entry = {
};
enum cmd_retval
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_detach_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c, *c2;
@@ -51,7 +51,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
msgtype = MSG_DETACH;
if (args_has(args, 's')) {
s = cmd_find_session(ctx, args_get(args, 's'), 0);
s = cmd_find_session(cmdq, args_get(args, 's'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
@@ -61,7 +61,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(c, msgtype, NULL, 0);
}
} else {
c = cmd_find_client(ctx, args_get(args, 't'));
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
@@ -76,5 +76,5 @@ cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
server_write_client(c, msgtype, NULL, 0);
}
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_STOP);
}
+21 -11
View File
@@ -27,7 +27,7 @@
* Displays a message in the status line.
*/
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_display_message_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_display_message_entry = {
"display-message", "display",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_display_message_entry = {
};
enum cmd_retval
cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_display_message_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
@@ -55,24 +55,33 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
time_t t;
size_t len;
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 't')) {
wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp);
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR);
} else {
wl = cmd_find_pane(ctx, NULL, &s, &wp);
wl = cmd_find_pane(cmdq, NULL, &s, &wp);
if (wl == NULL)
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'F') && args->argc != 0) {
ctx->error(ctx, "only one of -F or argument must be given");
cmdq_error(cmdq, "only one of -F or argument must be given");
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'c')) {
c = cmd_find_client(cmdq, args_get(args, 'c'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
} else {
c = cmd_current_client(cmdq);
if (c == NULL && !args_has(self->args, 'p')) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
}
template = args_get(args, 'F');
if (args->argc != 0)
template = args->argv[0];
@@ -80,7 +89,8 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
template = DISPLAY_MESSAGE_TEMPLATE;
ft = format_create();
format_client(ft, c);
if (c != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wp);
@@ -91,11 +101,11 @@ cmd_display_message_exec(struct cmd *self, struct cmd_ctx *ctx)
msg = format_expand(ft, out);
if (args_has(self->args, 'p'))
ctx->print(ctx, "%s", msg);
cmdq_print(cmdq, "%s", msg);
else
status_message_set(c, "%s", msg);
free(msg);
format_free(ft);
return (CMD_RETURN_NORMAL);
}
+3 -3
View File
@@ -24,7 +24,7 @@
* Display panes on a client.
*/
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_display_panes_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_display_panes_entry = {
"display-panes", "displayp",
@@ -37,12 +37,12 @@ const struct cmd_entry cmd_display_panes_entry = {
};
enum cmd_retval
cmd_display_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_display_panes_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
server_set_identify(c);
+11 -26
View File
@@ -28,10 +28,9 @@
* Find window containing text.
*/
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmd_q *);
void cmd_find_window_callback(struct window_choose_data *);
void cmd_find_window_free(struct window_choose_data *);
/* Flags for determining matching behavior. */
#define CMD_FIND_WINDOW_BY_TITLE 0x1
@@ -128,9 +127,10 @@ cmd_find_window_match(struct cmd_find_window_data_list *find_list,
}
enum cmd_retval
cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_find_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct window_choose_data *cdata;
struct session *s;
struct winlink *wl, *wm;
@@ -139,13 +139,13 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *template;
u_int i, match_flags;
if (ctx->curclient == NULL) {
ctx->error(ctx, "must be run interactively");
if ((c = cmd_current_client(cmdq)) == NULL) {
cmdq_error(cmdq, "no client available");
return (CMD_RETURN_ERROR);
}
s = ctx->curclient->session;
s = c->session;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
if ((template = args_get(args, 'F')) == NULL)
@@ -162,7 +162,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
free(searchstr);
if (ARRAY_LENGTH(&find_list) == 0) {
ctx->error(ctx, "no windows matching: %s", str);
cmdq_error(cmdq, "no windows matching: %s", str);
ARRAY_FREE(&find_list);
return (CMD_RETURN_ERROR);
}
@@ -180,9 +180,8 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
for (i = 0; i < ARRAY_LENGTH(&find_list); i++) {
wm = ARRAY_ITEM(&find_list, i).wl;
cdata = window_choose_data_create(ctx);
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
cdata->idx = wm->idx;
cdata->client->references++;
cdata->wl = wm;
cdata->ft_template = xstrdup(template);
@@ -198,8 +197,7 @@ cmd_find_window_exec(struct cmd *self, struct cmd_ctx *ctx)
window_choose_add(wl->window->active, cdata);
}
window_choose_ready(wl->window->active,
0, cmd_find_window_callback, cmd_find_window_free);
window_choose_ready(wl->window->active, 0, cmd_find_window_callback);
out:
ARRAY_FREE(&find_list);
@@ -215,7 +213,7 @@ cmd_find_window_callback(struct window_choose_data *cdata)
if (cdata == NULL)
return;
s = cdata->session;
s = cdata->start_session;
if (!session_alive(s))
return;
@@ -228,16 +226,3 @@ cmd_find_window_callback(struct window_choose_data *cdata)
recalculate_sizes();
}
}
void
cmd_find_window_free(struct window_choose_data *cdata)
{
if (cdata == NULL)
return;
cdata->session->references--;
free(cdata->ft_template);
format_free(cdata->ft);
free(cdata);
}
+3 -3
View File
@@ -24,7 +24,7 @@
* Cause client to report an error and exit with 1 if session doesn't exist.
*/
enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_has_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
@@ -37,11 +37,11 @@ const struct cmd_entry cmd_has_session_entry = {
};
enum cmd_retval
cmd_has_session_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_has_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
if (cmd_find_session(ctx, args_get(args, 't'), 0) == NULL)
if (cmd_find_session(cmdq, args_get(args, 't'), 0) == NULL)
return (CMD_RETURN_ERROR);
return (CMD_RETURN_NORMAL);
+84 -28
View File
@@ -29,15 +29,16 @@
* Executes a tmux command if a shell command returns true or false.
*/
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmd_q *);
void cmd_if_shell_callback(struct job *);
void cmd_if_shell_done(struct cmd_q *);
void cmd_if_shell_free(void *);
const struct cmd_entry cmd_if_shell_entry = {
"if-shell", "if",
"", 2, 3,
"shell-command command [command]",
"bt:", 2, 3,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command command [command]",
0,
NULL,
NULL,
@@ -47,15 +48,43 @@ const struct cmd_entry cmd_if_shell_entry = {
struct cmd_if_shell_data {
char *cmd_if;
char *cmd_else;
struct cmd_ctx ctx;
struct cmd_q *cmdq;
int bflag;
int started;
};
enum cmd_retval
cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_if_shell_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct cmd_if_shell_data *cdata;
const char *shellcmd = args->argv[0];
char *shellcmd;
struct client *c;
struct session *s = NULL;
struct winlink *wl = NULL;
struct window_pane *wp = NULL;
struct format_tree *ft;
if (args_has(args, 't'))
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
else {
c = cmd_find_client(cmdq, NULL, 1);
if (c != NULL && c->session != NULL) {
s = c->session;
wl = s->curw;
wp = wl->window->active;
}
}
ft = format_create();
if (s != NULL)
format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
cdata = xmalloc(sizeof *cdata);
cdata->cmd_if = xstrdup(args->argv[1]);
@@ -63,56 +92,83 @@ cmd_if_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cdata->cmd_else = xstrdup(args->argv[2]);
else
cdata->cmd_else = NULL;
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
cdata->bflag = args_has(args, 'b');
if (ctx->cmdclient != NULL)
ctx->cmdclient->references++;
if (ctx->curclient != NULL)
ctx->curclient->references++;
cdata->started = 0;
cdata->cmdq = cmdq;
cmdq->references++;
job_run(shellcmd, cmd_if_shell_callback, cmd_if_shell_free, cdata);
job_run(shellcmd, s, cmd_if_shell_callback, cmd_if_shell_free, cdata);
free(shellcmd);
return (CMD_RETURN_YIELD); /* don't let client exit */
if (cdata->bflag)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}
void
cmd_if_shell_callback(struct job *job)
{
struct cmd_if_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx;
struct cmd_q *cmdq = cdata->cmdq, *cmdq1;
struct cmd_list *cmdlist;
char *cause, *cmd;
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0) {
if (cmdq->dead)
return;
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
cmd = cdata->cmd_else;
if (cmd == NULL)
return;
} else
else
cmd = cdata->cmd_if;
if (cmd_string_parse(cmd, &cmdlist, &cause) != 0) {
if (cmd == NULL)
return;
if (cmd_string_parse(cmd, &cmdlist, NULL, 0, &cause) != 0) {
if (cause != NULL) {
ctx->error(ctx, "%s", cause);
cmdq_error(cmdq, "%s", cause);
free(cause);
}
return;
}
cmd_list_exec(cmdlist, ctx);
cdata->started = 1;
cmdq1 = cmdq_new(cmdq->client);
cmdq1->emptyfn = cmd_if_shell_done;
cmdq1->data = cdata;
cmdq_run(cmdq1, cmdlist);
cmd_list_free(cmdlist);
}
void
cmd_if_shell_done(struct cmd_q *cmdq1)
{
struct cmd_if_shell_data *cdata = cmdq1->data;
struct cmd_q *cmdq = cdata->cmdq;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
cmdq_free(cmdq1);
free(cdata->cmd_else);
free(cdata->cmd_if);
free(cdata);
}
void
cmd_if_shell_free(void *data)
{
struct cmd_if_shell_data *cdata = data;
struct cmd_ctx *ctx = &cdata->ctx;
struct cmd_q *cmdq = cdata->cmdq;
if (ctx->cmdclient != NULL) {
ctx->cmdclient->references--;
ctx->cmdclient->flags |= CLIENT_EXIT;
}
if (ctx->curclient != NULL)
ctx->curclient->references--;
if (cdata->started)
return;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
free(cdata->cmd_else);
free(cdata->cmd_if);
+14 -12
View File
@@ -29,9 +29,9 @@
*/
void cmd_join_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_join_pane_exec(struct cmd *, struct cmd_q *);
enum cmd_retval join_pane(struct cmd *, struct cmd_ctx *, int);
enum cmd_retval join_pane(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_join_pane_entry = {
"join-pane", "joinp",
@@ -68,13 +68,13 @@ cmd_join_pane_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_join_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
return (join_pane(self, ctx, self->entry == &cmd_join_pane_entry));
return (join_pane(self, cmdq, self->entry == &cmd_join_pane_entry));
}
enum cmd_retval
join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
{
struct args *args = self->args;
struct session *dst_s;
@@ -86,23 +86,25 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
enum layout_type type;
struct layout_cell *lc;
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), &dst_s, &dst_wp);
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), &dst_s, &dst_wp);
if (dst_wl == NULL)
return (CMD_RETURN_ERROR);
dst_w = dst_wl->window;
dst_idx = dst_wl->idx;
server_unzoom_window(dst_w);
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
if (src_wl == NULL)
return (CMD_RETURN_ERROR);
src_w = src_wl->window;
server_unzoom_window(src_w);
if (not_same_window && src_w == dst_w) {
ctx->error(ctx, "can't join a pane to its own window");
cmdq_error(cmdq, "can't join a pane to its own window");
return (CMD_RETURN_ERROR);
}
if (!not_same_window && src_wp == dst_wp) {
ctx->error(ctx, "source and target panes must be different");
cmdq_error(cmdq, "source and target panes must be different");
return (CMD_RETURN_ERROR);
}
@@ -114,14 +116,14 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
if (args_has(args, 'l')) {
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "size %s", cause);
cmdq_error(cmdq, "size %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
} else if (args_has(args, 'p')) {
percentage = args_strtonum(args, 'p', 0, 100, &cause);
if (cause != NULL) {
ctx->error(ctx, "percentage %s", cause);
cmdq_error(cmdq, "percentage %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -132,7 +134,7 @@ join_pane(struct cmd *self, struct cmd_ctx *ctx, int not_same_window)
}
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'));
if (lc == NULL) {
ctx->error(ctx, "create pane failed: pane too small");
cmdq_error(cmdq, "create pane failed: pane too small");
return (CMD_RETURN_ERROR);
}
+4 -3
View File
@@ -26,7 +26,7 @@
* Kill pane.
*/
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_kill_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_kill_pane_entry = {
"kill-pane", "killp",
@@ -39,14 +39,15 @@ const struct cmd_entry cmd_kill_pane_entry = {
};
enum cmd_retval
cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
struct window_pane *loopwp, *tmpwp, *wp;
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
return (CMD_RETURN_ERROR);
server_unzoom_window(wl->window);
if (window_count_panes(wl->window) == 1) {
/* Only one pane, kill the window. */
+2 -3
View File
@@ -27,7 +27,7 @@
* Kill the server and do nothing else.
*/
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_kill_server_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_kill_server_entry = {
"kill-server", NULL,
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_kill_server_entry = {
cmd_kill_server_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
cmd_kill_server_exec(unused struct cmd *self, unused struct cmd_q *cmdq)
{
kill(getpid(), SIGTERM);
+3 -3
View File
@@ -27,7 +27,7 @@
* Note this deliberately has no alias to make it hard to hit by accident.
*/
enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_kill_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_kill_session_entry = {
"kill-session", NULL,
@@ -40,12 +40,12 @@ const struct cmd_entry cmd_kill_session_entry = {
};
enum cmd_retval
cmd_kill_session_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_kill_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s, *s2, *s3;
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
+3 -3
View File
@@ -24,7 +24,7 @@
* Destroy window.
*/
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_kill_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_kill_window_entry = {
"kill-window", "killw",
@@ -37,13 +37,13 @@ const struct cmd_entry cmd_kill_window_entry = {
};
enum cmd_retval
cmd_kill_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_kill_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl, *wl2, *wl3;
struct session *s;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'a')) {
+5 -5
View File
@@ -26,7 +26,7 @@
* Link a window into another session.
*/
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_link_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_link_window_entry = {
"link-window", "linkw",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_link_window_entry = {
};
enum cmd_retval
cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_link_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *src, *dst;
@@ -47,15 +47,15 @@ cmd_link_window_exec(struct cmd *self, struct cmd_ctx *ctx)
char *cause;
int idx, kflag, dflag;
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
return (CMD_RETURN_ERROR);
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
return (CMD_RETURN_ERROR);
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
ctx->error(ctx, "can't link window: %s", cause);
cmdq_error(cmdq, "can't link window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
+3 -4
View File
@@ -27,7 +27,7 @@
* List paste buffers.
*/
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_buffers_entry = {
"list-buffers", "lsb",
@@ -39,9 +39,8 @@ const struct cmd_entry cmd_list_buffers_entry = {
cmd_list_buffers_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
cmd_list_buffers_exec(unused struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct paste_buffer *pb;
@@ -60,7 +59,7 @@ cmd_list_buffers_exec(unused struct cmd *self, struct cmd_ctx *ctx)
format_paste_buffer(ft, pb);
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
cmdq_print(cmdq, "%s", line);
free(line);
format_free(ft);
+4 -5
View File
@@ -28,7 +28,7 @@
* List all clients.
*/
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_clients_entry = {
"list-clients", "lsc",
@@ -40,9 +40,8 @@ const struct cmd_entry cmd_list_clients_entry = {
cmd_list_clients_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_clients_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
@@ -53,7 +52,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
char *line;
if (args_has(args, 't')) {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
} else
@@ -76,7 +75,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
format_client(ft, c);
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
cmdq_print(cmdq, "%s", line);
free(line);
format_free(ft);
+11 -5
View File
@@ -24,7 +24,7 @@
* List all commands with usages.
*/
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_commands_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_commands_entry = {
"list-commands", "lscm",
@@ -36,14 +36,20 @@ const struct cmd_entry cmd_list_commands_entry = {
cmd_list_commands_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_list_commands_exec(unused struct cmd *self, struct cmd_ctx *ctx)
cmd_list_commands_exec(unused struct cmd *self, struct cmd_q *cmdq)
{
const struct cmd_entry **entryp;
for (entryp = cmd_table; *entryp != NULL; entryp++)
ctx->print(ctx, "%s %s", (*entryp)->name, (*entryp)->usage);
for (entryp = cmd_table; *entryp != NULL; entryp++) {
if ((*entryp)->alias != NULL) {
cmdq_print(cmdq, "%s (%s) %s", (*entryp)->name,
(*entryp)->alias, (*entryp)->usage);
} else {
cmdq_print(cmdq, "%s %s", (*entryp)->name,
(*entryp)->usage);
}
}
return (CMD_RETURN_NORMAL);
}
+12 -9
View File
@@ -26,8 +26,8 @@
* List key bindings.
*/
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_list_keys_table(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_keys_entry = {
"list-keys", "lsk",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_list_keys_entry = {
};
enum cmd_retval
cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_keys_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct key_binding *bd;
@@ -50,7 +50,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
int width, keywidth;
if (args_has(args, 't'))
return (cmd_list_keys_table(self, ctx));
return (cmd_list_keys_table(self, cmdq));
width = 0;
@@ -91,14 +91,14 @@ cmd_list_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
continue;
cmd_list_print(bd->cmdlist, tmp + used, (sizeof tmp) - used);
ctx->print(ctx, "bind-key %s", tmp);
cmdq_print(cmdq, "bind-key %s", tmp);
}
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_keys_table(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *tablename;
@@ -109,7 +109,7 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) {
ctx->error(ctx, "unknown key table: %s", tablename);
cmdq_error(cmdq, "unknown key table: %s", tablename);
return (CMD_RETURN_ERROR);
}
@@ -138,9 +138,12 @@ cmd_list_keys_table(struct cmd *self, struct cmd_ctx *ctx)
mode = "c";
cmdstr = mode_key_tostring(mtab->cmdstr, mbind->cmd);
if (cmdstr != NULL) {
ctx->print(ctx, "bind-key -%st %s%s %*s %s",
cmdq_print(cmdq, "bind-key -%st %s%s %*s %s%s%s%s",
mode, any_mode && *mode == '\0' ? " " : "",
mtab->name, (int) width, key, cmdstr);
mtab->name, (int) width, key, cmdstr,
mbind->arg != NULL ? " \"" : "",
mbind->arg != NULL ? mbind->arg : "",
mbind->arg != NULL ? "\"": "");
}
}
+16 -16
View File
@@ -27,13 +27,13 @@
* List panes on given window.
*/
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_panes_exec(struct cmd *, struct cmd_q *);
void cmd_list_panes_server(struct cmd *, struct cmd_ctx *);
void cmd_list_panes_server(struct cmd *, struct cmd_q *);
void cmd_list_panes_session(
struct cmd *, struct session *, struct cmd_ctx *, int);
struct cmd *, struct session *, struct cmd_q *, int);
void cmd_list_panes_window(struct cmd *,
struct session *, struct winlink *, struct cmd_ctx *, int);
struct session *, struct winlink *, struct cmd_q *, int);
const struct cmd_entry cmd_list_panes_entry = {
"list-panes", "lsp",
@@ -46,51 +46,51 @@ const struct cmd_entry cmd_list_panes_entry = {
};
enum cmd_retval
cmd_list_panes_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_panes_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
struct winlink *wl;
if (args_has(args, 'a'))
cmd_list_panes_server(self, ctx);
cmd_list_panes_server(self, cmdq);
else if (args_has(args, 's')) {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
cmd_list_panes_session(self, s, ctx, 1);
cmd_list_panes_session(self, s, cmdq, 1);
} else {
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
if (wl == NULL)
return (CMD_RETURN_ERROR);
cmd_list_panes_window(self, s, wl, ctx, 0);
cmd_list_panes_window(self, s, wl, cmdq, 0);
}
return (CMD_RETURN_NORMAL);
}
void
cmd_list_panes_server(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_panes_server(struct cmd *self, struct cmd_q *cmdq)
{
struct session *s;
RB_FOREACH(s, sessions, &sessions)
cmd_list_panes_session(self, s, ctx, 2);
cmd_list_panes_session(self, s, cmdq, 2);
}
void
cmd_list_panes_session(
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
struct cmd *self, struct session *s, struct cmd_q *cmdq, int type)
{
struct winlink *wl;
RB_FOREACH(wl, winlinks, &s->windows)
cmd_list_panes_window(self, s, wl, ctx, type);
cmd_list_panes_window(self, s, wl, cmdq, type);
}
void
cmd_list_panes_window(struct cmd *self,
struct session *s, struct winlink *wl, struct cmd_ctx *ctx, int type)
struct session *s, struct winlink *wl, struct cmd_q *cmdq, int type)
{
struct args *args = self->args;
struct window_pane *wp;
@@ -135,7 +135,7 @@ cmd_list_panes_window(struct cmd *self,
format_window_pane(ft, wp);
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
cmdq_print(cmdq, "%s", line);
free(line);
format_free(ft);
+3 -3
View File
@@ -28,7 +28,7 @@
* List all sessions.
*/
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_sessions_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_list_sessions_entry = {
"list-sessions", "ls",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
};
enum cmd_retval
cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_sessions_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
@@ -60,7 +60,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmd_ctx *ctx)
format_session(ft, s);
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
cmdq_print(cmdq, "%s", line);
free(line);
format_free(ft);
+11 -11
View File
@@ -27,11 +27,11 @@
* List windows on given session.
*/
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmd_q *);
void cmd_list_windows_server(struct cmd *, struct cmd_ctx *);
void cmd_list_windows_server(struct cmd *, struct cmd_q *);
void cmd_list_windows_session(
struct cmd *, struct session *, struct cmd_ctx *, int);
struct cmd *, struct session *, struct cmd_q *, int);
const struct cmd_entry cmd_list_windows_entry = {
"list-windows", "lsw",
@@ -44,35 +44,35 @@ const struct cmd_entry cmd_list_windows_entry = {
};
enum cmd_retval
cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_windows_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
if (args_has(args, 'a'))
cmd_list_windows_server(self, ctx);
cmd_list_windows_server(self, cmdq);
else {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
cmd_list_windows_session(self, s, ctx, 0);
cmd_list_windows_session(self, s, cmdq, 0);
}
return (CMD_RETURN_NORMAL);
}
void
cmd_list_windows_server(struct cmd *self, struct cmd_ctx *ctx)
cmd_list_windows_server(struct cmd *self, struct cmd_q *cmdq)
{
struct session *s;
RB_FOREACH(s, sessions, &sessions)
cmd_list_windows_session(self, s, ctx, 1);
cmd_list_windows_session(self, s, cmdq, 1);
}
void
cmd_list_windows_session(
struct cmd *self, struct session *s, struct cmd_ctx *ctx, int type)
struct cmd *self, struct session *s, struct cmd_q *cmdq, int type)
{
struct args *args = self->args;
struct winlink *wl;
@@ -102,7 +102,7 @@ cmd_list_windows_session(
format_window_pane(ft, wl->window->active);
line = format_expand(ft, template);
ctx->print(ctx, "%s", line);
cmdq_print(cmdq, "%s", line);
free(line);
format_free(ft);
+12 -64
View File
@@ -24,7 +24,8 @@
#include "tmux.h"
struct cmd_list *
cmd_list_parse(int argc, char **argv, char **cause)
cmd_list_parse(int argc, char **argv, const char* file, u_int line,
char **cause)
{
struct cmd_list *cmdlist;
struct cmd *cmd;
@@ -34,7 +35,7 @@ cmd_list_parse(int argc, char **argv, char **cause)
copy_argv = cmd_copy_argv(argc, argv);
cmdlist = xmalloc(sizeof *cmdlist);
cmdlist = xcalloc(1, sizeof *cmdlist);
cmdlist->references = 1;
TAILQ_INIT(&cmdlist->list);
@@ -55,7 +56,7 @@ cmd_list_parse(int argc, char **argv, char **cause)
if (arglen != 1)
new_argc++;
cmd = cmd_parse(new_argc, new_argv, cause);
cmd = cmd_parse(new_argc, new_argv, file, line, cause);
if (cmd == NULL)
goto bad;
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
@@ -64,7 +65,8 @@ cmd_list_parse(int argc, char **argv, char **cause)
}
if (lastsplit != argc) {
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit, cause);
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit,
file, line, cause);
if (cmd == NULL)
goto bad;
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
@@ -79,75 +81,21 @@ bad:
return (NULL);
}
enum cmd_retval
cmd_list_exec(struct cmd_list *cmdlist, struct cmd_ctx *ctx)
{
struct client *c = ctx->curclient;
struct cmd *cmd;
enum cmd_retval retval;
int guards, n;
guards = 0;
if (c != NULL && c->session != NULL)
guards = c->flags & CLIENT_CONTROL;
notify_disable();
retval = 0;
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
if (guards)
ctx->print(ctx, "%%begin");
n = cmd_exec(cmd, ctx);
if (guards)
ctx->print(ctx, "%%end");
switch (n)
{
case CMD_RETURN_ERROR:
return (CMD_RETURN_ERROR);
case CMD_RETURN_ATTACH:
/* Client is being attached (send MSG_READY). */
retval = CMD_RETURN_ATTACH;
/*
* Mangle the context to treat any following commands
* as if they were called from inside.
*/
if (ctx->curclient == NULL) {
ctx->curclient = ctx->cmdclient;
ctx->cmdclient = NULL;
ctx->error = key_bindings_error;
ctx->print = key_bindings_print;
ctx->info = key_bindings_info;
}
break;
case CMD_RETURN_YIELD:
if (retval == CMD_RETURN_NORMAL)
retval = CMD_RETURN_YIELD;
break;
case CMD_RETURN_NORMAL:
break;
}
}
notify_enable();
return (retval);
}
void
cmd_list_free(struct cmd_list *cmdlist)
{
struct cmd *cmd;
struct cmd *cmd, *cmd1;
if (--cmdlist->references != 0)
return;
while (!TAILQ_EMPTY(&cmdlist->list)) {
cmd = TAILQ_FIRST(&cmdlist->list);
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
cmd_free(cmd);
args_free(cmd->args);
free(cmd->file);
free(cmd);
}
free(cmdlist);
}
+17 -13
View File
@@ -30,7 +30,7 @@
* Loads a paste buffer from a file.
*/
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_load_buffer_exec(struct cmd *, struct cmd_q *);
void cmd_load_buffer_callback(struct client *, int, void *);
const struct cmd_entry cmd_load_buffer_entry = {
@@ -44,10 +44,10 @@ const struct cmd_entry cmd_load_buffer_entry = {
};
enum cmd_retval
cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_load_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c = ctx->cmdclient;
struct client *c = cmdq->client;
struct session *s;
FILE *f;
const char *path, *newpath, *wd;
@@ -61,7 +61,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -75,16 +75,16 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
error = server_set_stdin_callback (c, cmd_load_buffer_callback,
buffer_ptr, &cause);
if (error != 0) {
ctx->error(ctx, "%s: %s", path, cause);
cmdq_error(cmdq, "%s: %s", path, cause);
free(cause);
return (CMD_RETURN_ERROR);
}
return (CMD_RETURN_YIELD);
return (CMD_RETURN_WAIT);
}
if (c != NULL)
wd = c->cwd;
else if ((s = cmd_current_session(ctx, 0)) != NULL) {
else if ((s = cmd_current_session(cmdq, 0)) != NULL) {
wd = options_get_string(&s->options, "default-path");
if (*wd == '\0')
wd = s->cwd;
@@ -96,7 +96,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
path = newpath;
}
if ((f = fopen(path, "rb")) == NULL) {
ctx->error(ctx, "%s: %s", path, strerror(errno));
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
@@ -105,14 +105,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
while ((ch = getc(f)) != EOF) {
/* Do not let the server die due to memory exhaustion. */
if ((new_pdata = realloc(pdata, psize + 2)) == NULL) {
ctx->error(ctx, "realloc error: %s", strerror(errno));
cmdq_error(cmdq, "realloc error: %s", strerror(errno));
goto error;
}
pdata = new_pdata;
pdata[psize++] = ch;
}
if (ferror(f)) {
ctx->error(ctx, "%s: read error", path);
cmdq_error(cmdq, "%s: read error", path);
goto error;
}
if (pdata != NULL)
@@ -126,7 +126,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL);
}
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
cmdq_error(cmdq, "no buffer %d", buffer);
free(pdata);
return (CMD_RETURN_ERROR);
}
@@ -153,12 +153,13 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
c->stdin_callback = NULL;
c->references--;
c->flags |= CLIENT_EXIT;
if (c->flags & CLIENT_DEAD)
return;
psize = EVBUFFER_LENGTH(c->stdin_data);
if (psize == 0 || (pdata = malloc(psize + 1)) == NULL) {
free(data);
return;
goto out;
}
memcpy(pdata, EVBUFFER_DATA(c->stdin_data), psize);
pdata[psize] = '\0';
@@ -174,4 +175,7 @@ cmd_load_buffer_callback(struct client *c, int closed, void *data)
}
free(data);
out:
cmdq_continue(c->cmdq);
}
+6 -5
View File
@@ -28,7 +28,7 @@
* Lock commands.
*/
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_lock_server_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_lock_server_entry = {
"lock-server", "lock",
@@ -60,9 +60,8 @@ const struct cmd_entry cmd_lock_client_entry = {
cmd_lock_server_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
cmd_lock_server_exec(struct cmd *self, unused struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
@@ -71,11 +70,13 @@ cmd_lock_server_exec(struct cmd *self, unused struct cmd_ctx *ctx)
if (self->entry == &cmd_lock_server_entry)
server_lock();
else if (self->entry == &cmd_lock_session_entry) {
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
server_lock_session(s);
} else {
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
c = cmd_find_client(cmdq, args_get(args, 't'), 0);
if (c == NULL)
return (CMD_RETURN_ERROR);
server_lock_client(c);
}
+6 -6
View File
@@ -26,7 +26,7 @@
* Move a window.
*/
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_move_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_move_window_entry = {
"move-window", "movew",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_move_window_entry = {
};
enum cmd_retval
cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_move_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *src, *dst, *s;
@@ -48,7 +48,7 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
int idx, kflag, dflag;
if (args_has(args, 'r')) {
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
session_renumber_windows(s);
@@ -57,15 +57,15 @@ cmd_move_window_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL);
}
if ((wl = cmd_find_window(ctx, args_get(args, 's'), &src)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 's'), &src)) == NULL)
return (CMD_RETURN_ERROR);
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &dst)) == -2)
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &dst)) == -2)
return (CMD_RETURN_ERROR);
kflag = args_has(self->args, 'k');
dflag = args_has(self->args, 'd');
if (server_link_window(src, wl, dst, idx, kflag, !dflag, &cause) != 0) {
ctx->error(ctx, "can't move window: %s", cause);
cmdq_error(cmdq, "can't move window: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
+77 -83
View File
@@ -31,13 +31,13 @@
*/
enum cmd_retval cmd_new_session_check(struct args *);
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_new_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_session_entry = {
"new-session", "new",
"dn:s:t:x:y:", 0, 1,
"[-d] [-n window-name] [-s session-name] " CMD_TARGET_SESSION_USAGE
" [-x width] [-y height] [command]",
"AdDF:n:Ps:t:x:y:", 0, 1,
"[-AdDP] [-F format] [-n window-name] [-s session-name] "
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
CMD_STARTSERVER|CMD_CANTNEST|CMD_SENDENVIRON,
NULL,
cmd_new_session_check,
@@ -53,62 +53,57 @@ cmd_new_session_check(struct args *args)
}
enum cmd_retval
cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s, *old_s, *groupwith;
struct client *c = cmdq->client;
struct session *s, *groupwith;
struct window *w;
struct environ env;
struct termios tio, *tiop;
struct passwd *pw;
const char *newname, *target, *update, *cwd, *errstr;
char *cmd, *cause;
const char *template;
char *cmd, *cause, *cp;
int detached, idx;
u_int sx, sy;
int already_attached;
struct format_tree *ft;
newname = args_get(args, 's');
if (newname != NULL) {
if (!session_check_name(newname)) {
ctx->error(ctx, "bad session name: %s", newname);
cmdq_error(cmdq, "bad session name: %s", newname);
return (CMD_RETURN_ERROR);
}
if (session_find(newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", newname);
if (args_has(args, 'A')) {
return (cmd_attach_session(cmdq, newname,
args_has(args, 'D'), 0));
}
cmdq_error(cmdq, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
}
}
target = args_get(args, 't');
if (target != NULL) {
groupwith = cmd_find_session(ctx, target, 0);
groupwith = cmd_find_session(cmdq, target, 0);
if (groupwith == NULL)
return (CMD_RETURN_ERROR);
} else
groupwith = NULL;
/*
* There are three cases:
*
* 1. If cmdclient is non-NULL, new-session has been called from the
* command-line - cmdclient is to become a new attached, interactive
* client. Unless -d is given, the terminal must be opened and then
* the client sent MSG_READY.
*
* 2. If cmdclient is NULL, new-session has been called from an
* existing client (such as a key binding).
*
* 3. Both are NULL, the command was in the configuration file. Treat
* this as if -d was given even if it was not.
*
* In all cases, a new additional session needs to be created and
* (unless -d) set as the current session for the client.
*/
/* Set -d if no client. */
detached = args_has(args, 'd');
if (ctx->cmdclient == NULL && ctx->curclient == NULL)
if (c == NULL)
detached = 1;
/* Is this client already attached? */
already_attached = 0;
if (c != NULL && c->session != NULL)
already_attached = 1;
/*
* Save the termios settings, part of which is used for new windows in
* this session.
@@ -118,25 +113,25 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* before opening the terminal as that calls tcsetattr() to prepare for
* tmux taking over.
*/
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
if (!detached && !already_attached && c->tty.fd != -1) {
if (tcgetattr(c->tty.fd, &tio) != 0)
fatal("tcgetattr failed");
tiop = &tio;
} else
tiop = NULL;
/* Open the terminal if necessary. */
if (!detached && ctx->cmdclient != NULL) {
if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
if (!detached && !already_attached) {
if (server_client_open(c, NULL, &cause) != 0) {
cmdq_error(cmdq, "open terminal failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
/* Get the new session working directory. */
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
cwd = ctx->cmdclient->cwd;
if (c != NULL && c->cwd != NULL)
cwd = c->cwd;
else {
pw = getpwuid(getuid());
if (pw->pw_dir != NULL && *pw->pw_dir != '\0')
@@ -146,32 +141,25 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
}
/* Find new session size. */
if (ctx->cmdclient != NULL) {
sx = ctx->cmdclient->tty.sx;
sy = ctx->cmdclient->tty.sy;
} else if (ctx->curclient != NULL) {
sx = ctx->curclient->tty.sx;
sy = ctx->curclient->tty.sy;
if (c != NULL) {
sx = c->tty.sx;
sy = c->tty.sy;
} else {
sx = 80;
sy = 24;
}
if (detached) {
if (args_has(args, 'x')) {
sx = strtonum(
args_get(args, 'x'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "width %s", errstr);
return (CMD_RETURN_ERROR);
}
if (detached && args_has(args, 'x')) {
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
cmdq_error(cmdq, "width %s", errstr);
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'y')) {
sy = strtonum(
args_get(args, 'y'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "height %s", errstr);
return (CMD_RETURN_ERROR);
}
}
if (detached && args_has(args, 'y')) {
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
if (errstr != NULL) {
cmdq_error(cmdq, "height %s", errstr);
return (CMD_RETURN_ERROR);
}
}
if (sy > 0 && options_get_number(&global_s_options, "status"))
@@ -192,14 +180,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Construct the environment. */
environ_init(&env);
update = options_get_string(&global_s_options, "update-environment");
if (ctx->cmdclient != NULL)
environ_update(update, &ctx->cmdclient->environ, &env);
if (c != NULL)
environ_update(update, &c->environ, &env);
/* Create the new session. */
idx = -1 - options_get_number(&global_s_options, "base-index");
s = session_create(newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
if (s == NULL) {
ctx->error(ctx, "create session failed: %s", cause);
cmdq_error(cmdq, "create session failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -208,9 +196,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Set the initial window name if one given. */
if (cmd != NULL && args_has(args, 'n')) {
w = s->curw->window;
window_set_name(w, args_get(args, 'n'));
options_set_number(&w->options, "automatic-rename", 0);
}
@@ -229,25 +215,14 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* taking this session and needs to get MSG_READY and stay around.
*/
if (!detached) {
if (ctx->cmdclient != NULL) {
server_write_ready(ctx->cmdclient);
old_s = ctx->cmdclient->session;
if (old_s != NULL)
ctx->cmdclient->last_session = old_s;
ctx->cmdclient->session = s;
notify_attached_session_changed(ctx->cmdclient);
session_update_activity(s);
server_redraw_client(ctx->cmdclient);
} else {
old_s = ctx->curclient->session;
if (old_s != NULL)
ctx->curclient->last_session = old_s;
ctx->curclient->session = s;
notify_attached_session_changed(ctx->curclient);
session_update_activity(s);
server_redraw_client(ctx->curclient);
}
if (!already_attached)
server_write_ready(c);
else if (c->session != NULL)
c->last_session = c->session;
c->session = s;
notify_attached_session_changed(c);
session_update_activity(s);
server_redraw_client(c);
}
recalculate_sizes();
server_update_socket();
@@ -257,7 +232,26 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* session's current window into more mode and display them now.
*/
if (cfg_finished)
show_cfg_causes(s);
cfg_show_causes(s);
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
/* Print if requested. */
if (args_has(args, 'P')) {
if ((template = args_get(args, 'F')) == NULL)
template = NEW_SESSION_TEMPLATE;
ft = format_create();
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
cp = format_expand(ft, template);
cmdq_print(cmdq, "%s", cp);
free(cp);
format_free(ft);
}
if (!detached)
cmdq->client_exit = 0;
return (CMD_RETURN_NORMAL);
}
+12 -14
View File
@@ -26,7 +26,7 @@
* Create a new window.
*/
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_new_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_new_window_entry = {
"new-window", "neww",
@@ -40,21 +40,19 @@ const struct cmd_entry cmd_new_window_entry = {
};
enum cmd_retval
cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
struct winlink *wl;
struct client *c;
const char *cmd, *cwd;
const char *template;
char *cause;
const char *cmd, *cwd, *template;
char *cause, *cp;
int idx, last, detached;
struct format_tree *ft;
char *cp;
if (args_has(args, 'a')) {
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
if (wl == NULL)
return (CMD_RETURN_ERROR);
idx = wl->idx + 1;
@@ -65,7 +63,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
break;
}
if (last == INT_MAX) {
ctx->error(ctx, "no free window indexes");
cmdq_error(cmdq, "no free window indexes");
return (CMD_RETURN_ERROR);
}
@@ -76,7 +74,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
server_unlink_window(s, wl);
}
} else {
if ((idx = cmd_find_index(ctx, args_get(args, 't'), &s)) == -2)
if ((idx = cmd_find_index(cmdq, args_get(args, 't'), &s)) == -2)
return (CMD_RETURN_ERROR);
}
detached = args_has(args, 'd');
@@ -105,13 +103,13 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
if (idx == -1)
idx = -1 - options_get_number(&s->options, "base-index");
wl = session_new(s, args_get(args, 'n'), cmd, cwd, idx, &cause);
if (wl == NULL) {
ctx->error(ctx, "create window failed: %s", cause);
cmdq_error(cmdq, "create window failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -126,14 +124,14 @@ cmd_new_window_exec(struct cmd *self, struct cmd_ctx *ctx)
template = NEW_WINDOW_TEMPLATE;
ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL)
format_client(ft, c);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, wl->window->active);
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
cmdq_print(cmdq, "%s", cp);
free(cp);
format_free(ft);
+5 -5
View File
@@ -27,7 +27,7 @@
* Paste paste buffer if present.
*/
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_paste_buffer_exec(struct cmd *, struct cmd_q *);
void cmd_paste_buffer_filter(struct window_pane *,
const char *, size_t, const char *, int);
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
};
enum cmd_retval
cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_paste_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct window_pane *wp;
@@ -54,7 +54,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
int buffer;
int pflag;
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (!args_has(args, 'b'))
@@ -62,7 +62,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -73,7 +73,7 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
else {
pb = paste_get_index(&global_buffers, buffer);
if (pb == NULL) {
ctx->error(ctx, "no buffer %d", buffer);
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
}
+6 -7
View File
@@ -31,7 +31,7 @@
* Open pipe to redirect pane output. If already open, close first.
*/
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmd_q *);
void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_pipe_pane_entry = {
};
enum cmd_retval
cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_pipe_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
@@ -54,9 +54,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
char *command;
int old_fd, pipe_fd[2], null_fd;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
c = cmd_find_client(ctx, NULL);
c = cmd_find_client(cmdq, NULL, 1);
/* Destroy the old pipe. */
old_fd = wp->pipe_fd;
@@ -81,14 +81,14 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Open the new pipe. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
ctx->error(ctx, "socketpair error: %s", strerror(errno));
cmdq_error(cmdq, "socketpair error: %s", strerror(errno));
return (CMD_RETURN_ERROR);
}
/* Fork the child. */
switch (fork()) {
case -1:
ctx->error(ctx, "fork error: %s", strerror(errno));
cmdq_error(cmdq, "fork error: %s", strerror(errno));
return (CMD_RETURN_ERROR);
case 0:
/* Child process. */
@@ -130,7 +130,6 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
/* ARGSUSED */
void
cmd_pipe_pane_error_callback(
unused struct bufferevent *bufev, unused short what, void *data)
+282
View File
@@ -0,0 +1,282 @@
/* $Id$ */
/*
* Copyright (c) 2013 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 <ctype.h>
#include <stdlib.h>
#include <time.h>
#include "tmux.h"
/* Create new command queue. */
struct cmd_q *
cmdq_new(struct client *c)
{
struct cmd_q *cmdq;
cmdq = xcalloc(1, sizeof *cmdq);
cmdq->references = 1;
cmdq->dead = 0;
cmdq->client = c;
cmdq->client_exit = 0;
TAILQ_INIT(&cmdq->queue);
cmdq->item = NULL;
cmdq->cmd = NULL;
return (cmdq);
}
/* Free command queue */
int
cmdq_free(struct cmd_q *cmdq)
{
if (--cmdq->references != 0)
return (cmdq->dead);
cmdq_flush(cmdq);
free(cmdq);
return (1);
}
/* Show message from command. */
void printflike2
cmdq_print(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
struct window *w;
va_list ap;
va_start(ap, fmt);
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
w = c->session->curw->window;
if (w->active->mode != &window_copy_mode) {
window_pane_reset_mode(w->active);
window_pane_set_mode(w->active, &window_copy_mode);
window_copy_init_for_output(w->active);
}
window_copy_vadd(w->active, fmt, ap);
}
va_end(ap);
}
/* Show info from command. */
void printflike2
cmdq_info(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
va_list ap;
char *msg;
if (options_get_number(&global_options, "quiet"))
return;
va_start(ap, fmt);
if (c == NULL)
/* nothing */;
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
} else {
xvasprintf(&msg, fmt, ap);
*msg = toupper((u_char) *msg);
status_message_set(c, "%s", msg);
free(msg);
}
va_end(ap);
}
/* Show error from command. */
void printflike2
cmdq_error(struct cmd_q *cmdq, const char *fmt, ...)
{
struct client *c = cmdq->client;
struct cmd *cmd = cmdq->cmd;
va_list ap;
char *msg, *cause;
size_t msglen;
va_start(ap, fmt);
msglen = xvasprintf(&msg, fmt, ap);
va_end(ap);
if (c == NULL) {
xasprintf(&cause, "%s:%u: %s", cmd->file, cmd->line, msg);
ARRAY_ADD(&cfg_causes, cause);
} else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
evbuffer_add(c->stderr_data, msg, msglen);
evbuffer_add(c->stderr_data, "\n", 1);
server_push_stderr(c);
c->retcode = 1;
} else {
*msg = toupper((u_char) *msg);
status_message_set(c, "%s", msg);
}
free(msg);
}
/* Print a guard line. */
int
cmdq_guard(struct cmd_q *cmdq, const char *guard)
{
struct client *c = cmdq->client;
if (c == NULL || c->session == NULL)
return 0;
if (!(c->flags & CLIENT_CONTROL))
return 0;
evbuffer_add_printf(c->stdout_data, "%%%s %ld %u\n", guard,
(long) cmdq->time, cmdq->number);
server_push_stdout(c);
return 1;
}
/* Add command list to queue and begin processing if needed. */
void
cmdq_run(struct cmd_q *cmdq, struct cmd_list *cmdlist)
{
cmdq_append(cmdq, cmdlist);
if (cmdq->item == NULL) {
cmdq->cmd = NULL;
cmdq_continue(cmdq);
}
}
/* Add command list to queue. */
void
cmdq_append(struct cmd_q *cmdq, struct cmd_list *cmdlist)
{
struct cmd_q_item *item;
item = xcalloc(1, sizeof *item);
item->cmdlist = cmdlist;
TAILQ_INSERT_TAIL(&cmdq->queue, item, qentry);
cmdlist->references++;
}
/* Continue processing command queue. Returns 1 if finishes empty. */
int
cmdq_continue(struct cmd_q *cmdq)
{
struct cmd_q_item *next;
enum cmd_retval retval;
int empty, guard;
char s[1024];
notify_disable();
empty = TAILQ_EMPTY(&cmdq->queue);
if (empty)
goto empty;
if (cmdq->item == NULL) {
cmdq->item = TAILQ_FIRST(&cmdq->queue);
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
} else
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
do {
next = TAILQ_NEXT(cmdq->item, qentry);
while (cmdq->cmd != NULL) {
cmd_print(cmdq->cmd, s, sizeof s);
log_debug("cmdq %p: %s (client %d)", cmdq, s,
cmdq->client != NULL ? cmdq->client->ibuf.fd : -1);
cmdq->time = time(NULL);
cmdq->number++;
guard = cmdq_guard(cmdq, "begin");
retval = cmdq->cmd->entry->exec(cmdq->cmd, cmdq);
if (guard) {
if (retval == CMD_RETURN_ERROR)
cmdq_guard(cmdq, "error");
else
cmdq_guard(cmdq, "end");
}
if (retval == CMD_RETURN_ERROR)
break;
if (retval == CMD_RETURN_WAIT)
goto out;
if (retval == CMD_RETURN_STOP) {
cmdq_flush(cmdq);
goto empty;
}
cmdq->cmd = TAILQ_NEXT(cmdq->cmd, qentry);
}
TAILQ_REMOVE(&cmdq->queue, cmdq->item, qentry);
cmd_list_free(cmdq->item->cmdlist);
free(cmdq->item);
cmdq->item = next;
if (cmdq->item != NULL)
cmdq->cmd = TAILQ_FIRST(&cmdq->item->cmdlist->list);
} while (cmdq->item != NULL);
empty:
if (cmdq->client_exit)
cmdq->client->flags |= CLIENT_EXIT;
if (cmdq->emptyfn != NULL)
cmdq->emptyfn(cmdq); /* may free cmdq */
empty = 1;
out:
notify_enable();
return (empty);
}
/* Flush command queue. */
void
cmdq_flush(struct cmd_q *cmdq)
{
struct cmd_q_item *item, *item1;
TAILQ_FOREACH_SAFE(item, &cmdq->queue, qentry, item1) {
TAILQ_REMOVE(&cmdq->queue, item, qentry);
cmd_list_free(item->cmdlist);
free(item);
}
cmdq->item = NULL;
}
+28 -6
View File
@@ -24,12 +24,12 @@
* Refresh client.
*/
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_refresh_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_refresh_client_entry = {
"refresh-client", "refresh",
"St:", 0, 0,
"[-S] " CMD_TARGET_CLIENT_USAGE,
"C:St:", 0, 0,
"[-S] [-C size]" CMD_TARGET_CLIENT_USAGE,
0,
NULL,
NULL,
@@ -37,15 +37,37 @@ const struct cmd_entry cmd_refresh_client_entry = {
};
enum cmd_retval
cmd_refresh_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_refresh_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
const char *size;
u_int w, h;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'S')) {
if (args_has(args, 'C')) {
if ((size = args_get(args, 'C')) == NULL) {
cmdq_error(cmdq, "missing size");
return (CMD_RETURN_ERROR);
}
if (sscanf(size, "%u,%u", &w, &h) != 2) {
cmdq_error(cmdq, "bad size argument");
return (CMD_RETURN_ERROR);
}
if (w < PANE_MINIMUM || w > 5000 ||
h < PANE_MINIMUM || h > 5000) {
cmdq_error(cmdq, "size too small or too big");
return (CMD_RETURN_ERROR);
}
if (!(c->flags & CLIENT_CONTROL)) {
cmdq_error(cmdq, "not a control client");
return (CMD_RETURN_ERROR);
}
if (tty_set_size(&c->tty, w, h))
recalculate_sizes();
} else if (args_has(args, 'S')) {
status_update_jobs(c);
server_status_client(c);
} else
+5 -5
View File
@@ -26,7 +26,7 @@
* Change session name.
*/
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_rename_session_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rename_session_entry = {
"rename-session", "rename",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_rename_session_entry = {
};
enum cmd_retval
cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_rename_session_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
@@ -47,15 +47,15 @@ cmd_rename_session_exec(struct cmd *self, struct cmd_ctx *ctx)
newname = args->argv[0];
if (!session_check_name(newname)) {
ctx->error(ctx, "bad session name: %s", newname);
cmdq_error(cmdq, "bad session name: %s", newname);
return (CMD_RETURN_ERROR);
}
if (session_find(newname) != NULL) {
ctx->error(ctx, "duplicate session: %s", newname);
cmdq_error(cmdq, "duplicate session: %s", newname);
return (CMD_RETURN_ERROR);
}
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
RB_REMOVE(sessions, &sessions, s);
+3 -3
View File
@@ -26,7 +26,7 @@
* Rename a window.
*/
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_rename_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rename_window_entry = {
"rename-window", "renamew",
@@ -39,13 +39,13 @@ const struct cmd_entry cmd_rename_window_entry = {
};
enum cmd_retval
cmd_rename_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_rename_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
struct winlink *wl;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
window_set_name(wl->window, args->argv[0]);
+46 -6
View File
@@ -27,12 +27,12 @@
*/
void cmd_resize_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_resize_pane_entry = {
"resize-pane", "resizep",
"DLRt:U", 0, 1,
"[-DLRU] " CMD_TARGET_PANE_USAGE " [adjustment]",
"DLRt:Ux:y:Z", 0, 1,
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
0,
cmd_resize_pane_key_binding,
NULL,
@@ -75,6 +75,10 @@ cmd_resize_pane_key_binding(struct cmd *self, int key)
self->args = args_create(1, "5");
args_set(self->args, 'R', NULL);
break;
case 'z':
self->args = args_create(0);
args_set(self->args, 'Z', NULL);
break;
default:
self->args = args_create(0);
break;
@@ -82,27 +86,63 @@ cmd_resize_pane_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
struct window *w;
const char *errstr;
char *cause;
struct window_pane *wp;
u_int adjust;
int x, y;
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
if (args_has(args, 'Z')) {
if (w->flags & WINDOW_ZOOMED)
window_unzoom(w);
else
window_zoom(wp);
server_redraw_window(w);
server_status_window(w);
return (CMD_RETURN_NORMAL);
}
server_unzoom_window(w);
if (args->argc == 0)
adjust = 1;
else {
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "adjustment %s", errstr);
cmdq_error(cmdq, "adjustment %s", errstr);
return (CMD_RETURN_ERROR);
}
}
if (args_has(self->args, 'x')) {
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
&cause);
if (cause != NULL) {
cmdq_error(cmdq, "width %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
}
if (args_has(self->args, 'y')) {
y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
&cause);
if (cause != NULL) {
cmdq_error(cmdq, "height %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
}
if (args_has(self->args, 'L'))
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust);
else if (args_has(self->args, 'R'))
+5 -5
View File
@@ -28,7 +28,7 @@
* Respawn a pane (restart the command). Kill existing if -k given.
*/
enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_respawn_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_respawn_pane_entry = {
"respawn-pane", "respawnp",
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_respawn_pane_entry = {
};
enum cmd_retval
cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_respawn_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -53,14 +53,14 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
char *cause;
u_int idx;
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
if (!args_has(self->args, 'k') && wp->fd != -1) {
if (window_pane_index(wp, &idx) != 0)
fatalx("index not found");
ctx->error(ctx, "pane still active: %s:%u.%u",
cmdq_error(cmdq, "pane still active: %s:%u.%u",
s->name, wl->idx, idx);
return (CMD_RETURN_ERROR);
}
@@ -79,7 +79,7 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
else
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
ctx->error(ctx, "respawn pane failed: %s", cause);
cmdq_error(cmdq, "respawn pane failed: %s", cause);
free(cause);
environ_free(&env);
return (CMD_RETURN_ERROR);
+6 -6
View File
@@ -27,7 +27,7 @@
* Respawn a window (restart the command). Kill existing if -k given.
*/
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_respawn_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_respawn_window_entry = {
"respawn-window", "respawnw",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
};
enum cmd_retval
cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -51,7 +51,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *cmd;
char *cause;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
@@ -59,7 +59,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp->fd == -1)
continue;
ctx->error(ctx,
cmdq_error(cmdq,
"window still active: %s:%d", s->name, wl->idx);
return (CMD_RETURN_ERROR);
}
@@ -81,13 +81,13 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
else
cmd = NULL;
if (window_pane_spawn(wp, cmd, NULL, NULL, &env, s->tio, &cause) != 0) {
ctx->error(ctx, "respawn window failed: %s", cause);
cmdq_error(cmdq, "respawn window failed: %s", cause);
free(cause);
environ_free(&env);
server_destroy_pane(wp);
return (CMD_RETURN_ERROR);
}
layout_init(w);
layout_init(w, wp);
window_pane_reset_mode(wp);
screen_reinit(&wp->base);
input_init(wp);
+3 -3
View File
@@ -25,7 +25,7 @@
*/
void cmd_rotate_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_rotate_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_rotate_window_entry = {
"rotate-window", "rotatew",
@@ -46,7 +46,7 @@ cmd_rotate_window_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_rotate_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -55,7 +55,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct layout_cell *lc;
u_int sx, sy, xoff, yoff;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
+55 -38
View File
@@ -29,7 +29,7 @@
* Runs a command without a window.
*/
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmd_q *);
void cmd_run_shell_callback(struct job *);
void cmd_run_shell_free(void *);
@@ -37,8 +37,8 @@ void cmd_run_shell_print(struct job *, const char *);
const struct cmd_entry cmd_run_shell_entry = {
"run-shell", "run",
"t:", 1, 1,
CMD_TARGET_PANE_USAGE " command",
"bt:", 1, 1,
"[-b] " CMD_TARGET_PANE_USAGE " shell-command",
0,
NULL,
NULL,
@@ -47,20 +47,21 @@ const struct cmd_entry cmd_run_shell_entry = {
struct cmd_run_shell_data {
char *cmd;
struct cmd_ctx ctx;
u_int wp_id;
struct cmd_q *cmdq;
int bflag;
int wp_id;
};
void
cmd_run_shell_print(struct job *job, const char *msg)
{
struct cmd_run_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx;
struct window_pane *wp;
struct window_pane *wp = NULL;
wp = window_pane_find_by_id(cdata->wp_id);
if (cdata->wp_id != -1)
wp = window_pane_find_by_id(cdata->wp_id);
if (wp == NULL) {
ctx->print(ctx, "%s", msg);
cmdq_print(cdata->cmdq, "%s", msg);
return;
}
@@ -71,50 +72,72 @@ cmd_run_shell_print(struct job *job, const char *msg)
}
enum cmd_retval
cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_run_shell_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
const char *shellcmd = args->argv[0];
struct window_pane *wp;
char *shellcmd;
struct client *c;
struct session *s = NULL;
struct winlink *wl = NULL;
struct window_pane *wp = NULL;
struct format_tree *ft;
if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 't'))
wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp);
else {
c = cmd_find_client(cmdq, NULL, 1);
if (c != NULL && c->session != NULL) {
s = c->session;
wl = s->curw;
wp = wl->window->active;
}
}
ft = format_create();
if (s != NULL)
format_session(ft, s);
if (s != NULL && wl != NULL)
format_winlink(ft, s, wl);
if (wp != NULL)
format_window_pane(ft, wp);
shellcmd = format_expand(ft, args->argv[0]);
format_free(ft);
cdata = xmalloc(sizeof *cdata);
cdata->cmd = xstrdup(args->argv[0]);
cdata->wp_id = wp->id;
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
cdata->cmd = shellcmd;
cdata->bflag = args_has(args, 'b');
cdata->wp_id = wp != NULL ? (int) wp->id : -1;
if (ctx->cmdclient != NULL)
ctx->cmdclient->references++;
if (ctx->curclient != NULL)
ctx->curclient->references++;
cdata->cmdq = cmdq;
cmdq->references++;
job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
job_run(shellcmd, s, cmd_run_shell_callback, cmd_run_shell_free, cdata);
return (CMD_RETURN_YIELD); /* don't let client exit */
if (cdata->bflag)
return (CMD_RETURN_NORMAL);
return (CMD_RETURN_WAIT);
}
void
cmd_run_shell_callback(struct job *job)
{
struct cmd_run_shell_data *cdata = job->data;
struct cmd_ctx *ctx = &cdata->ctx;
struct cmd_q *cmdq = cdata->cmdq;
char *cmd, *msg, *line;
size_t size;
int retcode;
u_int lines;
if (ctx->cmdclient != NULL && ctx->cmdclient->flags & CLIENT_DEAD)
return;
if (ctx->curclient != NULL && ctx->curclient->flags & CLIENT_DEAD)
if (cmdq->dead)
return;
cmd = cdata->cmd;
lines = 0;
do {
if ((line = evbuffer_readline(job->event->input)) != NULL) {
cmd_run_shell_print (job, line);
cmd_run_shell_print(job, line);
free(line);
lines++;
}
} while (line != NULL);
@@ -131,8 +154,6 @@ cmd_run_shell_callback(struct job *job)
free(line);
}
cmd = cdata->cmd;
msg = NULL;
if (WIFEXITED(job->status)) {
if ((retcode = WEXITSTATUS(job->status)) != 0)
@@ -143,7 +164,7 @@ cmd_run_shell_callback(struct job *job)
}
if (msg != NULL) {
if (lines == 0)
ctx->info(ctx, "%s", msg);
cmdq_info(cmdq, "%s", msg);
else
cmd_run_shell_print(job, msg);
free(msg);
@@ -154,14 +175,10 @@ void
cmd_run_shell_free(void *data)
{
struct cmd_run_shell_data *cdata = data;
struct cmd_ctx *ctx = &cdata->ctx;
struct cmd_q *cmdq = cdata->cmdq;
if (ctx->cmdclient != NULL) {
ctx->cmdclient->references--;
ctx->cmdclient->flags |= CLIENT_EXIT;
}
if (ctx->curclient != NULL)
ctx->curclient->references--;
if (!cmdq_free(cmdq) && !cdata->bflag)
cmdq_continue(cmdq);
free(cdata->cmd);
free(cdata);
+95 -42
View File
@@ -29,7 +29,7 @@
* Saves a paste buffer to a file.
*/
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_save_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_save_buffer_entry = {
"save-buffer", "saveb",
@@ -41,79 +41,132 @@ const struct cmd_entry cmd_save_buffer_entry = {
cmd_save_buffer_exec
};
const struct cmd_entry cmd_show_buffer_entry = {
"show-buffer", "showb",
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
NULL,
cmd_save_buffer_exec
};
enum cmd_retval
cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c = ctx->cmdclient;
struct client *c;
struct session *s;
struct paste_buffer *pb;
const char *path, *newpath, *wd;
char *cause;
char *cause, *start, *end;
size_t size, used;
int buffer;
mode_t mask;
FILE *f;
char *msg;
size_t msglen;
if (!args_has(args, 'b')) {
if ((pb = paste_get_top(&global_buffers)) == NULL) {
ctx->error(ctx, "no buffers");
cmdq_error(cmdq, "no buffers");
return (CMD_RETURN_ERROR);
}
} else {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
pb = paste_get_index(&global_buffers, buffer);
if (pb == NULL) {
ctx->error(ctx, "no buffer %d", buffer);
cmdq_error(cmdq, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
}
path = args->argv[0];
if (self->entry == &cmd_show_buffer_entry)
path = "-";
else
path = args->argv[0];
if (strcmp(path, "-") == 0) {
c = cmdq->client;
if (c == NULL) {
ctx->error(ctx, "%s: can't write to stdout", path);
cmdq_error(cmdq, "can't write to stdout");
return (CMD_RETURN_ERROR);
}
evbuffer_add(c->stdout_data, pb->data, pb->size);
server_push_stdout(c);
} else {
if (c != NULL)
wd = c->cwd;
else if ((s = cmd_current_session(ctx, 0)) != NULL) {
wd = options_get_string(&s->options, "default-path");
if (*wd == '\0')
wd = s->cwd;
} else
wd = NULL;
if (wd != NULL && *wd != '\0') {
newpath = get_full_path(wd, path);
if (newpath != NULL)
path = newpath;
}
mask = umask(S_IRWXG | S_IRWXO);
if (args_has(self->args, 'a'))
f = fopen(path, "ab");
else
f = fopen(path, "wb");
umask(mask);
if (f == NULL) {
ctx->error(ctx, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
ctx->error(ctx, "%s: fwrite error", path);
fclose(f);
return (CMD_RETURN_ERROR);
}
fclose(f);
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
goto do_stdout;
goto do_print;
}
c = cmdq->client;
if (c != NULL)
wd = c->cwd;
else if ((s = cmd_current_session(cmdq, 0)) != NULL) {
wd = options_get_string(&s->options, "default-path");
if (*wd == '\0')
wd = s->cwd;
} else
wd = NULL;
if (wd != NULL && *wd != '\0') {
newpath = get_full_path(wd, path);
if (newpath != NULL)
path = newpath;
}
mask = umask(S_IRWXG | S_IRWXO);
if (args_has(self->args, 'a'))
f = fopen(path, "ab");
else
f = fopen(path, "wb");
umask(mask);
if (f == NULL) {
cmdq_error(cmdq, "%s: %s", path, strerror(errno));
return (CMD_RETURN_ERROR);
}
if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
cmdq_error(cmdq, "%s: fwrite error", path);
fclose(f);
return (CMD_RETURN_ERROR);
}
fclose(f);
return (CMD_RETURN_NORMAL);
do_stdout:
evbuffer_add(c->stdout_data, pb->data, pb->size);
server_push_stdout(c);
return (CMD_RETURN_NORMAL);
do_print:
if (pb->size > (INT_MAX / 4) - 1) {
cmdq_error(cmdq, "buffer too big");
return (CMD_RETURN_ERROR);
}
msg = NULL;
msglen = 0;
used = 0;
while (used != pb->size) {
start = pb->data + used;
end = memchr(start, '\n', pb->size - used);
if (end != NULL)
size = end - start;
else
size = pb->size - used;
msglen = size * 4 + 1;
msg = xrealloc(msg, 1, msglen);
strvisx(msg, start, size, VIS_OCTAL|VIS_TAB);
cmdq_print(cmdq, "%s", msg);
used += size + (end != NULL);
}
free(msg);
return (CMD_RETURN_NORMAL);
}
+8 -7
View File
@@ -25,7 +25,7 @@
*/
void cmd_select_layout_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_select_layout_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl",
@@ -83,15 +83,16 @@ cmd_select_layout_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
const char *layoutname;
int next, previous, layout;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), NULL)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
return (CMD_RETURN_ERROR);
server_unzoom_window(wl->window);
next = self->entry == &cmd_next_layout_entry;
if (args_has(self->args, 'n'))
@@ -106,7 +107,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
else
layout = layout_set_previous(wl->window);
server_redraw_window(wl->window);
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
return (CMD_RETURN_NORMAL);
}
@@ -117,18 +118,18 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
if (layout != -1) {
layout = layout_set_select(wl->window, layout);
server_redraw_window(wl->window);
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
cmdq_info(cmdq, "arranging in: %s", layout_set_name(layout));
return (CMD_RETURN_NORMAL);
}
if (args->argc != 0) {
layoutname = args->argv[0];
if (layout_parse(wl->window, layoutname) == -1) {
ctx->error(ctx, "can't set layout: %s", layoutname);
cmdq_error(cmdq, "can't set layout: %s", layoutname);
return (CMD_RETURN_ERROR);
}
server_redraw_window(wl->window);
ctx->info(ctx, "arranging in: %s", layoutname);
cmdq_info(cmdq, "arranging in: %s", layoutname);
}
return (CMD_RETURN_NORMAL);
}
+9 -7
View File
@@ -25,7 +25,7 @@
*/
void cmd_select_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_select_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_pane_entry = {
"select-pane", "selectp",
@@ -64,22 +64,23 @@ cmd_select_pane_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
struct window_pane *wp;
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL)
return (CMD_RETURN_ERROR);
if (wl->window->last == NULL) {
ctx->error(ctx, "no last pane");
cmdq_error(cmdq, "no last pane");
return (CMD_RETURN_ERROR);
}
server_unzoom_window(wl->window);
window_set_active_pane(wl->window, wl->window->last);
server_status_window(wl->window);
server_redraw_window_borders(wl->window);
@@ -87,11 +88,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL);
}
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
return (CMD_RETURN_ERROR);
server_unzoom_window(wp->window);
if (!window_pane_visible(wp)) {
ctx->error(ctx, "pane not visible");
cmdq_error(cmdq, "pane not visible");
return (CMD_RETURN_ERROR);
}
@@ -104,7 +106,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
else if (args_has(self->args, 'D'))
wp = window_pane_find_down(wp);
if (wp == NULL) {
ctx->error(ctx, "pane not found");
cmdq_error(cmdq, "pane not found");
return (CMD_RETURN_ERROR);
}
+8 -8
View File
@@ -27,7 +27,7 @@
*/
void cmd_select_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_select_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_select_window_entry = {
"select-window", "selectw",
@@ -84,7 +84,7 @@ cmd_select_window_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_select_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -102,31 +102,31 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
last = 1;
if (next || previous || last) {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
activity = args_has(self->args, 'a');
if (next) {
if (session_next(s, activity) != 0) {
ctx->error(ctx, "no next window");
cmdq_error(cmdq, "no next window");
return (CMD_RETURN_ERROR);
}
} else if (previous) {
if (session_previous(s, activity) != 0) {
ctx->error(ctx, "no previous window");
cmdq_error(cmdq, "no previous window");
return (CMD_RETURN_ERROR);
}
} else {
if (session_last(s) != 0) {
ctx->error(ctx, "no last window");
cmdq_error(cmdq, "no last window");
return (CMD_RETURN_ERROR);
}
}
server_redraw_session(s);
} else {
wl = cmd_find_window(ctx, args_get(args, 't'), &s);
wl = cmd_find_window(cmdq, args_get(args, 't'), &s);
if (wl == NULL)
return (CMD_RETURN_ERROR);
@@ -136,7 +136,7 @@ cmd_select_window_exec(struct cmd *self, struct cmd_ctx *ctx)
*/
if (args_has(self->args, 'T') && wl == s->curw) {
if (session_last(s) != 0) {
ctx->error(ctx, "no last window");
cmdq_error(cmdq, "no last window");
return (-1);
}
server_redraw_session(s);
+22 -3
View File
@@ -27,7 +27,7 @@
* Send keys to client.
*/
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_send_keys_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_send_keys_entry = {
"send-keys", "send",
@@ -39,8 +39,18 @@ const struct cmd_entry cmd_send_keys_entry = {
cmd_send_keys_exec
};
const struct cmd_entry cmd_send_prefix_entry = {
"send-prefix", NULL,
"2t:", 0, 0,
"[-2] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_send_keys_exec
};
enum cmd_retval
cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_send_keys_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct window_pane *wp;
@@ -49,9 +59,18 @@ cmd_send_keys_exec(struct cmd *self, struct cmd_ctx *ctx)
const char *str;
int i, key;
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
if (cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (self->entry == &cmd_send_prefix_entry) {
if (args_has(args, '2'))
key = options_get_number(&s->options, "prefix2");
else
key = options_get_number(&s->options, "prefix");
window_pane_key(wp, s, key);
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'R')) {
ictx = &wp->ictx;
-57
View File
@@ -1,57 +0,0 @@
/* $Id$ */
/*
* 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 "tmux.h"
/*
* Send prefix key as a key.
*/
enum cmd_retval cmd_send_prefix_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_send_prefix_entry = {
"send-prefix", NULL,
"2t:", 0, 0,
"[-2] " CMD_TARGET_PANE_USAGE,
0,
NULL,
NULL,
cmd_send_prefix_exec
};
enum cmd_retval
cmd_send_prefix_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct session *s;
struct window_pane *wp;
int key;
if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, '2'))
key = options_get_number(&s->options, "prefix2");
else
key = options_get_number(&s->options, "prefix");
window_pane_key(wp, s, key);
return (CMD_RETURN_NORMAL);
}
+28 -29
View File
@@ -30,7 +30,7 @@
* Show various information about server.
*/
enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_server_info_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_server_info_entry = {
"server-info", "info",
@@ -42,9 +42,8 @@ const struct cmd_entry cmd_server_info_entry = {
cmd_server_info_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
cmd_server_info_exec(unused struct cmd *self, struct cmd_q *cmdq)
{
struct tty_term *term;
struct client *c;
@@ -66,48 +65,48 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
tim = ctime(&start_time);
*strchr(tim, '\n') = '\0';
ctx->print(ctx,
cmdq_print(cmdq,
"tmux " VERSION ", pid %ld, started %s", (long) getpid(), tim);
ctx->print(
ctx, "socket path %s, debug level %d", socket_path, debug_level);
cmdq_print(cmdq, "socket path %s, debug level %d", socket_path,
debug_level);
if (uname(&un) >= 0) {
ctx->print(ctx, "system is %s %s %s %s",
cmdq_print(cmdq, "system is %s %s %s %s",
un.sysname, un.release, un.version, un.machine);
}
if (cfg_file != NULL)
ctx->print(ctx, "configuration file is %s", cfg_file);
cmdq_print(cmdq, "configuration file is %s", cfg_file);
else
ctx->print(ctx, "configuration file not specified");
ctx->print(ctx, "protocol version is %d", PROTOCOL_VERSION);
ctx->print(ctx, "%s", "");
cmdq_print(cmdq, "configuration file not specified");
cmdq_print(cmdq, "protocol version is %d", PROTOCOL_VERSION);
cmdq_print(cmdq, "%s", "");
ctx->print(ctx, "Clients:");
cmdq_print(cmdq, "Clients:");
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
continue;
ctx->print(ctx,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
cmdq_print(cmdq,"%2d: %s (%d, %d): %s [%ux%u %s bs=%hho "
"class=%u] [flags=0x%x/0x%x, references=%u]", i,
c->tty.path, c->ibuf.fd, c->tty.fd, c->session->name,
c->tty.sx, c->tty.sy, c->tty.termname,
c->tty.tio.c_cc[VERASE], c->tty.class,
c->flags, c->tty.flags, c->references);
}
ctx->print(ctx, "%s", "");
cmdq_print(cmdq, "%s", "");
ctx->print(ctx, "Sessions: [%zu]", sizeof (struct grid_cell));
cmdq_print(cmdq, "Sessions: [%zu]", sizeof (struct grid_cell));
RB_FOREACH(s, sessions, &sessions) {
t = s->creation_time.tv_sec;
tim = ctime(&t);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "%2u: %s: %u windows (created %s) [%ux%u] "
"[flags=0x%x]", s->idx, s->name,
cmdq_print(cmdq, "%2u: %s: %u windows (created %s) [%ux%u] "
"[flags=0x%x]", s->id, s->name,
winlink_count(&s->windows), tim, s->sx, s->sy, s->flags);
RB_FOREACH(wl, winlinks, &s->windows) {
w = wl->window;
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
cmdq_print(cmdq, "%4u: %s [%ux%u] [flags=0x%x, "
"references=%u, last layout=%d]", wl->idx, w->name,
w->sx, w->sy, w->flags, w->references,
w->lastlayout);
@@ -123,7 +122,7 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
size += gl->cellsize *
sizeof *gl->celldata;
}
ctx->print(ctx,
cmdq_print(cmdq,
"%6u: %s %lu %d %u/%u, %zu bytes", j,
wp->tty, (u_long) wp->pid, wp->fd, lines,
gd->hsize + gd->sy, size);
@@ -131,43 +130,43 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
}
}
}
ctx->print(ctx, "%s", "");
cmdq_print(cmdq, "%s", "");
ctx->print(ctx, "Terminals:");
cmdq_print(cmdq, "Terminals:");
LIST_FOREACH(term, &tty_terms, entry) {
ctx->print(ctx, "%s [references=%u, flags=0x%x]:",
cmdq_print(cmdq, "%s [references=%u, flags=0x%x]:",
term->name, term->references, term->flags);
for (i = 0; i < NTTYCODE; i++) {
ent = &tty_term_codes[i];
code = &term->codes[ent->code];
switch (code->type) {
case TTYCODE_NONE:
ctx->print(ctx, "%2u: %s: [missing]",
cmdq_print(cmdq, "%2u: %s: [missing]",
ent->code, ent->name);
break;
case TTYCODE_STRING:
strnvis(out, code->value.string, sizeof out,
VIS_OCTAL|VIS_TAB|VIS_NL);
ctx->print(ctx, "%2u: %s: (string) %s",
cmdq_print(cmdq, "%2u: %s: (string) %s",
ent->code, ent->name, out);
break;
case TTYCODE_NUMBER:
ctx->print(ctx, "%2u: %s: (number) %d",
cmdq_print(cmdq, "%2u: %s: (number) %d",
ent->code, ent->name, code->value.number);
break;
case TTYCODE_FLAG:
ctx->print(ctx, "%2u: %s: (flag) %s",
cmdq_print(cmdq, "%2u: %s: (flag) %s",
ent->code, ent->name,
code->value.flag ? "true" : "false");
break;
}
}
}
ctx->print(ctx, "%s", "");
cmdq_print(cmdq, "%s", "");
ctx->print(ctx, "Jobs:");
cmdq_print(cmdq, "Jobs:");
LIST_FOREACH(job, &all_jobs, lentry) {
ctx->print(ctx, "%s [fd=%d, pid=%d, status=%d]",
cmdq_print(cmdq, "%s [fd=%d, pid=%d, status=%d]",
job->cmd, job->fd, job->pid, job->status);
}
+4 -4
View File
@@ -27,7 +27,7 @@
* Add or set a paste buffer.
*/
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_set_buffer_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_set_buffer_entry = {
"set-buffer", "setb",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
};
enum cmd_retval
cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_set_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
u_int limit;
@@ -60,14 +60,14 @@ cmd_set_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
cmdq_error(cmdq, "buffer %s", cause);
free(cause);
free(pdata);
return (CMD_RETURN_ERROR);
}
if (paste_replace(&global_buffers, buffer, pdata, psize) != 0) {
ctx->error(ctx, "no buffer %d", buffer);
cmdq_error(cmdq, "no buffer %d", buffer);
free(pdata);
return (CMD_RETURN_ERROR);
}
+8 -8
View File
@@ -27,7 +27,7 @@
* Set an environment variable.
*/
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_set_environment_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_set_environment_entry = {
"set-environment", "setenv",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_set_environment_entry = {
};
enum cmd_retval
cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
@@ -49,11 +49,11 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
name = args->argv[0];
if (*name == '\0') {
ctx->error(ctx, "empty variable name");
cmdq_error(cmdq, "empty variable name");
return (CMD_RETURN_ERROR);
}
if (strchr(name, '=') != NULL) {
ctx->error(ctx, "variable name contains =");
cmdq_error(cmdq, "variable name contains =");
return (CMD_RETURN_ERROR);
}
@@ -65,26 +65,26 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
env = &global_environ;
else {
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
env = &s->environ;
}
if (args_has(self->args, 'u')) {
if (value != NULL) {
ctx->error(ctx, "can't specify a value with -u");
cmdq_error(cmdq, "can't specify a value with -u");
return (CMD_RETURN_ERROR);
}
environ_unset(env, name);
} else if (args_has(self->args, 'r')) {
if (value != NULL) {
ctx->error(ctx, "can't specify a value with -r");
cmdq_error(cmdq, "can't specify a value with -r");
return (CMD_RETURN_ERROR);
}
environ_set(env, name, NULL);
} else {
if (value == NULL) {
ctx->error(ctx, "no value specified");
cmdq_error(cmdq, "no value specified");
return (CMD_RETURN_ERROR);
}
environ_set(env, name, value);
+130 -53
View File
@@ -27,41 +27,44 @@
* Set an option.
*/
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *);
int cmd_set_option_unset(struct cmd *, struct cmd_ctx *,
enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *,
const char *, const char *);
int cmd_set_option_unset(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
int cmd_set_option_set(struct cmd *, struct cmd_ctx *,
int cmd_set_option_set(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_string(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_number(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_key(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_colour(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_attributes(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_flag(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_ctx *,
struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *,
const char *);
const struct cmd_entry cmd_set_option_entry = {
"set-option", "set",
"agqst:uw", 1, 2,
"[-agsquw] [-t target-session|target-window] option [value]",
"agoqst:uw", 1, 2,
"[-agosquw] [-t target-session|target-window] option [value]",
0,
NULL,
NULL,
@@ -70,8 +73,8 @@ const struct cmd_entry cmd_set_option_entry = {
const struct cmd_entry cmd_set_window_option_entry = {
"set-window-option", "setw",
"agqt:u", 1, 2,
"[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
"agoqt:u", 1, 2,
"[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
0,
NULL,
NULL,
@@ -79,7 +82,7 @@ const struct cmd_entry cmd_set_window_option_entry = {
};
enum cmd_retval
cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const struct options_table_entry *table, *oe;
@@ -94,7 +97,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Get the option name and value. */
optstr = args->argv[0];
if (*optstr == '\0') {
ctx->error(ctx, "invalid option");
cmdq_error(cmdq, "invalid option");
return (CMD_RETURN_ERROR);
}
if (args->argc < 2)
@@ -102,14 +105,18 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
else
valstr = args->argv[1];
/* Is this a user option? */
if (*optstr == '@')
return (cmd_set_option_user(self, cmdq, optstr, valstr));
/* Find the option entry, try each table. */
table = oe = NULL;
if (options_table_find(optstr, &table, &oe) != 0) {
ctx->error(ctx, "ambiguous option: %s", optstr);
cmdq_error(cmdq, "ambiguous option: %s", optstr);
return (CMD_RETURN_ERROR);
}
if (oe == NULL) {
ctx->error(ctx, "unknown option: %s", optstr);
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
@@ -120,7 +127,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
oo = &global_w_options;
else {
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL)
return (CMD_RETURN_ERROR);
oo = &wl->window->options;
@@ -129,22 +136,27 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
oo = &global_s_options;
else {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
oo = &s->options;
}
} else {
ctx->error(ctx, "unknown table");
cmdq_error(cmdq, "unknown table");
return (CMD_RETURN_ERROR);
}
/* Unset or set the option. */
if (args_has(args, 'u')) {
if (cmd_set_option_unset(self, ctx, oe, oo, valstr) != 0)
if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0)
return (CMD_RETURN_ERROR);
} else {
if (cmd_set_option_set(self, ctx, oe, oo, valstr) != 0)
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
if (!args_has(args, 'q'))
cmdq_print(cmdq, "already set: %s", optstr);
return (CMD_RETURN_NORMAL);
}
if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0)
return (CMD_RETURN_ERROR);
}
@@ -171,31 +183,95 @@ cmd_set_option_exec(struct cmd *self, struct cmd_ctx *ctx)
return (CMD_RETURN_NORMAL);
}
/* Set user option. */
enum cmd_retval
cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr,
const char *valstr)
{
struct args *args = self->args;
struct session *s;
struct winlink *wl;
struct options *oo;
if (args_has(args, 's'))
oo = &global_options;
else if (args_has(self->args, 'w') ||
self->entry == &cmd_set_window_option_entry) {
if (args_has(self->args, 'g'))
oo = &global_w_options;
else {
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL)
return (CMD_RETURN_ERROR);
oo = &wl->window->options;
}
} else {
if (args_has(self->args, 'g'))
oo = &global_s_options;
else {
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
oo = &s->options;
}
}
if (args_has(args, 'u')) {
if (options_find1(oo, optstr) == NULL) {
cmdq_error(cmdq, "unknown option: %s", optstr);
return (CMD_RETURN_ERROR);
}
if (valstr != NULL) {
cmdq_error(cmdq, "value passed to unset option: %s",
optstr);
return (CMD_RETURN_ERROR);
}
options_remove(oo, optstr);
} else {
if (valstr == NULL) {
cmdq_error(cmdq, "empty value");
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) {
if (!args_has(args, 'q'))
cmdq_print(cmdq, "already set: %s", optstr);
return (CMD_RETURN_NORMAL);
}
options_set_string(oo, optstr, "%s", valstr);
if (!args_has(args, 'q')) {
cmdq_info(cmdq, "set option: %s -> %s", optstr,
valstr);
}
}
return (CMD_RETURN_NORMAL);
}
/* Unset an option. */
int
cmd_set_option_unset(struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_unset(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
if (args_has(args, 'g')) {
ctx->error(ctx, "can't unset global option: %s", oe->name);
cmdq_error(cmdq, "can't unset global option: %s", oe->name);
return (-1);
}
if (value != NULL) {
ctx->error(ctx, "value passed to unset option: %s", oe->name);
cmdq_error(cmdq, "value passed to unset option: %s", oe->name);
return (-1);
}
options_remove(oo, oe->name);
if (!args_has(args, 'q'))
ctx->info(ctx, "unset option: %s", oe->name);
cmdq_info(cmdq, "unset option: %s", oe->name);
return (0);
}
/* Set an option. */
int
cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_set(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
@@ -203,46 +279,46 @@ cmd_set_option_set(struct cmd *self, struct cmd_ctx *ctx,
const char *s;
if (oe->type != OPTIONS_TABLE_FLAG && value == NULL) {
ctx->error(ctx, "empty value");
cmdq_error(cmdq, "empty value");
return (-1);
}
o = NULL;
switch (oe->type) {
case OPTIONS_TABLE_STRING:
o = cmd_set_option_string(self, ctx, oe, oo, value);
o = cmd_set_option_string(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_NUMBER:
o = cmd_set_option_number(self, ctx, oe, oo, value);
o = cmd_set_option_number(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_KEY:
o = cmd_set_option_key(self, ctx, oe, oo, value);
o = cmd_set_option_key(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_COLOUR:
o = cmd_set_option_colour(self, ctx, oe, oo, value);
o = cmd_set_option_colour(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_ATTRIBUTES:
o = cmd_set_option_attributes(self, ctx, oe, oo, value);
o = cmd_set_option_attributes(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_FLAG:
o = cmd_set_option_flag(self, ctx, oe, oo, value);
o = cmd_set_option_flag(self, cmdq, oe, oo, value);
break;
case OPTIONS_TABLE_CHOICE:
o = cmd_set_option_choice(self, ctx, oe, oo, value);
o = cmd_set_option_choice(self, cmdq, oe, oo, value);
break;
}
if (o == NULL)
return (-1);
s = options_table_print_entry(oe, o);
s = options_table_print_entry(oe, o, 0);
if (!args_has(args, 'q'))
ctx->info(ctx, "set option: %s -> %s", oe->name, s);
cmdq_info(cmdq, "set option: %s -> %s", oe->name, s);
return (0);
}
/* Set a string option. */
struct options_entry *
cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
cmd_set_option_string(struct cmd *self, unused struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
struct args *args = self->args;
@@ -263,7 +339,7 @@ cmd_set_option_string(struct cmd *self, unused struct cmd_ctx *ctx,
/* Set a number option. */
struct options_entry *
cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_number(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
long long ll;
@@ -271,7 +347,7 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
ll = strtonum(value, oe->minimum, oe->maximum, &errstr);
if (errstr != NULL) {
ctx->error(ctx, "value is %s: %s", errstr, value);
cmdq_error(cmdq, "value is %s: %s", errstr, value);
return (NULL);
}
@@ -280,13 +356,13 @@ cmd_set_option_number(unused struct cmd *self, struct cmd_ctx *ctx,
/* Set a key option. */
struct options_entry *
cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_key(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int key;
if ((key = key_string_lookup_string(value)) == KEYC_NONE) {
ctx->error(ctx, "bad key: %s", value);
cmdq_error(cmdq, "bad key: %s", value);
return (NULL);
}
@@ -295,13 +371,13 @@ cmd_set_option_key(unused struct cmd *self, struct cmd_ctx *ctx,
/* Set a colour option. */
struct options_entry *
cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_colour(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int colour;
if ((colour = colour_fromstring(value)) == -1) {
ctx->error(ctx, "bad colour: %s", value);
cmdq_error(cmdq, "bad colour: %s", value);
return (NULL);
}
@@ -310,13 +386,13 @@ cmd_set_option_colour(unused struct cmd *self, struct cmd_ctx *ctx,
/* Set an attributes option. */
struct options_entry *
cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_attributes(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int attr;
if ((attr = attributes_fromstring(value)) == -1) {
ctx->error(ctx, "bad attributes: %s", value);
cmdq_error(cmdq, "bad attributes: %s", value);
return (NULL);
}
@@ -325,7 +401,7 @@ cmd_set_option_attributes(unused struct cmd *self, struct cmd_ctx *ctx,
/* Set a flag option. */
struct options_entry *
cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
cmd_set_option_flag(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo, const char *value)
{
int flag;
@@ -342,7 +418,7 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
strcasecmp(value, "no") == 0)
flag = 0;
else {
ctx->error(ctx, "bad value: %s", value);
cmdq_error(cmdq, "bad value: %s", value);
return (NULL);
}
}
@@ -352,8 +428,9 @@ cmd_set_option_flag(unused struct cmd *self, struct cmd_ctx *ctx,
/* Set a choice option. */
struct options_entry *
cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
const struct options_table_entry *oe, struct options *oo, const char *value)
cmd_set_option_choice(unused struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *oe, struct options *oo,
const char *value)
{
const char **choicep;
int n, choice = -1;
@@ -365,13 +442,13 @@ cmd_set_option_choice(unused struct cmd *self, struct cmd_ctx *ctx,
continue;
if (choice != -1) {
ctx->error(ctx, "ambiguous value: %s", value);
cmdq_error(cmdq, "ambiguous value: %s", value);
return (NULL);
}
choice = n - 1;
}
if (choice == -1) {
ctx->error(ctx, "unknown value: %s", value);
cmdq_error(cmdq, "unknown value: %s", value);
return (NULL);
}
-111
View File
@@ -1,111 +0,0 @@
/* $Id$ */
/*
* 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 <stdlib.h>
#include "tmux.h"
/*
* Show a paste buffer.
*/
enum cmd_retval cmd_show_buffer_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_buffer_entry = {
"show-buffer", "showb",
"b:", 0, 0,
CMD_BUFFER_USAGE,
0,
NULL,
NULL,
cmd_show_buffer_exec
};
enum cmd_retval
cmd_show_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct session *s;
struct paste_buffer *pb;
int buffer;
char *in, *buf, *ptr, *cause;
size_t size, len;
u_int width;
if ((s = cmd_find_session(ctx, NULL, 0)) == NULL)
return (CMD_RETURN_ERROR);
if (!args_has(args, 'b')) {
if ((pb = paste_get_top(&global_buffers)) == NULL) {
ctx->error(ctx, "no buffers");
return (CMD_RETURN_ERROR);
}
} else {
buffer = args_strtonum(args, 'b', 0, INT_MAX, &cause);
if (cause != NULL) {
ctx->error(ctx, "buffer %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
pb = paste_get_index(&global_buffers, buffer);
if (pb == NULL) {
ctx->error(ctx, "no buffer %d", buffer);
return (CMD_RETURN_ERROR);
}
}
size = pb->size;
if (size > SIZE_MAX / 4 - 1)
size = SIZE_MAX / 4 - 1;
in = xmalloc(size * 4 + 1);
strvisx(in, pb->data, size, VIS_OCTAL|VIS_TAB);
width = s->sx;
if (ctx->cmdclient != NULL)
width = ctx->cmdclient->tty.sx;
buf = xmalloc(width + 1);
len = 0;
ptr = in;
do {
buf[len++] = *ptr++;
if (len == width || buf[len - 1] == '\n') {
if (buf[len - 1] == '\n')
len--;
buf[len] = '\0';
ctx->print(ctx, "%s", buf);
len = 0;
}
} while (*ptr != '\0');
if (len != 0) {
buf[len] = '\0';
ctx->print(ctx, "%s", buf);
}
free(buf);
free(in);
return (CMD_RETURN_NORMAL);
}
+8 -8
View File
@@ -27,7 +27,7 @@
* Show environment.
*/
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_show_environment_entry = {
"show-environment", "showenv",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_show_environment_entry = {
};
enum cmd_retval
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
@@ -50,7 +50,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
env = &global_environ;
else {
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL)
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
env = &s->environ;
}
@@ -58,21 +58,21 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args->argc != 0) {
envent = environ_find(env, args->argv[0]);
if (envent == NULL) {
ctx->error(ctx, "unknown variable: %s", args->argv[0]);
cmdq_error(cmdq, "unknown variable: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (envent->value != NULL)
ctx->print(ctx, "%s=%s", envent->name, envent->value);
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
else
ctx->print(ctx, "-%s", envent->name);
cmdq_print(cmdq, "-%s", envent->name);
return (CMD_RETURN_NORMAL);
}
RB_FOREACH(envent, environ, env) {
if (envent->value != NULL)
ctx->print(ctx, "%s=%s", envent->name, envent->value);
cmdq_print(cmdq, "%s=%s", envent->name, envent->value);
else
ctx->print(ctx, "-%s", envent->name);
cmdq_print(cmdq, "-%s", envent->name);
}
return (CMD_RETURN_NORMAL);
+4 -4
View File
@@ -27,7 +27,7 @@
* Show client message log.
*/
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_show_messages_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_show_messages_entry = {
"show-messages", "showmsgs",
@@ -40,7 +40,7 @@ const struct cmd_entry cmd_show_messages_entry = {
};
enum cmd_retval
cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_show_messages_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
@@ -48,7 +48,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
char *tim;
u_int i;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
for (i = 0; i < ARRAY_LENGTH(&c->message_log); i++) {
@@ -57,7 +57,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmd_ctx *ctx)
tim = ctime(&msg->msg_time);
*strchr(tim, '\n') = '\0';
ctx->print(ctx, "%s %s", tim, msg->msg);
cmdq_print(cmdq, "%s %s", tim, msg->msg);
}
return (CMD_RETURN_NORMAL);
+88 -28
View File
@@ -27,12 +27,17 @@
* Show options.
*/
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *,
struct options *, int);
enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *,
const struct options_table_entry *, struct options *);
const struct cmd_entry cmd_show_options_entry = {
"show-options", "show",
"gst:w", 0, 1,
"[-gsw] [-t target-session|target-window] [option]",
"gqst:vw", 0, 1,
"[-gqsvw] [-t target-session|target-window] [option]",
0,
NULL,
NULL,
@@ -41,8 +46,8 @@ const struct cmd_entry cmd_show_options_entry = {
const struct cmd_entry cmd_show_window_options_entry = {
"show-window-options", "showw",
"gt:", 0, 1,
"[-g] " CMD_TARGET_WINDOW_USAGE " [option]",
"gvt:", 0, 1,
"[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
0,
NULL,
NULL,
@@ -50,15 +55,14 @@ const struct cmd_entry cmd_show_window_options_entry = {
};
enum cmd_retval
cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const struct options_table_entry *table, *oe;
struct session *s;
struct winlink *wl;
const struct options_table_entry *table;
struct options *oo;
struct options_entry *o;
const char *optval;
int quiet;
if (args_has(self->args, 's')) {
oo = &global_options;
@@ -69,7 +73,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
oo = &global_w_options;
else {
wl = cmd_find_window(ctx, args_get(args, 't'), NULL);
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL)
return (CMD_RETURN_ERROR);
oo = &wl->window->options;
@@ -79,34 +83,90 @@ cmd_show_options_exec(struct cmd *self, struct cmd_ctx *ctx)
if (args_has(self->args, 'g'))
oo = &global_s_options;
else {
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
oo = &s->options;
}
}
if (args->argc != 0) {
table = oe = NULL;
if (options_table_find(args->argv[0], &table, &oe) != 0) {
ctx->error(ctx, "ambiguous option: %s", args->argv[0]);
quiet = args_has(self->args, 'q');
if (args->argc == 0)
return (cmd_show_options_all(self, cmdq, table, oo));
else
return (cmd_show_options_one(self, cmdq, oo, quiet));
}
enum cmd_retval
cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq,
struct options *oo, int quiet)
{
struct args *args = self->args;
const struct options_table_entry *table, *oe;
struct options_entry *o;
const char *optval;
if (*args->argv[0] == '@') {
if ((o = options_find1(oo, args->argv[0])) == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (oe == NULL) {
ctx->error(ctx, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", o->str);
else
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
return (CMD_RETURN_NORMAL);
}
table = oe = NULL;
if (options_table_find(args->argv[0], &table, &oe) != 0) {
cmdq_error(cmdq, "ambiguous option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if (oe == NULL) {
if (quiet)
return (CMD_RETURN_NORMAL);
cmdq_error(cmdq, "unknown option: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
if ((o = options_find1(oo, oe->name)) == NULL)
return (CMD_RETURN_NORMAL);
optval = options_table_print_entry(oe, o, args_has(self->args, 'v'));
if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", optval);
else
cmdq_print(cmdq, "%s %s", oe->name, optval);
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_show_options_all(struct cmd *self, struct cmd_q *cmdq,
const struct options_table_entry *table, struct options *oo)
{
const struct options_table_entry *oe;
struct options_entry *o;
const char *optval;
RB_FOREACH(o, options_tree, &oo->tree) {
if (*o->name == '@') {
if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", o->str);
else
cmdq_print(cmdq, "%s \"%s\"", o->name, o->str);
}
}
for (oe = table; oe->name != NULL; oe++) {
if ((o = options_find1(oo, oe->name)) == NULL)
return (CMD_RETURN_NORMAL);
optval = options_table_print_entry(oe, o);
ctx->print(ctx, "%s %s", oe->name, optval);
} else {
for (oe = table; oe->name != NULL; oe++) {
if ((o = options_find1(oo, oe->name)) == NULL)
continue;
optval = options_table_print_entry(oe, o);
ctx->print(ctx, "%s %s", oe->name, optval);
}
continue;
optval = options_table_print_entry(oe, o,
args_has(self->args, 'v'));
if (args_has(self->args, 'v'))
cmdq_print(cmdq, "%s", optval);
else
cmdq_print(cmdq, "%s %s", oe->name, optval);
}
return (CMD_RETURN_NORMAL);
+57 -22
View File
@@ -26,7 +26,10 @@
* Sources a configuration file.
*/
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_q *);
void cmd_source_file_show(struct cmd_q *);
void cmd_source_file_done(struct cmd_q *);
const struct cmd_entry cmd_source_file_entry = {
"source-file", "source",
@@ -39,35 +42,67 @@ const struct cmd_entry cmd_source_file_entry = {
};
enum cmd_retval
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_source_file_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
int retval;
u_int i;
char *cause;
struct args *args = self->args;
struct cmd_q *cmdq1;
char *cause;
retval = load_cfg(args->argv[0], ctx, &cfg_causes);
cmdq1 = cmdq_new(NULL);
cmdq1->emptyfn = cmd_source_file_done;
cmdq1->data = cmdq;
/*
* If the context for the cmdclient came from tmux's configuration
* file, then return the status of this command now, regardless of the
* error condition. Any errors from parsing a configuration file at
* startup will be handled for us by the server.
*/
if (cfg_references > 0 ||
(ctx->curclient == NULL && ctx->cmdclient == NULL))
return (retval);
switch (load_cfg(args->argv[0], cmdq1, &cause)) {
case -1:
if (cfg_references == 0) {
cmdq_free(cmdq1);
cmdq_error(cmdq, "%s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
ARRAY_ADD(&cfg_causes, cause);
/* FALLTHROUGH */
case 0:
if (cfg_references == 0)
cmd_source_file_show(cmdq);
cmdq_free(cmdq1);
return (CMD_RETURN_NORMAL);
}
cmdq->references++;
cfg_references++;
cmdq_continue(cmdq1);
return (CMD_RETURN_WAIT);
}
void
cmd_source_file_show(struct cmd_q *cmdq)
{
u_int i;
char *cause;
/*
* We were called from the command-line in which case print the errors
* gathered here directly.
*/
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
ctx->print(ctx, "%s", cause);
cmdq_print(cmdq, "%s", cause);
free(cause);
}
ARRAY_FREE(&cfg_causes);
}
return (retval);
void
cmd_source_file_done(struct cmd_q *cmdq1)
{
struct cmd_q *cmdq = cmdq1->data;
cmdq_free(cmdq1);
cfg_references--;
if (cmdq_free(cmdq))
return;
if (cfg_references == 0)
cmd_source_file_show(cmdq);
cmdq_continue(cmdq);
}
+9 -8
View File
@@ -28,7 +28,7 @@
*/
void cmd_split_window_key_binding(struct cmd *, int);
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw",
@@ -50,7 +50,7 @@ cmd_split_window_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct session *s;
@@ -69,9 +69,10 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct format_tree *ft;
char *cp;
if ((wl = cmd_find_pane(ctx, args_get(args, 't'), &s, &wp)) == NULL)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
server_unzoom_window(w);
environ_init(&env);
environ_copy(&global_environ, &env);
@@ -82,7 +83,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd = options_get_string(&s->options, "default-command");
else
cmd = args->argv[0];
cwd = cmd_get_default_path(ctx, args_get(args, 'c'));
cwd = cmd_get_default_path(cmdq, args_get(args, 'c'));
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
@@ -142,14 +143,14 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
template = SPLIT_WINDOW_TEMPLATE;
ft = format_create();
if ((c = cmd_find_client(ctx, NULL)) != NULL)
format_client(ft, c);
if ((c = cmd_find_client(cmdq, NULL, 1)) != NULL)
format_client(ft, c);
format_session(ft, s);
format_winlink(ft, s, wl);
format_window_pane(ft, new_wp);
cp = format_expand(ft, template);
ctx->print(ctx, "%s", cp);
cmdq_print(cmdq, "%s", cp);
free(cp);
format_free(ft);
@@ -161,7 +162,7 @@ error:
environ_free(&env);
if (new_wp != NULL)
window_remove_pane(w, new_wp);
ctx->error(ctx, "create pane failed: %s", cause);
cmdq_error(cmdq, "create pane failed: %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
+2 -3
View File
@@ -24,7 +24,7 @@
* Start the server and do nothing else.
*/
enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_start_server_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_start_server_entry = {
"start-server", "start",
@@ -36,9 +36,8 @@ const struct cmd_entry cmd_start_server_entry = {
cmd_start_server_exec
};
/* ARGSUSED */
enum cmd_retval
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_ctx *ctx)
cmd_start_server_exec(unused struct cmd *self, unused struct cmd_q *cmdq)
{
return (CMD_RETURN_NORMAL);
}
+3 -2
View File
@@ -59,7 +59,8 @@ cmd_string_ungetc(size_t *p)
* string, or NULL for empty command.
*/
int
cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
cmd_string_parse(const char *s, struct cmd_list **cmdlist, const char *file,
u_int line, char **cause)
{
size_t p;
int ch, i, argc, rval;
@@ -131,7 +132,7 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
if (argc == 0)
goto out;
*cmdlist = cmd_list_parse(argc, argv, cause);
*cmdlist = cmd_list_parse(argc, argv, file, line, cause);
if (*cmdlist == NULL)
goto out;
+3 -3
View File
@@ -27,7 +27,7 @@
* Suspend client with SIGTSTP.
*/
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_suspend_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_suspend_client_entry = {
"suspend-client", "suspendc",
@@ -40,12 +40,12 @@ const struct cmd_entry cmd_suspend_client_entry = {
};
enum cmd_retval
cmd_suspend_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_suspend_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
if ((c = cmd_find_client(ctx, args_get(args, 't'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 't'), 0)) == NULL)
return (CMD_RETURN_ERROR);
tty_stop_tty(&c->tty);
+6 -4
View File
@@ -27,7 +27,7 @@
*/
void cmd_swap_pane_key_binding(struct cmd *, int);
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_swap_pane_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_swap_pane_entry = {
"swap-pane", "swapp",
@@ -50,7 +50,7 @@ cmd_swap_pane_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *src_wl, *dst_wl;
@@ -59,10 +59,11 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct layout_cell *src_lc, *dst_lc;
u_int sx, sy, xoff, yoff;
dst_wl = cmd_find_pane(ctx, args_get(args, 't'), NULL, &dst_wp);
dst_wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &dst_wp);
if (dst_wl == NULL)
return (CMD_RETURN_ERROR);
dst_w = dst_wl->window;
server_unzoom_window(dst_w);
if (!args_has(args, 's')) {
src_w = dst_w;
@@ -77,11 +78,12 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
} else
return (CMD_RETURN_NORMAL);
} else {
src_wl = cmd_find_pane(ctx, args_get(args, 's'), NULL, &src_wp);
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
if (src_wl == NULL)
return (CMD_RETURN_ERROR);
src_w = src_wl->window;
}
server_unzoom_window(src_w);
if (src_wp == dst_wp)
return (CMD_RETURN_NORMAL);
+5 -5
View File
@@ -26,7 +26,7 @@
* Swap one window with another.
*/
enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_swap_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_swap_window_entry = {
"swap-window", "swapw",
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_swap_window_entry = {
};
enum cmd_retval
cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *target_src, *target_dst;
@@ -49,17 +49,17 @@ cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct window *w;
target_src = args_get(args, 's');
if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL)
if ((wl_src = cmd_find_window(cmdq, target_src, &src)) == NULL)
return (CMD_RETURN_ERROR);
target_dst = args_get(args, 't');
if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL)
if ((wl_dst = cmd_find_window(cmdq, target_dst, &dst)) == NULL)
return (CMD_RETURN_ERROR);
sg_src = session_group_find(src);
sg_dst = session_group_find(dst);
if (src != dst &&
sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) {
ctx->error(ctx, "can't move window, sessions are grouped");
cmdq_error(cmdq, "can't move window, sessions are grouped");
return (CMD_RETURN_ERROR);
}
+9 -9
View File
@@ -28,7 +28,7 @@
*/
void cmd_switch_client_key_binding(struct cmd *, int);
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_switch_client_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_switch_client_entry = {
"switch-client", "switchc",
@@ -58,45 +58,45 @@ cmd_switch_client_key_binding(struct cmd *self, int key)
}
enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_switch_client_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct client *c;
struct session *s;
if ((c = cmd_find_client(ctx, args_get(args, 'c'))) == NULL)
if ((c = cmd_find_client(cmdq, args_get(args, 'c'), 0)) == NULL)
return (CMD_RETURN_ERROR);
if (args_has(args, 'r')) {
if (c->flags & CLIENT_READONLY) {
c->flags &= ~CLIENT_READONLY;
ctx->info(ctx, "made client writable");
cmdq_info(cmdq, "made client writable");
} else {
c->flags |= CLIENT_READONLY;
ctx->info(ctx, "made client read-only");
cmdq_info(cmdq, "made client read-only");
}
}
s = NULL;
if (args_has(args, 'n')) {
if ((s = session_next_session(c->session)) == NULL) {
ctx->error(ctx, "can't find next session");
cmdq_error(cmdq, "can't find next session");
return (CMD_RETURN_ERROR);
}
} else if (args_has(args, 'p')) {
if ((s = session_previous_session(c->session)) == NULL) {
ctx->error(ctx, "can't find previous session");
cmdq_error(cmdq, "can't find previous session");
return (CMD_RETURN_ERROR);
}
} else if (args_has(args, 'l')) {
if (c->last_session != NULL && session_alive(c->last_session))
s = c->last_session;
if (s == NULL) {
ctx->error(ctx, "can't find last session");
cmdq_error(cmdq, "can't find last session");
return (CMD_RETURN_ERROR);
}
} else
s = cmd_find_session(ctx, args_get(args, 't'), 0);
s = cmd_find_session(cmdq, args_get(args, 't'), 0);
if (s == NULL)
return (CMD_RETURN_ERROR);
+7 -7
View File
@@ -27,8 +27,8 @@
*/
enum cmd_retval cmd_unbind_key_check(struct args *);
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_ctx *, int);
enum cmd_retval cmd_unbind_key_exec(struct cmd *, struct cmd_q *);
enum cmd_retval cmd_unbind_key_table(struct cmd *, struct cmd_q *, int);
const struct cmd_entry cmd_unbind_key_entry = {
"unbind-key", "unbind",
@@ -51,7 +51,7 @@ cmd_unbind_key_check(struct args *args)
}
enum cmd_retval
cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
cmd_unbind_key_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct key_binding *bd;
@@ -60,14 +60,14 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
if (!args_has(args, 'a')) {
key = key_string_lookup_string(args->argv[0]);
if (key == KEYC_NONE) {
ctx->error(ctx, "unknown key: %s", args->argv[0]);
cmdq_error(cmdq, "unknown key: %s", args->argv[0]);
return (CMD_RETURN_ERROR);
}
} else
key = KEYC_NONE;
if (args_has(args, 't'))
return (cmd_unbind_key_table(self, ctx, key));
return (cmd_unbind_key_table(self, cmdq, key));
if (key == KEYC_NONE) {
while (!RB_EMPTY(&key_bindings)) {
@@ -84,7 +84,7 @@ cmd_unbind_key_exec(struct cmd *self, unused struct cmd_ctx *ctx)
}
enum cmd_retval
cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
cmd_unbind_key_table(struct cmd *self, struct cmd_q *cmdq, int key)
{
struct args *args = self->args;
const char *tablename;
@@ -93,7 +93,7 @@ cmd_unbind_key_table(struct cmd *self, struct cmd_ctx *ctx, int key)
tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) {
ctx->error(ctx, "unknown key table: %s", tablename);
cmdq_error(cmdq, "unknown key table: %s", tablename);
return (CMD_RETURN_ERROR);
}
+4 -4
View File
@@ -24,7 +24,7 @@
* Unlink a window, unless it would be destroyed by doing so (only one link).
*/
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_ctx *);
enum cmd_retval cmd_unlink_window_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_unlink_window_entry = {
"unlink-window", "unlinkw",
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
};
enum cmd_retval
cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
cmd_unlink_window_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
@@ -46,7 +46,7 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session_group *sg;
u_int references;
if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL)
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), &s)) == NULL)
return (CMD_RETURN_ERROR);
w = wl->window;
@@ -59,7 +59,7 @@ cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx)
references = 1;
if (!args_has(self->args, 'k') && w->references == references) {
ctx->error(ctx, "window is only linked to one session");
cmdq_error(cmdq, "window is only linked to one session");
return (CMD_RETURN_ERROR);
}
+197
View File
@@ -0,0 +1,197 @@
/* $Id$ */
/*
* Copyright (c) 2013 Nicholas Marriott <nicm@users.sourceforge.net>
* Copyright (c) 2013 Thiago de Arruda <tpadilha84@gmail.com>
*
* 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 <string.h>
#include "tmux.h"
/*
* Block or wake a client on a named wait channel.
*/
enum cmd_retval cmd_wait_for_exec(struct cmd *, struct cmd_q *);
const struct cmd_entry cmd_wait_for_entry = {
"wait-for", "wait",
"LSU", 1, 1,
"[-LSU] channel",
0,
NULL,
NULL,
cmd_wait_for_exec
};
struct wait_channel {
const char *name;
int locked;
TAILQ_HEAD(, cmd_q) waiters;
TAILQ_HEAD(, cmd_q) lockers;
RB_ENTRY(wait_channel) entry;
};
RB_HEAD(wait_channels, wait_channel);
struct wait_channels wait_channels = RB_INITIALIZER(wait_channels);
int wait_channel_cmp(struct wait_channel *, struct wait_channel *);
RB_PROTOTYPE(wait_channels, wait_channel, entry, wait_channel_cmp);
RB_GENERATE(wait_channels, wait_channel, entry, wait_channel_cmp);
int
wait_channel_cmp(struct wait_channel *wc1, struct wait_channel *wc2)
{
return (strcmp(wc1->name, wc2->name));
}
enum cmd_retval cmd_wait_for_signal(struct cmd_q *, const char *,
struct wait_channel *);
enum cmd_retval cmd_wait_for_wait(struct cmd_q *, const char *,
struct wait_channel *);
enum cmd_retval cmd_wait_for_lock(struct cmd_q *, const char *,
struct wait_channel *);
enum cmd_retval cmd_wait_for_unlock(struct cmd_q *, const char *,
struct wait_channel *);
enum cmd_retval
cmd_wait_for_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
const char *name = args->argv[0];
struct wait_channel *wc, wc0;
wc0.name = name;
wc = RB_FIND(wait_channels, &wait_channels, &wc0);
if (args_has(args, 'S'))
return (cmd_wait_for_signal(cmdq, name, wc));
if (args_has(args, 'L'))
return (cmd_wait_for_lock(cmdq, name, wc));
if (args_has(args, 'U'))
return (cmd_wait_for_unlock(cmdq, name, wc));
return (cmd_wait_for_wait(cmdq, name, wc));
}
enum cmd_retval
cmd_wait_for_signal(struct cmd_q *cmdq, const char *name,
struct wait_channel *wc)
{
struct cmd_q *wq, *wq1;
if (wc == NULL || TAILQ_EMPTY(&wc->waiters)) {
cmdq_error(cmdq, "no waiting clients on %s", name);
return (CMD_RETURN_ERROR);
}
TAILQ_FOREACH_SAFE(wq, &wc->waiters, waitentry, wq1) {
TAILQ_REMOVE(&wc->waiters, wq, waitentry);
if (!cmdq_free(wq))
cmdq_continue(wq);
}
if (!wc->locked) {
RB_REMOVE(wait_channels, &wait_channels, wc);
free((void*) wc->name);
free(wc);
}
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_wait_for_wait(struct cmd_q *cmdq, const char *name,
struct wait_channel *wc)
{
if (cmdq->client == NULL || cmdq->client->session != NULL) {
cmdq_error(cmdq, "not able to wait");
return (CMD_RETURN_ERROR);
}
if (wc == NULL) {
wc = xmalloc(sizeof *wc);
wc->name = xstrdup(name);
wc->locked = 0;
TAILQ_INIT(&wc->waiters);
TAILQ_INIT(&wc->lockers);
RB_INSERT(wait_channels, &wait_channels, wc);
}
TAILQ_INSERT_TAIL(&wc->waiters, cmdq, waitentry);
cmdq->references++;
return (CMD_RETURN_WAIT);
}
enum cmd_retval
cmd_wait_for_lock(struct cmd_q *cmdq, const char *name,
struct wait_channel *wc)
{
if (cmdq->client == NULL || cmdq->client->session != NULL) {
cmdq_error(cmdq, "not able to lock");
return (CMD_RETURN_ERROR);
}
if (wc == NULL) {
wc = xmalloc(sizeof *wc);
wc->name = xstrdup(name);
wc->locked = 0;
TAILQ_INIT(&wc->waiters);
TAILQ_INIT(&wc->lockers);
RB_INSERT(wait_channels, &wait_channels, wc);
}
if (wc->locked) {
TAILQ_INSERT_TAIL(&wc->lockers, cmdq, waitentry);
cmdq->references++;
return (CMD_RETURN_WAIT);
}
wc->locked = 1;
return (CMD_RETURN_NORMAL);
}
enum cmd_retval
cmd_wait_for_unlock(struct cmd_q *cmdq, const char *name,
struct wait_channel *wc)
{
struct cmd_q *wq;
if (wc == NULL || !wc->locked) {
cmdq_error(cmdq, "channel %s not locked", name);
return (CMD_RETURN_ERROR);
}
if ((wq = TAILQ_FIRST(&wc->lockers)) != NULL) {
TAILQ_REMOVE(&wc->lockers, wq, waitentry);
if (!cmdq_free(wq))
cmdq_continue(wq);
} else {
wc->locked = 0;
if (TAILQ_EMPTY(&wc->waiters)) {
RB_REMOVE(wait_channels, &wait_channels, wc);
free((void*) wc->name);
free(wc);
}
}
return (CMD_RETURN_NORMAL);
}
+102 -82
View File
@@ -112,6 +112,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_switch_client_entry,
&cmd_unbind_key_entry,
&cmd_unlink_window_entry,
&cmd_wait_for_entry,
NULL
};
@@ -121,13 +122,14 @@ struct session *cmd_choose_session(int);
struct client *cmd_choose_client(struct clients *);
struct client *cmd_lookup_client(const char *);
struct session *cmd_lookup_session(const char *, int *);
struct session *cmd_lookup_session_id(const char *);
struct winlink *cmd_lookup_window(struct session *, const char *, int *);
int cmd_lookup_index(struct session *, const char *, int *);
struct window_pane *cmd_lookup_paneid(const char *);
struct winlink *cmd_lookup_winlink_windowid(struct session *, const char *);
struct window *cmd_lookup_windowid(const char *);
struct session *cmd_window_session(struct cmd_ctx *,
struct window *, struct winlink **);
struct session *cmd_window_session(struct cmd_q *, struct window *,
struct winlink **);
struct winlink *cmd_find_window_offset(const char *, struct session *, int *);
int cmd_find_index_offset(const char *, struct session *, int *);
struct window_pane *cmd_find_pane_offset(const char *, struct winlink *);
@@ -205,7 +207,7 @@ cmd_free_argv(int argc, char **argv)
}
struct cmd *
cmd_parse(int argc, char **argv, char **cause)
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
{
const struct cmd_entry **entryp, *entry;
struct cmd *cmd;
@@ -255,9 +257,14 @@ cmd_parse(int argc, char **argv, char **cause)
if (entry->check != NULL && entry->check(args) != 0)
goto usage;
cmd = xmalloc(sizeof *cmd);
cmd = xcalloc(1, sizeof *cmd);
cmd->entry = entry;
cmd->args = args;
if (file != NULL)
cmd->file = xstrdup(file);
cmd->line = line;
return (cmd);
ambiguous:
@@ -281,19 +288,6 @@ usage:
return (NULL);
}
enum cmd_retval
cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
{
return (cmd->entry->exec(cmd, ctx));
}
void
cmd_free(struct cmd *cmd)
{
args_free(cmd->args);
free(cmd);
}
size_t
cmd_print(struct cmd *cmd, char *buf, size_t len)
{
@@ -319,31 +313,33 @@ cmd_print(struct cmd *cmd, char *buf, size_t len)
* session from all sessions.
*/
struct session *
cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
cmd_current_session(struct cmd_q *cmdq, int prefer_unattached)
{
struct msg_command_data *data = ctx->msgdata;
struct client *c = ctx->cmdclient;
struct msg_command_data *data = cmdq->msgdata;
struct client *c = cmdq->client;
struct session *s;
struct sessionslist ss;
struct winlink *wl;
struct window_pane *wp;
const char *path;
int found;
if (ctx->curclient != NULL && ctx->curclient->session != NULL)
return (ctx->curclient->session);
if (c != NULL && c->session != NULL)
return (c->session);
/*
* If the name of the calling client's pty is know, build a list of the
* sessions that contain it and if any choose either the first or the
* newest.
* If the name of the calling client's pty is known, build a list of
* the sessions that contain it and if any choose either the first or
* the newest.
*/
if (c != NULL && c->tty.path != NULL) {
path = c == NULL ? NULL : c->tty.path;
if (path != NULL) {
ARRAY_INIT(&ss);
RB_FOREACH(s, sessions, &sessions) {
found = 0;
RB_FOREACH(wl, winlinks, &s->windows) {
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
if (strcmp(wp->tty, c->tty.path) == 0) {
if (strcmp(wp->tty, path) == 0) {
found = 1;
break;
}
@@ -362,8 +358,8 @@ cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
}
/* Use the session from the TMUX environment variable. */
if (data != NULL && data->pid == getpid() && data->idx != -1) {
s = session_find_by_index(data->idx);
if (data != NULL && data->pid == getpid() && data->session_id != -1) {
s = session_find_by_id(data->session_id);
if (s != NULL)
return (s);
}
@@ -434,21 +430,21 @@ cmd_choose_session_list(struct sessionslist *ss)
* then of all clients.
*/
struct client *
cmd_current_client(struct cmd_ctx *ctx)
cmd_current_client(struct cmd_q *cmdq)
{
struct session *s;
struct client *c;
struct clients cc;
u_int i;
if (ctx->curclient != NULL)
return (ctx->curclient);
if (cmdq->client != NULL && cmdq->client->session != NULL)
return (cmdq->client);
/*
* No current client set. Find the current session and return the
* newest of its clients.
*/
s = cmd_current_session(ctx, 0);
s = cmd_current_session(cmdq, 0);
if (s != NULL && !(s->flags & SESSION_UNATTACHED)) {
ARRAY_INIT(&cc);
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
@@ -493,15 +489,19 @@ cmd_choose_client(struct clients *cc)
/* Find the target client or report an error and return NULL. */
struct client *
cmd_find_client(struct cmd_ctx *ctx, const char *arg)
cmd_find_client(struct cmd_q *cmdq, const char *arg, int quiet)
{
struct client *c;
char *tmparg;
size_t arglen;
/* A NULL argument means the current client. */
if (arg == NULL)
return (cmd_current_client(ctx));
if (arg == NULL) {
c = cmd_current_client(cmdq);
if (c == NULL && !quiet)
cmdq_error(cmdq, "no clients");
return (c);
}
tmparg = xstrdup(arg);
/* Trim a single trailing colon if any. */
@@ -513,8 +513,8 @@ cmd_find_client(struct cmd_ctx *ctx, const char *arg)
c = cmd_lookup_client(tmparg);
/* If no client found, report an error. */
if (c == NULL)
ctx->error(ctx, "client not found: %s", tmparg);
if (c == NULL && !quiet)
cmdq_error(cmdq, "client not found: %s", tmparg);
free(tmparg);
return (c);
@@ -533,7 +533,7 @@ cmd_lookup_client(const char *name)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (c == NULL || c->session == NULL)
if (c == NULL || c->session == NULL || c->tty.path == NULL)
continue;
path = c->tty.path;
@@ -551,6 +551,21 @@ cmd_lookup_client(const char *name)
return (NULL);
}
/* Find the target session or report an error and return NULL. */
struct session *
cmd_lookup_session_id(const char *arg)
{
char *endptr;
long id;
if (arg[0] != '$')
return (NULL);
id = strtol(arg + 1, &endptr, 10);
if (arg[1] != '\0' && *endptr == '\0')
return (session_find_by_id(id));
return (NULL);
}
/* Lookup a session by name. If no session is found, NULL is returned. */
struct session *
cmd_lookup_session(const char *name, int *ambiguous)
@@ -559,6 +574,10 @@ cmd_lookup_session(const char *name, int *ambiguous)
*ambiguous = 0;
/* Look for $id first. */
if ((s = cmd_lookup_session_id(name)) != NULL)
return (s);
/*
* Look for matches. First look for exact matches - session names must
* be unique so an exact match can't be ambigious and can just be
@@ -716,14 +735,14 @@ cmd_lookup_windowid(const char *arg)
/* Find session and winlink for window. */
struct session *
cmd_window_session(struct cmd_ctx *ctx, struct window *w, struct winlink **wlp)
cmd_window_session(struct cmd_q *cmdq, struct window *w, struct winlink **wlp)
{
struct session *s;
struct sessionslist ss;
struct winlink *wl;
/* If this window is in the current session, return that winlink. */
s = cmd_current_session(ctx, 0);
s = cmd_current_session(cmdq, 0);
if (s != NULL) {
wl = winlink_find_by_window(&s->windows, w);
if (wl != NULL) {
@@ -748,7 +767,7 @@ cmd_window_session(struct cmd_ctx *ctx, struct window *w, struct winlink **wlp)
/* Find the target session or report an error and return NULL. */
struct session *
cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
cmd_find_session(struct cmd_q *cmdq, const char *arg, int prefer_unattached)
{
struct session *s;
struct window_pane *wp;
@@ -760,13 +779,13 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
/* A NULL argument means the current session. */
if (arg == NULL)
return (cmd_current_session(ctx, prefer_unattached));
return (cmd_current_session(cmdq, prefer_unattached));
/* Lookup as pane id or window id. */
if ((wp = cmd_lookup_paneid(arg)) != NULL)
return (cmd_window_session(ctx, wp->window, NULL));
return (cmd_window_session(cmdq, wp->window, NULL));
if ((w = cmd_lookup_windowid(arg)) != NULL)
return (cmd_window_session(ctx, w, NULL));
return (cmd_window_session(cmdq, w, NULL));
/* Trim a single trailing colon if any. */
tmparg = xstrdup(arg);
@@ -777,7 +796,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
/* An empty session name is the current session. */
if (*tmparg == '\0') {
free(tmparg);
return (cmd_current_session(ctx, prefer_unattached));
return (cmd_current_session(cmdq, prefer_unattached));
}
/* Find the session, if any. */
@@ -790,9 +809,9 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
/* If no session found, report an error. */
if (s == NULL) {
if (ambiguous)
ctx->error(ctx, "more than one session: %s", tmparg);
cmdq_error(cmdq, "more than one session: %s", tmparg);
else
ctx->error(ctx, "session not found: %s", tmparg);
cmdq_error(cmdq, "session not found: %s", tmparg);
}
free(tmparg);
@@ -801,7 +820,7 @@ cmd_find_session(struct cmd_ctx *ctx, const char *arg, int prefer_unattached)
/* Find the target session and window or report an error and return NULL. */
struct winlink *
cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
cmd_find_window(struct cmd_q *cmdq, const char *arg, struct session **sp)
{
struct session *s;
struct winlink *wl;
@@ -814,8 +833,8 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
* Find the current session. There must always be a current session, if
* it can't be found, report an error.
*/
if ((s = cmd_current_session(ctx, 0)) == NULL) {
ctx->error(ctx, "can't establish current session");
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
cmdq_error(cmdq, "can't establish current session");
return (NULL);
}
@@ -828,7 +847,7 @@ cmd_find_window(struct cmd_ctx *ctx, const char *arg, struct session **sp)
/* Lookup as pane id. */
if ((wp = cmd_lookup_paneid(arg)) != NULL) {
s = cmd_window_session(ctx, wp->window, &wl);
s = cmd_window_session(cmdq, wp->window, &wl);
if (sp != NULL)
*sp = s;
return (wl);
@@ -909,17 +928,17 @@ lookup_session:
no_session:
if (ambiguous)
ctx->error(ctx, "multiple sessions: %s", arg);
cmdq_error(cmdq, "multiple sessions: %s", arg);
else
ctx->error(ctx, "session not found: %s", arg);
cmdq_error(cmdq, "session not found: %s", arg);
free(sessptr);
return (NULL);
not_found:
if (ambiguous)
ctx->error(ctx, "multiple windows: %s", arg);
cmdq_error(cmdq, "multiple windows: %s", arg);
else
ctx->error(ctx, "window not found: %s", arg);
cmdq_error(cmdq, "window not found: %s", arg);
free(sessptr);
return (NULL);
}
@@ -951,7 +970,7 @@ cmd_find_window_offset(const char *winptr, struct session *s, int *ambiguous)
* example if it is going to be created).
*/
int
cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp)
cmd_find_index(struct cmd_q *cmdq, const char *arg, struct session **sp)
{
struct session *s;
struct winlink *wl;
@@ -963,8 +982,8 @@ cmd_find_index(struct cmd_ctx *ctx, const char *arg, struct session **sp)
* Find the current session. There must always be a current session, if
* it can't be found, report an error.
*/
if ((s = cmd_current_session(ctx, 0)) == NULL) {
ctx->error(ctx, "can't establish current session");
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
cmdq_error(cmdq, "can't establish current session");
return (-2);
}
@@ -1047,25 +1066,25 @@ lookup_session:
no_session:
if (ambiguous)
ctx->error(ctx, "multiple sessions: %s", arg);
cmdq_error(cmdq, "multiple sessions: %s", arg);
else
ctx->error(ctx, "session not found: %s", arg);
cmdq_error(cmdq, "session not found: %s", arg);
free(sessptr);
return (-2);
invalid_index:
if (ambiguous)
goto not_found;
ctx->error(ctx, "invalid index: %s", arg);
cmdq_error(cmdq, "invalid index: %s", arg);
free(sessptr);
return (-2);
not_found:
if (ambiguous)
ctx->error(ctx, "multiple windows: %s", arg);
cmdq_error(cmdq, "multiple windows: %s", arg);
else
ctx->error(ctx, "window not found: %s", arg);
cmdq_error(cmdq, "window not found: %s", arg);
free(sessptr);
return (-2);
}
@@ -1102,7 +1121,7 @@ cmd_find_index_offset(const char *winptr, struct session *s, int *ambiguous)
* such as mysession:mywindow.0.
*/
struct winlink *
cmd_find_pane(struct cmd_ctx *ctx,
cmd_find_pane(struct cmd_q *cmdq,
const char *arg, struct session **sp, struct window_pane **wpp)
{
struct session *s;
@@ -1112,8 +1131,8 @@ cmd_find_pane(struct cmd_ctx *ctx,
u_int idx;
/* Get the current session. */
if ((s = cmd_current_session(ctx, 0)) == NULL) {
ctx->error(ctx, "can't establish current session");
if ((s = cmd_current_session(cmdq, 0)) == NULL) {
cmdq_error(cmdq, "can't establish current session");
return (NULL);
}
if (sp != NULL)
@@ -1127,7 +1146,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
/* Lookup as pane id. */
if ((*wpp = cmd_lookup_paneid(arg)) != NULL) {
s = cmd_window_session(ctx, (*wpp)->window, &wl);
s = cmd_window_session(cmdq, (*wpp)->window, &wl);
if (sp != NULL)
*sp = s;
return (wl);
@@ -1142,7 +1161,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
winptr[period - arg] = '\0';
if (*winptr == '\0')
wl = s->curw;
else if ((wl = cmd_find_window(ctx, winptr, sp)) == NULL)
else if ((wl = cmd_find_window(cmdq, winptr, sp)) == NULL)
goto error;
/* Find the pane section and look it up. */
@@ -1166,7 +1185,7 @@ cmd_find_pane(struct cmd_ctx *ctx,
lookup_string:
/* Try pane string description. */
if ((*wpp = window_find_string(wl->window, paneptr)) == NULL) {
ctx->error(ctx, "can't find pane: %s", paneptr);
cmdq_error(cmdq, "can't find pane: %s", paneptr);
goto error;
}
@@ -1191,7 +1210,7 @@ lookup_window:
return (s->curw);
/* Try as a window and use the active pane. */
if ((wl = cmd_find_window(ctx, arg, sp)) != NULL)
if ((wl = cmd_find_window(cmdq, arg, sp)) != NULL)
*wpp = wl->window->active;
return (wl);
@@ -1221,14 +1240,14 @@ cmd_find_pane_offset(const char *paneptr, struct winlink *wl)
/* Replace the first %% or %idx in template by s. */
char *
cmd_template_replace(char *template, const char *s, int idx)
cmd_template_replace(const char *template, const char *s, int idx)
{
char ch;
char *buf, *ptr;
int replaced;
size_t len;
char ch, *buf;
const char *ptr;
int replaced;
size_t len;
if (strstr(template, "%") == NULL)
if (strchr(template, '%') == NULL)
return (xstrdup(template));
buf = xmalloc(1);
@@ -1269,8 +1288,9 @@ cmd_template_replace(char *template, const char *s, int idx)
* directory.
*/
const char *
cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd)
cmd_get_default_path(struct cmd_q *cmdq, const char *cwd)
{
struct client *c = cmdq->client;
struct session *s;
struct environ_entry *envent;
const char *root;
@@ -1280,7 +1300,7 @@ cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd)
size_t skip;
static char path[MAXPATHLEN];
if ((s = cmd_current_session(ctx, 0)) == NULL)
if ((s = cmd_current_session(cmdq, 0)) == NULL)
return (NULL);
if (cwd == NULL)
@@ -1310,9 +1330,9 @@ cmd_get_default_path(struct cmd_ctx *ctx, const char *cwd)
return (cwd);
} else {
/* Empty or relative path. */
if (ctx->cmdclient != NULL && ctx->cmdclient->cwd != NULL)
root = ctx->cmdclient->cwd;
else if (ctx->curclient != NULL && s->curw != NULL)
if (c != NULL && c->session == NULL && c->cwd != NULL)
root = c->cwd;
else if (s->curw != NULL)
root = osdep_get_cwd(s->curw->window->active->fd);
else
return (s->cwd);
+2
View File
@@ -67,6 +67,8 @@ BSDgetopt(int nargc, char *const *nargv, const char *ostr)
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
if (place[1])
return (BADCH);
++BSDoptind;
place = EMSG;
return (-1);
+5 -2
View File
@@ -41,7 +41,7 @@ AC_CHECK_HEADERS(
)
# Is this a debug build?
found_debug=yes
#found_debug=yes
AC_ARG_ENABLE(
debug,
AC_HELP_STRING(--enable-debug, create a debug build),
@@ -53,8 +53,11 @@ AM_CONDITIONAL(IS_DEBUG, test "x$found_debug" = xyes)
AC_ARG_ENABLE(
static,
AC_HELP_STRING(--enable-static, create a static build),
[LDFLAGS="$LDFLAGS -static"]
found_static=$enable_static
)
if test "x$found_static" = xyes; then
LDFLAGS="$LDFLAGS -static"
fi
# Is this gcc?
AM_CONDITIONAL(IS_GCC, test "x$GCC" = xyes)
+15 -24
View File
@@ -46,8 +46,12 @@ control_notify_input(struct client *c, struct window_pane *wp,
if (winlink_find_by_window(&c->session->windows, wp->window) != NULL) {
message = evbuffer_new();
evbuffer_add_printf(message, "%%output %%%u ", wp->id);
for (i = 0; i < len; i++)
evbuffer_add_printf(message, "%02hhx", buf[i]);
for (i = 0; i < len; i++) {
if (buf[i] < ' ' || buf[i] == '\\')
evbuffer_add_printf(message, "\\%03o", buf[i]);
else
evbuffer_add_printf(message, "%c", buf[i]);
}
control_write_buffer(c, message);
evbuffer_free(message);
}
@@ -95,19 +99,14 @@ void
control_notify_window_unlinked(unused struct session *s, struct window *w)
{
struct client *c;
struct session *cs;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
cs = c->session;
if (winlink_find_by_window_id(&cs->windows, w->id) != NULL)
control_write(c, "%%window-close %u", w->id);
else
control_write(c, "%%unlinked-window-close %u", w->id);
control_write(c, "%%window-close @%u", w->id);
}
}
@@ -125,9 +124,9 @@ control_notify_window_linked(unused struct session *s, struct window *w)
cs = c->session;
if (winlink_find_by_window_id(&cs->windows, w->id) != NULL)
control_write(c, "%%window-add %u", w->id);
control_write(c, "%%window-add @%u", w->id);
else
control_write(c, "%%unlinked-window-add %u", w->id);
control_write(c, "%%unlinked-window-add @%u", w->id);
}
}
@@ -135,22 +134,14 @@ void
control_notify_window_renamed(struct window *w)
{
struct client *c;
struct session *s;
u_int i;
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
continue;
s = c->session;
if (winlink_find_by_window_id(&s->windows, w->id) != NULL) {
control_write(c, "%%window-renamed %u %s",
w->id, w->name);
} else {
control_write(c, "%%unlinked-window-renamed %u %s",
w->id, w->name);
}
control_write(c, "%%window-renamed @%u %s", w->id, w->name);
}
}
@@ -163,7 +154,7 @@ control_notify_attached_session_changed(struct client *c)
return;
s = c->session;
control_write(c, "%%session-changed %d %s", s->idx, s->name);
control_write(c, "%%session-changed $%u %s", s->id, s->name);
}
void
@@ -174,10 +165,10 @@ control_notify_session_renamed(struct session *s)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session != s)
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
control_write(c, "%%session-renamed %s", s->name);
control_write(c, "%%session-renamed $%u %s", s->id, s->name);
}
}
@@ -189,7 +180,7 @@ control_notify_session_created(unused struct session *s)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
control_write(c, "%%sessions-changed");
@@ -204,7 +195,7 @@ control_notify_session_close(unused struct session *s)
for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
c = ARRAY_ITEM(&clients, i);
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;
control_write(c, "%%sessions-changed");
+8 -51
View File
@@ -22,49 +22,10 @@
#include <event.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tmux.h"
void printflike2 control_msg_error(struct cmd_ctx *, const char *, ...);
void printflike2 control_msg_print(struct cmd_ctx *, const char *, ...);
void printflike2 control_msg_info(struct cmd_ctx *, const char *, ...);
/* Command error callback. */
void printflike2
control_msg_error(struct cmd_ctx *ctx, const char *fmt, ...)
{
struct client *c = ctx->curclient;
va_list ap;
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
}
/* Command print callback. */
void printflike2
control_msg_print(struct cmd_ctx *ctx, const char *fmt, ...)
{
struct client *c = ctx->curclient;
va_list ap;
va_start(ap, fmt);
evbuffer_add_vprintf(c->stdout_data, fmt, ap);
va_end(ap);
evbuffer_add(c->stdout_data, "\n", 1);
server_push_stdout(c);
}
/* Command info callback. */
void printflike2
control_msg_info(unused struct cmd_ctx *ctx, unused const char *fmt, ...)
{
}
/* Write a line. */
void printflike2
control_write(struct client *c, const char *fmt, ...)
@@ -93,7 +54,6 @@ void
control_callback(struct client *c, int closed, unused void *data)
{
char *line, *cause;
struct cmd_ctx ctx;
struct cmd_list *cmdlist;
if (closed)
@@ -108,20 +68,17 @@ control_callback(struct client *c, int closed, unused void *data)
break;
}
ctx.msgdata = NULL;
ctx.cmdclient = NULL;
ctx.curclient = c;
if (cmd_string_parse(line, &cmdlist, NULL, 0, &cause) != 0) {
c->cmdq->time = time(NULL);
c->cmdq->number++;
ctx.error = control_msg_error;
ctx.print = control_msg_print;
ctx.info = control_msg_info;
cmdq_guard(c->cmdq, "begin");
control_write(c, "parse error: %s", cause);
cmdq_guard(c->cmdq, "error");
if (cmd_string_parse(line, &cmdlist, &cause) != 0) {
control_write(c, "%%error in line \"%s\": %s", line,
cause);
free(cause);
} else {
cmd_list_exec(cmdlist, &ctx);
cmdq_run(c->cmdq, cmdlist);
cmd_list_free(cmdlist);
}
-57
View File
@@ -1,57 +0,0 @@
#!/bin/bash
# Copyright (c) 2012 Juan Ignacio Pumarino, jipumarino@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Instructions
# ------------
#
# 1. Install this script and give it execute permission somewhere in your PATH.
# For example:
#
# $ mkdir -p ~/bin
# $ wget https://raw.github.com/jipumarino/tmux-zoom/master/tmux-zoom.sh -O ~/bin/tmux-zoom.sh
# $ chmod +x ~/bin/tmux-zoom.sh
#
# 2. Add a shortcut in your ~/.tmux.conf file:
#
# bind C-k run "tmux-zoom.sh"
#
# 3. When using this shortcut, the current tmux pane will open in a new window by itself.
# Running it again in the zoomed window will return it to its original pane. You can have
# as many zoomed windows as you want.
current=$(tmux display-message -p '#W-#I-#P')
list=$(tmux list-window)
[[ "$current" =~ ^(.*)-([0-9]+)-([0-9]+) ]]
current_window=${BASH_REMATCH[1]}
current_pane=${BASH_REMATCH[2]}-${BASH_REMATCH[3]}
new_zoom_window=ZOOM-$current_pane
if [[ $current_window =~ ZOOM-([0-9]+)-([0-9+]) ]]; then
old_zoom_window=ZOOM-${BASH_REMATCH[1]}-${BASH_REMATCH[2]}
tmux select-window -t ${BASH_REMATCH[1]} \; select-pane -t ${BASH_REMATCH[2]} \; swap-pane -s $old_zoom_window.1 \; kill-window -t $old_zoom_window
elif [[ $list =~ $new_zoom_window ]]; then
tmux select-window -t $new_zoom_window
else
tmux new-window -d -n $new_zoom_window \; swap-pane -s $new_zoom_window.1 \; select-window -t $new_zoom_window
fi
+14
View File
@@ -3,6 +3,20 @@
" Maintainer: Tiago Cunha <tcunha@users.sourceforge.net>
" Last Change: $Date: 2010-07-27 18:29:07 $
" License: This file is placed in the public domain.
"
" To install this file:
"
" - Drop the file in the syntax directory into runtimepath (such as
" ~/.vim/syntax/tmux.vim).
" - Make the filetype recognisable by adding the following to filetype.vim
" (~/.vim/filetype.vim):
"
" augroup filetypedetect
" au BufNewFile,BufRead .tmux.conf*,tmux.conf* setf tmux
" augroup END
"
" - Switch on syntax highlighting by adding "syntax enable" to .vimrc.
"
if version < 600
syntax clear
+90 -14
View File
@@ -32,8 +32,9 @@
* string.
*/
int format_replace(struct format_tree *,
const char *, size_t, char **, size_t *, size_t *);
int format_replace(struct format_tree *, const char *, size_t, char **,
size_t *, size_t *);
void format_window_pane_tabs(struct format_tree *, struct window_pane *);
/* Format key-value replacement entry. */
RB_GENERATE(format_tree, format_entry, entry, format_cmp);
@@ -251,10 +252,11 @@ format_expand(struct format_tree *ft, const char *fmt)
continue;
}
}
while (len - off < 2) {
while (len - off < 3) {
buf = xrealloc(buf, 2, len);
len *= 2;
}
buf[off++] = '#';
buf[off++] = ch;
continue;
}
@@ -278,6 +280,7 @@ format_session(struct format_tree *ft, struct session *s)
format_add(ft, "session_windows", "%u", winlink_count(&s->windows));
format_add(ft, "session_width", "%u", s->sx);
format_add(ft, "session_height", "%u", s->sy);
format_add(ft, "session_id", "$%u", s->id);
sg = session_group_find(s);
format_add(ft, "session_grouped", "%d", sg != NULL);
@@ -300,8 +303,9 @@ format_session(struct format_tree *ft, struct session *s)
void
format_client(struct format_tree *ft, struct client *c)
{
char *tim;
time_t t;
char *tim;
time_t t;
struct session *s;
format_add(ft, "client_cwd", "%s", c->cwd);
format_add(ft, "client_height", "%u", c->tty.sy);
@@ -321,6 +325,8 @@ format_client(struct format_tree *ft, struct client *c)
*strchr(tim, '\n') = '\0';
format_add(ft, "client_activity_string", "%s", tim);
format_add(ft, "client_prefix", "%d", !!(c->flags & CLIENT_PREFIX));
if (c->tty.flags & TTY_UTF8)
format_add(ft, "client_utf8", "%d", 1);
else
@@ -330,6 +336,13 @@ format_client(struct format_tree *ft, struct client *c)
format_add(ft, "client_readonly", "%d", 1);
else
format_add(ft, "client_readonly", "%d", 0);
s = c->session;
if (s != NULL)
format_add(ft, "client_session", "%s", s->name);
s = c->last_session;
if (s != NULL && session_alive(s))
format_add(ft, "client_last_session", "%s", s->name);
}
/* Set default format keys for a winlink. */
@@ -356,6 +369,28 @@ format_winlink(struct format_tree *ft, struct session *s, struct winlink *wl)
free(layout);
}
/* Add window pane tabs. */
void
format_window_pane_tabs(struct format_tree *ft, struct window_pane *wp)
{
struct evbuffer *buffer;
u_int i;
buffer = evbuffer_new();
for (i = 0; i < wp->base.grid->sx; i++) {
if (!bit_test(wp->base.tabs, i))
continue;
if (EVBUFFER_LENGTH(buffer) > 0)
evbuffer_add(buffer, ",", 1);
evbuffer_add_printf(buffer, "%d", i);
}
format_add(ft, "pane_tabs", "%.*s", (int) EVBUFFER_LENGTH(buffer),
EVBUFFER_DATA(buffer));
evbuffer_free(buffer);
}
/* Set default format keys for a window pane. */
void
format_window_pane(struct format_tree *ft, struct window_pane *wp)
@@ -363,9 +398,9 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
struct grid *gd = wp->base.grid;
struct grid_line *gl;
unsigned long long size;
u_int i;
u_int idx;
u_int i, idx;
const char *cwd;
char *cmd;
size = 0;
for (i = 0; i < gd->hsize; i++) {
@@ -373,31 +408,72 @@ format_window_pane(struct format_tree *ft, struct window_pane *wp)
size += gl->cellsize * sizeof *gl->celldata;
}
size += gd->hsize * sizeof *gd->linedata;
format_add(ft, "history_size", "%u", gd->hsize);
format_add(ft, "history_limit", "%u", gd->hlimit);
format_add(ft, "history_bytes", "%llu", size);
if (window_pane_index(wp, &idx) != 0)
fatalx("index not found");
format_add(ft, "pane_index", "%u", idx);
format_add(ft, "pane_width", "%u", wp->sx);
format_add(ft, "pane_height", "%u", wp->sy);
format_add(ft, "pane_title", "%s", wp->base.title);
format_add(ft, "pane_index", "%u", idx);
format_add(ft, "history_size", "%u", gd->hsize);
format_add(ft, "history_limit", "%u", gd->hlimit);
format_add(ft, "history_bytes", "%llu", size);
format_add(ft, "pane_id", "%%%u", wp->id);
format_add(ft, "pane_active", "%d", wp == wp->window->active);
format_add(ft, "pane_dead", "%d", wp->fd == -1);
format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
if (wp->tty != NULL)
format_add(ft, "pane_tty", "%s", wp->tty);
format_add(ft, "pane_pid", "%ld", (long) wp->pid);
if (wp->cmd != NULL)
format_add(ft, "pane_start_command", "%s", wp->cmd);
if (wp->cwd != NULL)
format_add(ft, "pane_start_path", "%s", wp->cwd);
if ((cwd = osdep_get_cwd(wp->fd)) != NULL)
format_add(ft, "pane_current_path", "%s", cwd);
format_add(ft, "pane_pid", "%ld", (long) wp->pid);
if (wp->tty != NULL)
format_add(ft, "pane_tty", "%s", wp->tty);
if ((cmd = osdep_get_name(wp->fd, wp->tty)) != NULL) {
format_add(ft, "pane_current_command", "%s", cmd);
free(cmd);
}
format_add(ft, "cursor_x", "%d", wp->base.cx);
format_add(ft, "cursor_y", "%d", wp->base.cy);
format_add(ft, "scroll_region_upper", "%d", wp->base.rupper);
format_add(ft, "scroll_region_lower", "%d", wp->base.rlower);
format_add(ft, "saved_cursor_x", "%d", wp->ictx.old_cx);
format_add(ft, "saved_cursor_y", "%d", wp->ictx.old_cy);
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
format_add(ft, "alternate_saved_x", "%d", wp->saved_cx);
format_add(ft, "alternate_saved_y", "%d", wp->saved_cy);
format_add(ft, "cursor_flag", "%d",
!!(wp->base.mode & MODE_CURSOR));
format_add(ft, "insert_flag", "%d",
!!(wp->base.mode & MODE_INSERT));
format_add(ft, "keypad_cursor_flag", "%d",
!!(wp->base.mode & MODE_KCURSOR));
format_add(ft, "keypad_flag", "%d",
!!(wp->base.mode & MODE_KKEYPAD));
format_add(ft, "wrap_flag", "%d",
!!(wp->base.mode & MODE_WRAP));
format_add(ft, "mouse_standard_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_STANDARD));
format_add(ft, "mouse_button_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_BUTTON));
format_add(ft, "mouse_any_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_ANY));
format_add(ft, "mouse_utf8_flag", "%d",
!!(wp->base.mode & MODE_MOUSE_UTF8));
format_window_pane_tabs(ft, wp);
}
/* Set default format keys for paste buffer. */
void
format_paste_buffer(struct format_tree *ft, struct paste_buffer *pb)
{
+1 -1
View File
@@ -234,5 +234,5 @@ grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
px = grid_view_x(gd, px);
py = grid_view_y(gd, py);
return (grid_string_cells(gd, px, py, nx));
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0));
}
+351 -36
View File
@@ -70,6 +70,15 @@ grid_check_y(struct grid *gd, u_int py)
}
#endif
void grid_reflow_join(struct grid *, u_int *, struct grid_line *, u_int);
void grid_reflow_split(struct grid *, u_int *, struct grid_line *, u_int,
u_int);
void grid_reflow_move(struct grid *, u_int *, struct grid_line *);
size_t grid_string_cells_fg(const struct grid_cell *, int *);
size_t grid_string_cells_bg(const struct grid_cell *, int *);
void grid_string_cells_code(const struct grid_cell *,
const struct grid_cell *, char *, size_t, int);
/* Create a new grid. */
struct grid *
grid_create(u_int sx, u_int sy, u_int hlimit)
@@ -225,6 +234,15 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
gl->cellsize = sx;
}
/* Peek at grid line. */
const struct grid_line *
grid_peek_line(struct grid *gd, u_int py)
{
if (grid_check_y(gd, py) != 0)
return (NULL);
return (&gd->linedata[py]);
}
/* Get cell for reading. */
const struct grid_cell *
grid_peek_cell(struct grid *gd, u_int px, u_int py)
@@ -387,18 +405,201 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx)
}
}
/* Get ANSI foreground sequence. */
size_t
grid_string_cells_fg(const struct grid_cell *gc, int *values)
{
size_t n;
n = 0;
if (gc->flags & GRID_FLAG_FG256) {
values[n++] = 38;
values[n++] = 5;
values[n++] = gc->fg;
} else {
switch (gc->fg) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
values[n++] = gc->fg + 30;
break;
case 8:
values[n++] = 39;
break;
case 90:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 97:
values[n++] = gc->fg;
break;
}
}
return (n);
}
/* Get ANSI background sequence. */
size_t
grid_string_cells_bg(const struct grid_cell *gc, int *values)
{
size_t n;
n = 0;
if (gc->flags & GRID_FLAG_BG256) {
values[n++] = 48;
values[n++] = 5;
values[n++] = gc->bg;
} else {
switch (gc->bg) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
values[n++] = gc->bg + 40;
break;
case 8:
values[n++] = 49;
break;
case 100:
case 101:
case 102:
case 103:
case 104:
case 105:
case 106:
case 107:
values[n++] = gc->bg - 10;
break;
}
}
return (n);
}
/*
* Returns ANSI code to set particular attributes (colour, bold and so on)
* given a current state. The output buffer must be able to hold at least 57
* bytes.
*/
void
grid_string_cells_code(const struct grid_cell *lastgc,
const struct grid_cell *gc, char *buf, size_t len, int escape_c0)
{
int oldc[16], newc[16], s[32];
size_t noldc, nnewc, n, i;
u_int attr = gc->attr;
u_int lastattr = lastgc->attr;
char tmp[64];
struct {
u_int mask;
u_int code;
} attrs[] = {
{ GRID_ATTR_BRIGHT, 1 },
{ GRID_ATTR_DIM, 2 },
{ GRID_ATTR_ITALICS, 3 },
{ GRID_ATTR_UNDERSCORE, 4 },
{ GRID_ATTR_BLINK, 5 },
{ GRID_ATTR_REVERSE, 7 },
{ GRID_ATTR_HIDDEN, 8 }
};
n = 0;
/* If any attribute is removed, begin with 0. */
for (i = 0; i < nitems(attrs); i++) {
if (!(attr & attrs[i].mask) && (lastattr & attrs[i].mask)) {
s[n++] = 0;
lastattr &= GRID_ATTR_CHARSET;
break;
}
}
/* For each attribute that is newly set, add its code. */
for (i = 0; i < nitems(attrs); i++) {
if ((attr & attrs[i].mask) && !(lastattr & attrs[i].mask))
s[n++] = attrs[i].code;
}
/* If the foreground c changed, append its parameters. */
nnewc = grid_string_cells_fg(gc, newc);
noldc = grid_string_cells_fg(lastgc, oldc);
if (nnewc != noldc ||
memcmp(newc,oldc, nnewc * sizeof newc[0]) != 0) {
for (i = 0; i < nnewc; i++)
s[n++] = newc[i];
}
/* If the background c changed, append its parameters. */
nnewc = grid_string_cells_bg(gc, newc);
noldc = grid_string_cells_bg(lastgc, oldc);
if (nnewc != noldc ||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
for (i = 0; i < nnewc; i++)
s[n++] = newc[i];
}
/* If there are any parameters, append an SGR code. */
*buf = '\0';
if (n > 0) {
if (escape_c0)
strlcat(buf, "\\033[", len);
else
strlcat(buf, "\033[", len);
for (i = 0; i < n; i++) {
if (i + 1 < n)
xsnprintf(tmp, sizeof tmp, "%d;", s[i]);
else
xsnprintf(tmp, sizeof tmp, "%d", s[i]);
strlcat(buf, tmp, len);
}
strlcat(buf, "m", len);
}
/* Append shift in/shift out if needed. */
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
if (escape_c0)
strlcat(buf, "\\016", len); /* SO */
else
strlcat(buf, "\016", len); /* SO */
}
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
if (escape_c0)
strlcat(buf, "\\017", len); /* SI */
else
strlcat(buf, "\017", len); /* SI */
}
}
/* Convert cells into a string. */
char *
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
struct grid_cell **lastgc, int with_codes, int escape_c0, int trim)
{
const struct grid_cell *gc;
static struct grid_cell lastgc1;
struct utf8_data ud;
char *buf;
size_t len, off;
const char* data;
char *buf, code[128];
size_t len, off, size, codelen;
u_int xx;
GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
if (lastgc != NULL && *lastgc == NULL) {
memcpy(&lastgc1, &grid_default_cell, sizeof lastgc1);
*lastgc = &lastgc1;
}
len = 128;
buf = xmalloc(len);
off = 0;
@@ -409,18 +610,40 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
continue;
grid_cell_get(gc, &ud);
while (len < off + ud.size + 1) {
if (with_codes) {
grid_string_cells_code(*lastgc, gc, code, sizeof code,
escape_c0);
codelen = strlen(code);
memcpy(*lastgc, gc, sizeof *gc);
} else
codelen = 0;
data = ud.data;
size = ud.size;
if (escape_c0 && size == 1 && *data == '\\') {
data = "\\\\";
size = 2;
}
while (len < off + size + codelen + 1) {
buf = xrealloc(buf, 2, len);
len *= 2;
}
memcpy(buf + off, ud.data, ud.size);
off += ud.size;
if (codelen != 0) {
memcpy(buf + off, code, codelen);
off += codelen;
}
memcpy(buf + off, data, size);
off += size;
}
while (off > 0 && buf[off - 1] == ' ')
off--;
if (trim) {
while (off > 0 && buf[off - 1] == ' ')
off--;
}
buf[off] = '\0';
return (buf);
}
@@ -461,43 +684,135 @@ grid_duplicate_lines(
}
}
/* Join line data. */
void
grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
u_int new_x)
{
struct grid_line *dst_gl = &dst->linedata[(*py) - 1];
u_int left, to_copy, ox, nx;
/* How much is left on the old line? */
left = new_x - dst_gl->cellsize;
/* Work out how much to append. */
to_copy = src_gl->cellsize;
if (to_copy > left)
to_copy = left;
ox = dst_gl->cellsize;
nx = ox + to_copy;
/* Resize the destination line. */
dst_gl->celldata = xrealloc(dst_gl->celldata, nx,
sizeof *dst_gl->celldata);
dst_gl->cellsize = nx;
/* Append as much as possible. */
memcpy(&dst_gl->celldata[ox], &src_gl->celldata[0],
to_copy * sizeof src_gl->celldata[0]);
/* If there is any left in the source, split it. */
if (src_gl->cellsize > to_copy) {
dst_gl->flags |= GRID_LINE_WRAPPED;
src_gl->cellsize -= to_copy;
grid_reflow_split(dst, py, src_gl, new_x, to_copy);
}
}
/* Split line data. */
void
grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
u_int new_x, u_int offset)
{
struct grid_line *dst_gl = NULL;
u_int to_copy;
/* Loop and copy sections of the source line. */
while (src_gl->cellsize > 0) {
/* Create new line. */
if (*py >= dst->hsize + dst->sy)
grid_scroll_history(dst);
dst_gl = &dst->linedata[*py];
(*py)++;
/* How much should we copy? */
to_copy = new_x;
if (to_copy > src_gl->cellsize)
to_copy = src_gl->cellsize;
/* Expand destination line. */
dst_gl->celldata = xmalloc(to_copy * sizeof *dst_gl->celldata);
dst_gl->cellsize = to_copy;
dst_gl->flags |= GRID_LINE_WRAPPED;
/* Copy the data. */
memcpy (&dst_gl->celldata[0], &src_gl->celldata[offset],
to_copy * sizeof dst_gl->celldata[0]);
/* Move offset and reduce old line size. */
offset += to_copy;
src_gl->cellsize -= to_copy;
}
/* Last line is not wrapped. */
if (dst_gl != NULL)
dst_gl->flags &= ~GRID_LINE_WRAPPED;
}
/* Move line data. */
void
grid_reflow_move(struct grid *dst, u_int *py, struct grid_line *src_gl)
{
struct grid_line *dst_gl;
/* Create new line. */
if (*py >= dst->hsize + dst->sy)
grid_scroll_history(dst);
dst_gl = &dst->linedata[*py];
(*py)++;
/* Copy the old line. */
memcpy(dst_gl, src_gl, sizeof *dst_gl);
dst_gl->flags &= ~GRID_LINE_WRAPPED;
/* Clear old line. */
src_gl->celldata = NULL;
}
/*
* Reflow lines from src grid into dst grid based on width sx. Returns number
* of lines fewer in the visible area, or zero.
* Reflow lines from src grid into dst grid of width new_x. Returns number of
* lines fewer in the visible area. The source grid is destroyed.
*/
u_int
grid_reflow(struct grid *dst, const struct grid *src, u_int sx)
grid_reflow(struct grid *dst, struct grid *src, u_int new_x)
{
u_int px, py, line, cell;
u_int py, sy, line;
int previous_wrapped;
struct grid_line *gl;
struct grid_line *src_gl;
px = py = 0;
previous_wrapped = 1;
for (line = 0; line < src->sy + src->hsize; line++) {
gl = src->linedata + line;
py = 0;
sy = src->sy;
previous_wrapped = 0;
for (line = 0; line < sy + src->hsize; line++) {
src_gl = src->linedata + line;
if (!previous_wrapped) {
px = 0;
py++;
if (py >= dst->hsize + dst->sy)
grid_scroll_history(dst);
/* Wasn't wrapped. If smaller, move to destination. */
if (src_gl->cellsize <= new_x)
grid_reflow_move(dst, &py, src_gl);
else
grid_reflow_split(dst, &py, src_gl, new_x, 0);
} else {
/* Previous was wrapped. Try to join. */
grid_reflow_join(dst, &py, src_gl, new_x);
}
for (cell = 0; cell < gl->cellsize; cell++) {
if (px == sx) {
dst->linedata[py].flags |= GRID_LINE_WRAPPED;
px = 0;
py++;
if (py >= dst->hsize + dst->sy)
grid_scroll_history(dst);
}
grid_set_cell(dst, px, py, gl->celldata + cell);
px++;
}
previous_wrapped = gl->flags & GRID_LINE_WRAPPED;
previous_wrapped = src_gl->flags & GRID_LINE_WRAPPED;
}
py++; /* account for final line, which never wraps */
if (py > src->sy)
grid_destroy(src);
if (py > sy)
return (0);
return (src->sy - py);
return (sy - py);
}
+16 -2
View File
@@ -201,12 +201,26 @@ input_key(struct window_pane *wp, int key)
void
input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
{
char buf[10];
char buf[40];
size_t len;
struct paste_buffer *pb;
if (wp->screen->mode & ALL_MOUSE_MODES) {
if (wp->screen->mode & MODE_MOUSE_UTF8) {
/*
* Use the SGR (1006) extension only if the application
* requested it and the underlying terminal also sent the event
* in this format (this is because an old style mouse release
* event cannot be converted into the new SGR format, since the
* released button is unknown). Otherwise pretend that tmux
* doesn't speak this extension, and fall back to the UTF-8
* (1005) extension if the application requested, or to the
* legacy format.
*/
if (m->sgr && (wp->screen->mode & MODE_MOUSE_SGR)) {
len = xsnprintf(buf, sizeof buf, "\033[<%d;%d;%d%c",
m->sgr_xb, m->x + 1, m->y + 1,
m->sgr_rel ? 'm' : 'M');
} else if (wp->screen->mode & MODE_MOUSE_UTF8) {
len = xsnprintf(buf, sizeof buf, "\033[M");
len += utf8_split2(m->xb + 32, &buf[len]);
len += utf8_split2(m->x + 33, &buf[len]);
+40 -18
View File
@@ -1033,10 +1033,10 @@ input_esc_dispatch(struct input_ctx *ictx)
screen_write_reverseindex(sctx);
break;
case INPUT_ESC_DECKPAM:
screen_write_kkeypadmode(sctx, 1);
screen_write_mode_set(sctx, MODE_KKEYPAD);
break;
case INPUT_ESC_DECKPNM:
screen_write_kkeypadmode(sctx, 0);
screen_write_mode_clear(sctx, MODE_KKEYPAD);
break;
case INPUT_ESC_DECSC:
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
@@ -1232,7 +1232,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_RM:
switch (input_get(ictx, 0, 0, -1)) {
case 4: /* IRM */
screen_write_insertmode(&ictx->ctx, 0);
screen_write_mode_clear(&ictx->ctx, MODE_INSERT);
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
@@ -1242,23 +1242,32 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_RM_PRIVATE:
switch (input_get(ictx, 0, 0, -1)) {
case 1: /* GATM */
screen_write_kcursormode(&ictx->ctx, 0);
screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR);
break;
case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0);
screen_write_clearscreen(&ictx->ctx);
break;
case 7: /* DECAWM */
screen_write_mode_clear(&ictx->ctx, MODE_WRAP);
break;
case 25: /* TCEM */
screen_write_cursormode(&ictx->ctx, 0);
screen_write_mode_clear(&ictx->ctx, MODE_CURSOR);
break;
case 1000:
case 1001:
case 1002:
case 1003:
screen_write_mousemode_off(&ictx->ctx);
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
break;
case 1004:
screen_write_mode_clear(&ictx->ctx, MODE_FOCUSON);
break;
case 1005:
screen_write_utf8mousemode(&ictx->ctx, 0);
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_UTF8);
break;
case 1006:
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_SGR);
break;
case 47:
case 1047:
@@ -1268,7 +1277,7 @@ input_csi_dispatch(struct input_ctx *ictx)
window_pane_alternate_off(wp, &ictx->cell, 1);
break;
case 2004:
screen_write_bracketpaste(&ictx->ctx, 0);
screen_write_mode_clear(&ictx->ctx, MODE_BRACKETPASTE);
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
@@ -1286,7 +1295,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_SM:
switch (input_get(ictx, 0, 0, -1)) {
case 4: /* IRM */
screen_write_insertmode(&ictx->ctx, 1);
screen_write_mode_set(&ictx->ctx, MODE_INSERT);
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
@@ -1296,28 +1305,41 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_SM_PRIVATE:
switch (input_get(ictx, 0, 0, -1)) {
case 1: /* GATM */
screen_write_kcursormode(&ictx->ctx, 1);
screen_write_mode_set(&ictx->ctx, MODE_KCURSOR);
break;
case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0);
screen_write_clearscreen(&ictx->ctx);
break;
case 7: /* DECAWM */
screen_write_mode_set(&ictx->ctx, MODE_WRAP);
break;
case 25: /* TCEM */
screen_write_cursormode(&ictx->ctx, 1);
screen_write_mode_set(&ictx->ctx, MODE_CURSOR);
break;
case 1000:
screen_write_mousemode_on(
&ictx->ctx, MODE_MOUSE_STANDARD);
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_STANDARD);
break;
case 1002:
screen_write_mousemode_on(
&ictx->ctx, MODE_MOUSE_BUTTON);
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_BUTTON);
break;
case 1003:
screen_write_mousemode_on(&ictx->ctx, MODE_MOUSE_ANY);
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_ANY);
break;
case 1004:
if (s->mode & MODE_FOCUSON)
break;
screen_write_mode_set(&ictx->ctx, MODE_FOCUSON);
wp->flags &= ~PANE_FOCUSED; /* force update if needed */
break;
case 1005:
screen_write_utf8mousemode(&ictx->ctx, 1);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_UTF8);
break;
case 1006:
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_SGR);
break;
case 47:
case 1047:
@@ -1327,7 +1349,7 @@ input_csi_dispatch(struct input_ctx *ictx)
window_pane_alternate_on(wp, &ictx->cell, 1);
break;
case 2004:
screen_write_bracketpaste(&ictx->ctx, 1);
screen_write_mode_set(&ictx->ctx, MODE_BRACKETPASTE);
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
+27 -8
View File
@@ -32,13 +32,14 @@
*/
void job_callback(struct bufferevent *, short, void *);
void job_write_callback(struct bufferevent *, void *);
/* All jobs list. */
struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
/* Start a job running, if it isn't already. */
struct job *
job_run(const char *cmd,
job_run(const char *cmd, struct session *s,
void (*callbackfn)(struct job *), void (*freefn)(void *), void *data)
{
struct job *job;
@@ -51,7 +52,9 @@ job_run(const char *cmd,
environ_init(&env);
environ_copy(&global_environ, &env);
server_fill_environ(NULL, &env);
if (s != NULL)
environ_copy(&s->environ, &env);
server_fill_environ(s, &env);
switch (pid = fork()) {
case -1:
@@ -63,20 +66,20 @@ job_run(const char *cmd,
environ_push(&env);
environ_free(&env);
if (dup2(out[1], STDIN_FILENO) == -1)
fatal("dup2 failed");
if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed");
if (out[1] != STDOUT_FILENO)
if (out[1] != STDIN_FILENO && out[1] != STDOUT_FILENO)
close(out[1]);
close(out[0]);
nullfd = open(_PATH_DEVNULL, O_RDWR, 0);
if (nullfd < 0)
fatal("open failed");
if (dup2(nullfd, STDIN_FILENO) == -1)
fatal("dup2 failed");
if (dup2(nullfd, STDERR_FILENO) == -1)
fatal("dup2 failed");
if (nullfd != STDIN_FILENO && nullfd != STDERR_FILENO)
if (nullfd != STDERR_FILENO)
close(nullfd);
closefrom(STDERR_FILENO + 1);
@@ -103,7 +106,8 @@ job_run(const char *cmd,
job->fd = out[0];
setblocking(job->fd, 0);
job->event = bufferevent_new(job->fd, NULL, NULL, job_callback, job);
job->event = bufferevent_new(job->fd, NULL, job_write_callback,
job_callback, job);
bufferevent_enable(job->event, EV_READ);
log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
@@ -132,8 +136,23 @@ job_free(struct job *job)
free(job);
}
/* Called when output buffer falls below low watermark (default is 0). */
void
job_write_callback(unused struct bufferevent *bufev, void *data)
{
struct job *job = data;
size_t len = EVBUFFER_LENGTH(EVBUFFER_OUTPUT(job->event));
log_debug("job write %p: %s, pid %ld, output left %lu", job, job->cmd,
(long) job->pid, (unsigned long) len);
if (len == 0) {
shutdown(job->fd, SHUT_WR);
bufferevent_disable(job->event, EV_WRITE);
}
}
/* Job buffer error callback. */
/* ARGSUSED */
void
job_callback(unused struct bufferevent *bufev, unused short events, void *data)
{
+7 -76
View File
@@ -150,6 +150,7 @@ key_bindings_init(void)
{ 't', 0, &cmd_clock_mode_entry },
{ 'w', 0, &cmd_choose_window_entry },
{ 'x', 0, &cmd_confirm_before_entry },
{ 'z', 0, &cmd_resize_pane_entry },
{ '{', 0, &cmd_swap_pane_entry },
{ '}', 0, &cmd_swap_pane_entry },
{ '~', 0, &cmd_show_messages_entry },
@@ -182,11 +183,11 @@ key_bindings_init(void)
RB_INIT(&key_bindings);
for (i = 0; i < nitems(table); i++) {
cmdlist = xmalloc(sizeof *cmdlist);
TAILQ_INIT(&cmdlist->list);
cmdlist = xcalloc(1, sizeof *cmdlist);
cmdlist->references = 1;
TAILQ_INIT(&cmdlist->list);
cmd = xmalloc(sizeof *cmd);
cmd = xcalloc(1, sizeof *cmd);
cmd->entry = table[i].entry;
if (cmd->entry->key_binding != NULL)
cmd->entry->key_binding(cmd, table[i].key);
@@ -199,91 +200,21 @@ key_bindings_init(void)
}
}
void printflike2
key_bindings_error(struct cmd_ctx *ctx, const char *fmt, ...)
{
va_list ap;
char *msg;
if (ctx->curclient->session == NULL)
return;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end(ap);
*msg = toupper((u_char) *msg);
status_message_set(ctx->curclient, "%s", msg);
free(msg);
}
void printflike2
key_bindings_print(struct cmd_ctx *ctx, const char *fmt, ...)
{
struct winlink *wl;
va_list ap;
if (ctx->curclient->session == NULL)
return;
wl = ctx->curclient->session->curw;
if (wl->window->active->mode != &window_copy_mode) {
window_pane_reset_mode(wl->window->active);
window_pane_set_mode(wl->window->active, &window_copy_mode);
window_copy_init_for_output(wl->window->active);
}
va_start(ap, fmt);
window_copy_vadd(wl->window->active, fmt, ap);
va_end(ap);
}
void printflike2
key_bindings_info(struct cmd_ctx *ctx, const char *fmt, ...)
{
va_list ap;
char *msg;
if (ctx->curclient->session == NULL)
return;
if (options_get_number(&global_options, "quiet"))
return;
va_start(ap, fmt);
xvasprintf(&msg, fmt, ap);
va_end(ap);
*msg = toupper((u_char) *msg);
status_message_set(ctx->curclient, "%s", msg);
free(msg);
}
void
key_bindings_dispatch(struct key_binding *bd, struct client *c)
{
struct cmd_ctx ctx;
struct cmd *cmd;
int readonly;
ctx.msgdata = NULL;
ctx.curclient = c;
ctx.error = key_bindings_error;
ctx.print = key_bindings_print;
ctx.info = key_bindings_info;
ctx.cmdclient = NULL;
readonly = 1;
TAILQ_FOREACH(cmd, &bd->cmdlist->list, qentry) {
if (!(cmd->entry->flags & CMD_READONLY))
readonly = 0;
}
if (!readonly && c->flags & CLIENT_READONLY) {
key_bindings_info(&ctx, "Client is read-only");
if (!readonly && (c->flags & CLIENT_READONLY)) {
cmdq_info(c->cmdq, "client is read-only");
return;
}
cmd_list_exec(bd->cmdlist, &ctx);
cmdq_run(c->cmdq, bd->cmdlist);
}
+6 -5
View File
@@ -136,9 +136,10 @@ key_string_get_modifiers(const char **string)
int
key_string_lookup_string(const char *string)
{
int key, modifiers;
u_short u;
int size;
static const char *other = "!#()+,-.0123456789:;<=>?'\r\t";
int key, modifiers;
u_short u;
int size;
/* Is this a hexadecimal value? */
if (string[0] == '0' && string[1] == 'x') {
@@ -170,7 +171,7 @@ key_string_lookup_string(const char *string)
}
/* Convert the standard control keys. */
if (key < KEYC_BASE && (modifiers & KEYC_CTRL)) {
if (key < KEYC_BASE && (modifiers & KEYC_CTRL) && !strchr(other, key)) {
if (key >= 97 && key <= 122)
key -= 96;
else if (key >= 64 && key <= 95)
@@ -193,7 +194,7 @@ key_string_lookup_key(int key)
{
static char out[24];
char tmp[8];
u_int i;
u_int i;
*out = '\0';
+6 -3
View File
@@ -63,7 +63,7 @@ layout_dump(struct window *w)
if (layout_append(w->layout_root, layout, sizeof layout) != 0)
return (NULL);
xasprintf(&out, "%4x,%s", layout_checksum(layout), layout);
xasprintf(&out, "%04x,%s", layout_checksum(layout), layout);
return (out);
}
@@ -206,11 +206,11 @@ layout_construct(struct layout_cell *lcparent, const char **layout)
{
struct layout_cell *lc, *lcchild;
u_int sx, sy, xoff, yoff;
const char *saved;
if (!isdigit((u_char) **layout))
return (NULL);
if (sscanf(*layout, "%ux%u,%u,%u,%*u", &sx, &sy, &xoff, &yoff) != 4 &&
sscanf(*layout, "%ux%u,%u,%u", &sx, &sy, &xoff, &yoff) != 4)
if (sscanf(*layout, "%ux%u,%u,%u", &sx, &sy, &xoff, &yoff) != 4)
return (NULL);
while (isdigit((u_char) **layout))
@@ -231,9 +231,12 @@ layout_construct(struct layout_cell *lcparent, const char **layout)
while (isdigit((u_char) **layout))
(*layout)++;
if (**layout == ',') {
saved = *layout;
(*layout)++;
while (isdigit((u_char) **layout))
(*layout)++;
if (**layout == 'x')
*layout = saved;
}
lc = layout_create_cell(lcparent);
+38 -2
View File
@@ -374,13 +374,13 @@ layout_destroy_cell(struct layout_cell *lc, struct layout_cell **lcroot)
}
void
layout_init(struct window *w)
layout_init(struct window *w, struct window_pane *wp)
{
struct layout_cell *lc;
lc = w->layout_root = layout_create_cell(NULL);
layout_set_size(lc, w->sx, w->sy, 0, 0);
layout_make_leaf(lc, TAILQ_FIRST(&w->panes));
layout_make_leaf(lc, wp);
layout_fix_panes(w, w->sx, w->sy);
}
@@ -443,6 +443,39 @@ layout_resize(struct window *w, u_int sx, u_int sy)
layout_fix_panes(w, sx, sy);
}
/* Resize a pane to an absolute size. */
void
layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
u_int new_size)
{
struct layout_cell *lc, *lcparent;
int change, size;
lc = wp->layout_cell;
/* Find next parent of the same type. */
lcparent = lc->parent;
while (lcparent != NULL && lcparent->type != type) {
lc = lcparent;
lcparent = lc->parent;
}
if (lcparent == NULL)
return;
/* Work out the size adjustment. */
if (type == LAYOUT_LEFTRIGHT)
size = lc->sx;
else
size = lc->sy;
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
change = size - new_size;
else
change = new_size - size;
/* Resize the pane. */
layout_resize_pane(wp, type, change);
}
/* Resize a single pane within the layout. */
void
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
@@ -486,6 +519,7 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
notify_window_layout_changed(wp->window);
}
/* Resize pane based on mouse events. */
void
layout_resize_pane_mouse(struct client *c)
{
@@ -534,6 +568,7 @@ layout_resize_pane_mouse(struct client *c)
m->flags &= ~MOUSE_RESIZE_PANE;
}
/* Helper function to grow pane. */
int
layout_resize_pane_grow(
struct layout_cell *lc, enum layout_type type, int needed)
@@ -574,6 +609,7 @@ layout_resize_pane_grow(
return (size);
}
/* Helper function to shrink pane. */
int
layout_resize_pane_shrink(
struct layout_cell *lc, enum layout_type type, int needed)

Some files were not shown because too many files have changed in this diff Show More