mirror of
https://github.com/tmux/tmux.git
synced 2026-03-13 20:15:47 +00:00
Compare commits
540 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87fe00e8b4 | ||
|
|
ced83792b1 | ||
|
|
42f6d11a6b | ||
|
|
74fb959f6d | ||
|
|
9daaf01730 | ||
|
|
86a184b288 | ||
|
|
af596c0828 | ||
|
|
58c8ea1209 | ||
|
|
2f2bb82f5f | ||
|
|
6a5d210e55 | ||
|
|
384f0ee269 | ||
|
|
006a529db1 | ||
|
|
af1496b300 | ||
|
|
2b60ff588e | ||
|
|
cd89000c1d | ||
|
|
20b0b38cf4 | ||
|
|
0a8f356c72 | ||
|
|
af611815ea | ||
|
|
4ae2c64657 | ||
|
|
cd692b5a68 | ||
|
|
bf33e807b6 | ||
|
|
cf7e1c94df | ||
|
|
1b28b2b51d | ||
|
|
95baa32383 | ||
|
|
ead75c2d51 | ||
|
|
2cad9a6af8 | ||
|
|
3b7dae9a53 | ||
|
|
5ed64657d8 | ||
|
|
c6b51cea92 | ||
|
|
58d1a206c6 | ||
|
|
e0c982c5ad | ||
|
|
d4423dca19 | ||
|
|
8bcd392ee7 | ||
|
|
3a6d82b7c8 | ||
|
|
0c84a20d2f | ||
|
|
996e54763c | ||
|
|
18105c8ecb | ||
|
|
d6306b634e | ||
|
|
6e9a9d265e | ||
|
|
36648f2668 | ||
|
|
7f86cab1d2 | ||
|
|
39b1e96b45 | ||
|
|
1e9c3b3c63 | ||
|
|
fc6580574e | ||
|
|
2df7bc14fa | ||
|
|
880abd0ec2 | ||
|
|
1c69a91c25 | ||
|
|
98de5784a0 | ||
|
|
d4eda7f9e5 | ||
|
|
89a0046ad3 | ||
|
|
60a0a904e0 | ||
|
|
c0508c9321 | ||
|
|
fe44b105e4 | ||
|
|
ad7113e0db | ||
|
|
23e613fcf5 | ||
|
|
98b92c0525 | ||
|
|
57f331438a | ||
|
|
8aed444201 | ||
|
|
f97d784f17 | ||
|
|
759f949654 | ||
|
|
f1d8724198 | ||
|
|
367ee79df0 | ||
|
|
d5a84de842 | ||
|
|
355ced93cc | ||
|
|
bc0bd8213d | ||
|
|
141a823ea4 | ||
|
|
42e7959336 | ||
|
|
9947f7416a | ||
|
|
c030d6fe36 | ||
|
|
046530878b | ||
|
|
a26ebccd42 | ||
|
|
92a26a8b8c | ||
|
|
f74a98cd07 | ||
|
|
4893edd5d6 | ||
|
|
6a0a783c26 | ||
|
|
7f40c5b647 | ||
|
|
eabbc80b75 | ||
|
|
190b88fcab | ||
|
|
2adbe3ec16 | ||
|
|
9efa419955 | ||
|
|
921be61930 | ||
|
|
b0ff446727 | ||
|
|
65c0af76fb | ||
|
|
87b248f3e8 | ||
|
|
2d9f4ca9a1 | ||
|
|
fc82f2525c | ||
|
|
ded695504f | ||
|
|
ac16f2c641 | ||
|
|
fc7f1e7acb | ||
|
|
207b1bc385 | ||
|
|
d26a4ea463 | ||
|
|
422fcd294a | ||
|
|
b638886716 | ||
|
|
938130bc69 | ||
|
|
5e491e7947 | ||
|
|
792d13af49 | ||
|
|
964deae422 | ||
|
|
6a1706a62f | ||
|
|
10d689e735 | ||
|
|
5d4c3ef762 | ||
|
|
e6e737ac0b | ||
|
|
ee3f1d25d5 | ||
|
|
bfbe972225 | ||
|
|
cf217fa618 | ||
|
|
25337ac102 | ||
|
|
a3d920930b | ||
|
|
2fb6089e81 | ||
|
|
ad9b805983 | ||
|
|
04952f15df | ||
|
|
98cd8e4cad | ||
|
|
9ed1226a66 | ||
|
|
afd9b68d10 | ||
|
|
54d2249716 | ||
|
|
7eff2fe780 | ||
|
|
a731b1a916 | ||
|
|
f84f1c0cfe | ||
|
|
7d4224f207 | ||
|
|
bf14bf6259 | ||
|
|
f39a71aaad | ||
|
|
cd9a81e242 | ||
|
|
047c011a15 | ||
|
|
649685ff6d | ||
|
|
2750195709 | ||
|
|
2da096d828 | ||
|
|
2e59ff2db9 | ||
|
|
60688afe9c | ||
|
|
e8d6d53a7b | ||
|
|
dc0746946e | ||
|
|
2be5488693 | ||
|
|
d54b18ca2b | ||
|
|
fa71e9a079 | ||
|
|
0fd01f8873 | ||
|
|
a9b880921d | ||
|
|
88d9a8fc05 | ||
|
|
818b2176ef | ||
|
|
722f395e61 | ||
|
|
0027ee13a0 | ||
|
|
c7c7e875a0 | ||
|
|
85ef73591d | ||
|
|
5076beb009 | ||
|
|
f85208602d | ||
|
|
df681390a6 | ||
|
|
040164555a | ||
|
|
c67abcf818 | ||
|
|
07e2d88c20 | ||
|
|
784d6a3929 | ||
|
|
53ee4f0334 | ||
|
|
c0598e2515 | ||
|
|
3276f0c184 | ||
|
|
948d2fad0a | ||
|
|
1fdec20b0d | ||
|
|
375f6c90b0 | ||
|
|
b46abeb34d | ||
|
|
57396b55a2 | ||
|
|
c401c91ad9 | ||
|
|
5080acc127 | ||
|
|
a5cf7a9b39 | ||
|
|
97900d0442 | ||
|
|
a4f336a91a | ||
|
|
7e34645fcb | ||
|
|
1b7afd5129 | ||
|
|
7a4ba6d4a5 | ||
|
|
770d28b8c5 | ||
|
|
6c0397f497 | ||
|
|
a6b361e775 | ||
|
|
28b6237c62 | ||
|
|
e5e4df7a22 | ||
|
|
b2b94dcba7 | ||
|
|
080079c55a | ||
|
|
e6e3c75ed7 | ||
|
|
47923bd5f6 | ||
|
|
9aad945f7e | ||
|
|
9c82ff1778 | ||
|
|
ff64aafeab | ||
|
|
ba9b9367d5 | ||
|
|
e4856de8bf | ||
|
|
70d330a353 | ||
|
|
c6149adf55 | ||
|
|
5c5712be5c | ||
|
|
8941dbe482 | ||
|
|
9c1633a865 | ||
|
|
1f9aad2bb4 | ||
|
|
db3aabcc34 | ||
|
|
138ffc7cb6 | ||
|
|
d721fb2a9f | ||
|
|
7532a5cf95 | ||
|
|
71c3234dc7 | ||
|
|
ef676e1202 | ||
|
|
ecac73f664 | ||
|
|
8fccbbb026 | ||
|
|
333cf6429a | ||
|
|
add03dfb8d | ||
|
|
b55f0ac6b9 | ||
|
|
cb8a0d83fb | ||
|
|
630c592ef8 | ||
|
|
10b3cd17fa | ||
|
|
8f1cc0e9fa | ||
|
|
77fc7ac3be | ||
|
|
57100376cc | ||
|
|
1fc0d1b74f | ||
|
|
200b6536e1 | ||
|
|
7d330c19e8 | ||
|
|
774903f6c4 | ||
|
|
8d2286b769 | ||
|
|
4fe5aa99fb | ||
|
|
c76904343a | ||
|
|
60cacdffea | ||
|
|
4acad43013 | ||
|
|
49d33a4282 | ||
|
|
76f5d3364c | ||
|
|
c77924bb56 | ||
|
|
9695114230 | ||
|
|
5745bd27fd | ||
|
|
6f46f71d58 | ||
|
|
197a116f5a | ||
|
|
eb82ad5216 | ||
|
|
3934d9b24d | ||
|
|
ef46eb91a5 | ||
|
|
0cca695d6e | ||
|
|
619d934d7b | ||
|
|
9b4148b12c | ||
|
|
5071b82c77 | ||
|
|
8235957eaa | ||
|
|
be2413292f | ||
|
|
289ac55ebd | ||
|
|
7bd9cdf6fc | ||
|
|
1bf2f811ea | ||
|
|
acba07629e | ||
|
|
8a9bfd0cdd | ||
|
|
65bb36d6bd | ||
|
|
f26b8c57ff | ||
|
|
9e986d6a96 | ||
|
|
51ff77d47b | ||
|
|
2c188ee0c5 | ||
|
|
cc27a43c40 | ||
|
|
c57df2bb73 | ||
|
|
537302f2c1 | ||
|
|
264fe7fc2a | ||
|
|
add20637f2 | ||
|
|
ee9885a40c | ||
|
|
d0ab1a837a | ||
|
|
fb23df679b | ||
|
|
837ca176d1 | ||
|
|
aff2a473ec | ||
|
|
b8581ec80e | ||
|
|
af82106fae | ||
|
|
759efe1b33 | ||
|
|
7ca863c5af | ||
|
|
7800a431ea | ||
|
|
bf0f694f91 | ||
|
|
50a77f4417 | ||
|
|
fed7b29c7e | ||
|
|
5f63181ed5 | ||
|
|
9574496333 | ||
|
|
5374417428 | ||
|
|
5359b76619 | ||
|
|
c8802c776a | ||
|
|
da05d05824 | ||
|
|
d8996a1c1d | ||
|
|
e06a4e041c | ||
|
|
479c9563c7 | ||
|
|
9f6164a05c | ||
|
|
9b1fdb291e | ||
|
|
3d5a02bf45 | ||
|
|
bf595a0cb0 | ||
|
|
68c8905859 | ||
|
|
03f9963f3d | ||
|
|
257e9ba69a | ||
|
|
9c77a5b9f0 | ||
|
|
b2482535d0 | ||
|
|
097a792f9d | ||
|
|
25df71b90d | ||
|
|
c4b969ca62 | ||
|
|
409e121cac | ||
|
|
3c3d371f99 | ||
|
|
8554b80b8b | ||
|
|
3be44313aa | ||
|
|
ed280e14c8 | ||
|
|
86d505af46 | ||
|
|
7186ab25c9 | ||
|
|
a049ebd6f7 | ||
|
|
adb620c4e4 | ||
|
|
2b9830f0e7 | ||
|
|
a19cac5c46 | ||
|
|
ddcf5b801a | ||
|
|
b28fffc0f7 | ||
|
|
e6b40cb339 | ||
|
|
33ac7a346e | ||
|
|
3b10392bfc | ||
|
|
3358c9a8f1 | ||
|
|
5cdc1bdd32 | ||
|
|
31a6e5eff4 | ||
|
|
768fb9080f | ||
|
|
42b0be4cfd | ||
|
|
a0b39dba31 | ||
|
|
732288c489 | ||
|
|
34312fd6ee | ||
|
|
cf5e1bb80a | ||
|
|
5a4b2fd68c | ||
|
|
d776c9acfc | ||
|
|
329c2c2a91 | ||
|
|
d62aee506b | ||
|
|
388f0fe973 | ||
|
|
609baea95e | ||
|
|
daec63e5e6 | ||
|
|
fd756a150b | ||
|
|
c6375a0d40 | ||
|
|
24636be42b | ||
|
|
f4f8d3b5ed | ||
|
|
6616b42b2c | ||
|
|
a3c6057b51 | ||
|
|
c7266ca78d | ||
|
|
03d173cbd8 | ||
|
|
c6d6af4903 | ||
|
|
6ac09aa47c | ||
|
|
a252fadf8a | ||
|
|
78da5a3756 | ||
|
|
7fe3588e49 | ||
|
|
841ce74b43 | ||
|
|
95a374d7d2 | ||
|
|
210e71edf3 | ||
|
|
03b83a5a34 | ||
|
|
1f0c0914c7 | ||
|
|
4a753dbefc | ||
|
|
3ed37a2079 | ||
|
|
1dec1ca146 | ||
|
|
bc71e233d9 | ||
|
|
2e9bafaf14 | ||
|
|
03054598df | ||
|
|
72d905f32c | ||
|
|
c0048d6d20 | ||
|
|
324f87cf14 | ||
|
|
0084cbef5a | ||
|
|
069f5925af | ||
|
|
921991c98d | ||
|
|
326d2ef234 | ||
|
|
63b6eec278 | ||
|
|
5241dae87d | ||
|
|
4d3367e965 | ||
|
|
68cacaec68 | ||
|
|
c286fbdcd7 | ||
|
|
62036121fa | ||
|
|
110ba767e5 | ||
|
|
08e6360f23 | ||
|
|
d371764d02 | ||
|
|
b0da0cee4d | ||
|
|
d589be6c65 | ||
|
|
caa8703a23 | ||
|
|
5f32b7d961 | ||
|
|
de94a344f6 | ||
|
|
c76b28de24 | ||
|
|
944fde7c57 | ||
|
|
90dd474c3e | ||
|
|
6cbc83c6a6 | ||
|
|
e463e8622d | ||
|
|
01b13de655 | ||
|
|
41822ef782 | ||
|
|
5ed5b11b45 | ||
|
|
84955e3d62 | ||
|
|
f984446d19 | ||
|
|
0f02fecd95 | ||
|
|
28d26fca35 | ||
|
|
3676779156 | ||
|
|
3177d7b617 | ||
|
|
551bafc18d | ||
|
|
5413a73ded | ||
|
|
c587ad027f | ||
|
|
82836c7394 | ||
|
|
a8be47f0f4 | ||
|
|
5fdea440ce | ||
|
|
66aaa9e484 | ||
|
|
2b0d798982 | ||
|
|
bacae4b4ad | ||
|
|
4f62aadc93 | ||
|
|
7869ec87e0 | ||
|
|
de9697b456 | ||
|
|
0dad8dd982 | ||
|
|
41ababdf6c | ||
|
|
1a7eb6ca90 | ||
|
|
158f0e8c41 | ||
|
|
f2d4a1f022 | ||
|
|
21ce1e04fe | ||
|
|
c1be1b351d | ||
|
|
22e5fc02c3 | ||
|
|
30786abe0e | ||
|
|
3f8954b11b | ||
|
|
befe7cb1c5 | ||
|
|
65a539c02e | ||
|
|
4cc6db7281 | ||
|
|
79f075bf1b | ||
|
|
54773d23b5 | ||
|
|
7d7d7c9605 | ||
|
|
63aa968642 | ||
|
|
7a0cec5ecf | ||
|
|
2588c3e52e | ||
|
|
92615b534a | ||
|
|
7789639b5d | ||
|
|
614611a8bd | ||
|
|
4c07367bfe | ||
|
|
13a0da205b | ||
|
|
2bb0b9d6c5 | ||
|
|
a2b8506917 | ||
|
|
f725f9bc8a | ||
|
|
94d96c6179 | ||
|
|
e2f6f58fe5 | ||
|
|
db9195463d | ||
|
|
6feb8f6505 | ||
|
|
9b00472820 | ||
|
|
9d7b1960c2 | ||
|
|
5d451551b6 | ||
|
|
fada3eb932 | ||
|
|
26773ea9ef | ||
|
|
163908fe8a | ||
|
|
44ada9cd67 | ||
|
|
7eea3d7ab8 | ||
|
|
01fd4b997e | ||
|
|
e9d49161e0 | ||
|
|
9013600074 | ||
|
|
7a06b92061 | ||
|
|
338ec859a4 | ||
|
|
f6755c6f2c | ||
|
|
705411ea5c | ||
|
|
9d80ec6cc9 | ||
|
|
be5988457f | ||
|
|
33e332428c | ||
|
|
24cd6851f6 | ||
|
|
19812b2d29 | ||
|
|
4bccff9556 | ||
|
|
ef5602a590 | ||
|
|
acd70ea643 | ||
|
|
950d3c5bbc | ||
|
|
97b5962ab1 | ||
|
|
e3fa6cd96c | ||
|
|
93cc8df692 | ||
|
|
4b88872c85 | ||
|
|
c063831df5 | ||
|
|
42490f4750 | ||
|
|
63f9f3113c | ||
|
|
e37aa45681 | ||
|
|
7cbf4c9027 | ||
|
|
78ec057916 | ||
|
|
f0e02387b2 | ||
|
|
e3ff887d2a | ||
|
|
0ea6cdca90 | ||
|
|
d723466df2 | ||
|
|
732c72c98e | ||
|
|
bb4bc8caf4 | ||
|
|
38c5788232 | ||
|
|
7496e70bd7 | ||
|
|
df3fe2aa72 | ||
|
|
c1d5dda62e | ||
|
|
51915b9b0a | ||
|
|
ed575182e3 | ||
|
|
32f2d9d089 | ||
|
|
35c2958ae4 | ||
|
|
b1a8c0fe02 | ||
|
|
3dfb77416f | ||
|
|
1d4296f17f | ||
|
|
a83fb8127a | ||
|
|
9f3874e5c7 | ||
|
|
87521214d3 | ||
|
|
6a8d848a3e | ||
|
|
0d0683c28a | ||
|
|
96ad8280b2 | ||
|
|
0490707671 | ||
|
|
ac98385e55 | ||
|
|
57aaad2ddb | ||
|
|
d25738b61e | ||
|
|
a35c897f0f | ||
|
|
1e879ef458 | ||
|
|
43514f4af6 | ||
|
|
8d75542986 | ||
|
|
3a5b576399 | ||
|
|
77b1290698 | ||
|
|
77bd6b9ec3 | ||
|
|
1bbdd2aba2 | ||
|
|
73bf358f6d | ||
|
|
f706a7e236 | ||
|
|
cfc7c9cf24 | ||
|
|
866117636e | ||
|
|
6c659494f5 | ||
|
|
02a6b39db7 | ||
|
|
f02a6c34e0 | ||
|
|
f9f97c8145 | ||
|
|
84e22168a5 | ||
|
|
b573dbba90 | ||
|
|
0c5cbbbf5c | ||
|
|
9f38a8807c | ||
|
|
64c276c23b | ||
|
|
1ee231956c | ||
|
|
788f56b40a | ||
|
|
c46a607dc1 | ||
|
|
e5106bfb96 | ||
|
|
747423be67 | ||
|
|
607e6b1c33 | ||
|
|
7a236869ba | ||
|
|
9ea971dc04 | ||
|
|
5f7ff732fa | ||
|
|
83024f57a6 | ||
|
|
01ba6a23f2 | ||
|
|
022d0210c5 | ||
|
|
f03b27c72b | ||
|
|
4ca6b42c24 | ||
|
|
bde3829131 | ||
|
|
d00d682069 | ||
|
|
f2951bd4a5 | ||
|
|
8da4573088 | ||
|
|
c03b57465b | ||
|
|
40467726e3 | ||
|
|
2e7ec8c0b9 | ||
|
|
32c97a7f2f | ||
|
|
e2d01795d2 | ||
|
|
589d3eb48f | ||
|
|
cf6034da92 | ||
|
|
ce8c56cc97 | ||
|
|
43c292fa91 | ||
|
|
cb9a0627f0 | ||
|
|
7a6446ac17 | ||
|
|
cd6af4a52e | ||
|
|
8363c6af2e | ||
|
|
6c2bf0e221 | ||
|
|
88575a27e2 | ||
|
|
3a892228f4 | ||
|
|
5fa8e5e13f | ||
|
|
73cf767a35 | ||
|
|
b2588eed03 | ||
|
|
9af78c8e69 | ||
|
|
dda3bf896b | ||
|
|
98650658a7 | ||
|
|
6f6b7f8261 | ||
|
|
bb6242675a | ||
|
|
33f9b08bbb | ||
|
|
e88d48f804 | ||
|
|
dfcc9f8cbc | ||
|
|
16f1c5f0a1 | ||
|
|
bbb3509bc5 | ||
|
|
c5c2871d22 | ||
|
|
90614dfe05 | ||
|
|
ff860e5fe4 | ||
|
|
715835510b |
5
.github/CONTRIBUTING.md
vendored
5
.github/CONTRIBUTING.md
vendored
@@ -29,7 +29,7 @@ uname -sp && tmux -V && echo $TERM
|
||||
|
||||
Also include:
|
||||
|
||||
- Your platform (Linux, OS X, or whatever).
|
||||
- Your platform (Linux, macOS, or whatever).
|
||||
|
||||
- A brief description of the problem with steps to reproduce.
|
||||
|
||||
@@ -37,7 +37,8 @@ Also include:
|
||||
|
||||
- Your terminal, and `$TERM` inside and outside of tmux.
|
||||
|
||||
- Logs from tmux (see below).
|
||||
- Logs from tmux (see below). Please attach logs to the issue directly rather
|
||||
than using a download site or pastebin. Put in a zip file if necessary.
|
||||
|
||||
- At most one or two screenshots, if helpful.
|
||||
|
||||
|
||||
2
.github/README.md
vendored
2
.github/README.md
vendored
@@ -4,7 +4,7 @@ tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
||||
accessed, and controlled from a single screen. tmux may be detached from a
|
||||
screen and continue running in the background, then later reattached.
|
||||
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, macOS and Solaris.
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
10
.github/lock.yml
vendored
10
.github/lock.yml
vendored
@@ -1,10 +0,0 @@
|
||||
daysUntilLock: 30
|
||||
skipCreatedBefore: false
|
||||
exemptLabels: []
|
||||
lockLabel: false
|
||||
lockComment: >
|
||||
This thread has been automatically locked since there has not been
|
||||
any recent activity after it was closed. Please open a new issue for
|
||||
related bugs.
|
||||
setLockReason: false
|
||||
#only: issues
|
||||
23
.github/workflows/lock.yml
vendored
Normal file
23
.github/workflows/lock.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: 'Lock Threads'
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v2
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-lock-inactive-days: '30'
|
||||
pr-lock-inactive-days: '60'
|
||||
issue-lock-comment: >
|
||||
This issue has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
Please open a new issue for related bugs.
|
||||
pr-lock-comment: >
|
||||
This pull request has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
Please open a new issue for related bugs.
|
||||
177
CHANGES
177
CHANGES
@@ -1,3 +1,174 @@
|
||||
CHANGES FROM 3.2a TO 3.3
|
||||
|
||||
* Add an ACL list for users connecting to the tmux socket. Users may be
|
||||
forbidden from attaching, forced to attach read-only, or allowed to attach
|
||||
read-write. A new command, server-access, configures the list. File system
|
||||
permissions must still be configured manually.
|
||||
|
||||
* Emit window-layout-changed on swap-pane.
|
||||
|
||||
* Better error reporting when applying custom layouts.
|
||||
|
||||
* Handle ANSI escape sequences in run-shell output.
|
||||
|
||||
* Add pane_start_path to match start_command.
|
||||
|
||||
* Set PWD so shells have a hint about the real path.
|
||||
|
||||
* Do not allow pipe-pane on dead panes.
|
||||
|
||||
* Do not report mouse positions (incorrectly) above the maximum of 223 in
|
||||
normal mouse mode.
|
||||
|
||||
* Add an option (default off) to control the passthrough escape sequence.
|
||||
|
||||
* Support more mouse buttons when the terminal sends them.
|
||||
|
||||
* Add a window-resized hook which is fired when the window is actually resized
|
||||
which may be later than the client resize.
|
||||
|
||||
* Add next_session_id format with the next session ID.
|
||||
|
||||
* Add formats for client and server UID and user.
|
||||
|
||||
* Add argument to refresh-client -l to forward clipboard to a pane.
|
||||
|
||||
* Add remain-on-exit-format to set text shown when pane is dead.
|
||||
|
||||
* With split-window -f use percentages of window size not pane size.
|
||||
|
||||
* Add an option (fill-character) to set the character used for unused areas of
|
||||
a client.
|
||||
|
||||
* Add an option (scroll-on-clear) to control if tmux scrolls into history on
|
||||
clear.
|
||||
|
||||
* Add a capability for OSC 7 and use it similarly to how the title is set (and
|
||||
controlled by the same set-titles option).
|
||||
|
||||
* Add support for systemd socket activation (where systemd creates the Unix
|
||||
domain socket for tmux rather than tmux creating it). Build with
|
||||
--enable-systemd.
|
||||
|
||||
* Add an option (pane-border-indicators) to select how the active pane is shown
|
||||
on the pane border (colour, arrows or both).
|
||||
|
||||
* Support underscore styles with capture-pane -e.
|
||||
|
||||
* Make pane-border-format a pane option rather than window.
|
||||
|
||||
* Respond to OSC 4 queries
|
||||
|
||||
* Fix g/G keys in modes to do the same thing as copy mode (and vi).
|
||||
|
||||
* Bump the time terminals have to respond to device attributes queries to three
|
||||
seconds.
|
||||
|
||||
* If automatic-rename is off, allow the rename escape sequence to set an empty
|
||||
name.
|
||||
|
||||
* Trim menu item text more intelligently.
|
||||
|
||||
* Add cursor-style and cursor-colour options to set the default cursor style
|
||||
and colour.
|
||||
|
||||
* Accept some useful and non-conflicting emacs keys in vi normal mode at the
|
||||
command prompt.
|
||||
|
||||
* Add a format modifier (c) to force a colour to RGB.
|
||||
|
||||
* Add -s and -S to display-popup to set styles, -b to set lines and -T to set
|
||||
popup title. New popup-border-lines, popup-border-style and popup-style
|
||||
options set the defaults.
|
||||
|
||||
* Add -e flag to set an environment variable for a popup.
|
||||
|
||||
* Make send-keys without arguments send the key it is bound to (if bound to a
|
||||
key).
|
||||
|
||||
* Try to leave terminal cursor at the right position even when tmux is drawing
|
||||
its own cursor or selection (such as at the command prompt and in choose
|
||||
mode) for people using screen readers and similar which can make use of it.
|
||||
|
||||
* Change so that {} is converted to tmux commands immediately when parsed. This
|
||||
means it must contain valid tmux commands. For commands which expand %% and
|
||||
%%%, this now only happens within string arguments. Use of nested aliases
|
||||
inside {} is now forbidden. Processing of commands given in quotes remains
|
||||
the same.
|
||||
|
||||
* Disable evports on SunOS since they are broken.
|
||||
|
||||
* Do not expand the file given with tmux -f so it can contain :s.
|
||||
|
||||
* Bump FORMAT_LOOP_LIMIT and add a log message when hit.
|
||||
|
||||
* Add a terminal feature for the mouse (since FreeBSD termcap does not have kmous).
|
||||
|
||||
* Forbid empty session names.
|
||||
|
||||
* Improve error reporting when the tmux /tmp directory cannot be created or
|
||||
used.
|
||||
|
||||
* Give #() commands a one second grace period where the output is empty before
|
||||
telling the user they aren't doing anything ("not ready").
|
||||
|
||||
* When building, pick default-terminal from the first of tmux-256color, tmux,
|
||||
screen-256color, screen that is available on the build system (--with-TERM
|
||||
can override).
|
||||
|
||||
* Do not close popups on resize, instead adjust them to fit.
|
||||
|
||||
* Add a client-active hook.
|
||||
|
||||
* Make window-linked and window-unlinked window options.
|
||||
|
||||
* Do not configure on macOS without the user making a choice about utf8proc
|
||||
(either --enable-utf8proc or --disable-utf8proc).
|
||||
|
||||
* Do not freeze output in panes when a popup is open, let them continue to
|
||||
redraw.
|
||||
|
||||
* Add pipe variants of the line copy commands.
|
||||
|
||||
* Change copy-line and copy-end-of-line not to cancel and add -and-cancel
|
||||
variants, like the other copy commands.
|
||||
|
||||
* Support the OSC palette-setting sequences in popups.
|
||||
|
||||
* Add a pane-colours array option to specify the defaults palette.
|
||||
|
||||
* Add support for Unicode zero-width joiner.
|
||||
|
||||
* Make newline a style delimiter as well so they can cross multiple lines for
|
||||
readability in configuration files.
|
||||
|
||||
* Change focus to be driven by events rather than scanning panes so the
|
||||
ordering of in and out is consistent.
|
||||
|
||||
* Add display-popup -B to open a popup without a border.
|
||||
|
||||
* Add a menu for popups that can be opened with button three outside the popup
|
||||
or on the left or top border. Resizing now only works on the right and bottom
|
||||
borders or when using Meta. The menu allows a popup to be closed, expanded to
|
||||
the full size of the client, centered in the client or changed into a pane.
|
||||
|
||||
* Make command-prompt and confirm-before block by default (like run-shell). A
|
||||
new -b flags runs them in the background as before. Also set return code for
|
||||
confirm-before.
|
||||
|
||||
* Change cursor style handling so tmux understands which sequences contain
|
||||
blinking and sets the flag appropriately, means that it works whether cnorm
|
||||
disables blinking or not. This now matches xterm's behaviour.
|
||||
|
||||
* More accurate vi(1) word navigation in copy mode and on the status line. This
|
||||
changes the meaning of the word-separators option: setting it to the empty
|
||||
string is equivalent to the previous behavior.
|
||||
|
||||
* Add -F for command-prompt and use it to fix "Rename" on the window menu.
|
||||
|
||||
* Add different command histories for different types of prompts ("command",
|
||||
"search" etc).
|
||||
|
||||
CHANGES FROM 3.2 TO 3.2a
|
||||
|
||||
* Add an "always" value for the "extended-keys" option; if set then tmux will
|
||||
@@ -118,7 +289,7 @@ CHANGES FROM 3.1c TO 3.2
|
||||
|
||||
* Add a way for control mode clients to subscribe to a format and be notified
|
||||
of changes rather than having to poll.
|
||||
|
||||
|
||||
* Add some formats for search in copy mode (search_present, search_match).
|
||||
|
||||
* Do not wait on shutdown for commands started with run -b.
|
||||
@@ -242,7 +413,7 @@ CHANGES FROM 3.1c TO 3.2
|
||||
only show windows and C-b . only targets.
|
||||
|
||||
* Change all the style options to string options so they can support formats.
|
||||
Change pane-border-active-style to use this to change the border colour when
|
||||
Change pane-active-border-style to use this to change the border colour when
|
||||
in a mode or with synchronize-panes on. This also implies a few minor changes
|
||||
to existing behaviour:
|
||||
|
||||
@@ -3100,7 +3271,7 @@ The list of older changes is below.
|
||||
* (nicm) -n on new-session is now -s, and -n is now the initial window name.
|
||||
This was documented but not implemented :-/.
|
||||
* (nicm) kill-window command, bound to & by default (because it should be hard
|
||||
to hit accidently).
|
||||
to hit accidentally).
|
||||
* (nicm) bell-style option with three choices: "none" completely ignore bell;
|
||||
"any" pass through a bell in any window to current; "current" ignore bells
|
||||
except in current window. This applies only to the bell terminal signal,
|
||||
|
||||
15
Makefile.am
15
Makefile.am
@@ -13,7 +13,8 @@ dist_EXTRA_tmux_SOURCES = compat/*.[ch]
|
||||
# Preprocessor flags.
|
||||
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
||||
-DTMUX_VERSION='"@VERSION@"' \
|
||||
-DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"'
|
||||
-DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"' \
|
||||
-DTMUX_TERM='"@DEFAULT_TERM@"'
|
||||
|
||||
# Additional object files.
|
||||
LDADD = $(LIBOBJS)
|
||||
@@ -29,6 +30,9 @@ AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
||||
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k
|
||||
if IS_DARWIN
|
||||
AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align
|
||||
endif
|
||||
AM_CPPFLAGS += -DDEBUG
|
||||
endif
|
||||
AM_CPPFLAGS += -iquote.
|
||||
@@ -119,12 +123,14 @@ dist_tmux_SOURCES = \
|
||||
cmd-select-pane.c \
|
||||
cmd-select-window.c \
|
||||
cmd-send-keys.c \
|
||||
cmd-server-access.c \
|
||||
cmd-set-buffer.c \
|
||||
cmd-set-environment.c \
|
||||
cmd-set-option.c \
|
||||
cmd-show-environment.c \
|
||||
cmd-show-messages.c \
|
||||
cmd-show-options.c \
|
||||
cmd-show-prompt-history.c \
|
||||
cmd-source-file.c \
|
||||
cmd-split-window.c \
|
||||
cmd-swap-pane.c \
|
||||
@@ -167,6 +173,7 @@ dist_tmux_SOURCES = \
|
||||
screen-redraw.c \
|
||||
screen-write.c \
|
||||
screen.c \
|
||||
server-acl.c \
|
||||
server-client.c \
|
||||
server-fn.c \
|
||||
server.c \
|
||||
@@ -176,6 +183,7 @@ dist_tmux_SOURCES = \
|
||||
style.c \
|
||||
tmux.c \
|
||||
tmux.h \
|
||||
tmux-protocol.h \
|
||||
tty-acs.c \
|
||||
tty-features.c \
|
||||
tty-keys.c \
|
||||
@@ -198,6 +206,11 @@ if NEED_FORKPTY
|
||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
||||
endif
|
||||
|
||||
# Add compat file for systemd.
|
||||
if HAVE_SYSTEMD
|
||||
nodist_tmux_SOURCES += compat/systemd.c
|
||||
endif
|
||||
|
||||
# Add compat file for utf8proc.
|
||||
if HAVE_UTF8PROC
|
||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
||||
|
||||
10
README
10
README
@@ -4,7 +4,7 @@ tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
||||
accessed, and controlled from a single screen. tmux may be detached from a
|
||||
screen and continue running in the background, then later reattached.
|
||||
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, macOS and Solaris.
|
||||
|
||||
* Dependencies
|
||||
|
||||
@@ -55,6 +55,14 @@ source tree with:
|
||||
|
||||
A small example configuration is in example_tmux.conf.
|
||||
|
||||
Other documentation is available in the wiki:
|
||||
|
||||
https://github.com/tmux/tmux/wiki
|
||||
|
||||
Also see the tmux FAQ at:
|
||||
|
||||
https://github.com/tmux/tmux/wiki/FAQ
|
||||
|
||||
A bash(1) completion file is at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
|
||||
@@ -3,7 +3,7 @@ tmuxへようこそ!
|
||||
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
||||
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
||||
|
||||
OpenBSD、FreeBSD、NetBSD、Linux、OS X、Solarisで実行できます。
|
||||
OpenBSD、FreeBSD、NetBSD、Linux、macOS、Solarisで実行できます。
|
||||
|
||||
tmuxはlibevent 2.x.に依存します。 下記からダウンロードしてください。
|
||||
|
||||
|
||||
2
SYNCING
2
SYNCING
@@ -89,7 +89,7 @@ of the remote name "obsd-tmux", we can now create the master branch from
|
||||
% git checkout -b obsd-master obsd-tmux/master
|
||||
|
||||
Adding in the fake history points
|
||||
=================================
|
||||
=================================
|
||||
|
||||
To tie both the "master" branch from "tmux" and the "obsd-master"
|
||||
branch from "tmux-openbsd" together, the fake history points added to the
|
||||
|
||||
652
arguments.c
652
arguments.c
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -28,12 +29,10 @@
|
||||
* Manipulate command arguments.
|
||||
*/
|
||||
|
||||
struct args_value {
|
||||
char *value;
|
||||
TAILQ_ENTRY(args_value) entry;
|
||||
};
|
||||
/* List of argument values. */
|
||||
TAILQ_HEAD(args_values, args_value);
|
||||
|
||||
/* Single arguments flag. */
|
||||
struct args_entry {
|
||||
u_char flag;
|
||||
struct args_values values;
|
||||
@@ -41,6 +40,20 @@ struct args_entry {
|
||||
RB_ENTRY(args_entry) entry;
|
||||
};
|
||||
|
||||
/* Parsed argument flags and values. */
|
||||
struct args {
|
||||
struct args_tree tree;
|
||||
u_int count;
|
||||
struct args_value *values;
|
||||
};
|
||||
|
||||
/* Prepared command state. */
|
||||
struct args_command_state {
|
||||
struct cmd_list *cmdlist;
|
||||
char *cmd;
|
||||
struct cmd_parse_input pi;
|
||||
};
|
||||
|
||||
static struct args_entry *args_find(struct args *, u_char);
|
||||
|
||||
static int args_cmp(struct args_entry *, struct args_entry *);
|
||||
@@ -63,38 +76,300 @@ args_find(struct args *args, u_char flag)
|
||||
return (RB_FIND(args_tree, &args->tree, &entry));
|
||||
}
|
||||
|
||||
/* Parse an argv and argc into a new argument set. */
|
||||
struct args *
|
||||
args_parse(const char *template, int argc, char **argv)
|
||||
/* Copy value. */
|
||||
static void
|
||||
args_copy_value(struct args_value *to, struct args_value *from)
|
||||
{
|
||||
struct args *args;
|
||||
int opt;
|
||||
to->type = from->type;
|
||||
switch (from->type) {
|
||||
case ARGS_NONE:
|
||||
break;
|
||||
case ARGS_COMMANDS:
|
||||
to->cmdlist = from->cmdlist;
|
||||
to->cmdlist->references++;
|
||||
break;
|
||||
case ARGS_STRING:
|
||||
to->string = xstrdup(from->string);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get value as string. */
|
||||
static const char *
|
||||
args_value_as_string(struct args_value *value)
|
||||
{
|
||||
switch (value->type) {
|
||||
case ARGS_NONE:
|
||||
return ("");
|
||||
case ARGS_COMMANDS:
|
||||
if (value->cached == NULL)
|
||||
value->cached = cmd_list_print(value->cmdlist, 0);
|
||||
return (value->cached);
|
||||
case ARGS_STRING:
|
||||
return (value->string);
|
||||
}
|
||||
fatalx("unexpected argument type");
|
||||
}
|
||||
|
||||
/* Create an empty arguments set. */
|
||||
struct args *
|
||||
args_create(void)
|
||||
{
|
||||
struct args *args;
|
||||
|
||||
args = xcalloc(1, sizeof *args);
|
||||
|
||||
optreset = 1;
|
||||
optind = 1;
|
||||
optarg = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
||||
if (opt < 0)
|
||||
continue;
|
||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
args_set(args, opt, optarg);
|
||||
optarg = NULL;
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
args->argc = argc;
|
||||
args->argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
RB_INIT(&args->tree);
|
||||
return (args);
|
||||
}
|
||||
|
||||
/* Parse arguments into a new argument set. */
|
||||
struct args *
|
||||
args_parse(const struct args_parse *parse, struct args_value *values,
|
||||
u_int count, char **cause)
|
||||
{
|
||||
struct args *args;
|
||||
u_int i;
|
||||
enum args_parse_type type;
|
||||
struct args_value *value, *new;
|
||||
u_char flag;
|
||||
const char *found, *string, *s;
|
||||
int optional_argument;
|
||||
|
||||
if (count == 0)
|
||||
return (args_create());
|
||||
|
||||
args = args_create();
|
||||
for (i = 1; i < count; /* nothing */) {
|
||||
value = &values[i];
|
||||
if (value->type != ARGS_STRING)
|
||||
break;
|
||||
|
||||
string = value->string;
|
||||
if (*string++ != '-' || *string == '\0')
|
||||
break;
|
||||
i++;
|
||||
if (string[0] == '-' && string[1] == '\0')
|
||||
break;
|
||||
|
||||
for (;;) {
|
||||
flag = *string++;
|
||||
if (flag == '\0')
|
||||
break;
|
||||
if (flag == '?') {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (!isalnum(flag)) {
|
||||
xasprintf(cause, "invalid flag -%c", flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
found = strchr(parse->template, flag);
|
||||
if (found == NULL) {
|
||||
xasprintf(cause, "unknown flag -%c", flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (*++found != ':') {
|
||||
log_debug("%s: -%c", __func__, flag);
|
||||
args_set(args, flag, NULL);
|
||||
continue;
|
||||
}
|
||||
if (*found == ':') {
|
||||
optional_argument = 1;
|
||||
found++;
|
||||
}
|
||||
new = xcalloc(1, sizeof *new);
|
||||
if (*string != '\0') {
|
||||
new->type = ARGS_STRING;
|
||||
new->string = xstrdup(string);
|
||||
} else {
|
||||
if (i == count) {
|
||||
if (optional_argument) {
|
||||
log_debug("%s: -%c", __func__,
|
||||
flag);
|
||||
args_set(args, flag, NULL);
|
||||
continue;
|
||||
}
|
||||
xasprintf(cause,
|
||||
"-%c expects an argument",
|
||||
flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (values[i].type != ARGS_STRING) {
|
||||
xasprintf(cause,
|
||||
"-%c argument must be a string",
|
||||
flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
args_copy_value(new, &values[i++]);
|
||||
}
|
||||
s = args_value_as_string(new);
|
||||
log_debug("%s: -%c = %s", __func__, flag, s);
|
||||
args_set(args, flag, new);
|
||||
break;
|
||||
}
|
||||
}
|
||||
log_debug("%s: flags end at %u of %u", __func__, i, count);
|
||||
if (i != count) {
|
||||
for (/* nothing */; i < count; i++) {
|
||||
value = &values[i];
|
||||
|
||||
s = args_value_as_string(value);
|
||||
log_debug("%s: %u = %s (type %d)", __func__, i, s,
|
||||
value->type);
|
||||
|
||||
if (parse->cb != NULL) {
|
||||
type = parse->cb(args, args->count, cause);
|
||||
if (type == ARGS_PARSE_INVALID) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
} else
|
||||
type = ARGS_PARSE_STRING;
|
||||
|
||||
args->values = xrecallocarray(args->values,
|
||||
args->count, args->count + 1, sizeof *args->values);
|
||||
new = &args->values[args->count++];
|
||||
|
||||
switch (type) {
|
||||
case ARGS_PARSE_INVALID:
|
||||
fatalx("unexpected argument type");
|
||||
case ARGS_PARSE_STRING:
|
||||
if (value->type != ARGS_STRING) {
|
||||
xasprintf(cause,
|
||||
"argument %u must be \"string\"",
|
||||
args->count);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
args_copy_value(new, value);
|
||||
break;
|
||||
case ARGS_PARSE_COMMANDS_OR_STRING:
|
||||
args_copy_value(new, value);
|
||||
break;
|
||||
case ARGS_PARSE_COMMANDS:
|
||||
if (value->type != ARGS_COMMANDS) {
|
||||
xasprintf(cause,
|
||||
"argument %u must be { commands }",
|
||||
args->count);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
args_copy_value(new, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parse->lower != -1 && args->count < (u_int)parse->lower) {
|
||||
xasprintf(cause,
|
||||
"too few arguments (need at least %u)",
|
||||
parse->lower);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (parse->upper != -1 && args->count > (u_int)parse->upper) {
|
||||
xasprintf(cause,
|
||||
"too many arguments (need at most %u)",
|
||||
parse->upper);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
return (args);
|
||||
}
|
||||
|
||||
/* Copy and expand a value. */
|
||||
static void
|
||||
args_copy_copy_value(struct args_value *to, struct args_value *from, int argc,
|
||||
char **argv)
|
||||
{
|
||||
char *s, *expanded;
|
||||
int i;
|
||||
|
||||
to->type = from->type;
|
||||
switch (from->type) {
|
||||
case ARGS_NONE:
|
||||
break;
|
||||
case ARGS_STRING:
|
||||
expanded = xstrdup(from->string);
|
||||
for (i = 0; i < argc; i++) {
|
||||
s = cmd_template_replace(expanded, argv[i], i + 1);
|
||||
free(expanded);
|
||||
expanded = s;
|
||||
}
|
||||
to->string = expanded;
|
||||
break;
|
||||
case ARGS_COMMANDS:
|
||||
to->cmdlist = cmd_list_copy(from->cmdlist, argc, argv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy an arguments set. */
|
||||
struct args *
|
||||
args_copy(struct args *args, int argc, char **argv)
|
||||
{
|
||||
struct args *new_args;
|
||||
struct args_entry *entry;
|
||||
struct args_value *value, *new_value;
|
||||
u_int i;
|
||||
|
||||
cmd_log_argv(argc, argv, "%s", __func__);
|
||||
|
||||
new_args = args_create();
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (TAILQ_EMPTY(&entry->values)) {
|
||||
for (i = 0; i < entry->count; i++)
|
||||
args_set(new_args, entry->flag, NULL);
|
||||
continue;
|
||||
}
|
||||
TAILQ_FOREACH(value, &entry->values, entry) {
|
||||
new_value = xcalloc(1, sizeof *new_value);
|
||||
args_copy_copy_value(new_value, value, argc, argv);
|
||||
args_set(new_args, entry->flag, new_value);
|
||||
}
|
||||
}
|
||||
if (args->count == 0)
|
||||
return (new_args);
|
||||
new_args->count = args->count;
|
||||
new_args->values = xcalloc(args->count, sizeof *new_args->values);
|
||||
for (i = 0; i < args->count; i++) {
|
||||
new_value = &new_args->values[i];
|
||||
args_copy_copy_value(new_value, &args->values[i], argc, argv);
|
||||
}
|
||||
return (new_args);
|
||||
}
|
||||
|
||||
/* Free a value. */
|
||||
void
|
||||
args_free_value(struct args_value *value)
|
||||
{
|
||||
switch (value->type) {
|
||||
case ARGS_NONE:
|
||||
break;
|
||||
case ARGS_STRING:
|
||||
free(value->string);
|
||||
break;
|
||||
case ARGS_COMMANDS:
|
||||
cmd_list_free(value->cmdlist);
|
||||
break;
|
||||
}
|
||||
free(value->cached);
|
||||
}
|
||||
|
||||
/* Free values. */
|
||||
void
|
||||
args_free_values(struct args_value *values, u_int count)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
args_free_value(&values[i]);
|
||||
}
|
||||
|
||||
/* Free an arguments set. */
|
||||
void
|
||||
args_free(struct args *args)
|
||||
@@ -104,13 +379,14 @@ args_free(struct args *args)
|
||||
struct args_value *value;
|
||||
struct args_value *value1;
|
||||
|
||||
cmd_free_argv(args->argc, args->argv);
|
||||
args_free_values(args->values, args->count);
|
||||
free(args->values);
|
||||
|
||||
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
||||
RB_REMOVE(args_tree, &args->tree, entry);
|
||||
TAILQ_FOREACH_SAFE(value, &entry->values, entry, value1) {
|
||||
TAILQ_REMOVE(&entry->values, value, entry);
|
||||
free(value->value);
|
||||
args_free_value(value);
|
||||
free(value);
|
||||
}
|
||||
free(entry);
|
||||
@@ -119,11 +395,52 @@ args_free(struct args *args)
|
||||
free(args);
|
||||
}
|
||||
|
||||
/* Convert arguments to vector. */
|
||||
void
|
||||
args_to_vector(struct args *args, int *argc, char ***argv)
|
||||
{
|
||||
char *s;
|
||||
u_int i;
|
||||
|
||||
*argc = 0;
|
||||
*argv = NULL;
|
||||
|
||||
for (i = 0; i < args->count; i++) {
|
||||
switch (args->values[i].type) {
|
||||
case ARGS_NONE:
|
||||
break;
|
||||
case ARGS_STRING:
|
||||
cmd_append_argv(argc, argv, args->values[i].string);
|
||||
break;
|
||||
case ARGS_COMMANDS:
|
||||
s = cmd_list_print(args->values[i].cmdlist, 0);
|
||||
cmd_append_argv(argc, argv, s);
|
||||
free(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert arguments from vector. */
|
||||
struct args_value *
|
||||
args_from_vector(int argc, char **argv)
|
||||
{
|
||||
struct args_value *values;
|
||||
int i;
|
||||
|
||||
values = xcalloc(argc, sizeof *values);
|
||||
for (i = 0; i < argc; i++) {
|
||||
values[i].type = ARGS_STRING;
|
||||
values[i].string = xstrdup(argv[i]);
|
||||
}
|
||||
return (values);
|
||||
}
|
||||
|
||||
/* Add to string. */
|
||||
static void printflike(3, 4)
|
||||
args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
char *s;
|
||||
size_t slen;
|
||||
|
||||
@@ -140,43 +457,35 @@ args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
||||
|
||||
/* Add value to string. */
|
||||
static void
|
||||
args_print_add_value(char **buf, size_t *len, struct args_entry *entry,
|
||||
struct args_value *value)
|
||||
args_print_add_value(char **buf, size_t *len, struct args_value *value)
|
||||
{
|
||||
char *escaped;
|
||||
|
||||
if (**buf != '\0')
|
||||
args_print_add(buf, len, " -%c ", entry->flag);
|
||||
else
|
||||
args_print_add(buf, len, "-%c ", entry->flag);
|
||||
|
||||
escaped = args_escape(value->value);
|
||||
args_print_add(buf, len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
|
||||
/* Add argument to string. */
|
||||
static void
|
||||
args_print_add_argument(char **buf, size_t *len, const char *argument)
|
||||
{
|
||||
char *escaped;
|
||||
char *expanded = NULL;
|
||||
|
||||
if (**buf != '\0')
|
||||
args_print_add(buf, len, " ");
|
||||
|
||||
escaped = args_escape(argument);
|
||||
args_print_add(buf, len, "%s", escaped);
|
||||
free(escaped);
|
||||
switch (value->type) {
|
||||
case ARGS_NONE:
|
||||
break;
|
||||
case ARGS_COMMANDS:
|
||||
expanded = cmd_list_print(value->cmdlist, 0);
|
||||
args_print_add(buf, len, "{ %s }", expanded);
|
||||
break;
|
||||
case ARGS_STRING:
|
||||
expanded = args_escape(value->string);
|
||||
args_print_add(buf, len, "%s", expanded);
|
||||
break;
|
||||
}
|
||||
free(expanded);
|
||||
}
|
||||
|
||||
/* Print a set of arguments. */
|
||||
char *
|
||||
args_print(struct args *args)
|
||||
{
|
||||
size_t len;
|
||||
size_t len;
|
||||
char *buf;
|
||||
int i;
|
||||
u_int j;
|
||||
u_int i, j;
|
||||
struct args_entry *entry;
|
||||
struct args_value *value;
|
||||
|
||||
@@ -196,13 +505,18 @@ args_print(struct args *args)
|
||||
|
||||
/* Then the flags with arguments. */
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
TAILQ_FOREACH(value, &entry->values, entry)
|
||||
args_print_add_value(&buf, &len, entry, value);
|
||||
TAILQ_FOREACH(value, &entry->values, entry) {
|
||||
if (*buf != '\0')
|
||||
args_print_add(&buf, &len, " -%c", entry->flag);
|
||||
else
|
||||
args_print_add(&buf, &len, "-%c", entry->flag);
|
||||
args_print_add_value(&buf, &len, value);
|
||||
}
|
||||
}
|
||||
|
||||
/* And finally the argument vector. */
|
||||
for (i = 0; i < args->argc; i++)
|
||||
args_print_add_argument(&buf, &len, args->argv[i]);
|
||||
for (i = 0; i < args->count; i++)
|
||||
args_print_add_value(&buf, &len, &args->values[i]);
|
||||
|
||||
return (buf);
|
||||
}
|
||||
@@ -211,7 +525,7 @@ args_print(struct args *args)
|
||||
char *
|
||||
args_escape(const char *s)
|
||||
{
|
||||
static const char dquoted[] = " #';${}";
|
||||
static const char dquoted[] = " #';${}%";
|
||||
static const char squoted[] = " \"";
|
||||
char *escaped, *result;
|
||||
int flags, quotes = 0;
|
||||
@@ -268,10 +582,9 @@ args_has(struct args *args, u_char flag)
|
||||
|
||||
/* Set argument value in the arguments tree. */
|
||||
void
|
||||
args_set(struct args *args, u_char flag, const char *s)
|
||||
args_set(struct args *args, u_char flag, struct args_value *value)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
struct args_value *value;
|
||||
|
||||
entry = args_find(args, flag);
|
||||
if (entry == NULL) {
|
||||
@@ -282,12 +595,8 @@ args_set(struct args *args, u_char flag, const char *s)
|
||||
RB_INSERT(args_tree, &args->tree, entry);
|
||||
} else
|
||||
entry->count++;
|
||||
|
||||
if (s != NULL) {
|
||||
value = xcalloc(1, sizeof *value);
|
||||
value->value = xstrdup(s);
|
||||
if (value != NULL && value->type != ARGS_NONE)
|
||||
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get argument value. Will be NULL if it isn't present. */
|
||||
@@ -300,7 +609,7 @@ args_get(struct args *args, u_char flag)
|
||||
return (NULL);
|
||||
if (TAILQ_EMPTY(&entry->values))
|
||||
return (NULL);
|
||||
return (TAILQ_LAST(&entry->values, args_values)->value);
|
||||
return (TAILQ_LAST(&entry->values, args_values)->string);
|
||||
}
|
||||
|
||||
/* Get first argument. */
|
||||
@@ -323,31 +632,188 @@ args_next(struct args_entry **entry)
|
||||
return ((*entry)->flag);
|
||||
}
|
||||
|
||||
/* Get first value in argument. */
|
||||
/* Get argument count. */
|
||||
u_int
|
||||
args_count(struct args *args)
|
||||
{
|
||||
return (args->count);
|
||||
}
|
||||
|
||||
/* Get argument values. */
|
||||
struct args_value *
|
||||
args_values(struct args *args)
|
||||
{
|
||||
return (args->values);
|
||||
}
|
||||
|
||||
/* Get argument value. */
|
||||
struct args_value *
|
||||
args_value(struct args *args, u_int idx)
|
||||
{
|
||||
if (idx >= args->count)
|
||||
return (NULL);
|
||||
return (&args->values[idx]);
|
||||
}
|
||||
|
||||
/* Return argument as string. */
|
||||
const char *
|
||||
args_first_value(struct args *args, u_char flag, struct args_value **value)
|
||||
args_string(struct args *args, u_int idx)
|
||||
{
|
||||
if (idx >= args->count)
|
||||
return (NULL);
|
||||
return (args_value_as_string(&args->values[idx]));
|
||||
}
|
||||
|
||||
/* Make a command now. */
|
||||
struct cmd_list *
|
||||
args_make_commands_now(struct cmd *self, struct cmdq_item *item, u_int idx,
|
||||
int expand)
|
||||
{
|
||||
struct args_command_state *state;
|
||||
char *error;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
state = args_make_commands_prepare(self, item, idx, NULL, 0, expand);
|
||||
cmdlist = args_make_commands(state, 0, NULL, &error);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
}
|
||||
else
|
||||
cmdlist->references++;
|
||||
args_make_commands_free(state);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
/* Save bits to make a command later. */
|
||||
struct args_command_state *
|
||||
args_make_commands_prepare(struct cmd *self, struct cmdq_item *item, u_int idx,
|
||||
const char *default_command, int wait, int expand)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct args_value *value;
|
||||
struct args_command_state *state;
|
||||
const char *cmd;
|
||||
|
||||
state = xcalloc(1, sizeof *state);
|
||||
|
||||
if (idx < args->count) {
|
||||
value = &args->values[idx];
|
||||
if (value->type == ARGS_COMMANDS) {
|
||||
state->cmdlist = value->cmdlist;
|
||||
state->cmdlist->references++;
|
||||
return (state);
|
||||
}
|
||||
cmd = value->string;
|
||||
} else {
|
||||
if (default_command == NULL)
|
||||
fatalx("argument out of range");
|
||||
cmd = default_command;
|
||||
}
|
||||
|
||||
|
||||
if (expand)
|
||||
state->cmd = format_single_from_target(item, cmd);
|
||||
else
|
||||
state->cmd = xstrdup(cmd);
|
||||
log_debug("%s: %s", __func__, state->cmd);
|
||||
|
||||
if (wait)
|
||||
state->pi.item = item;
|
||||
cmd_get_source(self, &state->pi.file, &state->pi.line);
|
||||
state->pi.c = tc;
|
||||
if (state->pi.c != NULL)
|
||||
state->pi.c->references++;
|
||||
cmd_find_copy_state(&state->pi.fs, target);
|
||||
|
||||
return (state);
|
||||
}
|
||||
|
||||
/* Return argument as command. */
|
||||
struct cmd_list *
|
||||
args_make_commands(struct args_command_state *state, int argc, char **argv,
|
||||
char **error)
|
||||
{
|
||||
struct cmd_parse_result *pr;
|
||||
char *cmd, *new_cmd;
|
||||
int i;
|
||||
|
||||
if (state->cmdlist != NULL) {
|
||||
if (argc == 0)
|
||||
return (state->cmdlist);
|
||||
return (cmd_list_copy(state->cmdlist, argc, argv));
|
||||
}
|
||||
|
||||
cmd = xstrdup(state->cmd);
|
||||
for (i = 0; i < argc; i++) {
|
||||
new_cmd = cmd_template_replace(cmd, argv[i], i + 1);
|
||||
log_debug("%s: %%%u %s: %s", __func__, i + 1, argv[i], new_cmd);
|
||||
free(cmd);
|
||||
cmd = new_cmd;
|
||||
}
|
||||
log_debug("%s: %s", __func__, cmd);
|
||||
|
||||
pr = cmd_parse_from_string(cmd, &state->pi);
|
||||
free(cmd);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_ERROR:
|
||||
*error = pr->error;
|
||||
return (NULL);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
return (pr->cmdlist);
|
||||
}
|
||||
fatalx("invalid parse return state");
|
||||
}
|
||||
|
||||
/* Free commands state. */
|
||||
void
|
||||
args_make_commands_free(struct args_command_state *state)
|
||||
{
|
||||
if (state->cmdlist != NULL)
|
||||
cmd_list_free(state->cmdlist);
|
||||
if (state->pi.c != NULL)
|
||||
server_client_unref(state->pi.c);
|
||||
free(state->cmd);
|
||||
free(state);
|
||||
}
|
||||
|
||||
/* Get prepared command. */
|
||||
char *
|
||||
args_make_commands_get_command(struct args_command_state *state)
|
||||
{
|
||||
struct cmd *first;
|
||||
int n;
|
||||
char *s;
|
||||
|
||||
if (state->cmdlist != NULL) {
|
||||
first = cmd_list_first(state->cmdlist);
|
||||
if (first == NULL)
|
||||
return (xstrdup(""));
|
||||
return (xstrdup(cmd_get_entry(first)->name));
|
||||
}
|
||||
n = strcspn(state->cmd, " ,");
|
||||
xasprintf(&s, "%.*s", n, state->cmd);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* Get first value in argument. */
|
||||
struct args_value *
|
||||
args_first_value(struct args *args, u_char flag)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
|
||||
if ((entry = args_find(args, flag)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
*value = TAILQ_FIRST(&entry->values);
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
return ((*value)->value);
|
||||
return (TAILQ_FIRST(&entry->values));
|
||||
}
|
||||
|
||||
/* Get next value in argument. */
|
||||
const char *
|
||||
args_next_value(struct args_value **value)
|
||||
struct args_value *
|
||||
args_next_value(struct args_value *value)
|
||||
{
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
*value = TAILQ_NEXT(*value, entry);
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
return ((*value)->value);
|
||||
return (TAILQ_NEXT(value, entry));
|
||||
}
|
||||
|
||||
/* Convert an argument value to a number. */
|
||||
@@ -356,7 +822,7 @@ args_strtonum(struct args *args, u_char flag, long long minval,
|
||||
long long maxval, char **cause)
|
||||
{
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
long long ll;
|
||||
struct args_entry *entry;
|
||||
struct args_value *value;
|
||||
|
||||
@@ -365,8 +831,14 @@ args_strtonum(struct args *args, u_char flag, long long minval,
|
||||
return (0);
|
||||
}
|
||||
value = TAILQ_LAST(&entry->values, args_values);
|
||||
if (value == NULL ||
|
||||
value->type != ARGS_STRING ||
|
||||
value->string == NULL) {
|
||||
*cause = xstrdup("missing");
|
||||
return (0);
|
||||
}
|
||||
|
||||
ll = strtonum(value->value, minval, maxval, &errstr);
|
||||
ll = strtonum(value->string, minval, maxval, &errstr);
|
||||
if (errstr != NULL) {
|
||||
*cause = xstrdup(errstr);
|
||||
return (0);
|
||||
@@ -388,7 +860,7 @@ args_percentage(struct args *args, u_char flag, long long minval,
|
||||
*cause = xstrdup("missing");
|
||||
return (0);
|
||||
}
|
||||
value = TAILQ_LAST(&entry->values, args_values)->value;
|
||||
value = TAILQ_LAST(&entry->values, args_values)->string;
|
||||
return (args_string_percentage(value, minval, maxval, curval, cause));
|
||||
}
|
||||
|
||||
@@ -398,7 +870,7 @@ args_string_percentage(const char *value, long long minval, long long maxval,
|
||||
long long curval, char **cause)
|
||||
{
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
long long ll;
|
||||
size_t valuelen = strlen(value);
|
||||
char *copy;
|
||||
|
||||
|
||||
6
cfg.c
6
cfg.c
@@ -124,8 +124,6 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
||||
|
||||
pr = cmd_parse_from_file(f, &pi);
|
||||
fclose(f);
|
||||
if (pr->status == CMD_PARSE_EMPTY)
|
||||
return (0);
|
||||
if (pr->status == CMD_PARSE_ERROR) {
|
||||
cfg_add_cause("%s", pr->error);
|
||||
free(pr->error);
|
||||
@@ -178,8 +176,6 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
||||
pi.c = c;
|
||||
|
||||
pr = cmd_parse_from_buffer(buf, len, &pi);
|
||||
if (pr->status == CMD_PARSE_EMPTY)
|
||||
return (0);
|
||||
if (pr->status == CMD_PARSE_ERROR) {
|
||||
cfg_add_cause("%s", pr->error);
|
||||
free(pr->error);
|
||||
@@ -254,7 +250,7 @@ cfg_show_causes(struct session *s)
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
||||
window_copy_add(wp, 0, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
}
|
||||
|
||||
|
||||
15
client.c
15
client.c
@@ -243,6 +243,7 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
||||
ssize_t linelen;
|
||||
char *line = NULL, **caps = NULL, *cause;
|
||||
u_int ncaps = 0;
|
||||
struct args_value *values;
|
||||
|
||||
/* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
@@ -258,17 +259,20 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
||||
msg = MSG_COMMAND;
|
||||
|
||||
/*
|
||||
* It sucks parsing the command string twice (in client and
|
||||
* later in server) but it is necessary to get the start server
|
||||
* flag.
|
||||
* It's annoying parsing the command string twice (in client
|
||||
* and later in server) but it is necessary to get the start
|
||||
* server flag.
|
||||
*/
|
||||
pr = cmd_parse_from_arguments(argc, argv, NULL);
|
||||
values = args_from_vector(argc, argv);
|
||||
pr = cmd_parse_from_arguments(values, argc, NULL);
|
||||
if (pr->status == CMD_PARSE_SUCCESS) {
|
||||
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
|
||||
flags |= CLIENT_STARTSERVER;
|
||||
cmd_list_free(pr->cmdlist);
|
||||
} else
|
||||
free(pr->error);
|
||||
args_free_values(values, argc);
|
||||
free(values);
|
||||
}
|
||||
|
||||
/* Create client process structure (starts logging). */
|
||||
@@ -357,6 +361,7 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
||||
/* Send identify messages. */
|
||||
client_send_identify(ttynam, termname, caps, ncaps, cwd, feat);
|
||||
tty_term_free_list(caps, ncaps);
|
||||
proc_flush_peer(client_peer);
|
||||
|
||||
/* Send first command. */
|
||||
if (msg == MSG_COMMAND) {
|
||||
@@ -527,7 +532,7 @@ client_signal(int sig)
|
||||
if (sig == SIGCHLD)
|
||||
waitpid(WAIT_ANY, &status, WNOHANG);
|
||||
else if (!client_attached) {
|
||||
if (sig == SIGTERM)
|
||||
if (sig == SIGTERM || sig == SIGHUP)
|
||||
proc_exit(client_proc);
|
||||
} else {
|
||||
switch (sig) {
|
||||
|
||||
@@ -37,13 +37,13 @@ const struct cmd_entry cmd_attach_session_entry = {
|
||||
.name = "attach-session",
|
||||
.alias = "attach",
|
||||
|
||||
.args = { "c:dEf:rt:x", 0, 0 },
|
||||
.args = { "c:dEf:rt:x", 0, 0, NULL },
|
||||
.usage = "[-dErx] [-c working-directory] [-f flags] "
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
/* -t is special */
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.flags = CMD_STARTSERVER|CMD_READONLY,
|
||||
.exec = cmd_attach_session_exec
|
||||
};
|
||||
|
||||
@@ -69,6 +69,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
|
||||
if (c == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (server_client_check_nested(c)) {
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
@@ -124,17 +125,9 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
c->session = s;
|
||||
server_client_set_session(c, s);
|
||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
s->curw->window->latest = c;
|
||||
} else {
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
@@ -156,25 +149,14 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
if (!Eflag)
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
c->session = s;
|
||||
server_client_set_session(c, s);
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
s->curw->window->latest = c;
|
||||
|
||||
if (~c->flags & CLIENT_CONTROL)
|
||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||
notify_client("client-attached", c);
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
}
|
||||
recalculate_sizes();
|
||||
alerts_check_session(s);
|
||||
server_update_socket();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,16 @@
|
||||
* Bind a key to a command.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_bind_key_exec(struct cmd *, struct cmdq_item *);
|
||||
static enum args_parse_type cmd_bind_key_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
static enum cmd_retval cmd_bind_key_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_bind_key_entry = {
|
||||
.name = "bind-key",
|
||||
.alias = "bind",
|
||||
|
||||
.args = { "nrN:T:", 1, -1 },
|
||||
.args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
|
||||
.usage = "[-nr] [-T key-table] [-N note] key "
|
||||
"[command [arguments]]",
|
||||
|
||||
@@ -41,6 +44,13 @@ const struct cmd_entry cmd_bind_key_entry = {
|
||||
.exec = cmd_bind_key_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_bind_key_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -48,12 +58,13 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
key_code key;
|
||||
const char *tablename, *note = args_get(args, 'N');
|
||||
struct cmd_parse_result *pr;
|
||||
char **argv = args->argv;
|
||||
int argc = args->argc, repeat;
|
||||
int repeat;
|
||||
struct args_value *value;
|
||||
u_int count = args_count(args);
|
||||
|
||||
key = key_string_lookup_string(argv[0]);
|
||||
key = key_string_lookup_string(args_string(args, 0));
|
||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "unknown key: %s", argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -65,24 +76,32 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
tablename = "prefix";
|
||||
repeat = args_has(args, 'r');
|
||||
|
||||
if (argc != 1) {
|
||||
if (argc == 2)
|
||||
pr = cmd_parse_from_string(argv[1], NULL);
|
||||
else
|
||||
pr = cmd_parse_from_arguments(argc - 1, argv + 1, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
cmdq_error(item, "empty command");
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
||||
} else
|
||||
if (count == 1) {
|
||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_value(args, 1);
|
||||
if (count == 2 && value->type == ARGS_COMMANDS) {
|
||||
key_bindings_add(tablename, key, note, repeat, value->cmdlist);
|
||||
value->cmdlist->references++;
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (count == 2)
|
||||
pr = cmd_parse_from_string(args_string(args, 1), NULL);
|
||||
else {
|
||||
pr = cmd_parse_from_arguments(args_values(args) + 1, count - 1,
|
||||
NULL);
|
||||
}
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
key_bindings_add(tablename, key, note, repeat, pr->cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_break_pane_entry = {
|
||||
.name = "break-pane",
|
||||
.alias = "breakp",
|
||||
|
||||
.args = { "abdPF:n:s:t:", 0, 0 },
|
||||
.args = { "abdPF:n:s:t:", 0, 0, NULL },
|
||||
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
|
||||
"[-t dst-window]",
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
||||
.name = "capture-pane",
|
||||
.alias = "capturep",
|
||||
|
||||
.args = { "ab:CeE:JNpPqS:t:", 0, 0 },
|
||||
.args = { "ab:CeE:JNpPqS:t:", 0, 0, NULL },
|
||||
.usage = "[-aCeJNpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
@@ -53,7 +53,7 @@ const struct cmd_entry cmd_clear_history_entry = {
|
||||
.name = "clear-history",
|
||||
.alias = "clearhist",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -24,13 +24,16 @@
|
||||
* Enter a mode.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
|
||||
static enum args_parse_type cmd_choose_tree_args_parse(struct args *args,
|
||||
u_int idx, char **cause);
|
||||
static enum cmd_retval cmd_choose_tree_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_choose_tree_entry = {
|
||||
.name = "choose-tree",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:GK:NO:rst:wZ", 0, 1 },
|
||||
.args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -44,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = {
|
||||
.name = "choose-client",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1 },
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -58,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.name = "choose-buffer",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1 },
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -72,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = {
|
||||
.name = "customize-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:Nt:Z", 0, 0 },
|
||||
.args = { "F:f:Nt:Z", 0, 0, NULL },
|
||||
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -81,6 +84,13 @@ const struct cmd_entry cmd_customize_mode_entry = {
|
||||
.exec = cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_choose_tree_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
|
||||
@@ -29,8 +29,10 @@
|
||||
* Prompt for command in client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum args_parse_type cmd_command_prompt_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static int cmd_command_prompt_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
@@ -40,79 +42,111 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
||||
.name = "command-prompt",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "1kiI:Np:Tt:W", 0, 1 },
|
||||
.usage = "[-1kiNTW] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
||||
"[template]",
|
||||
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
||||
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
||||
" [-T type] [template]",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_command_prompt_exec
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
int flags;
|
||||
|
||||
char *inputs;
|
||||
char *next_input;
|
||||
|
||||
char *prompts;
|
||||
char *next_prompt;
|
||||
|
||||
char *template;
|
||||
int idx;
|
||||
struct cmd_command_prompt_prompt {
|
||||
char *input;
|
||||
char *prompt;
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
struct cmdq_item *item;
|
||||
struct args_command_state *state;
|
||||
|
||||
int flags;
|
||||
enum prompt_type prompt_type;
|
||||
|
||||
struct cmd_command_prompt_prompt *prompts;
|
||||
u_int count;
|
||||
u_int current;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_command_prompt_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
const char *inputs, *prompts;
|
||||
const char *type, *s, *input;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
char *prompt, *ptr, *input = NULL;
|
||||
size_t n;
|
||||
char *tmp, *prompts, *prompt, *next_prompt;
|
||||
char *inputs = NULL, *next_input;
|
||||
u_int count = args_count(args);
|
||||
int wait = !args_has(args, 'b'), space = 1;
|
||||
|
||||
if (tc->prompt_string != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (args_has(args, 'i'))
|
||||
wait = 0;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
cdata->state = args_make_commands_prepare(self, item, 0, "%1", wait,
|
||||
args_has(args, 'F'));
|
||||
|
||||
cdata->inputs = NULL;
|
||||
cdata->next_input = NULL;
|
||||
|
||||
cdata->prompts = NULL;
|
||||
cdata->next_prompt = NULL;
|
||||
|
||||
cdata->template = NULL;
|
||||
cdata->idx = 1;
|
||||
|
||||
if (args->argc != 0)
|
||||
cdata->template = xstrdup(args->argv[0]);
|
||||
else
|
||||
cdata->template = xstrdup("%1");
|
||||
|
||||
if ((prompts = args_get(args, 'p')) != NULL)
|
||||
cdata->prompts = xstrdup(prompts);
|
||||
else if (args->argc != 0) {
|
||||
n = strcspn(cdata->template, " ,");
|
||||
xasprintf(&cdata->prompts, "(%.*s) ", (int) n, cdata->template);
|
||||
if ((s = args_get(args, 'p')) == NULL) {
|
||||
if (count != 0) {
|
||||
tmp = args_make_commands_get_command(cdata->state);
|
||||
xasprintf(&prompts, "(%s)", tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
prompts = xstrdup(":");
|
||||
space = 0;
|
||||
}
|
||||
next_prompt = prompts;
|
||||
} else
|
||||
cdata->prompts = xstrdup(":");
|
||||
|
||||
/* Get first prompt. */
|
||||
cdata->next_prompt = cdata->prompts;
|
||||
ptr = strsep(&cdata->next_prompt, ",");
|
||||
if (prompts == NULL)
|
||||
prompt = xstrdup(ptr);
|
||||
next_prompt = prompts = xstrdup(s);
|
||||
if ((s = args_get(args, 'I')) != NULL)
|
||||
next_input = inputs = xstrdup(s);
|
||||
else
|
||||
xasprintf(&prompt, "%s ", ptr);
|
||||
next_input = NULL;
|
||||
while ((prompt = strsep(&next_prompt, ",")) != NULL) {
|
||||
cdata->prompts = xreallocarray(cdata->prompts, cdata->count + 1,
|
||||
sizeof *cdata->prompts);
|
||||
if (!space)
|
||||
tmp = xstrdup(prompt);
|
||||
else
|
||||
xasprintf(&tmp, "%s ", prompt);
|
||||
cdata->prompts[cdata->count].prompt = tmp;
|
||||
|
||||
/* Get initial prompt input. */
|
||||
if ((inputs = args_get(args, 'I')) != NULL) {
|
||||
cdata->inputs = xstrdup(inputs);
|
||||
cdata->next_input = cdata->inputs;
|
||||
input = strsep(&cdata->next_input, ",");
|
||||
if (next_input != NULL) {
|
||||
input = strsep(&next_input, ",");
|
||||
if (input == NULL)
|
||||
input = "";
|
||||
} else
|
||||
input = "";
|
||||
cdata->prompts[cdata->count].input = xstrdup(input);
|
||||
|
||||
cdata->count++;
|
||||
}
|
||||
free(inputs);
|
||||
free(prompts);
|
||||
|
||||
if ((type = args_get(args, 'T')) != NULL) {
|
||||
cdata->prompt_type = status_prompt_type(type);
|
||||
if (cdata->prompt_type == PROMPT_TYPE_INVALID) {
|
||||
cmdq_error(item, "unknown type: %s", type);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
cdata->prompt_type = PROMPT_TYPE_COMMAND;
|
||||
|
||||
if (args_has(args, '1'))
|
||||
cdata->flags |= PROMPT_SINGLE;
|
||||
@@ -122,62 +156,68 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->flags |= PROMPT_INCREMENTAL;
|
||||
else if (args_has(args, 'k'))
|
||||
cdata->flags |= PROMPT_KEY;
|
||||
else if (args_has(args, 'W'))
|
||||
cdata->flags |= PROMPT_WINDOW;
|
||||
else if (args_has(args, 'T'))
|
||||
cdata->flags |= PROMPT_TARGET;
|
||||
status_prompt_set(tc, target, prompt, input,
|
||||
cmd_command_prompt_callback, cmd_command_prompt_free, cdata,
|
||||
cdata->flags);
|
||||
free(prompt);
|
||||
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);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
int done)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
char *new_template, *prompt, *ptr, *error;
|
||||
char *input = NULL;
|
||||
enum cmd_parse_status status;
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
char *error;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd_command_prompt_prompt *prompt;
|
||||
int argc = 0;
|
||||
char **argv = NULL;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
if (done && (cdata->flags & PROMPT_INCREMENTAL))
|
||||
return (0);
|
||||
|
||||
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
||||
goto out;
|
||||
if (done) {
|
||||
free(cdata->template);
|
||||
cdata->template = new_template;
|
||||
if (cdata->flags & PROMPT_INCREMENTAL)
|
||||
goto out;
|
||||
|
||||
cmd_append_argv(&cdata->argc, &cdata->argv, s);
|
||||
if (++cdata->current != cdata->count) {
|
||||
prompt = &cdata->prompts[cdata->current];
|
||||
status_prompt_update(c, prompt->prompt, prompt->input);
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if there are more prompts; if so, get its respective input
|
||||
* and update the prompt data.
|
||||
*/
|
||||
if (done && (ptr = strsep(&cdata->next_prompt, ",")) != NULL) {
|
||||
xasprintf(&prompt, "%s ", ptr);
|
||||
input = strsep(&cdata->next_input, ",");
|
||||
status_prompt_update(c, prompt, input);
|
||||
|
||||
free(prompt);
|
||||
cdata->idx++;
|
||||
return (1);
|
||||
argc = cdata->argc;
|
||||
argv = cmd_copy_argv(cdata->argc, cdata->argv);
|
||||
cmd_append_argv(&argc, &argv, s);
|
||||
if (done) {
|
||||
cdata->argc = argc;
|
||||
cdata->argv = cmd_copy_argv(argc, argv);
|
||||
}
|
||||
|
||||
status = cmd_parse_and_append(new_template, NULL, c, NULL, &error);
|
||||
if (status == CMD_PARSE_ERROR) {
|
||||
cmdlist = args_make_commands(cdata->state, argc, argv, &error);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_append(c, cmdq_get_error(error));
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
cmd_free_argv(argc, argv);
|
||||
|
||||
if (!done)
|
||||
free(new_template);
|
||||
if (c->prompt_inputcb != cmd_command_prompt_callback)
|
||||
return (1);
|
||||
|
||||
out:
|
||||
if (item != NULL)
|
||||
cmdq_continue(item);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -185,9 +225,14 @@ static void
|
||||
cmd_command_prompt_free(void *data)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
u_int i;
|
||||
|
||||
free(cdata->inputs);
|
||||
for (i = 0; i < cdata->count; i++) {
|
||||
free(cdata->prompts[i].prompt);
|
||||
free(cdata->prompts[i].input);
|
||||
}
|
||||
free(cdata->prompts);
|
||||
free(cdata->template);
|
||||
cmd_free_argv(cdata->argc, cdata->argv);
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
* Asks for confirmation before executing a command.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum args_parse_type cmd_confirm_before_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static int cmd_confirm_before_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
@@ -39,17 +41,25 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
||||
.name = "confirm-before",
|
||||
.alias = "confirm",
|
||||
|
||||
.args = { "p:t:", 1, 1 },
|
||||
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||
.args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse },
|
||||
.usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_confirm_before_exec
|
||||
};
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
char *cmd;
|
||||
struct cmdq_item *item;
|
||||
struct cmd_list *cmdlist;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_confirm_before_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -57,27 +67,33 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
char *cmd, *copy, *new_prompt, *ptr;
|
||||
const char *prompt;
|
||||
char *new_prompt;
|
||||
const char *prompt, *cmd;
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmdlist = args_make_commands_now(self, item, 0, 1);
|
||||
if (cdata->cmdlist == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
|
||||
if ((prompt = args_get(args, 'p')) != NULL)
|
||||
xasprintf(&new_prompt, "%s ", prompt);
|
||||
else {
|
||||
ptr = copy = xstrdup(args->argv[0]);
|
||||
cmd = strsep(&ptr, " \t");
|
||||
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
|
||||
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
||||
free(copy);
|
||||
}
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(args->argv[0]);
|
||||
|
||||
status_prompt_set(tc, target, new_prompt, NULL,
|
||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||
PROMPT_SINGLE);
|
||||
|
||||
PROMPT_SINGLE, PROMPT_TYPE_COMMAND);
|
||||
free(new_prompt);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -85,23 +101,34 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
char *error;
|
||||
enum cmd_parse_status status;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
int retcode = 1;
|
||||
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
return (0);
|
||||
goto out;
|
||||
|
||||
if (s == NULL || *s == '\0')
|
||||
return (0);
|
||||
goto out;
|
||||
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
|
||||
return (0);
|
||||
goto out;
|
||||
retcode = 0;
|
||||
|
||||
status = cmd_parse_and_append(cdata->cmd, NULL, c, NULL, &error);
|
||||
if (status == CMD_PARSE_ERROR) {
|
||||
cmdq_append(c, cmdq_get_error(error));
|
||||
free(error);
|
||||
if (item == NULL) {
|
||||
new_item = cmdq_get_command(cdata->cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cdata->cmdlist,
|
||||
cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
out:
|
||||
if (item != NULL) {
|
||||
if (cmdq_get_client(item) != NULL &&
|
||||
cmdq_get_client(item)->session == NULL)
|
||||
cmdq_get_client(item)->retval = retcode;
|
||||
cmdq_continue(item);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -110,6 +137,6 @@ cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
|
||||
free(cdata->cmd);
|
||||
cmd_list_free(cdata->cmdlist);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
||||
.name = "copy-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "eHMs:t:uq", 0, 0 },
|
||||
.args = { "eHMs:t:uq", 0, 0, NULL },
|
||||
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
||||
.name = "clock-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_detach_client_entry = {
|
||||
.name = "detach-client",
|
||||
.alias = "detach",
|
||||
|
||||
.args = { "aE:s:t:P", 0, 0 },
|
||||
.args = { "aE:s:t:P", 0, 0, NULL },
|
||||
.usage = "[-aP] [-E shell-command] "
|
||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
||||
.name = "suspend-client",
|
||||
.alias = "suspendc",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
|
||||
@@ -27,16 +27,18 @@
|
||||
* Display a menu on a client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum cmd_retval cmd_display_popup_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum args_parse_type cmd_display_menu_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum cmd_retval cmd_display_popup_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_menu_entry = {
|
||||
.name = "display-menu",
|
||||
.alias = "menu",
|
||||
|
||||
.args = { "c:t:OT:x:y:", 1, -1 },
|
||||
.args = { "c:t:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
|
||||
.usage = "[-O] [-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
|
||||
"[-x position] [-y position] name key command ...",
|
||||
|
||||
@@ -50,10 +52,12 @@ const struct cmd_entry cmd_display_popup_entry = {
|
||||
.name = "display-popup",
|
||||
.alias = "popup",
|
||||
|
||||
.args = { "Cc:d:Eh:t:w:x:y:", 0, -1 },
|
||||
.usage = "[-CE] [-c target-client] [-d start-directory] [-h height] "
|
||||
CMD_TARGET_PANE_USAGE " [-w width] "
|
||||
"[-x position] [-y position] [command]",
|
||||
.args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL },
|
||||
.usage = "[-BCE] [-b border-lines] [-c target-client] "
|
||||
"[-d start-directory] [-e environment] [-h height] "
|
||||
"[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE
|
||||
"[-T title] [-w width] [-x position] [-y position] "
|
||||
"[shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -61,6 +65,30 @@ const struct cmd_entry cmd_display_popup_entry = {
|
||||
.exec = cmd_display_popup_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause)
|
||||
{
|
||||
u_int i = 0;
|
||||
enum args_parse_type type = ARGS_PARSE_STRING;
|
||||
|
||||
for (;;) {
|
||||
type = ARGS_PARSE_STRING;
|
||||
if (i == idx)
|
||||
break;
|
||||
if (*args_string(args, i++) == '\0')
|
||||
continue;
|
||||
|
||||
type = ARGS_PARSE_STRING;
|
||||
if (i++ == idx)
|
||||
break;
|
||||
|
||||
type = ARGS_PARSE_COMMANDS_OR_STRING;
|
||||
if (i++ == idx)
|
||||
break;
|
||||
}
|
||||
return (type);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
struct args *args, u_int *px, u_int *py, u_int w, u_int h)
|
||||
@@ -120,8 +148,6 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
if (sr != NULL)
|
||||
break;
|
||||
}
|
||||
if (line == lines)
|
||||
ranges = &tc->status.entries[0].ranges;
|
||||
|
||||
if (sr != NULL) {
|
||||
format_add(ft, "popup_window_status_line_x", "%u",
|
||||
@@ -174,8 +200,8 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
} else
|
||||
format_add(ft, "popup_mouse_centre_y", "%ld", n);
|
||||
n = (long)event->m.y + h;
|
||||
if (n + h >= tty->sy)
|
||||
format_add(ft, "popup_mouse_top", "%u", tty->sy - h);
|
||||
if (n >= tty->sy)
|
||||
format_add(ft, "popup_mouse_top", "%u", tty->sy - 1);
|
||||
else
|
||||
format_add(ft, "popup_mouse_top", "%ld", n);
|
||||
n = event->m.y - h;
|
||||
@@ -219,7 +245,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
else if (n < 0)
|
||||
n = 0;
|
||||
*px = n;
|
||||
log_debug("%s: -x: %s = %s = %u", __func__, xp, p, *px);
|
||||
log_debug("%s: -x: %s = %s = %u (-w %u)", __func__, xp, p, *px, w);
|
||||
free(p);
|
||||
|
||||
/* Expand vertical position */
|
||||
@@ -245,7 +271,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
else if (n < 0)
|
||||
n = 0;
|
||||
*py = n;
|
||||
log_debug("%s: -y: %s = %s = %u", __func__, yp, p, *py);
|
||||
log_debug("%s: -y: %s = %s = %u (-h %u)", __func__, yp, p, *py, h);
|
||||
free(p);
|
||||
|
||||
return (1);
|
||||
@@ -260,10 +286,10 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct menu *menu = NULL;
|
||||
struct menu_item menu_item;
|
||||
const char *key;
|
||||
char *title, *name;
|
||||
int flags = 0, i;
|
||||
u_int px, py;
|
||||
const char *key, *name;
|
||||
char *title;
|
||||
int flags = 0;
|
||||
u_int px, py, i, count = args_count(args);
|
||||
|
||||
if (tc->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -274,24 +300,24 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
title = xstrdup("");
|
||||
menu = menu_create(title);
|
||||
|
||||
for (i = 0; i != args->argc; /* nothing */) {
|
||||
name = args->argv[i++];
|
||||
for (i = 0; i != count; /* nothing */) {
|
||||
name = args_string(args, i++);
|
||||
if (*name == '\0') {
|
||||
menu_add_item(menu, NULL, item, tc, target);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args->argc - i < 2) {
|
||||
if (count - i < 2) {
|
||||
cmdq_error(item, "not enough arguments");
|
||||
free(title);
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key = args->argv[i++];
|
||||
key = args_string(args, i++);
|
||||
|
||||
menu_item.name = name;
|
||||
menu_item.key = key_string_lookup_string(key);
|
||||
menu_item.command = args->argv[i++];
|
||||
menu_item.command = args_string(args, i++);
|
||||
|
||||
menu_add_item(menu, &menu_item, item, tc, target);
|
||||
}
|
||||
@@ -328,11 +354,17 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s = target->s;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct tty *tty = &tc->tty;
|
||||
const char *value, *shell[] = { NULL, NULL };
|
||||
const char *shellcmd = NULL;
|
||||
char *cwd, *cause, **argv = args->argv;
|
||||
int flags = 0, argc = args->argc;
|
||||
u_int px, py, w, h;
|
||||
const char *value, *shell, *shellcmd = NULL;
|
||||
const char *style = args_get(args, 's');
|
||||
const char *border_style = args_get(args, 'S');
|
||||
char *cwd, *cause = NULL, **argv = NULL, *title;
|
||||
int flags = 0, argc = 0;
|
||||
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||
u_int px, py, w, h, count = args_count(args);
|
||||
struct args_value *av;
|
||||
struct environ *env = NULL;
|
||||
struct options *o = s->curw->window->options;
|
||||
struct options_entry *oe;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
server_client_clear_overlay(tc);
|
||||
@@ -361,37 +393,73 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
if (w > tty->sx - 1)
|
||||
w = tty->sx - 1;
|
||||
if (h > tty->sy - 1)
|
||||
h = tty->sy - 1;
|
||||
if (w > tty->sx)
|
||||
w = tty->sx;
|
||||
if (h > tty->sy)
|
||||
h = tty->sy;
|
||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
value = args_get(args, 'b');
|
||||
if (args_has(args, 'B'))
|
||||
lines = BOX_LINES_NONE;
|
||||
else if (value != NULL) {
|
||||
oe = options_get(o, "popup-border-lines");
|
||||
lines = options_find_choice(options_table_entry(oe), value,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "popup-border-lines %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
value = args_get(args, 'd');
|
||||
if (value != NULL)
|
||||
cwd = format_single_from_target(item, value);
|
||||
else
|
||||
cwd = xstrdup(server_client_get_cwd(tc, s));
|
||||
if (argc == 0)
|
||||
if (count == 0)
|
||||
shellcmd = options_get_string(s->options, "default-command");
|
||||
else if (argc == 1)
|
||||
shellcmd = argv[0];
|
||||
if (argc <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||
else if (count == 1)
|
||||
shellcmd = args_string(args, 0);
|
||||
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||
shellcmd = NULL;
|
||||
shell[0] = options_get_string(s->options, "default-shell");
|
||||
if (!checkshell(shell[0]))
|
||||
shell[0] = _PATH_BSHELL;
|
||||
argc = 1;
|
||||
argv = (char**)shell;
|
||||
shell = options_get_string(s->options, "default-shell");
|
||||
if (!checkshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
cmd_append_argv(&argc, &argv, shell);
|
||||
} else
|
||||
args_to_vector(args, &argc, &argv);
|
||||
|
||||
if (args_has(args, 'e') >= 1) {
|
||||
env = environ_create();
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
title = format_single_from_target(item, args_get(args, 'T'));
|
||||
else
|
||||
title = xstrdup("");
|
||||
if (args_has(args, 'E') > 1)
|
||||
flags |= POPUP_CLOSEEXITZERO;
|
||||
else if (args_has(args, 'E'))
|
||||
flags |= POPUP_CLOSEEXIT;
|
||||
if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd,
|
||||
tc, s, NULL, NULL) != 0)
|
||||
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
||||
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) {
|
||||
cmd_free_argv(argc, argv);
|
||||
if (env != NULL)
|
||||
environ_free(env);
|
||||
free(title);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (env != NULL)
|
||||
environ_free(env);
|
||||
free(title);
|
||||
cmd_free_argv(argc, argv);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.name = "display-message",
|
||||
.alias = "display",
|
||||
|
||||
.args = { "acd:INpt:F:v", 0, 1 },
|
||||
.args = { "ac:d:INpt:F:v", 0, 1, NULL },
|
||||
.usage = "[-aINpv] [-c target-client] [-d delay] [-F format] "
|
||||
CMD_TARGET_PANE_USAGE " [message]",
|
||||
|
||||
@@ -68,22 +68,26 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *template;
|
||||
char *msg, *cause;
|
||||
int delay = -1;
|
||||
int delay = -1, flags;
|
||||
struct format_tree *ft;
|
||||
int flags;
|
||||
u_int count = args_count(args);
|
||||
|
||||
if (args_has(args, 'I')) {
|
||||
if (wp == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (window_pane_start_input(wp, item, &cause) != 0) {
|
||||
switch (window_pane_start_input(wp, item, &cause)) {
|
||||
case -1:
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 1:
|
||||
return (CMD_RETURN_NORMAL);
|
||||
case 0:
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
if (args_has(args, 'F') && args->argc != 0) {
|
||||
if (args_has(args, 'F') && count != 0) {
|
||||
cmdq_error(item, "only one of -F or argument must be given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -97,9 +101,10 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (args->argc != 0)
|
||||
template = args->argv[0];
|
||||
if (count != 0)
|
||||
template = args_string(args, 0);
|
||||
else
|
||||
template = args_get(args, 'F');
|
||||
if (template == NULL)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
|
||||
@@ -27,14 +27,16 @@
|
||||
* Display panes on a client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum args_parse_type cmd_display_panes_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
.name = "display-panes",
|
||||
.alias = "displayp",
|
||||
|
||||
.args = { "bd:Nt:", 0, 1 },
|
||||
.args = { "bd:Nt:", 0, 1, cmd_display_panes_args_parse },
|
||||
.usage = "[-bN] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
@@ -42,10 +44,17 @@ const struct cmd_entry cmd_display_panes_entry = {
|
||||
};
|
||||
|
||||
struct cmd_display_panes_data {
|
||||
struct cmdq_item *item;
|
||||
char *command;
|
||||
struct cmdq_item *item;
|
||||
struct args_command_state *state;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_display_panes_args_parse(__unused struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
struct window_pane *wp)
|
||||
@@ -139,7 +148,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
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, buf, len, len);
|
||||
tty_putn(tty, " ", 1, 1);
|
||||
tty_putn(tty, lbuf, llen, llen);
|
||||
} else {
|
||||
@@ -186,7 +195,8 @@ out:
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
|
||||
cmd_display_panes_draw(struct client *c, __unused void *data,
|
||||
struct screen_redraw_ctx *ctx)
|
||||
{
|
||||
struct window *w = c->session->curw->window;
|
||||
struct window_pane *wp;
|
||||
@@ -200,24 +210,25 @@ cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_free(struct client *c)
|
||||
cmd_display_panes_free(__unused struct client *c, void *data)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
||||
struct cmd_display_panes_data *cdata = data;
|
||||
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
free(cdata->command);
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_panes_key(struct client *c, struct key_event *event)
|
||||
cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
||||
char *cmd, *expanded, *error;
|
||||
struct cmd_display_panes_data *cdata = data;
|
||||
char *expanded, *error;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
struct window *w = c->session->curw->window;
|
||||
struct window_pane *wp;
|
||||
enum cmd_parse_status status;
|
||||
u_int index;
|
||||
key_code key;
|
||||
|
||||
@@ -238,15 +249,19 @@ cmd_display_panes_key(struct client *c, struct key_event *event)
|
||||
window_unzoom(w);
|
||||
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(cdata->command, expanded, 1);
|
||||
|
||||
status = cmd_parse_and_append(cmd, NULL, c, NULL, &error);
|
||||
if (status == CMD_PARSE_ERROR) {
|
||||
cmdlist = args_make_commands(cdata->state, 1, &expanded, &error);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_append(c, cmdq_get_error(error));
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
return (1);
|
||||
}
|
||||
@@ -257,9 +272,10 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = tc->session;
|
||||
u_int delay;
|
||||
u_int delay;
|
||||
char *cause;
|
||||
struct cmd_display_panes_data *cdata;
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
if (tc->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -274,27 +290,23 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
} else
|
||||
delay = options_get_number(s->options, "display-panes-time");
|
||||
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
if (args->argc != 0)
|
||||
cdata->command = xstrdup(args->argv[0]);
|
||||
else
|
||||
cdata->command = xstrdup("select-pane -t '%%'");
|
||||
if (args_has(args, 'b'))
|
||||
cdata->item = NULL;
|
||||
else
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (wait)
|
||||
cdata->item = item;
|
||||
cdata->state = args_make_commands_prepare(self, item, 0,
|
||||
"select-pane -t \"%%%\"", wait, 0);
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
||||
cmd_display_panes_draw, NULL, cmd_display_panes_free,
|
||||
cmd_display_panes_draw, NULL, cmd_display_panes_free, NULL,
|
||||
cdata);
|
||||
} else {
|
||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
||||
cmd_display_panes_draw, cmd_display_panes_key,
|
||||
cmd_display_panes_free, cdata);
|
||||
cmd_display_panes_free, NULL, cdata);
|
||||
}
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_find_window_entry = {
|
||||
.name = "find-window",
|
||||
.alias = "findw",
|
||||
|
||||
.args = { "CiNrt:TZ", 1, 1 },
|
||||
.args = { "CiNrt:TZ", 1, 1, NULL },
|
||||
.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -47,8 +47,8 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = cmd_get_args(self), *new_args;
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *s = args->argv[0], *suffix = "";
|
||||
char *filter, *argv = { NULL };
|
||||
const char *s = args_string(args, 0), *suffix = "";
|
||||
struct args_value *filter;
|
||||
int C, N, T;
|
||||
|
||||
C = args_has(args, 'C');
|
||||
@@ -65,41 +65,49 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!C && !N && !T)
|
||||
C = N = T = 1;
|
||||
|
||||
filter = xcalloc(1, sizeof *filter);
|
||||
filter->type = ARGS_STRING;
|
||||
|
||||
if (C && N && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:"
|
||||
"#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}}",
|
||||
suffix, s, suffix, s, suffix, s);
|
||||
} else if (C && N) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (C && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (N && T) {
|
||||
xasprintf(&filter,
|
||||
xasprintf(&filter->string,
|
||||
"#{||:#{m%s:*%s*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
} else if (C)
|
||||
xasprintf(&filter, "#{C%s:%s}", suffix, s);
|
||||
else if (N)
|
||||
xasprintf(&filter, "#{m%s:*%s*,#{window_name}}", suffix, s);
|
||||
else
|
||||
xasprintf(&filter, "#{m%s:*%s*,#{pane_title}}", suffix, s);
|
||||
} else if (C) {
|
||||
xasprintf(&filter->string,
|
||||
"#{C%s:%s}",
|
||||
suffix, s);
|
||||
} else if (N) {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:*%s*,#{window_name}}",
|
||||
suffix, s);
|
||||
} else {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:*%s*,#{pane_title}}",
|
||||
suffix, s);
|
||||
}
|
||||
|
||||
new_args = args_parse("", 1, &argv);
|
||||
new_args = args_create();
|
||||
if (args_has(args, 'Z'))
|
||||
args_set(new_args, 'Z', NULL);
|
||||
args_set(new_args, 'f', filter);
|
||||
|
||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||
|
||||
args_free(new_args);
|
||||
free(filter);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
168
cmd-if-shell.c
168
cmd-if-shell.c
@@ -20,6 +20,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -29,16 +30,19 @@
|
||||
* Executes a tmux command if a shell command returns true or false.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *);
|
||||
static enum args_parse_type cmd_if_shell_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_if_shell_callback(struct job *);
|
||||
static void cmd_if_shell_free(void *);
|
||||
static void cmd_if_shell_callback(struct job *);
|
||||
static void cmd_if_shell_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_if_shell_entry = {
|
||||
.name = "if-shell",
|
||||
.alias = "if",
|
||||
|
||||
.args = { "bFt:", 2, 3 },
|
||||
.args = { "bFt:", 2, 3, cmd_if_shell_args_parse },
|
||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
||||
"[command]",
|
||||
|
||||
@@ -49,86 +53,72 @@ const struct cmd_entry cmd_if_shell_entry = {
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
struct cmd_parse_input input;
|
||||
struct args_command_state *cmd_if;
|
||||
struct args_command_state *cmd_else;
|
||||
|
||||
char *cmd_if;
|
||||
char *cmd_else;
|
||||
|
||||
struct client *client;
|
||||
struct cmdq_item *item;
|
||||
struct client *client;
|
||||
struct cmdq_item *item;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_if_shell_args_parse(__unused struct args *args, u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
if (idx == 1 || idx == 2)
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
return (ARGS_PARSE_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_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 cmdq_state *state = cmdq_get_state(item);
|
||||
struct cmd_if_shell_data *cdata;
|
||||
char *shellcmd, *cmd, *error;
|
||||
const char *file;
|
||||
struct cmdq_item *new_item;
|
||||
char *shellcmd;
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct cmd_parse_input pi;
|
||||
enum cmd_parse_status status;
|
||||
struct cmd_list *cmdlist;
|
||||
u_int count = args_count(args);
|
||||
int wait = !args_has(args, 'b');
|
||||
|
||||
shellcmd = format_single_from_target(item, args->argv[0]);
|
||||
shellcmd = format_single_from_target(item, args_string(args, 0));
|
||||
if (args_has(args, 'F')) {
|
||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||
cmd = args->argv[1];
|
||||
else if (args->argc == 3)
|
||||
cmd = args->argv[2];
|
||||
else
|
||||
cmd = NULL;
|
||||
free(shellcmd);
|
||||
if (cmd == NULL)
|
||||
cmdlist = args_make_commands_now(self, item, 1, 0);
|
||||
else if (count == 3)
|
||||
cmdlist = args_make_commands_now(self, item, 2, 0);
|
||||
else {
|
||||
free(shellcmd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
memset(&pi, 0, sizeof pi);
|
||||
cmd_get_source(self, &pi.file, &pi.line);
|
||||
pi.item = item;
|
||||
pi.c = tc;
|
||||
cmd_find_copy_state(&pi.fs, target);
|
||||
|
||||
status = cmd_parse_and_insert(cmd, &pi, item, state, &error);
|
||||
if (status == CMD_PARSE_ERROR) {
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(shellcmd);
|
||||
if (cmdlist == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
|
||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
||||
if (args->argc == 3)
|
||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
||||
else
|
||||
cdata->cmd_else = NULL;
|
||||
cdata->cmd_if = args_make_commands_prepare(self, item, 1, NULL, wait,
|
||||
0);
|
||||
if (count == 3) {
|
||||
cdata->cmd_else = args_make_commands_prepare(self, item, 2,
|
||||
NULL, wait, 0);
|
||||
}
|
||||
|
||||
if (!args_has(args, 'b'))
|
||||
if (wait) {
|
||||
cdata->client = cmdq_get_client(item);
|
||||
else
|
||||
cdata->item = item;
|
||||
} else
|
||||
cdata->client = tc;
|
||||
if (cdata->client != NULL)
|
||||
cdata->client->references++;
|
||||
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
else
|
||||
cdata->item = NULL;
|
||||
|
||||
memset(&cdata->input, 0, sizeof cdata->input);
|
||||
cmd_get_source(self, &file, &cdata->input.line);
|
||||
if (file != NULL)
|
||||
cdata->input.file = xstrdup(file);
|
||||
cdata->input.c = tc;
|
||||
if (cdata->input.c != NULL)
|
||||
cdata->input.c->references++;
|
||||
cmd_find_copy_state(&cdata->input.fs, target);
|
||||
|
||||
if (job_run(shellcmd, 0, NULL, s,
|
||||
if (job_run(shellcmd, 0, NULL, NULL, s,
|
||||
server_client_get_cwd(cmdq_get_client(item), s), NULL,
|
||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,
|
||||
-1) == NULL) {
|
||||
@@ -139,7 +129,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
free(shellcmd);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
if (!wait)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
@@ -149,45 +139,34 @@ cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job_get_data(job);
|
||||
struct client *c = cdata->client;
|
||||
struct cmdq_item *new_item = NULL;
|
||||
struct cmdq_state *new_state = NULL;
|
||||
char *cmd;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct args_command_state *state;
|
||||
struct cmd_list *cmdlist;
|
||||
char *error;
|
||||
int status;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
status = job_get_status(job);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
cmd = cdata->cmd_else;
|
||||
state = cdata->cmd_else;
|
||||
else
|
||||
cmd = cdata->cmd_if;
|
||||
if (cmd == NULL)
|
||||
state = cdata->cmd_if;
|
||||
if (state == NULL)
|
||||
goto out;
|
||||
|
||||
pr = cmd_parse_from_string(cmd, &cdata->input);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
if (cdata->item != NULL)
|
||||
cmdq_error(cdata->item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
if (cdata->item == NULL)
|
||||
new_state = cmdq_new_state(NULL, NULL, 0);
|
||||
else
|
||||
new_state = cmdq_get_state(cdata->item);
|
||||
new_item = cmdq_get_command(pr->cmdlist, new_state);
|
||||
if (cdata->item == NULL)
|
||||
cmdq_free_state(new_state);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
break;
|
||||
}
|
||||
if (new_item != NULL) {
|
||||
if (cdata->item == NULL)
|
||||
cmdq_append(c, new_item);
|
||||
else
|
||||
cmdq_insert_after(cdata->item, new_item);
|
||||
cmdlist = args_make_commands(state, 0, NULL, &error);
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -203,12 +182,9 @@ cmd_if_shell_free(void *data)
|
||||
if (cdata->client != NULL)
|
||||
server_client_unref(cdata->client);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
|
||||
if (cdata->input.c != NULL)
|
||||
server_client_unref(cdata->input.c);
|
||||
free((void *)cdata->input.file);
|
||||
if (cdata->cmd_else != NULL)
|
||||
args_make_commands_free(cdata->cmd_else);
|
||||
args_make_commands_free(cdata->cmd_if);
|
||||
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_join_pane_entry = {
|
||||
.name = "join-pane",
|
||||
.alias = "joinp",
|
||||
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0 },
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
||||
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_move_pane_entry = {
|
||||
.name = "move-pane",
|
||||
.alias = "movep",
|
||||
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0 },
|
||||
.args = { "bdfhvp:l:s:t:", 0, 0, NULL },
|
||||
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
.name = "kill-pane",
|
||||
.alias = "killp",
|
||||
|
||||
.args = { "at:", 0, 0 },
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_server_entry = {
|
||||
.name = "kill-server",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "", 0, 0 },
|
||||
.args = { "", 0, 0, NULL },
|
||||
.usage = "",
|
||||
|
||||
.flags = 0,
|
||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_start_server_entry = {
|
||||
.name = "start-server",
|
||||
.alias = "start",
|
||||
|
||||
.args = { "", 0, 0 },
|
||||
.args = { "", 0, 0, NULL },
|
||||
.usage = "",
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_session_entry = {
|
||||
.name = "kill-session",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "aCt:", 0, 0 },
|
||||
.args = { "aCt:", 0, 0, NULL },
|
||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_kill_window_entry = {
|
||||
.name = "kill-window",
|
||||
.alias = "killw",
|
||||
|
||||
.args = { "at:", 0, 0 },
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
||||
.name = "unlink-window",
|
||||
.alias = "unlinkw",
|
||||
|
||||
.args = { "kt:", 0, 0 },
|
||||
.args = { "kt:", 0, 0, NULL },
|
||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
.name = "list-buffers",
|
||||
.alias = "lsb",
|
||||
|
||||
.args = { "F:f:", 0, 0 },
|
||||
.args = { "F:f:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define LIST_CLIENTS_TEMPLATE \
|
||||
"#{client_name}: #{session_name} " \
|
||||
"[#{client_width}x#{client_height} #{client_termname}] " \
|
||||
"#{?#{!=:#{client_uid},#{uid}}," \
|
||||
"[user #{?client_user,#{client_user},#{client_uid},}] ,}" \
|
||||
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
||||
|
||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
||||
@@ -39,7 +41,7 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
.name = "list-clients",
|
||||
.alias = "lsc",
|
||||
|
||||
.args = { "F:t:", 0, 0 },
|
||||
.args = { "F:t:", 0, 0, NULL },
|
||||
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_list_keys_entry = {
|
||||
.name = "list-keys",
|
||||
.alias = "lsk",
|
||||
|
||||
.args = { "1aNP:T:", 0, 1 },
|
||||
.args = { "1aNP:T:", 0, 1, NULL },
|
||||
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_list_commands_entry = {
|
||||
.name = "list-commands",
|
||||
.alias = "lscm",
|
||||
|
||||
.args = { "F:", 0, 1 },
|
||||
.args = { "F:", 0, 1, NULL },
|
||||
.usage = "[-F format] [command]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
@@ -150,7 +150,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
const char *tablename, *r;
|
||||
const char *tablename, *r, *keystr;
|
||||
char *key, *cp, *tmp, *start, *empty;
|
||||
key_code prefix, only = KEYC_UNKNOWN;
|
||||
int repeat, width, tablewidth, keywidth, found = 0;
|
||||
@@ -159,10 +159,10 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
||||
return (cmd_list_keys_commands(self, item));
|
||||
|
||||
if (args->argc != 0) {
|
||||
only = key_string_lookup_string(args->argv[0]);
|
||||
if ((keystr = args_string(args, 0)) != NULL) {
|
||||
only = key_string_lookup_string(keystr);
|
||||
if (only == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "invalid key: %s", args->argv[0]);
|
||||
cmdq_error(item, "invalid key: %s", keystr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
only &= (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||
@@ -211,7 +211,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
repeat = 0;
|
||||
tablewidth = keywidth = 0;
|
||||
table = key_bindings_first_table ();
|
||||
table = key_bindings_first_table();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
@@ -244,7 +244,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
tmpsize = 256;
|
||||
tmp = xmalloc(tmpsize);
|
||||
|
||||
table = key_bindings_first_table ();
|
||||
table = key_bindings_first_table();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
@@ -308,7 +308,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
out:
|
||||
if (only != KEYC_UNKNOWN && !found) {
|
||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -321,12 +321,9 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
const char *template, *s, *command = NULL;
|
||||
const char *template, *s, *command;
|
||||
char *line;
|
||||
|
||||
if (args->argc != 0)
|
||||
command = args->argv[0];
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL) {
|
||||
template = "#{command_list_name}"
|
||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
||||
@@ -336,6 +333,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
command = args_string(args, 0);
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
entry = *entryp;
|
||||
if (command != NULL &&
|
||||
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_list_panes_entry = {
|
||||
.name = "list-panes",
|
||||
.alias = "lsp",
|
||||
|
||||
.args = { "asF:f:t:", 0, 0 },
|
||||
.args = { "asF:f:t:", 0, 0, NULL },
|
||||
.usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
.name = "list-sessions",
|
||||
.alias = "ls",
|
||||
|
||||
.args = { "F:f:", 0, 0 },
|
||||
.args = { "F:f:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
|
||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_list_windows_entry = {
|
||||
.name = "list-windows",
|
||||
.alias = "lsw",
|
||||
|
||||
.args = { "F:f:at:", 0, 0 },
|
||||
.args = { "F:f:at:", 0, 0, NULL },
|
||||
.usage = "[-a] [-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_load_buffer_entry = {
|
||||
.name = "load-buffer",
|
||||
.alias = "loadb",
|
||||
|
||||
.args = { "b:t:w", 1, 1 },
|
||||
.args = { "b:t:w", 1, 1, NULL },
|
||||
.usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
||||
@@ -105,7 +105,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->client->references++;
|
||||
}
|
||||
|
||||
path = format_single_from_target(item, args->argv[0]);
|
||||
path = format_single_from_target(item, args_string(args, 0));
|
||||
file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata);
|
||||
free(path);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_lock_server_entry = {
|
||||
.name = "lock-server",
|
||||
.alias = "lock",
|
||||
|
||||
.args = { "", 0, 0 },
|
||||
.args = { "", 0, 0, NULL },
|
||||
.usage = "",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_lock_session_entry = {
|
||||
.name = "lock-session",
|
||||
.alias = "locks",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
@@ -54,7 +54,7 @@ const struct cmd_entry cmd_lock_client_entry = {
|
||||
.name = "lock-client",
|
||||
.alias = "lockc",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_move_window_entry = {
|
||||
.name = "move-window",
|
||||
.alias = "movew",
|
||||
|
||||
.args = { "abdkrs:t:", 0, 0 },
|
||||
.args = { "abdkrs:t:", 0, 0, NULL },
|
||||
.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_link_window_entry = {
|
||||
.name = "link-window",
|
||||
.alias = "linkw",
|
||||
|
||||
.args = { "abdks:t:", 0, 0 },
|
||||
.args = { "abdks:t:", 0, 0, NULL },
|
||||
.usage = "[-abdk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -39,10 +39,11 @@ const struct cmd_entry cmd_new_session_entry = {
|
||||
.name = "new-session",
|
||||
.alias = "new",
|
||||
|
||||
.args = { "Ac:dDe:EF:f:n:Ps:t:x:Xy:", 0, -1 },
|
||||
.args = { "Ac:dDe:EF:f:n:Ps:t:x:Xy:", 0, -1, NULL },
|
||||
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-f flags] [-n window-name] [-s session-name] "
|
||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
|
||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
||||
"[shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
@@ -54,7 +55,7 @@ const struct cmd_entry cmd_has_session_entry = {
|
||||
.name = "has-session",
|
||||
.alias = "has",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
@@ -75,15 +76,15 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct options *oo;
|
||||
struct termios tio, *tiop;
|
||||
struct session_group *sg = NULL;
|
||||
const char *errstr, *template, *group, *tmp, *add;
|
||||
const char *errstr, *template, *group, *tmp;
|
||||
char *cause, *cwd = NULL, *cp, *newname = NULL;
|
||||
char *name, *prefix = NULL;
|
||||
int detached, already_attached, is_control = 0;
|
||||
u_int sx, sy, dsx, dsy;
|
||||
struct spawn_context sc;
|
||||
u_int sx, sy, dsx, dsy, count = args_count(args);
|
||||
struct spawn_context sc = { 0 };
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *value;
|
||||
struct args_value *av;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_has_session_entry) {
|
||||
/*
|
||||
@@ -93,7 +94,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 't') && (args->argc != 0 || args_has(args, 'n'))) {
|
||||
if (args_has(args, 't') && (count != 0 || args_has(args, 'n'))) {
|
||||
cmdq_error(item, "command or window name given with target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -102,6 +103,11 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
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);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
if (args_has(args, 'A')) {
|
||||
@@ -134,8 +140,14 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
prefix = xstrdup(sg->name);
|
||||
else if (groupwith != NULL)
|
||||
prefix = xstrdup(groupwith->name);
|
||||
else
|
||||
else {
|
||||
prefix = session_check_name(group);
|
||||
if (prefix == NULL) {
|
||||
cmdq_error(item, "invalid session group: %s",
|
||||
group);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set -d if no client. */
|
||||
@@ -258,22 +270,21 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
env = environ_create();
|
||||
if (c != NULL && !args_has(args, 'E'))
|
||||
environ_update(global_s_options, c->environ, env);
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(env, add, 0);
|
||||
add = args_next_value(&value);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
||||
|
||||
/* Spawn the initial window. */
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.tc = c;
|
||||
if (!detached)
|
||||
sc.tc = c;
|
||||
|
||||
sc.name = args_get(args, 'n');
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
@@ -317,18 +328,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||
} else if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
server_client_set_session(c, s);
|
||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
server_redraw_client(c);
|
||||
}
|
||||
recalculate_sizes();
|
||||
server_update_socket();
|
||||
|
||||
/*
|
||||
* If there are still configuration file errors to display, put the new
|
||||
@@ -354,12 +357,16 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
free(cwd);
|
||||
free(newname);
|
||||
free(prefix);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
free(cwd);
|
||||
free(newname);
|
||||
free(prefix);
|
||||
|
||||
@@ -38,9 +38,9 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
.name = "new-window",
|
||||
.alias = "neww",
|
||||
|
||||
.args = { "abc:de:F:kn:PSt:", 0, -1 },
|
||||
.args = { "abc:de:F:kn:PSt:", 0, -1, NULL },
|
||||
.usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
@@ -55,16 +55,15 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct spawn_context sc;
|
||||
struct spawn_context sc = { 0 };
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
struct winlink *wl = target->wl, *new_wl = NULL;
|
||||
int idx = target->idx, before;
|
||||
struct winlink *new_wl = NULL;
|
||||
char *cause = NULL, *cp;
|
||||
const char *template, *add, *name;
|
||||
const char *template, *name;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *value;
|
||||
struct args_value *av;
|
||||
|
||||
/*
|
||||
* If -S and -n are given and -t is not and a single window with this
|
||||
@@ -94,7 +93,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
before = args_has(args, 'b');
|
||||
if (args_has(args, 'a') || before) {
|
||||
idx = winlink_shuffle_up(s, wl, before);
|
||||
@@ -102,20 +100,18 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
idx = target->idx;
|
||||
}
|
||||
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.tc = tc;
|
||||
|
||||
sc.name = args_get(args, 'n');
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add, 0);
|
||||
add = args_next_value(&value);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
sc.idx = idx;
|
||||
@@ -130,6 +126,9 @@ 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);
|
||||
}
|
||||
if (!args_has(args, 'd') || new_wl == s->curw) {
|
||||
@@ -150,6 +149,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_find_from_winlink(&fs, new_wl, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
559
cmd-parse.y
559
cmd-parse.y
@@ -42,13 +42,27 @@ struct cmd_parse_scope {
|
||||
TAILQ_ENTRY (cmd_parse_scope) entry;
|
||||
};
|
||||
|
||||
enum cmd_parse_argument_type {
|
||||
CMD_PARSE_STRING,
|
||||
CMD_PARSE_COMMANDS,
|
||||
CMD_PARSE_PARSED_COMMANDS
|
||||
};
|
||||
|
||||
struct cmd_parse_argument {
|
||||
enum cmd_parse_argument_type type;
|
||||
char *string;
|
||||
struct cmd_parse_commands *commands;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
TAILQ_ENTRY(cmd_parse_argument) entry;
|
||||
};
|
||||
TAILQ_HEAD(cmd_parse_arguments, cmd_parse_argument);
|
||||
|
||||
struct cmd_parse_command {
|
||||
u_int line;
|
||||
u_int line;
|
||||
struct cmd_parse_arguments arguments;
|
||||
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
TAILQ_ENTRY(cmd_parse_command) entry;
|
||||
TAILQ_ENTRY(cmd_parse_command) entry;
|
||||
};
|
||||
TAILQ_HEAD(cmd_parse_commands, cmd_parse_command);
|
||||
|
||||
@@ -77,8 +91,9 @@ static char *cmd_parse_get_error(const char *, u_int, const char *);
|
||||
static void cmd_parse_free_command(struct cmd_parse_command *);
|
||||
static struct cmd_parse_commands *cmd_parse_new_commands(void);
|
||||
static void cmd_parse_free_commands(struct cmd_parse_commands *);
|
||||
static char *cmd_parse_commands_to_string(struct cmd_parse_commands *);
|
||||
static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
||||
static void cmd_parse_build_commands(struct cmd_parse_commands *,
|
||||
struct cmd_parse_input *, struct cmd_parse_result *);
|
||||
static void cmd_parse_print_commands(struct cmd_parse_input *,
|
||||
struct cmd_list *);
|
||||
|
||||
%}
|
||||
@@ -86,10 +101,8 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
||||
%union
|
||||
{
|
||||
char *token;
|
||||
struct {
|
||||
int argc;
|
||||
char **argv;
|
||||
} arguments;
|
||||
struct cmd_parse_arguments *arguments;
|
||||
struct cmd_parse_argument *argument;
|
||||
int flag;
|
||||
struct {
|
||||
int flag;
|
||||
@@ -107,8 +120,9 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
||||
%token ENDIF
|
||||
%token <token> FORMAT TOKEN EQUALS
|
||||
|
||||
%type <token> argument expanded format
|
||||
%type <token> expanded format
|
||||
%type <arguments> arguments
|
||||
%type <argument> argument
|
||||
%type <flag> if_open if_elif
|
||||
%type <elif> elif elif1
|
||||
%type <commands> argument_statements statements statement
|
||||
@@ -360,7 +374,7 @@ commands : command
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
|
||||
$$ = cmd_parse_new_commands();
|
||||
if ($1->argc != 0 &&
|
||||
if (!TAILQ_EMPTY(&$1->arguments) &&
|
||||
(ps->scope == NULL || ps->scope->flag))
|
||||
TAILQ_INSERT_TAIL($$, $1, entry);
|
||||
else
|
||||
@@ -380,7 +394,7 @@ commands : command
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
|
||||
if ($3->argc != 0 &&
|
||||
if (!TAILQ_EMPTY(&$3->arguments) &&
|
||||
(ps->scope == NULL || ps->scope->flag)) {
|
||||
$$ = $1;
|
||||
TAILQ_INSERT_TAIL($$, $3, entry);
|
||||
@@ -401,27 +415,38 @@ command : assignment
|
||||
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->line = ps->input->line;
|
||||
TAILQ_INIT(&$$->arguments);
|
||||
}
|
||||
| optional_assignment TOKEN
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
struct cmd_parse_argument *arg;
|
||||
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->line = ps->input->line;
|
||||
TAILQ_INIT(&$$->arguments);
|
||||
|
||||
cmd_prepend_argv(&$$->argc, &$$->argv, $2);
|
||||
|
||||
arg = xcalloc(1, sizeof *arg);
|
||||
arg->type = CMD_PARSE_STRING;
|
||||
arg->string = $2;
|
||||
TAILQ_INSERT_HEAD(&$$->arguments, arg, entry);
|
||||
}
|
||||
| optional_assignment TOKEN arguments
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
struct cmd_parse_argument *arg;
|
||||
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->line = ps->input->line;
|
||||
TAILQ_INIT(&$$->arguments);
|
||||
|
||||
$$->argc = $3.argc;
|
||||
$$->argv = $3.argv;
|
||||
cmd_prepend_argv(&$$->argc, &$$->argv, $2);
|
||||
TAILQ_CONCAT(&$$->arguments, $3, entry);
|
||||
free($3);
|
||||
|
||||
arg = xcalloc(1, sizeof *arg);
|
||||
arg->type = CMD_PARSE_STRING;
|
||||
arg->string = $2;
|
||||
TAILQ_INSERT_HEAD(&$$->arguments, arg, entry);
|
||||
}
|
||||
|
||||
condition1 : if_open commands if_close
|
||||
@@ -505,30 +530,34 @@ elif1 : if_elif commands
|
||||
|
||||
arguments : argument
|
||||
{
|
||||
$$.argc = 1;
|
||||
$$.argv = xreallocarray(NULL, 1, sizeof *$$.argv);
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
TAILQ_INIT($$);
|
||||
|
||||
$$.argv[0] = $1;
|
||||
TAILQ_INSERT_HEAD($$, $1, entry);
|
||||
}
|
||||
| argument arguments
|
||||
{
|
||||
cmd_prepend_argv(&$2.argc, &$2.argv, $1);
|
||||
free($1);
|
||||
TAILQ_INSERT_HEAD($2, $1, entry);
|
||||
$$ = $2;
|
||||
}
|
||||
|
||||
argument : TOKEN
|
||||
{
|
||||
$$ = $1;
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->type = CMD_PARSE_STRING;
|
||||
$$->string = $1;
|
||||
}
|
||||
| EQUALS
|
||||
{
|
||||
$$ = $1;
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->type = CMD_PARSE_STRING;
|
||||
$$->string = $1;
|
||||
}
|
||||
| '{' argument_statements
|
||||
{
|
||||
$$ = cmd_parse_commands_to_string($2);
|
||||
cmd_parse_free_commands($2);
|
||||
$$ = xcalloc(1, sizeof *$$);
|
||||
$$->type = CMD_PARSE_COMMANDS;
|
||||
$$->commands = $2;
|
||||
}
|
||||
|
||||
argument_statements : statement '}'
|
||||
@@ -552,30 +581,57 @@ cmd_parse_get_error(const char *file, u_int line, const char *error)
|
||||
if (file == NULL)
|
||||
s = xstrdup(error);
|
||||
else
|
||||
xasprintf (&s, "%s:%u: %s", file, line, error);
|
||||
xasprintf(&s, "%s:%u: %s", file, line, error);
|
||||
return (s);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_print_commands(struct cmd_parse_input *pi, u_int line,
|
||||
struct cmd_list *cmdlist)
|
||||
cmd_parse_print_commands(struct cmd_parse_input *pi, struct cmd_list *cmdlist)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (pi->item != NULL && (pi->flags & CMD_PARSE_VERBOSE)) {
|
||||
s = cmd_list_print(cmdlist, 0);
|
||||
if (pi->file != NULL)
|
||||
cmdq_print(pi->item, "%s:%u: %s", pi->file, line, s);
|
||||
else
|
||||
cmdq_print(pi->item, "%u: %s", line, s);
|
||||
free(s);
|
||||
if (pi->item == NULL || (~pi->flags & CMD_PARSE_VERBOSE))
|
||||
return;
|
||||
s = cmd_list_print(cmdlist, 0);
|
||||
if (pi->file != NULL)
|
||||
cmdq_print(pi->item, "%s:%u: %s", pi->file, pi->line, s);
|
||||
else
|
||||
cmdq_print(pi->item, "%u: %s", pi->line, s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_free_argument(struct cmd_parse_argument *arg)
|
||||
{
|
||||
switch (arg->type) {
|
||||
case CMD_PARSE_STRING:
|
||||
free(arg->string);
|
||||
break;
|
||||
case CMD_PARSE_COMMANDS:
|
||||
cmd_parse_free_commands(arg->commands);
|
||||
break;
|
||||
case CMD_PARSE_PARSED_COMMANDS:
|
||||
cmd_list_free(arg->cmdlist);
|
||||
break;
|
||||
}
|
||||
free(arg);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_free_arguments(struct cmd_parse_arguments *args)
|
||||
{
|
||||
struct cmd_parse_argument *arg, *arg1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(arg, args, entry, arg1) {
|
||||
TAILQ_REMOVE(args, arg, entry);
|
||||
cmd_parse_free_argument(arg);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_free_command(struct cmd_parse_command *cmd)
|
||||
{
|
||||
cmd_free_argv(cmd->argc, cmd->argv);
|
||||
cmd_parse_free_arguments(&cmd->arguments);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
@@ -585,7 +641,7 @@ cmd_parse_new_commands(void)
|
||||
struct cmd_parse_commands *cmds;
|
||||
|
||||
cmds = xmalloc(sizeof *cmds);
|
||||
TAILQ_INIT (cmds);
|
||||
TAILQ_INIT(cmds);
|
||||
return (cmds);
|
||||
}
|
||||
|
||||
@@ -601,30 +657,6 @@ cmd_parse_free_commands(struct cmd_parse_commands *cmds)
|
||||
free(cmds);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_parse_commands_to_string(struct cmd_parse_commands *cmds)
|
||||
{
|
||||
struct cmd_parse_command *cmd;
|
||||
char *string = NULL, *s, *line;
|
||||
|
||||
TAILQ_FOREACH(cmd, cmds, entry) {
|
||||
line = cmd_stringify_argv(cmd->argc, cmd->argv);
|
||||
if (string == NULL)
|
||||
s = line;
|
||||
else {
|
||||
xasprintf(&s, "%s ; %s", s, line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
free(string);
|
||||
string = s;
|
||||
}
|
||||
if (string == NULL)
|
||||
string = xstrdup("");
|
||||
log_debug("%s: %s", __func__, string);
|
||||
return (string);
|
||||
}
|
||||
|
||||
static struct cmd_parse_commands *
|
||||
cmd_parse_run_parser(char **cause)
|
||||
{
|
||||
@@ -674,72 +706,170 @@ cmd_parse_do_buffer(const char *buf, size_t len, struct cmd_parse_input *pi,
|
||||
return (cmd_parse_run_parser(cause));
|
||||
}
|
||||
|
||||
static struct cmd_parse_result *
|
||||
cmd_parse_build_commands(struct cmd_parse_commands *cmds,
|
||||
struct cmd_parse_input *pi)
|
||||
static void
|
||||
cmd_parse_log_commands(struct cmd_parse_commands *cmds, const char *prefix)
|
||||
{
|
||||
static struct cmd_parse_result pr;
|
||||
struct cmd_parse_commands *cmds2;
|
||||
struct cmd_parse_command *cmd, *cmd2, *next, *next2, *after;
|
||||
u_int line = UINT_MAX;
|
||||
int i;
|
||||
struct cmd_list *cmdlist = NULL, *result;
|
||||
struct cmd_parse_command *cmd;
|
||||
struct cmd_parse_argument *arg;
|
||||
u_int i, j;
|
||||
char *s;
|
||||
|
||||
i = 0;
|
||||
TAILQ_FOREACH(cmd, cmds, entry) {
|
||||
j = 0;
|
||||
TAILQ_FOREACH(arg, &cmd->arguments, entry) {
|
||||
switch (arg->type) {
|
||||
case CMD_PARSE_STRING:
|
||||
log_debug("%s %u:%u: %s", prefix, i, j,
|
||||
arg->string);
|
||||
break;
|
||||
case CMD_PARSE_COMMANDS:
|
||||
xasprintf(&s, "%s %u:%u", prefix, i, j);
|
||||
cmd_parse_log_commands(arg->commands, s);
|
||||
free(s);
|
||||
break;
|
||||
case CMD_PARSE_PARSED_COMMANDS:
|
||||
s = cmd_list_print(arg->cmdlist, 0);
|
||||
log_debug("%s %u:%u: %s", prefix, i, j, s);
|
||||
free(s);
|
||||
break;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_parse_expand_alias(struct cmd_parse_command *cmd,
|
||||
struct cmd_parse_input *pi, struct cmd_parse_result *pr)
|
||||
{
|
||||
struct cmd_parse_argument *arg, *arg1, *first;
|
||||
struct cmd_parse_commands *cmds;
|
||||
struct cmd_parse_command *last;
|
||||
char *alias, *name, *cause;
|
||||
|
||||
if (pi->flags & CMD_PARSE_NOALIAS)
|
||||
return (0);
|
||||
memset(pr, 0, sizeof *pr);
|
||||
|
||||
first = TAILQ_FIRST(&cmd->arguments);
|
||||
if (first == NULL || first->type != CMD_PARSE_STRING) {
|
||||
pr->status = CMD_PARSE_SUCCESS;
|
||||
pr->cmdlist = cmd_list_new();
|
||||
return (1);
|
||||
}
|
||||
name = first->string;
|
||||
|
||||
alias = cmd_get_alias(name);
|
||||
if (alias == NULL)
|
||||
return (0);
|
||||
log_debug("%s: %u alias %s = %s", __func__, pi->line, name, alias);
|
||||
|
||||
cmds = cmd_parse_do_buffer(alias, strlen(alias), pi, &cause);
|
||||
free(alias);
|
||||
if (cmds == NULL) {
|
||||
pr->status = CMD_PARSE_ERROR;
|
||||
pr->error = cause;
|
||||
return (1);
|
||||
}
|
||||
|
||||
last = TAILQ_LAST(cmds, cmd_parse_commands);
|
||||
if (last == NULL) {
|
||||
pr->status = CMD_PARSE_SUCCESS;
|
||||
pr->cmdlist = cmd_list_new();
|
||||
return (1);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&cmd->arguments, first, entry);
|
||||
cmd_parse_free_argument(first);
|
||||
|
||||
TAILQ_FOREACH_SAFE(arg, &cmd->arguments, entry, arg1) {
|
||||
TAILQ_REMOVE(&cmd->arguments, arg, entry);
|
||||
TAILQ_INSERT_TAIL(&last->arguments, arg, entry);
|
||||
}
|
||||
cmd_parse_log_commands(cmds, __func__);
|
||||
|
||||
pi->flags |= CMD_PARSE_NOALIAS;
|
||||
cmd_parse_build_commands(cmds, pi, pr);
|
||||
pi->flags &= ~CMD_PARSE_NOALIAS;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_build_command(struct cmd_parse_command *cmd,
|
||||
struct cmd_parse_input *pi, struct cmd_parse_result *pr)
|
||||
{
|
||||
struct cmd_parse_argument *arg;
|
||||
struct cmd *add;
|
||||
char *name, *alias, *cause, *s;
|
||||
char *cause;
|
||||
struct args_value *values = NULL;
|
||||
u_int count = 0, idx;
|
||||
|
||||
memset(pr, 0, sizeof *pr);
|
||||
|
||||
if (cmd_parse_expand_alias(cmd, pi, pr))
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH(arg, &cmd->arguments, entry) {
|
||||
values = xrecallocarray(values, count, count + 1,
|
||||
sizeof *values);
|
||||
switch (arg->type) {
|
||||
case CMD_PARSE_STRING:
|
||||
values[count].type = ARGS_STRING;
|
||||
values[count].string = xstrdup(arg->string);
|
||||
break;
|
||||
case CMD_PARSE_COMMANDS:
|
||||
cmd_parse_build_commands(arg->commands, pi, pr);
|
||||
if (pr->status != CMD_PARSE_SUCCESS)
|
||||
goto out;
|
||||
values[count].type = ARGS_COMMANDS;
|
||||
values[count].cmdlist = pr->cmdlist;
|
||||
break;
|
||||
case CMD_PARSE_PARSED_COMMANDS:
|
||||
values[count].type = ARGS_COMMANDS;
|
||||
values[count].cmdlist = arg->cmdlist;
|
||||
values[count].cmdlist->references++;
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
|
||||
add = cmd_parse(values, count, pi->file, pi->line, &cause);
|
||||
if (add == NULL) {
|
||||
pr->status = CMD_PARSE_ERROR;
|
||||
pr->error = cmd_parse_get_error(pi->file, pi->line, cause);
|
||||
free(cause);
|
||||
goto out;
|
||||
}
|
||||
pr->status = CMD_PARSE_SUCCESS;
|
||||
pr->cmdlist = cmd_list_new();
|
||||
cmd_list_append(pr->cmdlist, add);
|
||||
|
||||
out:
|
||||
for (idx = 0; idx < count; idx++)
|
||||
args_free_value(&values[idx]);
|
||||
free(values);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_parse_build_commands(struct cmd_parse_commands *cmds,
|
||||
struct cmd_parse_input *pi, struct cmd_parse_result *pr)
|
||||
{
|
||||
struct cmd_parse_command *cmd;
|
||||
u_int line = UINT_MAX;
|
||||
struct cmd_list *current = NULL, *result;
|
||||
char *s;
|
||||
|
||||
memset(pr, 0, sizeof *pr);
|
||||
|
||||
/* Check for an empty list. */
|
||||
if (TAILQ_EMPTY(cmds)) {
|
||||
cmd_parse_free_commands(cmds);
|
||||
pr.status = CMD_PARSE_EMPTY;
|
||||
return (&pr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk the commands and expand any aliases. Each alias is parsed
|
||||
* individually to a new command list, any trailing arguments appended
|
||||
* to the last command, and all commands inserted into the original
|
||||
* command list.
|
||||
*/
|
||||
TAILQ_FOREACH_SAFE(cmd, cmds, entry, next) {
|
||||
name = cmd->argv[0];
|
||||
|
||||
alias = cmd_get_alias(name);
|
||||
if (alias == NULL)
|
||||
continue;
|
||||
|
||||
line = cmd->line;
|
||||
log_debug("%s: %u %s = %s", __func__, line, name, alias);
|
||||
|
||||
pi->line = line;
|
||||
cmds2 = cmd_parse_do_buffer(alias, strlen(alias), pi, &cause);
|
||||
free(alias);
|
||||
if (cmds2 == NULL) {
|
||||
pr.status = CMD_PARSE_ERROR;
|
||||
pr.error = cause;
|
||||
goto out;
|
||||
}
|
||||
|
||||
cmd2 = TAILQ_LAST(cmds2, cmd_parse_commands);
|
||||
if (cmd2 == NULL) {
|
||||
TAILQ_REMOVE(cmds, cmd, entry);
|
||||
cmd_parse_free_command(cmd);
|
||||
continue;
|
||||
}
|
||||
for (i = 1; i < cmd->argc; i++)
|
||||
cmd_append_argv(&cmd2->argc, &cmd2->argv, cmd->argv[i]);
|
||||
|
||||
after = cmd;
|
||||
TAILQ_FOREACH_SAFE(cmd2, cmds2, entry, next2) {
|
||||
cmd2->line = line;
|
||||
TAILQ_REMOVE(cmds2, cmd2, entry);
|
||||
TAILQ_INSERT_AFTER(cmds, after, cmd2, entry);
|
||||
after = cmd2;
|
||||
}
|
||||
cmd_parse_free_commands(cmds2);
|
||||
|
||||
TAILQ_REMOVE(cmds, cmd, entry);
|
||||
cmd_parse_free_command(cmd);
|
||||
pr->status = CMD_PARSE_SUCCESS;
|
||||
pr->cmdlist = cmd_list_new();
|
||||
return;
|
||||
}
|
||||
cmd_parse_log_commands(cmds, __func__);
|
||||
|
||||
/*
|
||||
* Parse each command into a command list. Create a new command list
|
||||
@@ -749,49 +879,39 @@ cmd_parse_build_commands(struct cmd_parse_commands *cmds,
|
||||
*/
|
||||
result = cmd_list_new();
|
||||
TAILQ_FOREACH(cmd, cmds, entry) {
|
||||
name = cmd->argv[0];
|
||||
log_debug("%s: %u %s", __func__, cmd->line, name);
|
||||
cmd_log_argv(cmd->argc, cmd->argv, __func__);
|
||||
|
||||
if (cmdlist == NULL ||
|
||||
((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
|
||||
if (cmdlist != NULL) {
|
||||
cmd_parse_print_commands(pi, line, cmdlist);
|
||||
cmd_list_move(result, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
if (((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
|
||||
if (current != NULL) {
|
||||
cmd_parse_print_commands(pi, current);
|
||||
cmd_list_move(result, current);
|
||||
cmd_list_free(current);
|
||||
}
|
||||
cmdlist = cmd_list_new();
|
||||
current = cmd_list_new();
|
||||
}
|
||||
line = cmd->line;
|
||||
if (current == NULL)
|
||||
current = cmd_list_new();
|
||||
line = pi->line = cmd->line;
|
||||
|
||||
add = cmd_parse(cmd->argc, cmd->argv, pi->file, line, &cause);
|
||||
if (add == NULL) {
|
||||
cmd_parse_build_command(cmd, pi, pr);
|
||||
if (pr->status != CMD_PARSE_SUCCESS) {
|
||||
cmd_list_free(result);
|
||||
pr.status = CMD_PARSE_ERROR;
|
||||
pr.error = cmd_parse_get_error(pi->file, line, cause);
|
||||
free(cause);
|
||||
cmd_list_free(cmdlist);
|
||||
goto out;
|
||||
cmd_list_free(current);
|
||||
return;
|
||||
}
|
||||
cmd_list_append(cmdlist, add);
|
||||
cmd_list_append_all(current, pr->cmdlist);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
}
|
||||
if (cmdlist != NULL) {
|
||||
cmd_parse_print_commands(pi, line, cmdlist);
|
||||
cmd_list_move(result, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
if (current != NULL) {
|
||||
cmd_parse_print_commands(pi, current);
|
||||
cmd_list_move(result, current);
|
||||
cmd_list_free(current);
|
||||
}
|
||||
|
||||
s = cmd_list_print(result, 0);
|
||||
log_debug("%s: %s", __func__, s);
|
||||
free(s);
|
||||
|
||||
pr.status = CMD_PARSE_SUCCESS;
|
||||
pr.cmdlist = result;
|
||||
|
||||
out:
|
||||
cmd_parse_free_commands(cmds);
|
||||
|
||||
return (&pr);
|
||||
pr->status = CMD_PARSE_SUCCESS;
|
||||
pr->cmdlist = result;
|
||||
}
|
||||
|
||||
struct cmd_parse_result *
|
||||
@@ -814,7 +934,10 @@ cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi)
|
||||
pr.error = cause;
|
||||
return (&pr);
|
||||
}
|
||||
return (cmd_parse_build_commands(cmds, pi));
|
||||
cmd_parse_build_commands(cmds, pi, &pr);
|
||||
cmd_parse_free_commands(cmds);
|
||||
return (&pr);
|
||||
|
||||
}
|
||||
|
||||
struct cmd_parse_result *
|
||||
@@ -845,8 +968,6 @@ cmd_parse_and_insert(const char *s, struct cmd_parse_input *pi,
|
||||
|
||||
pr = cmd_parse_from_string(s, pi);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
if (error != NULL)
|
||||
*error = pr->error;
|
||||
@@ -871,8 +992,6 @@ cmd_parse_and_append(const char *s, struct cmd_parse_input *pi,
|
||||
|
||||
pr = cmd_parse_from_string(s, pi);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
if (error != NULL)
|
||||
*error = pr->error;
|
||||
@@ -903,9 +1022,8 @@ cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi)
|
||||
memset(&pr, 0, sizeof pr);
|
||||
|
||||
if (len == 0) {
|
||||
pr.status = CMD_PARSE_EMPTY;
|
||||
pr.cmdlist = NULL;
|
||||
pr.error = NULL;
|
||||
pr.status = CMD_PARSE_SUCCESS;
|
||||
pr.cmdlist = cmd_list_new();
|
||||
return (&pr);
|
||||
}
|
||||
|
||||
@@ -915,18 +1033,24 @@ cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi)
|
||||
pr.error = cause;
|
||||
return (&pr);
|
||||
}
|
||||
return (cmd_parse_build_commands(cmds, pi));
|
||||
cmd_parse_build_commands(cmds, pi, &pr);
|
||||
cmd_parse_free_commands(cmds);
|
||||
return (&pr);
|
||||
}
|
||||
|
||||
struct cmd_parse_result *
|
||||
cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi)
|
||||
cmd_parse_from_arguments(struct args_value *values, u_int count,
|
||||
struct cmd_parse_input *pi)
|
||||
{
|
||||
struct cmd_parse_input input;
|
||||
struct cmd_parse_commands *cmds;
|
||||
struct cmd_parse_command *cmd;
|
||||
char **copy, **new_argv;
|
||||
size_t size;
|
||||
int i, last, new_argc;
|
||||
static struct cmd_parse_result pr;
|
||||
struct cmd_parse_input input;
|
||||
struct cmd_parse_commands *cmds;
|
||||
struct cmd_parse_command *cmd;
|
||||
struct cmd_parse_argument *arg;
|
||||
u_int i;
|
||||
char *copy;
|
||||
size_t size;
|
||||
int end;
|
||||
|
||||
/*
|
||||
* The commands are already split up into arguments, so just separate
|
||||
@@ -937,62 +1061,55 @@ cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi)
|
||||
memset(&input, 0, sizeof input);
|
||||
pi = &input;
|
||||
}
|
||||
cmd_log_argv(argc, argv, "%s", __func__);
|
||||
memset(&pr, 0, sizeof pr);
|
||||
|
||||
cmds = cmd_parse_new_commands();
|
||||
copy = cmd_copy_argv(argc, argv);
|
||||
|
||||
last = 0;
|
||||
for (i = 0; i < argc; i++) {
|
||||
size = strlen(copy[i]);
|
||||
if (size == 0 || copy[i][size - 1] != ';')
|
||||
continue;
|
||||
copy[i][--size] = '\0';
|
||||
if (size > 0 && copy[i][size - 1] == '\\') {
|
||||
copy[i][size - 1] = ';';
|
||||
continue;
|
||||
}
|
||||
|
||||
new_argc = i - last;
|
||||
new_argv = copy + last;
|
||||
if (size != 0)
|
||||
new_argc++;
|
||||
|
||||
if (new_argc != 0) {
|
||||
cmd_log_argv(new_argc, new_argv, "%s: at %u", __func__,
|
||||
i);
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->line = pi->line;
|
||||
TAILQ_INIT(&cmd->arguments);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
end = 0;
|
||||
if (values[i].type == ARGS_STRING) {
|
||||
copy = xstrdup(values[i].string);
|
||||
size = strlen(copy);
|
||||
if (size != 0 && copy[size - 1] == ';') {
|
||||
copy[--size] = '\0';
|
||||
if (size > 0 && copy[size - 1] == '\\')
|
||||
copy[size - 1] = ';';
|
||||
else
|
||||
end = 1;
|
||||
}
|
||||
if (!end || size != 0) {
|
||||
arg = xcalloc(1, sizeof *arg);
|
||||
arg->type = CMD_PARSE_STRING;
|
||||
arg->string = copy;
|
||||
TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry);
|
||||
}
|
||||
} else if (values[i].type == ARGS_COMMANDS) {
|
||||
arg = xcalloc(1, sizeof *arg);
|
||||
arg->type = CMD_PARSE_PARSED_COMMANDS;
|
||||
arg->cmdlist = values[i].cmdlist;
|
||||
arg->cmdlist->references++;
|
||||
TAILQ_INSERT_TAIL(&cmd->arguments, arg, entry);
|
||||
} else
|
||||
fatalx("unknown argument type");
|
||||
if (end) {
|
||||
TAILQ_INSERT_TAIL(cmds, cmd, entry);
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->line = pi->line;
|
||||
|
||||
cmd->argc = new_argc;
|
||||
cmd->argv = cmd_copy_argv(new_argc, new_argv);
|
||||
|
||||
TAILQ_INSERT_TAIL(cmds, cmd, entry);
|
||||
}
|
||||
|
||||
last = i + 1;
|
||||
}
|
||||
if (last != argc) {
|
||||
new_argv = copy + last;
|
||||
new_argc = argc - last;
|
||||
|
||||
if (new_argc != 0) {
|
||||
cmd_log_argv(new_argc, new_argv, "%s: at %u", __func__,
|
||||
last);
|
||||
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->line = pi->line;
|
||||
|
||||
cmd->argc = new_argc;
|
||||
cmd->argv = cmd_copy_argv(new_argc, new_argv);
|
||||
|
||||
TAILQ_INSERT_TAIL(cmds, cmd, entry);
|
||||
TAILQ_INIT(&cmd->arguments);
|
||||
}
|
||||
}
|
||||
if (!TAILQ_EMPTY(&cmd->arguments))
|
||||
TAILQ_INSERT_TAIL(cmds, cmd, entry);
|
||||
else
|
||||
free(cmd);
|
||||
|
||||
cmd_free_argv(argc, copy);
|
||||
return (cmd_parse_build_commands(cmds, pi));
|
||||
cmd_parse_build_commands(cmds, pi, &pr);
|
||||
cmd_parse_free_commands(cmds);
|
||||
return (&pr);
|
||||
}
|
||||
|
||||
static int printflike(1, 2)
|
||||
@@ -1309,7 +1426,7 @@ yylex_token_escape(char **buf, size_t *len)
|
||||
if (o3 >= '0' && o3 <= '7') {
|
||||
ch = 64 * (ch - '0') +
|
||||
8 * (o2 - '0') +
|
||||
(o3 - '0');
|
||||
(o3 - '0');
|
||||
yylex_append1(buf, len, ch);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.name = "paste-buffer",
|
||||
.alias = "pasteb",
|
||||
|
||||
.args = { "db:prs:t:", 0, 0 },
|
||||
.args = { "db:prs:t:", 0, 0, NULL },
|
||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
.name = "pipe-pane",
|
||||
.alias = "pipep",
|
||||
|
||||
.args = { "IOot:", 0, 1 },
|
||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
.args = { "IOot:", 0, 1, NULL },
|
||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -67,6 +67,12 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct format_tree *ft;
|
||||
sigset_t set, oldset;
|
||||
|
||||
/* Do nothing if pane is dead. */
|
||||
if (wp->fd == -1 || (wp->flags & PANE_EXITED)) {
|
||||
cmdq_error(item, "target pane has exited");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* Destroy the old pipe. */
|
||||
old_fd = wp->pipe_fd;
|
||||
if (wp->pipe_fd != -1) {
|
||||
@@ -81,7 +87,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
/* If no pipe command, that is enough. */
|
||||
if (args->argc == 0 || *args->argv[0] == '\0')
|
||||
if (args_count(args) == 0 || *args_string(args, 0) == '\0')
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/*
|
||||
@@ -111,7 +117,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
/* Expand the command. */
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, tc, s, wl, wp);
|
||||
cmd = format_expand_time(ft, args->argv[0]);
|
||||
cmd = format_expand_time(ft, args_string(args, 0));
|
||||
format_free(ft);
|
||||
|
||||
/* Fork the child. */
|
||||
@@ -130,7 +136,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[0]);
|
||||
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY);
|
||||
if (out) {
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||
_exit(1);
|
||||
|
||||
72
cmd-queue.c
72
cmd-queue.c
@@ -19,9 +19,11 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -124,7 +126,7 @@ cmdq_new(void)
|
||||
{
|
||||
struct cmdq_list *queue;
|
||||
|
||||
queue = xcalloc (1, sizeof *queue);
|
||||
queue = xcalloc(1, sizeof *queue);
|
||||
TAILQ_INIT (&queue->list);
|
||||
return (queue);
|
||||
}
|
||||
@@ -269,6 +271,15 @@ cmdq_add_format(struct cmdq_state *state, const char *key, const char *fmt, ...)
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Add formats to command queue. */
|
||||
void
|
||||
cmdq_add_formats(struct cmdq_state *state, struct format_tree *ft)
|
||||
{
|
||||
if (state->formats == NULL)
|
||||
state->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
|
||||
format_merge(state->formats, ft);
|
||||
}
|
||||
|
||||
/* Merge formats from item. */
|
||||
void
|
||||
cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
|
||||
@@ -343,12 +354,12 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
||||
struct cmdq_state *state = item->state;
|
||||
struct cmd *cmd = item->cmd;
|
||||
struct args *args = cmd_get_args(cmd);
|
||||
struct args_entry *entryp;
|
||||
struct args_value *valuep;
|
||||
struct args_entry *ae;
|
||||
struct args_value *av;
|
||||
struct options *oo;
|
||||
va_list ap;
|
||||
char *name, tmp[32], flag, *arguments;
|
||||
int i;
|
||||
u_int i;
|
||||
const char *value;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmdq_state *new_state;
|
||||
@@ -385,11 +396,11 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
||||
cmdq_add_format(new_state, "hook_arguments", "%s", arguments);
|
||||
free(arguments);
|
||||
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
for (i = 0; i < args_count(args); i++) {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_argument_%d", i);
|
||||
cmdq_add_format(new_state, tmp, "%s", args->argv[i]);
|
||||
cmdq_add_format(new_state, tmp, "%s", args_string(args, i));
|
||||
}
|
||||
flag = args_first(args, &entryp);
|
||||
flag = args_first(args, &ae);
|
||||
while (flag != 0) {
|
||||
value = args_get(args, flag);
|
||||
if (value == NULL) {
|
||||
@@ -401,15 +412,15 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
||||
}
|
||||
|
||||
i = 0;
|
||||
value = args_first_value(args, flag, &valuep);
|
||||
while (value != NULL) {
|
||||
av = args_first_value(args, flag);
|
||||
while (av != NULL) {
|
||||
xsnprintf(tmp, sizeof tmp, "hook_flag_%c_%d", flag, i);
|
||||
cmdq_add_format(new_state, tmp, "%s", value);
|
||||
cmdq_add_format(new_state, tmp, "%s", av->string);
|
||||
i++;
|
||||
value = args_next_value(&valuep);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
flag = args_next(&entryp);
|
||||
flag = args_next(&ae);
|
||||
}
|
||||
|
||||
a = options_array_first(o);
|
||||
@@ -469,6 +480,13 @@ cmdq_remove_group(struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
/* Empty command callback. */
|
||||
static enum cmd_retval
|
||||
cmdq_empty_command(__unused struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Get a command for the command queue. */
|
||||
struct cmdq_item *
|
||||
cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
||||
@@ -478,12 +496,14 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
||||
const struct cmd_entry *entry;
|
||||
int created = 0;
|
||||
|
||||
if ((cmd = cmd_list_first(cmdlist)) == NULL)
|
||||
return (cmdq_get_callback(cmdq_empty_command, NULL));
|
||||
|
||||
if (state == NULL) {
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
created = 1;
|
||||
}
|
||||
|
||||
cmd = cmd_list_first(cmdlist);
|
||||
while (cmd != NULL) {
|
||||
entry = cmd_get_entry(cmd);
|
||||
|
||||
@@ -540,17 +560,31 @@ cmdq_add_message(struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct cmdq_state *state = item->state;
|
||||
const char *name, *key;
|
||||
const char *key;
|
||||
char *tmp;
|
||||
uid_t uid;
|
||||
struct passwd *pw;
|
||||
char *user = NULL;
|
||||
|
||||
tmp = cmd_print(item->cmd);
|
||||
if (c != NULL) {
|
||||
name = c->name;
|
||||
uid = proc_get_peer_uid(c->peer);
|
||||
if (uid != (uid_t)-1 && uid != getuid()) {
|
||||
if ((pw = getpwuid(uid)) != NULL)
|
||||
xasprintf(&user, "[%s]", pw->pw_name);
|
||||
else
|
||||
user = xstrdup("[unknown]");
|
||||
} else
|
||||
user = xstrdup("");
|
||||
if (c->session != NULL && state->event.key != KEYC_NONE) {
|
||||
key = key_string_lookup_key(state->event.key, 0);
|
||||
server_add_message("%s key %s: %s", name, key, tmp);
|
||||
} else
|
||||
server_add_message("%s command: %s", name, tmp);
|
||||
server_add_message("%s%s key %s: %s", c->name, user,
|
||||
key, tmp);
|
||||
} else {
|
||||
server_add_message("%s%s command: %s", c->name, user,
|
||||
tmp);
|
||||
}
|
||||
free(user);
|
||||
} else
|
||||
server_add_message("command: %s", tmp);
|
||||
free(tmp);
|
||||
@@ -822,7 +856,7 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL,
|
||||
NULL);
|
||||
}
|
||||
window_copy_add(wp, "%s", msg);
|
||||
window_copy_add(wp, 0, "%s", msg);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.name = "refresh-client",
|
||||
.alias = "refresh",
|
||||
|
||||
.args = { "A:B:cC:Df:F:lLRSt:U", 0, 1 },
|
||||
.args = { "A:B:cC:Df:F:l::LRSt:U", 0, 1, NULL },
|
||||
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
|
||||
"[-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
||||
|
||||
@@ -77,6 +77,58 @@ out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_control_client_size(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
const char *size = args_get(args, 'C');
|
||||
u_int w, x, y;
|
||||
struct client_window *cw;
|
||||
|
||||
if (sscanf(size, "@%u:%ux%u", &w, &x, &y) == 3) {
|
||||
if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
|
||||
y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
|
||||
cmdq_error(item, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
log_debug("%s: client %s window @%u: size %ux%u", __func__,
|
||||
tc->name, w, x, y);
|
||||
cw = server_client_add_client_window(tc, w);
|
||||
cw->sx = x;
|
||||
cw->sy = y;
|
||||
tc->flags |= CLIENT_WINDOWSIZECHANGED;
|
||||
recalculate_sizes_now(1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (sscanf(size, "@%u:", &w) == 1) {
|
||||
cw = server_client_get_client_window(tc, w);
|
||||
if (cw != NULL) {
|
||||
log_debug("%s: client %s window @%u: no size", __func__,
|
||||
tc->name, w);
|
||||
cw->sx = 0;
|
||||
cw->sy = 0;
|
||||
recalculate_sizes_now(1);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (sscanf(size, "%u,%u", &x, &y) != 2 &&
|
||||
sscanf(size, "%ux%u", &x, &y) != 2) {
|
||||
cmdq_error(item, "bad size argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
|
||||
y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
|
||||
cmdq_error(item, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
tty_set_size(&tc->tty, x, y, 0, 0);
|
||||
tc->flags |= CLIENT_SIZECHANGED;
|
||||
recalculate_sizes_now(1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_refresh_client_update_offset(struct client *tc, const char *value)
|
||||
{
|
||||
@@ -110,6 +162,37 @@ out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_clipboard(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
const char *p;
|
||||
u_int i;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
p = args_get(args, 'l');
|
||||
if (p == NULL) {
|
||||
if (tc->flags & CLIENT_CLIPBOARDBUFFER)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
tc->flags |= CLIENT_CLIPBOARDBUFFER;
|
||||
} else {
|
||||
if (cmd_find_target(&fs, item, p, CMD_FIND_PANE, 0) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
for (i = 0; i < tc->clipboard_npanes; i++) {
|
||||
if (tc->clipboard_panes[i] == fs.wp->id)
|
||||
break;
|
||||
}
|
||||
if (i != tc->clipboard_npanes)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
tc->clipboard_panes = xreallocarray(tc->clipboard_panes,
|
||||
tc->clipboard_npanes + 1, sizeof *tc->clipboard_panes);
|
||||
tc->clipboard_panes[tc->clipboard_npanes++] = fs.wp->id;
|
||||
}
|
||||
tty_clipboard_query(&tc->tty);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -117,8 +200,8 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct tty *tty = &tc->tty;
|
||||
struct window *w;
|
||||
const char *size, *errstr, *value;
|
||||
u_int x, y, adjust;
|
||||
const char *errstr;
|
||||
u_int adjust;
|
||||
struct args_value *av;
|
||||
|
||||
if (args_has(args, 'c') ||
|
||||
@@ -127,10 +210,11 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
args_has(args, 'U') ||
|
||||
args_has(args, 'D'))
|
||||
{
|
||||
if (args->argc == 0)
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX,
|
||||
&errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -171,10 +255,8 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'l')) {
|
||||
tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(args, 'l'))
|
||||
return (cmd_refresh_client_clipboard(self, item));
|
||||
|
||||
if (args_has(args, 'F')) /* -F is an alias for -f */
|
||||
server_client_set_flags(tc, args_get(args, 'F'));
|
||||
@@ -184,41 +266,27 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'A')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
value = args_first_value(args, 'A', &av);
|
||||
while (value != NULL) {
|
||||
cmd_refresh_client_update_offset(tc, value);
|
||||
value = args_next_value(&av);
|
||||
av = args_first_value(args, 'A');
|
||||
while (av != NULL) {
|
||||
cmd_refresh_client_update_offset(tc, av->string);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(args, 'B')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
value = args_first_value(args, 'B', &av);
|
||||
while (value != NULL) {
|
||||
cmd_refresh_client_update_subscription(tc, value);
|
||||
value = args_next_value(&av);
|
||||
av = args_first_value(args, 'B');
|
||||
while (av != NULL) {
|
||||
cmd_refresh_client_update_subscription(tc, av->string);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_has(args, 'C')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
goto not_control_client;
|
||||
size = args_get(args, 'C');
|
||||
if (sscanf(size, "%u,%u", &x, &y) != 2 &&
|
||||
sscanf(size, "%ux%u", &x, &y) != 2) {
|
||||
cmdq_error(item, "bad size argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
|
||||
y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
|
||||
cmdq_error(item, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
tty_set_size(&tc->tty, x, y, 0, 0);
|
||||
tc->flags |= CLIENT_SIZECHANGED;
|
||||
recalculate_sizes_now(1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (cmd_refresh_client_control_client_size(self, item));
|
||||
}
|
||||
|
||||
if (args_has(args, 'S')) {
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
.name = "rename-session",
|
||||
.alias = "rename",
|
||||
|
||||
.args = { "t:", 1, 1 },
|
||||
.args = { "t:", 1, 1, NULL },
|
||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
@@ -51,8 +51,13 @@ cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s = target->s;
|
||||
char *newname, *tmp;
|
||||
|
||||
tmp = format_single_from_target(item, args->argv[0]);
|
||||
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);
|
||||
free(tmp);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(tmp);
|
||||
if (strcmp(newname, s->name) == 0) {
|
||||
free(newname);
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_rename_window_entry = {
|
||||
.name = "rename-window",
|
||||
.alias = "renamew",
|
||||
|
||||
.args = { "t:", 1, 1 },
|
||||
.args = { "t:", 1, 1, NULL },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -50,7 +50,7 @@ cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct winlink *wl = target->wl;
|
||||
char *newname;
|
||||
|
||||
newname = format_single_from_target(item, args->argv[0]);
|
||||
newname = format_single_from_target(item, args_string(args, 0));
|
||||
window_set_name(wl->window, newname);
|
||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_resize_pane_entry = {
|
||||
.name = "resize-pane",
|
||||
.alias = "resizep",
|
||||
|
||||
.args = { "DLMRTt:Ux:y:Z", 0, 1 },
|
||||
.args = { "DLMRTt:Ux:y:Z", 0, 1, NULL },
|
||||
.usage = "[-DLMRTUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
||||
"[adjustment]",
|
||||
|
||||
@@ -60,7 +60,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust;
|
||||
int x, y;
|
||||
int x, y, status;
|
||||
struct grid *gd = wp->base.grid;
|
||||
|
||||
if (args_has(args, 'T')) {
|
||||
@@ -95,10 +95,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args->argc == 0)
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -121,6 +121,17 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
switch (status) {
|
||||
case PANE_STATUS_TOP:
|
||||
if (y != INT_MAX && wp->yoff == 1)
|
||||
y++;
|
||||
break;
|
||||
case PANE_STATUS_BOTTOM:
|
||||
if (y != INT_MAX && wp->yoff + wp->sy == w->sy - 1)
|
||||
y++;
|
||||
break;
|
||||
}
|
||||
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_resize_window_entry = {
|
||||
.name = "resize-window",
|
||||
.alias = "resizew",
|
||||
|
||||
.args = { "aADLRt:Ux:y:", 0, 1 },
|
||||
.args = { "aADLRt:Ux:y:", 0, 1, NULL },
|
||||
.usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
|
||||
"[adjustment]",
|
||||
|
||||
@@ -56,10 +56,10 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
u_int adjust, sx, sy;
|
||||
int xpixel = -1, ypixel = -1;
|
||||
|
||||
if (args->argc == 0)
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -108,7 +108,9 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
|
||||
resize_window(w, sx, sy, xpixel, ypixel);
|
||||
w->manual_sx = sx;
|
||||
w->manual_sy = sy;
|
||||
recalculate_size(w, 1);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
.name = "respawn-pane",
|
||||
.alias = "respawnp",
|
||||
|
||||
.args = { "c:e:kt:", 0, -1 },
|
||||
.args = { "c:e:kt:", 0, -1, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_PANE_USAGE " [command]",
|
||||
CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -49,31 +49,26 @@ cmd_respawn_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 spawn_context sc;
|
||||
struct spawn_context sc = { 0 };
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *wp = target->wp;
|
||||
char *cause = NULL;
|
||||
const char *add;
|
||||
struct args_value *value;
|
||||
struct args_value *av;
|
||||
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
|
||||
sc.wp0 = wp;
|
||||
sc.lc = NULL;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add, 0);
|
||||
add = args_next_value(&value);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
sc.idx = -1;
|
||||
@@ -86,6 +81,9 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (spawn_pane(&sc, &cause) == NULL) {
|
||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
||||
free(cause);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -93,6 +91,8 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
server_redraw_window_borders(wp->window);
|
||||
server_status_window(wp->window);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.name = "respawn-window",
|
||||
.alias = "respawnw",
|
||||
|
||||
.args = { "c:e:kt:", 0, -1 },
|
||||
.args = { "c:e:kt:", 0, -1, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -49,29 +49,25 @@ cmd_respawn_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 spawn_context sc;
|
||||
struct spawn_context sc = { 0 };
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
char *cause = NULL;
|
||||
const char *add;
|
||||
struct args_value *value;
|
||||
struct args_value *av;
|
||||
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
sc.tc = tc;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add, 0);
|
||||
add = args_next_value(&value);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
sc.idx = -1;
|
||||
@@ -84,11 +80,16 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (spawn_window(&sc, &cause) == NULL) {
|
||||
cmdq_error(item, "respawn 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);
|
||||
}
|
||||
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
.name = "rotate-window",
|
||||
.alias = "rotatew",
|
||||
|
||||
.args = { "Dt:UZ", 0, 0 },
|
||||
.args = { "Dt:UZ", 0, 0, NULL },
|
||||
.usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
123
cmd-run-shell.c
123
cmd-run-shell.c
@@ -30,7 +30,10 @@
|
||||
* Runs a command without a window.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *, struct cmdq_item *);
|
||||
static enum args_parse_type cmd_run_shell_args_parse(struct args *, u_int,
|
||||
char **);
|
||||
static enum cmd_retval cmd_run_shell_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_run_shell_timer(int, short, void *);
|
||||
static void cmd_run_shell_callback(struct job *);
|
||||
@@ -41,7 +44,7 @@ const struct cmd_entry cmd_run_shell_entry = {
|
||||
.name = "run-shell",
|
||||
.alias = "run",
|
||||
|
||||
.args = { "bd:Ct:", 0, 1 },
|
||||
.args = { "bd:Ct:", 0, 1, cmd_run_shell_args_parse },
|
||||
.usage = "[-bC] [-d delay] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -51,18 +54,26 @@ const struct cmd_entry cmd_run_shell_entry = {
|
||||
};
|
||||
|
||||
struct cmd_run_shell_data {
|
||||
struct client *client;
|
||||
char *cmd;
|
||||
int shell;
|
||||
char *cwd;
|
||||
struct cmdq_item *item;
|
||||
struct session *s;
|
||||
int wp_id;
|
||||
struct event timer;
|
||||
int flags;
|
||||
struct cmd_parse_input pi;
|
||||
struct client *client;
|
||||
char *cmd;
|
||||
struct args_command_state *state;
|
||||
char *cwd;
|
||||
struct cmdq_item *item;
|
||||
struct session *s;
|
||||
int wp_id;
|
||||
struct event timer;
|
||||
int flags;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_run_shell_args_parse(struct args *args, __unused u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
if (args_has(args, 'C'))
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
return (ARGS_PARSE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_run_shell_print(struct job *job, const char *msg)
|
||||
{
|
||||
@@ -73,22 +84,17 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
|
||||
if (cdata->wp_id != -1)
|
||||
wp = window_pane_find_by_id(cdata->wp_id);
|
||||
if (wp == NULL) {
|
||||
if (cdata->item != NULL) {
|
||||
cmdq_print(cdata->item, "%s", msg);
|
||||
return;
|
||||
}
|
||||
if (cmd_find_from_nothing(&fs, 0) != 0)
|
||||
return;
|
||||
if (wp == NULL && cdata->item != NULL)
|
||||
wp = server_client_get_pane(cdata->client);
|
||||
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
|
||||
wp = fs.wp;
|
||||
if (wp == NULL)
|
||||
return;
|
||||
}
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
||||
window_copy_add(wp, "%s", msg);
|
||||
window_copy_add(wp, 1, "%s", msg);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -100,7 +106,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *delay;
|
||||
const char *delay, *cmd;
|
||||
double d;
|
||||
struct timeval tv;
|
||||
char *end;
|
||||
@@ -112,21 +118,17 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "invalid delay time: %s", delay);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args->argc == 0)
|
||||
} else if (args_count(args) == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (args->argc != 0)
|
||||
cdata->cmd = format_single_from_target(item, args->argv[0]);
|
||||
|
||||
cdata->shell = !args_has(args, 'C');
|
||||
if (!cdata->shell) {
|
||||
memset(&cdata->pi, 0, sizeof cdata->pi);
|
||||
cmd_get_source(self, &cdata->pi.file, &cdata->pi.line);
|
||||
if (wait)
|
||||
cdata->pi.item = item;
|
||||
cdata->pi.c = tc;
|
||||
cmd_find_copy_state(&cdata->pi.fs, target);
|
||||
if (!args_has(args, 'C')) {
|
||||
cmd = args_string(args, 0);
|
||||
if (cmd != NULL)
|
||||
cdata->cmd = format_single_from_target(item, cmd);
|
||||
} else {
|
||||
cdata->state = args_make_commands_prepare(self, item, 0, NULL,
|
||||
wait, 1);
|
||||
}
|
||||
|
||||
if (args_has(args, 't') && wp != NULL)
|
||||
@@ -170,34 +172,38 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
|
||||
struct cmd_run_shell_data *cdata = arg;
|
||||
struct client *c = cdata->client;
|
||||
const char *cmd = cdata->cmd;
|
||||
struct cmdq_item *item = cdata->item, *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
char *error;
|
||||
struct cmdq_item *item = cdata->item;
|
||||
enum cmd_parse_status status;
|
||||
|
||||
if (cmd != NULL && cdata->shell) {
|
||||
if (job_run(cmd, 0, NULL, cdata->s, cdata->cwd, NULL,
|
||||
if (cdata->state == NULL) {
|
||||
if (cmd == NULL) {
|
||||
if (cdata->item != NULL)
|
||||
cmdq_continue(cdata->item);
|
||||
cmd_run_shell_free(cdata);
|
||||
return;
|
||||
}
|
||||
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)
|
||||
cmd_run_shell_free(cdata);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmd != NULL) {
|
||||
if (item != NULL) {
|
||||
status = cmd_parse_and_insert(cmd, &cdata->pi, item,
|
||||
cmdq_get_state(item), &error);
|
||||
} else {
|
||||
status = cmd_parse_and_append(cmd, &cdata->pi, c, NULL,
|
||||
&error);
|
||||
}
|
||||
if (status == CMD_PARSE_ERROR) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
}
|
||||
cmdlist = args_make_commands(cdata->state, 0, NULL, &error);
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
} else if (item == NULL) {
|
||||
new_item = cmdq_get_command(cmdlist, NULL);
|
||||
cmdq_append(c, new_item);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
if (cdata->item != NULL)
|
||||
@@ -216,7 +222,8 @@ cmd_run_shell_callback(struct job *job)
|
||||
int retcode, status;
|
||||
|
||||
do {
|
||||
if ((line = evbuffer_readline(event->input)) != NULL) {
|
||||
line = evbuffer_readln(event->input, NULL, EVBUFFER_EOL_LF);
|
||||
if (line != NULL) {
|
||||
cmd_run_shell_print(job, line);
|
||||
free(line);
|
||||
}
|
||||
@@ -265,6 +272,8 @@ cmd_run_shell_free(void *data)
|
||||
session_remove_ref(cdata->s, __func__);
|
||||
if (cdata->client != NULL)
|
||||
server_client_unref(cdata->client);
|
||||
if (cdata->state != NULL)
|
||||
args_make_commands_free(cdata->state);
|
||||
free(cdata->cwd);
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
|
||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_save_buffer_entry = {
|
||||
.name = "save-buffer",
|
||||
.alias = "saveb",
|
||||
|
||||
.args = { "ab:", 1, 1 },
|
||||
.args = { "ab:", 1, 1, NULL },
|
||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
@@ -48,7 +48,7 @@ const struct cmd_entry cmd_show_buffer_entry = {
|
||||
.name = "show-buffer",
|
||||
.alias = "showb",
|
||||
|
||||
.args = { "b:", 0, 0 },
|
||||
.args = { "b:", 0, 0, NULL },
|
||||
.usage = CMD_BUFFER_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
@@ -104,7 +104,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
path = xstrdup("-");
|
||||
} else
|
||||
path = format_single_from_target(item, args->argv[0]);
|
||||
path = format_single_from_target(item, args_string(args, 0));
|
||||
if (args_has(args, 'a'))
|
||||
flags = O_APPEND;
|
||||
else
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_layout_entry = {
|
||||
.name = "select-layout",
|
||||
.alias = "selectl",
|
||||
|
||||
.args = { "Enopt:", 0, 1 },
|
||||
.args = { "Enopt:", 0, 1, NULL },
|
||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_next_layout_entry = {
|
||||
.name = "next-layout",
|
||||
.alias = "nextl",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -59,7 +59,7 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
.name = "previous-layout",
|
||||
.alias = "prevl",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -77,7 +77,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *layoutname;
|
||||
char *oldlayout;
|
||||
char *oldlayout, *cause;
|
||||
int next, previous, layout;
|
||||
|
||||
server_unzoom_window(w);
|
||||
@@ -105,27 +105,28 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
goto changed;
|
||||
}
|
||||
|
||||
if (args_count(args) != 0)
|
||||
layoutname = args_string(args, 0);
|
||||
else if (args_has(args, 'o'))
|
||||
layoutname = oldlayout;
|
||||
else
|
||||
layoutname = NULL;
|
||||
|
||||
if (!args_has(args, 'o')) {
|
||||
if (args->argc == 0)
|
||||
if (layoutname == NULL)
|
||||
layout = w->lastlayout;
|
||||
else
|
||||
layout = layout_set_lookup(args->argv[0]);
|
||||
layout = layout_set_lookup(layoutname);
|
||||
if (layout != -1) {
|
||||
layout_set_select(w, layout);
|
||||
goto changed;
|
||||
}
|
||||
}
|
||||
|
||||
if (args->argc != 0)
|
||||
layoutname = args->argv[0];
|
||||
else if (args_has(args, 'o'))
|
||||
layoutname = oldlayout;
|
||||
else
|
||||
layoutname = NULL;
|
||||
|
||||
if (layoutname != NULL) {
|
||||
if (layout_parse(w, layoutname) == -1) {
|
||||
cmdq_error(item, "can't set layout: %s", layoutname);
|
||||
if (layout_parse(w, layoutname, &cause) == -1) {
|
||||
cmdq_error(item, "%s: %s", cause, layoutname);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
goto changed;
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_pane_entry = {
|
||||
.name = "select-pane",
|
||||
.alias = "selectp",
|
||||
|
||||
.args = { "DdegLlMmP:RT:t:UZ", 0, 0 }, /* -P and -g deprecated */
|
||||
.args = { "DdegLlMmP:RT:t:UZ", 0, 0, NULL }, /* -P and -g deprecated */
|
||||
.usage = "[-DdeLlMmRUZ] [-T title] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_last_pane_entry = {
|
||||
.name = "last-pane",
|
||||
.alias = "lastp",
|
||||
|
||||
.args = { "det:Z", 0, 0 },
|
||||
.args = { "det:Z", 0, 0, NULL },
|
||||
.usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -145,10 +145,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
markedwp = marked_pane.wp;
|
||||
|
||||
if (lastwp != NULL) {
|
||||
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
server_redraw_window_borders(lastwp->window);
|
||||
server_status_window(lastwp->window);
|
||||
}
|
||||
if (markedwp != NULL) {
|
||||
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
server_redraw_window_borders(markedwp->window);
|
||||
server_status_window(markedwp->window);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_window_entry = {
|
||||
.name = "select-window",
|
||||
.alias = "selectw",
|
||||
|
||||
.args = { "lnpTt:", 0, 0 },
|
||||
.args = { "lnpTt:", 0, 0, NULL },
|
||||
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_next_window_entry = {
|
||||
.name = "next-window",
|
||||
.alias = "next",
|
||||
|
||||
.args = { "at:", 0, 0 },
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
@@ -59,7 +59,7 @@ const struct cmd_entry cmd_previous_window_entry = {
|
||||
.name = "previous-window",
|
||||
.alias = "prev",
|
||||
|
||||
.args = { "at:", 0, 0 },
|
||||
.args = { "at:", 0, 0, NULL },
|
||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
@@ -72,7 +72,7 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
.name = "last-window",
|
||||
.alias = "last",
|
||||
|
||||
.args = { "t:", 0, 0 },
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_send_keys_entry = {
|
||||
.name = "send-keys",
|
||||
.alias = "send",
|
||||
|
||||
.args = { "FHlMN:Rt:X", 0, -1 },
|
||||
.args = { "FHlMN:Rt:X", 0, -1, NULL },
|
||||
.usage = "[-FHlMRX] [-N repeat-count] " CMD_TARGET_PANE_USAGE
|
||||
" key ...",
|
||||
|
||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
||||
.name = "send-prefix",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "2t:", 0, 0 },
|
||||
.args = { "2t:", 0, 0, NULL },
|
||||
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -90,7 +90,7 @@ static struct cmdq_item *
|
||||
cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
||||
struct args *args, int i)
|
||||
{
|
||||
const char *s = args->argv[i];
|
||||
const char *s = args_string(args, i);
|
||||
struct utf8_data *ud, *loop;
|
||||
utf8_char uc;
|
||||
key_code key;
|
||||
@@ -145,9 +145,9 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct mouse_event *m = &event->m;
|
||||
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
||||
struct cmdq_item *after = item;
|
||||
int i;
|
||||
key_code key;
|
||||
u_int np = 1;
|
||||
u_int i, np = 1;
|
||||
u_int count = args_count(args);
|
||||
char *cause = NULL;
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
@@ -157,7 +157,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (wme != NULL && (args_has(args, 'X') || args->argc == 0)) {
|
||||
if (wme != NULL && (args_has(args, 'X') || count == 0)) {
|
||||
if (wme->mode->command == NULL) {
|
||||
cmdq_error(item, "not in a mode");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -197,12 +197,21 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
if (args_has(args, 'R')) {
|
||||
window_pane_reset_palette(wp);
|
||||
colour_palette_clear(&wp->palette);
|
||||
input_reset(wp->ictx, 1);
|
||||
wp->flags |= (PANE_STYLECHANGED|PANE_REDRAW);
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
if (args_has(args, 'N') || args_has(args, 'R'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
for (; np != 0; np--)
|
||||
cmd_send_keys_inject_key(item, NULL, event->key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
for (; np != 0; np--) {
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
for (i = 0; i < count; i++) {
|
||||
after = cmd_send_keys_inject_string(item, after, args,
|
||||
i);
|
||||
}
|
||||
|
||||
147
cmd-server-access.c
Normal file
147
cmd-server-access.c
Normal file
@@ -0,0 +1,147 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Dallas Lyons <dallasdlyons@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Controls access to session.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_server_access_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_server_access_entry = {
|
||||
.name = "server-access",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "adlrw", 0, 1, NULL },
|
||||
.usage = "[-adlrw] " CMD_TARGET_PANE_USAGE " [user]",
|
||||
|
||||
.flags = CMD_CLIENT_CANFAIL,
|
||||
.exec = cmd_server_access_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_server_access_deny(struct cmdq_item *item, struct passwd *pw)
|
||||
{
|
||||
struct client *loop;
|
||||
struct server_acl_user *user;
|
||||
uid_t uid;
|
||||
|
||||
if ((user = server_acl_user_find(pw->pw_uid)) == NULL) {
|
||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
TAILQ_FOREACH(loop, &clients, entry) {
|
||||
uid = proc_get_peer_uid(loop->peer);
|
||||
if (uid == server_acl_get_uid(user)) {
|
||||
loop->exit_message = xstrdup("access not allowed");
|
||||
loop->flags |= CLIENT_EXIT;
|
||||
}
|
||||
}
|
||||
server_acl_user_deny(pw->pw_uid);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_server_access_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *c = cmdq_get_target_client(item);
|
||||
char *name;
|
||||
struct passwd *pw = NULL;
|
||||
|
||||
if (args_has(args, 'l')) {
|
||||
server_acl_display(item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (args_count(args) == 0) {
|
||||
cmdq_error(item, "missing user argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
name = format_single(item, args_string(args, 0), c, NULL, NULL, NULL);
|
||||
if (*name != '\0')
|
||||
pw = getpwnam(name);
|
||||
if (pw == NULL) {
|
||||
cmdq_error(item, "unknown user: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(name);
|
||||
|
||||
if (pw->pw_uid == 0 || pw->pw_uid == getuid()) {
|
||||
cmdq_error(item, "%s owns the server, can't change access",
|
||||
pw->pw_name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'a') && args_has(args, 'd')) {
|
||||
cmdq_error(item, "-a and -d cannot be used together");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(args, 'w') && args_has(args, 'r')) {
|
||||
cmdq_error(item, "-r and -w cannot be used together");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'd'))
|
||||
return (cmd_server_access_deny(item, pw));
|
||||
if (args_has(args, 'a')) {
|
||||
if (server_acl_user_find(pw->pw_uid) != NULL) {
|
||||
cmdq_error(item, "user %s is already added",
|
||||
pw->pw_name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_acl_user_allow(pw->pw_uid);
|
||||
/* Do not return - allow -r or -w with -a. */
|
||||
} else if (args_has(args, 'r') || args_has(args, 'w')) {
|
||||
/* -r or -w implies -a if user does not exist. */
|
||||
if (server_acl_user_find(pw->pw_uid) == NULL)
|
||||
server_acl_user_allow(pw->pw_uid);
|
||||
}
|
||||
|
||||
if (args_has(args, 'w')) {
|
||||
if (server_acl_user_find(pw->pw_uid) == NULL) {
|
||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_acl_user_allow_write(pw->pw_uid);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
if (server_acl_user_find(pw->pw_uid) == NULL) {
|
||||
cmdq_error(item, "user %s not found", pw->pw_name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
server_acl_user_deny_write(pw->pw_uid);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
|
||||
.name = "set-buffer",
|
||||
.alias = "setb",
|
||||
|
||||
.args = { "ab:t:n:w", 0, 1 },
|
||||
.args = { "ab:t:n:w", 0, 1, NULL },
|
||||
.usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
|
||||
CMD_TARGET_CLIENT_USAGE " data",
|
||||
|
||||
@@ -45,7 +45,7 @@ const struct cmd_entry cmd_delete_buffer_entry = {
|
||||
.name = "delete-buffer",
|
||||
.alias = "deleteb",
|
||||
|
||||
.args = { "b:", 0, 0 },
|
||||
.args = { "b:", 0, 0, NULL },
|
||||
.usage = CMD_BUFFER_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
@@ -94,11 +94,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args->argc != 1) {
|
||||
if (args_count(args) != 1) {
|
||||
cmdq_error(item, "no data specified");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if ((newsize = strlen(args->argv[0])) == 0)
|
||||
if ((newsize = strlen(args_string(args, 0))) == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
bufsize = 0;
|
||||
@@ -111,7 +111,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
bufdata = xrealloc(bufdata, bufsize + newsize);
|
||||
memcpy(bufdata + bufsize, args->argv[0], newsize);
|
||||
memcpy(bufdata + bufsize, args_string(args, 0), newsize);
|
||||
bufsize += newsize;
|
||||
|
||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
.name = "set-environment",
|
||||
.alias = "setenv",
|
||||
|
||||
.args = { "Fhgrt:u", 1, 2 },
|
||||
.args = { "Fhgrt:u", 1, 2, NULL },
|
||||
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
@@ -49,11 +49,11 @@ cmd_set_environment_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 environ *env;
|
||||
const char *name, *value, *tflag;
|
||||
char *expand = NULL;
|
||||
const char *name = args_string(args, 0), *value;
|
||||
const char *tflag;
|
||||
char *expanded = NULL;
|
||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
||||
|
||||
name = args->argv[0];
|
||||
if (*name == '\0') {
|
||||
cmdq_error(item, "empty variable name");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -63,13 +63,14 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args->argc < 2)
|
||||
if (args_count(args) < 2)
|
||||
value = NULL;
|
||||
else if (args_has(args, 'F'))
|
||||
value = expand = format_single_from_target(item, args->argv[1]);
|
||||
else
|
||||
value = args->argv[1];
|
||||
|
||||
value = args_string(args, 1);
|
||||
if (value != NULL && args_has(args, 'F')) {
|
||||
expanded = format_single_from_target(item, value);
|
||||
value = expanded;
|
||||
}
|
||||
if (args_has(args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
@@ -113,6 +114,6 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
out:
|
||||
free(expand);
|
||||
free(expanded);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
@@ -27,13 +27,16 @@
|
||||
* Set an option.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmdq_item *);
|
||||
static enum args_parse_type cmd_set_option_args_parse(struct args *,
|
||||
u_int, char **);
|
||||
static enum cmd_retval cmd_set_option_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_set_option_entry = {
|
||||
.name = "set-option",
|
||||
.alias = "set",
|
||||
|
||||
.args = { "aFgopqst:uUw", 1, 2 },
|
||||
.args = { "aFgopqst:uUw", 1, 2, cmd_set_option_args_parse },
|
||||
.usage = "[-aFgopqsuUw] " CMD_TARGET_PANE_USAGE " option [value]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -46,7 +49,7 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
||||
.name = "set-window-option",
|
||||
.alias = "setw",
|
||||
|
||||
.args = { "aFgoqt:u", 1, 2 },
|
||||
.args = { "aFgoqt:u", 1, 2, cmd_set_option_args_parse },
|
||||
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
@@ -59,7 +62,7 @@ const struct cmd_entry cmd_set_hook_entry = {
|
||||
.name = "set-hook",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "agpRt:uw", 1, 2 },
|
||||
.args = { "agpRt:uw", 1, 2, cmd_set_option_args_parse },
|
||||
.usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -68,6 +71,15 @@ const struct cmd_entry cmd_set_hook_entry = {
|
||||
.exec = cmd_set_option_exec
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
cmd_set_option_args_parse(__unused struct args *args, u_int idx,
|
||||
__unused char **cause)
|
||||
{
|
||||
if (idx == 1)
|
||||
return (ARGS_PARSE_COMMANDS_OR_STRING);
|
||||
return (ARGS_PARSE_STRING);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -77,14 +89,16 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window_pane *loop;
|
||||
struct options *oo;
|
||||
struct options_entry *parent, *o, *po;
|
||||
char *name, *argument, *value = NULL, *cause;
|
||||
char *name, *argument, *expanded = NULL;
|
||||
char *cause;
|
||||
const char *value;
|
||||
int window, idx, already, error, ambiguous;
|
||||
int scope;
|
||||
|
||||
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
|
||||
|
||||
/* Expand argument. */
|
||||
argument = format_single_from_target(item, args->argv[0]);
|
||||
argument = format_single_from_target(item, args_string(args, 0));
|
||||
|
||||
/* If set-hook -R, fire the hook straight away. */
|
||||
if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) {
|
||||
@@ -104,12 +118,14 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "invalid option: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
if (args->argc < 2)
|
||||
if (args_count(args) < 2)
|
||||
value = NULL;
|
||||
else if (args_has(args, 'F'))
|
||||
value = format_single_from_target(item, args->argv[1]);
|
||||
else
|
||||
value = xstrdup(args->argv[1]);
|
||||
value = args_string(args, 1);
|
||||
if (value != NULL && args_has(args, 'F')) {
|
||||
expanded = format_single_from_target(item, value);
|
||||
value = expanded;
|
||||
}
|
||||
|
||||
/* Get the scope and table for the option .*/
|
||||
scope = options_scope_from_name(args, window, name, target, &oo,
|
||||
@@ -211,13 +227,13 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
out:
|
||||
free(argument);
|
||||
free(value);
|
||||
free(expanded);
|
||||
free(name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(argument);
|
||||
free(value);
|
||||
free(expanded);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_environment_entry = {
|
||||
.name = "show-environment",
|
||||
.alias = "showenv",
|
||||
|
||||
.args = { "hgst:", 0, 1 },
|
||||
.args = { "hgst:", 0, 1, NULL },
|
||||
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
@@ -101,7 +101,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct environ *env;
|
||||
struct environ_entry *envent;
|
||||
const char *tflag;
|
||||
const char *tflag, *name = args_string(args, 0);
|
||||
|
||||
if ((tflag = args_get(args, 't')) != NULL) {
|
||||
if (target->s == NULL) {
|
||||
@@ -124,10 +124,10 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
env = target->s->environ;
|
||||
}
|
||||
|
||||
if (args->argc != 0) {
|
||||
envent = environ_find(env, args->argv[0]);
|
||||
if (name != NULL) {
|
||||
envent = environ_find(env, name);
|
||||
if (envent == NULL) {
|
||||
cmdq_error(item, "unknown variable: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown variable: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmd_show_environment_print(self, item, envent);
|
||||
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_messages_entry = {
|
||||
.name = "show-messages",
|
||||
.alias = "showmsgs",
|
||||
|
||||
.args = { "JTt:", 0, 0 },
|
||||
.args = { "JTt:", 0, 0, NULL },
|
||||
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_options_entry = {
|
||||
.name = "show-options",
|
||||
.alias = "show",
|
||||
|
||||
.args = { "AgHpqst:vw", 0, 1 },
|
||||
.args = { "AgHpqst:vw", 0, 1, NULL },
|
||||
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -51,7 +51,7 @@ const struct cmd_entry cmd_show_window_options_entry = {
|
||||
.name = "show-window-options",
|
||||
.alias = "showw",
|
||||
|
||||
.args = { "gvt:", 0, 1 },
|
||||
.args = { "gvt:", 0, 1, NULL },
|
||||
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
@@ -64,7 +64,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
||||
.name = "show-hooks",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "gpt:w", 0, 1 },
|
||||
.args = { "gpt:w", 0, 1, NULL },
|
||||
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -85,7 +85,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
window = (cmd_get_entry(self) == &cmd_show_window_options_entry);
|
||||
|
||||
if (args->argc == 0) {
|
||||
if (args_count(args) == 0) {
|
||||
scope = options_scope_from_flags(args, window, target, &oo,
|
||||
&cause);
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
@@ -97,12 +97,12 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
return (cmd_show_options_all(self, item, scope, oo));
|
||||
}
|
||||
argument = format_single_from_target(item, args->argv[0]);
|
||||
argument = format_single_from_target(item, args_string(args, 0));
|
||||
|
||||
name = options_match(argument, &idx, &ambiguous);
|
||||
if (name == NULL) {
|
||||
if (args_has(args, 'q'))
|
||||
goto fail;
|
||||
goto out;
|
||||
if (ambiguous)
|
||||
cmdq_error(item, "ambiguous option: %s", argument);
|
||||
else
|
||||
@@ -113,7 +113,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
&cause);
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
if (args_has(args, 'q'))
|
||||
goto fail;
|
||||
goto out;
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
goto fail;
|
||||
@@ -126,7 +126,14 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
parent = 0;
|
||||
if (o != NULL)
|
||||
cmd_show_options_print(self, item, o, idx, parent);
|
||||
else if (*name == '@') {
|
||||
if (args_has(args, 'q'))
|
||||
goto out;
|
||||
cmdq_error(item, "invalid option: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
out:
|
||||
free(name);
|
||||
free(argument);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
108
cmd-show-prompt-history.c
Normal file
108
cmd-show-prompt-history.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Anindya Mukherjee <anindya49@hotmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Show or clear prompt history.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_show_prompt_history_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_show_prompt_history_entry = {
|
||||
.name = "show-prompt-history",
|
||||
.alias = "showphist",
|
||||
|
||||
.args = { "T:", 0, 0, NULL },
|
||||
.usage = "[-T type]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_prompt_history_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_clear_prompt_history_entry = {
|
||||
.name = "clear-prompt-history",
|
||||
.alias = "clearphist",
|
||||
|
||||
.args = { "T:", 0, 0, NULL },
|
||||
.usage = "[-T type]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_prompt_history_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_prompt_history_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *typestr = args_get(args, 'T');
|
||||
enum prompt_type type;
|
||||
u_int tidx, hidx;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_clear_prompt_history_entry) {
|
||||
if (typestr == NULL) {
|
||||
for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
|
||||
free(status_prompt_hlist[tidx]);
|
||||
status_prompt_hlist[tidx] = NULL;
|
||||
status_prompt_hsize[tidx] = 0;
|
||||
}
|
||||
} else {
|
||||
type = status_prompt_type(typestr);
|
||||
if (type == PROMPT_TYPE_INVALID) {
|
||||
cmdq_error(item, "invalid type: %s", typestr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(status_prompt_hlist[type]);
|
||||
status_prompt_hlist[type] = NULL;
|
||||
status_prompt_hsize[type] = 0;
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (typestr == NULL) {
|
||||
for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
|
||||
cmdq_print(item, "History for %s:\n",
|
||||
status_prompt_type_string(tidx));
|
||||
for (hidx = 0; hidx < status_prompt_hsize[tidx];
|
||||
hidx++) {
|
||||
cmdq_print(item, "%d: %s", hidx + 1,
|
||||
status_prompt_hlist[tidx][hidx]);
|
||||
}
|
||||
cmdq_print(item, "%s", "");
|
||||
}
|
||||
} else {
|
||||
type = status_prompt_type(typestr);
|
||||
if (type == PROMPT_TYPE_INVALID) {
|
||||
cmdq_error(item, "invalid type: %s", typestr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmdq_print(item, "History for %s:\n",
|
||||
status_prompt_type_string(type));
|
||||
for (hidx = 0; hidx < status_prompt_hsize[type]; hidx++) {
|
||||
cmdq_print(item, "%d: %s", hidx + 1,
|
||||
status_prompt_hlist[type][hidx]);
|
||||
}
|
||||
cmdq_print(item, "%s", "");
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_source_file_entry = {
|
||||
.name = "source-file",
|
||||
.alias = "source",
|
||||
|
||||
.args = { "Fnqv", 1, -1 },
|
||||
.args = { "Fnqv", 1, -1, NULL },
|
||||
.usage = "[-Fnqv] path ...",
|
||||
|
||||
.flags = 0,
|
||||
@@ -65,6 +65,7 @@ static void
|
||||
cmd_source_file_complete(struct client *c, struct cmd_source_file_data *cdata)
|
||||
{
|
||||
struct cmdq_item *new_item;
|
||||
u_int i;
|
||||
|
||||
if (cfg_finished) {
|
||||
if (cdata->retval == CMD_RETURN_ERROR &&
|
||||
@@ -75,6 +76,8 @@ cmd_source_file_complete(struct client *c, struct cmd_source_file_data *cdata)
|
||||
cmdq_insert_after(cdata->after, new_item);
|
||||
}
|
||||
|
||||
for (i = 0; i < cdata->nfiles; i++)
|
||||
free(cdata->files[i]);
|
||||
free(cdata->files);
|
||||
free(cdata);
|
||||
}
|
||||
@@ -128,11 +131,11 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_source_file_data *cdata;
|
||||
struct client *c = cmdq_get_client(item);
|
||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
||||
char *pattern, *cwd, *expand = NULL;
|
||||
char *pattern, *cwd, *expanded = NULL;
|
||||
const char *path, *error;
|
||||
glob_t g;
|
||||
int i, result;
|
||||
u_int j;
|
||||
int result;
|
||||
u_int i, j;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->item = item;
|
||||
@@ -146,13 +149,13 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
for (i = 0; i < args_count(args); i++) {
|
||||
path = args_string(args, i);
|
||||
if (args_has(args, 'F')) {
|
||||
free(expand);
|
||||
expand = format_single_from_target(item, args->argv[i]);
|
||||
path = expand;
|
||||
} else
|
||||
path = args->argv[i];
|
||||
free(expanded);
|
||||
expanded = format_single_from_target(item, path);
|
||||
path = expanded;
|
||||
}
|
||||
if (strcmp(path, "-") == 0) {
|
||||
cmd_source_file_add(cdata, "-");
|
||||
continue;
|
||||
@@ -176,15 +179,17 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "%s: %s", path, error);
|
||||
retval = CMD_RETURN_ERROR;
|
||||
}
|
||||
globfree(&g);
|
||||
free(pattern);
|
||||
continue;
|
||||
}
|
||||
free(expand);
|
||||
free(pattern);
|
||||
|
||||
for (j = 0; j < g.gl_pathc; j++)
|
||||
cmd_source_file_add(cdata, g.gl_pathv[j]);
|
||||
globfree(&g);
|
||||
}
|
||||
free(expanded);
|
||||
|
||||
cdata->after = item;
|
||||
cdata->retval = retval;
|
||||
|
||||
@@ -39,9 +39,10 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
.name = "split-window",
|
||||
.alias = "splitw",
|
||||
|
||||
.args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1 },
|
||||
.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 " [command]",
|
||||
"[-F format] [-l size] " CMD_TARGET_PANE_USAGE
|
||||
"[shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -55,19 +56,21 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *current = cmdq_get_current(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct spawn_context sc;
|
||||
struct spawn_context sc = { 0 };
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
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 cmd_find_state fs;
|
||||
int size, percentage, flags, input;
|
||||
const char *template, *add, *errstr, *p;
|
||||
const char *template, *errstr, *p;
|
||||
char *cause, *cp, *copy;
|
||||
size_t plen;
|
||||
struct args_value *value;
|
||||
struct args_value *av;
|
||||
u_int count = args_count(args);
|
||||
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
@@ -84,10 +87,17 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "percentage %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
if (args_has(args, 'f')) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (w->sy * percentage) / 100;
|
||||
else
|
||||
size = (w->sx * percentage) / 100;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
}
|
||||
} else {
|
||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
@@ -103,22 +113,29 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
if (args_has(args, 'f')) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (w->sy * percentage) / 100;
|
||||
else
|
||||
size = (w->sx * percentage) / 100;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
}
|
||||
} else
|
||||
size = -1;
|
||||
|
||||
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
|
||||
input = (args_has(args, 'I') && args->argc == 0);
|
||||
input = (args_has(args, 'I') && count == 0);
|
||||
|
||||
flags = 0;
|
||||
if (args_has(args, 'b'))
|
||||
flags |= SPAWN_BEFORE;
|
||||
if (args_has(args, 'f'))
|
||||
flags |= SPAWN_FULLSIZE;
|
||||
if (input || (args->argc == 1 && *args->argv[0] == '\0'))
|
||||
if (input || (count == 1 && *args_string(args, 0) == '\0'))
|
||||
flags |= SPAWN_EMPTY;
|
||||
|
||||
lc = layout_split_pane(wp, type, size, flags);
|
||||
@@ -127,7 +144,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
@@ -135,15 +151,13 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
sc.wp0 = wp;
|
||||
sc.lc = lc;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
args_to_vector(args, &sc.argc, &sc.argv);
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add, 0);
|
||||
add = args_next_value(&value);
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(sc.environ, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
|
||||
sc.idx = -1;
|
||||
@@ -158,15 +172,27 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((new_wp = spawn_pane(&sc, &cause)) == NULL) {
|
||||
cmdq_error(item, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (input && window_pane_start_input(new_wp, item, &cause) != 0) {
|
||||
server_client_remove_pane(new_wp);
|
||||
layout_close_pane(new_wp);
|
||||
window_remove_pane(wp->window, new_wp);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (input) {
|
||||
switch (window_pane_start_input(new_wp, item, &cause)) {
|
||||
case -1:
|
||||
server_client_remove_pane(new_wp);
|
||||
layout_close_pane(new_wp);
|
||||
window_remove_pane(wp->window, new_wp);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 1:
|
||||
input = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!args_has(args, 'd'))
|
||||
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
|
||||
@@ -185,6 +211,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-split-window");
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
environ_free(sc.environ);
|
||||
if (input)
|
||||
return (CMD_RETURN_WAIT);
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
||||
.name = "swap-pane",
|
||||
.alias = "swapp",
|
||||
|
||||
.args = { "dDs:t:UZ", 0, 0 },
|
||||
.args = { "dDs:t:UZ", 0, 0, NULL },
|
||||
.usage = "[-dDUZ] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
@@ -135,6 +135,9 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
server_redraw_window(src_w);
|
||||
server_redraw_window(dst_w);
|
||||
notify_window("window-layout-changed", src_w);
|
||||
if (src_w != dst_w)
|
||||
notify_window("window-layout-changed", dst_w);
|
||||
|
||||
out:
|
||||
if (window_pop_zoom(src_w))
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_swap_window_entry = {
|
||||
.name = "swap-window",
|
||||
.alias = "swapw",
|
||||
|
||||
.args = { "ds:t:", 0, 0 },
|
||||
.args = { "ds:t:", 0, 0, NULL },
|
||||
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
.name = "switch-client",
|
||||
.alias = "switchc",
|
||||
|
||||
.args = { "lc:EFnpt:rT:Z", 0, 0 },
|
||||
.args = { "lc:EFnpt:rT:Z", 0, 0, NULL },
|
||||
.usage = "[-ElnprZ] [-c target-client] [-t target-session] "
|
||||
"[-T key-table]",
|
||||
|
||||
@@ -134,23 +134,9 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!args_has(args, 'E'))
|
||||
environ_update(s->options, tc->environ, s->environ);
|
||||
|
||||
if (tc->session != NULL && tc->session != s)
|
||||
tc->last_session = tc->session;
|
||||
tc->session = s;
|
||||
server_client_set_session(tc, s);
|
||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||
server_client_set_key_table(tc, NULL);
|
||||
tty_update_client_offset(tc);
|
||||
status_timer_start(tc);
|
||||
notify_client("client-session-changed", tc);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
|
||||
server_check_unattached();
|
||||
server_redraw_client(tc);
|
||||
s->curw->flags &= ~WINLINK_ALERTFLAGS;
|
||||
s->curw->window->latest = tc;
|
||||
recalculate_sizes();
|
||||
alerts_check_session(s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_unbind_key_entry = {
|
||||
.name = "unbind-key",
|
||||
.alias = "unbind",
|
||||
|
||||
.args = { "anqT:", 0, 1 },
|
||||
.args = { "anqT:", 0, 1, NULL },
|
||||
.usage = "[-anq] [-T key-table] key",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
@@ -44,11 +44,11 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
key_code key;
|
||||
const char *tablename;
|
||||
const char *tablename, *keystr = args_string(args, 0);
|
||||
int quiet = args_has(args, 'q');
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
if (args->argc != 0) {
|
||||
if (keystr != NULL) {
|
||||
if (!quiet)
|
||||
cmdq_error(item, "key given with -a");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -73,16 +73,16 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args->argc != 1) {
|
||||
if (keystr == NULL) {
|
||||
if (!quiet)
|
||||
cmdq_error(item, "missing key");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
key = key_string_lookup_string(keystr);
|
||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||
if (!quiet)
|
||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", keystr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_wait_for_entry = {
|
||||
.name = "wait-for",
|
||||
.alias = "wait",
|
||||
|
||||
.args = { "LSU", 1, 1 },
|
||||
.args = { "LSU", 1, 1, NULL },
|
||||
.usage = "[-L|-S|-U] channel",
|
||||
|
||||
.flags = 0,
|
||||
@@ -121,11 +121,11 @@ static enum cmd_retval
|
||||
cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const char *name = args->argv[0];
|
||||
struct wait_channel *wc, wc0;
|
||||
const char *name = args_string(args, 0);
|
||||
struct wait_channel *wc, find;
|
||||
|
||||
wc0.name = name;
|
||||
wc = RB_FIND(wait_channels, &wait_channels, &wc0);
|
||||
find.name = name;
|
||||
wc = RB_FIND(wait_channels, &wait_channels, &find);
|
||||
|
||||
if (args_has(args, 'S'))
|
||||
return (cmd_wait_for_signal(item, name, wc));
|
||||
|
||||
117
cmd.c
117
cmd.c
@@ -35,6 +35,7 @@ extern const struct cmd_entry cmd_choose_buffer_entry;
|
||||
extern const struct cmd_entry cmd_choose_client_entry;
|
||||
extern const struct cmd_entry cmd_choose_tree_entry;
|
||||
extern const struct cmd_entry cmd_clear_history_entry;
|
||||
extern const struct cmd_entry cmd_clear_prompt_history_entry;
|
||||
extern const struct cmd_entry cmd_clock_mode_entry;
|
||||
extern const struct cmd_entry cmd_command_prompt_entry;
|
||||
extern const struct cmd_entry cmd_confirm_before_entry;
|
||||
@@ -94,6 +95,7 @@ extern const struct cmd_entry cmd_select_pane_entry;
|
||||
extern const struct cmd_entry cmd_select_window_entry;
|
||||
extern const struct cmd_entry cmd_send_keys_entry;
|
||||
extern const struct cmd_entry cmd_send_prefix_entry;
|
||||
extern const struct cmd_entry cmd_server_access_entry;
|
||||
extern const struct cmd_entry cmd_set_buffer_entry;
|
||||
extern const struct cmd_entry cmd_set_environment_entry;
|
||||
extern const struct cmd_entry cmd_set_hook_entry;
|
||||
@@ -104,6 +106,7 @@ extern const struct cmd_entry cmd_show_environment_entry;
|
||||
extern const struct cmd_entry cmd_show_hooks_entry;
|
||||
extern const struct cmd_entry cmd_show_messages_entry;
|
||||
extern const struct cmd_entry cmd_show_options_entry;
|
||||
extern const struct cmd_entry cmd_show_prompt_history_entry;
|
||||
extern const struct cmd_entry cmd_show_window_options_entry;
|
||||
extern const struct cmd_entry cmd_source_file_entry;
|
||||
extern const struct cmd_entry cmd_split_window_entry;
|
||||
@@ -126,6 +129,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_choose_client_entry,
|
||||
&cmd_choose_tree_entry,
|
||||
&cmd_clear_history_entry,
|
||||
&cmd_clear_prompt_history_entry,
|
||||
&cmd_clock_mode_entry,
|
||||
&cmd_command_prompt_entry,
|
||||
&cmd_confirm_before_entry,
|
||||
@@ -184,6 +188,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_select_window_entry,
|
||||
&cmd_send_keys_entry,
|
||||
&cmd_send_prefix_entry,
|
||||
&cmd_server_access_entry,
|
||||
&cmd_set_buffer_entry,
|
||||
&cmd_set_environment_entry,
|
||||
&cmd_set_hook_entry,
|
||||
@@ -194,6 +199,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_show_hooks_entry,
|
||||
&cmd_show_messages_entry,
|
||||
&cmd_show_options_entry,
|
||||
&cmd_show_prompt_history_entry,
|
||||
&cmd_show_window_options_entry,
|
||||
&cmd_source_file_entry,
|
||||
&cmd_split_window_entry,
|
||||
@@ -217,10 +223,6 @@ struct cmd {
|
||||
char *file;
|
||||
u_int line;
|
||||
|
||||
char *alias;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
TAILQ_HEAD(cmds, cmd);
|
||||
@@ -247,7 +249,7 @@ cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
|
||||
/* Prepend to an argument vector. */
|
||||
void
|
||||
cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
cmd_prepend_argv(int *argc, char ***argv, const char *arg)
|
||||
{
|
||||
char **new_argv;
|
||||
int i;
|
||||
@@ -264,7 +266,7 @@ cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
|
||||
/* Append to an argument vector. */
|
||||
void
|
||||
cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
cmd_append_argv(int *argc, char ***argv, const char *arg)
|
||||
{
|
||||
*argv = xreallocarray(*argv, (*argc) + 1, sizeof **argv);
|
||||
(*argv)[(*argc)++] = xstrdup(arg);
|
||||
@@ -495,31 +497,32 @@ ambiguous:
|
||||
|
||||
/* Parse a single command from an argument vector. */
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
|
||||
char **cause)
|
||||
{
|
||||
const struct cmd_entry *entry;
|
||||
const char *name;
|
||||
struct cmd *cmd;
|
||||
struct args *args;
|
||||
char *error = NULL;
|
||||
|
||||
if (argc == 0) {
|
||||
if (count == 0 || values[0].type != ARGS_STRING) {
|
||||
xasprintf(cause, "no command");
|
||||
return (NULL);
|
||||
}
|
||||
name = argv[0];
|
||||
|
||||
entry = cmd_find(name, cause);
|
||||
entry = cmd_find(values[0].string, cause);
|
||||
if (entry == NULL)
|
||||
return (NULL);
|
||||
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
||||
|
||||
args = args_parse(entry->args.template, argc, argv);
|
||||
if (args == NULL)
|
||||
goto usage;
|
||||
if (entry->args.lower != -1 && args->argc < entry->args.lower)
|
||||
goto usage;
|
||||
if (entry->args.upper != -1 && args->argc > entry->args.upper)
|
||||
goto usage;
|
||||
args = args_parse(&entry->args, values, count, &error);
|
||||
if (args == NULL && error == NULL) {
|
||||
xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
|
||||
return (NULL);
|
||||
}
|
||||
if (args == NULL) {
|
||||
xasprintf(cause, "command %s: %s", entry->name, error);
|
||||
free(error);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->entry = entry;
|
||||
@@ -529,32 +532,36 @@ cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
cmd->file = xstrdup(file);
|
||||
cmd->line = line;
|
||||
|
||||
cmd->alias = NULL;
|
||||
cmd->argc = argc;
|
||||
cmd->argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
return (cmd);
|
||||
|
||||
usage:
|
||||
if (args != NULL)
|
||||
args_free(args);
|
||||
xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Free a command. */
|
||||
void
|
||||
cmd_free(struct cmd *cmd)
|
||||
{
|
||||
free(cmd->alias);
|
||||
cmd_free_argv(cmd->argc, cmd->argv);
|
||||
|
||||
free(cmd->file);
|
||||
|
||||
args_free(cmd->args);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
/* Copy a command. */
|
||||
struct cmd *
|
||||
cmd_copy(struct cmd *cmd, int argc, char **argv)
|
||||
{
|
||||
struct cmd *new_cmd;
|
||||
|
||||
new_cmd = xcalloc(1, sizeof *new_cmd);
|
||||
new_cmd->entry = cmd->entry;
|
||||
new_cmd->args = args_copy(cmd->args, argc, argv);
|
||||
|
||||
if (cmd->file != NULL)
|
||||
new_cmd->file = xstrdup(cmd->file);
|
||||
new_cmd->line = cmd->line;
|
||||
|
||||
return (new_cmd);
|
||||
}
|
||||
|
||||
/* Get a command as a string. */
|
||||
char *
|
||||
cmd_print(struct cmd *cmd)
|
||||
@@ -593,7 +600,18 @@ cmd_list_append(struct cmd_list *cmdlist, struct cmd *cmd)
|
||||
TAILQ_INSERT_TAIL(cmdlist->list, cmd, qentry);
|
||||
}
|
||||
|
||||
/* Move all commands from one command list to another */
|
||||
/* Append all commands from one list to another. */
|
||||
void
|
||||
cmd_list_append_all(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
|
||||
TAILQ_FOREACH(cmd, from->list, qentry)
|
||||
cmd->group = cmdlist->group;
|
||||
TAILQ_CONCAT(cmdlist->list, from->list, qentry);
|
||||
}
|
||||
|
||||
/* Move all commands from one command list to another. */
|
||||
void
|
||||
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||
{
|
||||
@@ -618,6 +636,37 @@ cmd_list_free(struct cmd_list *cmdlist)
|
||||
free(cmdlist);
|
||||
}
|
||||
|
||||
/* Copy a command list, expanding %s in arguments. */
|
||||
struct cmd_list *
|
||||
cmd_list_copy(struct cmd_list *cmdlist, int argc, char **argv)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *new_cmdlist;
|
||||
struct cmd *new_cmd;
|
||||
u_int group = cmdlist->group;
|
||||
char *s;
|
||||
|
||||
s = cmd_list_print(cmdlist, 0);
|
||||
log_debug("%s: %s", __func__, s);
|
||||
free(s);
|
||||
|
||||
new_cmdlist = cmd_list_new();
|
||||
TAILQ_FOREACH(cmd, cmdlist->list, qentry) {
|
||||
if (cmd->group != group) {
|
||||
new_cmdlist->group = cmd_list_next_group++;
|
||||
group = cmd->group;
|
||||
}
|
||||
new_cmd = cmd_copy(cmd, argc, argv);
|
||||
cmd_list_append(new_cmdlist, new_cmd);
|
||||
}
|
||||
|
||||
s = cmd_list_print(new_cmdlist, 0);
|
||||
log_debug("%s: %s", __func__, s);
|
||||
free(s);
|
||||
|
||||
return (new_cmdlist);
|
||||
}
|
||||
|
||||
/* Get a command list as a string. */
|
||||
char *
|
||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
|
||||
129
colour.c
129
colour.c
@@ -105,6 +105,21 @@ colour_split_rgb(int c, u_char *r, u_char *g, u_char *b)
|
||||
*b = c & 0xff;
|
||||
}
|
||||
|
||||
/* Force colour to RGB if not already. */
|
||||
int
|
||||
colour_force_rgb(int c)
|
||||
{
|
||||
if (c & COLOUR_FLAG_RGB)
|
||||
return (c);
|
||||
if (c & COLOUR_FLAG_256)
|
||||
return (colour_256toRGB(c));
|
||||
if (c >= 0 && c <= 7)
|
||||
return (colour_256toRGB(c));
|
||||
if (c >= 90 && c <= 97)
|
||||
return (colour_256toRGB(8 + c - 90));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Convert colour to a string. */
|
||||
const char *
|
||||
colour_tostring(int c)
|
||||
@@ -113,7 +128,7 @@ colour_tostring(int c)
|
||||
u_char r, g, b;
|
||||
|
||||
if (c == -1)
|
||||
return ("invalid");
|
||||
return ("none");
|
||||
|
||||
if (c & COLOUR_FLAG_RGB) {
|
||||
colour_split_rgb(c, &r, &g, &b);
|
||||
@@ -944,3 +959,115 @@ colour_byname(const char *name)
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Initialize palette. */
|
||||
void
|
||||
colour_palette_init(struct colour_palette *p)
|
||||
{
|
||||
p->fg = 8;
|
||||
p->bg = 8;
|
||||
p->palette = NULL;
|
||||
p->default_palette = NULL;
|
||||
}
|
||||
|
||||
/* Clear palette. */
|
||||
void
|
||||
colour_palette_clear(struct colour_palette *p)
|
||||
{
|
||||
if (p != NULL) {
|
||||
p->fg = 8;
|
||||
p->bg = 8;
|
||||
free(p->palette);
|
||||
p->palette = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Free a palette. */
|
||||
void
|
||||
colour_palette_free(struct colour_palette *p)
|
||||
{
|
||||
if (p != NULL) {
|
||||
free(p->palette);
|
||||
p->palette = NULL;
|
||||
free(p->default_palette);
|
||||
p->default_palette = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get a colour from a palette. */
|
||||
int
|
||||
colour_palette_get(struct colour_palette *p, int c)
|
||||
{
|
||||
if (p == NULL)
|
||||
return (-1);
|
||||
|
||||
if (c >= 90 && c <= 97)
|
||||
c = 8 + c - 90;
|
||||
else if (c & COLOUR_FLAG_256)
|
||||
c &= ~COLOUR_FLAG_256;
|
||||
else if (c >= 8)
|
||||
return (-1);
|
||||
|
||||
if (p->palette != NULL && p->palette[c] != -1)
|
||||
return (p->palette[c]);
|
||||
if (p->default_palette != NULL && p->default_palette[c] != -1)
|
||||
return (p->default_palette[c]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Set a colour in a palette. */
|
||||
int
|
||||
colour_palette_set(struct colour_palette *p, int n, int c)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
if (p == NULL || n > 255)
|
||||
return (0);
|
||||
|
||||
if (c == -1 && p->palette == NULL)
|
||||
return (0);
|
||||
|
||||
if (c != -1 && p->palette == NULL) {
|
||||
if (p->palette == NULL)
|
||||
p->palette = xcalloc(256, sizeof *p->palette);
|
||||
for (i = 0; i < 256; i++)
|
||||
p->palette[i] = -1;
|
||||
}
|
||||
p->palette[n] = c;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Build palette defaults from an option. */
|
||||
void
|
||||
colour_palette_from_option(struct colour_palette *p, struct options *oo)
|
||||
{
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
u_int i, n;
|
||||
int c;
|
||||
|
||||
if (p == NULL)
|
||||
return;
|
||||
|
||||
o = options_get(oo, "pane-colours");
|
||||
if ((a = options_array_first(o)) == NULL) {
|
||||
if (p->default_palette != NULL) {
|
||||
free(p->default_palette);
|
||||
p->default_palette = NULL;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (p->default_palette == NULL)
|
||||
p->default_palette = xcalloc(256, sizeof *p->default_palette);
|
||||
for (i = 0; i < 256; i++)
|
||||
p->default_palette[i] = -1;
|
||||
while (a != NULL) {
|
||||
n = options_array_item_index(a);
|
||||
if (n < 256) {
|
||||
c = options_array_item_value(a)->number;
|
||||
p->default_palette[n] = c;
|
||||
}
|
||||
a = options_array_next(a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10
compat.h
10
compat.h
@@ -334,6 +334,11 @@ char *strndup(const char *, size_t);
|
||||
void *memmem(const void *, size_t, const void *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETPEEREID
|
||||
/* getpeereid.c */
|
||||
int getpeereid(int, uid_t *, gid_t *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
/* daemon.c */
|
||||
int daemon(int, int);
|
||||
@@ -416,6 +421,11 @@ void *reallocarray(void *, size_t, size_t);
|
||||
void *recallocarray(void *, size_t, size_t, size_t);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
/* systemd.c */
|
||||
int systemd_create_socket(int, char **);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTF8PROC
|
||||
/* utf8proc.c */
|
||||
int utf8proc_wcwidth(wchar_t);
|
||||
|
||||
58
compat/getpeereid.c
Normal file
58
compat/getpeereid.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_UCRED_H
|
||||
#include <ucred.h>
|
||||
#endif
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
{
|
||||
#ifdef HAVE_SO_PEERCRED
|
||||
struct ucred uc;
|
||||
int len = sizeof uc;
|
||||
|
||||
if (getsockopt(s, SOL_SOCKET, SO_PEERCRED, &uc, &len) == -1)
|
||||
return (-1);
|
||||
*uid = uc.uid;
|
||||
*gid = uc.gid;
|
||||
return (0);
|
||||
#elif defined(HAVE_GETPEERUCRED)
|
||||
int
|
||||
getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
{
|
||||
ucred_t *ucred = NULL;
|
||||
|
||||
if (getpeerucred(s, &ucred) == -1)
|
||||
return (-1);
|
||||
if ((*uid = ucred_geteuid(ucred)) == -1)
|
||||
return (-1);
|
||||
if ((*gid = ucred_getrgid(ucred)) == -1)
|
||||
return (-1);
|
||||
ucred_free(ucred);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
return (getuid());
|
||||
#endif
|
||||
}
|
||||
58
compat/systemd.c
Normal file
58
compat/systemd.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2022 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include <systemd/sd-daemon.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
int
|
||||
systemd_create_socket(int flags, char **cause)
|
||||
{
|
||||
int fds;
|
||||
int fd;
|
||||
struct sockaddr_un sa;
|
||||
int addrlen = sizeof sa;
|
||||
|
||||
fds = sd_listen_fds(0);
|
||||
if (fds > 1) { /* too many file descriptors */
|
||||
errno = E2BIG;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (fds == 1) { /* socket-activated */
|
||||
fd = SD_LISTEN_FDS_START;
|
||||
if (!sd_is_socket_unix(fd, SOCK_STREAM, 1, NULL, 0)) {
|
||||
errno = EPFNOSUPPORT;
|
||||
goto fail;
|
||||
}
|
||||
if (getsockname(fd, (struct sockaddr *)&sa, &addrlen) == -1)
|
||||
goto fail;
|
||||
socket_path = xstrdup(sa.sun_path);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
return (server_create_socket(flags, cause));
|
||||
|
||||
fail:
|
||||
if (cause != NULL)
|
||||
xasprintf(cause, "systemd socket error (%s)", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
201
configure.ac
201
configure.ac
@@ -1,6 +1,6 @@
|
||||
# configure.ac
|
||||
|
||||
AC_INIT([tmux], 3.2a)
|
||||
AC_INIT([tmux], 3.3)
|
||||
AC_PREREQ([2.60])
|
||||
|
||||
AC_CONFIG_AUX_DIR(etc)
|
||||
@@ -24,11 +24,11 @@ SAVED_LDFLAGS="$LDFLAGS"
|
||||
# Is this oss-fuzz build?
|
||||
AC_ARG_ENABLE(
|
||||
fuzzing,
|
||||
AC_HELP_STRING(--enable-fuzzing, build fuzzers)
|
||||
AS_HELP_STRING(--enable-fuzzing, build fuzzers)
|
||||
)
|
||||
AC_ARG_VAR(
|
||||
FUZZING_LIBS,
|
||||
AC_HELP_STRING(libraries to link fuzzing targets with)
|
||||
AS_HELP_STRING(libraries to link fuzzing targets with)
|
||||
)
|
||||
|
||||
# Set up convenient fuzzing defaults before initializing compiler.
|
||||
@@ -59,21 +59,41 @@ test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
||||
case "x$VERSION" in xnext*) enable_debug=yes;; esac
|
||||
AC_ARG_ENABLE(
|
||||
debug,
|
||||
AC_HELP_STRING(--enable-debug, enable debug build flags),
|
||||
AS_HELP_STRING(--enable-debug, enable debug build flags),
|
||||
)
|
||||
AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
|
||||
|
||||
# Is this a static build?
|
||||
AC_ARG_ENABLE(
|
||||
static,
|
||||
AC_HELP_STRING(--enable-static, create a static build)
|
||||
AS_HELP_STRING(--enable-static, create a static build)
|
||||
)
|
||||
if test "x$enable_static" = xyes; then
|
||||
case "$host_os" in
|
||||
*darwin*)
|
||||
AC_MSG_ERROR([static linking is not supported on macOS])
|
||||
;;
|
||||
esac
|
||||
test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static"
|
||||
AM_LDFLAGS="-static $AM_LDFLAGS"
|
||||
LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
|
||||
fi
|
||||
|
||||
# Allow default TERM to be set.
|
||||
AC_ARG_WITH(
|
||||
TERM,
|
||||
AS_HELP_STRING(--with-TERM, set default TERM),
|
||||
[DEFAULT_TERM=$withval],
|
||||
[DEFAULT_TERM=]
|
||||
)
|
||||
case "x$DEFAULT_TERM" in
|
||||
xscreen*|xtmux*|x)
|
||||
;;
|
||||
*)
|
||||
AC_MSG_ERROR("unsuitable TERM (must be screen* or tmux*)")
|
||||
;;
|
||||
esac
|
||||
|
||||
# Do we need fuzzers?
|
||||
AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
|
||||
|
||||
@@ -108,6 +128,7 @@ AC_CHECK_HEADERS([ \
|
||||
sys/dir.h \
|
||||
sys/ndir.h \
|
||||
sys/tree.h \
|
||||
ucred.h \
|
||||
util.h \
|
||||
])
|
||||
|
||||
@@ -126,7 +147,8 @@ AC_CHECK_FUNCS([ \
|
||||
flock \
|
||||
prctl \
|
||||
proc_pidinfo \
|
||||
sysconf
|
||||
getpeerucred \
|
||||
sysconf \
|
||||
])
|
||||
|
||||
# Check for functions with a compatibility implementation.
|
||||
@@ -140,6 +162,7 @@ AC_REPLACE_FUNCS([ \
|
||||
freezero \
|
||||
getdtablecount \
|
||||
getdtablesize \
|
||||
getpeereid \
|
||||
getline \
|
||||
getprogname \
|
||||
memmem \
|
||||
@@ -156,11 +179,12 @@ AC_FUNC_STRNLEN
|
||||
# Check if strtonum works.
|
||||
AC_MSG_CHECKING([for working strtonum])
|
||||
AC_RUN_IFELSE([AC_LANG_PROGRAM(
|
||||
[#include <stdlib.h>],
|
||||
[return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
|
||||
)],
|
||||
[AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
|
||||
[AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
|
||||
[#include <stdlib.h>],
|
||||
[return (strtonum("0", 0, 1, NULL) == 0 ? 0 : 1);]
|
||||
)],
|
||||
[AC_DEFINE(HAVE_STRTONUM) AC_MSG_RESULT(yes)],
|
||||
[AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)],
|
||||
[AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
|
||||
)
|
||||
|
||||
# Clang sanitizers wrap reallocarray even if it isn't available on the target
|
||||
@@ -298,6 +322,7 @@ if test "x$found_ncurses" = xno; then
|
||||
fi
|
||||
fi
|
||||
if test "x$found_ncurses" = xyes; then
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
|
||||
AC_DEFINE(HAVE_NCURSES_H)
|
||||
else
|
||||
AC_CHECK_LIB(
|
||||
@@ -313,6 +338,7 @@ else
|
||||
)
|
||||
if test "x$found_curses" = xyes; then
|
||||
LIBS="$LIBS -lcurses"
|
||||
CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
|
||||
AC_DEFINE(HAVE_CURSES_H)
|
||||
else
|
||||
AC_MSG_ERROR("curses not found")
|
||||
@@ -322,7 +348,7 @@ fi
|
||||
# Look for utempter.
|
||||
AC_ARG_ENABLE(
|
||||
utempter,
|
||||
AC_HELP_STRING(--enable-utempter, use utempter if it is installed)
|
||||
AS_HELP_STRING(--enable-utempter, use utempter if it is installed)
|
||||
)
|
||||
if test "x$enable_utempter" = xyes; then
|
||||
AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
|
||||
@@ -344,7 +370,7 @@ fi
|
||||
# Look for utf8proc.
|
||||
AC_ARG_ENABLE(
|
||||
utf8proc,
|
||||
AC_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
|
||||
AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
|
||||
)
|
||||
if test "x$enable_utf8proc" = xyes; then
|
||||
AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
|
||||
@@ -364,15 +390,42 @@ if test "x$enable_utf8proc" = xyes; then
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
|
||||
|
||||
# Check for systemd support.
|
||||
AC_ARG_ENABLE(
|
||||
systemd,
|
||||
AS_HELP_STRING(--enable-systemd, enable systemd integration)
|
||||
)
|
||||
if test x"$enable_systemd" = xyes; then
|
||||
PKG_CHECK_MODULES(
|
||||
SYSTEMD,
|
||||
libsystemd,
|
||||
[
|
||||
AM_CPPFLAGS="$SYSTEMD_CFLAGS $AM_CPPFLAGS"
|
||||
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
|
||||
LIBS="$SYSTEMD_LIBS $LIBS"
|
||||
found_systemd=yes
|
||||
],
|
||||
found_systemd=no
|
||||
)
|
||||
if test "x$found_systemd" = xyes; then
|
||||
AC_DEFINE(HAVE_SYSTEMD)
|
||||
else
|
||||
AC_MSG_ERROR("systemd not found")
|
||||
fi
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_SYSTEMD, [test "x$found_systemd" = xyes])
|
||||
|
||||
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
|
||||
AC_MSG_CHECKING(for b64_ntop)
|
||||
AC_TRY_LINK(
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
],
|
||||
[b64_ntop(NULL, 0, NULL, 0);],
|
||||
[
|
||||
b64_ntop(NULL, 0, NULL, 0);
|
||||
])],
|
||||
found_b64_ntop=yes,
|
||||
found_b64_ntop=no
|
||||
)
|
||||
@@ -381,13 +434,15 @@ OLD_LIBS="$LIBS"
|
||||
if test "x$found_b64_ntop" = xno; then
|
||||
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
||||
LIBS="$OLD_LIBS -lresolv"
|
||||
AC_TRY_LINK(
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
],
|
||||
[b64_ntop(NULL, 0, NULL, 0);],
|
||||
[
|
||||
b64_ntop(NULL, 0, NULL, 0);
|
||||
])],
|
||||
found_b64_ntop=yes,
|
||||
found_b64_ntop=no
|
||||
)
|
||||
@@ -396,13 +451,15 @@ fi
|
||||
if test "x$found_b64_ntop" = xno; then
|
||||
AC_MSG_CHECKING(for b64_ntop with -lnetwork)
|
||||
LIBS="$OLD_LIBS -lnetwork"
|
||||
AC_TRY_LINK(
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <resolv.h>
|
||||
],
|
||||
[b64_ntop(NULL, 0, NULL, 0);],
|
||||
[
|
||||
b64_ntop(NULL, 0, NULL, 0);
|
||||
])],
|
||||
found_b64_ntop=yes,
|
||||
found_b64_ntop=no
|
||||
)
|
||||
@@ -599,7 +656,7 @@ AC_CHECK_DECL(
|
||||
)
|
||||
AC_CHECK_DECL(
|
||||
TAILQ_PREV,
|
||||
found_queue_h=yes,
|
||||
,
|
||||
found_queue_h=no,
|
||||
[#include <sys/queue.h>]
|
||||
)
|
||||
@@ -655,6 +712,14 @@ AC_CHECK_DECL(
|
||||
[#include <sys/prctl.h>]
|
||||
)
|
||||
|
||||
# Look for setsockopt(SO_PEERCRED).
|
||||
AC_CHECK_DECL(
|
||||
SO_PEERCRED,
|
||||
AC_DEFINE(HAVE_SO_PEERCRED),
|
||||
,
|
||||
[#include <sys/socket.h>]
|
||||
)
|
||||
|
||||
# Look for fcntl(F_CLOSEM).
|
||||
AC_CHECK_DECL(
|
||||
F_CLOSEM,
|
||||
@@ -672,6 +737,74 @@ else
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
|
||||
# Try to figure out what the best value for TERM might be.
|
||||
if test "x$DEFAULT_TERM" = x; then
|
||||
DEFAULT_TERM=screen
|
||||
AC_MSG_CHECKING(TERM)
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(HAVE_CURSES_H)
|
||||
#include <curses.h>
|
||||
#elif defined(HAVE_NCURSES_H)
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <term.h>
|
||||
int main(void) {
|
||||
if (setupterm("screen-256color", -1, NULL) != OK)
|
||||
exit(1);
|
||||
exit(0);
|
||||
}
|
||||
])],
|
||||
[DEFAULT_TERM=screen-256color],
|
||||
,
|
||||
[DEFAULT_TERM=screen]
|
||||
)
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(HAVE_CURSES_H)
|
||||
#include <curses.h>
|
||||
#elif defined(HAVE_NCURSES_H)
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <term.h>
|
||||
int main(void) {
|
||||
if (setupterm("tmux", -1, NULL) != OK)
|
||||
exit(1);
|
||||
exit(0);
|
||||
}
|
||||
])],
|
||||
[DEFAULT_TERM=tmux],
|
||||
,
|
||||
[DEFAULT_TERM=screen]
|
||||
)
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE(
|
||||
[
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if defined(HAVE_CURSES_H)
|
||||
#include <curses.h>
|
||||
#elif defined(HAVE_NCURSES_H)
|
||||
#include <ncurses.h>
|
||||
#endif
|
||||
#include <term.h>
|
||||
int main(void) {
|
||||
if (setupterm("tmux-256color", -1, NULL) != OK)
|
||||
exit(1);
|
||||
exit(0);
|
||||
}
|
||||
])],
|
||||
[DEFAULT_TERM=tmux-256color],
|
||||
,
|
||||
[DEFAULT_TERM=screen]
|
||||
)
|
||||
AC_MSG_RESULT($DEFAULT_TERM)
|
||||
fi
|
||||
AC_SUBST(DEFAULT_TERM)
|
||||
|
||||
# Man page defaults to mdoc.
|
||||
MANFORMAT=mdoc
|
||||
AC_SUBST(MANFORMAT)
|
||||
@@ -687,19 +820,32 @@ case "$host_os" in
|
||||
AC_MSG_RESULT(darwin)
|
||||
PLATFORM=darwin
|
||||
#
|
||||
# OS X uses __dead2 instead of __dead, like FreeBSD. But it
|
||||
# defines __dead away so it needs to be removed before we can
|
||||
# replace it.
|
||||
# macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
|
||||
# __dead away so it needs to be removed before we can replace it.
|
||||
#
|
||||
AC_DEFINE(BROKEN___DEAD)
|
||||
#
|
||||
# OS X CMSG_FIRSTHDR is broken, so redefine it with a working
|
||||
# one. daemon works but has some stupid side effects, so use
|
||||
# our internal version which has a workaround.
|
||||
# macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
|
||||
# daemon works but has some stupid side effects, so use our internal
|
||||
# version which has a workaround.
|
||||
#
|
||||
AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
|
||||
AC_LIBOBJ(daemon)
|
||||
AC_LIBOBJ(daemon-darwin)
|
||||
#
|
||||
# macOS wcwidth(3) is bad, so complain and suggest using utf8proc
|
||||
# instead.
|
||||
#
|
||||
if test "x$enable_utf8proc" = x; then
|
||||
AC_MSG_NOTICE([])
|
||||
AC_MSG_NOTICE([ macOS library support for Unicode is very poor,])
|
||||
AC_MSG_NOTICE([ particularly for complex codepoints like emojis;])
|
||||
AC_MSG_NOTICE([ to use these correctly, configuring with])
|
||||
AC_MSG_NOTICE([ --enable-utf8proc is recommended. To build])
|
||||
AC_MSG_NOTICE([ without anyway, use --disable-utf8proc])
|
||||
AC_MSG_NOTICE([])
|
||||
AC_MSG_ERROR([must give --enable-utf8proc or --disable-utf8proc])
|
||||
fi
|
||||
;;
|
||||
*dragonfly*)
|
||||
AC_MSG_RESULT(dragonfly)
|
||||
@@ -779,4 +925,5 @@ AC_SUBST(AM_LDFLAGS)
|
||||
LDFLAGS="$SAVED_LDFLAGS"
|
||||
|
||||
# autoconf should create a Makefile.
|
||||
AC_OUTPUT(Makefile)
|
||||
AC_CONFIG_FILES(Makefile)
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -385,7 +385,7 @@ control_pause_pane(struct client *c, struct window_pane *wp)
|
||||
}
|
||||
|
||||
/* Write a line. */
|
||||
static void
|
||||
static void printflike(2, 0)
|
||||
control_vwrite(struct client *c, const char *fmt, va_list ap)
|
||||
{
|
||||
struct control_state *cs = c->control_state;
|
||||
@@ -664,7 +664,7 @@ control_write_pending(struct client *c, struct control_pane *cp, size_t limit)
|
||||
uint64_t age, t = get_timer();
|
||||
|
||||
wp = control_window_pane(c, cp->pane);
|
||||
if (wp == NULL) {
|
||||
if (wp == NULL || wp->fd == -1) {
|
||||
TAILQ_FOREACH_SAFE(cb, &cp->blocks, entry, cb1) {
|
||||
TAILQ_REMOVE(&cp->blocks, cb, entry);
|
||||
control_free_block(cs, cb);
|
||||
@@ -864,7 +864,7 @@ control_check_subs_pane(struct client *c, struct control_sub *csub)
|
||||
struct control_sub_pane *csp, find;
|
||||
|
||||
wp = window_pane_find_by_id(csub->id);
|
||||
if (wp == NULL)
|
||||
if (wp == NULL || wp->fd == -1)
|
||||
return;
|
||||
w = wp->window;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ bind y set synchronize-panes\; display 'synchronize-panes #{?synchronize-panes,o
|
||||
# should be started with "tmux attach" rather than "tmux new"
|
||||
new -d -s0 -nirssi 'exec irssi'
|
||||
set -t0:0 monitor-activity on
|
||||
set -t0:0 aggressive-resize on
|
||||
set -t0:0 aggressive-resize on
|
||||
neww -d -ntodo 'exec emacs ~/TODO'
|
||||
setw -t0:1 aggressive-resize on
|
||||
neww -d -nmutt 'exec mutt'
|
||||
|
||||
4
file.c
4
file.c
@@ -555,7 +555,7 @@ file_write_open(struct client_files *files, struct tmuxpeer *peer,
|
||||
log_debug("open write file %d %s", msg->stream, path);
|
||||
|
||||
find.stream = msg->stream;
|
||||
if ((cf = RB_FIND(client_files, files, &find)) != NULL) {
|
||||
if (RB_FIND(client_files, files, &find) != NULL) {
|
||||
error = EBADF;
|
||||
goto reply;
|
||||
}
|
||||
@@ -714,7 +714,7 @@ file_read_open(struct client_files *files, struct tmuxpeer *peer,
|
||||
log_debug("open read file %d %s", msg->stream, path);
|
||||
|
||||
find.stream = msg->stream;
|
||||
if ((cf = RB_FIND(client_files, files, &find)) != NULL) {
|
||||
if (RB_FIND(client_files, files, &find) != NULL) {
|
||||
error = EBADF;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
204
format-draw.c
204
format-draw.c
@@ -632,6 +632,36 @@ format_draw_absolute_centre(struct screen_write_ctx *octx, u_int available,
|
||||
width_after);
|
||||
}
|
||||
|
||||
/* Get width and count of any leading #s. */
|
||||
static const char *
|
||||
format_leading_hashes(const char *cp, u_int *n, u_int *width)
|
||||
{
|
||||
for (*n = 0; cp[*n] == '#'; (*n)++)
|
||||
/* nothing */;
|
||||
if (*n == 0) {
|
||||
*width = 0;
|
||||
return (cp);
|
||||
}
|
||||
if (cp[*n] != '[') {
|
||||
if ((*n % 2) == 0)
|
||||
*width = (*n / 2);
|
||||
else
|
||||
*width = (*n / 2) + 1;
|
||||
return (cp + *n);
|
||||
}
|
||||
*width = (*n / 2);
|
||||
if ((*n % 2) == 0) {
|
||||
/*
|
||||
* An even number of #s means that all #s are escaped, so not a
|
||||
* style. The caller should not skip this. Return pointing to
|
||||
* the [.
|
||||
*/
|
||||
return (cp + *n);
|
||||
}
|
||||
/* This is a style, so return pointing to the #. */
|
||||
return (cp + *n - 1);
|
||||
}
|
||||
|
||||
/* Draw multiple characters. */
|
||||
static void
|
||||
format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch,
|
||||
@@ -647,7 +677,8 @@ format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch,
|
||||
/* Draw a format to a screen. */
|
||||
void
|
||||
format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
u_int available, const char *expanded, struct style_ranges *srs)
|
||||
u_int available, const char *expanded, struct style_ranges *srs,
|
||||
int default_colours)
|
||||
{
|
||||
enum { LEFT,
|
||||
CENTRE,
|
||||
@@ -789,6 +820,10 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
log_debug("%s: style '%s' -> '%s'", __func__, tmp,
|
||||
style_tostring(&sy));
|
||||
free(tmp);
|
||||
if (default_colours) {
|
||||
sy.gc.bg = base->bg;
|
||||
sy.gc.fg = base->fg;
|
||||
}
|
||||
|
||||
/* If this style has a fill colour, store it for later. */
|
||||
if (sy.fill != 8)
|
||||
@@ -1002,37 +1037,22 @@ u_int
|
||||
format_width(const char *expanded)
|
||||
{
|
||||
const char *cp, *end;
|
||||
u_int n, width = 0;
|
||||
u_int n, leading_width, width = 0;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
cp = expanded;
|
||||
while (*cp != '\0') {
|
||||
if (*cp == '#') {
|
||||
for (n = 1; cp[n] == '#'; n++)
|
||||
/* nothing */;
|
||||
if (cp[n] != '[') {
|
||||
width += n;
|
||||
cp += n;
|
||||
continue;
|
||||
end = format_leading_hashes(cp, &n, &leading_width);
|
||||
width += leading_width;
|
||||
cp = end;
|
||||
if (*cp == '#') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
return (0);
|
||||
cp = end + 1;
|
||||
}
|
||||
width += (n / 2); /* one for each ## */
|
||||
|
||||
if ((n % 2) == 0) {
|
||||
/*
|
||||
* An even number of #s means that all #s are
|
||||
* escaped, so not a style.
|
||||
*/
|
||||
width++; /* one for the [ */
|
||||
cp += (n + 1);
|
||||
continue;
|
||||
}
|
||||
cp += (n - 1); /* point to the [ */
|
||||
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
return (0);
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
@@ -1059,7 +1079,7 @@ format_trim_left(const char *expanded, u_int limit)
|
||||
{
|
||||
char *copy, *out;
|
||||
const char *cp = expanded, *end;
|
||||
u_int even, n, width = 0;
|
||||
u_int n, width = 0, leading_width;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
@@ -1068,44 +1088,27 @@ format_trim_left(const char *expanded, u_int limit)
|
||||
if (width >= limit)
|
||||
break;
|
||||
if (*cp == '#') {
|
||||
for (end = cp + 1; *end == '#'; end++)
|
||||
/* nothing */;
|
||||
n = end - cp;
|
||||
if (*end != '[') {
|
||||
if (n > limit - width)
|
||||
n = limit - width;
|
||||
memcpy(out, cp, n);
|
||||
out += n;
|
||||
width += n;
|
||||
cp = end;
|
||||
continue;
|
||||
}
|
||||
even = ((n % 2) == 0);
|
||||
|
||||
n /= 2;
|
||||
if (n > limit - width)
|
||||
n = limit - width;
|
||||
width += n;
|
||||
n *= 2;
|
||||
memcpy(out, cp, n);
|
||||
out += n;
|
||||
|
||||
if (even) {
|
||||
if (width + 1 <= limit) {
|
||||
*out++ = '[';
|
||||
width++;
|
||||
end = format_leading_hashes(cp, &n, &leading_width);
|
||||
if (leading_width > limit - width)
|
||||
leading_width = limit - width;
|
||||
if (leading_width != 0) {
|
||||
if (n == 1)
|
||||
*out++ = '#';
|
||||
else {
|
||||
memset(out, '#', 2 * leading_width);
|
||||
out += 2 * leading_width;
|
||||
}
|
||||
cp = end + 1;
|
||||
continue;
|
||||
width += leading_width;
|
||||
}
|
||||
cp = end;
|
||||
if (*cp == '#') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
break;
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
}
|
||||
cp = end - 1;
|
||||
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
break;
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
@@ -1137,7 +1140,8 @@ format_trim_right(const char *expanded, u_int limit)
|
||||
{
|
||||
char *copy, *out;
|
||||
const char *cp = expanded, *end;
|
||||
u_int width = 0, total_width, skip, old_n, even, n;
|
||||
u_int width = 0, total_width, skip, n;
|
||||
u_int leading_width, copy_width;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
@@ -1149,64 +1153,32 @@ format_trim_right(const char *expanded, u_int limit)
|
||||
out = copy = xcalloc(1, strlen(expanded) + 1);
|
||||
while (*cp != '\0') {
|
||||
if (*cp == '#') {
|
||||
for (end = cp + 1; *end == '#'; end++)
|
||||
/* nothing */;
|
||||
old_n = n = end - cp;
|
||||
if (*end != '[') {
|
||||
if (width <= skip) {
|
||||
if (skip - width >= n)
|
||||
n = 0;
|
||||
else
|
||||
n -= (skip - width);
|
||||
}
|
||||
if (n != 0) {
|
||||
memcpy(out, cp, n);
|
||||
out += n;
|
||||
}
|
||||
|
||||
/*
|
||||
* The width always increases by the full
|
||||
* amount even if we can't copy anything yet.
|
||||
*/
|
||||
width += old_n;
|
||||
cp = end;
|
||||
continue;
|
||||
}
|
||||
even = ((n % 2) == 0);
|
||||
|
||||
n /= 2;
|
||||
end = format_leading_hashes(cp, &n, &leading_width);
|
||||
copy_width = leading_width;
|
||||
if (width <= skip) {
|
||||
if (skip - width >= n)
|
||||
n = 0;
|
||||
if (skip - width >= copy_width)
|
||||
copy_width = 0;
|
||||
else
|
||||
n -= (skip - width);
|
||||
copy_width -= (skip - width);
|
||||
}
|
||||
if (n != 0) {
|
||||
/*
|
||||
* Copy the full amount because it hasn't been
|
||||
* escaped yet.
|
||||
*/
|
||||
memcpy(out, cp, old_n);
|
||||
out += old_n;
|
||||
if (copy_width != 0) {
|
||||
if (n == 1)
|
||||
*out++ = '#';
|
||||
else {
|
||||
memset(out, '#', 2 * copy_width);
|
||||
out += 2 * copy_width;
|
||||
}
|
||||
}
|
||||
cp += old_n;
|
||||
width += (old_n / 2) - even;
|
||||
|
||||
if (even) {
|
||||
if (width > skip)
|
||||
*out++ = '[';
|
||||
width++;
|
||||
continue;
|
||||
width += leading_width;
|
||||
cp = end;
|
||||
if (*cp == '#') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
break;
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
}
|
||||
cp = end - 1;
|
||||
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL) {
|
||||
break;
|
||||
}
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
|
||||
234
format.c
234
format.c
@@ -24,6 +24,7 @@
|
||||
#include <fnmatch.h>
|
||||
#include <libgen.h>
|
||||
#include <math.h>
|
||||
#include <pwd.h>
|
||||
#include <regex.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
@@ -101,6 +102,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
||||
#define FORMAT_WINDOW_NAME 0x4000
|
||||
#define FORMAT_SESSION_NAME 0x8000
|
||||
#define FORMAT_CHARACTER 0x10000
|
||||
#define FORMAT_COLOUR 0x20000
|
||||
|
||||
/* Limit on recursion. */
|
||||
#define FORMAT_LOOP_LIMIT 100
|
||||
@@ -371,9 +373,6 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
||||
fj->client = ft->client;
|
||||
fj->tag = ft->tag;
|
||||
fj->cmd = xstrdup(cmd);
|
||||
fj->expanded = NULL;
|
||||
|
||||
xasprintf(&fj->out, "<'%s' not ready>", fj->cmd);
|
||||
|
||||
RB_INSERT(format_job_tree, jobs, fj);
|
||||
}
|
||||
@@ -393,7 +392,7 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
||||
if (force && fj->job != NULL)
|
||||
job_free(fj->job);
|
||||
if (force || (fj->job == NULL && fj->last != t)) {
|
||||
fj->job = job_run(expanded, 0, NULL, NULL,
|
||||
fj->job = job_run(expanded, 0, NULL, NULL, NULL,
|
||||
server_client_get_cwd(ft->client, NULL), format_job_update,
|
||||
format_job_complete, NULL, fj, JOB_NOWAIT, -1, -1);
|
||||
if (fj->job == NULL) {
|
||||
@@ -402,11 +401,14 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
||||
}
|
||||
fj->last = t;
|
||||
fj->updated = 0;
|
||||
}
|
||||
} else if (fj->job != NULL && (t - fj->last) > 1 && fj->out == NULL)
|
||||
xasprintf(&fj->out, "<'%s' not ready>", fj->cmd);
|
||||
free(expanded);
|
||||
|
||||
if (ft->flags & FORMAT_STATUS)
|
||||
fj->status = 1;
|
||||
if (fj->out == NULL)
|
||||
return (xstrdup(""));
|
||||
return (format_expand1(&next, fj->out));
|
||||
}
|
||||
|
||||
@@ -799,6 +801,20 @@ format_cb_start_command(struct format_tree *ft)
|
||||
return (cmd_stringify_argv(wp->argc, wp->argv));
|
||||
}
|
||||
|
||||
/* Callback for pane_start_path. */
|
||||
static void *
|
||||
format_cb_start_path(struct format_tree *ft)
|
||||
{
|
||||
struct window_pane *wp = ft->wp;
|
||||
|
||||
if (wp == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (wp->cwd == NULL)
|
||||
return (xstrdup(""));
|
||||
return (xstrdup(wp->cwd));
|
||||
}
|
||||
|
||||
/* Callback for pane_current_command. */
|
||||
static void *
|
||||
format_cb_current_command(struct format_tree *ft)
|
||||
@@ -929,6 +945,9 @@ format_cb_pane_fg(struct format_tree *ft)
|
||||
struct window_pane *wp = ft->wp;
|
||||
struct grid_cell gc;
|
||||
|
||||
if (wp == NULL)
|
||||
return (NULL);
|
||||
|
||||
tty_default_colours(&gc, wp);
|
||||
return (xstrdup(colour_tostring(gc.fg)));
|
||||
}
|
||||
@@ -940,6 +959,9 @@ format_cb_pane_bg(struct format_tree *ft)
|
||||
struct window_pane *wp = ft->wp;
|
||||
struct grid_cell gc;
|
||||
|
||||
if (wp == NULL)
|
||||
return (NULL);
|
||||
|
||||
tty_default_colours(&gc, wp);
|
||||
return (xstrdup(colour_tostring(gc.bg)));
|
||||
}
|
||||
@@ -1380,6 +1402,35 @@ format_cb_client_tty(struct format_tree *ft)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for client_uid. */
|
||||
static void *
|
||||
format_cb_client_uid(struct format_tree *ft)
|
||||
{
|
||||
uid_t uid;
|
||||
|
||||
if (ft->c != NULL) {
|
||||
uid = proc_get_peer_uid(ft->c->peer);
|
||||
if (uid != (uid_t)-1)
|
||||
return (format_printf("%ld", (long)uid));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for client_user. */
|
||||
static void *
|
||||
format_cb_client_user(struct format_tree *ft)
|
||||
{
|
||||
uid_t uid;
|
||||
struct passwd *pw;
|
||||
|
||||
if (ft->c != NULL) {
|
||||
uid = proc_get_peer_uid(ft->c->peer);
|
||||
if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL)
|
||||
return (xstrdup(pw->pw_name));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for client_utf8. */
|
||||
static void *
|
||||
format_cb_client_utf8(struct format_tree *ft)
|
||||
@@ -1608,11 +1659,16 @@ format_cb_mouse_x(struct format_tree *ft)
|
||||
struct window_pane *wp;
|
||||
u_int x, y;
|
||||
|
||||
if (ft->m.valid) {
|
||||
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||
if (wp != NULL && cmd_mouse_at(wp, &ft->m, &x, &y, 0) == 0)
|
||||
return (format_printf("%u", x));
|
||||
if (!ft->m.valid)
|
||||
return (NULL);
|
||||
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||
if (wp != NULL && cmd_mouse_at(wp, &ft->m, &x, &y, 0) == 0)
|
||||
return (format_printf("%u", x));
|
||||
if (ft->c != NULL && (ft->c->tty.flags & TTY_STARTED)) {
|
||||
if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines)
|
||||
return (format_printf("%u", ft->m.x));
|
||||
if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat)
|
||||
return (format_printf("%u", ft->m.x));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
@@ -1624,15 +1680,27 @@ format_cb_mouse_y(struct format_tree *ft)
|
||||
struct window_pane *wp;
|
||||
u_int x, y;
|
||||
|
||||
if (ft->m.valid) {
|
||||
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||
if (wp != NULL && cmd_mouse_at(wp, &ft->m, &x, &y, 0) == 0)
|
||||
return (format_printf("%u", y));
|
||||
if (!ft->m.valid)
|
||||
return (NULL);
|
||||
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||
if (wp != NULL && cmd_mouse_at(wp, &ft->m, &x, &y, 0) == 0)
|
||||
return (format_printf("%u", y));
|
||||
if (ft->c != NULL && (ft->c->tty.flags & TTY_STARTED)) {
|
||||
if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines)
|
||||
return (format_printf("%u", ft->m.y));
|
||||
if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat)
|
||||
return (format_printf("%u", ft->m.y - ft->m.statusat));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for next_session_id. */
|
||||
static void *
|
||||
format_cb_next_session_id(__unused struct format_tree *ft)
|
||||
{
|
||||
return (format_printf("$%u", next_session_id));
|
||||
}
|
||||
|
||||
/* Callback for origin_flag. */
|
||||
static void *
|
||||
format_cb_origin_flag(struct format_tree *ft)
|
||||
@@ -1702,6 +1770,23 @@ format_cb_pane_dead(struct format_tree *ft)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for pane_dead_signal. */
|
||||
static void *
|
||||
format_cb_pane_dead_signal(struct format_tree *ft)
|
||||
{
|
||||
struct window_pane *wp = ft->wp;
|
||||
const char *name;
|
||||
|
||||
if (wp != NULL) {
|
||||
if ((wp->flags & PANE_STATUSREADY) && WIFSIGNALED(wp->status)) {
|
||||
name = sig2name(WTERMSIG(wp->status));
|
||||
return (format_printf("%s", name));
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for pane_dead_status. */
|
||||
static void *
|
||||
format_cb_pane_dead_status(struct format_tree *ft)
|
||||
@@ -1716,6 +1801,20 @@ format_cb_pane_dead_status(struct format_tree *ft)
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for pane_dead_time. */
|
||||
static void *
|
||||
format_cb_pane_dead_time(struct format_tree *ft)
|
||||
{
|
||||
struct window_pane *wp = ft->wp;
|
||||
|
||||
if (wp != NULL) {
|
||||
if (wp->flags & PANE_STATUSDRAWN)
|
||||
return (&wp->dead_time);
|
||||
return (NULL);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Callback for pane_format. */
|
||||
static void *
|
||||
format_cb_pane_format(struct format_tree *ft)
|
||||
@@ -2079,7 +2178,7 @@ static void *
|
||||
format_cb_session_windows(struct format_tree *ft)
|
||||
{
|
||||
if (ft->s != NULL)
|
||||
return (format_printf ("%u", winlink_count(&ft->s->windows)));
|
||||
return (format_printf("%u", winlink_count(&ft->s->windows)));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
@@ -2497,6 +2596,24 @@ format_cb_tree_mode_format(__unused struct format_tree *ft)
|
||||
return (xstrdup(window_tree_mode.default_format));
|
||||
}
|
||||
|
||||
/* Callback for uid. */
|
||||
static void *
|
||||
format_cb_uid(__unused struct format_tree *ft)
|
||||
{
|
||||
return (format_printf("%ld", (long)getuid()));
|
||||
}
|
||||
|
||||
/* Callback for user. */
|
||||
static void *
|
||||
format_cb_user(__unused struct format_tree *ft)
|
||||
{
|
||||
struct passwd *pw;
|
||||
|
||||
if ((pw = getpwuid(getuid())) != NULL)
|
||||
return (xstrdup(pw->pw_name));
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Format table type. */
|
||||
enum format_table_type {
|
||||
FORMAT_TABLE_STRING,
|
||||
@@ -2603,6 +2720,12 @@ static const struct format_table_entry format_table[] = {
|
||||
{ "client_tty", FORMAT_TABLE_STRING,
|
||||
format_cb_client_tty
|
||||
},
|
||||
{ "client_uid", FORMAT_TABLE_STRING,
|
||||
format_cb_client_uid
|
||||
},
|
||||
{ "client_user", FORMAT_TABLE_STRING,
|
||||
format_cb_client_user
|
||||
},
|
||||
{ "client_utf8", FORMAT_TABLE_STRING,
|
||||
format_cb_client_utf8
|
||||
},
|
||||
@@ -2690,6 +2813,9 @@ static const struct format_table_entry format_table[] = {
|
||||
{ "mouse_y", FORMAT_TABLE_STRING,
|
||||
format_cb_mouse_y
|
||||
},
|
||||
{ "next_session_id", FORMAT_TABLE_STRING,
|
||||
format_cb_next_session_id
|
||||
},
|
||||
{ "origin_flag", FORMAT_TABLE_STRING,
|
||||
format_cb_origin_flag
|
||||
},
|
||||
@@ -2723,9 +2849,15 @@ static const struct format_table_entry format_table[] = {
|
||||
{ "pane_dead", FORMAT_TABLE_STRING,
|
||||
format_cb_pane_dead
|
||||
},
|
||||
{ "pane_dead_signal", FORMAT_TABLE_STRING,
|
||||
format_cb_pane_dead_signal
|
||||
},
|
||||
{ "pane_dead_status", FORMAT_TABLE_STRING,
|
||||
format_cb_pane_dead_status
|
||||
},
|
||||
{ "pane_dead_time", FORMAT_TABLE_TIME,
|
||||
format_cb_pane_dead_time
|
||||
},
|
||||
{ "pane_fg", FORMAT_TABLE_STRING,
|
||||
format_cb_pane_fg
|
||||
},
|
||||
@@ -2780,6 +2912,9 @@ static const struct format_table_entry format_table[] = {
|
||||
{ "pane_start_command", FORMAT_TABLE_STRING,
|
||||
format_cb_start_command
|
||||
},
|
||||
{ "pane_start_path", FORMAT_TABLE_STRING,
|
||||
format_cb_start_path
|
||||
},
|
||||
{ "pane_synchronized", FORMAT_TABLE_STRING,
|
||||
format_cb_pane_synchronized
|
||||
},
|
||||
@@ -2879,6 +3014,12 @@ static const struct format_table_entry format_table[] = {
|
||||
{ "tree_mode_format", FORMAT_TABLE_STRING,
|
||||
format_cb_tree_mode_format
|
||||
},
|
||||
{ "uid", FORMAT_TABLE_STRING,
|
||||
format_cb_uid
|
||||
},
|
||||
{ "user", FORMAT_TABLE_STRING,
|
||||
format_cb_user
|
||||
},
|
||||
{ "version", FORMAT_TABLE_STRING,
|
||||
format_cb_version
|
||||
},
|
||||
@@ -3079,6 +3220,22 @@ format_free(struct format_tree *ft)
|
||||
free(ft);
|
||||
}
|
||||
|
||||
/* Log each format. */
|
||||
static void
|
||||
format_log_debug_cb(const char *key, const char *value, void *arg)
|
||||
{
|
||||
const char *prefix = arg;
|
||||
|
||||
log_debug("%s: %s=%s", prefix, key, value);
|
||||
}
|
||||
|
||||
/* Log a format tree. */
|
||||
void
|
||||
format_log_debug(struct format_tree *ft, const char *prefix)
|
||||
{
|
||||
format_each(ft, format_log_debug_cb, (void *)prefix);
|
||||
}
|
||||
|
||||
/* Walk each format. */
|
||||
void
|
||||
format_each(struct format_tree *ft, void (*cb)(const char *, const char *,
|
||||
@@ -3305,7 +3462,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers,
|
||||
fte = format_table_get(key);
|
||||
if (fte != NULL) {
|
||||
value = fte->cb(ft);
|
||||
if (fte->type == FORMAT_TABLE_TIME)
|
||||
if (fte->type == FORMAT_TABLE_TIME && value != NULL)
|
||||
t = ((struct timeval *)value)->tv_sec;
|
||||
else
|
||||
found = value;
|
||||
@@ -3523,7 +3680,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
|
||||
/*
|
||||
* Modifiers are a ; separated list of the forms:
|
||||
* l,m,C,a,b,d,n,t,w,q,E,T,S,W,P,<,>
|
||||
* l,m,C,a,b,c,d,n,t,w,q,E,T,S,W,P,<,>
|
||||
* =a
|
||||
* =/a
|
||||
* =/a/
|
||||
@@ -3540,7 +3697,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
cp++;
|
||||
|
||||
/* Check single character modifiers with no arguments. */
|
||||
if (strchr("labdnwETSWP<>", cp[0]) != NULL &&
|
||||
if (strchr("labcdnwETSWP<>", cp[0]) != NULL &&
|
||||
format_is_end(cp[1])) {
|
||||
format_add_modifier(&list, count, cp, 1, NULL, 0);
|
||||
cp++;
|
||||
@@ -3604,7 +3761,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
||||
break;
|
||||
cp++;
|
||||
|
||||
argv = xreallocarray (argv, argc + 1, sizeof *argv);
|
||||
argv = xreallocarray(argv, argc + 1, sizeof *argv);
|
||||
value = xstrndup(cp, end - cp);
|
||||
argv[argc++] = format_expand1(es, value);
|
||||
free(value);
|
||||
@@ -4020,10 +4177,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
const char *errstr, *copy, *cp, *marker = NULL;
|
||||
const char *time_format = NULL;
|
||||
char *copy0, *condition, *found, *new;
|
||||
char *value, *left, *right, c;
|
||||
char *value, *left, *right;
|
||||
size_t valuelen;
|
||||
int modifiers = 0, limit = 0, width = 0;
|
||||
int j;
|
||||
int j, c;
|
||||
struct format_modifier *list, *cmp = NULL, *search = NULL;
|
||||
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
|
||||
u_int i, count, nsub = 0;
|
||||
@@ -4056,8 +4213,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
case 's':
|
||||
if (fm->argc < 2)
|
||||
break;
|
||||
sub = xreallocarray (sub, nsub + 1,
|
||||
sizeof *sub);
|
||||
sub = xreallocarray(sub, nsub + 1, sizeof *sub);
|
||||
sub[nsub++] = fm;
|
||||
break;
|
||||
case '=':
|
||||
@@ -4095,6 +4251,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
case 'b':
|
||||
modifiers |= FORMAT_BASENAME;
|
||||
break;
|
||||
case 'c':
|
||||
modifiers |= FORMAT_COLOUR;
|
||||
break;
|
||||
case 'd':
|
||||
modifiers |= FORMAT_DIRNAME;
|
||||
break;
|
||||
@@ -4166,7 +4325,19 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
value = xstrdup("");
|
||||
else
|
||||
xasprintf(&value, "%c", c);
|
||||
free (new);
|
||||
free(new);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Is this a colour? */
|
||||
if (modifiers & FORMAT_COLOUR) {
|
||||
new = format_expand1(es, copy);
|
||||
c = colour_fromstring(new);
|
||||
if (c == -1 || (c = colour_force_rgb(c)) == -1)
|
||||
value = xstrdup("");
|
||||
else
|
||||
xasprintf(&value, "%06x", c & 0xffffff);
|
||||
free(new);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -4278,15 +4449,14 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
||||
if (strcmp(found, condition) == 0) {
|
||||
free(found);
|
||||
found = xstrdup("");
|
||||
format_log(es, "condition '%s' found: %s",
|
||||
condition, found);
|
||||
} else {
|
||||
format_log(es,
|
||||
"condition '%s' not found; assuming false",
|
||||
condition);
|
||||
}
|
||||
} else
|
||||
format_log(es, "condition '%s' found", condition);
|
||||
} else {
|
||||
format_log(es, "condition '%s' found: %s", condition,
|
||||
found);
|
||||
}
|
||||
|
||||
if (format_choose(es, cp + 1, &left, &right, 0) != 0) {
|
||||
format_log(es, "condition '%s' syntax error: %s",
|
||||
@@ -4731,7 +4901,7 @@ format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
||||
if (wp != NULL)
|
||||
format_defaults_pane(ft, wp);
|
||||
|
||||
pb = paste_get_top (NULL);
|
||||
pb = paste_get_top(NULL);
|
||||
if (pb != NULL)
|
||||
format_defaults_paste_buffer(ft, pb);
|
||||
}
|
||||
@@ -4809,7 +4979,8 @@ format_grid_word(struct grid *gd, u_int x, u_int y)
|
||||
grid_get_cell(gd, x, y, &gc);
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
break;
|
||||
if (utf8_cstrhas(ws, &gc.data)) {
|
||||
if (utf8_cstrhas(ws, &gc.data) ||
|
||||
(gc.data.size == 1 && *gc.data.data == ' ')) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
@@ -4846,7 +5017,8 @@ format_grid_word(struct grid *gd, u_int x, u_int y)
|
||||
grid_get_cell(gd, x, y, &gc);
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
break;
|
||||
if (utf8_cstrhas(ws, &gc.data))
|
||||
if (utf8_cstrhas(ws, &gc.data) ||
|
||||
(gc.data.size == 1 && *gc.data.data == ' '))
|
||||
break;
|
||||
|
||||
ud = xreallocarray(ud, size + 2, sizeof *ud);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -26,7 +27,7 @@
|
||||
struct event_base *libevent;
|
||||
|
||||
int
|
||||
LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
|
||||
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
|
||||
{
|
||||
struct bufferevent *vpty[2];
|
||||
struct window *w;
|
||||
@@ -43,10 +44,15 @@ LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
|
||||
w = window_create(PANE_WIDTH, PANE_HEIGHT, 0, 0);
|
||||
wp = window_add_pane(w, NULL, 0, 0);
|
||||
bufferevent_pair_new(libevent, BEV_OPT_CLOSE_ON_FREE, vpty);
|
||||
wp->ictx = input_init(wp, vpty[0]);
|
||||
wp->ictx = input_init(wp, vpty[0], NULL);
|
||||
window_add_ref(w, __func__);
|
||||
|
||||
input_parse_buffer(wp, (u_char*) data, size);
|
||||
wp->fd = open("/dev/null", O_WRONLY);
|
||||
if (wp->fd == -1)
|
||||
errx(1, "open(\"/dev/null\") failed");
|
||||
wp->event = bufferevent_new(wp->fd, NULL, NULL, NULL, NULL);
|
||||
|
||||
input_parse_buffer(wp, (u_char *)data, size);
|
||||
while (cmdq_next(NULL) != 0)
|
||||
;
|
||||
error = event_base_loop(libevent, EVLOOP_NONBLOCK);
|
||||
@@ -84,6 +90,7 @@ LLVMFuzzerInitialize(__unused int *argc, __unused char ***argv)
|
||||
options_set_number(global_w_options, "monitor-bell", 0);
|
||||
options_set_number(global_w_options, "allow-rename", 1);
|
||||
options_set_number(global_options, "set-clipboard", 2);
|
||||
socket_path = xstrdup("dummy");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
161
grid-reader.c
161
grid-reader.c
@@ -153,6 +153,29 @@ grid_reader_cursor_end_of_line(struct grid_reader *gr, int wrap, int all)
|
||||
gr->cx = grid_reader_line_length(gr);
|
||||
}
|
||||
|
||||
/* Handle line wrapping while moving the cursor. */
|
||||
static int
|
||||
grid_reader_handle_wrap(struct grid_reader *gr, u_int *xx, u_int *yy)
|
||||
{
|
||||
/*
|
||||
* Make sure the cursor lies within the grid reader's bounding area,
|
||||
* wrapping to the next line as necessary. Return zero if the cursor
|
||||
* would wrap past the bottom of the grid.
|
||||
*/
|
||||
while (gr->cx > *xx) {
|
||||
if (gr->cy == *yy)
|
||||
return (0);
|
||||
grid_reader_cursor_start_of_line(gr, 0);
|
||||
grid_reader_cursor_down(gr);
|
||||
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||
*xx = gr->gd->sx - 1;
|
||||
else
|
||||
*xx = grid_reader_line_length(gr);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Check if character under cursor is in set. */
|
||||
int
|
||||
grid_reader_in_set(struct grid_reader *gr, const char *set)
|
||||
@@ -170,7 +193,6 @@ void
|
||||
grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
||||
{
|
||||
u_int xx, yy;
|
||||
int expected = 0;
|
||||
|
||||
/* Do not break up wrapped words. */
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||
@@ -180,33 +202,35 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
||||
yy = gr->gd->hsize + gr->gd->sy - 1;
|
||||
|
||||
/*
|
||||
* If we started inside a word, skip over word characters. Then skip
|
||||
* over separators till the next word.
|
||||
* When navigating via spaces (for example with next-space) separators
|
||||
* should be empty.
|
||||
*
|
||||
* expected is initially set to 0 for the former and then 1 for the
|
||||
* latter. It is finally set to 0 when the beginning of the next word is
|
||||
* found.
|
||||
* If we started on a separator that is not whitespace, skip over
|
||||
* subsequent separators that are not whitespace. Otherwise, if we
|
||||
* started on a non-whitespace character, skip over subsequent
|
||||
* characters that are neither whitespace nor separators. Then, skip
|
||||
* over whitespace (if any) until the next non-whitespace character.
|
||||
*/
|
||||
do {
|
||||
while (gr->cx > xx ||
|
||||
grid_reader_in_set(gr, separators) == expected) {
|
||||
/* Move down if we are past the end of the line. */
|
||||
if (gr->cx > xx) {
|
||||
if (gr->cy == yy)
|
||||
return;
|
||||
grid_reader_cursor_start_of_line(gr, 0);
|
||||
grid_reader_cursor_down(gr);
|
||||
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags &
|
||||
GRID_LINE_WRAPPED)
|
||||
xx = gr->gd->sx - 1;
|
||||
else
|
||||
xx = grid_reader_line_length(gr);
|
||||
} else
|
||||
if (!grid_reader_handle_wrap(gr, &xx, &yy))
|
||||
return;
|
||||
if (!grid_reader_in_set(gr, WHITESPACE)) {
|
||||
if (grid_reader_in_set(gr, separators)) {
|
||||
do
|
||||
gr->cx++;
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
grid_reader_in_set(gr, separators) &&
|
||||
!grid_reader_in_set(gr, WHITESPACE));
|
||||
} else {
|
||||
do
|
||||
gr->cx++;
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
!(grid_reader_in_set(gr, separators) ||
|
||||
grid_reader_in_set(gr, WHITESPACE)));
|
||||
}
|
||||
expected = !expected;
|
||||
} while (expected == 1);
|
||||
}
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
grid_reader_in_set(gr, WHITESPACE))
|
||||
gr->cx++;
|
||||
}
|
||||
|
||||
/* Move cursor to the end of the next word. */
|
||||
@@ -214,7 +238,6 @@ void
|
||||
grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
|
||||
{
|
||||
u_int xx, yy;
|
||||
int expected = 1;
|
||||
|
||||
/* Do not break up wrapped words. */
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||
@@ -224,49 +247,54 @@ grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
|
||||
yy = gr->gd->hsize + gr->gd->sy - 1;
|
||||
|
||||
/*
|
||||
* If we started on a separator, skip over separators. Then skip over
|
||||
* word characters till the next separator.
|
||||
* When navigating via spaces (for example with next-space), separators
|
||||
* should be empty in both modes.
|
||||
*
|
||||
* expected is initially set to 1 for the former and then 1 for the
|
||||
* latter. It is finally set to 1 when the end of the next word is
|
||||
* found.
|
||||
* If we started on a whitespace, move until reaching the first
|
||||
* non-whitespace character. If that character is a separator, treat
|
||||
* subsequent separators as a word, and continue moving until the first
|
||||
* non-separator. Otherwise, continue moving until the first separator
|
||||
* or whitespace.
|
||||
*/
|
||||
do {
|
||||
while (gr->cx > xx ||
|
||||
grid_reader_in_set(gr, separators) == expected) {
|
||||
/* Move down if we are past the end of the line. */
|
||||
if (gr->cx > xx) {
|
||||
if (gr->cy == yy)
|
||||
return;
|
||||
grid_reader_cursor_start_of_line(gr, 0);
|
||||
grid_reader_cursor_down(gr);
|
||||
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags &
|
||||
GRID_LINE_WRAPPED)
|
||||
xx = gr->gd->sx - 1;
|
||||
else
|
||||
xx = grid_reader_line_length(gr);
|
||||
} else
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy)) {
|
||||
if (grid_reader_in_set(gr, WHITESPACE))
|
||||
gr->cx++;
|
||||
else if (grid_reader_in_set(gr, separators)) {
|
||||
do
|
||||
gr->cx++;
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
grid_reader_in_set(gr, separators) &&
|
||||
!grid_reader_in_set(gr, WHITESPACE));
|
||||
return;
|
||||
} else {
|
||||
do
|
||||
gr->cx++;
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
!(grid_reader_in_set(gr, WHITESPACE) ||
|
||||
grid_reader_in_set(gr, separators)));
|
||||
return;
|
||||
}
|
||||
expected = !expected;
|
||||
} while (expected == 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Move to the previous place where a word begins. */
|
||||
void
|
||||
grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
||||
int already)
|
||||
int already, int stop_at_eol)
|
||||
{
|
||||
int oldx, oldy, r;
|
||||
int oldx, oldy, at_eol, word_is_letters;
|
||||
|
||||
/* Move back to the previous word character. */
|
||||
if (already || grid_reader_in_set(gr, separators)) {
|
||||
if (already || grid_reader_in_set(gr, WHITESPACE)) {
|
||||
for (;;) {
|
||||
if (gr->cx > 0) {
|
||||
gr->cx--;
|
||||
if (!grid_reader_in_set(gr, separators))
|
||||
if (!grid_reader_in_set(gr, WHITESPACE)) {
|
||||
word_is_letters =
|
||||
!grid_reader_in_set(gr, separators);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (gr->cy == 0)
|
||||
return;
|
||||
@@ -274,17 +302,21 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
||||
grid_reader_cursor_end_of_line(gr, 0, 0);
|
||||
|
||||
/* Stop if separator at EOL. */
|
||||
if (gr->cx > 0) {
|
||||
if (stop_at_eol && gr->cx > 0) {
|
||||
oldx = gr->cx;
|
||||
gr->cx--;
|
||||
r = grid_reader_in_set(gr, separators);
|
||||
at_eol = grid_reader_in_set(gr,
|
||||
WHITESPACE);
|
||||
gr->cx = oldx;
|
||||
if (r)
|
||||
if (at_eol) {
|
||||
word_is_letters = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
word_is_letters = !grid_reader_in_set(gr, separators);
|
||||
|
||||
/* Move back to the beginning of this word. */
|
||||
do {
|
||||
@@ -292,15 +324,16 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
||||
oldy = gr->cy;
|
||||
if (gr->cx == 0) {
|
||||
if (gr->cy == 0 ||
|
||||
~grid_get_line(gr->gd, gr->cy - 1)->flags &
|
||||
GRID_LINE_WRAPPED)
|
||||
(~grid_get_line(gr->gd, gr->cy - 1)->flags &
|
||||
GRID_LINE_WRAPPED))
|
||||
break;
|
||||
grid_reader_cursor_up(gr);
|
||||
grid_reader_cursor_end_of_line(gr, 0, 1);
|
||||
}
|
||||
if (gr->cx > 0)
|
||||
gr->cx--;
|
||||
} while (!grid_reader_in_set(gr, separators));
|
||||
} while (!grid_reader_in_set(gr, WHITESPACE) &&
|
||||
word_is_letters != grid_reader_in_set(gr, separators));
|
||||
gr->cx = oldx;
|
||||
gr->cy = oldy;
|
||||
}
|
||||
@@ -324,17 +357,17 @@ grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
|
||||
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||
gr->cx = px;
|
||||
gr->cy = py;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
px++;
|
||||
}
|
||||
|
||||
if (py == yy ||
|
||||
!(grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED))
|
||||
return 0;
|
||||
return (0);
|
||||
px = 0;
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Jump back to character. */
|
||||
@@ -354,16 +387,16 @@ grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
|
||||
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||
gr->cx = px - 1;
|
||||
gr->cy = py - 1;
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
}
|
||||
|
||||
if (py == 1 ||
|
||||
!(grid_get_line(gr->gd, py - 2)->flags & GRID_LINE_WRAPPED))
|
||||
return 0;
|
||||
return (0);
|
||||
xx = grid_line_length(gr->gd, py - 2);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Jump back to the first non-blank character of the line. */
|
||||
|
||||
98
grid.c
98
grid.c
@@ -826,6 +826,56 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values)
|
||||
return (n);
|
||||
}
|
||||
|
||||
/* Get underscore colour sequence. */
|
||||
static size_t
|
||||
grid_string_cells_us(const struct grid_cell *gc, int *values)
|
||||
{
|
||||
size_t n;
|
||||
u_char r, g, b;
|
||||
|
||||
n = 0;
|
||||
if (gc->us & COLOUR_FLAG_256) {
|
||||
values[n++] = 58;
|
||||
values[n++] = 5;
|
||||
values[n++] = gc->us & 0xff;
|
||||
} else if (gc->us & COLOUR_FLAG_RGB) {
|
||||
values[n++] = 58;
|
||||
values[n++] = 2;
|
||||
colour_split_rgb(gc->us, &r, &g, &b);
|
||||
values[n++] = r;
|
||||
values[n++] = g;
|
||||
values[n++] = b;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
/* Add on SGR code. */
|
||||
static void
|
||||
grid_string_cells_add_code(char *buf, size_t len, u_int n, int *s, int *newc,
|
||||
int *oldc, size_t nnewc, size_t noldc, int escape_c0)
|
||||
{
|
||||
u_int i;
|
||||
char tmp[64];
|
||||
|
||||
if (nnewc != 0 &&
|
||||
(nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0))) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < nnewc; i++) {
|
||||
if (i + 1 < nnewc)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
|
||||
else
|
||||
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
|
||||
strlcat(buf, tmp, len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns ANSI code to set particular attributes (colour, bold and so on)
|
||||
* given a current state.
|
||||
@@ -861,7 +911,9 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
|
||||
/* If any attribute is removed, begin with 0. */
|
||||
for (i = 0; i < nitems(attrs); i++) {
|
||||
if (!(attr & attrs[i].mask) && (lastattr & attrs[i].mask)) {
|
||||
if (((~attr & attrs[i].mask) &&
|
||||
(lastattr & attrs[i].mask)) ||
|
||||
(lastgc->us != 0 && gc->us == 0)) {
|
||||
s[n++] = 0;
|
||||
lastattr &= GRID_ATTR_CHARSET;
|
||||
break;
|
||||
@@ -897,42 +949,20 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
/* If the foreground colour changed, write its parameters. */
|
||||
nnewc = grid_string_cells_fg(gc, newc);
|
||||
noldc = grid_string_cells_fg(lastgc, oldc);
|
||||
if (nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < nnewc; i++) {
|
||||
if (i + 1 < nnewc)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
|
||||
else
|
||||
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
|
||||
strlcat(buf, tmp, len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
|
||||
/* If the background colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_bg(gc, newc);
|
||||
noldc = grid_string_cells_bg(lastgc, oldc);
|
||||
if (nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < nnewc; i++) {
|
||||
if (i + 1 < nnewc)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
|
||||
else
|
||||
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
|
||||
strlcat(buf, tmp, len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
|
||||
/* If the underscore colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_us(gc, newc);
|
||||
noldc = grid_string_cells_us(lastgc, oldc);
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
|
||||
/* Append shift in/shift out if needed. */
|
||||
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
||||
@@ -973,7 +1003,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||
|
||||
gl = grid_peek_line(gd, py);
|
||||
for (xx = px; xx < px + nx; xx++) {
|
||||
if (gl == NULL || xx >= gl->cellsize)
|
||||
if (gl == NULL || xx >= gl->cellused)
|
||||
break;
|
||||
grid_get_cell(gd, xx, py, &gc);
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
|
||||
48
input-keys.c
48
input-keys.c
@@ -333,7 +333,7 @@ input_key_cmp(struct input_key_entry *ike1, struct input_key_entry *ike2)
|
||||
|
||||
/* Look for key in tree. */
|
||||
static struct input_key_entry *
|
||||
input_key_get (key_code key)
|
||||
input_key_get(key_code key)
|
||||
{
|
||||
struct input_key_entry entry = { .key = key };
|
||||
|
||||
@@ -417,7 +417,7 @@ int
|
||||
input_key(struct screen *s, struct bufferevent *bev, key_code key)
|
||||
{
|
||||
struct input_key_entry *ike;
|
||||
key_code justkey, newkey, outkey;
|
||||
key_code justkey, newkey, outkey, modifiers;
|
||||
struct utf8_data ud;
|
||||
char tmp[64], modifier;
|
||||
|
||||
@@ -518,7 +518,12 @@ input_key(struct screen *s, struct bufferevent *bev, key_code key)
|
||||
return (input_key(s, bev, key & ~KEYC_CTRL));
|
||||
}
|
||||
outkey = (key & KEYC_MASK_KEY);
|
||||
switch (key & KEYC_MASK_MODIFIERS) {
|
||||
modifiers = (key & KEYC_MASK_MODIFIERS);
|
||||
if (outkey < 32 && outkey != 9 && outkey != 13 && outkey != 27) {
|
||||
outkey = 64 + outkey;
|
||||
modifiers |= KEYC_CTRL;
|
||||
}
|
||||
switch (modifiers) {
|
||||
case KEYC_SHIFT:
|
||||
modifier = '2';
|
||||
break;
|
||||
@@ -577,13 +582,13 @@ input_key_get_mouse(struct screen *s, struct mouse_event *m, u_int x, u_int y,
|
||||
*/
|
||||
if (m->sgr_type != ' ') {
|
||||
if (MOUSE_DRAG(m->sgr_b) &&
|
||||
MOUSE_BUTTONS(m->sgr_b) == 3 &&
|
||||
MOUSE_RELEASE(m->sgr_b) &&
|
||||
(~s->mode & MODE_MOUSE_ALL))
|
||||
return (0);
|
||||
} else {
|
||||
if (MOUSE_DRAG(m->b) &&
|
||||
MOUSE_BUTTONS(m->b) == 3 &&
|
||||
MOUSE_BUTTONS(m->lb) == 3 &&
|
||||
MOUSE_RELEASE(m->b) &&
|
||||
MOUSE_RELEASE(m->lb) &&
|
||||
(~s->mode & MODE_MOUSE_ALL))
|
||||
return (0);
|
||||
}
|
||||
@@ -601,19 +606,34 @@ input_key_get_mouse(struct screen *s, struct mouse_event *m, u_int x, u_int y,
|
||||
len = xsnprintf(buf, sizeof buf, "\033[<%u;%u;%u%c",
|
||||
m->sgr_b, x + 1, y + 1, m->sgr_type);
|
||||
} else if (s->mode & MODE_MOUSE_UTF8) {
|
||||
if (m->b > 0x7ff - 32 || x > 0x7ff - 33 || y > 0x7ff - 33)
|
||||
if (m->b > MOUSE_PARAM_UTF8_MAX - MOUSE_PARAM_BTN_OFF ||
|
||||
x > MOUSE_PARAM_UTF8_MAX - MOUSE_PARAM_POS_OFF ||
|
||||
y > MOUSE_PARAM_UTF8_MAX - MOUSE_PARAM_POS_OFF)
|
||||
return (0);
|
||||
len = xsnprintf(buf, sizeof buf, "\033[M");
|
||||
len += input_key_split2(m->b + 32, &buf[len]);
|
||||
len += input_key_split2(x + 33, &buf[len]);
|
||||
len += input_key_split2(y + 33, &buf[len]);
|
||||
len += input_key_split2(m->b + MOUSE_PARAM_BTN_OFF, &buf[len]);
|
||||
len += input_key_split2(x + MOUSE_PARAM_POS_OFF, &buf[len]);
|
||||
len += input_key_split2(y + MOUSE_PARAM_POS_OFF, &buf[len]);
|
||||
} else {
|
||||
if (m->b > 223)
|
||||
if (m->b + MOUSE_PARAM_BTN_OFF > MOUSE_PARAM_MAX)
|
||||
return (0);
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "\033[M");
|
||||
buf[len++] = m->b + 32;
|
||||
buf[len++] = x + 33;
|
||||
buf[len++] = y + 33;
|
||||
buf[len++] = m->b + MOUSE_PARAM_BTN_OFF;
|
||||
|
||||
/*
|
||||
* The incoming x and y may be out of the range which can be
|
||||
* supported by the "normal" mouse protocol. Clamp the
|
||||
* coordinates to the supported range.
|
||||
*/
|
||||
if (x + MOUSE_PARAM_POS_OFF > MOUSE_PARAM_MAX)
|
||||
buf[len++] = MOUSE_PARAM_MAX;
|
||||
else
|
||||
buf[len++] = x + MOUSE_PARAM_POS_OFF;
|
||||
if (y + MOUSE_PARAM_POS_OFF > MOUSE_PARAM_MAX)
|
||||
buf[len++] = MOUSE_PARAM_MAX;
|
||||
else
|
||||
buf[len++] = y + MOUSE_PARAM_POS_OFF;
|
||||
}
|
||||
|
||||
*rbuf = buf;
|
||||
|
||||
323
input.c
323
input.c
@@ -77,6 +77,7 @@ struct input_ctx {
|
||||
struct window_pane *wp;
|
||||
struct bufferevent *event;
|
||||
struct screen_write_ctx ctx;
|
||||
struct colour_palette *palette;
|
||||
|
||||
struct input_cell cell;
|
||||
|
||||
@@ -136,10 +137,12 @@ static void input_reset_cell(struct input_ctx *);
|
||||
static void input_osc_4(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 *);
|
||||
static void input_osc_52(struct input_ctx *, const char *);
|
||||
static void input_osc_104(struct input_ctx *, const char *);
|
||||
static void input_osc_110(struct input_ctx *, const char *);
|
||||
static void input_osc_111(struct input_ctx *, const char *);
|
||||
static void input_osc_112(struct input_ctx *, const char *);
|
||||
|
||||
/* Transition entry/exit handlers. */
|
||||
static void input_clear(struct input_ctx *);
|
||||
@@ -797,13 +800,15 @@ input_restore_state(struct input_ctx *ictx)
|
||||
|
||||
/* Initialise input parser. */
|
||||
struct input_ctx *
|
||||
input_init(struct window_pane *wp, struct bufferevent *bev)
|
||||
input_init(struct window_pane *wp, struct bufferevent *bev,
|
||||
struct colour_palette *palette)
|
||||
{
|
||||
struct input_ctx *ictx;
|
||||
|
||||
ictx = xcalloc(1, sizeof *ictx);
|
||||
ictx->wp = wp;
|
||||
ictx->event = bev;
|
||||
ictx->palette = palette;
|
||||
|
||||
ictx->input_space = INPUT_BUF_START;
|
||||
ictx->input_buf = xmalloc(INPUT_BUF_START);
|
||||
@@ -1073,6 +1078,9 @@ input_reply(struct input_ctx *ictx, const char *fmt, ...)
|
||||
va_list ap;
|
||||
char *reply;
|
||||
|
||||
if (bev == NULL)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&reply, fmt, ap);
|
||||
va_end(ap);
|
||||
@@ -1252,7 +1260,6 @@ static int
|
||||
input_esc_dispatch(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
struct screen *s = sctx->s;
|
||||
struct input_table_entry *entry;
|
||||
|
||||
@@ -1269,10 +1276,10 @@ input_esc_dispatch(struct input_ctx *ictx)
|
||||
|
||||
switch (entry->type) {
|
||||
case INPUT_ESC_RIS:
|
||||
if (wp != NULL)
|
||||
window_pane_reset_palette(wp);
|
||||
colour_palette_clear(ictx->palette);
|
||||
input_reset_cell(ictx);
|
||||
screen_write_reset(sctx);
|
||||
screen_write_fullredraw(sctx);
|
||||
break;
|
||||
case INPUT_ESC_IND:
|
||||
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg);
|
||||
@@ -1615,7 +1622,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
case INPUT_CSI_DECSCUSR:
|
||||
n = input_get(ictx, 0, 0, 0);
|
||||
if (n != -1)
|
||||
screen_set_cursor_style(s, n);
|
||||
screen_set_cursor_style(n, &s->cstyle, &s->mode);
|
||||
break;
|
||||
case INPUT_CSI_XDA:
|
||||
n = input_get(ictx, 0, 0, 0);
|
||||
@@ -1644,7 +1651,7 @@ input_csi_dispatch_rm(struct input_ctx *ictx)
|
||||
screen_write_mode_clear(sctx, MODE_INSERT);
|
||||
break;
|
||||
case 34:
|
||||
screen_write_mode_set(sctx, MODE_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_CURSOR_VERY_VISIBLE);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1680,7 +1687,8 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
||||
screen_write_mode_clear(sctx, MODE_WRAP);
|
||||
break;
|
||||
case 12:
|
||||
screen_write_mode_clear(sctx, MODE_BLINKING);
|
||||
screen_write_mode_clear(sctx, MODE_CURSOR_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_CURSOR_BLINKING_SET);
|
||||
break;
|
||||
case 25: /* TCEM */
|
||||
screen_write_mode_clear(sctx, MODE_CURSOR);
|
||||
@@ -1732,7 +1740,7 @@ input_csi_dispatch_sm(struct input_ctx *ictx)
|
||||
screen_write_mode_set(sctx, MODE_INSERT);
|
||||
break;
|
||||
case 34:
|
||||
screen_write_mode_clear(sctx, MODE_BLINKING);
|
||||
screen_write_mode_clear(sctx, MODE_CURSOR_VERY_VISIBLE);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1769,7 +1777,8 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
screen_write_mode_set(sctx, MODE_WRAP);
|
||||
break;
|
||||
case 12:
|
||||
screen_write_mode_set(sctx, MODE_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_CURSOR_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_CURSOR_BLINKING_SET);
|
||||
break;
|
||||
case 25: /* TCEM */
|
||||
screen_write_mode_set(sctx, MODE_CURSOR);
|
||||
@@ -1790,8 +1799,14 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
if (sctx->s->mode & MODE_FOCUSON)
|
||||
break;
|
||||
screen_write_mode_set(sctx, MODE_FOCUSON);
|
||||
if (wp != NULL)
|
||||
wp->flags |= PANE_FOCUSPUSH; /* force update */
|
||||
if (wp == NULL)
|
||||
break;
|
||||
if (!options_get_number(global_options, "focus-events"))
|
||||
break;
|
||||
if (wp->flags & PANE_FOCUSED)
|
||||
bufferevent_write(wp->event, "\033[I", 3);
|
||||
else
|
||||
bufferevent_write(wp->event, "\033[O", 3);
|
||||
break;
|
||||
case 1005:
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_UTF8);
|
||||
@@ -1874,11 +1889,11 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
|
||||
case 0:
|
||||
case 2:
|
||||
screen_pop_title(sctx->s);
|
||||
if (wp != NULL) {
|
||||
notify_pane("pane-title-changed", wp);
|
||||
server_redraw_window_borders(wp->window);
|
||||
server_status_window(wp->window);
|
||||
}
|
||||
if (wp == NULL)
|
||||
break;
|
||||
notify_pane("pane-title-changed", wp);
|
||||
server_redraw_window_borders(wp->window);
|
||||
server_status_window(wp->window);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -2225,15 +2240,19 @@ input_enter_dcs(struct input_ctx *ictx)
|
||||
static int
|
||||
input_dcs_dispatch(struct input_ctx *ictx)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
u_char *buf = ictx->input_buf;
|
||||
size_t len = ictx->input_len;
|
||||
const char prefix[] = "tmux;";
|
||||
const u_int prefixlen = (sizeof prefix) - 1;
|
||||
|
||||
if (wp == NULL)
|
||||
return (0);
|
||||
if (ictx->flags & INPUT_DISCARD)
|
||||
return (0);
|
||||
|
||||
if (!options_get_number(ictx->wp->options, "allow-passthrough"))
|
||||
return (0);
|
||||
log_debug("%s: \"%s\"", __func__, buf);
|
||||
|
||||
if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0)
|
||||
@@ -2304,8 +2323,7 @@ input_exit_osc(struct input_ctx *ictx)
|
||||
input_osc_11(ictx, p);
|
||||
break;
|
||||
case 12:
|
||||
if (utf8_isvalid(p) && *p != '?') /* ? is colour request */
|
||||
screen_set_cursor_colour(sctx->s, p);
|
||||
input_osc_12(ictx, p);
|
||||
break;
|
||||
case 52:
|
||||
input_osc_52(ictx, p);
|
||||
@@ -2320,8 +2338,7 @@ input_exit_osc(struct input_ctx *ictx)
|
||||
input_osc_111(ictx, p);
|
||||
break;
|
||||
case 112:
|
||||
if (*p == '\0') /* no arguments allowed */
|
||||
screen_set_cursor_colour(sctx->s, "");
|
||||
input_osc_112(ictx, p);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%u'", __func__, option);
|
||||
@@ -2374,6 +2391,7 @@ static void
|
||||
input_exit_rename(struct input_ctx *ictx)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
struct window *w;
|
||||
struct options_entry *o;
|
||||
|
||||
if (wp == NULL)
|
||||
@@ -2386,17 +2404,20 @@ input_exit_rename(struct input_ctx *ictx)
|
||||
|
||||
if (!utf8_isvalid(ictx->input_buf))
|
||||
return;
|
||||
w = wp->window;
|
||||
|
||||
if (ictx->input_len == 0) {
|
||||
o = options_get_only(wp->window->options, "automatic-rename");
|
||||
o = options_get_only(w->options, "automatic-rename");
|
||||
if (o != NULL)
|
||||
options_remove_or_default(o, -1, NULL);
|
||||
return;
|
||||
if (!options_get_number(w->options, "automatic-rename"))
|
||||
window_set_name(w, "");
|
||||
} else {
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
window_set_name(w, ictx->input_buf);
|
||||
}
|
||||
window_set_name(wp->window, ictx->input_buf);
|
||||
options_set_number(wp->window->options, "automatic-rename", 0);
|
||||
server_redraw_window_borders(wp->window);
|
||||
server_status_window(wp->window);
|
||||
server_redraw_window_borders(w);
|
||||
server_status_window(w);
|
||||
}
|
||||
|
||||
/* Open UTF-8 character. */
|
||||
@@ -2483,7 +2504,9 @@ input_osc_colour_reply(struct input_ctx *ictx, u_int n, int c)
|
||||
u_char r, g, b;
|
||||
const char *end;
|
||||
|
||||
if (c == 8 || (~c & COLOUR_FLAG_RGB))
|
||||
if (c != -1)
|
||||
c = colour_force_rgb(c);
|
||||
if (c == -1)
|
||||
return;
|
||||
colour_split_rgb(c, &r, &g, &b);
|
||||
|
||||
@@ -2491,44 +2514,49 @@ input_osc_colour_reply(struct input_ctx *ictx, u_int n, int c)
|
||||
end = "\007";
|
||||
else
|
||||
end = "\033\\";
|
||||
input_reply(ictx, "\033]%u;rgb:%02hhx/%02hhx/%02hhx%s", n, r, g, b, end);
|
||||
input_reply(ictx, "\033]%u;rgb:%02hhx%02hhx/%02hhx%02hhx/%02hhx%02hhx%s",
|
||||
n, r, r, g, g, b, b, end);
|
||||
}
|
||||
|
||||
/* Handle the OSC 4 sequence for setting (multiple) palette entries. */
|
||||
static void
|
||||
input_osc_4(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *copy, *s, *next = NULL;
|
||||
long idx;
|
||||
int c;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
char *copy, *s, *next = NULL;
|
||||
long idx;
|
||||
int c, bad = 0, redraw = 0;
|
||||
|
||||
copy = s = xstrdup(p);
|
||||
while (s != NULL && *s != '\0') {
|
||||
idx = strtol(s, &next, 10);
|
||||
if (*next++ != ';')
|
||||
goto bad;
|
||||
if (idx < 0 || idx >= 0x100)
|
||||
goto bad;
|
||||
if (*next++ != ';') {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
if (idx < 0 || idx >= 256) {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
s = strsep(&next, ";");
|
||||
if (strcmp(s, "?") == 0) {
|
||||
c = colour_palette_get(ictx->palette, idx);
|
||||
if (c != -1)
|
||||
input_osc_colour_reply(ictx, 4, c);
|
||||
continue;
|
||||
}
|
||||
if ((c = input_osc_parse_colour(s)) == -1) {
|
||||
s = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
window_pane_set_palette(wp, idx, c);
|
||||
if (colour_palette_set(ictx->palette, idx, c))
|
||||
redraw = 1;
|
||||
s = next;
|
||||
}
|
||||
|
||||
free(copy);
|
||||
return;
|
||||
|
||||
bad:
|
||||
log_debug("bad OSC 4: %s", p);
|
||||
if (bad)
|
||||
log_debug("bad OSC 4: %s", p);
|
||||
if (redraw)
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
free(copy);
|
||||
}
|
||||
|
||||
@@ -2540,40 +2568,40 @@ input_osc_10(struct input_ctx *ictx, const char *p)
|
||||
struct grid_cell defaults;
|
||||
int c;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (strcmp(p, "?") == 0) {
|
||||
tty_default_colours(&defaults, wp);
|
||||
input_osc_colour_reply(ictx, 10, defaults.fg);
|
||||
if (wp != NULL) {
|
||||
tty_default_colours(&defaults, wp);
|
||||
input_osc_colour_reply(ictx, 10, defaults.fg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((c = input_osc_parse_colour(p)) == -1)
|
||||
goto bad;
|
||||
wp->fg = c;
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
|
||||
return;
|
||||
|
||||
bad:
|
||||
log_debug("bad OSC 10: %s", p);
|
||||
if ((c = input_osc_parse_colour(p)) == -1) {
|
||||
log_debug("bad OSC 10: %s", p);
|
||||
return;
|
||||
}
|
||||
if (ictx->palette != NULL) {
|
||||
ictx->palette->fg = c;
|
||||
if (wp != NULL)
|
||||
wp->flags |= PANE_STYLECHANGED;
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the OSC 110 sequence for resetting background colour. */
|
||||
/* Handle the OSC 110 sequence for resetting foreground colour. */
|
||||
static void
|
||||
input_osc_110(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (*p != '\0')
|
||||
return;
|
||||
|
||||
wp->fg = 8;
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
if (ictx->palette != NULL) {
|
||||
ictx->palette->fg = 8;
|
||||
if (wp != NULL)
|
||||
wp->flags |= PANE_STYLECHANGED;
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the OSC 11 sequence for setting and querying background colour. */
|
||||
@@ -2584,24 +2612,24 @@ input_osc_11(struct input_ctx *ictx, const char *p)
|
||||
struct grid_cell defaults;
|
||||
int c;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (strcmp(p, "?") == 0) {
|
||||
tty_default_colours(&defaults, wp);
|
||||
input_osc_colour_reply(ictx, 11, defaults.bg);
|
||||
if (wp != NULL) {
|
||||
tty_default_colours(&defaults, wp);
|
||||
input_osc_colour_reply(ictx, 11, defaults.bg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((c = input_osc_parse_colour(p)) == -1)
|
||||
goto bad;
|
||||
wp->bg = c;
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
|
||||
return;
|
||||
|
||||
bad:
|
||||
log_debug("bad OSC 11: %s", p);
|
||||
if ((c = input_osc_parse_colour(p)) == -1) {
|
||||
log_debug("bad OSC 11: %s", p);
|
||||
return;
|
||||
}
|
||||
if (ictx->palette != NULL) {
|
||||
ictx->palette->bg = c;
|
||||
if (wp != NULL)
|
||||
wp->flags |= PANE_STYLECHANGED;
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the OSC 111 sequence for resetting background colour. */
|
||||
@@ -2610,24 +2638,57 @@ input_osc_111(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
|
||||
if (*p != '\0')
|
||||
return;
|
||||
|
||||
wp->bg = 8;
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
if (ictx->palette != NULL) {
|
||||
ictx->palette->bg = 8;
|
||||
if (wp != NULL)
|
||||
wp->flags |= PANE_STYLECHANGED;
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle the OSC 12 sequence for setting and querying cursor colour. */
|
||||
static void
|
||||
input_osc_12(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
int c;
|
||||
|
||||
if (strcmp(p, "?") == 0) {
|
||||
if (wp != NULL) {
|
||||
c = ictx->ctx.s->ccolour;
|
||||
if (c == -1)
|
||||
c = ictx->ctx.s->default_ccolour;
|
||||
input_osc_colour_reply(ictx, 12, c);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ((c = input_osc_parse_colour(p)) == -1) {
|
||||
log_debug("bad OSC 12: %s", p);
|
||||
return;
|
||||
}
|
||||
screen_set_cursor_colour(ictx->ctx.s, c);
|
||||
}
|
||||
|
||||
/* Handle the OSC 112 sequence for resetting cursor colour. */
|
||||
static void
|
||||
input_osc_112(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
if (*p == '\0') /* no arguments allowed */
|
||||
screen_set_cursor_colour(ictx->ctx.s, -1);
|
||||
}
|
||||
|
||||
|
||||
/* Handle the OSC 52 sequence for setting the clipboard. */
|
||||
static void
|
||||
input_osc_52(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *end;
|
||||
const char *buf;
|
||||
size_t len;
|
||||
const char *buf = NULL;
|
||||
size_t len = 0;
|
||||
u_char *out;
|
||||
int outlen, state;
|
||||
struct screen_write_ctx ctx;
|
||||
@@ -2647,26 +2708,12 @@ input_osc_52(struct input_ctx *ictx, const char *p)
|
||||
log_debug("%s: %s", __func__, end);
|
||||
|
||||
if (strcmp(end, "?") == 0) {
|
||||
if ((pb = paste_get_top(NULL)) != NULL) {
|
||||
if ((pb = paste_get_top(NULL)) != NULL)
|
||||
buf = paste_buffer_data(pb, &len);
|
||||
outlen = 4 * ((len + 2) / 3) + 1;
|
||||
out = xmalloc(outlen);
|
||||
if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
|
||||
free(out);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
outlen = 0;
|
||||
out = NULL;
|
||||
}
|
||||
bufferevent_write(ictx->event, "\033]52;;", 6);
|
||||
if (outlen != 0)
|
||||
bufferevent_write(ictx->event, out, outlen);
|
||||
if (ictx->input_end == INPUT_END_BEL)
|
||||
bufferevent_write(ictx->event, "\007", 1);
|
||||
input_reply_clipboard(ictx->event, buf, len, "\007");
|
||||
else
|
||||
bufferevent_write(ictx->event, "\033\\", 2);
|
||||
free(out);
|
||||
input_reply_clipboard(ictx->event, buf, len, "\033\\");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2692,34 +2739,58 @@ input_osc_52(struct input_ctx *ictx, const char *p)
|
||||
static void
|
||||
input_osc_104(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *copy, *s;
|
||||
long idx;
|
||||
|
||||
if (wp == NULL)
|
||||
return;
|
||||
char *copy, *s;
|
||||
long idx;
|
||||
int bad = 0, redraw = 0;
|
||||
|
||||
if (*p == '\0') {
|
||||
window_pane_reset_palette(wp);
|
||||
colour_palette_clear(ictx->palette);
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
copy = s = xstrdup(p);
|
||||
while (*s != '\0') {
|
||||
idx = strtol(s, &s, 10);
|
||||
if (*s != '\0' && *s != ';')
|
||||
goto bad;
|
||||
if (idx < 0 || idx >= 0x100)
|
||||
goto bad;
|
||||
|
||||
window_pane_unset_palette(wp, idx);
|
||||
if (*s != '\0' && *s != ';') {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
if (idx < 0 || idx >= 256) {
|
||||
bad = 1;
|
||||
break;
|
||||
}
|
||||
if (colour_palette_set(ictx->palette, idx, -1))
|
||||
redraw = 1;
|
||||
if (*s == ';')
|
||||
s++;
|
||||
}
|
||||
free(copy);
|
||||
return;
|
||||
|
||||
bad:
|
||||
log_debug("bad OSC 104: %s", p);
|
||||
if (bad)
|
||||
log_debug("bad OSC 104: %s", p);
|
||||
if (redraw)
|
||||
screen_write_fullredraw(&ictx->ctx);
|
||||
free(copy);
|
||||
}
|
||||
|
||||
void
|
||||
input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
|
||||
const char *end)
|
||||
{
|
||||
char *out = NULL;
|
||||
size_t outlen = 0;
|
||||
|
||||
if (buf != NULL && len != 0) {
|
||||
outlen = 4 * ((len + 2) / 3) + 1;
|
||||
out = xmalloc(outlen);
|
||||
if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
|
||||
free(out);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bufferevent_write(bev, "\033]52;;", 6);
|
||||
if (outlen != 0)
|
||||
bufferevent_write(bev, out, outlen);
|
||||
bufferevent_write(bev, end, strlen(end));
|
||||
free(out);
|
||||
}
|
||||
|
||||
38
job.c
38
job.c
@@ -50,6 +50,7 @@ struct job {
|
||||
|
||||
char *cmd;
|
||||
pid_t pid;
|
||||
char tty[TTY_NAME_MAX];
|
||||
int status;
|
||||
|
||||
int fd;
|
||||
@@ -68,7 +69,7 @@ static LIST_HEAD(joblist, job) all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
|
||||
/* Start a job running. */
|
||||
struct job *
|
||||
job_run(const char *cmd, int argc, char **argv, struct session *s,
|
||||
job_run(const char *cmd, int argc, char **argv, struct environ *e, struct session *s,
|
||||
const char *cwd, job_update_cb updatecb, job_complete_cb completecb,
|
||||
job_free_cb freecb, void *data, int flags, int sx, int sy)
|
||||
{
|
||||
@@ -79,13 +80,15 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
|
||||
const char *home;
|
||||
sigset_t set, oldset;
|
||||
struct winsize ws;
|
||||
char **argvp;
|
||||
char **argvp, tty[TTY_NAME_MAX];
|
||||
|
||||
/*
|
||||
* Do not set TERM during .tmux.conf, it is nice to be able to use
|
||||
* if-shell to decide on default-terminal based on outside TERM.
|
||||
*/
|
||||
env = environ_for_session(s, !cfg_finished);
|
||||
if (e != NULL)
|
||||
environ_copy(e, env);
|
||||
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
@@ -94,7 +97,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
|
||||
memset(&ws, 0, sizeof ws);
|
||||
ws.ws_col = sx;
|
||||
ws.ws_row = sy;
|
||||
pid = fdforkpty(ptm_fd, &master, NULL, NULL, &ws);
|
||||
pid = fdforkpty(ptm_fd, &master, tty, NULL, &ws);
|
||||
} else {
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
|
||||
goto fail;
|
||||
@@ -136,7 +139,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
|
||||
close(out[1]);
|
||||
close(out[0]);
|
||||
|
||||
nullfd = open(_PATH_DEVNULL, O_RDWR, 0);
|
||||
nullfd = open(_PATH_DEVNULL, O_RDWR);
|
||||
if (nullfd == -1)
|
||||
fatal("open failed");
|
||||
if (dup2(nullfd, STDERR_FILENO) == -1)
|
||||
@@ -168,6 +171,7 @@ job_run(const char *cmd, int argc, char **argv, struct session *s,
|
||||
else
|
||||
job->cmd = cmd_stringify_argv(argc, argv);
|
||||
job->pid = pid;
|
||||
strlcpy(job->tty, tty, sizeof job->tty);
|
||||
job->status = 0;
|
||||
|
||||
LIST_INSERT_HEAD(&all_jobs, job, entry);
|
||||
@@ -199,6 +203,32 @@ fail:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/* Take job's file descriptor and free the job. */
|
||||
int
|
||||
job_transfer(struct job *job, pid_t *pid, char *tty, size_t ttylen)
|
||||
{
|
||||
int fd = job->fd;
|
||||
|
||||
log_debug("transfer job %p: %s", job, job->cmd);
|
||||
|
||||
if (pid != NULL)
|
||||
*pid = job->pid;
|
||||
if (tty != NULL)
|
||||
strlcpy(tty, job->tty, ttylen);
|
||||
|
||||
LIST_REMOVE(job, entry);
|
||||
free(job->cmd);
|
||||
|
||||
if (job->freecb != NULL && job->data != NULL)
|
||||
job->freecb(job->data);
|
||||
|
||||
if (job->event != NULL)
|
||||
bufferevent_free(job->event);
|
||||
|
||||
free(job);
|
||||
return (fd);
|
||||
}
|
||||
|
||||
/* Kill and free an individual job. */
|
||||
void
|
||||
job_free(struct job *job)
|
||||
|
||||
519
key-bindings.c
519
key-bindings.c
@@ -29,7 +29,7 @@
|
||||
" 'Previous' 'p' {switch-client -p}" \
|
||||
" ''" \
|
||||
" 'Renumber' 'N' {move-window -r}" \
|
||||
" 'Rename' 'n' {command-prompt -I \"#S\" \"rename-session -- '%%'\"}" \
|
||||
" 'Rename' 'n' {command-prompt -I \"#S\" {rename-session -- '%%'}}" \
|
||||
" ''" \
|
||||
" 'New Session' 's' {new-session}" \
|
||||
" 'New Window' 'w' {new-window}"
|
||||
@@ -41,7 +41,7 @@
|
||||
" 'Kill' 'X' {kill-window}" \
|
||||
" 'Respawn' 'R' {respawn-window -k}" \
|
||||
" '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
|
||||
" 'Rename' 'n' {command-prompt -I \"#W\" \"rename-window -- '%%'\"}" \
|
||||
" 'Rename' 'n' {command-prompt -FI \"#W\" {rename-window -t '#{window_id}' -- '%%'}}" \
|
||||
" ''" \
|
||||
" 'New After' 'w' {new-window -a}" \
|
||||
" 'New At End' 'W' {new-window}"
|
||||
@@ -187,6 +187,7 @@ key_bindings_add(const char *name, key_code key, const char *note, int repeat,
|
||||
{
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
char *s;
|
||||
|
||||
table = key_bindings_get_table(name, 1);
|
||||
|
||||
@@ -216,8 +217,10 @@ key_bindings_add(const char *name, key_code key, const char *note, int repeat,
|
||||
bd->flags |= KEY_BINDING_REPEAT;
|
||||
bd->cmdlist = cmdlist;
|
||||
|
||||
s = cmd_list_print(bd->cmdlist, 0);
|
||||
log_debug("%s: %#llx %s = %s", __func__, bd->key,
|
||||
key_string_lookup_key(bd->key, 1), cmd_list_print(bd->cmdlist, 0));
|
||||
key_string_lookup_key(bd->key, 1), s);
|
||||
free(s);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -340,299 +343,303 @@ key_bindings_init(void)
|
||||
{
|
||||
static const char *defaults[] = {
|
||||
/* Prefix keys. */
|
||||
"bind -N 'Send the prefix key' C-b send-prefix",
|
||||
"bind -N 'Rotate through the panes' C-o rotate-window",
|
||||
"bind -N 'Suspend the current client' C-z suspend-client",
|
||||
"bind -N 'Select next layout' Space next-layout",
|
||||
"bind -N 'Break pane to a new window' ! break-pane",
|
||||
"bind -N 'Split window vertically' '\"' split-window",
|
||||
"bind -N 'List all paste buffers' '#' list-buffers",
|
||||
"bind -N 'Rename current session' '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
|
||||
"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 -Wpindex \"select-window -t ':%%'\"",
|
||||
"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 -- '%%'\"",
|
||||
"bind -N 'Delete the most recent paste buffer' - delete-buffer",
|
||||
"bind -N 'Move the current window' . command-prompt -T \"move-window -t '%%'\"",
|
||||
"bind -N 'Describe key binding' '/' command-prompt -kpkey 'list-keys -1N \"%%%\"'",
|
||||
"bind -N 'Select window 0' 0 select-window -t:=0",
|
||||
"bind -N 'Select window 1' 1 select-window -t:=1",
|
||||
"bind -N 'Select window 2' 2 select-window -t:=2",
|
||||
"bind -N 'Select window 3' 3 select-window -t:=3",
|
||||
"bind -N 'Select window 4' 4 select-window -t:=4",
|
||||
"bind -N 'Select window 5' 5 select-window -t:=5",
|
||||
"bind -N 'Select window 6' 6 select-window -t:=6",
|
||||
"bind -N 'Select window 7' 7 select-window -t:=7",
|
||||
"bind -N 'Select window 8' 8 select-window -t:=8",
|
||||
"bind -N 'Select window 9' 9 select-window -t:=9",
|
||||
"bind -N 'Prompt for a command' : command-prompt",
|
||||
"bind -N 'Move to the previously active pane' \\; last-pane",
|
||||
"bind -N 'Choose a paste buffer from a list' = choose-buffer -Z",
|
||||
"bind -N 'List key bindings' ? list-keys -N",
|
||||
"bind -N 'Choose a client from a list' D choose-client -Z",
|
||||
"bind -N 'Spread panes out evenly' E select-layout -E",
|
||||
"bind -N 'Switch to the last client' L switch-client -l",
|
||||
"bind -N 'Clear the marked pane' M select-pane -M",
|
||||
"bind -N 'Enter copy mode' [ copy-mode",
|
||||
"bind -N 'Paste the most recent paste buffer' ] paste-buffer -p",
|
||||
"bind -N 'Create a new window' c new-window",
|
||||
"bind -N 'Detach the current client' d detach-client",
|
||||
"bind -N 'Search for a pane' f command-prompt \"find-window -Z -- '%%'\"",
|
||||
"bind -N 'Display window information' i display-message",
|
||||
"bind -N 'Select the previously current window' l last-window",
|
||||
"bind -N 'Toggle the marked pane' m select-pane -m",
|
||||
"bind -N 'Select the next window' n next-window",
|
||||
"bind -N 'Select the next pane' o select-pane -t:.+",
|
||||
"bind -N 'Customize options' C customize-mode -Z",
|
||||
"bind -N 'Select the previous window' p previous-window",
|
||||
"bind -N 'Display pane numbers' q display-panes",
|
||||
"bind -N 'Redraw the current client' r refresh-client",
|
||||
"bind -N 'Choose a session from a list' s choose-tree -Zs",
|
||||
"bind -N 'Show a clock' t clock-mode",
|
||||
"bind -N 'Choose a window from a list' w choose-tree -Zw",
|
||||
"bind -N 'Kill the active pane' x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
|
||||
"bind -N 'Zoom the active pane' z resize-pane -Z",
|
||||
"bind -N 'Swap the active pane with the pane above' '{' swap-pane -U",
|
||||
"bind -N 'Swap the active pane with the pane below' '}' swap-pane -D",
|
||||
"bind -N 'Show messages' '~' show-messages",
|
||||
"bind -N 'Enter copy mode and scroll up' PPage copy-mode -u",
|
||||
"bind -N 'Select the pane above the active pane' -r Up select-pane -U",
|
||||
"bind -N 'Select the pane below the active pane' -r Down select-pane -D",
|
||||
"bind -N 'Select the pane to the left of the active pane' -r Left select-pane -L",
|
||||
"bind -N 'Select the pane to the right of the active pane' -r Right select-pane -R",
|
||||
"bind -N 'Set the even-horizontal layout' M-1 select-layout even-horizontal",
|
||||
"bind -N 'Set the even-vertical layout' M-2 select-layout even-vertical",
|
||||
"bind -N 'Set the main-horizontal layout' M-3 select-layout main-horizontal",
|
||||
"bind -N 'Set the main-vertical layout' M-4 select-layout main-vertical",
|
||||
"bind -N 'Select the tiled layout' M-5 select-layout tiled",
|
||||
"bind -N 'Select the next window with an alert' M-n next-window -a",
|
||||
"bind -N 'Rotate through the panes in reverse' M-o rotate-window -D",
|
||||
"bind -N 'Select the previous window with an alert' M-p previous-window -a",
|
||||
"bind -N 'Move the visible part of the window up' -r S-Up refresh-client -U 10",
|
||||
"bind -N 'Move the visible part of the window down' -r S-Down refresh-client -D 10",
|
||||
"bind -N 'Move the visible part of the window left' -r S-Left refresh-client -L 10",
|
||||
"bind -N 'Move the visible part of the window right' -r S-Right refresh-client -R 10",
|
||||
"bind -N 'Reset so the visible part of the window follows the cursor' -r DC refresh-client -c",
|
||||
"bind -N 'Resize the pane up by 5' -r M-Up resize-pane -U 5",
|
||||
"bind -N 'Resize the pane down by 5' -r M-Down resize-pane -D 5",
|
||||
"bind -N 'Resize the pane left by 5' -r M-Left resize-pane -L 5",
|
||||
"bind -N 'Resize the pane right by 5' -r M-Right resize-pane -R 5",
|
||||
"bind -N 'Resize the pane up' -r C-Up resize-pane -U",
|
||||
"bind -N 'Resize the pane down' -r C-Down resize-pane -D",
|
||||
"bind -N 'Resize the pane left' -r C-Left resize-pane -L",
|
||||
"bind -N 'Resize the pane right' -r C-Right resize-pane -R",
|
||||
"bind -N 'Send the prefix key' C-b { send-prefix }",
|
||||
"bind -N 'Rotate through the panes' C-o { rotate-window }",
|
||||
"bind -N 'Suspend the current client' C-z { suspend-client }",
|
||||
"bind -N 'Select next layout' Space { next-layout }",
|
||||
"bind -N 'Break pane to a new window' ! { break-pane }",
|
||||
"bind -N 'Split window vertically' '\"' { split-window }",
|
||||
"bind -N 'List all paste buffers' '#' { list-buffers }",
|
||||
"bind -N 'Rename current session' '$' { command-prompt -I'#S' { rename-session -- '%%' } }",
|
||||
"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 '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 -- '%%' } }",
|
||||
"bind -N 'Delete the most recent paste buffer' - { delete-buffer }",
|
||||
"bind -N 'Move the current window' . { command-prompt -T target { move-window -t '%%' } }",
|
||||
"bind -N 'Describe key binding' '/' { command-prompt -kpkey { list-keys -1N '%%' } }",
|
||||
"bind -N 'Select window 0' 0 { select-window -t:=0 }",
|
||||
"bind -N 'Select window 1' 1 { select-window -t:=1 }",
|
||||
"bind -N 'Select window 2' 2 { select-window -t:=2 }",
|
||||
"bind -N 'Select window 3' 3 { select-window -t:=3 }",
|
||||
"bind -N 'Select window 4' 4 { select-window -t:=4 }",
|
||||
"bind -N 'Select window 5' 5 { select-window -t:=5 }",
|
||||
"bind -N 'Select window 6' 6 { select-window -t:=6 }",
|
||||
"bind -N 'Select window 7' 7 { select-window -t:=7 }",
|
||||
"bind -N 'Select window 8' 8 { select-window -t:=8 }",
|
||||
"bind -N 'Select window 9' 9 { select-window -t:=9 }",
|
||||
"bind -N 'Prompt for a command' : { command-prompt }",
|
||||
"bind -N 'Move to the previously active pane' \\; { last-pane }",
|
||||
"bind -N 'Choose a paste buffer from a list' = { choose-buffer -Z }",
|
||||
"bind -N 'List key bindings' ? { list-keys -N }",
|
||||
"bind -N 'Choose a client from a list' D { choose-client -Z }",
|
||||
"bind -N 'Spread panes out evenly' E { select-layout -E }",
|
||||
"bind -N 'Switch to the last client' L { switch-client -l }",
|
||||
"bind -N 'Clear the marked pane' M { select-pane -M }",
|
||||
"bind -N 'Enter copy mode' [ { copy-mode }",
|
||||
"bind -N 'Paste the most recent paste buffer' ] { paste-buffer -p }",
|
||||
"bind -N 'Create a new window' c { new-window }",
|
||||
"bind -N 'Detach the current client' d { detach-client }",
|
||||
"bind -N 'Search for a pane' f { command-prompt { find-window -Z -- '%%' } }",
|
||||
"bind -N 'Display window information' i { display-message }",
|
||||
"bind -N 'Select the previously current window' l { last-window }",
|
||||
"bind -N 'Toggle the marked pane' m { select-pane -m }",
|
||||
"bind -N 'Select the next window' n { next-window }",
|
||||
"bind -N 'Select the next pane' o { select-pane -t:.+ }",
|
||||
"bind -N 'Customize options' C { customize-mode -Z }",
|
||||
"bind -N 'Select the previous window' p { previous-window }",
|
||||
"bind -N 'Display pane numbers' q { display-panes }",
|
||||
"bind -N 'Redraw the current client' r { refresh-client }",
|
||||
"bind -N 'Choose a session from a list' s { choose-tree -Zs }",
|
||||
"bind -N 'Show a clock' t { clock-mode }",
|
||||
"bind -N 'Choose a window from a list' w { choose-tree -Zw }",
|
||||
"bind -N 'Kill the active pane' x { confirm-before -p\"kill-pane #P? (y/n)\" kill-pane }",
|
||||
"bind -N 'Zoom the active pane' z { resize-pane -Z }",
|
||||
"bind -N 'Swap the active pane with the pane above' '{' { swap-pane -U }",
|
||||
"bind -N 'Swap the active pane with the pane below' '}' { swap-pane -D }",
|
||||
"bind -N 'Show messages' '~' { show-messages }",
|
||||
"bind -N 'Enter copy mode and scroll up' PPage { copy-mode -u }",
|
||||
"bind -N 'Select the pane above the active pane' -r Up { select-pane -U }",
|
||||
"bind -N 'Select the pane below the active pane' -r Down { select-pane -D }",
|
||||
"bind -N 'Select the pane to the left of the active pane' -r Left { select-pane -L }",
|
||||
"bind -N 'Select the pane to the right of the active pane' -r Right { select-pane -R }",
|
||||
"bind -N 'Set the even-horizontal layout' M-1 { select-layout even-horizontal }",
|
||||
"bind -N 'Set the even-vertical layout' M-2 { select-layout even-vertical }",
|
||||
"bind -N 'Set the main-horizontal layout' M-3 { select-layout main-horizontal }",
|
||||
"bind -N 'Set the main-vertical layout' M-4 { select-layout main-vertical }",
|
||||
"bind -N 'Select the tiled layout' M-5 { select-layout tiled }",
|
||||
"bind -N 'Select the next window with an alert' M-n { next-window -a }",
|
||||
"bind -N 'Rotate through the panes in reverse' M-o { rotate-window -D }",
|
||||
"bind -N 'Select the previous window with an alert' M-p { previous-window -a }",
|
||||
"bind -N 'Move the visible part of the window up' -r S-Up { refresh-client -U 10 }",
|
||||
"bind -N 'Move the visible part of the window down' -r S-Down { refresh-client -D 10 }",
|
||||
"bind -N 'Move the visible part of the window left' -r S-Left { refresh-client -L 10 }",
|
||||
"bind -N 'Move the visible part of the window right' -r S-Right { refresh-client -R 10 }",
|
||||
"bind -N 'Reset so the visible part of the window follows the cursor' -r DC { refresh-client -c }",
|
||||
"bind -N 'Resize the pane up by 5' -r M-Up { resize-pane -U 5 }",
|
||||
"bind -N 'Resize the pane down by 5' -r M-Down { resize-pane -D 5 }",
|
||||
"bind -N 'Resize the pane left by 5' -r M-Left { resize-pane -L 5 }",
|
||||
"bind -N 'Resize the pane right by 5' -r M-Right { resize-pane -R 5 }",
|
||||
"bind -N 'Resize the pane up' -r C-Up { resize-pane -U }",
|
||||
"bind -N 'Resize the pane down' -r C-Down { resize-pane -D }",
|
||||
"bind -N 'Resize the pane left' -r C-Left { resize-pane -L }",
|
||||
"bind -N 'Resize the pane right' -r C-Right { resize-pane -R }",
|
||||
|
||||
/* Menu keys */
|
||||
"bind < display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU,
|
||||
"bind > display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU,
|
||||
"bind < { display-menu -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU " }",
|
||||
"bind > { display-menu -xP -yP -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
|
||||
|
||||
/* Mouse button 1 down on pane. */
|
||||
"bind -n MouseDown1Pane select-pane -t=\\; send -M",
|
||||
"bind -n MouseDown1Pane { select-pane -t=; send -M }",
|
||||
|
||||
/* Mouse button 1 drag on pane. */
|
||||
"bind -n MouseDrag1Pane if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M }",
|
||||
"bind -n MouseDrag1Pane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -M } }",
|
||||
|
||||
/* Mouse wheel up on pane. */
|
||||
"bind -n WheelUpPane if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e }",
|
||||
"bind -n WheelUpPane { if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -e } }",
|
||||
|
||||
/* Mouse button 2 down on pane. */
|
||||
"bind -n MouseDown2Pane select-pane -t=\\; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p }",
|
||||
"bind -n MouseDown2Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { paste -p } }",
|
||||
|
||||
/* Mouse button 1 double click on pane. */
|
||||
"bind -n DoubleClick1Pane select-pane -t=\\; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
|
||||
"bind -n DoubleClick1Pane { select-pane -t=; if -F '#{||:#{pane_in_mode},#{mouse_any_flag}}' { send -M } { copy-mode -H; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel } }",
|
||||
|
||||
/* 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 }",
|
||||
"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 drag on border. */
|
||||
"bind -n MouseDrag1Border resize-pane -M",
|
||||
"bind -n MouseDrag1Border { resize-pane -M }",
|
||||
|
||||
/* Mouse button 1 down on status line. */
|
||||
"bind -n MouseDown1Status select-window -t=",
|
||||
"bind -n MouseDown1Status { select-window -t= }",
|
||||
|
||||
/* Mouse wheel down on status line. */
|
||||
"bind -n WheelDownStatus next-window",
|
||||
"bind -n WheelDownStatus { next-window }",
|
||||
|
||||
/* Mouse wheel up on status line. */
|
||||
"bind -n WheelUpStatus previous-window",
|
||||
"bind -n WheelUpStatus { previous-window }",
|
||||
|
||||
/* Mouse button 3 down on status left. */
|
||||
"bind -n MouseDown3StatusLeft display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU,
|
||||
"bind -n MouseDown3StatusLeft { display-menu -t= -xM -yW -T '#[align=centre]#{session_name}' " DEFAULT_SESSION_MENU " }",
|
||||
|
||||
/* Mouse button 3 down on status line. */
|
||||
"bind -n MouseDown3Status display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU,
|
||||
"bind -n MouseDown3Status { display-menu -t= -xW -yW -T '#[align=centre]#{window_index}:#{window_name}' " DEFAULT_WINDOW_MENU "}",
|
||||
|
||||
/* Mouse button 3 down on pane. */
|
||||
"bind -n MouseDown3Pane if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
|
||||
"bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU,
|
||||
"bind -n MouseDown3Pane { if -Ft= '#{||:#{mouse_any_flag},#{&&:#{pane_in_mode},#{?#{m/r:(copy|view)-mode,#{pane_mode}},0,1}}}' { select-pane -t=; send -M } { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " } }",
|
||||
"bind -n M-MouseDown3Pane { display-menu -t= -xM -yM -T '#[align=centre]#{pane_index} (#{pane_id})' " DEFAULT_PANE_MENU " }",
|
||||
|
||||
/* Copy mode (emacs) keys. */
|
||||
"bind -Tcopy-mode C-Space send -X begin-selection",
|
||||
"bind -Tcopy-mode C-a send -X start-of-line",
|
||||
"bind -Tcopy-mode C-c send -X cancel",
|
||||
"bind -Tcopy-mode C-e send -X end-of-line",
|
||||
"bind -Tcopy-mode C-f send -X cursor-right",
|
||||
"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-end-of-line",
|
||||
"bind -Tcopy-mode C-n send -X cursor-down",
|
||||
"bind -Tcopy-mode C-p send -X cursor-up",
|
||||
"bind -Tcopy-mode C-r command-prompt -ip'(search up)' -I'#{pane_search_string}' 'send -X search-backward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-s command-prompt -ip'(search down)' -I'#{pane_search_string}' 'send -X search-forward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-v send -X page-down",
|
||||
"bind -Tcopy-mode C-w send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode Escape 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",
|
||||
"bind -Tcopy-mode F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode N send -X search-reverse",
|
||||
"bind -Tcopy-mode R send -X rectangle-toggle",
|
||||
"bind -Tcopy-mode T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode X send -X set-mark",
|
||||
"bind -Tcopy-mode f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode g command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode n send -X search-again",
|
||||
"bind -Tcopy-mode q send -X cancel",
|
||||
"bind -Tcopy-mode r send -X refresh-from-pane",
|
||||
"bind -Tcopy-mode t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode Home send -X start-of-line",
|
||||
"bind -Tcopy-mode End send -X end-of-line",
|
||||
"bind -Tcopy-mode C-Space { send -X begin-selection }",
|
||||
"bind -Tcopy-mode C-a { send -X start-of-line }",
|
||||
"bind -Tcopy-mode C-c { send -X cancel }",
|
||||
"bind -Tcopy-mode C-e { send -X end-of-line }",
|
||||
"bind -Tcopy-mode C-f { send -X cursor-right }",
|
||||
"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-n { send -X cursor-down }",
|
||||
"bind -Tcopy-mode C-p { send -X cursor-up }",
|
||||
"bind -Tcopy-mode C-r { command-prompt -T search -ip'(search up)' -I'#{pane_search_string}' { send -X search-backward-incremental '%%' } }",
|
||||
"bind -Tcopy-mode C-s { command-prompt -T search -ip'(search down)' -I'#{pane_search_string}' { send -X search-forward-incremental '%%' } }",
|
||||
"bind -Tcopy-mode C-v { send -X page-down }",
|
||||
"bind -Tcopy-mode C-w { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode Escape { 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 }",
|
||||
"bind -Tcopy-mode F { command-prompt -1p'(jump backward)' { send -X jump-backward '%%' } }",
|
||||
"bind -Tcopy-mode N { send -X search-reverse }",
|
||||
"bind -Tcopy-mode P { send -X toggle-position }",
|
||||
"bind -Tcopy-mode R { send -X rectangle-toggle }",
|
||||
"bind -Tcopy-mode T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward '%%' } }",
|
||||
"bind -Tcopy-mode X { send -X set-mark }",
|
||||
"bind -Tcopy-mode f { command-prompt -1p'(jump forward)' { send -X jump-forward '%%' } }",
|
||||
"bind -Tcopy-mode g { command-prompt -p'(goto line)' { send -X goto-line '%%' } }",
|
||||
"bind -Tcopy-mode n { send -X search-again }",
|
||||
"bind -Tcopy-mode q { send -X cancel }",
|
||||
"bind -Tcopy-mode r { send -X refresh-from-pane }",
|
||||
"bind -Tcopy-mode t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward '%%' } }",
|
||||
"bind -Tcopy-mode Home { send -X start-of-line }",
|
||||
"bind -Tcopy-mode End { send -X end-of-line }",
|
||||
"bind -Tcopy-mode MouseDown1Pane select-pane",
|
||||
"bind -Tcopy-mode MouseDrag1Pane select-pane\\; send -X begin-selection",
|
||||
"bind -Tcopy-mode MouseDragEnd1Pane send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode WheelUpPane select-pane\\; send -N5 -X scroll-up",
|
||||
"bind -Tcopy-mode WheelDownPane select-pane\\; send -N5 -X scroll-down",
|
||||
"bind -Tcopy-mode DoubleClick1Pane select-pane\\; send -X select-word\\; run -d0.3\\; send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode TripleClick1Pane select-pane\\; send -X select-line\\; run -d0.3\\; send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode NPage send -X page-down",
|
||||
"bind -Tcopy-mode PPage send -X page-up",
|
||||
"bind -Tcopy-mode Up send -X cursor-up",
|
||||
"bind -Tcopy-mode Down send -X cursor-down",
|
||||
"bind -Tcopy-mode Left send -X cursor-left",
|
||||
"bind -Tcopy-mode Right send -X cursor-right",
|
||||
"bind -Tcopy-mode M-1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-< send -X history-top",
|
||||
"bind -Tcopy-mode M-> send -X history-bottom",
|
||||
"bind -Tcopy-mode M-R send -X top-line",
|
||||
"bind -Tcopy-mode M-b send -X previous-word",
|
||||
"bind -Tcopy-mode C-M-b send -X previous-matching-bracket",
|
||||
"bind -Tcopy-mode M-f send -X next-word-end",
|
||||
"bind -Tcopy-mode C-M-f send -X next-matching-bracket",
|
||||
"bind -Tcopy-mode M-m send -X back-to-indentation",
|
||||
"bind -Tcopy-mode M-r send -X middle-line",
|
||||
"bind -Tcopy-mode M-v send -X page-up",
|
||||
"bind -Tcopy-mode M-w send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode M-x send -X jump-to-mark",
|
||||
"bind -Tcopy-mode 'M-{' send -X previous-paragraph",
|
||||
"bind -Tcopy-mode 'M-}' send -X next-paragraph",
|
||||
"bind -Tcopy-mode M-Up send -X halfpage-up",
|
||||
"bind -Tcopy-mode M-Down send -X halfpage-down",
|
||||
"bind -Tcopy-mode C-Up send -X scroll-up",
|
||||
"bind -Tcopy-mode C-Down send -X scroll-down",
|
||||
"bind -Tcopy-mode MouseDrag1Pane { select-pane; send -X begin-selection }",
|
||||
"bind -Tcopy-mode MouseDragEnd1Pane { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode WheelUpPane { select-pane; send -N5 -X scroll-up }",
|
||||
"bind -Tcopy-mode WheelDownPane { select-pane; send -N5 -X scroll-down }",
|
||||
"bind -Tcopy-mode DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode NPage { send -X page-down }",
|
||||
"bind -Tcopy-mode PPage { send -X page-up }",
|
||||
"bind -Tcopy-mode Up { send -X cursor-up }",
|
||||
"bind -Tcopy-mode Down { send -X cursor-down }",
|
||||
"bind -Tcopy-mode Left { send -X cursor-left }",
|
||||
"bind -Tcopy-mode Right { send -X cursor-right }",
|
||||
"bind -Tcopy-mode M-1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-3 { command-prompt -Np'(repeat)' -I3 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-4 { command-prompt -Np'(repeat)' -I4 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-5 { command-prompt -Np'(repeat)' -I5 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-6 { command-prompt -Np'(repeat)' -I6 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode M-< { send -X history-top }",
|
||||
"bind -Tcopy-mode M-> { send -X history-bottom }",
|
||||
"bind -Tcopy-mode M-R { send -X top-line }",
|
||||
"bind -Tcopy-mode M-b { send -X previous-word }",
|
||||
"bind -Tcopy-mode C-M-b { send -X previous-matching-bracket }",
|
||||
"bind -Tcopy-mode M-f { send -X next-word-end }",
|
||||
"bind -Tcopy-mode C-M-f { send -X next-matching-bracket }",
|
||||
"bind -Tcopy-mode M-m { send -X back-to-indentation }",
|
||||
"bind -Tcopy-mode M-r { send -X middle-line }",
|
||||
"bind -Tcopy-mode M-v { send -X page-up }",
|
||||
"bind -Tcopy-mode M-w { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode M-x { send -X jump-to-mark }",
|
||||
"bind -Tcopy-mode 'M-{' { send -X previous-paragraph }",
|
||||
"bind -Tcopy-mode 'M-}' { send -X next-paragraph }",
|
||||
"bind -Tcopy-mode M-Up { send -X halfpage-up }",
|
||||
"bind -Tcopy-mode M-Down { send -X halfpage-down }",
|
||||
"bind -Tcopy-mode C-Up { send -X scroll-up }",
|
||||
"bind -Tcopy-mode C-Down { send -X scroll-down }",
|
||||
|
||||
/* Copy mode (vi) keys. */
|
||||
"bind -Tcopy-mode-vi '#' send -FX search-backward '#{copy_cursor_word}'",
|
||||
"bind -Tcopy-mode-vi * send -FX search-forward '#{copy_cursor_word}'",
|
||||
"bind -Tcopy-mode-vi C-c send -X cancel",
|
||||
"bind -Tcopy-mode-vi C-d send -X halfpage-down",
|
||||
"bind -Tcopy-mode-vi C-e send -X scroll-down",
|
||||
"bind -Tcopy-mode-vi C-b send -X page-up",
|
||||
"bind -Tcopy-mode-vi C-f send -X page-down",
|
||||
"bind -Tcopy-mode-vi C-h send -X cursor-left",
|
||||
"bind -Tcopy-mode-vi C-j send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode-vi Enter send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode-vi C-u send -X halfpage-up",
|
||||
"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 Space send -X begin-selection",
|
||||
"bind -Tcopy-mode-vi '$' send -X end-of-line",
|
||||
"bind -Tcopy-mode-vi , send -X jump-reverse",
|
||||
"bind -Tcopy-mode-vi / command-prompt -p'(search down)' 'send -X search-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 0 send -X start-of-line",
|
||||
"bind -Tcopy-mode-vi 1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi : command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi \\; send -X jump-again",
|
||||
"bind -Tcopy-mode-vi ? command-prompt -p'(search up)' 'send -X search-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi A send -X append-selection-and-cancel",
|
||||
"bind -Tcopy-mode-vi B send -X previous-space",
|
||||
"bind -Tcopy-mode-vi D send -X copy-end-of-line",
|
||||
"bind -Tcopy-mode-vi E send -X next-space-end",
|
||||
"bind -Tcopy-mode-vi F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi G send -X history-bottom",
|
||||
"bind -Tcopy-mode-vi H send -X top-line",
|
||||
"bind -Tcopy-mode-vi J send -X scroll-down",
|
||||
"bind -Tcopy-mode-vi K send -X scroll-up",
|
||||
"bind -Tcopy-mode-vi L send -X bottom-line",
|
||||
"bind -Tcopy-mode-vi M send -X middle-line",
|
||||
"bind -Tcopy-mode-vi N send -X search-reverse",
|
||||
"bind -Tcopy-mode-vi T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi V send -X select-line",
|
||||
"bind -Tcopy-mode-vi W send -X next-space",
|
||||
"bind -Tcopy-mode-vi X send -X set-mark",
|
||||
"bind -Tcopy-mode-vi ^ send -X back-to-indentation",
|
||||
"bind -Tcopy-mode-vi b send -X previous-word",
|
||||
"bind -Tcopy-mode-vi e send -X next-word-end",
|
||||
"bind -Tcopy-mode-vi f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi g send -X history-top",
|
||||
"bind -Tcopy-mode-vi h send -X cursor-left",
|
||||
"bind -Tcopy-mode-vi j send -X cursor-down",
|
||||
"bind -Tcopy-mode-vi k send -X cursor-up",
|
||||
"bind -Tcopy-mode-vi l send -X cursor-right",
|
||||
"bind -Tcopy-mode-vi n send -X search-again",
|
||||
"bind -Tcopy-mode-vi o send -X other-end",
|
||||
"bind -Tcopy-mode-vi q send -X cancel",
|
||||
"bind -Tcopy-mode-vi r send -X refresh-from-pane",
|
||||
"bind -Tcopy-mode-vi t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi v send -X rectangle-toggle",
|
||||
"bind -Tcopy-mode-vi w send -X next-word",
|
||||
"bind -Tcopy-mode-vi '{' send -X previous-paragraph",
|
||||
"bind -Tcopy-mode-vi '}' send -X next-paragraph",
|
||||
"bind -Tcopy-mode-vi % send -X next-matching-bracket",
|
||||
"bind -Tcopy-mode-vi MouseDown1Pane select-pane",
|
||||
"bind -Tcopy-mode-vi MouseDrag1Pane select-pane\\; send -X begin-selection",
|
||||
"bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode-vi WheelUpPane select-pane\\; send -N5 -X scroll-up",
|
||||
"bind -Tcopy-mode-vi WheelDownPane select-pane\\; send -N5 -X scroll-down",
|
||||
"bind -Tcopy-mode-vi DoubleClick1Pane select-pane\\; send -X select-word\\; run -d0.3\\; send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode-vi TripleClick1Pane select-pane\\; send -X select-line\\; run -d0.3\\; send -X copy-pipe-and-cancel",
|
||||
"bind -Tcopy-mode-vi BSpace send -X cursor-left",
|
||||
"bind -Tcopy-mode-vi NPage send -X page-down",
|
||||
"bind -Tcopy-mode-vi PPage send -X page-up",
|
||||
"bind -Tcopy-mode-vi Up send -X cursor-up",
|
||||
"bind -Tcopy-mode-vi Down send -X cursor-down",
|
||||
"bind -Tcopy-mode-vi Left send -X cursor-left",
|
||||
"bind -Tcopy-mode-vi Right send -X cursor-right",
|
||||
"bind -Tcopy-mode-vi M-x send -X jump-to-mark",
|
||||
"bind -Tcopy-mode-vi C-Up send -X scroll-up",
|
||||
"bind -Tcopy-mode-vi C-Down send -X scroll-down",
|
||||
"bind -Tcopy-mode-vi '#' { send -FX search-backward '#{copy_cursor_word}' }",
|
||||
"bind -Tcopy-mode-vi * { send -FX search-forward '#{copy_cursor_word}' }",
|
||||
"bind -Tcopy-mode-vi C-c { send -X cancel }",
|
||||
"bind -Tcopy-mode-vi C-d { send -X halfpage-down }",
|
||||
"bind -Tcopy-mode-vi C-e { send -X scroll-down }",
|
||||
"bind -Tcopy-mode-vi C-b { send -X page-up }",
|
||||
"bind -Tcopy-mode-vi C-f { send -X page-down }",
|
||||
"bind -Tcopy-mode-vi C-h { send -X cursor-left }",
|
||||
"bind -Tcopy-mode-vi C-j { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode-vi Enter { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode-vi C-u { send -X halfpage-up }",
|
||||
"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 Space { send -X begin-selection }",
|
||||
"bind -Tcopy-mode-vi '$' { send -X end-of-line }",
|
||||
"bind -Tcopy-mode-vi , { send -X jump-reverse }",
|
||||
"bind -Tcopy-mode-vi / { command-prompt -T search -p'(search down)' { send -X search-forward '%%' } }",
|
||||
"bind -Tcopy-mode-vi 0 { send -X start-of-line }",
|
||||
"bind -Tcopy-mode-vi 1 { command-prompt -Np'(repeat)' -I1 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 2 { command-prompt -Np'(repeat)' -I2 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 3 { command-prompt -Np'(repeat)' -I3 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 4 { command-prompt -Np'(repeat)' -I4 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 5 { command-prompt -Np'(repeat)' -I5 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 6 { command-prompt -Np'(repeat)' -I6 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 7 { command-prompt -Np'(repeat)' -I7 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 8 { command-prompt -Np'(repeat)' -I8 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi 9 { command-prompt -Np'(repeat)' -I9 { send -N '%%' } }",
|
||||
"bind -Tcopy-mode-vi : { command-prompt -p'(goto line)' { send -X goto-line '%%' } }",
|
||||
"bind -Tcopy-mode-vi \\; { send -X jump-again }",
|
||||
"bind -Tcopy-mode-vi ? { command-prompt -T search -p'(search up)' { send -X search-backward '%%' } }",
|
||||
"bind -Tcopy-mode-vi A { send -X append-selection-and-cancel }",
|
||||
"bind -Tcopy-mode-vi B { send -X previous-space }",
|
||||
"bind -Tcopy-mode-vi D { send -X copy-pipe-end-of-line-and-cancel }",
|
||||
"bind -Tcopy-mode-vi E { send -X next-space-end }",
|
||||
"bind -Tcopy-mode-vi F { command-prompt -1p'(jump backward)' { send -X jump-backward '%%' } }",
|
||||
"bind -Tcopy-mode-vi G { send -X history-bottom }",
|
||||
"bind -Tcopy-mode-vi H { send -X top-line }",
|
||||
"bind -Tcopy-mode-vi J { send -X scroll-down }",
|
||||
"bind -Tcopy-mode-vi K { send -X scroll-up }",
|
||||
"bind -Tcopy-mode-vi L { send -X bottom-line }",
|
||||
"bind -Tcopy-mode-vi M { send -X middle-line }",
|
||||
"bind -Tcopy-mode-vi N { send -X search-reverse }",
|
||||
"bind -Tcopy-mode-vi P { send -X toggle-position }",
|
||||
"bind -Tcopy-mode-vi T { command-prompt -1p'(jump to backward)' { send -X jump-to-backward '%%' } }",
|
||||
"bind -Tcopy-mode-vi V { send -X select-line }",
|
||||
"bind -Tcopy-mode-vi W { send -X next-space }",
|
||||
"bind -Tcopy-mode-vi X { send -X set-mark }",
|
||||
"bind -Tcopy-mode-vi ^ { send -X back-to-indentation }",
|
||||
"bind -Tcopy-mode-vi b { send -X previous-word }",
|
||||
"bind -Tcopy-mode-vi e { send -X next-word-end }",
|
||||
"bind -Tcopy-mode-vi f { command-prompt -1p'(jump forward)' { send -X jump-forward '%%' } }",
|
||||
"bind -Tcopy-mode-vi g { send -X history-top }",
|
||||
"bind -Tcopy-mode-vi h { send -X cursor-left }",
|
||||
"bind -Tcopy-mode-vi j { send -X cursor-down }",
|
||||
"bind -Tcopy-mode-vi k { send -X cursor-up }",
|
||||
"bind -Tcopy-mode-vi l { send -X cursor-right }",
|
||||
"bind -Tcopy-mode-vi n { send -X search-again }",
|
||||
"bind -Tcopy-mode-vi o { send -X other-end }",
|
||||
"bind -Tcopy-mode-vi q { send -X cancel }",
|
||||
"bind -Tcopy-mode-vi r { send -X refresh-from-pane }",
|
||||
"bind -Tcopy-mode-vi t { command-prompt -1p'(jump to forward)' { send -X jump-to-forward '%%' } }",
|
||||
"bind -Tcopy-mode-vi v { send -X rectangle-toggle }",
|
||||
"bind -Tcopy-mode-vi w { send -X next-word }",
|
||||
"bind -Tcopy-mode-vi '{' { send -X previous-paragraph }",
|
||||
"bind -Tcopy-mode-vi '}' { send -X next-paragraph }",
|
||||
"bind -Tcopy-mode-vi % { send -X next-matching-bracket }",
|
||||
"bind -Tcopy-mode-vi MouseDown1Pane { select-pane }",
|
||||
"bind -Tcopy-mode-vi MouseDrag1Pane { select-pane; send -X begin-selection }",
|
||||
"bind -Tcopy-mode-vi MouseDragEnd1Pane { send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode-vi WheelUpPane { select-pane; send -N5 -X scroll-up }",
|
||||
"bind -Tcopy-mode-vi WheelDownPane { select-pane; send -N5 -X scroll-down }",
|
||||
"bind -Tcopy-mode-vi DoubleClick1Pane { select-pane; send -X select-word; run -d0.3; send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode-vi TripleClick1Pane { select-pane; send -X select-line; run -d0.3; send -X copy-pipe-and-cancel }",
|
||||
"bind -Tcopy-mode-vi BSpace { send -X cursor-left }",
|
||||
"bind -Tcopy-mode-vi NPage { send -X page-down }",
|
||||
"bind -Tcopy-mode-vi PPage { send -X page-up }",
|
||||
"bind -Tcopy-mode-vi Up { send -X cursor-up }",
|
||||
"bind -Tcopy-mode-vi Down { send -X cursor-down }",
|
||||
"bind -Tcopy-mode-vi Left { send -X cursor-left }",
|
||||
"bind -Tcopy-mode-vi Right { send -X cursor-right }",
|
||||
"bind -Tcopy-mode-vi M-x { send -X jump-to-mark }",
|
||||
"bind -Tcopy-mode-vi C-Up { send -X scroll-up }",
|
||||
"bind -Tcopy-mode-vi C-Down { send -X scroll-down }",
|
||||
};
|
||||
u_int i;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
for (i = 0; i < nitems(defaults); i++) {
|
||||
pr = cmd_parse_from_string(defaults[i], NULL);
|
||||
if (pr->status != CMD_PARSE_SUCCESS)
|
||||
if (pr->status != CMD_PARSE_SUCCESS) {
|
||||
log_debug("%s", pr->error);
|
||||
fatalx("bad default key: %s", defaults[i]);
|
||||
}
|
||||
cmdq_append(NULL, cmdq_get_command(pr->cmdlist, NULL));
|
||||
cmd_list_free(pr->cmdlist);
|
||||
}
|
||||
|
||||
44
key-string.c
44
key-string.c
@@ -91,26 +91,68 @@ static const struct {
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN1, MouseDown1),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN2, MouseDown2),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN3, MouseDown3),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN6, MouseDown6),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN7, MouseDown7),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN8, MouseDown8),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN9, MouseDown9),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN10, MouseDown10),
|
||||
KEYC_MOUSE_STRING(MOUSEDOWN11, MouseDown11),
|
||||
KEYC_MOUSE_STRING(MOUSEUP1, MouseUp1),
|
||||
KEYC_MOUSE_STRING(MOUSEUP2, MouseUp2),
|
||||
KEYC_MOUSE_STRING(MOUSEUP3, MouseUp3),
|
||||
KEYC_MOUSE_STRING(MOUSEUP6, MouseUp6),
|
||||
KEYC_MOUSE_STRING(MOUSEUP7, MouseUp7),
|
||||
KEYC_MOUSE_STRING(MOUSEUP8, MouseUp8),
|
||||
KEYC_MOUSE_STRING(MOUSEUP9, MouseUp9),
|
||||
KEYC_MOUSE_STRING(MOUSEUP10, MouseUp10),
|
||||
KEYC_MOUSE_STRING(MOUSEUP11, MouseUp11),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG1, MouseDrag1),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG2, MouseDrag2),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG3, MouseDrag3),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG6, MouseDrag6),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG7, MouseDrag7),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG8, MouseDrag8),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG9, MouseDrag9),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG10, MouseDrag10),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAG11, MouseDrag11),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND1, MouseDragEnd1),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND2, MouseDragEnd2),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND3, MouseDragEnd3),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND6, MouseDragEnd6),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND7, MouseDragEnd7),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND8, MouseDragEnd8),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND9, MouseDragEnd9),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND10, MouseDragEnd10),
|
||||
KEYC_MOUSE_STRING(MOUSEDRAGEND11, MouseDragEnd11),
|
||||
KEYC_MOUSE_STRING(WHEELUP, WheelUp),
|
||||
KEYC_MOUSE_STRING(WHEELDOWN, WheelDown),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK1, SecondClick1),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK2, SecondClick2),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK3, SecondClick3),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK6, SecondClick6),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK7, SecondClick7),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK8, SecondClick8),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK9, SecondClick9),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK10, SecondClick10),
|
||||
KEYC_MOUSE_STRING(SECONDCLICK11, SecondClick11),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK1, DoubleClick1),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK2, DoubleClick2),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK3, DoubleClick3),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK6, DoubleClick6),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK7, DoubleClick7),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK8, DoubleClick8),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK9, DoubleClick9),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK10, DoubleClick10),
|
||||
KEYC_MOUSE_STRING(DOUBLECLICK11, DoubleClick11),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK1, TripleClick1),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK2, TripleClick2),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK3, TripleClick3),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK6, TripleClick6),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK7, TripleClick7),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK8, TripleClick8),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK9, TripleClick9),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK10, TripleClick10),
|
||||
KEYC_MOUSE_STRING(TRIPLECLICK11, TripleClick11)
|
||||
};
|
||||
|
||||
/* Find key string in table. */
|
||||
@@ -183,6 +225,8 @@ key_string_lookup_string(const char *string)
|
||||
if (string[0] == '0' && string[1] == 'x') {
|
||||
if (sscanf(string + 2, "%x", &u) != 1)
|
||||
return (KEYC_UNKNOWN);
|
||||
if (u < 32)
|
||||
return (u);
|
||||
mlen = wctomb(m, u);
|
||||
if (mlen <= 0 || mlen > MB_LEN_MAX)
|
||||
return (KEYC_UNKNOWN);
|
||||
|
||||
@@ -154,7 +154,7 @@ layout_check(struct layout_cell *lc)
|
||||
|
||||
/* Parse a layout string and arrange window as layout. */
|
||||
int
|
||||
layout_parse(struct window *w, const char *layout)
|
||||
layout_parse(struct window *w, const char *layout, char **cause)
|
||||
{
|
||||
struct layout_cell *lc, *lcchild;
|
||||
struct window_pane *wp;
|
||||
@@ -165,22 +165,31 @@ layout_parse(struct window *w, const char *layout)
|
||||
if (sscanf(layout, "%hx,", &csum) != 1)
|
||||
return (-1);
|
||||
layout += 5;
|
||||
if (csum != layout_checksum(layout))
|
||||
if (csum != layout_checksum(layout)) {
|
||||
*cause = xstrdup("invalid layout");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Build the layout. */
|
||||
lc = layout_construct(NULL, &layout);
|
||||
if (lc == NULL)
|
||||
if (lc == NULL) {
|
||||
*cause = xstrdup("invalid layout");
|
||||
return (-1);
|
||||
if (*layout != '\0')
|
||||
}
|
||||
if (*layout != '\0') {
|
||||
*cause = xstrdup("invalid layout");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Check this window will fit into the layout. */
|
||||
for (;;) {
|
||||
npanes = window_count_panes(w);
|
||||
ncells = layout_count_cells(lc);
|
||||
if (npanes > ncells)
|
||||
if (npanes > ncells) {
|
||||
xasprintf(cause, "have %u panes but need %u", npanes,
|
||||
ncells);
|
||||
goto fail;
|
||||
}
|
||||
if (npanes == ncells)
|
||||
break;
|
||||
|
||||
@@ -217,8 +226,10 @@ layout_parse(struct window *w, const char *layout)
|
||||
}
|
||||
|
||||
/* Check the new layout. */
|
||||
if (!layout_check(lc))
|
||||
if (!layout_check(lc)) {
|
||||
*cause = xstrdup("size mismatch after applying layout");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Resize to the layout size. */
|
||||
window_resize(w, lc->sx, lc->sy, -1, -1);
|
||||
|
||||
40
log.c
40
log.c
@@ -29,9 +29,6 @@
|
||||
static FILE *log_file;
|
||||
static int log_level;
|
||||
|
||||
static void log_event_cb(int, const char *);
|
||||
static void log_vwrite(const char *, va_list);
|
||||
|
||||
/* Log callback for libevent. */
|
||||
static void
|
||||
log_event_cb(__unused int severity, const char *msg)
|
||||
@@ -100,29 +97,28 @@ log_close(void)
|
||||
}
|
||||
|
||||
/* Write a log message. */
|
||||
static void
|
||||
log_vwrite(const char *msg, va_list ap)
|
||||
static void printflike(1, 0)
|
||||
log_vwrite(const char *msg, va_list ap, const char *prefix)
|
||||
{
|
||||
char *fmt, *out;
|
||||
char *s, *out;
|
||||
struct timeval tv;
|
||||
|
||||
if (log_file == NULL)
|
||||
return;
|
||||
|
||||
if (vasprintf(&fmt, msg, ap) == -1)
|
||||
if (vasprintf(&s, msg, ap) == -1)
|
||||
return;
|
||||
if (stravis(&out, fmt, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) {
|
||||
free(fmt);
|
||||
if (stravis(&out, s, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL) == -1) {
|
||||
free(s);
|
||||
return;
|
||||
}
|
||||
free(s);
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
if (fprintf(log_file, "%lld.%06d %s\n", (long long)tv.tv_sec,
|
||||
(int)tv.tv_usec, out) != -1)
|
||||
if (fprintf(log_file, "%lld.%06d %s%s\n", (long long)tv.tv_sec,
|
||||
(int)tv.tv_usec, prefix, out) != -1)
|
||||
fflush(log_file);
|
||||
|
||||
free(out);
|
||||
free(fmt);
|
||||
}
|
||||
|
||||
/* Log a debug message. */
|
||||
@@ -135,7 +131,7 @@ log_debug(const char *msg, ...)
|
||||
return;
|
||||
|
||||
va_start(ap, msg);
|
||||
log_vwrite(msg, ap);
|
||||
log_vwrite(msg, ap, "");
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
@@ -143,14 +139,16 @@ log_debug(const char *msg, ...)
|
||||
__dead void
|
||||
fatal(const char *msg, ...)
|
||||
{
|
||||
char *fmt;
|
||||
char tmp[256];
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, msg);
|
||||
if (asprintf(&fmt, "fatal: %s: %s", msg, strerror(errno)) == -1)
|
||||
if (snprintf(tmp, sizeof tmp, "fatal: %s: ", strerror(errno)) < 0)
|
||||
exit(1);
|
||||
log_vwrite(fmt, ap);
|
||||
|
||||
va_start(ap, msg);
|
||||
log_vwrite(msg, ap, tmp);
|
||||
va_end(ap);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -158,13 +156,11 @@ fatal(const char *msg, ...)
|
||||
__dead void
|
||||
fatalx(const char *msg, ...)
|
||||
{
|
||||
char *fmt;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, msg);
|
||||
if (asprintf(&fmt, "fatal: %s", msg) == -1)
|
||||
exit(1);
|
||||
log_vwrite(fmt, ap);
|
||||
log_vwrite(msg, ap, "fatal: ");
|
||||
va_end(ap);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
BIN
logo/icons/128x128/tmux.png
Normal file
BIN
logo/icons/128x128/tmux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
BIN
logo/icons/16x16/tmux.png
Normal file
BIN
logo/icons/16x16/tmux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 791 B |
BIN
logo/icons/24x24/tmux.png
Normal file
BIN
logo/icons/24x24/tmux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 901 B |
BIN
logo/icons/32x32/tmux.png
Normal file
BIN
logo/icons/32x32/tmux.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 933 B |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user