mirror of
https://github.com/tmux/tmux.git
synced 2026-03-11 19:15:45 +00:00
Compare commits
913 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ae69c3795 | ||
|
|
0960862950 | ||
|
|
44ad25b367 | ||
|
|
40b97b1715 | ||
|
|
4bdb855020 | ||
|
|
ea7136fb83 | ||
|
|
428f8a9b28 | ||
|
|
84faada25b | ||
|
|
55d0abad89 | ||
|
|
7d91b4b90b | ||
|
|
66369416fc | ||
|
|
001e26d0bb | ||
|
|
2e39d698d2 | ||
|
|
e809c2ec35 | ||
|
|
4266d3efc8 | ||
|
|
40a20bc8ae | ||
|
|
f7bf7e9671 | ||
|
|
008ecd4592 | ||
|
|
73a2b12088 | ||
|
|
605bf21ff2 | ||
|
|
f028445407 | ||
|
|
bdf8e614af | ||
|
|
4dea352dee | ||
|
|
151875d144 | ||
|
|
88fd1f00b8 | ||
|
|
1a14d6d2e1 | ||
|
|
381c00a74e | ||
|
|
5aadee6df4 | ||
|
|
a5545dbc9f | ||
|
|
fdf465925e | ||
|
|
36e1ac6556 | ||
|
|
ffa376edf7 | ||
|
|
b777780720 | ||
|
|
347cd0b5f8 | ||
|
|
0ca28b362e | ||
|
|
51b80b985e | ||
|
|
789a98982e | ||
|
|
b202a2f1b5 | ||
|
|
7e79108f8a | ||
|
|
f09cde2542 | ||
|
|
9f9156c030 | ||
|
|
d394293ba5 | ||
|
|
c57a09269b | ||
|
|
8191c58737 | ||
|
|
f68d35c529 | ||
|
|
c02bc4dbe9 | ||
|
|
4872811ba7 | ||
|
|
1a1290f30b | ||
|
|
7be7ca7195 | ||
|
|
32197fa52d | ||
|
|
9653a52a6a | ||
|
|
d60c8942ce | ||
|
|
c99f9e92e0 | ||
|
|
e26356607e | ||
|
|
43e5e80343 | ||
|
|
1742138f05 | ||
|
|
c767d62329 | ||
|
|
7ad29b9831 | ||
|
|
d209fe9b1e | ||
|
|
c5542637d7 | ||
|
|
e7c829fc67 | ||
|
|
579829eef2 | ||
|
|
3aa20f6e75 | ||
|
|
f78279bb2e | ||
|
|
a99d7c6314 | ||
|
|
cf1ed67fcc | ||
|
|
1aec420465 | ||
|
|
16e4b39359 | ||
|
|
9456258ccc | ||
|
|
c41d59f232 | ||
|
|
d682ef88e6 | ||
|
|
c1e6e54e6e | ||
|
|
62f657845e | ||
|
|
a9841a6d1e | ||
|
|
70ecf17f85 | ||
|
|
71d453f169 | ||
|
|
071849f82f | ||
|
|
52084b2948 | ||
|
|
dfbc6b1888 | ||
|
|
e3a8b8434c | ||
|
|
8636848e63 | ||
|
|
3d93b0c52e | ||
|
|
d9942c769e | ||
|
|
6a45e6c256 | ||
|
|
b770a429c6 | ||
|
|
11e69f6025 | ||
|
|
57837bbf67 | ||
|
|
4c60afde78 | ||
|
|
ed689cd54e | ||
|
|
7a44984069 | ||
|
|
dee72ed41f | ||
|
|
1071ef8fc5 | ||
|
|
2b535bc173 | ||
|
|
b791f00bf1 | ||
|
|
3e82ad5340 | ||
|
|
7b1030293c | ||
|
|
a5fd80bbc3 | ||
|
|
fda3937734 | ||
|
|
b13c230749 | ||
|
|
715f39a53a | ||
|
|
2f74e811f1 | ||
|
|
828efc7bcf | ||
|
|
84936b832f | ||
|
|
c8494dff7b | ||
|
|
8fcc212e7a | ||
|
|
0e281530cb | ||
|
|
efded95ed7 | ||
|
|
18870913c5 | ||
|
|
63b7282377 | ||
|
|
269dab4b3e | ||
|
|
4ece43a029 | ||
|
|
8b3e2eab5a | ||
|
|
e4c4ceb286 | ||
|
|
b7e22d00b4 | ||
|
|
1a11c972ae | ||
|
|
43b841f188 | ||
|
|
f9b0460840 | ||
|
|
659d876cd5 | ||
|
|
ac43186dff | ||
|
|
e79fb214f8 | ||
|
|
9cf58d1a52 | ||
|
|
a2a02fd7d7 | ||
|
|
237ee6f231 | ||
|
|
4e57894e85 | ||
|
|
8c9fbbf4f3 | ||
|
|
3f3d61bd58 | ||
|
|
80d4f4afc6 | ||
|
|
2546216019 | ||
|
|
ff8882a24f | ||
|
|
ffe2410639 | ||
|
|
9e14c1f88d | ||
|
|
29a5dfc7c0 | ||
|
|
645bf8b3ab | ||
|
|
f41c536ff3 | ||
|
|
bdd05bdbd3 | ||
|
|
fe385b180f | ||
|
|
0eb5d25453 | ||
|
|
1d98394b41 | ||
|
|
149d9cc851 | ||
|
|
204d8f31d7 | ||
|
|
fbe6fe7f55 | ||
|
|
168eab11a7 | ||
|
|
41b318ac7c | ||
|
|
bf636d9575 | ||
|
|
39d41d0810 | ||
|
|
9d8131c190 | ||
|
|
0ff991b25f | ||
|
|
15c70e562c | ||
|
|
8f34504736 | ||
|
|
551e0c36d9 | ||
|
|
48eba4c195 | ||
|
|
9f605178c3 | ||
|
|
bcafe51378 | ||
|
|
280fe77edd | ||
|
|
b9524f5b72 | ||
|
|
a2018b2c3f | ||
|
|
c21af7e446 | ||
|
|
d73078838d | ||
|
|
22eb0334c3 | ||
|
|
a9ac614691 | ||
|
|
1d0f68dee9 | ||
|
|
ac4bb89d43 | ||
|
|
b55f34029a | ||
|
|
907f58cc3c | ||
|
|
023b0f76c3 | ||
|
|
ddaeebc213 | ||
|
|
1262e685b8 | ||
|
|
0bd78b42c0 | ||
|
|
4a0126f7fb | ||
|
|
7acc8d703d | ||
|
|
77118f3a9f | ||
|
|
e25926d3c4 | ||
|
|
0cb75f1332 | ||
|
|
93b1b78150 | ||
|
|
493922dc4b | ||
|
|
f10854cfc5 | ||
|
|
993e7a937f | ||
|
|
f5af3cfb21 | ||
|
|
e7e112fbd0 | ||
|
|
c42087c789 | ||
|
|
3aa458ea63 | ||
|
|
c4a6f403bb | ||
|
|
9789ea3fb4 | ||
|
|
f416ae1c12 | ||
|
|
d578cf8d3f | ||
|
|
789cb91f31 | ||
|
|
eb1f8d70a7 | ||
|
|
42895efac3 | ||
|
|
483cc77c1c | ||
|
|
9b1ea8b16d | ||
|
|
b41892622d | ||
|
|
9051220243 | ||
|
|
c0031f8b85 | ||
|
|
c1a30ed995 | ||
|
|
565de3f54b | ||
|
|
153ae758c9 | ||
|
|
5086377f30 | ||
|
|
7c0789d2d2 | ||
|
|
2a32565e0c | ||
|
|
7ced0a03d2 | ||
|
|
cb51942669 | ||
|
|
093fb53773 | ||
|
|
21e00e4635 | ||
|
|
09afc6c8ee | ||
|
|
a41a927441 | ||
|
|
3fe01ff09c | ||
|
|
b5ab4d2c13 | ||
|
|
4d79d463ef | ||
|
|
7cb48fc40b | ||
|
|
8bd17bff49 | ||
|
|
3b3f42053a | ||
|
|
70ff8cfe1e | ||
|
|
6249a4b866 | ||
|
|
7e497c7f23 | ||
|
|
1536b7e206 | ||
|
|
e46d0632a5 | ||
|
|
20da167377 | ||
|
|
fe475bd856 | ||
|
|
079f48e8a6 | ||
|
|
aaa043a20f | ||
|
|
48f41e4a41 | ||
|
|
6fb80527f3 | ||
|
|
f86eba2129 | ||
|
|
50f4e0fac9 | ||
|
|
77c135349a | ||
|
|
c449512be4 | ||
|
|
17290b9121 | ||
|
|
3be369522b | ||
|
|
dbfbd8a195 | ||
|
|
9614f51560 | ||
|
|
36896f6dd0 | ||
|
|
2d08235987 | ||
|
|
2291045116 | ||
|
|
9dd1f442c5 | ||
|
|
8edece2cdb | ||
|
|
d001a94d7b | ||
|
|
c2580cfe24 | ||
|
|
dafd6f462f | ||
|
|
2111142cf1 | ||
|
|
0fc961b22e | ||
|
|
5ce34add77 | ||
|
|
934f357149 | ||
|
|
ff2766b024 | ||
|
|
9ef854f5a9 | ||
|
|
a10452be2d | ||
|
|
9cc8e40aa0 | ||
|
|
f49f92737f | ||
|
|
19344ec890 | ||
|
|
a2cc601c3d | ||
|
|
9ab1ba36cd | ||
|
|
f03c3ca6c3 | ||
|
|
0a0ded3268 | ||
|
|
6da520c5a1 | ||
|
|
68dc9af9ac | ||
|
|
f7b30ed3d4 | ||
|
|
e867528209 | ||
|
|
038dfb27a8 | ||
|
|
416c27c995 | ||
|
|
19344efa78 | ||
|
|
9c34aad21c | ||
|
|
7c2dcd7238 | ||
|
|
03149bf7f6 | ||
|
|
497021d0db | ||
|
|
cfdc5b62ad | ||
|
|
9b08e5139b | ||
|
|
e139f977b1 | ||
|
|
9abf5d9fe5 | ||
|
|
273577ba0a | ||
|
|
e15058e60f | ||
|
|
de5cd54124 | ||
|
|
c6cf09450a | ||
|
|
c6e7568471 | ||
|
|
7b8ececd8d | ||
|
|
42ba6c1b22 | ||
|
|
9a2fdf8fd4 | ||
|
|
00812c9053 | ||
|
|
33c59100ae | ||
|
|
36d904011a | ||
|
|
9d9445a48e | ||
|
|
a8da24771c | ||
|
|
ab1d18d00f | ||
|
|
ee431d482a | ||
|
|
e06c09889c | ||
|
|
86dfbda0e4 | ||
|
|
697cebb4c1 | ||
|
|
3c65475561 | ||
|
|
dc6bc0e95a | ||
|
|
b130e951cc | ||
|
|
9e19f132f2 | ||
|
|
1afe22086f | ||
|
|
8e8b9865d1 | ||
|
|
a39827a85c | ||
|
|
9e03df5500 | ||
|
|
dd602eaa61 | ||
|
|
d0d2c39dec | ||
|
|
57fec74966 | ||
|
|
9360e0ef32 | ||
|
|
f08c019d41 | ||
|
|
c3af8f6b16 | ||
|
|
01c4919f5f | ||
|
|
cdacc12ce3 | ||
|
|
d8c527a5f9 | ||
|
|
b22edcf3a5 | ||
|
|
786cff8db9 | ||
|
|
b63afaea61 | ||
|
|
9c89f7c2af | ||
|
|
d46870ede5 | ||
|
|
a888ce9963 | ||
|
|
8ff3091d16 | ||
|
|
d9f84854ac | ||
|
|
89fe2680a9 | ||
|
|
7cee982f90 | ||
|
|
42358cc521 | ||
|
|
06869ff22f | ||
|
|
616bde08ac | ||
|
|
6d0828b81c | ||
|
|
42ddf02ffc | ||
|
|
56390e0a39 | ||
|
|
18a5835aff | ||
|
|
67960dcc9a | ||
|
|
0b355ae811 | ||
|
|
6a9bb2a622 | ||
|
|
988e59cf3e | ||
|
|
30e06e9d85 | ||
|
|
810daefdd1 | ||
|
|
ccc9dc3bb4 | ||
|
|
be2eb57d62 | ||
|
|
c07d582e24 | ||
|
|
afb3a5fe71 | ||
|
|
020c403dff | ||
|
|
e77e11ec6b | ||
|
|
3edda3c5e7 | ||
|
|
1184dc08d4 | ||
|
|
18838fbc87 | ||
|
|
be2617036f | ||
|
|
0f6227f46b | ||
|
|
c1ac007576 | ||
|
|
201a8d8e7e | ||
|
|
b566cd57bf | ||
|
|
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 | ||
|
|
3b929f332a | ||
|
|
c827f5092d | ||
|
|
d8feffd2bf | ||
|
|
f48c46a76a | ||
|
|
f06ee2b87b | ||
|
|
9b4c05b6b9 | ||
|
|
3b9b823df5 | ||
|
|
8aa34f616f | ||
|
|
5ea6ccbb7f | ||
|
|
434ac8734a | ||
|
|
47af583a50 | ||
|
|
aaf87abfb4 | ||
|
|
bacb4d1b4d | ||
|
|
ad2f7642f2 | ||
|
|
059580e0f7 | ||
|
|
cb2943faab | ||
|
|
7c28597e0f | ||
|
|
fb52921a86 | ||
|
|
ddc67152a5 | ||
|
|
4cf595a402 | ||
|
|
5107e84897 | ||
|
|
736a276cc9 | ||
|
|
825feac9f8 | ||
|
|
d8c0069254 | ||
|
|
33d4f854c0 | ||
|
|
9865ad27a5 | ||
|
|
16b497e12b | ||
|
|
a25af7d0f3 | ||
|
|
a11aa870b3 | ||
|
|
0431d4d639 | ||
|
|
d863978464 | ||
|
|
57d5f67552 | ||
|
|
bab7a9a085 | ||
|
|
2ab53d30d0 | ||
|
|
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:
|
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.
|
- 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.
|
- 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.
|
- 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
|
accessed, and controlled from a single screen. tmux may be detached from a
|
||||||
screen and continue running in the background, then later reattached.
|
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
|
## 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
|
|
||||||
29
.github/workflows/lock.yml
vendored
Normal file
29
.github/workflows/lock.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: 'Lock Threads'
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
lock:
|
||||||
|
permissions:
|
||||||
|
issues: write # for dessant/lock-threads to lock issues
|
||||||
|
pull-requests: write # for dessant/lock-threads to lock PRs
|
||||||
|
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.
|
||||||
322
CHANGES
322
CHANGES
@@ -1,3 +1,307 @@
|
|||||||
|
CHANGES FROM 3.3a to 3.4
|
||||||
|
|
||||||
|
* Add options keep-last and keep-group to destroy-unattached to keep the last
|
||||||
|
session whether in a group.
|
||||||
|
|
||||||
|
* Don't allow paste-buffer into dead panes.
|
||||||
|
|
||||||
|
* Add -t to source-file.
|
||||||
|
|
||||||
|
* Rewrite combined character handling to be more consistent and to support
|
||||||
|
newer Unicode combined characters.
|
||||||
|
|
||||||
|
* Add basic support for SIXEL if built with --enable-sixel.
|
||||||
|
|
||||||
|
* Add a session, pane and user mouse range types for the status line and add
|
||||||
|
format variables for mouse_status_line and mouse_status_range so they can be
|
||||||
|
associated with different commands in the key bindings.
|
||||||
|
|
||||||
|
* Add flag (-o) to next-prompt/previous-prompt to go to OSC 133 command output.
|
||||||
|
|
||||||
|
* Add options and flags for menu styles (menu-style, menu-border-style) similar
|
||||||
|
to those existing for popups.
|
||||||
|
|
||||||
|
* Add support for marking lines with a shell prompt based on the OSC 133 extension.
|
||||||
|
|
||||||
|
* Check for libterminfo for NetBSD.
|
||||||
|
|
||||||
|
* Add "us" to styles for underscore colour.
|
||||||
|
|
||||||
|
* Add flags (-c and -y) to change the confirm key and default behaviour of
|
||||||
|
confirm-before.
|
||||||
|
|
||||||
|
* Use ncurses' new tparm_s function (added in 6.4-20230424) instead of tparm so
|
||||||
|
it does not object to string arguments in c apabilities it doesn't already
|
||||||
|
know. Also ignore errors from tparm if using previous ncurses versions.
|
||||||
|
|
||||||
|
* Set default lock command to vlock on Linux if present at build time.
|
||||||
|
|
||||||
|
* Discard mouse sequences that have the right form but actually are invalid.
|
||||||
|
|
||||||
|
* Add support for spawning panes in separate cgroups with systemd and a
|
||||||
|
configure flag (--disable-cgroups) to turn off.
|
||||||
|
|
||||||
|
* Add a format (pane_unseen_changes) to show if there are unseen changes while
|
||||||
|
in a mode.
|
||||||
|
|
||||||
|
* Remove old buffer when renaming rather than complaining.
|
||||||
|
|
||||||
|
* Add an L modifier like P, W, S to loop over clients.
|
||||||
|
|
||||||
|
* Add -f to list-clients like the other list commands.
|
||||||
|
|
||||||
|
* Extend display-message to work for control clients.
|
||||||
|
|
||||||
|
* Add a flag to display-menu to select the manu item selected when the menu is
|
||||||
|
open.
|
||||||
|
|
||||||
|
* Have tmux recognise pasted text wrapped in bracket paste sequences, rather
|
||||||
|
than only forwarding them to the program inside.
|
||||||
|
|
||||||
|
* Have client return 1 if process is interrupted to an input pane.
|
||||||
|
|
||||||
|
* Query the client terminal for foreground and background colours and if OSC 10
|
||||||
|
or 11 is received but no colour has been set inside tmux, return the colour
|
||||||
|
from the first attached client.
|
||||||
|
|
||||||
|
* Add send-keys -K to handle keys directly as if typed (so look up in key
|
||||||
|
table).
|
||||||
|
|
||||||
|
* Process escape sequences in show-buffer.
|
||||||
|
|
||||||
|
* Add a -l flag to display-message to disable format expansion.
|
||||||
|
|
||||||
|
* Add paste-buffer-deleted notification and fix name of paste-buffer-changed.
|
||||||
|
|
||||||
|
* Do not attempt to connect to the socket as a client if systemd is active.
|
||||||
|
|
||||||
|
* Add scroll-top and scroll-bottom commands to scroll so cursor is at top or
|
||||||
|
bottom.
|
||||||
|
|
||||||
|
* Add a -T flag to capture-pane to stop at the last used cell instead of the
|
||||||
|
full width. Restore the previous behaviour by making it default to off unless
|
||||||
|
-J is used.
|
||||||
|
|
||||||
|
* Add message-line option to control where message and prompt go.
|
||||||
|
|
||||||
|
* Notification when a when a paste buffer is deleted.
|
||||||
|
|
||||||
|
* Add a Nobr terminfo(5) capability to tell tmux the terminal does not use bright
|
||||||
|
colours for bold.
|
||||||
|
|
||||||
|
* Change g and G to go to top and bottom in menus.
|
||||||
|
|
||||||
|
* Add a third state "all" to allow-passthrough to work even in invisible panes.
|
||||||
|
|
||||||
|
* Add support for OSC 8 hyperlinks.
|
||||||
|
|
||||||
|
* Store the time lines are scrolled into history and display in copy mode.
|
||||||
|
|
||||||
|
* Add a %config-error reply to control mode for configuration file errors since
|
||||||
|
reporting them in view mode is useless.
|
||||||
|
|
||||||
|
* A new feature flag (ignorefkeys) to ignore terminfo(5) function key
|
||||||
|
definitions for rxvt.
|
||||||
|
|
||||||
|
* Pass through first argument to OSC 52 (which clipboards to set) if the
|
||||||
|
application provides it.
|
||||||
|
|
||||||
|
* Expand arguments to send-keys, capture-pane, split-window, join-pane where it
|
||||||
|
makes sense to do so.
|
||||||
|
|
||||||
|
* Ignore named buffers when choosing a buffer if one is not specified by the user.
|
||||||
|
|
||||||
|
CHANGES FROM 3.3 TO 3.3a
|
||||||
|
|
||||||
|
* Do not crash when run-shell produces output from a config file.
|
||||||
|
|
||||||
|
* Do not unintentionally turn off all mouse mode when button mode is also
|
||||||
|
present.
|
||||||
|
|
||||||
|
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
|
||||||
|
forward extended keys to applications even if they do not request them.
|
||||||
|
|
||||||
|
* Add a "mouse" terminal feature so tmux can enable the mouse on terminals
|
||||||
|
where it is known to be supported even if terminfo(5) says otherwise.
|
||||||
|
|
||||||
|
* Do not expand the filename given to -f so it can contain colons.
|
||||||
|
|
||||||
|
* Fixes for problems with extended keys and modifiers, scroll region,
|
||||||
|
source-file, crosscompiling, format modifiers and other minor issues.
|
||||||
|
|
||||||
CHANGES FROM 3.1c TO 3.2
|
CHANGES FROM 3.1c TO 3.2
|
||||||
|
|
||||||
* Add a flag to disable keys to close a message.
|
* Add a flag to disable keys to close a message.
|
||||||
@@ -29,7 +333,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
* Add a -S flag to new-window to make it select the existing window if one
|
* Add a -S flag to new-window to make it select the existing window if one
|
||||||
with the given name already exists rather than failing with an error.
|
with the given name already exists rather than failing with an error.
|
||||||
|
|
||||||
* Addd a format modifier to check if a window or session name exists (N/w or
|
* Add a format modifier to check if a window or session name exists (N/w or
|
||||||
N/s).
|
N/s).
|
||||||
|
|
||||||
* Add compat clock_gettime for older macOS.
|
* Add compat clock_gettime for older macOS.
|
||||||
@@ -61,7 +365,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
an option on all panes.
|
an option on all panes.
|
||||||
|
|
||||||
* Make replacement of ##s consistent when drawing formats, whether followed by
|
* Make replacement of ##s consistent when drawing formats, whether followed by
|
||||||
[ or not. Add a flag (e) to the q: format modifier to double up #s
|
[ or not. Add a flag (e) to the q: format modifier to double up #s.
|
||||||
|
|
||||||
* Add -N flag to display-panes to ignore keys.
|
* Add -N flag to display-panes to ignore keys.
|
||||||
|
|
||||||
@@ -105,7 +409,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
|
|
||||||
* Add a way for control mode clients to subscribe to a format and be notified
|
* Add a way for control mode clients to subscribe to a format and be notified
|
||||||
of changes rather than having to poll.
|
of changes rather than having to poll.
|
||||||
|
|
||||||
* Add some formats for search in copy mode (search_present, search_match).
|
* Add some formats for search in copy mode (search_present, search_match).
|
||||||
|
|
||||||
* Do not wait on shutdown for commands started with run -b.
|
* Do not wait on shutdown for commands started with run -b.
|
||||||
@@ -229,7 +533,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
only show windows and C-b . only targets.
|
only show windows and C-b . only targets.
|
||||||
|
|
||||||
* Change all the style options to string options so they can support formats.
|
* 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
|
in a mode or with synchronize-panes on. This also implies a few minor changes
|
||||||
to existing behaviour:
|
to existing behaviour:
|
||||||
|
|
||||||
@@ -265,7 +569,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
|
|
||||||
* Wait until the initial command sequence is done before sending a device
|
* Wait until the initial command sequence is done before sending a device
|
||||||
attributes request and other bits that prompt a reply from the terminal. This
|
attributes request and other bits that prompt a reply from the terminal. This
|
||||||
means that stray relies are not left on the terminal if the command has
|
means that stray replies are not left on the terminal if the command has
|
||||||
attached and then immediately detached and tmux will not be around to receive
|
attached and then immediately detached and tmux will not be around to receive
|
||||||
them.
|
them.
|
||||||
|
|
||||||
@@ -280,7 +584,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
window-renamed
|
window-renamed
|
||||||
window-unlinked
|
window-unlinked
|
||||||
|
|
||||||
And these now pane options:
|
And these are now pane options:
|
||||||
|
|
||||||
pane-died
|
pane-died
|
||||||
pane-exited
|
pane-exited
|
||||||
@@ -355,7 +659,7 @@ CHANGES FROM 3.1c TO 3.2
|
|||||||
* Add a default binding for button 2 to paste.
|
* Add a default binding for button 2 to paste.
|
||||||
|
|
||||||
* Add -d flag to run-shell to delay before running the command and allow it to
|
* Add -d flag to run-shell to delay before running the command and allow it to
|
||||||
run without a command so it just delays.
|
be used without a command so it just delays.
|
||||||
|
|
||||||
* Add C-g to cancel command prompt with vi keys as well as emacs, and q in
|
* Add C-g to cancel command prompt with vi keys as well as emacs, and q in
|
||||||
command mode.
|
command mode.
|
||||||
@@ -1111,7 +1415,7 @@ Incompatible Changes
|
|||||||
|
|
||||||
bind -Tcopy-mode C-r command-prompt -i -p'search up' "send -X search-backward-incremental '%%'"
|
bind -Tcopy-mode C-r command-prompt -i -p'search up' "send -X search-backward-incremental '%%'"
|
||||||
|
|
||||||
There are also some new commmands available with send -X, such as
|
There are also some new commands available with send -X, such as
|
||||||
copy-pipe-and-cancel.
|
copy-pipe-and-cancel.
|
||||||
* set-remain-on-exit has gone -- can be achieved with hooks instead.
|
* set-remain-on-exit has gone -- can be achieved with hooks instead.
|
||||||
* Hooks: before hooks have been removed and only a selection of commands now
|
* Hooks: before hooks have been removed and only a selection of commands now
|
||||||
@@ -3087,7 +3391,7 @@ The list of older changes is below.
|
|||||||
* (nicm) -n on new-session is now -s, and -n is now the initial window name.
|
* (nicm) -n on new-session is now -s, and -n is now the initial window name.
|
||||||
This was documented but not implemented :-/.
|
This was documented but not implemented :-/.
|
||||||
* (nicm) kill-window command, bound to & by default (because it should be hard
|
* (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;
|
* (nicm) bell-style option with three choices: "none" completely ignore bell;
|
||||||
"any" pass through a bell in any window to current; "current" ignore bells
|
"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,
|
except in current window. This applies only to the bell terminal signal,
|
||||||
|
|||||||
25
Makefile.am
25
Makefile.am
@@ -1,5 +1,3 @@
|
|||||||
# Makefile.am
|
|
||||||
|
|
||||||
# Obvious program stuff.
|
# Obvious program stuff.
|
||||||
bin_PROGRAMS = tmux
|
bin_PROGRAMS = tmux
|
||||||
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
||||||
@@ -13,7 +11,9 @@ dist_EXTRA_tmux_SOURCES = compat/*.[ch]
|
|||||||
# Preprocessor flags.
|
# Preprocessor flags.
|
||||||
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
||||||
-DTMUX_VERSION='"@VERSION@"' \
|
-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_LOCK_CMD='"@DEFAULT_LOCK_CMD@"' \
|
||||||
|
-DTMUX_TERM='"@DEFAULT_TERM@"'
|
||||||
|
|
||||||
# Additional object files.
|
# Additional object files.
|
||||||
LDADD = $(LIBOBJS)
|
LDADD = $(LIBOBJS)
|
||||||
@@ -29,6 +29,9 @@ AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
|||||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||||
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
AM_CFLAGS += -Wdeclaration-after-statement -Wno-pointer-sign -Wno-attributes
|
||||||
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k
|
AM_CFLAGS += -Wno-unused-result -Wno-format-y2k
|
||||||
|
if IS_DARWIN
|
||||||
|
AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align
|
||||||
|
endif
|
||||||
AM_CPPFLAGS += -DDEBUG
|
AM_CPPFLAGS += -DDEBUG
|
||||||
endif
|
endif
|
||||||
AM_CPPFLAGS += -iquote.
|
AM_CPPFLAGS += -iquote.
|
||||||
@@ -119,12 +122,14 @@ dist_tmux_SOURCES = \
|
|||||||
cmd-select-pane.c \
|
cmd-select-pane.c \
|
||||||
cmd-select-window.c \
|
cmd-select-window.c \
|
||||||
cmd-send-keys.c \
|
cmd-send-keys.c \
|
||||||
|
cmd-server-access.c \
|
||||||
cmd-set-buffer.c \
|
cmd-set-buffer.c \
|
||||||
cmd-set-environment.c \
|
cmd-set-environment.c \
|
||||||
cmd-set-option.c \
|
cmd-set-option.c \
|
||||||
cmd-show-environment.c \
|
cmd-show-environment.c \
|
||||||
cmd-show-messages.c \
|
cmd-show-messages.c \
|
||||||
cmd-show-options.c \
|
cmd-show-options.c \
|
||||||
|
cmd-show-prompt-history.c \
|
||||||
cmd-source-file.c \
|
cmd-source-file.c \
|
||||||
cmd-split-window.c \
|
cmd-split-window.c \
|
||||||
cmd-swap-pane.c \
|
cmd-swap-pane.c \
|
||||||
@@ -144,6 +149,7 @@ dist_tmux_SOURCES = \
|
|||||||
grid-reader.c \
|
grid-reader.c \
|
||||||
grid-view.c \
|
grid-view.c \
|
||||||
grid.c \
|
grid.c \
|
||||||
|
hyperlinks.c \
|
||||||
input-keys.c \
|
input-keys.c \
|
||||||
input.c \
|
input.c \
|
||||||
job.c \
|
job.c \
|
||||||
@@ -167,6 +173,7 @@ dist_tmux_SOURCES = \
|
|||||||
screen-redraw.c \
|
screen-redraw.c \
|
||||||
screen-write.c \
|
screen-write.c \
|
||||||
screen.c \
|
screen.c \
|
||||||
|
server-acl.c \
|
||||||
server-client.c \
|
server-client.c \
|
||||||
server-fn.c \
|
server-fn.c \
|
||||||
server.c \
|
server.c \
|
||||||
@@ -176,11 +183,13 @@ dist_tmux_SOURCES = \
|
|||||||
style.c \
|
style.c \
|
||||||
tmux.c \
|
tmux.c \
|
||||||
tmux.h \
|
tmux.h \
|
||||||
|
tmux-protocol.h \
|
||||||
tty-acs.c \
|
tty-acs.c \
|
||||||
tty-features.c \
|
tty-features.c \
|
||||||
tty-keys.c \
|
tty-keys.c \
|
||||||
tty-term.c \
|
tty-term.c \
|
||||||
tty.c \
|
tty.c \
|
||||||
|
utf8-combined.c \
|
||||||
utf8.c \
|
utf8.c \
|
||||||
window-buffer.c \
|
window-buffer.c \
|
||||||
window-client.c \
|
window-client.c \
|
||||||
@@ -198,11 +207,21 @@ if NEED_FORKPTY
|
|||||||
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
nodist_tmux_SOURCES += compat/forkpty-@PLATFORM@.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Add compat file for systemd.
|
||||||
|
if HAVE_SYSTEMD
|
||||||
|
nodist_tmux_SOURCES += compat/systemd.c
|
||||||
|
endif
|
||||||
|
|
||||||
# Add compat file for utf8proc.
|
# Add compat file for utf8proc.
|
||||||
if HAVE_UTF8PROC
|
if HAVE_UTF8PROC
|
||||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
nodist_tmux_SOURCES += compat/utf8proc.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Enable sixel support.
|
||||||
|
if ENABLE_SIXEL
|
||||||
|
dist_tmux_SOURCES += image.c image-sixel.c
|
||||||
|
endif
|
||||||
|
|
||||||
if NEED_FUZZING
|
if NEED_FUZZING
|
||||||
check_PROGRAMS = fuzz/input-fuzzer
|
check_PROGRAMS = fuzz/input-fuzzer
|
||||||
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
|
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
|
||||||
|
|||||||
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
|
accessed, and controlled from a single screen. tmux may be detached from a
|
||||||
screen and continue running in the background, then later reattached.
|
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
|
* Dependencies
|
||||||
|
|
||||||
@@ -55,6 +55,14 @@ source tree with:
|
|||||||
|
|
||||||
A small example configuration is in example_tmux.conf.
|
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:
|
A bash(1) completion file is at:
|
||||||
|
|
||||||
https://github.com/imomaliev/tmux-bash-completion
|
https://github.com/imomaliev/tmux-bash-completion
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ tmuxへようこそ!
|
|||||||
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
||||||
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
||||||
|
|
||||||
OpenBSD、FreeBSD、NetBSD、Linux、OS X、Solarisで実行できます。
|
OpenBSD、FreeBSD、NetBSD、Linux、macOS、Solarisで実行できます。
|
||||||
|
|
||||||
tmuxはlibevent 2.x.に依存します。 下記からダウンロードしてください。
|
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
|
% git checkout -b obsd-master obsd-tmux/master
|
||||||
|
|
||||||
Adding in the fake history points
|
Adding in the fake history points
|
||||||
=================================
|
=================================
|
||||||
|
|
||||||
To tie both the "master" branch from "tmux" and the "obsd-master"
|
To tie both the "master" branch from "tmux" and the "obsd-master"
|
||||||
branch from "tmux-openbsd" together, the fake history points added to the
|
branch from "tmux-openbsd" together, the fake history points added to the
|
||||||
|
|||||||
819
arguments.c
819
arguments.c
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -28,19 +29,35 @@
|
|||||||
* Manipulate command arguments.
|
* Manipulate command arguments.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct args_value {
|
/* List of argument values. */
|
||||||
char *value;
|
|
||||||
TAILQ_ENTRY(args_value) entry;
|
|
||||||
};
|
|
||||||
TAILQ_HEAD(args_values, args_value);
|
TAILQ_HEAD(args_values, args_value);
|
||||||
|
|
||||||
|
/* Single arguments flag. */
|
||||||
struct args_entry {
|
struct args_entry {
|
||||||
u_char flag;
|
u_char flag;
|
||||||
struct args_values values;
|
struct args_values values;
|
||||||
u_int count;
|
u_int count;
|
||||||
|
|
||||||
|
int flags;
|
||||||
|
#define ARGS_ENTRY_OPTIONAL_VALUE 0x1
|
||||||
|
|
||||||
RB_ENTRY(args_entry) 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 struct args_entry *args_find(struct args *, u_char);
|
||||||
|
|
||||||
static int args_cmp(struct args_entry *, struct args_entry *);
|
static int args_cmp(struct args_entry *, struct args_entry *);
|
||||||
@@ -63,38 +80,344 @@ args_find(struct args *args, u_char flag)
|
|||||||
return (RB_FIND(args_tree, &args->tree, &entry));
|
return (RB_FIND(args_tree, &args->tree, &entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse an argv and argc into a new argument set. */
|
/* Copy value. */
|
||||||
struct args *
|
static void
|
||||||
args_parse(const char *template, int argc, char **argv)
|
args_copy_value(struct args_value *to, struct args_value *from)
|
||||||
{
|
{
|
||||||
struct args *args;
|
to->type = from->type;
|
||||||
int opt;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Type to string. */
|
||||||
|
static const char *
|
||||||
|
args_type_to_string (enum args_type type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ARGS_NONE:
|
||||||
|
return "NONE";
|
||||||
|
case ARGS_STRING:
|
||||||
|
return "STRING";
|
||||||
|
case ARGS_COMMANDS:
|
||||||
|
return "COMMANDS";
|
||||||
|
}
|
||||||
|
return "INVALID";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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);
|
args = xcalloc(1, sizeof *args);
|
||||||
|
RB_INIT(&args->tree);
|
||||||
|
return (args);
|
||||||
|
}
|
||||||
|
|
||||||
optreset = 1;
|
/* Parse a single flag. */
|
||||||
optind = 1;
|
static int
|
||||||
optarg = NULL;
|
args_parse_flag_argument(struct args_value *values, u_int count, char **cause,
|
||||||
|
struct args *args, u_int *i, const char *string, int flag,
|
||||||
|
int optional_argument)
|
||||||
|
{
|
||||||
|
struct args_value *argument, *new;
|
||||||
|
const char *s;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, template)) != -1) {
|
new = xcalloc(1, sizeof *new);
|
||||||
if (opt < 0)
|
if (*string != '\0') {
|
||||||
|
new->type = ARGS_STRING;
|
||||||
|
new->string = xstrdup(string);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*i == count)
|
||||||
|
argument = NULL;
|
||||||
|
else {
|
||||||
|
argument = &values[*i];
|
||||||
|
if (argument->type != ARGS_STRING) {
|
||||||
|
xasprintf(cause, "-%c argument must be a string", flag);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (argument == NULL) {
|
||||||
|
if (optional_argument) {
|
||||||
|
log_debug("%s: -%c (optional)", __func__, flag);
|
||||||
|
args_set(args, flag, NULL, ARGS_ENTRY_OPTIONAL_VALUE);
|
||||||
|
return (0); /* either - or end */
|
||||||
|
}
|
||||||
|
xasprintf(cause, "-%c expects an argument", flag);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
args_copy_value(new, argument);
|
||||||
|
(*i)++;
|
||||||
|
|
||||||
|
out:
|
||||||
|
s = args_value_as_string(new);
|
||||||
|
log_debug("%s: -%c = %s", __func__, flag, s);
|
||||||
|
args_set(args, flag, new, 0);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse flags argument. */
|
||||||
|
static int
|
||||||
|
args_parse_flags(const struct args_parse *parse, struct args_value *values,
|
||||||
|
u_int count, char **cause, struct args *args, u_int *i)
|
||||||
|
{
|
||||||
|
struct args_value *value;
|
||||||
|
u_char flag;
|
||||||
|
const char *found, *string;
|
||||||
|
int optional_argument;
|
||||||
|
|
||||||
|
value = &values[*i];
|
||||||
|
if (value->type != ARGS_STRING)
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
string = value->string;
|
||||||
|
log_debug("%s: next %s", __func__, string);
|
||||||
|
if (*string++ != '-' || *string == '\0')
|
||||||
|
return (1);
|
||||||
|
(*i)++;
|
||||||
|
if (string[0] == '-' && string[1] == '\0')
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
flag = *string++;
|
||||||
|
if (flag == '\0')
|
||||||
|
return (0);
|
||||||
|
if (flag == '?')
|
||||||
|
return (-1);
|
||||||
|
if (!isalnum(flag)) {
|
||||||
|
xasprintf(cause, "invalid flag -%c", flag);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
found = strchr(parse->template, flag);
|
||||||
|
if (found == NULL) {
|
||||||
|
xasprintf(cause, "unknown flag -%c", flag);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (found[1] != ':') {
|
||||||
|
log_debug("%s: -%c", __func__, flag);
|
||||||
|
args_set(args, flag, NULL, 0);
|
||||||
continue;
|
continue;
|
||||||
if (opt == '?' || strchr(template, opt) == NULL) {
|
}
|
||||||
|
optional_argument = (found[2] == ':');
|
||||||
|
return (args_parse_flag_argument(values, count, cause, args, i,
|
||||||
|
string, flag, optional_argument));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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;
|
||||||
|
const char *s;
|
||||||
|
int stop;
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return (args_create());
|
||||||
|
|
||||||
|
args = args_create();
|
||||||
|
for (i = 1; i < count; /* nothing */) {
|
||||||
|
stop = args_parse_flags(parse, values, count, cause, args, &i);
|
||||||
|
if (stop == -1) {
|
||||||
args_free(args);
|
args_free(args);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
args_set(args, opt, optarg);
|
if (stop == 1)
|
||||||
optarg = NULL;
|
break;
|
||||||
}
|
}
|
||||||
argc -= optind;
|
log_debug("%s: flags end at %u of %u", __func__, i, count);
|
||||||
argv += optind;
|
if (i != count) {
|
||||||
|
for (/* nothing */; i < count; i++) {
|
||||||
|
value = &values[i];
|
||||||
|
|
||||||
args->argc = argc;
|
s = args_value_as_string(value);
|
||||||
args->argv = cmd_copy_argv(argc, argv);
|
log_debug("%s: %u = %s (type %s)", __func__, i, s,
|
||||||
|
args_type_to_string (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);
|
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, 0);
|
||||||
|
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, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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. */
|
/* Free an arguments set. */
|
||||||
void
|
void
|
||||||
args_free(struct args *args)
|
args_free(struct args *args)
|
||||||
@@ -104,13 +427,14 @@ args_free(struct args *args)
|
|||||||
struct args_value *value;
|
struct args_value *value;
|
||||||
struct args_value *value1;
|
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_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
||||||
RB_REMOVE(args_tree, &args->tree, entry);
|
RB_REMOVE(args_tree, &args->tree, entry);
|
||||||
TAILQ_FOREACH_SAFE(value, &entry->values, entry, value1) {
|
TAILQ_FOREACH_SAFE(value, &entry->values, entry, value1) {
|
||||||
TAILQ_REMOVE(&entry->values, value, entry);
|
TAILQ_REMOVE(&entry->values, value, entry);
|
||||||
free(value->value);
|
args_free_value(value);
|
||||||
free(value);
|
free(value);
|
||||||
}
|
}
|
||||||
free(entry);
|
free(entry);
|
||||||
@@ -119,11 +443,52 @@ args_free(struct args *args)
|
|||||||
free(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. */
|
/* Add to string. */
|
||||||
static void printflike(3, 4)
|
static void printflike(3, 4)
|
||||||
args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *s;
|
char *s;
|
||||||
size_t slen;
|
size_t slen;
|
||||||
|
|
||||||
@@ -140,44 +505,37 @@ args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
|||||||
|
|
||||||
/* Add value to string. */
|
/* Add value to string. */
|
||||||
static void
|
static void
|
||||||
args_print_add_value(char **buf, size_t *len, struct args_entry *entry,
|
args_print_add_value(char **buf, size_t *len, struct args_value *value)
|
||||||
struct args_value *value)
|
|
||||||
{
|
{
|
||||||
char *escaped;
|
char *expanded = NULL;
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (**buf != '\0')
|
if (**buf != '\0')
|
||||||
args_print_add(buf, len, " ");
|
args_print_add(buf, len, " ");
|
||||||
|
|
||||||
escaped = args_escape(argument);
|
switch (value->type) {
|
||||||
args_print_add(buf, len, "%s", escaped);
|
case ARGS_NONE:
|
||||||
free(escaped);
|
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. */
|
/* Print a set of arguments. */
|
||||||
char *
|
char *
|
||||||
args_print(struct args *args)
|
args_print(struct args *args)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *buf;
|
char *buf;
|
||||||
int i;
|
u_int i, j;
|
||||||
u_int j;
|
|
||||||
struct args_entry *entry;
|
struct args_entry *entry;
|
||||||
|
struct args_entry *last = NULL;
|
||||||
struct args_value *value;
|
struct args_value *value;
|
||||||
|
|
||||||
len = 1;
|
len = 1;
|
||||||
@@ -185,6 +543,8 @@ args_print(struct args *args)
|
|||||||
|
|
||||||
/* Process the flags first. */
|
/* Process the flags first. */
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||||
|
if (entry->flags & ARGS_ENTRY_OPTIONAL_VALUE)
|
||||||
|
continue;
|
||||||
if (!TAILQ_EMPTY(&entry->values))
|
if (!TAILQ_EMPTY(&entry->values))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -196,13 +556,31 @@ args_print(struct args *args)
|
|||||||
|
|
||||||
/* Then the flags with arguments. */
|
/* Then the flags with arguments. */
|
||||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||||
TAILQ_FOREACH(value, &entry->values, entry)
|
if (entry->flags & ARGS_ENTRY_OPTIONAL_VALUE) {
|
||||||
args_print_add_value(&buf, &len, entry, value);
|
if (*buf != '\0')
|
||||||
|
args_print_add(&buf, &len, " -%c", entry->flag);
|
||||||
|
else
|
||||||
|
args_print_add(&buf, &len, "-%c", entry->flag);
|
||||||
|
last = entry;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (TAILQ_EMPTY(&entry->values))
|
||||||
|
continue;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
last = entry;
|
||||||
}
|
}
|
||||||
|
if (last && (last->flags & ARGS_ENTRY_OPTIONAL_VALUE))
|
||||||
|
args_print_add(&buf, &len, " --");
|
||||||
|
|
||||||
/* And finally the argument vector. */
|
/* And finally the argument vector. */
|
||||||
for (i = 0; i < args->argc; i++)
|
for (i = 0; i < args->count; i++)
|
||||||
args_print_add_argument(&buf, &len, args->argv[i]);
|
args_print_add_value(&buf, &len, &args->values[i]);
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@@ -211,7 +589,7 @@ args_print(struct args *args)
|
|||||||
char *
|
char *
|
||||||
args_escape(const char *s)
|
args_escape(const char *s)
|
||||||
{
|
{
|
||||||
static const char dquoted[] = " #';${}";
|
static const char dquoted[] = " #';${}%";
|
||||||
static const char squoted[] = " \"";
|
static const char squoted[] = " \"";
|
||||||
char *escaped, *result;
|
char *escaped, *result;
|
||||||
int flags, quotes = 0;
|
int flags, quotes = 0;
|
||||||
@@ -268,26 +646,22 @@ args_has(struct args *args, u_char flag)
|
|||||||
|
|
||||||
/* Set argument value in the arguments tree. */
|
/* Set argument value in the arguments tree. */
|
||||||
void
|
void
|
||||||
args_set(struct args *args, u_char flag, const char *s)
|
args_set(struct args *args, u_char flag, struct args_value *value, int flags)
|
||||||
{
|
{
|
||||||
struct args_entry *entry;
|
struct args_entry *entry;
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
entry = args_find(args, flag);
|
entry = args_find(args, flag);
|
||||||
if (entry == NULL) {
|
if (entry == NULL) {
|
||||||
entry = xcalloc(1, sizeof *entry);
|
entry = xcalloc(1, sizeof *entry);
|
||||||
entry->flag = flag;
|
entry->flag = flag;
|
||||||
entry->count = 1;
|
entry->count = 1;
|
||||||
|
entry->flags = flags;
|
||||||
TAILQ_INIT(&entry->values);
|
TAILQ_INIT(&entry->values);
|
||||||
RB_INSERT(args_tree, &args->tree, entry);
|
RB_INSERT(args_tree, &args->tree, entry);
|
||||||
} else
|
} else
|
||||||
entry->count++;
|
entry->count++;
|
||||||
|
if (value != NULL && value->type != ARGS_NONE)
|
||||||
if (s != NULL) {
|
|
||||||
value = xcalloc(1, sizeof *value);
|
|
||||||
value->value = xstrdup(s);
|
|
||||||
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get argument value. Will be NULL if it isn't present. */
|
/* Get argument value. Will be NULL if it isn't present. */
|
||||||
@@ -300,7 +674,7 @@ args_get(struct args *args, u_char flag)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
if (TAILQ_EMPTY(&entry->values))
|
if (TAILQ_EMPTY(&entry->values))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
return (TAILQ_LAST(&entry->values, args_values)->value);
|
return (TAILQ_LAST(&entry->values, args_values)->string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get first argument. */
|
/* Get first argument. */
|
||||||
@@ -323,31 +697,194 @@ args_next(struct args_entry **entry)
|
|||||||
return ((*entry)->flag);
|
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 *
|
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;
|
||||||
|
const char *file;
|
||||||
|
|
||||||
|
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, &file, &state->pi.line);
|
||||||
|
if (file != NULL)
|
||||||
|
state->pi.file = xstrdup(file);
|
||||||
|
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);
|
||||||
|
log_debug("%s: %s", __func__, cmd);
|
||||||
|
cmd_log_argv(argc, argv, __func__);
|
||||||
|
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((void *)state->pi.file);
|
||||||
|
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;
|
struct args_entry *entry;
|
||||||
|
|
||||||
if ((entry = args_find(args, flag)) == NULL)
|
if ((entry = args_find(args, flag)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
return (TAILQ_FIRST(&entry->values));
|
||||||
*value = TAILQ_FIRST(&entry->values);
|
|
||||||
if (*value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return ((*value)->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get next value in argument. */
|
/* Get next value in argument. */
|
||||||
const char *
|
struct args_value *
|
||||||
args_next_value(struct args_value **value)
|
args_next_value(struct args_value *value)
|
||||||
{
|
{
|
||||||
if (*value == NULL)
|
return (TAILQ_NEXT(value, entry));
|
||||||
return (NULL);
|
|
||||||
*value = TAILQ_NEXT(*value, entry);
|
|
||||||
if (*value == NULL)
|
|
||||||
return (NULL);
|
|
||||||
return ((*value)->value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert an argument value to a number. */
|
/* Convert an argument value to a number. */
|
||||||
@@ -356,7 +893,7 @@ args_strtonum(struct args *args, u_char flag, long long minval,
|
|||||||
long long maxval, char **cause)
|
long long maxval, char **cause)
|
||||||
{
|
{
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
long long ll;
|
long long ll;
|
||||||
struct args_entry *entry;
|
struct args_entry *entry;
|
||||||
struct args_value *value;
|
struct args_value *value;
|
||||||
|
|
||||||
@@ -365,8 +902,49 @@ args_strtonum(struct args *args, u_char flag, long long minval,
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
value = TAILQ_LAST(&entry->values, args_values);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
*cause = NULL;
|
||||||
|
return (ll);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert an argument value to a number, and expand formats. */
|
||||||
|
long long
|
||||||
|
args_strtonum_and_expand(struct args *args, u_char flag, long long minval,
|
||||||
|
long long maxval, struct cmdq_item *item, char **cause)
|
||||||
|
{
|
||||||
|
const char *errstr;
|
||||||
|
char *formatted;
|
||||||
|
long long ll;
|
||||||
|
struct args_entry *entry;
|
||||||
|
struct args_value *value;
|
||||||
|
|
||||||
|
if ((entry = args_find(args, flag)) == NULL) {
|
||||||
|
*cause = xstrdup("missing");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
value = TAILQ_LAST(&entry->values, args_values);
|
||||||
|
if (value == NULL ||
|
||||||
|
value->type != ARGS_STRING ||
|
||||||
|
value->string == NULL) {
|
||||||
|
*cause = xstrdup("missing");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
formatted = format_single_from_target(item, value->string);
|
||||||
|
ll = strtonum(formatted, minval, maxval, &errstr);
|
||||||
|
free(formatted);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
*cause = xstrdup(errstr);
|
*cause = xstrdup(errstr);
|
||||||
return (0);
|
return (0);
|
||||||
@@ -388,7 +966,11 @@ args_percentage(struct args *args, u_char flag, long long minval,
|
|||||||
*cause = xstrdup("missing");
|
*cause = xstrdup("missing");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
value = TAILQ_LAST(&entry->values, args_values)->value;
|
if (TAILQ_EMPTY(&entry->values)) {
|
||||||
|
*cause = xstrdup("empty");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
value = TAILQ_LAST(&entry->values, args_values)->string;
|
||||||
return (args_string_percentage(value, minval, maxval, curval, cause));
|
return (args_string_percentage(value, minval, maxval, curval, cause));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,10 +980,14 @@ args_string_percentage(const char *value, long long minval, long long maxval,
|
|||||||
long long curval, char **cause)
|
long long curval, char **cause)
|
||||||
{
|
{
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
long long ll;
|
long long ll;
|
||||||
size_t valuelen = strlen(value);
|
size_t valuelen = strlen(value);
|
||||||
char *copy;
|
char *copy;
|
||||||
|
|
||||||
|
if (valuelen == 0) {
|
||||||
|
*cause = xstrdup("empty");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
if (value[valuelen - 1] == '%') {
|
if (value[valuelen - 1] == '%') {
|
||||||
copy = xstrdup(value);
|
copy = xstrdup(value);
|
||||||
copy[valuelen - 1] = '\0';
|
copy[valuelen - 1] = '\0';
|
||||||
@@ -432,3 +1018,74 @@ args_string_percentage(const char *value, long long minval, long long maxval,
|
|||||||
*cause = NULL;
|
*cause = NULL;
|
||||||
return (ll);
|
return (ll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert an argument to a number which may be a percentage, and expand
|
||||||
|
* formats.
|
||||||
|
*/
|
||||||
|
long long
|
||||||
|
args_percentage_and_expand(struct args *args, u_char flag, long long minval,
|
||||||
|
long long maxval, long long curval, struct cmdq_item *item, char **cause)
|
||||||
|
{
|
||||||
|
const char *value;
|
||||||
|
struct args_entry *entry;
|
||||||
|
|
||||||
|
if ((entry = args_find(args, flag)) == NULL) {
|
||||||
|
*cause = xstrdup("missing");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (TAILQ_EMPTY(&entry->values)) {
|
||||||
|
*cause = xstrdup("empty");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
value = TAILQ_LAST(&entry->values, args_values)->string;
|
||||||
|
return (args_string_percentage_and_expand(value, minval, maxval, curval,
|
||||||
|
item, cause));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string to a number which may be a percentage, and expand formats.
|
||||||
|
*/
|
||||||
|
long long
|
||||||
|
args_string_percentage_and_expand(const char *value, long long minval,
|
||||||
|
long long maxval, long long curval, struct cmdq_item *item, char **cause)
|
||||||
|
{
|
||||||
|
const char *errstr;
|
||||||
|
long long ll;
|
||||||
|
size_t valuelen = strlen(value);
|
||||||
|
char *copy, *f;
|
||||||
|
|
||||||
|
if (value[valuelen - 1] == '%') {
|
||||||
|
copy = xstrdup(value);
|
||||||
|
copy[valuelen - 1] = '\0';
|
||||||
|
|
||||||
|
f = format_single_from_target(item, copy);
|
||||||
|
ll = strtonum(f, 0, 100, &errstr);
|
||||||
|
free(f);
|
||||||
|
free(copy);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
*cause = xstrdup(errstr);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
ll = (curval * ll) / 100;
|
||||||
|
if (ll < minval) {
|
||||||
|
*cause = xstrdup("too small");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (ll > maxval) {
|
||||||
|
*cause = xstrdup("too large");
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
f = format_single_from_target(item, value);
|
||||||
|
ll = strtonum(f, minval, maxval, &errstr);
|
||||||
|
free(f);
|
||||||
|
if (errstr != NULL) {
|
||||||
|
*cause = xstrdup(errstr);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*cause = NULL;
|
||||||
|
return (ll);
|
||||||
|
}
|
||||||
|
|||||||
53
cfg.c
53
cfg.c
@@ -51,8 +51,7 @@ cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
cfg_finished = 1;
|
cfg_finished = 1;
|
||||||
|
|
||||||
if (!RB_EMPTY(&sessions))
|
cfg_show_causes(NULL);
|
||||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
|
||||||
|
|
||||||
if (cfg_item != NULL)
|
if (cfg_item != NULL)
|
||||||
cmdq_continue(cfg_item);
|
cmdq_continue(cfg_item);
|
||||||
@@ -67,6 +66,7 @@ start_cfg(void)
|
|||||||
{
|
{
|
||||||
struct client *c;
|
struct client *c;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
int flags = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configuration files are loaded without a client, so commands are run
|
* Configuration files are loaded without a client, so commands are run
|
||||||
@@ -84,19 +84,17 @@ start_cfg(void)
|
|||||||
cmdq_append(c, cfg_item);
|
cmdq_append(c, cfg_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cfg_nfiles; i++) {
|
if (cfg_quiet)
|
||||||
if (cfg_quiet)
|
flags = CMD_PARSE_QUIET;
|
||||||
load_cfg(cfg_files[i], c, NULL, CMD_PARSE_QUIET, NULL);
|
for (i = 0; i < cfg_nfiles; i++)
|
||||||
else
|
load_cfg(cfg_files[i], c, NULL, NULL, flags, NULL);
|
||||||
load_cfg(cfg_files[i], c, NULL, 0, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
load_cfg(const char *path, struct client *c, struct cmdq_item *item,
|
||||||
struct cmdq_item **new_item)
|
struct cmd_find_state *current, int flags, struct cmdq_item **new_item)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
struct cmd_parse_input pi;
|
struct cmd_parse_input pi;
|
||||||
@@ -124,8 +122,6 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
|||||||
|
|
||||||
pr = cmd_parse_from_file(f, &pi);
|
pr = cmd_parse_from_file(f, &pi);
|
||||||
fclose(f);
|
fclose(f);
|
||||||
if (pr->status == CMD_PARSE_EMPTY)
|
|
||||||
return (0);
|
|
||||||
if (pr->status == CMD_PARSE_ERROR) {
|
if (pr->status == CMD_PARSE_ERROR) {
|
||||||
cfg_add_cause("%s", pr->error);
|
cfg_add_cause("%s", pr->error);
|
||||||
free(pr->error);
|
free(pr->error);
|
||||||
@@ -137,7 +133,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
state = cmdq_copy_state(cmdq_get_state(item));
|
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||||
else
|
else
|
||||||
state = cmdq_new_state(NULL, NULL, 0);
|
state = cmdq_new_state(NULL, NULL, 0);
|
||||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||||
@@ -157,8 +153,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
|||||||
|
|
||||||
int
|
int
|
||||||
load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
||||||
struct client *c, struct cmdq_item *item, int flags,
|
struct client *c, struct cmdq_item *item, struct cmd_find_state *current,
|
||||||
struct cmdq_item **new_item)
|
int flags, struct cmdq_item **new_item)
|
||||||
{
|
{
|
||||||
struct cmd_parse_input pi;
|
struct cmd_parse_input pi;
|
||||||
struct cmd_parse_result *pr;
|
struct cmd_parse_result *pr;
|
||||||
@@ -178,8 +174,6 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
|||||||
pi.c = c;
|
pi.c = c;
|
||||||
|
|
||||||
pr = cmd_parse_from_buffer(buf, len, &pi);
|
pr = cmd_parse_from_buffer(buf, len, &pi);
|
||||||
if (pr->status == CMD_PARSE_EMPTY)
|
|
||||||
return (0);
|
|
||||||
if (pr->status == CMD_PARSE_ERROR) {
|
if (pr->status == CMD_PARSE_ERROR) {
|
||||||
cfg_add_cause("%s", pr->error);
|
cfg_add_cause("%s", pr->error);
|
||||||
free(pr->error);
|
free(pr->error);
|
||||||
@@ -191,7 +185,7 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (item != NULL)
|
if (item != NULL)
|
||||||
state = cmdq_copy_state(cmdq_get_state(item));
|
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||||
else
|
else
|
||||||
state = cmdq_new_state(NULL, NULL, 0);
|
state = cmdq_new_state(NULL, NULL, 0);
|
||||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||||
@@ -242,11 +236,29 @@ cfg_print_causes(struct cmdq_item *item)
|
|||||||
void
|
void
|
||||||
cfg_show_causes(struct session *s)
|
cfg_show_causes(struct session *s)
|
||||||
{
|
{
|
||||||
|
struct client *c = TAILQ_FIRST(&clients);
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct window_mode_entry *wme;
|
struct window_mode_entry *wme;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (s == NULL || cfg_ncauses == 0)
|
if (cfg_ncauses == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (c != NULL && (c->flags & CLIENT_CONTROL)) {
|
||||||
|
for (i = 0; i < cfg_ncauses; i++) {
|
||||||
|
control_write(c, "%%config-error %s", cfg_causes[i]);
|
||||||
|
free(cfg_causes[i]);
|
||||||
|
}
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s == NULL) {
|
||||||
|
if (c != NULL && c->session != NULL)
|
||||||
|
s = c->session;
|
||||||
|
else
|
||||||
|
s = RB_MIN(sessions, &sessions);
|
||||||
|
}
|
||||||
|
if (s == NULL || s->attached == 0) /* wait for an attached session */
|
||||||
return;
|
return;
|
||||||
wp = s->curw->window->active;
|
wp = s->curw->window->active;
|
||||||
|
|
||||||
@@ -254,10 +266,11 @@ cfg_show_causes(struct session *s)
|
|||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
if (wme == NULL || wme->mode != &window_view_mode)
|
||||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
||||||
for (i = 0; i < cfg_ncauses; i++) {
|
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]);
|
free(cfg_causes[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
free(cfg_causes);
|
free(cfg_causes);
|
||||||
cfg_causes = NULL;
|
cfg_causes = NULL;
|
||||||
cfg_ncauses = 0;
|
cfg_ncauses = 0;
|
||||||
|
|||||||
44
client.c
44
client.c
@@ -243,9 +243,7 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
|||||||
ssize_t linelen;
|
ssize_t linelen;
|
||||||
char *line = NULL, **caps = NULL, *cause;
|
char *line = NULL, **caps = NULL, *cause;
|
||||||
u_int ncaps = 0;
|
u_int ncaps = 0;
|
||||||
|
struct args_value *values;
|
||||||
/* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */
|
|
||||||
signal(SIGCHLD, SIG_IGN);
|
|
||||||
|
|
||||||
/* Set up the initial command. */
|
/* Set up the initial command. */
|
||||||
if (shell_command != NULL) {
|
if (shell_command != NULL) {
|
||||||
@@ -258,17 +256,20 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
|||||||
msg = MSG_COMMAND;
|
msg = MSG_COMMAND;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* It sucks parsing the command string twice (in client and
|
* It's annoying parsing the command string twice (in client
|
||||||
* later in server) but it is necessary to get the start server
|
* and later in server) but it is necessary to get the start
|
||||||
* flag.
|
* 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 (pr->status == CMD_PARSE_SUCCESS) {
|
||||||
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
|
if (cmd_list_any_have(pr->cmdlist, CMD_STARTSERVER))
|
||||||
flags |= CLIENT_STARTSERVER;
|
flags |= CLIENT_STARTSERVER;
|
||||||
cmd_list_free(pr->cmdlist);
|
cmd_list_free(pr->cmdlist);
|
||||||
} else
|
} else
|
||||||
free(pr->error);
|
free(pr->error);
|
||||||
|
args_free_values(values, argc);
|
||||||
|
free(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create client process structure (starts logging). */
|
/* Create client process structure (starts logging). */
|
||||||
@@ -280,6 +281,12 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
|||||||
log_debug("flags are %#llx", (unsigned long long)client_flags);
|
log_debug("flags are %#llx", (unsigned long long)client_flags);
|
||||||
|
|
||||||
/* Initialize the client socket and start the server. */
|
/* Initialize the client socket and start the server. */
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
if (systemd_activated()) {
|
||||||
|
/* socket-based activation, do not even try to be a client. */
|
||||||
|
fd = server_start(client_proc, flags, base, 0, NULL);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
fd = client_connect(base, socket_path, client_flags);
|
fd = client_connect(base, socket_path, client_flags);
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
if (errno == ECONNREFUSED) {
|
if (errno == ECONNREFUSED) {
|
||||||
@@ -357,6 +364,7 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
|||||||
/* Send identify messages. */
|
/* Send identify messages. */
|
||||||
client_send_identify(ttynam, termname, caps, ncaps, cwd, feat);
|
client_send_identify(ttynam, termname, caps, ncaps, cwd, feat);
|
||||||
tty_term_free_list(caps, ncaps);
|
tty_term_free_list(caps, ncaps);
|
||||||
|
proc_flush_peer(client_peer);
|
||||||
|
|
||||||
/* Send first command. */
|
/* Send first command. */
|
||||||
if (msg == MSG_COMMAND) {
|
if (msg == MSG_COMMAND) {
|
||||||
@@ -522,12 +530,23 @@ client_signal(int sig)
|
|||||||
{
|
{
|
||||||
struct sigaction sigact;
|
struct sigaction sigact;
|
||||||
int status;
|
int status;
|
||||||
|
pid_t pid;
|
||||||
|
|
||||||
log_debug("%s: %s", __func__, strsignal(sig));
|
log_debug("%s: %s", __func__, strsignal(sig));
|
||||||
if (sig == SIGCHLD)
|
if (sig == SIGCHLD) {
|
||||||
waitpid(WAIT_ANY, &status, WNOHANG);
|
for (;;) {
|
||||||
else if (!client_attached) {
|
pid = waitpid(WAIT_ANY, &status, WNOHANG);
|
||||||
if (sig == SIGTERM)
|
if (pid == 0)
|
||||||
|
break;
|
||||||
|
if (pid == -1) {
|
||||||
|
if (errno == ECHILD)
|
||||||
|
break;
|
||||||
|
log_debug("waitpid failed: %s",
|
||||||
|
strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!client_attached) {
|
||||||
|
if (sig == SIGTERM || sig == SIGHUP)
|
||||||
proc_exit(client_proc);
|
proc_exit(client_proc);
|
||||||
} else {
|
} else {
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
@@ -689,6 +708,9 @@ client_dispatch_wait(struct imsg *imsg)
|
|||||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||||
NULL);
|
NULL);
|
||||||
break;
|
break;
|
||||||
|
case MSG_READ_CANCEL:
|
||||||
|
file_read_cancel(&client_files, imsg);
|
||||||
|
break;
|
||||||
case MSG_WRITE_OPEN:
|
case MSG_WRITE_OPEN:
|
||||||
file_write_open(&client_files, client_peer, imsg, 1,
|
file_write_open(&client_files, client_peer, imsg, 1,
|
||||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||||
|
|||||||
@@ -37,13 +37,13 @@ const struct cmd_entry cmd_attach_session_entry = {
|
|||||||
.name = "attach-session",
|
.name = "attach-session",
|
||||||
.alias = "attach",
|
.alias = "attach",
|
||||||
|
|
||||||
.args = { "c:dEf:rt:x", 0, 0 },
|
.args = { "c:dEf:rt:x", 0, 0, NULL },
|
||||||
.usage = "[-dErx] [-c working-directory] [-f flags] "
|
.usage = "[-dErx] [-c working-directory] [-f flags] "
|
||||||
CMD_TARGET_SESSION_USAGE,
|
CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
/* -t is special */
|
/* -t is special */
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER,
|
.flags = CMD_STARTSERVER|CMD_READONLY,
|
||||||
.exec = cmd_attach_session_exec
|
.exec = cmd_attach_session_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,6 +69,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
if (server_client_check_nested(c)) {
|
if (server_client_check_nested(c)) {
|
||||||
cmdq_error(item, "sessions should be nested with care, "
|
cmdq_error(item, "sessions should be nested with care, "
|
||||||
"unset $TMUX to force");
|
"unset $TMUX to force");
|
||||||
@@ -124,17 +125,9 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
if (!Eflag)
|
if (!Eflag)
|
||||||
environ_update(s->options, c->environ, s->environ);
|
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)
|
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||||
server_client_set_key_table(c, NULL);
|
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 {
|
} else {
|
||||||
if (server_client_open(c, &cause) != 0) {
|
if (server_client_open(c, &cause) != 0) {
|
||||||
cmdq_error(item, "open terminal failed: %s", cause);
|
cmdq_error(item, "open terminal failed: %s", cause);
|
||||||
@@ -156,25 +149,17 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
|||||||
if (!Eflag)
|
if (!Eflag)
|
||||||
environ_update(s->options, c->environ, s->environ);
|
environ_update(s->options, c->environ, s->environ);
|
||||||
|
|
||||||
c->session = s;
|
server_client_set_session(c, s);
|
||||||
server_client_set_key_table(c, NULL);
|
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)
|
if (~c->flags & CLIENT_CONTROL)
|
||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||||
notify_client("client-attached", c);
|
notify_client("client-attached", c);
|
||||||
c->flags |= CLIENT_ATTACHED;
|
c->flags |= CLIENT_ATTACHED;
|
||||||
}
|
}
|
||||||
recalculate_sizes();
|
|
||||||
alerts_check_session(s);
|
if (cfg_finished)
|
||||||
server_update_socket();
|
cfg_show_causes(s);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,16 @@
|
|||||||
* Bind a key to a command.
|
* 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 = {
|
const struct cmd_entry cmd_bind_key_entry = {
|
||||||
.name = "bind-key",
|
.name = "bind-key",
|
||||||
.alias = "bind",
|
.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 "
|
.usage = "[-nr] [-T key-table] [-N note] key "
|
||||||
"[command [arguments]]",
|
"[command [arguments]]",
|
||||||
|
|
||||||
@@ -41,6 +44,13 @@ const struct cmd_entry cmd_bind_key_entry = {
|
|||||||
.exec = cmd_bind_key_exec
|
.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
|
static enum cmd_retval
|
||||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
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;
|
key_code key;
|
||||||
const char *tablename, *note = args_get(args, 'N');
|
const char *tablename, *note = args_get(args, 'N');
|
||||||
struct cmd_parse_result *pr;
|
struct cmd_parse_result *pr;
|
||||||
char **argv = args->argv;
|
int repeat;
|
||||||
int argc = args->argc, 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) {
|
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);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,24 +76,32 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
tablename = "prefix";
|
tablename = "prefix";
|
||||||
repeat = args_has(args, 'r');
|
repeat = args_has(args, 'r');
|
||||||
|
|
||||||
if (argc != 1) {
|
if (count == 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
|
|
||||||
key_bindings_add(tablename, key, note, repeat, NULL);
|
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);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_break_pane_entry = {
|
|||||||
.name = "break-pane",
|
.name = "break-pane",
|
||||||
.alias = "breakp",
|
.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] "
|
.usage = "[-abdP] [-F format] [-n window-name] [-s src-pane] "
|
||||||
"[-t dst-window]",
|
"[-t dst-window]",
|
||||||
|
|
||||||
@@ -115,6 +115,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
layout_init(w, wp);
|
layout_init(w, wp);
|
||||||
wp->flags |= PANE_CHANGED;
|
wp->flags |= PANE_CHANGED;
|
||||||
|
colour_palette_from_option(&wp->palette, wp->options);
|
||||||
|
|
||||||
if (idx == -1)
|
if (idx == -1)
|
||||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
idx = -1 - options_get_number(dst_s->options, "base-index");
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
|||||||
.name = "capture-pane",
|
.name = "capture-pane",
|
||||||
.alias = "capturep",
|
.alias = "capturep",
|
||||||
|
|
||||||
.args = { "ab:CeE:JNpPqS:t:", 0, 0 },
|
.args = { "ab:CeE:JNpPqS:Tt:", 0, 0, NULL },
|
||||||
.usage = "[-aCeJNpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
.usage = "[-aCeJNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -53,8 +53,8 @@ const struct cmd_entry cmd_clear_history_entry = {
|
|||||||
.name = "clear-history",
|
.name = "clear-history",
|
||||||
.alias = "clearhist",
|
.alias = "clearhist",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "Ht:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_PANE_USAGE,
|
.usage = "[-H] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
const struct grid_line *gl;
|
const struct grid_line *gl;
|
||||||
struct grid_cell *gc = NULL;
|
struct grid_cell *gc = NULL;
|
||||||
int n, with_codes, escape_c0, join_lines, no_trim;
|
int n, join_lines, flags = 0;
|
||||||
u_int i, sx, top, bottom, tmp;
|
u_int i, sx, top, bottom, tmp;
|
||||||
char *cause, *buf, *line;
|
char *cause, *buf, *line;
|
||||||
const char *Sflag, *Eflag;
|
const char *Sflag, *Eflag;
|
||||||
@@ -133,7 +133,8 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
||||||
top = 0;
|
top = 0;
|
||||||
else {
|
else {
|
||||||
n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause);
|
n = args_strtonum_and_expand(args, 'S', INT_MIN, SHRT_MAX,
|
||||||
|
item, &cause);
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
top = gd->hsize;
|
top = gd->hsize;
|
||||||
free(cause);
|
free(cause);
|
||||||
@@ -149,7 +150,8 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
|
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
else {
|
else {
|
||||||
n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause);
|
n = args_strtonum_and_expand(args, 'E', INT_MIN, SHRT_MAX,
|
||||||
|
item, &cause);
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
bottom = gd->hsize + gd->sy - 1;
|
bottom = gd->hsize + gd->sy - 1;
|
||||||
free(cause);
|
free(cause);
|
||||||
@@ -167,15 +169,19 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
|||||||
top = tmp;
|
top = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
with_codes = args_has(args, 'e');
|
|
||||||
escape_c0 = args_has(args, 'C');
|
|
||||||
join_lines = args_has(args, 'J');
|
join_lines = args_has(args, 'J');
|
||||||
no_trim = args_has(args, 'N');
|
if (args_has(args, 'e'))
|
||||||
|
flags |= GRID_STRING_WITH_SEQUENCES;
|
||||||
|
if (args_has(args, 'C'))
|
||||||
|
flags |= GRID_STRING_ESCAPE_SEQUENCES;
|
||||||
|
if (!join_lines && !args_has(args, 'T'))
|
||||||
|
flags |= GRID_STRING_EMPTY_CELLS;
|
||||||
|
if (!join_lines && !args_has(args, 'N'))
|
||||||
|
flags |= GRID_STRING_TRIM_SPACES;
|
||||||
|
|
||||||
buf = NULL;
|
buf = NULL;
|
||||||
for (i = top; i <= bottom; i++) {
|
for (i = top; i <= bottom; i++) {
|
||||||
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
line = grid_string_cells(gd, 0, i, sx, &gc, flags, wp->screen);
|
||||||
escape_c0, !join_lines && !no_trim);
|
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
|
|
||||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
||||||
@@ -202,6 +208,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
||||||
window_pane_reset_mode_all(wp);
|
window_pane_reset_mode_all(wp);
|
||||||
grid_clear_history(wp->base.grid);
|
grid_clear_history(wp->base.grid);
|
||||||
|
if (args_has(args, 'H'))
|
||||||
|
screen_reset_hyperlinks(wp->screen);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,13 +24,16 @@
|
|||||||
* Enter a mode.
|
* 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 = {
|
const struct cmd_entry cmd_choose_tree_entry = {
|
||||||
.name = "choose-tree",
|
.name = "choose-tree",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:GK:NO:rst:wZ", 0, 1 },
|
.args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
|
||||||
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
|
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
|
||||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = {
|
|||||||
.name = "choose-client",
|
.name = "choose-client",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:K:NO:rt:Z", 0, 1 },
|
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||||
|
|
||||||
@@ -58,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
|||||||
.name = "choose-buffer",
|
.name = "choose-buffer",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:K:NO:rt:Z", 0, 1 },
|
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||||
|
|
||||||
@@ -72,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = {
|
|||||||
.name = "customize-mode",
|
.name = "customize-mode",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "F:f:Nt:Z", 0, 0 },
|
.args = { "F:f:Nt:Z", 0, 0, NULL },
|
||||||
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
|
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -81,6 +84,13 @@ const struct cmd_entry cmd_customize_mode_entry = {
|
|||||||
.exec = cmd_choose_tree_exec
|
.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
|
static enum cmd_retval
|
||||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
@@ -90,7 +100,7 @@ cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
const struct window_mode *mode;
|
const struct window_mode *mode;
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
|
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
|
||||||
if (paste_get_top(NULL) == NULL)
|
if (paste_is_empty())
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
mode = &window_buffer_mode;
|
mode = &window_buffer_mode;
|
||||||
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
|
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
|
||||||
|
|||||||
@@ -29,8 +29,10 @@
|
|||||||
* Prompt for command in client.
|
* Prompt for command in client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
static enum args_parse_type cmd_command_prompt_args_parse(struct args *,
|
||||||
struct cmdq_item *);
|
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 *,
|
static int cmd_command_prompt_callback(struct client *, void *,
|
||||||
const char *, int);
|
const char *, int);
|
||||||
@@ -40,79 +42,111 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
|||||||
.name = "command-prompt",
|
.name = "command-prompt",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "1kiI:Np:Tt:W", 0, 1 },
|
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
||||||
.usage = "[-1kiNTW] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
||||||
"[template]",
|
" [-T type] [template]",
|
||||||
|
|
||||||
.flags = CMD_CLIENT_TFLAG,
|
.flags = CMD_CLIENT_TFLAG,
|
||||||
.exec = cmd_command_prompt_exec
|
.exec = cmd_command_prompt_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_command_prompt_cdata {
|
struct cmd_command_prompt_prompt {
|
||||||
int flags;
|
char *input;
|
||||||
|
char *prompt;
|
||||||
char *inputs;
|
|
||||||
char *next_input;
|
|
||||||
|
|
||||||
char *prompts;
|
|
||||||
char *next_prompt;
|
|
||||||
|
|
||||||
char *template;
|
|
||||||
int idx;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
static enum cmd_retval
|
||||||
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct cmd_find_state *target = cmdq_get_target(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;
|
struct cmd_command_prompt_cdata *cdata;
|
||||||
char *prompt, *ptr, *input = NULL;
|
char *tmp, *prompts, *prompt, *next_prompt;
|
||||||
size_t n;
|
char *inputs = NULL, *next_input;
|
||||||
|
u_int count = args_count(args);
|
||||||
|
int wait = !args_has(args, 'b'), space = 1;
|
||||||
|
|
||||||
if (tc->prompt_string != NULL)
|
if (tc->prompt_string != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
if (args_has(args, 'i'))
|
||||||
|
wait = 0;
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
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;
|
if ((s = args_get(args, 'p')) == NULL) {
|
||||||
cdata->next_input = NULL;
|
if (count != 0) {
|
||||||
|
tmp = args_make_commands_get_command(cdata->state);
|
||||||
cdata->prompts = NULL;
|
xasprintf(&prompts, "(%s)", tmp);
|
||||||
cdata->next_prompt = NULL;
|
free(tmp);
|
||||||
|
} else {
|
||||||
cdata->template = NULL;
|
prompts = xstrdup(":");
|
||||||
cdata->idx = 1;
|
space = 0;
|
||||||
|
}
|
||||||
if (args->argc != 0)
|
next_prompt = prompts;
|
||||||
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);
|
|
||||||
} else
|
} else
|
||||||
cdata->prompts = xstrdup(":");
|
next_prompt = prompts = xstrdup(s);
|
||||||
|
if ((s = args_get(args, 'I')) != NULL)
|
||||||
/* Get first prompt. */
|
next_input = inputs = xstrdup(s);
|
||||||
cdata->next_prompt = cdata->prompts;
|
|
||||||
ptr = strsep(&cdata->next_prompt, ",");
|
|
||||||
if (prompts == NULL)
|
|
||||||
prompt = xstrdup(ptr);
|
|
||||||
else
|
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 (next_input != NULL) {
|
||||||
if ((inputs = args_get(args, 'I')) != NULL) {
|
input = strsep(&next_input, ",");
|
||||||
cdata->inputs = xstrdup(inputs);
|
if (input == NULL)
|
||||||
cdata->next_input = cdata->inputs;
|
input = "";
|
||||||
input = strsep(&cdata->next_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'))
|
if (args_has(args, '1'))
|
||||||
cdata->flags |= PROMPT_SINGLE;
|
cdata->flags |= PROMPT_SINGLE;
|
||||||
@@ -122,62 +156,71 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cdata->flags |= PROMPT_INCREMENTAL;
|
cdata->flags |= PROMPT_INCREMENTAL;
|
||||||
else if (args_has(args, 'k'))
|
else if (args_has(args, 'k'))
|
||||||
cdata->flags |= PROMPT_KEY;
|
cdata->flags |= PROMPT_KEY;
|
||||||
else if (args_has(args, 'W'))
|
status_prompt_set(tc, target, cdata->prompts[0].prompt,
|
||||||
cdata->flags |= PROMPT_WINDOW;
|
cdata->prompts[0].input, cmd_command_prompt_callback,
|
||||||
else if (args_has(args, 'T'))
|
cmd_command_prompt_free, cdata, cdata->flags, cdata->prompt_type);
|
||||||
cdata->flags |= PROMPT_TARGET;
|
|
||||||
status_prompt_set(tc, target, prompt, input,
|
|
||||||
cmd_command_prompt_callback, cmd_command_prompt_free, cdata,
|
|
||||||
cdata->flags);
|
|
||||||
free(prompt);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
if (!wait)
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||||
int done)
|
int done)
|
||||||
{
|
{
|
||||||
struct cmd_command_prompt_cdata *cdata = data;
|
struct cmd_command_prompt_cdata *cdata = data;
|
||||||
char *new_template, *prompt, *ptr, *error;
|
char *error;
|
||||||
char *input = NULL;
|
struct cmdq_item *item = cdata->item, *new_item;
|
||||||
enum cmd_parse_status status;
|
struct cmd_list *cmdlist;
|
||||||
|
struct cmd_command_prompt_prompt *prompt;
|
||||||
|
int argc = 0;
|
||||||
|
char **argv = NULL;
|
||||||
|
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return (0);
|
goto out;
|
||||||
if (done && (cdata->flags & PROMPT_INCREMENTAL))
|
|
||||||
return (0);
|
|
||||||
|
|
||||||
new_template = cmd_template_replace(cdata->template, s, cdata->idx);
|
|
||||||
if (done) {
|
if (done) {
|
||||||
free(cdata->template);
|
if (cdata->flags & PROMPT_INCREMENTAL)
|
||||||
cdata->template = new_template;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
argc = cdata->argc;
|
||||||
* Check if there are more prompts; if so, get its respective input
|
argv = cmd_copy_argv(cdata->argc, cdata->argv);
|
||||||
* and update the prompt data.
|
if (!done)
|
||||||
*/
|
cmd_append_argv(&argc, &argv, s);
|
||||||
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);
|
if (done) {
|
||||||
cdata->idx++;
|
cmd_free_argv(cdata->argc, cdata->argv);
|
||||||
return (1);
|
cdata->argc = argc;
|
||||||
|
cdata->argv = cmd_copy_argv(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = cmd_parse_and_append(new_template, NULL, c, NULL, &error);
|
cmdlist = args_make_commands(cdata->state, argc, argv, &error);
|
||||||
if (status == CMD_PARSE_ERROR) {
|
if (cmdlist == NULL) {
|
||||||
cmdq_append(c, cmdq_get_error(error));
|
cmdq_append(c, cmdq_get_error(error));
|
||||||
free(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)
|
if (c->prompt_inputcb != cmd_command_prompt_callback)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (item != NULL)
|
||||||
|
cmdq_continue(item);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,9 +228,14 @@ static void
|
|||||||
cmd_command_prompt_free(void *data)
|
cmd_command_prompt_free(void *data)
|
||||||
{
|
{
|
||||||
struct cmd_command_prompt_cdata *cdata = 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->prompts);
|
||||||
free(cdata->template);
|
cmd_free_argv(cdata->argc, cdata->argv);
|
||||||
|
args_make_commands_free(cdata->state);
|
||||||
free(cdata);
|
free(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,10 @@
|
|||||||
* Asks for confirmation before executing a command.
|
* Asks for confirmation before executing a command.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
static enum args_parse_type cmd_confirm_before_args_parse(struct args *,
|
||||||
struct cmdq_item *);
|
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 *,
|
static int cmd_confirm_before_callback(struct client *, void *,
|
||||||
const char *, int);
|
const char *, int);
|
||||||
@@ -39,17 +41,28 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
|||||||
.name = "confirm-before",
|
.name = "confirm-before",
|
||||||
.alias = "confirm",
|
.alias = "confirm",
|
||||||
|
|
||||||
.args = { "p:t:", 1, 1 },
|
.args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
|
||||||
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
.usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
|
||||||
|
" command",
|
||||||
|
|
||||||
.flags = CMD_CLIENT_TFLAG,
|
.flags = CMD_CLIENT_TFLAG,
|
||||||
.exec = cmd_confirm_before_exec
|
.exec = cmd_confirm_before_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_confirm_before_data {
|
struct cmd_confirm_before_data {
|
||||||
char *cmd;
|
struct cmdq_item *item;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
|
u_char confirm_key;
|
||||||
|
int default_yes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
static enum cmd_retval
|
||||||
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
@@ -57,27 +70,48 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct cmd_confirm_before_data *cdata;
|
struct cmd_confirm_before_data *cdata;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
char *cmd, *copy, *new_prompt, *ptr;
|
char *new_prompt;
|
||||||
const char *prompt;
|
const char *confirm_key, *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;
|
||||||
|
|
||||||
|
cdata->default_yes = args_has(args, 'y');
|
||||||
|
if ((confirm_key = args_get(args, 'c')) != NULL) {
|
||||||
|
if (confirm_key[1] == '\0' &&
|
||||||
|
confirm_key[0] > 31 &&
|
||||||
|
confirm_key[0] < 127)
|
||||||
|
cdata->confirm_key = confirm_key[0];
|
||||||
|
else {
|
||||||
|
cmdq_error(item, "invalid confirm key");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cdata->confirm_key = 'y';
|
||||||
|
|
||||||
if ((prompt = args_get(args, 'p')) != NULL)
|
if ((prompt = args_get(args, 'p')) != NULL)
|
||||||
xasprintf(&new_prompt, "%s ", prompt);
|
xasprintf(&new_prompt, "%s ", prompt);
|
||||||
else {
|
else {
|
||||||
ptr = copy = xstrdup(args->argv[0]);
|
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
|
||||||
cmd = strsep(&ptr, " \t");
|
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ",
|
||||||
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
cmd, cdata->confirm_key);
|
||||||
free(copy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
|
||||||
cdata->cmd = xstrdup(args->argv[0]);
|
|
||||||
|
|
||||||
status_prompt_set(tc, target, new_prompt, NULL,
|
status_prompt_set(tc, target, new_prompt, NULL,
|
||||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||||
PROMPT_SINGLE);
|
PROMPT_SINGLE, PROMPT_TYPE_COMMAND);
|
||||||
|
|
||||||
free(new_prompt);
|
free(new_prompt);
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
|
if (!wait)
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@@ -85,23 +119,34 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
|||||||
__unused int done)
|
__unused int done)
|
||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
char *error;
|
struct cmdq_item *item = cdata->item, *new_item;
|
||||||
enum cmd_parse_status status;
|
int retcode = 1;
|
||||||
|
|
||||||
if (c->flags & CLIENT_DEAD)
|
if (c->flags & CLIENT_DEAD)
|
||||||
return (0);
|
goto out;
|
||||||
|
|
||||||
if (s == NULL || *s == '\0')
|
if (s == NULL)
|
||||||
return (0);
|
goto out;
|
||||||
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
|
if (s[0] != cdata->confirm_key && (s[0] != '\0' || !cdata->default_yes))
|
||||||
return (0);
|
goto out;
|
||||||
|
retcode = 0;
|
||||||
|
|
||||||
status = cmd_parse_and_append(cdata->cmd, NULL, c, NULL, &error);
|
if (item == NULL) {
|
||||||
if (status == CMD_PARSE_ERROR) {
|
new_item = cmdq_get_command(cdata->cmdlist, NULL);
|
||||||
cmdq_append(c, cmdq_get_error(error));
|
cmdq_append(c, new_item);
|
||||||
free(error);
|
} 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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,6 +155,6 @@ cmd_confirm_before_free(void *data)
|
|||||||
{
|
{
|
||||||
struct cmd_confirm_before_data *cdata = data;
|
struct cmd_confirm_before_data *cdata = data;
|
||||||
|
|
||||||
free(cdata->cmd);
|
cmd_list_free(cdata->cmdlist);
|
||||||
free(cdata);
|
free(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
|||||||
.name = "copy-mode",
|
.name = "copy-mode",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "eHMs:t:uq", 0, 0 },
|
.args = { "eHMs:t:uq", 0, 0, NULL },
|
||||||
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, 0 },
|
.source = { 's', CMD_FIND_PANE, 0 },
|
||||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
|||||||
.name = "clock-mode",
|
.name = "clock-mode",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_PANE_USAGE,
|
.usage = CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_detach_client_entry = {
|
|||||||
.name = "detach-client",
|
.name = "detach-client",
|
||||||
.alias = "detach",
|
.alias = "detach",
|
||||||
|
|
||||||
.args = { "aE:s:t:P", 0, 0 },
|
.args = { "aE:s:t:P", 0, 0, NULL },
|
||||||
.usage = "[-aP] [-E shell-command] "
|
.usage = "[-aP] [-E shell-command] "
|
||||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
|||||||
.name = "suspend-client",
|
.name = "suspend-client",
|
||||||
.alias = "suspendc",
|
.alias = "suspendc",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||||
|
|
||||||
.flags = CMD_CLIENT_TFLAG,
|
.flags = CMD_CLIENT_TFLAG,
|
||||||
|
|||||||
@@ -27,17 +27,21 @@
|
|||||||
* Display a menu on a client.
|
* Display a menu on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
static enum args_parse_type cmd_display_menu_args_parse(struct args *,
|
||||||
struct cmdq_item *);
|
u_int, char **);
|
||||||
static enum cmd_retval cmd_display_popup_exec(struct cmd *,
|
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
||||||
struct cmdq_item *);
|
struct cmdq_item *);
|
||||||
|
static enum cmd_retval cmd_display_popup_exec(struct cmd *,
|
||||||
|
struct cmdq_item *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_menu_entry = {
|
const struct cmd_entry cmd_display_menu_entry = {
|
||||||
.name = "display-menu",
|
.name = "display-menu",
|
||||||
.alias = "menu",
|
.alias = "menu",
|
||||||
|
|
||||||
.args = { "c:t:OT:x:y:", 1, -1 },
|
.args = { "b:c:C:H:s:S:Ot:T:x:y:", 1, -1, cmd_display_menu_args_parse },
|
||||||
.usage = "[-O] [-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
|
.usage = "[-O] [-b border-lines] [-c target-client] "
|
||||||
|
"[-C starting-choice] [-H selected-style] [-s style] "
|
||||||
|
"[-S border-style] " CMD_TARGET_PANE_USAGE "[-T title] "
|
||||||
"[-x position] [-y position] name key command ...",
|
"[-x position] [-y position] name key command ...",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -50,10 +54,12 @@ const struct cmd_entry cmd_display_popup_entry = {
|
|||||||
.name = "display-popup",
|
.name = "display-popup",
|
||||||
.alias = "popup",
|
.alias = "popup",
|
||||||
|
|
||||||
.args = { "Cc:d:Eh:t:w:x:y:", 0, -1 },
|
.args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL },
|
||||||
.usage = "[-CE] [-c target-client] [-d start-directory] [-h height] "
|
.usage = "[-BCE] [-b border-lines] [-c target-client] "
|
||||||
CMD_TARGET_PANE_USAGE " [-w width] "
|
"[-d start-directory] [-e environment] [-h height] "
|
||||||
"[-x position] [-y position] [command]",
|
"[-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 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
@@ -61,6 +67,30 @@ const struct cmd_entry cmd_display_popup_entry = {
|
|||||||
.exec = cmd_display_popup_exec
|
.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
|
static int
|
||||||
cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
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)
|
struct args *args, u_int *px, u_int *py, u_int w, u_int h)
|
||||||
@@ -120,8 +150,6 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
|||||||
if (sr != NULL)
|
if (sr != NULL)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (line == lines)
|
|
||||||
ranges = &tc->status.entries[0].ranges;
|
|
||||||
|
|
||||||
if (sr != NULL) {
|
if (sr != NULL) {
|
||||||
format_add(ft, "popup_window_status_line_x", "%u",
|
format_add(ft, "popup_window_status_line_x", "%u",
|
||||||
@@ -174,8 +202,8 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
|||||||
} else
|
} else
|
||||||
format_add(ft, "popup_mouse_centre_y", "%ld", n);
|
format_add(ft, "popup_mouse_centre_y", "%ld", n);
|
||||||
n = (long)event->m.y + h;
|
n = (long)event->m.y + h;
|
||||||
if (n + h >= tty->sy)
|
if (n >= tty->sy)
|
||||||
format_add(ft, "popup_mouse_top", "%u", tty->sy - h);
|
format_add(ft, "popup_mouse_top", "%u", tty->sy - 1);
|
||||||
else
|
else
|
||||||
format_add(ft, "popup_mouse_top", "%ld", n);
|
format_add(ft, "popup_mouse_top", "%ld", n);
|
||||||
n = event->m.y - h;
|
n = event->m.y - h;
|
||||||
@@ -205,7 +233,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
|||||||
if (xp == NULL || strcmp(xp, "C") == 0)
|
if (xp == NULL || strcmp(xp, "C") == 0)
|
||||||
xp = "#{popup_centre_x}";
|
xp = "#{popup_centre_x}";
|
||||||
else if (strcmp(xp, "R") == 0)
|
else if (strcmp(xp, "R") == 0)
|
||||||
xp = "#{popup_right}";
|
xp = "#{popup_pane_right}";
|
||||||
else if (strcmp(xp, "P") == 0)
|
else if (strcmp(xp, "P") == 0)
|
||||||
xp = "#{popup_pane_left}";
|
xp = "#{popup_pane_left}";
|
||||||
else if (strcmp(xp, "M") == 0)
|
else if (strcmp(xp, "M") == 0)
|
||||||
@@ -219,7 +247,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
|||||||
else if (n < 0)
|
else if (n < 0)
|
||||||
n = 0;
|
n = 0;
|
||||||
*px = n;
|
*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);
|
free(p);
|
||||||
|
|
||||||
/* Expand vertical position */
|
/* Expand vertical position */
|
||||||
@@ -245,9 +273,10 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
|||||||
else if (n < 0)
|
else if (n < 0)
|
||||||
n = 0;
|
n = 0;
|
||||||
*py = n;
|
*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);
|
free(p);
|
||||||
|
|
||||||
|
format_free(ft);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -260,42 +289,62 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct menu *menu = NULL;
|
struct menu *menu = NULL;
|
||||||
struct menu_item menu_item;
|
struct menu_item menu_item;
|
||||||
const char *key;
|
const char *key, *name, *value;
|
||||||
char *title, *name;
|
const char *style = args_get(args, 's');
|
||||||
int flags = 0, i;
|
const char *border_style = args_get(args, 'S');
|
||||||
u_int px, py;
|
const char *selected_style = args_get(args, 'H');
|
||||||
|
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||||
|
char *title, *cause;
|
||||||
|
int flags = 0, starting_choice = 0;
|
||||||
|
u_int px, py, i, count = args_count(args);
|
||||||
|
struct options *o = target->s->curw->window->options;
|
||||||
|
struct options_entry *oe;
|
||||||
|
|
||||||
|
|
||||||
if (tc->overlay_draw != NULL)
|
if (tc->overlay_draw != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
|
if (args_has(args, 'C')) {
|
||||||
|
if (strcmp(args_get(args, 'C'), "-") == 0)
|
||||||
|
starting_choice = -1;
|
||||||
|
else {
|
||||||
|
starting_choice = args_strtonum(args, 'C', 0, UINT_MAX,
|
||||||
|
&cause);
|
||||||
|
if (cause != NULL) {
|
||||||
|
cmdq_error(item, "starting choice %s", cause);
|
||||||
|
free(cause);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args_has(args, 'T'))
|
if (args_has(args, 'T'))
|
||||||
title = format_single_from_target(item, args_get(args, 'T'));
|
title = format_single_from_target(item, args_get(args, 'T'));
|
||||||
else
|
else
|
||||||
title = xstrdup("");
|
title = xstrdup("");
|
||||||
menu = menu_create(title);
|
menu = menu_create(title);
|
||||||
|
free(title);
|
||||||
|
|
||||||
for (i = 0; i != args->argc; /* nothing */) {
|
for (i = 0; i != count; /* nothing */) {
|
||||||
name = args->argv[i++];
|
name = args_string(args, i++);
|
||||||
if (*name == '\0') {
|
if (*name == '\0') {
|
||||||
menu_add_item(menu, NULL, item, tc, target);
|
menu_add_item(menu, NULL, item, tc, target);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc - i < 2) {
|
if (count - i < 2) {
|
||||||
cmdq_error(item, "not enough arguments");
|
cmdq_error(item, "not enough arguments");
|
||||||
free(title);
|
|
||||||
menu_free(menu);
|
menu_free(menu);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
key = args->argv[i++];
|
key = args_string(args, i++);
|
||||||
|
|
||||||
menu_item.name = name;
|
menu_item.name = name;
|
||||||
menu_item.key = key_string_lookup_string(key);
|
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);
|
menu_add_item(menu, &menu_item, item, tc, target);
|
||||||
}
|
}
|
||||||
free(title);
|
|
||||||
if (menu == NULL) {
|
if (menu == NULL) {
|
||||||
cmdq_error(item, "invalid menu arguments");
|
cmdq_error(item, "invalid menu arguments");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -310,12 +359,24 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = args_get(args, 'b');
|
||||||
|
if (value != NULL) {
|
||||||
|
oe = options_get(o, "menu-border-lines");
|
||||||
|
lines = options_find_choice(options_table_entry(oe), value,
|
||||||
|
&cause);
|
||||||
|
if (lines == -1) {
|
||||||
|
cmdq_error(item, "menu-border-lines %s", cause);
|
||||||
|
free(cause);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (args_has(args, 'O'))
|
if (args_has(args, 'O'))
|
||||||
flags |= MENU_STAYOPEN;
|
flags |= MENU_STAYOPEN;
|
||||||
if (!event->m.valid)
|
if (!event->m.valid)
|
||||||
flags |= MENU_NOMOUSE;
|
flags |= MENU_NOMOUSE;
|
||||||
if (menu_display(menu, flags, item, px, py, tc, target, NULL,
|
if (menu_display(menu, flags, starting_choice, item, px, py, tc, lines,
|
||||||
NULL) != 0)
|
style, selected_style, border_style, target, NULL, NULL) != 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
return (CMD_RETURN_WAIT);
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
@@ -328,11 +389,17 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct tty *tty = &tc->tty;
|
struct tty *tty = &tc->tty;
|
||||||
const char *value, *shell[] = { NULL, NULL };
|
const char *value, *shell, *shellcmd = NULL;
|
||||||
const char *shellcmd = NULL;
|
const char *style = args_get(args, 's');
|
||||||
char *cwd, *cause, **argv = args->argv;
|
const char *border_style = args_get(args, 'S');
|
||||||
int flags = 0, argc = args->argc;
|
char *cwd, *cause = NULL, **argv = NULL, *title;
|
||||||
u_int px, py, w, h;
|
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')) {
|
if (args_has(args, 'C')) {
|
||||||
server_client_clear_overlay(tc);
|
server_client_clear_overlay(tc);
|
||||||
@@ -361,37 +428,75 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w > tty->sx - 1)
|
if (w > tty->sx)
|
||||||
w = tty->sx - 1;
|
w = tty->sx;
|
||||||
if (h > tty->sy - 1)
|
if (h > tty->sy)
|
||||||
h = tty->sy - 1;
|
h = tty->sy;
|
||||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
|
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
|
||||||
return (CMD_RETURN_NORMAL);
|
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');
|
value = args_get(args, 'd');
|
||||||
if (value != NULL)
|
if (value != NULL)
|
||||||
cwd = format_single_from_target(item, value);
|
cwd = format_single_from_target(item, value);
|
||||||
else
|
else
|
||||||
cwd = xstrdup(server_client_get_cwd(tc, s));
|
cwd = xstrdup(server_client_get_cwd(tc, s));
|
||||||
if (argc == 0)
|
if (count == 0)
|
||||||
shellcmd = options_get_string(s->options, "default-command");
|
shellcmd = options_get_string(s->options, "default-command");
|
||||||
else if (argc == 1)
|
else if (count == 1)
|
||||||
shellcmd = argv[0];
|
shellcmd = args_string(args, 0);
|
||||||
if (argc <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||||
shellcmd = NULL;
|
shellcmd = NULL;
|
||||||
shell[0] = options_get_string(s->options, "default-shell");
|
shell = options_get_string(s->options, "default-shell");
|
||||||
if (!checkshell(shell[0]))
|
if (!checkshell(shell))
|
||||||
shell[0] = _PATH_BSHELL;
|
shell = _PATH_BSHELL;
|
||||||
argc = 1;
|
cmd_append_argv(&argc, &argv, shell);
|
||||||
argv = (char**)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)
|
if (args_has(args, 'E') > 1)
|
||||||
flags |= POPUP_CLOSEEXITZERO;
|
flags |= POPUP_CLOSEEXITZERO;
|
||||||
else if (args_has(args, 'E'))
|
else if (args_has(args, 'E'))
|
||||||
flags |= POPUP_CLOSEEXIT;
|
flags |= POPUP_CLOSEEXIT;
|
||||||
if (popup_display(flags, item, px, py, w, h, shellcmd, argc, argv, cwd,
|
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
||||||
tc, s, NULL, NULL) != 0)
|
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) {
|
||||||
|
cmd_free_argv(argc, argv);
|
||||||
|
if (env != NULL)
|
||||||
|
environ_free(env);
|
||||||
|
free(cwd);
|
||||||
|
free(title);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
}
|
||||||
|
if (env != NULL)
|
||||||
|
environ_free(env);
|
||||||
|
free(cwd);
|
||||||
|
free(title);
|
||||||
|
cmd_free_argv(argc, argv);
|
||||||
return (CMD_RETURN_WAIT);
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
|
|||||||
.name = "display-message",
|
.name = "display-message",
|
||||||
.alias = "display",
|
.alias = "display",
|
||||||
|
|
||||||
.args = { "acd:INpt:F:v", 0, 1 },
|
.args = { "ac:d:lINpt:F:v", 0, 1, NULL },
|
||||||
.usage = "[-aINpv] [-c target-client] [-d delay] [-F format] "
|
.usage = "[-aIlNpv] [-c target-client] [-d delay] [-F format] "
|
||||||
CMD_TARGET_PANE_USAGE " [message]",
|
CMD_TARGET_PANE_USAGE " [message]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||||
@@ -68,22 +68,27 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *template;
|
const char *template;
|
||||||
char *msg, *cause;
|
char *msg, *cause;
|
||||||
int delay = -1;
|
int delay = -1, flags, Nflag = args_has(args, 'N');
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
int flags;
|
u_int count = args_count(args);
|
||||||
|
struct evbuffer *evb;
|
||||||
|
|
||||||
if (args_has(args, 'I')) {
|
if (args_has(args, 'I')) {
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
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);
|
cmdq_error(item, "%s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
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");
|
cmdq_error(item, "only one of -F or argument must be given");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
@@ -97,9 +102,10 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template = args_get(args, 'F');
|
if (count != 0)
|
||||||
if (args->argc != 0)
|
template = args_string(args, 0);
|
||||||
template = args->argv[0];
|
else
|
||||||
|
template = args_get(args, 'F');
|
||||||
if (template == NULL)
|
if (template == NULL)
|
||||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||||
|
|
||||||
@@ -127,15 +133,24 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = format_expand_time(ft, template);
|
if (args_has(args, 'l'))
|
||||||
|
msg = xstrdup(template);
|
||||||
|
else
|
||||||
|
msg = format_expand_time(ft, template);
|
||||||
|
|
||||||
if (cmdq_get_client(item) == NULL)
|
if (cmdq_get_client(item) == NULL)
|
||||||
cmdq_error(item, "%s", msg);
|
cmdq_error(item, "%s", msg);
|
||||||
else if (args_has(args, 'p'))
|
else if (args_has(args, 'p'))
|
||||||
cmdq_print(item, "%s", msg);
|
cmdq_print(item, "%s", msg);
|
||||||
else if (tc != NULL) {
|
else if (tc != NULL && (tc->flags & CLIENT_CONTROL)) {
|
||||||
status_message_set(tc, delay, 0, args_has(args, 'N'), "%s",
|
evb = evbuffer_new();
|
||||||
msg);
|
if (evb == NULL)
|
||||||
}
|
fatalx("out of memory");
|
||||||
|
evbuffer_add_printf(evb, "%%message %s", msg);
|
||||||
|
server_client_print(tc, 0, evb);
|
||||||
|
evbuffer_free(evb);
|
||||||
|
} else if (tc != NULL)
|
||||||
|
status_message_set(tc, delay, 0, Nflag, "%s", msg);
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
|
|||||||
@@ -27,14 +27,16 @@
|
|||||||
* Display panes on a client.
|
* Display panes on a client.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
static enum args_parse_type cmd_display_panes_args_parse(struct args *,
|
||||||
struct cmdq_item *);
|
u_int, char **);
|
||||||
|
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||||
|
struct cmdq_item *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_display_panes_entry = {
|
const struct cmd_entry cmd_display_panes_entry = {
|
||||||
.name = "display-panes",
|
.name = "display-panes",
|
||||||
.alias = "displayp",
|
.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]",
|
.usage = "[-bN] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||||
@@ -42,10 +44,17 @@ const struct cmd_entry cmd_display_panes_entry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_display_panes_data {
|
struct cmd_display_panes_data {
|
||||||
struct cmdq_item *item;
|
struct cmdq_item *item;
|
||||||
char *command;
|
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
|
static void
|
||||||
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||||
struct window_pane *wp)
|
struct window_pane *wp)
|
||||||
@@ -135,11 +144,11 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
|||||||
llen = 0;
|
llen = 0;
|
||||||
|
|
||||||
if (sx < len * 6 || sy < 5) {
|
if (sx < len * 6 || sy < 5) {
|
||||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL);
|
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
||||||
if (sx >= len + llen + 1) {
|
if (sx >= len + llen + 1) {
|
||||||
len += llen + 1;
|
len += llen + 1;
|
||||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
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, " ", 1, 1);
|
||||||
tty_putn(tty, lbuf, llen, llen);
|
tty_putn(tty, lbuf, llen, llen);
|
||||||
} else {
|
} else {
|
||||||
@@ -152,7 +161,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
|||||||
px -= len * 3;
|
px -= len * 3;
|
||||||
py -= 2;
|
py -= 2;
|
||||||
|
|
||||||
tty_attributes(tty, &bgc, &grid_default_cell, NULL);
|
tty_attributes(tty, &bgc, &grid_default_cell, NULL, NULL);
|
||||||
for (ptr = buf; *ptr != '\0'; ptr++) {
|
for (ptr = buf; *ptr != '\0'; ptr++) {
|
||||||
if (*ptr < '0' || *ptr > '9')
|
if (*ptr < '0' || *ptr > '9')
|
||||||
continue;
|
continue;
|
||||||
@@ -170,7 +179,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
|||||||
|
|
||||||
if (sy <= 6)
|
if (sy <= 6)
|
||||||
goto out;
|
goto out;
|
||||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL);
|
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
||||||
if (rlen != 0 && sx >= rlen) {
|
if (rlen != 0 && sx >= rlen) {
|
||||||
tty_cursor(tty, xoff + sx - rlen, yoff);
|
tty_cursor(tty, xoff + sx - rlen, yoff);
|
||||||
tty_putn(tty, rbuf, rlen, rlen);
|
tty_putn(tty, rbuf, rlen, rlen);
|
||||||
@@ -186,7 +195,8 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 *w = c->session->curw->window;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
@@ -200,24 +210,25 @@ cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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)
|
if (cdata->item != NULL)
|
||||||
cmdq_continue(cdata->item);
|
cmdq_continue(cdata->item);
|
||||||
free(cdata->command);
|
args_make_commands_free(cdata->state);
|
||||||
free(cdata);
|
free(cdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
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;
|
struct cmd_display_panes_data *cdata = data;
|
||||||
char *cmd, *expanded, *error;
|
char *expanded, *error;
|
||||||
|
struct cmdq_item *item = cdata->item, *new_item;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
struct window *w = c->session->curw->window;
|
struct window *w = c->session->curw->window;
|
||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
enum cmd_parse_status status;
|
|
||||||
u_int index;
|
u_int index;
|
||||||
key_code key;
|
key_code key;
|
||||||
|
|
||||||
@@ -238,15 +249,19 @@ cmd_display_panes_key(struct client *c, struct key_event *event)
|
|||||||
window_unzoom(w);
|
window_unzoom(w);
|
||||||
|
|
||||||
xasprintf(&expanded, "%%%u", wp->id);
|
xasprintf(&expanded, "%%%u", wp->id);
|
||||||
cmd = cmd_template_replace(cdata->command, expanded, 1);
|
|
||||||
|
|
||||||
status = cmd_parse_and_append(cmd, NULL, c, NULL, &error);
|
cmdlist = args_make_commands(cdata->state, 1, &expanded, &error);
|
||||||
if (status == CMD_PARSE_ERROR) {
|
if (cmdlist == NULL) {
|
||||||
cmdq_append(c, cmdq_get_error(error));
|
cmdq_append(c, cmdq_get_error(error));
|
||||||
free(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);
|
free(expanded);
|
||||||
return (1);
|
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 args *args = cmd_get_args(self);
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = tc->session;
|
struct session *s = tc->session;
|
||||||
u_int delay;
|
u_int delay;
|
||||||
char *cause;
|
char *cause;
|
||||||
struct cmd_display_panes_data *cdata;
|
struct cmd_display_panes_data *cdata;
|
||||||
|
int wait = !args_has(args, 'b');
|
||||||
|
|
||||||
if (tc->overlay_draw != NULL)
|
if (tc->overlay_draw != NULL)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
@@ -274,27 +290,23 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
} else
|
} else
|
||||||
delay = options_get_number(s->options, "display-panes-time");
|
delay = options_get_number(s->options, "display-panes-time");
|
||||||
|
|
||||||
cdata = xmalloc(sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
if (args->argc != 0)
|
if (wait)
|
||||||
cdata->command = xstrdup(args->argv[0]);
|
|
||||||
else
|
|
||||||
cdata->command = xstrdup("select-pane -t '%%'");
|
|
||||||
if (args_has(args, 'b'))
|
|
||||||
cdata->item = NULL;
|
|
||||||
else
|
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
|
cdata->state = args_make_commands_prepare(self, item, 0,
|
||||||
|
"select-pane -t \"%%%\"", wait, 0);
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
if (args_has(args, 'N')) {
|
||||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
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);
|
cdata);
|
||||||
} else {
|
} else {
|
||||||
server_client_set_overlay(tc, delay, NULL, NULL,
|
server_client_set_overlay(tc, delay, NULL, NULL,
|
||||||
cmd_display_panes_draw, cmd_display_panes_key,
|
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_NORMAL);
|
||||||
return (CMD_RETURN_WAIT);
|
return (CMD_RETURN_WAIT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_find_window_entry = {
|
|||||||
.name = "find-window",
|
.name = "find-window",
|
||||||
.alias = "findw",
|
.alias = "findw",
|
||||||
|
|
||||||
.args = { "CiNrt:TZ", 1, 1 },
|
.args = { "CiNrt:TZ", 1, 1, NULL },
|
||||||
.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
.usage = "[-CiNrTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -47,14 +47,17 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct args *args = cmd_get_args(self), *new_args;
|
struct args *args = cmd_get_args(self), *new_args;
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *s = args->argv[0], *suffix = "";
|
const char *s = args_string(args, 0), *suffix = "";
|
||||||
char *filter, *argv = { NULL };
|
const char *star = "*";
|
||||||
|
struct args_value *filter;
|
||||||
int C, N, T;
|
int C, N, T;
|
||||||
|
|
||||||
C = args_has(args, 'C');
|
C = args_has(args, 'C');
|
||||||
N = args_has(args, 'N');
|
N = args_has(args, 'N');
|
||||||
T = args_has(args, 'T');
|
T = args_has(args, 'T');
|
||||||
|
|
||||||
|
if (args_has(args, 'r'))
|
||||||
|
star = "";
|
||||||
if (args_has(args, 'r') && args_has(args, 'i'))
|
if (args_has(args, 'r') && args_has(args, 'i'))
|
||||||
suffix = "/ri";
|
suffix = "/ri";
|
||||||
else if (args_has(args, 'r'))
|
else if (args_has(args, 'r'))
|
||||||
@@ -65,41 +68,49 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (!C && !N && !T)
|
if (!C && !N && !T)
|
||||||
C = N = T = 1;
|
C = N = T = 1;
|
||||||
|
|
||||||
if (C && N && T) {
|
filter = xcalloc(1, sizeof *filter);
|
||||||
xasprintf(&filter,
|
filter->type = ARGS_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,
|
|
||||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{window_name}}}",
|
|
||||||
suffix, s, suffix, s);
|
|
||||||
} else if (C && T) {
|
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{C%s:%s},#{m%s:*%s*,#{pane_title}}}",
|
|
||||||
suffix, s, suffix, s);
|
|
||||||
} else if (N && T) {
|
|
||||||
xasprintf(&filter,
|
|
||||||
"#{||:#{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);
|
|
||||||
|
|
||||||
new_args = args_parse("", 1, &argv);
|
if (C && N && T) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{||:"
|
||||||
|
"#{C%s:%s},#{||:#{m%s:%s%s%s,#{window_name}},"
|
||||||
|
"#{m%s:%s%s%s,#{pane_title}}}}",
|
||||||
|
suffix, s, suffix, star, s, star, suffix, star, s, star);
|
||||||
|
} else if (C && N) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{window_name}}}",
|
||||||
|
suffix, s, suffix, star, s, star);
|
||||||
|
} else if (C && T) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{||:#{C%s:%s},#{m%s:%s%s%s,#{pane_title}}}",
|
||||||
|
suffix, s, suffix, star, s, star);
|
||||||
|
} else if (N && T) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{||:#{m%s:%s%s%s,#{window_name}},"
|
||||||
|
"#{m%s:%s%s%s,#{pane_title}}}",
|
||||||
|
suffix, star, s, star, suffix, star, s, star);
|
||||||
|
} else if (C) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{C%s:%s}",
|
||||||
|
suffix, s);
|
||||||
|
} else if (N) {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{m%s:%s%s%s,#{window_name}}",
|
||||||
|
suffix, star, s, star);
|
||||||
|
} else {
|
||||||
|
xasprintf(&filter->string,
|
||||||
|
"#{m%s:%s%s%s,#{pane_title}}",
|
||||||
|
suffix, star, s, star);
|
||||||
|
}
|
||||||
|
|
||||||
|
new_args = args_create();
|
||||||
if (args_has(args, 'Z'))
|
if (args_has(args, 'Z'))
|
||||||
args_set(new_args, 'Z', NULL);
|
args_set(new_args, 'Z', NULL, 0);
|
||||||
args_set(new_args, 'f', filter);
|
args_set(new_args, 'f', filter, 0);
|
||||||
|
|
||||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||||
|
|
||||||
args_free(new_args);
|
args_free(new_args);
|
||||||
free(filter);
|
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
12
cmd-find.c
12
cmd-find.c
@@ -582,27 +582,27 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
|||||||
|
|
||||||
/* Try special characters. */
|
/* Try special characters. */
|
||||||
if (strcmp(pane, "!") == 0) {
|
if (strcmp(pane, "!") == 0) {
|
||||||
fs->wp = fs->w->last;
|
fs->wp = TAILQ_FIRST(&fs->w->last_panes);
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
} else if (strcmp(pane, "{up-of}") == 0) {
|
} else if (strcmp(pane, "{up-of}") == 0) {
|
||||||
fs->wp = window_pane_find_up(fs->current->wp);
|
fs->wp = window_pane_find_up(fs->w->active);
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
} else if (strcmp(pane, "{down-of}") == 0) {
|
} else if (strcmp(pane, "{down-of}") == 0) {
|
||||||
fs->wp = window_pane_find_down(fs->current->wp);
|
fs->wp = window_pane_find_down(fs->w->active);
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
} else if (strcmp(pane, "{left-of}") == 0) {
|
} else if (strcmp(pane, "{left-of}") == 0) {
|
||||||
fs->wp = window_pane_find_left(fs->current->wp);
|
fs->wp = window_pane_find_left(fs->w->active);
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
} else if (strcmp(pane, "{right-of}") == 0) {
|
} else if (strcmp(pane, "{right-of}") == 0) {
|
||||||
fs->wp = window_pane_find_right(fs->current->wp);
|
fs->wp = window_pane_find_right(fs->w->active);
|
||||||
if (fs->wp == NULL)
|
if (fs->wp == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
@@ -614,7 +614,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
|||||||
n = strtonum(pane + 1, 1, INT_MAX, NULL);
|
n = strtonum(pane + 1, 1, INT_MAX, NULL);
|
||||||
else
|
else
|
||||||
n = 1;
|
n = 1;
|
||||||
wp = fs->current->wp;
|
wp = fs->w->active;
|
||||||
if (pane[0] == '+')
|
if (pane[0] == '+')
|
||||||
fs->wp = window_pane_next_by_number(fs->w, wp, n);
|
fs->wp = window_pane_next_by_number(fs->w, wp, n);
|
||||||
else
|
else
|
||||||
|
|||||||
168
cmd-if-shell.c
168
cmd-if-shell.c
@@ -20,6 +20,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -29,16 +30,19 @@
|
|||||||
* Executes a tmux command if a shell command returns true or false.
|
* 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_callback(struct job *);
|
||||||
static void cmd_if_shell_free(void *);
|
static void cmd_if_shell_free(void *);
|
||||||
|
|
||||||
const struct cmd_entry cmd_if_shell_entry = {
|
const struct cmd_entry cmd_if_shell_entry = {
|
||||||
.name = "if-shell",
|
.name = "if-shell",
|
||||||
.alias = "if",
|
.alias = "if",
|
||||||
|
|
||||||
.args = { "bFt:", 2, 3 },
|
.args = { "bFt:", 2, 3, cmd_if_shell_args_parse },
|
||||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
||||||
"[command]",
|
"[command]",
|
||||||
|
|
||||||
@@ -49,86 +53,72 @@ const struct cmd_entry cmd_if_shell_entry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_if_shell_data {
|
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;
|
struct client *client;
|
||||||
char *cmd_else;
|
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
|
static enum cmd_retval
|
||||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct cmdq_state *state = cmdq_get_state(item);
|
|
||||||
struct cmd_if_shell_data *cdata;
|
struct cmd_if_shell_data *cdata;
|
||||||
char *shellcmd, *cmd, *error;
|
struct cmdq_item *new_item;
|
||||||
const char *file;
|
char *shellcmd;
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct cmd_parse_input pi;
|
struct cmd_list *cmdlist;
|
||||||
enum cmd_parse_status status;
|
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 (args_has(args, 'F')) {
|
||||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||||
cmd = args->argv[1];
|
cmdlist = args_make_commands_now(self, item, 1, 0);
|
||||||
else if (args->argc == 3)
|
else if (count == 3)
|
||||||
cmd = args->argv[2];
|
cmdlist = args_make_commands_now(self, item, 2, 0);
|
||||||
else
|
else {
|
||||||
cmd = NULL;
|
free(shellcmd);
|
||||||
free(shellcmd);
|
|
||||||
if (cmd == NULL)
|
|
||||||
return (CMD_RETURN_NORMAL);
|
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);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
|
|
||||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
cdata->cmd_if = args_make_commands_prepare(self, item, 1, NULL, wait,
|
||||||
if (args->argc == 3)
|
0);
|
||||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
if (count == 3) {
|
||||||
else
|
cdata->cmd_else = args_make_commands_prepare(self, item, 2,
|
||||||
cdata->cmd_else = NULL;
|
NULL, wait, 0);
|
||||||
|
}
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
if (wait) {
|
||||||
cdata->client = cmdq_get_client(item);
|
cdata->client = cmdq_get_client(item);
|
||||||
else
|
cdata->item = item;
|
||||||
|
} else
|
||||||
cdata->client = tc;
|
cdata->client = tc;
|
||||||
if (cdata->client != NULL)
|
if (cdata->client != NULL)
|
||||||
cdata->client->references++;
|
cdata->client->references++;
|
||||||
|
|
||||||
if (!args_has(args, 'b'))
|
if (job_run(shellcmd, 0, NULL, NULL, s,
|
||||||
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,
|
|
||||||
server_client_get_cwd(cmdq_get_client(item), s), NULL,
|
server_client_get_cwd(cmdq_get_client(item), s), NULL,
|
||||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,
|
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0, -1,
|
||||||
-1) == NULL) {
|
-1) == NULL) {
|
||||||
@@ -139,7 +129,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
free(shellcmd);
|
free(shellcmd);
|
||||||
|
|
||||||
if (args_has(args, 'b'))
|
if (!wait)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
return (CMD_RETURN_WAIT);
|
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 cmd_if_shell_data *cdata = job_get_data(job);
|
||||||
struct client *c = cdata->client;
|
struct client *c = cdata->client;
|
||||||
struct cmdq_item *new_item = NULL;
|
struct cmdq_item *item = cdata->item, *new_item;
|
||||||
struct cmdq_state *new_state = NULL;
|
struct args_command_state *state;
|
||||||
char *cmd;
|
struct cmd_list *cmdlist;
|
||||||
|
char *error;
|
||||||
int status;
|
int status;
|
||||||
struct cmd_parse_result *pr;
|
|
||||||
|
|
||||||
status = job_get_status(job);
|
status = job_get_status(job);
|
||||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||||
cmd = cdata->cmd_else;
|
state = cdata->cmd_else;
|
||||||
else
|
else
|
||||||
cmd = cdata->cmd_if;
|
state = cdata->cmd_if;
|
||||||
if (cmd == NULL)
|
if (state == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
pr = cmd_parse_from_string(cmd, &cdata->input);
|
cmdlist = args_make_commands(state, 0, NULL, &error);
|
||||||
switch (pr->status) {
|
if (cmdlist == NULL) {
|
||||||
case CMD_PARSE_EMPTY:
|
if (cdata->item == NULL) {
|
||||||
break;
|
*error = toupper((u_char)*error);
|
||||||
case CMD_PARSE_ERROR:
|
status_message_set(c, -1, 1, 0, "%s", error);
|
||||||
if (cdata->item != NULL)
|
} else
|
||||||
cmdq_error(cdata->item, "%s", pr->error);
|
cmdq_error(cdata->item, "%s", error);
|
||||||
free(pr->error);
|
free(error);
|
||||||
break;
|
} else if (item == NULL) {
|
||||||
case CMD_PARSE_SUCCESS:
|
new_item = cmdq_get_command(cmdlist, NULL);
|
||||||
if (cdata->item == NULL)
|
cmdq_append(c, new_item);
|
||||||
new_state = cmdq_new_state(NULL, NULL, 0);
|
} else {
|
||||||
else
|
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||||
new_state = cmdq_get_state(cdata->item);
|
cmdq_insert_after(item, new_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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@@ -203,12 +182,9 @@ cmd_if_shell_free(void *data)
|
|||||||
if (cdata->client != NULL)
|
if (cdata->client != NULL)
|
||||||
server_client_unref(cdata->client);
|
server_client_unref(cdata->client);
|
||||||
|
|
||||||
free(cdata->cmd_else);
|
if (cdata->cmd_else != NULL)
|
||||||
free(cdata->cmd_if);
|
args_make_commands_free(cdata->cmd_else);
|
||||||
|
args_make_commands_free(cdata->cmd_if);
|
||||||
if (cdata->input.c != NULL)
|
|
||||||
server_client_unref(cdata->input.c);
|
|
||||||
free((void *)cdata->input.file);
|
|
||||||
|
|
||||||
free(cdata);
|
free(cdata);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_join_pane_entry = {
|
|||||||
.name = "join-pane",
|
.name = "join-pane",
|
||||||
.alias = "joinp",
|
.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,
|
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_move_pane_entry = {
|
|||||||
.name = "move-pane",
|
.name = "move-pane",
|
||||||
.alias = "movep",
|
.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,
|
.usage = "[-bdfhv] [-l size] " CMD_SRCDST_PANE_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||||
@@ -71,10 +71,11 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct window *src_w, *dst_w;
|
struct window *src_w, *dst_w;
|
||||||
struct window_pane *src_wp, *dst_wp;
|
struct window_pane *src_wp, *dst_wp;
|
||||||
char *cause = NULL;
|
char *cause = NULL;
|
||||||
int size, percentage, dst_idx;
|
int size, dst_idx;
|
||||||
int flags;
|
int flags;
|
||||||
enum layout_type type;
|
enum layout_type type;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
|
u_int curval = 0;
|
||||||
|
|
||||||
dst_s = target->s;
|
dst_s = target->s;
|
||||||
dst_wl = target->wl;
|
dst_wl = target->wl;
|
||||||
@@ -97,23 +98,30 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (args_has(args, 'h'))
|
if (args_has(args, 'h'))
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
|
|
||||||
|
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
|
||||||
|
if (args_has(args, 'l') || args_has(args, 'p')) {
|
||||||
|
if (args_has(args, 'f')) {
|
||||||
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
|
curval = dst_w->sy;
|
||||||
|
else
|
||||||
|
curval = dst_w->sx;
|
||||||
|
} else {
|
||||||
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
|
curval = dst_wp->sy;
|
||||||
|
else
|
||||||
|
curval = dst_wp->sx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size = -1;
|
size = -1;
|
||||||
if (args_has(args, 'l')) {
|
if (args_has(args, 'l')) {
|
||||||
if (type == LAYOUT_TOPBOTTOM) {
|
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
||||||
size = args_percentage(args, 'l', 0, INT_MAX,
|
item, &cause);
|
||||||
dst_wp->sy, &cause);
|
|
||||||
} else {
|
|
||||||
size = args_percentage(args, 'l', 0, INT_MAX,
|
|
||||||
dst_wp->sx, &cause);
|
|
||||||
}
|
|
||||||
} else if (args_has(args, 'p')) {
|
} else if (args_has(args, 'p')) {
|
||||||
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
||||||
if (cause == NULL) {
|
&cause);
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
if (cause == NULL)
|
||||||
size = (dst_wp->sy * percentage) / 100;
|
size = curval * size / 100;
|
||||||
else
|
|
||||||
size = (dst_wp->sx * percentage) / 100;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
cmdq_error(item, "size %s", cause);
|
cmdq_error(item, "size %s", cause);
|
||||||
@@ -147,6 +155,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
else
|
else
|
||||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||||
layout_assign_pane(lc, src_wp, 0);
|
layout_assign_pane(lc, src_wp, 0);
|
||||||
|
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
||||||
|
|
||||||
recalculate_sizes();
|
recalculate_sizes();
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
|||||||
.name = "kill-pane",
|
.name = "kill-pane",
|
||||||
.alias = "killp",
|
.alias = "killp",
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
.args = { "at:", 0, 0, NULL },
|
||||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_server_entry = {
|
|||||||
.name = "kill-server",
|
.name = "kill-server",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "", 0, 0 },
|
.args = { "", 0, 0, NULL },
|
||||||
.usage = "",
|
.usage = "",
|
||||||
|
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_start_server_entry = {
|
|||||||
.name = "start-server",
|
.name = "start-server",
|
||||||
.alias = "start",
|
.alias = "start",
|
||||||
|
|
||||||
.args = { "", 0, 0 },
|
.args = { "", 0, 0, NULL },
|
||||||
.usage = "",
|
.usage = "",
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER,
|
.flags = CMD_STARTSERVER,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_session_entry = {
|
|||||||
.name = "kill-session",
|
.name = "kill-session",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "aCt:", 0, 0 },
|
.args = { "aCt:", 0, 0, NULL },
|
||||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_kill_window_entry = {
|
|||||||
.name = "kill-window",
|
.name = "kill-window",
|
||||||
.alias = "killw",
|
.alias = "killw",
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
.args = { "at:", 0, 0, NULL },
|
||||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
|||||||
.name = "unlink-window",
|
.name = "unlink-window",
|
||||||
.alias = "unlinkw",
|
.alias = "unlinkw",
|
||||||
|
|
||||||
.args = { "kt:", 0, 0 },
|
.args = { "kt:", 0, 0, NULL },
|
||||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
|
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
|||||||
.name = "list-buffers",
|
.name = "list-buffers",
|
||||||
.alias = "lsb",
|
.alias = "lsb",
|
||||||
|
|
||||||
.args = { "F:f:", 0, 0 },
|
.args = { "F:f:", 0, 0, NULL },
|
||||||
.usage = "[-F format] [-f filter]",
|
.usage = "[-F format] [-f filter]",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#define LIST_CLIENTS_TEMPLATE \
|
#define LIST_CLIENTS_TEMPLATE \
|
||||||
"#{client_name}: #{session_name} " \
|
"#{client_name}: #{session_name} " \
|
||||||
"[#{client_width}x#{client_height} #{client_termname}] " \
|
"[#{client_width}x#{client_height} #{client_termname}] " \
|
||||||
|
"#{?#{!=:#{client_uid},#{uid}}," \
|
||||||
|
"[user #{?client_user,#{client_user},#{client_uid},}] ,}" \
|
||||||
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
"#{?client_flags,(,}#{client_flags}#{?client_flags,),}"
|
||||||
|
|
||||||
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
static enum cmd_retval cmd_list_clients_exec(struct cmd *, struct cmdq_item *);
|
||||||
@@ -39,8 +41,8 @@ const struct cmd_entry cmd_list_clients_entry = {
|
|||||||
.name = "list-clients",
|
.name = "list-clients",
|
||||||
.alias = "lsc",
|
.alias = "lsc",
|
||||||
|
|
||||||
.args = { "F:t:", 0, 0 },
|
.args = { "F:f:t:", 0, 0, NULL },
|
||||||
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
|
.usage = "[-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
|
|
||||||
@@ -56,9 +58,10 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct client *c;
|
struct client *c;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
const char *template;
|
const char *template, *filter;
|
||||||
u_int idx;
|
u_int idx;
|
||||||
char *line;
|
char *line, *expanded;
|
||||||
|
int flag;
|
||||||
|
|
||||||
if (args_has(args, 't'))
|
if (args_has(args, 't'))
|
||||||
s = target->s;
|
s = target->s;
|
||||||
@@ -67,6 +70,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL)
|
if ((template = args_get(args, 'F')) == NULL)
|
||||||
template = LIST_CLIENTS_TEMPLATE;
|
template = LIST_CLIENTS_TEMPLATE;
|
||||||
|
filter = args_get(args, 'f');
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
TAILQ_FOREACH(c, &clients, entry) {
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
@@ -77,9 +81,17 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
format_add(ft, "line", "%u", idx);
|
format_add(ft, "line", "%u", idx);
|
||||||
format_defaults(ft, c, NULL, NULL, NULL);
|
format_defaults(ft, c, NULL, NULL, NULL);
|
||||||
|
|
||||||
line = format_expand(ft, template);
|
if (filter != NULL) {
|
||||||
cmdq_print(item, "%s", line);
|
expanded = format_expand(ft, filter);
|
||||||
free(line);
|
flag = format_true(expanded);
|
||||||
|
free(expanded);
|
||||||
|
} else
|
||||||
|
flag = 1;
|
||||||
|
if (flag) {
|
||||||
|
line = format_expand(ft, template);
|
||||||
|
cmdq_print(item, "%s", line);
|
||||||
|
free(line);
|
||||||
|
}
|
||||||
|
|
||||||
format_free(ft);
|
format_free(ft);
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_list_keys_entry = {
|
|||||||
.name = "list-keys",
|
.name = "list-keys",
|
||||||
.alias = "lsk",
|
.alias = "lsk",
|
||||||
|
|
||||||
.args = { "1aNP:T:", 0, 1 },
|
.args = { "1aNP:T:", 0, 1, NULL },
|
||||||
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_list_commands_entry = {
|
|||||||
.name = "list-commands",
|
.name = "list-commands",
|
||||||
.alias = "lscm",
|
.alias = "lscm",
|
||||||
|
|
||||||
.args = { "F:", 0, 1 },
|
.args = { "F:", 0, 1, NULL },
|
||||||
.usage = "[-F format] [command]",
|
.usage = "[-F format] [command]",
|
||||||
|
|
||||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||||
@@ -148,9 +148,10 @@ static enum cmd_retval
|
|||||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct key_table *table;
|
struct key_table *table;
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
const char *tablename, *r;
|
const char *tablename, *r, *keystr;
|
||||||
char *key, *cp, *tmp, *start, *empty;
|
char *key, *cp, *tmp, *start, *empty;
|
||||||
key_code prefix, only = KEYC_UNKNOWN;
|
key_code prefix, only = KEYC_UNKNOWN;
|
||||||
int repeat, width, tablewidth, keywidth, found = 0;
|
int repeat, width, tablewidth, keywidth, found = 0;
|
||||||
@@ -159,13 +160,13 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
||||||
return (cmd_list_keys_commands(self, item));
|
return (cmd_list_keys_commands(self, item));
|
||||||
|
|
||||||
if (args->argc != 0) {
|
if ((keystr = args_string(args, 0)) != NULL) {
|
||||||
only = key_string_lookup_string(args->argv[0]);
|
only = key_string_lookup_string(keystr);
|
||||||
if (only == KEYC_UNKNOWN) {
|
if (only == KEYC_UNKNOWN) {
|
||||||
cmdq_error(item, "invalid key: %s", args->argv[0]);
|
cmdq_error(item, "invalid key: %s", keystr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
only &= KEYC_MASK_KEY;
|
only &= (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
tablename = args_get(args, 'T');
|
tablename = args_get(args, 'T');
|
||||||
@@ -211,7 +212,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
repeat = 0;
|
repeat = 0;
|
||||||
tablewidth = keywidth = 0;
|
tablewidth = keywidth = 0;
|
||||||
table = key_bindings_first_table ();
|
table = key_bindings_first_table();
|
||||||
while (table != NULL) {
|
while (table != NULL) {
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||||
table = key_bindings_next_table(table);
|
table = key_bindings_next_table(table);
|
||||||
@@ -244,7 +245,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
tmpsize = 256;
|
tmpsize = 256;
|
||||||
tmp = xmalloc(tmpsize);
|
tmp = xmalloc(tmpsize);
|
||||||
|
|
||||||
table = key_bindings_first_table ();
|
table = key_bindings_first_table();
|
||||||
while (table != NULL) {
|
while (table != NULL) {
|
||||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||||
table = key_bindings_next_table(table);
|
table = key_bindings_next_table(table);
|
||||||
@@ -296,9 +297,15 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
strlcat(tmp, cp, tmpsize);
|
strlcat(tmp, cp, tmpsize);
|
||||||
free(cp);
|
free(cp);
|
||||||
|
|
||||||
cmdq_print(item, "bind-key %s", tmp);
|
if (args_has(args, '1') && tc != NULL) {
|
||||||
|
status_message_set(tc, -1, 1, 0, "bind-key %s",
|
||||||
|
tmp);
|
||||||
|
} else
|
||||||
|
cmdq_print(item, "bind-key %s", tmp);
|
||||||
free(key);
|
free(key);
|
||||||
|
|
||||||
|
if (args_has(args, '1'))
|
||||||
|
break;
|
||||||
bd = key_bindings_next(table, bd);
|
bd = key_bindings_next(table, bd);
|
||||||
}
|
}
|
||||||
table = key_bindings_next_table(table);
|
table = key_bindings_next_table(table);
|
||||||
@@ -308,7 +315,7 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
if (only != KEYC_UNKNOWN && !found) {
|
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_ERROR);
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
@@ -321,12 +328,9 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
|||||||
const struct cmd_entry **entryp;
|
const struct cmd_entry **entryp;
|
||||||
const struct cmd_entry *entry;
|
const struct cmd_entry *entry;
|
||||||
struct format_tree *ft;
|
struct format_tree *ft;
|
||||||
const char *template, *s, *command = NULL;
|
const char *template, *s, *command;
|
||||||
char *line;
|
char *line;
|
||||||
|
|
||||||
if (args->argc != 0)
|
|
||||||
command = args->argv[0];
|
|
||||||
|
|
||||||
if ((template = args_get(args, 'F')) == NULL) {
|
if ((template = args_get(args, 'F')) == NULL) {
|
||||||
template = "#{command_list_name}"
|
template = "#{command_list_name}"
|
||||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
"#{?command_list_alias, (#{command_list_alias}),} "
|
||||||
@@ -336,6 +340,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
|||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
command = args_string(args, 0);
|
||||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||||
entry = *entryp;
|
entry = *entryp;
|
||||||
if (command != NULL &&
|
if (command != NULL &&
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_list_panes_entry = {
|
|||||||
.name = "list-panes",
|
.name = "list-panes",
|
||||||
.alias = "lsp",
|
.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,
|
.usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
|||||||
.name = "list-sessions",
|
.name = "list-sessions",
|
||||||
.alias = "ls",
|
.alias = "ls",
|
||||||
|
|
||||||
.args = { "F:f:", 0, 0 },
|
.args = { "F:f:", 0, 0, NULL },
|
||||||
.usage = "[-F format] [-f filter]",
|
.usage = "[-F format] [-f filter]",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_list_windows_entry = {
|
|||||||
.name = "list-windows",
|
.name = "list-windows",
|
||||||
.alias = "lsw",
|
.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,
|
.usage = "[-a] [-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_load_buffer_entry = {
|
|||||||
.name = "load-buffer",
|
.name = "load-buffer",
|
||||||
.alias = "loadb",
|
.alias = "loadb",
|
||||||
|
|
||||||
.args = { "b:t:w", 1, 1 },
|
.args = { "b:t:w", 1, 1, NULL },
|
||||||
.usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
|
.usage = CMD_BUFFER_USAGE " " CMD_TARGET_CLIENT_USAGE " path",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
||||||
@@ -77,7 +77,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
|||||||
} else if (tc != NULL &&
|
} else if (tc != NULL &&
|
||||||
tc->session != NULL &&
|
tc->session != NULL &&
|
||||||
(~tc->flags & CLIENT_DEAD))
|
(~tc->flags & CLIENT_DEAD))
|
||||||
tty_set_selection(&tc->tty, copy, bsize);
|
tty_set_selection(&tc->tty, "", copy, bsize);
|
||||||
if (tc != NULL)
|
if (tc != NULL)
|
||||||
server_client_unref(tc);
|
server_client_unref(tc);
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cdata->client->references++;
|
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);
|
file_read(cmdq_get_client(item), path, cmd_load_buffer_done, cdata);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ const struct cmd_entry cmd_lock_server_entry = {
|
|||||||
.name = "lock-server",
|
.name = "lock-server",
|
||||||
.alias = "lock",
|
.alias = "lock",
|
||||||
|
|
||||||
.args = { "", 0, 0 },
|
.args = { "", 0, 0, NULL },
|
||||||
.usage = "",
|
.usage = "",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_lock_session_entry = {
|
|||||||
.name = "lock-session",
|
.name = "lock-session",
|
||||||
.alias = "locks",
|
.alias = "locks",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
.usage = CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
@@ -54,7 +54,7 @@ const struct cmd_entry cmd_lock_client_entry = {
|
|||||||
.name = "lock-client",
|
.name = "lock-client",
|
||||||
.alias = "lockc",
|
.alias = "lockc",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_move_window_entry = {
|
|||||||
.name = "move-window",
|
.name = "move-window",
|
||||||
.alias = "movew",
|
.alias = "movew",
|
||||||
|
|
||||||
.args = { "abdkrs:t:", 0, 0 },
|
.args = { "abdkrs:t:", 0, 0, NULL },
|
||||||
.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
|
.usage = "[-abdkr] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_link_window_entry = {
|
|||||||
.name = "link-window",
|
.name = "link-window",
|
||||||
.alias = "linkw",
|
.alias = "linkw",
|
||||||
|
|
||||||
.args = { "abdks:t:", 0, 0 },
|
.args = { "abdks:t:", 0, 0, NULL },
|
||||||
.usage = "[-abdk] " CMD_SRCDST_WINDOW_USAGE,
|
.usage = "[-abdk] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||||
|
|||||||
@@ -39,10 +39,11 @@ const struct cmd_entry cmd_new_session_entry = {
|
|||||||
.name = "new-session",
|
.name = "new-session",
|
||||||
.alias = "new",
|
.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] "
|
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
|
||||||
"[-f flags] [-n window-name] [-s session-name] "
|
"[-f flags] [-n window-name] [-s session-name] "
|
||||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] [command]",
|
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
||||||
|
"[shell-command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ const struct cmd_entry cmd_has_session_entry = {
|
|||||||
.name = "has-session",
|
.name = "has-session",
|
||||||
.alias = "has",
|
.alias = "has",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
.usage = CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.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 options *oo;
|
||||||
struct termios tio, *tiop;
|
struct termios tio, *tiop;
|
||||||
struct session_group *sg = NULL;
|
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 *cause, *cwd = NULL, *cp, *newname = NULL;
|
||||||
char *name, *prefix = NULL;
|
char *name, *prefix = NULL;
|
||||||
int detached, already_attached, is_control = 0;
|
int detached, already_attached, is_control = 0;
|
||||||
u_int sx, sy, dsx, dsy;
|
u_int sx, sy, dsx, dsy, count = args_count(args);
|
||||||
struct spawn_context sc;
|
struct spawn_context sc = { 0 };
|
||||||
enum cmd_retval retval;
|
enum cmd_retval retval;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
struct args_value *value;
|
struct args_value *av;
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_has_session_entry) {
|
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);
|
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");
|
cmdq_error(item, "command or window name given with target");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
@@ -102,6 +103,11 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (tmp != NULL) {
|
if (tmp != NULL) {
|
||||||
name = format_single(item, tmp, c, NULL, NULL, NULL);
|
name = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||||
newname = session_check_name(name);
|
newname = session_check_name(name);
|
||||||
|
if (newname == NULL) {
|
||||||
|
cmdq_error(item, "invalid session: %s", name);
|
||||||
|
free(name);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
if (args_has(args, 'A')) {
|
if (args_has(args, 'A')) {
|
||||||
@@ -134,8 +140,14 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
prefix = xstrdup(sg->name);
|
prefix = xstrdup(sg->name);
|
||||||
else if (groupwith != NULL)
|
else if (groupwith != NULL)
|
||||||
prefix = xstrdup(groupwith->name);
|
prefix = xstrdup(groupwith->name);
|
||||||
else
|
else {
|
||||||
prefix = session_check_name(group);
|
prefix = session_check_name(group);
|
||||||
|
if (prefix == NULL) {
|
||||||
|
cmdq_error(item, "invalid session group: %s",
|
||||||
|
group);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set -d if no client. */
|
/* Set -d if no client. */
|
||||||
@@ -258,21 +270,21 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
env = environ_create();
|
env = environ_create();
|
||||||
if (c != NULL && !args_has(args, 'E'))
|
if (c != NULL && !args_has(args, 'E'))
|
||||||
environ_update(global_s_options, c->environ, env);
|
environ_update(global_s_options, c->environ, env);
|
||||||
add = args_first_value(args, 'e', &value);
|
av = args_first_value(args, 'e');
|
||||||
while (add != NULL) {
|
while (av != NULL) {
|
||||||
environ_put(env, add, 0);
|
environ_put(env, av->string, 0);
|
||||||
add = args_next_value(&value);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
||||||
|
|
||||||
/* Spawn the initial window. */
|
/* Spawn the initial window. */
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
sc.item = item;
|
||||||
sc.s = s;
|
sc.s = s;
|
||||||
|
if (!detached)
|
||||||
|
sc.tc = c;
|
||||||
|
|
||||||
sc.name = args_get(args, 'n');
|
sc.name = args_get(args, 'n');
|
||||||
sc.argc = args->argc;
|
args_to_vector(args, &sc.argc, &sc.argv);
|
||||||
sc.argv = args->argv;
|
|
||||||
|
|
||||||
sc.idx = -1;
|
sc.idx = -1;
|
||||||
sc.cwd = args_get(args, 'c');
|
sc.cwd = args_get(args, 'c');
|
||||||
@@ -316,25 +328,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
proc_send(c->peer, MSG_READY, -1, NULL, 0);
|
||||||
} else if (c->session != NULL)
|
} else if (c->session != NULL)
|
||||||
c->last_session = c->session;
|
c->last_session = c->session;
|
||||||
c->session = s;
|
server_client_set_session(c, s);
|
||||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||||
server_client_set_key_table(c, NULL);
|
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
|
|
||||||
* session's current window into more mode and display them now.
|
|
||||||
*/
|
|
||||||
if (cfg_finished)
|
|
||||||
cfg_show_causes(s);
|
|
||||||
|
|
||||||
/* Print if requested. */
|
/* Print if requested. */
|
||||||
if (args_has(args, 'P')) {
|
if (args_has(args, 'P')) {
|
||||||
@@ -353,12 +350,19 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_session(&fs, s, 0);
|
cmd_find_from_session(&fs, s, 0);
|
||||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
||||||
|
|
||||||
|
if (cfg_finished)
|
||||||
|
cfg_show_causes(s);
|
||||||
|
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
free(cwd);
|
free(cwd);
|
||||||
free(newname);
|
free(newname);
|
||||||
free(prefix);
|
free(prefix);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
free(cwd);
|
free(cwd);
|
||||||
free(newname);
|
free(newname);
|
||||||
free(prefix);
|
free(prefix);
|
||||||
|
|||||||
@@ -38,9 +38,9 @@ const struct cmd_entry cmd_new_window_entry = {
|
|||||||
.name = "new-window",
|
.name = "new-window",
|
||||||
.alias = "neww",
|
.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] "
|
.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 },
|
.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 client *c = cmdq_get_client(item);
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct cmd_find_state *current = cmdq_get_current(item);
|
||||||
struct cmd_find_state *target = cmdq_get_target(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 client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl, *new_wl = NULL;
|
||||||
int idx = target->idx, before;
|
int idx = target->idx, before;
|
||||||
struct winlink *new_wl = NULL;
|
char *cause = NULL, *cp, *expanded;
|
||||||
char *cause = NULL, *cp;
|
const char *template, *name;
|
||||||
const char *template, *add, *name;
|
|
||||||
struct cmd_find_state fs;
|
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
|
* If -S and -n are given and -t is not and a single window with this
|
||||||
@@ -72,16 +71,19 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
*/
|
*/
|
||||||
name = args_get(args, 'n');
|
name = args_get(args, 'n');
|
||||||
if (args_has(args, 'S') && name != NULL && target->idx == -1) {
|
if (args_has(args, 'S') && name != NULL && target->idx == -1) {
|
||||||
|
expanded = format_single(item, name, c, s, NULL, NULL);
|
||||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||||
if (strcmp(wl->window->name, name) != 0)
|
if (strcmp(wl->window->name, expanded) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (new_wl == NULL) {
|
if (new_wl == NULL) {
|
||||||
new_wl = wl;
|
new_wl = wl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
cmdq_error(item, "multiple windows named %s", name);
|
cmdq_error(item, "multiple windows named %s", name);
|
||||||
|
free(expanded);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
free(expanded);
|
||||||
if (new_wl != NULL) {
|
if (new_wl != NULL) {
|
||||||
if (args_has(args, 'd'))
|
if (args_has(args, 'd'))
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
@@ -94,7 +96,6 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
before = args_has(args, 'b');
|
before = args_has(args, 'b');
|
||||||
if (args_has(args, 'a') || before) {
|
if (args_has(args, 'a') || before) {
|
||||||
idx = winlink_shuffle_up(s, wl, before);
|
idx = winlink_shuffle_up(s, wl, before);
|
||||||
@@ -102,20 +103,18 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
idx = target->idx;
|
idx = target->idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
sc.item = item;
|
||||||
sc.s = s;
|
sc.s = s;
|
||||||
sc.tc = tc;
|
sc.tc = tc;
|
||||||
|
|
||||||
sc.name = args_get(args, 'n');
|
sc.name = args_get(args, 'n');
|
||||||
sc.argc = args->argc;
|
args_to_vector(args, &sc.argc, &sc.argv);
|
||||||
sc.argv = args->argv;
|
|
||||||
sc.environ = environ_create();
|
sc.environ = environ_create();
|
||||||
|
|
||||||
add = args_first_value(args, 'e', &value);
|
av = args_first_value(args, 'e');
|
||||||
while (add != NULL) {
|
while (av != NULL) {
|
||||||
environ_put(sc.environ, add, 0);
|
environ_put(sc.environ, av->string, 0);
|
||||||
add = args_next_value(&value);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = idx;
|
sc.idx = idx;
|
||||||
@@ -130,6 +129,9 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
|
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
|
||||||
cmdq_error(item, "create window failed: %s", cause);
|
cmdq_error(item, "create window failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if (!args_has(args, 'd') || new_wl == s->curw) {
|
if (!args_has(args, 'd') || new_wl == s->curw) {
|
||||||
@@ -150,6 +152,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_winlink(&fs, new_wl, 0);
|
cmd_find_from_winlink(&fs, new_wl, 0);
|
||||||
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
||||||
|
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
environ_free(sc.environ);
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
577
cmd-parse.y
577
cmd-parse.y
@@ -42,13 +42,27 @@ struct cmd_parse_scope {
|
|||||||
TAILQ_ENTRY (cmd_parse_scope) entry;
|
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 {
|
struct cmd_parse_command {
|
||||||
u_int line;
|
u_int line;
|
||||||
|
struct cmd_parse_arguments arguments;
|
||||||
|
|
||||||
int argc;
|
TAILQ_ENTRY(cmd_parse_command) entry;
|
||||||
char **argv;
|
|
||||||
|
|
||||||
TAILQ_ENTRY(cmd_parse_command) entry;
|
|
||||||
};
|
};
|
||||||
TAILQ_HEAD(cmd_parse_commands, cmd_parse_command);
|
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 void cmd_parse_free_command(struct cmd_parse_command *);
|
||||||
static struct cmd_parse_commands *cmd_parse_new_commands(void);
|
static struct cmd_parse_commands *cmd_parse_new_commands(void);
|
||||||
static void cmd_parse_free_commands(struct cmd_parse_commands *);
|
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_build_commands(struct cmd_parse_commands *,
|
||||||
static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
struct cmd_parse_input *, struct cmd_parse_result *);
|
||||||
|
static void cmd_parse_print_commands(struct cmd_parse_input *,
|
||||||
struct cmd_list *);
|
struct cmd_list *);
|
||||||
|
|
||||||
%}
|
%}
|
||||||
@@ -86,10 +101,8 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
|||||||
%union
|
%union
|
||||||
{
|
{
|
||||||
char *token;
|
char *token;
|
||||||
struct {
|
struct cmd_parse_arguments *arguments;
|
||||||
int argc;
|
struct cmd_parse_argument *argument;
|
||||||
char **argv;
|
|
||||||
} arguments;
|
|
||||||
int flag;
|
int flag;
|
||||||
struct {
|
struct {
|
||||||
int flag;
|
int flag;
|
||||||
@@ -107,8 +120,9 @@ static void cmd_parse_print_commands(struct cmd_parse_input *, u_int,
|
|||||||
%token ENDIF
|
%token ENDIF
|
||||||
%token <token> FORMAT TOKEN EQUALS
|
%token <token> FORMAT TOKEN EQUALS
|
||||||
|
|
||||||
%type <token> argument expanded format
|
%type <token> expanded format
|
||||||
%type <arguments> arguments
|
%type <arguments> arguments
|
||||||
|
%type <argument> argument
|
||||||
%type <flag> if_open if_elif
|
%type <flag> if_open if_elif
|
||||||
%type <elif> elif elif1
|
%type <elif> elif elif1
|
||||||
%type <commands> argument_statements statements statement
|
%type <commands> argument_statements statements statement
|
||||||
@@ -360,7 +374,7 @@ commands : command
|
|||||||
struct cmd_parse_state *ps = &parse_state;
|
struct cmd_parse_state *ps = &parse_state;
|
||||||
|
|
||||||
$$ = cmd_parse_new_commands();
|
$$ = cmd_parse_new_commands();
|
||||||
if ($1->argc != 0 &&
|
if (!TAILQ_EMPTY(&$1->arguments) &&
|
||||||
(ps->scope == NULL || ps->scope->flag))
|
(ps->scope == NULL || ps->scope->flag))
|
||||||
TAILQ_INSERT_TAIL($$, $1, entry);
|
TAILQ_INSERT_TAIL($$, $1, entry);
|
||||||
else
|
else
|
||||||
@@ -380,7 +394,7 @@ commands : command
|
|||||||
{
|
{
|
||||||
struct cmd_parse_state *ps = &parse_state;
|
struct cmd_parse_state *ps = &parse_state;
|
||||||
|
|
||||||
if ($3->argc != 0 &&
|
if (!TAILQ_EMPTY(&$3->arguments) &&
|
||||||
(ps->scope == NULL || ps->scope->flag)) {
|
(ps->scope == NULL || ps->scope->flag)) {
|
||||||
$$ = $1;
|
$$ = $1;
|
||||||
TAILQ_INSERT_TAIL($$, $3, entry);
|
TAILQ_INSERT_TAIL($$, $3, entry);
|
||||||
@@ -401,27 +415,38 @@ command : assignment
|
|||||||
|
|
||||||
$$ = xcalloc(1, sizeof *$$);
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
$$->line = ps->input->line;
|
$$->line = ps->input->line;
|
||||||
|
TAILQ_INIT(&$$->arguments);
|
||||||
}
|
}
|
||||||
| optional_assignment TOKEN
|
| 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 *$$);
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
$$->line = ps->input->line;
|
$$->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
|
| 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 *$$);
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
$$->line = ps->input->line;
|
$$->line = ps->input->line;
|
||||||
|
TAILQ_INIT(&$$->arguments);
|
||||||
|
|
||||||
$$->argc = $3.argc;
|
TAILQ_CONCAT(&$$->arguments, $3, entry);
|
||||||
$$->argv = $3.argv;
|
free($3);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
condition1 : if_open commands if_close
|
condition1 : if_open commands if_close
|
||||||
@@ -505,30 +530,34 @@ elif1 : if_elif commands
|
|||||||
|
|
||||||
arguments : argument
|
arguments : argument
|
||||||
{
|
{
|
||||||
$$.argc = 1;
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
$$.argv = xreallocarray(NULL, 1, sizeof *$$.argv);
|
TAILQ_INIT($$);
|
||||||
|
|
||||||
$$.argv[0] = $1;
|
TAILQ_INSERT_HEAD($$, $1, entry);
|
||||||
}
|
}
|
||||||
| argument arguments
|
| argument arguments
|
||||||
{
|
{
|
||||||
cmd_prepend_argv(&$2.argc, &$2.argv, $1);
|
TAILQ_INSERT_HEAD($2, $1, entry);
|
||||||
free($1);
|
|
||||||
$$ = $2;
|
$$ = $2;
|
||||||
}
|
}
|
||||||
|
|
||||||
argument : TOKEN
|
argument : TOKEN
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
|
$$->type = CMD_PARSE_STRING;
|
||||||
|
$$->string = $1;
|
||||||
}
|
}
|
||||||
| EQUALS
|
| EQUALS
|
||||||
{
|
{
|
||||||
$$ = $1;
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
|
$$->type = CMD_PARSE_STRING;
|
||||||
|
$$->string = $1;
|
||||||
}
|
}
|
||||||
| '{' argument_statements
|
| '{' argument_statements
|
||||||
{
|
{
|
||||||
$$ = cmd_parse_commands_to_string($2);
|
$$ = xcalloc(1, sizeof *$$);
|
||||||
cmd_parse_free_commands($2);
|
$$->type = CMD_PARSE_COMMANDS;
|
||||||
|
$$->commands = $2;
|
||||||
}
|
}
|
||||||
|
|
||||||
argument_statements : statement '}'
|
argument_statements : statement '}'
|
||||||
@@ -552,30 +581,57 @@ cmd_parse_get_error(const char *file, u_int line, const char *error)
|
|||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
s = xstrdup(error);
|
s = xstrdup(error);
|
||||||
else
|
else
|
||||||
xasprintf (&s, "%s:%u: %s", file, line, error);
|
xasprintf(&s, "%s:%u: %s", file, line, error);
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cmd_parse_print_commands(struct cmd_parse_input *pi, u_int line,
|
cmd_parse_print_commands(struct cmd_parse_input *pi, struct cmd_list *cmdlist)
|
||||||
struct cmd_list *cmdlist)
|
|
||||||
{
|
{
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
if (pi->item != NULL && (pi->flags & CMD_PARSE_VERBOSE)) {
|
if (pi->item == NULL || (~pi->flags & CMD_PARSE_VERBOSE))
|
||||||
s = cmd_list_print(cmdlist, 0);
|
return;
|
||||||
if (pi->file != NULL)
|
s = cmd_list_print(cmdlist, 0);
|
||||||
cmdq_print(pi->item, "%s:%u: %s", pi->file, line, s);
|
if (pi->file != NULL)
|
||||||
else
|
cmdq_print(pi->item, "%s:%u: %s", pi->file, pi->line, s);
|
||||||
cmdq_print(pi->item, "%u: %s", line, s);
|
else
|
||||||
free(s);
|
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
|
static void
|
||||||
cmd_parse_free_command(struct cmd_parse_command *cmd)
|
cmd_parse_free_command(struct cmd_parse_command *cmd)
|
||||||
{
|
{
|
||||||
cmd_free_argv(cmd->argc, cmd->argv);
|
cmd_parse_free_arguments(&cmd->arguments);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -585,7 +641,7 @@ cmd_parse_new_commands(void)
|
|||||||
struct cmd_parse_commands *cmds;
|
struct cmd_parse_commands *cmds;
|
||||||
|
|
||||||
cmds = xmalloc(sizeof *cmds);
|
cmds = xmalloc(sizeof *cmds);
|
||||||
TAILQ_INIT (cmds);
|
TAILQ_INIT(cmds);
|
||||||
return (cmds);
|
return (cmds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,30 +657,6 @@ cmd_parse_free_commands(struct cmd_parse_commands *cmds)
|
|||||||
free(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 *
|
static struct cmd_parse_commands *
|
||||||
cmd_parse_run_parser(char **cause)
|
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));
|
return (cmd_parse_run_parser(cause));
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct cmd_parse_result *
|
static void
|
||||||
cmd_parse_build_commands(struct cmd_parse_commands *cmds,
|
cmd_parse_log_commands(struct cmd_parse_commands *cmds, const char *prefix)
|
||||||
struct cmd_parse_input *pi)
|
|
||||||
{
|
{
|
||||||
static struct cmd_parse_result pr;
|
struct cmd_parse_command *cmd;
|
||||||
struct cmd_parse_commands *cmds2;
|
struct cmd_parse_argument *arg;
|
||||||
struct cmd_parse_command *cmd, *cmd2, *next, *next2, *after;
|
u_int i, j;
|
||||||
u_int line = UINT_MAX;
|
char *s;
|
||||||
int i;
|
|
||||||
struct cmd_list *cmdlist = NULL, *result;
|
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;
|
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. */
|
/* Check for an empty list. */
|
||||||
if (TAILQ_EMPTY(cmds)) {
|
if (TAILQ_EMPTY(cmds)) {
|
||||||
cmd_parse_free_commands(cmds);
|
pr->status = CMD_PARSE_SUCCESS;
|
||||||
pr.status = CMD_PARSE_EMPTY;
|
pr->cmdlist = cmd_list_new();
|
||||||
return (&pr);
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
cmd_parse_log_commands(cmds, __func__);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse each command into a command list. Create a new command list
|
* 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();
|
result = cmd_list_new();
|
||||||
TAILQ_FOREACH(cmd, cmds, entry) {
|
TAILQ_FOREACH(cmd, cmds, entry) {
|
||||||
name = cmd->argv[0];
|
if (((~pi->flags & CMD_PARSE_ONEGROUP) && cmd->line != line)) {
|
||||||
log_debug("%s: %u %s", __func__, cmd->line, name);
|
if (current != NULL) {
|
||||||
cmd_log_argv(cmd->argc, cmd->argv, __func__);
|
cmd_parse_print_commands(pi, current);
|
||||||
|
cmd_list_move(result, current);
|
||||||
if (cmdlist == NULL ||
|
cmd_list_free(current);
|
||||||
((~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);
|
|
||||||
}
|
}
|
||||||
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);
|
cmd_parse_build_command(cmd, pi, pr);
|
||||||
if (add == NULL) {
|
if (pr->status != CMD_PARSE_SUCCESS) {
|
||||||
cmd_list_free(result);
|
cmd_list_free(result);
|
||||||
pr.status = CMD_PARSE_ERROR;
|
cmd_list_free(current);
|
||||||
pr.error = cmd_parse_get_error(pi->file, line, cause);
|
return;
|
||||||
free(cause);
|
|
||||||
cmd_list_free(cmdlist);
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
cmd_list_append(cmdlist, add);
|
cmd_list_append_all(current, pr->cmdlist);
|
||||||
|
cmd_list_free(pr->cmdlist);
|
||||||
}
|
}
|
||||||
if (cmdlist != NULL) {
|
if (current != NULL) {
|
||||||
cmd_parse_print_commands(pi, line, cmdlist);
|
cmd_parse_print_commands(pi, current);
|
||||||
cmd_list_move(result, cmdlist);
|
cmd_list_move(result, current);
|
||||||
cmd_list_free(cmdlist);
|
cmd_list_free(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = cmd_list_print(result, 0);
|
s = cmd_list_print(result, 0);
|
||||||
log_debug("%s: %s", __func__, s);
|
log_debug("%s: %s", __func__, s);
|
||||||
free(s);
|
free(s);
|
||||||
|
|
||||||
pr.status = CMD_PARSE_SUCCESS;
|
pr->status = CMD_PARSE_SUCCESS;
|
||||||
pr.cmdlist = result;
|
pr->cmdlist = result;
|
||||||
|
|
||||||
out:
|
|
||||||
cmd_parse_free_commands(cmds);
|
|
||||||
|
|
||||||
return (&pr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cmd_parse_result *
|
struct cmd_parse_result *
|
||||||
@@ -814,7 +934,10 @@ cmd_parse_from_file(FILE *f, struct cmd_parse_input *pi)
|
|||||||
pr.error = cause;
|
pr.error = cause;
|
||||||
return (&pr);
|
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 *
|
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);
|
pr = cmd_parse_from_string(s, pi);
|
||||||
switch (pr->status) {
|
switch (pr->status) {
|
||||||
case CMD_PARSE_EMPTY:
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_ERROR:
|
case CMD_PARSE_ERROR:
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
*error = pr->error;
|
*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);
|
pr = cmd_parse_from_string(s, pi);
|
||||||
switch (pr->status) {
|
switch (pr->status) {
|
||||||
case CMD_PARSE_EMPTY:
|
|
||||||
break;
|
|
||||||
case CMD_PARSE_ERROR:
|
case CMD_PARSE_ERROR:
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
*error = pr->error;
|
*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);
|
memset(&pr, 0, sizeof pr);
|
||||||
|
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
pr.status = CMD_PARSE_EMPTY;
|
pr.status = CMD_PARSE_SUCCESS;
|
||||||
pr.cmdlist = NULL;
|
pr.cmdlist = cmd_list_new();
|
||||||
pr.error = NULL;
|
|
||||||
return (&pr);
|
return (&pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -915,18 +1033,24 @@ cmd_parse_from_buffer(const void *buf, size_t len, struct cmd_parse_input *pi)
|
|||||||
pr.error = cause;
|
pr.error = cause;
|
||||||
return (&pr);
|
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 *
|
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;
|
static struct cmd_parse_result pr;
|
||||||
struct cmd_parse_commands *cmds;
|
struct cmd_parse_input input;
|
||||||
struct cmd_parse_command *cmd;
|
struct cmd_parse_commands *cmds;
|
||||||
char **copy, **new_argv;
|
struct cmd_parse_command *cmd;
|
||||||
size_t size;
|
struct cmd_parse_argument *arg;
|
||||||
int i, last, new_argc;
|
u_int i;
|
||||||
|
char *copy;
|
||||||
|
size_t size;
|
||||||
|
int end;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The commands are already split up into arguments, so just separate
|
* The commands are already split up into arguments, so just separate
|
||||||
@@ -937,62 +1061,56 @@ cmd_parse_from_arguments(int argc, char **argv, struct cmd_parse_input *pi)
|
|||||||
memset(&input, 0, sizeof input);
|
memset(&input, 0, sizeof input);
|
||||||
pi = &input;
|
pi = &input;
|
||||||
}
|
}
|
||||||
cmd_log_argv(argc, argv, "%s", __func__);
|
memset(&pr, 0, sizeof pr);
|
||||||
|
|
||||||
cmds = cmd_parse_new_commands();
|
cmds = cmd_parse_new_commands();
|
||||||
copy = cmd_copy_argv(argc, argv);
|
|
||||||
|
|
||||||
last = 0;
|
cmd = xcalloc(1, sizeof *cmd);
|
||||||
for (i = 0; i < argc; i++) {
|
cmd->line = pi->line;
|
||||||
size = strlen(copy[i]);
|
TAILQ_INIT(&cmd->arguments);
|
||||||
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);
|
|
||||||
|
|
||||||
|
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
|
||||||
|
free(copy);
|
||||||
|
} 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 = xcalloc(1, sizeof *cmd);
|
||||||
cmd->line = pi->line;
|
cmd->line = pi->line;
|
||||||
|
TAILQ_INIT(&cmd->arguments);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!TAILQ_EMPTY(&cmd->arguments))
|
||||||
|
TAILQ_INSERT_TAIL(cmds, cmd, entry);
|
||||||
|
else
|
||||||
|
free(cmd);
|
||||||
|
|
||||||
cmd_free_argv(argc, copy);
|
cmd_parse_build_commands(cmds, pi, &pr);
|
||||||
return (cmd_parse_build_commands(cmds, pi));
|
cmd_parse_free_commands(cmds);
|
||||||
|
return (&pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printflike(1, 2)
|
static int printflike(1, 2)
|
||||||
@@ -1309,7 +1427,7 @@ yylex_token_escape(char **buf, size_t *len)
|
|||||||
if (o3 >= '0' && o3 <= '7') {
|
if (o3 >= '0' && o3 <= '7') {
|
||||||
ch = 64 * (ch - '0') +
|
ch = 64 * (ch - '0') +
|
||||||
8 * (o2 - '0') +
|
8 * (o2 - '0') +
|
||||||
(o3 - '0');
|
(o3 - '0');
|
||||||
yylex_append1(buf, len, ch);
|
yylex_append1(buf, len, ch);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -1497,13 +1615,24 @@ yylex_token(int ch)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
/* EOF or \n are always the end of the token. */
|
/* EOF or \n are always the end of the token. */
|
||||||
if (ch == EOF || (state == NONE && ch == '\n'))
|
if (ch == EOF) {
|
||||||
|
log_debug("%s: end at EOF", __func__);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
if (state == NONE && ch == '\n') {
|
||||||
|
log_debug("%s: end at EOL", __func__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Whitespace or ; or } ends a token unless inside quotes. */
|
/* Whitespace or ; or } ends a token unless inside quotes. */
|
||||||
if ((ch == ' ' || ch == '\t' || ch == ';' || ch == '}') &&
|
if (state == NONE && (ch == ' ' || ch == '\t')) {
|
||||||
state == NONE)
|
log_debug("%s: end at WS", __func__);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
if (state == NONE && (ch == ';' || ch == '}')) {
|
||||||
|
log_debug("%s: end at %c", __func__, ch);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Spaces and comments inside quotes after \n are removed but
|
* Spaces and comments inside quotes after \n are removed but
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
|||||||
.name = "paste-buffer",
|
.name = "paste-buffer",
|
||||||
.alias = "pasteb",
|
.alias = "pasteb",
|
||||||
|
|
||||||
.args = { "db:prs:t:", 0, 0 },
|
.args = { "db:prs:t:", 0, 0, NULL },
|
||||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
||||||
CMD_TARGET_PANE_USAGE,
|
CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
@@ -54,6 +54,11 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
size_t seplen, bufsize;
|
size_t seplen, bufsize;
|
||||||
int bracket = args_has(args, 'p');
|
int bracket = args_has(args, 'p');
|
||||||
|
|
||||||
|
if (window_pane_exited(wp)) {
|
||||||
|
cmdq_error(item, "target pane has exited");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
bufname = NULL;
|
bufname = NULL;
|
||||||
if (args_has(args, 'b'))
|
if (args_has(args, 'b'))
|
||||||
bufname = args_get(args, 'b');
|
bufname = args_get(args, 'b');
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ const struct cmd_entry cmd_pipe_pane_entry = {
|
|||||||
.name = "pipe-pane",
|
.name = "pipe-pane",
|
||||||
.alias = "pipep",
|
.alias = "pipep",
|
||||||
|
|
||||||
.args = { "IOot:", 0, 1 },
|
.args = { "IOot:", 0, 1, NULL },
|
||||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [command]",
|
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.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;
|
struct format_tree *ft;
|
||||||
sigset_t set, oldset;
|
sigset_t set, oldset;
|
||||||
|
|
||||||
|
/* Do nothing if pane is dead. */
|
||||||
|
if (window_pane_exited(wp)) {
|
||||||
|
cmdq_error(item, "target pane has exited");
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
/* Destroy the old pipe. */
|
/* Destroy the old pipe. */
|
||||||
old_fd = wp->pipe_fd;
|
old_fd = wp->pipe_fd;
|
||||||
if (wp->pipe_fd != -1) {
|
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 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);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -111,7 +117,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
/* Expand the command. */
|
/* Expand the command. */
|
||||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||||
format_defaults(ft, tc, s, wl, wp);
|
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);
|
format_free(ft);
|
||||||
|
|
||||||
/* Fork the child. */
|
/* Fork the child. */
|
||||||
@@ -130,7 +136,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||||
close(pipe_fd[0]);
|
close(pipe_fd[0]);
|
||||||
|
|
||||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
null_fd = open(_PATH_DEVNULL, O_WRONLY);
|
||||||
if (out) {
|
if (out) {
|
||||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||||
_exit(1);
|
_exit(1);
|
||||||
|
|||||||
121
cmd-queue.c
121
cmd-queue.c
@@ -19,9 +19,11 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -124,7 +126,7 @@ cmdq_new(void)
|
|||||||
{
|
{
|
||||||
struct cmdq_list *queue;
|
struct cmdq_list *queue;
|
||||||
|
|
||||||
queue = xcalloc (1, sizeof *queue);
|
queue = xcalloc(1, sizeof *queue);
|
||||||
TAILQ_INIT (&queue->list);
|
TAILQ_INIT (&queue->list);
|
||||||
return (queue);
|
return (queue);
|
||||||
}
|
}
|
||||||
@@ -234,8 +236,10 @@ cmdq_link_state(struct cmdq_state *state)
|
|||||||
|
|
||||||
/* Make a copy of a state. */
|
/* Make a copy of a state. */
|
||||||
struct cmdq_state *
|
struct cmdq_state *
|
||||||
cmdq_copy_state(struct cmdq_state *state)
|
cmdq_copy_state(struct cmdq_state *state, struct cmd_find_state *current)
|
||||||
{
|
{
|
||||||
|
if (current != NULL)
|
||||||
|
return (cmdq_new_state(current, &state->event, state->flags));
|
||||||
return (cmdq_new_state(&state->current, &state->event, state->flags));
|
return (cmdq_new_state(&state->current, &state->event, state->flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,6 +273,15 @@ cmdq_add_format(struct cmdq_state *state, const char *key, const char *fmt, ...)
|
|||||||
free(value);
|
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. */
|
/* Merge formats from item. */
|
||||||
void
|
void
|
||||||
cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
|
cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
|
||||||
@@ -343,12 +356,12 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|||||||
struct cmdq_state *state = item->state;
|
struct cmdq_state *state = item->state;
|
||||||
struct cmd *cmd = item->cmd;
|
struct cmd *cmd = item->cmd;
|
||||||
struct args *args = cmd_get_args(cmd);
|
struct args *args = cmd_get_args(cmd);
|
||||||
struct args_entry *entryp;
|
struct args_entry *ae;
|
||||||
struct args_value *valuep;
|
struct args_value *av;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
char *name, tmp[32], flag, *arguments;
|
char *name, tmp[32], flag, *arguments;
|
||||||
int i;
|
u_int i;
|
||||||
const char *value;
|
const char *value;
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
struct cmdq_state *new_state;
|
struct cmdq_state *new_state;
|
||||||
@@ -385,11 +398,11 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|||||||
cmdq_add_format(new_state, "hook_arguments", "%s", arguments);
|
cmdq_add_format(new_state, "hook_arguments", "%s", arguments);
|
||||||
free(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);
|
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) {
|
while (flag != 0) {
|
||||||
value = args_get(args, flag);
|
value = args_get(args, flag);
|
||||||
if (value == NULL) {
|
if (value == NULL) {
|
||||||
@@ -401,15 +414,15 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
|||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
value = args_first_value(args, flag, &valuep);
|
av = args_first_value(args, flag);
|
||||||
while (value != NULL) {
|
while (av != NULL) {
|
||||||
xsnprintf(tmp, sizeof tmp, "hook_flag_%c_%d", flag, i);
|
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++;
|
i++;
|
||||||
value = args_next_value(&valuep);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
flag = args_next(&entryp);
|
flag = args_next(&ae);
|
||||||
}
|
}
|
||||||
|
|
||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
@@ -469,6 +482,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. */
|
/* Get a command for the command queue. */
|
||||||
struct cmdq_item *
|
struct cmdq_item *
|
||||||
cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
||||||
@@ -478,12 +498,14 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmdq_state *state)
|
|||||||
const struct cmd_entry *entry;
|
const struct cmd_entry *entry;
|
||||||
int created = 0;
|
int created = 0;
|
||||||
|
|
||||||
|
if ((cmd = cmd_list_first(cmdlist)) == NULL)
|
||||||
|
return (cmdq_get_callback(cmdq_empty_command, NULL));
|
||||||
|
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
state = cmdq_new_state(NULL, NULL, 0);
|
state = cmdq_new_state(NULL, NULL, 0);
|
||||||
created = 1;
|
created = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = cmd_list_first(cmdlist);
|
|
||||||
while (cmd != NULL) {
|
while (cmd != NULL) {
|
||||||
entry = cmd_get_entry(cmd);
|
entry = cmd_get_entry(cmd);
|
||||||
|
|
||||||
@@ -540,17 +562,31 @@ cmdq_add_message(struct cmdq_item *item)
|
|||||||
{
|
{
|
||||||
struct client *c = item->client;
|
struct client *c = item->client;
|
||||||
struct cmdq_state *state = item->state;
|
struct cmdq_state *state = item->state;
|
||||||
const char *name, *key;
|
const char *key;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
uid_t uid;
|
||||||
|
struct passwd *pw;
|
||||||
|
char *user = NULL;
|
||||||
|
|
||||||
tmp = cmd_print(item->cmd);
|
tmp = cmd_print(item->cmd);
|
||||||
if (c != NULL) {
|
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) {
|
if (c->session != NULL && state->event.key != KEYC_NONE) {
|
||||||
key = key_string_lookup_key(state->event.key, 0);
|
key = key_string_lookup_key(state->event.key, 0);
|
||||||
server_add_message("%s key %s: %s", name, key, tmp);
|
server_add_message("%s%s key %s: %s", c->name, user,
|
||||||
} else
|
key, tmp);
|
||||||
server_add_message("%s command: %s", name, tmp);
|
} else {
|
||||||
|
server_add_message("%s%s command: %s", c->name, user,
|
||||||
|
tmp);
|
||||||
|
}
|
||||||
|
free(user);
|
||||||
} else
|
} else
|
||||||
server_add_message("command: %s", tmp);
|
server_add_message("command: %s", tmp);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
@@ -787,45 +823,30 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
|||||||
control_write(c, "%%%s %ld %u %d", guard, t, number, flags);
|
control_write(c, "%%%s %ld %u %d", guard, t, number, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Show message from command. */
|
||||||
|
void
|
||||||
|
cmdq_print_data(struct cmdq_item *item, int parse, struct evbuffer *evb)
|
||||||
|
{
|
||||||
|
server_client_print(item->client, parse, evb);
|
||||||
|
}
|
||||||
|
|
||||||
/* Show message from command. */
|
/* Show message from command. */
|
||||||
void
|
void
|
||||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
struct client *c = item->client;
|
va_list ap;
|
||||||
struct window_pane *wp;
|
struct evbuffer *evb;
|
||||||
struct window_mode_entry *wme;
|
|
||||||
va_list ap;
|
evb = evbuffer_new();
|
||||||
char *tmp, *msg;
|
if (evb == NULL)
|
||||||
|
fatalx("out of memory");
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
xvasprintf(&msg, fmt, ap);
|
evbuffer_add_vprintf(evb, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
log_debug("%s: %s", __func__, msg);
|
cmdq_print_data(item, 0, evb);
|
||||||
|
evbuffer_free(evb);
|
||||||
if (c == NULL)
|
|
||||||
/* nothing */;
|
|
||||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
|
||||||
if (~c->flags & CLIENT_UTF8) {
|
|
||||||
tmp = msg;
|
|
||||||
msg = utf8_sanitize(tmp);
|
|
||||||
free(tmp);
|
|
||||||
}
|
|
||||||
if (c->flags & CLIENT_CONTROL)
|
|
||||||
control_write(c, "%s", msg);
|
|
||||||
else
|
|
||||||
file_print(c, "%s\n", msg);
|
|
||||||
} else {
|
|
||||||
wp = server_client_get_pane(c);
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show error from command. */
|
/* Show error from command. */
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
|||||||
.name = "refresh-client",
|
.name = "refresh-client",
|
||||||
.alias = "refresh",
|
.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] "
|
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
|
||||||
"[-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
"[-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
||||||
|
|
||||||
@@ -77,6 +77,58 @@ out:
|
|||||||
free(copy);
|
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
|
static void
|
||||||
cmd_refresh_client_update_offset(struct client *tc, const char *value)
|
cmd_refresh_client_update_offset(struct client *tc, const char *value)
|
||||||
{
|
{
|
||||||
@@ -110,6 +162,37 @@ out:
|
|||||||
free(copy);
|
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
|
static enum cmd_retval
|
||||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
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 client *tc = cmdq_get_target_client(item);
|
||||||
struct tty *tty = &tc->tty;
|
struct tty *tty = &tc->tty;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
const char *size, *errstr, *value;
|
const char *errstr;
|
||||||
u_int x, y, adjust;
|
u_int adjust;
|
||||||
struct args_value *av;
|
struct args_value *av;
|
||||||
|
|
||||||
if (args_has(args, 'c') ||
|
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, 'U') ||
|
||||||
args_has(args, 'D'))
|
args_has(args, 'D'))
|
||||||
{
|
{
|
||||||
if (args->argc == 0)
|
if (args_count(args) == 0)
|
||||||
adjust = 1;
|
adjust = 1;
|
||||||
else {
|
else {
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
adjust = strtonum(args_string(args, 0), 1, INT_MAX,
|
||||||
|
&errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
cmdq_error(item, "adjustment %s", errstr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -171,10 +255,8 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'l')) {
|
if (args_has(args, 'l'))
|
||||||
tty_putcode_ptr2(&tc->tty, TTYC_MS, "", "?");
|
return (cmd_refresh_client_clipboard(self, item));
|
||||||
return (CMD_RETURN_NORMAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (args_has(args, 'F')) /* -F is an alias for -f */
|
if (args_has(args, 'F')) /* -F is an alias for -f */
|
||||||
server_client_set_flags(tc, args_get(args, '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 (args_has(args, 'A')) {
|
||||||
if (~tc->flags & CLIENT_CONTROL)
|
if (~tc->flags & CLIENT_CONTROL)
|
||||||
goto not_control_client;
|
goto not_control_client;
|
||||||
value = args_first_value(args, 'A', &av);
|
av = args_first_value(args, 'A');
|
||||||
while (value != NULL) {
|
while (av != NULL) {
|
||||||
cmd_refresh_client_update_offset(tc, value);
|
cmd_refresh_client_update_offset(tc, av->string);
|
||||||
value = args_next_value(&av);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
if (args_has(args, 'B')) {
|
if (args_has(args, 'B')) {
|
||||||
if (~tc->flags & CLIENT_CONTROL)
|
if (~tc->flags & CLIENT_CONTROL)
|
||||||
goto not_control_client;
|
goto not_control_client;
|
||||||
value = args_first_value(args, 'B', &av);
|
av = args_first_value(args, 'B');
|
||||||
while (value != NULL) {
|
while (av != NULL) {
|
||||||
cmd_refresh_client_update_subscription(tc, value);
|
cmd_refresh_client_update_subscription(tc, av->string);
|
||||||
value = args_next_value(&av);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
if (args_has(args, 'C')) {
|
if (args_has(args, 'C')) {
|
||||||
if (~tc->flags & CLIENT_CONTROL)
|
if (~tc->flags & CLIENT_CONTROL)
|
||||||
goto not_control_client;
|
goto not_control_client;
|
||||||
size = args_get(args, 'C');
|
return (cmd_refresh_client_control_client_size(self, item));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'S')) {
|
if (args_has(args, 'S')) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_rename_session_entry = {
|
|||||||
.name = "rename-session",
|
.name = "rename-session",
|
||||||
.alias = "rename",
|
.alias = "rename",
|
||||||
|
|
||||||
.args = { "t:", 1, 1 },
|
.args = { "t:", 1, 1, NULL },
|
||||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.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;
|
struct session *s = target->s;
|
||||||
char *newname, *tmp;
|
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);
|
newname = session_check_name(tmp);
|
||||||
|
if (newname == NULL) {
|
||||||
|
cmdq_error(item, "invalid session: %s", tmp);
|
||||||
|
free(tmp);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
free(tmp);
|
free(tmp);
|
||||||
if (strcmp(newname, s->name) == 0) {
|
if (strcmp(newname, s->name) == 0) {
|
||||||
free(newname);
|
free(newname);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_rename_window_entry = {
|
|||||||
.name = "rename-window",
|
.name = "rename-window",
|
||||||
.alias = "renamew",
|
.alias = "renamew",
|
||||||
|
|
||||||
.args = { "t:", 1, 1 },
|
.args = { "t:", 1, 1, NULL },
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.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;
|
struct winlink *wl = target->wl;
|
||||||
char *newname;
|
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);
|
window_set_name(wl->window, newname);
|
||||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_resize_pane_entry = {
|
|||||||
.name = "resize-pane",
|
.name = "resize-pane",
|
||||||
.alias = "resizep",
|
.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 " "
|
.usage = "[-DLMRTUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
||||||
"[adjustment]",
|
"[adjustment]",
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *cause;
|
char *cause;
|
||||||
u_int adjust;
|
u_int adjust;
|
||||||
int x, y;
|
int x, y, status;
|
||||||
struct grid *gd = wp->base.grid;
|
struct grid *gd = wp->base.grid;
|
||||||
|
|
||||||
if (args_has(args, 'T')) {
|
if (args_has(args, 'T')) {
|
||||||
@@ -95,10 +95,10 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
server_unzoom_window(w);
|
server_unzoom_window(w);
|
||||||
|
|
||||||
if (args->argc == 0)
|
if (args_count(args) == 0)
|
||||||
adjust = 1;
|
adjust = 1;
|
||||||
else {
|
else {
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
cmdq_error(item, "adjustment %s", errstr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -121,6 +121,17 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
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);
|
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_resize_window_entry = {
|
|||||||
.name = "resize-window",
|
.name = "resize-window",
|
||||||
.alias = "resizew",
|
.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 " "
|
.usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
|
||||||
"[adjustment]",
|
"[adjustment]",
|
||||||
|
|
||||||
@@ -53,13 +53,12 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
const char *errstr;
|
const char *errstr;
|
||||||
char *cause;
|
char *cause;
|
||||||
u_int adjust, sx, sy;
|
u_int adjust, sx, sy, xpixel = 0, ypixel = 0;
|
||||||
int xpixel = -1, ypixel = -1;
|
|
||||||
|
|
||||||
if (args->argc == 0)
|
if (args_count(args) == 0)
|
||||||
adjust = 1;
|
adjust = 1;
|
||||||
else {
|
else {
|
||||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
adjust = strtonum(args_string(args, 0), 1, INT_MAX, &errstr);
|
||||||
if (errstr != NULL) {
|
if (errstr != NULL) {
|
||||||
cmdq_error(item, "adjustment %s", errstr);
|
cmdq_error(item, "adjustment %s", errstr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -108,7 +107,9 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
|
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);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
|||||||
.name = "respawn-pane",
|
.name = "respawn-pane",
|
||||||
.alias = "respawnp",
|
.alias = "respawnp",
|
||||||
|
|
||||||
.args = { "c:e:kt:", 0, -1 },
|
.args = { "c:e:kt:", 0, -1, NULL },
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||||
CMD_TARGET_PANE_USAGE " [command]",
|
CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.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 args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct spawn_context sc;
|
struct spawn_context sc = { 0 };
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl;
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
char *cause = NULL;
|
char *cause = NULL;
|
||||||
const char *add;
|
struct args_value *av;
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
sc.item = item;
|
||||||
sc.s = s;
|
sc.s = s;
|
||||||
sc.wl = wl;
|
sc.wl = wl;
|
||||||
|
|
||||||
sc.wp0 = wp;
|
sc.wp0 = wp;
|
||||||
sc.lc = NULL;
|
|
||||||
|
|
||||||
sc.name = NULL;
|
args_to_vector(args, &sc.argc, &sc.argv);
|
||||||
sc.argc = args->argc;
|
|
||||||
sc.argv = args->argv;
|
|
||||||
sc.environ = environ_create();
|
sc.environ = environ_create();
|
||||||
|
|
||||||
add = args_first_value(args, 'e', &value);
|
av = args_first_value(args, 'e');
|
||||||
while (add != NULL) {
|
while (av != NULL) {
|
||||||
environ_put(sc.environ, add, 0);
|
environ_put(sc.environ, av->string, 0);
|
||||||
add = args_next_value(&value);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
sc.idx = -1;
|
||||||
@@ -86,6 +81,9 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (spawn_pane(&sc, &cause) == NULL) {
|
if (spawn_pane(&sc, &cause) == NULL) {
|
||||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
cmdq_error(item, "respawn pane failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_ERROR);
|
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_redraw_window_borders(wp->window);
|
||||||
server_status_window(wp->window);
|
server_status_window(wp->window);
|
||||||
|
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
environ_free(sc.environ);
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
|||||||
.name = "respawn-window",
|
.name = "respawn-window",
|
||||||
.alias = "respawnw",
|
.alias = "respawnw",
|
||||||
|
|
||||||
.args = { "c:e:kt:", 0, -1 },
|
.args = { "c:e:kt:", 0, -1, NULL },
|
||||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.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 args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *target = cmdq_get_target(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 client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl;
|
||||||
char *cause = NULL;
|
char *cause = NULL;
|
||||||
const char *add;
|
struct args_value *av;
|
||||||
struct args_value *value;
|
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
sc.item = item;
|
||||||
sc.s = s;
|
sc.s = s;
|
||||||
sc.wl = wl;
|
sc.wl = wl;
|
||||||
sc.tc = tc;
|
sc.tc = tc;
|
||||||
|
|
||||||
sc.name = NULL;
|
args_to_vector(args, &sc.argc, &sc.argv);
|
||||||
sc.argc = args->argc;
|
|
||||||
sc.argv = args->argv;
|
|
||||||
sc.environ = environ_create();
|
sc.environ = environ_create();
|
||||||
|
|
||||||
add = args_first_value(args, 'e', &value);
|
av = args_first_value(args, 'e');
|
||||||
while (add != NULL) {
|
while (av != NULL) {
|
||||||
environ_put(sc.environ, add, 0);
|
environ_put(sc.environ, av->string, 0);
|
||||||
add = args_next_value(&value);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
sc.idx = -1;
|
||||||
@@ -84,11 +80,16 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (spawn_window(&sc, &cause) == NULL) {
|
if (spawn_window(&sc, &cause) == NULL) {
|
||||||
cmdq_error(item, "respawn window failed: %s", cause);
|
cmdq_error(item, "respawn window failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
server_redraw_window(wl->window);
|
server_redraw_window(wl->window);
|
||||||
|
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
environ_free(sc.environ);
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
|||||||
.name = "rotate-window",
|
.name = "rotate-window",
|
||||||
.alias = "rotatew",
|
.alias = "rotatew",
|
||||||
|
|
||||||
.args = { "Dt:UZ", 0, 0 },
|
.args = { "Dt:UZ", 0, 0, NULL },
|
||||||
.usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
|
.usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
|
|||||||
135
cmd-run-shell.c
135
cmd-run-shell.c
@@ -30,7 +30,10 @@
|
|||||||
* Runs a command without a window.
|
* 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_timer(int, short, void *);
|
||||||
static void cmd_run_shell_callback(struct job *);
|
static void cmd_run_shell_callback(struct job *);
|
||||||
@@ -41,8 +44,9 @@ const struct cmd_entry cmd_run_shell_entry = {
|
|||||||
.name = "run-shell",
|
.name = "run-shell",
|
||||||
.alias = "run",
|
.alias = "run",
|
||||||
|
|
||||||
.args = { "bd:Ct:", 0, 1 },
|
.args = { "bd:Ct:c:", 0, 2, cmd_run_shell_args_parse },
|
||||||
.usage = "[-bC] [-d delay] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
.usage = "[-bC] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
|
||||||
|
" [shell-command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
@@ -51,18 +55,26 @@ const struct cmd_entry cmd_run_shell_entry = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct cmd_run_shell_data {
|
struct cmd_run_shell_data {
|
||||||
struct client *client;
|
struct client *client;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int shell;
|
struct args_command_state *state;
|
||||||
char *cwd;
|
char *cwd;
|
||||||
struct cmdq_item *item;
|
struct cmdq_item *item;
|
||||||
struct session *s;
|
struct session *s;
|
||||||
int wp_id;
|
int wp_id;
|
||||||
struct event timer;
|
struct event timer;
|
||||||
int flags;
|
int flags;
|
||||||
struct cmd_parse_input pi;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
static void
|
||||||
cmd_run_shell_print(struct job *job, const char *msg)
|
cmd_run_shell_print(struct job *job, const char *msg)
|
||||||
{
|
{
|
||||||
@@ -73,22 +85,17 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
|||||||
|
|
||||||
if (cdata->wp_id != -1)
|
if (cdata->wp_id != -1)
|
||||||
wp = window_pane_find_by_id(cdata->wp_id);
|
wp = window_pane_find_by_id(cdata->wp_id);
|
||||||
if (wp == NULL) {
|
if (wp == NULL && cdata->item != NULL && cdata->client != NULL)
|
||||||
if (cdata->item != NULL) {
|
wp = server_client_get_pane(cdata->client);
|
||||||
cmdq_print(cdata->item, "%s", msg);
|
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (cmd_find_from_nothing(&fs, 0) != 0)
|
|
||||||
return;
|
|
||||||
wp = fs.wp;
|
wp = fs.wp;
|
||||||
if (wp == NULL)
|
if (wp == NULL)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
wme = TAILQ_FIRST(&wp->modes);
|
||||||
if (wme == NULL || wme->mode != &window_view_mode)
|
if (wme == NULL || wme->mode != &window_view_mode)
|
||||||
window_pane_set_mode(wp, NULL, &window_view_mode, NULL, NULL);
|
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
|
static enum cmd_retval
|
||||||
@@ -97,10 +104,11 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct cmd_run_shell_data *cdata;
|
struct cmd_run_shell_data *cdata;
|
||||||
|
struct client *c = cmdq_get_client(item);
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *delay;
|
const char *delay, *cmd;
|
||||||
double d;
|
double d;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char *end;
|
char *end;
|
||||||
@@ -112,21 +120,17 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmdq_error(item, "invalid delay time: %s", delay);
|
cmdq_error(item, "invalid delay time: %s", delay);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
} else if (args->argc == 0)
|
} else if (args_count(args) == 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
if (args->argc != 0)
|
if (!args_has(args, 'C')) {
|
||||||
cdata->cmd = format_single_from_target(item, args->argv[0]);
|
cmd = args_string(args, 0);
|
||||||
|
if (cmd != NULL)
|
||||||
cdata->shell = !args_has(args, 'C');
|
cdata->cmd = format_single_from_target(item, cmd);
|
||||||
if (!cdata->shell) {
|
} else {
|
||||||
memset(&cdata->pi, 0, sizeof cdata->pi);
|
cdata->state = args_make_commands_prepare(self, item, 0, NULL,
|
||||||
cmd_get_source(self, &cdata->pi.file, &cdata->pi.line);
|
wait, 1);
|
||||||
if (wait)
|
|
||||||
cdata->pi.item = item;
|
|
||||||
cdata->pi.c = tc;
|
|
||||||
cmd_find_copy_state(&cdata->pi.fs, target);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 't') && wp != NULL)
|
if (args_has(args, 't') && wp != NULL)
|
||||||
@@ -135,7 +139,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cdata->wp_id = -1;
|
cdata->wp_id = -1;
|
||||||
|
|
||||||
if (wait) {
|
if (wait) {
|
||||||
cdata->client = cmdq_get_client(item);
|
cdata->client = c;
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
} else {
|
} else {
|
||||||
cdata->client = tc;
|
cdata->client = tc;
|
||||||
@@ -143,8 +147,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
if (cdata->client != NULL)
|
if (cdata->client != NULL)
|
||||||
cdata->client->references++;
|
cdata->client->references++;
|
||||||
|
if (args_has(args, 'c'))
|
||||||
cdata->cwd = xstrdup(server_client_get_cwd(cmdq_get_client(item), s));
|
cdata->cwd = xstrdup(args_get(args, 'c'));
|
||||||
|
else
|
||||||
|
cdata->cwd = xstrdup(server_client_get_cwd(c, s));
|
||||||
|
|
||||||
cdata->s = s;
|
cdata->s = s;
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
@@ -170,34 +176,38 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
|
|||||||
struct cmd_run_shell_data *cdata = arg;
|
struct cmd_run_shell_data *cdata = arg;
|
||||||
struct client *c = cdata->client;
|
struct client *c = cdata->client;
|
||||||
const char *cmd = cdata->cmd;
|
const char *cmd = cdata->cmd;
|
||||||
|
struct cmdq_item *item = cdata->item, *new_item;
|
||||||
|
struct cmd_list *cmdlist;
|
||||||
char *error;
|
char *error;
|
||||||
struct cmdq_item *item = cdata->item;
|
|
||||||
enum cmd_parse_status status;
|
|
||||||
|
|
||||||
if (cmd != NULL && cdata->shell) {
|
if (cdata->state == NULL) {
|
||||||
if (job_run(cmd, 0, NULL, cdata->s, cdata->cwd, 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,
|
cmd_run_shell_callback, cmd_run_shell_free, cdata,
|
||||||
cdata->flags, -1, -1) == NULL)
|
cdata->flags, -1, -1) == NULL)
|
||||||
cmd_run_shell_free(cdata);
|
cmd_run_shell_free(cdata);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd != NULL) {
|
cmdlist = args_make_commands(cdata->state, 0, NULL, &error);
|
||||||
if (item != NULL) {
|
if (cmdlist == NULL) {
|
||||||
status = cmd_parse_and_insert(cmd, &cdata->pi, item,
|
if (cdata->item == NULL) {
|
||||||
cmdq_get_state(item), &error);
|
*error = toupper((u_char)*error);
|
||||||
} else {
|
status_message_set(c, -1, 1, 0, "%s", error);
|
||||||
status = cmd_parse_and_append(cmd, &cdata->pi, c, NULL,
|
} else
|
||||||
&error);
|
cmdq_error(cdata->item, "%s", error);
|
||||||
}
|
free(error);
|
||||||
if (status == CMD_PARSE_ERROR) {
|
} else if (item == NULL) {
|
||||||
if (cdata->item == NULL) {
|
new_item = cmdq_get_command(cmdlist, NULL);
|
||||||
*error = toupper((u_char)*error);
|
cmdq_append(c, new_item);
|
||||||
status_message_set(c, -1, 1, 0, "%s", error);
|
} else {
|
||||||
} else
|
new_item = cmdq_get_command(cmdlist, cmdq_get_state(item));
|
||||||
cmdq_error(cdata->item, "%s", error);
|
cmdq_insert_after(item, new_item);
|
||||||
free(error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cdata->item != NULL)
|
if (cdata->item != NULL)
|
||||||
@@ -216,7 +226,8 @@ cmd_run_shell_callback(struct job *job)
|
|||||||
int retcode, status;
|
int retcode, status;
|
||||||
|
|
||||||
do {
|
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);
|
cmd_run_shell_print(job, line);
|
||||||
free(line);
|
free(line);
|
||||||
}
|
}
|
||||||
@@ -265,6 +276,8 @@ cmd_run_shell_free(void *data)
|
|||||||
session_remove_ref(cdata->s, __func__);
|
session_remove_ref(cdata->s, __func__);
|
||||||
if (cdata->client != NULL)
|
if (cdata->client != NULL)
|
||||||
server_client_unref(cdata->client);
|
server_client_unref(cdata->client);
|
||||||
|
if (cdata->state != NULL)
|
||||||
|
args_make_commands_free(cdata->state);
|
||||||
free(cdata->cwd);
|
free(cdata->cwd);
|
||||||
free(cdata->cmd);
|
free(cdata->cmd);
|
||||||
free(cdata);
|
free(cdata);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_save_buffer_entry = {
|
|||||||
.name = "save-buffer",
|
.name = "save-buffer",
|
||||||
.alias = "saveb",
|
.alias = "saveb",
|
||||||
|
|
||||||
.args = { "ab:", 1, 1 },
|
.args = { "ab:", 1, 1, NULL },
|
||||||
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
.usage = "[-a] " CMD_BUFFER_USAGE " path",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
@@ -48,7 +48,7 @@ const struct cmd_entry cmd_show_buffer_entry = {
|
|||||||
.name = "show-buffer",
|
.name = "show-buffer",
|
||||||
.alias = "showb",
|
.alias = "showb",
|
||||||
|
|
||||||
.args = { "b:", 0, 0 },
|
.args = { "b:", 0, 0, NULL },
|
||||||
.usage = CMD_BUFFER_USAGE,
|
.usage = CMD_BUFFER_USAGE,
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
@@ -78,7 +78,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
int flags;
|
int flags;
|
||||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
const char *bufname = args_get(args, 'b'), *bufdata;
|
||||||
size_t bufsize;
|
size_t bufsize;
|
||||||
char *path, *tmp;
|
char *path;
|
||||||
|
struct evbuffer *evb;
|
||||||
|
|
||||||
if (bufname == NULL) {
|
if (bufname == NULL) {
|
||||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
if ((pb = paste_get_top(NULL)) == NULL) {
|
||||||
@@ -96,15 +97,17 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
||||||
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
||||||
utf8_stravisx(&tmp, bufdata, bufsize,
|
evb = evbuffer_new();
|
||||||
VIS_OCTAL|VIS_CSTYLE|VIS_TAB);
|
if (evb == NULL)
|
||||||
cmdq_print(item, "%s", tmp);
|
fatalx("out of memory");
|
||||||
free(tmp);
|
evbuffer_add(evb, bufdata, bufsize);
|
||||||
|
cmdq_print_data(item, 1, evb);
|
||||||
|
evbuffer_free(evb);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
path = xstrdup("-");
|
path = xstrdup("-");
|
||||||
} else
|
} 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'))
|
if (args_has(args, 'a'))
|
||||||
flags = O_APPEND;
|
flags = O_APPEND;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_layout_entry = {
|
|||||||
.name = "select-layout",
|
.name = "select-layout",
|
||||||
.alias = "selectl",
|
.alias = "selectl",
|
||||||
|
|
||||||
.args = { "Enopt:", 0, 1 },
|
.args = { "Enopt:", 0, 1, NULL },
|
||||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_next_layout_entry = {
|
|||||||
.name = "next-layout",
|
.name = "next-layout",
|
||||||
.alias = "nextl",
|
.alias = "nextl",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
@@ -59,7 +59,7 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
|||||||
.name = "previous-layout",
|
.name = "previous-layout",
|
||||||
.alias = "prevl",
|
.alias = "prevl",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.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 *w = wl->window;
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
const char *layoutname;
|
const char *layoutname;
|
||||||
char *oldlayout;
|
char *oldlayout, *cause;
|
||||||
int next, previous, layout;
|
int next, previous, layout;
|
||||||
|
|
||||||
server_unzoom_window(w);
|
server_unzoom_window(w);
|
||||||
@@ -105,27 +105,28 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
goto changed;
|
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_has(args, 'o')) {
|
||||||
if (args->argc == 0)
|
if (layoutname == NULL)
|
||||||
layout = w->lastlayout;
|
layout = w->lastlayout;
|
||||||
else
|
else
|
||||||
layout = layout_set_lookup(args->argv[0]);
|
layout = layout_set_lookup(layoutname);
|
||||||
if (layout != -1) {
|
if (layout != -1) {
|
||||||
layout_set_select(w, layout);
|
layout_set_select(w, layout);
|
||||||
goto changed;
|
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 (layoutname != NULL) {
|
||||||
if (layout_parse(w, layoutname) == -1) {
|
if (layout_parse(w, layoutname, &cause) == -1) {
|
||||||
cmdq_error(item, "can't set layout: %s", layoutname);
|
cmdq_error(item, "%s: %s", cause, layoutname);
|
||||||
|
free(cause);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
goto changed;
|
goto changed;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_pane_entry = {
|
|||||||
.name = "select-pane",
|
.name = "select-pane",
|
||||||
.alias = "selectp",
|
.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,
|
.usage = "[-DdeLlMmRUZ] [-T title] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_last_pane_entry = {
|
|||||||
.name = "last-pane",
|
.name = "last-pane",
|
||||||
.alias = "lastp",
|
.alias = "lastp",
|
||||||
|
|
||||||
.args = { "det:Z", 0, 0 },
|
.args = { "det:Z", 0, 0, NULL },
|
||||||
.usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
|
.usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
@@ -98,7 +98,11 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
|
|
||||||
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||||
lastwp = w->last;
|
/*
|
||||||
|
* Check for no last pane found in case the other pane was
|
||||||
|
* spawned without being visited (for example split-window -d).
|
||||||
|
*/
|
||||||
|
lastwp = TAILQ_FIRST(&w->last_panes);
|
||||||
if (lastwp == NULL && window_count_panes(w) == 2) {
|
if (lastwp == NULL && window_count_panes(w) == 2) {
|
||||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
||||||
if (lastwp == NULL)
|
if (lastwp == NULL)
|
||||||
@@ -145,10 +149,12 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
markedwp = marked_pane.wp;
|
markedwp = marked_pane.wp;
|
||||||
|
|
||||||
if (lastwp != NULL) {
|
if (lastwp != NULL) {
|
||||||
|
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||||
server_redraw_window_borders(lastwp->window);
|
server_redraw_window_borders(lastwp->window);
|
||||||
server_status_window(lastwp->window);
|
server_status_window(lastwp->window);
|
||||||
}
|
}
|
||||||
if (markedwp != NULL) {
|
if (markedwp != NULL) {
|
||||||
|
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||||
server_redraw_window_borders(markedwp->window);
|
server_redraw_window_borders(markedwp->window);
|
||||||
server_status_window(markedwp->window);
|
server_status_window(markedwp->window);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_select_window_entry = {
|
|||||||
.name = "select-window",
|
.name = "select-window",
|
||||||
.alias = "selectw",
|
.alias = "selectw",
|
||||||
|
|
||||||
.args = { "lnpTt:", 0, 0 },
|
.args = { "lnpTt:", 0, 0, NULL },
|
||||||
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_next_window_entry = {
|
|||||||
.name = "next-window",
|
.name = "next-window",
|
||||||
.alias = "next",
|
.alias = "next",
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
.args = { "at:", 0, 0, NULL },
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
@@ -59,7 +59,7 @@ const struct cmd_entry cmd_previous_window_entry = {
|
|||||||
.name = "previous-window",
|
.name = "previous-window",
|
||||||
.alias = "prev",
|
.alias = "prev",
|
||||||
|
|
||||||
.args = { "at:", 0, 0 },
|
.args = { "at:", 0, 0, NULL },
|
||||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
@@ -72,7 +72,7 @@ const struct cmd_entry cmd_last_window_entry = {
|
|||||||
.name = "last-window",
|
.name = "last-window",
|
||||||
.alias = "last",
|
.alias = "last",
|
||||||
|
|
||||||
.args = { "t:", 0, 0 },
|
.args = { "t:", 0, 0, NULL },
|
||||||
.usage = CMD_TARGET_SESSION_USAGE,
|
.usage = CMD_TARGET_SESSION_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||||
|
|||||||
@@ -33,13 +33,13 @@ const struct cmd_entry cmd_send_keys_entry = {
|
|||||||
.name = "send-keys",
|
.name = "send-keys",
|
||||||
.alias = "send",
|
.alias = "send",
|
||||||
|
|
||||||
.args = { "FHlMN:Rt:X", 0, -1 },
|
.args = { "c:FHKlMN:Rt:X", 0, -1, NULL },
|
||||||
.usage = "[-FHlMRX] [-N repeat-count] " CMD_TARGET_PANE_USAGE
|
.usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] "
|
||||||
" key ...",
|
CMD_TARGET_PANE_USAGE " key ...",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL,
|
||||||
.exec = cmd_send_keys_exec
|
.exec = cmd_send_keys_exec
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
|||||||
.name = "send-prefix",
|
.name = "send-prefix",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "2t:", 0, 0 },
|
.args = { "2t:", 0, 0, NULL },
|
||||||
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, 0 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
@@ -58,7 +58,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
|||||||
|
|
||||||
static struct cmdq_item *
|
static struct cmdq_item *
|
||||||
cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
|
cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
|
||||||
key_code key)
|
struct args *args, key_code key)
|
||||||
{
|
{
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct client *tc = cmdq_get_target_client(item);
|
struct client *tc = cmdq_get_target_client(item);
|
||||||
@@ -66,8 +66,20 @@ cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
|
|||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl;
|
||||||
struct window_pane *wp = target->wp;
|
struct window_pane *wp = target->wp;
|
||||||
struct window_mode_entry *wme;
|
struct window_mode_entry *wme;
|
||||||
struct key_table *table;
|
struct key_table *table = NULL;
|
||||||
struct key_binding *bd;
|
struct key_binding *bd;
|
||||||
|
struct key_event *event;
|
||||||
|
|
||||||
|
if (args_has(args, 'K')) {
|
||||||
|
if (tc == NULL)
|
||||||
|
return (item);
|
||||||
|
event = xmalloc(sizeof *event);
|
||||||
|
event->key = key|KEYC_SENT;
|
||||||
|
memset(&event->m, 0, sizeof event->m);
|
||||||
|
if (server_client_handle_key(tc, event) == 0)
|
||||||
|
free(event);
|
||||||
|
return (item);
|
||||||
|
}
|
||||||
|
|
||||||
wme = TAILQ_FIRST(&wp->modes);
|
wme = TAILQ_FIRST(&wp->modes);
|
||||||
if (wme == NULL || wme->mode->key_table == NULL) {
|
if (wme == NULL || wme->mode->key_table == NULL) {
|
||||||
@@ -90,7 +102,7 @@ static struct cmdq_item *
|
|||||||
cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
||||||
struct args *args, int i)
|
struct args *args, int i)
|
||||||
{
|
{
|
||||||
const char *s = args->argv[i];
|
const char *s = args_string(args, i);
|
||||||
struct utf8_data *ud, *loop;
|
struct utf8_data *ud, *loop;
|
||||||
utf8_char uc;
|
utf8_char uc;
|
||||||
key_code key;
|
key_code key;
|
||||||
@@ -102,14 +114,16 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
|||||||
n = strtol(s, &endptr, 16);
|
n = strtol(s, &endptr, 16);
|
||||||
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
|
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
|
||||||
return (item);
|
return (item);
|
||||||
return (cmd_send_keys_inject_key(item, after, KEYC_LITERAL|n));
|
return (cmd_send_keys_inject_key(item, after, args,
|
||||||
|
KEYC_LITERAL|n));
|
||||||
}
|
}
|
||||||
|
|
||||||
literal = args_has(args, 'l');
|
literal = args_has(args, 'l');
|
||||||
if (!literal) {
|
if (!literal) {
|
||||||
key = key_string_lookup_string(s);
|
key = key_string_lookup_string(s);
|
||||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
|
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
|
||||||
after = cmd_send_keys_inject_key(item, after, key);
|
after = cmd_send_keys_inject_key(item, after, args,
|
||||||
|
key);
|
||||||
if (after != NULL)
|
if (after != NULL)
|
||||||
return (after);
|
return (after);
|
||||||
}
|
}
|
||||||
@@ -125,7 +139,8 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
|||||||
continue;
|
continue;
|
||||||
key = uc;
|
key = uc;
|
||||||
}
|
}
|
||||||
after = cmd_send_keys_inject_key(item, after, key);
|
after = cmd_send_keys_inject_key(item, after, args,
|
||||||
|
key);
|
||||||
}
|
}
|
||||||
free(ud);
|
free(ud);
|
||||||
}
|
}
|
||||||
@@ -145,19 +160,20 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct mouse_event *m = &event->m;
|
struct mouse_event *m = &event->m;
|
||||||
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
||||||
struct cmdq_item *after = item;
|
struct cmdq_item *after = item;
|
||||||
int i;
|
|
||||||
key_code key;
|
key_code key;
|
||||||
u_int np = 1;
|
u_int i, np = 1;
|
||||||
|
u_int count = args_count(args);
|
||||||
char *cause = NULL;
|
char *cause = NULL;
|
||||||
|
|
||||||
if (args_has(args, 'N')) {
|
if (args_has(args, 'N')) {
|
||||||
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
|
np = args_strtonum_and_expand(args, 'N', 1, UINT_MAX, item,
|
||||||
|
&cause);
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
cmdq_error(item, "repeat count %s", cause);
|
cmdq_error(item, "repeat count %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
return (CMD_RETURN_ERROR);
|
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) {
|
if (wme->mode->command == NULL) {
|
||||||
cmdq_error(item, "not in a mode");
|
cmdq_error(item, "not in a mode");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -192,17 +208,26 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
key = options_get_number(s->options, "prefix2");
|
key = options_get_number(s->options, "prefix2");
|
||||||
else
|
else
|
||||||
key = options_get_number(s->options, "prefix");
|
key = options_get_number(s->options, "prefix");
|
||||||
cmd_send_keys_inject_key(item, item, key);
|
cmd_send_keys_inject_key(item, item, args, key);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'R')) {
|
if (args_has(args, 'R')) {
|
||||||
window_pane_reset_palette(wp);
|
colour_palette_clear(&wp->palette);
|
||||||
input_reset(wp->ictx, 1);
|
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, args, event->key);
|
||||||
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; np != 0; np--) {
|
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,
|
after = cmd_send_keys_inject_string(item, after, args,
|
||||||
i);
|
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",
|
.name = "set-buffer",
|
||||||
.alias = "setb",
|
.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] "
|
.usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
|
||||||
CMD_TARGET_CLIENT_USAGE " data",
|
CMD_TARGET_CLIENT_USAGE " data",
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ const struct cmd_entry cmd_delete_buffer_entry = {
|
|||||||
.name = "delete-buffer",
|
.name = "delete-buffer",
|
||||||
.alias = "deleteb",
|
.alias = "deleteb",
|
||||||
|
|
||||||
.args = { "b:", 0, 0 },
|
.args = { "b:", 0, 0, NULL },
|
||||||
.usage = CMD_BUFFER_USAGE,
|
.usage = CMD_BUFFER_USAGE,
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.flags = CMD_AFTERHOOK,
|
||||||
@@ -69,8 +69,13 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
pb = paste_get_name(bufname);
|
pb = paste_get_name(bufname);
|
||||||
|
|
||||||
if (cmd_get_entry(self) == &cmd_delete_buffer_entry) {
|
if (cmd_get_entry(self) == &cmd_delete_buffer_entry) {
|
||||||
if (pb == NULL)
|
if (pb == NULL) {
|
||||||
|
if (bufname != NULL) {
|
||||||
|
cmdq_error(item, "unknown buffer: %s", bufname);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
pb = paste_get_top(&bufname);
|
pb = paste_get_top(&bufname);
|
||||||
|
}
|
||||||
if (pb == NULL) {
|
if (pb == NULL) {
|
||||||
cmdq_error(item, "no buffer");
|
cmdq_error(item, "no buffer");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -80,8 +85,13 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (args_has(args, 'n')) {
|
if (args_has(args, 'n')) {
|
||||||
if (pb == NULL)
|
if (pb == NULL) {
|
||||||
|
if (bufname != NULL) {
|
||||||
|
cmdq_error(item, "unknown buffer: %s", bufname);
|
||||||
|
return (CMD_RETURN_ERROR);
|
||||||
|
}
|
||||||
pb = paste_get_top(&bufname);
|
pb = paste_get_top(&bufname);
|
||||||
|
}
|
||||||
if (pb == NULL) {
|
if (pb == NULL) {
|
||||||
cmdq_error(item, "no buffer");
|
cmdq_error(item, "no buffer");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -94,11 +104,11 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 1) {
|
if (args_count(args) != 1) {
|
||||||
cmdq_error(item, "no data specified");
|
cmdq_error(item, "no data specified");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if ((newsize = strlen(args->argv[0])) == 0)
|
if ((newsize = strlen(args_string(args, 0))) == 0)
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
bufsize = 0;
|
bufsize = 0;
|
||||||
@@ -111,7 +121,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bufdata = xrealloc(bufdata, bufsize + newsize);
|
bufdata = xrealloc(bufdata, bufsize + newsize);
|
||||||
memcpy(bufdata + bufsize, args->argv[0], newsize);
|
memcpy(bufdata + bufsize, args_string(args, 0), newsize);
|
||||||
bufsize += newsize;
|
bufsize += newsize;
|
||||||
|
|
||||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
||||||
@@ -121,7 +131,7 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if (args_has(args, 'w') && tc != NULL)
|
if (args_has(args, 'w') && tc != NULL)
|
||||||
tty_set_selection(&tc->tty, bufdata, bufsize);
|
tty_set_selection(&tc->tty, "", bufdata, bufsize);
|
||||||
|
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_set_environment_entry = {
|
|||||||
.name = "set-environment",
|
.name = "set-environment",
|
||||||
.alias = "setenv",
|
.alias = "setenv",
|
||||||
|
|
||||||
.args = { "Fhgrt:u", 1, 2 },
|
.args = { "Fhgrt:u", 1, 2, NULL },
|
||||||
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
.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 args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *target = cmdq_get_target(item);
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
const char *name, *value, *tflag;
|
const char *name = args_string(args, 0), *value;
|
||||||
char *expand = NULL;
|
const char *tflag;
|
||||||
|
char *expanded = NULL;
|
||||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
||||||
|
|
||||||
name = args->argv[0];
|
|
||||||
if (*name == '\0') {
|
if (*name == '\0') {
|
||||||
cmdq_error(item, "empty variable name");
|
cmdq_error(item, "empty variable name");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -63,13 +63,14 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc < 2)
|
if (args_count(args) < 2)
|
||||||
value = NULL;
|
value = NULL;
|
||||||
else if (args_has(args, 'F'))
|
|
||||||
value = expand = format_single_from_target(item, args->argv[1]);
|
|
||||||
else
|
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'))
|
if (args_has(args, 'g'))
|
||||||
env = global_environ;
|
env = global_environ;
|
||||||
else {
|
else {
|
||||||
@@ -113,6 +114,6 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
free(expand);
|
free(expanded);
|
||||||
return (retval);
|
return (retval);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,13 +27,16 @@
|
|||||||
* Set an option.
|
* 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 = {
|
const struct cmd_entry cmd_set_option_entry = {
|
||||||
.name = "set-option",
|
.name = "set-option",
|
||||||
.alias = "set",
|
.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]",
|
.usage = "[-aFgopqsuUw] " CMD_TARGET_PANE_USAGE " option [value]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.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",
|
.name = "set-window-option",
|
||||||
.alias = "setw",
|
.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]",
|
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||||
@@ -59,7 +62,7 @@ const struct cmd_entry cmd_set_hook_entry = {
|
|||||||
.name = "set-hook",
|
.name = "set-hook",
|
||||||
.alias = NULL,
|
.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]",
|
.usage = "[-agpRuw] " CMD_TARGET_PANE_USAGE " hook [command]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.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
|
.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
|
static enum cmd_retval
|
||||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
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 window_pane *loop;
|
||||||
struct options *oo;
|
struct options *oo;
|
||||||
struct options_entry *parent, *o, *po;
|
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 window, idx, already, error, ambiguous;
|
||||||
int scope;
|
int scope;
|
||||||
|
|
||||||
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
|
window = (cmd_get_entry(self) == &cmd_set_window_option_entry);
|
||||||
|
|
||||||
/* Expand argument. */
|
/* 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 set-hook -R, fire the hook straight away. */
|
||||||
if (cmd_get_entry(self) == &cmd_set_hook_entry && args_has(args, 'R')) {
|
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);
|
cmdq_error(item, "invalid option: %s", argument);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if (args->argc < 2)
|
if (args_count(args) < 2)
|
||||||
value = NULL;
|
value = NULL;
|
||||||
else if (args_has(args, 'F'))
|
|
||||||
value = format_single_from_target(item, args->argv[1]);
|
|
||||||
else
|
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 .*/
|
/* Get the scope and table for the option .*/
|
||||||
scope = options_scope_from_name(args, window, name, target, &oo,
|
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:
|
out:
|
||||||
free(argument);
|
free(argument);
|
||||||
free(value);
|
free(expanded);
|
||||||
free(name);
|
free(name);
|
||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
free(argument);
|
free(argument);
|
||||||
free(value);
|
free(expanded);
|
||||||
free(name);
|
free(name);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_environment_entry = {
|
|||||||
.name = "show-environment",
|
.name = "show-environment",
|
||||||
.alias = "showenv",
|
.alias = "showenv",
|
||||||
|
|
||||||
.args = { "hgst:", 0, 1 },
|
.args = { "hgst:", 0, 1, NULL },
|
||||||
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]",
|
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
.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 cmd_find_state *target = cmdq_get_target(item);
|
||||||
struct environ *env;
|
struct environ *env;
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
const char *tflag;
|
const char *tflag, *name = args_string(args, 0);
|
||||||
|
|
||||||
if ((tflag = args_get(args, 't')) != NULL) {
|
if ((tflag = args_get(args, 't')) != NULL) {
|
||||||
if (target->s == NULL) {
|
if (target->s == NULL) {
|
||||||
@@ -124,10 +124,10 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
env = target->s->environ;
|
env = target->s->environ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 0) {
|
if (name != NULL) {
|
||||||
envent = environ_find(env, args->argv[0]);
|
envent = environ_find(env, name);
|
||||||
if (envent == NULL) {
|
if (envent == NULL) {
|
||||||
cmdq_error(item, "unknown variable: %s", args->argv[0]);
|
cmdq_error(item, "unknown variable: %s", name);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
cmd_show_environment_print(self, item, envent);
|
cmd_show_environment_print(self, item, envent);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_messages_entry = {
|
|||||||
.name = "show-messages",
|
.name = "show-messages",
|
||||||
.alias = "showmsgs",
|
.alias = "showmsgs",
|
||||||
|
|
||||||
.args = { "JTt:", 0, 0 },
|
.args = { "JTt:", 0, 0, NULL },
|
||||||
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_show_options_entry = {
|
|||||||
.name = "show-options",
|
.name = "show-options",
|
||||||
.alias = "show",
|
.alias = "show",
|
||||||
|
|
||||||
.args = { "AgHpqst:vw", 0, 1 },
|
.args = { "AgHpqst:vw", 0, 1, NULL },
|
||||||
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",
|
.usage = "[-AgHpqsvw] " CMD_TARGET_PANE_USAGE " [option]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.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",
|
.name = "show-window-options",
|
||||||
.alias = "showw",
|
.alias = "showw",
|
||||||
|
|
||||||
.args = { "gvt:", 0, 1 },
|
.args = { "gvt:", 0, 1, NULL },
|
||||||
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||||
@@ -64,7 +64,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
|||||||
.name = "show-hooks",
|
.name = "show-hooks",
|
||||||
.alias = NULL,
|
.alias = NULL,
|
||||||
|
|
||||||
.args = { "gpt:w", 0, 1 },
|
.args = { "gpt:w", 0, 1, NULL },
|
||||||
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
||||||
|
|
||||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
.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);
|
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,
|
scope = options_scope_from_flags(args, window, target, &oo,
|
||||||
&cause);
|
&cause);
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
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));
|
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);
|
name = options_match(argument, &idx, &ambiguous);
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q'))
|
||||||
goto fail;
|
goto out;
|
||||||
if (ambiguous)
|
if (ambiguous)
|
||||||
cmdq_error(item, "ambiguous option: %s", argument);
|
cmdq_error(item, "ambiguous option: %s", argument);
|
||||||
else
|
else
|
||||||
@@ -113,7 +113,7 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
&cause);
|
&cause);
|
||||||
if (scope == OPTIONS_TABLE_NONE) {
|
if (scope == OPTIONS_TABLE_NONE) {
|
||||||
if (args_has(args, 'q'))
|
if (args_has(args, 'q'))
|
||||||
goto fail;
|
goto out;
|
||||||
cmdq_error(item, "%s", cause);
|
cmdq_error(item, "%s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
goto fail;
|
goto fail;
|
||||||
@@ -126,7 +126,14 @@ cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
parent = 0;
|
parent = 0;
|
||||||
if (o != NULL)
|
if (o != NULL)
|
||||||
cmd_show_options_print(self, item, o, idx, parent);
|
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(name);
|
||||||
free(argument);
|
free(argument);
|
||||||
return (CMD_RETURN_NORMAL);
|
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,8 +35,10 @@ const struct cmd_entry cmd_source_file_entry = {
|
|||||||
.name = "source-file",
|
.name = "source-file",
|
||||||
.alias = "source",
|
.alias = "source",
|
||||||
|
|
||||||
.args = { "Fnqv", 1, -1 },
|
.args = { "t:Fnqv", 1, -1, NULL },
|
||||||
.usage = "[-Fnqv] path ...",
|
.usage = "[-Fnqv] " CMD_TARGET_PANE_USAGE " path ...",
|
||||||
|
|
||||||
|
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||||
|
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
.exec = cmd_source_file_exec
|
.exec = cmd_source_file_exec
|
||||||
@@ -65,14 +67,19 @@ static void
|
|||||||
cmd_source_file_complete(struct client *c, struct cmd_source_file_data *cdata)
|
cmd_source_file_complete(struct client *c, struct cmd_source_file_data *cdata)
|
||||||
{
|
{
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
if (cfg_finished) {
|
if (cfg_finished) {
|
||||||
if (cdata->retval == CMD_RETURN_ERROR && c->session == NULL)
|
if (cdata->retval == CMD_RETURN_ERROR &&
|
||||||
|
c != NULL &&
|
||||||
|
c->session == NULL)
|
||||||
c->retval = 1;
|
c->retval = 1;
|
||||||
new_item = cmdq_get_callback(cmd_source_file_complete_cb, NULL);
|
new_item = cmdq_get_callback(cmd_source_file_complete_cb, NULL);
|
||||||
cmdq_insert_after(cdata->after, new_item);
|
cmdq_insert_after(cdata->after, new_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < cdata->nfiles; i++)
|
||||||
|
free(cdata->files[i]);
|
||||||
free(cdata->files);
|
free(cdata->files);
|
||||||
free(cdata);
|
free(cdata);
|
||||||
}
|
}
|
||||||
@@ -87,6 +94,7 @@ cmd_source_file_done(struct client *c, const char *path, int error,
|
|||||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
size_t bsize = EVBUFFER_LENGTH(buffer);
|
||||||
u_int n;
|
u_int n;
|
||||||
struct cmdq_item *new_item;
|
struct cmdq_item *new_item;
|
||||||
|
struct cmd_find_state *target = cmdq_get_target(item);
|
||||||
|
|
||||||
if (!closed)
|
if (!closed)
|
||||||
return;
|
return;
|
||||||
@@ -95,7 +103,7 @@ cmd_source_file_done(struct client *c, const char *path, int error,
|
|||||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
cmdq_error(item, "%s: %s", path, strerror(error));
|
||||||
else if (bsize != 0) {
|
else if (bsize != 0) {
|
||||||
if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after,
|
if (load_cfg_from_buffer(bdata, bsize, path, c, cdata->after,
|
||||||
cdata->flags, &new_item) < 0)
|
target, cdata->flags, &new_item) < 0)
|
||||||
cdata->retval = CMD_RETURN_ERROR;
|
cdata->retval = CMD_RETURN_ERROR;
|
||||||
else if (new_item != NULL)
|
else if (new_item != NULL)
|
||||||
cdata->after = new_item;
|
cdata->after = new_item;
|
||||||
@@ -126,11 +134,11 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct cmd_source_file_data *cdata;
|
struct cmd_source_file_data *cdata;
|
||||||
struct client *c = cmdq_get_client(item);
|
struct client *c = cmdq_get_client(item);
|
||||||
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
enum cmd_retval retval = CMD_RETURN_NORMAL;
|
||||||
char *pattern, *cwd, *expand = NULL;
|
char *pattern, *cwd, *expanded = NULL;
|
||||||
const char *path, *error;
|
const char *path, *error;
|
||||||
glob_t g;
|
glob_t g;
|
||||||
int i, result;
|
int result;
|
||||||
u_int j;
|
u_int i, j;
|
||||||
|
|
||||||
cdata = xcalloc(1, sizeof *cdata);
|
cdata = xcalloc(1, sizeof *cdata);
|
||||||
cdata->item = item;
|
cdata->item = item;
|
||||||
@@ -144,13 +152,13 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
|
|
||||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
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')) {
|
if (args_has(args, 'F')) {
|
||||||
free(expand);
|
free(expanded);
|
||||||
expand = format_single_from_target(item, args->argv[i]);
|
expanded = format_single_from_target(item, path);
|
||||||
path = expand;
|
path = expanded;
|
||||||
} else
|
}
|
||||||
path = args->argv[i];
|
|
||||||
if (strcmp(path, "-") == 0) {
|
if (strcmp(path, "-") == 0) {
|
||||||
cmd_source_file_add(cdata, "-");
|
cmd_source_file_add(cdata, "-");
|
||||||
continue;
|
continue;
|
||||||
@@ -174,15 +182,17 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmdq_error(item, "%s: %s", path, error);
|
cmdq_error(item, "%s: %s", path, error);
|
||||||
retval = CMD_RETURN_ERROR;
|
retval = CMD_RETURN_ERROR;
|
||||||
}
|
}
|
||||||
|
globfree(&g);
|
||||||
free(pattern);
|
free(pattern);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
free(expand);
|
|
||||||
free(pattern);
|
free(pattern);
|
||||||
|
|
||||||
for (j = 0; j < g.gl_pathc; j++)
|
for (j = 0; j < g.gl_pathc; j++)
|
||||||
cmd_source_file_add(cdata, g.gl_pathv[j]);
|
cmd_source_file_add(cdata, g.gl_pathv[j]);
|
||||||
|
globfree(&g);
|
||||||
}
|
}
|
||||||
|
free(expanded);
|
||||||
|
|
||||||
cdata->after = item;
|
cdata->after = item;
|
||||||
cdata->retval = retval;
|
cdata->retval = retval;
|
||||||
|
|||||||
@@ -39,9 +39,10 @@ const struct cmd_entry cmd_split_window_entry = {
|
|||||||
.name = "split-window",
|
.name = "split-window",
|
||||||
.alias = "splitw",
|
.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] "
|
.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 },
|
.target = { 't', CMD_FIND_PANE, 0 },
|
||||||
|
|
||||||
@@ -55,70 +56,65 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
struct cmd_find_state *current = cmdq_get_current(item);
|
struct cmd_find_state *current = cmdq_get_current(item);
|
||||||
struct cmd_find_state *target = cmdq_get_target(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 client *tc = cmdq_get_target_client(item);
|
||||||
struct session *s = target->s;
|
struct session *s = target->s;
|
||||||
struct winlink *wl = target->wl;
|
struct winlink *wl = target->wl;
|
||||||
|
struct window *w = wl->window;
|
||||||
struct window_pane *wp = target->wp, *new_wp;
|
struct window_pane *wp = target->wp, *new_wp;
|
||||||
enum layout_type type;
|
enum layout_type type;
|
||||||
struct layout_cell *lc;
|
struct layout_cell *lc;
|
||||||
struct cmd_find_state fs;
|
struct cmd_find_state fs;
|
||||||
int size, percentage, flags, input;
|
int size, flags, input;
|
||||||
const char *template, *add, *errstr, *p;
|
const char *template;
|
||||||
char *cause, *cp, *copy;
|
char *cause = NULL, *cp;
|
||||||
size_t plen;
|
struct args_value *av;
|
||||||
struct args_value *value;
|
u_int count = args_count(args), curval = 0;
|
||||||
|
|
||||||
|
type = LAYOUT_TOPBOTTOM;
|
||||||
if (args_has(args, 'h'))
|
if (args_has(args, 'h'))
|
||||||
type = LAYOUT_LEFTRIGHT;
|
type = LAYOUT_LEFTRIGHT;
|
||||||
else
|
|
||||||
type = LAYOUT_TOPBOTTOM;
|
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
|
||||||
if ((p = args_get(args, 'l')) != NULL) {
|
if (args_has(args, 'l') || args_has(args, 'p')) {
|
||||||
plen = strlen(p);
|
if (args_has(args, 'f')) {
|
||||||
if (p[plen - 1] == '%') {
|
|
||||||
copy = xstrdup(p);
|
|
||||||
copy[plen - 1] = '\0';
|
|
||||||
percentage = strtonum(copy, 0, INT_MAX, &errstr);
|
|
||||||
free(copy);
|
|
||||||
if (errstr != NULL) {
|
|
||||||
cmdq_error(item, "percentage %s", errstr);
|
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
size = (wp->sy * percentage) / 100;
|
curval = w->sy;
|
||||||
else
|
else
|
||||||
size = (wp->sx * percentage) / 100;
|
curval = w->sx;
|
||||||
} else {
|
} else {
|
||||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
if (type == LAYOUT_TOPBOTTOM)
|
||||||
if (cause != NULL) {
|
curval = wp->sy;
|
||||||
cmdq_error(item, "lines %s", cause);
|
else
|
||||||
free(cause);
|
curval = wp->sx;
|
||||||
return (CMD_RETURN_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = -1;
|
||||||
|
if (args_has(args, 'l')) {
|
||||||
|
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
||||||
|
item, &cause);
|
||||||
} else if (args_has(args, 'p')) {
|
} else if (args_has(args, 'p')) {
|
||||||
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
||||||
if (cause != NULL) {
|
&cause);
|
||||||
cmdq_error(item, "create pane failed: -p %s", cause);
|
if (cause == NULL)
|
||||||
free(cause);
|
size = curval * size / 100;
|
||||||
return (CMD_RETURN_ERROR);
|
}
|
||||||
}
|
if (cause != NULL) {
|
||||||
if (type == LAYOUT_TOPBOTTOM)
|
cmdq_error(item, "size %s", cause);
|
||||||
size = (wp->sy * percentage) / 100;
|
free(cause);
|
||||||
else
|
return (CMD_RETURN_ERROR);
|
||||||
size = (wp->sx * percentage) / 100;
|
}
|
||||||
} else
|
|
||||||
size = -1;
|
|
||||||
|
|
||||||
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
|
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;
|
flags = 0;
|
||||||
if (args_has(args, 'b'))
|
if (args_has(args, 'b'))
|
||||||
flags |= SPAWN_BEFORE;
|
flags |= SPAWN_BEFORE;
|
||||||
if (args_has(args, 'f'))
|
if (args_has(args, 'f'))
|
||||||
flags |= SPAWN_FULLSIZE;
|
flags |= SPAWN_FULLSIZE;
|
||||||
if (input || (args->argc == 1 && *args->argv[0] == '\0'))
|
if (input || (count == 1 && *args_string(args, 0) == '\0'))
|
||||||
flags |= SPAWN_EMPTY;
|
flags |= SPAWN_EMPTY;
|
||||||
|
|
||||||
lc = layout_split_pane(wp, type, size, flags);
|
lc = layout_split_pane(wp, type, size, flags);
|
||||||
@@ -127,7 +123,6 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&sc, 0, sizeof sc);
|
|
||||||
sc.item = item;
|
sc.item = item;
|
||||||
sc.s = s;
|
sc.s = s;
|
||||||
sc.wl = wl;
|
sc.wl = wl;
|
||||||
@@ -135,15 +130,13 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
sc.wp0 = wp;
|
sc.wp0 = wp;
|
||||||
sc.lc = lc;
|
sc.lc = lc;
|
||||||
|
|
||||||
sc.name = NULL;
|
args_to_vector(args, &sc.argc, &sc.argv);
|
||||||
sc.argc = args->argc;
|
|
||||||
sc.argv = args->argv;
|
|
||||||
sc.environ = environ_create();
|
sc.environ = environ_create();
|
||||||
|
|
||||||
add = args_first_value(args, 'e', &value);
|
av = args_first_value(args, 'e');
|
||||||
while (add != NULL) {
|
while (av != NULL) {
|
||||||
environ_put(sc.environ, add, 0);
|
environ_put(sc.environ, av->string, 0);
|
||||||
add = args_next_value(&value);
|
av = args_next_value(av);
|
||||||
}
|
}
|
||||||
|
|
||||||
sc.idx = -1;
|
sc.idx = -1;
|
||||||
@@ -158,15 +151,27 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if ((new_wp = spawn_pane(&sc, &cause)) == NULL) {
|
if ((new_wp = spawn_pane(&sc, &cause)) == NULL) {
|
||||||
cmdq_error(item, "create pane failed: %s", cause);
|
cmdq_error(item, "create pane failed: %s", cause);
|
||||||
free(cause);
|
free(cause);
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
|
environ_free(sc.environ);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
if (input && window_pane_start_input(new_wp, item, &cause) != 0) {
|
if (input) {
|
||||||
server_client_remove_pane(new_wp);
|
switch (window_pane_start_input(new_wp, item, &cause)) {
|
||||||
layout_close_pane(new_wp);
|
case -1:
|
||||||
window_remove_pane(wp->window, new_wp);
|
server_client_remove_pane(new_wp);
|
||||||
cmdq_error(item, "%s", cause);
|
layout_close_pane(new_wp);
|
||||||
free(cause);
|
window_remove_pane(wp->window, new_wp);
|
||||||
return (CMD_RETURN_ERROR);
|
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'))
|
if (!args_has(args, 'd'))
|
||||||
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
|
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
|
||||||
@@ -185,6 +190,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
||||||
cmdq_insert_hook(s, item, &fs, "after-split-window");
|
cmdq_insert_hook(s, item, &fs, "after-split-window");
|
||||||
|
|
||||||
|
if (sc.argv != NULL)
|
||||||
|
cmd_free_argv(sc.argc, sc.argv);
|
||||||
environ_free(sc.environ);
|
environ_free(sc.environ);
|
||||||
if (input)
|
if (input)
|
||||||
return (CMD_RETURN_WAIT);
|
return (CMD_RETURN_WAIT);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
|||||||
.name = "swap-pane",
|
.name = "swap-pane",
|
||||||
.alias = "swapp",
|
.alias = "swapp",
|
||||||
|
|
||||||
.args = { "dDs:t:UZ", 0, 0 },
|
.args = { "dDs:t:UZ", 0, 0, NULL },
|
||||||
.usage = "[-dDUZ] " CMD_SRCDST_PANE_USAGE,
|
.usage = "[-dDUZ] " CMD_SRCDST_PANE_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||||
@@ -128,13 +128,16 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
window_set_active_pane(dst_w, src_wp, 1);
|
window_set_active_pane(dst_w, src_wp, 1);
|
||||||
}
|
}
|
||||||
if (src_w != dst_w) {
|
if (src_w != dst_w) {
|
||||||
if (src_w->last == src_wp)
|
window_pane_stack_remove(&src_w->last_panes, src_wp);
|
||||||
src_w->last = NULL;
|
window_pane_stack_remove(&dst_w->last_panes, dst_wp);
|
||||||
if (dst_w->last == dst_wp)
|
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
||||||
dst_w->last = NULL;
|
colour_palette_from_option(&dst_wp->palette, dst_wp->options);
|
||||||
}
|
}
|
||||||
server_redraw_window(src_w);
|
server_redraw_window(src_w);
|
||||||
server_redraw_window(dst_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:
|
out:
|
||||||
if (window_pop_zoom(src_w))
|
if (window_pop_zoom(src_w))
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_swap_window_entry = {
|
|||||||
.name = "swap-window",
|
.name = "swap-window",
|
||||||
.alias = "swapw",
|
.alias = "swapw",
|
||||||
|
|
||||||
.args = { "ds:t:", 0, 0 },
|
.args = { "ds:t:", 0, 0, NULL },
|
||||||
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
|
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||||
|
|
||||||
.source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
|
.source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_switch_client_entry = {
|
|||||||
.name = "switch-client",
|
.name = "switch-client",
|
||||||
.alias = "switchc",
|
.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] "
|
.usage = "[-ElnprZ] [-c target-client] [-t target-session] "
|
||||||
"[-T key-table]",
|
"[-T key-table]",
|
||||||
|
|
||||||
@@ -134,23 +134,9 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
if (!args_has(args, 'E'))
|
if (!args_has(args, 'E'))
|
||||||
environ_update(s->options, tc->environ, s->environ);
|
environ_update(s->options, tc->environ, s->environ);
|
||||||
|
|
||||||
if (tc->session != NULL && tc->session != s)
|
server_client_set_session(tc, s);
|
||||||
tc->last_session = tc->session;
|
|
||||||
tc->session = s;
|
|
||||||
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
if (~cmdq_get_flags(item) & CMDQ_STATE_REPEAT)
|
||||||
server_client_set_key_table(tc, NULL);
|
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);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_unbind_key_entry = {
|
|||||||
.name = "unbind-key",
|
.name = "unbind-key",
|
||||||
.alias = "unbind",
|
.alias = "unbind",
|
||||||
|
|
||||||
.args = { "anqT:", 0, 1 },
|
.args = { "anqT:", 0, 1, NULL },
|
||||||
.usage = "[-anq] [-T key-table] key",
|
.usage = "[-anq] [-T key-table] key",
|
||||||
|
|
||||||
.flags = CMD_AFTERHOOK,
|
.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);
|
struct args *args = cmd_get_args(self);
|
||||||
key_code key;
|
key_code key;
|
||||||
const char *tablename;
|
const char *tablename, *keystr = args_string(args, 0);
|
||||||
int quiet = args_has(args, 'q');
|
int quiet = args_has(args, 'q');
|
||||||
|
|
||||||
if (args_has(args, 'a')) {
|
if (args_has(args, 'a')) {
|
||||||
if (args->argc != 0) {
|
if (keystr != NULL) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
cmdq_error(item, "key given with -a");
|
cmdq_error(item, "key given with -a");
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
@@ -73,16 +73,16 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
|
|||||||
return (CMD_RETURN_NORMAL);
|
return (CMD_RETURN_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->argc != 1) {
|
if (keystr == NULL) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
cmdq_error(item, "missing key");
|
cmdq_error(item, "missing key");
|
||||||
return (CMD_RETURN_ERROR);
|
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 (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
cmdq_error(item, "unknown key: %s", keystr);
|
||||||
return (CMD_RETURN_ERROR);
|
return (CMD_RETURN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_wait_for_entry = {
|
|||||||
.name = "wait-for",
|
.name = "wait-for",
|
||||||
.alias = "wait",
|
.alias = "wait",
|
||||||
|
|
||||||
.args = { "LSU", 1, 1 },
|
.args = { "LSU", 1, 1, NULL },
|
||||||
.usage = "[-L|-S|-U] channel",
|
.usage = "[-L|-S|-U] channel",
|
||||||
|
|
||||||
.flags = 0,
|
.flags = 0,
|
||||||
@@ -121,11 +121,11 @@ static enum cmd_retval
|
|||||||
cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item)
|
cmd_wait_for_exec(struct cmd *self, struct cmdq_item *item)
|
||||||
{
|
{
|
||||||
struct args *args = cmd_get_args(self);
|
struct args *args = cmd_get_args(self);
|
||||||
const char *name = args->argv[0];
|
const char *name = args_string(args, 0);
|
||||||
struct wait_channel *wc, wc0;
|
struct wait_channel *wc, find;
|
||||||
|
|
||||||
wc0.name = name;
|
find.name = name;
|
||||||
wc = RB_FIND(wait_channels, &wait_channels, &wc0);
|
wc = RB_FIND(wait_channels, &wait_channels, &find);
|
||||||
|
|
||||||
if (args_has(args, 'S'))
|
if (args_has(args, 'S'))
|
||||||
return (cmd_wait_for_signal(item, name, wc));
|
return (cmd_wait_for_signal(item, name, wc));
|
||||||
|
|||||||
129
cmd.c
129
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_client_entry;
|
||||||
extern const struct cmd_entry cmd_choose_tree_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_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_clock_mode_entry;
|
||||||
extern const struct cmd_entry cmd_command_prompt_entry;
|
extern const struct cmd_entry cmd_command_prompt_entry;
|
||||||
extern const struct cmd_entry cmd_confirm_before_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_select_window_entry;
|
||||||
extern const struct cmd_entry cmd_send_keys_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_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_buffer_entry;
|
||||||
extern const struct cmd_entry cmd_set_environment_entry;
|
extern const struct cmd_entry cmd_set_environment_entry;
|
||||||
extern const struct cmd_entry cmd_set_hook_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_hooks_entry;
|
||||||
extern const struct cmd_entry cmd_show_messages_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_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_show_window_options_entry;
|
||||||
extern const struct cmd_entry cmd_source_file_entry;
|
extern const struct cmd_entry cmd_source_file_entry;
|
||||||
extern const struct cmd_entry cmd_split_window_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_client_entry,
|
||||||
&cmd_choose_tree_entry,
|
&cmd_choose_tree_entry,
|
||||||
&cmd_clear_history_entry,
|
&cmd_clear_history_entry,
|
||||||
|
&cmd_clear_prompt_history_entry,
|
||||||
&cmd_clock_mode_entry,
|
&cmd_clock_mode_entry,
|
||||||
&cmd_command_prompt_entry,
|
&cmd_command_prompt_entry,
|
||||||
&cmd_confirm_before_entry,
|
&cmd_confirm_before_entry,
|
||||||
@@ -184,6 +188,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
&cmd_select_window_entry,
|
&cmd_select_window_entry,
|
||||||
&cmd_send_keys_entry,
|
&cmd_send_keys_entry,
|
||||||
&cmd_send_prefix_entry,
|
&cmd_send_prefix_entry,
|
||||||
|
&cmd_server_access_entry,
|
||||||
&cmd_set_buffer_entry,
|
&cmd_set_buffer_entry,
|
||||||
&cmd_set_environment_entry,
|
&cmd_set_environment_entry,
|
||||||
&cmd_set_hook_entry,
|
&cmd_set_hook_entry,
|
||||||
@@ -194,6 +199,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
&cmd_show_hooks_entry,
|
&cmd_show_hooks_entry,
|
||||||
&cmd_show_messages_entry,
|
&cmd_show_messages_entry,
|
||||||
&cmd_show_options_entry,
|
&cmd_show_options_entry,
|
||||||
|
&cmd_show_prompt_history_entry,
|
||||||
&cmd_show_window_options_entry,
|
&cmd_show_window_options_entry,
|
||||||
&cmd_source_file_entry,
|
&cmd_source_file_entry,
|
||||||
&cmd_split_window_entry,
|
&cmd_split_window_entry,
|
||||||
@@ -217,10 +223,6 @@ struct cmd {
|
|||||||
char *file;
|
char *file;
|
||||||
u_int line;
|
u_int line;
|
||||||
|
|
||||||
char *alias;
|
|
||||||
int argc;
|
|
||||||
char **argv;
|
|
||||||
|
|
||||||
TAILQ_ENTRY(cmd) qentry;
|
TAILQ_ENTRY(cmd) qentry;
|
||||||
};
|
};
|
||||||
TAILQ_HEAD(cmds, cmd);
|
TAILQ_HEAD(cmds, cmd);
|
||||||
@@ -247,7 +249,7 @@ cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
|||||||
|
|
||||||
/* Prepend to an argument vector. */
|
/* Prepend to an argument vector. */
|
||||||
void
|
void
|
||||||
cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
cmd_prepend_argv(int *argc, char ***argv, const char *arg)
|
||||||
{
|
{
|
||||||
char **new_argv;
|
char **new_argv;
|
||||||
int i;
|
int i;
|
||||||
@@ -264,7 +266,7 @@ cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
|||||||
|
|
||||||
/* Append to an argument vector. */
|
/* Append to an argument vector. */
|
||||||
void
|
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 = xreallocarray(*argv, (*argc) + 1, sizeof **argv);
|
||||||
(*argv)[(*argc)++] = xstrdup(arg);
|
(*argv)[(*argc)++] = xstrdup(arg);
|
||||||
@@ -495,31 +497,32 @@ ambiguous:
|
|||||||
|
|
||||||
/* Parse a single command from an argument vector. */
|
/* Parse a single command from an argument vector. */
|
||||||
struct cmd *
|
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 struct cmd_entry *entry;
|
||||||
const char *name;
|
|
||||||
struct cmd *cmd;
|
struct cmd *cmd;
|
||||||
struct args *args;
|
struct args *args;
|
||||||
|
char *error = NULL;
|
||||||
|
|
||||||
if (argc == 0) {
|
if (count == 0 || values[0].type != ARGS_STRING) {
|
||||||
xasprintf(cause, "no command");
|
xasprintf(cause, "no command");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
name = argv[0];
|
entry = cmd_find(values[0].string, cause);
|
||||||
|
|
||||||
entry = cmd_find(name, cause);
|
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
|
||||||
|
|
||||||
args = args_parse(entry->args.template, argc, argv);
|
args = args_parse(&entry->args, values, count, &error);
|
||||||
if (args == NULL)
|
if (args == NULL && error == NULL) {
|
||||||
goto usage;
|
xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
|
||||||
if (entry->args.lower != -1 && args->argc < entry->args.lower)
|
return (NULL);
|
||||||
goto usage;
|
}
|
||||||
if (entry->args.upper != -1 && args->argc > entry->args.upper)
|
if (args == NULL) {
|
||||||
goto usage;
|
xasprintf(cause, "command %s: %s", entry->name, error);
|
||||||
|
free(error);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
cmd = xcalloc(1, sizeof *cmd);
|
cmd = xcalloc(1, sizeof *cmd);
|
||||||
cmd->entry = entry;
|
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->file = xstrdup(file);
|
||||||
cmd->line = line;
|
cmd->line = line;
|
||||||
|
|
||||||
cmd->alias = NULL;
|
|
||||||
cmd->argc = argc;
|
|
||||||
cmd->argv = cmd_copy_argv(argc, argv);
|
|
||||||
|
|
||||||
return (cmd);
|
return (cmd);
|
||||||
|
|
||||||
usage:
|
|
||||||
if (args != NULL)
|
|
||||||
args_free(args);
|
|
||||||
xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
|
|
||||||
return (NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Free a command. */
|
/* Free a command. */
|
||||||
void
|
void
|
||||||
cmd_free(struct cmd *cmd)
|
cmd_free(struct cmd *cmd)
|
||||||
{
|
{
|
||||||
free(cmd->alias);
|
|
||||||
cmd_free_argv(cmd->argc, cmd->argv);
|
|
||||||
|
|
||||||
free(cmd->file);
|
free(cmd->file);
|
||||||
|
|
||||||
args_free(cmd->args);
|
args_free(cmd->args);
|
||||||
free(cmd);
|
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. */
|
/* Get a command as a string. */
|
||||||
char *
|
char *
|
||||||
cmd_print(struct cmd *cmd)
|
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);
|
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
|
void
|
||||||
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||||
{
|
{
|
||||||
@@ -618,6 +636,37 @@ cmd_list_free(struct cmd_list *cmdlist)
|
|||||||
free(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. */
|
/* Get a command list as a string. */
|
||||||
char *
|
char *
|
||||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||||
@@ -763,10 +812,14 @@ cmd_mouse_pane(struct mouse_event *m, struct session **sp,
|
|||||||
|
|
||||||
if ((wl = cmd_mouse_window(m, sp)) == NULL)
|
if ((wl = cmd_mouse_window(m, sp)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if ((wp = window_pane_find_by_id(m->wp)) == NULL)
|
if (m->wp == -1)
|
||||||
return (NULL);
|
wp = wl->window->active;
|
||||||
if (!window_has_pane(wl->window, wp))
|
else {
|
||||||
return (NULL);
|
if ((wp = window_pane_find_by_id(m->wp)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (!window_has_pane(wl->window, wp))
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (wlp != NULL)
|
if (wlp != NULL)
|
||||||
*wlp = wl;
|
*wlp = wl;
|
||||||
|
|||||||
169
colour.c
169
colour.c
@@ -105,6 +105,21 @@ colour_split_rgb(int c, u_char *r, u_char *g, u_char *b)
|
|||||||
*b = c & 0xff;
|
*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. */
|
/* Convert colour to a string. */
|
||||||
const char *
|
const char *
|
||||||
colour_tostring(int c)
|
colour_tostring(int c)
|
||||||
@@ -113,7 +128,7 @@ colour_tostring(int c)
|
|||||||
u_char r, g, b;
|
u_char r, g, b;
|
||||||
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
return ("invalid");
|
return ("none");
|
||||||
|
|
||||||
if (c & COLOUR_FLAG_RGB) {
|
if (c & COLOUR_FLAG_RGB) {
|
||||||
colour_split_rgb(c, &r, &g, &b);
|
colour_split_rgb(c, &r, &g, &b);
|
||||||
@@ -944,3 +959,155 @@ colour_byname(const char *name)
|
|||||||
}
|
}
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Parse colour from an X11 string. */
|
||||||
|
int
|
||||||
|
colour_parseX11(const char *p)
|
||||||
|
{
|
||||||
|
double c, m, y, k = 0;
|
||||||
|
u_int r, g, b;
|
||||||
|
size_t len = strlen(p);
|
||||||
|
int colour = -1;
|
||||||
|
char *copy;
|
||||||
|
|
||||||
|
if ((len == 12 && sscanf(p, "rgb:%02x/%02x/%02x", &r, &g, &b) == 3) ||
|
||||||
|
(len == 7 && sscanf(p, "#%02x%02x%02x", &r, &g, &b) == 3) ||
|
||||||
|
sscanf(p, "%d,%d,%d", &r, &g, &b) == 3)
|
||||||
|
colour = colour_join_rgb(r, g, b);
|
||||||
|
else if ((len == 18 &&
|
||||||
|
sscanf(p, "rgb:%04x/%04x/%04x", &r, &g, &b) == 3) ||
|
||||||
|
(len == 13 && sscanf(p, "#%04x%04x%04x", &r, &g, &b) == 3))
|
||||||
|
colour = colour_join_rgb(r >> 8, g >> 8, b >> 8);
|
||||||
|
else if ((sscanf(p, "cmyk:%lf/%lf/%lf/%lf", &c, &m, &y, &k) == 4 ||
|
||||||
|
sscanf(p, "cmy:%lf/%lf/%lf", &c, &m, &y) == 3) &&
|
||||||
|
c >= 0 && c <= 1 && m >= 0 && m <= 1 &&
|
||||||
|
y >= 0 && y <= 1 && k >= 0 && k <= 1) {
|
||||||
|
colour = colour_join_rgb(
|
||||||
|
(1 - c) * (1 - k) * 255,
|
||||||
|
(1 - m) * (1 - k) * 255,
|
||||||
|
(1 - y) * (1 - k) * 255);
|
||||||
|
} else {
|
||||||
|
while (len != 0 && *p == ' ') {
|
||||||
|
p++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
while (len != 0 && p[len - 1] == ' ')
|
||||||
|
len--;
|
||||||
|
copy = xstrndup(p, len);
|
||||||
|
colour = colour_byname(copy);
|
||||||
|
free(copy);
|
||||||
|
}
|
||||||
|
log_debug("%s: %s = %s", __func__, p, colour_tostring(colour));
|
||||||
|
return (colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
24
compat.h
24
compat.h
@@ -334,6 +334,23 @@ char *strndup(const char *, size_t);
|
|||||||
void *memmem(const void *, size_t, const void *, size_t);
|
void *memmem(const void *, size_t, const void *, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_HTONLL
|
||||||
|
/* htonll.c */
|
||||||
|
#undef htonll
|
||||||
|
uint64_t htonll(uint64_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_NTOHLL
|
||||||
|
/* ntohll.c */
|
||||||
|
#undef ntohll
|
||||||
|
uint64_t ntohll(uint64_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_GETPEEREID
|
||||||
|
/* getpeereid.c */
|
||||||
|
int getpeereid(int, uid_t *, gid_t *);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_DAEMON
|
#ifndef HAVE_DAEMON
|
||||||
/* daemon.c */
|
/* daemon.c */
|
||||||
int daemon(int, int);
|
int daemon(int, int);
|
||||||
@@ -416,6 +433,13 @@ void *reallocarray(void *, size_t, size_t);
|
|||||||
void *recallocarray(void *, size_t, size_t, size_t);
|
void *recallocarray(void *, size_t, size_t, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_SYSTEMD
|
||||||
|
/* systemd.c */
|
||||||
|
int systemd_activated(void);
|
||||||
|
int systemd_create_socket(int, char **);
|
||||||
|
int systemd_move_pid_to_new_cgroup(pid_t, char **);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_UTF8PROC
|
#ifdef HAVE_UTF8PROC
|
||||||
/* utf8proc.c */
|
/* utf8proc.c */
|
||||||
int utf8proc_wcwidth(wchar_t);
|
int utf8proc_wcwidth(wchar_t);
|
||||||
|
|||||||
57
compat/getpeereid.c
Normal file
57
compat/getpeereid.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* 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>
|
||||||
|
#include <unistd.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)
|
||||||
|
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
|
||||||
|
*uid = geteuid();
|
||||||
|
*gid = getegid();
|
||||||
|
return (0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
30
compat/htonll.c
Normal file
30
compat/htonll.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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 "compat.h"
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
htonll(uint64_t v)
|
||||||
|
{
|
||||||
|
uint32_t b;
|
||||||
|
uint32_t t;
|
||||||
|
|
||||||
|
b = htonl (v & 0xffffffff);
|
||||||
|
t = htonl (v >> 32);
|
||||||
|
return ((uint64_t)b << 32 | t);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/* $OpenBSD: imsg-buffer.c,v 1.12 2019/01/20 02:50:03 bcook Exp $ */
|
/* $OpenBSD: imsg-buffer.c,v 1.18 2023/12/12 15:47:41 claudio Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
||||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -19,9 +20,11 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -29,18 +32,36 @@
|
|||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "imsg.h"
|
#include "imsg.h"
|
||||||
|
|
||||||
|
#undef htobe16
|
||||||
|
#define htobe16 htons
|
||||||
|
#undef htobe32
|
||||||
|
#define htobe32 htonl
|
||||||
|
#undef htobe64
|
||||||
|
#define htobe64 htonll
|
||||||
|
#undef be16toh
|
||||||
|
#define be16toh ntohs
|
||||||
|
#undef be32toh
|
||||||
|
#define be32toh ntohl
|
||||||
|
#undef be64toh
|
||||||
|
#define be64toh ntohll
|
||||||
|
|
||||||
static int ibuf_realloc(struct ibuf *, size_t);
|
static int ibuf_realloc(struct ibuf *, size_t);
|
||||||
static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
||||||
static void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
static void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
||||||
|
static void msgbuf_drain(struct msgbuf *, size_t);
|
||||||
|
|
||||||
struct ibuf *
|
struct ibuf *
|
||||||
ibuf_open(size_t len)
|
ibuf_open(size_t len)
|
||||||
{
|
{
|
||||||
struct ibuf *buf;
|
struct ibuf *buf;
|
||||||
|
|
||||||
|
if (len == 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
|
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if ((buf->buf = malloc(len)) == NULL) {
|
if ((buf->buf = calloc(len, 1)) == NULL) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -55,14 +76,22 @@ ibuf_dynamic(size_t len, size_t max)
|
|||||||
{
|
{
|
||||||
struct ibuf *buf;
|
struct ibuf *buf;
|
||||||
|
|
||||||
if (max < len)
|
if (max == 0 || max < len) {
|
||||||
|
errno = EINVAL;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if ((buf = ibuf_open(len)) == NULL)
|
if ((buf = calloc(1, sizeof(struct ibuf))) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
if (len > 0) {
|
||||||
if (max > 0)
|
if ((buf->buf = calloc(len, 1)) == NULL) {
|
||||||
buf->max = max;
|
free(buf);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf->size = len;
|
||||||
|
buf->max = max;
|
||||||
|
buf->fd = -1;
|
||||||
|
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
@@ -73,7 +102,7 @@ ibuf_realloc(struct ibuf *buf, size_t len)
|
|||||||
unsigned char *b;
|
unsigned char *b;
|
||||||
|
|
||||||
/* on static buffers max is eq size and so the following fails */
|
/* on static buffers max is eq size and so the following fails */
|
||||||
if (buf->wpos + len > buf->max) {
|
if (len > SIZE_MAX - buf->wpos || buf->wpos + len > buf->max) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@@ -87,23 +116,16 @@ ibuf_realloc(struct ibuf *buf, size_t len)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
ibuf_add(struct ibuf *buf, const void *data, size_t len)
|
|
||||||
{
|
|
||||||
if (buf->wpos + len > buf->size)
|
|
||||||
if (ibuf_realloc(buf, len) == -1)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
memcpy(buf->buf + buf->wpos, data, len);
|
|
||||||
buf->wpos += len;
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ibuf_reserve(struct ibuf *buf, size_t len)
|
ibuf_reserve(struct ibuf *buf, size_t len)
|
||||||
{
|
{
|
||||||
void *b;
|
void *b;
|
||||||
|
|
||||||
|
if (len > SIZE_MAX - buf->wpos || buf->max == 0) {
|
||||||
|
errno = ERANGE;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
if (buf->wpos + len > buf->size)
|
if (buf->wpos + len > buf->size)
|
||||||
if (ibuf_realloc(buf, len) == -1)
|
if (ibuf_realloc(buf, len) == -1)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@@ -113,34 +135,416 @@ ibuf_reserve(struct ibuf *buf, size_t len)
|
|||||||
return (b);
|
return (b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add(struct ibuf *buf, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
void *b;
|
||||||
|
|
||||||
|
if ((b = ibuf_reserve(buf, len)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
memcpy(b, data, len);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_ibuf(struct ibuf *buf, const struct ibuf *from)
|
||||||
|
{
|
||||||
|
return ibuf_add(buf, ibuf_data(from), ibuf_size(from));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* remove after tree is converted */
|
||||||
|
int
|
||||||
|
ibuf_add_buf(struct ibuf *buf, const struct ibuf *from)
|
||||||
|
{
|
||||||
|
return ibuf_add_ibuf(buf, from);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_n8(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
uint8_t v;
|
||||||
|
|
||||||
|
if (value > UINT8_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return ibuf_add(buf, &v, sizeof(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_n16(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
uint16_t v;
|
||||||
|
|
||||||
|
if (value > UINT16_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = htobe16(value);
|
||||||
|
return ibuf_add(buf, &v, sizeof(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_n32(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
uint32_t v;
|
||||||
|
|
||||||
|
if (value > UINT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = htobe32(value);
|
||||||
|
return ibuf_add(buf, &v, sizeof(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_n64(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
value = htobe64(value);
|
||||||
|
return ibuf_add(buf, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_h16(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
uint16_t v;
|
||||||
|
|
||||||
|
if (value > UINT16_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return ibuf_add(buf, &v, sizeof(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_h32(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
uint32_t v;
|
||||||
|
|
||||||
|
if (value > UINT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return ibuf_add(buf, &v, sizeof(v));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_h64(struct ibuf *buf, uint64_t value)
|
||||||
|
{
|
||||||
|
return ibuf_add(buf, &value, sizeof(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_add_zero(struct ibuf *buf, size_t len)
|
||||||
|
{
|
||||||
|
void *b;
|
||||||
|
|
||||||
|
if ((b = ibuf_reserve(buf, len)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
memset(b, 0, len);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
ibuf_seek(struct ibuf *buf, size_t pos, size_t len)
|
ibuf_seek(struct ibuf *buf, size_t pos, size_t len)
|
||||||
{
|
{
|
||||||
/* only allowed to seek in already written parts */
|
/* only allow seeking between rpos and wpos */
|
||||||
if (pos + len > buf->wpos)
|
if (ibuf_size(buf) < pos || SIZE_MAX - pos < len ||
|
||||||
|
ibuf_size(buf) < pos + len) {
|
||||||
|
errno = ERANGE;
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
return (buf->buf + pos);
|
return (buf->buf + buf->rpos + pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set(struct ibuf *buf, size_t pos, const void *data, size_t len)
|
||||||
|
{
|
||||||
|
void *b;
|
||||||
|
|
||||||
|
if ((b = ibuf_seek(buf, pos, len)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
memcpy(b, data, len);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_n8(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
uint8_t v;
|
||||||
|
|
||||||
|
if (value > UINT8_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return (ibuf_set(buf, pos, &v, sizeof(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_n16(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
uint16_t v;
|
||||||
|
|
||||||
|
if (value > UINT16_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = htobe16(value);
|
||||||
|
return (ibuf_set(buf, pos, &v, sizeof(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_n32(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
uint32_t v;
|
||||||
|
|
||||||
|
if (value > UINT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = htobe32(value);
|
||||||
|
return (ibuf_set(buf, pos, &v, sizeof(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_n64(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
value = htobe64(value);
|
||||||
|
return (ibuf_set(buf, pos, &value, sizeof(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_h16(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
uint16_t v;
|
||||||
|
|
||||||
|
if (value > UINT16_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return (ibuf_set(buf, pos, &v, sizeof(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_h32(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
uint32_t v;
|
||||||
|
|
||||||
|
if (value > UINT32_MAX) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
v = value;
|
||||||
|
return (ibuf_set(buf, pos, &v, sizeof(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_set_h64(struct ibuf *buf, size_t pos, uint64_t value)
|
||||||
|
{
|
||||||
|
return (ibuf_set(buf, pos, &value, sizeof(value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void *
|
||||||
|
ibuf_data(const struct ibuf *buf)
|
||||||
|
{
|
||||||
|
return (buf->buf + buf->rpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ibuf_size(struct ibuf *buf)
|
ibuf_size(const struct ibuf *buf)
|
||||||
{
|
{
|
||||||
return (buf->wpos);
|
return (buf->wpos - buf->rpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
ibuf_left(struct ibuf *buf)
|
ibuf_left(const struct ibuf *buf)
|
||||||
{
|
{
|
||||||
|
if (buf->max == 0)
|
||||||
|
return (0);
|
||||||
return (buf->max - buf->wpos);
|
return (buf->max - buf->wpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_truncate(struct ibuf *buf, size_t len)
|
||||||
|
{
|
||||||
|
if (ibuf_size(buf) >= len) {
|
||||||
|
buf->wpos = buf->rpos + len;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (buf->max == 0) {
|
||||||
|
/* only allow to truncate down */
|
||||||
|
errno = ERANGE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return ibuf_add_zero(buf, len - ibuf_size(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_rewind(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
buf->rpos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf)
|
ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
{
|
{
|
||||||
ibuf_enqueue(msgbuf, buf);
|
ibuf_enqueue(msgbuf, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_from_buffer(struct ibuf *buf, void *data, size_t len)
|
||||||
|
{
|
||||||
|
memset(buf, 0, sizeof(*buf));
|
||||||
|
buf->buf = data;
|
||||||
|
buf->size = buf->wpos = len;
|
||||||
|
buf->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_from_ibuf(struct ibuf *buf, const struct ibuf *from)
|
||||||
|
{
|
||||||
|
ibuf_from_buffer(buf, ibuf_data(from), ibuf_size(from));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get(struct ibuf *buf, void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (ibuf_size(buf) < len) {
|
||||||
|
errno = EBADMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(data, ibuf_data(buf), len);
|
||||||
|
buf->rpos += len;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_ibuf(struct ibuf *buf, size_t len, struct ibuf *new)
|
||||||
|
{
|
||||||
|
if (ibuf_size(buf) < len) {
|
||||||
|
errno = EBADMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ibuf_from_buffer(new, ibuf_data(buf), len);
|
||||||
|
buf->rpos += len;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_n8(struct ibuf *buf, uint8_t *value)
|
||||||
|
{
|
||||||
|
return ibuf_get(buf, value, sizeof(*value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_n16(struct ibuf *buf, uint16_t *value)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = ibuf_get(buf, value, sizeof(*value));
|
||||||
|
*value = be16toh(*value);
|
||||||
|
return (rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_n32(struct ibuf *buf, uint32_t *value)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = ibuf_get(buf, value, sizeof(*value));
|
||||||
|
*value = be32toh(*value);
|
||||||
|
return (rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_n64(struct ibuf *buf, uint64_t *value)
|
||||||
|
{
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
rv = ibuf_get(buf, value, sizeof(*value));
|
||||||
|
*value = be64toh(*value);
|
||||||
|
return (rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_h16(struct ibuf *buf, uint16_t *value)
|
||||||
|
{
|
||||||
|
return ibuf_get(buf, value, sizeof(*value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_h32(struct ibuf *buf, uint32_t *value)
|
||||||
|
{
|
||||||
|
return ibuf_get(buf, value, sizeof(*value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_get_h64(struct ibuf *buf, uint64_t *value)
|
||||||
|
{
|
||||||
|
return ibuf_get(buf, value, sizeof(*value));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_skip(struct ibuf *buf, size_t len)
|
||||||
|
{
|
||||||
|
if (ibuf_size(buf) < len) {
|
||||||
|
errno = EBADMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
buf->rpos += len;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_free(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
if (buf == NULL)
|
||||||
|
return;
|
||||||
|
if (buf->max == 0) /* if buf lives on the stack */
|
||||||
|
abort(); /* abort before causing more harm */
|
||||||
|
if (buf->fd != -1)
|
||||||
|
close(buf->fd);
|
||||||
|
freezero(buf->buf, buf->size);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_fd_avail(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
return (buf->fd != -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ibuf_fd_get(struct ibuf *buf)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = buf->fd;
|
||||||
|
buf->fd = -1;
|
||||||
|
return (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ibuf_fd_set(struct ibuf *buf, int fd)
|
||||||
|
{
|
||||||
|
if (buf->max == 0) /* if buf lives on the stack */
|
||||||
|
abort(); /* abort before causing more harm */
|
||||||
|
if (buf->fd != -1)
|
||||||
|
close(buf->fd);
|
||||||
|
buf->fd = fd;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ibuf_write(struct msgbuf *msgbuf)
|
ibuf_write(struct msgbuf *msgbuf)
|
||||||
{
|
{
|
||||||
@@ -153,8 +557,8 @@ ibuf_write(struct msgbuf *msgbuf)
|
|||||||
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
||||||
if (i >= IOV_MAX)
|
if (i >= IOV_MAX)
|
||||||
break;
|
break;
|
||||||
iov[i].iov_base = buf->buf + buf->rpos;
|
iov[i].iov_base = ibuf_data(buf);
|
||||||
iov[i].iov_len = buf->wpos - buf->rpos;
|
iov[i].iov_len = ibuf_size(buf);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,15 +581,6 @@ again:
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ibuf_free(struct ibuf *buf)
|
|
||||||
{
|
|
||||||
if (buf == NULL)
|
|
||||||
return;
|
|
||||||
freezero(buf->buf, buf->size);
|
|
||||||
free(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
msgbuf_init(struct msgbuf *msgbuf)
|
msgbuf_init(struct msgbuf *msgbuf)
|
||||||
{
|
{
|
||||||
@@ -194,7 +589,7 @@ msgbuf_init(struct msgbuf *msgbuf)
|
|||||||
TAILQ_INIT(&msgbuf->bufs);
|
TAILQ_INIT(&msgbuf->bufs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
msgbuf_drain(struct msgbuf *msgbuf, size_t n)
|
msgbuf_drain(struct msgbuf *msgbuf, size_t n)
|
||||||
{
|
{
|
||||||
struct ibuf *buf, *next;
|
struct ibuf *buf, *next;
|
||||||
@@ -202,8 +597,8 @@ msgbuf_drain(struct msgbuf *msgbuf, size_t n)
|
|||||||
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
|
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
|
||||||
buf = next) {
|
buf = next) {
|
||||||
next = TAILQ_NEXT(buf, entry);
|
next = TAILQ_NEXT(buf, entry);
|
||||||
if (buf->rpos + n >= buf->wpos) {
|
if (n >= ibuf_size(buf)) {
|
||||||
n -= buf->wpos - buf->rpos;
|
n -= ibuf_size(buf);
|
||||||
ibuf_dequeue(msgbuf, buf);
|
ibuf_dequeue(msgbuf, buf);
|
||||||
} else {
|
} else {
|
||||||
buf->rpos += n;
|
buf->rpos += n;
|
||||||
@@ -225,7 +620,7 @@ int
|
|||||||
msgbuf_write(struct msgbuf *msgbuf)
|
msgbuf_write(struct msgbuf *msgbuf)
|
||||||
{
|
{
|
||||||
struct iovec iov[IOV_MAX];
|
struct iovec iov[IOV_MAX];
|
||||||
struct ibuf *buf;
|
struct ibuf *buf, *buf0 = NULL;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
@@ -241,24 +636,26 @@ msgbuf_write(struct msgbuf *msgbuf)
|
|||||||
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
|
||||||
if (i >= IOV_MAX)
|
if (i >= IOV_MAX)
|
||||||
break;
|
break;
|
||||||
iov[i].iov_base = buf->buf + buf->rpos;
|
if (i > 0 && buf->fd != -1)
|
||||||
iov[i].iov_len = buf->wpos - buf->rpos;
|
break;
|
||||||
|
iov[i].iov_base = ibuf_data(buf);
|
||||||
|
iov[i].iov_len = ibuf_size(buf);
|
||||||
i++;
|
i++;
|
||||||
if (buf->fd != -1)
|
if (buf->fd != -1)
|
||||||
break;
|
buf0 = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.msg_iov = iov;
|
msg.msg_iov = iov;
|
||||||
msg.msg_iovlen = i;
|
msg.msg_iovlen = i;
|
||||||
|
|
||||||
if (buf != NULL && buf->fd != -1) {
|
if (buf0 != NULL) {
|
||||||
msg.msg_control = (caddr_t)&cmsgbuf.buf;
|
msg.msg_control = (caddr_t)&cmsgbuf.buf;
|
||||||
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
cmsg->cmsg_len = CMSG_LEN(sizeof(int));
|
||||||
cmsg->cmsg_level = SOL_SOCKET;
|
cmsg->cmsg_level = SOL_SOCKET;
|
||||||
cmsg->cmsg_type = SCM_RIGHTS;
|
cmsg->cmsg_type = SCM_RIGHTS;
|
||||||
*(int *)CMSG_DATA(cmsg) = buf->fd;
|
*(int *)CMSG_DATA(cmsg) = buf0->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
again:
|
again:
|
||||||
@@ -279,9 +676,9 @@ again:
|
|||||||
* assumption: fd got sent if sendmsg sent anything
|
* assumption: fd got sent if sendmsg sent anything
|
||||||
* this works because fds are passed one at a time
|
* this works because fds are passed one at a time
|
||||||
*/
|
*/
|
||||||
if (buf != NULL && buf->fd != -1) {
|
if (buf0 != NULL) {
|
||||||
close(buf->fd);
|
close(buf0->fd);
|
||||||
buf->fd = -1;
|
buf0->fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
msgbuf_drain(msgbuf, n);
|
msgbuf_drain(msgbuf, n);
|
||||||
@@ -289,9 +686,17 @@ again:
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
msgbuf_queuelen(struct msgbuf *msgbuf)
|
||||||
|
{
|
||||||
|
return (msgbuf->queued);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
{
|
{
|
||||||
|
if (buf->max == 0) /* if buf lives on the stack */
|
||||||
|
abort(); /* abort before causing more harm */
|
||||||
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
||||||
msgbuf->queued++;
|
msgbuf->queued++;
|
||||||
}
|
}
|
||||||
@@ -300,10 +705,6 @@ static void
|
|||||||
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||||
{
|
{
|
||||||
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
||||||
|
|
||||||
if (buf->fd != -1)
|
|
||||||
close(buf->fd);
|
|
||||||
|
|
||||||
msgbuf->queued--;
|
msgbuf->queued--;
|
||||||
ibuf_free(buf);
|
ibuf_free(buf);
|
||||||
}
|
}
|
||||||
|
|||||||
286
compat/imsg.c
286
compat/imsg.c
@@ -1,6 +1,7 @@
|
|||||||
/* $OpenBSD: imsg.c,v 1.16 2017/12/14 09:27:44 kettenis Exp $ */
|
/* $OpenBSD: imsg.c,v 1.23 2023/12/12 15:47:41 claudio Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
||||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
@@ -28,23 +29,28 @@
|
|||||||
#include "compat.h"
|
#include "compat.h"
|
||||||
#include "imsg.h"
|
#include "imsg.h"
|
||||||
|
|
||||||
|
struct imsg_fd {
|
||||||
|
TAILQ_ENTRY(imsg_fd) entry;
|
||||||
|
int fd;
|
||||||
|
};
|
||||||
|
|
||||||
int imsg_fd_overhead = 0;
|
int imsg_fd_overhead = 0;
|
||||||
|
|
||||||
static int imsg_get_fd(struct imsgbuf *);
|
static int imsg_dequeue_fd(struct imsgbuf *);
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
imsg_init(struct imsgbuf *imsgbuf, int fd)
|
||||||
{
|
{
|
||||||
msgbuf_init(&ibuf->w);
|
msgbuf_init(&imsgbuf->w);
|
||||||
memset(&ibuf->r, 0, sizeof(ibuf->r));
|
memset(&imsgbuf->r, 0, sizeof(imsgbuf->r));
|
||||||
ibuf->fd = fd;
|
imsgbuf->fd = fd;
|
||||||
ibuf->w.fd = fd;
|
imsgbuf->w.fd = fd;
|
||||||
ibuf->pid = getpid();
|
imsgbuf->pid = getpid();
|
||||||
TAILQ_INIT(&ibuf->fds);
|
TAILQ_INIT(&imsgbuf->fds);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
imsg_read(struct imsgbuf *ibuf)
|
imsg_read(struct imsgbuf *imsgbuf)
|
||||||
{
|
{
|
||||||
struct msghdr msg;
|
struct msghdr msg;
|
||||||
struct cmsghdr *cmsg;
|
struct cmsghdr *cmsg;
|
||||||
@@ -60,8 +66,8 @@ imsg_read(struct imsgbuf *ibuf)
|
|||||||
memset(&msg, 0, sizeof(msg));
|
memset(&msg, 0, sizeof(msg));
|
||||||
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
|
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
|
||||||
|
|
||||||
iov.iov_base = ibuf->r.buf + ibuf->r.wpos;
|
iov.iov_base = imsgbuf->r.buf + imsgbuf->r.wpos;
|
||||||
iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
|
iov.iov_len = sizeof(imsgbuf->r.buf) - imsgbuf->r.wpos;
|
||||||
msg.msg_iov = &iov;
|
msg.msg_iov = &iov;
|
||||||
msg.msg_iovlen = 1;
|
msg.msg_iovlen = 1;
|
||||||
msg.msg_control = &cmsgbuf.buf;
|
msg.msg_control = &cmsgbuf.buf;
|
||||||
@@ -79,13 +85,13 @@ again:
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
|
if ((n = recvmsg(imsgbuf->fd, &msg, 0)) == -1) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
goto again;
|
goto again;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ibuf->r.wpos += n;
|
imsgbuf->r.wpos += n;
|
||||||
|
|
||||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
||||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||||
@@ -105,7 +111,7 @@ again:
|
|||||||
fd = ((int *)CMSG_DATA(cmsg))[i];
|
fd = ((int *)CMSG_DATA(cmsg))[i];
|
||||||
if (ifd != NULL) {
|
if (ifd != NULL) {
|
||||||
ifd->fd = fd;
|
ifd->fd = fd;
|
||||||
TAILQ_INSERT_TAIL(&ibuf->fds, ifd,
|
TAILQ_INSERT_TAIL(&imsgbuf->fds, ifd,
|
||||||
entry);
|
entry);
|
||||||
ifd = NULL;
|
ifd = NULL;
|
||||||
} else
|
} else
|
||||||
@@ -121,94 +127,235 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
|
||||||
{
|
{
|
||||||
|
struct imsg m;
|
||||||
size_t av, left, datalen;
|
size_t av, left, datalen;
|
||||||
|
|
||||||
av = ibuf->r.wpos;
|
av = imsgbuf->r.wpos;
|
||||||
|
|
||||||
if (IMSG_HEADER_SIZE > av)
|
if (IMSG_HEADER_SIZE > av)
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
|
memcpy(&m.hdr, imsgbuf->r.buf, sizeof(m.hdr));
|
||||||
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
|
if (m.hdr.len < IMSG_HEADER_SIZE ||
|
||||||
imsg->hdr.len > MAX_IMSGSIZE) {
|
m.hdr.len > MAX_IMSGSIZE) {
|
||||||
errno = ERANGE;
|
errno = ERANGE;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
if (imsg->hdr.len > av)
|
if (m.hdr.len > av)
|
||||||
return (0);
|
return (0);
|
||||||
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
|
||||||
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
|
|
||||||
if (datalen == 0)
|
|
||||||
imsg->data = NULL;
|
|
||||||
else if ((imsg->data = malloc(datalen)) == NULL)
|
|
||||||
return (-1);
|
|
||||||
|
|
||||||
if (imsg->hdr.flags & IMSGF_HASFD)
|
m.fd = -1;
|
||||||
imsg->fd = imsg_get_fd(ibuf);
|
m.buf = NULL;
|
||||||
else
|
m.data = NULL;
|
||||||
imsg->fd = -1;
|
|
||||||
|
|
||||||
memcpy(imsg->data, ibuf->r.rptr, datalen);
|
datalen = m.hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
imsgbuf->r.rptr = imsgbuf->r.buf + IMSG_HEADER_SIZE;
|
||||||
|
if (datalen != 0) {
|
||||||
|
if ((m.buf = ibuf_open(datalen)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
if (ibuf_add(m.buf, imsgbuf->r.rptr, datalen) == -1) {
|
||||||
|
/* this should never fail */
|
||||||
|
ibuf_free(m.buf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
m.data = ibuf_data(m.buf);
|
||||||
|
}
|
||||||
|
|
||||||
if (imsg->hdr.len < av) {
|
if (m.hdr.flags & IMSGF_HASFD)
|
||||||
left = av - imsg->hdr.len;
|
m.fd = imsg_dequeue_fd(imsgbuf);
|
||||||
memmove(&ibuf->r.buf, ibuf->r.buf + imsg->hdr.len, left);
|
|
||||||
ibuf->r.wpos = left;
|
if (m.hdr.len < av) {
|
||||||
|
left = av - m.hdr.len;
|
||||||
|
memmove(&imsgbuf->r.buf, imsgbuf->r.buf + m.hdr.len, left);
|
||||||
|
imsgbuf->r.wpos = left;
|
||||||
} else
|
} else
|
||||||
ibuf->r.wpos = 0;
|
imsgbuf->r.wpos = 0;
|
||||||
|
|
||||||
|
*imsg = m;
|
||||||
return (datalen + IMSG_HEADER_SIZE);
|
return (datalen + IMSG_HEADER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
imsg_get_ibuf(struct imsg *imsg, struct ibuf *ibuf)
|
||||||
int fd, const void *data, uint16_t datalen)
|
{
|
||||||
|
if (imsg->buf == NULL) {
|
||||||
|
errno = EBADMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return ibuf_get_ibuf(imsg->buf, ibuf_size(imsg->buf), ibuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_get_data(struct imsg *imsg, void *data, size_t len)
|
||||||
|
{
|
||||||
|
if (len == 0) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (imsg->buf == NULL || ibuf_size(imsg->buf) != len) {
|
||||||
|
errno = EBADMSG;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return ibuf_get(imsg->buf, data, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_get_fd(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
int fd = imsg->fd;
|
||||||
|
|
||||||
|
imsg->fd = -1;
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
imsg_get_id(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
return (imsg->hdr.peerid);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t
|
||||||
|
imsg_get_len(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
if (imsg->buf == NULL)
|
||||||
|
return 0;
|
||||||
|
return ibuf_size(imsg->buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t
|
||||||
|
imsg_get_pid(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
return (imsg->hdr.pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
imsg_get_type(struct imsg *imsg)
|
||||||
|
{
|
||||||
|
return (imsg->hdr.type);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
imsg_compose(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
|
||||||
|
int fd, const void *data, size_t datalen)
|
||||||
{
|
{
|
||||||
struct ibuf *wbuf;
|
struct ibuf *wbuf;
|
||||||
|
|
||||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (imsg_add(wbuf, data, datalen) == -1)
|
if (imsg_add(wbuf, data, datalen) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
wbuf->fd = fd;
|
ibuf_fd_set(wbuf, fd);
|
||||||
|
imsg_close(imsgbuf, wbuf);
|
||||||
imsg_close(ibuf, wbuf);
|
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
imsg_composev(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
|
||||||
int fd, const struct iovec *iov, int iovcnt)
|
int fd, const struct iovec *iov, int iovcnt)
|
||||||
{
|
{
|
||||||
struct ibuf *wbuf;
|
struct ibuf *wbuf;
|
||||||
int i, datalen = 0;
|
int i;
|
||||||
|
size_t datalen = 0;
|
||||||
|
|
||||||
for (i = 0; i < iovcnt; i++)
|
for (i = 0; i < iovcnt; i++)
|
||||||
datalen += iov[i].iov_len;
|
datalen += iov[i].iov_len;
|
||||||
|
|
||||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
for (i = 0; i < iovcnt; i++)
|
for (i = 0; i < iovcnt; i++)
|
||||||
if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
|
if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
wbuf->fd = fd;
|
ibuf_fd_set(wbuf, fd);
|
||||||
|
imsg_close(imsgbuf, wbuf);
|
||||||
imsg_close(ibuf, wbuf);
|
|
||||||
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/*
|
||||||
|
* Enqueue imsg with payload from ibuf buf. fd passing is not possible
|
||||||
|
* with this function.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
imsg_compose_ibuf(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id,
|
||||||
|
pid_t pid, struct ibuf *buf)
|
||||||
|
{
|
||||||
|
struct ibuf *hdrbuf = NULL;
|
||||||
|
struct imsg_hdr hdr;
|
||||||
|
int save_errno;
|
||||||
|
|
||||||
|
if (ibuf_size(buf) + IMSG_HEADER_SIZE > MAX_IMSGSIZE) {
|
||||||
|
errno = ERANGE;
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
hdr.type = type;
|
||||||
|
hdr.len = ibuf_size(buf) + IMSG_HEADER_SIZE;
|
||||||
|
hdr.flags = 0;
|
||||||
|
hdr.peerid = id;
|
||||||
|
if ((hdr.pid = pid) == 0)
|
||||||
|
hdr.pid = imsgbuf->pid;
|
||||||
|
|
||||||
|
if ((hdrbuf = ibuf_open(IMSG_HEADER_SIZE)) == NULL)
|
||||||
|
goto fail;
|
||||||
|
if (imsg_add(hdrbuf, &hdr, sizeof(hdr)) == -1)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
ibuf_close(&imsgbuf->w, hdrbuf);
|
||||||
|
ibuf_close(&imsgbuf->w, buf);
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
fail:
|
||||||
|
save_errno = errno;
|
||||||
|
ibuf_free(buf);
|
||||||
|
ibuf_free(hdrbuf);
|
||||||
|
errno = save_errno;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Forward imsg to another channel. Any attached fd is closed.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
imsg_forward(struct imsgbuf *imsgbuf, struct imsg *msg)
|
||||||
|
{
|
||||||
|
struct ibuf *wbuf;
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
if (msg->fd != -1) {
|
||||||
|
close(msg->fd);
|
||||||
|
msg->fd = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->buf != NULL) {
|
||||||
|
ibuf_rewind(msg->buf);
|
||||||
|
len = ibuf_size(msg->buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((wbuf = imsg_create(imsgbuf, msg->hdr.type, msg->hdr.peerid,
|
||||||
|
msg->hdr.pid, len)) == NULL)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
if (msg->buf != NULL) {
|
||||||
|
if (ibuf_add_buf(wbuf, msg->buf) == -1) {
|
||||||
|
ibuf_free(wbuf);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
imsg_close(imsgbuf, wbuf);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
struct ibuf *
|
struct ibuf *
|
||||||
imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
imsg_create(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
|
||||||
uint16_t datalen)
|
size_t datalen)
|
||||||
{
|
{
|
||||||
struct ibuf *wbuf;
|
struct ibuf *wbuf;
|
||||||
struct imsg_hdr hdr;
|
struct imsg_hdr hdr;
|
||||||
@@ -221,9 +368,9 @@ imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
|||||||
|
|
||||||
hdr.type = type;
|
hdr.type = type;
|
||||||
hdr.flags = 0;
|
hdr.flags = 0;
|
||||||
hdr.peerid = peerid;
|
hdr.peerid = id;
|
||||||
if ((hdr.pid = pid) == 0)
|
if ((hdr.pid = pid) == 0)
|
||||||
hdr.pid = ibuf->pid;
|
hdr.pid = imsgbuf->pid;
|
||||||
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -234,7 +381,7 @@ imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
imsg_add(struct ibuf *msg, const void *data, uint16_t datalen)
|
imsg_add(struct ibuf *msg, const void *data, size_t datalen)
|
||||||
{
|
{
|
||||||
if (datalen)
|
if (datalen)
|
||||||
if (ibuf_add(msg, data, datalen) == -1) {
|
if (ibuf_add(msg, data, datalen) == -1) {
|
||||||
@@ -245,58 +392,57 @@ imsg_add(struct ibuf *msg, const void *data, uint16_t datalen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
imsg_close(struct imsgbuf *imsgbuf, struct ibuf *msg)
|
||||||
{
|
{
|
||||||
struct imsg_hdr *hdr;
|
struct imsg_hdr *hdr;
|
||||||
|
|
||||||
hdr = (struct imsg_hdr *)msg->buf;
|
hdr = (struct imsg_hdr *)msg->buf;
|
||||||
|
|
||||||
hdr->flags &= ~IMSGF_HASFD;
|
hdr->flags &= ~IMSGF_HASFD;
|
||||||
if (msg->fd != -1)
|
if (ibuf_fd_avail(msg))
|
||||||
hdr->flags |= IMSGF_HASFD;
|
hdr->flags |= IMSGF_HASFD;
|
||||||
|
hdr->len = ibuf_size(msg);
|
||||||
|
|
||||||
hdr->len = (uint16_t)msg->wpos;
|
ibuf_close(&imsgbuf->w, msg);
|
||||||
|
|
||||||
ibuf_close(&ibuf->w, msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_free(struct imsg *imsg)
|
imsg_free(struct imsg *imsg)
|
||||||
{
|
{
|
||||||
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
ibuf_free(imsg->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
imsg_get_fd(struct imsgbuf *ibuf)
|
imsg_dequeue_fd(struct imsgbuf *imsgbuf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
struct imsg_fd *ifd;
|
struct imsg_fd *ifd;
|
||||||
|
|
||||||
if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL)
|
if ((ifd = TAILQ_FIRST(&imsgbuf->fds)) == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
fd = ifd->fd;
|
fd = ifd->fd;
|
||||||
TAILQ_REMOVE(&ibuf->fds, ifd, entry);
|
TAILQ_REMOVE(&imsgbuf->fds, ifd, entry);
|
||||||
free(ifd);
|
free(ifd);
|
||||||
|
|
||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
imsg_flush(struct imsgbuf *ibuf)
|
imsg_flush(struct imsgbuf *imsgbuf)
|
||||||
{
|
{
|
||||||
while (ibuf->w.queued)
|
while (imsgbuf->w.queued)
|
||||||
if (msgbuf_write(&ibuf->w) <= 0)
|
if (msgbuf_write(&imsgbuf->w) <= 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
imsg_clear(struct imsgbuf *ibuf)
|
imsg_clear(struct imsgbuf *imsgbuf)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
msgbuf_clear(&ibuf->w);
|
msgbuf_clear(&imsgbuf->w);
|
||||||
while ((fd = imsg_get_fd(ibuf)) != -1)
|
while ((fd = imsg_dequeue_fd(imsgbuf)) != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/* $OpenBSD: imsg.h,v 1.5 2019/01/20 02:50:03 bcook Exp $ */
|
/* $OpenBSD: imsg.h,v 1.8 2023/12/12 15:47:41 claudio Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
||||||
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
||||||
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
|
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
|
||||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
#ifndef _IMSG_H_
|
#ifndef _IMSG_H_
|
||||||
#define _IMSG_H_
|
#define _IMSG_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define IBUF_READ_SIZE 65535
|
#define IBUF_READ_SIZE 65535
|
||||||
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
||||||
@@ -49,11 +50,7 @@ struct ibuf_read {
|
|||||||
size_t wpos;
|
size_t wpos;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct imsg_fd {
|
struct imsg_fd;
|
||||||
TAILQ_ENTRY(imsg_fd) entry;
|
|
||||||
int fd;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct imsgbuf {
|
struct imsgbuf {
|
||||||
TAILQ_HEAD(, imsg_fd) fds;
|
TAILQ_HEAD(, imsg_fd) fds;
|
||||||
struct ibuf_read r;
|
struct ibuf_read r;
|
||||||
@@ -76,35 +73,83 @@ struct imsg {
|
|||||||
struct imsg_hdr hdr;
|
struct imsg_hdr hdr;
|
||||||
int fd;
|
int fd;
|
||||||
void *data;
|
void *data;
|
||||||
|
struct ibuf *buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct iovec;
|
||||||
|
|
||||||
/* buffer.c */
|
/* imsg-buffer.c */
|
||||||
struct ibuf *ibuf_open(size_t);
|
struct ibuf *ibuf_open(size_t);
|
||||||
struct ibuf *ibuf_dynamic(size_t, size_t);
|
struct ibuf *ibuf_dynamic(size_t, size_t);
|
||||||
int ibuf_add(struct ibuf *, const void *, size_t);
|
int ibuf_add(struct ibuf *, const void *, size_t);
|
||||||
|
int ibuf_add_buf(struct ibuf *, const struct ibuf *);
|
||||||
|
int ibuf_add_ibuf(struct ibuf *, const struct ibuf *);
|
||||||
|
int ibuf_add_zero(struct ibuf *, size_t);
|
||||||
|
int ibuf_add_n8(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_n16(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_n32(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_n64(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_h16(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_h32(struct ibuf *, uint64_t);
|
||||||
|
int ibuf_add_h64(struct ibuf *, uint64_t);
|
||||||
void *ibuf_reserve(struct ibuf *, size_t);
|
void *ibuf_reserve(struct ibuf *, size_t);
|
||||||
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
||||||
size_t ibuf_size(struct ibuf *);
|
int ibuf_set(struct ibuf *, size_t, const void *, size_t);
|
||||||
size_t ibuf_left(struct ibuf *);
|
int ibuf_set_n8(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_n16(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_n32(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_n64(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_h16(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_h32(struct ibuf *, size_t, uint64_t);
|
||||||
|
int ibuf_set_h64(struct ibuf *, size_t, uint64_t);
|
||||||
|
void *ibuf_data(const struct ibuf *);
|
||||||
|
size_t ibuf_size(const struct ibuf *);
|
||||||
|
size_t ibuf_left(const struct ibuf *);
|
||||||
|
int ibuf_truncate(struct ibuf *, size_t);
|
||||||
|
void ibuf_rewind(struct ibuf *);
|
||||||
void ibuf_close(struct msgbuf *, struct ibuf *);
|
void ibuf_close(struct msgbuf *, struct ibuf *);
|
||||||
int ibuf_write(struct msgbuf *);
|
void ibuf_from_buffer(struct ibuf *, void *, size_t);
|
||||||
|
void ibuf_from_ibuf(struct ibuf *, const struct ibuf *);
|
||||||
|
int ibuf_get(struct ibuf *, void *, size_t);
|
||||||
|
int ibuf_get_ibuf(struct ibuf *, size_t, struct ibuf *);
|
||||||
|
int ibuf_get_n8(struct ibuf *, uint8_t *);
|
||||||
|
int ibuf_get_n16(struct ibuf *, uint16_t *);
|
||||||
|
int ibuf_get_n32(struct ibuf *, uint32_t *);
|
||||||
|
int ibuf_get_n64(struct ibuf *, uint64_t *);
|
||||||
|
int ibuf_get_h16(struct ibuf *, uint16_t *);
|
||||||
|
int ibuf_get_h32(struct ibuf *, uint32_t *);
|
||||||
|
int ibuf_get_h64(struct ibuf *, uint64_t *);
|
||||||
|
int ibuf_skip(struct ibuf *, size_t);
|
||||||
void ibuf_free(struct ibuf *);
|
void ibuf_free(struct ibuf *);
|
||||||
|
int ibuf_fd_avail(struct ibuf *);
|
||||||
|
int ibuf_fd_get(struct ibuf *);
|
||||||
|
void ibuf_fd_set(struct ibuf *, int);
|
||||||
|
int ibuf_write(struct msgbuf *);
|
||||||
void msgbuf_init(struct msgbuf *);
|
void msgbuf_init(struct msgbuf *);
|
||||||
void msgbuf_clear(struct msgbuf *);
|
void msgbuf_clear(struct msgbuf *);
|
||||||
|
uint32_t msgbuf_queuelen(struct msgbuf *);
|
||||||
int msgbuf_write(struct msgbuf *);
|
int msgbuf_write(struct msgbuf *);
|
||||||
void msgbuf_drain(struct msgbuf *, size_t);
|
|
||||||
|
|
||||||
/* imsg.c */
|
/* imsg.c */
|
||||||
void imsg_init(struct imsgbuf *, int);
|
void imsg_init(struct imsgbuf *, int);
|
||||||
ssize_t imsg_read(struct imsgbuf *);
|
ssize_t imsg_read(struct imsgbuf *);
|
||||||
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
||||||
|
int imsg_get_ibuf(struct imsg *, struct ibuf *);
|
||||||
|
int imsg_get_data(struct imsg *, void *, size_t);
|
||||||
|
int imsg_get_fd(struct imsg *);
|
||||||
|
uint32_t imsg_get_id(struct imsg *);
|
||||||
|
size_t imsg_get_len(struct imsg *);
|
||||||
|
pid_t imsg_get_pid(struct imsg *);
|
||||||
|
uint32_t imsg_get_type(struct imsg *);
|
||||||
|
int imsg_forward(struct imsgbuf *, struct imsg *);
|
||||||
int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
int imsg_compose(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
||||||
const void *, uint16_t);
|
const void *, size_t);
|
||||||
int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
||||||
const struct iovec *, int);
|
const struct iovec *, int);
|
||||||
struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t);
|
int imsg_compose_ibuf(struct imsgbuf *, uint32_t, uint32_t, pid_t,
|
||||||
int imsg_add(struct ibuf *, const void *, uint16_t);
|
struct ibuf *);
|
||||||
|
struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, size_t);
|
||||||
|
int imsg_add(struct ibuf *, const void *, size_t);
|
||||||
void imsg_close(struct imsgbuf *, struct ibuf *);
|
void imsg_close(struct imsgbuf *, struct ibuf *);
|
||||||
void imsg_free(struct imsg *);
|
void imsg_free(struct imsg *);
|
||||||
int imsg_flush(struct imsgbuf *);
|
int imsg_flush(struct imsgbuf *);
|
||||||
|
|||||||
30
compat/ntohll.c
Normal file
30
compat/ntohll.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2024 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 "compat.h"
|
||||||
|
|
||||||
|
uint64_t
|
||||||
|
ntohll(uint64_t v)
|
||||||
|
{
|
||||||
|
uint32_t b;
|
||||||
|
uint32_t t;
|
||||||
|
|
||||||
|
b = ntohl (v & 0xffffffff);
|
||||||
|
t = ntohl (v >> 32);
|
||||||
|
return ((uint64_t)b << 32 | t);
|
||||||
|
}
|
||||||
215
compat/systemd.c
Normal file
215
compat/systemd.c
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
/* $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-bus.h>
|
||||||
|
#include <systemd/sd-daemon.h>
|
||||||
|
#include <systemd/sd-login.h>
|
||||||
|
#include <systemd/sd-id128.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
systemd_activated(void)
|
||||||
|
{
|
||||||
|
return (sd_listen_fds(0) >= 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
systemd_create_socket(int flags, char **cause)
|
||||||
|
{
|
||||||
|
int fds;
|
||||||
|
int fd;
|
||||||
|
struct sockaddr_un sa;
|
||||||
|
socklen_t 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
systemd_move_pid_to_new_cgroup(pid_t pid, char **cause)
|
||||||
|
{
|
||||||
|
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
|
sd_bus_message *m = NULL, *reply = NULL;
|
||||||
|
sd_bus *bus = NULL;
|
||||||
|
char *name, *desc, *slice;
|
||||||
|
sd_id128_t uuid;
|
||||||
|
int r;
|
||||||
|
pid_t parent_pid;
|
||||||
|
|
||||||
|
/* Connect to the session bus. */
|
||||||
|
r = sd_bus_default_user(&bus);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to connect to session bus: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start building the method call. */
|
||||||
|
r = sd_bus_message_new_method_call(bus, &m,
|
||||||
|
"org.freedesktop.systemd1",
|
||||||
|
"/org/freedesktop/systemd1",
|
||||||
|
"org.freedesktop.systemd1.Manager",
|
||||||
|
"StartTransientUnit");
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to create bus message: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Generate a unique name for the new scope, to avoid collisions. */
|
||||||
|
r = sd_id128_randomize(&uuid);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to generate uuid: %s", strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
xasprintf(&name, "tmux-spawn-" SD_ID128_UUID_FORMAT_STR ".scope",
|
||||||
|
SD_ID128_FORMAT_VAL(uuid));
|
||||||
|
r = sd_bus_message_append(m, "s", name);
|
||||||
|
free(name);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to bus message: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mode: fail if there's a queued unit with the same name. */
|
||||||
|
r = sd_bus_message_append(m, "s", "fail");
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to bus message: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start properties array. */
|
||||||
|
r = sd_bus_message_open_container(m, 'a', "(sv)");
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to start properties array: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent_pid = getpid();
|
||||||
|
xasprintf(&desc, "tmux child pane %ld launched by process %ld",
|
||||||
|
(long)pid, (long)parent_pid);
|
||||||
|
r = sd_bus_message_append(m, "(sv)", "Description", "s", desc);
|
||||||
|
free(desc);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to properties: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Inherit the slice from the parent process, or default to
|
||||||
|
* "app-tmux.slice" if that fails.
|
||||||
|
*/
|
||||||
|
r = sd_pid_get_user_slice(parent_pid, &slice);
|
||||||
|
if (r < 0) {
|
||||||
|
slice = xstrdup("app-tmux.slice");
|
||||||
|
}
|
||||||
|
r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
|
||||||
|
free(slice);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to properties: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* PIDs to add to the scope: length - 1 array of uint32_t. */
|
||||||
|
r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to properties: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean up the scope even if it fails. */
|
||||||
|
r = sd_bus_message_append(m, "(sv)", "CollectMode", "s",
|
||||||
|
"inactive-or-failed");
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to properties: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End properties array. */
|
||||||
|
r = sd_bus_message_close_container(m);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to end properties array: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* aux is currently unused and should be passed an empty array. */
|
||||||
|
r = sd_bus_message_append(m, "a(sa(sv))", 0);
|
||||||
|
if (r < 0) {
|
||||||
|
xasprintf(cause, "failed to append to bus message: %s",
|
||||||
|
strerror(-r));
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call the method with a timeout of 1 second = 1e6 us. */
|
||||||
|
r = sd_bus_call(bus, m, 1000000, &error, &reply);
|
||||||
|
if (r < 0) {
|
||||||
|
if (error.message != NULL) {
|
||||||
|
/* We have a specific error message from sd-bus. */
|
||||||
|
xasprintf(cause, "StartTransientUnit call failed: %s",
|
||||||
|
error.message);
|
||||||
|
} else {
|
||||||
|
xasprintf(cause, "StartTransientUnit call failed: %s",
|
||||||
|
strerror(-r));
|
||||||
|
}
|
||||||
|
goto finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
finish:
|
||||||
|
sd_bus_error_free(&error);
|
||||||
|
sd_bus_message_unref(m);
|
||||||
|
sd_bus_message_unref(reply);
|
||||||
|
sd_bus_unref(bus);
|
||||||
|
|
||||||
|
return (r);
|
||||||
|
}
|
||||||
271
configure.ac
271
configure.ac
@@ -1,6 +1,6 @@
|
|||||||
# configure.ac
|
# configure.ac
|
||||||
|
|
||||||
AC_INIT([tmux], 3.2)
|
AC_INIT([tmux], 3.4)
|
||||||
AC_PREREQ([2.60])
|
AC_PREREQ([2.60])
|
||||||
|
|
||||||
AC_CONFIG_AUX_DIR(etc)
|
AC_CONFIG_AUX_DIR(etc)
|
||||||
@@ -24,27 +24,27 @@ SAVED_LDFLAGS="$LDFLAGS"
|
|||||||
# Is this oss-fuzz build?
|
# Is this oss-fuzz build?
|
||||||
AC_ARG_ENABLE(
|
AC_ARG_ENABLE(
|
||||||
fuzzing,
|
fuzzing,
|
||||||
AC_HELP_STRING(--enable-fuzzing, build fuzzers)
|
AS_HELP_STRING(--enable-fuzzing, build fuzzers)
|
||||||
)
|
)
|
||||||
AC_ARG_VAR(
|
AC_ARG_VAR(
|
||||||
FUZZING_LIBS,
|
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.
|
# Set up convenient fuzzing defaults before initializing compiler.
|
||||||
if test "x$enable_fuzzing" = xyes; then
|
if test "x$enable_fuzzing" = xyes; then
|
||||||
AC_DEFINE(NEED_FUZZING)
|
AC_DEFINE(NEED_FUZZING)
|
||||||
test "x$CC" == x && CC=clang
|
test "x$CC" = x && CC=clang
|
||||||
test "x$FUZZING_LIBS" == x && \
|
test "x$FUZZING_LIBS" = x && \
|
||||||
FUZZING_LIBS="-fsanitize=fuzzer"
|
FUZZING_LIBS="-fsanitize=fuzzer"
|
||||||
test "x$SAVED_CFLAGS" == x && \
|
test "x$SAVED_CFLAGS" = x && \
|
||||||
AM_CFLAGS="-g -fsanitize=fuzzer-no-link,address"
|
AM_CFLAGS="-g -fsanitize=fuzzer-no-link,address"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set up the compiler in two different ways and say yes we may want to install.
|
# Set up the compiler in two different ways and say yes we may want to install.
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AM_PROG_CC_C_O
|
AM_PROG_CC_C_O
|
||||||
AC_PROG_CC_C99
|
m4_version_prereq(2.70, [AC_PROG_CC], [AC_PROG_CC_C99])
|
||||||
AC_PROG_CPP
|
AC_PROG_CPP
|
||||||
AC_PROG_EGREP
|
AC_PROG_EGREP
|
||||||
AC_PROG_INSTALL
|
AC_PROG_INSTALL
|
||||||
@@ -59,21 +59,41 @@ test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
|||||||
case "x$VERSION" in xnext*) enable_debug=yes;; esac
|
case "x$VERSION" in xnext*) enable_debug=yes;; esac
|
||||||
AC_ARG_ENABLE(
|
AC_ARG_ENABLE(
|
||||||
debug,
|
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)
|
AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
|
||||||
|
|
||||||
# Is this a static build?
|
# Is this a static build?
|
||||||
AC_ARG_ENABLE(
|
AC_ARG_ENABLE(
|
||||||
static,
|
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
|
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"
|
test "x$PKG_CONFIG" != x && PKG_CONFIG="$PKG_CONFIG --static"
|
||||||
AM_LDFLAGS="-static $AM_LDFLAGS"
|
AM_LDFLAGS="-static $AM_LDFLAGS"
|
||||||
LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
|
LDFLAGS="$AM_LDFLAGS $SAVED_LDFLAGS"
|
||||||
fi
|
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?
|
# Do we need fuzzers?
|
||||||
AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
|
AM_CONDITIONAL(NEED_FUZZING, test "x$enable_fuzzing" = xyes)
|
||||||
|
|
||||||
@@ -108,6 +128,7 @@ AC_CHECK_HEADERS([ \
|
|||||||
sys/dir.h \
|
sys/dir.h \
|
||||||
sys/ndir.h \
|
sys/ndir.h \
|
||||||
sys/tree.h \
|
sys/tree.h \
|
||||||
|
ucred.h \
|
||||||
util.h \
|
util.h \
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -126,6 +147,7 @@ AC_CHECK_FUNCS([ \
|
|||||||
flock \
|
flock \
|
||||||
prctl \
|
prctl \
|
||||||
proc_pidinfo \
|
proc_pidinfo \
|
||||||
|
getpeerucred \
|
||||||
sysconf
|
sysconf
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -140,9 +162,12 @@ AC_REPLACE_FUNCS([ \
|
|||||||
freezero \
|
freezero \
|
||||||
getdtablecount \
|
getdtablecount \
|
||||||
getdtablesize \
|
getdtablesize \
|
||||||
|
getpeereid \
|
||||||
getline \
|
getline \
|
||||||
getprogname \
|
getprogname \
|
||||||
|
htonll \
|
||||||
memmem \
|
memmem \
|
||||||
|
ntohll \
|
||||||
setenv \
|
setenv \
|
||||||
setproctitle \
|
setproctitle \
|
||||||
strcasestr \
|
strcasestr \
|
||||||
@@ -150,10 +175,20 @@ AC_REPLACE_FUNCS([ \
|
|||||||
strlcpy \
|
strlcpy \
|
||||||
strndup \
|
strndup \
|
||||||
strsep \
|
strsep \
|
||||||
strtonum \
|
|
||||||
])
|
])
|
||||||
AC_FUNC_STRNLEN
|
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)],
|
||||||
|
[AC_LIBOBJ(strtonum) AC_MSG_RESULT(no)]
|
||||||
|
)
|
||||||
|
|
||||||
# Clang sanitizers wrap reallocarray even if it isn't available on the target
|
# Clang sanitizers wrap reallocarray even if it isn't available on the target
|
||||||
# system. When compiled it always returns NULL and crashes the program. To
|
# system. When compiled it always returns NULL and crashes the program. To
|
||||||
# detect this we need a more complicated test.
|
# detect this we need a more complicated test.
|
||||||
@@ -163,6 +198,7 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM(
|
|||||||
[return (reallocarray(NULL, 1, 1) == NULL);]
|
[return (reallocarray(NULL, 1, 1) == NULL);]
|
||||||
)],
|
)],
|
||||||
AC_MSG_RESULT(yes),
|
AC_MSG_RESULT(yes),
|
||||||
|
[AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])],
|
||||||
[AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
|
[AC_LIBOBJ(reallocarray) AC_MSG_RESULT([no])]
|
||||||
)
|
)
|
||||||
AC_MSG_CHECKING([for working recallocarray])
|
AC_MSG_CHECKING([for working recallocarray])
|
||||||
@@ -171,6 +207,7 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM(
|
|||||||
[return (recallocarray(NULL, 1, 1, 1) == NULL);]
|
[return (recallocarray(NULL, 1, 1, 1) == NULL);]
|
||||||
)],
|
)],
|
||||||
AC_MSG_RESULT(yes),
|
AC_MSG_RESULT(yes),
|
||||||
|
[AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])],
|
||||||
[AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
|
[AC_LIBOBJ(recallocarray) AC_MSG_RESULT([no])]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -232,6 +269,12 @@ if test "x$found_libevent" = xno; then
|
|||||||
AC_MSG_ERROR("libevent not found")
|
AC_MSG_ERROR("libevent not found")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Look for yacc.
|
||||||
|
AC_CHECK_PROG(found_yacc, $YACC, yes, no)
|
||||||
|
if test "x$found_yacc" = xno; then
|
||||||
|
AC_MSG_ERROR("yacc not found")
|
||||||
|
fi
|
||||||
|
|
||||||
# Look for ncurses or curses. Try pkg-config first then directly for the
|
# Look for ncurses or curses. Try pkg-config first then directly for the
|
||||||
# library.
|
# library.
|
||||||
PKG_CHECK_MODULES(
|
PKG_CHECK_MODULES(
|
||||||
@@ -274,7 +317,7 @@ fi
|
|||||||
if test "x$found_ncurses" = xno; then
|
if test "x$found_ncurses" = xno; then
|
||||||
AC_SEARCH_LIBS(
|
AC_SEARCH_LIBS(
|
||||||
setupterm,
|
setupterm,
|
||||||
[tinfo ncurses ncursesw],
|
[tinfo terminfo ncurses ncursesw],
|
||||||
found_ncurses=yes,
|
found_ncurses=yes,
|
||||||
found_ncurses=no
|
found_ncurses=no
|
||||||
)
|
)
|
||||||
@@ -287,6 +330,7 @@ if test "x$found_ncurses" = xno; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if test "x$found_ncurses" = xyes; then
|
if test "x$found_ncurses" = xyes; then
|
||||||
|
CPPFLAGS="$CPPFLAGS -DHAVE_NCURSES_H"
|
||||||
AC_DEFINE(HAVE_NCURSES_H)
|
AC_DEFINE(HAVE_NCURSES_H)
|
||||||
else
|
else
|
||||||
AC_CHECK_LIB(
|
AC_CHECK_LIB(
|
||||||
@@ -302,16 +346,21 @@ else
|
|||||||
)
|
)
|
||||||
if test "x$found_curses" = xyes; then
|
if test "x$found_curses" = xyes; then
|
||||||
LIBS="$LIBS -lcurses"
|
LIBS="$LIBS -lcurses"
|
||||||
|
CPPFLAGS="$CPPFLAGS -DHAVE_CURSES_H"
|
||||||
AC_DEFINE(HAVE_CURSES_H)
|
AC_DEFINE(HAVE_CURSES_H)
|
||||||
else
|
else
|
||||||
AC_MSG_ERROR("curses not found")
|
AC_MSG_ERROR("curses not found")
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
AC_CHECK_FUNCS([ \
|
||||||
|
tiparm \
|
||||||
|
tiparm_s \
|
||||||
|
])
|
||||||
|
|
||||||
# Look for utempter.
|
# Look for utempter.
|
||||||
AC_ARG_ENABLE(
|
AC_ARG_ENABLE(
|
||||||
utempter,
|
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
|
if test "x$enable_utempter" = xyes; then
|
||||||
AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
|
AC_CHECK_HEADER(utempter.h, enable_utempter=yes, enable_utempter=no)
|
||||||
@@ -333,9 +382,18 @@ fi
|
|||||||
# Look for utf8proc.
|
# Look for utf8proc.
|
||||||
AC_ARG_ENABLE(
|
AC_ARG_ENABLE(
|
||||||
utf8proc,
|
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
|
if test "x$enable_utf8proc" = xyes; then
|
||||||
|
PKG_CHECK_MODULES(
|
||||||
|
LIBUTF8PROC,
|
||||||
|
libutf8proc,
|
||||||
|
[
|
||||||
|
AM_CPPFLAGS="$LIBUTF8PROC_CFLAGS $AM_CPPFLAGS"
|
||||||
|
CPPFLAGS="$LIBUTF8PROC_CFLAGS $SAVED_CPPFLAGS"
|
||||||
|
LIBS="$LIBUTF8PROC_LIBS $LIBS"
|
||||||
|
]
|
||||||
|
)
|
||||||
AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
|
AC_CHECK_HEADER(utf8proc.h, enable_utf8proc=yes, enable_utf8proc=no)
|
||||||
if test "x$enable_utf8proc" = xyes; then
|
if test "x$enable_utf8proc" = xyes; then
|
||||||
AC_SEARCH_LIBS(
|
AC_SEARCH_LIBS(
|
||||||
@@ -353,15 +411,67 @@ if test "x$enable_utf8proc" = xyes; then
|
|||||||
fi
|
fi
|
||||||
AM_CONDITIONAL(HAVE_UTF8PROC, [test "x$enable_utf8proc" = xyes])
|
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])
|
||||||
|
AC_ARG_ENABLE(
|
||||||
|
cgroups,
|
||||||
|
AS_HELP_STRING(--disable-cgroups, disable adding panes to new cgroups with systemd)
|
||||||
|
)
|
||||||
|
if test "x$enable_cgroups" = x; then
|
||||||
|
# Default to the same as $enable_systemd.
|
||||||
|
enable_cgroups=$enable_systemd
|
||||||
|
fi
|
||||||
|
if test "x$enable_cgroups" = xyes; then
|
||||||
|
if test "x$found_systemd" = xyes; then
|
||||||
|
AC_DEFINE(ENABLE_CGROUPS)
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR("cgroups requires systemd to be enabled")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable sixel support.
|
||||||
|
AC_ARG_ENABLE(
|
||||||
|
sixel,
|
||||||
|
AS_HELP_STRING(--enable-sixel, enable sixel images)
|
||||||
|
)
|
||||||
|
if test "x$enable_sixel" = xyes; then
|
||||||
|
AC_DEFINE(ENABLE_SIXEL)
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])
|
||||||
|
|
||||||
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
|
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
|
||||||
AC_MSG_CHECKING(for b64_ntop)
|
AC_MSG_CHECKING(for b64_ntop)
|
||||||
AC_TRY_LINK(
|
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||||
[
|
[
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
],
|
],
|
||||||
[b64_ntop(NULL, 0, NULL, 0);],
|
[
|
||||||
|
b64_ntop(NULL, 0, NULL, 0);
|
||||||
|
])],
|
||||||
found_b64_ntop=yes,
|
found_b64_ntop=yes,
|
||||||
found_b64_ntop=no
|
found_b64_ntop=no
|
||||||
)
|
)
|
||||||
@@ -370,13 +480,15 @@ OLD_LIBS="$LIBS"
|
|||||||
if test "x$found_b64_ntop" = xno; then
|
if test "x$found_b64_ntop" = xno; then
|
||||||
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
||||||
LIBS="$OLD_LIBS -lresolv"
|
LIBS="$OLD_LIBS -lresolv"
|
||||||
AC_TRY_LINK(
|
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||||
[
|
[
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
],
|
],
|
||||||
[b64_ntop(NULL, 0, NULL, 0);],
|
[
|
||||||
|
b64_ntop(NULL, 0, NULL, 0);
|
||||||
|
])],
|
||||||
found_b64_ntop=yes,
|
found_b64_ntop=yes,
|
||||||
found_b64_ntop=no
|
found_b64_ntop=no
|
||||||
)
|
)
|
||||||
@@ -385,13 +497,15 @@ fi
|
|||||||
if test "x$found_b64_ntop" = xno; then
|
if test "x$found_b64_ntop" = xno; then
|
||||||
AC_MSG_CHECKING(for b64_ntop with -lnetwork)
|
AC_MSG_CHECKING(for b64_ntop with -lnetwork)
|
||||||
LIBS="$OLD_LIBS -lnetwork"
|
LIBS="$OLD_LIBS -lnetwork"
|
||||||
AC_TRY_LINK(
|
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||||
[
|
[
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <resolv.h>
|
#include <resolv.h>
|
||||||
],
|
],
|
||||||
[b64_ntop(NULL, 0, NULL, 0);],
|
[
|
||||||
|
b64_ntop(NULL, 0, NULL, 0);
|
||||||
|
])],
|
||||||
found_b64_ntop=yes,
|
found_b64_ntop=yes,
|
||||||
found_b64_ntop=no
|
found_b64_ntop=no
|
||||||
)
|
)
|
||||||
@@ -588,7 +702,7 @@ AC_CHECK_DECL(
|
|||||||
)
|
)
|
||||||
AC_CHECK_DECL(
|
AC_CHECK_DECL(
|
||||||
TAILQ_PREV,
|
TAILQ_PREV,
|
||||||
found_queue_h=yes,
|
,
|
||||||
found_queue_h=no,
|
found_queue_h=no,
|
||||||
[#include <sys/queue.h>]
|
[#include <sys/queue.h>]
|
||||||
)
|
)
|
||||||
@@ -644,6 +758,14 @@ AC_CHECK_DECL(
|
|||||||
[#include <sys/prctl.h>]
|
[#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).
|
# Look for fcntl(F_CLOSEM).
|
||||||
AC_CHECK_DECL(
|
AC_CHECK_DECL(
|
||||||
F_CLOSEM,
|
F_CLOSEM,
|
||||||
@@ -661,6 +783,74 @@ else
|
|||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
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.
|
# Man page defaults to mdoc.
|
||||||
MANFORMAT=mdoc
|
MANFORMAT=mdoc
|
||||||
AC_SUBST(MANFORMAT)
|
AC_SUBST(MANFORMAT)
|
||||||
@@ -676,19 +866,32 @@ case "$host_os" in
|
|||||||
AC_MSG_RESULT(darwin)
|
AC_MSG_RESULT(darwin)
|
||||||
PLATFORM=darwin
|
PLATFORM=darwin
|
||||||
#
|
#
|
||||||
# OS X uses __dead2 instead of __dead, like FreeBSD. But it
|
# macOS uses __dead2 instead of __dead, like FreeBSD. But it defines
|
||||||
# defines __dead away so it needs to be removed before we can
|
# __dead away so it needs to be removed before we can replace it.
|
||||||
# replace it.
|
|
||||||
#
|
#
|
||||||
AC_DEFINE(BROKEN___DEAD)
|
AC_DEFINE(BROKEN___DEAD)
|
||||||
#
|
#
|
||||||
# OS X CMSG_FIRSTHDR is broken, so redefine it with a working
|
# macOS CMSG_FIRSTHDR is broken, so redefine it with a working one.
|
||||||
# one. daemon works but has some stupid side effects, so use
|
# daemon works but has some stupid side effects, so use our internal
|
||||||
# our internal version which has a workaround.
|
# version which has a workaround.
|
||||||
#
|
#
|
||||||
AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
|
AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
|
||||||
AC_LIBOBJ(daemon)
|
AC_LIBOBJ(daemon)
|
||||||
AC_LIBOBJ(daemon-darwin)
|
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*)
|
*dragonfly*)
|
||||||
AC_MSG_RESULT(dragonfly)
|
AC_MSG_RESULT(dragonfly)
|
||||||
@@ -758,6 +961,19 @@ AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
|
|||||||
AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
|
AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
|
||||||
AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
|
AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
|
||||||
|
|
||||||
|
# Set the default lock command
|
||||||
|
DEFAULT_LOCK_CMD="lock -np"
|
||||||
|
AC_MSG_CHECKING(lock-command)
|
||||||
|
if test "x$PLATFORM" = xlinux; then
|
||||||
|
AC_CHECK_PROG(found_vlock, vlock, yes, no)
|
||||||
|
if test "x$found_vlock" = xyes; then
|
||||||
|
DEFAULT_LOCK_CMD="vlock"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
AC_MSG_RESULT($DEFAULT_LOCK_CMD)
|
||||||
|
AC_SUBST(DEFAULT_LOCK_CMD)
|
||||||
|
|
||||||
|
|
||||||
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
|
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
|
||||||
# variables.
|
# variables.
|
||||||
AC_SUBST(AM_CPPFLAGS)
|
AC_SUBST(AM_CPPFLAGS)
|
||||||
@@ -768,4 +984,5 @@ AC_SUBST(AM_LDFLAGS)
|
|||||||
LDFLAGS="$SAVED_LDFLAGS"
|
LDFLAGS="$SAVED_LDFLAGS"
|
||||||
|
|
||||||
# autoconf should create a Makefile.
|
# autoconf should create a Makefile.
|
||||||
AC_OUTPUT(Makefile)
|
AC_CONFIG_FILES(Makefile)
|
||||||
|
AC_OUTPUT
|
||||||
|
|||||||
@@ -234,3 +234,29 @@ control_notify_session_window_changed(struct session *s)
|
|||||||
s->curw->window->id);
|
s->curw->window->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
control_notify_paste_buffer_changed(const char *name)
|
||||||
|
{
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
|
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
control_write(c, "%%paste-buffer-changed %s", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
control_notify_paste_buffer_deleted(const char *name)
|
||||||
|
{
|
||||||
|
struct client *c;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
|
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
control_write(c, "%%paste-buffer-deleted %s", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
18
control.c
18
control.c
@@ -385,7 +385,7 @@ control_pause_pane(struct client *c, struct window_pane *wp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Write a line. */
|
/* Write a line. */
|
||||||
static void
|
static void printflike(2, 0)
|
||||||
control_vwrite(struct client *c, const char *fmt, va_list ap)
|
control_vwrite(struct client *c, const char *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
struct control_state *cs = c->control_state;
|
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();
|
uint64_t age, t = get_timer();
|
||||||
|
|
||||||
wp = control_window_pane(c, cp->pane);
|
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_FOREACH_SAFE(cb, &cp->blocks, entry, cb1) {
|
||||||
TAILQ_REMOVE(&cp->blocks, cb, entry);
|
TAILQ_REMOVE(&cp->blocks, cb, entry);
|
||||||
control_free_block(cs, cb);
|
control_free_block(cs, cb);
|
||||||
@@ -775,13 +775,16 @@ control_start(struct client *c)
|
|||||||
|
|
||||||
cs->read_event = bufferevent_new(c->fd, control_read_callback,
|
cs->read_event = bufferevent_new(c->fd, control_read_callback,
|
||||||
control_write_callback, control_error_callback, c);
|
control_write_callback, control_error_callback, c);
|
||||||
bufferevent_enable(cs->read_event, EV_READ);
|
if (cs->read_event == NULL)
|
||||||
|
fatalx("out of memory");
|
||||||
|
|
||||||
if (c->flags & CLIENT_CONTROLCONTROL)
|
if (c->flags & CLIENT_CONTROLCONTROL)
|
||||||
cs->write_event = cs->read_event;
|
cs->write_event = cs->read_event;
|
||||||
else {
|
else {
|
||||||
cs->write_event = bufferevent_new(c->out_fd, NULL,
|
cs->write_event = bufferevent_new(c->out_fd, NULL,
|
||||||
control_write_callback, control_error_callback, c);
|
control_write_callback, control_error_callback, c);
|
||||||
|
if (cs->write_event == NULL)
|
||||||
|
fatalx("out of memory");
|
||||||
}
|
}
|
||||||
bufferevent_setwatermark(cs->write_event, EV_WRITE, CONTROL_BUFFER_LOW,
|
bufferevent_setwatermark(cs->write_event, EV_WRITE, CONTROL_BUFFER_LOW,
|
||||||
0);
|
0);
|
||||||
@@ -792,6 +795,13 @@ control_start(struct client *c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Control client ready. */
|
||||||
|
void
|
||||||
|
control_ready(struct client *c)
|
||||||
|
{
|
||||||
|
bufferevent_enable(c->control_state->read_event, EV_READ);
|
||||||
|
}
|
||||||
|
|
||||||
/* Discard all output for a client. */
|
/* Discard all output for a client. */
|
||||||
void
|
void
|
||||||
control_discard(struct client *c)
|
control_discard(struct client *c)
|
||||||
@@ -864,7 +874,7 @@ control_check_subs_pane(struct client *c, struct control_sub *csub)
|
|||||||
struct control_sub_pane *csp, find;
|
struct control_sub_pane *csp, find;
|
||||||
|
|
||||||
wp = window_pane_find_by_id(csub->id);
|
wp = window_pane_find_by_id(csub->id);
|
||||||
if (wp == NULL)
|
if (wp == NULL || wp->fd == -1)
|
||||||
return;
|
return;
|
||||||
w = wp->window;
|
w = wp->window;
|
||||||
|
|
||||||
|
|||||||
15
environ.c
15
environ.c
@@ -182,9 +182,11 @@ void
|
|||||||
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||||
{
|
{
|
||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
|
struct environ_entry *envent1;
|
||||||
struct options_entry *o;
|
struct options_entry *o;
|
||||||
struct options_array_item *a;
|
struct options_array_item *a;
|
||||||
union options_value *ov;
|
union options_value *ov;
|
||||||
|
int found;
|
||||||
|
|
||||||
o = options_get(oo, "update-environment");
|
o = options_get(oo, "update-environment");
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
@@ -192,14 +194,15 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
|||||||
a = options_array_first(o);
|
a = options_array_first(o);
|
||||||
while (a != NULL) {
|
while (a != NULL) {
|
||||||
ov = options_array_item_value(a);
|
ov = options_array_item_value(a);
|
||||||
RB_FOREACH(envent, environ, src) {
|
found = 0;
|
||||||
if (fnmatch(ov->string, envent->name, 0) == 0)
|
RB_FOREACH_SAFE(envent, environ, src, envent1) {
|
||||||
break;
|
if (fnmatch(ov->string, envent->name, 0) == 0) {
|
||||||
|
environ_set(dst, envent->name, 0, "%s", envent->value);
|
||||||
|
found = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (envent == NULL)
|
if (!found)
|
||||||
environ_clear(dst, ov->string);
|
environ_clear(dst, ov->string);
|
||||||
else
|
|
||||||
environ_set(dst, envent->name, 0, "%s", envent->value);
|
|
||||||
a = options_array_next(a);
|
a = options_array_next(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
# should be started with "tmux attach" rather than "tmux new"
|
||||||
new -d -s0 -nirssi 'exec irssi'
|
new -d -s0 -nirssi 'exec irssi'
|
||||||
set -t0:0 monitor-activity on
|
set -t0:0 monitor-activity on
|
||||||
set -t0:0 aggressive-resize on
|
set -t0:0 aggressive-resize on
|
||||||
neww -d -ntodo 'exec emacs ~/TODO'
|
neww -d -ntodo 'exec emacs ~/TODO'
|
||||||
setw -t0:1 aggressive-resize on
|
setw -t0:1 aggressive-resize on
|
||||||
neww -d -nmutt 'exec mutt'
|
neww -d -nmutt 'exec mutt'
|
||||||
|
|||||||
64
file.c
64
file.c
@@ -149,7 +149,8 @@ file_fire_done_cb(__unused int fd, __unused short events, void *arg)
|
|||||||
struct client_file *cf = arg;
|
struct client_file *cf = arg;
|
||||||
struct client *c = cf->c;
|
struct client *c = cf->c;
|
||||||
|
|
||||||
if (cf->cb != NULL && (c == NULL || (~c->flags & CLIENT_DEAD)))
|
if (cf->cb != NULL &&
|
||||||
|
(cf->closed || c == NULL || (~c->flags & CLIENT_DEAD)))
|
||||||
cf->cb(c, cf->path, cf->error, 1, cf->buffer, cf->data);
|
cf->cb(c, cf->path, cf->error, 1, cf->buffer, cf->data);
|
||||||
file_free(cf);
|
file_free(cf);
|
||||||
}
|
}
|
||||||
@@ -173,9 +174,9 @@ file_fire_read(struct client_file *cf)
|
|||||||
int
|
int
|
||||||
file_can_print(struct client *c)
|
file_can_print(struct client *c)
|
||||||
{
|
{
|
||||||
if (c == NULL)
|
if (c == NULL ||
|
||||||
return (0);
|
(c->flags & CLIENT_ATTACHED) ||
|
||||||
if (c->session != NULL && (~c->flags & CLIENT_CONTROL))
|
(c->flags & CLIENT_CONTROL))
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
@@ -352,7 +353,7 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Read a file. */
|
/* Read a file. */
|
||||||
void
|
struct client_file *
|
||||||
file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
|
file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
|
||||||
{
|
{
|
||||||
struct client_file *cf;
|
struct client_file *cf;
|
||||||
@@ -420,10 +421,27 @@ skip:
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
free(msg);
|
free(msg);
|
||||||
return;
|
return cf;
|
||||||
|
|
||||||
done:
|
done:
|
||||||
file_fire_done(cf);
|
file_fire_done(cf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cancel a file read. */
|
||||||
|
void
|
||||||
|
file_cancel(struct client_file *cf)
|
||||||
|
{
|
||||||
|
struct msg_read_cancel msg;
|
||||||
|
|
||||||
|
log_debug("read cancel file %d", cf->stream);
|
||||||
|
|
||||||
|
if (cf->closed)
|
||||||
|
return;
|
||||||
|
cf->closed = 1;
|
||||||
|
|
||||||
|
msg.stream = cf->stream;
|
||||||
|
proc_send(cf->peer, MSG_READ_CANCEL, -1, &msg, sizeof msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Push event, fired if there is more writing to be done. */
|
/* Push event, fired if there is more writing to be done. */
|
||||||
@@ -503,14 +521,14 @@ file_write_error_callback(__unused struct bufferevent *bev, __unused short what,
|
|||||||
|
|
||||||
log_debug("write error file %d", cf->stream);
|
log_debug("write error file %d", cf->stream);
|
||||||
|
|
||||||
if (cf->cb != NULL)
|
|
||||||
cf->cb(NULL, NULL, 0, -1, NULL, cf->data);
|
|
||||||
|
|
||||||
bufferevent_free(cf->event);
|
bufferevent_free(cf->event);
|
||||||
cf->event = NULL;
|
cf->event = NULL;
|
||||||
|
|
||||||
close(cf->fd);
|
close(cf->fd);
|
||||||
cf->fd = -1;
|
cf->fd = -1;
|
||||||
|
|
||||||
|
if (cf->cb != NULL)
|
||||||
|
cf->cb(NULL, NULL, 0, -1, NULL, cf->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Client file write callback. */
|
/* Client file write callback. */
|
||||||
@@ -555,7 +573,7 @@ file_write_open(struct client_files *files, struct tmuxpeer *peer,
|
|||||||
log_debug("open write file %d %s", msg->stream, path);
|
log_debug("open write file %d %s", msg->stream, path);
|
||||||
|
|
||||||
find.stream = msg->stream;
|
find.stream = msg->stream;
|
||||||
if ((cf = RB_FIND(client_files, files, &find)) != NULL) {
|
if (RB_FIND(client_files, files, &find) != NULL) {
|
||||||
error = EBADF;
|
error = EBADF;
|
||||||
goto reply;
|
goto reply;
|
||||||
}
|
}
|
||||||
@@ -585,6 +603,8 @@ file_write_open(struct client_files *files, struct tmuxpeer *peer,
|
|||||||
|
|
||||||
cf->event = bufferevent_new(cf->fd, NULL, file_write_callback,
|
cf->event = bufferevent_new(cf->fd, NULL, file_write_callback,
|
||||||
file_write_error_callback, cf);
|
file_write_error_callback, cf);
|
||||||
|
if (cf->event == NULL)
|
||||||
|
fatalx("out of memory");
|
||||||
bufferevent_enable(cf->event, EV_WRITE);
|
bufferevent_enable(cf->event, EV_WRITE);
|
||||||
goto reply;
|
goto reply;
|
||||||
|
|
||||||
@@ -714,7 +734,7 @@ file_read_open(struct client_files *files, struct tmuxpeer *peer,
|
|||||||
log_debug("open read file %d %s", msg->stream, path);
|
log_debug("open read file %d %s", msg->stream, path);
|
||||||
|
|
||||||
find.stream = msg->stream;
|
find.stream = msg->stream;
|
||||||
if ((cf = RB_FIND(client_files, files, &find)) != NULL) {
|
if (RB_FIND(client_files, files, &find) != NULL) {
|
||||||
error = EBADF;
|
error = EBADF;
|
||||||
goto reply;
|
goto reply;
|
||||||
}
|
}
|
||||||
@@ -744,6 +764,8 @@ file_read_open(struct client_files *files, struct tmuxpeer *peer,
|
|||||||
|
|
||||||
cf->event = bufferevent_new(cf->fd, file_read_callback, NULL,
|
cf->event = bufferevent_new(cf->fd, file_read_callback, NULL,
|
||||||
file_read_error_callback, cf);
|
file_read_error_callback, cf);
|
||||||
|
if (cf->event == NULL)
|
||||||
|
fatalx("out of memory");
|
||||||
bufferevent_enable(cf->event, EV_READ);
|
bufferevent_enable(cf->event, EV_READ);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -753,6 +775,24 @@ reply:
|
|||||||
proc_send(peer, MSG_READ_DONE, -1, &reply, sizeof reply);
|
proc_send(peer, MSG_READ_DONE, -1, &reply, sizeof reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Handle a read cancel message (client). */
|
||||||
|
void
|
||||||
|
file_read_cancel(struct client_files *files, struct imsg *imsg)
|
||||||
|
{
|
||||||
|
struct msg_read_cancel *msg = imsg->data;
|
||||||
|
size_t msglen = imsg->hdr.len - IMSG_HEADER_SIZE;
|
||||||
|
struct client_file find, *cf;
|
||||||
|
|
||||||
|
if (msglen != sizeof *msg)
|
||||||
|
fatalx("bad MSG_READ_CANCEL size");
|
||||||
|
find.stream = msg->stream;
|
||||||
|
if ((cf = RB_FIND(client_files, files, &find)) == NULL)
|
||||||
|
fatalx("unknown stream number");
|
||||||
|
log_debug("cancel file %d", cf->stream);
|
||||||
|
|
||||||
|
file_read_error_callback(NULL, 0, cf);
|
||||||
|
}
|
||||||
|
|
||||||
/* Handle a write ready message (server). */
|
/* Handle a write ready message (server). */
|
||||||
void
|
void
|
||||||
file_write_ready(struct client_files *files, struct imsg *imsg)
|
file_write_ready(struct client_files *files, struct imsg *imsg)
|
||||||
@@ -790,7 +830,7 @@ file_read_data(struct client_files *files, struct imsg *imsg)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
log_debug("file %d read %zu bytes", cf->stream, bsize);
|
log_debug("file %d read %zu bytes", cf->stream, bsize);
|
||||||
if (cf->error == 0) {
|
if (cf->error == 0 && !cf->closed) {
|
||||||
if (evbuffer_add(cf->buffer, bdata, bsize) != 0) {
|
if (evbuffer_add(cf->buffer, bdata, bsize) != 0) {
|
||||||
cf->error = ENOMEM;
|
cf->error = ENOMEM;
|
||||||
file_fire_done(cf);
|
file_fire_done(cf);
|
||||||
|
|||||||
258
format-draw.c
258
format-draw.c
@@ -33,6 +33,7 @@ struct format_range {
|
|||||||
|
|
||||||
enum style_range_type type;
|
enum style_range_type type;
|
||||||
u_int argument;
|
u_int argument;
|
||||||
|
char string[16];
|
||||||
|
|
||||||
TAILQ_ENTRY(format_range) entry;
|
TAILQ_ENTRY(format_range) entry;
|
||||||
};
|
};
|
||||||
@@ -44,9 +45,18 @@ format_is_type(struct format_range *fr, struct style *sy)
|
|||||||
{
|
{
|
||||||
if (fr->type != sy->range_type)
|
if (fr->type != sy->range_type)
|
||||||
return (0);
|
return (0);
|
||||||
if (fr->type == STYLE_RANGE_WINDOW &&
|
switch (fr->type) {
|
||||||
fr->argument != sy->range_argument)
|
case STYLE_RANGE_NONE:
|
||||||
return (0);
|
case STYLE_RANGE_LEFT:
|
||||||
|
case STYLE_RANGE_RIGHT:
|
||||||
|
return (1);
|
||||||
|
case STYLE_RANGE_PANE:
|
||||||
|
case STYLE_RANGE_WINDOW:
|
||||||
|
case STYLE_RANGE_SESSION:
|
||||||
|
return (fr->argument == sy->range_argument);
|
||||||
|
case STYLE_RANGE_USER:
|
||||||
|
return (strcmp(fr->string, sy->range_string) == 0);
|
||||||
|
}
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,6 +642,36 @@ format_draw_absolute_centre(struct screen_write_ctx *octx, u_int available,
|
|||||||
width_after);
|
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. */
|
/* Draw multiple characters. */
|
||||||
static void
|
static void
|
||||||
format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch,
|
format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch,
|
||||||
@@ -647,7 +687,8 @@ format_draw_many(struct screen_write_ctx *ctx, struct style *sy, char ch,
|
|||||||
/* Draw a format to a screen. */
|
/* Draw a format to a screen. */
|
||||||
void
|
void
|
||||||
format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
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,
|
enum { LEFT,
|
||||||
CENTRE,
|
CENTRE,
|
||||||
@@ -789,6 +830,10 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
|||||||
log_debug("%s: style '%s' -> '%s'", __func__, tmp,
|
log_debug("%s: style '%s' -> '%s'", __func__, tmp,
|
||||||
style_tostring(&sy));
|
style_tostring(&sy));
|
||||||
free(tmp);
|
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 this style has a fill colour, store it for later. */
|
||||||
if (sy.fill != 8)
|
if (sy.fill != 8)
|
||||||
@@ -907,6 +952,8 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
|||||||
|
|
||||||
fr->type = sy.range_type;
|
fr->type = sy.range_type;
|
||||||
fr->argument = sy.range_argument;
|
fr->argument = sy.range_argument;
|
||||||
|
strlcpy(fr->string, sy.range_string,
|
||||||
|
sizeof fr->string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,13 +1025,39 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
|||||||
sr = xcalloc(1, sizeof *sr);
|
sr = xcalloc(1, sizeof *sr);
|
||||||
sr->type = fr->type;
|
sr->type = fr->type;
|
||||||
sr->argument = fr->argument;
|
sr->argument = fr->argument;
|
||||||
|
strlcpy(sr->string, fr->string, sizeof sr->string);
|
||||||
sr->start = fr->start;
|
sr->start = fr->start;
|
||||||
sr->end = fr->end;
|
sr->end = fr->end;
|
||||||
TAILQ_INSERT_TAIL(srs, sr, entry);
|
TAILQ_INSERT_TAIL(srs, sr, entry);
|
||||||
|
|
||||||
log_debug("%s: range %d|%u at %u-%u", __func__, sr->type,
|
switch (sr->type) {
|
||||||
sr->argument, sr->start, sr->end);
|
case STYLE_RANGE_NONE:
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_LEFT:
|
||||||
|
log_debug("%s: range left at %u-%u", __func__,
|
||||||
|
sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_RIGHT:
|
||||||
|
log_debug("%s: range right at %u-%u", __func__,
|
||||||
|
sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_PANE:
|
||||||
|
log_debug("%s: range pane|%%%u at %u-%u", __func__,
|
||||||
|
sr->argument, sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_WINDOW:
|
||||||
|
log_debug("%s: range window|%u at %u-%u", __func__,
|
||||||
|
sr->argument, sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_SESSION:
|
||||||
|
log_debug("%s: range session|$%u at %u-%u", __func__,
|
||||||
|
sr->argument, sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
case STYLE_RANGE_USER:
|
||||||
|
log_debug("%s: range user|%u at %u-%u", __func__,
|
||||||
|
sr->argument, sr->start, sr->end);
|
||||||
|
break;
|
||||||
|
}
|
||||||
format_free_range(&frs, fr);
|
format_free_range(&frs, fr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1002,37 +1075,22 @@ u_int
|
|||||||
format_width(const char *expanded)
|
format_width(const char *expanded)
|
||||||
{
|
{
|
||||||
const char *cp, *end;
|
const char *cp, *end;
|
||||||
u_int n, width = 0;
|
u_int n, leading_width, width = 0;
|
||||||
struct utf8_data ud;
|
struct utf8_data ud;
|
||||||
enum utf8_state more;
|
enum utf8_state more;
|
||||||
|
|
||||||
cp = expanded;
|
cp = expanded;
|
||||||
while (*cp != '\0') {
|
while (*cp != '\0') {
|
||||||
if (*cp == '#') {
|
if (*cp == '#') {
|
||||||
for (n = 1; cp[n] == '#'; n++)
|
end = format_leading_hashes(cp, &n, &leading_width);
|
||||||
/* nothing */;
|
width += leading_width;
|
||||||
if (cp[n] != '[') {
|
cp = end;
|
||||||
width += n;
|
if (*cp == '#') {
|
||||||
cp += n;
|
end = format_skip(cp + 2, "]");
|
||||||
continue;
|
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) {
|
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||||
while (*++cp != '\0' && more == UTF8_MORE)
|
while (*++cp != '\0' && more == UTF8_MORE)
|
||||||
more = utf8_append(&ud, *cp);
|
more = utf8_append(&ud, *cp);
|
||||||
@@ -1059,53 +1117,36 @@ format_trim_left(const char *expanded, u_int limit)
|
|||||||
{
|
{
|
||||||
char *copy, *out;
|
char *copy, *out;
|
||||||
const char *cp = expanded, *end;
|
const char *cp = expanded, *end;
|
||||||
u_int even, n, width = 0;
|
u_int n, width = 0, leading_width;
|
||||||
struct utf8_data ud;
|
struct utf8_data ud;
|
||||||
enum utf8_state more;
|
enum utf8_state more;
|
||||||
|
|
||||||
out = copy = xcalloc(1, strlen(expanded) + 1);
|
out = copy = xcalloc(2, strlen(expanded) + 1);
|
||||||
while (*cp != '\0') {
|
while (*cp != '\0') {
|
||||||
if (width >= limit)
|
if (width >= limit)
|
||||||
break;
|
break;
|
||||||
if (*cp == '#') {
|
if (*cp == '#') {
|
||||||
for (end = cp + 1; *end == '#'; end++)
|
end = format_leading_hashes(cp, &n, &leading_width);
|
||||||
/* nothing */;
|
if (leading_width > limit - width)
|
||||||
n = end - cp;
|
leading_width = limit - width;
|
||||||
if (*end != '[') {
|
if (leading_width != 0) {
|
||||||
if (n > limit - width)
|
if (n == 1)
|
||||||
n = limit - width;
|
*out++ = '#';
|
||||||
memcpy(out, cp, n);
|
else {
|
||||||
out += n;
|
memset(out, '#', 2 * leading_width);
|
||||||
width += n;
|
out += 2 * leading_width;
|
||||||
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++;
|
|
||||||
}
|
}
|
||||||
cp = end + 1;
|
width += leading_width;
|
||||||
continue;
|
}
|
||||||
|
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) {
|
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||||
while (*++cp != '\0' && more == UTF8_MORE)
|
while (*++cp != '\0' && more == UTF8_MORE)
|
||||||
more = utf8_append(&ud, *cp);
|
more = utf8_append(&ud, *cp);
|
||||||
@@ -1137,7 +1178,8 @@ format_trim_right(const char *expanded, u_int limit)
|
|||||||
{
|
{
|
||||||
char *copy, *out;
|
char *copy, *out;
|
||||||
const char *cp = expanded, *end;
|
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;
|
struct utf8_data ud;
|
||||||
enum utf8_state more;
|
enum utf8_state more;
|
||||||
|
|
||||||
@@ -1146,67 +1188,35 @@ format_trim_right(const char *expanded, u_int limit)
|
|||||||
return (xstrdup(expanded));
|
return (xstrdup(expanded));
|
||||||
skip = total_width - limit;
|
skip = total_width - limit;
|
||||||
|
|
||||||
out = copy = xcalloc(1, strlen(expanded) + 1);
|
out = copy = xcalloc(2, strlen(expanded) + 1);
|
||||||
while (*cp != '\0') {
|
while (*cp != '\0') {
|
||||||
if (*cp == '#') {
|
if (*cp == '#') {
|
||||||
for (end = cp + 1; *end == '#'; end++)
|
end = format_leading_hashes(cp, &n, &leading_width);
|
||||||
/* nothing */;
|
copy_width = leading_width;
|
||||||
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;
|
|
||||||
if (width <= skip) {
|
if (width <= skip) {
|
||||||
if (skip - width >= n)
|
if (skip - width >= copy_width)
|
||||||
n = 0;
|
copy_width = 0;
|
||||||
else
|
else
|
||||||
n -= (skip - width);
|
copy_width -= (skip - width);
|
||||||
}
|
}
|
||||||
if (n != 0) {
|
if (copy_width != 0) {
|
||||||
/*
|
if (n == 1)
|
||||||
* Copy the full amount because it hasn't been
|
*out++ = '#';
|
||||||
* escaped yet.
|
else {
|
||||||
*/
|
memset(out, '#', 2 * copy_width);
|
||||||
memcpy(out, cp, old_n);
|
out += 2 * copy_width;
|
||||||
out += old_n;
|
}
|
||||||
}
|
}
|
||||||
cp += old_n;
|
width += leading_width;
|
||||||
width += (old_n / 2) - even;
|
cp = end;
|
||||||
|
if (*cp == '#') {
|
||||||
if (even) {
|
end = format_skip(cp + 2, "]");
|
||||||
if (width > skip)
|
if (end == NULL)
|
||||||
*out++ = '[';
|
break;
|
||||||
width++;
|
memcpy(out, cp, end + 1 - cp);
|
||||||
continue;
|
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) {
|
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||||
while (*++cp != '\0' && more == UTF8_MORE)
|
while (*++cp != '\0' && more == UTF8_MORE)
|
||||||
more = utf8_append(&ud, *cp);
|
more = utf8_append(&ud, *cp);
|
||||||
|
|||||||
503
format.c
503
format.c
@@ -24,6 +24,7 @@
|
|||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <pwd.h>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -101,9 +102,11 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
|
|||||||
#define FORMAT_WINDOW_NAME 0x4000
|
#define FORMAT_WINDOW_NAME 0x4000
|
||||||
#define FORMAT_SESSION_NAME 0x8000
|
#define FORMAT_SESSION_NAME 0x8000
|
||||||
#define FORMAT_CHARACTER 0x10000
|
#define FORMAT_CHARACTER 0x10000
|
||||||
|
#define FORMAT_COLOUR 0x20000
|
||||||
|
#define FORMAT_CLIENTS 0x40000
|
||||||
|
|
||||||
/* Limit on recursion. */
|
/* Limit on recursion. */
|
||||||
#define FORMAT_LOOP_LIMIT 10
|
#define FORMAT_LOOP_LIMIT 100
|
||||||
|
|
||||||
/* Format expand flags. */
|
/* Format expand flags. */
|
||||||
#define FORMAT_EXPAND_TIME 0x1
|
#define FORMAT_EXPAND_TIME 0x1
|
||||||
@@ -371,9 +374,6 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
|||||||
fj->client = ft->client;
|
fj->client = ft->client;
|
||||||
fj->tag = ft->tag;
|
fj->tag = ft->tag;
|
||||||
fj->cmd = xstrdup(cmd);
|
fj->cmd = xstrdup(cmd);
|
||||||
fj->expanded = NULL;
|
|
||||||
|
|
||||||
xasprintf(&fj->out, "<'%s' not ready>", fj->cmd);
|
|
||||||
|
|
||||||
RB_INSERT(format_job_tree, jobs, fj);
|
RB_INSERT(format_job_tree, jobs, fj);
|
||||||
}
|
}
|
||||||
@@ -393,7 +393,7 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
|||||||
if (force && fj->job != NULL)
|
if (force && fj->job != NULL)
|
||||||
job_free(fj->job);
|
job_free(fj->job);
|
||||||
if (force || (fj->job == NULL && fj->last != t)) {
|
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,
|
server_client_get_cwd(ft->client, NULL), format_job_update,
|
||||||
format_job_complete, NULL, fj, JOB_NOWAIT, -1, -1);
|
format_job_complete, NULL, fj, JOB_NOWAIT, -1, -1);
|
||||||
if (fj->job == NULL) {
|
if (fj->job == NULL) {
|
||||||
@@ -402,11 +402,14 @@ format_job_get(struct format_expand_state *es, const char *cmd)
|
|||||||
}
|
}
|
||||||
fj->last = t;
|
fj->last = t;
|
||||||
fj->updated = 0;
|
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);
|
free(expanded);
|
||||||
|
|
||||||
if (ft->flags & FORMAT_STATUS)
|
if (ft->flags & FORMAT_STATUS)
|
||||||
fj->status = 1;
|
fj->status = 1;
|
||||||
|
if (fj->out == NULL)
|
||||||
|
return (xstrdup(""));
|
||||||
return (format_expand1(&next, fj->out));
|
return (format_expand1(&next, fj->out));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -799,6 +802,20 @@ format_cb_start_command(struct format_tree *ft)
|
|||||||
return (cmd_stringify_argv(wp->argc, wp->argv));
|
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. */
|
/* Callback for pane_current_command. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_current_command(struct format_tree *ft)
|
format_cb_current_command(struct format_tree *ft)
|
||||||
@@ -929,6 +946,9 @@ format_cb_pane_fg(struct format_tree *ft)
|
|||||||
struct window_pane *wp = ft->wp;
|
struct window_pane *wp = ft->wp;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
|
|
||||||
|
if (wp == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
tty_default_colours(&gc, wp);
|
tty_default_colours(&gc, wp);
|
||||||
return (xstrdup(colour_tostring(gc.fg)));
|
return (xstrdup(colour_tostring(gc.fg)));
|
||||||
}
|
}
|
||||||
@@ -940,6 +960,9 @@ format_cb_pane_bg(struct format_tree *ft)
|
|||||||
struct window_pane *wp = ft->wp;
|
struct window_pane *wp = ft->wp;
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
|
|
||||||
|
if (wp == NULL)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
tty_default_colours(&gc, wp);
|
tty_default_colours(&gc, wp);
|
||||||
return (xstrdup(colour_tostring(gc.bg)));
|
return (xstrdup(colour_tostring(gc.bg)));
|
||||||
}
|
}
|
||||||
@@ -1103,7 +1126,6 @@ format_cb_mouse_word(struct format_tree *ft)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
struct grid *gd;
|
struct grid *gd;
|
||||||
u_int x, y;
|
u_int x, y;
|
||||||
char *s;
|
|
||||||
|
|
||||||
if (!ft->m.valid)
|
if (!ft->m.valid)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
@@ -1116,13 +1138,32 @@ format_cb_mouse_word(struct format_tree *ft)
|
|||||||
if (!TAILQ_EMPTY(&wp->modes)) {
|
if (!TAILQ_EMPTY(&wp->modes)) {
|
||||||
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode ||
|
if (TAILQ_FIRST(&wp->modes)->mode == &window_copy_mode ||
|
||||||
TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
|
TAILQ_FIRST(&wp->modes)->mode == &window_view_mode)
|
||||||
return (s = window_copy_get_word(wp, x, y));
|
return (window_copy_get_word(wp, x, y));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
gd = wp->base.grid;
|
gd = wp->base.grid;
|
||||||
return (format_grid_word(gd, x, gd->hsize + y));
|
return (format_grid_word(gd, x, gd->hsize + y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Callback for mouse_hyperlink. */
|
||||||
|
static void *
|
||||||
|
format_cb_mouse_hyperlink(struct format_tree *ft)
|
||||||
|
{
|
||||||
|
struct window_pane *wp;
|
||||||
|
struct grid *gd;
|
||||||
|
u_int x, y;
|
||||||
|
|
||||||
|
if (!ft->m.valid)
|
||||||
|
return (NULL);
|
||||||
|
wp = cmd_mouse_pane(&ft->m, NULL, NULL);
|
||||||
|
if (wp == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (cmd_mouse_at(wp, &ft->m, &x, &y, 0) != 0)
|
||||||
|
return (NULL);
|
||||||
|
gd = wp->base.grid;
|
||||||
|
return (format_grid_hyperlink(gd, x, gd->hsize + y, wp->screen));
|
||||||
|
}
|
||||||
|
|
||||||
/* Callback for mouse_line. */
|
/* Callback for mouse_line. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_mouse_line(struct format_tree *ft)
|
format_cb_mouse_line(struct format_tree *ft)
|
||||||
@@ -1149,6 +1190,72 @@ format_cb_mouse_line(struct format_tree *ft)
|
|||||||
return (format_grid_line(gd, gd->hsize + y));
|
return (format_grid_line(gd, gd->hsize + y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Callback for mouse_status_line. */
|
||||||
|
static void *
|
||||||
|
format_cb_mouse_status_line(struct format_tree *ft)
|
||||||
|
{
|
||||||
|
char *value;
|
||||||
|
u_int y;
|
||||||
|
|
||||||
|
if (!ft->m.valid)
|
||||||
|
return (NULL);
|
||||||
|
if (ft->c == NULL || (~ft->c->tty.flags & TTY_STARTED))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines) {
|
||||||
|
y = ft->m.y;
|
||||||
|
} else if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat) {
|
||||||
|
y = ft->m.y - ft->m.statusat;
|
||||||
|
} else
|
||||||
|
return (NULL);
|
||||||
|
xasprintf(&value, "%u", y);
|
||||||
|
return (value);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Callback for mouse_status_range. */
|
||||||
|
static void *
|
||||||
|
format_cb_mouse_status_range(struct format_tree *ft)
|
||||||
|
{
|
||||||
|
struct style_range *sr;
|
||||||
|
u_int x, y;
|
||||||
|
|
||||||
|
if (!ft->m.valid)
|
||||||
|
return (NULL);
|
||||||
|
if (ft->c == NULL || (~ft->c->tty.flags & TTY_STARTED))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if (ft->m.statusat == 0 && ft->m.y < ft->m.statuslines) {
|
||||||
|
x = ft->m.x;
|
||||||
|
y = ft->m.y;
|
||||||
|
} else if (ft->m.statusat > 0 && ft->m.y >= (u_int)ft->m.statusat) {
|
||||||
|
x = ft->m.x;
|
||||||
|
y = ft->m.y - ft->m.statusat;
|
||||||
|
} else
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
sr = status_get_range(ft->c, x, y);
|
||||||
|
if (sr == NULL)
|
||||||
|
return (NULL);
|
||||||
|
switch (sr->type) {
|
||||||
|
case STYLE_RANGE_NONE:
|
||||||
|
return (NULL);
|
||||||
|
case STYLE_RANGE_LEFT:
|
||||||
|
return (xstrdup("left"));
|
||||||
|
case STYLE_RANGE_RIGHT:
|
||||||
|
return (xstrdup("right"));
|
||||||
|
case STYLE_RANGE_PANE:
|
||||||
|
return (xstrdup("pane"));
|
||||||
|
case STYLE_RANGE_WINDOW:
|
||||||
|
return (xstrdup("window"));
|
||||||
|
case STYLE_RANGE_SESSION:
|
||||||
|
return (xstrdup("session"));
|
||||||
|
case STYLE_RANGE_USER:
|
||||||
|
return (xstrdup(sr->string));
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Callback for alternate_on. */
|
/* Callback for alternate_on. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_alternate_on(struct format_tree *ft)
|
format_cb_alternate_on(struct format_tree *ft)
|
||||||
@@ -1380,6 +1487,35 @@ format_cb_client_tty(struct format_tree *ft)
|
|||||||
return (NULL);
|
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. */
|
/* Callback for client_utf8. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_client_utf8(struct format_tree *ft)
|
format_cb_client_utf8(struct format_tree *ft)
|
||||||
@@ -1608,11 +1744,16 @@ format_cb_mouse_x(struct format_tree *ft)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int x, y;
|
u_int x, y;
|
||||||
|
|
||||||
if (ft->m.valid) {
|
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));
|
|
||||||
return (NULL);
|
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);
|
return (NULL);
|
||||||
}
|
}
|
||||||
@@ -1624,15 +1765,27 @@ format_cb_mouse_y(struct format_tree *ft)
|
|||||||
struct window_pane *wp;
|
struct window_pane *wp;
|
||||||
u_int x, y;
|
u_int x, y;
|
||||||
|
|
||||||
if (ft->m.valid) {
|
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));
|
|
||||||
return (NULL);
|
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);
|
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. */
|
/* Callback for origin_flag. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_origin_flag(struct format_tree *ft)
|
format_cb_origin_flag(struct format_tree *ft)
|
||||||
@@ -1702,6 +1855,23 @@ format_cb_pane_dead(struct format_tree *ft)
|
|||||||
return (NULL);
|
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. */
|
/* Callback for pane_dead_status. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_pane_dead_status(struct format_tree *ft)
|
format_cb_pane_dead_status(struct format_tree *ft)
|
||||||
@@ -1716,6 +1886,20 @@ format_cb_pane_dead_status(struct format_tree *ft)
|
|||||||
return (NULL);
|
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. */
|
/* Callback for pane_format. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_pane_format(struct format_tree *ft)
|
format_cb_pane_format(struct format_tree *ft)
|
||||||
@@ -1766,12 +1950,24 @@ format_cb_pane_input_off(struct format_tree *ft)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Callback for pane_unseen_changes. */
|
||||||
|
static void *
|
||||||
|
format_cb_pane_unseen_changes(struct format_tree *ft)
|
||||||
|
{
|
||||||
|
if (ft->wp != NULL) {
|
||||||
|
if (ft->wp->flags & PANE_UNSEENCHANGES)
|
||||||
|
return (xstrdup("1"));
|
||||||
|
return (xstrdup("0"));
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Callback for pane_last. */
|
/* Callback for pane_last. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_pane_last(struct format_tree *ft)
|
format_cb_pane_last(struct format_tree *ft)
|
||||||
{
|
{
|
||||||
if (ft->wp != NULL) {
|
if (ft->wp != NULL) {
|
||||||
if (ft->wp == ft->wp->window->last)
|
if (ft->wp == TAILQ_FIRST(&ft->wp->window->last_panes))
|
||||||
return (xstrdup("1"));
|
return (xstrdup("1"));
|
||||||
return (xstrdup("0"));
|
return (xstrdup("0"));
|
||||||
}
|
}
|
||||||
@@ -1946,6 +2142,18 @@ format_cb_scroll_region_upper(struct format_tree *ft)
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Callback for server_sessions. */
|
||||||
|
static void *
|
||||||
|
format_cb_server_sessions(__unused struct format_tree *ft)
|
||||||
|
{
|
||||||
|
struct session *s;
|
||||||
|
u_int n = 0;
|
||||||
|
|
||||||
|
RB_FOREACH(s, sessions, &sessions)
|
||||||
|
n++;
|
||||||
|
return (format_printf("%u", n));
|
||||||
|
}
|
||||||
|
|
||||||
/* Callback for session_attached. */
|
/* Callback for session_attached. */
|
||||||
static void *
|
static void *
|
||||||
format_cb_session_attached(struct format_tree *ft)
|
format_cb_session_attached(struct format_tree *ft)
|
||||||
@@ -2079,7 +2287,7 @@ static void *
|
|||||||
format_cb_session_windows(struct format_tree *ft)
|
format_cb_session_windows(struct format_tree *ft)
|
||||||
{
|
{
|
||||||
if (ft->s != NULL)
|
if (ft->s != NULL)
|
||||||
return (format_printf ("%u", winlink_count(&ft->s->windows)));
|
return (format_printf("%u", winlink_count(&ft->s->windows)));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2497,6 +2705,24 @@ format_cb_tree_mode_format(__unused struct format_tree *ft)
|
|||||||
return (xstrdup(window_tree_mode.default_format));
|
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. */
|
/* Format table type. */
|
||||||
enum format_table_type {
|
enum format_table_type {
|
||||||
FORMAT_TABLE_STRING,
|
FORMAT_TABLE_STRING,
|
||||||
@@ -2603,6 +2829,12 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "client_tty", FORMAT_TABLE_STRING,
|
{ "client_tty", FORMAT_TABLE_STRING,
|
||||||
format_cb_client_tty
|
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,
|
{ "client_utf8", FORMAT_TABLE_STRING,
|
||||||
format_cb_client_utf8
|
format_cb_client_utf8
|
||||||
},
|
},
|
||||||
@@ -2666,6 +2898,9 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "mouse_button_flag", FORMAT_TABLE_STRING,
|
{ "mouse_button_flag", FORMAT_TABLE_STRING,
|
||||||
format_cb_mouse_button_flag
|
format_cb_mouse_button_flag
|
||||||
},
|
},
|
||||||
|
{ "mouse_hyperlink", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_mouse_hyperlink
|
||||||
|
},
|
||||||
{ "mouse_line", FORMAT_TABLE_STRING,
|
{ "mouse_line", FORMAT_TABLE_STRING,
|
||||||
format_cb_mouse_line
|
format_cb_mouse_line
|
||||||
},
|
},
|
||||||
@@ -2678,6 +2913,12 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "mouse_standard_flag", FORMAT_TABLE_STRING,
|
{ "mouse_standard_flag", FORMAT_TABLE_STRING,
|
||||||
format_cb_mouse_standard_flag
|
format_cb_mouse_standard_flag
|
||||||
},
|
},
|
||||||
|
{ "mouse_status_line", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_mouse_status_line
|
||||||
|
},
|
||||||
|
{ "mouse_status_range", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_mouse_status_range
|
||||||
|
},
|
||||||
{ "mouse_utf8_flag", FORMAT_TABLE_STRING,
|
{ "mouse_utf8_flag", FORMAT_TABLE_STRING,
|
||||||
format_cb_mouse_utf8_flag
|
format_cb_mouse_utf8_flag
|
||||||
},
|
},
|
||||||
@@ -2690,6 +2931,9 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "mouse_y", FORMAT_TABLE_STRING,
|
{ "mouse_y", FORMAT_TABLE_STRING,
|
||||||
format_cb_mouse_y
|
format_cb_mouse_y
|
||||||
},
|
},
|
||||||
|
{ "next_session_id", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_next_session_id
|
||||||
|
},
|
||||||
{ "origin_flag", FORMAT_TABLE_STRING,
|
{ "origin_flag", FORMAT_TABLE_STRING,
|
||||||
format_cb_origin_flag
|
format_cb_origin_flag
|
||||||
},
|
},
|
||||||
@@ -2723,9 +2967,15 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "pane_dead", FORMAT_TABLE_STRING,
|
{ "pane_dead", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_dead
|
format_cb_pane_dead
|
||||||
},
|
},
|
||||||
|
{ "pane_dead_signal", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_pane_dead_signal
|
||||||
|
},
|
||||||
{ "pane_dead_status", FORMAT_TABLE_STRING,
|
{ "pane_dead_status", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_dead_status
|
format_cb_pane_dead_status
|
||||||
},
|
},
|
||||||
|
{ "pane_dead_time", FORMAT_TABLE_TIME,
|
||||||
|
format_cb_pane_dead_time
|
||||||
|
},
|
||||||
{ "pane_fg", FORMAT_TABLE_STRING,
|
{ "pane_fg", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_fg
|
format_cb_pane_fg
|
||||||
},
|
},
|
||||||
@@ -2780,6 +3030,9 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "pane_start_command", FORMAT_TABLE_STRING,
|
{ "pane_start_command", FORMAT_TABLE_STRING,
|
||||||
format_cb_start_command
|
format_cb_start_command
|
||||||
},
|
},
|
||||||
|
{ "pane_start_path", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_start_path
|
||||||
|
},
|
||||||
{ "pane_synchronized", FORMAT_TABLE_STRING,
|
{ "pane_synchronized", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_synchronized
|
format_cb_pane_synchronized
|
||||||
},
|
},
|
||||||
@@ -2795,6 +3048,9 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "pane_tty", FORMAT_TABLE_STRING,
|
{ "pane_tty", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_tty
|
format_cb_pane_tty
|
||||||
},
|
},
|
||||||
|
{ "pane_unseen_changes", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_pane_unseen_changes
|
||||||
|
},
|
||||||
{ "pane_width", FORMAT_TABLE_STRING,
|
{ "pane_width", FORMAT_TABLE_STRING,
|
||||||
format_cb_pane_width
|
format_cb_pane_width
|
||||||
},
|
},
|
||||||
@@ -2807,6 +3063,9 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "scroll_region_upper", FORMAT_TABLE_STRING,
|
{ "scroll_region_upper", FORMAT_TABLE_STRING,
|
||||||
format_cb_scroll_region_upper
|
format_cb_scroll_region_upper
|
||||||
},
|
},
|
||||||
|
{ "server_sessions", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_server_sessions
|
||||||
|
},
|
||||||
{ "session_activity", FORMAT_TABLE_TIME,
|
{ "session_activity", FORMAT_TABLE_TIME,
|
||||||
format_cb_session_activity
|
format_cb_session_activity
|
||||||
},
|
},
|
||||||
@@ -2879,6 +3138,12 @@ static const struct format_table_entry format_table[] = {
|
|||||||
{ "tree_mode_format", FORMAT_TABLE_STRING,
|
{ "tree_mode_format", FORMAT_TABLE_STRING,
|
||||||
format_cb_tree_mode_format
|
format_cb_tree_mode_format
|
||||||
},
|
},
|
||||||
|
{ "uid", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_uid
|
||||||
|
},
|
||||||
|
{ "user", FORMAT_TABLE_STRING,
|
||||||
|
format_cb_user
|
||||||
|
},
|
||||||
{ "version", FORMAT_TABLE_STRING,
|
{ "version", FORMAT_TABLE_STRING,
|
||||||
format_cb_version
|
format_cb_version
|
||||||
},
|
},
|
||||||
@@ -3079,6 +3344,22 @@ format_free(struct format_tree *ft)
|
|||||||
free(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. */
|
/* Walk each format. */
|
||||||
void
|
void
|
||||||
format_each(struct format_tree *ft, void (*cb)(const char *, const char *,
|
format_each(struct format_tree *ft, void (*cb)(const char *, const char *,
|
||||||
@@ -3230,12 +3511,12 @@ format_quote_style(const char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make a prettier time. */
|
/* Make a prettier time. */
|
||||||
static char *
|
char *
|
||||||
format_pretty_time(time_t t)
|
format_pretty_time(time_t t, int seconds)
|
||||||
{
|
{
|
||||||
struct tm now_tm, tm;
|
struct tm now_tm, tm;
|
||||||
time_t now, age;
|
time_t now, age;
|
||||||
char s[6];
|
char s[9];
|
||||||
|
|
||||||
time(&now);
|
time(&now);
|
||||||
if (now < t)
|
if (now < t)
|
||||||
@@ -3247,7 +3528,10 @@ format_pretty_time(time_t t)
|
|||||||
|
|
||||||
/* Last 24 hours. */
|
/* Last 24 hours. */
|
||||||
if (age < 24 * 3600) {
|
if (age < 24 * 3600) {
|
||||||
strftime(s, sizeof s, "%H:%M", &tm);
|
if (seconds)
|
||||||
|
strftime(s, sizeof s, "%H:%M:%S", &tm);
|
||||||
|
else
|
||||||
|
strftime(s, sizeof s, "%H:%M", &tm);
|
||||||
return (xstrdup(s));
|
return (xstrdup(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3305,7 +3589,7 @@ format_find(struct format_tree *ft, const char *key, int modifiers,
|
|||||||
fte = format_table_get(key);
|
fte = format_table_get(key);
|
||||||
if (fte != NULL) {
|
if (fte != NULL) {
|
||||||
value = fte->cb(ft);
|
value = fte->cb(ft);
|
||||||
if (fte->type == FORMAT_TABLE_TIME)
|
if (fte->type == FORMAT_TABLE_TIME && value != NULL)
|
||||||
t = ((struct timeval *)value)->tv_sec;
|
t = ((struct timeval *)value)->tv_sec;
|
||||||
else
|
else
|
||||||
found = value;
|
found = value;
|
||||||
@@ -3352,7 +3636,7 @@ found:
|
|||||||
if (t == 0)
|
if (t == 0)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
if (modifiers & FORMAT_PRETTY)
|
if (modifiers & FORMAT_PRETTY)
|
||||||
found = format_pretty_time(t);
|
found = format_pretty_time(t, 0);
|
||||||
else {
|
else {
|
||||||
if (time_format != NULL) {
|
if (time_format != NULL) {
|
||||||
localtime_r(&t, &tm);
|
localtime_r(&t, &tm);
|
||||||
@@ -3382,18 +3666,43 @@ found:
|
|||||||
}
|
}
|
||||||
if (modifiers & FORMAT_QUOTE_SHELL) {
|
if (modifiers & FORMAT_QUOTE_SHELL) {
|
||||||
saved = found;
|
saved = found;
|
||||||
found = xstrdup(format_quote_shell(saved));
|
found = format_quote_shell(saved);
|
||||||
free(saved);
|
free(saved);
|
||||||
}
|
}
|
||||||
if (modifiers & FORMAT_QUOTE_STYLE) {
|
if (modifiers & FORMAT_QUOTE_STYLE) {
|
||||||
saved = found;
|
saved = found;
|
||||||
found = xstrdup(format_quote_style(saved));
|
found = format_quote_style(saved);
|
||||||
free(saved);
|
free(saved);
|
||||||
}
|
}
|
||||||
return (found);
|
return (found);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove escaped characters from string. */
|
/* Unescape escaped characters. */
|
||||||
|
static char *
|
||||||
|
format_unescape(const char *s)
|
||||||
|
{
|
||||||
|
char *out, *cp;
|
||||||
|
int brackets = 0;
|
||||||
|
|
||||||
|
cp = out = xmalloc(strlen(s) + 1);
|
||||||
|
for (; *s != '\0'; s++) {
|
||||||
|
if (*s == '#' && s[1] == '{')
|
||||||
|
brackets++;
|
||||||
|
if (brackets == 0 &&
|
||||||
|
*s == '#' &&
|
||||||
|
strchr(",#{}:", s[1]) != NULL) {
|
||||||
|
*cp++ = *++s;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (*s == '}')
|
||||||
|
brackets--;
|
||||||
|
*cp++ = *s;
|
||||||
|
}
|
||||||
|
*cp = '\0';
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove escaped characters. */
|
||||||
static char *
|
static char *
|
||||||
format_strip(const char *s)
|
format_strip(const char *s)
|
||||||
{
|
{
|
||||||
@@ -3426,7 +3735,9 @@ format_skip(const char *s, const char *end)
|
|||||||
for (; *s != '\0'; s++) {
|
for (; *s != '\0'; s++) {
|
||||||
if (*s == '#' && s[1] == '{')
|
if (*s == '#' && s[1] == '{')
|
||||||
brackets++;
|
brackets++;
|
||||||
if (*s == '#' && strchr(",#{}:", s[1]) != NULL) {
|
if (*s == '#' &&
|
||||||
|
s[1] != '\0' &&
|
||||||
|
strchr(",#{}:", s[1]) != NULL) {
|
||||||
s++;
|
s++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -3523,7 +3834,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Modifiers are a ; separated list of the forms:
|
* 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
|
* =/a
|
||||||
* =/a/
|
* =/a/
|
||||||
@@ -3540,7 +3851,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
cp++;
|
cp++;
|
||||||
|
|
||||||
/* Check single character modifiers with no arguments. */
|
/* Check single character modifiers with no arguments. */
|
||||||
if (strchr("labdnwETSWP<>", cp[0]) != NULL &&
|
if (strchr("labcdnwETSWPL<>", cp[0]) != NULL &&
|
||||||
format_is_end(cp[1])) {
|
format_is_end(cp[1])) {
|
||||||
format_add_modifier(&list, count, cp, 1, NULL, 0);
|
format_add_modifier(&list, count, cp, 1, NULL, 0);
|
||||||
cp++;
|
cp++;
|
||||||
@@ -3575,7 +3886,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
argc = 0;
|
argc = 0;
|
||||||
|
|
||||||
/* Single argument with no wrapper character. */
|
/* Single argument with no wrapper character. */
|
||||||
if (!ispunct(cp[1]) || cp[1] == '-') {
|
if (!ispunct((u_char)cp[1]) || cp[1] == '-') {
|
||||||
end = format_skip(cp + 1, ":;");
|
end = format_skip(cp + 1, ":;");
|
||||||
if (end == NULL)
|
if (end == NULL)
|
||||||
break;
|
break;
|
||||||
@@ -3604,7 +3915,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
|
|||||||
break;
|
break;
|
||||||
cp++;
|
cp++;
|
||||||
|
|
||||||
argv = xreallocarray (argv, argc + 1, sizeof *argv);
|
argv = xreallocarray(argv, argc + 1, sizeof *argv);
|
||||||
value = xstrndup(cp, end - cp);
|
value = xstrndup(cp, end - cp);
|
||||||
argv[argc++] = format_expand1(es, value);
|
argv[argc++] = format_expand1(es, value);
|
||||||
free(value);
|
free(value);
|
||||||
@@ -3868,6 +4179,40 @@ format_loop_panes(struct format_expand_state *es, const char *fmt)
|
|||||||
return (value);
|
return (value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Loop over clients. */
|
||||||
|
static char *
|
||||||
|
format_loop_clients(struct format_expand_state *es, const char *fmt)
|
||||||
|
{
|
||||||
|
struct format_tree *ft = es->ft;
|
||||||
|
struct client *c;
|
||||||
|
struct cmdq_item *item = ft->item;
|
||||||
|
struct format_tree *nft;
|
||||||
|
struct format_expand_state next;
|
||||||
|
char *expanded, *value;
|
||||||
|
size_t valuelen;
|
||||||
|
|
||||||
|
value = xcalloc(1, 1);
|
||||||
|
valuelen = 1;
|
||||||
|
|
||||||
|
TAILQ_FOREACH(c, &clients, entry) {
|
||||||
|
format_log(es, "client loop: %s", c->name);
|
||||||
|
nft = format_create(c, item, 0, ft->flags);
|
||||||
|
format_defaults(nft, c, ft->s, ft->wl, ft->wp);
|
||||||
|
format_copy_state(&next, es, 0);
|
||||||
|
next.ft = nft;
|
||||||
|
expanded = format_expand1(&next, fmt);
|
||||||
|
format_free(nft);
|
||||||
|
|
||||||
|
valuelen += strlen(expanded);
|
||||||
|
value = xrealloc(value, valuelen);
|
||||||
|
|
||||||
|
strlcat(value, expanded, valuelen);
|
||||||
|
free(expanded);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (value);
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
format_replace_expression(struct format_modifier *mexp,
|
format_replace_expression(struct format_modifier *mexp,
|
||||||
struct format_expand_state *es, const char *copy)
|
struct format_expand_state *es, const char *copy)
|
||||||
@@ -3991,7 +4336,7 @@ format_replace_expression(struct format_modifier *mexp,
|
|||||||
result = (mleft < mright);
|
result = (mleft < mright);
|
||||||
break;
|
break;
|
||||||
case LESS_THAN_EQUAL:
|
case LESS_THAN_EQUAL:
|
||||||
result = (mleft > mright);
|
result = (mleft <= mright);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (use_fp)
|
if (use_fp)
|
||||||
@@ -4020,10 +4365,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
const char *errstr, *copy, *cp, *marker = NULL;
|
const char *errstr, *copy, *cp, *marker = NULL;
|
||||||
const char *time_format = NULL;
|
const char *time_format = NULL;
|
||||||
char *copy0, *condition, *found, *new;
|
char *copy0, *condition, *found, *new;
|
||||||
char *value, *left, *right, c;
|
char *value, *left, *right;
|
||||||
size_t valuelen;
|
size_t valuelen;
|
||||||
int modifiers = 0, limit = 0, width = 0;
|
int modifiers = 0, limit = 0, width = 0;
|
||||||
int j;
|
int j, c;
|
||||||
struct format_modifier *list, *cmp = NULL, *search = NULL;
|
struct format_modifier *list, *cmp = NULL, *search = NULL;
|
||||||
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
|
struct format_modifier **sub = NULL, *mexp = NULL, *fm;
|
||||||
u_int i, count, nsub = 0;
|
u_int i, count, nsub = 0;
|
||||||
@@ -4056,8 +4401,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
case 's':
|
case 's':
|
||||||
if (fm->argc < 2)
|
if (fm->argc < 2)
|
||||||
break;
|
break;
|
||||||
sub = xreallocarray (sub, nsub + 1,
|
sub = xreallocarray(sub, nsub + 1, sizeof *sub);
|
||||||
sizeof *sub);
|
|
||||||
sub[nsub++] = fm;
|
sub[nsub++] = fm;
|
||||||
break;
|
break;
|
||||||
case '=':
|
case '=':
|
||||||
@@ -4095,6 +4439,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
case 'b':
|
case 'b':
|
||||||
modifiers |= FORMAT_BASENAME;
|
modifiers |= FORMAT_BASENAME;
|
||||||
break;
|
break;
|
||||||
|
case 'c':
|
||||||
|
modifiers |= FORMAT_COLOUR;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
modifiers |= FORMAT_DIRNAME;
|
modifiers |= FORMAT_DIRNAME;
|
||||||
break;
|
break;
|
||||||
@@ -4140,6 +4487,9 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
case 'P':
|
case 'P':
|
||||||
modifiers |= FORMAT_PANES;
|
modifiers |= FORMAT_PANES;
|
||||||
break;
|
break;
|
||||||
|
case 'L':
|
||||||
|
modifiers |= FORMAT_CLIENTS;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else if (fm->size == 2) {
|
} else if (fm->size == 2) {
|
||||||
if (strcmp(fm->modifier, "||") == 0 ||
|
if (strcmp(fm->modifier, "||") == 0 ||
|
||||||
@@ -4154,7 +4504,8 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
|
|
||||||
/* Is this a literal string? */
|
/* Is this a literal string? */
|
||||||
if (modifiers & FORMAT_LITERAL) {
|
if (modifiers & FORMAT_LITERAL) {
|
||||||
value = xstrdup(copy);
|
format_log(es, "literal string is '%s'", copy);
|
||||||
|
value = format_unescape(copy);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4166,7 +4517,19 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
value = xstrdup("");
|
value = xstrdup("");
|
||||||
else
|
else
|
||||||
xasprintf(&value, "%c", c);
|
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;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4183,6 +4546,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
value = format_loop_panes(es, copy);
|
value = format_loop_panes(es, copy);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
} else if (modifiers & FORMAT_CLIENTS) {
|
||||||
|
value = format_loop_clients(es, copy);
|
||||||
|
if (value == NULL)
|
||||||
|
goto fail;
|
||||||
} else if (modifiers & FORMAT_WINDOW_NAME) {
|
} else if (modifiers & FORMAT_WINDOW_NAME) {
|
||||||
value = format_window_name(es, copy);
|
value = format_window_name(es, copy);
|
||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
@@ -4199,7 +4566,7 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
value = xstrdup("0");
|
value = xstrdup("0");
|
||||||
} else {
|
} else {
|
||||||
format_log(es, "search '%s' pane %%%u", new, wp->id);
|
format_log(es, "search '%s' pane %%%u", new, wp->id);
|
||||||
value = format_search(fm, wp, new);
|
value = format_search(search, wp, new);
|
||||||
}
|
}
|
||||||
free(new);
|
free(new);
|
||||||
} else if (cmp != NULL) {
|
} else if (cmp != NULL) {
|
||||||
@@ -4278,15 +4645,14 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
|
|||||||
if (strcmp(found, condition) == 0) {
|
if (strcmp(found, condition) == 0) {
|
||||||
free(found);
|
free(found);
|
||||||
found = xstrdup("");
|
found = xstrdup("");
|
||||||
format_log(es, "condition '%s' found: %s",
|
|
||||||
condition, found);
|
|
||||||
} else {
|
|
||||||
format_log(es,
|
format_log(es,
|
||||||
"condition '%s' not found; assuming false",
|
"condition '%s' not found; assuming false",
|
||||||
condition);
|
condition);
|
||||||
}
|
}
|
||||||
} else
|
} else {
|
||||||
format_log(es, "condition '%s' found", condition);
|
format_log(es, "condition '%s' found: %s", condition,
|
||||||
|
found);
|
||||||
|
}
|
||||||
|
|
||||||
if (format_choose(es, cp + 1, &left, &right, 0) != 0) {
|
if (format_choose(es, cp + 1, &left, &right, 0) != 0) {
|
||||||
format_log(es, "condition '%s' syntax error: %s",
|
format_log(es, "condition '%s' syntax error: %s",
|
||||||
@@ -4433,7 +4799,7 @@ format_expand1(struct format_expand_state *es, const char *fmt)
|
|||||||
{
|
{
|
||||||
struct format_tree *ft = es->ft;
|
struct format_tree *ft = es->ft;
|
||||||
char *buf, *out, *name;
|
char *buf, *out, *name;
|
||||||
const char *ptr, *s;
|
const char *ptr, *s, *style_end = NULL;
|
||||||
size_t off, len, n, outlen;
|
size_t off, len, n, outlen;
|
||||||
int ch, brackets;
|
int ch, brackets;
|
||||||
char expanded[8192];
|
char expanded[8192];
|
||||||
@@ -4441,8 +4807,10 @@ format_expand1(struct format_expand_state *es, const char *fmt)
|
|||||||
if (fmt == NULL || *fmt == '\0')
|
if (fmt == NULL || *fmt == '\0')
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
|
|
||||||
if (es->loop == FORMAT_LOOP_LIMIT)
|
if (es->loop == FORMAT_LOOP_LIMIT) {
|
||||||
|
format_log(es, "reached loop limit (%u)", FORMAT_LOOP_LIMIT);
|
||||||
return (xstrdup(""));
|
return (xstrdup(""));
|
||||||
|
}
|
||||||
es->loop++;
|
es->loop++;
|
||||||
|
|
||||||
format_log(es, "expanding format: %s", fmt);
|
format_log(es, "expanding format: %s", fmt);
|
||||||
@@ -4526,18 +4894,20 @@ format_expand1(struct format_expand_state *es, const char *fmt)
|
|||||||
break;
|
break;
|
||||||
fmt += n + 1;
|
fmt += n + 1;
|
||||||
continue;
|
continue;
|
||||||
|
case '[':
|
||||||
case '#':
|
case '#':
|
||||||
/*
|
/*
|
||||||
* If ##[ (with two or more #s), then it is a style and
|
* If ##[ (with two or more #s), then it is a style and
|
||||||
* can be left for format_draw to handle.
|
* can be left for format_draw to handle.
|
||||||
*/
|
*/
|
||||||
ptr = fmt;
|
ptr = fmt - (ch == '[');
|
||||||
n = 2;
|
n = 2 - (ch == '[');
|
||||||
while (*ptr == '#') {
|
while (*ptr == '#') {
|
||||||
ptr++;
|
ptr++;
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
if (*ptr == '[') {
|
if (*ptr == '[') {
|
||||||
|
style_end = format_skip(fmt - 2, "]");
|
||||||
format_log(es, "found #*%zu[", n);
|
format_log(es, "found #*%zu[", n);
|
||||||
while (len - off < n + 2) {
|
while (len - off < n + 2) {
|
||||||
buf = xreallocarray(buf, 2, len);
|
buf = xreallocarray(buf, 2, len);
|
||||||
@@ -4560,10 +4930,12 @@ format_expand1(struct format_expand_state *es, const char *fmt)
|
|||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
s = NULL;
|
s = NULL;
|
||||||
if (ch >= 'A' && ch <= 'Z')
|
if (fmt > style_end) { /* skip inside #[] */
|
||||||
s = format_upper[ch - 'A'];
|
if (ch >= 'A' && ch <= 'Z')
|
||||||
else if (ch >= 'a' && ch <= 'z')
|
s = format_upper[ch - 'A'];
|
||||||
s = format_lower[ch - 'a'];
|
else if (ch >= 'a' && ch <= 'z')
|
||||||
|
s = format_lower[ch - 'a'];
|
||||||
|
}
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
while (len - off < 3) {
|
while (len - off < 3) {
|
||||||
buf = xreallocarray(buf, 2, len);
|
buf = xreallocarray(buf, 2, len);
|
||||||
@@ -4729,7 +5101,7 @@ format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
|||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
format_defaults_pane(ft, wp);
|
format_defaults_pane(ft, wp);
|
||||||
|
|
||||||
pb = paste_get_top (NULL);
|
pb = paste_get_top(NULL);
|
||||||
if (pb != NULL)
|
if (pb != NULL)
|
||||||
format_defaults_paste_buffer(ft, pb);
|
format_defaults_paste_buffer(ft, pb);
|
||||||
}
|
}
|
||||||
@@ -4807,7 +5179,8 @@ format_grid_word(struct grid *gd, u_int x, u_int y)
|
|||||||
grid_get_cell(gd, x, y, &gc);
|
grid_get_cell(gd, x, y, &gc);
|
||||||
if (gc.flags & GRID_FLAG_PADDING)
|
if (gc.flags & GRID_FLAG_PADDING)
|
||||||
break;
|
break;
|
||||||
if (utf8_cstrhas(ws, &gc.data)) {
|
if (utf8_cstrhas(ws, &gc.data) ||
|
||||||
|
(gc.data.size == 1 && *gc.data.data == ' ')) {
|
||||||
found = 1;
|
found = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -4844,7 +5217,8 @@ format_grid_word(struct grid *gd, u_int x, u_int y)
|
|||||||
grid_get_cell(gd, x, y, &gc);
|
grid_get_cell(gd, x, y, &gc);
|
||||||
if (gc.flags & GRID_FLAG_PADDING)
|
if (gc.flags & GRID_FLAG_PADDING)
|
||||||
break;
|
break;
|
||||||
if (utf8_cstrhas(ws, &gc.data))
|
if (utf8_cstrhas(ws, &gc.data) ||
|
||||||
|
(gc.data.size == 1 && *gc.data.data == ' '))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
ud = xreallocarray(ud, size + 2, sizeof *ud);
|
ud = xreallocarray(ud, size + 2, sizeof *ud);
|
||||||
@@ -4883,3 +5257,20 @@ format_grid_line(struct grid *gd, u_int y)
|
|||||||
}
|
}
|
||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return hyperlink at given coordinates. Caller frees. */
|
||||||
|
char *
|
||||||
|
format_grid_hyperlink(struct grid *gd, u_int x, u_int y, struct screen* s)
|
||||||
|
{
|
||||||
|
const char *uri;
|
||||||
|
struct grid_cell gc;
|
||||||
|
|
||||||
|
grid_get_cell(gd, x, y, &gc);
|
||||||
|
if (gc.flags & GRID_FLAG_PADDING)
|
||||||
|
return (NULL);
|
||||||
|
if (s->hyperlinks == NULL || gc.link == 0)
|
||||||
|
return (NULL);
|
||||||
|
if (!hyperlinks_get(s->hyperlinks, gc.link, &uri, NULL, NULL))
|
||||||
|
return (NULL);
|
||||||
|
return (xstrdup(uri));
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@
|
|||||||
struct event_base *libevent;
|
struct event_base *libevent;
|
||||||
|
|
||||||
int
|
int
|
||||||
LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
|
LLVMFuzzerTestOneInput(const u_char *data, size_t size)
|
||||||
{
|
{
|
||||||
struct bufferevent *vpty[2];
|
struct bufferevent *vpty[2];
|
||||||
struct window *w;
|
struct window *w;
|
||||||
@@ -43,10 +44,15 @@ LLVMFuzzerTestOneInput(const unsigned char *data, size_t size)
|
|||||||
w = window_create(PANE_WIDTH, PANE_HEIGHT, 0, 0);
|
w = window_create(PANE_WIDTH, PANE_HEIGHT, 0, 0);
|
||||||
wp = window_add_pane(w, NULL, 0, 0);
|
wp = window_add_pane(w, NULL, 0, 0);
|
||||||
bufferevent_pair_new(libevent, BEV_OPT_CLOSE_ON_FREE, vpty);
|
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__);
|
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)
|
while (cmdq_next(NULL) != 0)
|
||||||
;
|
;
|
||||||
error = event_base_loop(libevent, EVLOOP_NONBLOCK);
|
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, "monitor-bell", 0);
|
||||||
options_set_number(global_w_options, "allow-rename", 1);
|
options_set_number(global_w_options, "allow-rename", 1);
|
||||||
options_set_number(global_options, "set-clipboard", 2);
|
options_set_number(global_options, "set-clipboard", 2);
|
||||||
|
socket_path = xstrdup("dummy");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
174
grid-reader.c
174
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);
|
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. */
|
/* Check if character under cursor is in set. */
|
||||||
int
|
int
|
||||||
grid_reader_in_set(struct grid_reader *gr, const char *set)
|
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)
|
grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
||||||
{
|
{
|
||||||
u_int xx, yy;
|
u_int xx, yy;
|
||||||
int expected = 0;
|
|
||||||
|
|
||||||
/* Do not break up wrapped words. */
|
/* Do not break up wrapped words. */
|
||||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||||
@@ -180,33 +202,35 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
|||||||
yy = gr->gd->hsize + gr->gd->sy - 1;
|
yy = gr->gd->hsize + gr->gd->sy - 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we started inside a word, skip over word characters. Then skip
|
* When navigating via spaces (for example with next-space) separators
|
||||||
* over separators till the next word.
|
* should be empty.
|
||||||
*
|
*
|
||||||
* expected is initially set to 0 for the former and then 1 for the
|
* If we started on a separator that is not whitespace, skip over
|
||||||
* latter. It is finally set to 0 when the beginning of the next word is
|
* subsequent separators that are not whitespace. Otherwise, if we
|
||||||
* found.
|
* 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 {
|
if (!grid_reader_handle_wrap(gr, &xx, &yy))
|
||||||
while (gr->cx > xx ||
|
return;
|
||||||
grid_reader_in_set(gr, separators) == expected) {
|
if (!grid_reader_in_set(gr, WHITESPACE)) {
|
||||||
/* Move down if we are past the end of the line. */
|
if (grid_reader_in_set(gr, separators)) {
|
||||||
if (gr->cx > xx) {
|
do
|
||||||
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
|
|
||||||
gr->cx++;
|
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. */
|
/* 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)
|
grid_reader_cursor_next_word_end(struct grid_reader *gr, const char *separators)
|
||||||
{
|
{
|
||||||
u_int xx, yy;
|
u_int xx, yy;
|
||||||
int expected = 1;
|
|
||||||
|
|
||||||
/* Do not break up wrapped words. */
|
/* Do not break up wrapped words. */
|
||||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||||
@@ -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;
|
yy = gr->gd->hsize + gr->gd->sy - 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we started on a separator, skip over separators. Then skip over
|
* When navigating via spaces (for example with next-space), separators
|
||||||
* word characters till the next separator.
|
* should be empty in both modes.
|
||||||
*
|
*
|
||||||
* expected is initially set to 1 for the former and then 1 for the
|
* If we started on a whitespace, move until reaching the first
|
||||||
* latter. It is finally set to 1 when the end of the next word is
|
* non-whitespace character. If that character is a separator, treat
|
||||||
* found.
|
* 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 &
|
while (grid_reader_handle_wrap(gr, &xx, &yy)) {
|
||||||
GRID_LINE_WRAPPED)
|
if (grid_reader_in_set(gr, WHITESPACE))
|
||||||
xx = gr->gd->sx - 1;
|
gr->cx++;
|
||||||
else
|
else if (grid_reader_in_set(gr, separators)) {
|
||||||
xx = grid_reader_line_length(gr);
|
do
|
||||||
} else
|
|
||||||
gr->cx++;
|
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. */
|
/* Move to the previous place where a word begins. */
|
||||||
void
|
void
|
||||||
grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
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. */
|
/* Move back to the previous word character. */
|
||||||
if (already || grid_reader_in_set(gr, separators)) {
|
if (already || grid_reader_in_set(gr, WHITESPACE)) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (gr->cx > 0) {
|
if (gr->cx > 0) {
|
||||||
gr->cx--;
|
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;
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (gr->cy == 0)
|
if (gr->cy == 0)
|
||||||
return;
|
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);
|
grid_reader_cursor_end_of_line(gr, 0, 0);
|
||||||
|
|
||||||
/* Stop if separator at EOL. */
|
/* Stop if separator at EOL. */
|
||||||
if (gr->cx > 0) {
|
if (stop_at_eol && gr->cx > 0) {
|
||||||
oldx = gr->cx;
|
oldx = gr->cx;
|
||||||
gr->cx--;
|
gr->cx--;
|
||||||
r = grid_reader_in_set(gr, separators);
|
at_eol = grid_reader_in_set(gr,
|
||||||
|
WHITESPACE);
|
||||||
gr->cx = oldx;
|
gr->cx = oldx;
|
||||||
if (r)
|
if (at_eol) {
|
||||||
|
word_is_letters = 0;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
word_is_letters = !grid_reader_in_set(gr, separators);
|
||||||
|
|
||||||
/* Move back to the beginning of this word. */
|
/* Move back to the beginning of this word. */
|
||||||
do {
|
do {
|
||||||
@@ -292,15 +324,16 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
|||||||
oldy = gr->cy;
|
oldy = gr->cy;
|
||||||
if (gr->cx == 0) {
|
if (gr->cx == 0) {
|
||||||
if (gr->cy == 0 ||
|
if (gr->cy == 0 ||
|
||||||
~grid_get_line(gr->gd, gr->cy - 1)->flags &
|
(~grid_get_line(gr->gd, gr->cy - 1)->flags &
|
||||||
GRID_LINE_WRAPPED)
|
GRID_LINE_WRAPPED))
|
||||||
break;
|
break;
|
||||||
grid_reader_cursor_up(gr);
|
grid_reader_cursor_up(gr);
|
||||||
grid_reader_cursor_end_of_line(gr, 0, 1);
|
grid_reader_cursor_end_of_line(gr, 0, 1);
|
||||||
}
|
}
|
||||||
if (gr->cx > 0)
|
if (gr->cx > 0)
|
||||||
gr->cx--;
|
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->cx = oldx;
|
||||||
gr->cy = oldy;
|
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) {
|
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||||
gr->cx = px;
|
gr->cx = px;
|
||||||
gr->cy = py;
|
gr->cy = py;
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
px++;
|
px++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (py == yy ||
|
if (py == yy ||
|
||||||
!(grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED))
|
!(grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED))
|
||||||
return 0;
|
return (0);
|
||||||
px = 0;
|
px = 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Jump back to character. */
|
/* 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) {
|
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||||
gr->cx = px - 1;
|
gr->cx = px - 1;
|
||||||
gr->cy = py - 1;
|
gr->cy = py - 1;
|
||||||
return 1;
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (py == 1 ||
|
if (py == 1 ||
|
||||||
!(grid_get_line(gr->gd, py - 2)->flags & GRID_LINE_WRAPPED))
|
!(grid_get_line(gr->gd, py - 2)->flags & GRID_LINE_WRAPPED))
|
||||||
return 0;
|
return (0);
|
||||||
xx = grid_line_length(gr->gd, py - 2);
|
xx = grid_line_length(gr->gd, py - 2);
|
||||||
}
|
}
|
||||||
return 0;
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Jump back to the first non-blank character of the line. */
|
/* Jump back to the first non-blank character of the line. */
|
||||||
@@ -371,19 +404,26 @@ void
|
|||||||
grid_reader_cursor_back_to_indentation(struct grid_reader *gr)
|
grid_reader_cursor_back_to_indentation(struct grid_reader *gr)
|
||||||
{
|
{
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
u_int px, py, xx, yy;
|
u_int px, py, xx, yy, oldx, oldy;
|
||||||
|
|
||||||
yy = gr->gd->hsize + gr->gd->sy - 1;
|
yy = gr->gd->hsize + gr->gd->sy - 1;
|
||||||
|
oldx = gr->cx;
|
||||||
|
oldy = gr->cy;
|
||||||
grid_reader_cursor_start_of_line(gr, 1);
|
grid_reader_cursor_start_of_line(gr, 1);
|
||||||
|
|
||||||
for (py = gr->cy; py <= yy; py++) {
|
for (py = gr->cy; py <= yy; py++) {
|
||||||
xx = grid_line_length(gr->gd, py);
|
xx = grid_line_length(gr->gd, py);
|
||||||
for (px = 0; px < xx; px++) {
|
for (px = 0; px < xx; px++) {
|
||||||
grid_get_cell(gr->gd, px, py, &gc);
|
grid_get_cell(gr->gd, px, py, &gc);
|
||||||
if (gc.data.size != 1 || *gc.data.data != ' ')
|
if (gc.data.size != 1 || *gc.data.data != ' ') {
|
||||||
break;
|
gr->cx = px;
|
||||||
|
gr->cy = py;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (~grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED)
|
if (~grid_get_line(gr->gd, py)->flags & GRID_LINE_WRAPPED)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
gr->cx = oldx;
|
||||||
|
gr->cy = oldy;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -231,5 +231,5 @@ grid_view_string_cells(struct grid *gd, u_int px, u_int py, u_int nx)
|
|||||||
px = grid_view_x(gd, px);
|
px = grid_view_x(gd, px);
|
||||||
py = grid_view_y(gd, py);
|
py = grid_view_y(gd, py);
|
||||||
|
|
||||||
return (grid_string_cells(gd, px, py, nx, NULL, 0, 0, 0));
|
return (grid_string_cells(gd, px, py, nx, NULL, 0, NULL));
|
||||||
}
|
}
|
||||||
|
|||||||
214
grid.c
214
grid.c
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
/* Default grid cell data. */
|
/* Default grid cell data. */
|
||||||
const struct grid_cell grid_default_cell = {
|
const struct grid_cell grid_default_cell = {
|
||||||
{ { ' ' }, 0, 1, 1 }, 0, 0, 8, 8, 0
|
{ { ' ' }, 0, 1, 1 }, 0, 0, 8, 8, 8, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -45,15 +45,15 @@ const struct grid_cell grid_default_cell = {
|
|||||||
* appears in the grid - because of this, they are always extended cells.
|
* appears in the grid - because of this, they are always extended cells.
|
||||||
*/
|
*/
|
||||||
static const struct grid_cell grid_padding_cell = {
|
static const struct grid_cell grid_padding_cell = {
|
||||||
{ { '!' }, 0, 0, 0 }, 0, GRID_FLAG_PADDING, 8, 8, 0
|
{ { '!' }, 0, 0, 0 }, 0, GRID_FLAG_PADDING, 8, 8, 8, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Cleared grid cell data. */
|
/* Cleared grid cell data. */
|
||||||
static const struct grid_cell grid_cleared_cell = {
|
static const struct grid_cell grid_cleared_cell = {
|
||||||
{ { ' ' }, 0, 1, 1 }, 0, GRID_FLAG_CLEARED, 8, 8, 0
|
{ { ' ' }, 0, 1, 1 }, 0, GRID_FLAG_CLEARED, 8, 8, 8, 0
|
||||||
};
|
};
|
||||||
static const struct grid_cell_entry grid_cleared_entry = {
|
static const struct grid_cell_entry grid_cleared_entry = {
|
||||||
GRID_FLAG_CLEARED, { .data = { 0, 8, 8, ' ' } }
|
{ .data = { 0, 8, 8, ' ' } }, GRID_FLAG_CLEARED
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Store cell in entry. */
|
/* Store cell in entry. */
|
||||||
@@ -90,6 +90,8 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
|
|||||||
return (1);
|
return (1);
|
||||||
if (gc->us != 0) /* only supports 256 or RGB */
|
if (gc->us != 0) /* only supports 256 or RGB */
|
||||||
return (1);
|
return (1);
|
||||||
|
if (gc->link != 0)
|
||||||
|
return (1);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +133,7 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
|||||||
gee->fg = gc->fg;
|
gee->fg = gc->fg;
|
||||||
gee->bg = gc->bg;
|
gee->bg = gc->bg;
|
||||||
gee->us = gc->us;
|
gee->us = gc->us;
|
||||||
|
gee->link = gc->link;
|
||||||
return (gee);
|
return (gee);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +234,8 @@ grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
|
|||||||
return (0);
|
return (0);
|
||||||
if (gc1->attr != gc2->attr || gc1->flags != gc2->flags)
|
if (gc1->attr != gc2->attr || gc1->flags != gc2->flags)
|
||||||
return (0);
|
return (0);
|
||||||
|
if (gc1->link != gc2->link)
|
||||||
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,6 +404,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
|||||||
|
|
||||||
gd->hscrolled++;
|
gd->hscrolled++;
|
||||||
grid_compact_line(&gd->linedata[gd->hsize]);
|
grid_compact_line(&gd->linedata[gd->hsize]);
|
||||||
|
gd->linedata[gd->hsize].time = current_time;
|
||||||
gd->hsize++;
|
gd->hsize++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -438,6 +444,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg)
|
|||||||
|
|
||||||
/* Move the line into the history. */
|
/* Move the line into the history. */
|
||||||
memcpy(gl_history, gl_upper, sizeof *gl_history);
|
memcpy(gl_history, gl_upper, sizeof *gl_history);
|
||||||
|
gl_history->time = current_time;
|
||||||
|
|
||||||
/* Then move the region up and clear the bottom line. */
|
/* Then move the region up and clear the bottom line. */
|
||||||
memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper);
|
memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper);
|
||||||
@@ -507,6 +514,7 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
|||||||
gc->fg = gee->fg;
|
gc->fg = gee->fg;
|
||||||
gc->bg = gee->bg;
|
gc->bg = gee->bg;
|
||||||
gc->us = gee->us;
|
gc->us = gee->us;
|
||||||
|
gc->link = gee->link;
|
||||||
utf8_to_data(gee->data, &gc->data);
|
utf8_to_data(gee->data, &gc->data);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -520,8 +528,9 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
|||||||
gc->bg = gce->data.bg;
|
gc->bg = gce->data.bg;
|
||||||
if (gce->flags & GRID_FLAG_BG256)
|
if (gce->flags & GRID_FLAG_BG256)
|
||||||
gc->bg |= COLOUR_FLAG_256;
|
gc->bg |= COLOUR_FLAG_256;
|
||||||
gc->us = 0;
|
gc->us = 8;
|
||||||
utf8_set(&gc->data, gce->data.data);
|
utf8_set(&gc->data, gce->data.data);
|
||||||
|
gc->link = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Get cell for reading. */
|
/* Get cell for reading. */
|
||||||
@@ -826,20 +835,104 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values)
|
|||||||
return (n);
|
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 flags)
|
||||||
|
{
|
||||||
|
u_int i;
|
||||||
|
char tmp[64];
|
||||||
|
int reset = (n != 0 && s[0] == 0);
|
||||||
|
|
||||||
|
if (nnewc == 0)
|
||||||
|
return; /* no code to add */
|
||||||
|
if (!reset &&
|
||||||
|
nnewc == noldc &&
|
||||||
|
memcmp(newc, oldc, nnewc * sizeof newc[0]) == 0)
|
||||||
|
return; /* no reset and colour unchanged */
|
||||||
|
if (reset && (newc[0] == 49 || newc[0] == 39))
|
||||||
|
return; /* reset and colour default */
|
||||||
|
|
||||||
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
grid_string_cells_add_hyperlink(char *buf, size_t len, const char *id,
|
||||||
|
const char *uri, int flags)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
if (strlen(uri) + strlen(id) + 17 >= len)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
|
strlcat(buf, "\\033]8;", len);
|
||||||
|
else
|
||||||
|
strlcat(buf, "\033]8;", len);
|
||||||
|
if (*id != '\0') {
|
||||||
|
xasprintf(&tmp, "id=%s;", id);
|
||||||
|
strlcat(buf, tmp, len);
|
||||||
|
free(tmp);
|
||||||
|
} else
|
||||||
|
strlcat(buf, ";", len);
|
||||||
|
strlcat(buf, uri, len);
|
||||||
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
|
strlcat(buf, "\\033\\\\", len);
|
||||||
|
else
|
||||||
|
strlcat(buf, "\033\\", len);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Returns ANSI code to set particular attributes (colour, bold and so on)
|
* Returns ANSI code to set particular attributes (colour, bold and so on)
|
||||||
* given a current state.
|
* given a current state.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
grid_string_cells_code(const struct grid_cell *lastgc,
|
grid_string_cells_code(const struct grid_cell *lastgc,
|
||||||
const struct grid_cell *gc, char *buf, size_t len, int escape_c0)
|
const struct grid_cell *gc, char *buf, size_t len, int flags,
|
||||||
|
struct screen *sc, int *has_link)
|
||||||
{
|
{
|
||||||
int oldc[64], newc[64], s[128];
|
int oldc[64], newc[64], s[128];
|
||||||
size_t noldc, nnewc, n, i;
|
size_t noldc, nnewc, n, i;
|
||||||
u_int attr = gc->attr, lastattr = lastgc->attr;
|
u_int attr = gc->attr, lastattr = lastgc->attr;
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
|
const char *uri, *id;
|
||||||
|
|
||||||
struct {
|
static const struct {
|
||||||
u_int mask;
|
u_int mask;
|
||||||
u_int code;
|
u_int code;
|
||||||
} attrs[] = {
|
} attrs[] = {
|
||||||
@@ -861,7 +954,9 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
|||||||
|
|
||||||
/* If any attribute is removed, begin with 0. */
|
/* If any attribute is removed, begin with 0. */
|
||||||
for (i = 0; i < nitems(attrs); i++) {
|
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 != 8 && gc->us == 8)) {
|
||||||
s[n++] = 0;
|
s[n++] = 0;
|
||||||
lastattr &= GRID_ATTR_CHARSET;
|
lastattr &= GRID_ATTR_CHARSET;
|
||||||
break;
|
break;
|
||||||
@@ -876,7 +971,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
|||||||
/* Write the attributes. */
|
/* Write the attributes. */
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
if (escape_c0)
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
strlcat(buf, "\\033[", len);
|
strlcat(buf, "\\033[", len);
|
||||||
else
|
else
|
||||||
strlcat(buf, "\033[", len);
|
strlcat(buf, "\033[", len);
|
||||||
@@ -897,69 +992,60 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
|||||||
/* If the foreground colour changed, write its parameters. */
|
/* If the foreground colour changed, write its parameters. */
|
||||||
nnewc = grid_string_cells_fg(gc, newc);
|
nnewc = grid_string_cells_fg(gc, newc);
|
||||||
noldc = grid_string_cells_fg(lastgc, oldc);
|
noldc = grid_string_cells_fg(lastgc, oldc);
|
||||||
if (nnewc != noldc ||
|
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
flags);
|
||||||
(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the background colour changed, append its parameters. */
|
/* If the background colour changed, append its parameters. */
|
||||||
nnewc = grid_string_cells_bg(gc, newc);
|
nnewc = grid_string_cells_bg(gc, newc);
|
||||||
noldc = grid_string_cells_bg(lastgc, oldc);
|
noldc = grid_string_cells_bg(lastgc, oldc);
|
||||||
if (nnewc != noldc ||
|
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
flags);
|
||||||
(n != 0 && s[0] == 0)) {
|
|
||||||
if (escape_c0)
|
/* If the underscore colour changed, append its parameters. */
|
||||||
strlcat(buf, "\\033[", len);
|
nnewc = grid_string_cells_us(gc, newc);
|
||||||
else
|
noldc = grid_string_cells_us(lastgc, oldc);
|
||||||
strlcat(buf, "\033[", len);
|
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||||
for (i = 0; i < nnewc; i++) {
|
flags);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Append shift in/shift out if needed. */
|
/* Append shift in/shift out if needed. */
|
||||||
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
||||||
if (escape_c0)
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
strlcat(buf, "\\016", len); /* SO */
|
strlcat(buf, "\\016", len); /* SO */
|
||||||
else
|
else
|
||||||
strlcat(buf, "\016", len); /* SO */
|
strlcat(buf, "\016", len); /* SO */
|
||||||
}
|
}
|
||||||
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
|
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
|
||||||
if (escape_c0)
|
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||||
strlcat(buf, "\\017", len); /* SI */
|
strlcat(buf, "\\017", len); /* SI */
|
||||||
else
|
else
|
||||||
strlcat(buf, "\017", len); /* SI */
|
strlcat(buf, "\017", len); /* SI */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Add hyperlink if changed. */
|
||||||
|
if (sc != NULL && sc->hyperlinks != NULL && lastgc->link != gc->link) {
|
||||||
|
if (hyperlinks_get(sc->hyperlinks, gc->link, &uri, &id, NULL)) {
|
||||||
|
*has_link = grid_string_cells_add_hyperlink(buf, len,
|
||||||
|
id, uri, flags);
|
||||||
|
} else if (*has_link) {
|
||||||
|
grid_string_cells_add_hyperlink(buf, len, "", "",
|
||||||
|
flags);
|
||||||
|
*has_link = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert cells into a string. */
|
/* Convert cells into a string. */
|
||||||
char *
|
char *
|
||||||
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||||
struct grid_cell **lastgc, int with_codes, int escape_c0, int trim)
|
struct grid_cell **lastgc, int flags, struct screen *s)
|
||||||
{
|
{
|
||||||
struct grid_cell gc;
|
struct grid_cell gc;
|
||||||
static struct grid_cell lastgc1;
|
static struct grid_cell lastgc1;
|
||||||
const char *data;
|
const char *data;
|
||||||
char *buf, code[128];
|
char *buf, code[8192];
|
||||||
size_t len, off, size, codelen;
|
size_t len, off, size, codelen;
|
||||||
u_int xx;
|
u_int xx, end;
|
||||||
|
int has_link = 0;
|
||||||
const struct grid_line *gl;
|
const struct grid_line *gl;
|
||||||
|
|
||||||
if (lastgc != NULL && *lastgc == NULL) {
|
if (lastgc != NULL && *lastgc == NULL) {
|
||||||
@@ -972,16 +1058,20 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
off = 0;
|
off = 0;
|
||||||
|
|
||||||
gl = grid_peek_line(gd, py);
|
gl = grid_peek_line(gd, py);
|
||||||
|
if (flags & GRID_STRING_EMPTY_CELLS)
|
||||||
|
end = gl->cellsize;
|
||||||
|
else
|
||||||
|
end = gl->cellused;
|
||||||
for (xx = px; xx < px + nx; xx++) {
|
for (xx = px; xx < px + nx; xx++) {
|
||||||
if (gl == NULL || xx >= gl->cellsize)
|
if (gl == NULL || xx >= end)
|
||||||
break;
|
break;
|
||||||
grid_get_cell(gd, xx, py, &gc);
|
grid_get_cell(gd, xx, py, &gc);
|
||||||
if (gc.flags & GRID_FLAG_PADDING)
|
if (gc.flags & GRID_FLAG_PADDING)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (with_codes) {
|
if (flags & GRID_STRING_WITH_SEQUENCES) {
|
||||||
grid_string_cells_code(*lastgc, &gc, code, sizeof code,
|
grid_string_cells_code(*lastgc, &gc, code, sizeof code,
|
||||||
escape_c0);
|
flags, s, &has_link);
|
||||||
codelen = strlen(code);
|
codelen = strlen(code);
|
||||||
memcpy(*lastgc, &gc, sizeof **lastgc);
|
memcpy(*lastgc, &gc, sizeof **lastgc);
|
||||||
} else
|
} else
|
||||||
@@ -989,7 +1079,9 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
|
|
||||||
data = gc.data.data;
|
data = gc.data.data;
|
||||||
size = gc.data.size;
|
size = gc.data.size;
|
||||||
if (escape_c0 && size == 1 && *data == '\\') {
|
if ((flags & GRID_STRING_ESCAPE_SEQUENCES) &&
|
||||||
|
size == 1 &&
|
||||||
|
*data == '\\') {
|
||||||
data = "\\\\";
|
data = "\\\\";
|
||||||
size = 2;
|
size = 2;
|
||||||
}
|
}
|
||||||
@@ -1007,7 +1099,19 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
|||||||
off += size;
|
off += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trim) {
|
if (has_link) {
|
||||||
|
grid_string_cells_add_hyperlink(code, sizeof code, "", "",
|
||||||
|
flags);
|
||||||
|
codelen = strlen(code);
|
||||||
|
while (len < off + size + codelen + 1) {
|
||||||
|
buf = xreallocarray(buf, 2, len);
|
||||||
|
len *= 2;
|
||||||
|
}
|
||||||
|
memcpy(buf + off, code, codelen);
|
||||||
|
off += codelen;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & GRID_STRING_TRIM_SPACES) {
|
||||||
while (off > 0 && buf[off - 1] == ' ')
|
while (off > 0 && buf[off - 1] == ' ')
|
||||||
off--;
|
off--;
|
||||||
}
|
}
|
||||||
|
|||||||
227
hyperlinks.c
Normal file
227
hyperlinks.c
Normal file
@@ -0,0 +1,227 @@
|
|||||||
|
/* $OpenBSD$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Will <author@will.party>
|
||||||
|
* Copyright (c) 2022 Jeff Chiang <pobomp@gmail.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* OSC 8 hyperlinks, described at:
|
||||||
|
*
|
||||||
|
* https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda
|
||||||
|
*
|
||||||
|
* Each hyperlink and ID combination is assigned a number ("inner" in this
|
||||||
|
* file) which is stored in an extended grid cell and maps into a tree here.
|
||||||
|
*
|
||||||
|
* Each URI has one inner number and one external ID (which tmux uses to send
|
||||||
|
* the hyperlink to the terminal) and one internal ID (which is received from
|
||||||
|
* the sending application inside tmux).
|
||||||
|
*
|
||||||
|
* Anonymous hyperlinks are each unique and are not reused even if they have
|
||||||
|
* the same URI (terminals will not want to tie them together).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define MAX_HYPERLINKS 5000
|
||||||
|
|
||||||
|
static long long hyperlinks_next_external_id = 1;
|
||||||
|
static u_int global_hyperlinks_count;
|
||||||
|
|
||||||
|
struct hyperlinks_uri {
|
||||||
|
struct hyperlinks *tree;
|
||||||
|
|
||||||
|
u_int inner;
|
||||||
|
const char *internal_id;
|
||||||
|
const char *external_id;
|
||||||
|
const char *uri;
|
||||||
|
|
||||||
|
TAILQ_ENTRY(hyperlinks_uri) list_entry;
|
||||||
|
RB_ENTRY(hyperlinks_uri) by_inner_entry;
|
||||||
|
RB_ENTRY(hyperlinks_uri) by_uri_entry; /* by internal ID and URI */
|
||||||
|
};
|
||||||
|
RB_HEAD(hyperlinks_by_uri_tree, hyperlinks_uri);
|
||||||
|
RB_HEAD(hyperlinks_by_inner_tree, hyperlinks_uri);
|
||||||
|
|
||||||
|
TAILQ_HEAD(hyperlinks_list, hyperlinks_uri);
|
||||||
|
static struct hyperlinks_list global_hyperlinks =
|
||||||
|
TAILQ_HEAD_INITIALIZER(global_hyperlinks);
|
||||||
|
|
||||||
|
struct hyperlinks {
|
||||||
|
u_int next_inner;
|
||||||
|
struct hyperlinks_by_inner_tree by_inner;
|
||||||
|
struct hyperlinks_by_uri_tree by_uri;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
hyperlinks_by_uri_cmp(struct hyperlinks_uri *left, struct hyperlinks_uri *right)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
|
if (*left->internal_id == '\0' || *right->internal_id == '\0') {
|
||||||
|
/*
|
||||||
|
* If both URIs are anonymous, use the inner for comparison so
|
||||||
|
* that they do not match even if the URI is the same - each
|
||||||
|
* anonymous URI should be unique.
|
||||||
|
*/
|
||||||
|
if (*left->internal_id != '\0')
|
||||||
|
return (-1);
|
||||||
|
if (*right->internal_id != '\0')
|
||||||
|
return (1);
|
||||||
|
return (left->inner - right->inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
r = strcmp(left->internal_id, right->internal_id);
|
||||||
|
if (r != 0)
|
||||||
|
return (r);
|
||||||
|
return (strcmp(left->uri, right->uri));
|
||||||
|
}
|
||||||
|
RB_PROTOTYPE_STATIC(hyperlinks_by_uri_tree, hyperlinks_uri, by_uri_entry,
|
||||||
|
hyperlinks_by_uri_cmp);
|
||||||
|
RB_GENERATE_STATIC(hyperlinks_by_uri_tree, hyperlinks_uri, by_uri_entry,
|
||||||
|
hyperlinks_by_uri_cmp);
|
||||||
|
|
||||||
|
static int
|
||||||
|
hyperlinks_by_inner_cmp(struct hyperlinks_uri *left,
|
||||||
|
struct hyperlinks_uri *right)
|
||||||
|
{
|
||||||
|
return (left->inner - right->inner);
|
||||||
|
}
|
||||||
|
RB_PROTOTYPE_STATIC(hyperlinks_by_inner_tree, hyperlinks_uri, by_inner_entry,
|
||||||
|
hyperlinks_by_inner_cmp);
|
||||||
|
RB_GENERATE_STATIC(hyperlinks_by_inner_tree, hyperlinks_uri, by_inner_entry,
|
||||||
|
hyperlinks_by_inner_cmp);
|
||||||
|
|
||||||
|
/* Remove a hyperlink. */
|
||||||
|
static void
|
||||||
|
hyperlinks_remove(struct hyperlinks_uri *hlu)
|
||||||
|
{
|
||||||
|
struct hyperlinks *hl = hlu->tree;
|
||||||
|
|
||||||
|
TAILQ_REMOVE(&global_hyperlinks, hlu, list_entry);
|
||||||
|
global_hyperlinks_count--;
|
||||||
|
|
||||||
|
RB_REMOVE(hyperlinks_by_inner_tree, &hl->by_inner, hlu);
|
||||||
|
RB_REMOVE(hyperlinks_by_uri_tree, &hl->by_uri, hlu);
|
||||||
|
|
||||||
|
free((void *)hlu->internal_id);
|
||||||
|
free((void *)hlu->external_id);
|
||||||
|
free((void *)hlu->uri);
|
||||||
|
free(hlu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store a new hyperlink or return if it already exists. */
|
||||||
|
u_int
|
||||||
|
hyperlinks_put(struct hyperlinks *hl, const char *uri_in,
|
||||||
|
const char *internal_id_in)
|
||||||
|
{
|
||||||
|
struct hyperlinks_uri find, *hlu;
|
||||||
|
char *uri, *internal_id, *external_id;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Anonymous URI are stored with an empty internal ID and the tree
|
||||||
|
* comparator will make sure they never match each other (so each
|
||||||
|
* anonymous URI is unique).
|
||||||
|
*/
|
||||||
|
if (internal_id_in == NULL)
|
||||||
|
internal_id_in = "";
|
||||||
|
|
||||||
|
utf8_stravis(&uri, uri_in, VIS_OCTAL|VIS_CSTYLE);
|
||||||
|
utf8_stravis(&internal_id, internal_id_in, VIS_OCTAL|VIS_CSTYLE);
|
||||||
|
|
||||||
|
if (*internal_id_in != '\0') {
|
||||||
|
find.uri = uri;
|
||||||
|
find.internal_id = internal_id;
|
||||||
|
|
||||||
|
hlu = RB_FIND(hyperlinks_by_uri_tree, &hl->by_uri, &find);
|
||||||
|
if (hlu != NULL) {
|
||||||
|
free (uri);
|
||||||
|
free (internal_id);
|
||||||
|
return (hlu->inner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
xasprintf(&external_id, "tmux%llX", hyperlinks_next_external_id++);
|
||||||
|
|
||||||
|
hlu = xcalloc(1, sizeof *hlu);
|
||||||
|
hlu->inner = hl->next_inner++;
|
||||||
|
hlu->internal_id = internal_id;
|
||||||
|
hlu->external_id = external_id;
|
||||||
|
hlu->uri = uri;
|
||||||
|
hlu->tree = hl;
|
||||||
|
RB_INSERT(hyperlinks_by_uri_tree, &hl->by_uri, hlu);
|
||||||
|
RB_INSERT(hyperlinks_by_inner_tree, &hl->by_inner, hlu);
|
||||||
|
|
||||||
|
TAILQ_INSERT_TAIL(&global_hyperlinks, hlu, list_entry);
|
||||||
|
if (++global_hyperlinks_count == MAX_HYPERLINKS)
|
||||||
|
hyperlinks_remove(TAILQ_FIRST(&global_hyperlinks));
|
||||||
|
|
||||||
|
return (hlu->inner);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get hyperlink by inner number. */
|
||||||
|
int
|
||||||
|
hyperlinks_get(struct hyperlinks *hl, u_int inner, const char **uri_out,
|
||||||
|
const char **internal_id_out, const char **external_id_out)
|
||||||
|
{
|
||||||
|
struct hyperlinks_uri find, *hlu;
|
||||||
|
|
||||||
|
find.inner = inner;
|
||||||
|
|
||||||
|
hlu = RB_FIND(hyperlinks_by_inner_tree, &hl->by_inner, &find);
|
||||||
|
if (hlu == NULL)
|
||||||
|
return (0);
|
||||||
|
if (internal_id_out != NULL)
|
||||||
|
*internal_id_out = hlu->internal_id;
|
||||||
|
if (external_id_out != NULL)
|
||||||
|
*external_id_out = hlu->external_id;
|
||||||
|
*uri_out = hlu->uri;
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize hyperlink set. */
|
||||||
|
struct hyperlinks *
|
||||||
|
hyperlinks_init(void)
|
||||||
|
{
|
||||||
|
struct hyperlinks *hl;
|
||||||
|
|
||||||
|
hl = xcalloc(1, sizeof *hl);
|
||||||
|
hl->next_inner = 1;
|
||||||
|
RB_INIT(&hl->by_uri);
|
||||||
|
RB_INIT(&hl->by_inner);
|
||||||
|
return (hl);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free all hyperlinks but not the set itself. */
|
||||||
|
void
|
||||||
|
hyperlinks_reset(struct hyperlinks *hl)
|
||||||
|
{
|
||||||
|
struct hyperlinks_uri *hlu, *hlu1;
|
||||||
|
|
||||||
|
RB_FOREACH_SAFE(hlu, hyperlinks_by_inner_tree, &hl->by_inner, hlu1)
|
||||||
|
hyperlinks_remove(hlu);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Free hyperlink set. */
|
||||||
|
void
|
||||||
|
hyperlinks_free(struct hyperlinks *hl)
|
||||||
|
{
|
||||||
|
hyperlinks_reset(hl);
|
||||||
|
free(hl);
|
||||||
|
}
|
||||||
600
image-sixel.c
Normal file
600
image-sixel.c
Normal file
@@ -0,0 +1,600 @@
|
|||||||
|
/* $OpenBSD$ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 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 <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "tmux.h"
|
||||||
|
|
||||||
|
#define SIXEL_WIDTH_LIMIT 10000
|
||||||
|
#define SIXEL_HEIGHT_LIMIT 10000
|
||||||
|
|
||||||
|
struct sixel_line {
|
||||||
|
u_int x;
|
||||||
|
uint16_t *data;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct sixel_image {
|
||||||
|
u_int x;
|
||||||
|
u_int y;
|
||||||
|
u_int xpixel;
|
||||||
|
u_int ypixel;
|
||||||
|
|
||||||
|
u_int *colours;
|
||||||
|
u_int ncolours;
|
||||||
|
|
||||||
|
u_int dx;
|
||||||
|
u_int dy;
|
||||||
|
u_int dc;
|
||||||
|
|
||||||
|
struct sixel_line *lines;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
sixel_parse_expand_lines(struct sixel_image *si, u_int y)
|
||||||
|
{
|
||||||
|
if (y <= si->y)
|
||||||
|
return (0);
|
||||||
|
if (y > SIXEL_HEIGHT_LIMIT)
|
||||||
|
return (1);
|
||||||
|
si->lines = xrecallocarray(si->lines, si->y, y, sizeof *si->lines);
|
||||||
|
si->y = y;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sixel_parse_expand_line(struct sixel_image *si, struct sixel_line *sl, u_int x)
|
||||||
|
{
|
||||||
|
if (x <= sl->x)
|
||||||
|
return (0);
|
||||||
|
if (x > SIXEL_WIDTH_LIMIT)
|
||||||
|
return (1);
|
||||||
|
if (x > si->x)
|
||||||
|
si->x = x;
|
||||||
|
sl->data = xrecallocarray(sl->data, sl->x, si->x, sizeof *sl->data);
|
||||||
|
sl->x = si->x;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static u_int
|
||||||
|
sixel_get_pixel(struct sixel_image *si, u_int x, u_int y)
|
||||||
|
{
|
||||||
|
struct sixel_line *sl;
|
||||||
|
|
||||||
|
if (y >= si->y)
|
||||||
|
return (0);
|
||||||
|
sl = &si->lines[y];
|
||||||
|
if (x >= sl->x)
|
||||||
|
return (0);
|
||||||
|
return (sl->data[x]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sixel_set_pixel(struct sixel_image *si, u_int x, u_int y, u_int c)
|
||||||
|
{
|
||||||
|
struct sixel_line *sl;
|
||||||
|
|
||||||
|
if (sixel_parse_expand_lines(si, y + 1) != 0)
|
||||||
|
return (1);
|
||||||
|
sl = &si->lines[y];
|
||||||
|
if (sixel_parse_expand_line(si, sl, x + 1) != 0)
|
||||||
|
return (1);
|
||||||
|
sl->data[x] = c;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
sixel_parse_write(struct sixel_image *si, u_int ch)
|
||||||
|
{
|
||||||
|
struct sixel_line *sl;
|
||||||
|
u_int i;
|
||||||
|
|
||||||
|
if (sixel_parse_expand_lines(si, si->dy + 6) != 0)
|
||||||
|
return (1);
|
||||||
|
sl = &si->lines[si->dy];
|
||||||
|
|
||||||
|
for (i = 0; i < 6; i++) {
|
||||||
|
if (sixel_parse_expand_line(si, sl, si->dx + 1) != 0)
|
||||||
|
return (1);
|
||||||
|
if (ch & (1 << i))
|
||||||
|
sl->data[si->dx] = si->dc;
|
||||||
|
sl++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
sixel_parse_attributes(struct sixel_image *si, const char *cp, const char *end)
|
||||||
|
{
|
||||||
|
const char *last;
|
||||||
|
char *endptr;
|
||||||
|
u_int x, y;
|
||||||
|
|
||||||
|
last = cp;
|
||||||
|
while (last != end) {
|
||||||
|
if (*last != ';' && (*last < '0' || *last > '9'))
|
||||||
|
break;
|
||||||
|
last++;
|
||||||
|
}
|
||||||
|
strtoul(cp, &endptr, 10);
|
||||||
|
if (endptr == last || *endptr != ';')
|
||||||
|
return (last);
|
||||||
|
strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr == last)
|
||||||
|
return (last);
|
||||||
|
if (*endptr != ';') {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
x = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr == last || *endptr != ';') {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (x > SIXEL_WIDTH_LIMIT) {
|
||||||
|
log_debug("%s: image is too wide", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
y = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr != last) {
|
||||||
|
log_debug("%s: extra ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (y > SIXEL_HEIGHT_LIMIT) {
|
||||||
|
log_debug("%s: image is too tall", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
si->x = x;
|
||||||
|
sixel_parse_expand_lines(si, y);
|
||||||
|
|
||||||
|
return (last);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
sixel_parse_colour(struct sixel_image *si, const char *cp, const char *end)
|
||||||
|
{
|
||||||
|
const char *last;
|
||||||
|
char *endptr;
|
||||||
|
u_int c, type, r, g, b;
|
||||||
|
|
||||||
|
last = cp;
|
||||||
|
while (last != end) {
|
||||||
|
if (*last != ';' && (*last < '0' || *last > '9'))
|
||||||
|
break;
|
||||||
|
last++;
|
||||||
|
}
|
||||||
|
|
||||||
|
c = strtoul(cp, &endptr, 10);
|
||||||
|
if (c > SIXEL_COLOUR_REGISTERS) {
|
||||||
|
log_debug("%s: too many colours", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
si->dc = c + 1;
|
||||||
|
if (endptr == last || *endptr != ';')
|
||||||
|
return (last);
|
||||||
|
|
||||||
|
type = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr == last || *endptr != ';') {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
r = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr == last || *endptr != ';') {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
g = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr == last || *endptr != ';') {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
b = strtoul(endptr + 1, &endptr, 10);
|
||||||
|
if (endptr != last) {
|
||||||
|
log_debug("%s: missing ;", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type != 1 && type != 2) {
|
||||||
|
log_debug("%s: invalid type %d", __func__, type);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (c + 1 > si->ncolours) {
|
||||||
|
si->colours = xrecallocarray(si->colours, si->ncolours, c + 1,
|
||||||
|
sizeof *si->colours);
|
||||||
|
si->ncolours = c + 1;
|
||||||
|
}
|
||||||
|
si->colours[c] = (type << 24) | (r << 16) | (g << 8) | b;
|
||||||
|
return (last);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *
|
||||||
|
sixel_parse_repeat(struct sixel_image *si, const char *cp, const char *end)
|
||||||
|
{
|
||||||
|
const char *last;
|
||||||
|
char tmp[32], ch;
|
||||||
|
u_int n = 0, i;
|
||||||
|
const char *errstr = NULL;
|
||||||
|
|
||||||
|
last = cp;
|
||||||
|
while (last != end) {
|
||||||
|
if (*last < '0' || *last > '9')
|
||||||
|
break;
|
||||||
|
tmp[n++] = *last++;
|
||||||
|
if (n == (sizeof tmp) - 1) {
|
||||||
|
log_debug("%s: repeat not terminated", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n == 0 || last == end) {
|
||||||
|
log_debug("%s: repeat not terminated", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
tmp[n] = '\0';
|
||||||
|
|
||||||
|
n = strtonum(tmp, 1, SIXEL_WIDTH_LIMIT, &errstr);
|
||||||
|
if (n == 0 || errstr != NULL) {
|
||||||
|
log_debug("%s: repeat too wide", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
ch = (*last++) - 0x3f;
|
||||||
|
for (i = 0; i < n; i++) {
|
||||||
|
if (sixel_parse_write(si, ch) != 0) {
|
||||||
|
log_debug("%s: width limit reached", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
si->dx++;
|
||||||
|
}
|
||||||
|
return (last);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sixel_image *
|
||||||
|
sixel_parse(const char *buf, size_t len, u_int xpixel, u_int ypixel)
|
||||||
|
{
|
||||||
|
struct sixel_image *si;
|
||||||
|
const char *cp = buf, *end = buf + len;
|
||||||
|
char ch;
|
||||||
|
|
||||||
|
if (len == 0 || len == 1 || *cp++ != 'q') {
|
||||||
|
log_debug("%s: empty image", __func__);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
si = xcalloc (1, sizeof *si);
|
||||||
|
si->xpixel = xpixel;
|
||||||
|
si->ypixel = ypixel;
|
||||||
|
|
||||||
|
while (cp != end) {
|
||||||
|
ch = *cp++;
|
||||||
|
switch (ch) {
|
||||||
|
case '"':
|
||||||
|
cp = sixel_parse_attributes(si, cp, end);
|
||||||
|
if (cp == NULL)
|
||||||
|
goto bad;
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
cp = sixel_parse_colour(si, cp, end);
|
||||||
|
if (cp == NULL)
|
||||||
|
goto bad;
|
||||||
|
break;
|
||||||
|
case '!':
|
||||||
|
cp = sixel_parse_repeat(si, cp, end);
|
||||||
|
if (cp == NULL)
|
||||||
|
goto bad;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
si->dx = 0;
|
||||||
|
si->dy += 6;
|
||||||
|
break;
|
||||||
|
case '$':
|
||||||
|
si->dx = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (ch < 0x20)
|
||||||
|
break;
|
||||||
|
if (ch < 0x3f || ch > 0x7e)
|
||||||
|
goto bad;
|
||||||
|
if (sixel_parse_write(si, ch - 0x3f) != 0) {
|
||||||
|
log_debug("%s: width limit reached", __func__);
|
||||||
|
goto bad;
|
||||||
|
}
|
||||||
|
si->dx++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (si->x == 0 || si->y == 0)
|
||||||
|
goto bad;
|
||||||
|
return (si);
|
||||||
|
|
||||||
|
bad:
|
||||||
|
free(si);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixel_free(struct sixel_image *si)
|
||||||
|
{
|
||||||
|
u_int y;
|
||||||
|
|
||||||
|
for (y = 0; y < si->y; y++)
|
||||||
|
free(si->lines[y].data);
|
||||||
|
free(si->lines);
|
||||||
|
|
||||||
|
free(si->colours);
|
||||||
|
free(si);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixel_log(struct sixel_image *si)
|
||||||
|
{
|
||||||
|
struct sixel_line *sl;
|
||||||
|
char s[SIXEL_WIDTH_LIMIT + 1];
|
||||||
|
u_int i, x, y, cx, cy;
|
||||||
|
|
||||||
|
sixel_size_in_cells(si, &cx, &cy);
|
||||||
|
log_debug("%s: image %ux%u (%ux%u)", __func__, si->x, si->y, cx, cy);
|
||||||
|
for (i = 0; i < si->ncolours; i++)
|
||||||
|
log_debug("%s: colour %u is %07x", __func__, i, si->colours[i]);
|
||||||
|
for (y = 0; y < si->y; y++) {
|
||||||
|
sl = &si->lines[y];
|
||||||
|
for (x = 0; x < si->x; x++) {
|
||||||
|
if (x >= sl->x)
|
||||||
|
s[x] = '_';
|
||||||
|
else if (sl->data[x] != 0)
|
||||||
|
s[x] = '0' + (sl->data[x] - 1) % 10;
|
||||||
|
else
|
||||||
|
s[x] = '.';
|
||||||
|
}
|
||||||
|
s[x] = '\0';
|
||||||
|
log_debug("%s: %4u: %s", __func__, y, s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sixel_size_in_cells(struct sixel_image *si, u_int *x, u_int *y)
|
||||||
|
{
|
||||||
|
if ((si->x % si->xpixel) == 0)
|
||||||
|
*x = (si->x / si->xpixel);
|
||||||
|
else
|
||||||
|
*x = 1 + (si->x / si->xpixel);
|
||||||
|
if ((si->y % si->ypixel) == 0)
|
||||||
|
*y = (si->y / si->ypixel);
|
||||||
|
else
|
||||||
|
*y = 1 + (si->y / si->ypixel);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sixel_image *
|
||||||
|
sixel_scale(struct sixel_image *si, u_int xpixel, u_int ypixel, u_int ox,
|
||||||
|
u_int oy, u_int sx, u_int sy, int colours)
|
||||||
|
{
|
||||||
|
struct sixel_image *new;
|
||||||
|
u_int cx, cy, pox, poy, psx, psy, tsx, tsy, px, py;
|
||||||
|
u_int x, y, i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We want to get the section of the image at ox,oy in image cells and
|
||||||
|
* map it onto the same size in terminal cells, remembering that we
|
||||||
|
* can only draw vertical sections of six pixels.
|
||||||
|
*/
|
||||||
|
|
||||||
|
sixel_size_in_cells(si, &cx, &cy);
|
||||||
|
if (ox >= cx)
|
||||||
|
return (NULL);
|
||||||
|
if (oy >= cy)
|
||||||
|
return (NULL);
|
||||||
|
if (ox + sx >= cx)
|
||||||
|
sx = cx - ox;
|
||||||
|
if (oy + sy >= cy)
|
||||||
|
sy = cy - oy;
|
||||||
|
|
||||||
|
if (xpixel == 0)
|
||||||
|
xpixel = si->xpixel;
|
||||||
|
if (ypixel == 0)
|
||||||
|
ypixel = si->ypixel;
|
||||||
|
|
||||||
|
pox = ox * si->xpixel;
|
||||||
|
poy = oy * si->ypixel;
|
||||||
|
psx = sx * si->xpixel;
|
||||||
|
psy = sy * si->ypixel;
|
||||||
|
|
||||||
|
tsx = sx * xpixel;
|
||||||
|
tsy = ((sy * ypixel) / 6) * 6;
|
||||||
|
|
||||||
|
new = xcalloc (1, sizeof *si);
|
||||||
|
new->xpixel = xpixel;
|
||||||
|
new->ypixel = ypixel;
|
||||||
|
|
||||||
|
for (y = 0; y < tsy; y++) {
|
||||||
|
py = poy + ((double)y * psy / tsy);
|
||||||
|
for (x = 0; x < tsx; x++) {
|
||||||
|
px = pox + ((double)x * psx / tsx);
|
||||||
|
sixel_set_pixel(new, x, y, sixel_get_pixel(si, px, py));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colours) {
|
||||||
|
new->colours = xmalloc(si->ncolours * sizeof *new->colours);
|
||||||
|
for (i = 0; i < si->ncolours; i++)
|
||||||
|
new->colours[i] = si->colours[i];
|
||||||
|
new->ncolours = si->ncolours;
|
||||||
|
}
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sixel_print_add(char **buf, size_t *len, size_t *used, const char *s,
|
||||||
|
size_t slen)
|
||||||
|
{
|
||||||
|
if (*used + slen >= *len + 1) {
|
||||||
|
(*len) *= 2;
|
||||||
|
*buf = xrealloc(*buf, *len);
|
||||||
|
}
|
||||||
|
memcpy(*buf + *used, s, slen);
|
||||||
|
(*used) += slen;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sixel_print_repeat(char **buf, size_t *len, size_t *used, u_int count, char ch)
|
||||||
|
{
|
||||||
|
char tmp[16];
|
||||||
|
size_t tmplen;
|
||||||
|
|
||||||
|
if (count == 1)
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
else if (count == 2) {
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
} else if (count == 3) {
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
sixel_print_add(buf, len, used, &ch, 1);
|
||||||
|
} else if (count != 0) {
|
||||||
|
tmplen = xsnprintf(tmp, sizeof tmp, "!%u%c", count, ch);
|
||||||
|
sixel_print_add(buf, len, used, tmp, tmplen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
sixel_print(struct sixel_image *si, struct sixel_image *map, size_t *size)
|
||||||
|
{
|
||||||
|
char *buf, tmp[64], *contains, data, last = 0;
|
||||||
|
size_t len, used = 0, tmplen;
|
||||||
|
u_int *colours, ncolours, i, c, x, y, count;
|
||||||
|
struct sixel_line *sl;
|
||||||
|
|
||||||
|
if (map != NULL) {
|
||||||
|
colours = map->colours;
|
||||||
|
ncolours = map->ncolours;
|
||||||
|
} else {
|
||||||
|
colours = si->colours;
|
||||||
|
ncolours = si->ncolours;
|
||||||
|
}
|
||||||
|
contains = xcalloc(1, ncolours);
|
||||||
|
|
||||||
|
len = 8192;
|
||||||
|
buf = xmalloc(len);
|
||||||
|
|
||||||
|
sixel_print_add(&buf, &len, &used, "\033Pq", 3);
|
||||||
|
|
||||||
|
tmplen = xsnprintf(tmp, sizeof tmp, "\"1;1;%u;%u", si->x, si->y);
|
||||||
|
sixel_print_add(&buf, &len, &used, tmp, tmplen);
|
||||||
|
|
||||||
|
for (i = 0; i < ncolours; i++) {
|
||||||
|
c = colours[i];
|
||||||
|
tmplen = xsnprintf(tmp, sizeof tmp, "#%u;%u;%u;%u;%u",
|
||||||
|
i, c >> 24, (c >> 16) & 0xff, (c >> 8) & 0xff, c & 0xff);
|
||||||
|
sixel_print_add(&buf, &len, &used, tmp, tmplen);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (y = 0; y < si->y; y += 6) {
|
||||||
|
memset(contains, 0, ncolours);
|
||||||
|
for (x = 0; x < si->x; x++) {
|
||||||
|
for (i = 0; i < 6; i++) {
|
||||||
|
if (y + i >= si->y)
|
||||||
|
break;
|
||||||
|
sl = &si->lines[y + i];
|
||||||
|
if (x < sl->x && sl->data[x] != 0)
|
||||||
|
contains[sl->data[x] - 1] = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (c = 0; c < ncolours; c++) {
|
||||||
|
if (!contains[c])
|
||||||
|
continue;
|
||||||
|
tmplen = xsnprintf(tmp, sizeof tmp, "#%u", c);
|
||||||
|
sixel_print_add(&buf, &len, &used, tmp, tmplen);
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
for (x = 0; x < si->x; x++) {
|
||||||
|
data = 0;
|
||||||
|
for (i = 0; i < 6; i++) {
|
||||||
|
if (y + i >= si->y)
|
||||||
|
break;
|
||||||
|
sl = &si->lines[y + i];
|
||||||
|
if (x < sl->x && sl->data[x] == c + 1)
|
||||||
|
data |= (1 << i);
|
||||||
|
}
|
||||||
|
data += 0x3f;
|
||||||
|
if (data != last) {
|
||||||
|
sixel_print_repeat(&buf, &len, &used,
|
||||||
|
count, last);
|
||||||
|
last = data;
|
||||||
|
count = 1;
|
||||||
|
} else
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
sixel_print_repeat(&buf, &len, &used, count, data);
|
||||||
|
sixel_print_add(&buf, &len, &used, "$", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buf[used - 1] == '$')
|
||||||
|
used--;
|
||||||
|
if (buf[used - 1] != '-')
|
||||||
|
sixel_print_add(&buf, &len, &used, "-", 1);
|
||||||
|
}
|
||||||
|
if (buf[used - 1] == '$' || buf[used - 1] == '-')
|
||||||
|
used--;
|
||||||
|
|
||||||
|
sixel_print_add(&buf, &len, &used, "\033\\", 2);
|
||||||
|
|
||||||
|
buf[used] = '\0';
|
||||||
|
if (size != NULL)
|
||||||
|
*size = used;
|
||||||
|
|
||||||
|
free(contains);
|
||||||
|
return (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct screen *
|
||||||
|
sixel_to_screen(struct sixel_image *si)
|
||||||
|
{
|
||||||
|
struct screen *s;
|
||||||
|
struct screen_write_ctx ctx;
|
||||||
|
struct grid_cell gc;
|
||||||
|
u_int x, y, sx, sy;
|
||||||
|
|
||||||
|
sixel_size_in_cells(si, &sx, &sy);
|
||||||
|
|
||||||
|
s = xmalloc(sizeof *s);
|
||||||
|
screen_init(s, sx, sy, 0);
|
||||||
|
|
||||||
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||||
|
gc.attr |= (GRID_ATTR_CHARSET|GRID_ATTR_DIM);
|
||||||
|
utf8_set(&gc.data, '~');
|
||||||
|
|
||||||
|
screen_write_start(&ctx, s);
|
||||||
|
if (sx == 1 || sy == 1) {
|
||||||
|
for (y = 0; y < sy; y++) {
|
||||||
|
for (x = 0; x < sx; x++)
|
||||||
|
grid_view_set_cell(s->grid, x, y, &gc);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
screen_write_box(&ctx, sx, sy, BOX_LINES_DEFAULT, NULL, NULL);
|
||||||
|
for (y = 1; y < sy - 1; y++) {
|
||||||
|
for (x = 1; x < sx - 1; x++)
|
||||||
|
grid_view_set_cell(s->grid, x, y, &gc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
screen_write_stop(&ctx);
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user