Compare commits

..

357 Commits

Author SHA1 Message Date
Nicholas Marriott
e476c1230b Build with jemalloc on macOS for 3.7c also. 2026-07-23 12:16:26 +01:00
Nicholas Marriott
746f275d41 Update CHANGES. 2026-07-13 11:34:52 +01:00
nicm
e2d26c20d2 Check time periodically in loops rather than every one. 2026-07-13 11:33:01 +01:00
nicm
81e12f5397 Allow empty name with new-window again, from Jacob Koziej. 2026-07-09 08:51:07 +01:00
nicm
8f3963635b Set initial scrollbar state, from Michael Grant. 2026-07-08 12:15:47 +01:00
Nicholas Marriott
18d5232804 Fix empty argument to splitw. 2026-07-08 09:57:49 +01:00
nicm
c515d8cae0 Do not crash looking for next or previous session. GitHub issue 5344. 2026-07-08 09:56:40 +01:00
Nicholas Marriott
8237d72900 Unzoom before creating floating pane. 2026-07-06 09:05:05 +01:00
nicm
173cc3dfc5 Use message-style as default for message-format again. GitHub issue 5315. 2026-07-06 09:00:10 +01:00
Nicholas Marriott
e802909de0 Fix so that the end of a synchronized update again triggers a redraw. 2026-07-01 17:49:40 +01:00
Nicholas Marriott
0e418b62d2 Remove C-r from help. 2026-06-30 07:44:51 +01:00
Nicholas Marriott
78a2145a47 Update CHANGES. 2026-06-30 07:42:25 +01:00
Nicholas Marriott
dbe50934b1 Add caching of scrollbar options to 3.7a branch. 2026-06-30 07:41:02 +01:00
nicm
166267c87a Allow :. in names again, forbidding them is overly pernickety. Only
forbid invalid UTF-8 and #(.
2026-06-29 19:53:42 +01:00
nicm
132a63d1da Allow empty window and session names. 2026-06-29 17:36:40 +01:00
nicm
4e612612dc Only forbid #( in names and titles (styles are #[ and are useful). 2026-06-29 08:11:08 +01:00
Nicholas Marriott
6c2ef75681 Bump version. 2026-06-28 16:54:51 +01:00
Nicholas Marriott
84291b021f Fix check so as to not use NULL name. 2026-06-27 10:58:39 +01:00
Nicholas Marriott
81f88f8517 Add a missing {. 2026-06-26 18:55:59 +01:00
Nicholas Marriott
4eafb27b89 tmux 3.7. 2026-06-26 18:50:58 +01:00
Nicholas Marriott
4fc4644652 Tweak. 2026-06-26 18:50:42 +01:00
nicm
e7f414416f Set check callback for menus so they aren't overwritten by sync. 2026-06-23 08:35:09 +01:00
nicm
3b8e25fef4 Initialize wname so it we are not freeing garbage if it is not used. 2026-06-17 09:11:00 +01:00
nicm
64e83caf04 Be more strict about what names and titles we allow and reject them
immediately when possible, but allow # again for those directly set by
commands (but not escape sequences). From Barrett Ruth in GitHub issue
5175.
2026-06-17 09:10:55 +01:00
nicm
762e503978 Allow rectangle selection to extend past end of current line to behave
the same as vi with virtualedit=block set. From Mark Kelly in GitHub
issue 5227.
2026-06-16 11:11:47 +01:00
Nicholas Marriott
c809aea278 Fix a merge problem. 2026-06-16 10:24:06 +01:00
Nicholas Marriott
1596f9c9f5 Bump version again. 2026-06-16 10:22:51 +01:00
nicm
2f28d9a168 Fix resizing floating pane with a left scrollbar, from Michael Grant. 2026-06-16 10:22:12 +01:00
Nicholas Marriott
baac29debc Prefer libtinfow if it is available, GitHub issue 5224 from Lars Wendler. 2026-06-16 10:21:12 +01:00
nicm
2c4df765c5 Fix missing border when drawing floating panes. From Michael Grant. 2026-06-16 10:21:09 +01:00
nicm
2d9afa6348 Use correct x position when drawing clipped line. 2026-06-15 18:39:43 +01:00
nicm
bae5c14941 Tidy up screen_redraw_get_visible_ranges by using a couple of
temporaries for start and end of range.
2026-06-15 18:39:28 +01:00
nicm
9cf8de099c Convert cursor position back to pane coordinates for tty_cmd_cell. 2026-06-15 18:39:23 +01:00
nicm
f98aaf544d When redrawing a whole pane line, fall into tty_draw_line for any
characters that are not plain ASCII. Fixes redraw issues with partial
tabs and other wide characters when a pane is partly outside the window.
2026-06-15 09:07:23 +01:00
nicm
78afc24736 Fix various errors in redrawing:
- Fix the active pane colour when only two panes and scrollbars enabled.

- Clip left and right scrollbars the same for floating panes.

- Do not subtract scrollbar width twice when working out width of status
  line.

- Check if a character is inside a visible range correctly (do not
  include the next position outside the range).
2026-06-15 09:06:58 +01:00
nicm
83e4534387 Skip floating panes when working out the top or bottom cell. Fixes
missing bottom status pane status line when floating panes exist.
2026-06-15 09:06:55 +01:00
nicm
dabaae1534 Make buffer creation time sort oldest first like it used to, but change
windows to match sessions and panes as newest first.
2026-06-12 10:19:05 +01:00
nicm
cc87db74c7 Two fixes for RI codepoints. Firstly, do not combine more than two of
them - previously we were ending up with four codepoints in one cell
which tmux believed to be width 2, but terminals considered width 4.
Secondly, invalidate cursor position before redrawing the cell when the
second codepoint is received, terminals vary in how they manage
backspace and cursor movement across these characters, so it is better
to use absolute rather than relative positioning. GitHub issue 4853.
2026-06-09 13:20:14 +01:00
Nicholas Marriott
aa1f0653e9 Bump version to 3.7-rc2. 2026-06-09 09:47:18 +01:00
nicm
8771b6051f Fix mouse events on tiled pane status line - when panes share a border,
prefer the pane for which the border is the status line. With Dane
Jensen.
2026-06-09 09:12:21 +01:00
Nicholas Marriott
bbd4768bb6 3.7-rc version. 2026-06-08 21:08:37 +01:00
Thomas Adam
cb237b5193 Merge branch 'obsd-master' 2026-06-08 16:30:06 +01:00
nicm
85d72b9952 Return immediately if the list is empty in mode_tree_key instead of
crashing, from Bryce Miller in GitHub issue 5170.
2026-06-08 15:16:21 +00:00
Thomas Adam
a04c33c42d Merge branch 'obsd-master' 2026-06-07 21:15:06 +01:00
nicm
529afada82 Move checking of whether the cursor is visible inside the if so that it
always hits the calculation of the oy offset when the status line is at
the top. From Michael Grant.
2026-06-07 20:05:16 +00:00
nicm
a532f4868f Add -H flag to capture-pane to show hyperlinks. 2026-06-07 20:03:02 +00:00
Thomas Adam
e1d37c37b5 Merge branch 'obsd-master' 2026-06-07 17:30:06 +01:00
nicm
ae5e0e8c05 Add -L to show line numbers with capture-pane and -F to show line flags. 2026-06-07 16:23:05 +00:00
Nicholas Marriott
bbea0ef439 Update copy mode vi test, from Max Vim. 2026-06-07 17:22:14 +01:00
Nicholas Marriott
a134c43f4d Update test result. 2026-06-07 16:15:32 +01:00
Nicholas Marriott
e0ebae4481 Fix a couple of tests and add -f/dev/null to them all. 2026-06-07 16:11:38 +01:00
Thomas Adam
1fbc51b69f Merge branch 'obsd-master' 2026-06-07 16:00:06 +01:00
nicm
42f3e7f7ce Clear entire lines when removing from history or freeing. 2026-06-07 14:41:27 +00:00
Thomas Adam
e163cbacec Merge branch 'obsd-master' 2026-06-07 15:30:06 +01:00
Nicholas Marriott
0ec6870902 Add to CHANGES. 2026-06-07 15:24:53 +01:00
Thomas Adam
55421ede70 Merge branch 'obsd-master' 2026-06-07 15:15:06 +01:00
nicm
3acd247f5d Redraw entire session when making a new pane. 2026-06-07 14:11:20 +00:00
Thomas Adam
59151704b4 Merge branch 'obsd-master' 2026-06-07 15:00:06 +01:00
nicm
343ee5ece1 Add -g flag to kill-session to kill all sessions in a group, GitHub
issue 5157 from github at jiku dot jp.
2026-06-07 13:51:42 +00:00
nicm
0256ee77c2 Add some additional environment variables needed for Wayland, from
shbernal dot 01 at gmail dot com.
2026-06-07 13:37:39 +00:00
Thomas Adam
72f5415fc8 Merge branch 'obsd-master' 2026-06-07 14:30:06 +01:00
nicm
ef8e9df02f Tweak previous. 2026-06-07 13:29:16 +00:00
nicm
306ee0eddb Add -E to split-window to explicitly make an empty pane rather than
requiring an empty command.
2026-06-07 13:15:28 +00:00
Nicholas Marriott
3d9e6bf454 Update CHANGES for 3.7. 2026-06-07 12:01:09 +01:00
Thomas Adam
0fc6cb4099 Merge branch 'obsd-master' 2026-06-07 11:15:06 +01:00
nicm
5744021ac9 Allow floating panes to be created partially off the window, based on a
change from Michael Grant.
2026-06-07 09:54:25 +00:00
Thomas Adam
54be05e5e4 Merge branch 'obsd-master' 2026-06-07 09:30:06 +01:00
nicm
c9e22ab67b Enable floating panes. These are panes which sit above the layout
("tiled panes") like popups but unlike popups are not modal and behave
like panes (so the same escape sequence support). Floating panes are
created with the "new-pane" command, bound to * by default.

Currently floating panes can only be moved and resized using the mouse.
The default second status line (if "status-format" is set to 2) has
changed to show a list of panes.

This is the first step and many obvious features are not yet complete
(notably the ability to swap floating panes, resize them using
resize-pane, change them between floating and tiles, and restore custom
layouts with floating panes).

Mostly written by Michael Grant with help from Dane Jensen.
2026-06-07 08:25:59 +00:00
nicm
4063f968c6 Do not allow swapping floating panes for the moment. 2026-06-07 08:22:58 +00:00
Thomas Adam
8388c53a47 Merge branch 'obsd-master' 2026-06-06 19:00:06 +01:00
nicm
3a72f3beb8 Use correct X position for visible range checks in
screen_write_fast_copy, GitHub issue 5164 from Barrett Ruth.
2026-06-06 17:35:30 +00:00
nicm
35709a30ee Change so that floating panes are always part of the root layout. From
Dane Jensen.
2026-06-06 17:30:48 +00:00
Thomas Adam
f9a683cf39 Merge branch 'obsd-master' 2026-06-05 09:15:07 +01:00
nicm
d7a2b52da8 Add a way to quote for command arguments and use for key in list-keys,
GitHub issue 5153.
2026-06-05 08:04:03 +00:00
Thomas Adam
f43adc364a Merge branch 'obsd-master' 2026-06-04 10:45:09 +01:00
nicm
6beebbe074 Fix scrollbar drag position when window is taller than tty, from Michael
Grant.
2026-06-04 09:24:03 +00:00
Thomas Adam
019f8eb278 Merge branch 'obsd-master' 2026-06-03 21:30:06 +01:00
nicm
580f9ced08 Change run-shell expansion to just be #{1} etc not #1 which interferes
with colours.
2026-06-03 20:18:49 +00:00
nicm
642cc15b99 Change so panes scroll when the cursor is at the top instead of halfway
down, from Michael Grant.
2026-06-03 20:16:14 +00:00
Thomas Adam
cfeade6055 Merge branch 'obsd-master' 2026-06-02 21:00:06 +01:00
nicm
390207cdf1 Use new layout functions for join-pane also, from Dane Jensen. 2026-06-02 19:31:36 +00:00
Thomas Adam
c97b2b95e6 Merge branch 'obsd-master' 2026-06-02 20:30:06 +01:00
nicm
a3bf632276 Move cell creation into layout.c, from Dane Jensen. 2026-06-02 19:25:06 +00:00
Thomas Adam
5368ee32dd github: update lock-threads to v6
Use the latest release of lock-threads.
2026-06-02 16:26:13 +01:00
Thomas Adam
e89f02bd8f Merge branch 'obsd-master' 2026-06-02 09:30:06 +01:00
nicm
ae6a749d3a Move the PANE_FLOATING flag into the layout cell and add an accessor.
From Dane Jensen.
2026-06-02 08:13:50 +00:00
Thomas Adam
0759030ee8 Merge branch 'obsd-master' 2026-06-02 08:30:06 +01:00
nicm
35f4c8b333 Fix border colour bug in the floating panes branch where inactive
floating pane borders incorrectly use the active colour at intersections
with tiled pane borders. From Michael Grant.
2026-06-02 07:11:49 +00:00
Thomas Adam
97ac32f536 Merge branch 'obsd-master' 2026-06-01 21:30:06 +01:00
Thomas Adam
2f3ef88dbf Merge branch 'obsd-master' 2026-06-01 21:15:06 +01:00
nicm
9725a0b9bf Remove the actual LAYOUT_FLOATING enum member. 2026-06-01 20:10:01 +00:00
nicm
b368e89bea Remove LAYOUT_FLOATING and disable custom layouts with floating panes
for now, from Dane Jensen.
2026-06-01 20:09:26 +00:00
nicm
3269833caa Fix vertical position of scrollbar having wrong vertical offset when
status-position top, from Michael Grant.
2026-06-01 20:00:25 +00:00
nicm
922f7d1645 Fix resize of floating panes with pane-border-status top, from Michael
Grant.
2026-06-01 19:59:04 +00:00
nicm
a1873fef61 Only set saved_layout_cell if creating a new cell, avoids crash when
respawning pane. Reported by Mingjie Shen in GitHubb issue 5143.
2026-06-01 19:56:26 +00:00
Thomas Adam
0eff3b6b97 Merge branch 'obsd-master' 2026-06-01 19:30:06 +01:00
nicm
f6557d1ea2 Add a Z sort order in tree mode. 2026-06-01 18:19:51 +00:00
Thomas Adam
718eb2b4cc Merge branch 'obsd-master' 2026-06-01 19:15:06 +01:00
nicm
cd6c01e42b Mark floating panes in tree mode. 2026-06-01 18:00:20 +00:00
Thomas Adam
0b773dd792 Merge branch 'obsd-master' 2026-06-01 15:15:06 +01:00
nicm
b68ab3a4b4 Add pane_x, y, z format variables and show in list-panes. 2026-06-01 14:01:09 +00:00
Thomas Adam
d8c9f88fe7 Merge branch 'obsd-master' 2026-06-01 15:00:06 +01:00
Nicholas Marriott
f6398ba51c Add some more DECRQM responses, from Ayman Bagabas in GitHub issue 5118. 2026-06-01 14:30:33 +01:00
nicm
67dbf01eeb Add some more DECRQM responses, from Ayman Bagabas in GitHub issue 5118. 2026-06-01 13:28:49 +00:00
Thomas Adam
7c71064b64 Merge branch 'obsd-master' 2026-06-01 12:15:06 +01:00
nicm
4d91ff8d8d Do not try to use pane if there isn't one when redrawing wide characters,
GitHub issues 5145 and 5139.
2026-06-01 10:53:28 +00:00
Thomas Adam
e778f7f805 Merge branch 'obsd-master' 2026-06-01 09:45:06 +01:00
nicm
3bff7a9e62 Allow run-shell arguments after a shell command to be expanded as #1, #2
and so on. From Rasmus Thystrup Karstensen in GitHub issue 5121.
2026-06-01 08:27:37 +00:00
Thomas Adam
705c2ac55a Merge branch 'obsd-master' 2026-05-31 23:00:06 +01:00
Thomas Adam
3f3d65e452 Merge branch 'obsd-master' 2026-05-31 22:30:06 +01:00
nicm
a9721ea268 Only draw visible parts of numbers for display-panes. 2026-05-31 21:29:41 +00:00
nicm
d876bb8cf3 When pane-border-indicators is set to "both" or "arrows", only draw
arrows on the active floating pane and no other floating panes. Also
there is no need to loop in screen_redraw_cell_border if only checking
one pane.
2026-05-31 21:08:23 +00:00
Thomas Adam
b17dcc6773 Merge branch 'obsd-master' 2026-05-31 22:00:06 +01:00
nicm
e3ee2b327b Move back to starting position when pane is outside the window at all. 2026-05-31 20:41:07 +00:00
Thomas Adam
74b91d6dec Merge branch 'obsd-master' 2026-05-30 17:45:06 +01:00
nicm
7a3b7ae812 Return empty ranges if line is below window. 2026-05-30 16:10:13 +00:00
Thomas Adam
35df67c893 Merge branch 'obsd-master' 2026-05-30 12:30:06 +01:00
nicm
290303e64f Missed this file from previous. 2026-05-30 11:20:03 +00:00
nicm
f8ab7a5158 Handle ranges for panes which are outside the window to the left. 2026-05-30 11:19:39 +00:00
Thomas Adam
decaaf4b55 Merge branch 'obsd-master' 2026-05-30 11:15:06 +01:00
nicm
b9d228c72f Do not crash when a pane offset is negative. 2026-05-30 09:48:30 +00:00
Thomas Adam
11e48c3fa9 Merge branch 'obsd-master' 2026-05-30 10:15:06 +01:00
nicm
c40302a7ff Check if the range is invalid using start,end rather than length since
it will never be negative.
2026-05-30 08:58:29 +00:00
Thomas Adam
964e22cfef Merge branch 'obsd-master' 2026-05-29 17:15:06 +01:00
nicm
55db69e3b2 Correct offsets for redrawing entire line here too. 2026-05-29 15:51:03 +00:00
Thomas Adam
99b08ecde5 Merge branch 'obsd-master' 2026-05-29 09:15:06 +01:00
nicm
4ecf93487e Use correct X position for redrawing wide characters. 2026-05-29 07:49:01 +00:00
Nicholas Marriott
f066933418 Uninstall the man page too. 2026-05-28 15:20:04 +01:00
Thomas Adam
481d8299ca Merge branch 'obsd-master' 2026-05-28 12:45:06 +01:00
nicm
3b19536df9 Swap panes on z-index list as well. 2026-05-28 11:17:35 +00:00
Thomas Adam
2212157b61 Merge branch 'obsd-master' 2026-05-28 12:00:07 +01:00
nicm
7ebeed1ae7 Do not try to use last pane if there isn't one. 2026-05-28 10:45:17 +00:00
nicm
7769097915 Hide menu options that do not work for floating panes. 2026-05-28 10:34:38 +00:00
Thomas Adam
595b0cb471 Merge branch 'obsd-master' 2026-05-28 10:00:08 +01:00
nicm
c50c3629e6 Use the correct ranges when a pane is covered by a popup in tty_draw_pane. 2026-05-28 08:43:57 +00:00
Thomas Adam
887b6f4da7 Merge branch 'obsd-master' 2026-05-28 09:15:07 +01:00
nicm
9c6cfcd2e9 Obscured check should not be true if pane is same size as window. 2026-05-28 07:58:45 +00:00
Thomas Adam
658c7d1dbf Merge branch 'obsd-master' 2026-05-28 08:45:08 +01:00
nicm
ecfe6e4e7a Check visible ranges for collected cell output. 2026-05-28 07:23:52 +00:00
Thomas Adam
f53c4e7525 Merge branch 'obsd-master' 2026-05-27 22:15:06 +01:00
Nicholas Marriott
3690c64e88 Use -g -ggdb for debug. 2026-05-27 22:07:57 +01:00
Thomas Adam
c489f786b6 Merge branch 'obsd-master' 2026-05-27 22:00:06 +01:00
nicm
5c40cc43b2 Bring in the single-cell redraw parts for floating panes. 2026-05-27 20:57:53 +00:00
nicm
54ae850322 Do not adjust end position when removing partial padding, it does not
change.
2026-05-27 20:47:23 +00:00
Thomas Adam
a9b9d2f6d3 Merge branch 'obsd-master' 2026-05-27 21:00:08 +01:00
nicm
f00f92e7e3 Check visible ranges when copying screens. 2026-05-27 19:43:46 +00:00
nicm
bbe26df83d Add an accessor function needed for floating panes. 2026-05-27 19:36:04 +00:00
Thomas Adam
daf9988b3a Merge branch 'obsd-master' 2026-05-27 20:15:06 +01:00
nicm
ee67452772 Add window-pane-status-format options and adjust the default second
status line to show panes, also change how window-style is checked now
it is a pane option.
2026-05-27 18:57:10 +00:00
Thomas Adam
781364f7f9 Merge branch 'obsd-master' 2026-05-27 17:45:06 +01:00
nicm
84d016ddcf Floating panes clearing bits. 2026-05-27 16:25:01 +00:00
Nicholas Marriott
0241fdac1a Remove extra declaration. 2026-05-27 16:52:09 +01:00
Thomas Adam
d62bae442b Merge branch 'obsd-master' 2026-05-27 16:46:04 +01:00
nicm
9cc8947a43 Cache border and active border style separately, fixes problem reported
by Marcel Partap in GitHub issue 5125.
2026-05-27 13:41:20 +00:00
nicm
bff68fa079 Remove reference to an option that hasn't been added yet. 2026-05-27 12:52:47 +00:00
nicm
00c59041ea Bring in some more floating panes changes - obscured panes need to be
handled specially in screen_write_* rather than dropping into the client
redraw (tty.c).
2026-05-27 11:54:28 +00:00
Thomas Adam
a77b81f0e5 Merge branch 'obsd-master' 2026-05-27 08:15:06 +01:00
jsg
f839588c69 fix sort_get_clients() indentation; ok nicm@ 2026-05-27 07:05:20 +00:00
nicm
27d719cd4d Check error result correctly (*cause not cause), pointed out by jsg. 2026-05-27 07:01:36 +00:00
Thomas Adam
7a15dc6772 Merge branch 'obsd-master' 2026-05-25 16:15:06 +01:00
nicm
bfd7f468ce pane_zoomed_flag went missing somewhere in tmux.1, put it back. 2026-05-25 14:53:09 +00:00
Thomas Adam
cca1e77f95 Merge branch 'obsd-master' 2026-05-25 09:15:07 +01:00
nicm
cc81287665 More of floating panes redraw path, still mostly using flags which are never set. 2026-05-25 08:07:48 +00:00
nicm
ca95153b45 Preserve flags when creating new cells, from Brian Youngs. 2026-05-25 07:55:46 +00:00
Nicholas Marriott
eb330a6df6 Restore SIXEL bit. 2026-05-24 10:05:41 +01:00
Thomas Adam
b498979d4d Merge branch 'obsd-master' 2026-05-24 10:00:06 +01:00
nicm
f047b3f8e7 Do not crash when freeing layout cell, reported by Jere Viikari. 2026-05-24 08:40:43 +00:00
Thomas Adam
c67787536b Merge branch 'obsd-master' 2026-05-23 18:00:06 +01:00
nicm
3cfc96d4de Add missing argument to %unlinked-window-renamed, reported by Andrew
Grangaard.
2026-05-23 16:43:04 +00:00
Thomas Adam
91a8c66537 Merge branch 'obsd-master' 2026-05-23 08:45:06 +01:00
nicm
5c3a4746b7 Some code tidying up. 2026-05-23 07:22:50 +00:00
Nicholas Marriott
b8e0004ff2 Fix missing arguments. 2026-05-22 18:33:04 +01:00
Thomas Adam
4e0aabd8a7 Merge branch 'obsd-master' 2026-05-22 16:54:06 +01:00
nicm
143a177055 Tighten up read-only checks on attach-session, detach-client and
switch-client so that a user should be able to only detach their own
client. Reported by John Walker.
2026-05-22 15:22:43 +00:00
nicm
d45a9cad8c Work out if a pane is obscured by another one when drawing. 2026-05-22 11:55:43 +00:00
Nicholas Marriott
285a3b7522 Fix up SIXEL with recent changes. 2026-05-22 12:44:08 +01:00
Thomas Adam
d4255818c4 Merge branch 'obsd-master' 2026-05-22 12:01:06 +01:00
Thomas Adam
f714f3ee78 Merge branch 'obsd-master' 2026-05-22 10:28:51 +01:00
nicm
36bc351557 Use a union for the data passed around in tty_ctx instead of void *. 2026-05-22 09:21:32 +00:00
nicm
d5ee330d20 Tidy up a load of different flags and special values in the tty_ctx into
a single bitmask.
2026-05-22 09:05:16 +00:00
Thomas Adam
634e9d6213 Merge branch 'obsd-master' 2026-05-21 12:01:06 +01:00
nicm
9aa9a92f72 Pane resizing code for floating panes, mostly by Michael Grant. 2026-05-21 07:28:51 +00:00
Nicholas Marriott
8c51c0fdbd Merge tag '3.6b'
3.6b
2026-05-20 12:53:07 +01:00
Thomas Adam
24e4a545a2 Merge branch 'obsd-master' 2026-05-20 12:19:23 +01:00
Nicholas Marriott
c5fb5e8bb0 Update CHANGES. 2026-05-20 12:17:30 +01:00
Nicholas Marriott
b8434182c9 Track which list (images or saved_images) each image is on so they can be
removed from the correct list when the total image count is reached. Fixes
crash reported by xlabai at tencent dot com.
2026-05-20 12:15:34 +01:00
Nicholas Marriott
e1f942f26a Add a define for max images and bump to 20 for the moment. 2026-05-20 12:14:22 +01:00
Thomas Adam
91b85efabb Merge branch 'obsd-master' 2026-05-20 12:01:06 +01:00
nicm
0057905ca0 Increase escape delay if the buffer contains a partial paste end, fixes
issues with at least Windows Terminal. From jing dot empty at gmail.com
GitHub issue 5088.
2026-05-20 10:56:46 +00:00
nicm
572e26deb8 Some more trivial floating panes bits. 2026-05-20 08:54:40 +00:00
Thomas Adam
caff9a135f Merge branch 'obsd-master' 2026-05-20 08:47:44 +01:00
nicm
ce24b92758 Floating panes full redraw code, by Michael Grant. 2026-05-19 13:12:45 +00:00
nicm
f5a086ac98 Some more easy floating panes bits. 2026-05-19 12:16:25 +00:00
Thomas Adam
cb1025e0e8 Merge branch 'obsd-master' 2026-05-19 12:25:31 +01:00
nicm
a46cdb8bbc More (currently disabled) bits for creating floating panes, from Michael
Grant and Dane Jensen.
2026-05-19 10:26:03 +00:00
nicm
34e2035bad More bits for pane Z index tracking from floating panes, mostly by
Michael Grant.
2026-05-19 09:48:14 +00:00
Thomas Adam
a9ba7b8ecb Merge branch 'obsd-master' 2026-05-18 09:38:02 +01:00
nicm
962d647993 Remove some leftover debug code. 2026-05-17 16:02:33 +00:00
nicm
a8520ba59e Bring over some of layout and positioning code for floating panes, by
Michael Grant.
2026-05-17 16:01:42 +00:00
nicm
f12d7b4e67 When mode-keys is set to vi, do not allow the cursor to go into the
invisible extra cell to the right of the visible text. This is closer to
what vi(1) does. From Max Vim in GitHub issue 5070.
2026-05-17 13:12:21 +00:00
nicm
bbea6e6375 Add a five second limit on pasting for terminals which mysteriously lose
the end sequence if the paste is too big (that is, Terminal.app).
Reported by Garri Djavadyan in GitHub issue 4527.
2026-05-17 13:01:04 +00:00
nicm
b24b8424b1 Switch to use backing grid not copy mode's grid for copy line, GitHub
issue 4995.
2026-05-17 12:38:04 +00:00
nicm
35bd1a4c02 Do not include unattached clients on sorted list, fixes crash reported
by Marcel Partap.
2026-05-17 11:17:16 +00:00
nicm
818352c3cd Add some more explanatory text about targets, GitHub issue 4850. 2026-05-17 11:12:07 +00:00
nicm
742efe989f Report file open errors more sensibly, reported by Meriel Luna
Mittelbach in GitHub issue 5081.
2026-05-17 10:54:01 +00:00
nicm
4cea1c7189 Add new-pane command, currently this is equivalent to split-window but
it will have minor differences for floating panes in future. Also add
-R/-s/-S/-k/-m flags to control border and style and behaviour, like
popups. GitHub issue 5027 from Dane Jensen.
2026-05-17 10:44:53 +00:00
Nicholas Marriott
18ddda48d2 More. 2026-05-16 12:18:41 +01:00
Nicholas Marriott
5651519f5d Try to make Copilot shut up. 2026-05-16 12:07:09 +01:00
nicm
281e8ff766 Fix a couple of bugs in tty_draw_line: do not loop forever if orphan
padding appears, or if a wide character is trimmed at the right of the
region. Much help with testing from qingliu at alauda dot io in GitHub
issue 5024.
2026-05-13 13:12:23 +00:00
nicm
dbc0710bc9 Update supported features for Foot, from Meriel Luna Mittelbach in
GutHub issue 5079.
2026-05-13 10:24:57 +00:00
nicm
8f28f31b78 Do not crash if set progress bar with no pane, from Dane Jensen. 2026-05-13 08:25:05 +00:00
Thomas Adam
3f651d9fa9 Merge branch 'obsd-master' 2026-05-12 16:01:08 +01:00
nicm
18fced7e7f Make pane offsets signed, needed for floating panes. 2026-05-12 12:05:41 +00:00
Thomas Adam
f1f0158741 Merge branch 'obsd-master' 2026-05-12 12:01:11 +01:00
nicm
3d6c542e34 Turn off the "is this a paste" guessing if the terminal supports bracket
pasting instead, GitHub issue 5031.
2026-05-12 10:28:09 +00:00
Nicholas Marriott
c3036116de Update test output. 2026-05-12 10:38:29 +01:00
nicm
9e3653a612 Check FIONREAD for all panes not just piped panes, fixes issues with
tests, GitHub issue 4807.
2026-05-12 09:37:25 +00:00
nicm
27a00d1bfd Fix infinite loop due to underflow when redrawing scrollbar, from Pavel
Lavrukhin in GitHub issue 4932.
2026-05-12 09:32:49 +00:00
nicm
800837ff3f Fix control mode teardown ordering for queued pane output, GitHub issue
5064 from Aaron Campbell.
2026-05-12 09:27:28 +00:00
Nicholas Marriott
bfbfb6dbf3 Avoid overshooting Sixel height in sixel_parse_write, GitHub issue 5071 from
nincsnevem662 at gmail dot com.
2026-05-11 12:00:06 +01:00
Thomas Adam
8fb1b1d412 Merge branch 'obsd-master' 2026-05-08 12:01:09 +01:00
nicm
af98467d0d Do not cache format for status line because it stores various pointers
that might be stale, instead cache the cmd_find_state and rebuild the
formats every time they are needed. Reported by Marcel Partap in GitHub
isue 5065.
2026-05-08 06:57:38 +00:00
Thomas Adam
f9d50d580c Merge branch 'obsd-master' 2026-05-07 12:01:08 +01:00
nicm
496805476e Require layout prefix to be 5 characters, GitHub issue 5067 from
cglosner at gmail dot com.
2026-05-07 09:21:05 +00:00
nicm
962e565591 Add Emacs-style recentre-top-bottom, GitHub issue 5053 from sinyax75 at
gmail dot com.
2026-05-07 09:15:44 +00:00
Thomas Adam
862625a4bf Merge branch 'obsd-master' 2026-05-06 16:01:09 +01:00
nicm
2d8aade74b Add time limit to a couple of other loops. 2026-05-06 13:43:38 +00:00
Nicholas Marriott
2aad2cfc53 Add a configure flag for ASAN. 2026-05-06 08:23:45 +01:00
Thomas Adam
ad94405dac Merge branch 'obsd-master' 2026-05-05 16:01:08 +01:00
nicm
518fcf7e03 Do not sanitize title when popping it from stack, also add a limit to
number of pushed titles.
2026-05-05 13:18:46 +00:00
nicm
1fbd00e1e8 Add missing flags to screen_mode_to_string and do not write before
before if any are missed, second bit from qingliu at alauda dot io.
2026-05-05 12:06:52 +00:00
nicm
cae229cadc Discard queued data and clear offsets when turning pane off to prevent
later read of data that has been removed. From Aaron Campbell in GitHub
issue 5054.
2026-05-05 12:02:12 +00:00
Thomas Adam
9d3dcdbc38 Merge branch 'obsd-master' 2026-05-03 20:01:09 +01:00
nicm
d52fabce72 Allow the indicator in tree mode to be customized by two new options:
tree-mode-preview-format and tree-mode-preview-style.
2026-05-03 15:02:48 +00:00
nicm
637d4c3083 Fix control client hang on exit after toggling no-output, GitHub issue
5049 from Aaron Campbell.
2026-05-03 15:01:21 +00:00
nicm
1e96d9a87f Do not check for NULL after dereferencing, from alexarama at yahoo dot
com in GitHub issue 5051.
2026-05-03 14:57:09 +00:00
nicm
49172b256c Free working stuff when R formats fail. 2026-05-03 14:55:43 +00:00
Thomas Adam
9a94f48663 Merge branch 'obsd-master' 2026-05-01 16:01:09 +01:00
nicm
2e9c6c2586 Add some checks on line size to avoid underflow, from san65384 at gmail
dot com in GitHub issue 4955.
2026-05-01 11:56:41 +00:00
Thomas Adam
92522473b0 Merge branch 'obsd-master' 2026-05-01 12:01:08 +01:00
nicm
56200ca044 Do not leak cached last result from control subs, from Aaron Campbell in
GitHub issue 5047.
2026-05-01 09:59:42 +00:00
nicm
524f283cc6 Add support for line numbers in copy mode. A new copy-mode-line-numbers
option has the following modes: off, default (tmux's normal line
numbering where 0 is the top visible line), absolute (first line in
history is 1), relative (relative to the cursor) and hybrid (current
line is absolute, others relative). Also adds
copy-mode-line-number-style and copy-mode-current-line-number-style to
set the style of the line numbers. When copy mode is entered with the
mouse, line numbers stay off.

From Leo Henon in GitHub issue 5025.
2026-05-01 09:44:42 +00:00
nicm
a2acf0f7cf Check time inside repeat (R:) loop as well. 2026-05-01 09:34:05 +00:00
Thomas Adam
d85f1b942d Merge branch 'obsd-master' 2026-04-28 16:01:08 +01:00
Thomas Adam
8da41bdc2b Merge branch 'obsd-master' 2026-04-28 12:01:08 +01:00
nicm
4a926e489b Make C-[ have the same bindings as Escape for terminals with extended
keys where they are different, GitHub issue 5035 from Eric NICOLAS.
2026-04-28 10:01:07 +00:00
nicm
746dd91e86 Sanitize paste buffer names in paste_set and paste_rename, GitHub issue
5032 from Barrett Ruth.
2026-04-28 08:52:37 +00:00
nicm
763dec881a Do not leak socketpair fds in pipe-pane when fork fails. From Barrett
Ruth.
2026-04-28 08:47:55 +00:00
nicm
2a5715fad5 Do not deref NULL job in window_copy_pipe_run when job_run fails. From
Barrett Ruth in GitHub issue 5036.
2026-04-28 08:35:21 +00:00
nicm
ec58272b95 Do not hang run-shell when job_run fails, from Barrett Ruth in GitHub
issue 5037.
2026-04-28 08:34:15 +00:00
nicm
f90d3af403 Fix -p for for join-pane, from Dane Jensen. 2026-04-28 08:32:44 +00:00
Thomas Adam
c2659401b0 Merge branch 'obsd-master' 2026-04-27 16:01:09 +01:00
nicm
9840d4a4a3 Add a limit on maximum length of environment variable assignment in
configuration files.
2026-04-27 12:31:11 +00:00
Nicholas Marriott
fc6d94a9f8 Track which list (images or saved_images) each image is on so they can be
removed from the correct list when the total image count is reached. Fixes
crash reported by xlabai at tencent dot com.
2026-04-27 13:09:07 +01:00
Nicholas Marriott
61a7be0eab Turn off regular expressions when fuzzing because there are cases that take too
much time or memory that cannot be fixed.
2026-04-26 21:19:16 +01:00
Thomas Adam
e4a439aa0c Merge branch 'obsd-master' 2026-04-26 21:12:23 +01:00
nicm
b844cafb9c No need to stravis the window name twice. 2026-04-24 10:08:52 +00:00
nicm
1d9522a7a6 Kill client rather than fatalx on bad file handling messages, reported
by Tim Zheng.
2026-04-23 12:36:15 +00:00
nicm
ffe80579df Redraw correctly when a popup is present above pane borders, GitHub
issue 4997 from Manuel Einfalt.
2026-04-23 11:29:23 +00:00
Thomas Adam
bcd17cf99a Merge branch 'obsd-master' 2026-04-23 11:58:17 +01:00
nicm
bc15723f7f Add feature for progress bar and pass to outside terminal, GitHu issue
4972 from Eric Dorland.
2026-04-22 07:25:17 +00:00
nicm
7a0cc03532 Translate keypad keys to text in prompt input. From Barrett Ruth in
GitHub issue 4996.
2026-04-22 07:15:34 +00:00
nicm
d36f6783c7 Add a couple of controls (kill, zoom) to default pane-status-format.
Will be more to come with floating panes. From Dane Jensen in GitHub
issue 4981.
2026-04-22 07:13:26 +00:00
nicm
d339ab51eb Sanitize pane titles and window and session names more consistently and
strictly, prevents C0 characters and other nonvisible characters causing
problems. Reported (with a different fix) by Chris Monardo in GitHub
issue 4999.
2026-04-22 07:10:16 +00:00
nicm
fee70031f6 Make clock visible on terminals without colours, from Manuel Einfalt in
GitHub issue 5001.
2026-04-22 07:05:59 +00:00
nicm
303edb71bd Add a fairly low time limit to format evaluation to stop absurdly nested
formats from making tmux appear to hang.
2026-04-22 07:05:03 +00:00
nicm
314f0ae964 Do not leak hyperlinks in copy mode, from Barrett Ruth in GitHub issue
5020.
2026-04-22 07:03:06 +00:00
nicm
0835980ef1 Remove no longer accurate statement from tmux.1, reported by dkuettel at
gmail dot com.
2026-04-22 06:58:59 +00:00
nicm
baf55e4616 Add a default set of features for WezTerm. 2026-04-22 06:57:08 +00:00
Nicholas Marriott
dd62c2f946 Do not need to create a new window each time for input-keys.sh test. 2026-04-15 16:21:35 +01:00
Thomas Adam
638cecf43c Merge branch 'obsd-master' 2026-04-14 16:01:08 +01:00
nicm
a97cfe513d Do not leak old time format if it is replaced in same format. 2026-04-14 11:25:41 +00:00
Thomas Adam
9de3c0495f Merge branch 'obsd-master' 2026-04-14 12:01:08 +01:00
nicm
67e6f8245b If job_run fails, do not crash but instead free the popup. 2026-04-14 08:39:10 +00:00
nicm
31c93c483a Another check for partially initialized control client, from Matt
Koscica in GitHub issue 5004.
2026-04-14 08:32:30 +00:00
nicm
86d4d5689c Add detach to default session menu, suggested by Przemyslaw Sztoch. 2026-04-14 07:35:17 +00:00
nicm
663e82bc19 Fix key binding conflict in session menu, from Dane Jensen. 2026-04-14 07:28:57 +00:00
nicm
51109e3f72 Include window bits for pane notifications, GitHub issue 5007 from Saul
Nogueras.
2026-04-14 07:26:45 +00:00
nicm
a11363e9e7 Limit precision to 100 to stop silly formats from running out of memory,
reported by z1281552865 at gmail dot com.
2026-04-14 07:24:23 +00:00
nicm
cc57913d7a Add WAYLAND_DISPLAY to default update-environment, GitHub issue 4965 from
wgh at torlan dot ru.
2026-04-14 07:16:02 +00:00
Thomas Adam
057d169492 Merge branch 'obsd-master' 2026-04-13 12:01:08 +01:00
nicm
e5a2a25faf Do not notify clients if not fully initialized, from Ben Maurer in
GitHub issue 4980.
2026-04-13 09:35:20 +00:00
nicm
147521b757 Add -C flag to command-prompt to match display-message -C (do not freeze
panes). From Barrett Ruth in GitHub issue 4978.
2026-04-13 09:33:09 +00:00
Thomas Adam
31d77e29b6 Merge branch 'obsd-master' 2026-04-05 20:01:08 +01:00
nicm
4b0ff07bcb When a cell is cleared after having been moved, we cannot reuse its
extended data, because that may still be in use. Add a flag to
grid_clear_cell to indicate this. Fixes irritating problems with ICH
(CSI @) mostly visible in emacs.
2026-04-05 15:43:17 +00:00
Thomas Adam
0ee18d4421 Merge branch 'obsd-master' 2026-04-05 16:01:08 +01:00
nicm
21da45e5c3 Add extkeys feature to tmux itself so nested tmux works, GitHub issue 4960. 2026-04-05 14:29:04 +00:00
nicm
d5ed967f58 Set less crazy limits (than INT_MAX) for pad and trim, makes ossfuzz happier. 2026-04-05 13:24:02 +00:00
Thomas Adam
42dafcc62a Merge branch 'obsd-master' 2026-04-04 20:01:11 +01:00
nicm
cad282ebb7 Cache user from getpwuid because it can be very expensive on some
platforms. From Ben Maurer in GitHub issue 4973.
2026-04-04 17:13:07 +00:00
nicm
7f2ac9c871 Add remain-on-exit key to keep pane around until a key is pressed, from
Michael Grant.
2026-04-04 17:00:33 +00:00
nicm
87aaff5fae Bring some new formats from the floating panes work: pane_zoomed_flag,
pane_flags, pane_floating_flag. By Michael Grant.
2026-04-04 16:40:27 +00:00
Thomas Adam
b411010237 Merge branch 'obsd-master' 2026-04-04 16:01:09 +01:00
nicm
d2d86ac360 Document control ranges, from Dane Jensen. 2026-04-04 11:48:00 +00:00
nicm
a827725a8d Set up default and last cell before clearing padding, reported by
someone on GitHub.
2026-04-04 11:39:49 +00:00
nicm
3badbc50e0 Do not read off end of buffer if it ends in \ when expanding \c, found
by ossfuzz.
2026-04-04 11:32:05 +00:00
nicm
cd60de443e Clamp width to terminal width, also change calculation of end of screen
(it is OK to be outside the screen). Fixes problem reported by Dane
Jensen in GitHub issue 4969.
2026-04-04 11:20:01 +00:00
Nicholas Marriott
95e40115a2 Don't just resize buffer once, repeat until it is big enough. Also use
reallocarray. Reported by tuannguyenduc228 at gmail dot com.
2026-04-04 12:11:25 +01:00
Thomas Adam
66c324d7ef Merge branch 'obsd-master' 2026-04-03 16:01:08 +01:00
nicm
6b056eb53f Add some new mouse ranges called "control0" to "control9", will be used
for controls on floating panes, from Dane Jensen, with some bits from
Michael Grant.
2026-04-03 10:13:20 +00:00
Thomas Adam
8cfdcf9a6f Merge branch 'obsd-master' 2026-04-03 11:04:15 +01:00
nicm
0917cd7010 Missed a line from previous. 2026-04-03 09:18:24 +00:00
nicm
bdd78ce38e Handle OSC 9;4 progress bar sequence and store in format variables, from
Eric Dorland in GitHub issue 4954.
2026-04-03 09:14:27 +00:00
nicm
7497db6e37 Increase b64_pton buffer to allow for Base64 without padding, from
Michal Majchrowicz.
2026-04-03 08:23:10 +00:00
Thomas Adam
43e2942fa0 Merge branch 'obsd-master' 2026-04-02 16:01:08 +01:00
Thomas Adam
51bc2f3b76 Merge branch 'obsd-master' 2026-04-02 12:01:08 +01:00
nicm
483683c197 Do not leak command in list-keys, reported by tb@. Also tidy up some
function names while here.
2026-04-02 09:58:14 +00:00
nicm
c95d341220 Do not leak trimmed string when expanding, found by ossfuzz. 2026-04-02 09:35:46 +00:00
nicm
be2c6f3b5e Use INT_MIN + 1 as strtonum lower limits in formats so -ve works, found
by ossfuzz.
2026-04-02 09:28:22 +00:00
nicm
2d5736f297 Limit argc to between 0 and 1000 to prevent fatal from MSG_COMMAND, from
Michal Majchrowicz.
2026-04-02 09:11:39 +00:00
nicm
1a51193899 Handle empty regular expression in substitution, found by ossfuzz. 2026-04-02 08:45:35 +00:00
nicm
8b51abef08 Check for \0 after skipping # not before in format_expand1, from ossfuzz. 2026-04-02 08:37:14 +00:00
nicm
cbb49e8c84 Fix NULL dereference in sort.c, from Dane Jensen. 2026-04-02 08:01:47 +00:00
Thomas Adam
dc12da4573 Merge branch 'obsd-master' 2026-04-01 12:01:08 +01:00
nicm
7af58f74b0 Fixed missing drag end detection and mouse button detection with
modifiers. From Dane Jensen, reported by Joseph Tyson and Mark Kelly.
2026-04-01 08:10:02 +00:00
Thomas Adam
1081876810 Merge branch 'obsd-master' 2026-03-31 16:01:08 +01:00
nicm
2ff0dd3fef Reorganize structure of key_code so that it can be built directly by
bitshifts rather than a load of huge switches, from Dane Jensen in
GitHub issue 4953.
2026-03-31 11:46:43 +00:00
Thomas Adam
a30fc69f86 Merge branch 'obsd-master' 2026-03-30 12:01:08 +01:00
nicm
022b5cf193 When in copy mode with a large scroll offset and the window is resized
so that history shrinks, data->oy can exceed screen_hsize causing an
unsigned integer underflow in the py computation. Clamp data->oy in
window_copy_resize and window_copy_cmd_refresh_from_pane before the
subtraction. From futpib at gmail dot com in GitHub issue 4958.
2026-03-30 09:23:40 +00:00
Nicholas Marriott
7620c03b72 Add new fuzzers for command parsing, formats and styles, from David Korczynski
in GitHub issue 4957.
2026-03-30 10:20:16 +01:00
Thomas Adam
6324dae114 Merge branch 'obsd-master' 2026-03-27 12:01:10 +00:00
nicm
e0237c6b8c Ql -> Fl, from arza at arza dot us in GitHub issue 4949. 2026-03-27 08:41:54 +00:00
nicm
1cf3e02bfb Add a format flag for bracket paste, from George Nachman in GitHub issue
4951.
2026-03-27 08:40:26 +00:00
Thomas Adam
6ca5405db9 Merge branch 'obsd-master' 2026-03-25 12:01:07 +00:00
Nicholas Marriott
fa31f2a3eb Do not really need both. 2026-03-25 10:39:03 +00:00
Nicholas Marriott
d03f9454b9 Make COPYING the same. 2026-03-25 10:38:03 +00:00
Nicholas Marriott
616fb1cbcf Add a LICENSE file to see if it makes GitHub happy. 2026-03-25 10:26:15 +00:00
nicm
b7d1e6257c Use \- for hyphens in tmux.1 to cause newer groff versions to render
them correctly (ASCII hyphen rather than Unicode) which aids copy and
paste. From Keith Thompson in GitHub issue 4948.
2026-03-25 10:08:50 +00:00
Thomas Adam
b101ffaed6 Merge branch 'obsd-master' 2026-03-23 12:01:10 +00:00
nicm
f7dad4f38f Check lastgc is not NULL before using it, GitHub issue 4935 from Pavel
Lavrukhin.
2026-03-23 09:05:59 +00:00
nicm
b88c08f860 Fix a NULL dereference and use after free, GitHub issue 4936 from Pavel
Lavrukhin.
2026-03-23 09:03:43 +00:00
Nicholas Marriott
cc47f4d1c2 Use window options for cursor-style to avoid crash when no pane, from
Arden Packeer in GitHub issue 4942.
2026-03-23 09:00:42 +00:00
nicm
3909d7e92f Use window options for cursor-style to avoid crash when no pane, from
Arden Packeer in GitHub issue 4942.
2026-03-23 08:58:39 +00:00
nicm
d70edfa0a0 Fix issue where popup window gets overwritten by background updates,
from Conor Taylor in GitHub issue 4920.
2026-03-23 08:48:32 +00:00
nicm
d22ab85b84 Protect against overflow when scrollbar is off screen, from san65384 at
gmail dot com in GitHub issue 4933.
2026-03-23 08:45:30 +00:00
Thomas Adam
5c30b145df Merge branch 'obsd-master' 2026-03-18 12:01:09 +00:00
nicm
e446cba6a9 Copy hyperlinks when redrawing popup so they do not vanish, from Antoine
Gaudreau Simard in GitHub issue 4925.
2026-03-18 08:49:27 +00:00
Nicholas Marriott
8a0b4e0d8c Work around systemd killing panes early during system shutdown by creating
dependencies from the panes to the service which started tmux, GitHub issue
4926 from Dmitry Torokhov.
2026-03-18 08:46:16 +00:00
nicm
02a9cdff57 Fix buffer to both for get-clipboard, from Seth Girvan. 2026-03-18 08:41:20 +00:00
nicm
f516f8a1d4 Allow codepoint-widths to accept ranges, from san65384 at gmail dot com
in GitHub issue 4930.
2026-03-18 08:38:54 +00:00
Thomas Adam
bef4865d91 Merge branch 'obsd-master' 2026-03-12 16:01:08 +00:00
nicm
fd62f419ac Add a short builtin help text for each mode accessible with C-h,
based on code from Patrick Motard in GitHub issue 4751.
2026-03-12 12:40:40 +00:00
Thomas Adam
7fa6f320ed Merge branch 'obsd-master' 2026-03-12 12:01:09 +00:00
nicm
19f3fb131b Draw message as one format, allowing prompts and messages to occupy only
a portion of the status bar, overlaying the normal status content rather
than replacing the entire line. A new message-format option now controls
the entire message (like status-format). From Conor Taylor in GitHub
issue 4861.
2026-03-12 07:25:13 +00:00
nicm
551e8fcd24 Fix comparison of menu keys, reported by Vladimir Bauer in GitHub issue
4891.
2026-03-12 07:15:26 +00:00
Thomas Adam
04b4952f0e Merge branch 'obsd-master' 2026-03-09 20:01:07 +00:00
Thomas Adam
0d77555c97 Merge branch 'obsd-master' 2026-03-09 16:01:09 +00:00
nicm
67141fb4bb Add next/previous variables for windows in W: loop, from Conor Taylor in
GitHub issue 4856.
2026-03-09 15:46:01 +00:00
tb
2efa762c2b tmux: move block assigning to prefix a bit down to avoid a small leak
ok nicm
2026-03-09 14:37:26 +00:00
Nicholas Marriott
6c2dd193cf Fix memory leak in sixel_parse() on error path, from Renaud Allard in GitHub
issue 4916.
2026-03-09 14:34:58 +00:00
nicm
881bec958e Fix server crash when control client session is destroyed, from Renaud
Allard in GitHub issue 4916.
2026-03-09 14:33:55 +00:00
nicm
8899c751e5 Check for NULL value in tilde expansion before dereferencing, from
Renaud Allard in GitHub issue 4916.
2026-03-09 14:31:41 +00:00
Thomas Adam
d0caf0a322 Merge branch 'obsd-master' 2026-03-06 12:01:08 +00:00
tb
91b5108eae tmux: don't leak menu if the tty is too small to display it
ok nicm
2026-03-06 08:19:22 +00:00
nicm
2c7f73f9c4 Do not use recallocarray because the stored size may have changed during
reflow so may not match what it expects, fixes crash reported by Caspar
Schutijser.
2026-03-06 08:09:58 +00:00
Thomas Adam
5310592967 Merge branch 'obsd-master' 2026-03-06 04:01:09 +00:00
nicm
41bddae907 Fix incorrect condition for creating client name, from Vlad Apostol in
GitHub issue 4911.
2026-03-05 22:50:14 +00:00
135 changed files with 8727 additions and 5609 deletions

11
.github/copilot-instructions.md vendored Normal file
View File

@@ -0,0 +1,11 @@
For pull request code reviews in this repository, do not leave any review comments under any circumstances.
If asked to review a pull request, produce no comments.
Do not comment on pull requests in this repository.
For pull request code reviews in this repository, do not leave a pull request overview.
Do not leave inline review comments.
If asked to review a pull request, provide no summary, no overview, and no code comments.

View File

@@ -17,7 +17,7 @@ jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@v5
- uses: dessant/lock-threads@v6
with:
github-token: ${{ github.token }}
issue-inactive-days: '30'

361
CHANGES
View File

@@ -1,3 +1,364 @@
CHANGES FROM 3.7b TO 3.7c
* Build with jemalloc on macOS to avoid what appears to be a bug in calloc
(issue 5385).
* Fix scrollbar initial state so they appear on new windows (issue 5339).
* Check time periodically in loops rather than every one (issue 5367).
* Use message-style again as default for message-format.
* Unzoom before creating floating panes to avoid a crash.
CHANGES FROM 3.7a TO 3.7b
* Fix so that the end of a synchronized update again triggers a redraw.
CHANGES FROM 3.7 TO 3.7a
* Fix crash in break-pane when no name is provided.
* Scrollbar options are now cached rather than being looked up for every redraw
(issue 5298).
* Only forbid #( in names, allow #[, empty names, : and .
CHANGES FROM 3.6b TO 3.7
* Add floating panes. These are panes which sit above the layout ("tiled
panes") like popups but unlike popups are not modal and behave like panes (so
the same escape sequence support). Floating panes are created with the
new-pane command, bound to * by default.
This is an early release of this feature and they are relatively limited.
Currently floating panes can only be moved and resized using the mouse. The
default second status line (if status-format is set to 2) has changed to show
a list of panes. Many obvious features are not yet available for floating
panes (notably the ability to swap floating panes, resize them using
resize-pane, change them between floating and tiles, and restore custom
layouts with floating panes).
Mostly written by Michael Grant with help from Dane Jensen; testing and fixes
from others.
* Allow run-shell arguments after a shell command to be expanded as #{1}, #{2}
and so on (from Rasmus Thystrup Karstensen in issue 5121).
* Add -g to kill-session to kill all sessions in a session group (issue 5157
from github at jiku dot jp).
* Tighten up read-only checks on attach-session, detach-client and
switch-client so that a user should be able to only detach their own client
(reported by John Walker).
* Increase escape delay if the buffer contains a partial paste end, fixes
issues with at least Windows Terminal (from jing dot empty at gmail.com issue
5088).
* When mode-keys is set to vi, do not allow the cursor to go into the invisible
extra cell to the right of the visible text; this is closer to what vi(1)
does (from Max Vim in issue 5070).
* Add a five second limit on pasting for terminals which mysteriously lose the
end sequence if the paste is too big (that is, Terminal.app) (reported by
Garri Djavadyan in issue 4527).
* Show file open errors more sensibly (reported by Meriel Luna Mittelbach in
issue 5081).
* Update supported features list for Foot terminal (from Meriel Luna Mittelbach
in issue 5079).
* Turn off the "is this a paste" guessing if the terminal supports bracket
pasting instead (issue 5031).
* Check FIONREAD for all panes not just piped panes.
* Add emacs-style recentre-top-bottom command to copy mode (issue 5053 from
sinyax75 at gmail dot com).
* Allow the indicator in tree mode to be customized by two new options:
tree-mode-preview-format and tree-mode-preview-style.
* Fix control client hang on exit after toggling no-output (issue 5049 from
Aaron Campbell). Also various other control mode fixes.
* Add support for line numbers in copy mode. There is a new
copy-mode-line-numbers option which may be set to off, default (tmux's normal
line numbering where 0 is the top visible line), absolute (first line in
history is 1), relative (relative to the cursor) and hybrid (current line is
absolute, others relative). Also adds copy-mode-line-number-style and
copy-mode-current-line-number-style to set the style of the line numbers.
When copy mode is entered with the mouse, line numbers stay off. From Leo
Henon in issue 5025.
* Make C-[ have the same bindings as Escape for terminals with extended
keys where they are different (issue 5035 from Eric Nicolas).
* Sanitize paste buffer names in paste_set and paste_rename (issue 5032 from
Barrett Ruth).
* Do not hang in run-shell when job_run fails (from Barrett Ruth in issue
5037).
* Add ability to forward progress bar to outside terminal (issue 4972
from Eric Dorland).
* Translate keypad keys to text in prompt input (from Barrett Ruth in issue
4996).
* Sanitize pane titles and window and session names more consistently and
strictly, prevents C0 characters and other invisible characters causing
problems (reported by Chris Monardo in issue 4999).
* Make clock visible on terminals without colours (from Manuel Einfalt in issue
5001).
* Add detach to default session menu (suggested by Przemyslaw Sztoch).
* Include window format variables for pane notifications (issue 5007 from Saul
Nogueras).
* Limit precision to 100 for formats to stop silly formats from running out of
memory, reported by z1281552865 at gmail dot com. Also various other similar
changes, mostly found by OSS-Fuzz.
* Add WAYLAND_DISPLAY to default update-environment (issue 4965). Also some
additional XDG_* variables (issue 5169).
* Add -C flag to command-prompt to match display-message -C (do not freeze
panes) (from Barrett Ruth in issue 4978).
* Cache user from getpwuid because it can be very expensive on some
platforms (from Ben Maurer in issue 4973).
* Add remain-on-exit key to keep pane around until a key is pressed (from
Michael Grant).
* Add some new mouse ranges called "control0" to "control9" and use to add some
mouse controls to the pane state line (from Dane Jensen with some bits from
Michael Grant).
* Handle OSC 9;4 progress bar sequence and store in format variables (from Eric
Dorland in issue 4954).
* Correctly size buffer used for parsing clipboard sequences (from Michal
Majchrowicz).
* Limit MSG_COMMAND argument to between 0 and 1000 to prevent a misbehaving
client from crashing the server (from Michal Majchrowicz).
* Reorganize host keys are represented internally so they can be built more
easily (from Dane Jensen in issue 4953).
* Add new fuzzers for command parsing, formats and styles (from David
Korczynski in issue 4957). Also fix various issues shown from these.
* Add bracket_paste_flag format flag (from George Nachman in issue 4951).
* Use \- for hyphens in tmux.1 to cause newer groff versions to render them
correctly (from Keith Thompson in issue 4948).
* Various minor code improvements and fixes from Pavel Lavrukhin (issue 4936
and others).
* Use window options for cursor-style to avoid crash when no pane (from Arden
Packeer in issue 4942).
* Fix issue where popup window gets overwritten by background updates (from
Conor Taylor in issue 4920).
* Protect against overflow when scrollbar is off screen (from san65384 at gmail
dot com in issue 4933).
* Copy hyperlinks when redrawing popup so they do not vanish (from Antoine
Gaudreau Simard in issue 4925).
* Work around systemd killing panes early during system shutdown by creating
dependencies from the panes to the service which started tmux (issue 4926
from Dmitry Torokhov).
* Allow codepoint-widths to accept ranges (from san65384 at gmail dot com in
issue 4930).
* Add a short builtin help text for each mode accessible with C-h (based on
code from Patrick Motard in issue 4751).
* Draw message as one format, allowing prompts and messages to occupy only a
portion of the status bar, overlaying the normal status content rather than
replacing the entire line. A new message-format option now controls the
entire message (like status-format). The message-style option now need to
include "fill" in order to cover the whole width (the default has
"fill=yellow"). From Conor Taylor in issue 4861.
* Add next/previous variables for windows in W: loop (from Conor Taylor in
issue 4856).
* Various bug and memory leak fixes from Renaud Allard (issue 4916).
* Add pane_pipe_pid with pipe file descriptor.
* Make -c work with new-session -A (from Jody Frankowski in issue 4906).
* Allow copy mode to work for readonly clients, except for copy commands (from
Dane Jensen).
* Pass paste buffer through vis(3) when pasting to prevent buffers containing
for example the bracket end sequence causing issues, a new -S flag disables
(reported by Mason Davis).
* Add sorting (-O flag) and a custom format (-F) to list-keys (from Dane Jensen
in issue 4845).
* Add scroll-exit-on, scroll-exit-off, scroll-exit-toggle commands to copy mode
(from xcdnlgd at hotmail dot com in issue 4884).
* Respond to DECRQM 2026 (from David Turnbull in issue 4887) and various others
(from Ayman Bagabas in issue 5118).
* Fix various memory leaks reported by Huihui Huang (issue 4872).
* Pass which clipboard is set through to the terminal (from Axel Lindskog in
issue 4858).
* Reuse extended entry when clearing RGB cell, to prevent memory growth when
cells are repeatedly cleared (from Michael K Darling in issue 4862).
* Do not write before buffer when parsing empty clipboard or palette replies,
or try to allocate zero bytes with an empty clipboard sequence (reported by
DongHan Kim).
* Various bug fixes and code improvements from Conor Taylor (issue 4848).
* Clear search counts when clearing marks in case of repeated search (reported
by Daniel Pereira in issue 4817).
* Make OSC 52 work in popups (from gogongxt at 163 dot com in issue 4797).
* Refresh copy mode when style changes (from Josh Cooper in issue 4830).
* Make sorting code common and add -O for sorting to the list commands (from
Dane Jensen in issue 4813).
* Do not treat cells as empty unless the background colour stays the same,
fixes invisible clock in clock mode (reported by Theo Buehler).
* When history-limit is changed, apply to existing panes, not just new
ones (issue 4705).
* Reevaluate menu and popup styles on each draw to allow them to change when
options change (from Josh Cooper in issues 4828 and 4829).
* Handle theme keys earlier so they are processed even if a popup is open (from
Josh Cooper in issue 4827).
* Fix window-size=latest not resizing on switch-client in session groups (from
Ilya Grigoriev in issue 4818).
* Add -e flag to command-prompt to close if empty (from Dane Jensen in issue
4812).
* Correctly draw indicators when pane-border-indicators is set to both
(reported by Ilya Grigoriev in issue 4780).
* Remember last pane or type of location for double and triple clicks and
correctly handle it changes between first and second or second and third
(issue 4795 from Shaobo Song).
* Add paste to the default pane menu (issue 4763).
* Reduce request timeout to 500 milliseconds to match the extended escape-time,
and discard palette requests if receiving a reply for a different index.
* Extend escape timeout if there are active forwarded requests not just
tmux's own requests (issue 4793).
* Correct redrawing of wide characters when overwritten (reported by Jake
Stewart in issue 4737).
* If cannot find a terminator for palette responses, treat as a partial key not
complete (issue 4749).
* Do not send theme unless it has changed, and do not send immediately when
updates are enabled (issue 5787).
* Do not use ;;s in list-keys output as it is confusing and cannot be
parsed on input (from Patrick Motard in issue 4750).
* Redraw pane borders when entering or leaving alternate screen (from Mike
Jonkmans in issue 4788).
* Add focus-follows-mouse option (from Barry Wasdell in issue 4771).
* Add selection_mode format variable for copy mode (from Mike Jonkmans in issue
4773).
* Add prompt-command-cursor-style (from Joshua Cooper in issue 4765).
* With status-keys vi, move the cursor left by one when pressing Escape to
enter command mode, like vi (issue 4767 from Joshua Cooper).
* Add {current}/{active} for -t for current window or active pane (from Manuel
Einfalt, issue 4766).
* Add support for applications to use synchronized output mode (DECSET 2026) to
prevent screen tearing during rapid updates (from Chris Lloyd in issue 4744).
* Do not set a default prompt cursor colour because some terminals (urxvt, st)
do not support the reset sequence (issue 4759).
* Add a scroll-to-mouse command for copy mode to scroll to the mouse position
and bind to the scrollbar, brings the scrollbar keys into line with the other
mouse keys (from Michael Grant in issue 4731).
* Bump the maximum number of SIXEL images to 20.
* Fix key code for M-BSpace (issue 4717).
* Fix calculation of scaled SIXEL size (from nincsnevem662 at gmail dot com in
issue 4739). Also various other fixes and improvements for SIXEL.
* Fix a race between fork and pane_current_path, most noticeable on systems
where starting processes is slow (issue 4719).
* Fix mouse position calculation on scrollbar with pane status line at the top
(issue 4738 from Michael Grant).
* Do not read outside buffer if format is a single #, and do not loop forever
if UTF-8 is unfinished in a format (reported by Giorgi Kobakhia in issue
4735).
* Add a missing skin tone character (from Jake Stewart in issue 4736).
* Allow UTF-8 characters to be combined in either order (reported by Jake
Stewart in issue 4726).
* Do not show scrollbar when entering copy mode from a pane in the alternate
screen (issue 4728 from Michael Grant).
* Fix the size calculation for left-right windows used to spread out cells
horizontally evenly (from Michael Grant in issue 4724).
* Add a get-clipboard option which when enabled (the default is off) and a
clipboard is requested from a pane, requests it from the terminal and
forwards to the requesting pane; also remove the now-redundant
forward-to-pane ability from "refresh-client -l" (issue 4275).
* Fix the noattr attribute in styles, used by the default mode-style (issue
4713).
* Do not remove TERM for commands run from config file (regression reported by
Dennis Eriksen).
* Add seconds options for clock mode (from augustus7613 dot mail at pm dot me,
issue 4697; later improved by Joao Pedro in issue 4760).
CHANGES FROM 3.6a TO 3.6b
* Remove images from the correct list when they are removed while in the
alternate screen (reported by xlabai at tencent dot com).
CHANGES FROM 3.6 TO 3.6a
* Fix a buffer overread and an infinite loop in format processing (reported by

View File

@@ -1,9 +1,4 @@
THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE.
The README, CHANGES, FAQ and TODO files are licensed under the ISC license. All
other files have a license and copyright notice at their start, typically:
Copyright (c) <author>
Copyright (c) Various Authors
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above

View File

@@ -27,7 +27,7 @@ else
AM_CFLAGS += -O0
endif
if IS_DEBUG
AM_CFLAGS += -g
AM_CFLAGS += -g3 -ggdb
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2 -Wno-use-after-free
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
@@ -41,6 +41,10 @@ endif
AM_CPPFLAGS += -DDEBUG
endif
AM_CPPFLAGS += -iquote.
if IS_ASAN
AM_CFLAGS += -fsanitize=address
AM_LDFLAGS += -fsanitize=address
endif
endif
# Set flags for Solaris.
@@ -232,24 +236,25 @@ nodist_tmux_SOURCES += compat/utf8proc.c
endif
# Enable sixel support.
if ENABLE_SIXEL_IMAGES
if ENABLE_SIXEL
dist_tmux_SOURCES += image.c image-sixel.c
else
# If not sixel, still need image.c for kitty.
if ENABLE_KITTY_IMAGES
dist_tmux_SOURCES += image.c
endif
endif
# Enable kitty graphics protocol support.
if ENABLE_KITTY_IMAGES
dist_tmux_SOURCES += image-kitty.c
endif
# Add bits for fuzzing if enabled.
if NEED_FUZZING
check_PROGRAMS = fuzz/input-fuzzer
check_PROGRAMS = \
fuzz/input-fuzzer \
fuzz/cmd-parse-fuzzer \
fuzz/format-fuzzer \
fuzz/style-fuzzer
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
fuzz_input_fuzzer_LDADD = $(LDADD) $(tmux_OBJECTS)
fuzz_cmd_parse_fuzzer_LDFLAGS = $(FUZZING_LIBS)
fuzz_cmd_parse_fuzzer_LDADD = $(LDADD) $(tmux_OBJECTS)
fuzz_format_fuzzer_LDFLAGS = $(FUZZING_LIBS)
fuzz_format_fuzzer_LDADD = $(LDADD) $(tmux_OBJECTS)
fuzz_style_fuzzer_LDFLAGS = $(FUZZING_LIBS)
fuzz_style_fuzzer_LDADD = $(LDADD) $(tmux_OBJECTS)
endif
# Install tmux.1 in the right format.
@@ -264,3 +269,7 @@ install-exec-hook:
$(mkdir_p) $(DESTDIR)$(mandir)/man1
$(INSTALL_DATA) $(srcdir)/tmux.1.@MANFORMAT@ \
$(DESTDIR)$(mandir)/man1/tmux.1
# And uninstall it.
uninstall-hook:
rm -f $(DESTDIR)$(mandir)/man1/tmux.1

View File

@@ -61,6 +61,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
struct window_pane *wp;
char *cwd, *cause;
enum msgtype msgtype;
uid_t uid;
if (RB_EMPTY(&sessions)) {
cmdq_error(item, "no sessions");
@@ -106,8 +107,16 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
}
if (fflag)
server_client_set_flags(c, fflag);
if (rflag)
if (rflag) {
if (c->flags & CLIENT_READONLY) {
uid = proc_get_peer_uid(c->peer);
if (uid != getuid()) {
cmdq_error(item, "client is read-only");
return (CMD_RETURN_ERROR);
}
}
c->flags |= (CLIENT_READONLY|CLIENT_IGNORESIZE);
}
c->last_session = c->session;
if (c->session != NULL) {

View File

@@ -58,9 +58,14 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
struct session *dst_s = target->s;
struct window_pane *wp = source->wp;
struct window *w = wl->window;
char *name, *cause, *cp;
char *newname, *cause, *cp;
int idx = target->idx, before;
const char *template;
const char *template, *name = args_get(args, 'n');
if (name != NULL && !check_name(name)) {
cmdq_error(item, "invalid window name: %s", name);
return (CMD_RETURN_ERROR);
}
before = args_has(args, 'b');
if (args_has(args, 'a') || before) {
@@ -73,15 +78,15 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
}
server_unzoom_window(w);
if (window_count_panes(w) == 1) {
if (window_count_panes(w, 1) == 1) {
if (server_link_window(src_s, wl, dst_s, idx, 0,
!args_has(args, 'd'), &cause) != 0) {
cmdq_error(item, "%s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
if (args_has(args, 'n')) {
window_set_name(w, args_get(args, 'n'));
if (name != NULL) {
window_set_name(w, name, 0);
options_set_number(w->options, "automatic-rename", 0);
}
server_unlink_window(src_s, wl);
@@ -96,6 +101,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
}
TAILQ_REMOVE(&w->panes, wp, entry);
TAILQ_REMOVE(&w->z_index, wp, zentry);
server_client_remove_pane(wp);
window_lost_pane(w, wp);
layout_close_pane(wp);
@@ -104,15 +110,16 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
options_set_parent(wp->options, w->options);
wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
TAILQ_INSERT_HEAD(&w->z_index, wp, zentry);
w->active = wp;
w->latest = tc;
if (!args_has(args, 'n')) {
name = default_window_name(w);
window_set_name(w, name);
free(name);
if (name == NULL) {
newname = default_window_name(w);
window_set_name(w, newname, 0);
free(newname);
} else {
window_set_name(w, args_get(args, 'n'));
window_set_name(w, name, 0);
options_set_number(w->options, "automatic-rename", 0);
}

View File

@@ -29,18 +29,21 @@
static enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmdq_item *);
static char *cmd_capture_pane_append(char *, size_t *, char *, size_t);
static char *cmd_capture_pane_append(char *, size_t *, const char *,
size_t);
static char *cmd_capture_pane_pending(struct args *, struct window_pane *,
size_t *);
static char *cmd_capture_pane_history(struct args *, struct cmdq_item *,
struct window_pane *, size_t *);
static char *cmd_capture_pane_hyperlinks(struct grid *, struct screen *,
u_int, u_int *, u_int *, size_t *);
const struct cmd_entry cmd_capture_pane_entry = {
.name = "capture-pane",
.alias = "capturep",
.args = { "ab:CeE:JMNpPqS:Tt:", 0, 0, NULL },
.usage = "[-aCeJMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
.args = { "ab:CeE:FHJLMNpPqS:Tt:", 0, 0, NULL },
.usage = "[-aCeFHJLMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
"[-S start-line] " CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 },
@@ -63,7 +66,8 @@ const struct cmd_entry cmd_clear_history_entry = {
};
static char *
cmd_capture_pane_append(char *buf, size_t *len, char *line, size_t linelen)
cmd_capture_pane_append(char *buf, size_t *len, const char *line,
size_t linelen)
{
buf = xrealloc(buf, *len + linelen + 1);
memcpy(buf + *len, line, linelen);
@@ -103,6 +107,46 @@ cmd_capture_pane_pending(struct args *args, struct window_pane *wp,
return (buf);
}
static char *
cmd_capture_pane_hyperlinks(struct grid *gd, struct screen *s, u_int py,
u_int *links, u_int *nlinks, size_t *len)
{
const struct grid_line *gl = grid_peek_line(gd, py);
struct grid_cell gc;
const char *uri;
char *line = xstrdup("");
u_int i, j;
*len = 0;
if (s->hyperlinks == NULL || (~gl->flags & GRID_LINE_HYPERLINK))
return (line);
for (i = 0; i < gl->cellused; i++) {
grid_get_cell(gd, i, py, &gc);
if (gc.link == 0)
continue;
for (j = 0; j < *nlinks; j++) {
if (links[j] == gc.link)
break;
}
if (j != *nlinks)
continue;
if (!hyperlinks_get(s->hyperlinks, gc.link, &uri, NULL, NULL))
continue;
if (*nlinks == gd->sx)
break;
links[(*nlinks)++] = gc.link;
if (*len != 0)
line = cmd_capture_pane_append(line, len, " ", 1);
line = cmd_capture_pane_append(line, len, uri, strlen(uri));
}
return (line);
}
static char *
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
struct window_pane *wp, size_t *len)
@@ -112,9 +156,11 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
struct screen *s;
struct grid_cell *gc = NULL;
struct window_mode_entry *wme;
int n, join_lines, flags = 0;
int n, join_lines, number_lines, flags = 0;
int show_flags, hyperlinks;
u_int *links = NULL, nlinks = 0;
u_int i, sx, top, bottom, tmp;
char *cause, *buf, *line;
char *cause, *buf = NULL, *line, b[64], *cp;
const char *Sflag, *Eflag;
size_t linelen;
@@ -152,7 +198,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
if (cause != NULL) {
top = gd->hsize;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
} else if (n < 0 && (u_int)-n > gd->hsize)
top = 0;
else
top = gd->hsize + n;
@@ -169,7 +215,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
if (cause != NULL) {
bottom = gd->hsize + gd->sy - 1;
free(cause);
} else if (n < 0 && (u_int) -n > gd->hsize)
} else if (n < 0 && (u_int)-n > gd->hsize)
bottom = 0;
else
bottom = gd->hsize + n;
@@ -192,12 +238,57 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
flags |= GRID_STRING_EMPTY_CELLS;
if (!join_lines && !args_has(args, 'N'))
flags |= GRID_STRING_TRIM_SPACES;
number_lines = args_has(args, 'L');
show_flags = args_has(args, 'F');
hyperlinks = args_has(args, 'H');
if (hyperlinks)
links = xreallocarray(NULL, gd->sx, sizeof *links);
buf = NULL;
for (i = top; i <= bottom; i++) {
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
linelen = strlen(line);
if (hyperlinks) {
line = cmd_capture_pane_hyperlinks(gd, s, i, links,
&nlinks, &linelen);
} else {
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
linelen = strlen(line);
}
if (hyperlinks && linelen == 0) {
free(line);
continue;
}
if (number_lines) {
if (i >= gd->hsize)
n = i - gd->hsize;
else
n = (int)i - (int)gd->hsize;
n = snprintf(b, sizeof b, "%d ", n);
if (n >= 0)
buf = cmd_capture_pane_append(buf, len, b, n);
}
if (show_flags) {
cp = b;
*cp = '\0';
gl = grid_peek_line(gd, i);
if (gl->flags & GRID_LINE_DEAD)
*cp++ = 'D';
if (gl->flags & GRID_LINE_HYPERLINK)
*cp++ = 'H';
if (gl->flags & GRID_LINE_START_OUTPUT)
*cp++ = 'O';
if (gl->flags & GRID_LINE_START_PROMPT)
*cp++ = 'P';
if (gl->flags & GRID_LINE_WRAPPED)
*cp++ = 'W';
if (gl->flags & GRID_LINE_EXTENDED)
*cp++ = 'X';
if (b == cp)
*cp++ = '-';
*cp++ = ' ';
*cp = '\0';
buf = cmd_capture_pane_append(buf, len, b, strlen (b));
}
buf = cmd_capture_pane_append(buf, len, line, linelen);
gl = grid_peek_line(gd, i);
@@ -206,6 +297,9 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
free(line);
}
free(links);
if (buf == NULL)
buf = xstrdup("");
return (buf);
}
@@ -228,7 +322,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
}
len = 0;
if (args_has(args, 'P'))
if (args_has(args, 'P') && !args_has(args, 'H'))
buf = cmd_capture_pane_pending(args, wp, &len);
else
buf = cmd_capture_pane_history(args, item, wp, &len);

View File

@@ -42,8 +42,8 @@ const struct cmd_entry cmd_command_prompt_entry = {
.name = "command-prompt",
.alias = NULL,
.args = { "1beFiklI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
.usage = "[-1beFiklN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
.args = { "1CbeFiklI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
.usage = "[-1CbeFiklN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
" [-T prompt-type] [template]",
.flags = CMD_CLIENT_TFLAG,
@@ -165,6 +165,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
cdata->flags |= PROMPT_KEY;
else if (args_has(args, 'e'))
cdata->flags |= PROMPT_BSPACE_EXIT;
if (args_has(args, 'C'))
cdata->flags |= PROMPT_NOFREEZE;
status_prompt_set(tc, target, cdata->prompts[0].prompt,
cdata->prompts[0].input, cmd_command_prompt_callback,
cmd_command_prompt_free, cdata, cdata->flags, cdata->prompt_type);

View File

@@ -63,6 +63,8 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
struct client *c = cmdq_get_client(item);
struct session *s;
struct window_pane *wp = target->wp, *swp;
u_int tty_ox, tty_oy, tty_sx, tty_sy;
int line_numbers;
if (args_has(args, 'q')) {
window_pane_reset_mode_all(wp);
@@ -85,17 +87,23 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
swp = source->wp;
else
swp = wp;
line_numbers = 1;
if (event != NULL && KEYC_IS_MOUSE(event->key))
line_numbers = 0;
if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) {
window_copy_set_line_numbers(wp, line_numbers);
if (args_has(args, 'M'))
window_copy_start_drag(c, &event->m);
}
} else
window_copy_set_line_numbers(wp, line_numbers);
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);
if (args_has(args, 'd'))
window_copy_pagedown(wp, 0, args_has(args, 'e'));
if (args_has(args, 'S')) {
tty_window_offset(&c->tty, &tty_ox, &tty_oy, &tty_sx, &tty_sy);
window_copy_scroll(wp, c->tty.mouse_slider_mpos, event->m.y,
args_has(args, 'e'));
tty_oy, args_has(args, 'e'));
return (CMD_RETURN_NORMAL);
}

View File

@@ -59,6 +59,7 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmd_find_state *source = cmdq_get_source(item);
struct client *c = cmdq_get_client(item);
struct client *tc = cmdq_get_target_client(item), *loop;
struct session *s;
enum msgtype msgtype;
@@ -69,6 +70,13 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
if (c->flags & CLIENT_READONLY) {
if (args_has(args, 's') || args_has(args, 'a') || c != tc) {
cmdq_error(item, "client is read-only");
return (CMD_RETURN_ERROR);
}
}
if (args_has(args, 'P'))
msgtype = MSG_DETACHKILL;
else

View File

@@ -370,7 +370,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
flags |= MENU_NOMOUSE;
if (menu_display(menu, flags, starting_choice, item, px, py, tc, lines,
style, selected_style, border_style, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);
goto out;
return (CMD_RETURN_WAIT);
out:

View File

@@ -55,6 +55,27 @@ cmd_display_panes_args_parse(__unused struct args *args, __unused u_int idx,
return (ARGS_PARSE_COMMANDS_OR_STRING);
}
static void
cmd_display_panes_put(struct screen_redraw_ctx *ctx,
struct window_pane *wp, u_int cx, u_int cy, const char *buf, size_t len)
{
struct client *c = ctx->c;
struct tty *tty = &c->tty;
struct visible_ranges *r;
struct visible_range *ri;
u_int i, j;
r = screen_redraw_get_visible_ranges(wp, ctx->ox + cx, ctx->oy + cy,
len, NULL);
for (i = 0; i < r->used; i++) {
ri = &r->ranges[i];
for (j = ri->px; j < ri->px + ri->nx; j++) {
tty_cursor(tty, j - ctx->ox, cy);
tty_putn(tty, &buf[j - ri->px], 1, 1);
}
}
}
static void
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
struct window_pane *wp)
@@ -66,14 +87,15 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
struct window *w = wp->window;
struct grid_cell fgc, bgc;
u_int pane, idx, px, py, i, j, xoff, yoff, sx, sy;
u_int cx, cy;
int colour, active_colour;
char buf[16], lbuf[16], rbuf[16], *ptr;
size_t len, llen, rlen;
if (wp->xoff + wp->sx <= ctx->ox ||
wp->xoff >= ctx->ox + ctx->sx ||
wp->yoff + wp->sy <= ctx->oy ||
wp->yoff >= ctx->oy + ctx->sy)
if (wp->xoff + (int)wp->sx <= ctx->ox ||
wp->xoff >= ctx->ox + (int)ctx->sx ||
wp->yoff + (int)wp->sy <= ctx->oy ||
wp->yoff >= ctx->oy + (int)ctx->sy)
return;
if (wp->xoff >= ctx->ox && wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
@@ -147,13 +169,17 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
if (sx >= len + llen + 1) {
len += llen + 1;
tty_cursor(tty, xoff + px - len / 2, yoff + py);
tty_putn(tty, buf, len, len);
tty_putn(tty, " ", 1, 1);
tty_putn(tty, lbuf, llen, llen);
cx = xoff + px - len / 2;
cy = yoff + py;
cmd_display_panes_put(ctx, wp, cx, cy, buf, len);
cx += len;
cmd_display_panes_put(ctx, wp, cx, cy, " ", 1);
cx++;
cmd_display_panes_put(ctx, wp, cx, cy, lbuf, llen);
} else {
tty_cursor(tty, xoff + px - len / 2, yoff + py);
tty_putn(tty, buf, len, len);
cx = xoff + px - len / 2;
cy = yoff + py;
cmd_display_panes_put(ctx, wp, cx, cy, buf, len);
}
goto out;
}
@@ -169,9 +195,11 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
for (j = 0; j < 5; j++) {
for (i = px; i < px + 5; i++) {
tty_cursor(tty, xoff + i, yoff + py + j);
if (window_clock_table[idx][j][i - px])
tty_putc(tty, ' ');
if (!window_clock_table[idx][j][i - px])
continue;
cx = xoff + i;
cy = yoff + py + j;
cmd_display_panes_put(ctx, wp, cx, cy, " ", 1);
}
}
px += 6;
@@ -181,13 +209,14 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
goto out;
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
if (rlen != 0 && sx >= rlen) {
tty_cursor(tty, xoff + sx - rlen, yoff);
tty_putn(tty, rbuf, rlen, rlen);
cx = xoff + sx - rlen;
cy = yoff;
cmd_display_panes_put(ctx, wp, cx, cy, rbuf, rlen);
}
if (llen != 0) {
tty_cursor(tty, xoff + sx / 2 + len * 3 - llen - 1,
yoff + py + 5);
tty_putn(tty, lbuf, llen, llen);
cx = xoff + sx / 2 + len * 3 - llen - 1;
cy = yoff + py + 5;
cmd_display_panes_put(ctx, wp, cx, cy, lbuf, llen);
}
out:

View File

@@ -71,11 +71,8 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *src_w, *dst_w;
struct window_pane *src_wp, *dst_wp;
char *cause = NULL;
int size, dst_idx;
int flags;
enum layout_type type;
int flags = 0, dst_idx;
struct layout_cell *lc;
u_int curval = 0;
dst_s = target->s;
dst_wl = target->wl;
@@ -94,66 +91,30 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
if (args_has(args, 'l') || args_has(args, 'p')) {
if (args_has(args, 'f')) {
if (type == LAYOUT_TOPBOTTOM)
curval = dst_w->sy;
else
curval = dst_w->sx;
} else {
if (type == LAYOUT_TOPBOTTOM)
curval = dst_wp->sy;
else
curval = dst_wp->sx;
}
}
size = -1;
if (args_has(args, 'l')) {
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
item, &cause);
} else if (args_has(args, 'p')) {
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
&cause);
if (cause == NULL)
size = curval * size / 100;
}
lc = layout_get_tiled_cell(item, args, dst_w, dst_wp, flags, &cause);
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
cmdq_error(item, "size or position %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
flags = 0;
if (args_has(args, 'b'))
flags |= SPAWN_BEFORE;
if (args_has(args, 'f'))
flags |= SPAWN_FULLSIZE;
lc = layout_split_pane(dst_wp, type, size, flags);
if (lc == NULL) {
cmdq_error(item, "create pane failed: pane too small");
return (CMD_RETURN_ERROR);
}
layout_close_pane(src_wp);
server_client_remove_pane(src_wp);
window_lost_pane(src_w, src_wp);
TAILQ_REMOVE(&src_w->panes, src_wp, entry);
TAILQ_REMOVE(&src_w->z_index, src_wp, zentry);
src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options);
src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
if (flags & SPAWN_BEFORE)
if (flags & SPAWN_BEFORE) {
TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry);
else
TAILQ_INSERT_BEFORE(dst_wp, src_wp, zentry);
} else {
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
TAILQ_INSERT_AFTER(&dst_w->z_index, dst_wp, src_wp, zentry);
}
layout_assign_pane(lc, src_wp, 0);
colour_palette_from_option(&src_wp->palette, src_wp->options);
@@ -170,7 +131,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
} else
server_status_session(dst_s);
if (window_count_panes(src_w) == 0)
if (window_count_panes(src_w, 1) == 0)
server_kill_window(src_w, 1);
else
notify_window("window-layout-changed", src_w);

View File

@@ -62,6 +62,10 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
if (wp == NULL) {
cmdq_error(item, "no active pane to kill");
return (CMD_RETURN_ERROR);
}
server_kill_pane(wp);
return (CMD_RETURN_NORMAL);
}

View File

@@ -33,8 +33,8 @@ const struct cmd_entry cmd_kill_session_entry = {
.name = "kill-session",
.alias = NULL,
.args = { "aCt:", 0, 0, NULL },
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
.args = { "aCgt:", 0, 0, NULL },
.usage = "[-aCg] " CMD_TARGET_SESSION_USAGE,
.target = { 't', CMD_FIND_SESSION, 0 },
@@ -48,6 +48,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item);
struct session *s = target->s, *sloop, *stmp;
struct session_group *sg;
struct winlink *wl;
if (args_has(args, 'C')) {
@@ -63,6 +64,12 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
session_destroy(sloop, 1, __func__);
}
}
} else if (args_has(args, 'g') &&
(sg = session_group_contains(s)) != NULL) {
TAILQ_FOREACH_SAFE(sloop, &sg->sessions, gentry, stmp) {
server_destroy_session(sloop);
session_destroy(sloop, 1, __func__);
}
} else {
server_destroy_session(s);
session_destroy(s, 1, __func__);

View File

@@ -35,7 +35,7 @@
"," \
"bind-key #{?key_has_repeat,#{?key_repeat,-r, },} " \
"-T #{p|#{key_table_width}:key_table} " \
"#{p|#{key_string_width}:key_string} " \
"#{p|#{key_string_width}:#{q|a:key_string}} " \
"#{key_command}}"
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
@@ -93,7 +93,7 @@ cmd_list_keys_get_table_width(struct key_binding **l, u_int n)
}
static struct key_binding **
cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
cmd_list_keys_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
{
const char *tables[] = { "prefix", "root" };
struct key_table *t;
@@ -119,7 +119,7 @@ cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
}
static void
cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
cmd_list_keys_filter_key_list(int filter_notes, int filter_key, key_code only,
struct key_binding **l, u_int *n)
{
key_code key;
@@ -137,10 +137,10 @@ cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
}
static void
cmd_format_add_key_binding(struct format_tree *ft,
cmd_list_keys_format_add_key_binding(struct format_tree *ft,
const struct key_binding *bd, const char *prefix)
{
const char *s;
char *s;
if (bd->flags & KEY_BINDING_REPEAT)
format_add(ft, "key_repeat", "1");
@@ -155,12 +155,12 @@ cmd_format_add_key_binding(struct format_tree *ft,
format_add(ft, "key_prefix", "%s", prefix);
format_add(ft, "key_table", "%s", bd->tablename);
s = key_string_lookup_key(bd->key, 0);
format_add(ft, "key_string", "%s", s);
format_add(ft, "key_string", "%s", key_string_lookup_key(bd->key, 0));
s = cmd_list_print(bd->cmdlist,
CMD_LIST_PRINT_ESCAPED|CMD_LIST_PRINT_NO_GROUPS);
s = cmd_list_print(bd->cmdlist, CMD_LIST_PRINT_ESCAPED|
CMD_LIST_PRINT_NO_GROUPS);
format_add(ft, "key_command", "%s", s);
free(s);
}
static enum cmd_retval
@@ -195,10 +195,6 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
}
sort_crit.reversed = args_has(args, 'r');
prefix = cmd_list_keys_get_prefix(args);
single = args_has(args, '1');
notes_only = args_has(args, 'N');
if ((tablename = args_get(args, 'T')) != NULL) {
table = key_bindings_get_table(tablename, 0);
if (table == NULL) {
@@ -207,20 +203,26 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
}
}
prefix = cmd_list_keys_get_prefix(args);
single = args_has(args, '1');
notes_only = args_has(args, 'N');
if ((template = args_get(args, 'F')) == NULL)
template = LIST_KEYS_TEMPLATE;
if (table)
l = sort_get_key_bindings_table(table, &n, &sort_crit);
else if (notes_only)
l = cmd_get_root_and_prefix(&n, &sort_crit);
l = cmd_list_keys_get_root_and_prefix(&n, &sort_crit);
else
l = sort_get_key_bindings(&n, &sort_crit);
filter_notes = notes_only && !args_has(args, 'a');
filter_key = only != KEYC_UNKNOWN;
if (filter_notes || filter_key)
cmd_filter_key_list(filter_notes, filter_key, only, l, &n);
if (filter_notes || filter_key) {
cmd_list_keys_filter_key_list(filter_notes, filter_key, only, l,
&n);
}
if (single)
n = 1;
@@ -232,7 +234,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
format_add(ft, "key_table_width", "%u",
cmd_list_keys_get_table_width(l, n));
for (i = 0; i < n; i++) {
cmd_format_add_key_binding(ft, l[i], prefix);
cmd_list_keys_format_add_key_binding(ft, l[i], prefix);
line = format_expand(ft, template);
if ((single && tc != NULL) || n == 1)

View File

@@ -110,22 +110,28 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
switch (type) {
case 0:
template = "#{pane_index}: "
"[#{pane_width}x#{pane_height}] [history "
"[#{pane_width}x#{pane_height}"
"#{?pane_floating_flag, "
"#{pane_x}#,#{pane_y}#,#{pane_z}}] [history "
"#{history_size}/#{history_limit}, "
"#{history_bytes} bytes] #{pane_id}"
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
break;
case 1:
template = "#{window_index}.#{pane_index}: "
"[#{pane_width}x#{pane_height}] [history "
"[#{pane_width}x#{pane_height}"
"#{?pane_floating_flag, "
"#{pane_x}#,#{pane_y}#,#{pane_z}}] [history "
"#{history_size}/#{history_limit}, "
"#{history_bytes} bytes] #{pane_id}"
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
break;
case 2:
template = "#{session_name}:#{window_index}."
"#{pane_index}: [#{pane_width}x#{pane_height}] "
"[history #{history_size}/#{history_limit}, "
"#{pane_index}: [#{pane_width}x#{pane_height}"
"#{?pane_floating_flag, "
"#{pane_x}#,#{pane_y}#,#{pane_z}}] [history "
"#{history_size}/#{history_limit}, "
"#{history_bytes} bytes] #{pane_id}"
"#{?pane_active, (active),}#{?pane_dead, (dead),}";
break;

View File

@@ -77,8 +77,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
struct termios tio, *tiop;
struct session_group *sg = NULL;
const char *errstr, *template, *group, *tmp;
char *cause, *cwd = NULL, *cp, *newname = NULL;
char *name, *prefix = NULL;
char *cause, *cwd = NULL, *cp, *ename;
char *wname = NULL, *sname = NULL, *prefix = NULL;
int detached, already_attached, is_control = 0;
u_int sx, sy, dsx, dsy, count = args_count(args);
struct spawn_context sc = { 0 };
@@ -99,20 +99,29 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
}
tmp = args_get(args, 's');
if (tmp != NULL) {
name = format_single(item, tmp, c, NULL, NULL, NULL);
newname = session_check_name(name);
if (newname == NULL) {
cmdq_error(item, "invalid session: %s", name);
free(name);
if ((tmp = args_get(args, 'n')) != NULL) {
ename = format_single(item, tmp, c, NULL, NULL, NULL);
if (!check_name(ename)) {
cmdq_error(item, "invalid window name: %s", ename);
free(ename);
return (CMD_RETURN_ERROR);
}
free(name);
wname = clean_name(ename, 0);
free(ename);
}
if ((tmp = args_get(args, 's')) != NULL) {
ename = format_single(item, tmp, c, NULL, NULL, NULL);
if (!check_name(ename)) {
cmdq_error(item, "invalid session name: %s", ename);
free(ename);
goto fail;
}
sname = clean_name(ename, 0);
free(ename);
}
if (args_has(args, 'A')) {
if (newname != NULL)
as = session_find(newname);
if (sname != NULL)
as = session_find(sname);
else
as = target->s;
if (as != NULL) {
@@ -120,12 +129,13 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
args_has(args, 'D'), args_has(args, 'X'), 0,
args_get(args, 'c'), args_has(args, 'E'),
args_get(args, 'f'));
free(newname);
free(wname);
free(sname);
return (retval);
}
}
if (newname != NULL && session_find(newname) != NULL) {
cmdq_error(item, "duplicate session: %s", newname);
if (sname != NULL && session_find(sname) != NULL) {
cmdq_error(item, "duplicate session: %s", sname);
goto fail;
}
@@ -142,12 +152,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
else if (groupwith != NULL)
prefix = xstrdup(groupwith->name);
else {
prefix = session_check_name(group);
if (prefix == NULL) {
cmdq_error(item, "invalid session group: %s",
group);
if (!check_name(group)) {
cmdq_error(item,
"invalid session group name: %s", group);
goto fail;
}
prefix = clean_name(group, 0);
}
}
@@ -276,7 +286,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
environ_put(env, av->string, 0);
av = args_next_value(av);
}
s = session_create(prefix, newname, cwd, env, oo, tiop);
s = session_create(prefix, sname, cwd, env, oo, tiop);
/* Spawn the initial window. */
sc.item = item;
@@ -284,7 +294,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
if (!detached)
sc.tc = c;
sc.name = args_get(args, 'n');
sc.name = wname;
args_to_vector(args, &sc.argc, &sc.argv);
sc.idx = -1;
@@ -357,7 +367,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
if (sc.argv != NULL)
cmd_free_argv(sc.argc, sc.argv);
free(cwd);
free(newname);
free(wname);
free(sname);
free(prefix);
return (CMD_RETURN_NORMAL);
@@ -365,7 +376,8 @@ fail:
if (sc.argv != NULL)
cmd_free_argv(sc.argc, sc.argv);
free(cwd);
free(newname);
free(wname);
free(sname);
free(prefix);
return (CMD_RETURN_ERROR);
}

View File

@@ -61,7 +61,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = target->s;
struct winlink *wl = target->wl, *new_wl = NULL;
int idx = target->idx, before;
char *cause = NULL, *cp, *expanded;
char *cause = NULL, *cp, *expanded, *wname = NULL;
const char *template, *name;
struct cmd_find_state fs;
struct args_value *av;
@@ -71,8 +71,18 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
* name already exists, select it.
*/
name = args_get(args, 'n');
if (args_has(args, 'S') && name != NULL && target->idx == -1) {
if (name != NULL) {
expanded = format_single(item, name, c, s, NULL, NULL);
if (!check_name(expanded)) {
cmdq_error(item, "invalid window name: %s", expanded);
free(expanded);
return (CMD_RETURN_ERROR);
}
wname = clean_name(expanded, 0);
free(expanded);
}
if (args_has(args, 'S') && wname != NULL && target->idx == -1) {
expanded = format_single(item, wname, c, s, NULL, NULL);
RB_FOREACH(wl, winlinks, &s->windows) {
if (strcmp(wl->window->name, expanded) != 0)
continue;
@@ -80,12 +90,14 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
new_wl = wl;
continue;
}
cmdq_error(item, "multiple windows named %s", name);
cmdq_error(item, "multiple windows named %s", wname);
free(wname);
free(expanded);
return (CMD_RETURN_ERROR);
}
free(expanded);
if (new_wl != NULL) {
free(wname);
if (args_has(args, 'd'))
return (CMD_RETURN_NORMAL);
if (session_set_current(s, new_wl) == 0)
@@ -108,7 +120,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
sc.s = s;
sc.tc = tc;
sc.name = args_get(args, 'n');
sc.name = wname;
args_to_vector(args, &sc.argc, &sc.argv);
sc.environ = environ_create();
@@ -130,10 +142,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
cmdq_error(item, "create window failed: %s", cause);
free(cause);
if (sc.argv != NULL)
cmd_free_argv(sc.argc, sc.argv);
environ_free(sc.environ);
return (CMD_RETURN_ERROR);
goto fail;
}
if (!args_has(args, 'd') || new_wl == s->curw) {
cmd_find_from_winlink(current, new_wl, 0);
@@ -156,5 +165,13 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
if (sc.argv != NULL)
cmd_free_argv(sc.argc, sc.argv);
environ_free(sc.environ);
free(wname);
return (CMD_RETURN_NORMAL);
fail:
if (sc.argv != NULL)
cmd_free_argv(sc.argc, sc.argv);
environ_free(sc.environ);
free(wname);
return (CMD_RETURN_ERROR);
}

View File

@@ -37,6 +37,8 @@ static void printflike(1,2) yyerror(const char *, ...);
static char *yylex_token(int);
static char *yylex_format(void);
#define CMD_PARSE_MAX_ENVIRON_LEN 16384
struct cmd_parse_scope {
int flag;
TAILQ_ENTRY (cmd_parse_scope) entry;
@@ -232,6 +234,10 @@ assignment : EQUALS
flag = flag && scope->flag;
}
if (strlen($1) > CMD_PARSE_MAX_ENVIRON_LEN) {
yyerror("environment variable is too long");
YYABORT;
}
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
environ_put(global_environ, $1, 0);
free($1);
@@ -250,6 +256,10 @@ hidden_assignment : HIDDEN EQUALS
flag = flag && scope->flag;
}
if (strlen($2) > CMD_PARSE_MAX_ENVIRON_LEN) {
yyerror("environment variable is too long");
YYABORT;
}
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
environ_put(global_environ, $2, ENVIRON_HIDDEN);
free($2);
@@ -1604,7 +1614,9 @@ yylex_token_tilde(char **buf, size_t *len)
if (*name == '\0') {
envent = environ_find(global_environ, "HOME");
if (envent != NULL && *envent->value != '\0')
if (envent != NULL &&
envent->value != NULL &&
*envent->value != '\0')
home = envent->value;
else if ((pw = getpwuid(getuid())) != NULL)
home = pw->pw_dir;

View File

@@ -128,6 +128,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
sigprocmask(SIG_SETMASK, &oldset, NULL);
cmdq_error(item, "fork error: %s", strerror(errno));
close(pipe_fd[0]);
close(pipe_fd[1]);
free(cmd);
return (CMD_RETURN_ERROR);
case 0:

View File

@@ -52,12 +52,12 @@ cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
char *newname, *tmp;
tmp = format_single_from_target(item, args_string(args, 0));
newname = session_check_name(tmp);
if (newname == NULL) {
cmdq_error(item, "invalid session: %s", tmp);
if (!check_name(tmp)) {
cmdq_error(item, "invalid session name: %s", tmp);
free(tmp);
return (CMD_RETURN_ERROR);
}
newname = clean_name(tmp, 0);
free(tmp);
if (strcmp(newname, s->name) == 0) {
free(newname);

View File

@@ -48,15 +48,21 @@ cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item);
struct winlink *wl = target->wl;
char *newname;
char *name;
newname = format_single_from_target(item, args_string(args, 0));
window_set_name(wl->window, newname);
name = format_single_from_target(item, args_string(args, 0));
if (!check_name(name)) {
cmdq_error(item, "invalid window name: %s", name);
free(name);
return (CMD_RETURN_ERROR);
}
window_set_name(wl->window, name, 0);
options_set_number(wl->window->options, "automatic-rename", 0);
free(name);
server_redraw_window_borders(wl->window);
server_status_window(wl->window);
free(newname);
return (CMD_RETURN_NORMAL);
}

View File

@@ -29,8 +29,12 @@
static enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmdq_item *);
static void cmd_resize_pane_mouse_update(struct client *,
struct mouse_event *);
static enum cmd_retval cmd_resize_pane_mouse_update(struct cmd *,
struct cmdq_item *);
static void cmd_resize_pane_mouse_update_floating(struct client *,
struct mouse_event *);
static void cmd_resize_pane_mouse_update_tiled(struct client *,
struct mouse_event *);
const struct cmd_entry cmd_resize_pane_entry = {
.name = "resize-pane",
@@ -51,13 +55,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item);
struct key_event *event = cmdq_get_event(item);
struct window_pane *wp = target->wp;
struct winlink *wl = target->wl;
struct window *w = wl->window;
struct client *c = cmdq_get_client(item);
struct session *s = target->s;
const char *errstr;
const char *errstr;
char *cause;
u_int adjust;
int x, y, status;
@@ -75,15 +76,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'M')) {
if (!event->m.valid || cmd_mouse_window(&event->m, &s) == NULL)
return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL);
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
cmd_resize_pane_mouse_update(c, &event->m);
return (CMD_RETURN_NORMAL);
}
if (args_has(args, 'M'))
return (cmd_resize_pane_mouse_update(self, item));
if (args_has(args, 'Z')) {
if (w->flags & WINDOW_ZOOMED)
@@ -148,13 +142,168 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_NORMAL);
}
static enum cmd_retval
cmd_resize_pane_mouse_update(__unused struct cmd *self, struct cmdq_item *item)
{
struct cmd_find_state *target = cmdq_get_target(item);
struct key_event *event = cmdq_get_event(item);
struct window_pane *wp = target->wp;
struct winlink *wl = target->wl;
struct window *w = wl->window;
struct client *c = cmdq_get_client(item);
struct session *s = target->s;
if (!event->m.valid)
return (CMD_RETURN_NORMAL);
wp = cmd_mouse_pane(&event->m, &s, NULL);
if (wp == NULL || c == NULL || c->session != s)
return (CMD_RETURN_NORMAL);
if (!window_pane_is_floating(wp)) {
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update_tiled;
cmd_resize_pane_mouse_update_tiled(c, &event->m);
return (CMD_RETURN_NORMAL);
}
window_redraw_active_switch(w, wp);
window_set_active_pane(w, wp, 1);
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update_floating;
cmd_resize_pane_mouse_update_floating(c, &event->m);
return (CMD_RETURN_NORMAL);
}
static void
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
cmd_resize_pane_mouse_update_floating(struct client *c, struct mouse_event *m)
{
struct winlink *wl;
struct window *w;
struct window_pane *wp;
struct layout_cell *lc;
int y, ly, x, lx, sx, sy, new_sx, new_sy;
int left, right;
int new_xoff, new_yoff, resizes = 0;
wp = cmd_mouse_pane(m, NULL, &wl);
if (wp == NULL) {
c->tty.mouse_drag_update = NULL;
return;
}
w = wl->window;
lc = wp->layout_cell;
sx = wp->sx;
sy = wp->sy;
left = wp->xoff - 1;
right = wp->xoff + sx;
if (window_pane_show_scrollbar(wp) &&
w->sb_pos == PANE_SCROLLBARS_LEFT) {
left -= wp->scrollbar_style.width + wp->scrollbar_style.pad;
} else if (window_pane_show_scrollbar(wp) &&
w->sb_pos == PANE_SCROLLBARS_RIGHT) {
right += wp->scrollbar_style.width + wp->scrollbar_style.pad;
}
y = m->y + m->oy; x = m->x + m->ox;
if (m->statusat == 0 && y >= (int)m->statuslines)
y -= m->statuslines;
else if (m->statusat > 0 && y >= m->statusat)
y = m->statusat - 1;
ly = m->ly + m->oy; lx = m->lx + m->ox;
if (m->statusat == 0 && ly >= (int)m->statuslines)
ly -= m->statuslines;
else if (m->statusat > 0 && ly >= m->statusat)
ly = m->statusat - 1;
if ((lx == left || lx == left + 1) && ly == wp->yoff - 1) {
/* Top left corner. */
new_sx = lc->sx + (lx - x);
if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM;
new_sy = lc->sy + (ly - y);
if (new_sy < PANE_MINIMUM)
new_sy = PANE_MINIMUM;
new_xoff = x + 1; /* because mouse is on border at xoff - 1 */
new_yoff = y + 1;
layout_set_size(lc, new_sx, new_sy, new_xoff, new_yoff);
resizes++;
} else if ((lx == right + 1 || lx == right) &&
ly == wp->yoff - 1) {
/* Top right corner. */
new_sx = x - lc->xoff;
if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM;
new_sy = lc->sy + (ly - y);
if (new_sy < PANE_MINIMUM)
new_sy = PANE_MINIMUM;
new_yoff = y + 1;
layout_set_size(lc, new_sx, new_sy, lc->xoff, new_yoff);
resizes++;
} else if ((lx == left || lx == left + 1) &&
ly == wp->yoff + sy) {
/* Bottom left corner. */
new_sx = lc->sx + (lx - x);
if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM;
new_sy = y - lc->yoff;
if (new_sy < PANE_MINIMUM)
return;
new_xoff = x + 1;
layout_set_size(lc, new_sx, new_sy, new_xoff, lc->yoff);
resizes++;
} else if ((lx == right + 1 || lx == right) &&
ly == wp->yoff + sy) {
/* Bottom right corner. */
new_sx = x - lc->xoff;
if (new_sx < PANE_MINIMUM)
new_sx = PANE_MINIMUM;
new_sy = y - lc->yoff;
if (new_sy < PANE_MINIMUM)
new_sy = PANE_MINIMUM;
layout_set_size(lc, new_sx, new_sy, lc->xoff, lc->yoff);
resizes++;
} else if (lx == right) {
/* Right border. */
new_sx = x - lc->xoff;
if (new_sx < PANE_MINIMUM)
return;
layout_set_size(lc, new_sx, lc->sy, lc->xoff, lc->yoff);
resizes++;
} else if (lx == left) {
/* Left border. */
new_sx = lc->sx + (lx - x);
if (new_sx < PANE_MINIMUM)
return;
new_xoff = x + 1;
layout_set_size(lc, new_sx, lc->sy, new_xoff, lc->yoff);
resizes++;
} else if (ly == wp->yoff + sy) {
/* Bottom border. */
new_sy = y - lc->yoff;
if (new_sy < PANE_MINIMUM)
return;
layout_set_size(lc, lc->sx, new_sy, lc->xoff, lc->yoff);
resizes++;
} else if (ly == wp->yoff - 1) {
/* Top border (move instead of resize). */
new_xoff = lc->xoff + (x - lx);
new_yoff = y + 1;
layout_set_size(lc, lc->sx, lc->sy, new_xoff, new_yoff);
resizes++;
}
if (resizes != 0) {
layout_fix_panes(w, NULL);
server_redraw_window(w);
server_redraw_window_borders(w);
}
}
static void
cmd_resize_pane_mouse_update_tiled(struct client *c, struct mouse_event *m)
{
struct winlink *wl;
struct window *w;
u_int y, ly, x, lx;
static const int offsets[][2] = {
static const int offsets[][2] = {
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
};
struct layout_cell *cells[nitems(offsets)], *lc;

View File

@@ -44,9 +44,9 @@ const struct cmd_entry cmd_run_shell_entry = {
.name = "run-shell",
.alias = "run",
.args = { "bd:Ct:Es:c:", 0, 1, cmd_run_shell_args_parse },
.args = { "bd:Ct:Es:c:", 0, -1, cmd_run_shell_args_parse },
.usage = "[-bCE] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
" [shell-command]",
" [shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
@@ -115,9 +115,11 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = target->s;
struct window_pane *wp = target->wp;
const char *delay, *cmd;
struct format_tree *ft;
double d;
struct timeval tv;
char *end;
char *end, key[16];
u_int i;
int wait = !args_has(args, 'b');
if ((delay = args_get(args, 'd')) != NULL) {
@@ -132,8 +134,15 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
cdata = xcalloc(1, sizeof *cdata);
if (!args_has(args, 'C')) {
cmd = args_string(args, 0);
if (cmd != NULL)
cdata->cmd = format_single_from_target(item, cmd);
if (cmd != NULL) {
ft = format_create_from_target(item);
for (i = 1; i < args_count(args); i++) {
xsnprintf(key, sizeof key, "%u", i);
format_add(ft, key, "%s", args_string(args, i));
}
cdata->cmd = format_expand(ft, cmd);
format_free(ft);
}
} else {
cdata->state = args_make_commands_prepare(self, item, 0, NULL,
wait, 1);
@@ -198,8 +207,17 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
}
if (job_run(cmd, 0, NULL, NULL, cdata->s, cdata->cwd, NULL,
cmd_run_shell_callback, cmd_run_shell_free, cdata,
cdata->flags, -1, -1) == NULL)
cdata->flags, -1, -1) == NULL) {
if (cdata->item == NULL)
status_message_set(c, -1, 1, 0, 0,
"failed to run command: %s", cmd);
else {
cmdq_error(cdata->item,
"failed to run command: %s", cmd);
cmdq_continue(cdata->item);
}
cmd_run_shell_free(cdata);
}
return;
}

View File

@@ -90,7 +90,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
previous = 1;
oldlayout = w->old_layout;
w->old_layout = layout_dump(w->layout_root);
w->old_layout = layout_dump(w, w->layout_root);
if (next || previous) {
if (next)

View File

@@ -103,7 +103,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
* spawned without being visited (for example split-window -d).
*/
lastwp = TAILQ_FIRST(&w->last_panes);
if (lastwp == NULL && window_count_panes(w) == 2) {
if (lastwp == NULL && window_count_panes(w, 1) == 2) {
lastwp = TAILQ_PREV(w->active, window_panes, entry);
if (lastwp == NULL)
lastwp = TAILQ_NEXT(w->active, entry);
@@ -160,6 +160,10 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
server_redraw_window_borders(markedwp->window);
server_status_window(markedwp->window);
}
if (window_pane_is_floating(wp)) {
window_redraw_active_switch(w, wp);
window_set_active_pane(w, wp, 1);
}
return (CMD_RETURN_NORMAL);
}
@@ -213,7 +217,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
if (args_has(args, 'T')) {
title = format_single_from_target(item, args_get(args, 'T'));
if (screen_set_title(&wp->base, title)) {
if (screen_set_title(&wp->base, title, 0)) {
notify_pane("pane-title-changed", wp);
server_redraw_window_borders(wp->window);
server_status_window(wp->window);

View File

@@ -27,22 +27,41 @@
#include "tmux.h"
/*
* Split a window (add a new pane).
* Create a new pane.
*/
#define SPLIT_WINDOW_TEMPLATE "#{session_name}:#{window_index}.#{pane_index}"
static enum cmd_retval cmd_split_window_exec(struct cmd *,
struct cmdq_item *);
static enum cmd_retval cmd_split_window_exec(struct cmd *, struct cmdq_item *);
const struct cmd_entry cmd_new_pane_entry = {
.name = "new-pane",
.alias = "newp",
.args = { "bc:de:EfF:hIkl:Lm:p:PR:s:S:t:vx:X:y:Y:Z", 0, -1, NULL },
.usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] [-m message] [-p percentage] "
"[-s style] [-S active-border-style] "
"[-R inactive-border-style] [-x width] [-y height] "
"[-X x-position] [-Y y-position] " CMD_TARGET_PANE_USAGE " "
"[shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 },
.flags = 0,
.exec = cmd_split_window_exec
};
const struct cmd_entry cmd_split_window_entry = {
.name = "split-window",
.alias = "splitw",
.args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1, NULL },
.usage = "[-bdefhIPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] " CMD_TARGET_PANE_USAGE
" [shell-command [argument ...]]",
.args = { "bc:de:EfF:hIkl:m:p:PR:s:S:t:vZ", 0, -1, NULL },
.usage = "[-bdefhIklPvZ] [-c start-directory] [-e environment] "
"[-F format] [-l size] [-m message] [-p percentage] "
"[-s style] [-S active-border-style] "
"[-R inactive-border-style] " CMD_TARGET_PANE_USAGE " "
"[shell-command [argument ...]]",
.target = { 't', CMD_FIND_PANE, 0 },
@@ -62,64 +81,46 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
struct winlink *wl = target->wl;
struct window *w = wl->window;
struct window_pane *wp = target->wp, *new_wp;
enum layout_type type;
struct layout_cell *lc;
struct layout_cell *lc = NULL;
struct cmd_find_state fs;
int size, flags, input;
const char *template;
int input, empty, is_floating, flags = 0;
const char *template, *style;
char *cause = NULL, *cp;
struct args_value *av;
u_int count = args_count(args), curval = 0;
u_int count = args_count(args);
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
if (cmd_get_entry(self) == &cmd_new_pane_entry)
is_floating = !args_has(args, 'L');
else
is_floating = 0;
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
if (args_has(args, 'l') || args_has(args, 'p')) {
if (args_has(args, 'f')) {
if (type == LAYOUT_TOPBOTTOM)
curval = w->sy;
else
curval = w->sx;
} else {
if (type == LAYOUT_TOPBOTTOM)
curval = wp->sy;
else
curval = wp->sx;
}
}
size = -1;
if (args_has(args, 'l')) {
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
item, &cause);
} else if (args_has(args, 'p')) {
size = args_strtonum_and_expand(args, 'p', 0, 100, item,
&cause);
if (cause == NULL)
size = curval * size / 100;
}
if (cause != NULL) {
cmdq_error(item, "size %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
input = (args_has(args, 'I') && count == 0);
flags = 0;
flags = is_floating ? SPAWN_FLOATING : 0;
if (args_has(args, 'b'))
flags |= SPAWN_BEFORE;
if (args_has(args, 'f'))
flags |= SPAWN_FULLSIZE;
input = args_has(args, 'I');
if (input || (count == 1 && *args_string(args, 0) == '\0'))
empty = 1;
else
empty = args_has(args, 'E');
if (empty &&
count != 0 &&
(count != 1 || *args_string(args, 0) != '\0')) {
cmdq_error(item, "command cannot be given for empty pane");
return (CMD_RETURN_ERROR);
}
if (empty)
flags |= SPAWN_EMPTY;
lc = layout_split_pane(wp, type, size, flags);
if (lc == NULL) {
cmdq_error(item, "no space for new pane");
if (is_floating)
lc = layout_get_floating_cell(item, args, w, wp, &cause);
else
lc = layout_get_tiled_cell(item, args, w, wp, flags, &cause);
if (cause != NULL) {
cmdq_error(item, "size or position %s", cause);
free(cause);
return (CMD_RETURN_ERROR);
}
@@ -156,11 +157,51 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
environ_free(sc.environ);
return (CMD_RETURN_ERROR);
}
style = args_get(args, 's');
if (style != NULL) {
if (options_set_string(new_wp->options, "window-style", 0,
"%s", style) == NULL) {
cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR);
}
options_set_string(new_wp->options, "window-active-style", 0,
"%s", style);
new_wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|
PANE_THEMECHANGED);
}
style = args_get(args, 'S');
if (style != NULL) {
if (options_set_string(new_wp->options,
"pane-active-border-style", 0, "%s", style) == NULL) {
cmdq_error(item, "bad active border style: %s", style);
return (CMD_RETURN_ERROR);
}
}
style = args_get(args, 'R');
if (style != NULL) {
if (options_set_string(new_wp->options, "pane-border-style", 0,
"%s", style) == NULL) {
cmdq_error(item, "bad inactive border style: %s",
style);
return (CMD_RETURN_ERROR);
}
}
if (args_has(args, 'k') || args_has(args, 'm')) {
options_set_number(new_wp->options, "remain-on-exit", 3);
if (args_has(args, 'm')) {
options_set_string(new_wp->options,
"remain-on-exit-format", 0, "%s",
args_get(args, 'm'));
}
}
if (input) {
switch (window_pane_start_input(new_wp, item, &cause)) {
case -1:
server_client_remove_pane(new_wp);
layout_close_pane(new_wp);
if (!is_floating)
layout_close_pane(new_wp);
window_remove_pane(wp->window, new_wp);
cmdq_error(item, "%s", cause);
free(cause);
@@ -175,9 +216,12 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
}
if (!args_has(args, 'd'))
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
window_pop_zoom(wp->window);
server_redraw_window(wp->window);
server_status_session(s);
if (!is_floating) {
window_pop_zoom(wp->window);
server_redraw_window(wp->window);
}
server_redraw_session(s);
if (args_has(args, 'P')) {
if ((template = args_get(args, 'F')) == NULL)

View File

@@ -79,6 +79,12 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
if (src_wp == dst_wp)
goto out;
if (window_pane_is_floating(src_wp) ||
window_pane_is_floating(dst_wp)) {
cmdq_error(item, "cannot swap floating panes");
return (CMD_RETURN_ERROR);
}
server_client_remove_pane(src_wp);
server_client_remove_pane(dst_wp);
@@ -92,12 +98,26 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
else
TAILQ_INSERT_AFTER(&dst_w->panes, tmp_wp, src_wp, entry);
tmp_wp = TAILQ_PREV(dst_wp, window_panes, zentry);
TAILQ_REMOVE(&dst_w->z_index, dst_wp, zentry);
TAILQ_REPLACE(&src_w->z_index, src_wp, dst_wp, zentry);
if (tmp_wp == src_wp)
tmp_wp = dst_wp;
if (tmp_wp == NULL)
TAILQ_INSERT_HEAD(&dst_w->z_index, src_wp, zentry);
else
TAILQ_INSERT_AFTER(&dst_w->z_index, tmp_wp, src_wp, zentry);
src_lc = src_wp->layout_cell;
dst_lc = dst_wp->layout_cell;
src_lc->wp = dst_wp;
dst_wp->layout_cell = src_lc;
dst_lc->wp = src_wp;
src_wp->layout_cell = dst_lc;
if (window_pane_is_floating(src_wp) != window_pane_is_floating(dst_wp)) {
src_wp->layout_cell->flags ^= LAYOUT_CELL_FLOATING;
dst_wp->layout_cell->flags ^= LAYOUT_CELL_FLOATING;
}
src_wp->window = dst_w;
options_set_parent(src_wp->options, dst_w->options);

View File

@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tmux.h"
@@ -53,6 +54,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
const char *tflag = args_get(args, 't');
enum cmd_find_type type;
int flags;
struct client *c = cmdq_get_client(item);
struct client *tc = cmdq_get_target_client(item);
struct session *s;
struct winlink *wl;
@@ -61,6 +63,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
const char *tablename;
struct key_table *table;
struct sort_criteria sort_crit;
uid_t uid;
if (tflag != NULL &&
(tflag[strcspn(tflag, ":.%")] != '\0' || strcmp(tflag, "=") == 0)) {
@@ -77,6 +80,13 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
wp = target.wp;
if (args_has(args, 'r')) {
if (tc->flags & CLIENT_READONLY) {
uid = proc_get_peer_uid(c->peer);
if (uid != getuid()) {
cmdq_error(item, "client is read-only");
return (CMD_RETURN_ERROR);
}
}
if (tc->flags & CLIENT_READONLY)
tc->flags &= ~(CLIENT_READONLY|CLIENT_IGNORESIZE);
else

8
cmd.c
View File

@@ -71,6 +71,7 @@ extern const struct cmd_entry cmd_lock_server_entry;
extern const struct cmd_entry cmd_lock_session_entry;
extern const struct cmd_entry cmd_move_pane_entry;
extern const struct cmd_entry cmd_move_window_entry;
extern const struct cmd_entry cmd_new_pane_entry;
extern const struct cmd_entry cmd_new_session_entry;
extern const struct cmd_entry cmd_new_window_entry;
extern const struct cmd_entry cmd_next_layout_entry;
@@ -163,6 +164,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_lock_session_entry,
&cmd_move_pane_entry,
&cmd_move_window_entry,
&cmd_new_pane_entry,
&cmd_new_session_entry,
&cmd_new_window_entry,
&cmd_next_layout_entry,
@@ -303,6 +305,8 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
if (argc == 0)
return (0);
if (argc < 0 || argc > 1000)
return (-1);
*argv = xcalloc(argc, sizeof **argv);
buf[len - 1] = '\0';
@@ -772,9 +776,9 @@ cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
if (m->statusat == 0 && y >= m->statuslines)
y -= m->statuslines;
if (x < wp->xoff || x >= wp->xoff + wp->sx)
if ((int)x < wp->xoff || (int)x >= wp->xoff + (int)wp->sx)
return (-1);
if (y < wp->yoff || y >= wp->yoff + wp->sy)
if ((int)y < wp->yoff || (int)y >= wp->yoff + (int)wp->sy)
return (-1);
if (xp != NULL)

View File

@@ -463,6 +463,9 @@ int utf8proc_wctomb(char *, wchar_t);
#ifdef NEED_FUZZING
/* tmux.c */
#define main __weak main
#define regcomp(preg, pattern, cflags) (0)
#define regexec(preg, string, nmatch, pmatch, eflags) (REG_NOMATCH)
#define regfree(preg) ((void)0)
#endif
/* getopt.c */

View File

@@ -81,7 +81,8 @@ struct systemd_job_watch {
};
static int
job_removed_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
job_removed_handler(sd_bus_message *m, void *userdata,
__unused sd_bus_error *ret_error)
{
struct systemd_job_watch *watch = userdata;
const char *path = NULL;
@@ -109,7 +110,7 @@ systemd_move_to_new_cgroup(char **cause)
sd_bus_message *m = NULL, *reply = NULL;
sd_bus *bus = NULL;
sd_bus_slot *slot = NULL;
char *name, *desc, *slice;
char *name, *desc, *slice, *unit;
sd_id128_t uuid;
int r;
uint64_t elapsed_usec;
@@ -241,6 +242,26 @@ systemd_move_to_new_cgroup(char **cause)
goto finish;
}
/*
* Try locating systemd unit that started the server, and mark pane units
* as dependent on it. Use "Before" to make sure systemd will not try to
* kill them first.
*/
if (sd_pid_get_user_unit(parent_pid, &unit) == 0 ||
sd_pid_get_unit(parent_pid, &unit) == 0) {
r = sd_bus_message_append(m, "(sv)", "Before", "as", 1, unit);
if (r >= 0) {
r = sd_bus_message_append(m, "(sv)", "PartOf", "as", 1,
unit);
}
free(unit);
if (r < 0) {
xasprintf(cause, "failed to append to properties: %s",
strerror(-r));
goto finish;
}
}
/* End properties array. */
r = sd_bus_message_close_container(m);
if (r < 0) {

View File

@@ -1,6 +1,6 @@
# configure.ac
AC_INIT([tmux], next-3.7)
AC_INIT([tmux], 3.7c)
AC_PREREQ([2.60])
AC_CONFIG_AUX_DIR(etc)
@@ -73,6 +73,13 @@ AC_ARG_ENABLE(
)
AM_CONDITIONAL(IS_OPTIMIZED, test "x$enable_optimizations" = xyes)
# Is this --enable-asan?
AC_ARG_ENABLE(
asan,
AS_HELP_STRING(--enable-asan, enable ASAN build flags)
)
AM_CONDITIONAL(IS_ASAN, test "x$enable_asan" = xyes)
# Is this a static build?
AC_ARG_ENABLE(
static,
@@ -232,6 +239,7 @@ AC_LIBOBJ(getopt_long)
# Look for libevent. Try libevent_core or libevent with pkg-config first then
# look for the library.
libevent_version=off
PKG_CHECK_MODULES(
LIBEVENT_CORE,
[libevent_core >= 2],
@@ -240,6 +248,8 @@ PKG_CHECK_MODULES(
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBEVENT_CORE_LIBS $LIBS"
found_libevent=yes
libevent_version=`$PKG_CONFIG --modversion libevent_core 2>/dev/null`
test "x$libevent_version" = x && libevent_version=on
],
found_libevent=no
)
@@ -252,6 +262,8 @@ if test x$found_libevent = xno; then
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBEVENT_LIBS $LIBS"
found_libevent=yes
libevent_version=`$PKG_CONFIG --modversion libevent 2>/dev/null`
test "x$libevent_version" = x && libevent_version=on
],
found_libevent=no
)
@@ -260,7 +272,8 @@ if test x$found_libevent = xno; then
AC_SEARCH_LIBS(
event_init,
[event_core event event-1.4],
found_libevent=yes,
[found_libevent=yes
libevent_version=on],
found_libevent=no
)
fi
@@ -287,26 +300,31 @@ fi
# Look for ncurses or curses. Try pkg-config first then directly for the
# library.
ncurses_version=off
PKG_CHECK_MODULES(
LIBTINFO,
tinfo,
LIBTINFOW,
tinfow,
[
AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBTINFO_LIBS $LIBS"
AM_CPPFLAGS="$LIBTINFOW_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBTINFOW_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBTINFOW_LIBS $LIBS"
found_ncurses=yes
ncurses_version=`$PKG_CONFIG --modversion tinfow 2>/dev/null`
test "x$ncurses_version" = x && ncurses_version=on
],
found_ncurses=no
)
if test "x$found_ncurses" = xno; then
PKG_CHECK_MODULES(
LIBNCURSES,
ncurses,
LIBTINFO,
tinfo,
[
AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBNCURSES_LIBS $LIBS"
AM_CPPFLAGS="$LIBTINFO_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBTINFO_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBTINFO_LIBS $LIBS"
found_ncurses=yes
ncurses_version=`$PKG_CONFIG --modversion tinfo 2>/dev/null`
test "x$ncurses_version" = x && ncurses_version=on
],
found_ncurses=no
)
@@ -320,6 +338,23 @@ if test "x$found_ncurses" = xno; then
CPPFLAGS="$LIBNCURSESW_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBNCURSESW_LIBS $LIBS"
found_ncurses=yes
ncurses_version=`$PKG_CONFIG --modversion ncursesw 2>/dev/null`
test "x$ncurses_version" = x && ncurses_version=on
],
found_ncurses=no
)
fi
if test "x$found_ncurses" = xno; then
PKG_CHECK_MODULES(
LIBNCURSES,
ncurses,
[
AM_CPPFLAGS="$LIBNCURSES_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBNCURSES_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBNCURSES_LIBS $LIBS"
found_ncurses=yes
ncurses_version=`$PKG_CONFIG --modversion ncurses 2>/dev/null`
test "x$ncurses_version" = x && ncurses_version=on
],
found_ncurses=no
)
@@ -327,8 +362,9 @@ fi
if test "x$found_ncurses" = xno; then
AC_SEARCH_LIBS(
setupterm,
[tinfo terminfo ncurses ncursesw],
found_ncurses=yes,
[tinfow tinfo terminfo ncursesw ncurses],
[found_ncurses=yes
ncurses_version=on],
found_ncurses=no
)
if test "x$found_ncurses" = xyes; then
@@ -358,6 +394,7 @@ else
LIBS="$LIBS -lcurses"
CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
AC_DEFINE(HAVE_CURSES_H)
ncurses_version=on
else
AC_MSG_ERROR("curses not found")
fi
@@ -368,6 +405,7 @@ AC_CHECK_FUNCS([ \
])
# Look for utempter.
utempter_version=off
AC_ARG_ENABLE(
utempter,
AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
@@ -384,17 +422,34 @@ if test "x$enable_utempter" = xyes; then
fi
if test "x$enable_utempter" = xyes; then
AC_DEFINE(HAVE_UTEMPTER)
utempter_version=on
else
AC_MSG_ERROR("utempter not found")
fi
fi
# Look for utf8proc.
utf8proc_version=off
AC_ARG_ENABLE(
utf8proc,
AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
)
try_utf8proc=no
require_utf8proc=no
if test "x$enable_utf8proc" = xyes; then
try_utf8proc=yes
elif test "x$enable_utf8proc" = x; then
case "$host_os" in
*darwin*)
try_utf8proc=yes
require_utf8proc=yes
;;
esac
fi
if test "x$try_utf8proc" = xyes; then
SAVED_AM_CPPFLAGS="$AM_CPPFLAGS"
SAVED_OLD_CPPFLAGS="$CPPFLAGS"
SAVED_LIBS="$LIBS"
PKG_CHECK_MODULES(
LIBUTF8PROC,
libutf8proc,
@@ -402,7 +457,10 @@ if test "x$enable_utf8proc" = xyes; then
AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBUTF8PROC_LIBS $LIBS"
]
utf8proc_version=`$PKG_CONFIG --modversion libutf8proc 2>/dev/null`
test "x$utf8proc_version" = x && utf8proc_version=on
],
[:]
)
AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
if test "x$enable_utf8proc" = xyes; then
@@ -415,13 +473,23 @@ if test "x$enable_utf8proc" = xyes; then
fi
if test "x$enable_utf8proc" = xyes; then
AC_DEFINE(HAVE_UTF8PROC)
test "x$utf8proc_version" = xoff && utf8proc_version=on
else
AC_MSG_ERROR("utf8proc not found")
AM_CPPFLAGS="$SAVED_AM_CPPFLAGS"
CPPFLAGS="$SAVED_OLD_CPPFLAGS"
LIBS="$SAVED_LIBS"
utf8proc_version=off
if test "x$require_utf8proc" = xyes; then
enable_utf8proc=
else
AC_MSG_ERROR("utf8proc not found")
fi
fi
fi
AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
# Check for systemd support.
systemd_version=off
AC_ARG_ENABLE(
systemd,
AS_HELP_STRING(--enable-systemd, enable systemd integration)
@@ -435,6 +503,8 @@ if test x"$enable_systemd" = xyes; then
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
LIBS="$SYSTEMD_LIBS $LIBS"
found_systemd=yes
systemd_version=`$PKG_CONFIG --modversion libsystemd 2>/dev/null`
test "x$systemd_version" = x && systemd_version=on
],
found_systemd=no
)
@@ -462,33 +532,14 @@ if test "x$enable_cgroups" = xyes; then
fi
# Enable sixel support.
AC_ARG_ENABLE(
sixel-images,
AS_HELP_STRING(--enable-sixel-images, enable sixel images)
)
AC_ARG_ENABLE(
sixel,
AS_HELP_STRING(--enable-sixel support),
[
enable_sixel_images="$enableval"
]
AS_HELP_STRING(--enable-sixel, enable sixel images)
)
if test "x$enable_sixel_images" = xyes; then
AC_DEFINE(ENABLE_SIXEL_IMAGES)
if test "x$enable_sixel" = xyes; then
AC_DEFINE(ENABLE_SIXEL)
fi
AM_CONDITIONAL(ENABLE_SIXEL_IMAGES, [test "x$enable_sixel_images" = xyes])
# Enable kitty graphics protocol support.
AC_ARG_ENABLE(
kitty-images,
AS_HELP_STRING(--enable-kitty-images, enable kitty terminal graphics)
)
if test "x$enable_kitty_images" = xyes; then
AC_DEFINE(ENABLE_KITTY_IMAGES)
fi
AM_CONDITIONAL(ENABLE_KITTY_IMAGES, [test "x$enable_kitty_images" = xyes])
AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
AC_MSG_CHECKING(for b64_ntop)
@@ -578,11 +629,27 @@ if test "x$found_malloc_trim" = xyes; then
fi
# Build against jemalloc if requested.
jemalloc_version=off
AC_ARG_ENABLE(
jemalloc,
AS_HELP_STRING(--enable-jemalloc, use jemalloc if it is installed)
)
try_jemalloc=no
require_jemalloc=no
if test "x$enable_jemalloc" = xyes; then
try_jemalloc=yes
elif test "x$enable_jemalloc" = x; then
case "$host_os" in
*darwin*)
try_jemalloc=yes
require_jemalloc=yes
;;
esac
fi
if test "x$try_jemalloc" = xyes; then
SAVED_AM_CPPFLAGS="$AM_CPPFLAGS"
SAVED_OLD_CPPFLAGS="$CPPFLAGS"
SAVED_LIBS="$LIBS"
PKG_CHECK_MODULES(
JEMALLOC,
jemalloc,
@@ -590,9 +657,26 @@ if test "x$enable_jemalloc" = xyes; then
AM_CPPFLAGS="$JEMALLOC_CFLAGS $AM_CPPFLAGS"
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
LIBS="$LIBS $JEMALLOC_LIBS"
jemalloc_version=`$PKG_CONFIG --modversion jemalloc 2>/dev/null`
test "x$jemalloc_version" = x && jemalloc_version=on
],
AC_MSG_ERROR("jemalloc not found")
enable_jemalloc=no
)
if test "x$enable_jemalloc" = xno; then
AM_CPPFLAGS="$SAVED_AM_CPPFLAGS"
CPPFLAGS="$SAVED_OLD_CPPFLAGS"
LIBS="$SAVED_LIBS"
jemalloc_version=off
if test "x$require_jemalloc" = xyes; then
enable_jemalloc=
else
AC_MSG_ERROR("jemalloc not found")
fi
else
enable_jemalloc=yes
AC_DEFINE(HAVE_JEMALLOC)
test "x$jemalloc_version" = xoff && jemalloc_version=on
fi
fi
# Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
@@ -939,6 +1023,20 @@ case "$host_os" in
AC_MSG_NOTICE([])
AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
fi
#
# macOS calloc(3) does not appear to always zero memory correctly,
# so complain and suggest using jemalloc instead.
#
if test "x$enable_jemalloc" = x; then
AC_MSG_NOTICE([])
AC_MSG_NOTICE([ macOS calloc(3) appears not to correctly])
AC_MSG_NOTICE([ zero allocations in some circumstances;])
AC_MSG_NOTICE([ to avoid this, configuring with])
AC_MSG_NOTICE([ --enable-jemalloc is recommended. To build])
AC_MSG_NOTICE([ without anyway, use --disable-jemalloc])
AC_MSG_NOTICE([])
AC_MSG_ERROR([must give --enable-jemalloc or --disable-jemalloc])
fi
;;
*dragonfly*)
AC_MSG_RESULT(dragonfly)
@@ -1026,6 +1124,26 @@ AC_MSG_CHECKING(lock-command)
AC_MSG_RESULT($DEFAULT_LOCK_CMD)
AC_SUBST(DEFAULT_LOCK_CMD)
# Print a summary.
AC_MSG_NOTICE([])
if test "x$enable_asan" = xyes; then
AC_MSG_NOTICE([ASAN: on])
else
AC_MSG_NOTICE([ASAN: off])
fi
if test "x$enable_debug" = xyes; then
AC_MSG_NOTICE([debug: on])
else
AC_MSG_NOTICE([debug: off])
fi
AC_MSG_NOTICE([jemalloc: $jemalloc_version])
AC_MSG_NOTICE([libevent: $libevent_version])
AC_MSG_NOTICE([ncurses: $ncurses_version])
AC_MSG_NOTICE([systemd: $systemd_version])
AC_MSG_NOTICE([utempter: $utempter_version])
AC_MSG_NOTICE([utf8proc: $utf8proc_version])
AC_MSG_NOTICE([])
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
# variables.
AC_SUBST(AM_CPPFLAGS)

