431 Commits
3.5a ... 3.6a

Author SHA1 Message Date
Nicholas Marriott
cc117b5048 Update CHANGES. 2025-12-05 05:39:46 +00:00
nicm
faebe7a70a Do not read over buffer if format is a single #, and do not loop forever
if UTF-8 is unfinished in a format. Reported by Giorgi Kobakhia im
GitHub issue 4735.
2025-12-05 05:38:05 +00:00
nicm
01962e25dc Allow drag in alternate screen again, GitHub issue 4743 reported by Brad
King.
2025-12-05 05:37:57 +00:00
nicm
ff207eb583 Fix y offset of mouse if status at top. GitHub issue 4738 from Michael
Grant.
2025-12-05 05:37:48 +00:00
Nicholas Marriott
2fc123cf4a Update CHANGES. 2025-12-04 20:54:44 +00:00
nicm
3b57077d01 Add a missing skin tone, from Jake Stewart in GitHub issue 4736. 2025-12-04 20:53:01 +00:00
nicm
33c1ba1549 Allow characters to be combined in either order, reported by Jake
Stewart in GitHub issue 4726.
2025-12-04 20:52:55 +00:00
Nicholas Marriott
52917abe21 Update CHANGES. 2025-12-02 14:26:30 +00:00
nicm
a40f98df0a Change noattr to be an explicit attribute in the style so that it works
correctly and does not delete attributes set in the style itself, GitHub
issue 4713.
2025-12-02 14:25:05 +00:00
nicm
2c78a5aceb Add horizontal border case to server_client_check_mouse_in_pane to fix
mouse resizing. GitHub issue 4720 from Michael Grant, reported by
someone in GitHub issue 4715.
2025-12-02 14:24:57 +00:00
Nicholas Marriott
bfecbb0685 Fix combine-test.result, GitHub issue 4717. 2025-12-01 08:21:04 +00:00
Nicholas Marriott
640e1a7643 Update CHANGES. 2025-11-27 07:26:09 +00:00
nicm
2a0b078e15 Place cursor on correct line if message-line is not 0, reported by
Alexis Hildebrandt.
2025-11-27 07:24:50 +00:00
nicm
0af04295f3 Newer libevents do not allow event_del on a zero'd event. 2025-11-27 07:24:47 +00:00
Nicholas Marriott
ec4b5b52af Version and CHANGES. 2025-11-26 19:00:17 +00:00
Nicholas Marriott
6db6a30ab5 Need signal.h for utempter, from Yasuhiro Kimura. 2025-11-26 18:43:11 +00:00
Nicholas Marriott
0dac7fe434 Add to CHANGES. 2025-11-26 08:34:33 +00:00
nicm
a6690032ad Add seconds options for clock mode, from augustus7613 dot mail at pm dot
me in GitHub issue 4697.
2025-11-26 08:33:32 +00:00
Nicholas Marriott
00cef3e6be Add to CHANGES. 2025-11-25 22:07:09 +00:00
Nicholas Marriott
3f4a8713c9 Merge branch 'master' into tmux-3.6 2025-11-25 22:06:41 +00:00
Thomas Adam
7c188aec3c Merge branch 'obsd-master' 2025-11-25 22:01:08 +00:00
Nicholas Marriott
ca74fa1db0 Update version and CHANGES. 2025-11-25 21:21:59 +00:00
Nicholas Marriott
987986631d Merge tag '3.5a'
tmux 3.5a.
2025-11-25 20:42:10 +00:00
nicm
1d89233047 Add a resize callback for menus so that they are correctly moved on
resize. From m-einfalt at gmx dot de in GitHub issue 4696.
2025-11-25 20:27:23 +00:00
Thomas Adam
348f16093c Merge branch 'obsd-master' 2025-11-18 10:01:07 +00:00
nicm
2a3ec87887 Make -v to source-file pass through to subsequent source-file commands,
GitHub issue 4216.
2025-11-18 08:42:09 +00:00
nicm
b52dcff745 Allow show-messages to work without a client. 2025-11-18 08:37:54 +00:00
Thomas Adam
f372112a8d Merge branch 'obsd-master' 2025-11-14 10:01:08 +00:00
nicm
72117debf7 Send matching terminator on queued requests, reported by Henry Qin. 2025-11-14 07:55:23 +00:00
Thomas Adam
2f3c71595b Merge branch 'obsd-master' 2025-11-13 16:01:07 +00:00
nicm
113aaf37fc When copying a line from one screen to another, stop only when both
source and target are beyond the allocated line length. Fixes problems
with trailing spaces on pane-border-format. GitHub issue 4688 from
Dmitry Ryabkov.
2025-11-13 13:08:44 +00:00
Nicholas Marriott
768042d29d Fix build afte merge, from Vladimir Lomov. 2025-11-13 07:18:53 +00:00
Thomas Adam
db274f9c39 Merge branch 'obsd-master' 2025-11-12 21:26:29 +00:00
nicm
66279c124e Make requests to the external terminal one queue instead of one by type,
and include any other requests as well so that ordering is maintained.
2025-11-12 20:41:06 +00:00
Thomas Adam
b335419505 Merge branch 'obsd-master' 2025-11-12 16:01:09 +00:00
nicm
3c9e10139f If display-popup is used inside a popup, modify that popup. From
m-einfalt at gmx dot de in GitHub issue 4678.
2025-11-12 13:47:51 +00:00
Thomas Adam
34898c89cd Merge branch 'obsd-master' 2025-11-12 10:01:08 +00:00
nicm
40600eebfa Do not send theme updates to panes that have exited, GitHub issue 4671. 2025-11-12 08:06:33 +00:00
nicm
12497ecade Convert all keys for backspace, not just A-Z. 2025-11-12 07:54:52 +00:00
nicm
9e21f426c0 Add a command to explcitly set the selection mode in copy mode, GitHub
issue 3842.
2025-11-12 07:53:22 +00:00
Nicholas Marriott
c77d49f67e Save and restore images in alternate screen, GitHub issue 3732. 2025-11-12 07:49:17 +00:00
Thomas Adam
33cfe8b809 Merge branch 'obsd-master' 2025-11-07 14:01:08 +00:00
jsg
0d0ef5d0d2 correct test for COLORTERM containing 256
found with smatch, ok nicm@
2025-11-07 12:43:47 +00:00
Nicholas Marriott
d65bac979d Do not try to allocate zero size colours, GitHub issue 4674. 2025-11-07 12:36:07 +00:00
jsg
c1667bd85e consistently use tabs for indentation
found with smatch, ok nicm@
2025-11-07 12:30:36 +00:00
Thomas Adam
815f7ecffb Merge branch 'obsd-master' 2025-11-03 12:01:06 +00:00
Thomas Adam
44c0443983 Merge branch 'obsd-master' 2025-11-03 09:57:35 +00:00
nicm
3051076dd1 Ignore Hangul filler character. There doesn't seem to be much agreement
on what to do with this but ignoring it seems rightand does improve
things. GitHub issue 3998.
2025-11-03 09:27:06 +00:00
nicm
d90b414223 Handle regional indicators and emoji modifiers in a better way, GitHub
issue 3998.
2025-11-01 16:44:24 +00:00
nicm
8cb2805eb7 Handle ~ correctly when loading a file, GitHub issue 3518. 2025-11-01 16:42:59 +00:00
nicm
e5ab5995db Fix now-incorrect text about {}s. 2025-10-31 09:00:26 +00:00
nicm
e774b89062 Preserve marked pane with swap-window and move-window, GitHub issue 3443. 2025-10-30 13:52:08 +00:00
nicm
29db8ac36e Set and check COLORTERM as a hint for RGB colour. 2025-10-30 11:52:25 +00:00
Thomas Adam
be2d4aa434 Merge branch 'obsd-master' 2025-10-30 10:01:07 +00:00
nicm
1e61e52400 If tmux receives a palette request (OSC 4) in a pane and the palette
entry has not been set, send a request to the most recently used client
and forward any response instead. Based on change from Tim Culverhouse
in GitHub issue 4665.
2025-10-30 07:41:19 +00:00
Thomas Adam
4bdfbfa854 Merge branch 'obsd-master' 2025-10-29 12:01:07 +00:00
nicm
2c08960f4e Add -l flag to command-prompt to disable splitting into multiple prompts,
GitHub issue 4483.
2025-10-29 09:37:36 +00:00
nicm
1a419609e3 Don't enter copy mode on mouse wheel in alternate screen, GitHub issue 3705. 2025-10-29 09:33:20 +00:00
Nicholas Marriott
f812b8d304 Cast to avoid warnings on 32-bit architectures. GitHub issue 4597. 2025-10-29 08:49:16 +00:00
Thomas Adam
ff6eefd7c7 Merge branch 'obsd-master' 2025-10-28 18:01:08 +00:00
nicm
0c5abfefd3 Add commands to centre the cursor in copy mode, from m-einfalt at gmx
dot de in GitHub issue 4662.
2025-10-28 16:36:52 +00:00
Thomas Adam
e560a09db0 Merge branch 'obsd-master' 2025-10-28 15:16:58 +00:00
nicm
9bf8ca5856 Support case insensitive search in modes in the same way as copy mode
(like emacs, so all-lowercase means case insensitive). GitHub issue
4396.
2025-10-28 14:21:06 +00:00
Thomas Adam
410abb5afb Merge branch 'obsd-master' 2025-10-28 14:01:08 +00:00
Thomas Adam
482aa937b1 Merge branch 'obsd-master' 2025-10-28 12:01:07 +00:00
nicm
b4ba6e49af Do not realpath() everything since it is pointless and breaks symlinks.
GitHub issue 4427.
2025-10-28 10:51:30 +00:00
Thomas Adam
010394ab63 Merge branch 'obsd-master' 2025-10-28 10:01:07 +00:00
nicm
7cbb96528c Do not try to reflow if line is NULL. 2025-10-28 09:01:12 +00:00
nicm
aa420cd54a Tweak error messages so that file name isn't modified when we capitalize
the first letter, from Pavel Roskin in GitHub issue 4666.
2025-10-28 07:32:26 +00:00
Thomas Adam
d5302ec327 Merge branch 'obsd-master' 2025-10-27 22:01:08 +00:00
nicm
f31a2d229c Do not play games with lines for view mode output since it stops them
wrapping, GitHub issue 4462.
2025-10-27 20:31:40 +00:00
Thomas Adam
35ad72e56f Merge branch 'obsd-master' 2025-10-20 10:01:07 +01:00
nicm
f501817154 Fix the logic of the no-detached case for detach-on-destroy option - a
previous change made it so that even in the no-detached case, tmux would
always re-attach to a session, even if there weren't any detached ones.
From Martin Louazel in GitHub issue 4649.
2025-10-20 07:28:38 +00:00
Thomas Adam
449f255f3e Merge branch 'obsd-master' 2025-10-13 10:01:08 +01:00
nicm
21d890e6df Add buffer_full format variable, from Mohammad AlSaleh in GitHub issue
4630.
2025-10-13 07:29:53 +00:00
nicm
feb3b90596 Check allow-set-title for APC as well. 2025-10-13 07:19:08 +00:00
Nicholas Marriott
0ff2676a25 Implement getdtablecount(3) for Darwin, from Chip Davis in GitHub issue 4636. 2025-10-06 11:13:53 +01:00
Thomas Adam
3e28777ecb Merge branch 'obsd-master' 2025-09-12 12:01:09 +01:00
nicm
7516f8e94f Check the right flags member, reported by someone in GitHub issue 4634. 2025-09-12 08:46:29 +00:00
Thomas Adam
ac574b6782 Merge branch 'obsd-master' 2025-09-09 12:01:09 +01:00
nicm
50dafd6187 Remove some unnecessary assignments. 2025-09-09 08:49:22 +00:00
Thomas Adam
d4f129b513 Merge branch 'obsd-master' 2025-09-08 14:01:08 +01:00
Nicholas Marriott
9a72317c4f Check for vlock earlier to neaten output. 2025-09-08 12:27:26 +01:00
nicm
b21b1ee9af Don't try to change directory if it is NULL. 2025-09-08 11:21:56 +00:00
nicm
c62fe6dac8 The client can be NULL, fixes -v in config file. 2025-09-08 11:21:29 +00:00
Thomas Adam
9dc136f445 Merge branch 'obsd-master' 2025-09-08 12:01:10 +01:00
Thomas Adam
418bf148e0 Merge branch 'obsd-master' 2025-09-08 10:01:08 +01:00
jsg
408721ae37 correct indentation, no functional change
found with smatch, ok nicm@
2025-09-08 08:23:19 +00:00
Nicholas Marriott
b1b6850fa9 Add test for control mode, from Sergei Nizovtsev. 2025-09-08 08:31:23 +01:00
nicm
d73196750f Change so that source-file errors are reported correctly in control
mode, from Sergei Nizovtsev in GitHub issue 4626.
2025-09-08 07:30:15 +00:00
Thomas Adam
093754db3f Merge branch 'obsd-master' 2025-09-07 18:01:08 +01:00
nicm
7cc15969ff Quote cwd for glob in a way that actually works, from Pavel Roskin in
GitHub issue 4623.
2025-09-07 14:17:25 +00:00
nicm
b53cf70262 Introduce a new window option: tiled-layout-max-columns. It configures
the maximum number of columns in the tiled layout. The default value is
0 which means no limit and makes the change backward-compatible. From
vkadlcik at redhat dot com.
2025-09-07 14:03:18 +00:00
Nicholas Marriott
1dadd6c9ae Do not force SIXEL images to a multiple of 6 lines. From nincsnevem662 at gmail
dot com in GitHub issue 4622.
2025-09-07 14:55:18 +01:00
Nicholas Marriott
a7a94cb86f Fix OOB access in sixel_print by ensuring that the number of chunks actually
matches the highest color used on the image, even if not defined as a color
register. From nincsnevem662 at gmail dot com in GitHub issue 4621.
2025-09-07 14:53:08 +01:00
Thomas Adam
3d6954f0f0 Merge branch 'obsd-master' 2025-09-05 10:01:08 +01:00
nicm
267efefdfa Restore default blinking state when restoring default cursor style, from
Andrea Alberti.
2025-09-05 06:15:48 +00:00
Thomas Adam
6a3170386e Merge branch 'obsd-master' 2025-09-02 18:36:44 +01:00
nicm
4d83eef756 Add support for DECRQSS SP q (report cursor style), DECRQM ?12 (report
cursor blink state) and DECRQM ?2004, ?1004, ?1006 (report mouse state).

From Andrea Alberti in GitHub issue 4618.
2025-09-02 15:15:12 +00:00
Thomas Adam
44b7a2d1f9 Merge branch 'obsd-master' 2025-09-02 16:01:08 +01:00
nicm
c32570c602 Set PWD for jobs as well as panes. 2025-09-02 13:39:14 +00:00
Thomas Adam
9702ef3f91 Merge branch 'obsd-master' 2025-09-02 02:01:07 +01:00
Thomas Adam
b2194ac549 Merge branch 'obsd-master' 2025-09-02 00:01:08 +01:00
nicm
b5413dacc7 Delete timer before adding it again. 2025-09-01 22:11:23 +00:00
nicm
aa33757e45 Fix missing argument from OSC 4 reply, from someone in GitHub issue 4596. 2025-09-01 21:44:37 +00:00
Thomas Adam
a0065bea04 Merge branch 'obsd-master' 2025-09-01 12:01:08 +01:00
nicm
5c89d835a6 Add -k flag to display-popup which allows any key to dismiss the popup
once the command has exited. From Meriel Luna Mittelbach in GitHub issue
4612.
2025-09-01 08:03:07 +00:00
nicm
cfb906a0ce Increase the escape delay when waiting for an RGB response no matter
when it is triggered (they can also be sent on resize). GitHub issue
4569.
2025-09-01 07:58:09 +00:00
nicm
af36d7c430 Ensure break-pane -P prints when only one pane is left. From Chaoyi Yin
in GitHub issue 4615.
2025-09-01 07:53:49 +00:00
Nicholas Marriott
0c9165fc71 Give another bit to the first component of SIXEL colours to fix the HLS color
space which uses 360 degrees in its first component. From nincsnevem662 at
gmail dot com in GitHub issue 4616.
2025-09-01 08:31:57 +01:00
Thomas Adam
fa63088dce Merge branch 'obsd-master' 2025-08-26 10:01:07 +01:00
nicm
0b7235c5f0 Correctly calculate lines to clear for deletions, from Pavel Roskin. 2025-08-26 07:17:51 +00:00
nicm
ca0f0419e6 input_stop_utf8 can move the cursor, so it is now wrong to store the
cursor position before calling it. Problem found by Jayakrishna
Vadayath.
2025-08-26 07:15:00 +00:00
nicm
3520e833a4 Be more robust against misbehaving clients, prompted by deraadt based on
a report from sai02 at student dot ubc dot ca.
2025-08-26 07:00:22 +00:00
Nicholas Marriott
bb4866047a Fix build. 2025-08-22 12:58:19 +01:00
Thomas Adam
2070731af1 Merge branch 'obsd-master' 2025-08-22 12:01:08 +01:00
Thomas Adam
a5909b450c Merge branch 'obsd-master' 2025-08-22 10:01:08 +01:00
nicm
94bafa5aaf A couple of memory leaks from someone in GitHub issue 4590. 2025-08-22 07:48:23 +00:00
nicm
7325da3052 Extend pane lookup special case for switch-client to mouse target ("=")
so that it works for panes on status line.
2025-08-22 07:42:51 +00:00
nicm
e6d275b371 Do not leak label if it is too long, GitHub issue 4591. 2025-08-22 07:39:40 +00:00
Thomas Adam
f4c0fe2ede Merge branch 'obsd-master' 2025-08-22 08:37:26 +01:00
nicm
12452f4427 Do not double free argv from MSG_COMMAND if it is too long, reported by
sai02 at student dot ubc dot ca via deraadt. ok deraadt
2025-08-22 07:26:25 +00:00
nicm
1370791734 Add a nicer default second and third status line, from Michael Grant in
GitHub 4490.
2025-08-14 07:15:40 +00:00
nicm
0646814235 Add some NULL checks, GitHub issue 4586. 2025-08-14 06:49:53 +00:00
nicm
84775130a0 Add pane-border-lines value to use spaces for pane borders, from lukas
dot 23022005 at gmail dot com in GitHub issue 4587.
2025-08-14 06:44:50 +00:00
nicm
4ce893ebc0 Do not leak opened file, from lg65438805 at gmail dot com in GitHub
issue 4577.
2025-08-14 06:37:29 +00:00
nicm
3ae0d560be Replace invalid UTF-8 with the placeholder instead of ignoring them
(this is what most terminals do), GitHub issue 4514.
2025-08-12 12:33:05 +00:00
nicm
06c84dba59 Fix PageDown in menus, from Pavel Roskin in GitHub issue 4581. 2025-08-12 12:29:58 +00:00
nicm
d90e7623c6 Free command on failure, GitHub issue 4578. 2025-08-12 12:26:09 +00:00
Thomas Adam
b13005e802 Merge branch 'obsd-master' 2025-08-04 16:01:07 +01:00
nicm
05b2893b9f Do not leak buffer if not used, reported by someone in GitHub issue
4575.
2025-08-04 13:22:10 +00:00
nicm
1bf2023ed4 Flush scrolling when wrapping so UTF-8 in last position draws correctly,
GitHub issue 4518.
2025-08-04 13:16:13 +00:00
Thomas Adam
6f9bcb7fee Merge branch 'obsd-master' 2025-08-01 12:01:08 +01:00
nicm
6d94909c08 Do not leak on failure, GitHub 4565. 2025-08-01 09:05:51 +00:00
Nicholas Marriott
86153fbba9 Add UTF-8 regress test. 2025-08-01 09:45:18 +01:00
nicm
4f38af01e0 Fix reverse documentation of display-popup -s and -S, from Ricardo Signes. 2025-08-01 08:17:27 +00:00
Thomas Adam
a6588d6918 Merge branch 'obsd-master' 2025-07-22 10:01:08 +01:00
Nicholas Marriott
720d1e831d The AIX functions hang on 7300-01-01-2246 according to GitHub issue 4400.
Remove them.
2025-07-22 09:09:56 +01:00
nicm
206f492401 Fix incorrect handling of Korean Hangul Jamo characters. GitHub issue
4546 from Roy Jung.
2025-07-22 07:42:52 +00:00
Nicholas Marriott
fa5f3cef3d Send SIGCHLD after utempter_remove_record as well. GitHub issue 4559. 2025-07-20 19:59:11 +01:00
Thomas Adam
c70d0a6a69 Merge branch 'obsd-master' 2025-07-19 22:01:08 +01:00
nicm
6549aaf393 yyerror should be void. 2025-07-19 19:30:37 +00:00
nicm
6378c87d15 Only accept DA and DA2 when they end in 'c', stops them being confused
with theme responses.. GitHub issue 4561.
2025-07-19 19:20:10 +00:00
Thomas Adam
4a0eff1296 Merge branch 'obsd-master' 2025-07-19 00:01:08 +01:00
nicm
9c07903ae9 Correctly remove overwritten wide characters at column 1. 2025-07-18 20:44:13 +00:00
Thomas Adam
32b7b3a6f7 Merge branch 'obsd-master' 2025-07-17 14:01:08 +01:00
nicm
041bbf8bdf Allow uppercase letters in gray/grey color names, GitHub issue 4560 from
Pavel Roskin.
2025-07-17 11:39:23 +00:00
Nicholas Marriott
701f6b4b2f Update use-this-issue-template.md 2025-07-17 10:59:53 +01:00
Nicholas Marriott
bddd019a04 Update use-this-issue-template.md 2025-07-17 10:58:28 +01:00
Thomas Adam
865117a05f Merge branch 'obsd-master' 2025-07-13 10:01:08 +01:00
nicm
e6bac234db Increase delay for foreground and background queries as well as device
attributes, GitHub issue 4541.
2025-07-13 06:32:34 +00:00
Nicholas Marriott
9f1fac9142 Use MAC_OS_X_VERSION_MIN_REQUIRED. From Sevan Janiyan, GitHub issue 4550. 2025-07-13 07:26:35 +01:00
nicm
9831175a2d Use window index not ID for sorting, reported by naru at naruaway dot
com in GitHub issue 4551.
2025-07-13 06:16:28 +00:00
Thomas Adam
7e43953937 Merge branch 'obsd-master' 2025-07-02 12:01:08 +01:00
nicm
28481e984b Add sorting to W, P, L operators as well, and add some new session
format variables. From Michael Grant in GitHub issue 4516.
2025-07-02 08:13:09 +00:00
Thomas Adam
30e4f119d3 Merge branch 'obsd-master' 2025-07-01 12:01:08 +01:00
jsg
01da87c112 new sentence, new line 2025-07-01 08:54:50 +00:00
Nicholas Marriott
e7f15d09be Missed a header. 2025-06-24 15:04:24 +01:00
Nicholas Marriott
cbb3c4bfed Update imsg from OpenBSD. 2025-06-24 15:02:16 +01:00
Thomas Adam
d24993aeab Merge branch 'obsd-master' 2025-06-24 14:01:08 +01:00
nicm
d858ad1179 Detect support for OSC 52 using the device attributes report. Some
terminals are using this to indicate that they support copying to the
clipboard with XTerm's OSC 52 sequence. From James Holderness in GitHub
issue 4539.
2025-06-24 10:57:35 +00:00
Thomas Adam
96244dd727 Merge branch 'obsd-master' 2025-06-20 18:01:08 +01:00
Thomas Adam
b38b5d3df2 Merge branch 'obsd-master' 2025-06-20 16:01:08 +01:00
nicm
ad3e6ff054 Add noattr and use in mode-style to allow whether attributes are ignored
or used to be configured. GitHub issue 4498.
2025-06-20 14:54:33 +00:00
nicm
522652913f Add S: to list sessions with modifiers for sorting, from Michael Grant. 2025-06-20 13:31:59 +00:00
Thomas Adam
43e88c892d Merge branch 'obsd-master' 2025-06-16 02:01:07 +01:00
nicm
d82d9468b4 Expand mode-style with E: so # is correctly processed, GitHub issue
4533.
2025-06-15 22:24:51 +00:00
nicm
d7f75ac985 Do not replace SHELL when using /bin/sh. From someone in GitHub issue 4528. 2025-06-15 21:57:58 +00:00
Thomas Adam
1dbceaa790 Merge branch 'obsd-master' 2025-05-28 14:01:08 +01:00
nicm
77ca59acac Add missing theme hooks, from Eric NICOLAS in GitHub issue 4519. 2025-05-28 09:53:57 +00:00
Thomas Adam
7be0613657 Merge branch 'obsd-master' 2025-05-22 12:01:07 +01:00
Thomas Adam
b9ad9186fe Merge branch 'obsd-master' 2025-05-22 10:01:08 +01:00
nicm
3f4b154b70 Bump UTF8_SIZE to the maximum 32 because there are some crazy long UTF-8
sequences out there (GitHub issue 4506). This should not significantly
increase typical memory consumption because we only store each Unicode
character once in the shared cache.
2025-05-22 08:01:29 +00:00
Nicholas Marriott
ff73c95547 New bash completion URL, from David Mandelberg. 2025-05-22 08:52:10 +01:00
Nicholas Marriott
aa0d05f676 Typos, from someone in GitHub issue 4511. 2025-05-22 08:51:14 +01:00
nicm
545832e9fa Typo, from someone in GitHub issue 4511. 2025-05-22 07:49:24 +00:00
nicm
a0ac2a5d63 When there are more than two horizontal windows and the active window is
in not on an edge, correctly highlight both its left and right borders.
GitHub issue 4513 from Michael Grant.
2025-05-22 07:46:38 +00:00
nicm
833c7fbf6d Add a set-default style attribute which replaces the current default
colours and attributes completely, useful at the start of compound
format strings (like status-format) to set the default colours for all
the following options.
2025-05-22 07:43:38 +00:00
Thomas Adam
faf2a44890 Merge branch 'obsd-master' 2025-05-12 14:01:10 +01:00
Thomas Adam
d194ceb604 Merge branch 'obsd-master' 2025-05-12 12:01:10 +01:00
nicm
37a2c98d3d Expand prompts when they are used rather than ahead of time, so the
input can be used as part of the format.
2025-05-12 10:34:13 +00:00
nicm
79b02998a6 Add R format modifier to repeat an argument. 2025-05-12 10:26:19 +00:00
nicm
1ce1e7ef27 Add -E to run-shell to forward stderr as well as stdout, from github at
jyn dot dev in GitHub issue 4246.
2025-05-12 10:16:42 +00:00
nicm
7499d925da Do not downgrade styled underscores to standard underscore if the
terminal does not support them, this matches what would happen if the
application tried to use them on a terminal without support.
2025-05-12 09:50:00 +00:00
nicm
367f17a4ff Preserve colours in selection if the option style is default, GitHub
issue 4498.
2025-05-12 09:17:42 +00:00
Thomas Adam
3d2b26dcfe Merge branch 'obsd-master' 2025-05-01 10:01:11 +01:00
nicm
6106a0f2c4 Add an option variation-selector-always-wide to instruct tmux not to
always interpret VS16 as a wide character and assume the terminal does
likewise. This is behaviour seen in a number of newer terminals' Unicode
14 support but not in older terminals; it seems to be a little
contentious and is currently difficult to detect.

Probably in the long run tmux should pick a behaviour, look at a (new)
terminfo(5) capability to tell it what the terminal will do, and emulate
as required, but at this point I'm not sure that is worth it for
something where support is mixed, seems to be in flux, and that mostly
only matters for emojis.

GitHub issues 3923 and 4475 and others before that.
2025-05-01 07:12:00 +00:00
nicm
1926c1b683 Don't map 256 to white-on-white either, and tidy code a bit. 2025-05-01 06:59:32 +00:00
Nicholas Marriott
6cc1a607fc optarg should be "extern char *" not "extern const char *". 2025-05-01 07:53:02 +01:00
Nicholas Marriott
1905afb3d8 tmux has its own warnx so there is no need for logit (and this gets rid of a
warning).
2025-04-29 17:39:56 +01:00
Nicholas Marriott
345a45083d Run the regress/style-trim.sh test in a plain Bash session, from Koichi Murase. 2025-04-29 17:29:32 +01:00
Nicholas Marriott
3a3babf597 Use printf not echo, from Koichi Murase. 2025-04-28 14:51:27 +01:00
Nicholas Marriott
f367e3a6c8 Switch to getopt_long from OpenSSH, from Koichi Murase in GitHub issue 4492. 2025-04-28 09:02:15 +01:00
Nicholas Marriott
f2283b0cb5 Fix some regress tests. 2025-04-28 08:57:29 +01:00
Nicholas Marriott
26081ac125 Create config.yml 2025-04-28 07:27:57 +01:00
Thomas Adam
36fba4cc54 Merge branch 'obsd-master' 2025-04-25 16:01:08 +01:00
Thomas Adam
58b4286edb Merge branch 'obsd-master' 2025-04-25 14:01:10 +01:00
nicm
b0b6a6f665 Revert change to handle command parsing failures in the client because
it breaks aliases.
2025-04-25 12:25:32 +00:00
nicm
63e5989f53 Remove a stray period, reported by David Mandelberg. 2025-04-25 11:39:39 +00:00
Nicholas Marriott
9da5707d3e Add a run-shell output test. 2025-04-25 12:06:51 +01:00
Thomas Adam
55292b72d1 Merge branch 'obsd-master' 2025-04-25 12:01:09 +01:00
Nicholas Marriott
06b1ad6241 Tests for boolean expressions from David Mandelberg. 2025-04-25 09:28:57 +01:00
nicm
1efe41b9b9 Add more features for boolean expressions in formats: 1) extend && and
|| to support arbitrarily many arguments and 2) add ! and !! for not and
not-not.
2025-04-25 08:28:21 +00:00
Nicholas Marriott
1198eed632 Currently the DCS dispatcher detects Sixel sequences based entirely on the
final character of the sequence, ignoring any intermediates. This means that
other DCS sequences with a q final (like DECRQSS), can be mistakenly
interpreted as Sixel. Add a check to make sure there are no intermediates
before dispatching potential Sixel sequences. From James Holderness in GitHub
issue 4488.
2025-04-25 08:26:26 +01:00
Thomas Adam
0772fe822a Merge branch 'obsd-master' 2025-04-24 12:01:10 +01:00
nicm
f53fac1b56 Do not add a trailing / if there is nothing to follow it, Johannes
Altmanninger in GitHub issue 4472.
2025-04-24 08:55:40 +00:00
nicm
68f2ac9296 Fix examples with too many backslashes, pointed out by David Mandelberg. 2025-04-24 08:54:40 +00:00
Thomas Adam
b4f8340f16 Merge branch 'obsd-master' 2025-04-22 16:01:12 +01:00
nicm
d2f73c17d5 Add calls to layout_fix_panes after a pane swap to fix case if one of
the panes is in alternate screen mode and had a scrollbar. From Michael
Grant in GitHub issue 4481.
2025-04-22 12:36:03 +00:00
nicm
5db914b745 Add notes to menu keys, from someone in GitHub issue 4478. 2025-04-22 12:34:56 +00:00
nicm
cd3d2910ee Fix description of pane_in_mode, from Julian Prein in GitHub issue 4469. 2025-04-22 12:33:35 +00:00
Nicholas Marriott
de7653f5a4 Update format tests for #? changes, from David Mandelberg. 2025-04-22 13:23:33 +01:00
nicm
b905039ed2 Improve #? conditional expression in formats:
1) add support for else if, so
   #{?cond1,value1,#{?cond2,value2,else-value}} can be changed to
   #{?cond1,value1,cond2,value2,else-value};

2) add default empty string if there's no else value, so
   #{?cond1,value1,} can be changed to #{?cond1,value1}.

From David Mandelberg in GitHub issue 4451.
2025-04-22 12:23:26 +00:00
Nicholas Marriott
f0a85d0469 Move cgroup dbus requests to the child to avoid a race where a spawned child
that quickly forks will have only the parent process moved to the newly created
cgroup. From Daniel De Graaf, GitHub issue 4435.
2025-04-14 07:27:02 +01:00
Thomas Adam
ac2779f4d8 Merge branch 'obsd-master' 2025-04-09 10:01:12 +01:00
nicm
68ffe65499 Fix documentation around optional arguments. This includes:
- Syncing between the usage string in code and in the man page.
- Adding optional arguments that were not mentioned (such as
  shell-command arguments).
- Adding square brackets around arguments that are actually optional.

From Julian Prein (julian at druck dot dev) in GitHub issue 4419.
2025-04-09 07:03:04 +00:00
nicm
3e14e7c48b Formats can use environment variables, from David Mandelberg. 2025-04-09 06:51:31 +00:00
nicm
b526e678b5 Make some usages more consistent and add -h to show usage, GitHub issue
4455 from David Mandelberg.
2025-04-09 06:27:43 +00:00
Thomas Adam
d3c39375d5 Merge branch 'obsd-master' 2025-04-03 14:01:10 +01:00
nicm
a7991dcbad Fix padding for word function as well, GitHub issue 4425. 2025-04-03 11:52:25 +00:00
nicm
47dff97834 Use backing grid for word in copy mode for wrapped flags, from someone
in GitHub issue 4447.
2025-04-03 11:51:27 +00:00
Thomas Adam
2905395695 Merge branch 'obsd-master' 2025-04-02 12:01:13 +01:00
nicm
4bf38da4d4 Only align panes and windows, not sessions, from David Mandelberg in
GitHub issue 4444.
2025-04-02 09:31:00 +00:00
nicm
9b37b9285e Popup window should not be draggable while mouse still pressed, and do
not try to work out theme if no pane. From Michael Grant in GitHub issue
4330.
2025-04-02 09:12:05 +00:00
Thomas Adam
dfdced2ab1 Merge branch 'obsd-master' 2025-03-31 00:01:10 +01:00
Nicholas Marriott
c2a95a372f Add a note about closed issues, from David Mandelberg. 2025-03-30 23:04:22 +01:00
nicm
ef923d28ff Do not try to trigger theme changed if session is NULL. 2025-03-30 22:01:55 +00:00
nicm
53b0e0bc02 Missing space, from David Mandelberg. 2025-03-30 21:47:01 +00:00
Thomas Adam
096c4b3e63 Merge branch 'obsd-master' 2025-03-28 20:01:10 +00:00
Thomas Adam
b8189d6ee3 Merge branch 'obsd-master' 2025-03-28 18:01:11 +00:00
nicm
f41dc91357 Only copy the key string not two bytes extra, found by David Mandelberg. 2025-03-28 17:15:25 +00:00
nicm
ef0c12ad9e Fix read of uninitialized memory for jobs with JOB_PTY flag. From David
Mandelberg.
2025-03-28 17:03:49 +00:00
Thomas Adam
9e1f110db0 Merge branch 'obsd-master' 2025-03-24 22:01:11 +00:00
nicm
483b2b3edb Correctly skip wide characters in hyperlinks, from someone in GitHub
issue 4425.
2025-03-24 20:17:24 +00:00
nicm
34a35b0f09 Expand formats with the pane modifier in tree mode so that #() doesn't
always use the same value. From Michael Grant in GitHub issues 4412 and
4420.
2025-03-24 20:13:03 +00:00
nicm
aca3ffb30a Add default-client-command to set the command used is tmux is run
without a command (the default stays new-session). From David Mandelberg
in GitHub issue 4422.
2025-03-24 20:01:03 +00:00
Thomas Adam
c3c4524def Merge branch 'obsd-master' 2025-03-21 16:01:11 +00:00
nicm
f101762d1b Fix mouse_hyperlink format in copy mode. From someone in GitHub issue
4418.
2025-03-21 14:04:26 +00:00
nicm
a541be3951 Add S-Up and S-Down to move windows in tree mode. From David Mandelberg
in GitHub issue 4415.
2025-03-21 13:36:42 +00:00
nicm
b7d640e764 Add some additional cursor format variables. From shiro at usagi dot io
in GitHub issue 4414.
2025-03-21 13:26:39 +00:00
Thomas Adam
969f6a60c3 portable: SYNCING: correct tmux-openbsd
The tmux-openbsd repository is called tmux-obsd.

Noticed via Github issue #4419
2025-03-21 12:46:06 +00:00
Thomas Adam
6703cb85d9 Merge branch 'obsd-master' 2025-03-21 04:01:10 +00:00
jsg
111e16e772 remove prototypes for removed functions 2025-03-21 02:10:42 +00:00
Thomas Adam
3eb93383a3 Merge branch 'obsd-master' 2025-03-17 22:01:10 +00:00
nicm
817b621d20 If there is an active query, set escape time temporarily to a higher
value (the old default - 500). Some Windows terminals are very slow to
respond, or the network may be slow. From github at jyn dot dev.
2025-03-17 20:43:29 +00:00
nicm
5eb30c1543 Handle padding cells correctly for regular expression searching, GitHub issue 4399 from
github at jyn dot dev.
2025-03-17 20:33:20 +00:00
Thomas Adam
d4b8635f50 Merge branch 'obsd-master' 2025-03-11 10:01:12 +00:00
nicm
4e4fe3eb39 Cleanup window_get_active_at function. GitHub issue 4401 from Michael
Grant.
2025-03-11 08:14:26 +00:00
Thomas Adam
882fb4d295 Merge branch 'obsd-master' 2025-03-04 10:01:15 +00:00
nicm
eaf70c955b Add mode 2031 support to automatically report dark or light theme. tmux
will guess the theme from the background colour on terminals which do
not themselves support the escape sequence. Written by Jonathan
Slenders, GitHub issue 4353.
2025-03-04 08:45:04 +00:00
nicm
3543d79048 Free fill character string if it cannot be used, GitHub issue 4394. 2025-03-04 08:03:19 +00:00
Thomas Adam
94783addfc Merge branch 'obsd-master' 2025-02-26 10:01:14 +00:00
nicm
91c0de60b4 Also need the implied meta paste keys in the list for output. 2025-02-26 09:02:00 +00:00
nicm
21f7db4c4d Do not allow meta prefix on paste start and end sequences, GitHub issue 4387. 2025-02-26 08:55:27 +00:00
nicm
f224d61f37 Document the use of ';' as a modifier separator, from Matt Liggett in
GitHub issue 4384.
2025-02-26 07:50:36 +00:00
nicm
d938ab5dd7 If command parsing fails in the client, report the error rather than
trying to send the command to the server. GitHub issue 4372 from Nikola
Tadic.
2025-02-26 07:47:46 +00:00
nicm
9a8f46e554 Fix colouring of pane border when scrollbars are enabled, GitHub issue
4378 from Michael Grant.
2025-02-26 07:42:52 +00:00
nicm
27ee0c9c3b Add the width of the scrollbars to the calculation of the width of the
window panes when finding the adjacent panes, GitHub issue 4370 from
Michael Grant.
2025-02-26 07:39:50 +00:00
Thomas Adam
251a87e2d2 Merge branch 'obsd-master' 2025-02-20 16:01:14 +00:00
nicm
084e6ee9ec Add a -M flag to capture-pane to use the copy mode screen, GitHub issue
4358.
2025-02-20 13:39:58 +00:00
nicm
18331e39bf Reset overlay_resize pointer when clearing overlay. 2025-02-20 13:32:07 +00:00
Nicholas Marriott
250c88efdc Add .swp, from Nikola Tadic. 2025-02-20 13:31:07 +00:00
Thomas Adam
9a377485be Merge branch 'obsd-master' 2025-02-13 18:01:08 +00:00
nicm
47a56c11f2 Add a note about C-r and C-s behaviour, GitHub issue 4309.
Also add a missing word, from jmc@.
2025-02-13 16:31:25 +00:00
Nicholas Marriott
c4b9716873 Look for imsg_add not _init now. 2025-02-13 16:24:33 +00:00
Thomas Adam
ec119b2f9e Merge branch 'obsd-master' 2025-02-10 10:01:11 +00:00
nicm
5d1a6acc84 Align index numbers in trees, from David Mandelberg, GitHub issue 4360. 2025-02-10 08:18:23 +00:00
nicm
80eb460fc9 Add display-message -C flag to update pane while message is displayed,
GitHub issue 4363 from Vitaly Ostrosablin.
2025-02-10 08:14:32 +00:00
Thomas Adam
ef68debc8d Merge branch 'obsd-master' 2025-01-27 12:01:13 +00:00
nicm
4c12ac9fb8 Make list-commands command show only one command if an argument is
given, from Ilya Grigoriev in GitHub issue 4352.
2025-01-27 09:16:05 +00:00
nicm
244bb726e2 Add some missing spaces, from Ilya Grigoriev. 2025-01-27 09:05:22 +00:00
Nicholas Marriott
6ab268c7bb Remove old issue template. 2025-01-20 13:06:03 +00:00
Nicholas Marriott
0c9f8ff189 Update issue templates 2025-01-20 13:02:24 +00:00
Nicholas Marriott
dd7d04be95 Update issue templates 2025-01-20 13:00:07 +00:00
Thomas Adam
58392d29da Merge branch 'obsd-master' 2025-01-17 18:01:08 +00:00
nicm
9260f5dc96 Do not update focus on client's without a session. 2025-01-17 15:53:01 +00:00
Thomas Adam
62a6c16b43 Merge branch 'obsd-master' 2025-01-13 12:01:11 +00:00
nicm
31e8d4676a Count line numbers correctly inside strings, reported by Pedro Navarro
in GitHub issue 4325.
2025-01-13 08:58:34 +00:00
Thomas Adam
d3cbe00f78 Merge branch 'obsd-master' 2025-01-12 16:01:11 +00:00
nicm
97fe3563fa Do not crash if moving popup that has exited to a pane, from Michael
Grant in GitHub issue 4312.
2025-01-12 14:36:28 +00:00
nicm
37ad1e2f6d Map bright black (colour 8) to white (7) if the background is black on
terminals with only eight colours so the text is not invisible. From
Dmytro Bagrii in GitHub issue 4322.
2025-01-12 14:20:49 +00:00
Thomas Adam
00894d188d Merge branch 'obsd-master' 2025-01-02 12:01:10 +00:00
nicm
2a5eba7899 Check backspace against VERASE earlier before it is translated to an
internal key and do not go through the mapping on output. Fixes problems
reported by Ben Price in GitHub issue 4284 and by tb@.
2025-01-02 10:34:45 +00:00
Thomas Adam
bf30492d57 Merge branch 'obsd-master' 2025-01-01 18:01:10 +00:00
nicm
e00853ee82 Add an option allowing users to override the width of individual Unicode
codepoints (overriding tmux's default list).
2025-01-01 15:17:36 +00:00
Thomas Adam
e75f3a0060 Merge branch 'obsd-master' 2024-12-20 10:01:10 +00:00
nicm
eece41547e Only map S-Tag in mode 2, not mode 1. GitHub issue 4304. 2024-12-20 07:10:51 +00:00
Thomas Adam
c311202b73 Merge branch 'obsd-master' 2024-12-17 10:01:11 +00:00
nicm
e149d29803 Assign excess space more evenly when spreading out cells, from Torbjorn
Lonnemark.
2024-12-17 08:40:24 +00:00
Thomas Adam
190ddda572 Merge branch 'obsd-master' 2024-12-16 12:01:12 +00:00
Thomas Adam
6b470c5222 Merge branch 'obsd-master' 2024-12-16 10:01:11 +00:00
nicm
6b32d195e8 Add a nesting limit to source-file, from Fadi Afani in GitHub issue
4223.
2024-12-16 09:13:09 +00:00
nicm
bec6ce54c1 Memory leak, GitHub issue 4298. 2024-12-16 08:54:34 +00:00
nicm
106d1c3538 Missing main-vertical-mirrored from layout list, from charlotte at
lottia dot net.
2024-12-16 08:51:41 +00:00
Thomas Adam
ae8f2208c9 Merge branch 'obsd-master' 2024-12-06 12:01:11 +00:00
nicm
5c3cf2f08b Preserve modifiers on backspace. 2024-12-06 09:07:40 +00:00
nicm
102f34090d Do not write bracketed paste keys themselves if the pane has not asked
for them.
2024-12-06 09:06:56 +00:00
Thomas Adam
99790c90aa Merge branch 'obsd-master' 2024-12-04 22:01:08 +00:00
nicm
6d792e4123 Fix backspace option for new key format, GitHub issue 4284. 2024-12-04 19:11:15 +00:00
Thomas Adam
98e322d5a5 Merge branch 'obsd-master' 2024-12-03 14:01:12 +00:00
jmc
01edce40f3 M-1 to M-7 for 7 preset layouts; from bunkmate
ok nicm
2024-12-03 11:18:34 +00:00
Thomas Adam
0549f87ccc Merge branch 'obsd-master' 2024-11-28 10:01:11 +00:00
nicm
72cd0eac29 Add extended keys flag for foot terminal. 2024-11-28 08:49:14 +00:00
Thomas Adam
f0c68533c4 Merge branch 'obsd-master' 2024-11-27 12:01:08 +00:00
Nicholas Marriott
9e4a9c51cc Use evbuffer_readline if readln is not available. It doesn't work properly but
at least it builds.
2024-11-27 10:37:45 +00:00
Nicholas Marriott
6874ec0dcc Remove endian.h. 2024-11-27 10:31:51 +00:00
Nicholas Marriott
252f41818e Update imsg and remove workaround. 2024-11-27 10:30:52 +00:00
nicm
d361f21065 Do not check for latest client in callback since the type may be latest
but with no window, fixes new-session -x and -y with another attached
client. GitHub issue 4268.
2024-11-27 10:12:20 +00:00
nicm
feb090abb3 Do not stop drag on double or triple click, GitHub issue 4272. 2024-11-27 10:10:20 +00:00
Thomas Adam
db771ec6e3 Merge branch 'obsd-master' 2024-11-26 18:01:10 +00:00
nicm
6f7db82b18 Add copy-mode-position-style and copy-mode-selection-style for copy
mode (they default to mode-style as before).
2024-11-26 15:52:41 +00:00
nicm
67cc7f6dc6 Enter is now sent from single prompt as \r not empty string. 2024-11-26 15:51:48 +00:00
Thomas Adam
db978db271 Merge branch 'obsd-master' 2024-11-25 14:01:12 +00:00
nicm
363f35f076 Do not try to terminate an empty buffer. 2024-11-25 12:32:24 +00:00
Thomas Adam
49b7276f2a Merge branch 'obsd-master' 2024-11-25 10:01:11 +00:00
nicm
f57131e11b Use cursor style from global options instead of default for popups, from
Alexander Arch.
2024-11-25 08:36:46 +00:00
nicm
420af9e108 Do not rely on window reference count for linked formats because they
are also used for notifications, GitHub issue 4258.
2024-11-25 08:34:01 +00:00
Thomas Adam
ceaf9b7452 Merge branch 'obsd-master' 2024-11-22 14:01:11 +00:00
nicm
5fd45b3892 Do not strvis output to terminal from commands. 2024-11-22 12:58:05 +00:00
nicm
64d82d5988 Document command prompt escape sequence, from Von Welch. 2024-11-22 12:36:13 +00:00
Nicholas Marriott
0f308bd18f imsg no longer associates file descriptors with the imsg they were sent with,
work around this for the moment (it is not clear if this is intentional).
2024-11-22 09:58:47 +00:00
Nicholas Marriott
1365f1ce52 Add an __unused. 2024-11-22 08:07:21 +00:00
Nicholas Marriott
7fc4e54efe And arpa/inet.h needs to stay... 2024-11-22 08:06:30 +00:00
Nicholas Marriott
c98c08c232 Need to remove endian.h as well. 2024-11-22 08:05:02 +00:00
Nicholas Marriott
990c724bd8 Bring in updated imsg. 2024-11-22 08:03:55 +00:00
Thomas Adam
b82c7b40b0 Merge branch 'obsd-master' 2024-11-21 16:01:11 +00:00
claudio
70299c6646 Convert sbin and usr.bin to check for imsgbuf_init failure and add
imsgbuf_allow_fdpass where needed.

OK tb@
2024-11-21 13:35:20 +00:00
Thomas Adam
ea6c5053c8 Merge branch 'obsd-master' 2024-11-21 10:01:09 +00:00
nicm
3f4fd45d5c Fix save-buffer documentation - it writes to stdout. From Ilya Grigoriev. 2024-11-21 07:37:21 +00:00
nicm
7c7e88253e When the mouse clicked on the border between two horizontal panes, the
location was not being set properly. Pulled the checking of this into
separate function for clarity. Fixes dragging on horizontal pane border.
From Michael Grant.
2024-11-21 07:34:38 +00:00
Thomas Adam
bb94a5437d Merge branch 'obsd-master' 2024-11-21 00:01:13 +00:00
nicm
273f9b2027 Fix word navigation on lines with tabs, from Alexander Arch. 2024-11-20 20:54:02 +00:00
Nicholas Marriott
b6d0b4be30 Define SD_ID128_UUID_FORMAT_STR if missing, from Marc Reisner. 2024-11-19 17:55:12 +00:00
Thomas Adam
2dce45f427 Merge branch 'obsd-master' 2024-11-18 10:01:12 +00:00
nicm
a3ede3106a Check all %if in the list when deciding whether to process an
assignment, not just the most recent.
2024-11-18 08:29:35 +00:00
Thomas Adam
dd9722184b Merge branch 'obsd-master' 2024-11-16 18:01:08 +00:00
nicm
a854e36f2b Do not call layout_fix_panes if wp is NULL (that is, a popup). 2024-11-16 16:49:50 +00:00
Thomas Adam
be594ff8a4 Merge branch 'obsd-master' 2024-11-15 16:01:11 +00:00
nicm
c66628e52b Add no-detach-on-destroy client option (useful for control mode
clients). From laur dot aliste at gmail dot com, GitHub issue 4242.
2024-11-15 14:09:04 +00:00
nicm
350a151ee4 Add two new style parameters, width and pad, which apply to scrollbars.
From Michael Grant, GitHub issue 4241.
2024-11-15 13:12:20 +00:00
Thomas Adam
d35458e3fe Merge branch 'obsd-master' 2024-11-15 10:01:11 +00:00
nicm
d6883c0266 Turn off scrollbar when pane is in alternate screen, from Michael Grant,
GitHub issue 4231.
2024-11-15 09:01:16 +00:00
Thomas Adam
563ed05353 Merge branch 'obsd-master' 2024-11-12 12:01:10 +00:00
nicm
f527412d9b Tidy up loop, from Alexander Arch. 2024-11-12 10:06:35 +00:00
nicm
713cacab1e Mouse support on the scrollbars, from Michael Grant. 2024-11-12 09:32:56 +00:00
Thomas Adam
846f813565 Merge branch 'obsd-master' 2024-11-11 10:01:08 +00:00
nicm
c26d71d3e9 Add an option to control the input buffer size, from Ken Lau. 2024-11-11 08:41:05 +00:00
Thomas Adam
c8677d3272 Merge branch 'obsd-master' 2024-11-08 10:01:08 +00:00
nicm
596ea62dc3 Some fixes for searching for tabs, from Alexander Arch. 2024-11-08 08:51:36 +00:00
Thomas Adam
1fe30bb2e8 Merge branch 'obsd-master' 2024-11-06 20:33:45 +00:00
nicm
809d659e64 Xr to Ic, from jmc. 2024-11-05 21:07:19 +00:00
nicm
09f4e43189 Add support for a scrollbar at the side of each pane. New options
pane-scrollbars turn them on or off, pane-scrollbars-position sets the
position (left or right), and pane-scrollbars-style to set the colours.
Mouse support will come later. From Michael Grant in GitHub issue 4221.
2024-11-05 09:41:17 +00:00
Thomas Adam
679bbdcf8f Merge branch 'obsd-master' 2024-11-04 10:01:09 +00:00
nicm
a0c79aa87b Do not make padding cells extended (there can be a lot of them), from
Alexander Arch .
2024-11-04 08:52:13 +00:00
Nicholas Marriott
46f3846659 Add -Wno-macro-redefined for macOS. 2024-10-31 12:57:40 +00:00
Thomas Adam
bbc3cc558c Merge branch 'obsd-master' 2024-10-28 10:01:08 +00:00
nicm
c8bd42de16 Match tab cells when searching, from Alexander Arch in GitHub issue
4201.
2024-10-28 08:16:51 +00:00
nicm
62e15e905b Treat tabs as a word separator, from Alexander Arch in GitHub issue
4201.
2024-10-28 08:16:06 +00:00
nicm
125a7b9177 Fix issues in the command prompt: set PROMPT_QUOTENEXT after quoting
than before, meaning that accidentally scrolling the mouse wheel doesn't
break quoting; and move the cursor correctly over wide characters. From
Alexander Arch in GitHub issue 4212.
2024-10-28 08:11:59 +00:00
Thomas Adam
895044c52b Merge branch 'obsd-master' 2024-10-25 22:01:10 +01:00
nicm
40c01c2d37 Allow tabs even on terminals without UTF-8, reported by jmc. 2024-10-25 19:36:38 +00:00
Thomas Adam
911d768b71 Merge branch 'obsd-master' 2024-10-25 18:01:11 +01:00
nicm
71a503e40c Allow control characters to be entered at the command prompt prefixed
with with C-v, from  Alexander Arch in GitHub issue 4206.
2024-10-25 15:32:51 +00:00
nicm
487b0ee124 Do not attempt to search for zero length strings, from Alexander Arch in
GitHub issue 4209.
2024-10-25 15:19:15 +00:00
nicm
eaec0a48f4 Do not stop stop at first padding in format_grid_line and handle tabs. 2024-10-25 15:13:10 +00:00
nicm
fdbc6cdea5 Flag tabs if possible in the grid cell so they can be preserved on
copying and capture-pane. From Alexander Arch in GitHub issue 4201.
2024-10-25 15:00:18 +00:00
Thomas Adam
9623ec3ee4 Merge branch 'obsd-master' 2024-10-25 10:01:07 +01:00
nicm
63582c154c Add a helper function for cell data comparison, from Alexander Arch. 2024-10-25 07:57:49 +00:00
Thomas Adam
914815e70f Merge branch 'obsd-master' 2024-10-21 16:01:07 +01:00
nicm
354926a956 Bump up the maximum for repeat-time (some people want it to be
effectively infinite).
2024-10-21 12:42:06 +00:00
nicm
df303770ea Add function to get current offset from copy mode, from Michael Grant. 2024-10-21 12:39:49 +00:00
Thomas Adam
a269c33a54 Merge branch 'obsd-master' 2024-10-21 10:01:08 +01:00
nicm
eb04f9314b Adjust how Ctrl and Meta keys are sent to use standard representation if
available in mode 1, from Stanislav Kljuhhin, GitHub issue 4188.
2024-10-21 07:38:06 +00:00
Thomas Adam
a9d0461839 Merge branch 'obsd-master' 2024-10-17 20:01:07 +01:00
nicm
71aa4fe767 Switch pane-colors and cursor-style options to be in alphabetical order,
from Teubel Gyorgy, GitHub issue 4191.
2024-10-17 17:22:01 +00:00
nicm
cfd3c02306 Allow attributes in menu style, from Japin Li in GitHub issue 4194. 2024-10-17 17:10:41 +00:00
Thomas Adam
35104059ed Merge branch 'obsd-master' 2024-10-15 00:01:10 +01:00
nicm
934035db71 Set ACS flag for REP. Reported by Romain Francoise, GitHub issue 4182. 2024-10-14 20:26:45 +00:00
Nicholas Marriott
8ff65230e1 Optimize sixel_print. Previously, the algorithm scanned each pixel several
times; once to find out which colors are active, and then once for every single
active color to actually construct the output string.

Now it constructs the compressed sixel patterns in the first pass (now x * 12
iters), so we can reduce the second pass (the really expensive part, at active
colors * x * 6 iters) to just appending these to the output buffer.

From nincsnevem662 at gmail dot com in GitHub issue 4184.
2024-10-14 11:05:59 +01:00
Thomas Adam
cb00e869ea Merge branch 'obsd-master' 2024-10-12 12:01:09 +01:00
nicm
f8b56fdc3f Call realpath on the source file to match -f on the command line, GitHub
issue 4180.
2024-10-12 08:20:32 +00:00
nicm
2d8b6fcf23 Do not rename a buffer to itself, GitHub issue 4181. 2024-10-12 08:13:52 +00:00
Nicholas Marriott
6ddee22f81 Portable tmux needs to check ENABLE_SIXEL. 2024-10-10 12:07:29 +01:00
Thomas Adam
66c738bc10 Merge branch 'obsd-master' 2024-10-10 12:01:08 +01:00
nicm
bcc47add38 Add a sixel_support format variable which is 1 if SIXEL is supported
(always 0 on OpenBSD), requested by Misaki Masa in GitHub issue 4177
2024-10-10 10:41:33 +00:00
Thomas Adam
d326c51d79 Merge branch 'obsd-master' 2024-10-08 12:01:09 +01:00
nicm
940fdf7ed0 Draw pane status line on the correct line when at the bottom, fixes
issues if the window size is smaller than the entire terminal. GitHub
issue 3943.
2024-10-08 09:40:50 +00:00
Thomas Adam
4f5d6d97d3 Merge branch 'obsd-master' 2024-10-08 10:01:08 +01:00
nicm
00412b570b Put the prompt cursor attributes into the status line screen and use
that rather than updating the current screen (since there might not be
one).
2024-10-08 06:29:44 +00:00
Thomas Adam
6a35b8ad07 Merge branch 'obsd-master' 2024-10-07 16:01:08 +01:00
nicm
735082b7c2 Add prompt-cursor-colour and prompt-cursor-style to set the style of the
cursor in the command prompt and remove the emulated cursor, from
Alexander Arch in GitHub issue 4170.
2024-10-07 12:58:36 +00:00
Thomas Adam
5b7bdc82c8 Merge branch 'obsd-master' 2024-10-07 12:01:08 +01:00
nicm
a3dea81b49 Add initial-repeat-time option to allow the first repeat time to be
increased and later reduced, from David le Blanc in GitHub issue 4164.
2024-10-07 08:50:47 +00:00
Thomas Adam
486221f206 Merge branch 'obsd-master' 2024-10-06 12:01:07 +01:00
nicm
9528d7470b Try to stay near the same line in modes if the current one is removed. 2024-10-06 09:30:22 +00:00
Thomas Adam
933d6b90ed Merge branch 'obsd-master' 2024-10-05 16:01:07 +01:00
nicm
a869693405 Send focus events to pane when entering or leaving popup, GitHub issue
3991.
2024-10-05 12:10:16 +00:00
Thomas Adam
114977dd25 Merge branch 'obsd-master' 2024-10-05 04:01:08 +01:00
Thomas Adam
aba8ffbe7b Merge branch 'obsd-master' 2024-10-05 02:01:07 +01:00
nicm
455a2b3705 Remove some debugging left behind. 2024-10-05 00:35:35 +00:00
nicm
e0638c48cd Add copy-mode-position-format to configure the position indicator. 2024-10-05 00:32:55 +00:00
nicm
41f6b691e3 Document missing window-layout-changed hook. 2024-10-04 22:36:11 +00:00
Nicholas Marriott
0f30fa34e3 Add install step. 2024-10-04 23:29:36 +01:00
Thomas Adam
e486f5ffdc Merge branch 'obsd-master' 2024-10-04 22:01:09 +01:00
nicm
5a68730e2f Add -y flag to disable confirmation prompts in modes, GitHub issue 4152. 2024-10-04 19:16:13 +00:00
Thomas Adam
16b44d2a5b Merge branch 'obsd-master' 2024-10-04 18:01:07 +01:00
nicm
34775fc235 Do not translate BSpace as Unicode, GitHub issue 4156. 2024-10-04 14:55:17 +00:00
Thomas Adam
f2fd8c854a Merge branch 'obsd-master' 2024-10-04 10:01:08 +01:00
nicm
9f2a853d87 Rework of copy mode commands ("send-keys -X") to parse the arguments so
that flags may be detected propertly rather than just looking for
strings ("-O" and so on). Also add -C and -P flags to the copy commands:
-C prevents the commands from sending the text to the clipboard and -P
prevents them from adding the text as a paste buffer.

Note some of the default key bindings change to add "--" and any similar
custom key bindings using "send-keys -X" may need a similar change.

GitHub issue 4153.
2024-10-04 07:03:08 +00:00
Nicholas Marriott
7a78cdf78c Three SIXEL improvements from nincsnevem662 at gmail dot com in GitHub issue
4149:

- Pass P2 on the received image through when forwarding the image to the
  outside terminal to preserve transparency;

- Preserve raster attribute dimensions which may be smaller than the actual
  image (used to crop out parts of the image to work around the limitation that
  rows must come in groups of six);

- To avoid collapsing empty sixel lines, no longer ignore duplicate "-" new
  line specifiers.
2024-10-04 07:49:07 +01:00
Thomas Adam
2df15ad08c Merge branch 'obsd-master' 2024-10-03 08:01:07 +01:00
nicm
780a87be9a Improve fix for shifted keys so it works for all the keys it should,
Stanislav Kljuhhin in GitHub issue 4146.
2024-10-03 05:41:59 +00:00
Nicholas Marriott
1e303b6a9d Bypass permission check for Cygwin, based on a different change by Yuya Adachi
via Rafael Kitover; GitHub issue 4148.
2024-10-02 14:04:06 +01:00
Thomas Adam
8d2aee34ab Merge branch 'obsd-master' 2024-10-02 14:01:10 +01:00
nicm
05116cefe6 Add MSYSTEM to default update-environment. 2024-10-02 11:51:15 +00:00
nicm
ce4be58eef Add a define for the socket permissions check so it can be overridden
more easily (for Cgywin).
2024-10-02 11:48:16 +00:00
Nicholas Marriott
8d6eb4be40 Set client stdout file descriptor also for Cgywin, from Michael Wild via Rafael
Kitover in GitHub issue 4148.
2024-10-02 12:16:24 +01:00
Thomas Adam
38c38f1c64 Merge branch 'obsd-master' 2024-10-02 10:01:08 +01:00
nicm
ddf6af79e3 Report shifted keys like S-A as A not as S-A in mode 1 extended keys,
from Stanislav Kljuhhin.
2024-10-02 08:06:45 +00:00
Thomas Adam
826ba515be Merge branch 'obsd-master' 2024-10-01 14:01:08 +01:00
Nicholas Marriott
729bded8bf Fix up regression tests. 2024-10-01 13:40:42 +01:00
nicm
b95a06d2d4 Add a way to make the preview larger in tree mode, GitHub issue 4124. 2024-10-01 10:10:29 +00:00
Thomas Adam
157d748949 Merge branch 'obsd-master' 2024-10-01 10:01:10 +01:00
nicm
1c1f4c1219 Use global cursor style and colour options for modes instead of default,
GitHub issue 4117.
2024-10-01 08:01:19 +00:00
nicm
17bab32794 Change pasting to bypass the output key processing entirely and write
what was originally received. Fixes problems with pasted text being
interpreted as extended keys reported by Mark Kelly.
2024-10-01 06:15:47 +00:00
Thomas Adam
25b1cc1e8e Merge branch 'obsd-master' 2024-09-30 12:01:11 +01:00
nicm
89adec0ca5 On some Windows terminals, if TIOCWINSZ does not return xpixel and
ypixel (they are zero), if this is the case then try the query escape
sequences. From Dmitry Galchinsky in GitHub issue 4099.
2024-09-30 08:10:20 +00:00
nicm
f95d055e04 Only use default-shell for popups, return to /bin/sh for run-shell,
if-shell and #() - these have been documented as using /bin/sh for a
long time and scripts rely on it. Pointed out by Gregory Pakosz.
2024-09-30 07:54:51 +00:00
Thomas Adam
7b148f7b5b Merge branch 'obsd-master' 2024-09-29 22:01:09 +01:00
nicm
9bd039d1bc Fix grey colour, from Magnus Gross. 2024-09-29 20:05:42 +00:00
Nicholas Marriott
7c30056d96 Bump to 3.6. 2024-09-27 08:58:00 +01:00
126 changed files with 9119 additions and 2759 deletions

View File

@@ -77,3 +77,8 @@ The log files are:
- `tmux-out*.log`: output log file. - `tmux-out*.log`: output log file.
Please attach the log files to your issue. Please attach the log files to your issue.
## What does it mean if an issue is closed?
All it means is that work on the issue is not planned for the near future. See
the issue's comments to find out if contributions would be welcome.

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@@ -0,0 +1 @@
blank_issues_enabled: false

View File

@@ -1,3 +1,12 @@
---
name: Use this issue template
about: Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
title: ''
labels: ''
assignees: ''
---
### Issue description ### Issue description
Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
@@ -14,9 +23,11 @@ built from the latest code in Git.
### Required information ### Required information
Please provide the following information: Please provide the following information. These are **required**. Note that bug reports without logs may be ignored or closed without comment.
* tmux version (`tmux -V`). * tmux version (`tmux -V`).
* Platform (`uname -sp`). * Platform (`uname -sp`).
* $TERM inside and outside of tmux (`echo $TERM`). * Terminal in use (xterm, rxvt, etc).
* $TERM *inside* tmux (`echo $TERM`).
* $TERM *outside* tmux (`echo $TERM`).
* Logs from tmux (`tmux kill-server; tmux -vv new`). * Logs from tmux (`tmux kill-server; tmux -vv new`).

2
.github/README.md vendored
View File

@@ -79,7 +79,7 @@ A small example configuration is in `example_tmux.conf`.
And a bash(1) completion file at: And a bash(1) completion file at:
https://github.com/imomaliev/tmux-bash-completion https://github.com/scop/bash-completion/blob/main/completions/tmux
For debugging, run tmux with `-v` or `-vv` to generate server and client log For debugging, run tmux with `-v` or `-vv` to generate server and client log
files in the current directory. files in the current directory.

35
.gitignore vendored
View File

@@ -1,23 +1,24 @@
*.o
*~
*.diff
*.patch
*.core *.core
core *.dSYM
tags *.diff
*.o
*.patch
*.swp
*~
.deps/ .deps/
compat/.dirstamp .dirstamp
aclocal.m4
autom4te.cache/
config.log
config.status
etc/
tmux
Makefile Makefile
Makefile.in Makefile.in
configure aclocal.m4
tmux.1.* autom4te.cache/
*.dSYM
cmd-parse.c cmd-parse.c
compat/.dirstamp
config.log
config.status
configure
core
etc/
fuzz/*-fuzzer fuzz/*-fuzzer
.dirstamp tags
tmux
tmux.1.*

230
CHANGES
View File

@@ -1,3 +1,231 @@
CHANGES FROM 3.6 TO 3.6a
* Fix a buffer overread and an infinite loop in format processing (reported by
Giorgi Kobakhia, issue 4735).
* Allow drag in alternate screen again (issue 4743 reported by Brad King).
* Fix y offset of mouse if status at top (issue 4738 from Michael Grant).
* Add a missing skin tone (from Jake Stewart, issue 4736).
* Allow characters to be combined in either order (issue 4726, reported by Jake
Stewart).
* Fix horizontal mouse resizing when pane status lines are on (from Michael
Grant, issue 4720).
* Fix noattr so it does not delete attributes set in the style itself (issue
4713).
* Newer libevents do not allow event_del on a zero'd event (issue 4706).
* Place cursor on correct line if message-line is not 0 (issue 4707).
* Fix compile error on FreeBSD (from Yasuhiro Kimura, issue 4701).
CHANGES FROM 3.5a TO 3.6
* Add seconds options for clock mode (issue 4697).
* Add a resize callback for menus so that they are correctly moved on resize
(issue 4696).
* Make -v to source-file pass through to subsequent source-file commands (issue
4216).
* If display-popup is used inside a popup, modify that popup (issue 4678).
* Add selection-mode command to expilcitly set the selection mode in copy mode
(issue 3842).
* Save and restore images in alternate screen (issue 3732).
* Ignore Hangul filler character (issue 3998).
* Improve handling of regional indicators and emoji modifiers (issue 3998).
* Preserve marked pane with swap-window and move-window (issue 3443).
* Set and check COLORTERM as a hint for RGB colour.
* If tmux receives a palette request (OSC 4) in a pane and the palette entry
has not been set, send a request to the most recently used client and
forward any response instead (based on change from Tim Culverhouse, issue
4665).
* Add -l flag to command-prompt to disable splitting into multiple prompts
(issue 4483).
* Don't enter copy mode on mouse wheel in alternate screen (issue 3705).
* Add commands to centre the cursor in copy mode (issue 4662).
* Support case insensitive search in modes in the same way as copy mode
(like emacs, so all-lowercase means case insensitive) (issue 4396).
* Fix the logic of the no-detached case for the detach-on-destroy option (from
Martin Louazel, issue 4649).
* Add buffer_full format variable (from Mohammad AlSaleh, issue 4630).
* Introduce a new window option, tiled-layout-max-columns, which configures the
maximum number of columns in the tiled layout.
* Add support for DECRQSS SP q (report cursor style), DECRQM ?12 (report cursor
blink state) and DECRQM ?2004, ?1004, ?1006 (report mouse state) ( rom
Andrea Alberti, issue 4618).
* Fix missing argument from OSC 4 reply (issue 4596).
* Add -k flag to display-popup which allows any key to dismiss the popup once
the command has exited (from Meriel Luna Mittelbach, issue 4612).
* Add nicer default second and third status lines (from Michael Grant, issue
4490).
* Add a pane-border-lines "spaces" value to use spaces for pane borders (issue
4587).
* Replace invalid UTF-8 characters with the placeholder instead of ignoring
them (issue 4514).
* Fix incorrect handling of Korean Hangul Jamo characters (from Roy Jung, issue
4546).
* Allow uppercase letters in gray/grey color names (from Pavel Roskin, issue
4560).
* Add sorting to W, P, L loop operators (from Michael Grant, issue 4516).
* Detect support for OSC 52 using the device attributes report (from James
Holderness, issue 4539).
* Add noattr for styles and use in mode-style to allow whether attributes are
ignored or used to be configured (issue 4498).
* Add a set-default style attribute which replaces the current default colours
and attributes completely.
* Add -E to run-shell to forward stderr as well as stdout (issue 4246).
* Add an option variation-selector-always-wide to instruct tmux not to
always interpret VS16 as a wide character and assume the terminal does
likewise.
* Switch to getopt_long from OpenSSH (from Koichi Murase, issue 4492).
* Add more features for boolean expressions in formats: 1) extend && and || to
support arbitrarily many arguments and 2) add ! and !! for not and not-not
(from David Mandelberg).
* Do not mistake other DCS sequences for SIXEL sequences (from James
Holderness, issue 4488).
* Improve #? conditional expression in formats: add support for else if and
default empty string if no else value (from David Mandelberg, issue 4451).
* Add default-client-command to set the command used if tmux is run without a
command; the default stays new-session (from David Mandelberg, issue
4422).
* Add S-Up and S-Down to move windows in tree mode (from David Mandelberg,
issue 4415).
* Add mode 2031 support to automatically report dark or light theme. tmux will
guess the theme from the background colour on terminals which do not
themselves support the escape sequence (from Jonathan Slenders, issue 4353).
* Add -M flag to capture-pane to use the copy mode screen (issue 4358).
* Align index numbers in trees (from David Mandelberg, issue 4360).
* Add display-message -C flag to update pane while message is displayed (from
Vitaly Ostrosablin, issue 4363).
* Make list-commands command show only one command if an argument is given
(from Ilya Grigoriev, issue 4352).
* Count line numbers correctly inside strings in configuration files (reported
by Pedro Navarro, issue 4325).
* Map bright black (colour 8) to white (7) if the background is black on
terminals with only eight colours so the text is not invisible (from Dmytro
Bagrii, issue 4322).
* New codepoint-widths option allowing users to override the width of
individual Unicode codepoints.
* Add a nesting limit to source-file (from Fadi Afani, issue 4223).
* Add copy-mode-position-style and copy-mode-selection-style options for copy
mode.
* Add no-detach-on-destroy client option (issue 4242).
* Add input-buffer-size option (from Ken Lau).
* Add support for a scrollbar at the side of each pane. New options
pane-scrollbars turn them on or off, pane-scrollbars-position sets the
position (left or right), and pane-scrollbars-style to set the colours (from
Michael Grant, issue 4221).
* Allow control characters to be entered at the command prompt by prefixing
with C-v (from Alexander Arch, issue 4206).
* Do not attempt to search for zero length strings (from Alexander Arch, issue
4209).
* Preserve tabs for copying and capture-pane (from Alexander Arch, issue
4201).
* Increase the maximum for repeat-time.
* Adjust how Ctrl and Meta keys are sent to use standard representation if
available in mode 1 (from Stanislav Kljuhhin, issue 4188).
* Allow attributes in menu style (from Japin Li, issue 4194).
* Add a sixel_support format variable which is 1 if SIXEL is supported, always
0 on OpenBSD (requested by Misaki Masa, issue 4177).
* Add prompt-cursor-colour and prompt-cursor-style to set the style of the
cursor in the command prompt and remove the emulated cursor (from Alexander
Arch, issue 4170).
* Add initial-repeat-time option to allow the first repeat time to be increased
and later reduced (from David le Blanc, issue 4164).
* Send focus events to pane when entering or leaving popup (issue 3991).
* Add copy-mode-position-format to configure the position indicator.
* Add -y flag to disable confirmation prompts in modes (issue 4152).
* Add -C and -P flags to the copy commands in copy mode: -C prevents the
commands from sending the text to the clipboard and -P prevents them from
adding the text as a paste buffer (issue 4153).
* Preserve transparency and raster attribute dimensions when sending a SIXEL
image, and avoid collapsing empty lines (issue 4149).
* Bypass permission check for Cygwin (based on a change by Yuya Adachi via
Rafael Kitover, issue 4148).
* Add MSYSTEM to default update-environment (for Cgywin).
* Set client stdout file descriptor also for Cgywin (from Michael Wild via Rafael
Kitover, issue 4148).
* Use global cursor style and colour options for modes instead of default
(issue 4117).
* Fix pasting so it does not interpret keys but instead copies the input
without interpretation (reported by Mark Kelly).
* Try to query window pixel size from the outside terminal if the values
returned by TIOCGWINSZ are zero (Dmitry Galchinsky, issue 4099).
CHANGES FROM 3.5 TO 3.5a CHANGES FROM 3.5 TO 3.5a
* Do not translate BSpace as Unicode with extended keys. * Do not translate BSpace as Unicode with extended keys.
@@ -400,7 +628,7 @@ CHANGES FROM 3.2 TO 3.2a
* Do not expand the filename given to -f so it can contain colons. * Do not expand the filename given to -f so it can contain colons.
* Fixes for problems with extended keys and modifiers, scroll region, * Fixes for problems with extended keys and modifiers, scroll region,
source-file, crosscompiling, format modifiers and other minor issues. source-file, cross compiling, format modifiers and other minor issues.
CHANGES FROM 3.1c TO 3.2 CHANGES FROM 3.1c TO 3.2

View File

@@ -30,7 +30,7 @@ AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k AM_CFLAGS += -Wno-unused-result -Wno-format-y2k
if IS_DARWIN if IS_DARWIN
AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align -Wno-macro-redefined
endif endif
AM_CPPFLAGS += -DDEBUG AM_CPPFLAGS += -DDEBUG
endif endif
@@ -66,6 +66,11 @@ if IS_HAIKU
AM_CPPFLAGS += -D_BSD_SOURCE AM_CPPFLAGS += -D_BSD_SOURCE
endif endif
# Set flags for Cygwin.
if IS_CYGWIN
AM_CPPFLAGS += -DTMUX_SOCK_PERM=0
endif
# List of sources. # List of sources.
dist_tmux_SOURCES = \ dist_tmux_SOURCES = \
alerts.c \ alerts.c \

3
README
View File

@@ -36,6 +36,7 @@ autoconf, automake and pkg-config:
$ cd tmux $ cd tmux
$ sh autogen.sh $ sh autogen.sh
$ ./configure && make $ ./configure && make
$ sudo make install
* Contributing * Contributing
@@ -65,7 +66,7 @@ Also see the tmux FAQ at:
A bash(1) completion file is at: A bash(1) completion file is at:
https://github.com/imomaliev/tmux-bash-completion https://github.com/scop/bash-completion/blob/main/completions/tmux
For debugging, run tmux with -v and -vv to generate server and client log files For debugging, run tmux with -v and -vv to generate server and client log files
in the current directory. in the current directory.

View File

@@ -38,7 +38,7 @@ tmuxのドキュメントについてはtmux.1マニュアルをご覧くださ
サンプル設定は本リポジトリのexample_tmux.confに サンプル設定は本リポジトリのexample_tmux.confに
また、bash-completionファイルは下記にあります。 また、bash-completionファイルは下記にあります。
https://github.com/imomaliev/tmux-bash-completion https://github.com/scop/bash-completion/blob/main/completions/tmux
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。 「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。

32
SYNCING
View File

@@ -1,17 +1,17 @@
Preamble Preamble
======== ========
Tmux portable relies on repositories "tmux" and "tmux-openbsd". Tmux portable relies on repositories "tmux" and "tmux-obsd".
Here's a description of them: Here's a description of them:
* "tmux" is the portable version, the one which contains code for other * "tmux" is the portable version, the one which contains code for other
operating systems, and autotools, etc., which isn't found or needed in the operating systems, and autotools, etc., which isn't found or needed in the
OpenBSD base system. OpenBSD base system.
* "tmux-openbsd" is the version of tmux in OpenBSD base system which provides * "tmux-obsd" is the version of tmux in OpenBSD base system which provides
the basis of the portable tmux version. the basis of the portable tmux version.
Note: The "tmux-openbsd" repository is actually handled by "git cvsimport" Note: The "tmux-obsd" repository is actually handled by "git cvsimport"
running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS
repository will take at least that long to appear in this git repository. repository will take at least that long to appear in this git repository.
(It might take longer, depending on the CVS mirror used to import the (It might take longer, depending on the CVS mirror used to import the
@@ -34,11 +34,11 @@ this information has ever been set before.
Cloning repositories Cloning repositories
==================== ====================
This involves having both tmux and tmux-openbsd cloned, as in: This involves having both tmux and tmux-obsd cloned, as in:
% cd /some/where/useful % cd /some/where/useful
% git clone https://github.com/tmux/tmux.git % git clone https://github.com/tmux/tmux.git
% git clone https://github.com/ThomasAdam/tmux-openbsd.git % git clone https://github.com/ThomasAdam/tmux-obsd.git
Note that you do not need additional checkouts to manage the sync -- an Note that you do not need additional checkouts to manage the sync -- an
existing clone of either repositories will suffice. So if you already have existing clone of either repositories will suffice. So if you already have
@@ -47,30 +47,30 @@ these checkouts existing, skip that.
Adding in git-remotes Adding in git-remotes
===================== =====================
Because the portable "tmux" git repository and the "tmux-openbsd" Because the portable "tmux" git repository and the "tmux-obsd"
repository do not inherently share any history between each other, the repository do not inherently share any history between each other, the
history has been faked between them. This "faking of history" is something history has been faked between them. This "faking of history" is something
which has to be told to git for the purposes of comparing the "tmux" and which has to be told to git for the purposes of comparing the "tmux" and
"tmux-openbsd" repositories for syncing. To do this, we must reference the "tmux-obsd" repositories for syncing. To do this, we must reference the
clone of the "tmux-openbsd" repository from the "tmux" repository, as clone of the "tmux-obsd" repository from the "tmux" repository, as
shown by the following command: shown by the following command:
% cd /path/to/tmux % cd /path/to/tmux
% git remote add obsd-tmux file:///path/to/tmux-openbsd % git remote add obsd-tmux file:///path/to/tmux-obsd
So that now, the remote "obsd-tmux" can be used to reference branches and So that now, the remote "obsd-tmux" can be used to reference branches and
commits from the "tmux-openbsd" repository, but from the context of the commits from the "tmux-obsd" repository, but from the context of the
portable "tmux" repository, which makes sense because it's the "tmux" portable "tmux" repository, which makes sense because it's the "tmux"
repository which will have the updates applied to them. repository which will have the updates applied to them.
Fetching updates Fetching updates
================ ================
To ensure the latest commits from "tmux-openbsd" can be found from within To ensure the latest commits from "tmux-obsd" can be found from within
"tmux", we have to ensure the "master" branch from "tmux-openbsd" is "tmux", we have to ensure the "master" branch from "tmux-obsd" is
up-to-date first, and then reference that update in "tmux", as in: up-to-date first, and then reference that update in "tmux", as in:
% cd /path/to/tmux-openbsd % cd /path/to/tmux-obsd
% git checkout master % git checkout master
% git pull % git pull
@@ -82,9 +82,9 @@ Then back in "tmux":
Creating the necessary branches Creating the necessary branches
=============================== ===============================
Now that "tmux" can see commits and branches from "tmux-openbsd" by way Now that "tmux" can see commits and branches from "tmux-obsd" by way
of the remote name "obsd-tmux", we can now create the master branch from of the remote name "obsd-tmux", we can now create the master branch from
"tmux-openbsd" in the "tmux" repository: "tmux-obsd" in the "tmux" repository:
% git checkout -b obsd-master obsd-tmux/master % git checkout -b obsd-master obsd-tmux/master
@@ -92,7 +92,7 @@ Adding in the fake history points
================================= =================================
To tie both the "master" branch from "tmux" and the "obsd-master" To tie both the "master" branch from "tmux" and the "obsd-master"
branch from "tmux-openbsd" together, the fake history points added to the branch from "tmux-obsd" together, the fake history points added to the
"tmux" repository need to be added. To do this, we must add an "tmux" repository need to be added. To do this, we must add an
additional refspec line, as in: additional refspec line, as in:

View File

@@ -315,11 +315,11 @@ alerts_set_message(struct winlink *wl, const char *type, const char *option)
if (visual == VISUAL_OFF) if (visual == VISUAL_OFF)
continue; continue;
if (c->session->curw == wl) { if (c->session->curw == wl) {
status_message_set(c, -1, 1, 0, "%s in current window", status_message_set(c, -1, 1, 0, 0,
type); "%s in current window", type);
} else { } else {
status_message_set(c, -1, 1, 0, "%s in window %d", type, status_message_set(c, -1, 1, 0, 0,
wl->idx); "%s in window %d", type, wl->idx);
} }
} }
} }

View File

@@ -31,7 +31,7 @@ attributes_tostring(int attr)
if (attr == 0) if (attr == 0)
return ("none"); return ("none");
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
(attr & GRID_ATTR_CHARSET) ? "acs," : "", (attr & GRID_ATTR_CHARSET) ? "acs," : "",
(attr & GRID_ATTR_BRIGHT) ? "bright," : "", (attr & GRID_ATTR_BRIGHT) ? "bright," : "",
(attr & GRID_ATTR_DIM) ? "dim," : "", (attr & GRID_ATTR_DIM) ? "dim," : "",
@@ -45,7 +45,8 @@ attributes_tostring(int attr)
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "", (attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "", (attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "", (attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
(attr & GRID_ATTR_OVERLINE) ? "overline," : ""); (attr & GRID_ATTR_OVERLINE) ? "overline," : "",
(attr & GRID_ATTR_NOATTR) ? "noattr," : "");
if (len > 0) if (len > 0)
buf[len - 1] = '\0'; buf[len - 1] = '\0';

8
cfg.c
View File

@@ -221,10 +221,14 @@ cfg_add_cause(const char *fmt, ...)
void void
cfg_print_causes(struct cmdq_item *item) cfg_print_causes(struct cmdq_item *item)
{ {
u_int i; struct client *c = cmdq_get_client(item);
u_int i;
for (i = 0; i < cfg_ncauses; i++) { for (i = 0; i < cfg_ncauses; i++) {
cmdq_print(item, "%s", cfg_causes[i]); if (c != NULL && (c->flags & CLIENT_CONTROL))
control_write(c, "%%config-error %s", cfg_causes[i]);
else
cmdq_print(item, "%s", cfg_causes[i]);
free(cfg_causes[i]); free(cfg_causes[i]);
} }

View File

@@ -38,7 +38,7 @@ const struct cmd_entry cmd_bind_key_entry = {
.args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse }, .args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
.usage = "[-nr] [-T key-table] [-N note] key " .usage = "[-nr] [-T key-table] [-N note] key "
"[command [arguments]]", "[command [argument ...]]",
.flags = CMD_AFTERHOOK, .flags = CMD_AFTERHOOK,
.exec = cmd_bind_key_exec .exec = cmd_bind_key_exec

View File

@@ -85,7 +85,10 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
options_set_number(w->options, "automatic-rename", 0); options_set_number(w->options, "automatic-rename", 0);
} }
server_unlink_window(src_s, wl); server_unlink_window(src_s, wl);
return (CMD_RETURN_NORMAL); wl = winlink_find_by_window(&dst_s->windows, w);
if (wl == NULL)
return (CMD_RETURN_ERROR);
goto out;
} }
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) { if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
cmdq_error(item, "index in use: %d", idx); cmdq_error(item, "index in use: %d", idx);
@@ -99,7 +102,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel); w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
options_set_parent(wp->options, w->options); options_set_parent(wp->options, w->options);
wp->flags |= PANE_STYLECHANGED; wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
TAILQ_INSERT_HEAD(&w->panes, wp, entry); TAILQ_INSERT_HEAD(&w->panes, wp, entry);
w->active = wp; w->active = wp;
w->latest = tc; w->latest = tc;
@@ -132,6 +135,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
if (src_s != dst_s) if (src_s != dst_s)
server_status_session_group(dst_s); server_status_session_group(dst_s);
out:
if (args_has(args, 'P')) { if (args_has(args, 'P')) {
if ((template = args_get(args, 'F')) == NULL) if ((template = args_get(args, 'F')) == NULL)
template = BREAK_PANE_TEMPLATE; template = BREAK_PANE_TEMPLATE;

View File

@@ -39,8 +39,8 @@ const struct cmd_entry cmd_capture_pane_entry = {
.name = "capture-pane", .name = "capture-pane",
.alias = "capturep", .alias = "capturep",
.args = { "ab:CeE:JNpPqS:Tt:", 0, 0, NULL }, .args = { "ab:CeE:JMNpPqS:Tt:", 0, 0, NULL },
.usage = "[-aCeJNpPqT] " CMD_BUFFER_USAGE " [-E end-line] " .usage = "[-aCeJMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line] " CMD_TARGET_PANE_USAGE, "[-S start-line] " CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@@ -107,14 +107,16 @@ static char *
cmd_capture_pane_history(struct args *args, struct cmdq_item *item, cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
struct window_pane *wp, size_t *len) struct window_pane *wp, size_t *len)
{ {
struct grid *gd; struct grid *gd;
const struct grid_line *gl; const struct grid_line *gl;
struct grid_cell *gc = NULL; struct screen *s;
int n, join_lines, flags = 0; struct grid_cell *gc = NULL;
u_int i, sx, top, bottom, tmp; struct window_mode_entry *wme;
char *cause, *buf, *line; int n, join_lines, flags = 0;
const char *Sflag, *Eflag; u_int i, sx, top, bottom, tmp;
size_t linelen; char *cause, *buf, *line;
const char *Sflag, *Eflag;
size_t linelen;
sx = screen_size_x(&wp->base); sx = screen_size_x(&wp->base);
if (args_has(args, 'a')) { if (args_has(args, 'a')) {
@@ -126,8 +128,20 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
} }
return (xstrdup("")); return (xstrdup(""));
} }
} else s = &wp->base;
} else if (args_has(args, 'M')) {
wme = TAILQ_FIRST(&wp->modes);
if (wme != NULL && wme->mode->get_screen != NULL) {
s = wme->mode->get_screen (wme);
gd = s->grid;
} else {
s = &wp->base;
gd = wp->base.grid;
}
} else {
s = &wp->base;
gd = wp->base.grid; gd = wp->base.grid;
}
Sflag = args_get(args, 'S'); Sflag = args_get(args, 'S');
if (Sflag != NULL && strcmp(Sflag, "-") == 0) if (Sflag != NULL && strcmp(Sflag, "-") == 0)
@@ -181,7 +195,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
buf = NULL; buf = NULL;
for (i = top; i <= bottom; i++) { for (i = top; i <= bottom; i++) {
line = grid_string_cells(gd, 0, i, sx, &gc, flags, wp->screen); line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
linelen = strlen(line); linelen = strlen(line);
buf = cmd_capture_pane_append(buf, len, line, linelen); buf = cmd_capture_pane_append(buf, len, line, linelen);
@@ -234,8 +248,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
file_print_buffer(c, buf, len); file_print_buffer(c, buf, len);
file_print(c, "\n"); file_print(c, "\n");
free(buf);
} }
free(buf);
} else { } else {
bufname = NULL; bufname = NULL;
if (args_has(args, 'b')) if (args_has(args, 'b'))

View File

@@ -33,7 +33,7 @@ const struct cmd_entry cmd_choose_tree_entry = {
.name = "choose-tree", .name = "choose-tree",
.alias = NULL, .alias = NULL,
.args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse }, .args = { "F:f:GK:NO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] " .usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = {
.name = "choose-client", .name = "choose-client",
.alias = NULL, .alias = NULL,
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse }, .args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] " .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@@ -61,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.name = "choose-buffer", .name = "choose-buffer",
.alias = NULL, .alias = NULL,
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse }, .args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] " .usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]", "[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
@@ -75,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = {
.name = "customize-mode", .name = "customize-mode",
.alias = NULL, .alias = NULL,
.args = { "F:f:Nt:Z", 0, 0, NULL }, .args = { "F:f:Nt:yZ", 0, 0, NULL },
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE, .usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },

View File

@@ -42,9 +42,9 @@ const struct cmd_entry cmd_command_prompt_entry = {
.name = "command-prompt", .name = "command-prompt",
.alias = NULL, .alias = NULL,
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse }, .args = { "1bFkliI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE .usage = "[-1bFkliN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
" [-T type] [template]", " [-T prompt-type] [template]",
.flags = CMD_CLIENT_TFLAG, .flags = CMD_CLIENT_TFLAG,
.exec = cmd_command_prompt_exec .exec = cmd_command_prompt_exec
@@ -117,27 +117,33 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
next_input = inputs = xstrdup(s); next_input = inputs = xstrdup(s);
else else
next_input = NULL; next_input = NULL;
while ((prompt = strsep(&next_prompt, ",")) != NULL) { if (args_has(args, 'l')) {
cdata->prompts = xreallocarray(cdata->prompts, cdata->count + 1, cdata->prompts = xcalloc(1, sizeof *cdata->prompts);
sizeof *cdata->prompts); cdata->prompts[0].prompt = prompts;
if (!space) cdata->prompts[0].input = inputs;
tmp = xstrdup(prompt); cdata->count = 1;
else } else {
xasprintf(&tmp, "%s ", prompt); while ((prompt = strsep(&next_prompt, ",")) != NULL) {
cdata->prompts[cdata->count].prompt = tmp; cdata->prompts = xreallocarray(cdata->prompts,
cdata->count + 1, sizeof *cdata->prompts);
if (!space)
tmp = xstrdup(prompt);
else
xasprintf(&tmp, "%s ", prompt);
cdata->prompts[cdata->count].prompt = tmp;
if (next_input != NULL) { if (next_input != NULL) {
input = strsep(&next_input, ","); input = strsep(&next_input, ",");
if (input == NULL) if (input == NULL)
input = "";
} else
input = ""; input = "";
} else cdata->prompts[cdata->count].input = xstrdup(input);
input = ""; cdata->count++;
cdata->prompts[cdata->count].input = xstrdup(input); }
free(inputs);
cdata->count++; free(prompts);
} }
free(inputs);
free(prompts);
if ((type = args_get(args, 'T')) != NULL) { if ((type = args_get(args, 'T')) != NULL) {
cdata->prompt_type = status_prompt_type(type); cdata->prompt_type = status_prompt_type(type);

View File

@@ -42,7 +42,7 @@ const struct cmd_entry cmd_confirm_before_entry = {
.alias = "confirm", .alias = "confirm",
.args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse }, .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
.usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE .usage = "[-by] [-c confirm-key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
" command", " command",
.flags = CMD_CLIENT_TFLAG, .flags = CMD_CLIENT_TFLAG,
@@ -130,7 +130,7 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
if (s == NULL) if (s == NULL)
goto out; goto out;
if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes)) if (s[0] != cdata->confirm_key && (s[0] != '\r' || !cdata->default_yes))
goto out; goto out;
retcode = 0; retcode = 0;

View File

@@ -30,8 +30,8 @@ const struct cmd_entry cmd_copy_mode_entry = {
.name = "copy-mode", .name = "copy-mode",
.alias = NULL, .alias = NULL,
.args = { "deHMs:t:uq", 0, 0, NULL }, .args = { "deHMqSs:t:u", 0, 0, NULL },
.usage = "[-deHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE, .usage = "[-deHMqSu] [-s src-pane] " CMD_TARGET_PANE_USAGE,
.source = { 's', CMD_FIND_PANE, 0 }, .source = { 's', CMD_FIND_PANE, 0 },
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@@ -92,7 +92,12 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'u')) if (args_has(args, 'u'))
window_copy_pageup(wp, 0); window_copy_pageup(wp, 0);
if (args_has(args, 'd')) if (args_has(args, 'd'))
window_copy_pagedown(wp, 0, args_has(args, 'e')); window_copy_pagedown(wp, 0, args_has(args, 'e'));
if (args_has(args, 'S')) {
window_copy_scroll(wp, c->tty.mouse_slider_mpos, event->m.y,
args_has(args, 'e'));
return (CMD_RETURN_NORMAL);
}
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@@ -41,8 +41,8 @@ const struct cmd_entry cmd_display_menu_entry = {
.args = { "b:c:C:H:s:S:MOt:T:x:y:", 1, -1, cmd_display_menu_args_parse }, .args = { "b:c:C:H:s:S:MOt:T:x:y:", 1, -1, cmd_display_menu_args_parse },
.usage = "[-MO] [-b border-lines] [-c target-client] " .usage = "[-MO] [-b border-lines] [-c target-client] "
"[-C starting-choice] [-H selected-style] [-s style] " "[-C starting-choice] [-H selected-style] [-s style] "
"[-S border-style] " CMD_TARGET_PANE_USAGE "[-T title] " "[-S border-style] " CMD_TARGET_PANE_USAGE " [-T title] "
"[-x position] [-y position] name key command ...", "[-x position] [-y position] name [key] [command] ...",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@@ -54,12 +54,12 @@ const struct cmd_entry cmd_display_popup_entry = {
.name = "display-popup", .name = "display-popup",
.alias = "popup", .alias = "popup",
.args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL }, .args = { "Bb:Cc:d:e:Eh:kNs:S:t:T:w:x:y:", 0, -1, NULL },
.usage = "[-BCE] [-b border-lines] [-c target-client] " .usage = "[-BCEkN] [-b border-lines] [-c target-client] "
"[-d start-directory] [-e environment] [-h height] " "[-d start-directory] [-e environment] [-h height] "
"[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE "[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE
"[-T title] [-w width] [-x position] [-y position] " " [-T title] [-w width] [-x position] [-y position] "
"[shell-command]", "[shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@@ -92,7 +92,7 @@ cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause)
} }
static int static int
cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item, cmd_display_menu_get_pos(struct client *tc, struct cmdq_item *item,
struct args *args, u_int *px, u_int *py, u_int w, u_int h) struct args *args, u_int *px, u_int *py, u_int w, u_int h)
{ {
struct tty *tty = &tc->tty; struct tty *tty = &tc->tty;
@@ -353,8 +353,8 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
menu_free(menu); menu_free(menu);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, menu->width + 4,
menu->width + 4, menu->count + 2)) { menu->count + 2)) {
menu_free(menu); menu_free(menu);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
@@ -392,8 +392,10 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
const char *value, *shell, *shellcmd = NULL; const char *value, *shell, *shellcmd = NULL;
const char *style = args_get(args, 's'); const char *style = args_get(args, 's');
const char *border_style = args_get(args, 'S'); const char *border_style = args_get(args, 'S');
char *cwd, *cause = NULL, **argv = NULL, *title; char *cwd = NULL, *cause = NULL, **argv = NULL;
int flags = 0, argc = 0; char *title;
int modify = popup_present(tc);
int flags = -1, argc = 0;
enum box_lines lines = BOX_LINES_DEFAULT; enum box_lines lines = BOX_LINES_DEFAULT;
u_int px, py, w, h, count = args_count(args); u_int px, py, w, h, count = args_count(args);
struct args_value *av; struct args_value *av;
@@ -405,36 +407,68 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
server_client_clear_overlay(tc); server_client_clear_overlay(tc);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
if (tc->overlay_draw != NULL) if (!modify && tc->overlay_draw != NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
h = tty->sy / 2; if (!modify) {
if (args_has(args, 'h')) { h = tty->sy / 2;
h = args_percentage(args, 'h', 1, tty->sy, tty->sy, &cause); if (args_has(args, 'h')) {
if (cause != NULL) { h = args_percentage(args, 'h', 1, tty->sy, tty->sy,
cmdq_error(item, "height %s", cause); &cause);
free(cause); if (cause != NULL) {
return (CMD_RETURN_ERROR); cmdq_error(item, "height %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
w = tty->sx / 2;
if (args_has(args, 'w')) {
w = args_percentage(args, 'w', 1, tty->sx, tty->sx,
&cause);
if (cause != NULL) {
cmdq_error(item, "width %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
if (w > tty->sx)
w = tty->sx;
if (h > tty->sy)
h = tty->sy;
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, w, h))
return (CMD_RETURN_NORMAL);
value = args_get(args, 'd');
if (value != NULL)
cwd = format_single_from_target(item, value);
else
cwd = xstrdup(server_client_get_cwd(tc, s));
if (count == 0) {
shellcmd = options_get_string(s->options,
"default-command");
} else if (count == 1)
shellcmd = args_string(args, 0);
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
shellcmd = NULL;
shell = options_get_string(s->options, "default-shell");
if (!checkshell(shell))
shell = _PATH_BSHELL;
cmd_append_argv(&argc, &argv, shell);
} else
args_to_vector(args, &argc, &argv);
if (args_has(args, 'e') >= 1) {
env = environ_create();
av = args_first_value(args, 'e');
while (av != NULL) {
environ_put(env, av->string, 0);
av = args_next_value(av);
}
} }
} }
w = tty->sx / 2;
if (args_has(args, 'w')) {
w = args_percentage(args, 'w', 1, tty->sx, tty->sx, &cause);
if (cause != NULL) {
cmdq_error(item, "width %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
}
if (w > tty->sx)
w = tty->sx;
if (h > tty->sy)
h = tty->sy;
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
return (CMD_RETURN_NORMAL);
value = args_get(args, 'b'); value = args_get(args, 'b');
if (args_has(args, 'B')) if (args_has(args, 'B'))
lines = BOX_LINES_NONE; lines = BOX_LINES_NONE;
@@ -449,41 +483,33 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
} }
} }
value = args_get(args, 'd');
if (value != NULL)
cwd = format_single_from_target(item, value);
else
cwd = xstrdup(server_client_get_cwd(tc, s));
if (count == 0)
shellcmd = options_get_string(s->options, "default-command");
else if (count == 1)
shellcmd = args_string(args, 0);
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
shellcmd = NULL;
shell = options_get_string(s->options, "default-shell");
if (!checkshell(shell))
shell = _PATH_BSHELL;
cmd_append_argv(&argc, &argv, shell);
} else
args_to_vector(args, &argc, &argv);
if (args_has(args, 'e') >= 1) {
env = environ_create();
av = args_first_value(args, 'e');
while (av != NULL) {
environ_put(env, av->string, 0);
av = args_next_value(av);
}
}
if (args_has(args, 'T')) if (args_has(args, 'T'))
title = format_single_from_target(item, args_get(args, 'T')); title = format_single_from_target(item, args_get(args, 'T'));
else else
title = xstrdup(""); title = xstrdup("");
if (args_has(args, 'E') > 1)
if (args_has(args, 'N') || !modify)
flags = 0;
if (args_has(args, 'E') > 1) {
if (flags == -1)
flags = 0;
flags |= POPUP_CLOSEEXITZERO; flags |= POPUP_CLOSEEXITZERO;
else if (args_has(args, 'E')) } else if (args_has(args, 'E')) {
if (flags == -1)
flags = 0;
flags |= POPUP_CLOSEEXIT; flags |= POPUP_CLOSEEXIT;
}
if (args_has(args, 'k')) {
if (flags == -1)
flags = 0;
flags |= POPUP_CLOSEANYKEY;
}
if (modify) {
popup_modify(tc, title, style, border_style, lines, flags);
free(title);
return (CMD_RETURN_NORMAL);
}
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc, if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) { argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) {
cmd_free_argv(argc, argv); cmd_free_argv(argc, argv);

View File

@@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
.name = "display-message", .name = "display-message",
.alias = "display", .alias = "display",
.args = { "ac:d:lINpt:F:v", 0, 1, NULL }, .args = { "aCc:d:lINpt:F:v", 0, 1, NULL },
.usage = "[-aIlNpv] [-c target-client] [-d delay] [-F format] " .usage = "[-aCIlNpv] [-c target-client] [-d delay] [-F format] "
CMD_TARGET_PANE_USAGE " [message]", CMD_TARGET_PANE_USAGE " [message]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
@@ -69,6 +69,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
const char *template; const char *template;
char *msg, *cause; char *msg, *cause;
int delay = -1, flags, Nflag = args_has(args, 'N'); int delay = -1, flags, Nflag = args_has(args, 'N');
int Cflag = args_has(args, 'C');
struct format_tree *ft; struct format_tree *ft;
u_int count = args_count(args); u_int count = args_count(args);
struct evbuffer *evb; struct evbuffer *evb;
@@ -150,7 +151,7 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
server_client_print(tc, 0, evb); server_client_print(tc, 0, evb);
evbuffer_free(evb); evbuffer_free(evb);
} else if (tc != NULL) } else if (tc != NULL)
status_message_set(tc, delay, 0, Nflag, "%s", msg); status_message_set(tc, delay, 0, Nflag, Cflag, "%s", msg);
free(msg); free(msg);
format_free(ft); format_free(ft);

View File

@@ -124,7 +124,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
-1) == NULL) { -1) == NULL) {
cmdq_error(item, "failed to run command: %s", shellcmd); cmdq_error(item, "failed to run command: %s", shellcmd);
free(shellcmd); free(shellcmd);
free(cdata); cmd_if_shell_free(cdata);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
free(shellcmd); free(shellcmd);
@@ -157,7 +157,7 @@ cmd_if_shell_callback(struct job *job)
if (cmdlist == NULL) { if (cmdlist == NULL) {
if (cdata->item == NULL) { if (cdata->item == NULL) {
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, 0, "%s", error); status_message_set(c, -1, 1, 0, 0, "%s", error);
} else } else
cmdq_error(cdata->item, "%s", error); cmdq_error(cdata->item, "%s", error);
free(error); free(error);

View File

@@ -149,7 +149,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
src_wp->window = dst_w; src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options); options_set_parent(src_wp->options, dst_w->options);
src_wp->flags |= PANE_STYLECHANGED; src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
if (flags & SPAWN_BEFORE) if (flags & SPAWN_BEFORE)
TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry); TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry);
else else

View File

@@ -91,7 +91,7 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
struct key_binding *bd; struct key_binding *bd;
const char *key; const char *key;
char *tmp, *note; char *tmp, *note;
int found = 0; int found = 0;
table = key_bindings_get_table(tablename, 0); table = key_bindings_get_table(tablename, 0);
if (table == NULL) if (table == NULL)
@@ -114,8 +114,8 @@ cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
note = xstrdup(bd->note); note = xstrdup(bd->note);
tmp = utf8_padcstr(key, keywidth + 1); tmp = utf8_padcstr(key, keywidth + 1);
if (args_has(args, '1') && tc != NULL) { if (args_has(args, '1') && tc != NULL) {
status_message_set(tc, -1, 1, 0, "%s%s%s", prefix, tmp, status_message_set(tc, -1, 1, 0, 0, "%s%s%s", prefix,
note); tmp, note);
} else } else
cmdq_print(item, "%s%s%s", prefix, tmp, note); cmdq_print(item, "%s%s%s", prefix, tmp, note);
free(tmp); free(tmp);
@@ -298,8 +298,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
free(cp); free(cp);
if (args_has(args, '1') && tc != NULL) { if (args_has(args, '1') && tc != NULL) {
status_message_set(tc, -1, 1, 0, "bind-key %s", status_message_set(tc, -1, 1, 0, 0,
tmp); "bind-key %s", tmp);
} else } else
cmdq_print(item, "bind-key %s", tmp); cmdq_print(item, "bind-key %s", tmp);
free(key); free(key);
@@ -321,6 +321,31 @@ out:
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
static void
cmd_list_single_command(const struct cmd_entry *entry, struct format_tree *ft,
const char *template, struct cmdq_item *item)
{
const char *s;
char *line;
format_add(ft, "command_list_name", "%s", entry->name);
if (entry->alias != NULL)
s = entry->alias;
else
s = "";
format_add(ft, "command_list_alias", "%s", s);
if (entry->usage != NULL)
s = entry->usage;
else
s = "";
format_add(ft, "command_list_usage", "%s", s);
line = format_expand(ft, template);
if (*line != '\0')
cmdq_print(item, "%s", line);
free(line);
}
static enum cmd_retval static enum cmd_retval
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item) cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
{ {
@@ -328,8 +353,8 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
const struct cmd_entry **entryp; const struct cmd_entry **entryp;
const struct cmd_entry *entry; const struct cmd_entry *entry;
struct format_tree *ft; struct format_tree *ft;
const char *template, *s, *command; const char *template, *command;
char *line; char *cause;
if ((template = args_get(args, 'F')) == NULL) { if ((template = args_get(args, 'F')) == NULL) {
template = "#{command_list_name}" template = "#{command_list_name}"
@@ -341,30 +366,19 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
format_defaults(ft, NULL, NULL, NULL, NULL); format_defaults(ft, NULL, NULL, NULL, NULL);
command = args_string(args, 0); command = args_string(args, 0);
for (entryp = cmd_table; *entryp != NULL; entryp++) { if (command == NULL) {
entry = *entryp; for (entryp = cmd_table; *entryp != NULL; entryp++)
if (command != NULL && cmd_list_single_command(*entryp, ft, template, item);
(strcmp(entry->name, command) != 0 && } else {
(entry->alias == NULL || entry = cmd_find(command, &cause);
strcmp(entry->alias, command) != 0))) if (entry != NULL)
continue; cmd_list_single_command(entry, ft, template, item);
else {
format_add(ft, "command_list_name", "%s", entry->name); cmdq_error(item, "%s", cause);
if (entry->alias != NULL) free(cause);
s = entry->alias; format_free(ft);
else return (CMD_RETURN_ERROR);
s = ""; }
format_add(ft, "command_list_alias", "%s", s);
if (entry->usage != NULL)
s = entry->usage;
else
s = "";
format_add(ft, "command_list_usage", "%s", s);
line = format_expand(ft, template);
if (*line != '\0')
cmdq_print(item, "%s", line);
free(line);
} }
format_free(ft); format_free(ft);

View File

@@ -66,7 +66,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
return; return;
if (error != 0) if (error != 0)
cmdq_error(item, "%s: %s", path, strerror(error)); cmdq_error(item, "%s: %s", strerror(error), path);
else if (bsize != 0) { else if (bsize != 0) {
copy = xmalloc(bsize); copy = xmalloc(bsize);
memcpy(copy, bdata, bsize); memcpy(copy, bdata, bsize);

View File

@@ -43,7 +43,7 @@ const struct cmd_entry cmd_new_session_entry = {
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] " .usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
"[-f flags] [-n window-name] [-s session-name] " "[-f flags] [-n window-name] [-s session-name] "
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] " CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
"[shell-command]", "[shell-command [argument ...]]",
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },

View File

@@ -40,7 +40,8 @@ const struct cmd_entry cmd_new_window_entry = {
.args = { "abc:de:F:kn:PSt:", 0, -1, NULL }, .args = { "abc:de:F:kn:PSt:", 0, -1, NULL },
.usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] " .usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] "
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [shell-command]", "[-n window-name] " CMD_TARGET_WINDOW_USAGE
" [shell-command [argument ...]]",
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX }, .target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },

View File

@@ -32,7 +32,7 @@
static int yylex(void); static int yylex(void);
static int yyparse(void); static int yyparse(void);
static int printflike(1,2) yyerror(const char *, ...); static void printflike(1,2) yyerror(const char *, ...);
static char *yylex_token(int); static char *yylex_token(int);
static char *yylex_format(void); static char *yylex_format(void);
@@ -223,9 +223,16 @@ assignment : EQUALS
{ {
struct cmd_parse_state *ps = &parse_state; struct cmd_parse_state *ps = &parse_state;
int flags = ps->input->flags; int flags = ps->input->flags;
int flag = 1;
struct cmd_parse_scope *scope;
if ((~flags & CMD_PARSE_PARSEONLY) && if (ps->scope != NULL) {
(ps->scope == NULL || ps->scope->flag)) flag = ps->scope->flag;
TAILQ_FOREACH(scope, &ps->stack, entry)
flag = flag && scope->flag;
}
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
environ_put(global_environ, $1, 0); environ_put(global_environ, $1, 0);
free($1); free($1);
} }
@@ -234,9 +241,16 @@ hidden_assignment : HIDDEN EQUALS
{ {
struct cmd_parse_state *ps = &parse_state; struct cmd_parse_state *ps = &parse_state;
int flags = ps->input->flags; int flags = ps->input->flags;
int flag = 1;
struct cmd_parse_scope *scope;
if ((~flags & CMD_PARSE_PARSEONLY) && if (ps->scope != NULL) {
(ps->scope == NULL || ps->scope->flag)) flag = ps->scope->flag;
TAILQ_FOREACH(scope, &ps->stack, entry)
flag = flag && scope->flag;
}
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
environ_put(global_environ, $2, ENVIRON_HIDDEN); environ_put(global_environ, $2, ENVIRON_HIDDEN);
free($2); free($2);
} }
@@ -835,7 +849,7 @@ cmd_parse_build_command(struct cmd_parse_command *cmd,
count++; count++;
} }
add = cmd_parse(values, count, pi->file, pi->line, &cause); add = cmd_parse(values, count, pi->file, pi->line, pi->flags, &cause);
if (add == NULL) { if (add == NULL) {
pr->status = CMD_PARSE_ERROR; pr->status = CMD_PARSE_ERROR;
pr->error = cmd_parse_get_error(pi->file, pi->line, cause); pr->error = cmd_parse_get_error(pi->file, pi->line, cause);
@@ -1113,7 +1127,7 @@ cmd_parse_from_arguments(struct args_value *values, u_int count,
return (&pr); return (&pr);
} }
static int printflike(1, 2) static void printflike(1, 2)
yyerror(const char *fmt, ...) yyerror(const char *fmt, ...)
{ {
struct cmd_parse_state *ps = &parse_state; struct cmd_parse_state *ps = &parse_state;
@@ -1122,7 +1136,7 @@ yyerror(const char *fmt, ...)
char *error; char *error;
if (ps->error != NULL) if (ps->error != NULL)
return (0); return;
va_start(ap, fmt); va_start(ap, fmt);
xvasprintf(&error, fmt, ap); xvasprintf(&error, fmt, ap);
@@ -1130,7 +1144,6 @@ yyerror(const char *fmt, ...)
ps->error = cmd_parse_get_error(pi->file, pi->line, error); ps->error = cmd_parse_get_error(pi->file, pi->line, error);
free(error); free(error);
return (0);
} }
static int static int
@@ -1613,6 +1626,7 @@ yylex_token_tilde(char **buf, size_t *len)
static char * static char *
yylex_token(int ch) yylex_token(int ch)
{ {
struct cmd_parse_state *ps = &parse_state;
char *buf; char *buf;
size_t len; size_t len;
enum { START, enum { START,
@@ -1636,9 +1650,12 @@ yylex_token(int ch)
ch = '\r'; ch = '\r';
} }
} }
if (state == NONE && ch == '\n') { if (ch == '\n') {
log_debug("%s: end at EOL", __func__); if (state == NONE) {
break; log_debug("%s: end at EOL", __func__);
break;
}
ps->input->line++;
} }
/* Whitespace or ; or } ends a token unless inside quotes. */ /* Whitespace or ; or } ends a token unless inside quotes. */

View File

@@ -834,9 +834,9 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
/* Show message from command. */ /* Show message from command. */
void void
cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb) cmdq_print_data(struct cmdq_item *item, struct evbuffer *evb)
{ {
server_client_print(item->client, parse, evb); server_client_print(item->client, 1, evb);
} }
/* Show message from command. */ /* Show message from command. */
@@ -854,7 +854,7 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
evbuffer_add_vprintf(evb, fmt, ap); evbuffer_add_vprintf(evb, fmt, ap);
va_end(ap); va_end(ap);
cmdq_print_data(item, 0, evb); cmdq_print_data(item, evb);
evbuffer_free(evb); evbuffer_free(evb);
} }
@@ -892,7 +892,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
c->retval = 1; c->retval = 1;
} else { } else {
*msg = toupper((u_char) *msg); *msg = toupper((u_char) *msg);
status_message_set(c, -1, 1, 0, "%s", msg); status_message_set(c, -1, 1, 0, 0, "%s", msg);
} }
free(msg); free(msg);

View File

@@ -36,7 +36,7 @@ const struct cmd_entry cmd_refresh_client_entry = {
.args = { "A:B:cC:Df:r:F:l::LRSt:U", 0, 1, NULL }, .args = { "A:B:cC:Df:r:F:l::LRSt:U", 0, 1, NULL },
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] " .usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
"[-C XxY] [-f flags] [-r pane:report]" CMD_TARGET_CLIENT_USAGE "[-C XxY] [-f flags] [-r pane:report] " CMD_TARGET_CLIENT_USAGE
" [adjustment]", " [adjustment]",
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,

View File

@@ -36,7 +36,7 @@ const struct cmd_entry cmd_respawn_pane_entry = {
.args = { "c:e:kt:", 0, -1, NULL }, .args = { "c:e:kt:", 0, -1, NULL },
.usage = "[-k] [-c start-directory] [-e environment] " .usage = "[-k] [-c start-directory] [-e environment] "
CMD_TARGET_PANE_USAGE " [shell-command]", CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },

View File

@@ -36,7 +36,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
.args = { "c:e:kt:", 0, -1, NULL }, .args = { "c:e:kt:", 0, -1, NULL },
.usage = "[-k] [-c start-directory] [-e environment] " .usage = "[-k] [-c start-directory] [-e environment] "
CMD_TARGET_WINDOW_USAGE " [shell-command]", CMD_TARGET_WINDOW_USAGE " [shell-command [argument ...]]",
.target = { 't', CMD_FIND_WINDOW, 0 }, .target = { 't', CMD_FIND_WINDOW, 0 },

View File

@@ -44,8 +44,8 @@ const struct cmd_entry cmd_run_shell_entry = {
.name = "run-shell", .name = "run-shell",
.alias = "run", .alias = "run",
.args = { "bd:Ct:c:", 0, 2, cmd_run_shell_args_parse }, .args = { "bd:Ct:Es:c:", 0, 1, cmd_run_shell_args_parse },
.usage = "[-bC] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE .usage = "[-bCE] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
" [shell-command]", " [shell-command]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
@@ -158,6 +158,9 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
else else
cdata->cwd = xstrdup(server_client_get_cwd(c, s)); cdata->cwd = xstrdup(server_client_get_cwd(c, s));
if (args_has(args, 'E'))
cdata->flags |= JOB_SHOWSTDERR;
cdata->s = s; cdata->s = s;
if (s != NULL) if (s != NULL)
session_add_ref(s, __func__); session_add_ref(s, __func__);
@@ -204,7 +207,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
if (cmdlist == NULL) { if (cmdlist == NULL) {
if (cdata->item == NULL) { if (cdata->item == NULL) {
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, 0, "%s", error); status_message_set(c, -1, 1, 0, 0, "%s", error);
} else } else
cmdq_error(cdata->item, "%s", error); cmdq_error(cdata->item, "%s", error);
free(error); free(error);

View File

@@ -65,7 +65,7 @@ cmd_save_buffer_done(__unused struct client *c, const char *path, int error,
return; return;
if (error != 0) if (error != 0)
cmdq_error(item, "%s: %s", path, strerror(error)); cmdq_error(item, "%s: %s", strerror(error), path);
cmdq_continue(item); cmdq_continue(item);
} }
@@ -101,7 +101,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
if (evb == NULL) if (evb == NULL)
fatalx("out of memory"); fatalx("out of memory");
evbuffer_add(evb, bufdata, bufsize); evbuffer_add(evb, bufdata, bufsize);
cmdq_print_data(item, 1, evb); cmdq_print_data(item, evb);
evbuffer_free(evb); evbuffer_free(evb);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@@ -149,12 +149,14 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
markedwp = marked_pane.wp; markedwp = marked_pane.wp;
if (lastwp != NULL) { if (lastwp != NULL) {
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|
PANE_THEMECHANGED);
server_redraw_window_borders(lastwp->window); server_redraw_window_borders(lastwp->window);
server_status_window(lastwp->window); server_status_window(lastwp->window);
} }
if (markedwp != NULL) { if (markedwp != NULL) {
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|
PANE_THEMECHANGED);
server_redraw_window_borders(markedwp->window); server_redraw_window_borders(markedwp->window);
server_status_window(markedwp->window); server_status_window(markedwp->window);
} }
@@ -169,7 +171,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
options_set_string(oo, "window-active-style", 0, "%s", style); options_set_string(oo, "window-active-style", 0, "%s", style);
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED); wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|PANE_THEMECHANGED);
} }
if (args_has(args, 'g')) { if (args_has(args, 'g')) {
cmdq_print(item, "%s", options_get_string(oo, "window-style")); cmdq_print(item, "%s", options_get_string(oo, "window-style"));

View File

@@ -35,7 +35,7 @@ const struct cmd_entry cmd_send_keys_entry = {
.args = { "c:FHKlMN:Rt:X", 0, -1, NULL }, .args = { "c:FHKlMN:Rt:X", 0, -1, NULL },
.usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] " .usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] "
CMD_TARGET_PANE_USAGE " key ...", CMD_TARGET_PANE_USAGE " [key ...]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@@ -73,11 +73,13 @@ cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
if (args_has(args, 'K')) { if (args_has(args, 'K')) {
if (tc == NULL) if (tc == NULL)
return (item); return (item);
event = xmalloc(sizeof *event); event = xcalloc(1, sizeof *event);
event->key = key|KEYC_SENT; event->key = key|KEYC_SENT;
memset(&event->m, 0, sizeof event->m); memset(&event->m, 0, sizeof event->m);
if (server_client_handle_key(tc, event) == 0) if (server_client_handle_key(tc, event) == 0) {
free(event->buf);
free(event); free(event);
}
return (item); return (item);
} }
@@ -215,7 +217,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'R')) { if (args_has(args, 'R')) {
colour_palette_clear(&wp->palette); colour_palette_clear(&wp->palette);
input_reset(wp->ictx, 1); input_reset(wp->ictx, 1);
wp->flags |= (PANE_STYLECHANGED|PANE_REDRAW); wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED|PANE_REDRAW);
} }
if (count == 0) { if (count == 0) {

View File

@@ -35,7 +35,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
.args = { "ab:t:n:w", 0, 1, NULL }, .args = { "ab:t:n:w", 0, 1, NULL },
.usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] " .usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
CMD_TARGET_CLIENT_USAGE " data", CMD_TARGET_CLIENT_USAGE " [data]",
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL, .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_set_buffer_exec .exec = cmd_set_buffer_exec

View File

@@ -35,7 +35,7 @@ const struct cmd_entry cmd_set_environment_entry = {
.alias = "setenv", .alias = "setenv",
.args = { "Fhgrt:u", 1, 2, NULL }, .args = { "Fhgrt:u", 1, 2, NULL },
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]", .usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " variable [value]",
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },

View File

@@ -39,7 +39,7 @@ const struct cmd_entry cmd_show_environment_entry = {
.alias = "showenv", .alias = "showenv",
.args = { "hgst:", 0, 1, NULL }, .args = { "hgst:", 0, 1, NULL },
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]", .usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [variable]",
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },

View File

@@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_messages_entry = {
.args = { "JTt:", 0, 0, NULL }, .args = { "JTt:", 0, 0, NULL },
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE, .usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG, .flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
.exec = cmd_show_messages_exec .exec = cmd_show_messages_exec
}; };
@@ -55,7 +55,7 @@ cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank)
n = 0; n = 0;
LIST_FOREACH(term, &tty_terms, entry) { LIST_FOREACH(term, &tty_terms, entry) {
if (args_has(args, 't') && term != tc->tty.term) if (args_has(args, 't') && tc != NULL && term != tc->tty.term)
continue; continue;
if (blank) { if (blank) {
cmdq_print(item, "%s", ""); cmdq_print(item, "%s", "");

View File

@@ -65,7 +65,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
.alias = NULL, .alias = NULL,
.args = { "gpt:w", 0, 1, NULL }, .args = { "gpt:w", 0, 1, NULL },
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE, .usage = "[-gpw] " CMD_TARGET_PANE_USAGE " [hook]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL }, .target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },

View File

@@ -32,7 +32,7 @@ const struct cmd_entry cmd_show_prompt_history_entry = {
.alias = "showphist", .alias = "showphist",
.args = { "T:", 0, 0, NULL }, .args = { "T:", 0, 0, NULL },
.usage = "[-T type]", .usage = "[-T prompt-type]",
.flags = CMD_AFTERHOOK, .flags = CMD_AFTERHOOK,
.exec = cmd_show_prompt_history_exec .exec = cmd_show_prompt_history_exec
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_clear_prompt_history_entry = {
.alias = "clearphist", .alias = "clearphist",
.args = { "T:", 0, 0, NULL }, .args = { "T:", 0, 0, NULL },
.usage = "[-T type]", .usage = "[-T prompt-type]",
.flags = CMD_AFTERHOOK, .flags = CMD_AFTERHOOK,
.exec = cmd_show_prompt_history_exec .exec = cmd_show_prompt_history_exec

View File

@@ -18,6 +18,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <ctype.h>
#include <errno.h> #include <errno.h>
#include <glob.h> #include <glob.h>
#include <stdlib.h> #include <stdlib.h>
@@ -29,6 +30,9 @@
* Sources a configuration file. * Sources a configuration file.
*/ */
#define CMD_SOURCE_FILE_DEPTH_LIMIT 50
static u_int cmd_source_file_depth;
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *); static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
const struct cmd_entry cmd_source_file_entry = { const struct cmd_entry cmd_source_file_entry = {
@@ -59,6 +63,16 @@ struct cmd_source_file_data {
static enum cmd_retval static enum cmd_retval
cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data) cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data)
{ {
struct client *c = cmdq_get_client(item);
if (c == NULL) {
cmd_source_file_depth--;
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
} else {
c->source_file_depth--;
log_debug("%s: depth now %u", __func__, c->source_file_depth);
}
cfg_print_causes(item); cfg_print_causes(item);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }
@@ -100,7 +114,7 @@ cmd_source_file_done(struct client *c, const char *path, int error,
return; return;
if (error != 0) if (error != 0)
cmdq_error(item, "%s: %s", path, strerror(error)); cmdq_error(item, "%s: %s", strerror(error), path);
else if (bsize != 0) { else if (bsize != 0) {
if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after, if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after,
target, cdata->flags, &new_item) < 0) target, cdata->flags, &new_item) < 0)
@@ -127,6 +141,21 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
cdata->files[cdata->nfiles++] = xstrdup(path); cdata->files[cdata->nfiles++] = xstrdup(path);
} }
static char *
cmd_source_file_quote_for_glob(const char *path)
{
char *quoted = xmalloc(2 * strlen(path) + 1), *q = quoted;
const char *p = path;
while (*p != '\0') {
if ((u_char)*p < 128 && !isalnum((u_char)*p) && *p != '/')
*q++ = '\\';
*q++ = *p++;
}
*q = '\0';
return (quoted);
}
static enum cmd_retval static enum cmd_retval
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
{ {
@@ -137,9 +166,25 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
char *pattern, *cwd, *expanded = NULL; char *pattern, *cwd, *expanded = NULL;
const char *path, *error; const char *path, *error;
glob_t g; glob_t g;
int result; int result, parse_flags;
u_int i, j; u_int i, j;
if (c == NULL) {
if (cmd_source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
cmdq_error(item, "too many nested files");
return (CMD_RETURN_ERROR);
}
cmd_source_file_depth++;
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
} else {
if (c->source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
cmdq_error(item, "too many nested files");
return (CMD_RETURN_ERROR);
}
c->source_file_depth++;
log_debug("%s: depth now %u", __func__, c->source_file_depth);
}
cdata = xcalloc(1, sizeof *cdata); cdata = xcalloc(1, sizeof *cdata);
cdata->item = item; cdata->item = item;
@@ -147,10 +192,13 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
cdata->flags |= CMD_PARSE_QUIET; cdata->flags |= CMD_PARSE_QUIET;
if (args_has(args, 'n')) if (args_has(args, 'n'))
cdata->flags |= CMD_PARSE_PARSEONLY; cdata->flags |= CMD_PARSE_PARSEONLY;
if (args_has(args, 'v')) if (c == NULL || ~c->flags & CLIENT_CONTROL) {
cdata->flags |= CMD_PARSE_VERBOSE; parse_flags = cmd_get_parse_flags(self);
if (args_has(args, 'v') || (parse_flags & CMD_PARSE_VERBOSE))
cdata->flags |= CMD_PARSE_VERBOSE;
}
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB); cwd = cmd_source_file_quote_for_glob(server_client_get_cwd(c, NULL));
for (i = 0; i < args_count(args); i++) { for (i = 0; i < args_count(args); i++) {
path = args_string(args, i); path = args_string(args, i);
@@ -179,7 +227,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
error = strerror(ENOMEM); error = strerror(ENOMEM);
else else
error = strerror(EINVAL); error = strerror(EINVAL);
cmdq_error(item, "%s: %s", path, error); cmdq_error(item, "%s: %s", error, path);
retval = CMD_RETURN_ERROR; retval = CMD_RETURN_ERROR;
} }
globfree(&g); globfree(&g);

View File

@@ -42,7 +42,7 @@ const struct cmd_entry cmd_split_window_entry = {
.args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1, NULL }, .args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1, NULL },
.usage = "[-bdefhIPvZ] [-c start-directory] [-e environment] " .usage = "[-bdefhIPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] " CMD_TARGET_PANE_USAGE "[-F format] [-l size] " CMD_TARGET_PANE_USAGE
"[shell-command]", " [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },

View File

@@ -101,10 +101,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
src_wp->window = dst_w; src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options); options_set_parent(src_wp->options, dst_w->options);
src_wp->flags |= PANE_STYLECHANGED; src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
dst_wp->window = src_w; dst_wp->window = src_w;
options_set_parent(dst_wp->options, src_w->options); options_set_parent(dst_wp->options, src_w->options);
dst_wp->flags |= PANE_STYLECHANGED; dst_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
sx = src_wp->sx; sy = src_wp->sy; sx = src_wp->sx; sy = src_wp->sy;
xoff = src_wp->xoff; yoff = src_wp->yoff; xoff = src_wp->xoff; yoff = src_wp->yoff;
@@ -132,9 +132,12 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
window_pane_stack_remove(&dst_w->last_panes, dst_wp); window_pane_stack_remove(&dst_w->last_panes, dst_wp);
colour_palette_from_option(&src_wp->palette, src_wp->options); colour_palette_from_option(&src_wp->palette, src_wp->options);
colour_palette_from_option(&dst_wp->palette, dst_wp->options); colour_palette_from_option(&dst_wp->palette, dst_wp->options);
layout_fix_panes(src_w, NULL);
server_redraw_window(src_w);
} }
server_redraw_window(src_w); layout_fix_panes(dst_w, NULL);
server_redraw_window(dst_w); server_redraw_window(dst_w);
notify_window("window-layout-changed", src_w); notify_window("window-layout-changed", src_w);
if (src_w != dst_w) if (src_w != dst_w)
notify_window("window-layout-changed", dst_w); notify_window("window-layout-changed", dst_w);

View File

@@ -77,6 +77,8 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
wl_src->window = w_dst; wl_src->window = w_dst;
TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry); TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry);
if (marked_pane.wl == wl_src)
marked_pane.wl = wl_dst;
if (args_has(args, 'd')) { if (args_has(args, 'd')) {
session_select(dst, wl_dst->idx); session_select(dst, wl_dst->idx);
if (src != dst) if (src != dst)

View File

@@ -61,7 +61,8 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
const char *tablename; const char *tablename;
struct key_table *table; struct key_table *table;
if (tflag != NULL && tflag[strcspn(tflag, ":.%")] != '\0') { if (tflag != NULL &&
(tflag[strcspn(tflag, ":.%")] != '\0' || strcmp(tflag, "=") == 0)) {
type = CMD_FIND_PANE; type = CMD_FIND_PANE;
flags = 0; flags = 0;
} else { } else {

17
cmd.c
View File

@@ -220,6 +220,7 @@ struct cmd {
char *file; char *file;
u_int line; u_int line;
int parse_flags;
TAILQ_ENTRY(cmd) qentry; TAILQ_ENTRY(cmd) qentry;
}; };
@@ -412,6 +413,13 @@ cmd_get_source(struct cmd *cmd, const char **file, u_int *line)
*line = cmd->line; *line = cmd->line;
} }
/* Get parse flags for command. */
int
cmd_get_parse_flags(struct cmd *cmd)
{
return (cmd->parse_flags);
}
/* Look for an alias for a command. */ /* Look for an alias for a command. */
char * char *
cmd_get_alias(const char *name) cmd_get_alias(const char *name)
@@ -444,7 +452,7 @@ cmd_get_alias(const char *name)
} }
/* Look up a command entry by name. */ /* Look up a command entry by name. */
static const struct cmd_entry * const struct cmd_entry *
cmd_find(const char *name, char **cause) cmd_find(const char *name, char **cause)
{ {
const struct cmd_entry **loop, *entry, *found = NULL; const struct cmd_entry **loop, *entry, *found = NULL;
@@ -496,7 +504,7 @@ ambiguous:
/* Parse a single command from an argument vector. */ /* Parse a single command from an argument vector. */
struct cmd * struct cmd *
cmd_parse(struct args_value *values, u_int count, const char *file, u_int line, cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
char **cause) int parse_flags, char **cause)
{ {
const struct cmd_entry *entry; const struct cmd_entry *entry;
struct cmd *cmd; struct cmd *cmd;
@@ -525,6 +533,7 @@ cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
cmd = xcalloc(1, sizeof *cmd); cmd = xcalloc(1, sizeof *cmd);
cmd->entry = entry; cmd->entry = entry;
cmd->args = args; cmd->args = args;
cmd->parse_flags = parse_flags;
if (file != NULL) if (file != NULL)
cmd->file = xstrdup(file); cmd->file = xstrdup(file);
@@ -636,7 +645,7 @@ cmd_list_free(struct cmd_list *cmdlist)
/* Copy a command list, expanding %s in arguments. */ /* Copy a command list, expanding %s in arguments. */
struct cmd_list * struct cmd_list *
cmd_list_copy(struct cmd_list *cmdlist, int argc, char **argv) cmd_list_copy(const struct cmd_list *cmdlist, int argc, char **argv)
{ {
struct cmd *cmd; struct cmd *cmd;
struct cmd_list *new_cmdlist; struct cmd_list *new_cmdlist;
@@ -667,7 +676,7 @@ cmd_list_copy(struct cmd_list *cmdlist, int argc, char **argv)
/* Get a command list as a string. */ /* Get a command list as a string. */
char * char *
cmd_list_print(struct cmd_list *cmdlist, int escaped) cmd_list_print(const struct cmd_list *cmdlist, int escaped)
{ {
struct cmd *cmd, *next; struct cmd *cmd, *next;
char *buf, *this; char *buf, *this;

View File

@@ -182,6 +182,46 @@ colour_tostring(int c)
return ("invalid"); return ("invalid");
} }
/* Convert background colour to theme. */
enum client_theme
colour_totheme(int c)
{
int r, g, b, brightness;
if (c == -1)
return (THEME_UNKNOWN);
if (c & COLOUR_FLAG_RGB) {
r = (c >> 16) & 0xff;
g = (c >> 8) & 0xff;
b = (c >> 0) & 0xff;
brightness = r + g + b;
if (brightness > 382)
return (THEME_LIGHT);
return (THEME_DARK);
}
if (c & COLOUR_FLAG_256)
return (colour_totheme(colour_256toRGB(c)));
switch (c) {
case 0:
case 90:
return (THEME_DARK);
case 7:
case 97:
return (THEME_LIGHT);
default:
if (c >= 0 && c <= 7)
return (colour_totheme(colour_256toRGB(c)));
if (c >= 90 && c <= 97)
return (colour_totheme(colour_256toRGB(8 + c - 90)));
break;
}
return (THEME_UNKNOWN);
}
/* Convert colour from string. */ /* Convert colour from string. */
int int
colour_fromstring(const char *s) colour_fromstring(const char *s)
@@ -946,7 +986,8 @@ colour_byname(const char *name)
int c; int c;
const char *errstr; const char *errstr;
if (strncmp(name, "grey", 4) == 0 || strncmp(name, "gray", 4) == 0) { if (strncasecmp(name, "grey", 4) == 0 ||
strncasecmp(name, "gray", 4) == 0) {
if (name[4] == '\0') if (name[4] == '\0')
return (0xbebebe|COLOUR_FLAG_RGB); return (0xbebebe|COLOUR_FLAG_RGB);
c = strtonum(name + 4, 0, 100, &errstr); c = strtonum(name + 4, 0, 100, &errstr);

View File

@@ -38,6 +38,14 @@
#include <event2/bufferevent_compat.h> #include <event2/bufferevent_compat.h>
#else #else
#include <event.h> #include <event.h>
#ifndef EVBUFFER_EOL_LF
/*
* This doesn't really work because evbuffer_readline is broken, but gets us to
* build with very old (older than 1.4.14) libevent.
*/
#define EVBUFFER_EOL_LF
#define evbuffer_readln(a, b, c) evbuffer_readline(a)
#endif
#endif #endif
#ifdef HAVE_MALLOC_TRIM #ifdef HAVE_MALLOC_TRIM
@@ -442,7 +450,7 @@ void *recallocarray(void *, size_t, size_t, size_t);
/* systemd.c */ /* systemd.c */
int systemd_activated(void); int systemd_activated(void);
int systemd_create_socket(int, char **); int systemd_create_socket(int, char **);
int systemd_move_pid_to_new_cgroup(pid_t, char **); int systemd_move_to_new_cgroup(char **);
#endif #endif
#ifdef HAVE_UTF8PROC #ifdef HAVE_UTF8PROC
@@ -458,11 +466,11 @@ int utf8proc_wctomb(char *, wchar_t);
#endif #endif
/* getopt.c */ /* getopt.c */
extern int BSDopterr; extern int BSDopterr;
extern int BSDoptind; extern int BSDoptind;
extern int BSDoptopt; extern int BSDoptopt;
extern int BSDoptreset; extern int BSDoptreset;
extern char *BSDoptarg; extern char *BSDoptarg;
int BSDgetopt(int, char *const *, const char *); int BSDgetopt(int, char *const *, const char *);
#define getopt(ac, av, o) BSDgetopt(ac, av, o) #define getopt(ac, av, o) BSDgetopt(ac, av, o)
#define opterr BSDopterr #define opterr BSDopterr

View File

@@ -27,7 +27,7 @@
#endif #endif
int int
clock_gettime(int clock, struct timespec *ts) clock_gettime(__unused int clock, struct timespec *ts)
{ {
struct timeval tv; struct timeval tv;

View File

@@ -49,12 +49,12 @@
#include <mach/mach.h> #include <mach/mach.h>
#include <Availability.h> #include <AvailabilityMacros.h>
#include <unistd.h> #include <unistd.h>
void daemon_darwin(void); void daemon_darwin(void);
#ifdef __MAC_10_10 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
extern kern_return_t bootstrap_look_up_per_user(mach_port_t, const char *, extern kern_return_t bootstrap_look_up_per_user(mach_port_t, const char *,
uid_t, mach_port_t *); uid_t, mach_port_t *);

View File

@@ -18,13 +18,28 @@
#include <glob.h> #include <glob.h>
#include <unistd.h> #include <unistd.h>
#if defined(HAVE_LIBPROC_H)
#include <libproc.h>
#endif
#include "compat.h" #include "compat.h"
void fatal(const char *, ...); void fatal(const char *, ...);
void fatalx(const char *, ...); void fatalx(const char *, ...);
#ifdef HAVE_PROC_PID #if defined(HAVE_LIBPROC_H) && defined(HAVE_PROC_PIDINFO)
int
getdtablecount(void)
{
int sz;
pid_t pid = getpid();
sz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
if (sz == -1)
return (0);
return (sz / PROC_PIDLISTFD_SIZE);
}
#elif defined(HAVE_PROC_PID)
int int
getdtablecount(void) getdtablecount(void)
{ {

View File

@@ -1,115 +0,0 @@
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
#include "compat.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int BSDopterr = 1, /* if error message should be printed */
BSDoptind = 1, /* index into parent argv vector */
BSDoptopt, /* character checked for validity */
BSDoptreset; /* reset getopt */
char *BSDoptarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
int
BSDgetopt(int nargc, char *const *nargv, const char *ostr)
{
static const char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */
if (ostr == NULL)
return (-1);
if (BSDoptreset || !*place) { /* update scanning pointer */
BSDoptreset = 0;
if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
if (place[1])
return (BADCH);
++BSDoptind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((BSDoptopt = (int)*place++) == (int)':' ||
!(oli = strchr(ostr, BSDoptopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (BSDoptopt == (int)'-')
return (-1);
if (!*place)
++BSDoptind;
if (BSDopterr && *ostr != ':')
(void)fprintf(stderr,
"%s: unknown option -- %c\n", getprogname(),
BSDoptopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
BSDoptarg = NULL;
if (!*place)
++BSDoptind;
}
else { /* need an argument */
if (*place) /* no white space */
BSDoptarg = (char *)place;
else if (nargc <= ++BSDoptind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (BSDopterr)
(void)fprintf(stderr,
"%s: option requires an argument -- %c\n",
getprogname(), BSDoptopt);
return (BADCH);
}
else /* white space */
BSDoptarg = nargv[BSDoptind];
place = EMSG;
++BSDoptind;
}
return (BSDoptopt); /* dump back option letter */
}

577
compat/getopt_long.c Normal file
View File

@@ -0,0 +1,577 @@
/* This file is obtained from OpenSSH:
* Repository: https://github.com/openssh/openssh-portable
* Commit: b5b405fee7f3e79d44e2d2971a4b6b4cc53f112e
* File: /openbsd-compat/getopt_long.c */
/*
* Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.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 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.
*
* Sponsored in part by the Defense Advanced Research Projects
* Agency (DARPA) and Air Force Research Laboratory, Air Force
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
*/
/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Dieter Baron and Thomas Klausner.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt_long.c */
#include "compat.h"
/* The following macro constants are taken from getopt.h of OpenSSH:
* Repository: https://github.com/openssh/openssh-portable
* Commit: b5b405fee7f3e79d44e2d2971a4b6b4cc53f112e
* File: /openbsd-compat/getopt.h
*
* ---- BEGIN - Copyright notice and license of getopt.h ----
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Dieter Baron and Thomas Klausner.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* ---- END ----
*/
#define no_argument 0
#define required_argument 1
#define optional_argument 2
#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
#if 0
#include <err.h>
#include <getopt.h>
#endif
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
struct option {
/* name of long option */
const char *name;
/*
* one of no_argument, required_argument, and optional_argument:
* whether option takes an argument
*/
int has_arg;
/* if not NULL, set *flag to val when option found */
int *flag;
/* if flag not NULL, value to set *flag to; else return value */
int val;
};
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define PRINT_ERROR ((opterr) && (*options != ':'))
#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
/* return values */
#define BADCH (int)'?'
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
#define INORDER (int)1
#define EMSG (char *)""
static int getopt_internal(int, char * const *, const char *,
const struct option *, int *, int);
static int parse_long_options(char * const *, const char *,
const struct option *, int *, int);
static int gcd(int, int);
static void permute_args(int, int, int, char * const *);
static char *place = EMSG; /* option letter processing */
/* XXX: set optreset to 1 rather than these two */
static int nonopt_start = -1; /* first non option argument (for permute) */
static int nonopt_end = -1; /* first option after non options (for permute) */
/* Error messages */
static const char recargchar[] = "option requires an argument -- %c";
static const char recargstring[] = "option requires an argument -- %s";
static const char ambig[] = "ambiguous option -- %.*s";
static const char noarg[] = "option doesn't take an argument -- %.*s";
static const char illoptchar[] = "unknown option -- %c";
static const char illoptstring[] = "unknown option -- %s";
/*
* Compute the greatest common divisor of a and b.
*/
static int
gcd(int a, int b)
{
int c;
c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return (b);
}
/*
* Exchange the block from nonopt_start to nonopt_end with the block
* from nonopt_end to opt_end (keeping the same order of arguments
* in each block).
*/
static void
permute_args(int panonopt_start, int panonopt_end, int opt_end,
char * const *nargv)
{
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
char *swap;
/*
* compute lengths of blocks and number and size of cycles
*/
nnonopts = panonopt_end - panonopt_start;
nopts = opt_end - panonopt_end;
ncycle = gcd(nnonopts, nopts);
cyclelen = (opt_end - panonopt_start) / ncycle;
for (i = 0; i < ncycle; i++) {
cstart = panonopt_end+i;
pos = cstart;
for (j = 0; j < cyclelen; j++) {
if (pos >= panonopt_end)
pos -= nnonopts;
else
pos += nopts;
swap = nargv[pos];
/* LINTED const cast */
((char **) nargv)[pos] = nargv[cstart];
/* LINTED const cast */
((char **)nargv)[cstart] = swap;
}
}
}
/*
* parse_long_options --
* Parse long options in argc/argv argument vector.
* Returns -1 if short_too is set and the option does not match long_options.
*/
static int
parse_long_options(char * const *nargv, const char *options,
const struct option *long_options, int *idx, int short_too)
{
char *current_argv, *has_equal;
size_t current_argv_len;
int i, match;
current_argv = place;
match = -1;
optind++;
if ((has_equal = strchr(current_argv, '=')) != NULL) {
/* argument found (--option=arg) */
current_argv_len = has_equal - current_argv;
has_equal++;
} else
current_argv_len = strlen(current_argv);
for (i = 0; long_options[i].name; i++) {
/* find matching long option */
if (strncmp(current_argv, long_options[i].name,
current_argv_len))
continue;
if (strlen(long_options[i].name) == current_argv_len) {
/* exact match */
match = i;
break;
}
/*
* If this is a known short option, don't allow
* a partial match of a single character.
*/
if (short_too && current_argv_len == 1)
continue;
if (match == -1) /* partial match */
match = i;
else {
/* ambiguous abbreviation */
if (PRINT_ERROR)
warnx(ambig, (int)current_argv_len,
current_argv);
optopt = 0;
return (BADCH);
}
}
if (match != -1) { /* option found */
if (long_options[match].has_arg == no_argument
&& has_equal) {
if (PRINT_ERROR)
warnx(noarg, (int)current_argv_len,
current_argv);
/*
* XXX: GNU sets optopt to val regardless of flag
*/
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
return (BADARG);
}
if (long_options[match].has_arg == required_argument ||
long_options[match].has_arg == optional_argument) {
if (has_equal)
optarg = has_equal;
else if (long_options[match].has_arg ==
required_argument) {
/*
* optional argument doesn't use next nargv
*/
optarg = nargv[optind++];
}
}
if ((long_options[match].has_arg == required_argument)
&& (optarg == NULL)) {
/*
* Missing argument; leading ':' indicates no error
* should be generated.
*/
if (PRINT_ERROR)
warnx(recargstring,
current_argv);
/*
* XXX: GNU sets optopt to val regardless of flag
*/
if (long_options[match].flag == NULL)
optopt = long_options[match].val;
else
optopt = 0;
--optind;
return (BADARG);
}
} else { /* unknown option */
if (short_too) {
--optind;
return (-1);
}
if (PRINT_ERROR)
warnx(illoptstring, current_argv);
optopt = 0;
return (BADCH);
}
if (idx)
*idx = match;
if (long_options[match].flag) {
*long_options[match].flag = long_options[match].val;
return (0);
} else
return (long_options[match].val);
}
/*
* getopt_internal --
* Parse argc/argv argument vector. Called by user level routines.
*/
static int
getopt_internal(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx, int flags)
{
char *oli; /* option letter list index */
int optchar, short_too;
static int posixly_correct = -1;
if (options == NULL)
return (-1);
/*
* XXX Some GNU programs (like cvs) set optind to 0 instead of
* XXX using optreset. Work around this braindamage.
*/
if (optind == 0)
optind = optreset = 1;
/*
* Disable GNU extensions if POSIXLY_CORRECT is set or options
* string begins with a '+'.
*/
if (posixly_correct == -1 || optreset)
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
if (*options == '-')
flags |= FLAG_ALLARGS;
else if (posixly_correct || *options == '+')
flags &= ~FLAG_PERMUTE;
if (*options == '+' || *options == '-')
options++;
optarg = NULL;
if (optreset)
nonopt_start = nonopt_end = -1;
start:
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc) { /* end of argument vector */
place = EMSG;
if (nonopt_end != -1) {
/* do permutation, if we have to */
permute_args(nonopt_start, nonopt_end,
optind, nargv);
optind -= nonopt_end - nonopt_start;
}
else if (nonopt_start != -1) {
/*
* If we skipped non-options, set optind
* to the first of them.
*/
optind = nonopt_start;
}
nonopt_start = nonopt_end = -1;
return (-1);
}
if (*(place = nargv[optind]) != '-' ||
(place[1] == '\0' && strchr(options, '-') == NULL)) {
place = EMSG; /* found non-option */
if (flags & FLAG_ALLARGS) {
/*
* GNU extension:
* return non-option as argument to option 1
*/
optarg = nargv[optind++];
return (INORDER);
}
if (!(flags & FLAG_PERMUTE)) {
/*
* If no permutation wanted, stop parsing
* at first non-option.
*/
return (-1);
}
/* do permutation */
if (nonopt_start == -1)
nonopt_start = optind;
else if (nonopt_end != -1) {
permute_args(nonopt_start, nonopt_end,
optind, nargv);
nonopt_start = optind -
(nonopt_end - nonopt_start);
nonopt_end = -1;
}
optind++;
/* process next argument */
goto start;
}
if (nonopt_start != -1 && nonopt_end == -1)
nonopt_end = optind;
/*
* If we have "-" do nothing, if "--" we are done.
*/
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
optind++;
place = EMSG;
/*
* We found an option (--), so if we skipped
* non-options, we have to permute.
*/
if (nonopt_end != -1) {
permute_args(nonopt_start, nonopt_end,
optind, nargv);
optind -= nonopt_end - nonopt_start;
}
nonopt_start = nonopt_end = -1;
return (-1);
}
}
/*
* Check long options if:
* 1) we were passed some
* 2) the arg is not just "-"
* 3) either the arg starts with -- we are getopt_long_only()
*/
if (long_options != NULL && place != nargv[optind] &&
(*place == '-' || (flags & FLAG_LONGONLY))) {
short_too = 0;
if (*place == '-')
place++; /* --foo long option */
else if (*place != ':' && strchr(options, *place) != NULL)
short_too = 1; /* could be short option too */
optchar = parse_long_options(nargv, options, long_options,
idx, short_too);
if (optchar != -1) {
place = EMSG;
return (optchar);
}
}
if ((optchar = (int)*place++) == (int)':' ||
(optchar == (int)'-' && *place != '\0') ||
(oli = strchr(options, optchar)) == NULL) {
/*
* If the user specified "-" and '-' isn't listed in
* options, return -1 (non-option) as per POSIX.
* Otherwise, it is an unknown option character (or ':').
*/
if (optchar == (int)'-' && *place == '\0')
return (-1);
if (!*place)
++optind;
if (PRINT_ERROR)
warnx(illoptchar, optchar);
optopt = optchar;
return (BADCH);
}
if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
/* -W long-option */
if (*place) /* no space */
/* NOTHING */;
else if (++optind >= nargc) { /* no arg */
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
} else /* white space */
place = nargv[optind];
optchar = parse_long_options(nargv, options, long_options,
idx, 0);
place = EMSG;
return (optchar);
}
if (*++oli != ':') { /* doesn't take argument */
if (!*place)
++optind;
} else { /* takes (optional) argument */
optarg = NULL;
if (*place) /* no white space */
optarg = place;
else if (oli[1] != ':') { /* arg not optional */
if (++optind >= nargc) { /* no arg */
place = EMSG;
if (PRINT_ERROR)
warnx(recargchar, optchar);
optopt = optchar;
return (BADARG);
} else
optarg = nargv[optind];
}
place = EMSG;
++optind;
}
/* dump back option letter */
return (optchar);
}
/*
* getopt --
* Parse argc/argv argument vector.
*
* [eventually this will replace the BSD getopt]
*/
int
getopt(int nargc, char * const *nargv, const char *options)
{
/*
* We don't pass FLAG_PERMUTE to getopt_internal() since
* the BSD getopt(3) (unlike GNU) has never done this.
*
* Furthermore, since many privileged programs call getopt()
* before dropping privileges it makes sense to keep things
* as simple (and bug-free) as possible.
*/
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
#if 0
/*
* getopt_long --
* Parse argc/argv argument vector.
*/
int
getopt_long(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE));
}
/*
* getopt_long_only --
* Parse argc/argv argument vector.
*/
int
getopt_long_only(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
{
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE|FLAG_LONGONLY));
}
#endif
#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: imsg-buffer.c,v 1.18 2023/12/12 15:47:41 claudio Exp $ */ /* $OpenBSD: imsg-buffer.c,v 1.35 2025/06/04 09:06:56 claudio Exp $ */
/* /*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -45,25 +45,39 @@
#undef be64toh #undef be64toh
#define be64toh ntohll #define be64toh ntohll
static int ibuf_realloc(struct ibuf *, size_t); struct ibufqueue {
static void ibuf_enqueue(struct msgbuf *, struct ibuf *); TAILQ_HEAD(, ibuf) bufs;
static void ibuf_dequeue(struct msgbuf *, struct ibuf *); uint32_t queued;
};
struct msgbuf {
struct ibufqueue bufs;
struct ibufqueue rbufs;
char *rbuf;
struct ibuf *rpmsg;
struct ibuf *(*readhdr)(struct ibuf *, void *, int *);
void *rarg;
size_t roff;
size_t hdrsize;
};
static void msgbuf_drain(struct msgbuf *, size_t); static void msgbuf_drain(struct msgbuf *, size_t);
static void ibufq_init(struct ibufqueue *);
#define IBUF_FD_MARK_ON_STACK -2
struct ibuf * struct ibuf *
ibuf_open(size_t len) ibuf_open(size_t len)
{ {
struct ibuf *buf; struct ibuf *buf;
if (len == 0) {
errno = EINVAL;
return (NULL);
}
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
return (NULL); return (NULL);
if ((buf->buf = calloc(len, 1)) == NULL) { if (len > 0) {
free(buf); if ((buf->buf = calloc(len, 1)) == NULL) {
return (NULL); free(buf);
return (NULL);
}
} }
buf->size = buf->max = len; buf->size = buf->max = len;
buf->fd = -1; buf->fd = -1;
@@ -96,39 +110,36 @@ ibuf_dynamic(size_t len, size_t max)
return (buf); return (buf);
} }
static int
ibuf_realloc(struct ibuf *buf, size_t len)
{
unsigned char *b;
/* on static buffers max is eq size and so the following fails */
if (len > SIZE_MAX - buf->wpos || buf->wpos + len > buf->max) {
errno = ERANGE;
return (-1);
}
b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
if (b == NULL)
return (-1);
buf->buf = b;
buf->size = buf->wpos + len;
return (0);
}
void * void *
ibuf_reserve(struct ibuf *buf, size_t len) ibuf_reserve(struct ibuf *buf, size_t len)
{ {
void *b; void *b;
if (len > SIZE_MAX - buf->wpos || buf->max == 0) { if (len > SIZE_MAX - buf->wpos) {
errno = ERANGE; errno = ERANGE;
return (NULL); return (NULL);
} }
if (buf->fd == IBUF_FD_MARK_ON_STACK) {
/* can not grow stack buffers */
errno = EINVAL;
return (NULL);
}
if (buf->wpos + len > buf->size) if (buf->wpos + len > buf->size) {
if (ibuf_realloc(buf, len) == -1) unsigned char *nb;
/* check if buffer is allowed to grow */
if (buf->wpos + len > buf->max) {
errno = ERANGE;
return (NULL); return (NULL);
}
nb = realloc(buf->buf, buf->wpos + len);
if (nb == NULL)
return (NULL);
memset(nb + buf->size, 0, buf->wpos + len - buf->size);
buf->buf = nb;
buf->size = buf->wpos + len;
}
b = buf->buf + buf->wpos; b = buf->buf + buf->wpos;
buf->wpos += len; buf->wpos += len;
@@ -140,6 +151,9 @@ ibuf_add(struct ibuf *buf, const void *data, size_t len)
{ {
void *b; void *b;
if (len == 0)
return (0);
if ((b = ibuf_reserve(buf, len)) == NULL) if ((b = ibuf_reserve(buf, len)) == NULL)
return (-1); return (-1);
@@ -153,13 +167,6 @@ ibuf_add_ibuf(struct ibuf *buf, const struct ibuf *from)
return ibuf_add(buf, ibuf_data(from), ibuf_size(from)); return ibuf_add(buf, ibuf_data(from), ibuf_size(from));
} }
/* remove after tree is converted */
int
ibuf_add_buf(struct ibuf *buf, const struct ibuf *from)
{
return ibuf_add_ibuf(buf, from);
}
int int
ibuf_add_n8(struct ibuf *buf, uint64_t value) ibuf_add_n8(struct ibuf *buf, uint64_t value)
{ {
@@ -243,12 +250,34 @@ ibuf_add_zero(struct ibuf *buf, size_t len)
{ {
void *b; void *b;
if (len == 0)
return (0);
if ((b = ibuf_reserve(buf, len)) == NULL) if ((b = ibuf_reserve(buf, len)) == NULL)
return (-1); return (-1);
memset(b, 0, len); memset(b, 0, len);
return (0); return (0);
} }
int
ibuf_add_strbuf(struct ibuf *buf, const char *str, size_t len)
{
char *b;
size_t n;
if ((b = ibuf_reserve(buf, len)) == NULL)
return (-1);
n = strlcpy(b, str, len);
if (n >= len) {
/* also covers the case where len == 0 */
errno = EOVERFLOW;
return (-1);
}
memset(b + n, 0, len - n);
return (0);
}
void * void *
ibuf_seek(struct ibuf *buf, size_t pos, size_t len) ibuf_seek(struct ibuf *buf, size_t pos, size_t len)
{ {
@@ -270,6 +299,8 @@ ibuf_set(struct ibuf *buf, size_t pos, const void *data, size_t len)
if ((b = ibuf_seek(buf, pos, len)) == NULL) if ((b = ibuf_seek(buf, pos, len)) == NULL)
return (-1); return (-1);
if (len == 0)
return (0);
memcpy(b, data, len); memcpy(b, data, len);
return (0); return (0);
} }
@@ -352,6 +383,22 @@ ibuf_set_h64(struct ibuf *buf, size_t pos, uint64_t value)
return (ibuf_set(buf, pos, &value, sizeof(value))); return (ibuf_set(buf, pos, &value, sizeof(value)));
} }
int
ibuf_set_maxsize(struct ibuf *buf, size_t max)
{
if (buf->fd == IBUF_FD_MARK_ON_STACK) {
/* can't fiddle with stack buffers */
errno = EINVAL;
return (-1);
}
if (max > buf->max) {
errno = ERANGE;
return (-1);
}
buf->max = max;
return (0);
}
void * void *
ibuf_data(const struct ibuf *buf) ibuf_data(const struct ibuf *buf)
{ {
@@ -367,7 +414,8 @@ ibuf_size(const struct ibuf *buf)
size_t size_t
ibuf_left(const struct ibuf *buf) ibuf_left(const struct ibuf *buf)
{ {
if (buf->max == 0) /* on stack buffers have no space left */
if (buf->fd == IBUF_FD_MARK_ON_STACK)
return (0); return (0);
return (buf->max - buf->wpos); return (buf->max - buf->wpos);
} }
@@ -379,8 +427,8 @@ ibuf_truncate(struct ibuf *buf, size_t len)
buf->wpos = buf->rpos + len; buf->wpos = buf->rpos + len;
return (0); return (0);
} }
if (buf->max == 0) { if (buf->fd == IBUF_FD_MARK_ON_STACK) {
/* only allow to truncate down */ /* only allow to truncate down for stack buffers */
errno = ERANGE; errno = ERANGE;
return (-1); return (-1);
} }
@@ -396,7 +444,7 @@ ibuf_rewind(struct ibuf *buf)
void void
ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf)
{ {
ibuf_enqueue(msgbuf, buf); ibufq_push(&msgbuf->bufs, buf);
} }
void void
@@ -405,7 +453,7 @@ ibuf_from_buffer(struct ibuf *buf, void *data, size_t len)
memset(buf, 0, sizeof(*buf)); memset(buf, 0, sizeof(*buf));
buf->buf = data; buf->buf = data;
buf->size = buf->wpos = len; buf->size = buf->wpos = len;
buf->fd = -1; buf->fd = IBUF_FD_MARK_ON_STACK;
} }
void void
@@ -440,6 +488,24 @@ ibuf_get_ibuf(struct ibuf *buf, size_t len, struct ibuf *new)
return (0); return (0);
} }
int
ibuf_get_h16(struct ibuf *buf, uint16_t *value)
{
return ibuf_get(buf, value, sizeof(*value));
}
int
ibuf_get_h32(struct ibuf *buf, uint32_t *value)
{
return ibuf_get(buf, value, sizeof(*value));
}
int
ibuf_get_h64(struct ibuf *buf, uint64_t *value)
{
return ibuf_get(buf, value, sizeof(*value));
}
int int
ibuf_get_n8(struct ibuf *buf, uint8_t *value) ibuf_get_n8(struct ibuf *buf, uint8_t *value)
{ {
@@ -476,22 +542,39 @@ ibuf_get_n64(struct ibuf *buf, uint64_t *value)
return (rv); return (rv);
} }
int char *
ibuf_get_h16(struct ibuf *buf, uint16_t *value) ibuf_get_string(struct ibuf *buf, size_t len)
{ {
return ibuf_get(buf, value, sizeof(*value)); char *str;
if (ibuf_size(buf) < len) {
errno = EBADMSG;
return (NULL);
}
str = strndup(ibuf_data(buf), len);
if (str == NULL)
return (NULL);
buf->rpos += len;
return (str);
} }
int int
ibuf_get_h32(struct ibuf *buf, uint32_t *value) ibuf_get_strbuf(struct ibuf *buf, char *str, size_t len)
{ {
return ibuf_get(buf, value, sizeof(*value)); if (len == 0) {
} errno = EINVAL;
return (-1);
}
int if (ibuf_get(buf, str, len) == -1)
ibuf_get_h64(struct ibuf *buf, uint64_t *value) return -1;
{ if (str[len - 1] != '\0') {
return ibuf_get(buf, value, sizeof(*value)); str[len - 1] = '\0';
errno = EOVERFLOW;
return -1;
}
return 0;
} }
int int
@@ -509,20 +592,24 @@ ibuf_skip(struct ibuf *buf, size_t len)
void void
ibuf_free(struct ibuf *buf) ibuf_free(struct ibuf *buf)
{ {
int save_errno = errno;
if (buf == NULL) if (buf == NULL)
return; return;
if (buf->max == 0) /* if buf lives on the stack */ /* if buf lives on the stack abort before causing more harm */
abort(); /* abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK)
if (buf->fd != -1) abort();
if (buf->fd >= 0)
close(buf->fd); close(buf->fd);
freezero(buf->buf, buf->size); freezero(buf->buf, buf->size);
free(buf); free(buf);
errno = save_errno;
} }
int int
ibuf_fd_avail(struct ibuf *buf) ibuf_fd_avail(struct ibuf *buf)
{ {
return (buf->fd != -1); return (buf->fd >= 0);
} }
int int
@@ -530,6 +617,9 @@ ibuf_fd_get(struct ibuf *buf)
{ {
int fd; int fd;
/* negative fds are internal use and equivalent to -1 */
if (buf->fd < 0)
return (-1);
fd = buf->fd; fd = buf->fd;
buf->fd = -1; buf->fd = -1;
return (fd); return (fd);
@@ -538,73 +628,72 @@ ibuf_fd_get(struct ibuf *buf)
void void
ibuf_fd_set(struct ibuf *buf, int fd) ibuf_fd_set(struct ibuf *buf, int fd)
{ {
if (buf->max == 0) /* if buf lives on the stack */ /* if buf lives on the stack abort before causing more harm */
abort(); /* abort before causing more harm */ if (buf->fd == IBUF_FD_MARK_ON_STACK)
if (buf->fd != -1) abort();
if (buf->fd >= 0)
close(buf->fd); close(buf->fd);
buf->fd = fd; buf->fd = -1;
if (fd >= 0)
buf->fd = fd;
} }
int struct msgbuf *
ibuf_write(struct msgbuf *msgbuf) msgbuf_new(void)
{ {
struct iovec iov[IOV_MAX]; struct msgbuf *msgbuf;
struct ibuf *buf;
unsigned int i = 0;
ssize_t n;
memset(&iov, 0, sizeof(iov)); if ((msgbuf = calloc(1, sizeof(*msgbuf))) == NULL)
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { return (NULL);
if (i >= IOV_MAX) ibufq_init(&msgbuf->bufs);
break; ibufq_init(&msgbuf->rbufs);
iov[i].iov_base = ibuf_data(buf);
iov[i].iov_len = ibuf_size(buf); return msgbuf;
i++; }
struct msgbuf *
msgbuf_new_reader(size_t hdrsz,
struct ibuf *(*readhdr)(struct ibuf *, void *, int *), void *arg)
{
struct msgbuf *msgbuf;
char *buf;
if (hdrsz == 0 || hdrsz > IBUF_READ_SIZE / 2) {
errno = EINVAL;
return (NULL);
} }
again: if ((buf = malloc(IBUF_READ_SIZE)) == NULL)
if ((n = writev(msgbuf->fd, iov, i)) == -1) { return (NULL);
if (errno == EINTR)
goto again; msgbuf = msgbuf_new();
if (errno == ENOBUFS) if (msgbuf == NULL) {
errno = EAGAIN; free(buf);
return (-1); return (NULL);
} }
if (n == 0) { /* connection closed */ msgbuf->rbuf = buf;
errno = 0; msgbuf->hdrsize = hdrsz;
return (0); msgbuf->readhdr = readhdr;
} msgbuf->rarg = arg;
msgbuf_drain(msgbuf, n); return (msgbuf);
return (1);
} }
void void
msgbuf_init(struct msgbuf *msgbuf) msgbuf_free(struct msgbuf *msgbuf)
{ {
msgbuf->queued = 0; if (msgbuf == NULL)
msgbuf->fd = -1; return;
TAILQ_INIT(&msgbuf->bufs); msgbuf_clear(msgbuf);
free(msgbuf->rbuf);
free(msgbuf);
} }
static void uint32_t
msgbuf_drain(struct msgbuf *msgbuf, size_t n) msgbuf_queuelen(struct msgbuf *msgbuf)
{ {
struct ibuf *buf, *next; return ibufq_queuelen(&msgbuf->bufs);
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
buf = next) {
next = TAILQ_NEXT(buf, entry);
if (n >= ibuf_size(buf)) {
n -= ibuf_size(buf);
ibuf_dequeue(msgbuf, buf);
} else {
buf->rpos += n;
n = 0;
}
}
} }
void void
@@ -612,12 +701,63 @@ msgbuf_clear(struct msgbuf *msgbuf)
{ {
struct ibuf *buf; struct ibuf *buf;
while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) /* write side */
ibuf_dequeue(msgbuf, buf); ibufq_flush(&msgbuf->bufs);
/* read side */
ibufq_flush(&msgbuf->rbufs);
msgbuf->roff = 0;
ibuf_free(msgbuf->rpmsg);
msgbuf->rpmsg = NULL;
}
struct ibuf *
msgbuf_get(struct msgbuf *msgbuf)
{
return ibufq_pop(&msgbuf->rbufs);
}
void
msgbuf_concat(struct msgbuf *msgbuf, struct ibufqueue *from)
{
ibufq_concat(&msgbuf->bufs, from);
} }
int int
msgbuf_write(struct msgbuf *msgbuf) ibuf_write(int fd, struct msgbuf *msgbuf)
{
struct iovec iov[IOV_MAX];
struct ibuf *buf;
unsigned int i = 0;
ssize_t n;
memset(&iov, 0, sizeof(iov));
TAILQ_FOREACH(buf, &msgbuf->bufs.bufs, entry) {
if (i >= IOV_MAX)
break;
iov[i].iov_base = ibuf_data(buf);
iov[i].iov_len = ibuf_size(buf);
i++;
}
if (i == 0)
return (0); /* nothing queued */
again:
if ((n = writev(fd, iov, i)) == -1) {
if (errno == EINTR)
goto again;
if (errno == EAGAIN || errno == ENOBUFS)
/* lets retry later again */
return (0);
return (-1);
}
msgbuf_drain(msgbuf, n);
return (0);
}
int
msgbuf_write(int fd, struct msgbuf *msgbuf)
{ {
struct iovec iov[IOV_MAX]; struct iovec iov[IOV_MAX];
struct ibuf *buf, *buf0 = NULL; struct ibuf *buf, *buf0 = NULL;
@@ -633,7 +773,7 @@ msgbuf_write(struct msgbuf *msgbuf)
memset(&iov, 0, sizeof(iov)); memset(&iov, 0, sizeof(iov));
memset(&msg, 0, sizeof(msg)); memset(&msg, 0, sizeof(msg));
memset(&cmsgbuf, 0, sizeof(cmsgbuf)); memset(&cmsgbuf, 0, sizeof(cmsgbuf));
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { TAILQ_FOREACH(buf, &msgbuf->bufs.bufs, entry) {
if (i >= IOV_MAX) if (i >= IOV_MAX)
break; break;
if (i > 0 && buf->fd != -1) if (i > 0 && buf->fd != -1)
@@ -645,6 +785,9 @@ msgbuf_write(struct msgbuf *msgbuf)
buf0 = buf; buf0 = buf;
} }
if (i == 0)
return (0); /* nothing queued */
msg.msg_iov = iov; msg.msg_iov = iov;
msg.msg_iovlen = i; msg.msg_iovlen = i;
@@ -658,20 +801,16 @@ msgbuf_write(struct msgbuf *msgbuf)
*(int *)CMSG_DATA(cmsg) = buf0->fd; *(int *)CMSG_DATA(cmsg) = buf0->fd;
} }
again: again:
if ((n = sendmsg(msgbuf->fd, &msg, 0)) == -1) { if ((n = sendmsg(fd, &msg, 0)) == -1) {
if (errno == EINTR) if (errno == EINTR)
goto again; goto again;
if (errno == ENOBUFS) if (errno == EAGAIN || errno == ENOBUFS)
errno = EAGAIN; /* lets retry later again */
return (0);
return (-1); return (-1);
} }
if (n == 0) { /* connection closed */
errno = 0;
return (0);
}
/* /*
* assumption: fd got sent if sendmsg sent anything * assumption: fd got sent if sendmsg sent anything
* this works because fds are passed one at a time * this works because fds are passed one at a time
@@ -683,28 +822,257 @@ again:
msgbuf_drain(msgbuf, n); msgbuf_drain(msgbuf, n);
return (0);
}
static int
ibuf_read_process(struct msgbuf *msgbuf, int fd)
{
struct ibuf rbuf, msg;
ssize_t sz;
ibuf_from_buffer(&rbuf, msgbuf->rbuf, msgbuf->roff);
do {
if (msgbuf->rpmsg == NULL) {
if (ibuf_size(&rbuf) < msgbuf->hdrsize)
break;
/* get size from header */
ibuf_from_buffer(&msg, ibuf_data(&rbuf),
msgbuf->hdrsize);
if ((msgbuf->rpmsg = msgbuf->readhdr(&msg,
msgbuf->rarg, &fd)) == NULL)
goto fail;
}
if (ibuf_left(msgbuf->rpmsg) <= ibuf_size(&rbuf))
sz = ibuf_left(msgbuf->rpmsg);
else
sz = ibuf_size(&rbuf);
/* neither call below can fail */
if (ibuf_get_ibuf(&rbuf, sz, &msg) == -1 ||
ibuf_add_ibuf(msgbuf->rpmsg, &msg) == -1)
goto fail;
if (ibuf_left(msgbuf->rpmsg) == 0) {
ibufq_push(&msgbuf->rbufs, msgbuf->rpmsg);
msgbuf->rpmsg = NULL;
}
} while (ibuf_size(&rbuf) > 0);
if (ibuf_size(&rbuf) > 0)
memmove(msgbuf->rbuf, ibuf_data(&rbuf), ibuf_size(&rbuf));
msgbuf->roff = ibuf_size(&rbuf);
if (fd != -1)
close(fd);
return (1); return (1);
fail:
/* XXX how to properly clean up is unclear */
if (fd != -1)
close(fd);
return (-1);
}
int
ibuf_read(int fd, struct msgbuf *msgbuf)
{
struct iovec iov;
ssize_t n;
if (msgbuf->rbuf == NULL) {
errno = EINVAL;
return (-1);
}
iov.iov_base = msgbuf->rbuf + msgbuf->roff;
iov.iov_len = IBUF_READ_SIZE - msgbuf->roff;
again:
if ((n = readv(fd, &iov, 1)) == -1) {
if (errno == EINTR)
goto again;
if (errno == EAGAIN)
/* lets retry later again */
return (1);
return (-1);
}
if (n == 0) /* connection closed */
return (0);
msgbuf->roff += n;
/* new data arrived, try to process it */
return (ibuf_read_process(msgbuf, -1));
}
int
msgbuf_read(int fd, struct msgbuf *msgbuf)
{
struct msghdr msg;
struct cmsghdr *cmsg;
union {
struct cmsghdr hdr;
char buf[CMSG_SPACE(sizeof(int) * 1)];
} cmsgbuf;
struct iovec iov;
ssize_t n;
int fdpass = -1;
if (msgbuf->rbuf == NULL) {
errno = EINVAL;
return (-1);
}
memset(&msg, 0, sizeof(msg));
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
iov.iov_base = msgbuf->rbuf + msgbuf->roff;
iov.iov_len = IBUF_READ_SIZE - msgbuf->roff;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
again:
if ((n = recvmsg(fd, &msg, 0)) == -1) {
if (errno == EINTR)
goto again;
if (errno == EMSGSIZE)
/*
* Not enough fd slots: fd passing failed, retry
* to receive the message without fd.
* imsg_get_fd() will return -1 in that case.
*/
goto again;
if (errno == EAGAIN)
/* lets retry later again */
return (1);
return (-1);
}
if (n == 0) /* connection closed */
return (0);
msgbuf->roff += n;
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int i, j, f;
/*
* We only accept one file descriptor. Due to C
* padding rules, our control buffer might contain
* more than one fd, and we must close them.
*/
j = ((char *)cmsg + cmsg->cmsg_len -
(char *)CMSG_DATA(cmsg)) / sizeof(int);
for (i = 0; i < j; i++) {
f = ((int *)CMSG_DATA(cmsg))[i];
if (i == 0)
fdpass = f;
else
close(f);
}
}
/* we do not handle other ctl data level */
}
/* new data arrived, try to process it */
return (ibuf_read_process(msgbuf, fdpass));
}
static void
msgbuf_drain(struct msgbuf *msgbuf, size_t n)
{
struct ibuf *buf;
while ((buf = TAILQ_FIRST(&msgbuf->bufs.bufs)) != NULL) {
if (n >= ibuf_size(buf)) {
n -= ibuf_size(buf);
TAILQ_REMOVE(&msgbuf->bufs.bufs, buf, entry);
msgbuf->bufs.queued--;
ibuf_free(buf);
} else {
buf->rpos += n;
return;
}
}
}
static void
ibufq_init(struct ibufqueue *bufq)
{
TAILQ_INIT(&bufq->bufs);
bufq->queued = 0;
}
struct ibufqueue *
ibufq_new(void)
{
struct ibufqueue *bufq;
if ((bufq = calloc(1, sizeof(*bufq))) == NULL)
return NULL;
ibufq_init(bufq);
return bufq;
}
void
ibufq_free(struct ibufqueue *bufq)
{
if (bufq == NULL)
return;
ibufq_flush(bufq);
free(bufq);
}
struct ibuf *
ibufq_pop(struct ibufqueue *bufq)
{
struct ibuf *buf;
if ((buf = TAILQ_FIRST(&bufq->bufs)) == NULL)
return NULL;
TAILQ_REMOVE(&bufq->bufs, buf, entry);
bufq->queued--;
return buf;
}
void
ibufq_push(struct ibufqueue *bufq, struct ibuf *buf)
{
/* if buf lives on the stack abort before causing more harm */
if (buf->fd == IBUF_FD_MARK_ON_STACK)
abort();
TAILQ_INSERT_TAIL(&bufq->bufs, buf, entry);
bufq->queued++;
} }
uint32_t uint32_t
msgbuf_queuelen(struct msgbuf *msgbuf) ibufq_queuelen(struct ibufqueue *bufq)
{ {
return (msgbuf->queued); return (bufq->queued);
} }
static void void
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) ibufq_concat(struct ibufqueue *to, struct ibufqueue *from)
{ {
if (buf->max == 0) /* if buf lives on the stack */ to->queued += from->queued;
abort(); /* abort before causing more harm */ TAILQ_CONCAT(&to->bufs, &from->bufs, entry);
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); from->queued = 0;
msgbuf->queued++;
} }
static void void
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) ibufq_flush(struct ibufqueue *bufq)
{ {
TAILQ_REMOVE(&msgbuf->bufs, buf, entry); struct ibuf *buf;
msgbuf->queued--;
ibuf_free(buf); while ((buf = TAILQ_FIRST(&bufq->bufs)) != NULL) {
TAILQ_REMOVE(&bufq->bufs, buf, entry);
ibuf_free(buf);
}
bufq->queued = 0;
} }

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: imsg.c,v 1.23 2023/12/12 15:47:41 claudio Exp $ */ /* $OpenBSD: imsg.c,v 1.42 2025/06/16 13:56:11 claudio Exp $ */
/* /*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -22,6 +22,7 @@
#include <sys/uio.h> #include <sys/uio.h>
#include <errno.h> #include <errno.h>
#include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -29,158 +30,156 @@
#include "compat.h" #include "compat.h"
#include "imsg.h" #include "imsg.h"
struct imsg_fd { #define IMSG_ALLOW_FDPASS 0x01
TAILQ_ENTRY(imsg_fd) entry; #define IMSG_FD_MARK 0x80000000U
int fd;
};
int imsg_fd_overhead = 0; static struct ibuf *imsg_parse_hdr(struct ibuf *, void *, int *);
static int imsg_dequeue_fd(struct imsgbuf *); int
imsgbuf_init(struct imsgbuf *imsgbuf, int fd)
void
imsg_init(struct imsgbuf *imsgbuf, int fd)
{ {
msgbuf_init(&imsgbuf->w); imsgbuf->w = msgbuf_new_reader(IMSG_HEADER_SIZE, imsg_parse_hdr,
memset(&imsgbuf->r, 0, sizeof(imsgbuf->r)); imsgbuf);
imsgbuf->fd = fd; if (imsgbuf->w == NULL)
imsgbuf->w.fd = fd; return (-1);
imsgbuf->pid = getpid(); imsgbuf->pid = getpid();
TAILQ_INIT(&imsgbuf->fds); imsgbuf->maxsize = MAX_IMSGSIZE;
imsgbuf->fd = fd;
imsgbuf->flags = 0;
return (0);
} }
ssize_t void
imsg_read(struct imsgbuf *imsgbuf) imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf)
{ {
struct msghdr msg; imsgbuf->flags |= IMSG_ALLOW_FDPASS;
struct cmsghdr *cmsg; }
union {
struct cmsghdr hdr;
char buf[CMSG_SPACE(sizeof(int) * 1)];
} cmsgbuf;
struct iovec iov;
ssize_t n = -1;
int fd;
struct imsg_fd *ifd;
memset(&msg, 0, sizeof(msg)); int
memset(&cmsgbuf, 0, sizeof(cmsgbuf)); imsgbuf_set_maxsize(struct imsgbuf *imsgbuf, uint32_t max)
{
iov.iov_base = imsgbuf->r.buf + imsgbuf->r.wpos; if (max > UINT32_MAX - IMSG_HEADER_SIZE) {
iov.iov_len = sizeof(imsgbuf->r.buf) - imsgbuf->r.wpos; errno = ERANGE;
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = &cmsgbuf.buf;
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL)
return (-1);
again:
if (getdtablecount() + imsg_fd_overhead +
(int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
>= getdtablesize()) {
errno = EAGAIN;
free(ifd);
return (-1); return (-1);
} }
max += IMSG_HEADER_SIZE;
if ((n = recvmsg(imsgbuf->fd, &msg, 0)) == -1) { if (max & IMSG_FD_MARK) {
if (errno == EINTR) errno = EINVAL;
goto again; return (-1);
goto fail;
} }
imsgbuf->maxsize = max;
return (0);
}
imsgbuf->r.wpos += n; int
imsgbuf_read(struct imsgbuf *imsgbuf)
{
if (imsgbuf->flags & IMSG_ALLOW_FDPASS)
return msgbuf_read(imsgbuf->fd, imsgbuf->w);
else
return ibuf_read(imsgbuf->fd, imsgbuf->w);
}
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; int
cmsg = CMSG_NXTHDR(&msg, cmsg)) { imsgbuf_write(struct imsgbuf *imsgbuf)
if (cmsg->cmsg_level == SOL_SOCKET && {
cmsg->cmsg_type == SCM_RIGHTS) { if (imsgbuf->flags & IMSG_ALLOW_FDPASS)
int i; return msgbuf_write(imsgbuf->fd, imsgbuf->w);
int j; else
return ibuf_write(imsgbuf->fd, imsgbuf->w);
}
/* int
* We only accept one file descriptor. Due to C imsgbuf_flush(struct imsgbuf *imsgbuf)
* padding rules, our control buffer might contain {
* more than one fd, and we must close them. while (imsgbuf_queuelen(imsgbuf) > 0) {
*/ if (imsgbuf_write(imsgbuf) == -1)
j = ((char *)cmsg + cmsg->cmsg_len - return (-1);
(char *)CMSG_DATA(cmsg)) / sizeof(int);
for (i = 0; i < j; i++) {
fd = ((int *)CMSG_DATA(cmsg))[i];
if (ifd != NULL) {
ifd->fd = fd;
TAILQ_INSERT_TAIL(&imsgbuf->fds, ifd,
entry);
ifd = NULL;
} else
close(fd);
}
}
/* we do not handle other ctl data level */
} }
return (0);
}
fail: void
free(ifd); imsgbuf_clear(struct imsgbuf *imsgbuf)
return (n); {
msgbuf_free(imsgbuf->w);
imsgbuf->w = NULL;
}
uint32_t
imsgbuf_queuelen(struct imsgbuf *imsgbuf)
{
return msgbuf_queuelen(imsgbuf->w);
}
int
imsgbuf_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
{
struct imsg m;
struct ibuf *buf;
if ((buf = msgbuf_get(imsgbuf->w)) == NULL)
return (0);
if (ibuf_get(buf, &m.hdr, sizeof(m.hdr)) == -1)
return (-1);
if (ibuf_size(buf))
m.data = ibuf_data(buf);
else
m.data = NULL;
m.buf = buf;
m.hdr.len &= ~IMSG_FD_MARK;
*imsg = m;
return (1);
} }
ssize_t ssize_t
imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg) imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
{ {
struct imsg m; int rv;
size_t av, left, datalen;
av = imsgbuf->r.wpos; if ((rv = imsgbuf_get(imsgbuf, imsg)) != 1)
return rv;
return (imsg_get_len(imsg) + IMSG_HEADER_SIZE);
}
if (IMSG_HEADER_SIZE > av) int
imsg_ibufq_pop(struct ibufqueue *bufq, struct imsg *imsg)
{
struct imsg m;
struct ibuf *buf;
if ((buf = ibufq_pop(bufq)) == NULL)
return (0); return (0);
memcpy(&m.hdr, imsgbuf->r.buf, sizeof(m.hdr)); if (ibuf_get(buf, &m.hdr, sizeof(m.hdr)) == -1)
if (m.hdr.len < IMSG_HEADER_SIZE ||
m.hdr.len > MAX_IMSGSIZE) {
errno = ERANGE;
return (-1); return (-1);
}
if (m.hdr.len > av)
return (0);
m.fd = -1; if (ibuf_size(buf))
m.buf = NULL; m.data = ibuf_data(buf);
m.data = NULL; else
m.data = NULL;
datalen = m.hdr.len - IMSG_HEADER_SIZE; m.buf = buf;
imsgbuf->r.rptr = imsgbuf->r.buf + IMSG_HEADER_SIZE; m.hdr.len &= ~IMSG_FD_MARK;
if (datalen != 0) {
if ((m.buf = ibuf_open(datalen)) == NULL)
return (-1);
if (ibuf_add(m.buf, imsgbuf->r.rptr, datalen) == -1) {
/* this should never fail */
ibuf_free(m.buf);
return (-1);
}
m.data = ibuf_data(m.buf);
}
if (m.hdr.flags & IMSGF_HASFD)
m.fd = imsg_dequeue_fd(imsgbuf);
if (m.hdr.len < av) {
left = av - m.hdr.len;
memmove(&imsgbuf->r.buf, imsgbuf->r.buf + m.hdr.len, left);
imsgbuf->r.wpos = left;
} else
imsgbuf->r.wpos = 0;
*imsg = m; *imsg = m;
return (datalen + IMSG_HEADER_SIZE); return (1);
}
void
imsg_ibufq_push(struct ibufqueue *bufq, struct imsg *imsg)
{
ibuf_rewind(imsg->buf);
ibufq_push(bufq, imsg->buf);
memset(imsg, 0, sizeof(*imsg));
} }
int int
imsg_get_ibuf(struct imsg *imsg, struct ibuf *ibuf) imsg_get_ibuf(struct imsg *imsg, struct ibuf *ibuf)
{ {
if (imsg->buf == NULL) { if (ibuf_size(imsg->buf) == 0) {
errno = EBADMSG; errno = EBADMSG;
return (-1); return (-1);
} }
@@ -194,20 +193,29 @@ imsg_get_data(struct imsg *imsg, void *data, size_t len)
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
if (imsg->buf == NULL || ibuf_size(imsg->buf) != len) { if (ibuf_size(imsg->buf) != len) {
errno = EBADMSG; errno = EBADMSG;
return (-1); return (-1);
} }
return ibuf_get(imsg->buf, data, len); return ibuf_get(imsg->buf, data, len);
} }
int
imsg_get_buf(struct imsg *imsg, void *data, size_t len)
{
return ibuf_get(imsg->buf, data, len);
}
int
imsg_get_strbuf(struct imsg *imsg, char *str, size_t len)
{
return ibuf_get_strbuf(imsg->buf, str, len);
}
int int
imsg_get_fd(struct imsg *imsg) imsg_get_fd(struct imsg *imsg)
{ {
int fd = imsg->fd; return ibuf_fd_get(imsg->buf);
imsg->fd = -1;
return fd;
} }
uint32_t uint32_t
@@ -219,8 +227,6 @@ imsg_get_id(struct imsg *imsg)
size_t size_t
imsg_get_len(struct imsg *imsg) imsg_get_len(struct imsg *imsg)
{ {
if (imsg->buf == NULL)
return 0;
return ibuf_size(imsg->buf); return ibuf_size(imsg->buf);
} }
@@ -243,15 +249,19 @@ imsg_compose(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
struct ibuf *wbuf; struct ibuf *wbuf;
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL) if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
return (-1); goto fail;
if (imsg_add(wbuf, data, datalen) == -1) if (ibuf_add(wbuf, data, datalen) == -1)
return (-1); goto fail;
ibuf_fd_set(wbuf, fd); ibuf_fd_set(wbuf, fd);
imsg_close(imsgbuf, wbuf); imsg_close(imsgbuf, wbuf);
return (1); return (1);
fail:
ibuf_free(wbuf);
return (-1);
} }
int int
@@ -266,16 +276,20 @@ imsg_composev(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
datalen += iov[i].iov_len; datalen += iov[i].iov_len;
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL) if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
return (-1); goto fail;
for (i = 0; i < iovcnt; i++) for (i = 0; i < iovcnt; i++)
if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1) if (ibuf_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
return (-1); goto fail;
ibuf_fd_set(wbuf, fd); ibuf_fd_set(wbuf, fd);
imsg_close(imsgbuf, wbuf); imsg_close(imsgbuf, wbuf);
return (1); return (1);
fail:
ibuf_free(wbuf);
return (-1);
} }
/* /*
@@ -288,34 +302,30 @@ imsg_compose_ibuf(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id,
{ {
struct ibuf *hdrbuf = NULL; struct ibuf *hdrbuf = NULL;
struct imsg_hdr hdr; struct imsg_hdr hdr;
int save_errno;
if (ibuf_size(buf) + IMSG_HEADER_SIZE > MAX_IMSGSIZE) { if (ibuf_size(buf) + IMSG_HEADER_SIZE > imsgbuf->maxsize) {
errno = ERANGE; errno = ERANGE;
goto fail; goto fail;
} }
hdr.type = type; hdr.type = type;
hdr.len = ibuf_size(buf) + IMSG_HEADER_SIZE; hdr.len = ibuf_size(buf) + IMSG_HEADER_SIZE;
hdr.flags = 0;
hdr.peerid = id; hdr.peerid = id;
if ((hdr.pid = pid) == 0) if ((hdr.pid = pid) == 0)
hdr.pid = imsgbuf->pid; hdr.pid = imsgbuf->pid;
if ((hdrbuf = ibuf_open(IMSG_HEADER_SIZE)) == NULL) if ((hdrbuf = ibuf_open(IMSG_HEADER_SIZE)) == NULL)
goto fail; goto fail;
if (imsg_add(hdrbuf, &hdr, sizeof(hdr)) == -1) if (ibuf_add(hdrbuf, &hdr, sizeof(hdr)) == -1)
goto fail; goto fail;
ibuf_close(&imsgbuf->w, hdrbuf); ibuf_close(imsgbuf->w, hdrbuf);
ibuf_close(&imsgbuf->w, buf); ibuf_close(imsgbuf->w, buf);
return (1); return (1);
fail: fail:
save_errno = errno;
ibuf_free(buf); ibuf_free(buf);
ibuf_free(hdrbuf); ibuf_free(hdrbuf);
errno = save_errno;
return (-1); return (-1);
} }
@@ -326,24 +336,18 @@ int
imsg_forward(struct imsgbuf *imsgbuf, struct imsg *msg) imsg_forward(struct imsgbuf *imsgbuf, struct imsg *msg)
{ {
struct ibuf *wbuf; struct ibuf *wbuf;
size_t len = 0; size_t len;
if (msg->fd != -1) { ibuf_rewind(msg->buf);
close(msg->fd); ibuf_skip(msg->buf, sizeof(msg->hdr));
msg->fd = -1; len = ibuf_size(msg->buf);
}
if (msg->buf != NULL) {
ibuf_rewind(msg->buf);
len = ibuf_size(msg->buf);
}
if ((wbuf = imsg_create(imsgbuf, msg->hdr.type, msg->hdr.peerid, if ((wbuf = imsg_create(imsgbuf, msg->hdr.type, msg->hdr.peerid,
msg->hdr.pid, len)) == NULL) msg->hdr.pid, len)) == NULL)
return (-1); return (-1);
if (msg->buf != NULL) { if (len != 0) {
if (ibuf_add_buf(wbuf, msg->buf) == -1) { if (ibuf_add_ibuf(wbuf, msg->buf) == -1) {
ibuf_free(wbuf); ibuf_free(wbuf);
return (-1); return (-1);
} }
@@ -361,23 +365,26 @@ imsg_create(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
struct imsg_hdr hdr; struct imsg_hdr hdr;
datalen += IMSG_HEADER_SIZE; datalen += IMSG_HEADER_SIZE;
if (datalen > MAX_IMSGSIZE) { if (datalen > imsgbuf->maxsize) {
errno = ERANGE; errno = ERANGE;
return (NULL); return (NULL);
} }
hdr.len = 0;
hdr.type = type; hdr.type = type;
hdr.flags = 0;
hdr.peerid = id; hdr.peerid = id;
if ((hdr.pid = pid) == 0) if ((hdr.pid = pid) == 0)
hdr.pid = imsgbuf->pid; hdr.pid = imsgbuf->pid;
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) { if ((wbuf = ibuf_dynamic(datalen, imsgbuf->maxsize)) == NULL)
return (NULL); goto fail;
} if (ibuf_add(wbuf, &hdr, sizeof(hdr)) == -1)
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1) goto fail;
return (NULL);
return (wbuf); return (wbuf);
fail:
ibuf_free(wbuf);
return (NULL);
} }
int int
@@ -394,16 +401,13 @@ imsg_add(struct ibuf *msg, const void *data, size_t datalen)
void void
imsg_close(struct imsgbuf *imsgbuf, struct ibuf *msg) imsg_close(struct imsgbuf *imsgbuf, struct ibuf *msg)
{ {
struct imsg_hdr *hdr; uint32_t len;
hdr = (struct imsg_hdr *)msg->buf; len = ibuf_size(msg);
hdr->flags &= ~IMSGF_HASFD;
if (ibuf_fd_avail(msg)) if (ibuf_fd_avail(msg))
hdr->flags |= IMSGF_HASFD; len |= IMSG_FD_MARK;
hdr->len = ibuf_size(msg); (void)ibuf_set_h32(msg, offsetof(struct imsg_hdr, len), len);
ibuf_close(imsgbuf->w, msg);
ibuf_close(&imsgbuf->w, msg);
} }
void void
@@ -412,37 +416,39 @@ imsg_free(struct imsg *imsg)
ibuf_free(imsg->buf); ibuf_free(imsg->buf);
} }
static int
imsg_dequeue_fd(struct imsgbuf *imsgbuf)
{
int fd;
struct imsg_fd *ifd;
if ((ifd = TAILQ_FIRST(&imsgbuf->fds)) == NULL)
return (-1);
fd = ifd->fd;
TAILQ_REMOVE(&imsgbuf->fds, ifd, entry);
free(ifd);
return (fd);
}
int int
imsg_flush(struct imsgbuf *imsgbuf) imsg_set_maxsize(struct ibuf *msg, size_t max)
{ {
while (imsgbuf->w.queued) if (max > UINT32_MAX - IMSG_HEADER_SIZE) {
if (msgbuf_write(&imsgbuf->w) <= 0) errno = ERANGE;
return (-1); return (-1);
return (0); }
return ibuf_set_maxsize(msg, max + IMSG_HEADER_SIZE);
} }
void static struct ibuf *
imsg_clear(struct imsgbuf *imsgbuf) imsg_parse_hdr(struct ibuf *buf, void *arg, int *fd)
{ {
int fd; struct imsgbuf *imsgbuf = arg;
struct imsg_hdr hdr;
struct ibuf *b;
uint32_t len;
msgbuf_clear(&imsgbuf->w); if (ibuf_get(buf, &hdr, sizeof(hdr)) == -1)
while ((fd = imsg_dequeue_fd(imsgbuf)) != -1) return (NULL);
close(fd);
len = hdr.len & ~IMSG_FD_MARK;
if (len < IMSG_HEADER_SIZE || len > imsgbuf->maxsize) {
errno = ERANGE;
return (NULL);
}
if ((b = ibuf_open(len)) == NULL)
return (NULL);
if (hdr.len & IMSG_FD_MARK) {
ibuf_fd_set(b, *fd);
*fd = -1;
}
return b;
} }

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: imsg.h,v 1.8 2023/12/12 15:47:41 claudio Exp $ */ /* $OpenBSD: imsg.h,v 1.24 2025/06/05 08:55:07 tb Exp $ */
/* /*
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org> * Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
@@ -23,6 +23,7 @@
#define _IMSG_H_ #define _IMSG_H_
#include <sys/types.h> #include <sys/types.h>
#include <stddef.h>
#define IBUF_READ_SIZE 65535 #define IBUF_READ_SIZE 65535
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr) #define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
@@ -38,40 +39,26 @@ struct ibuf {
int fd; int fd;
}; };
struct msgbuf { struct ibufqueue;
TAILQ_HEAD(, ibuf) bufs; struct msgbuf;
uint32_t queued;
int fd;
};
struct ibuf_read {
unsigned char buf[IBUF_READ_SIZE];
unsigned char *rptr;
size_t wpos;
};
struct imsg_fd;
struct imsgbuf { struct imsgbuf {
TAILQ_HEAD(, imsg_fd) fds; struct msgbuf *w;
struct ibuf_read r;
struct msgbuf w;
int fd;
pid_t pid; pid_t pid;
uint32_t maxsize;
int fd;
int flags;
}; };
#define IMSGF_HASFD 1
struct imsg_hdr { struct imsg_hdr {
uint32_t type; uint32_t type;
uint16_t len; uint32_t len;
uint16_t flags;
uint32_t peerid; uint32_t peerid;
uint32_t pid; uint32_t pid;
}; };
struct imsg { struct imsg {
struct imsg_hdr hdr; struct imsg_hdr hdr;
int fd;
void *data; void *data;
struct ibuf *buf; struct ibuf *buf;
}; };
@@ -82,7 +69,6 @@ struct iovec;
struct ibuf *ibuf_open(size_t); struct ibuf *ibuf_open(size_t);
struct ibuf *ibuf_dynamic(size_t, size_t); struct ibuf *ibuf_dynamic(size_t, size_t);
int ibuf_add(struct ibuf *, const void *, size_t); int ibuf_add(struct ibuf *, const void *, size_t);
int ibuf_add_buf(struct ibuf *, const struct ibuf *);
int ibuf_add_ibuf(struct ibuf *, const struct ibuf *); int ibuf_add_ibuf(struct ibuf *, const struct ibuf *);
int ibuf_add_zero(struct ibuf *, size_t); int ibuf_add_zero(struct ibuf *, size_t);
int ibuf_add_n8(struct ibuf *, uint64_t); int ibuf_add_n8(struct ibuf *, uint64_t);
@@ -92,6 +78,7 @@ int ibuf_add_n64(struct ibuf *, uint64_t);
int ibuf_add_h16(struct ibuf *, uint64_t); int ibuf_add_h16(struct ibuf *, uint64_t);
int ibuf_add_h32(struct ibuf *, uint64_t); int ibuf_add_h32(struct ibuf *, uint64_t);
int ibuf_add_h64(struct ibuf *, uint64_t); int ibuf_add_h64(struct ibuf *, uint64_t);
int ibuf_add_strbuf(struct ibuf *, const char *, size_t);
void *ibuf_reserve(struct ibuf *, size_t); void *ibuf_reserve(struct ibuf *, size_t);
void *ibuf_seek(struct ibuf *, size_t, size_t); void *ibuf_seek(struct ibuf *, size_t, size_t);
int ibuf_set(struct ibuf *, size_t, const void *, size_t); int ibuf_set(struct ibuf *, size_t, const void *, size_t);
@@ -102,6 +89,7 @@ int ibuf_set_n64(struct ibuf *, size_t, uint64_t);
int ibuf_set_h16(struct ibuf *, size_t, uint64_t); int ibuf_set_h16(struct ibuf *, size_t, uint64_t);
int ibuf_set_h32(struct ibuf *, size_t, uint64_t); int ibuf_set_h32(struct ibuf *, size_t, uint64_t);
int ibuf_set_h64(struct ibuf *, size_t, uint64_t); int ibuf_set_h64(struct ibuf *, size_t, uint64_t);
int ibuf_set_maxsize(struct ibuf *, size_t);
void *ibuf_data(const struct ibuf *); void *ibuf_data(const struct ibuf *);
size_t ibuf_size(const struct ibuf *); size_t ibuf_size(const struct ibuf *);
size_t ibuf_left(const struct ibuf *); size_t ibuf_left(const struct ibuf *);
@@ -119,23 +107,51 @@ int ibuf_get_n64(struct ibuf *, uint64_t *);
int ibuf_get_h16(struct ibuf *, uint16_t *); int ibuf_get_h16(struct ibuf *, uint16_t *);
int ibuf_get_h32(struct ibuf *, uint32_t *); int ibuf_get_h32(struct ibuf *, uint32_t *);
int ibuf_get_h64(struct ibuf *, uint64_t *); int ibuf_get_h64(struct ibuf *, uint64_t *);
char *ibuf_get_string(struct ibuf *, size_t);
int ibuf_get_strbuf(struct ibuf *, char *, size_t);
int ibuf_skip(struct ibuf *, size_t); int ibuf_skip(struct ibuf *, size_t);
void ibuf_free(struct ibuf *); void ibuf_free(struct ibuf *);
int ibuf_fd_avail(struct ibuf *); int ibuf_fd_avail(struct ibuf *);
int ibuf_fd_get(struct ibuf *); int ibuf_fd_get(struct ibuf *);
void ibuf_fd_set(struct ibuf *, int); void ibuf_fd_set(struct ibuf *, int);
int ibuf_write(struct msgbuf *); struct msgbuf *msgbuf_new(void);
void msgbuf_init(struct msgbuf *); struct msgbuf *msgbuf_new_reader(size_t,
struct ibuf *(*)(struct ibuf *, void *, int *), void *);
void msgbuf_free(struct msgbuf *);
void msgbuf_clear(struct msgbuf *); void msgbuf_clear(struct msgbuf *);
void msgbuf_concat(struct msgbuf *, struct ibufqueue *);
uint32_t msgbuf_queuelen(struct msgbuf *); uint32_t msgbuf_queuelen(struct msgbuf *);
int msgbuf_write(struct msgbuf *); int ibuf_write(int, struct msgbuf *);
int msgbuf_write(int, struct msgbuf *);
int ibuf_read(int, struct msgbuf *);
int msgbuf_read(int, struct msgbuf *);
struct ibuf *msgbuf_get(struct msgbuf *);
struct ibufqueue *ibufq_new(void);
void ibufq_free(struct ibufqueue *);
struct ibuf *ibufq_pop(struct ibufqueue *bufq);
void ibufq_push(struct ibufqueue *, struct ibuf *);
uint32_t ibufq_queuelen(struct ibufqueue *);
void ibufq_concat(struct ibufqueue *, struct ibufqueue *);
void ibufq_flush(struct ibufqueue *);
/* imsg.c */ /* imsg.c */
void imsg_init(struct imsgbuf *, int); int imsgbuf_init(struct imsgbuf *, int);
ssize_t imsg_read(struct imsgbuf *); void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf);
int imsgbuf_set_maxsize(struct imsgbuf *, uint32_t);
int imsgbuf_read(struct imsgbuf *);
int imsgbuf_write(struct imsgbuf *);
int imsgbuf_flush(struct imsgbuf *);
void imsgbuf_clear(struct imsgbuf *);
uint32_t imsgbuf_queuelen(struct imsgbuf *);
int imsgbuf_get(struct imsgbuf *, struct imsg *);
ssize_t imsg_get(struct imsgbuf *, struct imsg *); ssize_t imsg_get(struct imsgbuf *, struct imsg *);
int imsg_ibufq_pop(struct ibufqueue *, struct imsg *);
void imsg_ibufq_push(struct ibufqueue *, struct imsg *);
int imsg_get_ibuf(struct imsg *, struct ibuf *); int imsg_get_ibuf(struct imsg *, struct ibuf *);
int imsg_get_data(struct imsg *, void *, size_t); int imsg_get_data(struct imsg *, void *, size_t);
int imsg_get_buf(struct imsg *, void *, size_t);
int imsg_get_strbuf(struct imsg *, char *, size_t);
int imsg_get_fd(struct imsg *); int imsg_get_fd(struct imsg *);
uint32_t imsg_get_id(struct imsg *); uint32_t imsg_get_id(struct imsg *);
size_t imsg_get_len(struct imsg *); size_t imsg_get_len(struct imsg *);
@@ -152,7 +168,6 @@ struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, size_t);
int imsg_add(struct ibuf *, const void *, size_t); int imsg_add(struct ibuf *, const void *, size_t);
void imsg_close(struct imsgbuf *, struct ibuf *); void imsg_close(struct imsgbuf *, struct ibuf *);
void imsg_free(struct imsg *); void imsg_free(struct imsg *);
int imsg_flush(struct imsgbuf *); int imsg_set_maxsize(struct ibuf *, size_t);
void imsg_clear(struct imsgbuf *);
#endif #endif

View File

@@ -30,6 +30,11 @@
#include "tmux.h" #include "tmux.h"
#ifndef SD_ID128_UUID_FORMAT_STR
#define SD_ID128_UUID_FORMAT_STR \
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
#endif
int int
systemd_activated(void) systemd_activated(void)
{ {
@@ -70,16 +75,49 @@ fail:
return (-1); return (-1);
} }
int struct systemd_job_watch {
systemd_move_pid_to_new_cgroup(pid_t pid, char **cause) const char *path;
int done;
};
static int
job_removed_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
{ {
sd_bus_error error = SD_BUS_ERROR_NULL; struct systemd_job_watch *watch = userdata;
sd_bus_message *m = NULL, *reply = NULL; const char *path = NULL;
sd_bus *bus = NULL; uint32_t id;
char *name, *desc, *slice; int r;
sd_id128_t uuid;
int r; /* This handler could be called during the sd_bus_call. */
pid_t parent_pid; if (watch->path == NULL)
return 0;
r = sd_bus_message_read(m, "uo", &id, &path);
if (r < 0)
return (r);
if (strcmp(path, watch->path) == 0)
watch->done = 1;
return (0);
}
int
systemd_move_to_new_cgroup(char **cause)
{
sd_bus_error error = SD_BUS_ERROR_NULL;
sd_bus_message *m = NULL, *reply = NULL;
sd_bus *bus = NULL;
sd_bus_slot *slot = NULL;
char *name, *desc, *slice;
sd_id128_t uuid;
int r;
uint64_t elapsed_usec;
pid_t pid, parent_pid;
struct timeval start, now;
struct systemd_job_watch watch = {};
gettimeofday(&start, NULL);
/* Connect to the session bus. */ /* Connect to the session bus. */
r = sd_bus_default_user(&bus); r = sd_bus_default_user(&bus);
@@ -89,6 +127,20 @@ systemd_move_pid_to_new_cgroup(pid_t pid, char **cause)
goto finish; goto finish;
} }
/* Start watching for JobRemoved events */
r = sd_bus_match_signal(bus, &slot,
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"JobRemoved",
job_removed_handler,
&watch);
if (r < 0) {
xasprintf(cause, "failed to create match signal: %s",
strerror(-r));
goto finish;
}
/* Start building the method call. */ /* Start building the method call. */
r = sd_bus_message_new_method_call(bus, &m, r = sd_bus_message_new_method_call(bus, &m,
"org.freedesktop.systemd1", "org.freedesktop.systemd1",
@@ -133,7 +185,8 @@ systemd_move_pid_to_new_cgroup(pid_t pid, char **cause)
goto finish; goto finish;
} }
parent_pid = getpid(); pid = getpid();
parent_pid = getppid();
xasprintf(&desc, "tmux child pane %ld launched by process %ld", xasprintf(&desc, "tmux child pane %ld launched by process %ld",
(long)pid, (long)parent_pid); (long)pid, (long)parent_pid);
r = sd_bus_message_append(m, "(sv)", "Description", "s", desc); r = sd_bus_message_append(m, "(sv)", "Description", "s", desc);
@@ -218,10 +271,55 @@ systemd_move_pid_to_new_cgroup(pid_t pid, char **cause)
goto finish; goto finish;
} }
/* Get the job (object path) from the reply */
r = sd_bus_message_read(reply, "o", &watch.path);
if (r < 0) {
xasprintf(cause, "failed to parse method reply: %s",
strerror(-r));
goto finish;
}
while (!watch.done) {
/* Process events including callbacks. */
r = sd_bus_process(bus, NULL);
if (r < 0) {
xasprintf(cause,
"failed waiting for cgroup allocation: %s",
strerror(-r));
goto finish;
}
/*
* A positive return means we handled an event and should keep
* processing; zero indicates no events available, so wait.
*/
if (r > 0)
continue;
gettimeofday(&now, NULL);
elapsed_usec = (now.tv_sec - start.tv_sec) * 1000000 +
now.tv_usec - start.tv_usec;
if (elapsed_usec >= 1000000) {
xasprintf(cause,
"timeout waiting for cgroup allocation");
goto finish;
}
r = sd_bus_wait(bus, 1000000 - elapsed_usec);
if (r < 0) {
xasprintf(cause,
"failed waiting for cgroup allocation: %s",
strerror(-r));
goto finish;
}
}
finish: finish:
sd_bus_error_free(&error); sd_bus_error_free(&error);
sd_bus_message_unref(m); sd_bus_message_unref(m);
sd_bus_message_unref(reply); sd_bus_message_unref(reply);
sd_bus_slot_unref(slot);
sd_bus_unref(bus); sd_bus_unref(bus);
return (r); return (r);

View File

@@ -48,7 +48,7 @@ utf8proc_mbtowc(wchar_t *pwc, const char *s, size_t n)
* *pwc == -1 indicates invalid codepoint * *pwc == -1 indicates invalid codepoint
* slen < 0 indicates an error * slen < 0 indicates an error
*/ */
slen = utf8proc_iterate(s, n, pwc); slen = utf8proc_iterate(s, n, (utf8proc_int32_t*)pwc);
if (*pwc == (wchar_t)-1 || slen < 0) if (*pwc == (wchar_t)-1 || slen < 0)
return (-1); return (-1);
return (slen); return (slen);

View File

@@ -1,6 +1,6 @@
# configure.ac # configure.ac
AC_INIT([tmux], 3.5a) AC_INIT([tmux], 3.6a)
AC_PREREQ([2.60]) AC_PREREQ([2.60])
AC_CONFIG_AUX_DIR(etc) AC_CONFIG_AUX_DIR(etc)
@@ -219,7 +219,7 @@ AC_SEARCH_LIBS(clock_gettime, rt)
# musl does not set optarg to NULL for flags without arguments (although it is # musl does not set optarg to NULL for flags without arguments (although it is
# not required to, but it is helpful) 3) there are probably other weird # not required to, but it is helpful) 3) there are probably other weird
# implementations. # implementations.
AC_LIBOBJ(getopt) AC_LIBOBJ(getopt_long)
# Look for libevent. Try libevent_core or libevent with pkg-config first then # Look for libevent. Try libevent_core or libevent with pkg-config first then
# look for the library. # look for the library.
@@ -638,9 +638,9 @@ else
AC_LIBOBJ(err) AC_LIBOBJ(err)
fi fi
# Look for imsg_init in libutil. # Look for imsg_add in libutil.
AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no) AC_SEARCH_LIBS(imsg_add, util, found_imsg_add=yes, found_imsg_add=no)
if test "x$found_imsg_init" = xyes; then if test "x$found_imsg_add" = xyes; then
AC_DEFINE(HAVE_IMSG) AC_DEFINE(HAVE_IMSG)
else else
AC_LIBOBJ(imsg) AC_LIBOBJ(imsg)
@@ -982,22 +982,22 @@ AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd) AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos) AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux) AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
AM_CONDITIONAL(IS_CYGWIN, test "x$PLATFORM" = xcygwin)
AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku) AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown) AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
# Set the default lock command # Set the default lock command
DEFAULT_LOCK_CMD="lock -np" DEFAULT_LOCK_CMD="lock -np"
AC_MSG_CHECKING(lock-command)
if test "x$PLATFORM" = xlinux; then if test "x$PLATFORM" = xlinux; then
AC_CHECK_PROG(found_vlock, vlock, yes, no) AC_CHECK_PROG(found_vlock, vlock, yes, no)
if test "x$found_vlock" = xyes; then if test "x$found_vlock" = xyes; then
DEFAULT_LOCK_CMD="vlock" DEFAULT_LOCK_CMD="vlock"
fi fi
fi fi
AC_MSG_CHECKING(lock-command)
AC_MSG_RESULT($DEFAULT_LOCK_CMD) AC_MSG_RESULT($DEFAULT_LOCK_CMD)
AC_SUBST(DEFAULT_LOCK_CMD) AC_SUBST(DEFAULT_LOCK_CMD)
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user # Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
# variables. # variables.
AC_SUBST(AM_CPPFLAGS) AC_SUBST(AM_CPPFLAGS)

View File

@@ -262,6 +262,12 @@ environ_for_session(struct session *s, int no_TERM)
environ_set(env, "TERM", 0, "%s", value); environ_set(env, "TERM", 0, "%s", value);
environ_set(env, "TERM_PROGRAM", 0, "%s", "tmux"); environ_set(env, "TERM_PROGRAM", 0, "%s", "tmux");
environ_set(env, "TERM_PROGRAM_VERSION", 0, "%s", getversion()); environ_set(env, "TERM_PROGRAM_VERSION", 0, "%s", getversion());
environ_set(env, "COLORTERM", 0, "truecolor");
} else {
environ_unset(env, "TERM");
environ_unset(env, "TERM_PROGRAM");
environ_unset(env, "TERM_PROGRAM_VERSION");
environ_unset(env, "COLORTERM");
} }
#ifdef HAVE_SYSTEMD #ifdef HAVE_SYSTEMD

23
file.c
View File

@@ -41,13 +41,21 @@ RB_GENERATE(client_files, client_file, entry, file_cmp);
static char * static char *
file_get_path(struct client *c, const char *file) file_get_path(struct client *c, const char *file)
{ {
char *path; const char *home;
char *path, *full_path;
if (*file == '/') if (strncmp(file, "~/", 2) != 0)
path = xstrdup(file); path = xstrdup(file);
else else {
xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file); home = find_home();
return (path); if (home == NULL)
home = "";
xasprintf(&path, "%s%s", home, file + 1);
}
if (*path == '/')
return (path);
xasprintf(&full_path, "%s/%s", server_client_get_cwd(c, NULL), path);
return (full_path);
} }
/* Tree comparison function. */ /* Tree comparison function. */
@@ -361,7 +369,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
size_t msglen; size_t msglen;
int fd = -1; int fd = -1;
u_int stream = file_next_stream++; u_int stream = file_next_stream++;
FILE *f; FILE *f = NULL;
size_t size; size_t size;
char buffer[BUFSIZ]; char buffer[BUFSIZ];
@@ -401,7 +409,6 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
cf->error = EIO; cf->error = EIO;
goto done; goto done;
} }
fclose(f);
goto done; goto done;
} }
@@ -424,6 +431,8 @@ skip:
return cf; return cf;
done: done:
if (f != NULL)
fclose(f);
file_fire_done(cf); file_fire_done(cf);
return NULL; return NULL;
} }

View File

@@ -719,7 +719,7 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
int focus_start = -1, focus_end = -1; int focus_start = -1, focus_end = -1;
int list_state = -1, fill = -1, even; int list_state = -1, fill = -1, even;
enum style_align list_align = STYLE_ALIGN_DEFAULT; enum style_align list_align = STYLE_ALIGN_DEFAULT;
struct grid_cell gc, current_default; struct grid_cell gc, current_default, base_default;
struct style sy, saved_sy; struct style sy, saved_sy;
struct utf8_data *ud = &sy.gc.data; struct utf8_data *ud = &sy.gc.data;
const char *cp, *end; const char *cp, *end;
@@ -729,7 +729,9 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
struct format_ranges frs; struct format_ranges frs;
struct style_range *sr; struct style_range *sr;
memcpy(&base_default, base, sizeof base_default);
memcpy(&current_default, base, sizeof current_default); memcpy(&current_default, base, sizeof current_default);
base = &base_default;
style_set(&sy, &current_default); style_set(&sy, &current_default);
TAILQ_INIT(&frs); TAILQ_INIT(&frs);
log_debug("%s: %s", __func__, expanded); log_debug("%s: %s", __func__, expanded);
@@ -847,6 +849,12 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
} else if (sy.default_type == STYLE_DEFAULT_POP) { } else if (sy.default_type == STYLE_DEFAULT_POP) {
memcpy(&current_default, base, sizeof current_default); memcpy(&current_default, base, sizeof current_default);
sy.default_type = STYLE_DEFAULT_BASE; sy.default_type = STYLE_DEFAULT_BASE;
} else if (sy.default_type == STYLE_DEFAULT_SET) {
memcpy(&base_default, &saved_sy.gc,
sizeof base_default);
memcpy(&current_default, &saved_sy.gc,
sizeof current_default);
sy.default_type = STYLE_DEFAULT_BASE;
} }
/* Check the list state. */ /* Check the list state. */
@@ -1096,8 +1104,6 @@ format_width(const char *expanded)
more = utf8_append(&ud, *cp); more = utf8_append(&ud, *cp);
if (more == UTF8_DONE) if (more == UTF8_DONE)
width += ud.width; width += ud.width;
else
cp -= ud.have;
} else if (*cp > 0x1f && *cp < 0x7f) { } else if (*cp > 0x1f && *cp < 0x7f) {
width++; width++;
cp++; cp++;

935
format.c

File diff suppressed because it is too large Load Diff

View File

@@ -180,19 +180,14 @@ grid_reader_handle_wrap(struct grid_reader *gr, u_int *xx, u_int *yy)
int int
grid_reader_in_set(struct grid_reader *gr, const char *set) grid_reader_in_set(struct grid_reader *gr, const char *set)
{ {
struct grid_cell gc; return (grid_in_set(gr->gd, gr->cx, gr->cy, set));
grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
if (gc.flags & GRID_FLAG_PADDING)
return (0);
return (utf8_cstrhas(set, &gc.data));
} }
/* Move cursor to the start of the next word. */ /* Move cursor to the start of the next word. */
void void
grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators) grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
{ {
u_int xx, yy; u_int xx, yy, width;
/* Do not break up wrapped words. */ /* Do not break up wrapped words. */
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED) if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
@@ -229,8 +224,8 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
} }
} }
while (grid_reader_handle_wrap(gr, &xx, &yy) && while (grid_reader_handle_wrap(gr, &xx, &yy) &&
grid_reader_in_set(gr, WHITESPACE)) (width = grid_reader_in_set(gr, WHITESPACE)))
gr->cx++; gr->cx += width;
} }
/* Move cursor to the end of the next word. */ /* Move cursor to the end of the next word. */
@@ -338,6 +333,20 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
gr->cy = oldy; gr->cy = oldy;
} }
/* Compare grid cell to UTF-8 data. Return 1 if equal, 0 if not. */
static int
grid_reader_cell_equals_data(const struct grid_cell *gc,
const struct utf8_data *ud)
{
if (gc->flags & GRID_FLAG_PADDING)
return (0);
if (gc->flags & GRID_FLAG_TAB && ud->size == 1 && *ud->data == '\t')
return (1);
if (gc->data.size != ud->size)
return (0);
return (memcmp(gc->data.data, ud->data, gc->data.size) == 0);
}
/* Jump forward to character. */ /* Jump forward to character. */
int int
grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc) grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
@@ -352,9 +361,7 @@ grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
xx = grid_line_length(gr->gd, py); xx = grid_line_length(gr->gd, py);
while (px < xx) { while (px < xx) {
grid_get_cell(gr->gd, px, py, &gc); grid_get_cell(gr->gd, px, py, &gc);
if (!(gc.flags & GRID_FLAG_PADDING) && if (grid_reader_cell_equals_data(&gc, jc)) {
gc.data.size == jc->size &&
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
gr->cx = px; gr->cx = px;
gr->cy = py; gr->cy = py;
return (1); return (1);
@@ -382,9 +389,7 @@ grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
for (py = gr->cy + 1; py > 0; py--) { for (py = gr->cy + 1; py > 0; py--) {
for (px = xx; px > 0; px--) { for (px = xx; px > 0; px--) {
grid_get_cell(gr->gd, px - 1, py - 1, &gc); grid_get_cell(gr->gd, px - 1, py - 1, &gc);
if (!(gc.flags & GRID_FLAG_PADDING) && if (grid_reader_cell_equals_data(&gc, jc)) {
gc.data.size == jc->size &&
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
gr->cx = px - 1; gr->cx = px - 1;
gr->cy = py - 1; gr->cy = py - 1;
return (1); return (1);
@@ -415,7 +420,9 @@ grid_reader_cursor_back_to_indentation(struct grid_reader *gr)
xx = grid_line_length(gr->gd, py); xx = grid_line_length(gr->gd, py);
for (px = 0; px < xx; px++) { for (px = 0; px < xx; px++) {
grid_get_cell(gr->gd, px, py, &gc); grid_get_cell(gr->gd, px, py, &gc);
if (gc.data.size != 1 || *gc.data.data != ' ') { if ((gc.data.size != 1 || *gc.data.data != ' ') &&
~gc.flags & GRID_FLAG_TAB &&
~gc.flags & GRID_FLAG_PADDING) {
gr->cx = px; gr->cx = px;
gr->cy = py; gr->cy = py;
return; return;

View File

@@ -173,7 +173,7 @@ grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
sy = grid_view_y(gd, gd->sy); sy = grid_view_y(gd, gd->sy);
grid_move_lines(gd, py, py + ny, sy - py - ny, bg); grid_move_lines(gd, py, py + ny, sy - py - ny, bg);
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg); grid_clear(gd, 0, sy - ny, gd->sx, ny, bg);
} }
/* Delete lines inside scroll region. */ /* Delete lines inside scroll region. */
@@ -221,7 +221,7 @@ grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
sx = grid_view_x(gd, gd->sx); sx = grid_view_x(gd, gd->sx);
grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg); grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg); grid_clear(gd, sx - nx, py, nx, 1, bg);
} }
/* Convert cells into a string. */ /* Convert cells into a string. */

77
grid.c
View File

@@ -84,7 +84,7 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
return (1); return (1);
if (gc->attr > 0xff) if (gc->attr > 0xff)
return (1); return (1);
if (gc->data.size != 1 || gc->data.width != 1) if (gc->data.size > 1 || gc->data.width > 1)
return (1); return (1);
if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB)) if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB))
return (1); return (1);
@@ -92,6 +92,8 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
return (1); return (1);
if (gc->link != 0) if (gc->link != 0)
return (1); return (1);
if (gc->flags & GRID_FLAG_TAB)
return (1);
return (0); return (0);
} }
@@ -124,7 +126,10 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
fatalx("offset too big"); fatalx("offset too big");
gl->flags |= GRID_LINE_EXTENDED; gl->flags |= GRID_LINE_EXTENDED;
utf8_from_data(&gc->data, &uc); if (gc->flags & GRID_FLAG_TAB)
uc = gc->data.width;
else
utf8_from_data(&gc->data, &uc);
gee = &gl->extddata[gce->offset]; gee = &gl->extddata[gce->offset];
gee->data = uc; gee->data = uc;
@@ -230,9 +235,13 @@ grid_check_y(struct grid *gd, const char *from, u_int py)
int int
grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2) grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
{ {
int flags1 = gc1->flags, flags2 = gc2->flags;;
if (gc1->fg != gc2->fg || gc1->bg != gc2->bg) if (gc1->fg != gc2->fg || gc1->bg != gc2->bg)
return (0); return (0);
if (gc1->attr != gc2->attr || gc1->flags != gc2->flags) if (gc1->attr != gc2->attr)
return (0);
if ((flags1 & ~GRID_FLAG_CLEARED) != (flags2 & ~GRID_FLAG_CLEARED))
return (0); return (0);
if (gc1->link != gc2->link) if (gc1->link != gc2->link)
return (0); return (0);
@@ -252,6 +261,17 @@ grid_cells_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
return (memcmp(gc1->data.data, gc2->data.data, gc1->data.size) == 0); return (memcmp(gc1->data.data, gc2->data.data, gc1->data.size) == 0);
} }
/* Set grid cell to a tab. */
void
grid_set_tab(struct grid_cell *gc, u_int width)
{
memset(gc->data.data, 0, sizeof gc->data.data);
gc->flags |= GRID_FLAG_TAB;
gc->flags &= ~GRID_FLAG_PADDING;
gc->data.width = gc->data.size = gc->data.have = width;
memset(gc->data.data, ' ', gc->data.size);
}
/* Free one line. */ /* Free one line. */
static void static void
grid_free_line(struct grid *gd, u_int py) grid_free_line(struct grid *gd, u_int py)
@@ -515,7 +535,11 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
gc->bg = gee->bg; gc->bg = gee->bg;
gc->us = gee->us; gc->us = gee->us;
gc->link = gee->link; gc->link = gee->link;
utf8_to_data(gee->data, &gc->data);
if (gc->flags & GRID_FLAG_TAB)
grid_set_tab(gc, gee->data);
else
utf8_to_data(gee->data, &gc->data);
} }
return; return;
} }
@@ -1077,13 +1101,18 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
} else } else
codelen = 0; codelen = 0;
data = gc.data.data; if (gc.flags & GRID_FLAG_TAB) {
size = gc.data.size; data = "\t";
if ((flags & GRID_STRING_ESCAPE_SEQUENCES) && size = 1;
size == 1 && } else {
*data == '\\') { data = gc.data.data;
data = "\\\\"; size = gc.data.size;
size = 2; if ((flags & GRID_STRING_ESCAPE_SEQUENCES) &&
size == 1 &&
*data == '\\') {
data = "\\\\";
size = 2;
}
} }
while (len < off + size + codelen + 1) { while (len < off + size + codelen + 1) {
@@ -1275,7 +1304,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
if (!wrapped || want != from->cellused || width == sx) if (!wrapped || want != from->cellused || width == sx)
break; break;
} }
if (lines == 0) if (lines == 0 || from == NULL)
return; return;
/* /*
@@ -1533,3 +1562,27 @@ grid_line_length(struct grid *gd, u_int py)
} }
return (px); return (px);
} }
/* Check if character is in set. */
int
grid_in_set(struct grid *gd, u_int px, u_int py, const char *set)
{
struct grid_cell gc, tmp_gc;
u_int pxx;
grid_get_cell(gd, px, py, &gc);
if (strchr(set, '\t')) {
if (gc.flags & GRID_FLAG_PADDING) {
pxx = px;
do
grid_get_cell(gd, --pxx, py, &tmp_gc);
while (pxx > 0 && tmp_gc.flags & GRID_FLAG_PADDING);
if (tmp_gc.flags & GRID_FLAG_TAB)
return (tmp_gc.data.width - (px - pxx));
} else if (gc.flags & GRID_FLAG_TAB)
return (gc.data.width);
}
if (gc.flags & GRID_FLAG_PADDING)
return (0);
return (utf8_cstrhas(set, &gc.data));
}

View File

@@ -37,8 +37,14 @@ struct sixel_image {
u_int xpixel; u_int xpixel;
u_int ypixel; u_int ypixel;
u_int set_ra;
u_int ra_x;
u_int ra_y;
u_int *colours; u_int *colours;
u_int ncolours; u_int ncolours;
u_int used_colours;
u_int p2;
u_int dx; u_int dx;
u_int dy; u_int dy;
@@ -47,6 +53,19 @@ struct sixel_image {
struct sixel_line *lines; struct sixel_line *lines;
}; };
struct sixel_chunk {
u_int next_x;
u_int next_y;
u_int count;
char pattern;
char next_pattern;
size_t len;
size_t used;
char *data;
};
static int static int
sixel_parse_expand_lines(struct sixel_image *si, u_int y) sixel_parse_expand_lines(struct sixel_image *si, u_int y)
{ {
@@ -166,6 +185,10 @@ sixel_parse_attributes(struct sixel_image *si, const char *cp, const char *end)
si->x = x; si->x = x;
sixel_parse_expand_lines(si, y); sixel_parse_expand_lines(si, y);
si->set_ra = 1;
si->ra_x = x;
si->ra_y = y;
return (last); return (last);
} }
@@ -174,7 +197,7 @@ sixel_parse_colour(struct sixel_image *si, const char *cp, const char *end)
{ {
const char *last; const char *last;
char *endptr; char *endptr;
u_int c, type, r, g, b; u_int c, type, c1, c2, c3;
last = cp; last = cp;
while (last != end) { while (last != end) {
@@ -188,6 +211,8 @@ sixel_parse_colour(struct sixel_image *si, const char *cp, const char *end)
log_debug("%s: too many colours", __func__); log_debug("%s: too many colours", __func__);
return (NULL); return (NULL);
} }
if (si->used_colours <= c)
si->used_colours = c + 1;
si->dc = c + 1; si->dc = c + 1;
if (endptr == last || *endptr != ';') if (endptr == last || *endptr != ';')
return (last); return (last);
@@ -197,32 +222,36 @@ sixel_parse_colour(struct sixel_image *si, const char *cp, const char *end)
log_debug("%s: missing ;", __func__); log_debug("%s: missing ;", __func__);
return (NULL); return (NULL);
} }
r = strtoul(endptr + 1, &endptr, 10); c1 = strtoul(endptr + 1, &endptr, 10);
if (endptr == last || *endptr != ';') { if (endptr == last || *endptr != ';') {
log_debug("%s: missing ;", __func__); log_debug("%s: missing ;", __func__);
return (NULL); return (NULL);
} }
g = strtoul(endptr + 1, &endptr, 10); c2 = strtoul(endptr + 1, &endptr, 10);
if (endptr == last || *endptr != ';') { if (endptr == last || *endptr != ';') {
log_debug("%s: missing ;", __func__); log_debug("%s: missing ;", __func__);
return (NULL); return (NULL);
} }
b = strtoul(endptr + 1, &endptr, 10); c3 = strtoul(endptr + 1, &endptr, 10);
if (endptr != last) { if (endptr != last) {
log_debug("%s: missing ;", __func__); log_debug("%s: missing ;", __func__);
return (NULL); return (NULL);
} }
if (type != 1 && type != 2) { if ((type != 1 && type != 2) ||
log_debug("%s: invalid type %d", __func__, type); (type == 1 && (c1 > 360 || c2 > 100 || c3 > 100)) ||
(type == 2 && (c1 > 100 || c2 > 100 || c3 > 100))) {
log_debug("%s: invalid color %u;%u;%u;%u", __func__, type,
c1, c2, c3);
return (NULL); return (NULL);
} }
if (c + 1 > si->ncolours) { if (c + 1 > si->ncolours) {
si->colours = xrecallocarray(si->colours, si->ncolours, c + 1, si->colours = xrecallocarray(si->colours, si->ncolours, c + 1,
sizeof *si->colours); sizeof *si->colours);
si->ncolours = c + 1; si->ncolours = c + 1;
} }
si->colours[c] = (type << 24) | (r << 16) | (g << 8) | b; si->colours[c] = (type << 25) | (c1 << 16) | (c2 << 8) | c3;
return (last); return (last);
} }
@@ -268,7 +297,7 @@ sixel_parse_repeat(struct sixel_image *si, const char *cp, const char *end)
} }
struct sixel_image * struct sixel_image *
sixel_parse(const char *buf, size_t len, u_int xpixel, u_int ypixel) sixel_parse(const char *buf, size_t len, u_int p2, u_int xpixel, u_int ypixel)
{ {
struct sixel_image *si; struct sixel_image *si;
const char *cp = buf, *end = buf + len; const char *cp = buf, *end = buf + len;
@@ -282,6 +311,7 @@ sixel_parse(const char *buf, size_t len, u_int xpixel, u_int ypixel)
si = xcalloc (1, sizeof *si); si = xcalloc (1, sizeof *si);
si->xpixel = xpixel; si->xpixel = xpixel;
si->ypixel = ypixel; si->ypixel = ypixel;
si->p2 = p2;
while (cp != end) { while (cp != end) {
ch = *cp++; ch = *cp++;
@@ -393,8 +423,7 @@ sixel_scale(struct sixel_image *si, u_int xpixel, u_int ypixel, u_int ox,
/* /*
* We want to get the section of the image at ox,oy in image cells and * We want to get the section of the image at ox,oy in image cells and
* map it onto the same size in terminal cells, remembering that we * map it onto the same size in terminal cells.
* can only draw vertical sections of six pixels.
*/ */
sixel_size_in_cells(si, &cx, &cy); sixel_size_in_cells(si, &cx, &cy);
@@ -418,12 +447,25 @@ sixel_scale(struct sixel_image *si, u_int xpixel, u_int ypixel, u_int ox,
psy = sy * si->ypixel; psy = sy * si->ypixel;
tsx = sx * xpixel; tsx = sx * xpixel;
tsy = ((sy * ypixel) / 6) * 6; tsy = sy * ypixel;
new = xcalloc (1, sizeof *si); new = xcalloc (1, sizeof *si);
new->xpixel = xpixel; new->xpixel = xpixel;
new->ypixel = ypixel; new->ypixel = ypixel;
new->p2 = si->p2;
new->set_ra = si->set_ra;
/* clamp to slice end */
new->ra_x = si->ra_x < psx ? si->ra_x : psx;
new->ra_y = si->ra_y < psy ? si->ra_y : psy;
/* subtract slice origin */
new->ra_x = new->ra_x > pox ? new->ra_x - pox : 0;
new->ra_y = new->ra_y > poy ? new->ra_y - poy : 0;
/* resize */
new->ra_x = new->ra_x * xpixel / si->xpixel;
new->ra_y = new->ra_y * ypixel / si->ypixel;
new->used_colours = si->used_colours;
for (y = 0; y < tsy; y++) { for (y = 0; y < tsy; y++) {
py = poy + ((double)y * psy / tsy); py = poy + ((double)y * psy / tsy);
for (x = 0; x < tsx; x++) { for (x = 0; x < tsx; x++) {
@@ -432,7 +474,7 @@ sixel_scale(struct sixel_image *si, u_int xpixel, u_int ypixel, u_int ox,
} }
} }
if (colours) { if (colours && si->ncolours != 0) {
new->colours = xmalloc(si->ncolours * sizeof *new->colours); new->colours = xmalloc(si->ncolours * sizeof *new->colours);
for (i = 0; i < si->ncolours; i++) for (i = 0; i < si->ncolours; i++)
new->colours[i] = si->colours[i]; new->colours[i] = si->colours[i];
@@ -474,13 +516,66 @@ sixel_print_repeat(char **buf, size_t *len, size_t *used, u_int count, char ch)
} }
} }
static void
sixel_print_compress_colors(struct sixel_image *si, struct sixel_chunk *chunks,
u_int y, u_int *active, u_int *nactive)
{
u_int i, x, c, dx, colors[6];
struct sixel_chunk *chunk = NULL;
struct sixel_line *sl;
for (x = 0; x < si->x; x++) {
for (i = 0; i < 6; i++) {
colors[i] = 0;
if (y + i < si->y) {
sl = &si->lines[y + i];
if (x < sl->x && sl->data[x] != 0) {
colors[i] = sl->data[x];
c = sl->data[x] - 1;
chunks[c].next_pattern |= 1 << i;
}
}
}
for (i = 0; i < 6; i++) {
if (colors[i] == 0)
continue;
c = colors[i] - 1;
chunk = &chunks[c];
if (chunk->next_x == x + 1)
continue;
if (chunk->next_y < y + 1) {
chunk->next_y = y + 1;
active[(*nactive)++] = c;
}
dx = x - chunk->next_x;
if (chunk->pattern != chunk->next_pattern || dx != 0) {
sixel_print_repeat(&chunk->data, &chunk->len,
&chunk->used, chunk->count,
chunk->pattern + 0x3f);
sixel_print_repeat(&chunk->data, &chunk->len,
&chunk->used, dx, '?');
chunk->pattern = chunk->next_pattern;
chunk->count = 0;
}
chunk->count++;
chunk->next_pattern = 0;
chunk->next_x = x + 1;
}
}
}
char * char *
sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size) sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size)
{ {
char *buf, tmp[64], *contains, data, last = 0; char *buf, tmp[64];
size_t len, used = 0, tmplen; size_t len, used = 0, tmplen;
u_int *colours, ncolours, i, c, x, y, count; u_int *colours, ncolours, used_colours, i, c, y;
struct sixel_line *sl; u_int *active, nactive;
struct sixel_chunk *chunks, *chunk;
if (map != NULL) { if (map != NULL) {
colours = map->colours; colours = map->colours;
@@ -490,72 +585,60 @@ sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size)
ncolours = si->ncolours; ncolours = si->ncolours;
} }
if (ncolours == 0) used_colours = si->used_colours;
if (used_colours == 0)
return (NULL); return (NULL);
contains = xcalloc(1, ncolours);
len = 8192; len = 8192;
buf = xmalloc(len); buf = xmalloc(len);
sixel_print_add(&buf, &len, &used, "\033Pq", 3); tmplen = xsnprintf(tmp, sizeof tmp, "\033P0;%uq", si->p2);
tmplen = xsnprintf(tmp, sizeof tmp, "\"1;1;%u;%u", si->x, si->y);
sixel_print_add(&buf, &len, &used, tmp, tmplen); sixel_print_add(&buf, &len, &used, tmp, tmplen);
if (si->set_ra) {
tmplen = xsnprintf(tmp, sizeof tmp, "\"1;1;%u;%u", si->ra_x,
si->ra_y);
sixel_print_add(&buf, &len, &used, tmp, tmplen);
}
chunks = xcalloc(used_colours, sizeof *chunks);
active = xcalloc(used_colours, sizeof *active);
for (i = 0; i < ncolours; i++) { for (i = 0; i < ncolours; i++) {
c = colours[i]; c = colours[i];
tmplen = xsnprintf(tmp, sizeof tmp, "#%u;%u;%u;%u;%u", tmplen = xsnprintf(tmp, sizeof tmp, "#%u;%u;%u;%u;%u",
i, c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff); i, c >> 25, (c >> 16) & 0x1ff, (c >> 8) & 0xff, c & 0xff);
sixel_print_add(&buf, &len, &used, tmp, tmplen); sixel_print_add(&buf, &len, &used, tmp, tmplen);
} }
for (y = 0; y < si->y; y += 6) { for (i = 0; i < used_colours; i++) {
memset(contains, 0, ncolours); chunk = &chunks[i];
for (x = 0; x < si->x; x++) { chunk->len = 8;
for (i = 0; i < 6; i++) { chunk->data = xmalloc(chunk->len);
if (y + i >= si->y) }
break;
sl = &si->lines[y + i];
if (x < sl->x && sl->data[x] != 0)
contains[sl->data[x] - 1] = 1;
}
}
for (c = 0; c < ncolours; c++) { for (y = 0; y < si->y; y += 6) {
if (!contains[c]) nactive = 0;
continue; sixel_print_compress_colors(si, chunks, y, active, &nactive);
for (i = 0; i < nactive; i++) {
c = active[i];
chunk = &chunks[c];
tmplen = xsnprintf(tmp, sizeof tmp, "#%u", c); tmplen = xsnprintf(tmp, sizeof tmp, "#%u", c);
sixel_print_add(&buf, &len, &used, tmp, tmplen); sixel_print_add(&buf, &len, &used, tmp, tmplen);
sixel_print_add(&buf, &len, &used, chunk->data,
count = 0; chunk->used);
for (x = 0; x < si->x; x++) { sixel_print_repeat(&buf, &len, &used, chunk->count,
data = 0; chunk->pattern + 0x3f);
for (i = 0; i < 6; i++) {
if (y + i >= si->y)
break;
sl = &si->lines[y + i];
if (x < sl->x && sl->data[x] == c + 1)
data |= (1 << i);
}
data += 0x3f;
if (data != last) {
sixel_print_repeat(&buf, &len, &used,
count, last);
last = data;
count = 1;
} else
count++;
}
sixel_print_repeat(&buf, &len, &used, count, data);
sixel_print_add(&buf, &len, &used, "$", 1); sixel_print_add(&buf, &len, &used, "$", 1);
chunk->used = chunk->next_x = chunk->count = 0;
} }
if (buf[used - 1] == '$') if (buf[used - 1] == '$')
used--; used--;
if (buf[used - 1] != '-') sixel_print_add(&buf, &len, &used, "-", 1);
sixel_print_add(&buf, &len, &used, "-", 1);
} }
if (buf[used - 1] == '$' || buf[used - 1] == '-') if (buf[used - 1] == '-')
used--; used--;
sixel_print_add(&buf, &len, &used, "\033\\", 2); sixel_print_add(&buf, &len, &used, "\033\\", 2);
@@ -564,7 +647,11 @@ sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size)
if (size != NULL) if (size != NULL)
*size = used; *size = used;
free(contains); for (i = 0; i < used_colours; i++)
free(chunks[i].data);
free(active);
free(chunks);
return (buf); return (buf);
} }

View File

@@ -53,9 +53,15 @@ static struct input_key_entry input_key_defaults[] = {
{ .key = KEYC_PASTE_START, { .key = KEYC_PASTE_START,
.data = "\033[200~" .data = "\033[200~"
}, },
{ .key = KEYC_PASTE_START|KEYC_IMPLIED_META,
.data = "\033[200~"
},
{ .key = KEYC_PASTE_END, { .key = KEYC_PASTE_END,
.data = "\033[201~" .data = "\033[201~"
}, },
{ .key = KEYC_PASTE_END|KEYC_IMPLIED_META,
.data = "\033[201~"
},
/* Function keys. */ /* Function keys. */
{ .key = KEYC_F1, { .key = KEYC_F1,
@@ -307,6 +313,12 @@ static struct input_key_entry input_key_defaults[] = {
{ .key = KEYC_DC|KEYC_BUILD_MODIFIERS, { .key = KEYC_DC|KEYC_BUILD_MODIFIERS,
.data = "\033[3;_~" .data = "\033[3;_~"
}, },
{ .key = KEYC_REPORT_DARK_THEME,
.data = "\033[?997;1n"
},
{ .key = KEYC_REPORT_LIGHT_THEME,
.data = "\033[?997;2n"
},
}; };
static const key_code input_key_modifiers[] = { static const key_code input_key_modifiers[] = {
0, 0,
@@ -498,9 +510,12 @@ input_key_vt10x(struct bufferevent *bev, key_code key)
return (0); return (0);
} }
/* Prevent TAB and RET from being swallowed by C0 remapping logic. */ /*
* Prevent TAB, CR and LF from being swallowed by the C0 remapping
* logic.
*/
onlykey = key & KEYC_MASK_KEY; onlykey = key & KEYC_MASK_KEY;
if (onlykey == '\r' || onlykey == '\t') if (onlykey == '\r' || onlykey == '\n' || onlykey == '\t')
key &= ~KEYC_CTRL; key &= ~KEYC_CTRL;
/* /*
@@ -539,12 +554,16 @@ input_key_mode1(struct bufferevent *bev, key_code key)
log_debug("%s: key in %llx", __func__, key); log_debug("%s: key in %llx", __func__, key);
/* A regular or shifted key + Meta. */
if ((key & (KEYC_CTRL | KEYC_META)) == KEYC_META)
return (input_key_vt10x(bev, key));
/* /*
* As per * As per
* https://invisible-island.net/xterm/modified-keys-us-pc105.html. * https://invisible-island.net/xterm/modified-keys-us-pc105.html.
*/ */
onlykey = key & KEYC_MASK_KEY; onlykey = key & KEYC_MASK_KEY;
if ((key & (KEYC_META | KEYC_CTRL)) == KEYC_CTRL && if ((key & KEYC_CTRL) &&
(onlykey == ' ' || (onlykey == ' ' ||
onlykey == '/' || onlykey == '/' ||
onlykey == '@' || onlykey == '@' ||
@@ -553,13 +572,6 @@ input_key_mode1(struct bufferevent *bev, key_code key)
(onlykey >= '@' && onlykey <= '~'))) (onlykey >= '@' && onlykey <= '~')))
return (input_key_vt10x(bev, key)); return (input_key_vt10x(bev, key));
/*
* A regular key + Meta. In the absence of a standard to back this, we
* mimic what iTerm 2 does.
*/
if ((key & (KEYC_CTRL | KEYC_META)) == KEYC_META)
return (input_key_vt10x(bev, key));
return (-1); return (-1);
} }
@@ -585,14 +597,31 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key)
/* Is this backspace? */ /* Is this backspace? */
if ((key & KEYC_MASK_KEY) == KEYC_BSPACE) { if ((key & KEYC_MASK_KEY) == KEYC_BSPACE) {
newkey = options_get_number(global_options, "backspace"); newkey = options_get_number(global_options, "backspace");
if (newkey >= 0x7f) log_debug("%s: key 0x%llx is backspace -> 0x%llx", __func__,
newkey = '\177'; key, newkey);
key = newkey|(key & (KEYC_MASK_MODIFIERS|KEYC_MASK_FLAGS)); if ((key & KEYC_MASK_MODIFIERS) == 0) {
ud.data[0] = 255;
if ((newkey & KEYC_MASK_MODIFIERS) == 0)
ud.data[0] = newkey;
else if ((newkey & KEYC_MASK_MODIFIERS) == KEYC_CTRL) {
newkey &= KEYC_MASK_KEY;
if (newkey == '?')
ud.data[0] = 0x7f;
else if (newkey >= '@' && newkey <= '_')
ud.data[0] = newkey - 0x40;
else if (newkey >= 'a' && newkey <= 'z')
ud.data[0] = newkey - 0x60;
}
if (ud.data[0] != 255)
input_key_write(__func__, bev, &ud.data[0], 1);
return (0);
}
key = newkey|(key & (KEYC_MASK_FLAGS|KEYC_MASK_MODIFIERS));
} }
/* Is this backtab? */ /* Is this backtab? */
if ((key & KEYC_MASK_KEY) == KEYC_BTAB) { if ((key & KEYC_MASK_KEY) == KEYC_BTAB) {
if ((s->mode & EXTENDED_KEY_MODES) != 0) { if (s->mode & MODE_KEYS_EXTENDED_2) {
/* When in xterm extended mode, remap into S-Tab. */ /* When in xterm extended mode, remap into S-Tab. */
key = '\011' | (key & ~KEYC_MASK_KEY) | KEYC_SHIFT; key = '\011' | (key & ~KEYC_MASK_KEY) | KEYC_SHIFT;
} else { } else {
@@ -641,8 +670,7 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key)
if (ike != NULL) { if (ike != NULL) {
log_debug("%s: found key 0x%llx: \"%s\"", __func__, key, log_debug("%s: found key 0x%llx: \"%s\"", __func__, key,
ike->data); ike->data);
if ((key == KEYC_PASTE_START || key == KEYC_PASTE_END) && if (KEYC_IS_PASTE(key) && (~s->mode & MODE_BRACKETPASTE))
(~s->mode & MODE_BRACKETPASTE))
return (0); return (0);
if ((key & KEYC_META) && (~key & KEYC_IMPLIED_META)) if ((key & KEYC_META) && (~key & KEYC_IMPLIED_META))
input_key_write(__func__, bev, "\033", 1); input_key_write(__func__, bev, "\033", 1);

761
input.c

File diff suppressed because it is too large Load Diff

51
job.c
View File

@@ -50,7 +50,7 @@ struct job {
char *cmd; char *cmd;
pid_t pid; pid_t pid;
char tty[TTY_NAME_MAX]; char tty[TTY_NAME_MAX];
int status; int status;
int fd; int fd;
@@ -77,7 +77,7 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
struct job *job; struct job *job;
struct environ *env; struct environ *env;
pid_t pid; pid_t pid;
int nullfd, out[2], master; int nullfd, out[2], master, do_close = 1;
const char *home, *shell; const char *home, *shell;
sigset_t set, oldset; sigset_t set, oldset;
struct winsize ws; struct winsize ws;
@@ -139,10 +139,16 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
proc_clear_signals(server_proc, 1); proc_clear_signals(server_proc, 1);
sigprocmask(SIG_SETMASK, &oldset, NULL); sigprocmask(SIG_SETMASK, &oldset, NULL);
if ((cwd == NULL || chdir(cwd) != 0) && if (cwd != NULL) {
((home = find_home()) == NULL || chdir(home) != 0) && if (chdir(cwd) == 0)
chdir("/") != 0) environ_set(env, "PWD", 0, "%s", cwd);
fatal("chdir failed"); else if ((home = find_home()) != NULL && chdir(home) == 0)
environ_set(env, "PWD", 0, "%s", home);
else if (chdir("/") == 0)
environ_set(env, "PWD", 0, "/");
else
fatal("chdir failed");
}
environ_push(env); environ_push(env);
environ_free(env); environ_free(env);
@@ -150,24 +156,32 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
if (~flags & JOB_PTY) { if (~flags & JOB_PTY) {
if (dup2(out[1], STDIN_FILENO) == -1) if (dup2(out[1], STDIN_FILENO) == -1)
fatal("dup2 failed"); fatal("dup2 failed");
do_close = do_close && out[1] != STDIN_FILENO;
if (dup2(out[1], STDOUT_FILENO) == -1) if (dup2(out[1], STDOUT_FILENO) == -1)
fatal("dup2 failed"); fatal("dup2 failed");
if (out[1] != STDIN_FILENO && out[1] != STDOUT_FILENO) do_close = do_close && out[1] != STDOUT_FILENO;
if (flags & JOB_SHOWSTDERR) {
if (dup2(out[1], STDERR_FILENO) == -1)
fatal("dup2 failed");
do_close = do_close && out[1] != STDERR_FILENO;
} else {
nullfd = open(_PATH_DEVNULL, O_RDWR);
if (nullfd == -1)
fatal("open failed");
if (dup2(nullfd, STDERR_FILENO) == -1)
fatal("dup2 failed");
if (nullfd != STDERR_FILENO)
close(nullfd);
}
if (do_close)
close(out[1]); close(out[1]);
close(out[0]); close(out[0]);
nullfd = open(_PATH_DEVNULL, O_RDWR);
if (nullfd == -1)
fatal("open failed");
if (dup2(nullfd, STDERR_FILENO) == -1)
fatal("dup2 failed");
if (nullfd != STDERR_FILENO)
close(nullfd);
} }
closefrom(STDERR_FILENO + 1); closefrom(STDERR_FILENO + 1);
if (cmd != NULL) { if (cmd != NULL) {
setenv("SHELL", shell, 1); if (flags & JOB_DEFAULTSHELL)
setenv("SHELL", shell, 1);
execl(shell, argv0, "-c", cmd, (char *)NULL); execl(shell, argv0, "-c", cmd, (char *)NULL);
fatal("execl failed"); fatal("execl failed");
} else { } else {
@@ -181,7 +195,7 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
environ_free(env); environ_free(env);
free(argv0); free(argv0);
job = xmalloc(sizeof *job); job = xcalloc(1, sizeof *job);
job->state = JOB_RUNNING; job->state = JOB_RUNNING;
job->flags = flags; job->flags = flags;
@@ -190,7 +204,8 @@ job_run(const char *cmd, int argc, char **argv, struct environ *e,
else else
job->cmd = cmd_stringify_argv(argc, argv); job->cmd = cmd_stringify_argv(argc, argv);
job->pid = pid; job->pid = pid;
strlcpy(job->tty, tty, sizeof job->tty); if (flags & JOB_PTY)
strlcpy(job->tty, tty, sizeof job->tty);
job->status = 0; job->status = 0;
LIST_INSERT_HEAD(&all_jobs, job, entry); LIST_INSERT_HEAD(&all_jobs, job, entry);

View File

@@ -49,7 +49,7 @@
" '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top}" \ " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Top,}' '<' {send -X history-top}" \
" '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom}" \ " '#{?#{m/r:(copy|view)-mode,#{pane_mode}},Go To Bottom,}' '>' {send -X history-bottom}" \
" ''" \ " ''" \
" '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward \"#{q:mouse_word}\"}" \ " '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {if -F '#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}' 'copy-mode -t='; send -Xt= search-backward -- \"#{q:mouse_word}\"}" \
" '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"}" \ " '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {copy-mode -q; send-keys -l -- \"#{q:mouse_word}\"}" \
" '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"}" \ " '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {copy-mode -q; set-buffer -- \"#{q:mouse_word}\"}" \
" '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"}" \ " '#{?mouse_line,Copy Line,}' 'l' {copy-mode -q; set-buffer -- \"#{q:mouse_line}\"}" \
@@ -197,11 +197,12 @@ key_bindings_add(const char *name, key_code key, const char *note, int repeat,
bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS); bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
if (cmdlist == NULL) { if (cmdlist == NULL) {
if (bd != NULL) { if (bd != NULL) {
free((void *)bd->note); if (note != NULL) {
if (note != NULL) free((void *)bd->note);
bd->note = xstrdup(note); bd->note = xstrdup(note);
else }
bd->note = NULL; if (repeat)
bd->flags |= KEY_BINDING_REPEAT;
} }
return; return;
} }
@@ -433,8 +434,8 @@ key_bindings_init(void)
"bind -N 'Resize the pane right' -r C-Right { resize-pane -R }", "bind -N 'Resize the pane right' -r C-Right { resize-pane -R }",
/* Menu keys */ /* Menu keys */
"bind < { display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU " }", "bind -N 'Display window menu' < { display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU " }",
"bind > { display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }", "bind -N 'Display pane menu' > { display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
/* Mouse button 1 down on pane. */ /* Mouse button 1 down on pane. */
"bind -n MouseDown1Pane { select-pane -t=; send -M }", "bind -n MouseDown1Pane { select-pane -t=; send -M }",
@@ -443,7 +444,7 @@ key_bindings_init(void)
"bind -n MouseDrag1Pane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M } }", "bind -n MouseDrag1Pane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M } }",
/* Mouse wheel up on pane. */ /* Mouse wheel up on pane. */
"bind -n WheelUpPane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e } }", "bind -n WheelUpPane { if -F '#{||:#{alternate_on},#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e } }",
/* Mouse button 2 down on pane. */ /* Mouse button 2 down on pane. */
"bind -n MouseDown2Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p } }", "bind -n MouseDown2Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p } }",
@@ -458,7 +459,7 @@ key_bindings_init(void)
"bind -n MouseDrag1Border { resize-pane -M }", "bind -n MouseDrag1Border { resize-pane -M }",
/* Mouse button 1 down on status line. */ /* Mouse button 1 down on status line. */
"bind -n MouseDown1Status { select-window -t= }", "bind -n MouseDown1Status { switch-client -t= }",
/* Mouse wheel down on status line. */ /* Mouse wheel down on status line. */
"bind -n WheelDownStatus { next-window }", "bind -n WheelDownStatus { next-window }",
@@ -478,6 +479,11 @@ key_bindings_init(void)
"bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " } }", "bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " } }",
"bind -n M-MouseDown3Pane { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }", "bind -n M-MouseDown3Pane { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
/* Mouse on scrollbar. */
"bind -n MouseDown1ScrollbarUp { copy-mode -u }",
"bind -n MouseDown1ScrollbarDown { copy-mode -d }",
"bind -n MouseDrag1ScrollbarSlider { copy-mode -S }",
/* Copy mode (emacs) keys. */ /* Copy mode (emacs) keys. */
"bind -Tcopy-mode C-Space { send -X begin-selection }", "bind -Tcopy-mode C-Space { send -X begin-selection }",
"bind -Tcopy-mode C-a { send -X start-of-line }", "bind -Tcopy-mode C-a { send -X start-of-line }",
@@ -487,28 +493,30 @@ key_bindings_init(void)
"bind -Tcopy-mode C-b { send -X cursor-left }", "bind -Tcopy-mode C-b { send -X cursor-left }",
"bind -Tcopy-mode C-g { send -X clear-selection }", "bind -Tcopy-mode C-g { send -X clear-selection }",
"bind -Tcopy-mode C-k { send -X copy-pipe-end-of-line-and-cancel }", "bind -Tcopy-mode C-k { send -X copy-pipe-end-of-line-and-cancel }",
"bind -Tcopy-mode C-l { send -X cursor-centre-vertical }",
"bind -Tcopy-mode M-l { send -X cursor-centre-horizontal }",
"bind -Tcopy-mode C-n { send -X cursor-down }", "bind -Tcopy-mode C-n { send -X cursor-down }",
"bind -Tcopy-mode C-p { send -X cursor-up }", "bind -Tcopy-mode C-p { send -X cursor-up }",
"bind -Tcopy-mode C-r { command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental '%%' } }", "bind -Tcopy-mode C-r { command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental -- '%%' } }",
"bind -Tcopy-mode C-s { command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental '%%' } }", "bind -Tcopy-mode C-s { command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental -- '%%' } }",
"bind -Tcopy-mode C-v { send -X page-down }", "bind -Tcopy-mode C-v { send -X page-down }",
"bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }", "bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }",
"bind -Tcopy-mode Escape { send -X cancel }", "bind -Tcopy-mode Escape { send -X cancel }",
"bind -Tcopy-mode Space { send -X page-down }", "bind -Tcopy-mode Space { send -X page-down }",
"bind -Tcopy-mode , { send -X jump-reverse }", "bind -Tcopy-mode , { send -X jump-reverse }",
"bind -Tcopy-mode \\; { send -X jump-again }", "bind -Tcopy-mode \\; { send -X jump-again }",
"bind -Tcopy-mode F { command-prompt -1p'(jump backward)' { send -X jump-backward '%%' } }", "bind -Tcopy-mode F { command-prompt -1p'(jump backward)' { send -X jump-backward -- '%%' } }",
"bind -Tcopy-mode N { send -X search-reverse }", "bind -Tcopy-mode N { send -X search-reverse }",
"bind -Tcopy-mode P { send -X toggle-position }", "bind -Tcopy-mode P { send -X toggle-position }",
"bind -Tcopy-mode R { send -X rectangle-toggle }", "bind -Tcopy-mode R { send -X rectangle-toggle }",
"bind -Tcopy-mode T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward '%%' } }", "bind -Tcopy-mode T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }",
"bind -Tcopy-mode X { send -X set-mark }", "bind -Tcopy-mode X { send -X set-mark }",
"bind -Tcopy-mode f { command-prompt -1p'(jump forward)' { send -X jump-forward '%%' } }", "bind -Tcopy-mode f { command-prompt -1p'(jump forward)' { send -X jump-forward -- '%%' } }",
"bind -Tcopy-mode g { command-prompt -p'(goto line)' { send -X goto-line '%%' } }", "bind -Tcopy-mode g { command-prompt -p'(goto line)' { send -X goto-line -- '%%' } }",
"bind -Tcopy-mode n { send -X search-again }", "bind -Tcopy-mode n { send -X search-again }",
"bind -Tcopy-mode q { send -X cancel }", "bind -Tcopy-mode q { send -X cancel }",
"bind -Tcopy-mode r { send -X refresh-from-pane }", "bind -Tcopy-mode r { send -X refresh-from-pane }",
"bind -Tcopy-mode t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward '%%' } }", "bind -Tcopy-mode t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }",
"bind -Tcopy-mode Home { send -X start-of-line }", "bind -Tcopy-mode Home { send -X start-of-line }",
"bind -Tcopy-mode End { send -X end-of-line }", "bind -Tcopy-mode End { send -X end-of-line }",
"bind -Tcopy-mode MouseDown1Pane select-pane", "bind -Tcopy-mode MouseDown1Pane select-pane",
@@ -553,8 +561,8 @@ key_bindings_init(void)
"bind -Tcopy-mode C-Down { send -X scroll-down }", "bind -Tcopy-mode C-Down { send -X scroll-down }",
/* Copy mode (vi) keys. */ /* Copy mode (vi) keys. */
"bind -Tcopy-mode-vi '#' { send -FX search-backward '#{copy_cursor_word}' }", "bind -Tcopy-mode-vi '#' { send -FX search-backward -- '#{copy_cursor_word}' }",
"bind -Tcopy-mode-vi * { send -FX search-forward '#{copy_cursor_word}' }", "bind -Tcopy-mode-vi * { send -FX search-forward -- '#{copy_cursor_word}' }",
"bind -Tcopy-mode-vi C-c { send -X cancel }", "bind -Tcopy-mode-vi C-c { send -X cancel }",
"bind -Tcopy-mode-vi C-d { send -X halfpage-down }", "bind -Tcopy-mode-vi C-d { send -X halfpage-down }",
"bind -Tcopy-mode-vi C-e { send -X scroll-down }", "bind -Tcopy-mode-vi C-e { send -X scroll-down }",
@@ -570,7 +578,7 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi Space { send -X begin-selection }", "bind -Tcopy-mode-vi Space { send -X begin-selection }",
"bind -Tcopy-mode-vi '$' { send -X end-of-line }", "bind -Tcopy-mode-vi '$' { send -X end-of-line }",
"bind -Tcopy-mode-vi , { send -X jump-reverse }", "bind -Tcopy-mode-vi , { send -X jump-reverse }",
"bind -Tcopy-mode-vi / { command-prompt -T search -p'(search down)' { send -X search-forward '%%' } }", "bind -Tcopy-mode-vi / { command-prompt -T search -p'(search down)' { send -X search-forward -- '%%' } }",
"bind -Tcopy-mode-vi 0 { send -X start-of-line }", "bind -Tcopy-mode-vi 0 { send -X start-of-line }",
"bind -Tcopy-mode-vi 1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }", "bind -Tcopy-mode-vi 1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }",
"bind -Tcopy-mode-vi 2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }", "bind -Tcopy-mode-vi 2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }",
@@ -581,14 +589,14 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi 7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }", "bind -Tcopy-mode-vi 7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }",
"bind -Tcopy-mode-vi 8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }", "bind -Tcopy-mode-vi 8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }",
"bind -Tcopy-mode-vi 9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }", "bind -Tcopy-mode-vi 9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }",
"bind -Tcopy-mode-vi : { command-prompt -p'(goto line)' { send -X goto-line '%%' } }", "bind -Tcopy-mode-vi : { command-prompt -p'(goto line)' { send -X goto-line -- '%%' } }",
"bind -Tcopy-mode-vi \\; { send -X jump-again }", "bind -Tcopy-mode-vi \\; { send -X jump-again }",
"bind -Tcopy-mode-vi ? { command-prompt -T search -p'(search up)' { send -X search-backward '%%' } }", "bind -Tcopy-mode-vi ? { command-prompt -T search -p'(search up)' { send -X search-backward -- '%%' } }",
"bind -Tcopy-mode-vi A { send -X append-selection-and-cancel }", "bind -Tcopy-mode-vi A { send -X append-selection-and-cancel }",
"bind -Tcopy-mode-vi B { send -X previous-space }", "bind -Tcopy-mode-vi B { send -X previous-space }",
"bind -Tcopy-mode-vi D { send -X copy-pipe-end-of-line-and-cancel }", "bind -Tcopy-mode-vi D { send -X copy-pipe-end-of-line-and-cancel }",
"bind -Tcopy-mode-vi E { send -X next-space-end }", "bind -Tcopy-mode-vi E { send -X next-space-end }",
"bind -Tcopy-mode-vi F { command-prompt -1p'(jump backward)' { send -X jump-backward '%%' } }", "bind -Tcopy-mode-vi F { command-prompt -1p'(jump backward)' { send -X jump-backward -- '%%' } }",
"bind -Tcopy-mode-vi G { send -X history-bottom }", "bind -Tcopy-mode-vi G { send -X history-bottom }",
"bind -Tcopy-mode-vi H { send -X top-line }", "bind -Tcopy-mode-vi H { send -X top-line }",
"bind -Tcopy-mode-vi J { send -X scroll-down }", "bind -Tcopy-mode-vi J { send -X scroll-down }",
@@ -597,14 +605,14 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi M { send -X middle-line }", "bind -Tcopy-mode-vi M { send -X middle-line }",
"bind -Tcopy-mode-vi N { send -X search-reverse }", "bind -Tcopy-mode-vi N { send -X search-reverse }",
"bind -Tcopy-mode-vi P { send -X toggle-position }", "bind -Tcopy-mode-vi P { send -X toggle-position }",
"bind -Tcopy-mode-vi T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward '%%' } }", "bind -Tcopy-mode-vi T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward -- '%%' } }",
"bind -Tcopy-mode-vi V { send -X select-line }", "bind -Tcopy-mode-vi V { send -X select-line }",
"bind -Tcopy-mode-vi W { send -X next-space }", "bind -Tcopy-mode-vi W { send -X next-space }",
"bind -Tcopy-mode-vi X { send -X set-mark }", "bind -Tcopy-mode-vi X { send -X set-mark }",
"bind -Tcopy-mode-vi ^ { send -X back-to-indentation }", "bind -Tcopy-mode-vi ^ { send -X back-to-indentation }",
"bind -Tcopy-mode-vi b { send -X previous-word }", "bind -Tcopy-mode-vi b { send -X previous-word }",
"bind -Tcopy-mode-vi e { send -X next-word-end }", "bind -Tcopy-mode-vi e { send -X next-word-end }",
"bind -Tcopy-mode-vi f { command-prompt -1p'(jump forward)' { send -X jump-forward '%%' } }", "bind -Tcopy-mode-vi f { command-prompt -1p'(jump forward)' { send -X jump-forward -- '%%' } }",
"bind -Tcopy-mode-vi g { send -X history-top }", "bind -Tcopy-mode-vi g { send -X history-top }",
"bind -Tcopy-mode-vi h { send -X cursor-left }", "bind -Tcopy-mode-vi h { send -X cursor-left }",
"bind -Tcopy-mode-vi j { send -X cursor-down }", "bind -Tcopy-mode-vi j { send -X cursor-down }",
@@ -615,7 +623,7 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi o { send -X other-end }", "bind -Tcopy-mode-vi o { send -X other-end }",
"bind -Tcopy-mode-vi q { send -X cancel }", "bind -Tcopy-mode-vi q { send -X cancel }",
"bind -Tcopy-mode-vi r { send -X refresh-from-pane }", "bind -Tcopy-mode-vi r { send -X refresh-from-pane }",
"bind -Tcopy-mode-vi t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward '%%' } }", "bind -Tcopy-mode-vi t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward -- '%%' } }",
"bind -Tcopy-mode-vi v { send -X rectangle-toggle }", "bind -Tcopy-mode-vi v { send -X rectangle-toggle }",
"bind -Tcopy-mode-vi w { send -X next-word }", "bind -Tcopy-mode-vi w { send -X next-word }",
"bind -Tcopy-mode-vi '{' { send -X previous-paragraph }", "bind -Tcopy-mode-vi '{' { send -X previous-paragraph }",

View File

@@ -584,10 +584,11 @@ layout_set_main_v_mirrored(struct window *w)
void void
layout_set_tiled(struct window *w) layout_set_tiled(struct window *w)
{ {
struct options *oo = w->options;
struct window_pane *wp; struct window_pane *wp;
struct layout_cell *lc, *lcrow, *lcchild; struct layout_cell *lc, *lcrow, *lcchild;
u_int n, width, height, used, sx, sy; u_int n, width, height, used, sx, sy;
u_int i, j, columns, rows; u_int i, j, columns, rows, max_columns;
layout_print_cell(w->layout_root, __func__, 1); layout_print_cell(w->layout_root, __func__, 1);
@@ -596,11 +597,15 @@ layout_set_tiled(struct window *w)
if (n <= 1) if (n <= 1)
return; return;
/* Get maximum columns from window option. */
max_columns = options_get_number(oo, "tiled-layout-max-columns");
/* How many rows and columns are wanted? */ /* How many rows and columns are wanted? */
rows = columns = 1; rows = columns = 1;
while (rows * columns < n) { while (rows * columns < n) {
rows++; rows++;
if (rows * columns < n) if (rows * columns < n &&
(max_columns == 0 || columns < max_columns))
columns++; columns++;
} }

110
layout.c
View File

@@ -275,7 +275,8 @@ layout_cell_is_bottom(struct window *w, struct layout_cell *lc)
* the case for the most upper or lower panes only. * the case for the most upper or lower panes only.
*/ */
static int static int
layout_add_border(struct window *w, struct layout_cell *lc, int status) layout_add_horizontal_border(struct window *w, struct layout_cell *lc,
int status)
{ {
if (status == PANE_STATUS_TOP) if (status == PANE_STATUS_TOP)
return (layout_cell_is_top(w, lc)); return (layout_cell_is_top(w, lc));
@@ -290,22 +291,53 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
{ {
struct window_pane *wp; struct window_pane *wp;
struct layout_cell *lc; struct layout_cell *lc;
int status; int status, scrollbars, sb_pos, sb_w, sb_pad;
u_int sx, sy;
status = options_get_number(w->options, "pane-border-status"); status = options_get_number(w->options, "pane-border-status");
scrollbars = options_get_number(w->options, "pane-scrollbars");
sb_pos = options_get_number(w->options, "pane-scrollbars-position");
TAILQ_FOREACH(wp, &w->panes, entry) { TAILQ_FOREACH(wp, &w->panes, entry) {
if ((lc = wp->layout_cell) == NULL || wp == skip) if ((lc = wp->layout_cell) == NULL || wp == skip)
continue; continue;
wp->xoff = lc->xoff; wp->xoff = lc->xoff;
wp->yoff = lc->yoff; wp->yoff = lc->yoff;
sx = lc->sx;
sy = lc->sy;
if (layout_add_border(w, lc, status)) { if (layout_add_horizontal_border(w, lc, status)) {
if (status == PANE_STATUS_TOP) if (status == PANE_STATUS_TOP)
wp->yoff++; wp->yoff++;
window_pane_resize(wp, lc->sx, lc->sy - 1); sy--;
} else }
window_pane_resize(wp, lc->sx, lc->sy);
if (window_pane_show_scrollbar(wp, scrollbars)) {
sb_w = wp->scrollbar_style.width;
sb_pad = wp->scrollbar_style.pad;
if (sb_w < 1)
sb_w = 1;
if (sb_pad < 0)
sb_pad = 0;
if (sb_pos == PANE_SCROLLBARS_LEFT) {
if ((int)sx - sb_w < PANE_MINIMUM) {
wp->xoff = wp->xoff +
(int)sx - PANE_MINIMUM;
sx = PANE_MINIMUM;
} else {
sx = sx - sb_w - sb_pad;
wp->xoff = wp->xoff + sb_w + sb_pad;
}
} else /* sb_pos == PANE_SCROLLBARS_RIGHT */
if ((int)sx - sb_w - sb_pad < PANE_MINIMUM)
sx = PANE_MINIMUM;
else
sx = sx - sb_w - sb_pad;
wp->flags |= PANE_REDRAWSCROLLBAR;
}
window_pane_resize(wp, sx, sy);
} }
} }
@@ -336,18 +368,25 @@ layout_resize_check(struct window *w, struct layout_cell *lc,
enum layout_type type) enum layout_type type)
{ {
struct layout_cell *lcchild; struct layout_cell *lcchild;
struct style *sb_style = &w->active->scrollbar_style;
u_int available, minimum; u_int available, minimum;
int status; int status, scrollbars;
status = options_get_number(w->options, "pane-border-status"); status = options_get_number(w->options, "pane-border-status");
scrollbars = options_get_number(w->options, "pane-scrollbars");
if (lc->type == LAYOUT_WINDOWPANE) { if (lc->type == LAYOUT_WINDOWPANE) {
/* Space available in this cell only. */ /* Space available in this cell only. */
if (type == LAYOUT_LEFTRIGHT) { if (type == LAYOUT_LEFTRIGHT) {
available = lc->sx; available = lc->sx;
minimum = PANE_MINIMUM; if (scrollbars)
minimum = PANE_MINIMUM + sb_style->width +
sb_style->pad;
else
minimum = PANE_MINIMUM;
} else { } else {
available = lc->sy; available = lc->sy;
if (layout_add_border(w, lc, status)) if (layout_add_horizontal_border(w, lc, status))
minimum = PANE_MINIMUM + 1; minimum = PANE_MINIMUM + 1;
else else
minimum = PANE_MINIMUM; minimum = PANE_MINIMUM;
@@ -869,10 +908,12 @@ struct layout_cell *
layout_split_pane(struct window_pane *wp, enum layout_type type, int size, layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
int flags) int flags)
{ {
struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2; struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2;
u_int sx, sy, xoff, yoff, size1, size2, minimum; struct style *sb_style = &wp->scrollbar_style;
u_int new_size, saved_size, resize_first = 0; u_int sx, sy, xoff, yoff, size1, size2, minimum;
int full_size = (flags & SPAWN_FULLSIZE), status; u_int new_size, saved_size, resize_first = 0;
int full_size = (flags & SPAWN_FULLSIZE), status;
int scrollbars;
/* /*
* If full_size is specified, add a new cell at the top of the window * If full_size is specified, add a new cell at the top of the window
@@ -883,6 +924,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
else else
lc = wp->layout_cell; lc = wp->layout_cell;
status = options_get_number(wp->window->options, "pane-border-status"); status = options_get_number(wp->window->options, "pane-border-status");
scrollbars = options_get_number(wp->window->options, "pane-scrollbars");
/* Copy the old cell size. */ /* Copy the old cell size. */
sx = lc->sx; sx = lc->sx;
@@ -893,11 +935,16 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
/* Check there is enough space for the two new panes. */ /* Check there is enough space for the two new panes. */
switch (type) { switch (type) {
case LAYOUT_LEFTRIGHT: case LAYOUT_LEFTRIGHT:
if (sx < PANE_MINIMUM * 2 + 1) if (scrollbars) {
minimum = PANE_MINIMUM * 2 + sb_style->width +
sb_style->pad;
} else
minimum = PANE_MINIMUM * 2 + 1;
if (sx < minimum)
return (NULL); return (NULL);
break; break;
case LAYOUT_TOPBOTTOM: case LAYOUT_TOPBOTTOM:
if (layout_add_border(wp->window, lc, status)) if (layout_add_horizontal_border(wp->window, lc, status))
minimum = PANE_MINIMUM * 2 + 2; minimum = PANE_MINIMUM * 2 + 2;
else else
minimum = PANE_MINIMUM * 2 + 1; minimum = PANE_MINIMUM * 2 + 1;
@@ -1053,8 +1100,9 @@ int
layout_spread_cell(struct window *w, struct layout_cell *parent) layout_spread_cell(struct window *w, struct layout_cell *parent)
{ {
struct layout_cell *lc; struct layout_cell *lc;
u_int number, each, size, this; struct style *sb_style = &w->active->scrollbar_style;
int change, changed, status; u_int number, each, size, this, remainder;
int change, changed, status, scrollbars;
number = 0; number = 0;
TAILQ_FOREACH (lc, &parent->cells, entry) TAILQ_FOREACH (lc, &parent->cells, entry)
@@ -1062,11 +1110,16 @@ layout_spread_cell(struct window *w, struct layout_cell *parent)
if (number <= 1) if (number <= 1)
return (0); return (0);
status = options_get_number(w->options, "pane-border-status"); status = options_get_number(w->options, "pane-border-status");
scrollbars = options_get_number(w->options, "pane-scrollbars");
if (parent->type == LAYOUT_LEFTRIGHT) if (parent->type == LAYOUT_LEFTRIGHT) {
size = parent->sx; if (scrollbars)
size = parent->sx - sb_style->width + sb_style->pad;
else
size = parent->sx;
}
else if (parent->type == LAYOUT_TOPBOTTOM) { else if (parent->type == LAYOUT_TOPBOTTOM) {
if (layout_add_border(w, parent, status)) if (layout_add_horizontal_border(w, parent, status))
size = parent->sy - 1; size = parent->sy - 1;
else else
size = parent->sy; size = parent->sy;
@@ -1077,20 +1130,31 @@ layout_spread_cell(struct window *w, struct layout_cell *parent)
each = (size - (number - 1)) / number; each = (size - (number - 1)) / number;
if (each == 0) if (each == 0)
return (0); return (0);
/*
* Remaining space after assigning that which can be evenly
* distributed.
*/
remainder = size - (number * (each + 1)) + 1;
changed = 0; changed = 0;
TAILQ_FOREACH (lc, &parent->cells, entry) { TAILQ_FOREACH (lc, &parent->cells, entry) {
if (TAILQ_NEXT(lc, entry) == NULL)
each = size - ((each + 1) * (number - 1));
change = 0; change = 0;
if (parent->type == LAYOUT_LEFTRIGHT) { if (parent->type == LAYOUT_LEFTRIGHT) {
change = each - (int)lc->sx; change = each - (int)lc->sx;
if (remainder > 0) {
change++;
remainder--;
}
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change); layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change);
} else if (parent->type == LAYOUT_TOPBOTTOM) { } else if (parent->type == LAYOUT_TOPBOTTOM) {
if (layout_add_border(w, lc, status)) if (layout_add_horizontal_border(w, lc, status))
this = each + 1; this = each + 1;
else else
this = each; this = each;
if (remainder > 0) {
this++;
remainder--;
}
change = this - (int)lc->sy; change = this - (int)lc->sy;
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change); layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change);
} }

38
menu.c
View File

@@ -298,6 +298,7 @@ menu_key_cb(struct client *c, void *data, struct key_event *event)
} }
} }
switch (event->key & ~KEYC_MASK_FLAGS) { switch (event->key & ~KEYC_MASK_FLAGS) {
case KEYC_BTAB:
case KEYC_UP: case KEYC_UP:
case 'k': case 'k':
if (old == -1) if (old == -1)
@@ -363,7 +364,7 @@ menu_key_cb(struct client *c, void *data, struct key_event *event)
name = menu->items[md->choice].name; name = menu->items[md->choice].name;
if (md->choice != count - 1 && if (md->choice != count - 1 &&
(name != NULL && *name != '-')) (name != NULL && *name != '-'))
i++; i--;
else if (md->choice == count - 1) else if (md->choice == count - 1)
break; break;
} }
@@ -437,6 +438,38 @@ chosen:
return (1); return (1);
} }
static void
menu_resize_cb(struct client *c, void *data)
{
struct menu_data *md = data;
u_int nx, ny, w, h;
if (md == NULL)
return;
nx = md->px;
ny = md->py;
w = md->menu->width + 4;
h = md->menu->count + 2;
if (nx + w > c->tty.sx) {
if (c->tty.sx <= w)
nx = 0;
else
nx = c->tty.sx - w;
}
if (ny + h > c->tty.sy) {
if (c->tty.sy <= h)
ny = 0;
else
ny = c->tty.sy - h;
}
md->px = nx;
md->py = ny;
}
static void static void
menu_set_style(struct client *c, struct grid_cell *gc, const char *style, menu_set_style(struct client *c, struct grid_cell *gc, const char *style,
const char *option) const char *option)
@@ -453,7 +486,6 @@ menu_set_style(struct client *c, struct grid_cell *gc, const char *style,
gc->bg = sytmp.gc.bg; gc->bg = sytmp.gc.bg;
} }
} }
gc->attr = 0;
} }
struct menu_data * struct menu_data *
@@ -551,6 +583,6 @@ menu_display(struct menu *menu, int flags, int starting_choice,
if (md == NULL) if (md == NULL)
return (-1); return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb, server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,
menu_key_cb, menu_free_cb, NULL, md); menu_key_cb, menu_free_cb, menu_resize_cb, md);
return (0); return (0);
} }

View File

@@ -30,6 +30,12 @@ enum mode_tree_search_dir {
MODE_TREE_SEARCH_BACKWARD MODE_TREE_SEARCH_BACKWARD
}; };
enum mode_tree_preview {
MODE_TREE_PREVIEW_OFF,
MODE_TREE_PREVIEW_NORMAL,
MODE_TREE_PREVIEW_BIG
};
struct mode_tree_item; struct mode_tree_item;
TAILQ_HEAD(mode_tree_list, mode_tree_item); TAILQ_HEAD(mode_tree_list, mode_tree_item);
@@ -52,6 +58,7 @@ struct mode_tree_data {
mode_tree_menu_cb menucb; mode_tree_menu_cb menucb;
mode_tree_height_cb heightcb; mode_tree_height_cb heightcb;
mode_tree_key_cb keycb; mode_tree_key_cb keycb;
mode_tree_swap_cb swapcb;
struct mode_tree_list children; struct mode_tree_list children;
struct mode_tree_list saved; struct mode_tree_list saved;
@@ -60,6 +67,7 @@ struct mode_tree_data {
u_int line_size; u_int line_size;
u_int depth; u_int depth;
u_int maxdepth;
u_int width; u_int width;
u_int height; u_int height;
@@ -74,6 +82,7 @@ struct mode_tree_data {
char *filter; char *filter;
int no_matches; int no_matches;
enum mode_tree_search_dir search_dir; enum mode_tree_search_dir search_dir;
int search_icase;
}; };
struct mode_tree_item { struct mode_tree_item {
@@ -94,6 +103,7 @@ struct mode_tree_item {
int draw_as_parent; int draw_as_parent;
int no_tag; int no_tag;
int align;
struct mode_tree_list children; struct mode_tree_list children;
TAILQ_ENTRY(mode_tree_item) entry; TAILQ_ENTRY(mode_tree_item) entry;
@@ -123,6 +133,17 @@ static const struct menu_item mode_tree_menu_items[] = {
{ NULL, KEYC_NONE, NULL } { NULL, KEYC_NONE, NULL }
}; };
static int
mode_tree_is_lowercase(const char *ptr)
{
while (*ptr != '\0') {
if (*ptr != tolower((u_char)*ptr))
return (0);
++ptr;
}
return (1);
}
static struct mode_tree_item * static struct mode_tree_item *
mode_tree_find_item(struct mode_tree_list *mtl, uint64_t tag) mode_tree_find_item(struct mode_tree_list *mtl, uint64_t tag)
{ {
@@ -190,6 +211,8 @@ mode_tree_build_lines(struct mode_tree_data *mtd,
int flat = 1; int flat = 1;
mtd->depth = depth; mtd->depth = depth;
if (depth > mtd->maxdepth)
mtd->maxdepth = depth;
TAILQ_FOREACH(mti, mtl, entry) { TAILQ_FOREACH(mti, mtl, entry) {
mtd->line_list = xreallocarray(mtd->line_list, mtd->line_list = xreallocarray(mtd->line_list,
mtd->line_size + 1, sizeof *mtd->line_list); mtd->line_size + 1, sizeof *mtd->line_list);
@@ -278,6 +301,35 @@ mode_tree_down(struct mode_tree_data *mtd, int wrap)
return (1); return (1);
} }
static void
mode_tree_swap(struct mode_tree_data *mtd, int direction)
{
u_int current_depth = mtd->line_list[mtd->current].depth;
u_int swap_with, swap_with_depth;
if (mtd->swapcb == NULL)
return;
/* Find the next line at the same depth with the same parent . */
swap_with = mtd->current;
do {
if (direction < 0 && swap_with < (u_int)-direction)
return;
if (direction > 0 && swap_with + direction >= mtd->line_size)
return;
swap_with += direction;
swap_with_depth = mtd->line_list[swap_with].depth;
} while (swap_with_depth > current_depth);
if (swap_with_depth != current_depth)
return;
if (mtd->swapcb(mtd->line_list[mtd->current].item->itemdata,
mtd->line_list[swap_with].item->itemdata)) {
mtd->current = swap_with;
mode_tree_build(mtd);
}
}
void * void *
mode_tree_get_current(struct mode_tree_data *mtd) mode_tree_get_current(struct mode_tree_data *mtd)
{ {
@@ -350,8 +402,13 @@ mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
mtd->offset = 0; mtd->offset = 0;
return (1); return (1);
} }
mtd->current = 0; if (mtd->current >= mtd->line_size) {
mtd->offset = 0; mtd->current = mtd->line_size - 1;
if (mtd->current > mtd->height - 1)
mtd->offset = mtd->current - mtd->height + 1;
else
mtd->offset = 0;
}
return (0); return (0);
} }
@@ -396,9 +453,9 @@ struct mode_tree_data *
mode_tree_start(struct window_pane *wp, struct args *args, mode_tree_start(struct window_pane *wp, struct args *args,
mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb, mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,
mode_tree_search_cb searchcb, mode_tree_menu_cb menucb, mode_tree_search_cb searchcb, mode_tree_menu_cb menucb,
mode_tree_height_cb heightcb, mode_tree_key_cb keycb, void *modedata, mode_tree_height_cb heightcb, mode_tree_key_cb keycb,
const struct menu_item *menu, const char **sort_list, u_int sort_size, mode_tree_swap_cb swapcb, void *modedata, const struct menu_item *menu,
struct screen **s) const char **sort_list, u_int sort_size, struct screen **s)
{ {
struct mode_tree_data *mtd; struct mode_tree_data *mtd;
const char *sort; const char *sort;
@@ -414,7 +471,12 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->sort_list = sort_list; mtd->sort_list = sort_list;
mtd->sort_size = sort_size; mtd->sort_size = sort_size;
mtd->preview = !args_has(args, 'N'); if (args_has(args, 'N') > 1)
mtd->preview = MODE_TREE_PREVIEW_BIG;
else if (args_has(args, 'N'))
mtd->preview = MODE_TREE_PREVIEW_OFF;
else
mtd->preview = MODE_TREE_PREVIEW_NORMAL;
sort = args_get(args, 'O'); sort = args_get(args, 'O');
if (sort != NULL) { if (sort != NULL) {
@@ -436,6 +498,7 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->menucb = menucb; mtd->menucb = menucb;
mtd->heightcb = heightcb; mtd->heightcb = heightcb;
mtd->keycb = keycb; mtd->keycb = keycb;
mtd->swapcb = swapcb;
TAILQ_INIT(&mtd->children); TAILQ_INIT(&mtd->children);
@@ -470,12 +533,21 @@ mode_tree_set_height(struct mode_tree_data *mtd)
if (height < screen_size_y(s)) if (height < screen_size_y(s))
mtd->height = screen_size_y(s) - height; mtd->height = screen_size_y(s) - height;
} else { } else {
mtd->height = (screen_size_y(s) / 3) * 2; if (mtd->preview == MODE_TREE_PREVIEW_NORMAL) {
if (mtd->height > mtd->line_size) mtd->height = (screen_size_y(s) / 3) * 2;
mtd->height = screen_size_y(s) / 2; if (mtd->height > mtd->line_size)
mtd->height = screen_size_y(s) / 2;
if (mtd->height < 10)
mtd->height = screen_size_y(s);
} else if (mtd->preview == MODE_TREE_PREVIEW_BIG) {
mtd->height = screen_size_y(s) / 4;
if (mtd->height > mtd->line_size)
mtd->height = mtd->line_size;
if (mtd->height < 2)
mtd->height = 2;
} else
mtd->height = screen_size_y(s);
} }
if (mtd->height < 10)
mtd->height = screen_size_y(s);
if (screen_size_y(s) - mtd->height < 2) if (screen_size_y(s) - mtd->height < 2)
mtd->height = screen_size_y(s); mtd->height = screen_size_y(s);
} }
@@ -503,6 +575,7 @@ mode_tree_build(struct mode_tree_data *mtd)
TAILQ_INIT(&mtd->saved); TAILQ_INIT(&mtd->saved);
mode_tree_clear_lines(mtd); mode_tree_clear_lines(mtd);
mtd->maxdepth = 0;
mode_tree_build_lines(mtd, &mtd->children, 0); mode_tree_build_lines(mtd, &mtd->children, 0);
if (mtd->line_list != NULL && tag == UINT64_MAX) if (mtd->line_list != NULL && tag == UINT64_MAX)
@@ -510,7 +583,7 @@ mode_tree_build(struct mode_tree_data *mtd)
mode_tree_set_current(mtd, tag); mode_tree_set_current(mtd, tag);
mtd->width = screen_size_x(s); mtd->width = screen_size_x(s);
if (mtd->preview) if (mtd->preview != MODE_TREE_PREVIEW_OFF)
mode_tree_set_height(mtd); mode_tree_set_height(mtd);
else else
mtd->height = screen_size_y(s); mtd->height = screen_size_y(s);
@@ -607,6 +680,16 @@ mode_tree_no_tag(struct mode_tree_item *mti)
mti->no_tag = 1; mti->no_tag = 1;
} }
/*
* Set the alignment of mti->name: -1 to align left, 0 (default) to not align,
* or 1 to align right.
*/
void
mode_tree_align(struct mode_tree_item *mti, int align)
{
mti->align = align;
}
void void
mode_tree_remove(struct mode_tree_data *mtd, struct mode_tree_item *mti) mode_tree_remove(struct mode_tree_data *mtd, struct mode_tree_item *mti)
{ {
@@ -633,7 +716,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
char *text, *start, *key; char *text, *start, *key;
const char *tag, *symbol; const char *tag, *symbol;
size_t size, n; size_t size, n;
int keylen, pad; int keylen, pad, alignlen[mtd->maxdepth + 1];
if (mtd->line_size == 0) if (mtd->line_size == 0)
return; return;
@@ -657,6 +740,16 @@ mode_tree_draw(struct mode_tree_data *mtd)
keylen = mti->keylen + 3; keylen = mti->keylen + 3;
} }
for (i = 0; i < mtd->maxdepth + 1; i++)
alignlen[i] = 0;
for (i = 0; i < mtd->line_size; i++) {
line = &mtd->line_list[i];
mti = line->item;
if (mti->align &&
(int)strlen(mti->name) > alignlen[line->depth])
alignlen[line->depth] = strlen(mti->name);
}
for (i = 0; i < mtd->line_size; i++) { for (i = 0; i < mtd->line_size; i++) {
if (i < mtd->offset) if (i < mtd->offset)
continue; continue;
@@ -706,8 +799,9 @@ mode_tree_draw(struct mode_tree_data *mtd)
tag = "*"; tag = "*";
else else
tag = ""; tag = "";
xasprintf(&text, "%-*s%s%s%s%s", keylen, key, start, mti->name, xasprintf(&text, "%-*s%s%*s%s%s", keylen, key, start,
tag, (mti->text != NULL) ? ": " : "" ); mti->align * alignlen[line->depth], mti->name, tag,
(mti->text != NULL) ? ": " : "" );
width = utf8_cstrwidth(text); width = utf8_cstrwidth(text);
if (width > w) if (width > w)
width = w; width = w;
@@ -742,8 +836,11 @@ mode_tree_draw(struct mode_tree_data *mtd)
} }
} }
if (mtd->preview == MODE_TREE_PREVIEW_OFF)
goto done;
sy = screen_size_y(s); sy = screen_size_y(s);
if (!mtd->preview || sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) if (sy <= 4 || h < 2 || sy - h <= 4 || w <= 4)
goto done; goto done;
line = &mtd->line_list[mtd->current]; line = &mtd->line_list[mtd->current];
@@ -796,49 +893,57 @@ done:
static struct mode_tree_item * static struct mode_tree_item *
mode_tree_search_backward(struct mode_tree_data *mtd) mode_tree_search_backward(struct mode_tree_data *mtd)
{ {
struct mode_tree_item *mti, *last, *prev; struct mode_tree_item *mti, *last, *prev;
int icase = mtd->search_icase;
if (mtd->search == NULL) if (mtd->search == NULL)
return (NULL); return (NULL);
mti = last = mtd->line_list[mtd->current].item; mti = last = mtd->line_list[mtd->current].item;
for (;;) { for (;;) {
if ((prev = TAILQ_PREV(mti, mode_tree_list, entry)) != NULL) { if ((prev = TAILQ_PREV(mti, mode_tree_list, entry)) != NULL) {
/* Point to the last child in the previous subtree. */ /* Point to the last child in the previous subtree. */
while (!TAILQ_EMPTY(&prev->children)) while (!TAILQ_EMPTY(&prev->children)) {
prev = TAILQ_LAST(&prev->children, mode_tree_list); prev = TAILQ_LAST(&prev->children,
mti = prev; mode_tree_list);
} else { }
/* If prev is NULL, jump to the parent. */ mti = prev;
mti = mti->parent; } else {
} /* If prev is NULL, jump to the parent. */
mti = mti->parent;
}
if (mti == NULL) { if (mti == NULL) {
/* Point to the last child in the last root subtree. */ /* Point to the last child in the last root subtree. */
prev = TAILQ_LAST(&mtd->children, mode_tree_list); prev = TAILQ_LAST(&mtd->children, mode_tree_list);
while (!TAILQ_EMPTY(&prev->children)) while (!TAILQ_EMPTY(&prev->children)) {
prev = TAILQ_LAST(&prev->children, mode_tree_list); prev = TAILQ_LAST(&prev->children,
mti = prev; mode_tree_list);
} }
if (mti == last) mti = prev;
break; }
if (mti == last)
break;
if (mtd->searchcb == NULL) { if (mtd->searchcb == NULL) {
if (strstr(mti->name, mtd->search) != NULL) if (!icase && strstr(mti->name, mtd->search) != NULL)
return (mti);
if (icase && strcasestr(mti->name, mtd->search) != NULL)
return (mti);
continue;
}
if (mtd->searchcb(mtd->modedata, mti->itemdata, mtd->search,
icase))
return (mti); return (mti);
continue;
} }
if (mtd->searchcb(mtd->modedata, mti->itemdata, mtd->search)) return (NULL);
return (mti);
}
return (NULL);
} }
static struct mode_tree_item * static struct mode_tree_item *
mode_tree_search_forward(struct mode_tree_data *mtd) mode_tree_search_forward(struct mode_tree_data *mtd)
{ {
struct mode_tree_item *mti, *last, *next; struct mode_tree_item *mti, *last, *next;
int icase = mtd->search_icase;
if (mtd->search == NULL) if (mtd->search == NULL)
return (NULL); return (NULL);
@@ -866,11 +971,14 @@ mode_tree_search_forward(struct mode_tree_data *mtd)
break; break;
if (mtd->searchcb == NULL) { if (mtd->searchcb == NULL) {
if (strstr(mti->name, mtd->search) != NULL) if (!icase && strstr(mti->name, mtd->search) != NULL)
return (mti);
if (icase && strcasestr(mti->name, mtd->search) != NULL)
return (mti); return (mti);
continue; continue;
} }
if (mtd->searchcb(mtd->modedata, mti->itemdata, mtd->search)) if (mtd->searchcb(mtd->modedata, mti->itemdata, mtd->search,
icase))
return (mti); return (mti);
} }
return (NULL); return (NULL);
@@ -917,6 +1025,7 @@ mode_tree_search_callback(__unused struct client *c, void *data, const char *s,
return (0); return (0);
} }
mtd->search = xstrdup(s); mtd->search = xstrdup(s);
mtd->search_icase = mode_tree_is_lowercase(s);
mode_tree_search_set(mtd); mode_tree_search_set(mtd);
return (0); return (0);
@@ -1016,8 +1125,11 @@ mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
else else
x = 0; x = 0;
if (menu_display(menu, 0, 0, NULL, x, y, c, BOX_LINES_DEFAULT, NULL, if (menu_display(menu, 0, 0, NULL, x, y, c, BOX_LINES_DEFAULT, NULL,
NULL, NULL, NULL, mode_tree_menu_callback, mtm) != 0) NULL, NULL, NULL, mode_tree_menu_callback, mtm) != 0) {
mode_tree_remove_ref(mtd);
free(mtm);
menu_free(menu); menu_free(menu);
}
} }
int int
@@ -1041,7 +1153,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
if (x > mtd->width || y > mtd->height) { if (x > mtd->width || y > mtd->height) {
if (*key == KEYC_MOUSEDOWN3_PANE) if (*key == KEYC_MOUSEDOWN3_PANE)
mode_tree_display_menu(mtd, c, x, y, 1); mode_tree_display_menu(mtd, c, x, y, 1);
if (!mtd->preview) if (mtd->preview == MODE_TREE_PREVIEW_OFF)
*key = KEYC_NONE; *key = KEYC_NONE;
return (0); return (0);
} }
@@ -1102,6 +1214,14 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
case 'n'|KEYC_CTRL: case 'n'|KEYC_CTRL:
mode_tree_down(mtd, 1); mode_tree_down(mtd, 1);
break; break;
case KEYC_UP|KEYC_SHIFT:
case 'K':
mode_tree_swap(mtd, -1);
break;
case KEYC_DOWN|KEYC_SHIFT:
case 'J':
mode_tree_swap(mtd, 1);
break;
case KEYC_PPAGE: case KEYC_PPAGE:
case 'b'|KEYC_CTRL: case 'b'|KEYC_CTRL:
for (i = 0; i < mtd->height; i++) { for (i = 0; i < mtd->height; i++) {
@@ -1213,6 +1333,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
case '/': case '/':
case 's'|KEYC_CTRL: case 's'|KEYC_CTRL:
mtd->references++; mtd->references++;
mtd->search_dir = MODE_TREE_SEARCH_FORWARD;
status_prompt_set(c, NULL, "(search) ", "", status_prompt_set(c, NULL, "(search) ", "",
mode_tree_search_callback, mode_tree_search_free, mtd, mode_tree_search_callback, mode_tree_search_free, mtd,
PROMPT_NOFORMAT, PROMPT_TYPE_SEARCH); PROMPT_NOFORMAT, PROMPT_TYPE_SEARCH);
@@ -1232,9 +1353,19 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
PROMPT_NOFORMAT, PROMPT_TYPE_SEARCH); PROMPT_NOFORMAT, PROMPT_TYPE_SEARCH);
break; break;
case 'v': case 'v':
mtd->preview = !mtd->preview; switch (mtd->preview) {
case MODE_TREE_PREVIEW_OFF:
mtd->preview = MODE_TREE_PREVIEW_BIG;
break;
case MODE_TREE_PREVIEW_NORMAL:
mtd->preview = MODE_TREE_PREVIEW_OFF;
break;
case MODE_TREE_PREVIEW_BIG:
mtd->preview = MODE_TREE_PREVIEW_NORMAL;
break;
}
mode_tree_build(mtd); mode_tree_build(mtd);
if (mtd->preview) if (mtd->preview != MODE_TREE_PREVIEW_OFF)
mode_tree_check_selected(mtd); mode_tree_check_selected(mtd);
break; break;
} }
@@ -1256,7 +1387,7 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
if (status == CMD_PARSE_ERROR) { if (status == CMD_PARSE_ERROR) {
if (c != NULL) { if (c != NULL) {
*error = toupper((u_char)*error); *error = toupper((u_char)*error);
status_message_set(c, -1, 1, 0, "%s", error); status_message_set(c, -1, 1, 0, 0, "%s", error);
} }
free(error); free(error);
} }

View File

@@ -36,7 +36,7 @@ static const char *options_table_mode_keys_list[] = {
"emacs", "vi", NULL "emacs", "vi", NULL
}; };
static const char *options_table_clock_mode_style_list[] = { static const char *options_table_clock_mode_style_list[] = {
"12", "24", NULL "12", "24", "12-with-seconds", "24-with-seconds", NULL
}; };
static const char *options_table_status_list[] = { static const char *options_table_status_list[] = {
"off", "on", "2", "3", "4", "5", NULL "off", "on", "2", "3", "4", "5", NULL
@@ -63,6 +63,12 @@ static const char *options_table_cursor_style_list[] = {
"default", "blinking-block", "block", "blinking-underline", "underline", "default", "blinking-block", "block", "blinking-underline", "underline",
"blinking-bar", "bar", NULL "blinking-bar", "bar", NULL
}; };
static const char *options_table_pane_scrollbars_list[] = {
"off", "modal", "on", NULL
};
static const char *options_table_pane_scrollbars_position_list[] = {
"right", "left", NULL
};
static const char *options_table_pane_status_list[] = { static const char *options_table_pane_status_list[] = {
"off", "top", "bottom", NULL "off", "top", "bottom", NULL
}; };
@@ -70,7 +76,7 @@ static const char *options_table_pane_border_indicators_list[] = {
"off", "colour", "arrows", "both", NULL "off", "colour", "arrows", "both", NULL
}; };
static const char *options_table_pane_border_lines_list[] = { static const char *options_table_pane_border_lines_list[] = {
"single", "double", "heavy", "simple", "number", NULL "single", "double", "heavy", "simple", "number", "spaces", NULL
}; };
static const char *options_table_popup_border_lines_list[] = { static const char *options_table_popup_border_lines_list[] = {
"single", "double", "heavy", "simple", "rounded", "padded", "none", NULL "single", "double", "heavy", "simple", "rounded", "padded", "none", NULL
@@ -132,7 +138,7 @@ static const char *options_table_allow_passthrough_list[] = {
"#{T:window-status-format}" \ "#{T:window-status-format}" \
"#[pop-default]" \ "#[pop-default]" \
"#[norange default]" \ "#[norange default]" \
"#{?window_end_flag,,#{window-status-separator}}" \ "#{?loop_last_flag,,#{window-status-separator}}" \
"," \ "," \
"#[range=window|#{window_index} list=focus " \ "#[range=window|#{window_index} list=focus " \
"#{?#{!=:#{E:window-status-current-style},default}," \ "#{?#{!=:#{E:window-status-current-style},default}," \
@@ -159,7 +165,7 @@ static const char *options_table_allow_passthrough_list[] = {
"#{T:window-status-current-format}" \ "#{T:window-status-current-format}" \
"#[pop-default]" \ "#[pop-default]" \
"#[norange list=on default]" \ "#[norange list=on default]" \
"#{?window_end_flag,,#{window-status-separator}}" \ "#{?loop_last_flag,,#{window-status-separator}}" \
"}" \ "}" \
"#[nolist align=right range=right #{E:status-right-style}]" \ "#[nolist align=right range=right #{E:status-right-style}]" \
"#[push-default]" \ "#[push-default]" \
@@ -167,10 +173,60 @@ static const char *options_table_allow_passthrough_list[] = {
"#[pop-default]" \ "#[pop-default]" \
"#[norange default]" "#[norange default]"
#define OPTIONS_TABLE_STATUS_FORMAT2 \ #define OPTIONS_TABLE_STATUS_FORMAT2 \
"#[align=centre]#{P:#{?pane_active,#[reverse],}" \ "#[align=left]#{R: ,#{n:#{session_name}}}P: " \
"#{pane_index}[#{pane_width}x#{pane_height}]#[default] }" "#[norange default]" \
"#[list=on align=#{status-justify}]" \
"#[list=left-marker]<#[list=right-marker]>#[list=on]" \
"#{P:" \
"#[range=pane|#{pane_id} " \
"#{E:pane-status-style}" \
"]" \
"#[push-default]" \
"#P[#{pane_width}x#{pane_height}]" \
"#[pop-default]" \
"#[norange list=on default] " \
"," \
"#[range=pane|#{pane_id} list=focus " \
"#{?#{!=:#{E:pane-status-current-style},default}," \
"#{E:pane-status-current-style}," \
"#{E:pane-status-style}" \
"}" \
"]" \
"#[push-default]" \
"#P[#{pane_width}x#{pane_height}]*" \
"#[pop-default]" \
"#[norange list=on default] " \
"}"
#define OPTIONS_TABLE_STATUS_FORMAT3 \
"#[align=left]#{R: ,#{n:#{session_name}}}S: " \
"#[norange default]" \
"#[list=on align=#{status-justify}]" \
"#[list=left-marker]<#[list=right-marker]>#[list=on]" \
"#{S:" \
"#[range=session|#{session_id} " \
"#{E:session-status-style}" \
"]" \
"#[push-default]" \
"#S#{session_alert}" \
"#[pop-default]" \
"#[norange list=on default] " \
"," \
"#[range=session|#{session_id} list=focus " \
"#{?#{!=:#{E:session-status-current-style},default}," \
"#{E:session-status-current-style}," \
"#{E:session-status-style}" \
"}" \
"]" \
"#[push-default]" \
"#S*#{session_alert}" \
"#[pop-default]" \
"#[norange list=on default] " \
"}"
static const char *options_table_status_format_default[] = { static const char *options_table_status_format_default[] = {
OPTIONS_TABLE_STATUS_FORMAT1, OPTIONS_TABLE_STATUS_FORMAT2, NULL OPTIONS_TABLE_STATUS_FORMAT1,
OPTIONS_TABLE_STATUS_FORMAT2,
OPTIONS_TABLE_STATUS_FORMAT3,
NULL
}; };
/* Helpers for hook options. */ /* Helpers for hook options. */
@@ -207,6 +263,7 @@ const struct options_name_map options_other_names[] = {
{ "display-panes-active-color", "display-panes-active-colour" }, { "display-panes-active-color", "display-panes-active-colour" },
{ "clock-mode-color", "clock-mode-colour" }, { "clock-mode-color", "clock-mode-colour" },
{ "cursor-color", "cursor-colour" }, { "cursor-color", "cursor-colour" },
{ "prompt-cursor-color", "prompt-cursor-colour" },
{ "pane-colors", "pane-colours" }, { "pane-colors", "pane-colours" },
{ NULL, NULL } { NULL, NULL }
}; };
@@ -246,6 +303,15 @@ const struct options_table_entry options_table[] = {
"Each entry is an alias and a command separated by '='." "Each entry is an alias and a command separated by '='."
}, },
{ .name = "codepoint-widths",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER,
.flags = OPTIONS_TABLE_IS_ARRAY,
.default_str = "",
.separator = ",",
.text = "Array of override widths for Unicode codepoints."
},
{ .name = "copy-command", { .name = "copy-command",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER, .scope = OPTIONS_TABLE_SERVER,
@@ -269,6 +335,13 @@ const struct options_table_entry options_table[] = {
.text = "Style of the cursor." .text = "Style of the cursor."
}, },
{ .name = "default-client-command",
.type = OPTIONS_TABLE_COMMAND,
.scope = OPTIONS_TABLE_SERVER,
.default_str = "new-session",
.text = "Default command to run when tmux is run without a command."
},
{ .name = "default-terminal", { .name = "default-terminal",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SERVER, .scope = OPTIONS_TABLE_SERVER,
@@ -340,6 +413,15 @@ const struct options_table_entry options_table[] = {
"Empty does not write a history file." "Empty does not write a history file."
}, },
{ .name = "input-buffer-size",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SERVER,
.minimum = INPUT_BUF_DEFAULT_SIZE,
.maximum = UINT_MAX,
.default_num = INPUT_BUF_DEFAULT_SIZE,
.text = "Number of bytes accepted in a single input before dropping."
},
{ .name = "menu-style", { .name = "menu-style",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
@@ -373,7 +455,7 @@ const struct options_table_entry options_table[] = {
.choices = options_table_popup_border_lines_list, .choices = options_table_popup_border_lines_list,
.default_num = BOX_LINES_SINGLE, .default_num = BOX_LINES_SINGLE,
.text = "Type of characters used to draw menu border lines. Some of " .text = "Type of characters used to draw menu border lines. Some of "
"these are only supported on terminals with UTF-8 support." "these are only supported on terminals with UTF-8 support."
}, },
{ .name = "message-limit", { .name = "message-limit",
@@ -393,7 +475,7 @@ const struct options_table_entry options_table[] = {
.default_num = 0, .default_num = 0,
.unit = "milliseconds", .unit = "milliseconds",
.text = "The timeout for the prefix key if no subsequent key is " .text = "The timeout for the prefix key if no subsequent key is "
"pressed. Zero means disabled." "pressed. Zero means disabled."
}, },
{ .name = "prompt-history-limit", { .name = "prompt-history-limit",
@@ -430,7 +512,7 @@ const struct options_table_entry options_table[] = {
.flags = OPTIONS_TABLE_IS_ARRAY, .flags = OPTIONS_TABLE_IS_ARRAY,
.default_str = "xterm*:clipboard:ccolour:cstyle:focus:title," .default_str = "xterm*:clipboard:ccolour:cstyle:focus:title,"
"screen*:title," "screen*:title,"
"rxvt*:ignorefkeys", "rxvt*:ignorefkeys",
.separator = ",", .separator = ",",
.text = "List of terminal features, used if they cannot be " .text = "List of terminal features, used if they cannot be "
"automatically detected." "automatically detected."
@@ -447,6 +529,14 @@ const struct options_table_entry options_table[] = {
"'User0', 'User1' and so on." "'User0', 'User1' and so on."
}, },
{ .name = "variation-selector-always-wide",
.type = OPTIONS_TABLE_FLAG,
.scope = OPTIONS_TABLE_SERVER,
.default_num = 1,
.text = "If the Unicode VS16 codepoint should always be treated as a "
"wide character."
},
/* Session options. */ /* Session options. */
{ .name = "activity-action", { .name = "activity-action",
.type = OPTIONS_TABLE_CHOICE, .type = OPTIONS_TABLE_CHOICE,
@@ -571,6 +661,18 @@ const struct options_table_entry options_table[] = {
"If changed, the new value applies only to new panes." "If changed, the new value applies only to new panes."
}, },
{ .name = "initial-repeat-time",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SESSION,
.minimum = 0,
.maximum = 2000000,
.default_num = 0,
.unit = "milliseconds",
.text = "Time to wait for a key binding to repeat the first time the "
"key is pressed, if it is bound with the '-r' flag. "
"Subsequent presses use the 'repeat-time' option."
},
{ .name = "key-table", { .name = "key-table",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
@@ -658,7 +760,7 @@ const struct options_table_entry options_table[] = {
.type = OPTIONS_TABLE_NUMBER, .type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.minimum = 0, .minimum = 0,
.maximum = SHRT_MAX, .maximum = 2000000,
.default_num = 500, .default_num = 500,
.unit = "milliseconds", .unit = "milliseconds",
.text = "Time to wait for a key binding to repeat, if it is bound " .text = "Time to wait for a key binding to repeat, if it is bound "
@@ -819,11 +921,64 @@ const struct options_table_entry options_table[] = {
.text = "Style of the status line." .text = "Style of the status line."
}, },
{ .name = "pane-status-current-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of the current pane in the status line."
},
{ .name = "pane-status-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of panes in the status line, except the current "
"pane."
},
{ .name = "prompt-cursor-colour",
.type = OPTIONS_TABLE_COLOUR,
.scope = OPTIONS_TABLE_SESSION,
.default_num = 6,
.text = "Colour of the cursor when in the command prompt."
},
{ .name = "prompt-cursor-style",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SESSION,
.choices = options_table_cursor_style_list,
.default_num = 0,
.text = "Style of the cursor when in the command prompt."
},
{ .name = "session-status-current-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of the current session in the status line."
},
{ .name = "session-status-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of sessions in the status line, except the current "
"session."
},
{ .name = "update-environment", { .name = "update-environment",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION, .scope = OPTIONS_TABLE_SESSION,
.flags = OPTIONS_TABLE_IS_ARRAY, .flags = OPTIONS_TABLE_IS_ARRAY,
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK " .default_str = "DISPLAY KRB5CCNAME MSYSTEM SSH_ASKPASS SSH_AUTH_SOCK "
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY", "SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY",
.text = "List of environment variables to update in the session " .text = "List of environment variables to update in the session "
"environment when a client is attached." "environment when a client is attached."
@@ -970,6 +1125,36 @@ const struct options_table_entry options_table[] = {
.text = "Style of the marked line in copy mode." .text = "Style of the marked line in copy mode."
}, },
{ .name = "copy-mode-position-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "#[align=right]"
"#{t/p:top_line_time}#{?#{e|>:#{top_line_time},0}, ,}"
"[#{scroll_position}/#{history_size}]"
"#{?search_timed_out, (timed out),"
"#{?search_count, (#{search_count}"
"#{?search_count_partial,+,} results),}}",
.text = "Format of the position indicator in copy mode."
},
{ .name = "copy-mode-position-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "#{E:mode-style}",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of position indicator in copy mode."
},
{ .name = "copy-mode-selection-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "#{E:mode-style}",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of selection in copy mode."
},
{ .name = "fill-character", { .name = "fill-character",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
@@ -1005,7 +1190,7 @@ const struct options_table_entry options_table[] = {
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
.flags = OPTIONS_TABLE_IS_STYLE, .flags = OPTIONS_TABLE_IS_STYLE,
.default_str = "bg=yellow,fg=black", .default_str = "noattr,bg=yellow,fg=black",
.separator = ",", .separator = ",",
.text = "Style of indicators and highlighting in modes." .text = "Style of indicators and highlighting in modes."
}, },
@@ -1120,6 +1305,31 @@ const struct options_table_entry options_table[] = {
.text = "The default colour palette for colours zero to 255." .text = "The default colour palette for colours zero to 255."
}, },
{ .name = "pane-scrollbars",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW,
.choices = options_table_pane_scrollbars_list,
.default_num = PANE_SCROLLBARS_OFF,
.text = "Pane scrollbar state."
},
{ .name = "pane-scrollbars-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "bg=black,fg=white,width=1,pad=0",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of the pane scrollbar."
},
{ .name = "pane-scrollbars-position",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW,
.choices = options_table_pane_scrollbars_position_list,
.default_num = PANE_SCROLLBARS_RIGHT,
.text = "Pane scrollbar position."
},
{ .name = "popup-style", { .name = "popup-style",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW, .scope = OPTIONS_TABLE_WINDOW,
@@ -1161,12 +1371,12 @@ const struct options_table_entry options_table[] = {
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "Pane is dead (" .default_str = "Pane is dead ("
"#{?#{!=:#{pane_dead_status},}," "#{?#{!=:#{pane_dead_status},},"
"status #{pane_dead_status},}" "status #{pane_dead_status},}"
"#{?#{!=:#{pane_dead_signal},}," "#{?#{!=:#{pane_dead_signal},},"
"signal #{pane_dead_signal},}, " "signal #{pane_dead_signal},}, "
"#{t:pane_dead_time})", "#{t:pane_dead_time})",
.text = "Message shown after the program in a pane has exited, if " .text = "Message shown after the program in a pane has exited, if "
"remain-on-exit is enabled." "remain-on-exit is enabled."
}, },
{ .name = "scroll-on-clear", { .name = "scroll-on-clear",
@@ -1184,6 +1394,16 @@ const struct options_table_entry options_table[] = {
.text = "Whether typing should be sent to all panes simultaneously." .text = "Whether typing should be sent to all panes simultaneously."
}, },
{ .name = "tiled-layout-max-columns",
.type = OPTIONS_TABLE_NUMBER,
.scope = OPTIONS_TABLE_WINDOW,
.minimum = 0,
.maximum = USHRT_MAX,
.default_num = 0,
.text = "Maximum number of columns in the 'tiled' layout. "
"A value of 0 means no limit."
},
{ .name = "window-active-style", { .name = "window-active-style",
.type = OPTIONS_TABLE_STRING, .type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
@@ -1347,6 +1567,8 @@ const struct options_table_entry options_table[] = {
OPTIONS_TABLE_HOOK("client-focus-out", ""), OPTIONS_TABLE_HOOK("client-focus-out", ""),
OPTIONS_TABLE_HOOK("client-resized", ""), OPTIONS_TABLE_HOOK("client-resized", ""),
OPTIONS_TABLE_HOOK("client-session-changed", ""), OPTIONS_TABLE_HOOK("client-session-changed", ""),
OPTIONS_TABLE_HOOK("client-light-theme", ""),
OPTIONS_TABLE_HOOK("client-dark-theme", ""),
OPTIONS_TABLE_HOOK("command-error", ""), OPTIONS_TABLE_HOOK("command-error", ""),
OPTIONS_TABLE_PANE_HOOK("pane-died", ""), OPTIONS_TABLE_PANE_HOOK("pane-died", ""),
OPTIONS_TABLE_PANE_HOOK("pane-exited", ""), OPTIONS_TABLE_PANE_HOOK("pane-exited", ""),

View File

@@ -260,6 +260,7 @@ options_default(struct options *oo, const struct options_table_entry *oe)
struct options_entry *o; struct options_entry *o;
union options_value *ov; union options_value *ov;
u_int i; u_int i;
struct cmd_parse_result *pr;
o = options_empty(oo, oe); o = options_empty(oo, oe);
ov = &o->value; ov = &o->value;
@@ -278,6 +279,17 @@ options_default(struct options *oo, const struct options_table_entry *oe)
case OPTIONS_TABLE_STRING: case OPTIONS_TABLE_STRING:
ov->string = xstrdup(oe->default_str); ov->string = xstrdup(oe->default_str);
break; break;
case OPTIONS_TABLE_COMMAND:
pr = cmd_parse_from_string(oe->default_str, NULL);
switch (pr->status) {
case CMD_PARSE_ERROR:
free(pr->error);
break;
case CMD_PARSE_SUCCESS:
ov->cmdlist = pr->cmdlist;
break;
}
break;
default: default:
ov->number = oe->default_num; ov->number = oe->default_num;
break; break;
@@ -737,6 +749,19 @@ options_get_number(struct options *oo, const char *name)
return (o->value.number); return (o->value.number);
} }
const struct cmd_list *
options_get_command(struct options *oo, const char *name)
{
struct options_entry *o;
o = options_get(oo, name);
if (o == NULL)
fatalx("missing option %s", name);
if (!OPTIONS_IS_COMMAND(o))
fatalx("option %s is not a command", name);
return (o->value.cmdlist);
}
struct options_entry * struct options_entry *
options_set_string(struct options *oo, const char *name, int append, options_set_string(struct options *oo, const char *name, int append,
const char *fmt, ...) const char *fmt, ...)
@@ -798,6 +823,30 @@ options_set_number(struct options *oo, const char *name, long long value)
return (o); return (o);
} }
struct options_entry *
options_set_command(struct options *oo, const char *name,
struct cmd_list *value)
{
struct options_entry *o;
if (*name == '@')
fatalx("user option %s must be a string", name);
o = options_get_only(oo, name);
if (o == NULL) {
o = options_default(oo, options_parent_table_entry(oo, name));
if (o == NULL)
return (NULL);
}
if (!OPTIONS_IS_COMMAND(o))
fatalx("option %s is not a command", name);
if (o->value.cmdlist != NULL)
cmd_list_free(o->value.cmdlist);
o->value.cmdlist = value;
return (o);
}
int int
options_scope_from_name(struct args *args, int window, options_scope_from_name(struct args *args, int window,
const char *name, struct cmd_find_state *fs, struct options **oo, const char *name, struct cmd_find_state *fs, struct options **oo,
@@ -1054,6 +1103,7 @@ options_from_string(struct options *oo, const struct options_table_entry *oe,
const char *errstr, *new; const char *errstr, *new;
char *old; char *old;
key_code key; key_code key;
struct cmd_parse_result *pr;
if (oe != NULL) { if (oe != NULL) {
if (value == NULL && if (value == NULL &&
@@ -1112,6 +1162,15 @@ options_from_string(struct options *oo, const struct options_table_entry *oe,
case OPTIONS_TABLE_CHOICE: case OPTIONS_TABLE_CHOICE:
return (options_from_string_choice(oe, oo, name, value, cause)); return (options_from_string_choice(oe, oo, name, value, cause));
case OPTIONS_TABLE_COMMAND: case OPTIONS_TABLE_COMMAND:
pr = cmd_parse_from_string(value, NULL);
switch (pr->status) {
case CMD_PARSE_ERROR:
*cause = pr->error;
return (-1);
case CMD_PARSE_SUCCESS:
options_set_command(oo, name, pr->cmdlist);
return (0);
}
break; break;
} }
return (-1); return (-1);
@@ -1165,16 +1224,30 @@ options_push_changes(const char *name)
if (strcmp(name, "window-style") == 0 || if (strcmp(name, "window-style") == 0 ||
strcmp(name, "window-active-style") == 0) { strcmp(name, "window-active-style") == 0) {
RB_FOREACH(wp, window_pane_tree, &all_window_panes) RB_FOREACH(wp, window_pane_tree, &all_window_panes)
wp->flags |= PANE_STYLECHANGED; wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
} }
if (strcmp(name, "pane-colours") == 0) { if (strcmp(name, "pane-colours") == 0) {
RB_FOREACH(wp, window_pane_tree, &all_window_panes) RB_FOREACH(wp, window_pane_tree, &all_window_panes)
colour_palette_from_option(&wp->palette, wp->options); colour_palette_from_option(&wp->palette, wp->options);
} }
if (strcmp(name, "pane-border-status") == 0) { if (strcmp(name, "pane-border-status") == 0 ||
strcmp(name, "pane-scrollbars") == 0 ||
strcmp(name, "pane-scrollbars-position") == 0) {
RB_FOREACH(w, windows, &windows) RB_FOREACH(w, windows, &windows)
layout_fix_panes(w, NULL); layout_fix_panes(w, NULL);
} }
if (strcmp(name, "pane-scrollbars-style") == 0) {
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
style_set_scrollbar_style_from_option(
&wp->scrollbar_style, wp->options);
}
RB_FOREACH(w, windows, &windows)
layout_fix_panes(w, NULL);
}
if (strcmp(name, "codepoint-widths") == 0)
utf8_update_width_cache();
if (strcmp(name, "input-buffer-size") == 0)
input_set_buffer_size(options_get_number(global_options, name));
RB_FOREACH(s, sessions, &sessions) RB_FOREACH(s, sessions, &sessions)
status_update_cache(s); status_update_cache(s);

View File

@@ -16,75 +16,19 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <sys/param.h> #include <sys/types.h>
#include <sys/procfs.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include "tmux.h" #include "tmux.h"
char * char *
osdep_get_name(__unused int fd, char *tty) osdep_get_name(__unused int fd, __unused char *tty)
{ {
struct psinfo p; return (NULL);
char *path;
ssize_t bytes;
int f, ttyfd, retval;
pid_t pgrp;
if ((ttyfd = open(tty, O_RDONLY|O_NOCTTY)) == -1)
return (NULL);
retval = ioctl(ttyfd, TIOCGPGRP, &pgrp);
close(ttyfd);
if (retval == -1)
return (NULL);
xasprintf(&path, "/proc/%u/psinfo", (u_int) pgrp);
f = open(path, O_RDONLY);
free(path);
if (f < 0)
return (NULL);
bytes = read(f, &p, sizeof(p));
close(f);
if (bytes != sizeof(p))
return (NULL);
return (xstrdup(p.pr_fname));
} }
char * char *
osdep_get_cwd(int fd) osdep_get_cwd(__unused int fd)
{ {
static char target[MAXPATHLEN + 1];
char *path;
const char *ttypath;
ssize_t n;
pid_t pgrp;
int len, retval, ttyfd;
if ((ttypath = ptsname(fd)) == NULL)
return (NULL);
if ((ttyfd = open(ttypath, O_RDONLY|O_NOCTTY)) == -1)
return (NULL);
retval = ioctl(ttyfd, TIOCGPGRP, &pgrp);
close(ttyfd);
if (retval == -1)
return (NULL);
xasprintf(&path, "/proc/%u/cwd", (u_int) pgrp);
n = readlink(path, target, MAXPATHLEN);
free(path);
if (n > 0) {
target[n] = '\0';
if ((len = strlen(target)) > 1 && target[len - 1] == '/')
target[len - 1] = '\0';
return (target);
}
return (NULL); return (NULL);
} }

View File

@@ -16,11 +16,14 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/ */
#include <sys/cdefs.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <Availability.h> #include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
#include <libproc.h> #include <libproc.h>
#endif
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@@ -31,14 +34,10 @@ char *osdep_get_name(int, char *);
char *osdep_get_cwd(int); char *osdep_get_cwd(int);
struct event_base *osdep_event_init(void); struct event_base *osdep_event_init(void);
#ifndef __unused
#define __unused __attribute__ ((__unused__))
#endif
char * char *
osdep_get_name(int fd, __unused char *tty) osdep_get_name(int fd, __unused char *tty)
{ {
#ifdef __MAC_10_7 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
struct proc_bsdshortinfo bsdinfo; struct proc_bsdshortinfo bsdinfo;
pid_t pgrp; pid_t pgrp;
int ret; int ret;
@@ -72,6 +71,7 @@ osdep_get_name(int fd, __unused char *tty)
char * char *
osdep_get_cwd(int fd) osdep_get_cwd(int fd)
{ {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
static char wd[PATH_MAX]; static char wd[PATH_MAX];
struct proc_vnodepathinfo pathinfo; struct proc_vnodepathinfo pathinfo;
pid_t pgrp; pid_t pgrp;
@@ -86,6 +86,7 @@ osdep_get_cwd(int fd)
strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd); strlcpy(wd, pathinfo.pvi_cdir.vip_path, sizeof wd);
return (wd); return (wd);
} }
#endif
return (NULL); return (NULL);
} }

View File

@@ -40,7 +40,7 @@ osdep_get_name(int fd, __unused char *tty)
} }
char * char *
osdep_get_cwd(int fd) osdep_get_cwd(__unused int fd)
{ {
return (NULL); return (NULL);
} }

View File

@@ -240,6 +240,8 @@ paste_rename(const char *oldname, const char *newname, char **cause)
} }
pb_new = paste_get_name(newname); pb_new = paste_get_name(newname);
if (pb_new == pb)
return (0);
if (pb_new != NULL) if (pb_new != NULL)
paste_free(pb_new); paste_free(pb_new);

66
popup.c
View File

@@ -348,13 +348,17 @@ popup_make_pane(struct popup_data *pd, enum layout_type type)
window_unzoom(w, 1); window_unzoom(w, 1);
lc = layout_split_pane(wp, type, -1, 0); lc = layout_split_pane(wp, type, -1, 0);
if (lc == NULL)
return;
hlimit = options_get_number(s->options, "history-limit"); hlimit = options_get_number(s->options, "history-limit");
new_wp = window_add_pane(wp->window, NULL, hlimit, 0); new_wp = window_add_pane(wp->window, NULL, hlimit, 0);
layout_assign_pane(lc, new_wp, 0); layout_assign_pane(lc, new_wp, 0);
new_wp->fd = job_transfer(pd->job, &new_wp->pid, new_wp->tty, if (pd->job != NULL) {
sizeof new_wp->tty); new_wp->fd = job_transfer(pd->job, &new_wp->pid, new_wp->tty,
pd->job = NULL; sizeof new_wp->tty);
pd->job = NULL;
}
screen_set_title(&pd->s, new_wp->base.title); screen_set_title(&pd->s, new_wp->base.title);
screen_free(&new_wp->base); screen_free(&new_wp->base);
@@ -528,7 +532,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
(border == LEFT || border == TOP)) (border == LEFT || border == TOP))
goto menu; goto menu;
if (((m->b & MOUSE_MASK_MODIFIERS) == MOUSE_MASK_META) || if (((m->b & MOUSE_MASK_MODIFIERS) == MOUSE_MASK_META) ||
border != NONE) { (border != NONE && !MOUSE_DRAG(m->lb))) {
if (!MOUSE_DRAG(m->b)) if (!MOUSE_DRAG(m->b))
goto out; goto out;
if (MOUSE_BUTTONS(m->lb) == MOUSE_BUTTON_1) if (MOUSE_BUTTONS(m->lb) == MOUSE_BUTTON_1)
@@ -544,6 +548,9 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
pd->job == NULL) && pd->job == NULL) &&
(event->key == '\033' || event->key == ('c'|KEYC_CTRL))) (event->key == '\033' || event->key == ('c'|KEYC_CTRL)))
return (1); return (1);
if (pd->job == NULL && (pd->flags & POPUP_CLOSEANYKEY) &&
!KEYC_IS_MOUSE(event->key) && !KEYC_IS_PASTE(event->key))
return (1);
if (pd->job != NULL) { if (pd->job != NULL) {
if (KEYC_IS_MOUSE(event->key)) { if (KEYC_IS_MOUSE(event->key)) {
/* Must be inside, checked already. */ /* Must be inside, checked already. */
@@ -632,6 +639,56 @@ popup_job_complete_cb(struct job *job)
server_client_clear_overlay(pd->c); server_client_clear_overlay(pd->c);
} }
int
popup_present(struct client *c)
{
return (c->overlay_draw == popup_draw_cb);
}
int
popup_modify(struct client *c, const char *title, const char *style,
const char *border_style, enum box_lines lines, int flags)
{
struct popup_data *pd = c->overlay_data;
struct style sytmp;
if (title != NULL) {
if (pd->title != NULL)
free(pd->title);
pd->title = xstrdup(title);
}
if (border_style != NULL) {
style_set(&sytmp, &pd->border_cell);
if (style_parse(&sytmp, &pd->border_cell, border_style) == 0) {
pd->border_cell.fg = sytmp.gc.fg;
pd->border_cell.bg = sytmp.gc.bg;
}
}
if (style != NULL) {
style_set(&sytmp, &pd->defaults);
if (style_parse(&sytmp, &pd->defaults, style) == 0) {
pd->defaults.fg = sytmp.gc.fg;
pd->defaults.bg = sytmp.gc.bg;
}
}
if (lines != BOX_LINES_DEFAULT) {
if (lines == BOX_LINES_NONE && pd->border_lines != lines) {
screen_resize(&pd->s, pd->sx, pd->sy, 1);
job_resize(pd->job, pd->sx, pd->sy);
} else if (pd->border_lines == BOX_LINES_NONE && pd->border_lines != lines) {
screen_resize(&pd->s, pd->sx - 2, pd->sy - 2, 1);
job_resize(pd->job, pd->sx - 2, pd->sy - 2);
}
pd->border_lines = lines;
tty_resize(&c->tty);
}
if (flags != -1)
pd->flags = flags;
server_redraw_client(c);
return (0);
}
int int
popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px, popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd, u_int py, u_int sx, u_int sy, struct environ *env, const char *shellcmd,
@@ -691,6 +748,7 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
pd->border_cell.attr = 0; pd->border_cell.attr = 0;
screen_init(&pd->s, jx, jy, 0); screen_init(&pd->s, jx, jy, 0);
screen_set_default_cursor(&pd->s, global_w_options);
colour_palette_init(&pd->palette); colour_palette_init(&pd->palette);
colour_palette_from_option(&pd->palette, global_w_options); colour_palette_from_option(&pd->palette, global_w_options);

22
proc.c
View File

@@ -78,8 +78,7 @@ proc_event_cb(__unused int fd, short events, void *arg)
struct imsg imsg; struct imsg imsg;
if (!(peer->flags & PEER_BAD) && (events & EV_READ)) { if (!(peer->flags & PEER_BAD) && (events & EV_READ)) {
if (((n = imsg_read(&peer->ibuf)) == -1 && errno != EAGAIN) || if (imsgbuf_read(&peer->ibuf) != 1) {
n == 0) {
peer->dispatchcb(NULL, peer->arg); peer->dispatchcb(NULL, peer->arg);
return; return;
} }
@@ -93,9 +92,6 @@ proc_event_cb(__unused int fd, short events, void *arg)
log_debug("peer %p message %d", peer, imsg.hdr.type); log_debug("peer %p message %d", peer, imsg.hdr.type);
if (peer_check_version(peer, &imsg) != 0) { if (peer_check_version(peer, &imsg) != 0) {
fd = imsg_get_fd(&imsg);
if (fd != -1)
close(fd);
imsg_free(&imsg); imsg_free(&imsg);
break; break;
} }
@@ -106,13 +102,13 @@ proc_event_cb(__unused int fd, short events, void *arg)
} }
if (events & EV_WRITE) { if (events & EV_WRITE) {
if (msgbuf_write(&peer->ibuf.w) <= 0 && errno != EAGAIN) { if (imsgbuf_write(&peer->ibuf) == -1) {
peer->dispatchcb(NULL, peer->arg); peer->dispatchcb(NULL, peer->arg);
return; return;
} }
} }
if ((peer->flags & PEER_BAD) && peer->ibuf.w.queued == 0) { if ((peer->flags & PEER_BAD) && imsgbuf_queuelen(&peer->ibuf) == 0) {
peer->dispatchcb(NULL, peer->arg); peer->dispatchcb(NULL, peer->arg);
return; return;
} }
@@ -153,7 +149,7 @@ proc_update_event(struct tmuxpeer *peer)
event_del(&peer->event); event_del(&peer->event);
events = EV_READ; events = EV_READ;
if (peer->ibuf.w.queued > 0) if (imsgbuf_queuelen(&peer->ibuf) > 0)
events |= EV_WRITE; events |= EV_WRITE;
event_set(&peer->event, peer->ibuf.fd, events, proc_event_cb, peer); event_set(&peer->event, peer->ibuf.fd, events, proc_event_cb, peer);
@@ -225,7 +221,7 @@ proc_exit(struct tmuxproc *tp)
struct tmuxpeer *peer; struct tmuxpeer *peer;
TAILQ_FOREACH(peer, &tp->peers, entry) TAILQ_FOREACH(peer, &tp->peers, entry)
imsg_flush(&peer->ibuf); imsgbuf_flush(&peer->ibuf);
tp->exit = 1; tp->exit = 1;
} }
@@ -313,7 +309,9 @@ proc_add_peer(struct tmuxproc *tp, int fd,
peer->dispatchcb = dispatchcb; peer->dispatchcb = dispatchcb;
peer->arg = arg; peer->arg = arg;
imsg_init(&peer->ibuf, fd); if (imsgbuf_init(&peer->ibuf, fd) == -1)
fatal("imsgbuf_init");
imsgbuf_allow_fdpass(&peer->ibuf);
event_set(&peer->event, fd, EV_READ, proc_event_cb, peer); event_set(&peer->event, fd, EV_READ, proc_event_cb, peer);
if (getpeereid(fd, &peer->uid, &gid) != 0) if (getpeereid(fd, &peer->uid, &gid) != 0)
@@ -333,7 +331,7 @@ proc_remove_peer(struct tmuxpeer *peer)
log_debug("remove peer %p", peer); log_debug("remove peer %p", peer);
event_del(&peer->event); event_del(&peer->event);
imsg_clear(&peer->ibuf); imsgbuf_clear(&peer->ibuf);
close(peer->ibuf.fd); close(peer->ibuf.fd);
free(peer); free(peer);
@@ -348,7 +346,7 @@ proc_kill_peer(struct tmuxpeer *peer)
void void
proc_flush_peer(struct tmuxpeer *peer) proc_flush_peer(struct tmuxpeer *peer)
{ {
imsg_flush(&peer->ibuf); imsgbuf_flush(&peer->ibuf);
} }
void void

BIN
regress/UTF-8-test.txt Normal file

Binary file not shown.

View File

@@ -16,7 +16,7 @@ do_test() {
$TMUX -f/dev/null new -d " $TMUX -f/dev/null new -d "
printf '$1' printf '$1'
$TMUX capturep -peS0 -E1 >$TMP" $TMUX capturep -peS0 -E1 >$TMP"
echo $2 > $TMP2 printf "$2\n" > $TMP2
sleep 1 sleep 1
cmp $TMP $TMP2 || exit 1 cmp $TMP $TMP2 || exit 1
return 0 return 0

View File

@@ -4,7 +4,7 @@
Λ̊1 Λ̊1
🏻2 🏻2
👍🏻3 👍🏻3
👍🏻 👍🏻4 👍🏻 👍🏻4
🤷5 🤷5
7 7
🤷8 🤷8

View File

@@ -35,7 +35,7 @@ set-option -g default-command 'tmux pipe-pane -o "cat >>~/tmux_logs/output-`date
# from http://stackoverflow.com/questions/17255031/how-to-copy-from-tmux-running-in-putty-to-windows-clipbard # from http://stackoverflow.com/questions/17255031/how-to-copy-from-tmux-running-in-putty-to-windows-clipbard
# #
# for some reason this is wrapping at 80 cols, using save- instead of show- helps # for some reason this is wrapping at 80 cols, using save- instead of show- helps
# -b for background is needed because xclip continues to run to service the clipboard paste reqeusts until the # -b for background is needed because xclip continues to run to service the clipboard paste requests until the
# clipboard buffer is replaced with some new contents # clipboard buffer is replaced with some new contents
#bind C-y run-shell -b "tmux save-buffer - | DISPLAY=$(<~/.xdisplay) xclip -selection clipboard -in && tmux display-message 'xclipped successfully'" #bind C-y run-shell -b "tmux save-buffer - | DISPLAY=$(<~/.xdisplay) xclip -selection clipboard -in && tmux display-message 'xclipped successfully'"
bind C-y save-buffer ~/etc/clipboard.pipe bind C-y save-buffer ~/etc/clipboard.pipe

View File

@@ -42,7 +42,7 @@ $TMUX send-keys -X begin-selection
$TMUX send-keys -X next-word-end $TMUX send-keys -X next-word-end
$TMUX send-keys -X next-word-end $TMUX send-keys -X next-word-end
$TMUX send-keys -X copy-selection $TMUX send-keys -X copy-selection
[ "$($TMUX show-buffer)" = "$(printf "words\n Indented")" ] || exit 1 [ "$($TMUX show-buffer)" = "$(printf "words\n\tIndented")" ] || exit 1
# Test that `next-word` wraps around un-indented line breaks. # Test that `next-word` wraps around un-indented line breaks.
$TMUX send-keys -X next-word $TMUX send-keys -X next-word

View File

@@ -41,7 +41,7 @@ $TMUX send-keys -X begin-selection
$TMUX send-keys -X next-word-end $TMUX send-keys -X next-word-end
$TMUX send-keys -X next-word-end $TMUX send-keys -X next-word-end
$TMUX send-keys -X copy-selection $TMUX send-keys -X copy-selection
[ "$($TMUX show-buffer)" = "$(printf "words\n Indented")" ] || exit 1 [ "$($TMUX show-buffer)" = "$(printf "words\n\tIndented")" ] || exit 1
# Test that `next-word` wraps around un-indented line breaks. # Test that `next-word` wraps around un-indented line breaks.
$TMUX send-keys -X next-word $TMUX send-keys -X next-word

View File

@@ -60,7 +60,13 @@ test_conditional_with_session_name()
$TMUX kill-server 2>/dev/null $TMUX kill-server 2>/dev/null
$TMUX -f/dev/null new-session -d || exit 1 $TMUX -f/dev/null new-session -d || exit 1
$TMUX rename-session "Summer" || exit 1 # used later in conditionals
# used later in conditionals
$TMUX rename-session "Summer" || exit 1
$TMUX set @true 1 || exit 1
$TMUX set @false 0 || exit 1
$TMUX set @warm Summer || exit 1
$TMUX set @cold Winter || exit 1
# Plain string without substitutions et al # Plain string without substitutions et al
test_format "abc xyz" "abc xyz" test_format "abc xyz" "abc xyz"
@@ -77,13 +83,21 @@ test_format "###}" "#}" # not a "basic" one but interesting nevertheless
test_format "#{pane_in_mode}" "0" test_format "#{pane_in_mode}" "0"
# Simple conditionals # Simple conditionals
test_format "#{?}" ""
test_format "#{?abc}" "abc"
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc}" "abc" ""
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,xyz}" "abc" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,xyz}" "abc" "xyz"
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,@true,xyz}" "abc" "xyz"
test_format "#{?@false,abc,@false,xyz}" ""
test_format "#{?@false,abc,@false,xyz,default}" "default"
# Expansion in conditionals # Expansion in conditionals
test_conditional_with_pane_in_mode "#{?pane_in_mode,#{session_name},xyz}" "Summer" "xyz" test_format "#{?#{@warm}}" "Summer"
test_conditional_with_pane_in_mode "#{?#{pane_in_mode},#{@warm}}" "Summer" ""
test_conditional_with_pane_in_mode "#{?#{pane_in_mode},#{@warm},#{@cold}}" "Summer" "Winter"
# Basic escapes in conditionals # Basic escapes in conditionals
# First argument # Value of an (else-)if-condition
test_conditional_with_pane_in_mode "#{?pane_in_mode,##,xyz}" "#" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,##,xyz}" "#" "xyz"
test_conditional_with_pane_in_mode "#{?pane_in_mode,#,,xyz}" "," "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,#,,xyz}" "," "xyz"
test_conditional_with_pane_in_mode "#{?pane_in_mode,{,xyz}" "{" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,{,xyz}" "{" "xyz"
@@ -91,7 +105,7 @@ test_conditional_with_pane_in_mode "#{?pane_in_mode,##{,xyz}" "#{" "xyz"
test_conditional_with_pane_in_mode "#{?pane_in_mode,#},xyz}" "}" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,#},xyz}" "}" "xyz"
# not a "basic" one but interesting nevertheless # not a "basic" one but interesting nevertheless
test_conditional_with_pane_in_mode "#{?pane_in_mode,###},xyz}" "#}" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,###},xyz}" "#}" "xyz"
# Second argument # Default value if no condition matches
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,##}" "abc" "#" test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,##}" "abc" "#"
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,#,}" "abc" "," test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,#,}" "abc" ","
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,{}" "abc" "{" test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,{}" "abc" "{"
@@ -105,9 +119,6 @@ test_conditional_with_pane_in_mode "#{?pane_in_mode,#},{}" "}" "{"
test_conditional_with_pane_in_mode "#{?pane_in_mode,##{,###}}" "#{" "#}" test_conditional_with_pane_in_mode "#{?pane_in_mode,##{,###}}" "#{" "#}"
test_conditional_with_pane_in_mode "#{?pane_in_mode,###},##{}" "#}" "#{" test_conditional_with_pane_in_mode "#{?pane_in_mode,###},##{}" "#}" "#{"
# Conditionals split on the second comma (this is not documented)
test_conditional_with_pane_in_mode "#{?pane_in_mode,abc,xyz,bonus}" "abc" "xyz,bonus"
# Curly brackets {...} do not capture a comma inside of conditionals as the # Curly brackets {...} do not capture a comma inside of conditionals as the
# conditional ends on the first '}' # conditional ends on the first '}'
test_conditional_with_pane_in_mode "#{?pane_in_mode,{abc,xyz},bonus}" "{abc,bonus}" "xyz,bonus}" test_conditional_with_pane_in_mode "#{?pane_in_mode,{abc,xyz},bonus}" "{abc,bonus}" "xyz,bonus}"
@@ -116,12 +127,12 @@ test_conditional_with_pane_in_mode "#{?pane_in_mode,{abc,xyz},bonus}" "{abc,bonu
# invalid format: #{abc,xyz} is not a known variable name. # invalid format: #{abc,xyz} is not a known variable name.
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#{abc,xyz},bonus}" "" "bonus" #test_conditional_with_pane_in_mode "#{?pane_in_mode,#{abc,xyz},bonus}" "" "bonus"
# Parenthesis (...) do not captura a comma # Parenthesis (...) do not capture a comma, and "xyz)" is a false condition
test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc,xyz),bonus}" "(abc" "xyz),bonus" test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc,xyz),bonus}" "(abc" ""
test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc#,xyz),bonus}" "(abc,xyz)" "bonus" test_conditional_with_pane_in_mode "#{?pane_in_mode,(abc#,xyz),bonus}" "(abc,xyz)" "bonus"
# Brackets [...] do not captura a comma # Brackets [...] do not capture a comma, and "xyz]" is a false condition
test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc,xyz],bonus}" "[abc" "xyz],bonus" test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc,xyz],bonus}" "[abc" ""
test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc#,xyz],bonus}" "[abc,xyz]" "bonus" test_conditional_with_pane_in_mode "#{?pane_in_mode,[abc#,xyz],bonus}" "[abc,xyz]" "bonus"
@@ -138,12 +149,12 @@ test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "" "xyz"
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "," "xyz" #test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo #,),xyz}" "," "xyz"
# invalid format: '#(' is not closed in the first argument of #{?,,}. # invalid format: '#(' is not closed in the first argument of #{?,,}.
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo ,),xyz}" "" "),xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,#(echo ,)xyz}" "" ")xyz"
# Escape comma inside of #[...] # Escape comma inside of #[...]
test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default#,bg=default]abc,xyz}" "#[fg=default,bg=default]abc" "xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default#,bg=default]abc,xyz}" "#[fg=default,bg=default]abc" "xyz"
# invalid format: '#[' is not closed in the first argument of #{?,,} # invalid style: '#[' is not closed in the first argument of #{?,,}
#test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default,bg=default]abc,xyz}" "" "bg=default]abc,xyz" test_conditional_with_pane_in_mode "#{?pane_in_mode,#[fg=default,bg=default]abc}" "#[fg=default" "bg=default]abc"
# Conditionals with comparison # Conditionals with comparison
test_conditional_with_session_name "#{?#{==:#{session_name},Summer},abc,xyz}" "abc" "xyz" test_conditional_with_session_name "#{?#{==:#{session_name},Summer},abc,xyz}" "abc" "xyz"
@@ -164,6 +175,47 @@ test_conditional_with_pane_in_mode "#{?#{==:#{?pane_in_mode,#{session_name},#(ec
# Tests for boolean expressions
# "0" and the empty string are false, everything else is true.
test_format "#{!!:0}" "0"
test_format "#{!!:}" "0"
test_format "#{!!:1}" "1"
test_format "#{!!:2}" "1"
test_format "#{!!:non-empty string}" "1"
test_format "#{!!:-0}" "1"
test_format "#{!!:0.0}" "1"
# Logical operators
test_format "#{!:0}" "1"
test_format "#{!:1}" "0"
test_format "#{&&:0}" "0"
test_format "#{&&:1}" "1"
test_format "#{&&:0,0}" "0"
test_format "#{&&:0,1}" "0"
test_format "#{&&:1,0}" "0"
test_format "#{&&:1,1}" "1"
test_format "#{&&:0,0,0}" "0"
test_format "#{&&:0,1,1}" "0"
test_format "#{&&:1,0,1}" "0"
test_format "#{&&:1,1,0}" "0"
test_format "#{&&:1,1,1}" "1"
test_format "#{||:0}" "0"
test_format "#{||:1}" "1"
test_format "#{||:0,0}" "0"
test_format "#{||:0,1}" "1"
test_format "#{||:1,0}" "1"
test_format "#{||:1,1}" "1"
test_format "#{||:0,0,0}" "0"
test_format "#{||:1,0,0}" "1"
test_format "#{||:0,1,0}" "1"
test_format "#{||:0,0,1}" "1"
test_format "#{||:1,1,1}" "1"
# Format test for the literal option # Format test for the literal option
# Note: The behavior for #{l:...} with escapes is sometimes weird as #{l:...} # Note: The behavior for #{l:...} with escapes is sometimes weird as #{l:...}
# respects the escapes. # respects the escapes.

View File

@@ -21,3 +21,10 @@ EOF
$TMUX -f$TMP -C new <<EOF >$OUT $TMUX -f$TMP -C new <<EOF >$OUT
EOF EOF
grep -q "^%config-error $TMP:1: $TMP:1: unknown command: wibble$" $OUT grep -q "^%config-error $TMP:1: $TMP:1: unknown command: wibble$" $OUT
cat <<EOF >$TMP
wibble wobble
EOF
echo "source $TMP" | $TMUX -C new >$OUT
grep -q "^%config-error $TMP:1: unknown command: wibble$" $OUT

View File

@@ -3,16 +3,16 @@
# new session environment # new session environment
PATH=/bin:/usr/bin PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux) [ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest" TMUX="$TEST_TMUX -Ltest"
$TMUX kill-server 2>/dev/null $TMUX kill-server 2>/dev/null
TERM=$($TMUX start \; show -gv default-terminal)
TMP=$(mktemp) TMP=$(mktemp)
OUT=$(mktemp) OUT=$(mktemp)
SCRIPT=$(mktemp) SCRIPT=$(mktemp)
trap "rm -f $TMP $OUT $SCRIPT" 0 1 15 #trap "rm -f $TMP $OUT $SCRIPT" 0 1 15
cat <<EOF >$SCRIPT cat <<EOF >$SCRIPT
( (
@@ -32,7 +32,7 @@ EOF
$TMUX -f$TMP start) || exit 1 $TMUX -f$TMP start) || exit 1
sleep 1 sleep 1
(cat <<EOF|cmp -s - $OUT) || exit 1 (cat <<EOF|cmp -s - $OUT) || exit 1
TERM=screen TERM=$TERM
PWD=/ PWD=/
PATH=1 PATH=1
SHELL=/bin/sh SHELL=/bin/sh
@@ -43,7 +43,7 @@ EOF
$TMUX -f$TMP new -d -- /bin/sh $SCRIPT) || exit 1 $TMUX -f$TMP new -d -- /bin/sh $SCRIPT) || exit 1
sleep 1 sleep 1
(cat <<EOF|cmp -s - $OUT) || exit 1 (cat <<EOF|cmp -s - $OUT) || exit 1
TERM=screen TERM=$TERM
PWD=/ PWD=/
PATH=2 PATH=2
SHELL=/bin/sh SHELL=/bin/sh
@@ -54,7 +54,7 @@ EOF
$TMUX -f/dev/null new -d source $TMP) || exit 1 $TMUX -f/dev/null new -d source $TMP) || exit 1
sleep 1 sleep 1
(cat <<EOF|cmp -s - $OUT) || exit 1 (cat <<EOF|cmp -s - $OUT) || exit 1
TERM=screen TERM=$TERM
PWD=/ PWD=/
PATH=2 PATH=2
SHELL=/bin/sh SHELL=/bin/sh

View File

@@ -0,0 +1,25 @@
#!/bin/sh
# 4476
# run-shell should go to stdout if present without -t
PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)
trap "rm -f $TMP" 0 1 15
$TMUX -f/dev/null new -d "$TMUX run 'echo foo' >$TMP; sleep 10" || exit 1
sleep 1 && [ "$(cat $TMP)" = "foo" ] || exit 1
$TMUX -f/dev/null new -d "$TMUX run -t: 'echo foo' >$TMP; sleep 10" || exit 1
sleep 1 && [ "$(cat $TMP)" = "" ] || exit 1
[ "$($TMUX display -p '#{pane_mode}')" = "view-mode" ] || exit 1
$TMUX kill-server 2>/dev/null
exit 0

View File

@@ -3,13 +3,26 @@
PATH=/bin:/usr/bin PATH=/bin:/usr/bin
TERM=screen TERM=screen
shell=
if command -v bash >/dev/null 2>&1; then
# If Bash is available, we start a plain Bash session (without any user
# configuration files) for testing.
#
# Note: We disable the command history by passing "+o history". If an
# interactive Bash session is started without any configuration files,
# the user's command history may be truncated to the default maximum
# size of 500. To avoid breaking the user's command history, we disable
# the command history.
shell='bash --noprofile --norc +o history'
fi
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux) [ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest" TMUX="$TEST_TMUX -Ltest"
$TMUX kill-server 2>/dev/null $TMUX kill-server 2>/dev/null
TMUX2="$TEST_TMUX -Ltest2" TMUX2="$TEST_TMUX -Ltest2"
$TMUX2 kill-server 2>/dev/null $TMUX2 kill-server 2>/dev/null
$TMUX2 -f/dev/null new -d "$TMUX -f/dev/null new" $TMUX2 -f/dev/null new -d "$TMUX -f/dev/null new -- $shell"
sleep 2 sleep 2
$TMUX set -g status-style fg=default,bg=default $TMUX set -g status-style fg=default,bg=default

301
regress/utf8-test.result Normal file
View File

@@ -0,0 +1,301 @@
UTF-8 decoder capability and stress test
----------------------------------------
Markus Kuhn <http://www.cl.cam.ac.uk/~mgk25/> - 2015-08-28 - CC BY 4.0
This test file can help you examine, how your UTF-8 decoder handles
various types of correct, malformed, or otherwise interesting UTF-8
sequences. This file is not meant to be a conformance test. It does
not prescribe any particular outcome. Therefore, there is no way to
"pass" or "fail" this test file, even though the text does suggest a
preferable decoder behaviour at some places. Its aim is, instead, to
help you think about, and test, the behaviour of your UTF-8 decoder on a
systematic collection of unusual inputs. Experience so far suggests
that most first-time authors of UTF-8 decoders find at least one
serious problem in their decoder using this file.
The test lines below cover boundary conditions, malformed UTF-8
sequences, as well as correctly encoded UTF-8 sequences of Unicode code
points that should never occur in a correct UTF-8 file.
According to ISO 10646-1:2000, sections D.7 and 2.3c, a device
receiving UTF-8 shall interpret a "malformed sequence in the same way
that it interprets a character that is outside the adopted subset" and
"characters that are not within the adopted subset shall be indicated
to the user" by a receiving device. One commonly used approach in
UTF-8 decoders is to replace any malformed UTF-8 sequence by a
replacement character (U+FFFD), which looks a bit like an inverted
question mark, or a similar symbol. It might be a good idea to
visually distinguish a malformed UTF-8 sequence from a correctly
encoded Unicode character that is just not available in the current
font but otherwise fully legal, even though ISO 10646-1 doesn't
mandate this. In any case, just ignoring malformed sequences or
unavailable characters does not conform to ISO 10646, will make
debugging more difficult, and can lead to user confusion.
Please check, whether a malformed UTF-8 sequence is (1) represented at
all, (2) represented by exactly one single replacement character (or
equivalent signal), and (3) the following quotation mark after an
illegal UTF-8 sequence is correctly displayed, i.e. proper
resynchronization takes place immediately after any malformed
sequence. This file says "THE END" in the last line, so if you don't
see that, your decoder crashed somehow before, which should always be
cause for concern.
All lines in this file are exactly 79 characters long (plus the line
feed). In addition, all lines end with "|", except for the two test
lines 2.1.1 and 2.2.1, which contain non-printable ASCII controls
U+0000 and U+007F. If you display this file with a fixed-width font,
these "|" characters should all line up in column 79 (right margin).
This allows you to test quickly, whether your UTF-8 decoder finds the
correct number of characters in every line, that is whether each
malformed sequences is replaced by a single replacement character.
Note that, as an alternative to the notion of malformed sequence used
here, it is also a perfectly acceptable (and in some situations even
preferable) solution to represent each individual byte of a malformed
sequence with a replacement character. If you follow this strategy in
your decoder, then please ignore the "|" column.
Here come the tests: |
|
1 Some correct UTF-8 text |
|
You should see the Greek word 'kosme': "κόσμε" |
|
2 Boundary condition test cases |
|
2.1 First possible sequence of a certain length |
|
2.1.1 1 byte (U-00000000): ""
2.1.2 2 bytes (U-00000080): "€" |
2.1.3 3 bytes (U-00000800): "ࠀ" |
2.1.4 4 bytes (U-00010000): "𐀀" |
2.1.5 5 bytes (U-00200000): "<22><><EFBFBD><EFBFBD><EFBFBD>" |
2.1.6 6 bytes (U-04000000): "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
2.2 Last possible sequence of a certain length |
|
2.2.1 1 byte (U-0000007F): ""
2.2.2 2 bytes (U-000007FF): "߿" |
2.2.3 3 bytes (U-0000FFFF): "￿" |
2.2.4 4 bytes (U-001FFFFF): "<22><><EFBFBD><EFBFBD>" |
2.2.5 5 bytes (U-03FFFFFF): "<22><><EFBFBD><EFBFBD><EFBFBD>" |
2.2.6 6 bytes (U-7FFFFFFF): "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
2.3 Other boundary conditions |
|
2.3.1 U-0000D7FF = ed 9f bf = "퟿" |
2.3.2 U-0000E000 = ee 80 80 = "" |
2.3.3 U-0000FFFD = ef bf bd = "<22>" |
2.3.4 U-0010FFFF = f4 8f bf bf = "􏿿" |
2.3.5 U-00110000 = f4 90 80 80 = "<22>" |
|
3 Malformed sequences |
|
3.1 Unexpected continuation bytes |
|
Each unexpected continuation byte should be separately signalled as a |
malformed sequence of its own. |
|
3.1.1 First continuation byte 0x80: "<22>" |
3.1.2 Last continuation byte 0xbf: "<22>" |
|
3.1.3 2 continuation bytes: "<22><>" |
3.1.4 3 continuation bytes: "<22><><EFBFBD>" |
3.1.5 4 continuation bytes: "<22><><EFBFBD><EFBFBD>" |
3.1.6 5 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD>" |
3.1.7 6 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
3.1.8 7 continuation bytes: "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
3.1.9 Sequence of all 64 possible continuation bytes (0x80-0xbf): |
|
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
3.2 Lonely start characters |
|
3.2.1 All 32 first bytes of 2-byte sequences (0xc0-0xdf), |
each followed by a space character: |
|
"<22> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> |
<20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> " |
|
3.2.2 All 16 first bytes of 3-byte sequences (0xe0-0xef), |
each followed by a space character: |
|
"<22> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> <20> " |
|
3.2.3 All 8 first bytes of 4-byte sequences (0xf0-0xf7), |
each followed by a space character: |
|
"<22> <20> <20> <20> <20> <20> <20> <20> " |
|
3.2.4 All 4 first bytes of 5-byte sequences (0xf8-0xfb), |
each followed by a space character: |
|
"<22> <20> <20> <20> " |
|
3.2.5 All 2 first bytes of 6-byte sequences (0xfc-0xfd), |
each followed by a space character: |
|
"<22> <20> " |
|
3.3 Sequences with last continuation byte missing |
|
All bytes of an incomplete sequence should be signalled as a single |
malformed sequence, i.e., you should see only a single replacement |
character in each of the next 10 tests. (Characters as in section 2) |
|
3.3.1 2-byte sequence with last byte missing (U+0000): "<22>" |
3.3.2 3-byte sequence with last byte missing (U+0000): "<22>" |
3.3.3 4-byte sequence with last byte missing (U+0000): "<22>" |
3.3.4 5-byte sequence with last byte missing (U+0000): "<22><><EFBFBD><EFBFBD>" |
3.3.5 6-byte sequence with last byte missing (U+0000): "<22><><EFBFBD><EFBFBD><EFBFBD>" |
3.3.6 2-byte sequence with last byte missing (U-000007FF): "<22>" |
3.3.7 3-byte sequence with last byte missing (U-0000FFFF): "<22>" |
3.3.8 4-byte sequence with last byte missing (U-001FFFFF): "<22><><EFBFBD>" |
3.3.9 5-byte sequence with last byte missing (U-03FFFFFF): "<22><><EFBFBD><EFBFBD>" |
3.3.10 6-byte sequence with last byte missing (U-7FFFFFFF): "<22><><EFBFBD><EFBFBD><EFBFBD>" |
|
3.4 Concatenation of incomplete sequences |
|
All the 10 sequences of 3.3 concatenated, you should see 10 malformed |
sequences being signalled: |
|
"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
3.5 Impossible bytes |
|
The following two bytes cannot appear in a correct UTF-8 string |
|
3.5.1 fe = "<22>" |
3.5.2 ff = "<22>" |
3.5.3 fe fe ff ff = "<22><><EFBFBD><EFBFBD>" |
|
4 Overlong sequences |
|
The following sequences are not malformed according to the letter of |
the Unicode 2.0 standard. However, they are longer then necessary and |
a correct UTF-8 encoder is not allowed to produce them. A "safe UTF-8 |
decoder" should reject them just like malformed sequences for two |
reasons: (1) It helps to debug applications if overlong sequences are |
not treated as valid representations of characters, because this helps |
to spot problems more quickly. (2) Overlong sequences provide |
alternative representations of characters, that could maliciously be |
used to bypass filters that check only for ASCII characters. For |
instance, a 2-byte encoded line feed (LF) would not be caught by a |
line counter that counts only 0x0a bytes, but it would still be |
processed as a line feed by an unsafe UTF-8 decoder later in the |
pipeline. From a security point of view, ASCII compatibility of UTF-8 |
sequences means also, that ASCII characters are *only* allowed to be |
represented by ASCII bytes in the range 0x00-0x7f. To ensure this |
aspect of ASCII compatibility, use only "safe UTF-8 decoders" that |
reject overlong UTF-8 sequences for which a shorter encoding exists. |
|
4.1 Examples of an overlong ASCII character |
|
With a safe UTF-8 decoder, all of the following five overlong |
representations of the ASCII character slash ("/") should be rejected |
like a malformed UTF-8 sequence, for instance by substituting it with |
a replacement character. If you see a slash below, you do not have a |
safe UTF-8 decoder! |
|
4.1.1 U+002F = c0 af = "<22><>" |
4.1.2 U+002F = e0 80 af = "<22>" |
4.1.3 U+002F = f0 80 80 af = "<22>" |
4.1.4 U+002F = f8 80 80 80 af = "<22><><EFBFBD><EFBFBD><EFBFBD>" |
4.1.5 U+002F = fc 80 80 80 80 af = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
4.2 Maximum overlong sequences |
|
Below you see the highest Unicode value that is still resulting in an |
overlong sequence if represented with the given number of bytes. This |
is a boundary test for safe UTF-8 decoders. All five characters should |
be rejected like malformed UTF-8 sequences. |
|
4.2.1 U-0000007F = c1 bf = "<22><>" |
4.2.2 U-000007FF = e0 9f bf = "<22>" |
4.2.3 U-0000FFFF = f0 8f bf bf = "<22>" |
4.2.4 U-001FFFFF = f8 87 bf bf bf = "<22><><EFBFBD><EFBFBD><EFBFBD>" |
4.2.5 U-03FFFFFF = fc 83 bf bf bf bf = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
4.3 Overlong representation of the NUL character |
|
The following five sequences should also be rejected like malformed |
UTF-8 sequences and should not be treated like the ASCII NUL |
character. |
|
4.3.1 U+0000 = c0 80 = "<22><>" |
4.3.2 U+0000 = e0 80 80 = "<22>" |
4.3.3 U+0000 = f0 80 80 80 = "<22>" |
4.3.4 U+0000 = f8 80 80 80 80 = "<22><><EFBFBD><EFBFBD><EFBFBD>" |
4.3.5 U+0000 = fc 80 80 80 80 80 = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" |
|
5 Illegal code positions |
|
The following UTF-8 sequences should be rejected like malformed |
sequences, because they never represent valid ISO 10646 characters and |
a UTF-8 decoder that accepts them might introduce security problems |
comparable to overlong UTF-8 sequences. |
|
5.1 Single UTF-16 surrogates |
|
5.1.1 U+D800 = ed a0 80 = "<22>" |
5.1.2 U+DB7F = ed ad bf = "<22>" |
5.1.3 U+DB80 = ed ae 80 = "<22>" |
5.1.4 U+DBFF = ed af bf = "<22>" |
5.1.5 U+DC00 = ed b0 80 = "<22>" |
5.1.6 U+DF80 = ed be 80 = "<22>" |
5.1.7 U+DFFF = ed bf bf = "<22>" |
|
5.2 Paired UTF-16 surrogates |
|
5.2.1 U+D800 U+DC00 = ed a0 80 ed b0 80 = "<22><>" |
5.2.2 U+D800 U+DFFF = ed a0 80 ed bf bf = "<22><>" |
5.2.3 U+DB7F U+DC00 = ed ad bf ed b0 80 = "<22><>" |
5.2.4 U+DB7F U+DFFF = ed ad bf ed bf bf = "<22><>" |
5.2.5 U+DB80 U+DC00 = ed ae 80 ed b0 80 = "<22><>" |
5.2.6 U+DB80 U+DFFF = ed ae 80 ed bf bf = "<22><>" |
5.2.7 U+DBFF U+DC00 = ed af bf ed b0 80 = "<22><>" |
5.2.8 U+DBFF U+DFFF = ed af bf ed bf bf = "<22><>" |
|
5.3 Noncharacter code positions |
|
The following "noncharacters" are "reserved for internal use" by |
applications, and according to older versions of the Unicode Standard |
"should never be interchanged". Unicode Corrigendum #9 dropped the |
latter restriction. Nevertheless, their presence in incoming UTF-8 data |
can remain a potential security risk, depending on what use is made of |
these codes subsequently. Examples of such internal use: |
|
- Some file APIs with 16-bit characters may use the integer value -1 |
= U+FFFF to signal an end-of-file (EOF) or error condition. |
|
- In some UTF-16 receivers, code point U+FFFE might trigger a |
byte-swap operation (to convert between UTF-16LE and UTF-16BE). |
|
With such internal use of noncharacters, it may be desirable and safer |
to block those code points in UTF-8 decoders, as they should never |
occur legitimately in incoming UTF-8 data, and could trigger unsafe |
behaviour in subsequent processing. |
|
Particularly problematic noncharacters in 16-bit applications: |
|
5.3.1 U+FFFE = ef bf be = "￾" |
5.3.2 U+FFFF = ef bf bf = "￿" |
|
Other noncharacters: |
|
5.3.3 U+FDD0 .. U+FDEF = "﷐﷑﷒﷓﷔﷕﷖﷗﷘﷙﷚﷛﷜﷝﷞﷟﷠﷡﷢﷣﷤﷥﷦﷧﷨﷩﷪﷫﷬﷭﷮﷯"|
|
5.3.4 U+nFFFE U+nFFFF (for n = 1..10) |
|
"🿾🿿𯿾𯿿𿿾𿿿񏿾񏿿񟿾񟿿񯿾񯿿񿿾񿿿򏿾򏿿 |
򟿾򟿿򯿾򯿿򿿾򿿿󏿾󏿿󟿾󟿿󯿾󯿿󿿾󿿿􏿾􏿿" |
|
THE END |

21
regress/utf8-test.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMP=$(mktemp)
trap "rm -f $TMP" 0 1 15
$TMUX kill-server 2>/dev/null
$TMUX -f/dev/null \
set -g remain-on-exit on \; \
set -g remain-on-exit-format '' \; \
new -d -- cat UTF-8-test.txt
sleep 1
$TMUX capturep -pCeJS- >$TMP
$TMUX kill-server
cmp -s $TMP utf8-test.result || exit 1
exit 0

View File

@@ -264,16 +264,9 @@ skip:
} }
static int static int
default_window_size_skip_client(struct client *loop, int type, default_window_size_skip_client(struct client *loop, __unused int type,
__unused int current, struct session *s, struct window *w) __unused int current, struct session *s, struct window *w)
{ {
/*
* Latest checks separately, so do not check here. Otherwise only
* include clients where the session contains the window or where the
* session is the given session.
*/
if (type == WINDOW_SIZE_LATEST)
return (0);
if (w != NULL && !session_has(loop->session, w)) if (w != NULL && !session_has(loop->session, w))
return (1); return (1);
if (w == NULL && loop->session != s) if (w == NULL && loop->session != s)
@@ -305,12 +298,12 @@ default_window_size(struct client *c, struct session *s, struct window *w,
goto done; goto done;
} }
/* /*
* Ignore the given client if it is a control client - the creating * Ignore the given client if it is a control client - the creating
* client should only affect the size if it is not a control client. * client should only affect the size if it is not a control client.
*/ */
if (c != NULL && (c->flags & CLIENT_CONTROL)) if (c != NULL && (c->flags & CLIENT_CONTROL))
c = NULL; c = NULL;
/* /*
* Look for a client to base the size on. If none exists (or the type * Look for a client to base the size on. If none exists (or the type

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