View File

@@ -24,7 +24,8 @@
#include "tmux.h"
#define CONTROL_SHOULD_NOTIFY_CLIENT(c) \
((c) != NULL && ((c)->flags & CLIENT_CONTROL))
((c) != NULL && ((c)->flags & CLIENT_CONTROL) && \
(c)->control_state != NULL)
void
control_notify_pane_mode_changed(int pane)
@@ -76,6 +77,8 @@ control_notify_window_pane_changed(struct window *w)
{
struct client *c;
if (w->active == NULL)
return;
TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
continue;

View File

@@ -207,10 +207,12 @@ control_free_sub(struct control_state *cs, struct control_sub *csub)
RB_FOREACH_SAFE(csp, control_sub_panes, &csub->panes, csp1) {
RB_REMOVE(control_sub_panes, &csub->panes, csp);
free(csp->last);
free(csp);
}
RB_FOREACH_SAFE(csw, control_sub_windows, &csub->windows, csw1) {
RB_REMOVE(control_sub_windows, &csub->windows, csw);
free(csw->last);
free(csw);
}
free(csub->last);
@@ -298,6 +300,7 @@ control_reset_offsets(struct client *c)
struct control_pane *cp, *cp1;
RB_FOREACH_SAFE(cp, control_panes, &cs->panes, cp1) {
control_discard_pane(c, cp);
RB_REMOVE(control_panes, &cs->panes, cp);
free(cp);
}
@@ -352,6 +355,9 @@ control_set_pane_off(struct client *c, struct window_pane *wp)
struct control_pane *cp;
cp = control_add_pane(c, wp);
control_discard_pane(c, cp);
memcpy(&cp->offset, &wp->offset, sizeof cp->offset);
memcpy(&cp->queued, &wp->offset, sizeof cp->queued);
cp->flags |= CONTROL_PANE_OFF;
}
@@ -828,6 +834,9 @@ control_stop(struct client *c)
struct control_block *cb, *cb1;
struct control_sub *csub, *csub1;
if (cs == NULL)
return;
if (~c->flags & CLIENT_CONTROLCONTROL)
bufferevent_free(cs->write_event);
bufferevent_free(cs->read_event);
@@ -837,10 +846,11 @@ control_stop(struct client *c)
if (evtimer_initialized(&cs->subs_timer))
evtimer_del(&cs->subs_timer);
control_reset_offsets(c);
TAILQ_FOREACH_SAFE(cb, &cs->all_blocks, all_entry, cb1)
control_free_block(cs, cb);
control_reset_offsets(c);
c->control_state = NULL;
free(cs);
}
@@ -1045,6 +1055,9 @@ control_check_subs_timer(__unused int fd, __unused short events, void *data)
log_debug("%s: timer fired", __func__);
evtimer_add(&cs->subs_timer, &tv);
if (s == NULL)
return;
/* Find which subscription types are present. */
RB_FOREACH(csub, control_subs, &cs->subs) {
switch (csub->type) {

29
file.c
View File

@@ -399,6 +399,10 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
}
for (;;) {
size = fread(buffer, 1, sizeof buffer, f);
if (ferror(f)) {
cf->error = errno;
goto done;
}
if (evbuffer_add(cf->buffer, buffer, size) != 0) {
cf->error = ENOMEM;
goto done;
@@ -671,7 +675,7 @@ file_write_close(struct client_files *files, struct imsg *imsg)
/* Client file read error callback. */
static void
file_read_error_callback(__unused struct bufferevent *bev, __unused short what,
file_read_error_callback(__unused struct bufferevent *bev, short what,
void *arg)
{
struct client_file *cf = arg;
@@ -680,7 +684,7 @@ file_read_error_callback(__unused struct bufferevent *bev, __unused short what,
log_debug("read error file %d", cf->stream);
msg.stream = cf->stream;
msg.error = 0;
msg.error = (what & EVBUFFER_ERROR) ? EIO : 0;
proc_send(cf->peer, MSG_READ_DONE, -1, &msg, sizeof msg);
bufferevent_free(cf->event);
@@ -804,7 +808,7 @@ file_read_cancel(struct client_files *files, struct imsg *imsg)
}
/* Handle a write ready message (server). */
void
int
file_write_ready(struct client_files *files, struct imsg *imsg)
{
struct msg_write_ready *msg = imsg->data;
@@ -812,19 +816,20 @@ file_write_ready(struct client_files *files, struct imsg *imsg)
struct client_file find, *cf;
if (msglen != sizeof *msg)
fatalx("bad MSG_WRITE_READY size");
return (-1);
find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return;
return (0);
if (msg->error != 0) {
cf->error = msg->error;
file_fire_done(cf);
} else
file_push(cf);
return (0);
}
/* Handle read data message (server). */
void
int
file_read_data(struct client_files *files, struct imsg *imsg)
{
struct msg_read_data *msg = imsg->data;
@@ -834,10 +839,10 @@ file_read_data(struct client_files *files, struct imsg *imsg)
size_t bsize = msglen - sizeof *msg;
if (msglen < sizeof *msg)
fatalx("bad MSG_READ_DATA size");
return (-1);
find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return;
return (0);
log_debug("file %d read %zu bytes", cf->stream, bsize);
if (cf->error == 0 && !cf->closed) {
@@ -847,10 +852,11 @@ file_read_data(struct client_files *files, struct imsg *imsg)
} else
file_fire_read(cf);
}
return (0);
}
/* Handle a read done message (server). */
void
int
file_read_done(struct client_files *files, struct imsg *imsg)
{
struct msg_read_done *msg = imsg->data;
@@ -858,12 +864,13 @@ file_read_done(struct client_files *files, struct imsg *imsg)
struct client_file find, *cf;
if (msglen != sizeof *msg)
fatalx("bad MSG_READ_DONE size");
return (-1);
find.stream = msg->stream;
if ((cf = RB_FIND(client_files, files, &find)) == NULL)
return;
return (0);
log_debug("file %d read done", cf->stream);
cf->error = msg->error;
file_fire_done(cf);
return (0);
}

View File

@@ -49,6 +49,7 @@ format_is_type(struct format_range *fr, struct style *sy)
case STYLE_RANGE_NONE:
case STYLE_RANGE_LEFT:
case STYLE_RANGE_RIGHT:
case STYLE_RANGE_CONTROL:
return (1);
case STYLE_RANGE_PANE:
case STYLE_RANGE_WINDOW:
@@ -1065,6 +1066,10 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
log_debug("%s: range user|%u at %u-%u", __func__,
sr->argument, sr->start, sr->end);
break;
case STYLE_RANGE_CONTROL:
log_debug("%s: range control|%u at %u-%u", __func__,
sr->argument, sr->start, sr->end);
break;
}
format_free_range(&frs, fr);
}
@@ -1116,7 +1121,7 @@ format_width(const char *expanded)
/*
* Trim on the left, taking #[] into account. Note, we copy the whole set of
* unescaped #s, but only add their escaped size to width. This is because the
* format_draw function will actually do the escaping when it runs
* format_draw function will actually do the escaping.
*/
char *
format_trim_left(const char *expanded, u_int limit)

377
format.c
View File

@@ -84,6 +84,15 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
return (strcmp(fj1->cmd, fj2->cmd));
}
/* Maimum pad and trim width. */
#define FORMAT_MAX_WIDTH 10000
/* Maimum repeat size. */
#define FORMAT_MAX_REPEAT 10000
/* Maimum precision. */
#define FORMAT_MAX_PRECISION 100
/* Format modifiers. */
#define FORMAT_TIMESTRING 0x1
#define FORMAT_BASENAME 0x2
@@ -107,10 +116,17 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_NOT 0x80000
#define FORMAT_NOT_NOT 0x100000
#define FORMAT_REPEAT 0x200000
#define FORMAT_QUOTE_ARGUMENTS 0x400000
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 100
/* Limit on time taken (milliseconds). */
#define FORMAT_TIME_LIMIT 100
/* How often to check the time in long loops. */
#define FORMAT_TIME_LOOP_CHECK 10000
/* Format expand flags. */
#define FORMAT_EXPAND_TIME 0x1
#define FORMAT_EXPAND_NOJOBS 0x2
@@ -160,9 +176,11 @@ RB_GENERATE_STATIC(format_entry_tree, format_entry, entry, format_entry_cmp);
struct format_expand_state {
struct format_tree *ft;
u_int loop;
uint64_t start_time;
int flags;
time_t time;
struct tm tm;
int flags;
};
/* Format modifier. */
@@ -283,6 +301,7 @@ format_copy_state(struct format_expand_state *to,
to->time = from->time;
memcpy(&to->tm, &from->tm, sizeof to->tm);
to->flags = from->flags|flags;
to->start_time = from->start_time;
}
/* Format job update callback. */
@@ -825,8 +844,8 @@ format_cb_window_layout(struct format_tree *ft)
return (NULL);
if (w->saved_layout_root != NULL)
return (layout_dump(w->saved_layout_root));
return (layout_dump(w->layout_root));
return (layout_dump(w, w->saved_layout_root));
return (layout_dump(w, w->layout_root));
}
/* Callback for window_visible_layout. */
@@ -838,7 +857,7 @@ format_cb_window_visible_layout(struct format_tree *ft)
if (w == NULL)
return (NULL);
return (layout_dump(w->layout_root));
return (layout_dump(w, w->layout_root));
}
/* Callback for pane_start_command. */
@@ -1004,6 +1023,29 @@ format_cb_pane_fg(struct format_tree *ft)
return (xstrdup(colour_tostring(gc.fg)));
}
/* Callback for pane_flags. */
static void *
format_cb_pane_flags(struct format_tree *ft)
{
if (ft->wp != NULL)
return (xstrdup(window_pane_printable_flags(ft->wp)));
return (NULL);
}
/* Callback for pane_floating_flag. */
static void *
format_cb_pane_floating_flag(struct format_tree *ft)
{
struct window_pane *wp = ft->wp;
if (wp != NULL) {
if (window_pane_is_floating(wp))
return (xstrdup("1"));
return (xstrdup("0"));
}
return (NULL);
}
/* Callback for pane_bg. */
static void *
format_cb_pane_bg(struct format_tree *ft)
@@ -1146,9 +1188,9 @@ format_cb_pane_at_bottom(struct format_tree *ft)
status = options_get_number(w->options, "pane-border-status");
if (status == PANE_STATUS_BOTTOM)
flag = (wp->yoff + wp->sy == w->sy - 1);
flag = (wp->yoff + (int)wp->sy == (int)w->sy - 1);
else
flag = (wp->yoff + wp->sy == w->sy);
flag = (wp->yoff + (int)wp->sy == (int)w->sy);
xasprintf(&value, "%d", flag);
return (value);
}
@@ -1321,6 +1363,8 @@ format_cb_mouse_status_range(struct format_tree *ft)
return (xstrdup("session"));
case STYLE_RANGE_USER:
return (xstrdup(sr->string));
case STYLE_RANGE_CONTROL:
return (xstrdup("control"));
}
return (NULL);
}
@@ -1355,6 +1399,18 @@ format_cb_alternate_saved_y(struct format_tree *ft)
return (NULL);
}
/* Callback for bracket_paste_flag. */
static void *
format_cb_bracket_paste_flag(struct format_tree *ft)
{
if (ft->wp != NULL && ft->wp->screen != NULL) {
if (ft->wp->screen->mode & MODE_BRACKETPASTE)
return (xstrdup("1"));
return (xstrdup("0"));
}
return (NULL);
}
/* Callback for buffer_name. */
static void *
format_cb_buffer_name(struct format_tree *ft)
@@ -1593,9 +1649,13 @@ format_cb_client_user(struct format_tree *ft)
struct passwd *pw;
if (ft->c != NULL) {
if (ft->c->user != NULL)
return (xstrdup(ft->c->user));
uid = proc_get_peer_uid(ft->c->peer);
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL)
return (xstrdup(pw->pw_name));
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) {
ft->c->user = xstrdup(pw->pw_name);
return (xstrdup(ft->c->user));
}
}
return (NULL);
}
@@ -1992,7 +2052,7 @@ static void *
format_cb_pane_at_right(struct format_tree *ft)
{
if (ft->wp != NULL) {
if (ft->wp->xoff + ft->wp->sx == ft->wp->window->sx)
if (ft->wp->xoff + (int)ft->wp->sx == (int)ft->wp->window->sx)
return (xstrdup("1"));
return (xstrdup("0"));
}
@@ -2003,8 +2063,10 @@ format_cb_pane_at_right(struct format_tree *ft)
static void *
format_cb_pane_bottom(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%u", ft->wp->yoff + ft->wp->sy - 1));
struct window_pane *wp = ft->wp;
if (wp != NULL)
return (format_printf("%d", wp->yoff + (int)wp->sy - 1));
return (NULL);
}
@@ -2163,7 +2225,7 @@ static void *
format_cb_pane_left(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%u", ft->wp->xoff));
return (format_printf("%d", ft->wp->xoff));
return (NULL);
}
@@ -2250,12 +2312,46 @@ format_cb_pane_pipe_pid(struct format_tree *ft)
return (value);
}
/* Callback for pane_pb_progress. */
static void *
format_cb_pane_pb_progress(struct format_tree *ft)
{
char *value = NULL;
if (ft->wp != NULL)
xasprintf(&value, "%d", ft->wp->base.progress_bar.progress);
return (value);
}
/* Callback for pane_pb_state. */
static void *
format_cb_pane_pb_state(struct format_tree *ft)
{
if (ft->wp != NULL) {
switch (ft->wp->base.progress_bar.state) {
case PROGRESS_BAR_HIDDEN:
return xstrdup("hidden");
case PROGRESS_BAR_NORMAL:
return xstrdup("normal");
case PROGRESS_BAR_ERROR:
return xstrdup("error");
case PROGRESS_BAR_INDETERMINATE:
return xstrdup("indeterminate");
case PROGRESS_BAR_PAUSED:
return xstrdup("paused");
}
}
return (NULL);
}
/* Callback for pane_right. */
static void *
format_cb_pane_right(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%u", ft->wp->xoff + ft->wp->sx - 1));
struct window_pane *wp = ft->wp;
if (wp != NULL)
return (format_printf("%d", wp->xoff + (int)wp->sx - 1));
return (NULL);
}
@@ -2297,7 +2393,7 @@ static void *
format_cb_pane_top(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%u", ft->wp->yoff));
return (format_printf("%d", ft->wp->yoff));
return (NULL);
}
@@ -2319,6 +2415,49 @@ format_cb_pane_width(struct format_tree *ft)
return (NULL);
}
/* Callback for pane_x. */
static void *
format_cb_pane_x(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%d", ft->wp->xoff));
return (NULL);
}
/* Callback for pane_y. */
static void *
format_cb_pane_y(struct format_tree *ft)
{
if (ft->wp != NULL)
return (format_printf("%d", ft->wp->yoff));
return (NULL);
}
/* Callback for pane_z. */
static void *
format_cb_pane_z(struct format_tree *ft)
{
u_int idx;
if (ft->wp != NULL && window_pane_zindex(ft->wp, &idx) == 0)
return (format_printf("%u", idx));
return (NULL);
}
/* Callback for pane_zoomed_flag. */
static void *
format_cb_pane_zoomed_flag(struct format_tree *ft)
{
struct window_pane *wp = ft->wp;
if (wp != NULL) {
if (wp->flags & PANE_ZOOMED)
return (xstrdup("1"));
return (xstrdup("0"));
}
return (NULL);
}
/* Callback for scroll_region_lower. */
static void *
format_cb_scroll_region_lower(struct format_tree *ft)
@@ -2562,16 +2701,12 @@ format_cb_version(__unused struct format_tree *ft)
/* Callback for sixel_support. */
static void *
format_cb_image_support(__unused struct format_tree *ft)
format_cb_sixel_support(__unused struct format_tree *ft)
{
#if defined(ENABLE_SIXEL_IMAGES) && defined(ENABLE_KITTY_IMAGES)
return (xstrdup("kitty,sixel"));
#elif defined(ENABLE_SIXEL_IMAGES)
return (xstrdup("sixel"));
#elif defined(ENABLE_KITTY_IMAGES)
return (xstrdup("kitty"));
#ifdef ENABLE_SIXEL
return (xstrdup("1"));
#else
return (NULL);
return (xstrdup("0"));
#endif
}
@@ -2838,7 +2973,7 @@ static void *
format_cb_window_panes(struct format_tree *ft)
{
if (ft->w != NULL)
return (format_printf("%u", window_count_panes(ft->w)));
return (format_printf("%u", window_count_panes(ft->w, 1)));
return (NULL);
}
@@ -3015,10 +3150,13 @@ format_cb_uid(__unused struct format_tree *ft)
static void *
format_cb_user(__unused struct format_tree *ft)
{
static char *cached;
struct passwd *pw;
if ((pw = getpwuid(getuid())) != NULL)
return (xstrdup(pw->pw_name));
if (cached == NULL && (pw = getpwuid(getuid())) != NULL)
cached = xstrdup(pw->pw_name);
if (cached != NULL)
return (xstrdup(cached));
return (NULL);
}
@@ -3053,6 +3191,9 @@ static const struct format_table_entry format_table[] = {
{ "alternate_saved_y", FORMAT_TABLE_STRING,
format_cb_alternate_saved_y
},
{ "bracket_paste_flag", FORMAT_TABLE_STRING,
format_cb_bracket_paste_flag
},
{ "buffer_created", FORMAT_TABLE_TIME,
format_cb_buffer_created
},
@@ -3194,9 +3335,6 @@ static const struct format_table_entry format_table[] = {
{ "host_short", FORMAT_TABLE_STRING,
format_cb_host_short
},
{ "image_support", FORMAT_TABLE_STRING,
format_cb_image_support
},
{ "insert_flag", FORMAT_TABLE_STRING,
format_cb_insert_flag
},
@@ -3302,6 +3440,12 @@ static const struct format_table_entry format_table[] = {
{ "pane_fg", FORMAT_TABLE_STRING,
format_cb_pane_fg
},
{ "pane_flags", FORMAT_TABLE_STRING,
format_cb_pane_flags
},
{ "pane_floating_flag", FORMAT_TABLE_STRING,
format_cb_pane_floating_flag
},
{ "pane_format", FORMAT_TABLE_STRING,
format_cb_pane_format
},
@@ -3341,6 +3485,12 @@ static const struct format_table_entry format_table[] = {
{ "pane_path", FORMAT_TABLE_STRING,
format_cb_pane_path
},
{ "pane_pb_progress", FORMAT_TABLE_STRING,
format_cb_pane_pb_progress
},
{ "pane_pb_state", FORMAT_TABLE_STRING,
format_cb_pane_pb_state
},
{ "pane_pid", FORMAT_TABLE_STRING,
format_cb_pane_pid
},
@@ -3383,6 +3533,18 @@ static const struct format_table_entry format_table[] = {
{ "pane_width", FORMAT_TABLE_STRING,
format_cb_pane_width
},
{ "pane_x", FORMAT_TABLE_STRING,
format_cb_pane_x
},
{ "pane_y", FORMAT_TABLE_STRING,
format_cb_pane_y
},
{ "pane_z", FORMAT_TABLE_STRING,
format_cb_pane_z
},
{ "pane_zoomed_flag", FORMAT_TABLE_STRING,
format_cb_pane_zoomed_flag
},
{ "pid", FORMAT_TABLE_STRING,
format_cb_pid
},
@@ -3473,6 +3635,9 @@ static const struct format_table_entry format_table[] = {
{ "session_windows", FORMAT_TABLE_STRING,
format_cb_session_windows
},
{ "sixel_support", FORMAT_TABLE_STRING,
format_cb_sixel_support
},
{ "socket_path", FORMAT_TABLE_STRING,
format_cb_socket_path
},
@@ -4021,18 +4186,46 @@ found:
found = format_quote_style(saved);
free(saved);
}
if (modifiers & FORMAT_QUOTE_ARGUMENTS) {
saved = found;
found = args_escape(saved);
free(saved);
}
return (found);
}
/* Check if format has not taken too long. */
static int
format_check_time(struct format_expand_state *es, u_int *check)
{
uint64_t t;
if (check != NULL && ++*check % FORMAT_TIME_LOOP_CHECK != 0)
return (1);
t = get_timer();
if (t - es->start_time < FORMAT_TIME_LIMIT)
return (1);
t -= es->start_time;
format_log(es, "reached time limit (%llu)", (unsigned long long)t);
return (0);
}
/* Unescape escaped characters. */
static char *
format_unescape(const char *s)
format_unescape(struct format_expand_state *es, const char *s)
{
char *out, *cp;
int brackets = 0;
u_int check = 0;
cp = out = xmalloc(strlen(s) + 1);
for (; *s != '\0'; s++) {
if (!format_check_time(es, &check)) {
free(out);
return (xstrdup(""));
}
if (*s == '#' && s[1] == '{')
brackets++;
if (brackets == 0 &&
@@ -4051,13 +4244,18 @@ format_unescape(const char *s)
/* Remove escaped characters. */
static char *
format_strip(const char *s)
format_strip(struct format_expand_state *es, const char *s)
{
char *out, *cp;
int brackets = 0;
u_int check = 0;
cp = out = xmalloc(strlen(s) + 1);
for (; *s != '\0'; s++) {
if (!format_check_time(es, &check)) {
free(out);
return (xstrdup(""));
}
if (*s == '#' && s[1] == '{')
brackets++;
if (*s == '#' && strchr(",#{}:", s[1]) != NULL) {
@@ -4074,12 +4272,15 @@ format_strip(const char *s)
}
/* Skip until end. */
const char *
format_skip(const char *s, const char *end)
static const char *
format_skip1(struct format_expand_state *es, const char *s, const char *end)
{
int brackets = 0;
u_int check = 0;
for (; *s != '\0'; s++) {
if (es != NULL && !format_check_time(es, &check))
return (NULL);
if (*s == '#' && s[1] == '{')
brackets++;
if (*s == '#' &&
@@ -4098,6 +4299,13 @@ format_skip(const char *s, const char *end)
return (s);
}
/* Skip until end. */
const char *
format_skip(const char *s, const char *end)
{
return (format_skip1(NULL, s, end));
}
/* Return left and right alternatives separated by commas. */
static int
format_choose(struct format_expand_state *es, const char *s, char **left,
@@ -4106,7 +4314,7 @@ format_choose(struct format_expand_state *es, const char *s, char **left,
const char *cp;
char *left0, *right0;
cp = format_skip(s, ",");
cp = format_skip1(es, s, ",");
if (cp == NULL)
return (-1);
left0 = xstrndup(s, cp - s);
@@ -4196,6 +4404,8 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
/* Skip any separator character. */
if (*cp == ';')
cp++;
if (*cp == '\0')
break;
/* Check single character modifiers with no arguments. */
if (strchr("labcdnwETSWPL!<>", cp[0]) != NULL &&
@@ -4235,7 +4445,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
/* Single argument with no wrapper character. */
if (!ispunct((u_char)cp[1]) || cp[1] == '-') {
end = format_skip(cp + 1, ":;");
end = format_skip1(es, cp + 1, ":;");
if (end == NULL)
break;
@@ -4258,7 +4468,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
cp++;
break;
}
end = format_skip(cp + 1, last);
end = format_skip1(es, cp + 1, last);
if (end == NULL)
break;
cp++;
@@ -4372,7 +4582,7 @@ format_bool_op_n(struct format_expand_state *es, const char *fmt, int and)
cp1 = fmt;
while (and ? result : !result) {
cp2 = format_skip(cp1, ",");
cp2 = format_skip1(es, cp1, ",");
if (cp2 == NULL)
raw = xstrdup(cp1);
@@ -4495,6 +4705,37 @@ format_window_name(struct format_expand_state *es, const char *fmt)
return (xstrdup("0"));
}
/* Add neighbor window variables to the format tree. */
static void
format_add_window_neighbor(struct format_tree *nft, struct winlink *wl,
struct session *s, const char *prefix)
{
struct options_entry *o;
const char *oname;
char *key, *prefixed, *oval;
xasprintf(&key, "%s_window_index", prefix);
format_add(nft, key, "%u", wl->idx);
free(key);
xasprintf(&key, "%s_window_active", prefix);
format_add(nft, key, "%d", wl == s->curw);
free(key);
o = options_first(wl->window->options);
while (o != NULL) {
oname = options_name(o);
if (*oname == '@') {
xasprintf(&prefixed, "%s_%s", prefix, oname);
oval = options_to_string(o, -1, 1);
format_add(nft, prefixed, "%s", oval);
free(oval);
free(prefixed);
}
o = options_next(o);
}
}
/* Loop over windows. */
static char *
format_loop_windows(struct format_expand_state *es, const char *fmt)
@@ -4538,6 +4779,17 @@ format_loop_windows(struct format_expand_state *es, const char *fmt)
nft = format_create(c, item, FORMAT_WINDOW|w->id,
ft->flags|last);
format_defaults(nft, ft->c, ft->s, wl, NULL);
/* Add neighbor window data to the format tree. */
format_add(nft, "window_after_active", "%d",
i > 0 && l[i - 1] == ft->s->curw);
format_add(nft, "window_before_active", "%d",
i + 1 < n && l[i + 1] == ft->s->curw);
if (i + 1 < n)
format_add_window_neighbor(nft, l[i + 1], ft->s, "next");
if (i > 0)
format_add_window_neighbor(nft, l[i - 1], ft->s, "prev");
format_copy_state(&next, es, 0);
next.ft = nft;
expanded = format_expand1(&next, use);
@@ -4714,7 +4966,8 @@ format_replace_expression(struct format_modifier *mexp,
/* The third argument may be precision. */
if (argc >= 3) {
prec = strtonum(mexp->argv[2], INT_MIN, INT_MAX, &errstr);
prec = strtonum(mexp->argv[2], -FORMAT_MAX_PRECISION,
FORMAT_MAX_PRECISION, &errstr);
if (errstr != NULL) {
format_log(es, "expression precision %s: %s", errstr,
mexp->argv[2]);
@@ -4816,7 +5069,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
struct format_modifier *list, *cmp = NULL, *search = NULL;
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
struct format_modifier *bool_op_n = NULL;
u_int i, count, nsub = 0, nrep;
u_int i, count, nsub = 0, nrep, check = 0;
struct format_expand_state next;
/* Set sorting defaults. */
@@ -4859,8 +5112,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
case '=':
if (fm->argc < 1)
break;
limit = strtonum(fm->argv[0], INT_MIN, INT_MAX,
&errstr);
limit = strtonum(fm->argv[0], -FORMAT_MAX_WIDTH,
FORMAT_MAX_WIDTH, &errstr);
if (errstr != NULL)
limit = 0;
if (fm->argc >= 2 && fm->argv[1] != NULL)
@@ -4869,8 +5122,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
case 'p':
if (fm->argc < 1)
break;
width = strtonum(fm->argv[0], INT_MIN, INT_MAX,
&errstr);
width = strtonum(fm->argv[0], -FORMAT_MAX_WIDTH,
FORMAT_MAX_WIDTH, &errstr);
if (errstr != NULL)
width = 0;
break;
@@ -4907,8 +5160,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
if (strchr(fm->argv[0], 'p') != NULL)
modifiers |= FORMAT_PRETTY;
else if (fm->argc >= 2 &&
strchr(fm->argv[0], 'f') != NULL)
time_format = format_strip(fm->argv[1]);
strchr(fm->argv[0], 'f') != NULL) {
free(time_format);
time_format = format_strip(es, fm->argv[1]);
}
break;
case 'q':
if (fm->argc < 1)
@@ -4916,6 +5171,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
else if (strchr(fm->argv[0], 'e') != NULL ||
strchr(fm->argv[0], 'h') != NULL)
modifiers |= FORMAT_QUOTE_STYLE;
else if (strchr(fm->argv[0], 'a') != NULL)
modifiers |= FORMAT_QUOTE_ARGUMENTS;
break;
case 'E':
modifiers |= FORMAT_EXPAND;
@@ -5023,7 +5280,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
/* Is this a literal string? */
if (modifiers & FORMAT_LITERAL) {
format_log(es, "literal string is '%s'", copy);
value = format_unescape(copy);
value = format_unescape(es, copy);
goto done;
}
@@ -5087,18 +5344,24 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
value = format_search(search, wp, new);
}
free(new);
} else if (modifiers & FORMAT_REPEAT) {
} else if (modifiers & FORMAT_REPEAT) {
/* Repeat multiple times. */
if (format_choose(es, copy, &left, &right, 1) != 0) {
format_log(es, "repeat syntax error: %s", copy);
goto fail;
}
nrep = strtonum(right, 1, 10000, &errstr);
nrep = strtonum(right, 1, FORMAT_MAX_REPEAT, &errstr);
if (errstr != NULL)
value = xstrdup("");
else {
value = xstrdup("");
for (i = 0; i < nrep; i++) {
if (!format_check_time(es, &check)) {
free(right);
free(left);
free(value);
goto fail;
}
xasprintf(&new, "%s%s", value, left);
free(value);
value = new;
@@ -5106,7 +5369,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
}
free(right);
free(left);
} else if (modifiers & FORMAT_NOT) {
} else if (modifiers & FORMAT_NOT) {
value = format_bool_op_1(es, copy, 1);
} else if (modifiers & FORMAT_NOT_NOT) {
value = format_bool_op_1(es, copy, 0);
@@ -5170,7 +5433,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
*/
cp = copy + 1;
while (1) {
cp2 = format_skip(cp, ",");
cp2 = format_skip1(es, cp, ",");
if (cp2 == NULL) {
format_log(es,
"no condition matched in '%s'; using last "
@@ -5205,7 +5468,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
}
cp = cp2 + 1;
cp2 = format_skip(cp, ",");
cp2 = format_skip1(es, cp, ",");
if (format_true(found)) {
format_log(es, "condition '%s' is true",
condition);
@@ -5288,6 +5551,7 @@ done:
if (marker != NULL && strcmp(new, value) != 0) {
free(value);
xasprintf(&value, "%s%s", new, marker);
free(new);
} else {
free(value);
value = new;
@@ -5298,6 +5562,7 @@ done:
if (marker != NULL && strcmp(new, value) != 0) {
free(value);
xasprintf(&value, "%s%s", marker, new);
free(new);
} else {
free(value);
value = new;
@@ -5371,7 +5636,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
int ch, brackets;
char expanded[8192];
if (fmt == NULL || *fmt == '\0')
if (fmt == NULL || *fmt == '\0' || !format_check_time(es, NULL))
return (xstrdup(""));
if (es->loop == FORMAT_LOOP_LIMIT) {
@@ -5410,7 +5675,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
buf[off++] = *fmt++;
continue;
}
if (*fmt++ == '\0')
if (*++fmt == '\0')
break;
ch = (u_char)*fmt++;
@@ -5453,7 +5718,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
fmt += n + 1;
continue;
case '{':
ptr = format_skip((char *)fmt - 2, "}");
ptr = format_skip1(es, (char *)fmt - 2, "}");
if (ptr == NULL)
break;
n = ptr - fmt;
@@ -5476,7 +5741,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
n++;
}
if (*ptr == '[') {
style_end = format_skip(fmt - 2, "]");
style_end = format_skip1(es, fmt - 2, "]");
format_log(es, "found #*%zu[", n);
while (len - off < n + 2) {
buf = xreallocarray(buf, 2, len);
@@ -5540,6 +5805,7 @@ format_expand_time(struct format_tree *ft, const char *fmt)
memset(&es, 0, sizeof es);
es.ft = ft;
es.flags = FORMAT_EXPAND_TIME;
es.start_time = get_timer();
return (format_expand1(&es, fmt));
}
@@ -5552,6 +5818,7 @@ format_expand(struct format_tree *ft, const char *fmt)
memset(&es, 0, sizeof es);
es.ft = ft;
es.flags = 0;
es.start_time = get_timer();
return (format_expand1(&es, fmt));
}

83
fuzz/cmd-parse-fuzzer.c Normal file
View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2026 David Korczynski <david@adalogics.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Fuzz the tmux command parser (cmd_parse_from_buffer).
*
* This exercises:
* - cmd-parse.y (yacc grammar, lexer, command building)
* - cmd.c (command lookup and validation)
* - arguments.c (argument parsing and flag handling)
* - cmd-find.c (target resolution)
* - options.c (option name lookups during parsing)
*/
#include <stddef.h>
#include <string.h>
#include "tmux.h"
struct event_base *libevent;
int
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
{
struct cmd_parse_input pi;
struct cmd_parse_result *pr;
if (size > 2048 || size == 0)
return 0;
memset(&pi, 0, sizeof pi);
pi.flags = CMD_PARSE_QUIET;
pr = cmd_parse_from_buffer(data, size, &pi);
switch (pr->status) {
case CMD_PARSE_SUCCESS:
cmd_list_free(pr->cmdlist);
break;
case CMD_PARSE_ERROR:
free(pr->error);
break;
default:
break;
}
return 0;
}
int
LLVMFuzzerInitialize(__unused int *argc, __unused char ***argv)
{
const struct options_table_entry *oe;
global_environ = environ_create();
global_options = options_create(NULL);
global_s_options = options_create(NULL);
global_w_options = options_create(NULL);
for (oe = options_table; oe->name != NULL; oe++) {
if (oe->scope & OPTIONS_TABLE_SERVER)
options_default(global_options, oe);
if (oe->scope & OPTIONS_TABLE_SESSION)
options_default(global_s_options, oe);
if (oe->scope & OPTIONS_TABLE_WINDOW)
options_default(global_w_options, oe);
}
libevent = osdep_event_init();
socket_path = xstrdup("dummy");
return 0;
}

133
fuzz/cmd-parse-fuzzer.dict Normal file
View File

@@ -0,0 +1,133 @@
# tmux command names
"set-option"
"bind-key"
"unbind-key"
"send-keys"
"new-session"
"new-window"
"split-window"
"select-window"
"select-pane"
"kill-pane"
"kill-window"
"kill-session"
"kill-server"
"list-sessions"
"list-windows"
"list-panes"
"list-keys"
"list-buffers"
"list-clients"
"list-commands"
"attach-session"
"detach-client"
"switch-client"
"rename-session"
"rename-window"
"resize-pane"
"resize-window"
"display-message"
"display-menu"
"display-popup"
"display-panes"
"copy-mode"
"paste-buffer"
"capture-pane"
"save-buffer"
"load-buffer"
"set-buffer"
"delete-buffer"
"show-buffer"
"choose-buffer"
"choose-tree"
"choose-client"
"if-shell"
"run-shell"
"source-file"
"command-prompt"
"confirm-before"
"pipe-pane"
"wait-for"
"set-environment"
"show-environment"
"set-hook"
"show-hooks"
"show-messages"
"show-options"
"set-window-option"
"show-window-options"
"clear-history"
"clock-mode"
"find-window"
"join-pane"
"move-pane"
"break-pane"
"swap-pane"
"swap-window"
"move-window"
"link-window"
"unlink-window"
"rotate-window"
"next-window"
"previous-window"
"last-window"
"last-pane"
"next-layout"
"previous-layout"
"select-layout"
"customize-mode"
"refresh-client"
"suspend-client"
"lock-client"
"lock-server"
"lock-session"
"respawn-pane"
"respawn-window"
"start-server"
"server-access"
"send-prefix"
"clear-prompt-history"
"show-prompt-history"
# Common flags and syntax
"-t"
"-s"
"-g"
"-w"
"-p"
"-a"
"-o"
"-q"
"-u"
"-F"
"-f"
"-b"
"-d"
"-e"
"-n"
"-r"
# Targets and option names
"status"
"default"
"mouse"
"on"
"off"
"vi"
"emacs"
"set -g"
"set -s"
"setw"
"bind"
"unbind"
# Syntax elements
"{"
"}"
";"
"#{"
"%if"
"%elif"
"%else"
"%endif"
"%hidden"

View File

@@ -0,0 +1,2 @@
[libfuzzer]
max_len = 2048

88
fuzz/format-fuzzer.c Normal file
View File

@@ -0,0 +1,88 @@
/*
* Copyright (c) 2026 David Korczynski <david@adalogics.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Fuzz the tmux format string expander (format_expand).
*
* This exercises:
* - format.c (format parsing, modifier chains, conditionals, math, regex)
* - colour.c (colour name and RGB parsing within formats)
* - utf8.c (UTF-8 width calculations in format padding)
*/
#include <stddef.h>
#include <string.h>
#include "tmux.h"
struct event_base *libevent;
int
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
{
struct format_tree *ft;
char *buf, *expanded;
if (size > 2048 || size == 0)
return 0;
/* Null-terminate the input for format_expand. */
buf = malloc(size + 1);
if (buf == NULL)
return 0;
memcpy(buf, data, size);
buf[size] = '\0';
ft = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
format_add(ft, "session_name", "%s", "fuzz-session");
format_add(ft, "window_index", "%d", 0);
format_add(ft, "window_name", "%s", "fuzz-window");
format_add(ft, "pane_index", "%d", 0);
format_add(ft, "pane_id", "%s", "%%0");
format_add(ft, "host", "%s", "fuzzhost");
format_add(ft, "pane_width", "%d", 80);
format_add(ft, "pane_height", "%d", 25);
expanded = format_expand(ft, buf);
free(expanded);
format_free(ft);
free(buf);
return 0;
}
int
LLVMFuzzerInitialize(__unused int *argc, __unused char ***argv)
{
const struct options_table_entry *oe;
global_environ = environ_create();
global_options = options_create(NULL);
global_s_options = options_create(NULL);
global_w_options = options_create(NULL);
for (oe = options_table; oe->name != NULL; oe++) {
if (oe->scope & OPTIONS_TABLE_SERVER)
options_default(global_options, oe);
if (oe->scope & OPTIONS_TABLE_SESSION)
options_default(global_s_options, oe);
if (oe->scope & OPTIONS_TABLE_WINDOW)
options_default(global_w_options, oe);
}
libevent = osdep_event_init();
socket_path = xstrdup("dummy");
return 0;
}

71
fuzz/format-fuzzer.dict Normal file
View File

@@ -0,0 +1,71 @@
# Format expansion syntax
"#{"
"}"
"#{?"
"#{=="
"#{!="
"#{<"
"#{>"
"#{m:"
"#{C:"
"#{s/"
"#{t:"
"#{T:"
"#{E:"
"#{S:"
"#{W:"
"#{P:"
"##"
# Common format modifiers
"b:"
"d:"
"q:"
"l:"
"e:"
"t:"
"p:"
"w:"
"n:"
"a:"
"=:"
"||"
"&&"
","
"#{e|"
"#{p-1:"
"#{=/10/...:"
# Format variables
"session_name"
"window_index"
"window_name"
"pane_index"
"pane_id"
"host"
"pane_width"
"pane_height"
"pane_current_command"
"pane_pid"
"session_id"
"window_id"
"client_name"
"version"
"line"
# Conditionals
"#{?pane_active,"
",}"
"#{?#{==:"
# Math and comparison
"#{e|+:"
"#{e|-:"
"#{e|*:"
"#{e|/:"
"#{e|%:"
# Nested
"#{="
"#{"
"#{l:"

View File

@@ -0,0 +1,2 @@
[libfuzzer]
max_len = 2048

79
fuzz/style-fuzzer.c Normal file
View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2026 David Korczynski <david@adalogics.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
* Fuzz the tmux style parser (style_parse).
*
* This exercises:
* - style.c (style string parsing, alignment, ranges)
* - colour.c (colour name, RGB, and indexed colour parsing)
*/
#include <stddef.h>
#include <string.h>
#include "tmux.h"
struct event_base *libevent;
int
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
{
struct style sy;
struct grid_cell gc;
char *buf;
if (size > 512 || size == 0)
return 0;
/* Null-terminate the input for style_parse. */
buf = malloc(size + 1);
if (buf == NULL)
return 0;
memcpy(buf, data, size);
buf[size] = '\0';
memset(&gc, 0, sizeof gc);
style_set(&sy, &gc);
style_parse(&sy, &gc, buf);
free(buf);
return 0;
}
int
LLVMFuzzerInitialize(__unused int *argc, __unused char ***argv)
{
const struct options_table_entry *oe;
global_environ = environ_create();
global_options = options_create(NULL);
global_s_options = options_create(NULL);
global_w_options = options_create(NULL);
for (oe = options_table; oe->name != NULL; oe++) {
if (oe->scope & OPTIONS_TABLE_SERVER)
options_default(global_options, oe);
if (oe->scope & OPTIONS_TABLE_SESSION)
options_default(global_s_options, oe);
if (oe->scope & OPTIONS_TABLE_WINDOW)
options_default(global_w_options, oe);
}
libevent = osdep_event_init();
socket_path = xstrdup("dummy");
return 0;
}

73
fuzz/style-fuzzer.dict Normal file
View File

@@ -0,0 +1,73 @@
# Style attributes
"default"
"ignore"
"nodefaults"
"bright"
"bold"
"dim"
"underscore"
"blink"
"reverse"
"hidden"
"italics"
"overline"
"strikethrough"
"double-underscore"
"curly-underscore"
"dotted-underscore"
"dashed-underscore"
"nobright"
"nobold"
"nodim"
"nounderscore"
"noblink"
"noreverse"
"nohidden"
"noitalics"
"nooverline"
"nostrikethrough"
# Colours
"fg="
"bg="
"us="
"fill="
"colour0"
"colour255"
"red"
"green"
"blue"
"yellow"
"cyan"
"magenta"
"white"
"black"
# RGB and hex
"#ff0000"
"#00ff00"
"#0000ff"
# Alignment and ranges
"align=left"
"align=centre"
"align=right"
"align=absolute-centre"
"list=on"
"list=focus"
"list=left-marker"
"list=right-marker"
"range=left"
"range=right"
"range=pane"
"range=window"
"range=session"
"range=user"
# Width and padding
"width="
"pad="
# Delimiters
","
" "

View File

@@ -0,0 +1,2 @@
[libfuzzer]
max_len = 512

View File

@@ -45,15 +45,20 @@ grid_reader_line_length(struct grid_reader *gr)
/* Move cursor forward one position. */
void
grid_reader_cursor_right(struct grid_reader *gr, int wrap, int all)
grid_reader_cursor_right(struct grid_reader *gr, int wrap, int all, int onemore)
{
u_int px;
struct grid_cell gc;
if (all)
px = gr->gd->sx;
else
else if (onemore)
px = grid_reader_line_length(gr);
else {
px = grid_reader_line_length(gr);
if (px != 0)
px--;
}
if (wrap && gr->cx >= px && gr->cy < gr->gd->hsize + gr->gd->sy - 1) {
grid_reader_cursor_start_of_line(gr, 0);

36
grid.c
View File

@@ -125,6 +125,8 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
else if (gce->offset >= gl->extdsize)
fatalx("offset too big");
gl->flags |= GRID_LINE_EXTENDED;
if (gc->link != 0)
gl->flags |= GRID_LINE_HYPERLINK;
if (gc->flags & GRID_FLAG_TAB)
uc = gc->data.width;
@@ -200,7 +202,7 @@ grid_adjust_lines(struct grid *gd, u_int lines)
/* Copy default into a cell. */
static void
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg, int moved)
{
struct grid_line *gl = &gd->linedata[py];
struct grid_cell_entry *gce = &gl->celldata[px];
@@ -209,7 +211,7 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
int had_extd = (gce->flags & GRID_FLAG_EXTENDED);
memcpy(gce, &grid_cleared_entry, sizeof *gce);
if (had_extd && old_offset < gl->extdsize) {
if (!moved && had_extd && old_offset < gl->extdsize) {
gce->flags |= GRID_FLAG_EXTENDED;
gce->offset = old_offset;
gee = grid_extended_cell(gl, gce, &grid_cleared_cell);
@@ -285,9 +287,8 @@ static void
grid_free_line(struct grid *gd, u_int py)
{
free(gd->linedata[py].celldata);
gd->linedata[py].celldata = NULL;
free(gd->linedata[py].extddata);
gd->linedata[py].extddata = NULL;
memset(&gd->linedata[py], 0, sizeof gd->linedata[py]);
}
/* Free several lines. */
@@ -332,9 +333,7 @@ void
grid_destroy(struct grid *gd)
{
grid_free_lines(gd, 0, gd->hsize + gd->sy);
free(gd->linedata);
free(gd);
}
@@ -414,12 +413,14 @@ grid_collect_history(struct grid *gd, int all)
void
grid_remove_history(struct grid *gd, u_int ny)
{
u_int yy;
u_int yy, start;
if (ny > gd->hsize)
return;
start = gd->hsize + gd->sy - ny;
for (yy = 0; yy < ny; yy++)
grid_free_line(gd, gd->hsize + gd->sy - 1 - yy);
grid_free_line(gd, start + yy);
memset(&gd->linedata[start], 0, ny * sizeof *gd->linedata);
gd->hsize -= ny;
}
@@ -495,7 +496,7 @@ static void
grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
{
struct grid_line *gl;
u_int xx, old_cellsize;
u_int xx;
gl = &gd->linedata[py];
if (sx <= gl->cellsize)
@@ -508,11 +509,14 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
else if (gd->sx > sx)
sx = gd->sx;
old_cellsize = gl->cellsize;
gl->celldata = xrecallocarray(gl->celldata, old_cellsize, sx,
gl->celldata = xreallocarray(gl->celldata, sx,
sizeof *gl->celldata);
for (xx = old_cellsize; xx < sx; xx++)
grid_clear_cell(gd, xx, py, bg);
if (gl->cellsize < sx) {
memset(gl->celldata + gl->cellsize, 0,
(sx - gl->cellsize) * sizeof *gl->celldata);
}
for (xx = gl->cellsize; xx < sx; xx++)
grid_clear_cell(gd, xx, py, bg, 0);
gl->cellsize = sx;
}
@@ -680,7 +684,7 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
grid_expand_line(gd, yy, px + ox, 8); /* default bg first */
for (xx = px; xx < px + ox; xx++)
grid_clear_cell(gd, xx, yy, bg);
grid_clear_cell(gd, xx, yy, bg, 0);
}
}
@@ -774,7 +778,7 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx,
for (xx = px; xx < px + nx; xx++) {
if (xx >= dx && xx < dx + nx)
continue;
grid_clear_cell(gd, xx, py, bg);
grid_clear_cell(gd, xx, py, bg, 1);
}
}
@@ -1114,7 +1118,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
if (gc.flags & GRID_FLAG_PADDING)
continue;
if (flags & GRID_STRING_WITH_SEQUENCES) {
if (lastgc != NULL && (flags & GRID_STRING_WITH_SEQUENCES)) {
grid_string_cells_code(*lastgc, &gc, code, sizeof code,
flags, s, &has_link);
codelen = strlen(code);

View File

@@ -1,325 +0,0 @@
/* $OpenBSD$ */
/*
* Copyright (c) 2026 Thomas Adam <thomas@xteddy.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
#include "tmux.h"
/*
* kitty_image stores the raw decoded pixel data and metadata from a kitty
* graphics protocol APC sequence. It is used to re-emit the sequence to the
* outer terminal on redraw.
*/
struct kitty_image {
/* Control-data fields parsed from the APC sequence. */
char action; /* a=: 'T'=transmit+display, 't', 'p', 'd' */
u_int format; /* f=: 32=RGBA, 24=RGB, 100=PNG */
char medium; /* t=: 'd'=direct, 'f'=file, 't'=tmp, 's'=shm */
u_int pixel_w; /* s=: source image pixel width */
u_int pixel_h; /* v=: source image pixel height */
u_int cols; /* c=: display columns (0=auto) */
u_int rows; /* r=: display rows (0=auto) */
u_int image_id; /* i=: image id (0=unassigned) */
u_int image_num; /* I=: image number */
u_int placement_id; /* p=: placement id */
u_int more; /* m=: 1=more chunks coming, 0=last */
u_int quiet; /* q=: suppress responses */
int z_index; /* z=: z-index */
char compression; /* o=: 'z'=zlib, 0=none */
char delete_what; /* d=: delete target (used with a=d) */
/* Cell size at the time of parsing (from the owning window). */
u_int xpixel;
u_int ypixel;
/* Original base64-encoded payload (concatenated across all chunks). */
char *encoded;
size_t encodedlen;
char *ctrl;
size_t ctrllen;
};
/*
* Parse control-data key=value pairs from a kitty APC sequence.
* Format: key=value,key=value,...
*/
static int
kitty_parse_control(const char *ctrl, size_t ctrllen, struct kitty_image *ki)
{
const char *p = ctrl, *end = ctrl + ctrllen, *errstr;
char key[4], val[32];
size_t klen, vlen;
while (p < end) {
klen = 0;
while (p < end && *p != '=' && klen < sizeof(key) - 1)
key[klen++] = *p++;
key[klen] = '\0';
if (p >= end || *p != '=')
return (-1);
p++;
vlen = 0;
while (p < end && *p != ',' && vlen < sizeof(val) - 1)
val[vlen++] = *p++;
val[vlen] = '\0';
if (p < end && *p == ',')
p++;
if (klen != 1)
continue;
switch (key[0]) {
case 'a':
ki->action = val[0];
break;
case 'f':
ki->format = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 't':
ki->medium = val[0];
break;
case 's':
ki->pixel_w = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'v':
ki->pixel_h = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'c':
ki->cols = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'r':
ki->rows = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'i':
ki->image_id = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'I':
ki->image_num = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'p':
ki->placement_id = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'm':
ki->more = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'q':
ki->quiet = strtonum(val, 0, UINT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'z':
ki->z_index = strtonum(val, INT_MIN, INT_MAX, &errstr);
if (errstr != NULL)
return (-1);
break;
case 'o':
ki->compression = val[0];
break;
case 'd':
ki->delete_what = val[0];
break;
}
}
return (0);
}
/*
* Parse a kitty APC body (after the leading 'G').
* Stores the original control string and base64 payload verbatim for
* pass-through re-emission to the outer terminal.
*/
struct kitty_image *
kitty_parse(const u_char *buf, size_t len, u_int xpixel, u_int ypixel)
{
struct kitty_image *ki;
const u_char *semi;
const char *ctrl;
size_t ctrllen, paylen;
if (len == 0)
return (NULL);
semi = memchr(buf, ';', len);
if (semi != NULL) {
ctrl = (const char *)buf;
ctrllen = semi - buf;
paylen = len - ctrllen - 1;
} else {
ctrl = (const char *)buf;
ctrllen = len;
paylen = 0;
}
ki = xcalloc(1, sizeof *ki);
ki->xpixel = xpixel;
ki->ypixel = ypixel;
ki->action = 'T';
ki->format = 32;
ki->medium = 'd';
if (kitty_parse_control(ctrl, ctrllen, ki) != 0) {
free(ki);
return (NULL);
}
if (paylen > 0) {
ki->encoded = xmalloc(paylen + 1);
memcpy(ki->encoded, semi + 1, paylen);
ki->encoded[paylen] = '\0';
ki->encodedlen = paylen;
}
ki->ctrl = xmalloc(ctrllen + 1);
memcpy(ki->ctrl, ctrl, ctrllen);
ki->ctrl[ctrllen] = '\0';
ki->ctrllen = ctrllen;
return (ki);
}
void
kitty_free(struct kitty_image *ki)
{
if (ki == NULL)
return;
free(ki->encoded);
free(ki->ctrl);
free(ki);
}
/*
* Get the size in cells of a kitty image. If cols/rows are 0 (auto),
* calculate from pixel dimensions. Returns size via sx/sy pointers.
*/
void
kitty_size_in_cells(struct kitty_image *ki, u_int *sx, u_int *sy)
{
*sx = ki->cols;
*sy = ki->rows;
/*
* If cols/rows are 0, they mean "auto" - calculate from
* pixel dimensions.
*/
if (*sx == 0 && ki->pixel_w > 0 && ki->xpixel > 0) {
*sx = (ki->pixel_w + ki->xpixel - 1) / ki->xpixel;
}
if (*sy == 0 && ki->pixel_h > 0 && ki->ypixel > 0) {
*sy = (ki->pixel_h + ki->ypixel - 1) / ki->ypixel;
}
/* If still 0, use a reasonable default */
if (*sx == 0)
*sx = 10;
if (*sy == 0)
*sy = 10;
}
char
kitty_get_action(struct kitty_image *ki)
{
return (ki->action);
}
u_int
kitty_get_image_id(struct kitty_image *ki)
{
return (ki->image_id);
}
u_int
kitty_get_rows(struct kitty_image *ki)
{
return (ki->rows);
}
/*
* Serialize a kitty_image back into an APC escape sequence for transmission
* to the terminal. This recreates the original command that was parsed.
*/
char *
kitty_print(struct kitty_image *ki, size_t *outlen)
{
char *out;
size_t total, pos;
if (ki == NULL || ki->ctrl == NULL)
return (NULL);
/* Calculate total length: ESC _ G + ctrl + ; + encoded + ESC \ */
total = 3 + ki->ctrllen; /* \033_G + ctrl */
if (ki->encoded != NULL && ki->encodedlen > 0) {
total += 1 + ki->encodedlen; /* ; + encoded */
}
total += 2; /* \033\\ */
out = xmalloc(total + 1);
*outlen = total;
/* Build the sequence */
pos = 0;
memcpy(out + pos, "\033_G", 3);
pos += 3;
memcpy(out + pos, ki->ctrl, ki->ctrllen);
pos += ki->ctrllen;
if (ki->encoded != NULL && ki->encodedlen > 0) {
out[pos++] = ';';
memcpy(out + pos, ki->encoded, ki->encodedlen);
pos += ki->encodedlen;
}
memcpy(out + pos, "\033\\", 2);
pos += 2;
out[pos] = '\0';
return (out);
}
char *
kitty_delete_all(size_t *outlen)
{
char *out;
out = xstrdup("\033_Ga=d,d=a\033\\");
*outlen = strlen(out);
return (out);
}

View File

@@ -122,19 +122,13 @@ sixel_set_pixel(struct sixel_image *si, u_int x, u_int y, u_int c)
static int
sixel_parse_write(struct sixel_image *si, u_int ch)
{
struct sixel_line *sl;
u_int i;
if (sixel_parse_expand_lines(si, si->dy + 6) != 0)
return (1);
sl = &si->lines[si->dy];
for (i = 0; i < 6; i++) {
if (sixel_parse_expand_line(si, sl, si->dx + 1) != 0)
return (1);
if (ch & (1 << i))
sl->data[si->dx] = si->dc;
sl++;
if (ch & (1 << i)) {
if (sixel_set_pixel(si, si->dx, si->dy + i, si->dc))
return (1);
}
}
return (0);
}
@@ -357,7 +351,7 @@ sixel_parse(const char *buf, size_t len, u_int p2, u_int xpixel, u_int ypixel)
return (si);
bad:
free(si);
sixel_free(si);
return (NULL);
}
@@ -487,9 +481,9 @@ static void
sixel_print_add(char **buf, size_t *len, size_t *used, const char *s,
size_t slen)
{
if (*used + slen >= *len + 1) {
while (*used + slen >= *len + 1) {
*buf = xreallocarray(*buf, 2, *len);
(*len) *= 2;
*buf = xrealloc(*buf, *len);
}
memcpy(*buf + *used, s, slen);
(*used) += slen;

119
image.c
View File

@@ -53,30 +53,13 @@ image_log(struct image *im, const char* from, const char* fmt, ...)
static void
image_free(struct image *im)
{
struct screen *s = im->s;
image_log(im, __func__, NULL);
TAILQ_REMOVE(&all_images, im, all_entry);
all_images_count--;
TAILQ_REMOVE(&s->images, im, entry);
switch (im->type) {
#ifdef ENABLE_SIXEL_IMAGES
case IMAGE_SIXEL:
sixel_free(im->data.sixel);
break;
#endif
#ifdef ENABLE_KITTY_IMAGES
case IMAGE_KITTY:
kitty_free(im->data.kitty);
break;
#endif
default:
break;
}
TAILQ_REMOVE(im->list, im, entry);
sixel_free(im->data);
free(im->fallback);
free(im);
}
@@ -96,30 +79,13 @@ image_free_all(struct screen *s)
/* Create text placeholder for an image. */
static void
image_fallback(char **ret, enum image_type type, u_int sx, u_int sy)
image_fallback(char **ret, u_int sx, u_int sy)
{
char *buf, *label;
u_int py, size, lsize;
const char *type_name;
switch (type) {
#ifdef ENABLE_SIXEL_IMAGES
case IMAGE_SIXEL:
type_name = "SIXEL";
break;
#endif
#ifdef ENABLE_KITTY_IMAGES
case IMAGE_KITTY:
type_name = "KITTY";
break;
#endif
default:
type_name = "UNKNOWN";
break;
}
/* Allocate first line. */
lsize = xasprintf(&label, "%s IMAGE (%ux%u)\r\n", type_name, sx, sy) + 1;
lsize = xasprintf(&label, "SIXEL IMAGE (%ux%u)\r\n", sx, sy) + 1;
if (sx < lsize - 3)
size = lsize - 1;
else
@@ -154,39 +120,23 @@ image_fallback(char **ret, enum image_type type, u_int sx, u_int sy)
}
struct image*
image_store(struct screen *s, enum image_type type, void *data)
image_store(struct screen *s, struct sixel_image *si)
{
struct image *im;
im = xcalloc(1, sizeof *im);
im->type = type;
im->s = s;
im->data = si;
im->px = s->cx;
im->py = s->cy;
sixel_size_in_cells(si, &im->sx, &im->sy);
switch (type) {
#ifdef ENABLE_SIXEL_IMAGES
case IMAGE_SIXEL:
im->data.sixel = data;
sixel_size_in_cells(im->data.sixel, &im->sx, &im->sy);
break;
#endif
#ifdef ENABLE_KITTY_IMAGES
case IMAGE_KITTY:
im->data.kitty = data;
kitty_size_in_cells(im->data.kitty, &im->sx, &im->sy);
break;
#endif
default:
break;
}
image_fallback(&im->fallback, type, im->sx, im->sy);
image_fallback(&im->fallback, im->sx, im->sy);
image_log(im, __func__, NULL);
TAILQ_INSERT_TAIL(&s->images, im, entry);
im->list = &s->images;
TAILQ_INSERT_TAIL(im->list, im, entry);
TAILQ_INSERT_TAIL(&all_images, im, all_entry);
if (++all_images_count == MAX_IMAGE_COUNT)
@@ -237,10 +187,8 @@ image_scroll_up(struct screen *s, u_int lines)
{
struct image *im, *im1;
int redraw = 0;
#ifdef ENABLE_SIXEL_IMAGES
struct sixel_image *new;
u_int sx, sy;
#endif
struct sixel_image *new;
TAILQ_FOREACH_SAFE(im, &s->images, entry, im1) {
if (im->py >= lines) {
@@ -255,43 +203,20 @@ image_scroll_up(struct screen *s, u_int lines)
redraw = 1;
continue;
}
sx = im->sx;
sy = (im->py + im->sy) - lines;
image_log(im, __func__, "3, lines=%u, sy=%u", lines, sy);
/* Image is partially scrolled off - need to crop it */
switch (im->type) {
#ifdef ENABLE_SIXEL_IMAGES
case IMAGE_SIXEL:
sx = im->sx;
sy = (im->py + im->sy) - lines;
image_log(im, __func__, "sixel, lines=%u, sy=%u",
lines, sy);
new = sixel_scale(im->data, 0, 0, 0, im->sy - sy, sx, sy, 1);
sixel_free(im->data);
im->data = new;
new = sixel_scale(im->data.sixel, 0, 0, 0, im->sy - sy,
sx, sy, 1);
sixel_free(im->data.sixel);
im->data.sixel = new;
im->py = 0;
sixel_size_in_cells(im->data, &im->sx, &im->sy);
im->py = 0;
sixel_size_in_cells(im->data.sixel, &im->sx, &im->sy);
free(im->fallback);
image_fallback(&im->fallback, im->type, im->sx, im->sy);
redraw = 1;
break;
#endif
#ifdef ENABLE_KITTY_IMAGES
case IMAGE_KITTY:
/*
* For kitty images, we can't rescale - the terminal
* owns the placement. Just adjust position and let
* the terminal handle clipping.
*/
im->py = 0;
redraw = 1;
break;
#endif
default:
break;
}
free(im->fallback);
image_fallback(&im->fallback, im->sx, im->sy);
redraw = 1;
}
return (redraw);
}

View File

@@ -673,8 +673,7 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key)
}
/* Ignore internal function key codes. */
if ((key >= KEYC_BASE && key < KEYC_BASE_END) ||
(key >= KEYC_USER && key < KEYC_USER_END)) {
if (KEYC_IS_USER(key) || KEYC_IS_SPECIAL(key) || KEYC_IS_MOUSE(key)) {
log_debug("%s: ignoring key 0x%llx", __func__, key);
return (0);
}

286
input.c
View File

@@ -64,7 +64,7 @@ struct input_request {
enum input_request_type type;
uint64_t t;
enum input_end_type end;
enum input_end_type end;
int idx;
void *data;
@@ -145,12 +145,11 @@ struct input_ctx {
*/
struct evbuffer *since_ground;
struct event ground_timer;
};
/* Helper functions. */
struct input_transition;
static void input_request_timer_callback(int, short, void *);
static void input_request_timer_callback(int, short, void *);
static void input_start_request_timer(struct input_ctx *);
static struct input_request *input_make_request(struct input_ctx *,
enum input_request_type);
@@ -165,6 +164,7 @@ static void input_reset_cell(struct input_ctx *);
static void input_report_current_theme(struct input_ctx *);
static void input_osc_4(struct input_ctx *, const char *);
static void input_osc_8(struct input_ctx *, const char *);
static void input_osc_9(struct input_ctx *, const char *);
static void input_osc_10(struct input_ctx *, const char *);
static void input_osc_11(struct input_ctx *, const char *);
static void input_osc_12(struct input_ctx *, const char *);
@@ -181,7 +181,6 @@ static void input_ground(struct input_ctx *);
static void input_enter_dcs(struct input_ctx *);
static void input_enter_osc(struct input_ctx *);
static void input_exit_osc(struct input_ctx *);
static int input_da1_has_sixel(struct input_ctx *);
static void input_enter_apc(struct input_ctx *);
static void input_exit_apc(struct input_ctx *);
static void input_enter_rename(struct input_ctx *);
@@ -282,6 +281,7 @@ enum input_csi_type {
INPUT_CSI_IL,
INPUT_CSI_MODOFF,
INPUT_CSI_MODSET,
INPUT_CSI_QUERY,
INPUT_CSI_QUERY_PRIVATE,
INPUT_CSI_RCP,
INPUT_CSI_REP,
@@ -337,6 +337,7 @@ static const struct input_table_entry input_csi_table[] = {
{ 'n', "", INPUT_CSI_DSR },
{ 'n', ">", INPUT_CSI_MODOFF },
{ 'n', "?", INPUT_CSI_DSR_PRIVATE },
{ 'p', "$", INPUT_CSI_QUERY },
{ 'p', "?$", INPUT_CSI_QUERY_PRIVATE },
{ 'q', " ", INPUT_CSI_DECSCUSR },
{ 'q', ">", INPUT_CSI_XDA },
@@ -951,7 +952,7 @@ input_set_state(struct input_ctx *ictx, const struct input_transition *itr)
/* Parse data. */
static void
input_parse(struct input_ctx *ictx, u_char *buf, size_t len)
input_parse(struct input_ctx *ictx, const u_char *buf, size_t len)
{
struct screen_write_ctx *sctx = &ictx->ctx;
const struct input_state *state = NULL;
@@ -1022,7 +1023,7 @@ input_parse_pane(struct window_pane *wp)
/* Parse given input. */
void
input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
input_parse_buffer(struct window_pane *wp, const u_char *buf, size_t len)
{
struct input_ctx *ictx = wp->ictx;
struct screen_write_ctx *sctx = &ictx->ctx;
@@ -1053,7 +1054,7 @@ input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
/* Parse given input for screen. */
void
input_parse_screen(struct input_ctx *ictx, struct screen *s,
screen_write_init_ctx_cb cb, void *arg, u_char *buf, size_t len)
screen_write_init_ctx_cb cb, void *arg, const u_char *buf, size_t len)
{
struct screen_write_ctx *sctx = &ictx->ctx;
@@ -1383,10 +1384,6 @@ input_esc_dispatch(struct input_ctx *ictx)
input_reset_cell(ictx);
screen_write_reset(sctx);
screen_write_fullredraw(sctx);
#ifdef ENABLE_KITTY_IMAGES
if (ictx->wp != NULL)
tty_kitty_delete_all_pane(ictx->wp);
#endif
break;
case INPUT_ESC_IND:
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg);
@@ -1562,10 +1559,11 @@ input_csi_dispatch(struct input_ctx *ictx)
case -1:
break;
case 0:
if (input_da1_has_sixel(ictx))
input_reply(ictx, 1, "\033[?1;2;4c");
else
input_reply(ictx, 1, "\033[?1;2c");
#ifdef ENABLE_SIXEL
input_reply(ictx, 1, "\033[?1;2;4c");
#else
input_reply(ictx, 1, "\033[?1;2c");
#endif
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
@@ -1612,8 +1610,34 @@ input_csi_dispatch(struct input_ctx *ictx)
break;
}
break;
case INPUT_CSI_QUERY:
m = input_get(ictx, 0, 0, 0);
switch (m) {
case 4: /* IRM */
n = (s->mode & MODE_INSERT) ? 1 : 2;
break;
default:
n = 0;
break;
}
if (m > 0)
input_reply(ictx, 1, "\033[%d;%d$y", m, n);
break;
case INPUT_CSI_QUERY_PRIVATE:
switch (input_get(ictx, 0, 0, 0)) {
m = input_get(ictx, 0, 0, 0);
switch (m) {
case 1: /* DECCKM */
n = (s->mode & MODE_KCURSOR) ? 1 : 2;
break;
case 3: /* DECCOLM: always reset */
n = 4;
break;
case 6: /* DECOM */
n = (s->mode & MODE_ORIGIN) ? 1 : 2;
break;
case 7: /* DECAWM */
n = (s->mode & MODE_WRAP) ? 1 : 2;
break;
case 12: /* cursor blink: 1 = blink, 2 = steady */
if (s->cstyle != SCREEN_CURSOR_DEFAULT ||
s->mode & MODE_CURSOR_BLINKING_SET)
@@ -1622,34 +1646,54 @@ input_csi_dispatch(struct input_ctx *ictx)
if (ictx->wp != NULL)
oo = ictx->wp->options;
else
oo = global_options;
oo = global_w_options;
p = options_get_number(oo, "cursor-style");
/* blink for 1,3,5; steady for 0,2,4,6 */
n = (p == 1 || p == 3 || p == 5) ? 1 : 2;
n = (p == 1 || p == 3 || p == 5) ? 1 : 2;
}
input_reply(ictx, 1, "\033[?12;%d$y", n);
break;
case 1004: /* focus reporting */
case 25: /* DECTCEM */
n = (s->mode & MODE_CURSOR) ? 1 : 2;
break;
case 47:
case 1047:
case 1049: /* alternate screen */
n = SCREEN_IS_ALTERNATE(s) ? 1 : 2;
break;
case 1000: /* mouse: normal tracking */
n = (s->mode & MODE_MOUSE_STANDARD) ? 1 : 2;
break;
case 1002: /* mouse: button-event tracking */
n = (s->mode & MODE_MOUSE_BUTTON) ? 1 : 2;
break;
case 1003: /* mouse: any-event tracking */
n = (s->mode & MODE_MOUSE_ALL) ? 1 : 2;
break;
case 1004: /* focus reporting */
n = (s->mode & MODE_FOCUSON) ? 1 : 2;
input_reply(ictx, 1, "\033[?1004;%d$y", n);
break;
case 1006: /* SGR mouse */
case 1005: /* mouse: UTF-8 */
n = (s->mode & MODE_MOUSE_UTF8) ? 1 : 2;
break;
case 1006: /* mouse: SGR */
n = (s->mode & MODE_MOUSE_SGR) ? 1 : 2;
input_reply(ictx, 1, "\033[?1006;%d$y", n);
break;
case 2004: /* bracketed paste */
case 2004: /* bracketed paste */
n = (s->mode & MODE_BRACKETPASTE) ? 1 : 2;
input_reply(ictx, 1, "\033[?2004;%d$y", n);
break;
case 2026: /* synchronized output */
case 2026: /* synchronized output */
n = (s->mode & MODE_SYNC) ? 1 : 2;
input_reply(ictx, 1, "\033[?2026;%d$y", n);
break;
case 2031:
input_reply(ictx, 1, "\033[?2031;2$y");
case 2031: /* theme update notifications */
n = (s->mode & MODE_THEME_UPDATES) ? 1 : 2;
break;
default:
n = 0;
break;
}
if (m > 0)
input_reply(ictx, 1, "\033[?%d;%d$y", m, n);
break;
case INPUT_CSI_DSR:
switch (input_get(ictx, 0, 0, 0)) {
@@ -1909,16 +1953,16 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
case 2004:
screen_write_mode_clear(sctx, MODE_BRACKETPASTE);
break;
case 2026:
screen_write_stop_sync(ictx->wp);
if (ictx->wp != NULL)
ictx->wp->flags |= PANE_REDRAW;
break;
case 2031:
screen_write_mode_clear(sctx, MODE_THEME_UPDATES);
if (ictx->wp != NULL)
ictx->wp->flags &= ~PANE_THEMECHANGED;
break;
case 2026: /* synchronized output */
screen_write_stop_sync(ictx->wp);
if (ictx->wp != NULL)
ictx->wp->flags |= PANE_REDRAW;
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
break;
@@ -2021,7 +2065,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
ictx->wp->flags &= ~PANE_THEMECHANGED;
}
break;
case 2026: /* synchronized output */
case 2026:
screen_write_start_sync(ictx->wp);
break;
default:
@@ -2035,7 +2079,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
static void
input_csi_dispatch_sm_graphics(__unused struct input_ctx *ictx)
{
#ifdef ENABLE_SIXEL_IMAGES
#ifdef ENABLE_SIXEL
int n, m, o;
if (ictx->param_list_len > 3)
@@ -2527,7 +2571,7 @@ input_handle_decrqss(struct input_ctx *ictx)
if (wp != NULL)
oo = wp->options;
else
oo = global_options;
oo = global_w_options;
opt_ps = options_get_number(oo, "cursor-style");
/* Sanity clamp: valid Ps are 0..6 per DECSCUSR. */
@@ -2560,24 +2604,25 @@ input_dcs_dispatch(struct input_ctx *ictx)
const char prefix[] = "tmux;";
const u_int prefixlen = (sizeof prefix) - 1;
long long allow_passthrough = 0;
#ifdef ENABLE_SIXEL_IMAGES
#ifdef ENABLE_SIXEL
struct window *w;
struct sixel_image *si;
int p2;
#endif
if (wp == NULL)
return (0);
oo = wp->options;
oo = global_w_options;
else
oo = wp->options;
if (ictx->flags & INPUT_DISCARD) {
log_debug("%s: %zu bytes (discard)", __func__, len);
return (0);
}
#ifdef ENABLE_SIXEL_IMAGES
w = wp->window;
if (buf[0] == 'q' && ictx->interm_len == 0) {
#ifdef ENABLE_SIXEL
if (wp != NULL && buf[0] == 'q' && ictx->interm_len == 0) {
w = wp->window;
if (input_split(ictx) != 0)
return (0);
p2 = input_get(ictx, 1, 0, 0);
@@ -2656,7 +2701,7 @@ input_exit_osc(struct input_ctx *ictx)
case 2:
if (wp != NULL &&
options_get_number(wp->options, "allow-set-title") &&
screen_set_title(sctx->s, p)) {
screen_set_title(sctx->s, p, 1)) {
notify_pane("pane-title-changed", wp);
server_redraw_window_borders(wp->window);
server_status_window(wp->window);
@@ -2666,17 +2711,17 @@ input_exit_osc(struct input_ctx *ictx)
input_osc_4(ictx, p);
break;
case 7:
if (utf8_isvalid(p)) {
screen_set_path(sctx->s, p);
if (wp != NULL) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window);
}
if (wp != NULL && screen_set_path(sctx->s, p, 1)) {
server_redraw_window_borders(wp->window);
server_status_window(wp->window);
}
break;
case 8:
input_osc_8(ictx, p);
break;
case 9:
input_osc_9(ictx, p);
break;
case 10:
input_osc_10(ictx, p);
break;
@@ -2721,79 +2766,6 @@ input_enter_apc(struct input_ctx *ictx)
ictx->flags &= ~INPUT_LAST;
}
/*
* Check if any client viewing this pane has an outer terminal that supports
* sixel, so we can report it in the DA1 response.
*/
static int
input_da1_has_sixel(__unused struct input_ctx *ictx)
{
#ifdef ENABLE_SIXEL_IMAGES
struct window_pane *wp = ictx->wp;
struct client *c;
if (wp == NULL)
return (0);
TAILQ_FOREACH(c, &clients, entry) {
if (c->session == NULL)
continue;
if (c->session->curw->window != wp->window)
continue;
if (c->tty.term->flags & TERM_SIXEL)
return (1);
}
#endif
return (0);
}
#ifdef ENABLE_KITTY_IMAGES
/* Handle a kitty graphics APC sequence. */
static void
input_apc_kitty_image(struct input_ctx *ictx)
{
struct screen_write_ctx *sctx = &ictx->ctx;
struct window_pane *wp = ictx->wp;
struct window *w;
struct kitty_image *ki;
if (wp == NULL)
return;
w = wp->window;
ki = kitty_parse(ictx->input_buf + 1, ictx->input_len - 1,
w->xpixel, w->ypixel);
if (ki == NULL)
return;
/* Handle query commands. */
if (kitty_get_action(ki) == 'q') {
if (kitty_get_image_id(ki) != 0)
input_reply(ictx, 0, "\033_Gi=%u;OK\033\\",
kitty_get_image_id(ki));
else
input_reply(ictx, 0, "\033_Ga=q;OK\033\\");
kitty_free(ki);
return;
}
/* Store image placements and trigger a redraw. */
if (kitty_get_action(ki) == 'T' || kitty_get_action(ki) == 't' ||
kitty_get_action(ki) == 'p') {
screen_write_kittyimage(sctx, ki);
} else {
/* For other actions (delete, etc.), pass through. */
char *apc;
size_t apclen;
apclen = xasprintf(&apc, "\033_%s\033\\", ictx->input_buf);
tty_kitty_passthrough(wp, apc, apclen, sctx->s->cx,
sctx->s->cy);
free(apc);
kitty_free(ki);
}
}
#endif
/* APC terminator (ST) received. */
static void
input_exit_apc(struct input_ctx *ictx)
@@ -2805,16 +2777,9 @@ input_exit_apc(struct input_ctx *ictx)
return;
log_debug("%s: \"%s\"", __func__, ictx->input_buf);
#ifdef ENABLE_KITTY_IMAGES
if (ictx->input_len >= 1 && ictx->input_buf[0] == 'G') {
input_apc_kitty_image(ictx);
return;
}
#endif
if (wp != NULL &&
options_get_number(wp->options, "allow-set-title") &&
screen_set_title(sctx->s, ictx->input_buf)) {
screen_set_title(sctx->s, ictx->input_buf, 1)) {
notify_pane("pane-title-changed", wp);
server_redraw_window_borders(wp->window);
server_status_window(wp->window);
@@ -2857,10 +2822,10 @@ input_exit_rename(struct input_ctx *ictx)
if (o != NULL)
options_remove_or_default(o, -1, NULL);
if (!options_get_number(w->options, "automatic-rename"))
window_set_name(w, "");
window_set_name(w, "", 1);
} else {
options_set_number(w->options, "automatic-rename", 0);
window_set_name(w, ictx->input_buf);
window_set_name(w, ictx->input_buf, 1);
}
server_redraw_window_borders(w);
server_status_window(w);
@@ -3025,6 +2990,57 @@ bad:
free(id);
}
/* Helper to handle setting the progress bar and redrawing. */
static void
input_set_progress_bar(struct input_ctx *ictx, enum progress_bar_state state,
int p)
{
screen_set_progress_bar(ictx->ctx.s, state, p);
if (ictx->wp != NULL) {
server_redraw_window_borders(ictx->wp->window);
server_status_window(ictx->wp->window);
}
}
/* Handle the OSC 9;4 sequence for progress bars. */
static void
input_osc_9(struct input_ctx *ictx, const char *p)
{
const char *pb = p;
enum progress_bar_state state;
int progress = 0;
if (*pb++ != '4')
return;
if (*pb == '\0' || (*pb == ';' && pb[1] == '\0'))
return;
if (*pb++ != ';')
return;
if (*pb < '0' || *pb > '4')
goto bad;
state = *pb++ - '0';
if (*pb == '\0' || (*pb == ';' && pb[1] == '\0')) {
input_set_progress_bar(ictx, state, -1);
return;
}
if (*pb++ != ';')
goto bad;
while (*pb >= '0' && *pb <= '9') {
if (progress > 100)
goto bad;
progress = progress * 10 + *pb++ - '0';
}
if (*pb != '\0' || progress < 0 || progress > 100)
goto bad;
input_set_progress_bar(ictx, state, progress);
return;
bad:
log_debug("bad OSC 9;4 %s", p);
}
/* Handle the OSC 10 sequence for setting and querying foreground colour. */
static void
@@ -3235,7 +3251,7 @@ input_osc_52_parse(struct input_ctx *ictx, const char *p, u_char **out,
return (0);
}
len = (strlen(end) / 4) * 3;
len = ((strlen(end) + 3) / 4) * 3;
if (len == 0)
return (0);
@@ -3254,7 +3270,7 @@ static void
input_osc_52(struct input_ctx *ictx, const char *p)
{
struct window_pane *wp = ictx->wp;
struct screen_write_ctx ctx;
struct screen_write_ctx ctx;
u_char *out;
int outlen;
char clip[sizeof "cpqs01234567"] = "";

View File

@@ -29,7 +29,8 @@
" 'Previous' 'p' {switch-client -p}" \
" ''" \
" 'Renumber' 'N' {move-window -r}" \
" 'Rename' 'n' {command-prompt -I \"#S\" {rename-session -- '%%'}}" \
" 'Rename' 'r' {command-prompt -I \"#S\" {rename-session -- '%%'}}" \
" 'Detach' 'd' {detach-client}" \
" ''" \
" 'New Session' 's' {new-session}" \
" 'New Window' 'w' {new-window}"
@@ -59,11 +60,11 @@
" '#{?mouse_hyperlink,Type #[underscore]#{=/9/...:mouse_hyperlink},}' 'C-h' {copy-mode -q; send-keys -l -- \"#{q:mouse_hyperlink}\"}" \
" '#{?mouse_hyperlink,Copy #[underscore]#{=/9/...:mouse_hyperlink},}' 'h' {copy-mode -q; set-buffer -- \"#{q:mouse_hyperlink}\"}" \
" ''" \
" 'Horizontal Split' 'h' {split-window -h}" \
" 'Vertical Split' 'v' {split-window -v}" \
" '#{?#{!:#{pane_floating_flag}},Horizontal Split,}' 'h' {split-window -h}" \
" '#{?#{!:#{pane_floating_flag}},Vertical Split,}' 'v' {split-window -v}" \
" ''" \
" '#{?#{>:#{window_panes},1},,-}Swap Up' 'u' {swap-pane -U}" \
" '#{?#{>:#{window_panes},1},,-}Swap Down' 'd' {swap-pane -D}" \
" '#{?#{&&:#{!:#{pane_floating_flag}},#{>:#{window_panes},1}},Swap Up,}' 'u' {swap-pane -U}" \
" '#{?#{&&:#{!:#{pane_floating_flag}},#{>:#{window_panes},1}},Swap Down,}' 'd' {swap-pane -D}" \
" '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \
" ''" \
" 'Kill' 'X' {kill-pane}" \
@@ -361,6 +362,7 @@ key_bindings_init(void)
"bind -N 'Split window horizontally' % { split-window -h }",
"bind -N 'Kill current window' & { confirm-before -p\"kill-window #W? (y/n)\" kill-window }",
"bind -N 'Prompt for window index to select' \"'\" { command-prompt -T window-target -pindex { select-window -t ':%%' } }",
"bind -N 'New floating pane' * { new-pane }",
"bind -N 'Switch to previous client' ( { switch-client -p }",
"bind -N 'Switch to next client' ) { switch-client -n }",
"bind -N 'Rename current window' , { command-prompt -I'#W' { rename-window -- '%%' } }",
@@ -459,6 +461,9 @@ key_bindings_init(void)
/* Mouse button 1 triple click on pane. */
"bind -n TripleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel } }",
/* Mouse button 1 on border. */
"bind -n MouseDown1Border { select-pane -M }",
/* Mouse button 1 drag on border. */
"bind -n MouseDrag1Border { resize-pane -M }",
@@ -466,6 +471,10 @@ key_bindings_init(void)
"bind -n MouseDown1Status { switch-client -t= }",
"bind -n C-MouseDown1Status { swap-window -t@ }",
/* Mouse button 1 down on default pane-border-format */
"bind -n MouseDown1Control9 { display-menu -t= -xM -yM -O -T 'Kill pane #{pane_index}?' 'Yes' 'y' { kill-pane -t= } 'No' 'n' {}}",
"bind -n MouseDown1Control8 { resize-pane -Z }",
/* Mouse wheel down on status line. */
"bind -n WheelDownStatus { next-window }",
@@ -498,7 +507,7 @@ key_bindings_init(void)
"bind -Tcopy-mode C-b { send -X cursor-left }",
"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-l { send -X cursor-centre-vertical }",
"bind -Tcopy-mode C-l { send -X recentre-top-bottom }",
"bind -Tcopy-mode M-l { send -X cursor-centre-horizontal }",
"bind -Tcopy-mode C-n { send -X cursor-down }",
"bind -Tcopy-mode C-p { send -X cursor-up }",
@@ -507,6 +516,7 @@ key_bindings_init(void)
"bind -Tcopy-mode C-v { send -X page-down }",
"bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }",
"bind -Tcopy-mode Escape { send -X cancel }",
"bind -Tcopy-mode C-[ { send -X cancel }",
"bind -Tcopy-mode Space { send -X page-down }",
"bind -Tcopy-mode , { send -X jump-reverse }",
"bind -Tcopy-mode \\; { send -X jump-again }",
@@ -580,6 +590,7 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi C-v { send -X rectangle-toggle }",
"bind -Tcopy-mode-vi C-y { send -X scroll-up }",
"bind -Tcopy-mode-vi Escape { send -X clear-selection }",
"bind -Tcopy-mode-vi C-[ { send -X clear-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 jump-reverse }",

View File

@@ -202,7 +202,7 @@ key_string_search_table(const char *string)
return (key_string_table[i].key);
}
if (sscanf(string, "User%u", &user) == 1 && user < KEYC_NUSER)
if (sscanf(string, "User%u", &user) == 1 && user <= KEYC_NUSER)
return (KEYC_USER + user);
return (KEYC_UNKNOWN);
@@ -418,7 +418,7 @@ key_string_lookup_key(key_code key, int with_flags)
s = "MouseMoveBorder";
goto append;
}
if (key >= KEYC_USER && key < KEYC_USER_END) {
if (KEYC_IS_USER(key)) {
snprintf(tmp, sizeof tmp, "User%u", (u_int)(key - KEYC_USER));
strlcat(out, tmp, sizeof out);
goto out;

View File

@@ -27,10 +27,10 @@ static struct layout_cell *layout_find_bottomright(struct layout_cell *);
static u_short layout_checksum(const char *);
static int layout_append(struct layout_cell *, char *,
size_t);
static struct layout_cell *layout_construct(struct layout_cell *,
const char **);
static int layout_construct(struct layout_cell *,
const char **, struct layout_cell **);
static void layout_assign(struct window_pane **,
struct layout_cell *);
struct layout_cell *, int);
/* Find the bottom-right cell. */
static struct layout_cell *
@@ -58,14 +58,30 @@ layout_checksum(const char *layout)
/* Dump layout as a string. */
char *
layout_dump(struct layout_cell *root)
layout_dump(struct window *w, struct layout_cell *root)
{
char layout[8192], *out;
char layout[8192], *out;
int bracket = 0;
struct window_pane *wp;
*layout = '\0';
if (layout_append(root, layout, sizeof layout) != 0)
return (NULL);
TAILQ_FOREACH(wp, &w->z_index, zentry) {
if (!window_pane_is_floating(wp))
break;
if (!bracket) {
strlcat(layout, "<", sizeof layout);
bracket = 1;
}
if (layout_append(wp->layout_cell, layout, sizeof layout) != 0)
return (NULL);
strlcat(layout, ",", sizeof layout);
}
if (bracket)
layout[strlen(layout) - 1] = '>';
xasprintf(&out, "%04hx,%s", layout_checksum(layout), layout);
return (out);
}
@@ -81,12 +97,13 @@ layout_append(struct layout_cell *lc, char *buf, size_t len)
if (len == 0)
return (-1);
if (lc == NULL)
return (0);
if (lc->wp != NULL) {
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%u,%u,%u",
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d,%u",
lc->sx, lc->sy, lc->xoff, lc->yoff, lc->wp->id);
} else {
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%u,%u",
tmplen = xsnprintf(tmp, sizeof tmp, "%ux%u,%d,%d",
lc->sx, lc->sy, lc->xoff, lc->yoff);
}
if (tmplen > (sizeof tmp) - 1)
@@ -156,37 +173,43 @@ layout_check(struct layout_cell *lc)
int
layout_parse(struct window *w, const char *layout, char **cause)
{
struct layout_cell *lc, *lcchild;
struct layout_cell *lcchild, *tiled_lc = NULL;
struct window_pane *wp;
u_int npanes, ncells, sx = 0, sy = 0;
u_short csum;
int n;
/* Check validity. */
if (sscanf(layout, "%hx,", &csum) != 1) {
if (sscanf(layout, "%hx,%n", &csum, &n) != 1 || n != 5) {
*cause = xstrdup("invalid layout");
return (-1);
}
layout += 5;
layout += n;
if (csum != layout_checksum(layout)) {
*cause = xstrdup("invalid layout");
return (-1);
}
/* Build the layout. */
lc = layout_construct(NULL, &layout);
if (lc == NULL) {
if (layout_construct(NULL, &layout, &tiled_lc) != 0) {
*cause = xstrdup("invalid layout");
return (-1);
}
if (tiled_lc == NULL) {
/* A stub layout cell for an empty window. */
tiled_lc = layout_create_cell(NULL);
tiled_lc->type = LAYOUT_LEFTRIGHT;
layout_set_size(tiled_lc, w->sx, w->sy, 0, 0);
}
if (*layout != '\0') {
*cause = xstrdup("invalid layout");
goto fail;
}
/* Check this window will fit into the layout. */
npanes = window_count_panes(w, 1);
for (;;) {
npanes = window_count_panes(w);
ncells = layout_count_cells(lc);
ncells = layout_count_cells(tiled_lc);
if (npanes > ncells) {
xasprintf(cause, "have %u panes but need %u", npanes,
ncells);
@@ -195,9 +218,12 @@ layout_parse(struct window *w, const char *layout, char **cause)
if (npanes == ncells)
break;
/* Fewer panes than cells - close the bottom right. */
lcchild = layout_find_bottomright(lc);
layout_destroy_cell(w, lcchild, &lc);
/*
* Fewer panes than cells, close the bottom right until none
* remain.
*/
lcchild = layout_find_bottomright(tiled_lc);
layout_destroy_cell(w, lcchild, &tiled_lc);
}
/*
@@ -205,91 +231,104 @@ layout_parse(struct window *w, const char *layout, char **cause)
* an incorrect top cell size - if it is larger than the top child then
* correct that (if this is still wrong the check code will catch it).
*/
switch (lc->type) {
switch (tiled_lc->type) {
case LAYOUT_WINDOWPANE:
break;
case LAYOUT_LEFTRIGHT:
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
TAILQ_FOREACH(lcchild, &tiled_lc->cells, entry) {
sy = lcchild->sy + 1;
sx += lcchild->sx + 1;
}
break;
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
TAILQ_FOREACH(lcchild, &tiled_lc->cells, entry) {
sx = lcchild->sx + 1;
sy += lcchild->sy + 1;
}
break;
}
if (lc->type != LAYOUT_WINDOWPANE && (lc->sx != sx || lc->sy != sy)) {
log_debug("fix layout %u,%u to %u,%u", lc->sx, lc->sy, sx,sy);
layout_print_cell(lc, __func__, 0);
lc->sx = sx - 1; lc->sy = sy - 1;
if (tiled_lc->type != LAYOUT_WINDOWPANE &&
(tiled_lc->sx != sx || tiled_lc->sy != sy)) {
layout_print_cell(tiled_lc, __func__, 0);
tiled_lc->sx = sx - 1; tiled_lc->sy = sy - 1;
}
/* Check the new layout. */
if (!layout_check(lc)) {
if (!layout_check(tiled_lc)) {
*cause = xstrdup("size mismatch after applying layout");
goto fail;
}
/* Resize to the layout size. */
window_resize(w, lc->sx, lc->sy, -1, -1);
/* Resize window to the layout size. */
if (sx != 0 && sy != 0)
window_resize(w, tiled_lc->sx, tiled_lc->sy, -1, -1);
/* Destroy the old layout and swap to the new. */
layout_free_cell(w->layout_root);
w->layout_root = lc;
w->layout_root = tiled_lc;
/* Assign the panes into the cells. */
wp = TAILQ_FIRST(&w->panes);
layout_assign(&wp, lc);
if (tiled_lc != NULL)
layout_assign(&wp, tiled_lc, 0);
/* Fix pane z-indexes. */
while (!TAILQ_EMPTY(&w->z_index)) {
wp = TAILQ_FIRST(&w->z_index);
TAILQ_REMOVE(&w->z_index, wp, zentry);
}
layout_fix_zindexes(w, tiled_lc);
/* Update pane offsets and sizes. */
layout_fix_offsets(w);
layout_fix_panes(w, NULL);
recalculate_sizes();
layout_print_cell(lc, __func__, 0);
layout_print_cell(tiled_lc, __func__, 0);
notify_window("window-layout-changed", w);
return (0);
fail:
layout_free_cell(lc);
layout_free_cell(tiled_lc);
return (-1);
}
/* Assign panes into cells. */
static void
layout_assign(struct window_pane **wp, struct layout_cell *lc)
layout_assign(struct window_pane **wp, struct layout_cell *lc, int flags)
{
struct layout_cell *lcchild;
if (lc == NULL)
return;
switch (lc->type) {
case LAYOUT_WINDOWPANE:
layout_make_leaf(lc, *wp);
lc->flags |= flags;
*wp = TAILQ_NEXT(*wp, entry);
return;
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry)
layout_assign(wp, lcchild);
layout_assign(wp, lcchild, flags);
return;
}
}
/* Construct a cell from all or part of a layout tree. */
static struct layout_cell *
layout_construct(struct layout_cell *lcparent, const char **layout)
layout_construct_cell(struct layout_cell *lcparent, const char **layout)
{
struct layout_cell *lc, *lcchild;
u_int sx, sy, xoff, yoff;
struct layout_cell *lc;
u_int sx, sy;
int xoff, yoff;
const char *saved;
if (!isdigit((u_char) **layout))
return (NULL);
if (sscanf(*layout, "%ux%u,%u,%u", &sx, &sy, &xoff, &yoff) != 4)
if (sscanf(*layout, "%ux%u,%d,%d", &sx, &sy, &xoff, &yoff) != 4)
return (NULL);
while (isdigit((u_char) **layout))
@@ -324,17 +363,35 @@ layout_construct(struct layout_cell *lcparent, const char **layout)
lc->xoff = xoff;
lc->yoff = yoff;
return (lc);
}
/*
* Given a character string layout, recursively construct cells.
* Possible return values:
* lc LAYOUT_WINDOWPANE, no children
* lc LAYOUT_LEFTRIGHT or LAYOUT_TOPBOTTOM, with children
*/
static int
layout_construct(struct layout_cell *lcparent, const char **layout,
struct layout_cell **lc)
{
struct layout_cell *lcchild;
*lc = layout_construct_cell(lcparent, layout);
switch (**layout) {
case ',':
case '}':
case ']':
case '>':
case '\0':
return (lc);
return (0);
case '{':
lc->type = LAYOUT_LEFTRIGHT;
(*lc)->type = LAYOUT_LEFTRIGHT;
break;
case '[':
lc->type = LAYOUT_TOPBOTTOM;
(*lc)->type = LAYOUT_TOPBOTTOM;
break;
default:
goto fail;
@@ -342,13 +399,12 @@ layout_construct(struct layout_cell *lcparent, const char **layout)
do {
(*layout)++;
lcchild = layout_construct(lc, layout);
if (lcchild == NULL)
if (layout_construct(*lc, layout, &lcchild) != 0)
goto fail;
TAILQ_INSERT_TAIL(&lc->cells, lcchild, entry);
TAILQ_INSERT_TAIL(&(*lc)->cells, lcchild, entry);
} while (**layout == ',');
switch (lc->type) {
switch ((*lc)->type) {
case LAYOUT_LEFTRIGHT:
if (**layout != '}')
goto fail;
@@ -362,9 +418,9 @@ layout_construct(struct layout_cell *lcparent, const char **layout)
}
(*layout)++;
return (lc);
return (0);
fail:
layout_free_cell(lc);
return (NULL);
layout_free_cell(*lc);
return (-1);
}

View File

@@ -123,6 +123,18 @@ layout_set_previous(struct window *w)
return (layout);
}
static struct window_pane *
layout_first_tiled(struct window *w)
{
struct window_pane *wp;
TAILQ_FOREACH(wp, &w->panes, entry) {
if (!window_pane_is_floating(wp))
return (wp);
}
return (NULL);
}
static void
layout_set_even(struct window *w, enum layout_type type)
{
@@ -133,7 +145,7 @@ layout_set_even(struct window *w, enum layout_type type)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
@@ -156,6 +168,8 @@ layout_set_even(struct window *w, enum layout_type type)
/* Build new leaf cells. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (window_pane_is_floating(wp))
continue;
lcnew = layout_create_cell(lc);
layout_make_leaf(lcnew, wp);
lcnew->sx = w->sx;
@@ -201,7 +215,7 @@ layout_set_main_h(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -250,14 +264,16 @@ layout_set_main_h(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, sx, mainh, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Create the other pane. */
lcother = layout_create_cell(lc);
layout_set_size(lcother, sx, otherh, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -266,7 +282,9 @@ layout_set_main_h(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (window_pane_is_floating(wp))
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
@@ -299,7 +317,7 @@ layout_set_main_h_mirrored(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -349,7 +367,9 @@ layout_set_main_h_mirrored(struct window *w)
lcother = layout_create_cell(lc);
layout_set_size(lcother, sx, otherh, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -358,7 +378,9 @@ layout_set_main_h_mirrored(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (window_pane_is_floating(wp))
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
@@ -371,7 +393,7 @@ layout_set_main_h_mirrored(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, sx, mainh, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Fix cell offsets. */
@@ -397,7 +419,7 @@ layout_set_main_v(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -446,14 +468,16 @@ layout_set_main_v(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, mainw, sy, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Create the other pane. */
lcother = layout_create_cell(lc);
layout_set_size(lcother, otherw, sy, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -462,7 +486,9 @@ layout_set_main_v(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (window_pane_is_floating(wp))
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
@@ -495,7 +521,7 @@ layout_set_main_v_mirrored(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
n--; /* take off main pane */
@@ -545,7 +571,9 @@ layout_set_main_v_mirrored(struct window *w)
lcother = layout_create_cell(lc);
layout_set_size(lcother, otherw, sy, 0, 0);
if (n == 1) {
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
wp = TAILQ_NEXT(layout_first_tiled(w), entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
layout_make_leaf(lcother, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
} else {
@@ -554,7 +582,9 @@ layout_set_main_v_mirrored(struct window *w)
/* Add the remaining panes as children. */
TAILQ_FOREACH(wp, &w->panes, entry) {
if (wp == TAILQ_FIRST(&w->panes))
if (window_pane_is_floating(wp))
continue;
if (wp == layout_first_tiled(w))
continue;
lcchild = layout_create_cell(lcother);
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
@@ -567,7 +597,7 @@ layout_set_main_v_mirrored(struct window *w)
/* Create the main pane. */
lcmain = layout_create_cell(lc);
layout_set_size(lcmain, mainw, sy, 0, 0);
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
layout_make_leaf(lcmain, layout_first_tiled(w));
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
/* Fix cell offsets. */
@@ -593,7 +623,7 @@ layout_set_tiled(struct window *w)
layout_print_cell(w->layout_root, __func__, 1);
/* Get number of panes. */
n = window_count_panes(w);
n = window_count_panes(w, 0);
if (n <= 1)
return;
@@ -629,8 +659,10 @@ layout_set_tiled(struct window *w)
layout_set_size(lc, sx, sy, 0, 0);
layout_make_node(lc, LAYOUT_TOPBOTTOM);
/* Create a grid of the cells. */
/* Create a grid of the cells, skipping any floating panes. */
wp = TAILQ_FIRST(&w->panes);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
for (j = 0; j < rows; j++) {
/* If this is the last cell, all done. */
if (wp == NULL)
@@ -645,6 +677,8 @@ layout_set_tiled(struct window *w)
if (n - (j * columns) == 1 || columns == 1) {
layout_make_leaf(lcrow, wp);
wp = TAILQ_NEXT(wp, entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
continue;
}
@@ -657,8 +691,11 @@ layout_set_tiled(struct window *w)
layout_make_leaf(lcchild, wp);
TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry);
/* Move to the next cell. */
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
/* Move to the next non-floating cell. */
wp = TAILQ_NEXT(wp, entry);
while (wp != NULL && window_pane_is_floating(wp))
wp = TAILQ_NEXT(wp, entry);
if (wp == NULL)
break;
}

355
layout.c
View File

@@ -47,6 +47,7 @@ static int layout_set_size_check(struct window *, struct layout_cell *,
static void layout_resize_child_cells(struct window *,
struct layout_cell *);
/* Create a new layout cell. */
struct layout_cell *
layout_create_cell(struct layout_cell *lcparent)
{
@@ -54,6 +55,7 @@ layout_create_cell(struct layout_cell *lcparent)
lc = xmalloc(sizeof *lc);
lc->type = LAYOUT_WINDOWPANE;
lc->flags = 0;
lc->parent = lcparent;
TAILQ_INIT(&lc->cells);
@@ -61,19 +63,23 @@ layout_create_cell(struct layout_cell *lcparent)
lc->sx = UINT_MAX;
lc->sy = UINT_MAX;
lc->xoff = UINT_MAX;
lc->yoff = UINT_MAX;
lc->xoff = INT_MAX;
lc->yoff = INT_MAX;
lc->wp = NULL;
return (lc);
}
/* Free a layout cell. */
void
layout_free_cell(struct layout_cell *lc)
{
struct layout_cell *lcchild;
if (lc == NULL)
return;
switch (lc->type) {
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
@@ -84,20 +90,26 @@ layout_free_cell(struct layout_cell *lc)
}
break;
case LAYOUT_WINDOWPANE:
if (lc->wp != NULL)
if (lc->wp != NULL) {
lc->wp->layout_cell->parent = NULL;
lc->wp->layout_cell = NULL;
}
break;
}
free(lc);
}
/* Log a cell. */
void
layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
{
struct layout_cell *lcchild;
const char *type;
if (lc == NULL)
return;
switch (lc->type) {
case LAYOUT_LEFTRIGHT:
type = "LEFTRIGHT";
@@ -112,28 +124,31 @@ layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
type = "UNKNOWN";
break;
}
log_debug("%s:%*s%p type %s [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
log_debug("%s:%*s%p type %s [parent %p] wp=%p [%d,%d %ux%u]", hdr, n,
" ", lc, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
lc->sy);
switch (lc->type) {
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry)
layout_print_cell(lcchild, hdr, n + 1);
layout_print_cell(lcchild, hdr, n + 1);
break;
case LAYOUT_WINDOWPANE:
break;
}
}
/* Search for a cell by the border position. */
struct layout_cell *
layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
{
struct layout_cell *lcchild, *last = NULL;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx &&
y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) {
if ((int)x >= lcchild->xoff &&
(int)x < lcchild->xoff + (int)lcchild->sx &&
(int)y >= lcchild->yoff &&
(int)y < lcchild->yoff + (int)lcchild->sy) {
/* Inside the cell - recurse. */
return (layout_search_by_border(lcchild, x, y));
}
@@ -145,11 +160,13 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
switch (lc->type) {
case LAYOUT_LEFTRIGHT:
if (x < lcchild->xoff && x >= last->xoff + last->sx)
if ((int)x < lcchild->xoff &&
(int)x >= last->xoff + (int)last->sx)
return (last);
break;
case LAYOUT_TOPBOTTOM:
if (y < lcchild->yoff && y >= last->yoff + last->sy)
if ((int)y < lcchild->yoff &&
(int)y >= last->yoff + (int)last->sy)
return (last);
break;
case LAYOUT_WINDOWPANE:
@@ -162,9 +179,9 @@ layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
return (NULL);
}
/* Set cell size. */
void
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
u_int yoff)
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, int xoff, int yoff)
{
lc->sx = sx;
lc->sy = sy;
@@ -173,6 +190,7 @@ layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
lc->yoff = yoff;
}
/* Make a cell a leaf cell. */
void
layout_make_leaf(struct layout_cell *lc, struct window_pane *wp)
{
@@ -184,6 +202,7 @@ layout_make_leaf(struct layout_cell *lc, struct window_pane *wp)
lc->wp = wp;
}
/* Make a cell a node cell. */
void
layout_make_node(struct layout_cell *lc, enum layout_type type)
{
@@ -198,16 +217,41 @@ layout_make_node(struct layout_cell *lc, enum layout_type type)
lc->wp = NULL;
}
/* Fix z-indexes. */
void
layout_fix_zindexes(struct window *w, struct layout_cell *lc)
{
struct layout_cell *lcchild;
if (lc == NULL)
return;
switch (lc->type) {
case LAYOUT_WINDOWPANE:
TAILQ_INSERT_TAIL(&w->z_index, lc->wp, zentry);
break;
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
TAILQ_FOREACH(lcchild, &lc->cells, entry)
layout_fix_zindexes(w, lcchild);
return;
default:
fatalx("bad layout type");
}
}
/* Fix cell offsets for a child cell. */
static void
layout_fix_offsets1(struct layout_cell *lc)
{
struct layout_cell *lcchild;
u_int xoff, yoff;
int xoff, yoff;
if (lc->type == LAYOUT_LEFTRIGHT) {
xoff = lc->xoff;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
lcchild->xoff = xoff;
lcchild->yoff = lc->yoff;
if (lcchild->type != LAYOUT_WINDOWPANE)
@@ -217,6 +261,8 @@ layout_fix_offsets1(struct layout_cell *lc)
} else {
yoff = lc->yoff;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
lcchild->xoff = lc->xoff;
lcchild->yoff = yoff;
if (lcchild->type != LAYOUT_WINDOWPANE)
@@ -230,7 +276,11 @@ layout_fix_offsets1(struct layout_cell *lc)
void
layout_fix_offsets(struct window *w)
{
struct layout_cell *lc = w->layout_root;
struct layout_cell *lc = w->layout_root;
/* Root consists of a single floating cell */
if (lc->flags & LAYOUT_CELL_FLOATING)
return;
lc->xoff = 0;
lc->yoff = 0;
@@ -242,13 +292,22 @@ layout_fix_offsets(struct window *w)
static int
layout_cell_is_top(struct window *w, struct layout_cell *lc)
{
struct layout_cell *next;
struct layout_cell *next, *edge;
while (lc != w->layout_root) {
next = lc->parent;
if (next->type == LAYOUT_TOPBOTTOM &&
lc != TAILQ_FIRST(&next->cells))
if (next == NULL)
return (0);
if (next->type == LAYOUT_TOPBOTTOM) {
edge = TAILQ_FIRST(&next->cells);
while (edge != NULL) {
if (~edge->flags & LAYOUT_CELL_FLOATING)
break;
edge = TAILQ_NEXT(edge, entry);
}
if (lc != edge)
return (0);
}
lc = next;
}
return (1);
@@ -258,13 +317,22 @@ layout_cell_is_top(struct window *w, struct layout_cell *lc)
static int
layout_cell_is_bottom(struct window *w, struct layout_cell *lc)
{
struct layout_cell *next;
struct layout_cell *next, *edge;
while (lc != w->layout_root) {
next = lc->parent;
if (next->type == LAYOUT_TOPBOTTOM &&
lc != TAILQ_LAST(&next->cells, layout_cells))
if (next == NULL)
return (0);
if (next->type == LAYOUT_TOPBOTTOM) {
edge = TAILQ_LAST(&next->cells, layout_cells);
while (edge != NULL) {
if (~edge->flags & LAYOUT_CELL_FLOATING)
break;
edge = TAILQ_PREV(edge, layout_cells, entry);
}
if (lc != edge)
return (0);
}
lc = next;
}
return (1);
@@ -291,12 +359,10 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
{
struct window_pane *wp;
struct layout_cell *lc;
int status, scrollbars, sb_pos, sb_w, sb_pad;
int status, sb_w, sb_pad;
u_int sx, sy;
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) {
if ((lc = wp->layout_cell) == NULL || wp == skip)
@@ -307,20 +373,21 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
sx = lc->sx;
sy = lc->sy;
if (layout_add_horizontal_border(w, lc, status)) {
if (!window_pane_is_floating(wp) &&
layout_add_horizontal_border(w, lc, status)) {
if (status == PANE_STATUS_TOP)
wp->yoff++;
sy--;
}
if (window_pane_show_scrollbar(wp, scrollbars)) {
if (window_pane_show_scrollbar(wp)) {
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 (w->sb_pos == PANE_SCROLLBARS_LEFT) {
if ((int)sx - sb_w < PANE_MINIMUM) {
wp->xoff = wp->xoff +
(int)sx - PANE_MINIMUM;
@@ -329,7 +396,7 @@ layout_fix_panes(struct window *w, struct window_pane *skip)
sx = sx - sb_w - sb_pad;
wp->xoff = wp->xoff + sb_w + sb_pad;
}
} else /* sb_pos == PANE_SCROLLBARS_RIGHT */
} else /* w->sb_pos == PANE_SCROLLBARS_RIGHT */
if ((int)sx - sb_w - sb_pad < PANE_MINIMUM)
sx = PANE_MINIMUM;
else
@@ -346,14 +413,13 @@ u_int
layout_count_cells(struct layout_cell *lc)
{
struct layout_cell *lcchild;
u_int count;
u_int count = 0;
switch (lc->type) {
case LAYOUT_WINDOWPANE:
return (1);
case LAYOUT_LEFTRIGHT:
case LAYOUT_TOPBOTTOM:
count = 0;
TAILQ_FOREACH(lcchild, &lc->cells, entry)
count += layout_count_cells(lcchild);
return (count);
@@ -370,16 +436,15 @@ layout_resize_check(struct window *w, struct layout_cell *lc,
struct layout_cell *lcchild;
struct style *sb_style = &w->active->scrollbar_style;
u_int available, minimum;
int status, scrollbars;
int status;
status = options_get_number(w->options, "pane-border-status");
scrollbars = options_get_number(w->options, "pane-scrollbars");
if (lc->type == LAYOUT_WINDOWPANE) {
/* Space available in this cell only. */
if (type == LAYOUT_LEFTRIGHT) {
available = lc->sx;
if (scrollbars)
if (w->sb != PANE_SCROLLBARS_OFF)
minimum = PANE_MINIMUM + sb_style->width +
sb_style->pad;
else
@@ -436,8 +501,11 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
/* Child cell runs in a different direction. */
if (lc->type != type) {
TAILQ_FOREACH(lcchild, &lc->cells, entry)
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
layout_resize_adjust(w, lcchild, type, change);
}
return;
}
@@ -449,6 +517,8 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (change == 0)
break;
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
if (change > 0) {
layout_resize_adjust(w, lcchild, type, 1);
change--;
@@ -467,28 +537,33 @@ void
layout_destroy_cell(struct window *w, struct layout_cell *lc,
struct layout_cell **lcroot)
{
struct layout_cell *lcother, *lcparent;
struct layout_cell *lcother = NULL, *lcparent;
/*
* If no parent, this is the last pane so window close is imminent and
* there is no need to resize anything.
*/
/* If no parent, this is the last pane in a window. */
lcparent = lc->parent;
if (lcparent == NULL) {
if (lc->wp != NULL)
*lcroot = NULL;
layout_free_cell(lc);
*lcroot = NULL;
return;
}
/* Merge the space into the previous or next cell. */
if (lc == TAILQ_FIRST(&lcparent->cells))
lcother = TAILQ_NEXT(lc, entry);
else
lcother = TAILQ_PREV(lc, layout_cells, entry);
if (lcother != NULL && lcparent->type == LAYOUT_LEFTRIGHT)
layout_resize_adjust(w, lcother, lcparent->type, lc->sx + 1);
else if (lcother != NULL)
layout_resize_adjust(w, lcother, lcparent->type, lc->sy + 1);
if (~lc->flags & LAYOUT_CELL_FLOATING) {
/* Merge the space into the previous or next cell. */
if (lc == TAILQ_FIRST(&lcparent->cells))
lcother = TAILQ_NEXT(lc, entry);
else
lcother = TAILQ_PREV(lc, layout_cells, entry);
}
if (lcother != NULL && (~lcother->flags & LAYOUT_CELL_FLOATING)) {
if (lcparent->type == LAYOUT_LEFTRIGHT) {
layout_resize_adjust(w, lcother, lcparent->type,
lc->sx + 1);
} else {
layout_resize_adjust(w, lcother, lcparent->type,
lc->sy + 1);
}
}
/* Remove this from the parent's list. */
TAILQ_REMOVE(&lcparent->cells, lc, entry);
@@ -499,12 +574,15 @@ layout_destroy_cell(struct window *w, struct layout_cell *lc,
* replace it by that cell.
*/
lc = TAILQ_FIRST(&lcparent->cells);
if (TAILQ_NEXT(lc, entry) == NULL) {
if (lc != NULL && TAILQ_NEXT(lc, entry) == NULL) {
TAILQ_REMOVE(&lcparent->cells, lc, entry);
lc->parent = lcparent->parent;
if (lc->parent == NULL) {
lc->xoff = 0; lc->yoff = 0;
if (~lc->flags & LAYOUT_CELL_FLOATING) {
lc->xoff = 0;
lc->yoff = 0;
}
*lcroot = lc;
} else
TAILQ_REPLACE(&lc->parent->cells, lcparent, lc, entry);
@@ -513,6 +591,7 @@ layout_destroy_cell(struct window *w, struct layout_cell *lc,
}
}
/* Initialize layout for pane. */
void
layout_init(struct window *w, struct window_pane *wp)
{
@@ -524,6 +603,7 @@ layout_init(struct window *w, struct window_pane *wp)
layout_fix_panes(w, NULL);
}
/* Free layout for pane. */
void
layout_free(struct window *w)
{
@@ -550,6 +630,8 @@ layout_resize(struct window *w, u_int sx, u_int sy)
* out proportionately - this should leave the layout fitting the new
* window size.
*/
if (lc->type == LAYOUT_WINDOWPANE && (lc->flags & LAYOUT_CELL_FLOATING))
return;
xchange = sx - lc->sx;
xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT);
if (xchange < 0 && xchange < -xlimit)
@@ -741,7 +823,7 @@ layout_resize_pane_shrink(struct window *w, struct layout_cell *lc,
return (size);
}
/* Assign window pane to newly split cell. */
/* Assign window pane to new cell. */
void
layout_assign_pane(struct layout_cell *lc, struct window_pane *wp,
int do_not_resize)
@@ -862,6 +944,8 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
count = 0;
previous = 0;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
count++;
if (lc->type == LAYOUT_LEFTRIGHT)
previous += lcchild->sx;
@@ -880,6 +964,8 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
/* Resize children into the new size. */
idx = 0;
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
if (lcchild->flags & LAYOUT_CELL_FLOATING)
continue;
if (lc->type == LAYOUT_TOPBOTTOM) {
lcchild->sx = lc->sx;
lcchild->xoff = lc->xoff;
@@ -888,9 +974,10 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
lc->type, lc->sx, count - idx, available);
available -= (lcchild->sx + 1);
}
if (lc->type == LAYOUT_LEFTRIGHT)
if (lc->type == LAYOUT_LEFTRIGHT) {
lcchild->sy = lc->sy;
else {
lcchild->yoff = lc->yoff;
} else {
lcchild->sy = layout_new_pane_size(w, previous, lcchild,
lc->type, lc->sy, count - idx, available);
available -= (lcchild->sy + 1);
@@ -913,7 +1000,6 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
u_int sx, sy, xoff, yoff, size1, size2, minimum;
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
@@ -924,7 +1010,6 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
else
lc = wp->layout_cell;
status = options_get_number(wp->window->options, "pane-border-status");
scrollbars = options_get_number(wp->window->options, "pane-scrollbars");
/* Copy the old cell size. */
sx = lc->sx;
@@ -935,7 +1020,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
/* Check there is enough space for the two new panes. */
switch (type) {
case LAYOUT_LEFTRIGHT:
if (scrollbars) {
if (wp->window->sb != PANE_SCROLLBARS_OFF) {
minimum = PANE_MINIMUM * 2 + sb_style->width +
sb_style->pad;
} else
@@ -1079,14 +1164,51 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
return (lcnew);
}
/*
* Creates a cell for a new floating pane. This must be followed by
* layout_assign_pane before much else happens!
*/
struct layout_cell *
layout_floating_pane(struct window *w, u_int sx, u_int sy, int ox, int oy)
{
struct layout_cell *lc = w->layout_root, *lcnew, *lcparent;
if (lc->type == LAYOUT_WINDOWPANE) {
/*
* Adding a pane to a root that doesn't have a container. Must
* create and insert a new root.
*/
lcparent = layout_create_cell(NULL);
layout_make_node(lcparent, LAYOUT_TOPBOTTOM);
layout_set_size(lcparent, w->sx, w->sy, 0, 0);
w->layout_root = lcparent;
/* Insert the old cell. */
lc->parent = lcparent;
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
} else
lcparent = w->layout_root;
lcnew = layout_create_cell(lcparent);
TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
lcnew->flags |= LAYOUT_CELL_FLOATING;
layout_set_size(lcnew, sx, sy, ox, oy);
return (lcnew);
}
/* Destroy the cell associated with a pane. */
void
layout_close_pane(struct window_pane *wp)
{
struct window *w = wp->window;
if (wp->layout_cell == NULL)
return;
/* Remove the cell. */
layout_destroy_cell(w, wp->layout_cell, &w->layout_root);
wp->layout_cell = NULL;
/* Fix pane offsets and sizes. */
if (w->layout_root != NULL) {
@@ -1096,6 +1218,7 @@ layout_close_pane(struct window_pane *wp)
notify_window("window-layout-changed", w);
}
/* Spread out cells inside a parent cell. */
int
layout_spread_cell(struct window *w, struct layout_cell *parent)
{
@@ -1124,6 +1247,7 @@ layout_spread_cell(struct window *w, struct layout_cell *parent)
each = (size - (number - 1)) / number;
if (each == 0)
return (0);
/*
* Remaining space after assigning that which can be evenly
* distributed.
@@ -1158,6 +1282,7 @@ layout_spread_cell(struct window *w, struct layout_cell *parent)
return (changed);
}
/* Spread out cells evenly. */
void
layout_spread_out(struct window_pane *wp)
{
@@ -1176,3 +1301,123 @@ layout_spread_out(struct window_pane *wp)
}
} while ((parent = parent->parent) != NULL);
}
/* Get a new tiled cell. */
struct layout_cell *
layout_get_tiled_cell(struct cmdq_item *item, struct args *args,
struct window *w, struct window_pane *wp, int flags, char **cause)
{
struct layout_cell *lc;
enum layout_type type;
u_int curval;
int size = -1;
if (window_pane_is_floating(wp)) {
*cause = xstrdup("can't split a floating pane");
return (NULL);
}
type = LAYOUT_TOPBOTTOM;
if (args_has(args, 'h'))
type = LAYOUT_LEFTRIGHT;
if (args_has(args, 'l') || args_has(args, 'p')) {
if (args_has(args, 'f')) {
if (type == LAYOUT_TOPBOTTOM)
curval = w->sy;
else
curval = w->sx;
} else {
if (type == LAYOUT_TOPBOTTOM)
curval = wp->sy;
else
curval = wp->sx;
}
}
if (args_has(args, 'l')) {
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
item, cause);
} else if (args_has(args, 'p')) {
size = args_strtonum_and_expand(args, 'p', 0, 100, item,
cause);
if (*cause == NULL)
size = curval * size / 100;
}
if (*cause != NULL) {
*cause = xstrdup("invalid tiled geometry");
return (NULL);
}
if (args_has(args, 'b'))
flags |= SPAWN_BEFORE;
if (args_has(args, 'f'))
flags |= SPAWN_FULLSIZE;
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
lc = layout_split_pane(wp, type, size, flags);
if (lc == NULL)
*cause = xstrdup("no space for a new pane");
return (lc);
}
/* Get a new floating cell. */
struct layout_cell *
layout_get_floating_cell(struct cmdq_item *item, struct args *args,
struct window *w, __unused struct window_pane *wp, char **cause)
{
struct layout_cell *lcnew;
int sx = w->sx / 2, sy = w->sy / 4;
int ox = INT_MAX, oy = INT_MAX;
if (args_has(args, 'x')) {
sx = args_percentage_and_expand(args, 'x', 0, w->sx - 1, w->sx,
item, cause);
if (*cause != NULL)
return (NULL);
}
if (args_has(args, 'y')) {
sy = args_percentage_and_expand(args, 'y', 0, w->sy - 1, w->sy,
item, cause);
if (*cause != NULL)
return (NULL);
}
if (args_has(args, 'X')) {
ox = args_percentage_and_expand(args, 'X', -sx, w->sx,
w->sx, item, cause);
if (*cause != NULL)
return (NULL);
}
if (args_has(args, 'Y')) {
oy = args_percentage_and_expand(args, 'Y', -sy, w->sy,
w->sy, item, cause);
if (*cause != NULL)
return (NULL);
}
if (ox == INT_MAX) {
if (w->last_new_pane_x == 0)
ox = 4;
else {
ox = w->last_new_pane_x + 4;
if (w->last_new_pane_x > w->sx)
ox = 4;
}
w->last_new_pane_x = ox;
}
if (oy == INT_MAX) {
if (w->last_new_pane_y == 0)
oy = 2;
else {
oy = w->last_new_pane_y + 2;
if (w->last_new_pane_y > w->sy)
oy = 2;
}
w->last_new_pane_y = oy;
}
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
lcnew = layout_floating_pane(w, sx, sy, ox, oy);
return (lcnew);
}

7
menu.c
View File

@@ -363,7 +363,7 @@ menu_key_cb(struct client *c, void *data, struct key_event *event)
name = menu->items[i].name;
if (name == NULL || *name == '-')
continue;
if (event->key == menu->items[i].key) {
if ((event->key & ~KEYC_MASK_FLAGS) == menu->items[i].key) {
md->choice = i;
goto chosen;
}
@@ -471,6 +471,7 @@ menu_key_cb(struct client *c, void *data, struct key_event *event)
case '\r':
goto chosen;
case '\033': /* Escape */
case '['|KEYC_CTRL:
case 'c'|KEYC_CTRL:
case 'g'|KEYC_CTRL:
case 'q':
@@ -637,7 +638,7 @@ menu_display(struct menu *menu, int flags, int starting_choice,
style, selected_style, border_style, fs, cb, data);
if (md == NULL)
return (-1);
server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb,
menu_key_cb, menu_free_cb, menu_resize_cb, md);
server_client_set_overlay(c, 0, menu_check_cb, menu_mode_cb,
menu_draw_cb, menu_key_cb, menu_free_cb, menu_resize_cb, md);
return (0);
}

View File

@@ -58,6 +58,7 @@ struct mode_tree_data {
mode_tree_key_cb keycb;
mode_tree_swap_cb swapcb;
mode_tree_sort_cb sortcb;
mode_tree_help_cb helpcb;
struct mode_tree_list children;
struct mode_tree_list saved;
@@ -132,6 +133,35 @@ static const struct menu_item mode_tree_menu_items[] = {
{ NULL, KEYC_NONE, NULL }
};
static const char* mode_tree_help_start[] = {
"\r\033[1m Up, k \033[0m\016x\017 \033[0mMove cursor up\n",
"\r\033[1m Down, j \033[0m\016x\017 \033[0mMove cursor down\n",
"\r\033[1m g \033[0m\016x\017 \033[0mGo to top\n",
"\r\033[1m G \033[0m\016x\017 \033[0mGo to bottom\n",
"\r\033[1m PPage, C-b \033[0m\016x\017 \033[0mPage up\n",
"\r\033[1m NPage, C-f \033[0m\016x\017 \033[0mPage down\n",
"\r\033[1m Left, h \033[0m\016x\017 \033[0mCollapse %1\n",
"\r\033[1m Right, l \033[0m\016x\017 \033[0mExpand %1\n",
"\r\033[1m M-- \033[0m\016x\017 \033[0mCollapse all %1s\n",
"\r\033[1m M-+ \033[0m\016x\017 \033[0mExpand all %1s\n",
"\r\033[1m t \033[0m\016x\017 \033[0mToggle %1 tag\n",
"\r\033[1m T \033[0m\016x\017 \033[0mUntag all %1s\n",
"\r\033[1m C-t \033[0m\016x\017 \033[0mTag all %1s\n",
"\r\033[1m C-s \033[0m\016x\017 \033[0mSearch forward\n",
"\r\033[1m n \033[0m\016x\017 \033[0mRepeat search forward\n",
"\r\033[1m N \033[0m\016x\017 \033[0mRepeat search backward\n",
"\r\033[1m f \033[0m\016x\017 \033[0mFilter %1s\n",
"\r\033[1m O \033[0m\016x\017 \033[0mChange sort order\n",
"\r\033[1m r \033[0m\016x\017 \033[0mReverse sort order\n",
"\r\033[1m v \033[0m\016x\017 \033[0mToggle preview\n",
NULL
};
static const char* mode_tree_help_end[] = {
"\r\033[1m q, Escape \033[0m\016x\017 \033[0mExit mode\033[H",
NULL
};
#define MODE_TREE_HELP_DEFAULT_WIDTH 39
static int
mode_tree_is_lowercase(const char *ptr)
{
@@ -270,6 +300,8 @@ mode_tree_clear_tagged(struct mode_tree_list *mtl)
void
mode_tree_up(struct mode_tree_data *mtd, int wrap)
{
if (mtd->line_size == 0)
return;
if (mtd->current == 0) {
if (wrap) {
mtd->current = mtd->line_size - 1;
@@ -286,6 +318,8 @@ mode_tree_up(struct mode_tree_data *mtd, int wrap)
int
mode_tree_down(struct mode_tree_data *mtd, int wrap)
{
if (mtd->line_size == 0)
return (0);
if (mtd->current == mtd->line_size - 1) {
if (wrap) {
mtd->current = 0;
@@ -332,6 +366,8 @@ mode_tree_swap(struct mode_tree_data *mtd, int direction)
void *
mode_tree_get_current(struct mode_tree_data *mtd)
{
if (mtd->line_size == 0)
return (NULL);
return (mtd->line_list[mtd->current].item->itemdata);
}
@@ -402,6 +438,8 @@ mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
return (1);
}
if (mtd->current >= mtd->line_size) {
if (mtd->line_size == 0)
return (0);
mtd->current = mtd->line_size - 1;
if (mtd->current > mtd->height - 1)
mtd->offset = mtd->current - mtd->height + 1;
@@ -453,8 +491,9 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,
mode_tree_search_cb searchcb, mode_tree_menu_cb menucb,
mode_tree_height_cb heightcb, mode_tree_key_cb keycb,
mode_tree_swap_cb swapcb, mode_tree_sort_cb sortcb, void *modedata,
const struct menu_item *menu, struct screen **s)
mode_tree_swap_cb swapcb, mode_tree_sort_cb sortcb,
mode_tree_help_cb helpcb, void *modedata, const struct menu_item *menu,
struct screen **s)
{
struct mode_tree_data *mtd;
@@ -488,6 +527,7 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->keycb = keycb;
mtd->swapcb = swapcb;
mtd->sortcb = sortcb;
mtd->helpcb = helpcb;
TAILQ_INIT(&mtd->children);
@@ -1123,6 +1163,57 @@ mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
}
}
static void
mode_tree_display_help(__unused struct mode_tree_data *mtd, struct client *c)
{
struct session *s = c->session;
u_int px, py, w, h = 0;
const char **line, **lines = NULL, *item = "item";
char *new_line;
if (mtd->helpcb == NULL)
w = MODE_TREE_HELP_DEFAULT_WIDTH;
else {
lines = mtd->helpcb(&w, &item);
if (w < MODE_TREE_HELP_DEFAULT_WIDTH)
w = MODE_TREE_HELP_DEFAULT_WIDTH;
}
for (line = mode_tree_help_start; *line != NULL; line++)
h++;
for (line = lines; line != NULL && *line != NULL; line++)
h++;
for (line = mode_tree_help_end; *line != NULL; line++)
h++;
if (c->tty.sx < w || c->tty.sy < h)
return;
px = (c->tty.sx - w) / 2;
py = (c->tty.sy - h) / 2;
if (popup_display(POPUP_CLOSEANYKEY|POPUP_NOJOB, BOX_LINES_DEFAULT,
NULL, px, py, w, h, NULL, NULL, 0, NULL, NULL, NULL, c, s, NULL,
NULL, NULL, NULL) != 0)
return;
popup_write(c, "\033[H\033[?25l\033[?7l\033)0", 17);
for (line = mode_tree_help_start; *line != NULL; line++) {
new_line = cmd_template_replace(*line, item, 1);
popup_write(c, new_line, strlen(new_line));
free(new_line);
}
for (line = lines; line != NULL && *line != NULL; line++) {
new_line = cmd_template_replace(*line, item, 1);
popup_write(c, new_line, strlen(new_line));
free(new_line);
}
for (line = mode_tree_help_end; *line != NULL; line++) {
new_line = cmd_template_replace(*line, item, 1);
popup_write(c, new_line, strlen(new_line));
free(new_line);
}
popup_write(c, "\033[H", 3);
}
int
mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
struct mouse_event *m, u_int *xp, u_int *yp)
@@ -1130,7 +1221,12 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
struct mode_tree_line *line;
struct mode_tree_item *current, *parent, *mti;
u_int i, x, y;
int choice;
int choice, preview;
if (mtd->line_size == 0) {
*key = KEYC_NONE;
return (1);
}
if (KEYC_IS_MOUSE(*key) && m != NULL) {
if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
@@ -1142,9 +1238,10 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
if (yp != NULL)
*yp = y;
if (x > mtd->width || y > mtd->height) {
preview = mtd->preview;
if (*key == KEYC_MOUSEDOWN3_PANE)
mode_tree_display_menu(mtd, c, x, y, 1);
if (mtd->preview == MODE_TREE_PREVIEW_OFF)
if (preview == MODE_TREE_PREVIEW_OFF)
*key = KEYC_NONE;
return (0);
}
@@ -1191,8 +1288,13 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
switch (*key) {
case 'q':
case '\033': /* Escape */
case '['|KEYC_CTRL:
case 'g'|KEYC_CTRL:
return (1);
case KEYC_F1:
case 'h'|KEYC_CTRL:
mode_tree_display_help(mtd, c);
break;
case KEYC_UP:
case 'k':
case KEYC_WHEELUP_PANE:

View File

@@ -95,7 +95,7 @@ check_window_name(struct window *w)
name = format_window_name(w);
if (strcmp(name, w->name) != 0) {
log_debug("@%u new name %s (was %s)", w->id, name, w->name);
window_set_name(w, name);
window_set_name(w, name, 1);
server_redraw_window_borders(w);
server_status_window(w);
} else
@@ -166,7 +166,9 @@ parse_window_name(const char *in)
if (*name == '/')
name = basename(name);
name = xstrdup(name);
name = clean_name(name, 0);
free(copy);
if (name == NULL)
return (xstrdup(""));
return (name);
}

View File

@@ -208,8 +208,12 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
format_add(ne->formats, "hook_window", "@%u", w->id);
format_add(ne->formats, "hook_window_name", "%s", w->name);
}
if (wp != NULL)
if (wp != NULL) {
format_add(ne->formats, "hook_pane", "%%%d", wp->id);
format_add(ne->formats, "hook_window", "@%u", wp->window->id);
format_add(ne->formats, "hook_window_name", "%s",
wp->window->name);
}
format_log_debug(ne->formats, __func__);
if (c != NULL)

View File

@@ -91,7 +91,7 @@ static const char *options_table_window_size_list[] = {
"largest", "smallest", "manual", "latest", NULL
};
static const char *options_table_remain_on_exit_list[] = {
"off", "on", "failed", NULL
"off", "on", "failed", "key", NULL
};
static const char *options_table_destroy_unattached_list[] = {
"off", "on", "keep-last", "keep-group", NULL
@@ -108,6 +108,9 @@ static const char *options_table_extended_keys_format_list[] = {
static const char *options_table_allow_passthrough_list[] = {
"off", "on", "all", NULL
};
static const char *options_table_copy_mode_line_numbers_list[] = {
"off", "default", "absolute", "relative", "hybrid", NULL
};
/* Status line format. */
#define OPTIONS_TABLE_STATUS_FORMAT1 \
@@ -141,7 +144,7 @@ static const char *options_table_allow_passthrough_list[] = {
"#{T:window-status-format}" \
"#[pop-default]" \
"#[norange default]" \
"#{?loop_last_flag,,#{window-status-separator}}" \
"#{?loop_last_flag,,#{E:window-status-separator}}" \
"," \
"#[range=window|#{window_index} list=focus " \
"#{?#{!=:#{E:window-status-current-style},default}," \
@@ -168,7 +171,7 @@ static const char *options_table_allow_passthrough_list[] = {
"#{T:window-status-current-format}" \
"#[pop-default]" \
"#[norange list=on default]" \
"#{?loop_last_flag,,#{window-status-separator}}" \
"#{?loop_last_flag,,#{E:window-status-separator}}" \
"}" \
"#[nolist align=right range=right #{E:status-right-style}]" \
"#[push-default]" \
@@ -185,7 +188,7 @@ static const char *options_table_allow_passthrough_list[] = {
"#{E:pane-status-style}" \
"]" \
"#[push-default]" \
"#P[#{pane_width}x#{pane_height}]" \
"#{T:window-pane-status-format}" \
"#[pop-default]" \
"#[norange list=on default] " \
"," \
@@ -196,7 +199,7 @@ static const char *options_table_allow_passthrough_list[] = {
"}" \
"]" \
"#[push-default]" \
"#P[#{pane_width}x#{pane_height}]*" \
"#{T:window-pane-current-status-format}" \
"#[pop-default]" \
"#[norange list=on default] " \
"}"
@@ -414,10 +417,10 @@ const struct options_table_entry options_table[] = {
.choices = options_table_get_clipboard_list,
.default_num = 1,
.text = "When an application requests the clipboard, whether to "
"ignore the request ('off'); respond with the newest buffer "
"('buffer'); request the clipboard from the most recently "
"used terminal ('request'); or to request the clipboard, "
"create a buffer, and send it to the application ('both')."
"ignore the request ('off'); respond with the newest buffer "
"('buffer'); request the clipboard from the most recently "
"used terminal ('request'); or to request the clipboard, "
"create a buffer, and send it to the application ('both')."
},
{ .name = "history-file",
@@ -723,13 +726,24 @@ const struct options_table_entry options_table[] = {
{ .name = "message-command-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=black,fg=yellow",
.default_str = "bg=black,fg=yellow,fill=black",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of the command prompt when in command mode, if "
"'mode-keys' is set to 'vi'."
},
{ .name = "message-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "#[#{?#{command_prompt},"
"#{E:message-command-style},"
"#{E:message-style}}]"
"#{message}",
.text = "Format string for the prompt and message area. "
"The '#{message}' placeholder is replaced with the content."
},
{ .name = "message-line",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_SESSION,
@@ -741,10 +755,13 @@ const struct options_table_entry options_table[] = {
{ .name = "message-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_SESSION,
.default_str = "bg=yellow,fg=black",
.default_str = "bg=yellow,fg=black,fill=yellow",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of messages and the command prompt."
.text = "Style of messages and the command prompt. "
"A 'fill' attribute controls background clearing and "
"a 'width' attribute (fixed or percentage) constrains "
"the prompt area width."
},
{ .name = "mouse",
@@ -1010,7 +1027,9 @@ const struct options_table_entry options_table[] = {
.scope = OPTIONS_TABLE_SESSION,
.flags = OPTIONS_TABLE_IS_ARRAY,
.default_str = "DISPLAY KRB5CCNAME MSYSTEM SSH_ASKPASS SSH_AUTH_SOCK "
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY",
"SSH_AGENT_PID SSH_CONNECTION WAYLAND_DISPLAY "
"WINDOWID XAUTHORITY XDG_CURRENT_DESKTOP "
"XDG_SESSION_DESKTOP XDG_SESSION_TYPE",
.text = "List of environment variables to update in the session "
"environment when a client is attached."
},
@@ -1161,7 +1180,7 @@ const struct options_table_entry options_table[] = {
.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}]"
"[#{copy_position}/#{copy_position_limit}]"
"#{?search_timed_out, (timed out),"
"#{?search_count, (#{search_count}"
"#{?search_count_partial,+,} results),}}",
@@ -1186,6 +1205,32 @@ const struct options_table_entry options_table[] = {
.text = "Style of selection in copy mode."
},
{ .name = "copy-mode-current-line-number-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "fg=yellow",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of current line number in copy mode."
},
{ .name = "copy-mode-line-number-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "fg=white,dim",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of line numbers in copy mode."
},
{ .name = "copy-mode-line-numbers",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW,
.choices = options_table_copy_mode_line_numbers_list,
.default_num = 0,
.text = "Line number mode in copy mode."
},
{ .name = "fill-character",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
@@ -1269,7 +1314,7 @@ const struct options_table_entry options_table[] = {
{ .name = "pane-active-border-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "#{?pane_in_mode,fg=yellow,#{?synchronize-panes,fg=red,fg=green}}",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
@@ -1289,7 +1334,14 @@ const struct options_table_entry options_table[] = {
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "#{?pane_active,#[reverse],}#{pane_index}#[default] "
"\"#{pane_title}\"",
"\"#{pane_title}\""
"#{?#{mouse},"
"#[align=right]"
"#[range=control|8]["
"#{?#{window_zoomed_flag},u,z}"
"]#[norange]"
"#[range=control|9][x]#[norange]"
",}",
.text = "Format of text in the pane status lines."
},
@@ -1321,7 +1373,7 @@ const struct options_table_entry options_table[] = {
{ .name = "pane-border-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "default",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
@@ -1393,8 +1445,9 @@ const struct options_table_entry options_table[] = {
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.choices = options_table_remain_on_exit_list,
.default_num = 0,
.text = "Whether panes should remain ('on') or be automatically "
"killed ('off' or 'failed') when the program inside exits."
.text = "Whether panes should remain ('on'), remain until a key is "
"pressed ('key') or be automatically killed ('off' or "
"'failed') when the program inside exits."
},
{ .name = "remain-on-exit-format",
@@ -1435,6 +1488,28 @@ const struct options_table_entry options_table[] = {
"A value of 0 means no limit."
},
{ .name = "tree-mode-preview-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
.default_str = "#{?pane_format,"
"#{pane_index}:#{pane_title},"
"#{window_index}:#{window_name}}",
.text = "Format of the preview indicator in tree mode."
},
{ .name = "tree-mode-preview-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "fg=#{?#{||:"
"#{&&:#{pane_format},#{pane_active}},"
"#{&&:#{window_format},#{window_active}}},"
"#{display-panes-active-colour},"
"#{display-panes-colour}}",
.flags = OPTIONS_TABLE_IS_STYLE,
.separator = ",",
.text = "Style of preview indicator in tree mode."
},
{ .name = "window-active-style",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE,
@@ -1444,6 +1519,21 @@ const struct options_table_entry options_table[] = {
.text = "Default style of the active pane."
},
{ .name = "window-pane-current-status-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "#P:[#T]#{?pane_flags,#{pane_flags}, }",
.text = "Format of the current window pane in the status line."
},
{ .name = "window-pane-status-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
.default_str = "#P:[#T]#{?pane_flags,#{pane_flags}, }",
.text = "Format of window panes in the status line, except the "
"current pane."
},
{ .name = "window-size",
.type = OPTIONS_TABLE_CHOICE,
.scope = OPTIONS_TABLE_WINDOW,

View File

@@ -1237,8 +1237,13 @@ options_push_changes(const char *name)
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) {
w->sb = options_get_number(w->options,
"pane-scrollbars");
w->sb_pos = options_get_number(w->options,
"pane-scrollbars-position");
layout_fix_panes(w, NULL);
}
}
if (strcmp(name, "pane-scrollbars-style") == 0) {
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {

35
paste.c
View File

@@ -176,7 +176,6 @@ paste_add(const char *prefix, char *data, size_t size)
}
pb = xmalloc(sizeof *pb);
pb->name = NULL;
do {
free(pb->name);
@@ -204,6 +203,7 @@ int
paste_rename(const char *oldname, const char *newname, char **cause)
{
struct paste_buffer *pb, *pb_new;
char *name;
if (cause != NULL)
*cause = NULL;
@@ -219,23 +219,33 @@ paste_rename(const char *oldname, const char *newname, char **cause)
return (-1);
}
name = clean_name(newname, 0);
if (name == NULL) {
if (cause != NULL)
xasprintf(cause, "invalid buffer name: %s", newname);
return (-1);
}
pb = paste_get_name(oldname);
if (pb == NULL) {
if (cause != NULL)
xasprintf(cause, "no buffer %s", oldname);
free(name);
return (-1);
}
pb_new = paste_get_name(newname);
if (pb_new == pb)
pb_new = paste_get_name(name);
if (pb_new == pb) {
free(name);
return (0);
}
if (pb_new != NULL)
paste_free(pb_new);
RB_REMOVE(paste_name_tree, &paste_by_name, pb);
free(pb->name);
pb->name = xstrdup(newname);
pb->name = name;
if (pb->automatic)
paste_num_automatic--;
@@ -244,7 +254,7 @@ paste_rename(const char *oldname, const char *newname, char **cause)
RB_INSERT(paste_name_tree, &paste_by_name, pb);
notify_paste_buffer(oldname, 1);
notify_paste_buffer(newname, 0);
notify_paste_buffer(pb->name, 0);
return (0);
}
@@ -257,6 +267,7 @@ int
paste_set(char *data, size_t size, const char *name, char **cause)
{
struct paste_buffer *pb, *old;
char *newname;
if (cause != NULL)
*cause = NULL;
@@ -276,9 +287,15 @@ paste_set(char *data, size_t size, const char *name, char **cause)
return (-1);
}
pb = xmalloc(sizeof *pb);
newname = clean_name(name, 0);
if (newname == NULL) {
if (cause != NULL)
xasprintf(cause, "invalid buffer name: %s", name);
return (-1);
}
pb->name = xstrdup(name);
pb = xmalloc(sizeof *pb);
pb->name = newname;
pb->data = data;
pb->size = size;
@@ -288,13 +305,13 @@ paste_set(char *data, size_t size, const char *name, char **cause)
pb->created = time(NULL);
if ((old = paste_get_name(name)) != NULL)
if ((old = paste_get_name(pb->name)) != NULL)
paste_free(old);
RB_INSERT(paste_name_tree, &paste_by_name, pb);
RB_INSERT(paste_time_tree, &paste_by_time, pb);
notify_paste_buffer(name, 0);
notify_paste_buffer(pb->name, 0);
return (0);
}

76
popup.c
View File

@@ -103,6 +103,27 @@ static const struct menu_item popup_internal_menu_items[] = {
{ NULL, KEYC_NONE, NULL }
};
static void
popup_free(struct popup_data *pd)
{
server_client_unref(pd->c);
if (pd->job != NULL)
job_free(pd->job);
input_free(pd->ictx);
free(pd->or[0].ranges);
free(pd->or[1].ranges);
free(pd->r.ranges);
screen_free(&pd->s);
colour_palette_free(&pd->palette);
free(pd->title);
free(pd->style);
free(pd->border_style);
free(pd);
}
static void
popup_reapply_styles(struct popup_data *pd)
{
@@ -164,7 +185,6 @@ popup_set_client_cb(struct tty_ctx *ttyctx, struct client *c)
if (pd->c->flags & CLIENT_REDRAWOVERLAY)
return (0);
ttyctx->bigger = 0;
ttyctx->wox = 0;
ttyctx->woy = 0;
ttyctx->wsx = c->tty.sx;
@@ -187,6 +207,7 @@ popup_init_ctx_cb(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
struct popup_data *pd = ctx->arg;
memcpy(&ttyctx->defaults, &pd->defaults, sizeof ttyctx->defaults);
ttyctx->flags &= ~TTY_CTX_WINDOW_BIGGER;
ttyctx->palette = &pd->palette;
ttyctx->redraw_cb = popup_redraw_cb;
ttyctx->set_client_cb = popup_set_client_cb;
@@ -279,6 +300,10 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
popup_reapply_styles(pd);
screen_init(&s, pd->sx, pd->sy, 0);
if (pd->s.hyperlinks != NULL) {
hyperlinks_free(s.hyperlinks);
s.hyperlinks = hyperlinks_copy(pd->s.hyperlinks);
}
screen_write_start(&ctx, &s);
screen_write_clearscreen(&ctx, 8);
@@ -339,22 +364,8 @@ popup_free_cb(struct client *c, void *data)
cmdq_get_client(item)->retval = pd->status;
cmdq_continue(item);
}
server_client_unref(pd->c);
if (pd->job != NULL)
job_free(pd->job);
input_free(pd->ictx);
free(pd->or[0].ranges);
free(pd->or[1].ranges);
free(pd->r.ranges);
screen_free(&pd->s);
colour_palette_free(&pd->palette);
free(pd->title);
free(pd->style);
free(pd->border_style);
free(pd);
popup_free(pd);
}
static void
@@ -424,7 +435,7 @@ popup_make_pane(struct popup_data *pd, enum layout_type type)
pd->job = NULL;
}
screen_set_title(&pd->s, new_wp->base.title);
screen_set_title(&pd->s, new_wp->base.title, 0);
screen_free(&new_wp->base);
memcpy(&new_wp->base, &pd->s, sizeof wp->base);
screen_resize(&new_wp->base, new_wp->sx, new_wp->sy, 1);
@@ -847,16 +858,39 @@ popup_display(int flags, enum box_lines lines, struct cmdq_item *item, u_int px,
pd->psx = sx;
pd->psy = sy;
pd->job = job_run(shellcmd, argc, argv, env, s, cwd,
popup_job_update_cb, popup_job_complete_cb, NULL, pd,
JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE|JOB_DEFAULTSHELL, jx, jy);
pd->ictx = input_init(NULL, job_get_event(pd->job), &pd->palette, c);
if (flags & POPUP_NOJOB)
pd->ictx = input_init(NULL, NULL, &pd->palette, NULL);
else {
pd->job = job_run(shellcmd, argc, argv, env, s, cwd,
popup_job_update_cb, popup_job_complete_cb, NULL, pd,
JOB_NOWAIT|JOB_PTY|JOB_KEEPWRITE|JOB_DEFAULTSHELL, jx, jy);
if (pd->job == NULL) {
popup_free(pd);
return (-1);
}
pd->ictx = input_init(NULL, job_get_event(pd->job),
&pd->palette, c);
}
server_client_set_overlay(c, 0, popup_check_cb, popup_mode_cb,
popup_draw_cb, popup_key_cb, popup_free_cb, popup_resize_cb, pd);
return (0);
}
void
popup_write(struct client *c, const char *data, size_t size)
{
struct popup_data *pd = c->overlay_data;
if (!popup_present(c))
return;
c->overlay_check = NULL;
c->overlay_data = NULL;
input_parse_screen(pd->ictx, &pd->s, popup_init_ctx_cb, pd, data, size);
c->overlay_check = popup_check_cb;
c->overlay_data = pd;
}
static void
popup_editor_free(struct popup_editor *pe)
{

13
proc.c
View File

@@ -31,6 +31,10 @@
#include <ncurses.h>
#endif
#ifdef HAVE_JEMALLOC
#include <jemalloc/jemalloc.h>
#endif
#include "tmux.h"
struct tmuxproc {
@@ -180,6 +184,10 @@ proc_start(const char *name)
{
struct tmuxproc *tp;
struct utsname u;
#ifdef HAVE_JEMALLOC
const char *version;
size_t size = sizeof version;
#endif
log_open(name);
setproctitle("%s (%s)", name, socket_path);
@@ -194,6 +202,11 @@ proc_start(const char *name)
#ifdef HAVE_UTF8PROC
log_debug("using utf8proc %s", utf8proc_version());
#endif
#ifdef HAVE_JEMALLOC
if (mallctl("version", &version, &size, NULL, 0) != 0)
version = "(unknown version)";
log_debug("using jemalloc %s", version);
#endif
#ifdef NCURSES_VERSION
log_debug("using ncurses %s %06u", NCURSES_VERSION, NCURSES_VERSION_PATCH);
#endif

View File

@@ -4,9 +4,9 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMUX2="$TEST_TMUX -Ltest2"
TMUX2="$TEST_TMUX -Ltest2 -f/dev/null"
$TMUX2 kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -11,9 +11,9 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMUX_OUTER="$TEST_TMUX -Ltest2"
TMUX_OUTER="$TEST_TMUX -Ltest2 -f/dev/null"
$TMUX_OUTER kill-server 2>/dev/null
trap "$TMUX kill-server 2>/dev/null; $TMUX_OUTER kill-server 2>/dev/null" 0 1 15

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
TMP=$(mktemp)
TMP2=$(mktemp)
trap "rm -f $TMP $TMP2" 0 1 15

View File

@@ -7,7 +7,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
for i in conf/*.conf; do

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -8,7 +8,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -f/dev/null -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
$TMUX new -d -x40 -y10 \

View File

@@ -34,14 +34,17 @@ $TMUX send-keys -X previous-word
$TMUX send-keys -X copy-selection
[ "$($TMUX show-buffer)" = "line" ] || exit 1
# Test that `next-word-end` wraps around indented line breaks.
# Test that `next-word-end` stops at the end of the line.
$TMUX send-keys -X next-word
$TMUX send-keys -X next-word
$TMUX send-keys -X begin-selection
$TMUX send-keys -X next-word-end
$TMUX send-keys -X next-word-end
$TMUX send-keys -X copy-selection
[ "$($TMUX show-buffer)" = "$(printf "words\n\tIndented")" ] || exit 1
[ "$($TMUX show-buffer)" = "words" ] || exit 1
# Move to the next word for the following tests.
$TMUX send-keys -X next-word
# Test that `next-word` wraps around un-indented line breaks.
$TMUX send-keys -X next-word

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -f/dev/null -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -9,13 +9,12 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
sleep 1
TMP=$(mktemp)
TMP2=$(mktemp)
trap "rm -f $TMP $TMP2; $TMUX kill-server 2>/dev/null" 0 1 15
trap "rm -f $TMP; $TMUX kill-server 2>/dev/null" 0 1 15
$TMUX -f/dev/null new -d -x80 -y24 || exit 1
sleep 1
@@ -25,19 +24,21 @@ $TMUX set -g remain-on-exit on
exit_status=0
# query_decrpm <outfile> [setup_seq]
# query_decrpm <outfile> <mode> [setup_seq]
# Spawn a pane that optionally sends setup_seq, then sends DECRQM for
# mode 2026 and captures the response into outfile in cat -v form.
query_decrpm () {
query_decrpm() {
_outfile=$1
_setup=$2
_mode=$2
_setup=$3
_n=$4
$TMUX respawnw -k -t:0 -- sh -c "
exec 2>/dev/null
stty raw -echo
${_setup:+printf '$_setup'; sleep 0.2}
printf '\033[?2026\$p'
dd bs=1 count=11 2>/dev/null | cat -v > $_outfile
printf '\033[%s\$p' "$_mode"
dd bs=1 count=$_n 2>/dev/null | cat -v > $_outfile
sleep 0.2
" || exit 1
sleep 2
@@ -46,7 +47,7 @@ query_decrpm () {
# ------------------------------------------------------------------
# Test 1: mode 2026 should be reset by default (Ps=2)
# ------------------------------------------------------------------
query_decrpm "$TMP"
query_decrpm "$TMP" "?2026" '' 11
actual=$(cat "$TMP")
expected='^[[?2026;2$y'
@@ -63,9 +64,9 @@ fi
# ------------------------------------------------------------------
# Test 2: set mode 2026 (SM ?2026), then query (expect Ps=1)
# ------------------------------------------------------------------
query_decrpm "$TMP2" '\033[?2026h'
query_decrpm "$TMP" "?2026" '\033[?2026h' 11
actual=$(cat "$TMP2")
actual=$(cat "$TMP")
expected='^[[?2026;1$y'
if [ "$actual" = "$expected" ]; then
@@ -77,6 +78,61 @@ else
exit_status=1
fi
# ------------------------------------------------------------------
# Test 3: mode 25 should return current value
# ------------------------------------------------------------------
query_decrpm "$TMP" "?25" '\033[?25l' 9
actual=$(cat "$TMP")
expected='^[[?25;2$y'
if [ "$actual" = "$expected" ]; then
if [ -n "$VERBOSE" ]; then
echo "[PASS] DECTCEM 25 (reset) -> $actual"
fi
else
echo "[FAIL] DECTCEM 25 (reset): expected '$expected', got '$actual'"
exit_status=1
fi
# ------------------------------------------------------------------
# Test 4: mode ?9999 should return not recognized
# ------------------------------------------------------------------
query_decrpm "$TMP" "?9999" '\033[?9999h' 11
actual=$(cat "$TMP")
expected='^[[?9999;0$y'
if [ "$actual" = "$expected" ]; then
if [ -n "$VERBOSE" ]; then
echo "[PASS] DECSM 9999 (not recognized) -> $actual"
fi
else
echo "[FAIL] DECSM 9999 (not recognized): expected '$expected', got '$actual'"
exit_status=1
fi
$TMUX kill-server 2>/dev/null
exit $exit_status
exit $exit_status
# ------------------------------------------------------------------
# Test 5: mode 4 is reset by default
# ------------------------------------------------------------------
query_decrpm "$TMP" "4" '\033[4h' 11
actual=$(cat "$TMP")
expected='^[[4;1$y'
if [ "$actual" = "$expected" ]; then
if [ -n "$VERBOSE" ]; then
echo "[PASS] SM 4 (is set) -> $actual"
fi
else
echo "[FAIL] SM 4 (is set): expected '$expected', got '$actual'"
exit_status=1
fi
$TMUX kill-server 2>/dev/null
exit $exit_status

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
# test_format $format $expected_result
test_format()

View File

@@ -7,7 +7,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
$TMUX -f/dev/null has -tfoo </dev/null 2>/dev/null && exit 1

View File

@@ -7,7 +7,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -7,7 +7,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -7,7 +7,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,12 +4,13 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
sleep 1
$TMUX -f/dev/null new -x20 -y2 -d || exit 1
$TMUX -f/dev/null new -x20 -y2 -d \; set -g escape-time 0 || exit 1
sleep 1
W=$($TMUX new-window -P -- sh -c 'stty raw -echo && cat -tv')
sleep 1
$TMUX set -g escape-time 0
exit_status=0
@@ -17,14 +18,13 @@ assert_key () {
key=$1
expected_code=$2
W=$($TMUX new-window -P -- sh -c 'stty raw -echo && cat -tv')
$TMUX send-keys -t$W "$key" 'EOL' || exit 1
sleep 0.2
$TMUX send-keys -t$W -R \; \
clear-history -t$W \; \
send-keys -t$W "$key" 'EOL' || exit 1
actual_code=$($TMUX capturep -pt$W | \
head -1 | \
sed -e 's/EOL.*$//')
$TMUX kill-window -t$W || exit 1
if [ "$actual_code" = "$expected_code" ]; then
if [ -n "$VERBOSE" ]; then

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
sleep 1

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -5,14 +5,14 @@
PATH=/bin:/usr/bin
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TERM=$($TMUX start \; show -gv default-terminal)
TMP=$(mktemp)
OUT=$(mktemp)
SCRIPT=$(mktemp)
#trap "rm -f $TMP $OUT $SCRIPT" 0 1 15
trap "rm -f $TMP $OUT $SCRIPT" 0 1 15
cat <<EOF >$SCRIPT
(

View File

@@ -8,7 +8,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -6,7 +6,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
TMP=$(mktemp)

View File

@@ -4,7 +4,7 @@ PATH=/bin:/usr/bin
TERM=screen
[ -z "$TEST_TMUX" ] && TEST_TMUX=$(readlink -f ../tmux)
TMUX="$TEST_TMUX -Ltest"
TMUX="$TEST_TMUX -Ltest -f/dev/null"
$TMUX kill-server 2>/dev/null
$TMUX new -d

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