mirror of
https://github.com/tmux/tmux.git
synced 2026-03-11 19:15:45 +00:00
Compare commits
1079 Commits
3.3
...
ta/kitty-i
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1cf7889fd7 | ||
|
|
9c3ec2b8eb | ||
|
|
aefdb34846 | ||
|
|
5a233e26ec | ||
|
|
1634db8589 | ||
|
|
3b7e9fb175 | ||
|
|
cf6cbe430c | ||
|
|
d9d2b2f1ee | ||
|
|
1e208abd93 | ||
|
|
d32088b58a | ||
|
|
6d37cc94a7 | ||
|
|
55722a7ed7 | ||
|
|
d2fa20a390 | ||
|
|
bcbad050d4 | ||
|
|
27698c468b | ||
|
|
49bb43047d | ||
|
|
77ce0a837d | ||
|
|
bbbfa8f360 | ||
|
|
d781d2eaa1 | ||
|
|
f33b14bda6 | ||
|
|
e603549563 | ||
|
|
e80e0c761a | ||
|
|
9e804202b6 | ||
|
|
0c678b1e1a | ||
|
|
4cb29deb93 | ||
|
|
5413953d30 | ||
|
|
50e51b4513 | ||
|
|
ee0647aba6 | ||
|
|
35be70f1f0 | ||
|
|
dbb23d2182 | ||
|
|
478eaea982 | ||
|
|
0800e51d41 | ||
|
|
5ff385f8a9 | ||
|
|
5b3c642195 | ||
|
|
bd6e201926 | ||
|
|
08779aa2a3 | ||
|
|
09bd686327 | ||
|
|
9316476a73 | ||
|
|
00946007d8 | ||
|
|
bc47bc7c22 | ||
|
|
dc693601f4 | ||
|
|
f1f9c63cdb | ||
|
|
0cc4f0fd76 | ||
|
|
0dc1b5adfb | ||
|
|
a76e6eca6b | ||
|
|
8c7278b53a | ||
|
|
50a3b4c777 | ||
|
|
3094ca1da5 | ||
|
|
23ad10c849 | ||
|
|
c9fb989a31 | ||
|
|
8356578a54 | ||
|
|
0310404155 | ||
|
|
03f8690f9c | ||
|
|
4cc3de4f84 | ||
|
|
fedd4440f0 | ||
|
|
55cedc24fa | ||
|
|
c9162837a0 | ||
|
|
f218463976 | ||
|
|
1f0c54f7ea | ||
|
|
d3522c328c | ||
|
|
7e50eb0e83 | ||
|
|
5b455abecc | ||
|
|
7d41761e84 | ||
|
|
25f6d8b1e9 | ||
|
|
5a33616e65 | ||
|
|
1cf17b06ae | ||
|
|
aa03706ed0 | ||
|
|
d8794e2b30 | ||
|
|
b7939eb266 | ||
|
|
19b9a34c48 | ||
|
|
f016e08153 | ||
|
|
7b1c503086 | ||
|
|
5865001e4a | ||
|
|
62944da74b | ||
|
|
588013bb44 | ||
|
|
615c27c117 | ||
|
|
3c3d9ce3a9 | ||
|
|
66011fe48b | ||
|
|
d7f59eccaf | ||
|
|
e652213855 | ||
|
|
f70150a663 | ||
|
|
fe52f76913 | ||
|
|
0d9c3c895c | ||
|
|
6525bb7cef | ||
|
|
0790e74f84 | ||
|
|
195a9cfd88 | ||
|
|
ecbf8d76d0 | ||
|
|
818745a605 | ||
|
|
26aacd0e32 | ||
|
|
8e06739e26 | ||
|
|
ab1f2ef71c | ||
|
|
d2e09cb259 | ||
|
|
bf8ea85bd7 | ||
|
|
9c0aeaff40 | ||
|
|
95b4bb51c6 | ||
|
|
1e5f93b7b6 | ||
|
|
b89d46bb00 | ||
|
|
97d61131df | ||
|
|
5721767921 | ||
|
|
a443531280 | ||
|
|
ad083677c5 | ||
|
|
426467856d | ||
|
|
844042744e | ||
|
|
65b3a95be8 | ||
|
|
ca95950148 | ||
|
|
6234d79852 | ||
|
|
a5d8b92012 | ||
|
|
890cfc6dc3 | ||
|
|
0e6fc2e88b | ||
|
|
c8ccd420be | ||
|
|
ff4f6b9066 | ||
|
|
7cffa2de78 | ||
|
|
e2afaaea75 | ||
|
|
75d3974c12 | ||
|
|
583f12ea71 | ||
|
|
3de7a8ad8d | ||
|
|
f6c9052082 | ||
|
|
f226804149 | ||
|
|
cf94486e32 | ||
|
|
035a2f35d4 | ||
|
|
9b7732eac4 | ||
|
|
5f9dac8abc | ||
|
|
ccd4dd7ff2 | ||
|
|
77417b7cbe | ||
|
|
6a7cd79a63 | ||
|
|
baa3b51b3e | ||
|
|
abeba4910c | ||
|
|
356d0aedbd | ||
|
|
45f23f3a59 | ||
|
|
6ef7375ade | ||
|
|
00030aabf7 | ||
|
|
f72832cc08 | ||
|
|
b5c33ca2b7 | ||
|
|
d607399850 | ||
|
|
d005803934 | ||
|
|
a22ec275b4 | ||
|
|
188f963fe0 | ||
|
|
9c5df33325 | ||
|
|
74f60951cc | ||
|
|
54202fcaad | ||
|
|
fe645c5bcc | ||
|
|
86c15d7ae9 | ||
|
|
3c36d5e433 | ||
|
|
1c7e164c22 | ||
|
|
ce7eb22e3a | ||
|
|
739a97140f | ||
|
|
99ed397e9c | ||
|
|
d2c7668bc2 | ||
|
|
7abf3e8bdf | ||
|
|
506b4db762 | ||
|
|
21c27fdcae | ||
|
|
672e89a640 | ||
|
|
4b810ae493 | ||
|
|
52e2a7d990 | ||
|
|
2e5e9c0298 | ||
|
|
afa05ae15e | ||
|
|
f58b8d0d6a | ||
|
|
5c73d3878d | ||
|
|
ef0a7e328c | ||
|
|
cc117b5048 | ||
|
|
faebe7a70a | ||
|
|
01962e25dc | ||
|
|
ff207eb583 | ||
|
|
8e922ab690 | ||
|
|
1a3db6b65e | ||
|
|
987e05ff31 | ||
|
|
2fc123cf4a | ||
|
|
3b57077d01 | ||
|
|
33c1ba1549 | ||
|
|
bd16b22dac | ||
|
|
0929d8ddfa | ||
|
|
9d6c69ebde | ||
|
|
1bcd360dfe | ||
|
|
1f2210a3ce | ||
|
|
2fe1378d3a | ||
|
|
796539c60b | ||
|
|
700936b2ad | ||
|
|
a28dbe3a59 | ||
|
|
820df0f551 | ||
|
|
ee9cf1bbaa | ||
|
|
52917abe21 | ||
|
|
a40f98df0a | ||
|
|
2c78a5aceb | ||
|
|
02a8e3fd34 | ||
|
|
322adfbdde | ||
|
|
194d0a0e25 | ||
|
|
b2d6ebaa10 | ||
|
|
bfecbb0685 | ||
|
|
e4c552f5a5 | ||
|
|
04f32073c0 | ||
|
|
e9afd2bb5e | ||
|
|
55d660a548 | ||
|
|
dfaf47d97c | ||
|
|
640e1a7643 | ||
|
|
2a0b078e15 | ||
|
|
0af04295f3 | ||
|
|
3542bfa5b8 | ||
|
|
e3a54ed0f4 | ||
|
|
ec4b5b52af | ||
|
|
a0dfef3b04 | ||
|
|
6db6a30ab5 | ||
|
|
bfa2f73335 | ||
|
|
1decccace7 | ||
|
|
ee53d49059 | ||
|
|
0dac7fe434 | ||
|
|
a6690032ad | ||
|
|
f949f9a23a | ||
|
|
00cef3e6be | ||
|
|
3f4a8713c9 | ||
|
|
7c188aec3c | ||
|
|
f0dec832b8 | ||
|
|
ca74fa1db0 | ||
|
|
987986631d | ||
|
|
1d89233047 | ||
|
|
348f16093c | ||
|
|
2a3ec87887 | ||
|
|
b52dcff745 | ||
|
|
f372112a8d | ||
|
|
72117debf7 | ||
|
|
2f3c71595b | ||
|
|
113aaf37fc | ||
|
|
768042d29d | ||
|
|
db274f9c39 | ||
|
|
66279c124e | ||
|
|
b335419505 | ||
|
|
3c9e10139f | ||
|
|
34898c89cd | ||
|
|
40600eebfa | ||
|
|
12497ecade | ||
|
|
9e21f426c0 | ||
|
|
c77d49f67e | ||
|
|
33cfe8b809 | ||
|
|
0d0ef5d0d2 | ||
|
|
d65bac979d | ||
|
|
c1667bd85e | ||
|
|
815f7ecffb | ||
|
|
44c0443983 | ||
|
|
3051076dd1 | ||
|
|
d90b414223 | ||
|
|
8cb2805eb7 | ||
|
|
e5ab5995db | ||
|
|
e774b89062 | ||
|
|
29db8ac36e | ||
|
|
be2d4aa434 | ||
|
|
1e61e52400 | ||
|
|
4bdfbfa854 | ||
|
|
2c08960f4e | ||
|
|
1a419609e3 | ||
|
|
f812b8d304 | ||
|
|
ff6eefd7c7 | ||
|
|
0c5abfefd3 | ||
|
|
e560a09db0 | ||
|
|
9bf8ca5856 | ||
|
|
410abb5afb | ||
|
|
482aa937b1 | ||
|
|
b4ba6e49af | ||
|
|
010394ab63 | ||
|
|
7cbb96528c | ||
|
|
aa420cd54a | ||
|
|
d5302ec327 | ||
|
|
f31a2d229c | ||
|
|
35ad72e56f | ||
|
|
f501817154 | ||
|
|
449f255f3e | ||
|
|
21d890e6df | ||
|
|
feb3b90596 | ||
|
|
0ff2676a25 | ||
|
|
3e28777ecb | ||
|
|
7516f8e94f | ||
|
|
ac574b6782 | ||
|
|
50dafd6187 | ||
|
|
d4f129b513 | ||
|
|
9a72317c4f | ||
|
|
b21b1ee9af | ||
|
|
c62fe6dac8 | ||
|
|
9dc136f445 | ||
|
|
418bf148e0 | ||
|
|
408721ae37 | ||
|
|
b1b6850fa9 | ||
|
|
d73196750f | ||
|
|
093754db3f | ||
|
|
7cc15969ff | ||
|
|
b53cf70262 | ||
|
|
1dadd6c9ae | ||
|
|
a7a94cb86f | ||
|
|
3d6954f0f0 | ||
|
|
267efefdfa | ||
|
|
6a3170386e | ||
|
|
4d83eef756 | ||
|
|
44b7a2d1f9 | ||
|
|
c32570c602 | ||
|
|
9702ef3f91 | ||
|
|
b2194ac549 | ||
|
|
b5413dacc7 | ||
|
|
aa33757e45 | ||
|
|
a0065bea04 | ||
|
|
5c89d835a6 | ||
|
|
cfb906a0ce | ||
|
|
af36d7c430 | ||
|
|
0c9165fc71 | ||
|
|
fa63088dce | ||
|
|
0b7235c5f0 | ||
|
|
ca0f0419e6 | ||
|
|
3520e833a4 | ||
|
|
bb4866047a | ||
|
|
2070731af1 | ||
|
|
a5909b450c | ||
|
|
94bafa5aaf | ||
|
|
7325da3052 | ||
|
|
e6d275b371 | ||
|
|
f4c0fe2ede | ||
|
|
12452f4427 | ||
|
|
1370791734 | ||
|
|
0646814235 | ||
|
|
84775130a0 | ||
|
|
4ce893ebc0 | ||
|
|
3ae0d560be | ||
|
|
06c84dba59 | ||
|
|
d90e7623c6 | ||
|
|
b13005e802 | ||
|
|
05b2893b9f | ||
|
|
1bf2023ed4 | ||
|
|
6f9bcb7fee | ||
|
|
6d94909c08 | ||
|
|
86153fbba9 | ||
|
|
4f38af01e0 | ||
|
|
a6588d6918 | ||
|
|
720d1e831d | ||
|
|
206f492401 | ||
|
|
fa5f3cef3d | ||
|
|
c70d0a6a69 | ||
|
|
6549aaf393 | ||
|
|
6378c87d15 | ||
|
|
4a0eff1296 | ||
|
|
9c07903ae9 | ||
|
|
32b7b3a6f7 | ||
|
|
041bbf8bdf | ||
|
|
701f6b4b2f | ||
|
|
bddd019a04 | ||
|
|
865117a05f | ||
|
|
e6bac234db | ||
|
|
9f1fac9142 | ||
|
|
9831175a2d | ||
|
|
7e43953937 | ||
|
|
28481e984b | ||
|
|
30e4f119d3 | ||
|
|
01da87c112 | ||
|
|
e7f15d09be | ||
|
|
cbb3c4bfed | ||
|
|
d24993aeab | ||
|
|
d858ad1179 | ||
|
|
96244dd727 | ||
|
|
b38b5d3df2 | ||
|
|
ad3e6ff054 | ||
|
|
522652913f | ||
|
|
43e88c892d | ||
|
|
d82d9468b4 | ||
|
|
d7f75ac985 | ||
|
|
1dbceaa790 | ||
|
|
77ca59acac | ||
|
|
7be0613657 | ||
|
|
b9ad9186fe | ||
|
|
3f4b154b70 | ||
|
|
ff73c95547 | ||
|
|
aa0d05f676 | ||
|
|
545832e9fa | ||
|
|
a0ac2a5d63 | ||
|
|
833c7fbf6d | ||
|
|
faf2a44890 | ||
|
|
d194ceb604 | ||
|
|
37a2c98d3d | ||
|
|
79b02998a6 | ||
|
|
1ce1e7ef27 | ||
|
|
7499d925da | ||
|
|
367f17a4ff | ||
|
|
3d2b26dcfe | ||
|
|
6106a0f2c4 | ||
|
|
1926c1b683 | ||
|
|
6cc1a607fc | ||
|
|
1905afb3d8 | ||
|
|
345a45083d | ||
|
|
3a3babf597 | ||
|
|
f367e3a6c8 | ||
|
|
f2283b0cb5 | ||
|
|
26081ac125 | ||
|
|
36fba4cc54 | ||
|
|
58b4286edb | ||
|
|
b0b6a6f665 | ||
|
|
63e5989f53 | ||
|
|
9da5707d3e | ||
|
|
55292b72d1 | ||
|
|
06b1ad6241 | ||
|
|
1efe41b9b9 | ||
|
|
1198eed632 | ||
|
|
0772fe822a | ||
|
|
f53fac1b56 | ||
|
|
68f2ac9296 | ||
|
|
b4f8340f16 | ||
|
|
d2f73c17d5 | ||
|
|
5db914b745 | ||
|
|
cd3d2910ee | ||
|
|
de7653f5a4 | ||
|
|
b905039ed2 | ||
|
|
f0a85d0469 | ||
|
|
ac2779f4d8 | ||
|
|
68ffe65499 | ||
|
|
3e14e7c48b | ||
|
|
b526e678b5 | ||
|
|
d3c39375d5 | ||
|
|
a7991dcbad | ||
|
|
47dff97834 | ||
|
|
2905395695 | ||
|
|
4bf38da4d4 | ||
|
|
9b37b9285e | ||
|
|
dfdced2ab1 | ||
|
|
c2a95a372f | ||
|
|
ef923d28ff | ||
|
|
53b0e0bc02 | ||
|
|
096c4b3e63 | ||
|
|
b8189d6ee3 | ||
|
|
f41dc91357 | ||
|
|
ef0c12ad9e | ||
|
|
9e1f110db0 | ||
|
|
483b2b3edb | ||
|
|
34a35b0f09 | ||
|
|
aca3ffb30a | ||
|
|
c3c4524def | ||
|
|
f101762d1b | ||
|
|
a541be3951 | ||
|
|
b7d640e764 | ||
|
|
969f6a60c3 | ||
|
|
6703cb85d9 | ||
|
|
111e16e772 | ||
|
|
3eb93383a3 | ||
|
|
817b621d20 | ||
|
|
5eb30c1543 | ||
|
|
d4b8635f50 | ||
|
|
4e4fe3eb39 | ||
|
|
882fb4d295 | ||
|
|
eaf70c955b | ||
|
|
3543d79048 | ||
|
|
94783addfc | ||
|
|
91c0de60b4 | ||
|
|
21f7db4c4d | ||
|
|
f224d61f37 | ||
|
|
d938ab5dd7 | ||
|
|
9a8f46e554 | ||
|
|
27ee0c9c3b | ||
|
|
251a87e2d2 | ||
|
|
084e6ee9ec | ||
|
|
18331e39bf | ||
|
|
250c88efdc | ||
|
|
9a377485be | ||
|
|
47a56c11f2 | ||
|
|
c4b9716873 | ||
|
|
ec119b2f9e | ||
|
|
5d1a6acc84 | ||
|
|
80eb460fc9 | ||
|
|
ef68debc8d | ||
|
|
4c12ac9fb8 | ||
|
|
244bb726e2 | ||
|
|
6ab268c7bb | ||
|
|
0c9f8ff189 | ||
|
|
dd7d04be95 | ||
|
|
58392d29da | ||
|
|
9260f5dc96 | ||
|
|
62a6c16b43 | ||
|
|
31e8d4676a | ||
|
|
d3cbe00f78 | ||
|
|
97fe3563fa | ||
|
|
37ad1e2f6d | ||
|
|
00894d188d | ||
|
|
2a5eba7899 | ||
|
|
bf30492d57 | ||
|
|
e00853ee82 | ||
|
|
e75f3a0060 | ||
|
|
eece41547e | ||
|
|
c311202b73 | ||
|
|
e149d29803 | ||
|
|
190ddda572 | ||
|
|
6b470c5222 | ||
|
|
6b32d195e8 | ||
|
|
bec6ce54c1 | ||
|
|
106d1c3538 | ||
|
|
ae8f2208c9 | ||
|
|
5c3cf2f08b | ||
|
|
102f34090d | ||
|
|
99790c90aa | ||
|
|
6d792e4123 | ||
|
|
98e322d5a5 | ||
|
|
01edce40f3 | ||
|
|
0549f87ccc | ||
|
|
72cd0eac29 | ||
|
|
f0c68533c4 | ||
|
|
9e4a9c51cc | ||
|
|
6874ec0dcc | ||
|
|
252f41818e | ||
|
|
d361f21065 | ||
|
|
feb090abb3 | ||
|
|
db771ec6e3 | ||
|
|
6f7db82b18 | ||
|
|
67cc7f6dc6 | ||
|
|
db978db271 | ||
|
|
363f35f076 | ||
|
|
49b7276f2a | ||
|
|
f57131e11b | ||
|
|
420af9e108 | ||
|
|
ceaf9b7452 | ||
|
|
5fd45b3892 | ||
|
|
64d82d5988 | ||
|
|
0f308bd18f | ||
|
|
1365f1ce52 | ||
|
|
7fc4e54efe | ||
|
|
c98c08c232 | ||
|
|
990c724bd8 | ||
|
|
b82c7b40b0 | ||
|
|
70299c6646 | ||
|
|
ea6c5053c8 | ||
|
|
3f4fd45d5c | ||
|
|
7c7e88253e | ||
|
|
bb94a5437d | ||
|
|
273f9b2027 | ||
|
|
b6d0b4be30 | ||
|
|
2dce45f427 | ||
|
|
a3ede3106a | ||
|
|
dd9722184b | ||
|
|
a854e36f2b | ||
|
|
be594ff8a4 | ||
|
|
c66628e52b | ||
|
|
350a151ee4 | ||
|
|
d35458e3fe | ||
|
|
d6883c0266 | ||
|
|
563ed05353 | ||
|
|
f527412d9b | ||
|
|
713cacab1e | ||
|
|
846f813565 | ||
|
|
c26d71d3e9 | ||
|
|
c8677d3272 | ||
|
|
596ea62dc3 | ||
|
|
1fe30bb2e8 | ||
|
|
809d659e64 | ||
|
|
09f4e43189 | ||
|
|
679bbdcf8f | ||
|
|
a0c79aa87b | ||
|
|
46f3846659 | ||
|
|
bbc3cc558c | ||
|
|
c8bd42de16 | ||
|
|
62e15e905b | ||
|
|
125a7b9177 | ||
|
|
895044c52b | ||
|
|
40c01c2d37 | ||
|
|
911d768b71 | ||
|
|
71a503e40c | ||
|
|
487b0ee124 | ||
|
|
eaec0a48f4 | ||
|
|
fdbc6cdea5 | ||
|
|
9623ec3ee4 | ||
|
|
63582c154c | ||
|
|
914815e70f | ||
|
|
354926a956 | ||
|
|
df303770ea | ||
|
|
a269c33a54 | ||
|
|
eb04f9314b | ||
|
|
a9d0461839 | ||
|
|
71aa4fe767 | ||
|
|
cfd3c02306 | ||
|
|
35104059ed | ||
|
|
934035db71 | ||
|
|
8ff65230e1 | ||
|
|
cb00e869ea | ||
|
|
f8b56fdc3f | ||
|
|
2d8b6fcf23 | ||
|
|
6ddee22f81 | ||
|
|
66c738bc10 | ||
|
|
bcc47add38 | ||
|
|
d326c51d79 | ||
|
|
940fdf7ed0 | ||
|
|
4f5d6d97d3 | ||
|
|
00412b570b | ||
|
|
6a35b8ad07 | ||
|
|
735082b7c2 | ||
|
|
5b7bdc82c8 | ||
|
|
a3dea81b49 | ||
|
|
486221f206 | ||
|
|
9528d7470b | ||
|
|
933d6b90ed | ||
|
|
a869693405 | ||
|
|
549c35b061 | ||
|
|
42959db0a4 | ||
|
|
114977dd25 | ||
|
|
aba8ffbe7b | ||
|
|
455a2b3705 | ||
|
|
e0638c48cd | ||
|
|
41f6b691e3 | ||
|
|
0f30fa34e3 | ||
|
|
e486f5ffdc | ||
|
|
5a68730e2f | ||
|
|
7997fd3152 | ||
|
|
048db82041 | ||
|
|
16b44d2a5b | ||
|
|
34775fc235 | ||
|
|
f2fd8c854a | ||
|
|
9f2a853d87 | ||
|
|
7a78cdf78c | ||
|
|
356887bca2 | ||
|
|
2df15ad08c | ||
|
|
780a87be9a | ||
|
|
1e303b6a9d | ||
|
|
8d2aee34ab | ||
|
|
05116cefe6 | ||
|
|
ce4be58eef | ||
|
|
8d6eb4be40 | ||
|
|
834ec91b44 | ||
|
|
38c38f1c64 | ||
|
|
ddf6af79e3 | ||
|
|
826ba515be | ||
|
|
729bded8bf | ||
|
|
b95a06d2d4 | ||
|
|
157d748949 | ||
|
|
1c1f4c1219 | ||
|
|
17bab32794 | ||
|
|
868ddf5d38 | ||
|
|
a1b7a3bcb3 | ||
|
|
cbd419c483 | ||
|
|
25b1cc1e8e | ||
|
|
89adec0ca5 | ||
|
|
f95d055e04 | ||
|
|
7b148f7b5b | ||
|
|
9bd039d1bc | ||
|
|
7c30056d96 | ||
|
|
ac44566c9c | ||
|
|
64f1076d97 | ||
|
|
489c69f5ed | ||
|
|
f897049935 | ||
|
|
d8b66110f7 | ||
|
|
8b1a3bb2e5 | ||
|
|
37771a5a8d | ||
|
|
3a8a31d8d2 | ||
|
|
c36ffcbe56 | ||
|
|
3d8ead8a97 | ||
|
|
141cd78407 | ||
|
|
d0c8124661 | ||
|
|
2917bc5274 | ||
|
|
2d1e93447e | ||
|
|
31b6c9356c | ||
|
|
9e2a7c28f5 | ||
|
|
73b2277af8 | ||
|
|
a84c109604 | ||
|
|
4823acca8f | ||
|
|
34807388b0 | ||
|
|
08be883297 | ||
|
|
13bd0e46db | ||
|
|
6e9a914014 | ||
|
|
7990e5fa8f | ||
|
|
4860a58d07 | ||
|
|
99af9f23bd | ||
|
|
9ebbe2cca7 | ||
|
|
692bae9ea6 | ||
|
|
a6645c4de4 | ||
|
|
06292baadc | ||
|
|
ceda0a68ae | ||
|
|
4fa90c9acf | ||
|
|
c7e61a01e5 | ||
|
|
963e824f5f | ||
|
|
de6bce057a | ||
|
|
937ba1d8dd | ||
|
|
651891c3bd | ||
|
|
4008e2ff6d | ||
|
|
b88130d24b | ||
|
|
fc7ee7efc7 | ||
|
|
d0eb3fe543 | ||
|
|
2ac0faf119 | ||
|
|
775789fbd5 | ||
|
|
7b6fbe7262 | ||
|
|
109d2bda1a | ||
|
|
ddd4e57c65 | ||
|
|
3c2621b41b | ||
|
|
5039be657c | ||
|
|
d02254f754 | ||
|
|
aa1353947e | ||
|
|
171004dfd0 | ||
|
|
c773fe89e7 | ||
|
|
093b5a5518 | ||
|
|
db1665868f | ||
|
|
c07e856d24 | ||
|
|
692ce59bce | ||
|
|
9e7c1aee48 | ||
|
|
4c2eedca5a | ||
|
|
ac6c1e9589 | ||
|
|
0903790b00 | ||
|
|
03de52653e | ||
|
|
da06719309 | ||
|
|
fc84097379 | ||
|
|
4fd725c6e1 | ||
|
|
d39dcea30a | ||
|
|
bfd65398a9 | ||
|
|
452d987e0e | ||
|
|
8ef899f315 | ||
|
|
a18d1146aa | ||
|
|
5b5004e5ac | ||
|
|
6ff8f8fbf9 | ||
|
|
c9616700ca | ||
|
|
4c928dce74 | ||
|
|
fb37d52dde | ||
|
|
363d9c401e | ||
|
|
8643ece345 | ||
|
|
9ba433e521 | ||
|
|
3823fa2c57 | ||
|
|
0a8571b6fe | ||
|
|
ea9f416c99 | ||
|
|
036d8993e6 | ||
|
|
e8530c9fee | ||
|
|
dd4c0109a9 | ||
|
|
43530d4397 | ||
|
|
553d4cba79 | ||
|
|
c62a9ca16b | ||
|
|
424f13fe13 | ||
|
|
4bb6da75ba | ||
|
|
a28175dbfd | ||
|
|
fc204bb5e5 | ||
|
|
6207a45139 | ||
|
|
3c3643f580 | ||
|
|
89c1c43ef9 | ||
|
|
2e9d7ebf15 | ||
|
|
d8ddeec7db | ||
|
|
6f0254e6a8 | ||
|
|
aa17f0e0c1 | ||
|
|
0ae8b681b2 | ||
|
|
6c0067c103 | ||
|
|
5458cb2850 | ||
|
|
0c374868ca | ||
|
|
bf5d3f2e26 | ||
|
|
d5ef837f63 | ||
|
|
b79e28b2c3 | ||
|
|
8ffd5458ff | ||
|
|
b54e1fc4f7 | ||
|
|
bdb6321229 | ||
|
|
bd29a48b56 | ||
|
|
f3f1c3db58 | ||
|
|
608d113486 | ||
|
|
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 |
5
.github/CONTRIBUTING.md
vendored
5
.github/CONTRIBUTING.md
vendored
@@ -77,3 +77,8 @@ The log files are:
|
||||
- `tmux-out*.log`: output log file.
|
||||
|
||||
Please attach the log files to your issue.
|
||||
|
||||
## What does it mean if an issue is closed?
|
||||
|
||||
All it means is that work on the issue is not planned for the near future. See
|
||||
the issue's comments to find out if contributions would be welcome.
|
||||
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
blank_issues_enabled: false
|
||||
@@ -1,3 +1,12 @@
|
||||
---
|
||||
name: Use this issue template
|
||||
about: Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
### Issue description
|
||||
|
||||
Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
||||
@@ -14,9 +23,11 @@ built from the latest code in Git.
|
||||
|
||||
### Required information
|
||||
|
||||
Please provide the following information:
|
||||
Please provide the following information. These are **required**. Note that bug reports without logs may be ignored or closed without comment.
|
||||
|
||||
* tmux version (`tmux -V`).
|
||||
* Platform (`uname -sp`).
|
||||
* $TERM inside and outside of tmux (`echo $TERM`).
|
||||
* Terminal in use (xterm, rxvt, etc).
|
||||
* $TERM *inside* tmux (`echo $TERM`).
|
||||
* $TERM *outside* tmux (`echo $TERM`).
|
||||
* Logs from tmux (`tmux kill-server; tmux -vv new`).
|
||||
2
.github/README.md
vendored
2
.github/README.md
vendored
@@ -79,7 +79,7 @@ A small example configuration is in `example_tmux.conf`.
|
||||
|
||||
And a bash(1) completion file at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
https://github.com/scop/bash-completion/blob/main/completions-core/tmux.bash
|
||||
|
||||
For debugging, run tmux with `-v` or `-vv` to generate server and client log
|
||||
files in the current directory.
|
||||
|
||||
27
.github/workflows/lock.yml
vendored
27
.github/workflows/lock.yml
vendored
@@ -3,21 +3,32 @@ name: 'Lock Threads'
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
issues: write
|
||||
pull-requests: write
|
||||
discussions: write
|
||||
|
||||
concurrency:
|
||||
group: lock-threads
|
||||
|
||||
jobs:
|
||||
lock:
|
||||
action:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dessant/lock-threads@v2
|
||||
- uses: dessant/lock-threads@v5
|
||||
with:
|
||||
github-token: ${{ github.token }}
|
||||
issue-lock-inactive-days: '30'
|
||||
pr-lock-inactive-days: '60'
|
||||
issue-lock-comment: >
|
||||
issue-inactive-days: '30'
|
||||
issue-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: >
|
||||
pr-inactive-days: '60'
|
||||
pr-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.
|
||||
discussion-inactive-days: '60'
|
||||
discussion-comment: >
|
||||
This discussion has been automatically locked since there
|
||||
has not been any recent activity after it was closed.
|
||||
|
||||
35
.gitignore
vendored
35
.gitignore
vendored
@@ -1,23 +1,24 @@
|
||||
*.o
|
||||
*~
|
||||
*.diff
|
||||
*.patch
|
||||
*.core
|
||||
core
|
||||
tags
|
||||
*.dSYM
|
||||
*.diff
|
||||
*.o
|
||||
*.patch
|
||||
*.swp
|
||||
*~
|
||||
.deps/
|
||||
compat/.dirstamp
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
config.log
|
||||
config.status
|
||||
etc/
|
||||
tmux
|
||||
.dirstamp
|
||||
Makefile
|
||||
Makefile.in
|
||||
configure
|
||||
tmux.1.*
|
||||
*.dSYM
|
||||
aclocal.m4
|
||||
autom4te.cache/
|
||||
cmd-parse.c
|
||||
compat/.dirstamp
|
||||
config.log
|
||||
config.status
|
||||
configure
|
||||
core
|
||||
etc/
|
||||
fuzz/*-fuzzer
|
||||
.dirstamp
|
||||
tags
|
||||
tmux
|
||||
tmux.1.*
|
||||
|
||||
1
.mailmap
1
.mailmap
@@ -29,6 +29,7 @@ Ted Unangst <tedu@openbsd.org> tedu <tedu>
|
||||
Theo de Raadt <deraadt@openbsd.org> Theo Deraadt <deraadt@openbsd.org>
|
||||
Theo de Raadt <deraadt@openbsd.org> deraadt <deraadt>
|
||||
Thomas Adam <thomas@xteddy.org> Thomas <thomas@xteddy.org>
|
||||
Thomas Adam <thomas@xteddy.org> Thomas Adam <thomas.adam22@gmail.com>
|
||||
Thomas Adam <thomas@xteddy.org> Thomas Adam <thomas.adam@smoothwall.net>
|
||||
Thomas Adam <thomas@xteddy.org> n6tadam <n6tadam@xteddy.org>
|
||||
Tim van der Molen <tim@openbsd.org> tim <tim>
|
||||
|
||||
452
CHANGES
452
CHANGES
@@ -1,3 +1,451 @@
|
||||
CHANGES FROM 3.6 TO 3.6a
|
||||
|
||||
* Fix a buffer overread and an infinite loop in format processing (reported by
|
||||
Giorgi Kobakhia, issue 4735).
|
||||
|
||||
* Allow drag in alternate screen again (issue 4743 reported by Brad King).
|
||||
|
||||
* Fix y offset of mouse if status at top (issue 4738 from Michael Grant).
|
||||
|
||||
* Add a missing skin tone (from Jake Stewart, issue 4736).
|
||||
|
||||
* Allow characters to be combined in either order (issue 4726, reported by Jake
|
||||
Stewart).
|
||||
|
||||
* Fix horizontal mouse resizing when pane status lines are on (from Michael
|
||||
Grant, issue 4720).
|
||||
|
||||
* Fix noattr so it does not delete attributes set in the style itself (issue
|
||||
4713).
|
||||
|
||||
* Newer libevents do not allow event_del on a zero'd event (issue 4706).
|
||||
|
||||
* Place cursor on correct line if message-line is not 0 (issue 4707).
|
||||
|
||||
* Fix compile error on FreeBSD (from Yasuhiro Kimura, issue 4701).
|
||||
|
||||
CHANGES FROM 3.5a TO 3.6
|
||||
|
||||
* Add seconds options for clock mode (issue 4697).
|
||||
|
||||
* Add a resize callback for menus so that they are correctly moved on resize
|
||||
(issue 4696).
|
||||
|
||||
* Make -v to source-file pass through to subsequent source-file commands (issue
|
||||
4216).
|
||||
|
||||
* If display-popup is used inside a popup, modify that popup (issue 4678).
|
||||
|
||||
* Add selection-mode command to expilcitly set the selection mode in copy mode
|
||||
(issue 3842).
|
||||
|
||||
* Save and restore images in alternate screen (issue 3732).
|
||||
|
||||
* Ignore Hangul filler character (issue 3998).
|
||||
|
||||
* Improve handling of regional indicators and emoji modifiers (issue 3998).
|
||||
|
||||
* Preserve marked pane with swap-window and move-window (issue 3443).
|
||||
|
||||
* Set and check COLORTERM as a hint for RGB colour.
|
||||
|
||||
* If tmux receives a palette request (OSC 4) in a pane and the palette entry
|
||||
has not been set, send a request to the most recently used client and
|
||||
forward any response instead (based on change from Tim Culverhouse, issue
|
||||
4665).
|
||||
|
||||
* Add -l flag to command-prompt to disable splitting into multiple prompts
|
||||
(issue 4483).
|
||||
|
||||
* Don't enter copy mode on mouse wheel in alternate screen (issue 3705).
|
||||
|
||||
* Add commands to centre the cursor in copy mode (issue 4662).
|
||||
|
||||
* Support case insensitive search in modes in the same way as copy mode
|
||||
(like emacs, so all-lowercase means case insensitive) (issue 4396).
|
||||
|
||||
* Fix the logic of the no-detached case for the detach-on-destroy option (from
|
||||
Martin Louazel, issue 4649).
|
||||
|
||||
* Add buffer_full format variable (from Mohammad AlSaleh, issue 4630).
|
||||
|
||||
* Introduce a new window option, tiled-layout-max-columns, which configures the
|
||||
maximum number of columns in the tiled layout.
|
||||
|
||||
* Add support for DECRQSS SP q (report cursor style), DECRQM ?12 (report cursor
|
||||
blink state) and DECRQM ?2004, ?1004, ?1006 (report mouse state) ( rom
|
||||
Andrea Alberti, issue 4618).
|
||||
|
||||
* Fix missing argument from OSC 4 reply (issue 4596).
|
||||
|
||||
* Add -k flag to display-popup which allows any key to dismiss the popup once
|
||||
the command has exited (from Meriel Luna Mittelbach, issue 4612).
|
||||
|
||||
* Add nicer default second and third status lines (from Michael Grant, issue
|
||||
4490).
|
||||
|
||||
* Add a pane-border-lines "spaces" value to use spaces for pane borders (issue
|
||||
4587).
|
||||
|
||||
* Replace invalid UTF-8 characters with the placeholder instead of ignoring
|
||||
them (issue 4514).
|
||||
|
||||
* Fix incorrect handling of Korean Hangul Jamo characters (from Roy Jung, issue
|
||||
4546).
|
||||
|
||||
* Allow uppercase letters in gray/grey color names (from Pavel Roskin, issue
|
||||
4560).
|
||||
|
||||
* Add sorting to W, P, L loop operators (from Michael Grant, issue 4516).
|
||||
|
||||
* Detect support for OSC 52 using the device attributes report (from James
|
||||
Holderness, issue 4539).
|
||||
|
||||
* Add noattr for styles and use in mode-style to allow whether attributes are
|
||||
ignored or used to be configured (issue 4498).
|
||||
|
||||
* Add a set-default style attribute which replaces the current default colours
|
||||
and attributes completely.
|
||||
|
||||
* Add -E to run-shell to forward stderr as well as stdout (issue 4246).
|
||||
|
||||
* Add an option variation-selector-always-wide to instruct tmux not to
|
||||
always interpret VS16 as a wide character and assume the terminal does
|
||||
likewise.
|
||||
|
||||
* Switch to getopt_long from OpenSSH (from Koichi Murase, issue 4492).
|
||||
|
||||
* Add more features for boolean expressions in formats: 1) extend && and || to
|
||||
support arbitrarily many arguments and 2) add ! and !! for not and not-not
|
||||
(from David Mandelberg).
|
||||
|
||||
* Do not mistake other DCS sequences for SIXEL sequences (from James
|
||||
Holderness, issue 4488).
|
||||
|
||||
* Improve #? conditional expression in formats: add support for else if and
|
||||
default empty string if no else value (from David Mandelberg, issue 4451).
|
||||
|
||||
* Add default-client-command to set the command used if tmux is run without a
|
||||
command; the default stays new-session (from David Mandelberg, issue
|
||||
4422).
|
||||
|
||||
* Add S-Up and S-Down to move windows in tree mode (from David Mandelberg,
|
||||
issue 4415).
|
||||
|
||||
* Add mode 2031 support to automatically report dark or light theme. tmux will
|
||||
guess the theme from the background colour on terminals which do not
|
||||
themselves support the escape sequence (from Jonathan Slenders, issue 4353).
|
||||
|
||||
* Add -M flag to capture-pane to use the copy mode screen (issue 4358).
|
||||
|
||||
* Align index numbers in trees (from David Mandelberg, issue 4360).
|
||||
|
||||
* Add display-message -C flag to update pane while message is displayed (from
|
||||
Vitaly Ostrosablin, issue 4363).
|
||||
|
||||
* Make list-commands command show only one command if an argument is given
|
||||
(from Ilya Grigoriev, issue 4352).
|
||||
|
||||
* Count line numbers correctly inside strings in configuration files (reported
|
||||
by Pedro Navarro, issue 4325).
|
||||
|
||||
* Map bright black (colour 8) to white (7) if the background is black on
|
||||
terminals with only eight colours so the text is not invisible (from Dmytro
|
||||
Bagrii, issue 4322).
|
||||
|
||||
* New codepoint-widths option allowing users to override the width of
|
||||
individual Unicode codepoints.
|
||||
|
||||
* Add a nesting limit to source-file (from Fadi Afani, issue 4223).
|
||||
|
||||
* Add copy-mode-position-style and copy-mode-selection-style options for copy
|
||||
mode.
|
||||
|
||||
* Add no-detach-on-destroy client option (issue 4242).
|
||||
|
||||
* Add input-buffer-size option (from Ken Lau).
|
||||
|
||||
* Add support for a scrollbar at the side of each pane. New options
|
||||
pane-scrollbars turn them on or off, pane-scrollbars-position sets the
|
||||
position (left or right), and pane-scrollbars-style to set the colours (from
|
||||
Michael Grant, issue 4221).
|
||||
|
||||
* Allow control characters to be entered at the command prompt by prefixing
|
||||
with C-v (from Alexander Arch, issue 4206).
|
||||
|
||||
* Do not attempt to search for zero length strings (from Alexander Arch, issue
|
||||
4209).
|
||||
|
||||
* Preserve tabs for copying and capture-pane (from Alexander Arch, issue
|
||||
4201).
|
||||
|
||||
* Increase the maximum for repeat-time.
|
||||
|
||||
* Adjust how Ctrl and Meta keys are sent to use standard representation if
|
||||
available in mode 1 (from Stanislav Kljuhhin, issue 4188).
|
||||
|
||||
* Allow attributes in menu style (from Japin Li, issue 4194).
|
||||
|
||||
* Add a sixel_support format variable which is 1 if SIXEL is supported, always
|
||||
0 on OpenBSD (requested by Misaki Masa, issue 4177).
|
||||
|
||||
* Add prompt-cursor-colour and prompt-cursor-style to set the style of the
|
||||
cursor in the command prompt and remove the emulated cursor (from Alexander
|
||||
Arch, issue 4170).
|
||||
|
||||
* Add initial-repeat-time option to allow the first repeat time to be increased
|
||||
and later reduced (from David le Blanc, issue 4164).
|
||||
|
||||
* Send focus events to pane when entering or leaving popup (issue 3991).
|
||||
|
||||
* Add copy-mode-position-format to configure the position indicator.
|
||||
|
||||
* Add -y flag to disable confirmation prompts in modes (issue 4152).
|
||||
|
||||
* Add -C and -P flags to the copy commands in copy mode: -C prevents the
|
||||
commands from sending the text to the clipboard and -P prevents them from
|
||||
adding the text as a paste buffer (issue 4153).
|
||||
|
||||
* Preserve transparency and raster attribute dimensions when sending a SIXEL
|
||||
image, and avoid collapsing empty lines (issue 4149).
|
||||
|
||||
* Bypass permission check for Cygwin (based on a change by Yuya Adachi via
|
||||
Rafael Kitover, issue 4148).
|
||||
|
||||
* Add MSYSTEM to default update-environment (for Cgywin).
|
||||
|
||||
* Set client stdout file descriptor also for Cgywin (from Michael Wild via Rafael
|
||||
Kitover, issue 4148).
|
||||
|
||||
* Use global cursor style and colour options for modes instead of default
|
||||
(issue 4117).
|
||||
|
||||
* Fix pasting so it does not interpret keys but instead copies the input
|
||||
without interpretation (reported by Mark Kelly).
|
||||
|
||||
* Try to query window pixel size from the outside terminal if the values
|
||||
returned by TIOCGWINSZ are zero (Dmitry Galchinsky, issue 4099).
|
||||
|
||||
CHANGES FROM 3.5 TO 3.5a
|
||||
|
||||
* Do not translate BSpace as Unicode with extended keys.
|
||||
|
||||
* Fix so that keys with Shift are represented correctly with extended keys.
|
||||
|
||||
* Revert to using /bin/sh for #() and run-shell and if-shell; the change to use
|
||||
default-shell only applies now to popups.
|
||||
|
||||
* Fix grey colour without a number suffix in styles.
|
||||
|
||||
CHANGES FROM 3.4 TO 3.5
|
||||
|
||||
* Revamp extended keys support to more closely match xterm and support mode 2
|
||||
as well as mode 1. This is a substantial change to key handling which changes
|
||||
tmux to always request mode 2 from parent terminal, changes to an unambiguous
|
||||
internal representation of keys, and adds an option (extended-keys-format) to
|
||||
control the format similar to the xterm(1) formatOtherKeys resource.
|
||||
|
||||
* Clear an overlay (popup or menu) when command prompt is entered.
|
||||
|
||||
* Add copy-mode -d flag to scroll a page down if in copy mode already (matching
|
||||
-e).
|
||||
|
||||
* Display hyperlinks in copy mode and add copy_cursor_hyperlink format to get
|
||||
the hyperlink under the cursor.
|
||||
|
||||
* Add a prefix timeout option.
|
||||
|
||||
* Mouse move keys are not useful as key bindings because we do not turn them on
|
||||
unless the application requests them. Ignore them so they do not cause the
|
||||
prefix to be canceled
|
||||
|
||||
* Add search_count and search_count_partial formats in copy mode.
|
||||
|
||||
* Do not reset mouse pane if clicked on status line,
|
||||
|
||||
* Add mirrored versions of the main-horizontal and main-vertical layouts where
|
||||
the main pane is bottom or right instead of top or left.
|
||||
|
||||
* Allow REP to work with Unicode characters.
|
||||
|
||||
* Fix size calculation of terminators for clipboard escape sequences.
|
||||
|
||||
* Treat CRLF as LF in config files where it is easy to do so.
|
||||
|
||||
* The Linux console has some bugs with bright colours, so add some workarounds
|
||||
for it.
|
||||
|
||||
* If built with systemd, remove some environment variables it uses.
|
||||
|
||||
* Adjust the logic when deleting last buffer to better preserve the selection:
|
||||
if selecting the element below the deleted one fails (because as the last
|
||||
one), select the one above it instead.
|
||||
|
||||
* Add --enable-jemalloc to build with jemalloc memory allocator (since glibc
|
||||
malloc is so poor).
|
||||
|
||||
* Add a way (refresh-client -r) for control mode clients to provide OSC 10 and
|
||||
11 responses to tmux so they can set the default foreground and background
|
||||
colours.
|
||||
|
||||
* Add N to search backwards in tree modes.
|
||||
|
||||
* Use default-shell for command prompt, #() and popups.
|
||||
|
||||
* Revert part of a change intended to improve search performance by skipping
|
||||
parts of lines already searched, but which in fact skipped the ends of lines
|
||||
altogether.
|
||||
|
||||
* Add a command-error hook when a command fails.
|
||||
|
||||
* Add an option allow-set-title to forbid applications from changing the pane
|
||||
title.
|
||||
|
||||
* Correct handling of mouse up events (don't ignore all but the last released
|
||||
button), and always process down event for double click.
|
||||
|
||||
* Fix a crash if focusing a pane that is exiting.
|
||||
|
||||
* Pick newest session (as documented) when looking for next session for
|
||||
detach-on-destroy.
|
||||
|
||||
* Reduce default escape-time to 10 milliseconds.
|
||||
|
||||
* Add display-menu -M to always turn mouse on in a menu.
|
||||
|
||||
* Look for feature code 21 for DECSLRM and 28 for DECFRA in the device
|
||||
attributes and also accept level 1.
|
||||
|
||||
* Fix crash if built with SIXEL and the SIXEL colour register is invalid; also
|
||||
remove SIXEL images before reflow.
|
||||
|
||||
* Do not notify window-layout-changed if the window is about to be destroyed.
|
||||
|
||||
* Do not consider a selection present if it is empty for the selection_active
|
||||
and selection_present format variables.
|
||||
|
||||
* Fix split-window -p.
|
||||
|
||||
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 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
|
||||
@@ -180,7 +628,7 @@ CHANGES FROM 3.2 TO 3.2a
|
||||
* 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.
|
||||
source-file, cross compiling, format modifiers and other minor issues.
|
||||
|
||||
CHANGES FROM 3.1c TO 3.2
|
||||
|
||||
@@ -1295,7 +1743,7 @@ Incompatible Changes
|
||||
|
||||
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.
|
||||
* 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
|
||||
|
||||
44
Makefile.am
44
Makefile.am
@@ -1,5 +1,3 @@
|
||||
# Makefile.am
|
||||
|
||||
# Obvious program stuff.
|
||||
bin_PROGRAMS = tmux
|
||||
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
||||
@@ -14,6 +12,7 @@ dist_EXTRA_tmux_SOURCES = compat/*.[ch]
|
||||
AM_CPPFLAGS += @XOPEN_DEFINES@ \
|
||||
-DTMUX_VERSION='"@VERSION@"' \
|
||||
-DTMUX_CONF='"$(sysconfdir)/tmux.conf:~/.tmux.conf:$$XDG_CONFIG_HOME/tmux/tmux.conf:~/.config/tmux/tmux.conf"' \
|
||||
-DTMUX_LOCK_CMD='"@DEFAULT_LOCK_CMD@"' \
|
||||
-DTMUX_TERM='"@DEFAULT_TERM@"'
|
||||
|
||||
# Additional object files.
|
||||
@@ -21,17 +20,23 @@ LDADD = $(LIBOBJS)
|
||||
|
||||
# Set flags for gcc.
|
||||
if IS_GCC
|
||||
AM_CFLAGS += -std=gnu99 -O2
|
||||
AM_CFLAGS += -std=gnu99
|
||||
if IS_OPTIMIZED
|
||||
AM_CFLAGS += -O2
|
||||
else
|
||||
AM_CFLAGS += -O0
|
||||
endif
|
||||
if IS_DEBUG
|
||||
AM_CFLAGS += -g
|
||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2
|
||||
AM_CFLAGS += -Wno-long-long -Wall -W -Wformat=2 -Wno-use-after-free
|
||||
AM_CFLAGS += -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations
|
||||
AM_CFLAGS += -Wwrite-strings -Wshadow -Wpointer-arith -Wsign-compare
|
||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wcast-align
|
||||
AM_CFLAGS += -Wundef -Wbad-function-cast -Winline -Wno-cast-align
|
||||
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 -Wno-unknown-warning-option
|
||||
AM_CFLAGS += -Wno-maybe-uninitialized
|
||||
if IS_DARWIN
|
||||
AM_CFLAGS += -Wno-deprecated-declarations -Wno-cast-align
|
||||
AM_CFLAGS += -Wno-deprecated-declarations -Wno-macro-redefined
|
||||
endif
|
||||
AM_CPPFLAGS += -DDEBUG
|
||||
endif
|
||||
@@ -67,6 +72,11 @@ if IS_HAIKU
|
||||
AM_CPPFLAGS += -D_BSD_SOURCE
|
||||
endif
|
||||
|
||||
# Set flags for Cygwin.
|
||||
if IS_CYGWIN
|
||||
AM_CPPFLAGS += -DTMUX_SOCK_PERM=0
|
||||
endif
|
||||
|
||||
# List of sources.
|
||||
dist_tmux_SOURCES = \
|
||||
alerts.c \
|
||||
@@ -96,6 +106,7 @@ dist_tmux_SOURCES = \
|
||||
cmd-kill-window.c \
|
||||
cmd-list-buffers.c \
|
||||
cmd-list-clients.c \
|
||||
cmd-list-commands.c \
|
||||
cmd-list-keys.c \
|
||||
cmd-list-panes.c \
|
||||
cmd-list-sessions.c \
|
||||
@@ -150,6 +161,7 @@ dist_tmux_SOURCES = \
|
||||
grid-reader.c \
|
||||
grid-view.c \
|
||||
grid.c \
|
||||
hyperlinks.c \
|
||||
input-keys.c \
|
||||
input.c \
|
||||
job.c \
|
||||
@@ -178,6 +190,7 @@ dist_tmux_SOURCES = \
|
||||
server-fn.c \
|
||||
server.c \
|
||||
session.c \
|
||||
sort.c \
|
||||
spawn.c \
|
||||
status.c \
|
||||
style.c \
|
||||
@@ -185,10 +198,12 @@ dist_tmux_SOURCES = \
|
||||
tmux.h \
|
||||
tmux-protocol.h \
|
||||
tty-acs.c \
|
||||
tty-draw.c \
|
||||
tty-features.c \
|
||||
tty-keys.c \
|
||||
tty-term.c \
|
||||
tty.c \
|
||||
utf8-combined.c \
|
||||
utf8.c \
|
||||
window-buffer.c \
|
||||
window-client.c \
|
||||
@@ -216,6 +231,21 @@ if HAVE_UTF8PROC
|
||||
nodist_tmux_SOURCES += compat/utf8proc.c
|
||||
endif
|
||||
|
||||
# Enable sixel support.
|
||||
if ENABLE_SIXEL_IMAGES
|
||||
dist_tmux_SOURCES += image.c image-sixel.c
|
||||
else
|
||||
# If not sixel, still need image.c for kitty.
|
||||
if ENABLE_KITTY_IMAGES
|
||||
dist_tmux_SOURCES += image.c
|
||||
endif
|
||||
endif
|
||||
|
||||
# Enable kitty graphics protocol support.
|
||||
if ENABLE_KITTY_IMAGES
|
||||
dist_tmux_SOURCES += image-kitty.c
|
||||
endif
|
||||
|
||||
if NEED_FUZZING
|
||||
check_PROGRAMS = fuzz/input-fuzzer
|
||||
fuzz_input_fuzzer_LDFLAGS = $(FUZZING_LIBS)
|
||||
|
||||
3
README
3
README
@@ -36,6 +36,7 @@ autoconf, automake and pkg-config:
|
||||
$ cd tmux
|
||||
$ sh autogen.sh
|
||||
$ ./configure && make
|
||||
$ sudo make install
|
||||
|
||||
* Contributing
|
||||
|
||||
@@ -65,7 +66,7 @@ Also see the tmux FAQ at:
|
||||
|
||||
A bash(1) completion file is at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
https://github.com/scop/bash-completion/blob/main/completions/tmux
|
||||
|
||||
For debugging, run tmux with -v and -vv to generate server and client log files
|
||||
in the current directory.
|
||||
|
||||
@@ -38,7 +38,7 @@ tmuxのドキュメントについてはtmux.1マニュアルをご覧くださ
|
||||
サンプル設定は本リポジトリのexample_tmux.confに
|
||||
また、bash-completionファイルは下記にあります。
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
https://github.com/scop/bash-completion/blob/main/completions/tmux
|
||||
|
||||
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。
|
||||
|
||||
|
||||
32
SYNCING
32
SYNCING
@@ -1,17 +1,17 @@
|
||||
Preamble
|
||||
========
|
||||
|
||||
Tmux portable relies on repositories "tmux" and "tmux-openbsd".
|
||||
Tmux portable relies on repositories "tmux" and "tmux-obsd".
|
||||
Here's a description of them:
|
||||
|
||||
* "tmux" is the portable version, the one which contains code for other
|
||||
operating systems, and autotools, etc., which isn't found or needed in the
|
||||
OpenBSD base system.
|
||||
|
||||
* "tmux-openbsd" is the version of tmux in OpenBSD base system which provides
|
||||
* "tmux-obsd" is the version of tmux in OpenBSD base system which provides
|
||||
the basis of the portable tmux version.
|
||||
|
||||
Note: The "tmux-openbsd" repository is actually handled by "git cvsimport"
|
||||
Note: The "tmux-obsd" repository is actually handled by "git cvsimport"
|
||||
running at 15 minute intervals, so a commit made to OpenBSD's tmux CVS
|
||||
repository will take at least that long to appear in this git repository.
|
||||
(It might take longer, depending on the CVS mirror used to import the
|
||||
@@ -34,11 +34,11 @@ this information has ever been set before.
|
||||
Cloning repositories
|
||||
====================
|
||||
|
||||
This involves having both tmux and tmux-openbsd cloned, as in:
|
||||
This involves having both tmux and tmux-obsd cloned, as in:
|
||||
|
||||
% cd /some/where/useful
|
||||
% git clone https://github.com/tmux/tmux.git
|
||||
% git clone https://github.com/ThomasAdam/tmux-openbsd.git
|
||||
% git clone https://github.com/ThomasAdam/tmux-obsd.git
|
||||
|
||||
Note that you do not need additional checkouts to manage the sync -- an
|
||||
existing clone of either repositories will suffice. So if you already have
|
||||
@@ -47,30 +47,30 @@ these checkouts existing, skip that.
|
||||
Adding in git-remotes
|
||||
=====================
|
||||
|
||||
Because the portable "tmux" git repository and the "tmux-openbsd"
|
||||
Because the portable "tmux" git repository and the "tmux-obsd"
|
||||
repository do not inherently share any history between each other, the
|
||||
history has been faked between them. This "faking of history" is something
|
||||
which has to be told to git for the purposes of comparing the "tmux" and
|
||||
"tmux-openbsd" repositories for syncing. To do this, we must reference the
|
||||
clone of the "tmux-openbsd" repository from the "tmux" repository, as
|
||||
"tmux-obsd" repositories for syncing. To do this, we must reference the
|
||||
clone of the "tmux-obsd" repository from the "tmux" repository, as
|
||||
shown by the following command:
|
||||
|
||||
% cd /path/to/tmux
|
||||
% git remote add obsd-tmux file:///path/to/tmux-openbsd
|
||||
% git remote add obsd-tmux file:///path/to/tmux-obsd
|
||||
|
||||
So that now, the remote "obsd-tmux" can be used to reference branches and
|
||||
commits from the "tmux-openbsd" repository, but from the context of the
|
||||
commits from the "tmux-obsd" repository, but from the context of the
|
||||
portable "tmux" repository, which makes sense because it's the "tmux"
|
||||
repository which will have the updates applied to them.
|
||||
|
||||
Fetching updates
|
||||
================
|
||||
|
||||
To ensure the latest commits from "tmux-openbsd" can be found from within
|
||||
"tmux", we have to ensure the "master" branch from "tmux-openbsd" is
|
||||
To ensure the latest commits from "tmux-obsd" can be found from within
|
||||
"tmux", we have to ensure the "master" branch from "tmux-obsd" is
|
||||
up-to-date first, and then reference that update in "tmux", as in:
|
||||
|
||||
% cd /path/to/tmux-openbsd
|
||||
% cd /path/to/tmux-obsd
|
||||
% git checkout master
|
||||
% git pull
|
||||
|
||||
@@ -82,9 +82,9 @@ Then back in "tmux":
|
||||
Creating the necessary branches
|
||||
===============================
|
||||
|
||||
Now that "tmux" can see commits and branches from "tmux-openbsd" by way
|
||||
Now that "tmux" can see commits and branches from "tmux-obsd" by way
|
||||
of the remote name "obsd-tmux", we can now create the master branch from
|
||||
"tmux-openbsd" in the "tmux" repository:
|
||||
"tmux-obsd" in the "tmux" repository:
|
||||
|
||||
% git checkout -b obsd-master obsd-tmux/master
|
||||
|
||||
@@ -92,7 +92,7 @@ Adding in the fake history points
|
||||
=================================
|
||||
|
||||
To tie both the "master" branch from "tmux" and the "obsd-master"
|
||||
branch from "tmux-openbsd" together, the fake history points added to the
|
||||
branch from "tmux-obsd" together, the fake history points added to the
|
||||
"tmux" repository need to be added. To do this, we must add an
|
||||
additional refspec line, as in:
|
||||
|
||||
|
||||
8
alerts.c
8
alerts.c
@@ -315,11 +315,11 @@ alerts_set_message(struct winlink *wl, const char *type, const char *option)
|
||||
if (visual == VISUAL_OFF)
|
||||
continue;
|
||||
if (c->session->curw == wl) {
|
||||
status_message_set(c, -1, 1, 0, "%s in current window",
|
||||
type);
|
||||
status_message_set(c, -1, 1, 0, 0,
|
||||
"%s in current window", type);
|
||||
} else {
|
||||
status_message_set(c, -1, 1, 0, "%s in window %d", type,
|
||||
wl->idx);
|
||||
status_message_set(c, -1, 1, 0, 0,
|
||||
"%s in window %d", type, wl->idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
349
arguments.c
349
arguments.c
@@ -37,6 +37,10 @@ struct args_entry {
|
||||
u_char flag;
|
||||
struct args_values values;
|
||||
u_int count;
|
||||
|
||||
int flags;
|
||||
#define ARGS_ENTRY_OPTIONAL_VALUE 0x1
|
||||
|
||||
RB_ENTRY(args_entry) entry;
|
||||
};
|
||||
|
||||
@@ -94,6 +98,22 @@ args_copy_value(struct args_value *to, struct args_value *from)
|
||||
}
|
||||
}
|
||||
|
||||
/* 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)
|
||||
@@ -122,6 +142,103 @@ args_create(void)
|
||||
return (args);
|
||||
}
|
||||
|
||||
/* Parse a single flag. */
|
||||
static int
|
||||
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;
|
||||
|
||||
new = xcalloc(1, sizeof *new);
|
||||
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);
|
||||
args_free_value(new);
|
||||
free(new);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
if (argument == NULL) {
|
||||
args_free_value(new);
|
||||
free(new);
|
||||
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;
|
||||
}
|
||||
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,
|
||||
@@ -131,86 +248,21 @@ args_parse(const struct args_parse *parse, struct args_value *values,
|
||||
u_int i;
|
||||
enum args_parse_type type;
|
||||
struct args_value *value, *new;
|
||||
u_char flag;
|
||||
const char *found, *string, *s;
|
||||
int optional_argument;
|
||||
const char *s;
|
||||
int stop;
|
||||
|
||||
if (count == 0)
|
||||
return (args_create());
|
||||
|
||||
args = args_create();
|
||||
for (i = 1; i < count; /* nothing */) {
|
||||
value = &values[i];
|
||||
if (value->type != ARGS_STRING)
|
||||
break;
|
||||
|
||||
string = value->string;
|
||||
if (*string++ != '-' || *string == '\0')
|
||||
break;
|
||||
i++;
|
||||
if (string[0] == '-' && string[1] == '\0')
|
||||
break;
|
||||
|
||||
for (;;) {
|
||||
flag = *string++;
|
||||
if (flag == '\0')
|
||||
break;
|
||||
if (flag == '?') {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (!isalnum(flag)) {
|
||||
xasprintf(cause, "invalid flag -%c", flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
found = strchr(parse->template, flag);
|
||||
if (found == NULL) {
|
||||
xasprintf(cause, "unknown flag -%c", flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (*++found != ':') {
|
||||
log_debug("%s: -%c", __func__, flag);
|
||||
args_set(args, flag, NULL);
|
||||
continue;
|
||||
}
|
||||
if (*found == ':') {
|
||||
optional_argument = 1;
|
||||
found++;
|
||||
}
|
||||
new = xcalloc(1, sizeof *new);
|
||||
if (*string != '\0') {
|
||||
new->type = ARGS_STRING;
|
||||
new->string = xstrdup(string);
|
||||
} else {
|
||||
if (i == count) {
|
||||
if (optional_argument) {
|
||||
log_debug("%s: -%c", __func__,
|
||||
flag);
|
||||
args_set(args, flag, NULL);
|
||||
continue;
|
||||
}
|
||||
xasprintf(cause,
|
||||
"-%c expects an argument",
|
||||
flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (values[i].type != ARGS_STRING) {
|
||||
xasprintf(cause,
|
||||
"-%c argument must be a string",
|
||||
flag);
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
args_copy_value(new, &values[i++]);
|
||||
}
|
||||
s = args_value_as_string(new);
|
||||
log_debug("%s: -%c = %s", __func__, flag, s);
|
||||
args_set(args, flag, new);
|
||||
break;
|
||||
stop = args_parse_flags(parse, values, count, cause, args, &i);
|
||||
if (stop == -1) {
|
||||
args_free(args);
|
||||
return (NULL);
|
||||
}
|
||||
if (stop == 1)
|
||||
break;
|
||||
}
|
||||
log_debug("%s: flags end at %u of %u", __func__, i, count);
|
||||
if (i != count) {
|
||||
@@ -218,8 +270,8 @@ args_parse(const struct args_parse *parse, struct args_value *values,
|
||||
value = &values[i];
|
||||
|
||||
s = args_value_as_string(value);
|
||||
log_debug("%s: %u = %s (type %d)", __func__, i, s,
|
||||
value->type);
|
||||
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);
|
||||
@@ -323,13 +375,13 @@ args_copy(struct args *args, int argc, char **argv)
|
||||
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);
|
||||
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);
|
||||
args_set(new_args, entry->flag, new_value, 0);
|
||||
}
|
||||
}
|
||||
if (args->count == 0)
|
||||
@@ -487,6 +539,7 @@ args_print(struct args *args)
|
||||
char *buf;
|
||||
u_int i, j;
|
||||
struct args_entry *entry;
|
||||
struct args_entry *last = NULL;
|
||||
struct args_value *value;
|
||||
|
||||
len = 1;
|
||||
@@ -494,6 +547,8 @@ args_print(struct args *args)
|
||||
|
||||
/* Process the flags first. */
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->flags & ARGS_ENTRY_OPTIONAL_VALUE)
|
||||
continue;
|
||||
if (!TAILQ_EMPTY(&entry->values))
|
||||
continue;
|
||||
|
||||
@@ -505,6 +560,16 @@ args_print(struct args *args)
|
||||
|
||||
/* Then the flags with arguments. */
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->flags & ARGS_ENTRY_OPTIONAL_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);
|
||||
@@ -512,7 +577,10 @@ args_print(struct args *args)
|
||||
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. */
|
||||
for (i = 0; i < args->count; i++)
|
||||
@@ -582,7 +650,7 @@ args_has(struct args *args, u_char flag)
|
||||
|
||||
/* Set argument value in the arguments tree. */
|
||||
void
|
||||
args_set(struct args *args, u_char flag, struct args_value *value)
|
||||
args_set(struct args *args, u_char flag, struct args_value *value, int flags)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
|
||||
@@ -591,12 +659,15 @@ args_set(struct args *args, u_char flag, struct args_value *value)
|
||||
entry = xcalloc(1, sizeof *entry);
|
||||
entry->flag = flag;
|
||||
entry->count = 1;
|
||||
entry->flags = flags;
|
||||
TAILQ_INIT(&entry->values);
|
||||
RB_INSERT(args_tree, &args->tree, entry);
|
||||
} else
|
||||
entry->count++;
|
||||
if (value != NULL && value->type != ARGS_NONE)
|
||||
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
||||
else
|
||||
free(value);
|
||||
}
|
||||
|
||||
/* Get argument value. Will be NULL if it isn't present. */
|
||||
@@ -696,6 +767,7 @@ args_make_commands_prepare(struct cmd *self, struct cmdq_item *item, u_int idx,
|
||||
struct args_value *value;
|
||||
struct args_command_state *state;
|
||||
const char *cmd;
|
||||
const char *file;
|
||||
|
||||
state = xcalloc(1, sizeof *state);
|
||||
|
||||
@@ -722,7 +794,9 @@ args_make_commands_prepare(struct cmd *self, struct cmdq_item *item, u_int idx,
|
||||
|
||||
if (wait)
|
||||
state->pi.item = item;
|
||||
cmd_get_source(self, &state->pi.file, &state->pi.line);
|
||||
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++;
|
||||
@@ -747,6 +821,8 @@ args_make_commands(struct args_command_state *state, int argc, char **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);
|
||||
@@ -775,6 +851,7 @@ args_make_commands_free(struct args_command_state *state)
|
||||
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);
|
||||
}
|
||||
@@ -848,6 +925,41 @@ args_strtonum(struct args *args, u_char flag, long long minval,
|
||||
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) {
|
||||
*cause = xstrdup(errstr);
|
||||
return (0);
|
||||
}
|
||||
|
||||
*cause = NULL;
|
||||
return (ll);
|
||||
}
|
||||
|
||||
/* Convert an argument to a number which may be a percentage. */
|
||||
long long
|
||||
args_percentage(struct args *args, u_char flag, long long minval,
|
||||
@@ -860,6 +972,10 @@ args_percentage(struct args *args, u_char flag, long long minval,
|
||||
*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(value, minval, maxval, curval, cause));
|
||||
}
|
||||
@@ -874,6 +990,10 @@ args_string_percentage(const char *value, long long minval, long long maxval,
|
||||
size_t valuelen = strlen(value);
|
||||
char *copy;
|
||||
|
||||
if (valuelen == 0) {
|
||||
*cause = xstrdup("empty");
|
||||
return (0);
|
||||
}
|
||||
if (value[valuelen - 1] == '%') {
|
||||
copy = xstrdup(value);
|
||||
copy[valuelen - 1] = '\0';
|
||||
@@ -904,3 +1024,74 @@ args_string_percentage(const char *value, long long minval, long long maxval,
|
||||
*cause = NULL;
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ attributes_tostring(int attr)
|
||||
if (attr == 0)
|
||||
return ("none");
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
||||
(attr & GRID_ATTR_CHARSET) ? "acs," : "",
|
||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
||||
@@ -45,7 +45,8 @@ attributes_tostring(int attr)
|
||||
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
|
||||
(attr & GRID_ATTR_OVERLINE) ? "overline," : "");
|
||||
(attr & GRID_ATTR_OVERLINE) ? "overline," : "",
|
||||
(attr & GRID_ATTR_NOATTR) ? "noattr," : "");
|
||||
if (len > 0)
|
||||
buf[len - 1] = '\0';
|
||||
|
||||
|
||||
55
cfg.c
55
cfg.c
@@ -51,8 +51,7 @@ cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cfg_finished = 1;
|
||||
|
||||
if (!RB_EMPTY(&sessions))
|
||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
||||
cfg_show_causes(NULL);
|
||||
|
||||
if (cfg_item != NULL)
|
||||
cmdq_continue(cfg_item);
|
||||
@@ -67,6 +66,7 @@ start_cfg(void)
|
||||
{
|
||||
struct client *c;
|
||||
u_int i;
|
||||
int flags = 0;
|
||||
|
||||
/*
|
||||
* Configuration files are loaded without a client, so commands are run
|
||||
@@ -84,19 +84,17 @@ start_cfg(void)
|
||||
cmdq_append(c, cfg_item);
|
||||
}
|
||||
|
||||
for (i = 0; i < cfg_nfiles; i++) {
|
||||
if (cfg_quiet)
|
||||
load_cfg(cfg_files[i], c, NULL, CMD_PARSE_QUIET, NULL);
|
||||
else
|
||||
load_cfg(cfg_files[i], c, NULL, 0, NULL);
|
||||
}
|
||||
if (cfg_quiet)
|
||||
flags = CMD_PARSE_QUIET;
|
||||
for (i = 0; i < cfg_nfiles; i++)
|
||||
load_cfg(cfg_files[i], c, NULL, NULL, flags, NULL);
|
||||
|
||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
||||
}
|
||||
|
||||
int
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
||||
struct cmdq_item **new_item)
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item,
|
||||
struct cmd_find_state *current, int flags, struct cmdq_item **new_item)
|
||||
{
|
||||
FILE *f;
|
||||
struct cmd_parse_input pi;
|
||||
@@ -135,7 +133,7 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
||||
}
|
||||
|
||||
if (item != NULL)
|
||||
state = cmdq_copy_state(cmdq_get_state(item));
|
||||
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||
else
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||
@@ -155,8 +153,8 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
||||
|
||||
int
|
||||
load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
||||
struct client *c, struct cmdq_item *item, int flags,
|
||||
struct cmdq_item **new_item)
|
||||
struct client *c, struct cmdq_item *item, struct cmd_find_state *current,
|
||||
int flags, struct cmdq_item **new_item)
|
||||
{
|
||||
struct cmd_parse_input pi;
|
||||
struct cmd_parse_result *pr;
|
||||
@@ -187,7 +185,7 @@ load_cfg_from_buffer(const void *buf, size_t len, const char *path,
|
||||
}
|
||||
|
||||
if (item != NULL)
|
||||
state = cmdq_copy_state(cmdq_get_state(item));
|
||||
state = cmdq_copy_state(cmdq_get_state(item), current);
|
||||
else
|
||||
state = cmdq_new_state(NULL, NULL, 0);
|
||||
cmdq_add_format(state, "current_file", "%s", pi.file);
|
||||
@@ -223,10 +221,14 @@ cfg_add_cause(const char *fmt, ...)
|
||||
void
|
||||
cfg_print_causes(struct cmdq_item *item)
|
||||
{
|
||||
u_int i;
|
||||
struct client *c = cmdq_get_client(item);
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
cmdq_print(item, "%s", cfg_causes[i]);
|
||||
if (c != NULL && (c->flags & CLIENT_CONTROL))
|
||||
control_write(c, "%%config-error %s", cfg_causes[i]);
|
||||
else
|
||||
cmdq_print(item, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
}
|
||||
|
||||
@@ -238,11 +240,29 @@ cfg_print_causes(struct cmdq_item *item)
|
||||
void
|
||||
cfg_show_causes(struct session *s)
|
||||
{
|
||||
struct client *c = TAILQ_FIRST(&clients);
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
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;
|
||||
wp = s->curw->window->active;
|
||||
|
||||
@@ -254,6 +274,7 @@ cfg_show_causes(struct session *s)
|
||||
free(cfg_causes[i]);
|
||||
}
|
||||
|
||||
out:
|
||||
free(cfg_causes);
|
||||
cfg_causes = NULL;
|
||||
cfg_ncauses = 0;
|
||||
|
||||
48
client.c
48
client.c
@@ -245,9 +245,6 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
|
||||
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. */
|
||||
if (shell_command != NULL) {
|
||||
msg = MSG_SHELL;
|
||||
@@ -284,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);
|
||||
|
||||
/* 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);
|
||||
if (fd == -1) {
|
||||
if (errno == ECONNREFUSED) {
|
||||
@@ -449,11 +452,12 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
|
||||
{
|
||||
char **ss;
|
||||
size_t sslen;
|
||||
int fd, flags = client_flags;
|
||||
int fd;
|
||||
uint64_t flags = client_flags;
|
||||
pid_t pid;
|
||||
u_int i;
|
||||
|
||||
proc_send(client_peer, MSG_IDENTIFY_FLAGS, -1, &flags, sizeof flags);
|
||||
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &flags, sizeof flags);
|
||||
proc_send(client_peer, MSG_IDENTIFY_LONGFLAGS, -1, &client_flags,
|
||||
sizeof client_flags);
|
||||
|
||||
@@ -494,20 +498,10 @@ client_send_identify(const char *ttynam, const char *termname, char **caps,
|
||||
static __dead void
|
||||
client_exec(const char *shell, const char *shellcmd)
|
||||
{
|
||||
const char *name, *ptr;
|
||||
char *argv0;
|
||||
char *argv0;
|
||||
|
||||
log_debug("shell %s, command %s", shell, shellcmd);
|
||||
|
||||
ptr = strrchr(shell, '/');
|
||||
if (ptr != NULL && *(ptr + 1) != '\0')
|
||||
name = ptr + 1;
|
||||
else
|
||||
name = shell;
|
||||
if (client_flags & CLIENT_LOGIN)
|
||||
xasprintf(&argv0, "-%s", name);
|
||||
else
|
||||
xasprintf(&argv0, "%s", name);
|
||||
argv0 = shell_argv0(shell, !!(client_flags & CLIENT_LOGIN));
|
||||
setenv("SHELL", shell, 1);
|
||||
|
||||
proc_clear_signals(client_proc, 1);
|
||||
@@ -527,11 +521,22 @@ client_signal(int sig)
|
||||
{
|
||||
struct sigaction sigact;
|
||||
int status;
|
||||
pid_t pid;
|
||||
|
||||
log_debug("%s: %s", __func__, strsignal(sig));
|
||||
if (sig == SIGCHLD)
|
||||
waitpid(WAIT_ANY, &status, WNOHANG);
|
||||
else if (!client_attached) {
|
||||
if (sig == SIGCHLD) {
|
||||
for (;;) {
|
||||
pid = waitpid(WAIT_ANY, &status, WNOHANG);
|
||||
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);
|
||||
} else {
|
||||
@@ -694,6 +699,9 @@ client_dispatch_wait(struct imsg *imsg)
|
||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||
NULL);
|
||||
break;
|
||||
case MSG_READ_CANCEL:
|
||||
file_read_cancel(&client_files, imsg);
|
||||
break;
|
||||
case MSG_WRITE_OPEN:
|
||||
file_write_open(&client_files, client_peer, imsg, 1,
|
||||
!(client_flags & CLIENT_CONTROL), client_file_check_cb,
|
||||
|
||||
@@ -158,6 +158,9 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
}
|
||||
|
||||
if (cfg_finished)
|
||||
cfg_show_causes(s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ const struct cmd_entry cmd_bind_key_entry = {
|
||||
|
||||
.args = { "nrN:T:", 1, -1, cmd_bind_key_args_parse },
|
||||
.usage = "[-nr] [-T key-table] [-N note] key "
|
||||
"[command [arguments]]",
|
||||
"[command [argument ...]]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_bind_key_exec
|
||||
|
||||
@@ -85,7 +85,10 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
}
|
||||
server_unlink_window(src_s, wl);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
wl = winlink_find_by_window(&dst_s->windows, w);
|
||||
if (wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto out;
|
||||
}
|
||||
if (idx != -1 && winlink_find_by_index(&dst_s->windows, idx) != NULL) {
|
||||
cmdq_error(item, "index in use: %d", idx);
|
||||
@@ -99,7 +102,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
w = wp->window = window_create(w->sx, w->sy, w->xpixel, w->ypixel);
|
||||
options_set_parent(wp->options, w->options);
|
||||
wp->flags |= PANE_STYLECHANGED;
|
||||
wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
w->latest = tc;
|
||||
@@ -115,6 +118,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
layout_init(w, wp);
|
||||
wp->flags |= PANE_CHANGED;
|
||||
colour_palette_from_option(&wp->palette, wp->options);
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
||||
@@ -131,6 +135,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (src_s != dst_s)
|
||||
server_status_session_group(dst_s);
|
||||
|
||||
out:
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = BREAK_PANE_TEMPLATE;
|
||||
|
||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
||||
.name = "capture-pane",
|
||||
.alias = "capturep",
|
||||
|
||||
.args = { "ab:CeE:JNpPqS:t:", 0, 0, NULL },
|
||||
.usage = "[-aCeJNpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
.args = { "ab:CeE:JMNpPqS:Tt:", 0, 0, NULL },
|
||||
.usage = "[-aCeJMNpPqT] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -53,8 +53,8 @@ const struct cmd_entry cmd_clear_history_entry = {
|
||||
.name = "clear-history",
|
||||
.alias = "clearhist",
|
||||
|
||||
.args = { "t:", 0, 0, NULL },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
.args = { "Ht:", 0, 0, NULL },
|
||||
.usage = "[-H] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -107,14 +107,16 @@ static char *
|
||||
cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
struct window_pane *wp, size_t *len)
|
||||
{
|
||||
struct grid *gd;
|
||||
const struct grid_line *gl;
|
||||
struct grid_cell *gc = NULL;
|
||||
int n, with_codes, escape_c0, join_lines, no_trim;
|
||||
u_int i, sx, top, bottom, tmp;
|
||||
char *cause, *buf, *line;
|
||||
const char *Sflag, *Eflag;
|
||||
size_t linelen;
|
||||
struct grid *gd;
|
||||
const struct grid_line *gl;
|
||||
struct screen *s;
|
||||
struct grid_cell *gc = NULL;
|
||||
struct window_mode_entry *wme;
|
||||
int n, join_lines, flags = 0;
|
||||
u_int i, sx, top, bottom, tmp;
|
||||
char *cause, *buf, *line;
|
||||
const char *Sflag, *Eflag;
|
||||
size_t linelen;
|
||||
|
||||
sx = screen_size_x(&wp->base);
|
||||
if (args_has(args, 'a')) {
|
||||
@@ -126,14 +128,27 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
}
|
||||
return (xstrdup(""));
|
||||
}
|
||||
} else
|
||||
s = &wp->base;
|
||||
} else if (args_has(args, 'M')) {
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme != NULL && wme->mode->get_screen != NULL) {
|
||||
s = wme->mode->get_screen (wme);
|
||||
gd = s->grid;
|
||||
} else {
|
||||
s = &wp->base;
|
||||
gd = wp->base.grid;
|
||||
}
|
||||
} else {
|
||||
s = &wp->base;
|
||||
gd = wp->base.grid;
|
||||
}
|
||||
|
||||
Sflag = args_get(args, 'S');
|
||||
if (Sflag != NULL && strcmp(Sflag, "-") == 0)
|
||||
top = 0;
|
||||
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) {
|
||||
top = gd->hsize;
|
||||
free(cause);
|
||||
@@ -149,7 +164,8 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
if (Eflag != NULL && strcmp(Eflag, "-") == 0)
|
||||
bottom = gd->hsize + gd->sy - 1;
|
||||
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) {
|
||||
bottom = gd->hsize + gd->sy - 1;
|
||||
free(cause);
|
||||
@@ -167,15 +183,19 @@ cmd_capture_pane_history(struct args *args, struct cmdq_item *item,
|
||||
top = tmp;
|
||||
}
|
||||
|
||||
with_codes = args_has(args, 'e');
|
||||
escape_c0 = args_has(args, 'C');
|
||||
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;
|
||||
for (i = top; i <= bottom; i++) {
|
||||
line = grid_string_cells(gd, 0, i, sx, &gc, with_codes,
|
||||
escape_c0, !join_lines && !no_trim);
|
||||
line = grid_string_cells(gd, 0, i, sx, &gc, flags, s);
|
||||
linelen = strlen(line);
|
||||
|
||||
buf = cmd_capture_pane_append(buf, len, line, linelen);
|
||||
@@ -202,6 +222,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (cmd_get_entry(self) == &cmd_clear_history_entry) {
|
||||
window_pane_reset_mode_all(wp);
|
||||
grid_clear_history(wp->base.grid);
|
||||
if (args_has(args, 'H'))
|
||||
screen_reset_hyperlinks(wp->screen);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -226,8 +248,8 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
file_print_buffer(c, buf, len);
|
||||
file_print(c, "\n");
|
||||
free(buf);
|
||||
}
|
||||
free(buf);
|
||||
} else {
|
||||
bufname = NULL;
|
||||
if (args_has(args, 'b'))
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_choose_tree_entry = {
|
||||
.name = "choose-tree",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:GK:NO:rst:wZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.args = { "F:f:GK:NO:rst:wyZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-GNrswZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -47,7 +47,7 @@ const struct cmd_entry cmd_choose_client_entry = {
|
||||
.name = "choose-client",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||
.args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -61,7 +61,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.name = "choose-buffer",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:K:NO:rt:Z", 0, 1, cmd_choose_tree_args_parse },
|
||||
.args = { "F:f:K:NO:rt:yZ", 0, 1, cmd_choose_tree_args_parse },
|
||||
.usage = "[-NrZ] [-F format] [-f filter] [-K key-format] "
|
||||
"[-O sort-order] " CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
@@ -75,7 +75,7 @@ const struct cmd_entry cmd_customize_mode_entry = {
|
||||
.name = "customize-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:f:Nt:Z", 0, 0, NULL },
|
||||
.args = { "F:f:Nt:yZ", 0, 0, NULL },
|
||||
.usage = "[-NZ] [-F format] [-f filter] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -98,9 +98,16 @@ cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const struct window_mode *mode;
|
||||
enum sort_order order;
|
||||
|
||||
order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_choose_buffer_entry) {
|
||||
if (paste_get_top(NULL) == NULL)
|
||||
if (paste_is_empty())
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_buffer_mode;
|
||||
} else if (cmd_get_entry(self) == &cmd_choose_client_entry) {
|
||||
|
||||
@@ -42,9 +42,9 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
||||
.name = "command-prompt",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
||||
.usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
||||
" [-T type] [template]",
|
||||
.args = { "1beFiklI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse },
|
||||
.usage = "[-1beFiklN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE
|
||||
" [-T prompt-type] [template]",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_command_prompt_exec
|
||||
@@ -84,7 +84,7 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
const char *type, *s, *input;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
char *tmp, *prompts, *prompt, *next_prompt;
|
||||
char *inputs = NULL, *next_input;
|
||||
u_int count = args_count(args);
|
||||
@@ -117,32 +117,39 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
next_input = inputs = xstrdup(s);
|
||||
else
|
||||
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;
|
||||
if (args_has(args, 'l')) {
|
||||
cdata->prompts = xcalloc(1, sizeof *cdata->prompts);
|
||||
cdata->prompts[0].prompt = prompts;
|
||||
cdata->prompts[0].input = inputs;
|
||||
cdata->count = 1;
|
||||
} else {
|
||||
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;
|
||||
|
||||
if (next_input != NULL) {
|
||||
input = strsep(&next_input, ",");
|
||||
if (input == NULL)
|
||||
if (next_input != NULL) {
|
||||
input = strsep(&next_input, ",");
|
||||
if (input == NULL)
|
||||
input = "";
|
||||
} else
|
||||
input = "";
|
||||
} else
|
||||
input = "";
|
||||
cdata->prompts[cdata->count].input = xstrdup(input);
|
||||
|
||||
cdata->count++;
|
||||
cdata->prompts[cdata->count].input = xstrdup(input);
|
||||
cdata->count++;
|
||||
}
|
||||
free(inputs);
|
||||
free(prompts);
|
||||
}
|
||||
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);
|
||||
cmd_command_prompt_free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
@@ -156,6 +163,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->flags |= PROMPT_INCREMENTAL;
|
||||
else if (args_has(args, 'k'))
|
||||
cdata->flags |= PROMPT_KEY;
|
||||
else if (args_has(args, 'e'))
|
||||
cdata->flags |= PROMPT_BSPACE_EXIT;
|
||||
status_prompt_set(tc, target, cdata->prompts[0].prompt,
|
||||
cdata->prompts[0].input, cmd_command_prompt_callback,
|
||||
cmd_command_prompt_free, cdata, cdata->flags, cdata->prompt_type);
|
||||
@@ -179,10 +188,10 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
|
||||
if (s == NULL)
|
||||
goto out;
|
||||
|
||||
if (done) {
|
||||
if (cdata->flags & PROMPT_INCREMENTAL)
|
||||
goto out;
|
||||
|
||||
cmd_append_argv(&cdata->argc, &cdata->argv, s);
|
||||
if (++cdata->current != cdata->count) {
|
||||
prompt = &cdata->prompts[cdata->current];
|
||||
@@ -193,8 +202,11 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
|
||||
argc = cdata->argc;
|
||||
argv = cmd_copy_argv(cdata->argc, cdata->argv);
|
||||
cmd_append_argv(&argc, &argv, s);
|
||||
if (!done)
|
||||
cmd_append_argv(&argc, &argv, s);
|
||||
|
||||
if (done) {
|
||||
cmd_free_argv(cdata->argc, cdata->argv);
|
||||
cdata->argc = argc;
|
||||
cdata->argv = cmd_copy_argv(argc, argv);
|
||||
}
|
||||
@@ -224,7 +236,7 @@ out:
|
||||
static void
|
||||
cmd_command_prompt_free(void *data)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < cdata->count; i++) {
|
||||
|
||||
@@ -41,8 +41,9 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
||||
.name = "confirm-before",
|
||||
.alias = "confirm",
|
||||
|
||||
.args = { "bp:t:", 1, 1, cmd_confirm_before_args_parse },
|
||||
.usage = "[-b] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||
.args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse },
|
||||
.usage = "[-by] [-c confirm-key] [-p prompt] " CMD_TARGET_CLIENT_USAGE
|
||||
" command",
|
||||
|
||||
.flags = CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_confirm_before_exec
|
||||
@@ -51,6 +52,8 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
||||
struct cmd_confirm_before_data {
|
||||
struct cmdq_item *item;
|
||||
struct cmd_list *cmdlist;
|
||||
u_char confirm_key;
|
||||
int default_yes;
|
||||
};
|
||||
|
||||
static enum args_parse_type
|
||||
@@ -68,22 +71,41 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
char *new_prompt;
|
||||
const char *prompt, *cmd;
|
||||
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)
|
||||
if (cdata->cmdlist == NULL) {
|
||||
free(cdata);
|
||||
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");
|
||||
cmd_list_free(cdata->cmdlist);
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
cdata->confirm_key = 'y';
|
||||
|
||||
if ((prompt = args_get(args, 'p')) != NULL)
|
||||
xasprintf(&new_prompt, "%s ", prompt);
|
||||
else {
|
||||
cmd = cmd_get_entry(cmd_list_first(cdata->cmdlist))->name;
|
||||
xasprintf(&new_prompt, "Confirm '%s'? (y/n) ", cmd);
|
||||
xasprintf(&new_prompt, "Confirm '%s'? (%c/n) ", cmd,
|
||||
cdata->confirm_key);
|
||||
}
|
||||
|
||||
status_prompt_set(tc, target, new_prompt, NULL,
|
||||
@@ -107,9 +129,9 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
goto out;
|
||||
|
||||
if (s == NULL || *s == '\0')
|
||||
if (s == NULL)
|
||||
goto out;
|
||||
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
|
||||
if (s[0] != cdata->confirm_key && (s[0] != '\r' || !cdata->default_yes))
|
||||
goto out;
|
||||
retcode = 0;
|
||||
|
||||
@@ -123,12 +145,12 @@ cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,13 +30,13 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
||||
.name = "copy-mode",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "eHMs:t:uq", 0, 0, NULL },
|
||||
.usage = "[-eHMuq] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
||||
.args = { "deHMqSs:t:u", 0, 0, NULL },
|
||||
.usage = "[-deHMqSu] [-s src-pane] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.flags = CMD_AFTERHOOK|CMD_READONLY,
|
||||
.exec = cmd_copy_mode_exec
|
||||
};
|
||||
|
||||
@@ -91,6 +91,13 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
if (args_has(args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
if (args_has(args, 'd'))
|
||||
window_copy_pagedown(wp, 0, args_has(args, 'e'));
|
||||
if (args_has(args, 'S')) {
|
||||
window_copy_scroll(wp, c->tty.mouse_slider_mpos, event->m.y,
|
||||
args_has(args, 'e'));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -38,9 +38,11 @@ const struct cmd_entry cmd_display_menu_entry = {
|
||||
.name = "display-menu",
|
||||
.alias = "menu",
|
||||
|
||||
.args = { "c:t:OT:x:y:", 1, -1, cmd_display_menu_args_parse },
|
||||
.usage = "[-O] [-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
|
||||
"[-x position] [-y position] name key command ...",
|
||||
.args = { "b:c:C:H:s:S:MOt:T:x:y:", 1, -1, cmd_display_menu_args_parse },
|
||||
.usage = "[-MO] [-b border-lines] [-c target-client] "
|
||||
"[-C starting-choice] [-H selected-style] [-s style] "
|
||||
"[-S border-style] " CMD_TARGET_PANE_USAGE " [-T title] "
|
||||
"[-x position] [-y position] name [key] [command] ...",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -52,12 +54,12 @@ const struct cmd_entry cmd_display_popup_entry = {
|
||||
.name = "display-popup",
|
||||
.alias = "popup",
|
||||
|
||||
.args = { "Bb:Cc:d:e:Eh:s:S:t:T:w:x:y:", 0, -1, NULL },
|
||||
.usage = "[-BCE] [-b border-lines] [-c target-client] "
|
||||
.args = { "Bb:Cc:d:e:Eh:kNs:S:t:T:w:x:y:", 0, -1, NULL },
|
||||
.usage = "[-BCEkN] [-b border-lines] [-c target-client] "
|
||||
"[-d start-directory] [-e environment] [-h height] "
|
||||
"[-s style] [-S border-style] " CMD_TARGET_PANE_USAGE
|
||||
"[-T title] [-w width] [-x position] [-y position] "
|
||||
"[shell-command]",
|
||||
" [-T title] [-w width] [-x position] [-y position] "
|
||||
"[shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -90,7 +92,7 @@ cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause)
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
cmd_display_menu_get_pos(struct client *tc, struct cmdq_item *item,
|
||||
struct args *args, u_int *px, u_int *py, u_int w, u_int h)
|
||||
{
|
||||
struct tty *tty = &tc->tty;
|
||||
@@ -274,6 +276,7 @@ cmd_display_menu_get_position(struct client *tc, struct cmdq_item *item,
|
||||
log_debug("%s: -y: %s = %s = %u (-h %u)", __func__, yp, p, *py, h);
|
||||
free(p);
|
||||
|
||||
format_free(ft);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -286,19 +289,40 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct menu *menu = NULL;
|
||||
struct menu_item menu_item;
|
||||
const char *key, *name;
|
||||
char *title;
|
||||
int flags = 0;
|
||||
const char *key, *name, *value;
|
||||
const char *style = args_get(args, 's');
|
||||
const char *border_style = args_get(args, 'S');
|
||||
const char *selected_style = args_get(args, 'H');
|
||||
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||
char *title, *cause = NULL;
|
||||
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)
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
title = format_single_from_target(item, args_get(args, 'T'));
|
||||
else
|
||||
title = xstrdup("");
|
||||
menu = menu_create(title);
|
||||
free(title);
|
||||
|
||||
for (i = 0; i != count; /* nothing */) {
|
||||
name = args_string(args, i++);
|
||||
@@ -309,9 +333,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (count - i < 2) {
|
||||
cmdq_error(item, "not enough arguments");
|
||||
free(title);
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
key = args_string(args, i++);
|
||||
|
||||
@@ -321,29 +343,44 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
menu_add_item(menu, &menu_item, item, tc, target);
|
||||
}
|
||||
free(title);
|
||||
if (menu == NULL) {
|
||||
cmdq_error(item, "invalid menu arguments");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
if (menu->count == 0) {
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py,
|
||||
menu->width + 4, menu->count + 2)) {
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (menu->count == 0)
|
||||
goto out;
|
||||
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, menu->width + 4,
|
||||
menu->count + 2))
|
||||
goto out;
|
||||
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'O'))
|
||||
flags |= MENU_STAYOPEN;
|
||||
if (!event->m.valid)
|
||||
if (!event->m.valid && !args_has(args, 'M'))
|
||||
flags |= MENU_NOMOUSE;
|
||||
if (menu_display(menu, flags, item, px, py, tc, target, NULL,
|
||||
NULL) != 0)
|
||||
if (menu_display(menu, flags, starting_choice, item, px, py, tc, lines,
|
||||
style, selected_style, border_style, target, NULL, NULL) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
|
||||
out:
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(cause);
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -357,8 +394,10 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
const char *value, *shell, *shellcmd = NULL;
|
||||
const char *style = args_get(args, 's');
|
||||
const char *border_style = args_get(args, 'S');
|
||||
char *cwd, *cause = NULL, **argv = NULL, *title;
|
||||
int flags = 0, argc = 0;
|
||||
char *cwd = NULL, *cause = NULL, **argv = NULL;
|
||||
char *title = NULL;
|
||||
int modify = popup_present(tc);
|
||||
int flags = -1, argc = 0;
|
||||
enum box_lines lines = BOX_LINES_DEFAULT;
|
||||
u_int px, py, w, h, count = args_count(args);
|
||||
struct args_value *av;
|
||||
@@ -370,36 +409,66 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
server_client_clear_overlay(tc);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (tc->overlay_draw != NULL)
|
||||
if (!modify && tc->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
h = tty->sy / 2;
|
||||
if (args_has(args, 'h')) {
|
||||
h = args_percentage(args, 'h', 1, tty->sy, tty->sy, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (!modify) {
|
||||
h = tty->sy / 2;
|
||||
if (args_has(args, 'h')) {
|
||||
h = args_percentage(args, 'h', 1, tty->sy, tty->sy,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
w = tty->sx / 2;
|
||||
if (args_has(args, 'w')) {
|
||||
w = args_percentage(args, 'w', 1, tty->sx, tty->sx,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "width %s", cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
if (w > tty->sx)
|
||||
w = tty->sx;
|
||||
if (h > tty->sy)
|
||||
h = tty->sy;
|
||||
if (!cmd_display_menu_get_pos(tc, item, args, &px, &py, w, h))
|
||||
goto out;
|
||||
|
||||
value = args_get(args, 'd');
|
||||
if (value != NULL)
|
||||
cwd = format_single_from_target(item, value);
|
||||
else
|
||||
cwd = xstrdup(server_client_get_cwd(tc, s));
|
||||
if (count == 0) {
|
||||
shellcmd = options_get_string(s->options,
|
||||
"default-command");
|
||||
} else if (count == 1)
|
||||
shellcmd = args_string(args, 0);
|
||||
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||
shellcmd = NULL;
|
||||
shell = options_get_string(s->options, "default-shell");
|
||||
if (!checkshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
cmd_append_argv(&argc, &argv, shell);
|
||||
} else
|
||||
args_to_vector(args, &argc, &argv);
|
||||
|
||||
if (args_has(args, 'e') >= 1) {
|
||||
env = environ_create();
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w = tty->sx / 2;
|
||||
if (args_has(args, 'w')) {
|
||||
w = args_percentage(args, 'w', 1, tty->sx, tty->sx, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "width %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (w > tty->sx)
|
||||
w = tty->sx;
|
||||
if (h > tty->sy)
|
||||
h = tty->sy;
|
||||
if (!cmd_display_menu_get_position(tc, item, args, &px, &py, w, h))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
value = args_get(args, 'b');
|
||||
if (args_has(args, 'B'))
|
||||
lines = BOX_LINES_NONE;
|
||||
@@ -409,35 +478,7 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "popup-border-lines %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
value = args_get(args, 'd');
|
||||
if (value != NULL)
|
||||
cwd = format_single_from_target(item, value);
|
||||
else
|
||||
cwd = xstrdup(server_client_get_cwd(tc, s));
|
||||
if (count == 0)
|
||||
shellcmd = options_get_string(s->options, "default-command");
|
||||
else if (count == 1)
|
||||
shellcmd = args_string(args, 0);
|
||||
if (count <= 1 && (shellcmd == NULL || *shellcmd == '\0')) {
|
||||
shellcmd = NULL;
|
||||
shell = options_get_string(s->options, "default-shell");
|
||||
if (!checkshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
cmd_append_argv(&argc, &argv, shell);
|
||||
} else
|
||||
args_to_vector(args, &argc, &argv);
|
||||
|
||||
if (args_has(args, 'e') >= 1) {
|
||||
env = environ_create();
|
||||
av = args_first_value(args, 'e');
|
||||
while (av != NULL) {
|
||||
environ_put(env, av->string, 0);
|
||||
av = args_next_value(av);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,21 +486,49 @@ cmd_display_popup_exec(struct cmd *self, struct cmdq_item *item)
|
||||
title = format_single_from_target(item, args_get(args, 'T'));
|
||||
else
|
||||
title = xstrdup("");
|
||||
if (args_has(args, 'E') > 1)
|
||||
|
||||
if (args_has(args, 'N') || !modify)
|
||||
flags = 0;
|
||||
if (args_has(args, 'E') > 1) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEEXITZERO;
|
||||
else if (args_has(args, 'E'))
|
||||
} else if (args_has(args, 'E')) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEEXIT;
|
||||
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
||||
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0) {
|
||||
cmd_free_argv(argc, argv);
|
||||
if (env != NULL)
|
||||
environ_free(env);
|
||||
free(title);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (env != NULL)
|
||||
environ_free(env);
|
||||
if (args_has(args, 'k')) {
|
||||
if (flags == -1)
|
||||
flags = 0;
|
||||
flags |= POPUP_CLOSEANYKEY;
|
||||
}
|
||||
|
||||
if (modify) {
|
||||
popup_modify(tc, title, style, border_style, lines, flags);
|
||||
goto out;
|
||||
}
|
||||
if (popup_display(flags, lines, item, px, py, w, h, env, shellcmd, argc,
|
||||
argv, cwd, title, tc, s, style, border_style, NULL, NULL) != 0)
|
||||
goto out;
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
cmd_free_argv(argc, argv);
|
||||
return (CMD_RETURN_WAIT);
|
||||
|
||||
out:
|
||||
cmd_free_argv(argc, argv);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(cause);
|
||||
cmd_free_argv(argc, argv);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
free(title);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.name = "display-message",
|
||||
.alias = "display",
|
||||
|
||||
.args = { "ac:d:INpt:F:v", 0, 1, NULL },
|
||||
.usage = "[-aINpv] [-c target-client] [-d delay] [-F format] "
|
||||
.args = { "aCc:d:lINpt:F:v", 0, 1, NULL },
|
||||
.usage = "[-aCIlNpv] [-c target-client] [-d delay] [-F format] "
|
||||
CMD_TARGET_PANE_USAGE " [message]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
@@ -68,9 +68,11 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *template;
|
||||
char *msg, *cause;
|
||||
int delay = -1, flags;
|
||||
int delay = -1, flags, Nflag = args_has(args, 'N');
|
||||
int Cflag = args_has(args, 'C');
|
||||
struct format_tree *ft;
|
||||
u_int count = args_count(args);
|
||||
struct evbuffer *evb;
|
||||
|
||||
if (args_has(args, 'I')) {
|
||||
if (wp == NULL)
|
||||
@@ -129,21 +131,30 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
format_each(ft, cmd_display_message_each, item);
|
||||
format_free(ft);
|
||||
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)
|
||||
cmdq_error(item, "%s", msg);
|
||||
else if (args_has(args, 'p'))
|
||||
cmdq_print(item, "%s", msg);
|
||||
else if (tc != NULL) {
|
||||
status_message_set(tc, delay, 0, args_has(args, 'N'), "%s",
|
||||
msg);
|
||||
}
|
||||
else if (tc != NULL && (tc->flags & CLIENT_CONTROL)) {
|
||||
evb = evbuffer_new();
|
||||
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, Cflag, "%s", msg);
|
||||
free(msg);
|
||||
|
||||
format_free(ft);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
llen = 0;
|
||||
|
||||
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) {
|
||||
len += llen + 1;
|
||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
||||
@@ -161,7 +161,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
px -= len * 3;
|
||||
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++) {
|
||||
if (*ptr < '0' || *ptr > '9')
|
||||
continue;
|
||||
@@ -179,7 +179,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
|
||||
if (sy <= 6)
|
||||
goto out;
|
||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL);
|
||||
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL);
|
||||
if (rlen != 0 && sx >= rlen) {
|
||||
tty_cursor(tty, xoff + sx - rlen, yoff);
|
||||
tty_putn(tty, rbuf, rlen, rlen);
|
||||
@@ -246,7 +246,7 @@ cmd_display_panes_key(struct client *c, void *data, struct key_event *event)
|
||||
wp = window_pane_at_index(w, index);
|
||||
if (wp == NULL)
|
||||
return (1);
|
||||
window_unzoom(w);
|
||||
window_unzoom(w, 1);
|
||||
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct window_pane *wp = target->wp;
|
||||
const char *s = args_string(args, 0), *suffix = "";
|
||||
const char *star = "*";
|
||||
struct args_value *filter;
|
||||
int C, N, T;
|
||||
|
||||
@@ -55,6 +56,8 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
N = args_has(args, 'N');
|
||||
T = args_has(args, 'T');
|
||||
|
||||
if (args_has(args, 'r'))
|
||||
star = "";
|
||||
if (args_has(args, 'r') && args_has(args, 'i'))
|
||||
suffix = "/ri";
|
||||
else if (args_has(args, 'r'))
|
||||
@@ -71,40 +74,40 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (C && N && T) {
|
||||
xasprintf(&filter->string,
|
||||
"#{||:"
|
||||
"#{C%s:%s},#{||:#{m%s:*%s*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}}",
|
||||
suffix, s, suffix, s, suffix, s);
|
||||
"#{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*,#{window_name}}}",
|
||||
suffix, s, suffix, s);
|
||||
"#{||:#{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*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
"#{||:#{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*,#{window_name}},"
|
||||
"#{m%s:*%s*,#{pane_title}}}",
|
||||
suffix, s, suffix, s);
|
||||
"#{||:#{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*,#{window_name}}",
|
||||
suffix, s);
|
||||
"#{m%s:%s%s%s,#{window_name}}",
|
||||
suffix, star, s, star);
|
||||
} else {
|
||||
xasprintf(&filter->string,
|
||||
"#{m%s:*%s*,#{pane_title}}",
|
||||
suffix, s);
|
||||
"#{m%s:%s%s%s,#{pane_title}}",
|
||||
suffix, star, s, star);
|
||||
}
|
||||
|
||||
new_args = args_create();
|
||||
if (args_has(args, 'Z'))
|
||||
args_set(new_args, 'Z', NULL);
|
||||
args_set(new_args, 'f', filter);
|
||||
args_set(new_args, 'Z', NULL, 0);
|
||||
args_set(new_args, 'f', filter, 0);
|
||||
|
||||
window_pane_set_mode(wp, NULL, &window_tree_mode, target, new_args);
|
||||
args_free(new_args);
|
||||
|
||||
27
cmd-find.c
27
cmd-find.c
@@ -582,27 +582,27 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
|
||||
/* Try special characters. */
|
||||
if (strcmp(pane, "!") == 0) {
|
||||
fs->wp = fs->w->last;
|
||||
fs->wp = TAILQ_FIRST(&fs->w->last_panes);
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (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)
|
||||
return (-1);
|
||||
return (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)
|
||||
return (-1);
|
||||
return (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)
|
||||
return (-1);
|
||||
return (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)
|
||||
return (-1);
|
||||
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);
|
||||
else
|
||||
n = 1;
|
||||
wp = fs->current->wp;
|
||||
wp = fs->w->active;
|
||||
if (pane[0] == '+')
|
||||
fs->wp = window_pane_next_by_number(fs->w, wp, n);
|
||||
else
|
||||
@@ -924,6 +924,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
const char *target, enum cmd_find_type type, int flags)
|
||||
{
|
||||
struct mouse_event *m;
|
||||
struct client *c;
|
||||
struct cmd_find_state current;
|
||||
char *colon, *period, *copy = NULL, tmp[256];
|
||||
const char *session, *window, *pane, *s;
|
||||
@@ -990,6 +991,20 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
if (target == NULL || *target == '\0')
|
||||
goto current;
|
||||
|
||||
if (strcmp(target, "@") == 0 ||
|
||||
strcmp(target, "{active}") == 0 ||
|
||||
strcmp(target, "{current}") == 0) {
|
||||
c = cmdq_get_client(item);
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "no current client");
|
||||
goto error;
|
||||
}
|
||||
fs->wl = c->session->curw;
|
||||
fs->wp = c->session->curw->window->active;
|
||||
fs->w = c->session->curw->window;
|
||||
goto found;
|
||||
}
|
||||
|
||||
/* Mouse target is a plain = or {mouse}. */
|
||||
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
|
||||
m = &cmdq_get_event(item)->m;
|
||||
|
||||
@@ -124,7 +124,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
-1) == NULL) {
|
||||
cmdq_error(item, "failed to run command: %s", shellcmd);
|
||||
free(shellcmd);
|
||||
free(cdata);
|
||||
cmd_if_shell_free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(shellcmd);
|
||||
@@ -157,7 +157,7 @@ cmd_if_shell_callback(struct job *job)
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, "%s", error);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
|
||||
@@ -71,10 +71,11 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window *src_w, *dst_w;
|
||||
struct window_pane *src_wp, *dst_wp;
|
||||
char *cause = NULL;
|
||||
int size, percentage, dst_idx;
|
||||
int size, dst_idx;
|
||||
int flags;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
u_int curval = 0;
|
||||
|
||||
dst_s = target->s;
|
||||
dst_wl = target->wl;
|
||||
@@ -97,23 +98,30 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
|
||||
/* If the 'p' flag is dropped then this bit can be moved into 'l'. */
|
||||
if (args_has(args, 'l') || args_has(args, 'p')) {
|
||||
if (args_has(args, 'f')) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
curval = dst_w->sy;
|
||||
else
|
||||
curval = dst_w->sx;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
curval = dst_wp->sy;
|
||||
else
|
||||
curval = dst_wp->sx;
|
||||
}
|
||||
}
|
||||
|
||||
size = -1;
|
||||
if (args_has(args, 'l')) {
|
||||
if (type == LAYOUT_TOPBOTTOM) {
|
||||
size = args_percentage(args, 'l', 0, INT_MAX,
|
||||
dst_wp->sy, &cause);
|
||||
} else {
|
||||
size = args_percentage(args, 'l', 0, INT_MAX,
|
||||
dst_wp->sx, &cause);
|
||||
}
|
||||
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
||||
item, &cause);
|
||||
} else if (args_has(args, 'p')) {
|
||||
percentage = args_strtonum(args, 'p', 0, 100, &cause);
|
||||
if (cause == NULL) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (dst_wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (dst_wp->sx * percentage) / 100;
|
||||
}
|
||||
size = args_strtonum_and_expand(args, 'l', 0, 100, item,
|
||||
&cause);
|
||||
if (cause == NULL)
|
||||
size = curval * size / 100;
|
||||
}
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "size %s", cause);
|
||||
@@ -141,12 +149,13 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
src_wp->window = dst_w;
|
||||
options_set_parent(src_wp->options, dst_w->options);
|
||||
src_wp->flags |= PANE_STYLECHANGED;
|
||||
src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
if (flags & SPAWN_BEFORE)
|
||||
TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry);
|
||||
layout_assign_pane(lc, src_wp, 0);
|
||||
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
||||
|
||||
recalculate_sizes();
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
.name = "list-buffers",
|
||||
.alias = "lsb",
|
||||
|
||||
.args = { "F:f:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter]",
|
||||
.args = { "F:f:O:r", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter] [-O order]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_buffers_exec
|
||||
@@ -46,21 +46,30 @@ const struct cmd_entry cmd_list_buffers_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct paste_buffer *pb;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct paste_buffer **l;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
u_int i, n;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_BUFFERS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
pb = NULL;
|
||||
while ((pb = paste_walk(pb)) != NULL) {
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_buffers(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults_paste_buffer(ft, pb);
|
||||
format_defaults_paste_buffer(ft, l[i]);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
|
||||
@@ -41,8 +41,8 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
.name = "list-clients",
|
||||
.alias = "lsc",
|
||||
|
||||
.args = { "F:t:", 0, 0, NULL },
|
||||
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
.args = { "F:f:O:rt:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter] [-O order]" CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -53,14 +53,16 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct format_tree *ft;
|
||||
const char *template;
|
||||
u_int idx;
|
||||
char *line;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct client **l;
|
||||
struct session *s;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
u_int i, n;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
s = target->s;
|
||||
@@ -69,23 +71,37 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_CLIENTS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
idx = 0;
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == NULL || (s != NULL && s != c->session))
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_clients(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (l[i]->session == NULL || (s != NULL && s != l[i]->session))
|
||||
continue;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", idx);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
format_add(ft, "line", "%u", i);
|
||||
format_defaults(ft, l[i], NULL, NULL, NULL);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
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);
|
||||
|
||||
idx++;
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
107
cmd-list-commands.c
Normal file
107
cmd-list-commands.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 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"
|
||||
|
||||
/*
|
||||
* List all commands.
|
||||
*/
|
||||
|
||||
#define LIST_COMMANDS_TEMPLATE \
|
||||
"#{command_list_name}" \
|
||||
"#{?command_list_alias, (#{command_list_alias}),} " \
|
||||
"#{command_list_usage}"
|
||||
|
||||
static enum cmd_retval cmd_list_commands(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_commands_entry = {
|
||||
.name = "list-commands",
|
||||
.alias = "lscm",
|
||||
|
||||
.args = { "F:", 0, 1, NULL },
|
||||
.usage = "[-F format] [command]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_commands
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_list_single_command(const struct cmd_entry *entry, struct format_tree *ft,
|
||||
const char *template, struct cmdq_item *item)
|
||||
{
|
||||
const char *s;
|
||||
char *line;
|
||||
|
||||
format_add(ft, "command_list_name", "%s", entry->name);
|
||||
if (entry->alias != NULL)
|
||||
s = entry->alias;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_alias", "%s", s);
|
||||
if (entry->usage != NULL)
|
||||
s = entry->usage;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_usage", "%s", s);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
if (*line != '\0')
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
const char *template, *command;
|
||||
char *cause;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_COMMANDS_TEMPLATE;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
command = args_string(args, 0);
|
||||
if (command == NULL) {
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++)
|
||||
cmd_list_single_command(*entryp, ft, template, item);
|
||||
} else {
|
||||
entry = cmd_find(command, &cause);
|
||||
if (entry != NULL)
|
||||
cmd_list_single_command(entry, ft, template, item);
|
||||
else {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
426
cmd-list-keys.c
426
cmd-list-keys.c
@@ -27,137 +27,157 @@
|
||||
* List key bindings.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
#define LIST_KEYS_TEMPLATE \
|
||||
"#{?notes_only," \
|
||||
"#{key_prefix} " \
|
||||
"#{p|#{key_string_width}:key_string} " \
|
||||
"#{?key_note,#{key_note},#{key_command}}" \
|
||||
"," \
|
||||
"bind-key #{?key_has_repeat,#{?key_repeat,-r, },} " \
|
||||
"-T #{p|#{key_table_width}:key_table} " \
|
||||
"#{p|#{key_string_width}:key_string} " \
|
||||
"#{key_command}}"
|
||||
|
||||
static enum cmd_retval cmd_list_keys_commands(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
static enum cmd_retval cmd_list_keys_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_list_keys_entry = {
|
||||
.name = "list-keys",
|
||||
.alias = "lsk",
|
||||
|
||||
.args = { "1aNP:T:", 0, 1, NULL },
|
||||
.usage = "[-1aN] [-P prefix-string] [-T key-table] [key]",
|
||||
.args = { "1aF:NO:P:rT:", 0, 1, NULL },
|
||||
.usage = "[-1aNr] [-F format] [-O order] [-P prefix-string]"
|
||||
"[-T key-table] [key]",
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_list_commands_entry = {
|
||||
.name = "list-commands",
|
||||
.alias = "lscm",
|
||||
static char *
|
||||
cmd_list_keys_get_prefix(struct args *args)
|
||||
{
|
||||
key_code prefix;
|
||||
|
||||
.args = { "F:", 0, 1, NULL },
|
||||
.usage = "[-F format] [command]",
|
||||
if (args_has(args, 'P'))
|
||||
return (xstrdup(args_get(args, 'P')));
|
||||
|
||||
.flags = CMD_STARTSERVER|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_keys_exec
|
||||
};
|
||||
prefix = options_get_number(global_s_options, "prefix");
|
||||
if (prefix == KEYC_NONE)
|
||||
return (xstrdup(""));
|
||||
return (xstrdup(key_string_lookup_key(prefix, 0)));
|
||||
}
|
||||
|
||||
static u_int
|
||||
cmd_list_keys_get_width(const char *tablename, key_code only)
|
||||
cmd_list_keys_get_width(struct key_binding **l, u_int n)
|
||||
{
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
u_int width, keywidth = 0;
|
||||
u_int i, width, keywidth = 0;
|
||||
|
||||
table = key_bindings_get_table(tablename, 0);
|
||||
if (table == NULL)
|
||||
return (0);
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
||||
KEYC_IS_MOUSE(bd->key) ||
|
||||
bd->note == NULL ||
|
||||
*bd->note == '\0') {
|
||||
bd = key_bindings_next(table, bd);
|
||||
continue;
|
||||
}
|
||||
width = utf8_cstrwidth(key_string_lookup_key(bd->key, 0));
|
||||
for (i = 0; i < n; i++) {
|
||||
width = utf8_cstrwidth(key_string_lookup_key(l[i]->key, 0));
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
return (keywidth);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_list_keys_print_notes(struct cmdq_item *item, struct args *args,
|
||||
const char *tablename, u_int keywidth, key_code only, const char *prefix)
|
||||
static u_int
|
||||
cmd_list_keys_get_table_width(struct key_binding **l, u_int n)
|
||||
{
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
const char *key;
|
||||
char *tmp, *note;
|
||||
int found = 0;
|
||||
u_int i, width, tablewidth = 0;
|
||||
|
||||
table = key_bindings_get_table(tablename, 0);
|
||||
if (table == NULL)
|
||||
return (0);
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
if ((only != KEYC_UNKNOWN && bd->key != only) ||
|
||||
KEYC_IS_MOUSE(bd->key) ||
|
||||
((bd->note == NULL || *bd->note == '\0') &&
|
||||
!args_has(args, 'a'))) {
|
||||
bd = key_bindings_next(table, bd);
|
||||
continue;
|
||||
}
|
||||
found = 1;
|
||||
key = key_string_lookup_key(bd->key, 0);
|
||||
|
||||
if (bd->note == NULL || *bd->note == '\0')
|
||||
note = cmd_list_print(bd->cmdlist, 1);
|
||||
else
|
||||
note = xstrdup(bd->note);
|
||||
tmp = utf8_padcstr(key, keywidth + 1);
|
||||
if (args_has(args, '1') && tc != NULL) {
|
||||
status_message_set(tc, -1, 1, 0, "%s%s%s", prefix, tmp,
|
||||
note);
|
||||
} else
|
||||
cmdq_print(item, "%s%s%s", prefix, tmp, note);
|
||||
free(tmp);
|
||||
free(note);
|
||||
|
||||
if (args_has(args, '1'))
|
||||
break;
|
||||
bd = key_bindings_next(table, bd);
|
||||
for (i = 0; i < n; i++) {
|
||||
width = utf8_cstrwidth(l[i]->tablename);
|
||||
if (width > tablewidth)
|
||||
tablewidth = width;
|
||||
}
|
||||
return (found);
|
||||
return (tablewidth);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_list_keys_get_prefix(struct args *args, key_code *prefix)
|
||||
static struct key_binding **
|
||||
cmd_get_root_and_prefix(u_int *n, struct sort_criteria *sort_crit)
|
||||
{
|
||||
char *s;
|
||||
const char *tables[] = { "prefix", "root" };
|
||||
struct key_table *t;
|
||||
struct key_binding **lt;
|
||||
u_int i, ltsz, len = 0, offset = 0;
|
||||
static struct key_binding **l = NULL;
|
||||
static u_int lsz = 0;
|
||||
|
||||
*prefix = options_get_number(global_s_options, "prefix");
|
||||
if (!args_has(args, 'P')) {
|
||||
if (*prefix != KEYC_NONE)
|
||||
xasprintf(&s, "%s ", key_string_lookup_key(*prefix, 0));
|
||||
else
|
||||
s = xstrdup("");
|
||||
} else
|
||||
s = xstrdup(args_get(args, 'P'));
|
||||
return (s);
|
||||
for (i = 0; i < nitems(tables); i++) {
|
||||
t = key_bindings_get_table(tables[i], 0);
|
||||
lt = sort_get_key_bindings_table(t, <sz, sort_crit);
|
||||
len += ltsz;
|
||||
if (lsz <= len) {
|
||||
lsz = len + 100;
|
||||
l = xreallocarray(l, lsz, sizeof *l);
|
||||
}
|
||||
memcpy(l + offset, lt, ltsz * sizeof *l);
|
||||
offset += ltsz;
|
||||
}
|
||||
|
||||
*n = len;
|
||||
return (l);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_filter_key_list(int filter_notes, int filter_key, key_code only,
|
||||
struct key_binding **l, u_int *n)
|
||||
{
|
||||
key_code key;
|
||||
u_int i, j = 0;
|
||||
|
||||
for (i = 0; i < *n; i++) {
|
||||
key = l[i]->key & (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||
if (filter_key && only != key)
|
||||
continue;
|
||||
if (filter_notes && l[i]->note == NULL)
|
||||
continue;
|
||||
l[j++] = l[i];
|
||||
}
|
||||
*n = j;
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_format_add_key_binding(struct format_tree *ft,
|
||||
const struct key_binding *bd, const char *prefix)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
format_add(ft, "key_repeat", "1");
|
||||
else
|
||||
format_add(ft, "key_repeat", "0");
|
||||
|
||||
if (bd->note != NULL)
|
||||
format_add(ft, "key_note", "%s", bd->note);
|
||||
else
|
||||
format_add(ft, "key_note", "%s", "");
|
||||
|
||||
format_add(ft, "key_prefix", "%s", prefix);
|
||||
format_add(ft, "key_table", "%s", bd->tablename);
|
||||
|
||||
s = key_string_lookup_key(bd->key, 0);
|
||||
format_add(ft, "key_string", "%s", s);
|
||||
|
||||
s = cmd_list_print(bd->cmdlist,
|
||||
CMD_LIST_PRINT_ESCAPED|CMD_LIST_PRINT_NO_GROUPS);
|
||||
format_add(ft, "key_command", "%s", s);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
const char *tablename, *r, *keystr;
|
||||
char *key, *cp, *tmp, *start, *empty;
|
||||
key_code prefix, only = KEYC_UNKNOWN;
|
||||
int repeat, width, tablewidth, keywidth, found = 0;
|
||||
size_t tmpsize, tmpused, cplen;
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_list_commands_entry)
|
||||
return (cmd_list_keys_commands(self, item));
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct format_tree *ft;
|
||||
struct key_table *table = NULL;
|
||||
struct key_binding **l;
|
||||
key_code only = KEYC_UNKNOWN;
|
||||
const char *template, *tablename, *keystr;
|
||||
char *line;
|
||||
char *prefix = NULL;
|
||||
u_int i, n;
|
||||
int single, notes_only, filter_notes, filter_key;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if ((keystr = args_string(args, 0)) != NULL) {
|
||||
only = key_string_lookup_string(keystr);
|
||||
@@ -168,198 +188,64 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
only &= (KEYC_MASK_KEY|KEYC_MASK_MODIFIERS);
|
||||
}
|
||||
|
||||
tablename = args_get(args, 'T');
|
||||
if (tablename != NULL && key_bindings_get_table(tablename, 0) == NULL) {
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
if (tablename == NULL) {
|
||||
start = cmd_list_keys_get_prefix(args, &prefix);
|
||||
keywidth = cmd_list_keys_get_width("root", only);
|
||||
if (prefix != KEYC_NONE) {
|
||||
width = cmd_list_keys_get_width("prefix", only);
|
||||
if (width == 0)
|
||||
prefix = KEYC_NONE;
|
||||
else if (width > keywidth)
|
||||
keywidth = width;
|
||||
}
|
||||
empty = utf8_padcstr("", utf8_cstrwidth(start));
|
||||
|
||||
found = cmd_list_keys_print_notes(item, args, "root",
|
||||
keywidth, only, empty);
|
||||
if (prefix != KEYC_NONE) {
|
||||
if (cmd_list_keys_print_notes(item, args,
|
||||
"prefix", keywidth, only, start))
|
||||
found = 1;
|
||||
}
|
||||
free(empty);
|
||||
} else {
|
||||
if (args_has(args, 'P'))
|
||||
start = xstrdup(args_get(args, 'P'));
|
||||
else
|
||||
start = xstrdup("");
|
||||
keywidth = cmd_list_keys_get_width(tablename, only);
|
||||
found = cmd_list_keys_print_notes(item, args, tablename,
|
||||
keywidth, only, start);
|
||||
prefix = cmd_list_keys_get_prefix(args);
|
||||
single = args_has(args, '1');
|
||||
notes_only = args_has(args, 'N');
|
||||
|
||||
if ((tablename = args_get(args, 'T')) != NULL) {
|
||||
table = key_bindings_get_table(tablename, 0);
|
||||
if (table == NULL) {
|
||||
cmdq_error(item, "table %s doesn't exist", tablename);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(start);
|
||||
goto out;
|
||||
}
|
||||
|
||||
repeat = 0;
|
||||
tablewidth = keywidth = 0;
|
||||
table = key_bindings_first_table();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
continue;
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
||||
bd = key_bindings_next(table, bd);
|
||||
continue;
|
||||
}
|
||||
key = args_escape(key_string_lookup_key(bd->key, 0));
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_KEYS_TEMPLATE;
|
||||
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
repeat = 1;
|
||||
if (table)
|
||||
l = sort_get_key_bindings_table(table, &n, &sort_crit);
|
||||
else if (notes_only)
|
||||
l = cmd_get_root_and_prefix(&n, &sort_crit);
|
||||
else
|
||||
l = sort_get_key_bindings(&n, &sort_crit);
|
||||
|
||||
width = utf8_cstrwidth(table->name);
|
||||
if (width > tablewidth)
|
||||
tablewidth = width;
|
||||
width = utf8_cstrwidth(key);
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
|
||||
free(key);
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
table = key_bindings_next_table(table);
|
||||
}
|
||||
|
||||
tmpsize = 256;
|
||||
tmp = xmalloc(tmpsize);
|
||||
|
||||
table = key_bindings_first_table();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
continue;
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
if (only != KEYC_UNKNOWN && bd->key != only) {
|
||||
bd = key_bindings_next(table, bd);
|
||||
continue;
|
||||
}
|
||||
found = 1;
|
||||
key = args_escape(key_string_lookup_key(bd->key, 0));
|
||||
|
||||
if (!repeat)
|
||||
r = "";
|
||||
else if (bd->flags & KEY_BINDING_REPEAT)
|
||||
r = "-r ";
|
||||
else
|
||||
r = " ";
|
||||
tmpused = xsnprintf(tmp, tmpsize, "%s-T ", r);
|
||||
|
||||
cp = utf8_padcstr(table->name, tablewidth);
|
||||
cplen = strlen(cp) + 1;
|
||||
while (tmpused + cplen + 1 >= tmpsize) {
|
||||
tmpsize *= 2;
|
||||
tmp = xrealloc(tmp, tmpsize);
|
||||
}
|
||||
strlcat(tmp, cp, tmpsize);
|
||||
tmpused = strlcat(tmp, " ", tmpsize);
|
||||
free(cp);
|
||||
|
||||
cp = utf8_padcstr(key, keywidth);
|
||||
cplen = strlen(cp) + 1;
|
||||
while (tmpused + cplen + 1 >= tmpsize) {
|
||||
tmpsize *= 2;
|
||||
tmp = xrealloc(tmp, tmpsize);
|
||||
}
|
||||
strlcat(tmp, cp, tmpsize);
|
||||
tmpused = strlcat(tmp, " ", tmpsize);
|
||||
free(cp);
|
||||
|
||||
cp = cmd_list_print(bd->cmdlist, 1);
|
||||
cplen = strlen(cp);
|
||||
while (tmpused + cplen + 1 >= tmpsize) {
|
||||
tmpsize *= 2;
|
||||
tmp = xrealloc(tmp, tmpsize);
|
||||
}
|
||||
strlcat(tmp, cp, tmpsize);
|
||||
free(cp);
|
||||
|
||||
cmdq_print(item, "bind-key %s", tmp);
|
||||
|
||||
free(key);
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
table = key_bindings_next_table(table);
|
||||
}
|
||||
|
||||
free(tmp);
|
||||
|
||||
out:
|
||||
if (only != KEYC_UNKNOWN && !found) {
|
||||
cmdq_error(item, "unknown key: %s", args_string(args, 0));
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
const struct cmd_entry **entryp;
|
||||
const struct cmd_entry *entry;
|
||||
struct format_tree *ft;
|
||||
const char *template, *s, *command;
|
||||
char *line;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL) {
|
||||
template = "#{command_list_name}"
|
||||
"#{?command_list_alias, (#{command_list_alias}),} "
|
||||
"#{command_list_usage}";
|
||||
}
|
||||
filter_notes = notes_only && !args_has(args, 'a');
|
||||
filter_key = only != KEYC_UNKNOWN;
|
||||
if (filter_notes || filter_key)
|
||||
cmd_filter_key_list(filter_notes, filter_key, only, l, &n);
|
||||
if (single)
|
||||
n = 1;
|
||||
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
command = args_string(args, 0);
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
entry = *entryp;
|
||||
if (command != NULL &&
|
||||
(strcmp(entry->name, command) != 0 &&
|
||||
(entry->alias == NULL ||
|
||||
strcmp(entry->alias, command) != 0)))
|
||||
continue;
|
||||
|
||||
format_add(ft, "command_list_name", "%s", entry->name);
|
||||
if (entry->alias != NULL)
|
||||
s = entry->alias;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_alias", "%s", s);
|
||||
if (entry->usage != NULL)
|
||||
s = entry->usage;
|
||||
else
|
||||
s = "";
|
||||
format_add(ft, "command_list_usage", "%s", s);
|
||||
format_add(ft, "notes_only", "%d", notes_only);
|
||||
format_add(ft, "key_has_repeat", "%d", key_bindings_has_repeat(l, n));
|
||||
format_add(ft, "key_string_width", "%u", cmd_list_keys_get_width(l, n));
|
||||
format_add(ft, "key_table_width", "%u",
|
||||
cmd_list_keys_get_table_width(l, n));
|
||||
for (i = 0; i < n; i++) {
|
||||
cmd_format_add_key_binding(ft, l[i], prefix);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
if (*line != '\0')
|
||||
if ((single && tc != NULL) || n == 1)
|
||||
status_message_set(tc, -1, 1, 0, 0, "%s", line);
|
||||
else if (*line != '\0')
|
||||
cmdq_print(item, "%s", line);
|
||||
free(line);
|
||||
}
|
||||
|
||||
if (single)
|
||||
break;
|
||||
}
|
||||
format_free(ft);
|
||||
free(prefix);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,9 @@ const struct cmd_entry cmd_list_panes_entry = {
|
||||
.name = "list-panes",
|
||||
.alias = "lsp",
|
||||
|
||||
.args = { "asF:f:t:", 0, 0, NULL },
|
||||
.usage = "[-as] [-F format] [-f filter] " CMD_TARGET_WINDOW_USAGE,
|
||||
.args = { "aF:f:O:rst:", 0, 0, NULL },
|
||||
.usage = "[-asr] [-F format] [-f filter] [-O order]"
|
||||
CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -54,6 +55,13 @@ cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl;
|
||||
enum sort_order order;
|
||||
|
||||
order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_panes_server(self, item);
|
||||
@@ -89,12 +97,13 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct window_pane *wp;
|
||||
u_int n;
|
||||
struct window_pane *wp, **l;
|
||||
u_int i, n;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (template == NULL) {
|
||||
@@ -124,8 +133,12 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
}
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_panes_window(wl->window, &n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
wp = l[i];
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, wp);
|
||||
@@ -143,6 +156,5 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
.name = "list-sessions",
|
||||
.alias = "ls",
|
||||
|
||||
.args = { "F:f:", 0, 0, NULL },
|
||||
.usage = "[-F format] [-f filter]",
|
||||
.args = { "F:f:O:r", 0, 0, NULL },
|
||||
.usage = "[-r] [-F format] [-f filter] [-O order]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_sessions_exec
|
||||
@@ -52,23 +52,31 @@ const struct cmd_entry cmd_list_sessions_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session *s;
|
||||
u_int n;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct session **l;
|
||||
u_int n, i;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = LIST_SESSIONS_TEMPLATE;
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
l = sort_get_sessions(&n, &sort_crit);
|
||||
for (i = 0; i < n; i++) {
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, NULL, NULL);
|
||||
format_add(ft, "line", "%u", i);
|
||||
format_defaults(ft, NULL, l[i], NULL, NULL);
|
||||
|
||||
if (filter != NULL) {
|
||||
expanded = format_expand(ft, filter);
|
||||
@@ -83,7 +91,6 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
n++;
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -41,16 +41,13 @@
|
||||
|
||||
static enum cmd_retval cmd_list_windows_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_list_windows_server(struct cmd *, struct cmdq_item *);
|
||||
static void cmd_list_windows_session(struct cmd *, struct session *,
|
||||
struct cmdq_item *, int);
|
||||
|
||||
const struct cmd_entry cmd_list_windows_entry = {
|
||||
.name = "list-windows",
|
||||
.alias = "lsw",
|
||||
|
||||
.args = { "F:f:at:", 0, 0, NULL },
|
||||
.usage = "[-a] [-F format] [-f filter] " CMD_TARGET_SESSION_USAGE,
|
||||
.args = { "aF:f:O:rt:", 0, 0, NULL },
|
||||
.usage = "[-ar] [-F format] [-f filter] [-O order]"
|
||||
CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
@@ -63,51 +60,38 @@ cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_windows_server(self, item);
|
||||
else
|
||||
cmd_list_windows_session(self, target->s, item, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_list_windows_server(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct session *s;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
cmd_list_windows_session(self, s, item, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
struct cmdq_item *item, int type)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct winlink *wl;
|
||||
u_int n;
|
||||
struct winlink *wl, **l;
|
||||
struct session *s;
|
||||
u_int i, n;
|
||||
struct format_tree *ft;
|
||||
const char *template, *filter;
|
||||
char *line, *expanded;
|
||||
int flag;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (template == NULL) {
|
||||
switch (type) {
|
||||
case 0:
|
||||
template = LIST_WINDOWS_TEMPLATE;
|
||||
break;
|
||||
case 1:
|
||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
filter = args_get(args, 'f');
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
l = sort_get_winlinks(&n, &sort_crit);
|
||||
if (template == NULL)
|
||||
template = LIST_WINDOWS_WITH_SESSION_TEMPLATE;
|
||||
} else {
|
||||
l = sort_get_winlinks_session(target->s, &n, &sort_crit);
|
||||
if (template == NULL)
|
||||
template = LIST_WINDOWS_TEMPLATE;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
wl = l[i];
|
||||
s = wl->session;
|
||||
ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, NULL);
|
||||
@@ -125,6 +109,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
}
|
||||
|
||||
format_free(ft);
|
||||
n++;
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
return;
|
||||
|
||||
if (error != 0)
|
||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
||||
cmdq_error(item, "%s: %s", strerror(error), path);
|
||||
else if (bsize != 0) {
|
||||
copy = xmalloc(bsize);
|
||||
memcpy(copy, bdata, bsize);
|
||||
@@ -77,7 +77,7 @@ cmd_load_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
} else if (tc != NULL &&
|
||||
tc->session != NULL &&
|
||||
(~tc->flags & CLIENT_DEAD))
|
||||
tty_set_selection(&tc->tty, copy, bsize);
|
||||
tty_set_selection(&tc->tty, "", copy, bsize);
|
||||
if (tc != NULL)
|
||||
server_client_unref(tc);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_new_session_entry = {
|
||||
.usage = "[-AdDEPX] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-f flags] [-n window-name] [-s session-name] "
|
||||
CMD_TARGET_SESSION_USAGE " [-x width] [-y height] "
|
||||
"[shell-command]",
|
||||
"[shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
@@ -117,8 +117,9 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
as = target->s;
|
||||
if (as != NULL) {
|
||||
retval = cmd_attach_session(item, as->name,
|
||||
args_has(args, 'D'), args_has(args, 'X'), 0, NULL,
|
||||
args_has(args, 'E'), args_get(args, 'f'));
|
||||
args_has(args, 'D'), args_has(args, 'X'), 0,
|
||||
args_get(args, 'c'), args_has(args, 'E'),
|
||||
args_get(args, 'f'));
|
||||
free(newname);
|
||||
return (retval);
|
||||
}
|
||||
@@ -333,13 +334,6 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
server_client_set_key_table(c, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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. */
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
@@ -357,6 +351,9 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
||||
|
||||
if (cfg_finished)
|
||||
cfg_show_causes(s);
|
||||
|
||||
if (sc.argv != NULL)
|
||||
cmd_free_argv(sc.argc, sc.argv);
|
||||
free(cwd);
|
||||
|
||||
@@ -40,7 +40,8 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
|
||||
.args = { "abc:de:F:kn:PSt:", 0, -1, NULL },
|
||||
.usage = "[-abdkPS] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE
|
||||
" [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
@@ -60,7 +61,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s = target->s;
|
||||
struct winlink *wl = target->wl, *new_wl = NULL;
|
||||
int idx = target->idx, before;
|
||||
char *cause = NULL, *cp;
|
||||
char *cause = NULL, *cp, *expanded;
|
||||
const char *template, *name;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *av;
|
||||
@@ -71,16 +72,19 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
*/
|
||||
name = args_get(args, 'n');
|
||||
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) {
|
||||
if (strcmp(wl->window->name, name) != 0)
|
||||
if (strcmp(wl->window->name, expanded) != 0)
|
||||
continue;
|
||||
if (new_wl == NULL) {
|
||||
new_wl = wl;
|
||||
continue;
|
||||
}
|
||||
cmdq_error(item, "multiple windows named %s", name);
|
||||
free(expanded);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(expanded);
|
||||
if (new_wl != NULL) {
|
||||
if (args_has(args, 'd'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
79
cmd-parse.y
79
cmd-parse.y
@@ -32,7 +32,7 @@
|
||||
|
||||
static int yylex(void);
|
||||
static int yyparse(void);
|
||||
static int printflike(1,2) yyerror(const char *, ...);
|
||||
static void printflike(1,2) yyerror(const char *, ...);
|
||||
|
||||
static char *yylex_token(int);
|
||||
static char *yylex_format(void);
|
||||
@@ -223,9 +223,16 @@ assignment : EQUALS
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
int flags = ps->input->flags;
|
||||
int flag = 1;
|
||||
struct cmd_parse_scope *scope;
|
||||
|
||||
if ((~flags & CMD_PARSE_PARSEONLY) &&
|
||||
(ps->scope == NULL || ps->scope->flag))
|
||||
if (ps->scope != NULL) {
|
||||
flag = ps->scope->flag;
|
||||
TAILQ_FOREACH(scope, &ps->stack, entry)
|
||||
flag = flag && scope->flag;
|
||||
}
|
||||
|
||||
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
|
||||
environ_put(global_environ, $1, 0);
|
||||
free($1);
|
||||
}
|
||||
@@ -234,9 +241,16 @@ hidden_assignment : HIDDEN EQUALS
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
int flags = ps->input->flags;
|
||||
int flag = 1;
|
||||
struct cmd_parse_scope *scope;
|
||||
|
||||
if ((~flags & CMD_PARSE_PARSEONLY) &&
|
||||
(ps->scope == NULL || ps->scope->flag))
|
||||
if (ps->scope != NULL) {
|
||||
flag = ps->scope->flag;
|
||||
TAILQ_FOREACH(scope, &ps->stack, entry)
|
||||
flag = flag && scope->flag;
|
||||
}
|
||||
|
||||
if ((~flags & CMD_PARSE_PARSEONLY) && flag)
|
||||
environ_put(global_environ, $2, ENVIRON_HIDDEN);
|
||||
free($2);
|
||||
}
|
||||
@@ -744,7 +758,7 @@ 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_argument *first;
|
||||
struct cmd_parse_commands *cmds;
|
||||
struct cmd_parse_command *last;
|
||||
char *alias, *name, *cause;
|
||||
@@ -784,10 +798,7 @@ cmd_parse_expand_alias(struct cmd_parse_command *cmd,
|
||||
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);
|
||||
}
|
||||
TAILQ_CONCAT(&last->arguments, &cmd->arguments, entry);
|
||||
cmd_parse_log_commands(cmds, __func__);
|
||||
|
||||
pi->flags |= CMD_PARSE_NOALIAS;
|
||||
@@ -835,7 +846,7 @@ cmd_parse_build_command(struct cmd_parse_command *cmd,
|
||||
count++;
|
||||
}
|
||||
|
||||
add = cmd_parse(values, count, pi->file, pi->line, &cause);
|
||||
add = cmd_parse(values, count, pi->file, pi->line, pi->flags, &cause);
|
||||
if (add == NULL) {
|
||||
pr->status = CMD_PARSE_ERROR;
|
||||
pr->error = cmd_parse_get_error(pi->file, pi->line, cause);
|
||||
@@ -1086,7 +1097,8 @@ cmd_parse_from_arguments(struct args_value *values, u_int count,
|
||||
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;
|
||||
@@ -1112,7 +1124,7 @@ cmd_parse_from_arguments(struct args_value *values, u_int count,
|
||||
return (&pr);
|
||||
}
|
||||
|
||||
static int printflike(1, 2)
|
||||
static void printflike(1, 2)
|
||||
yyerror(const char *fmt, ...)
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
@@ -1121,7 +1133,7 @@ yyerror(const char *fmt, ...)
|
||||
char *error;
|
||||
|
||||
if (ps->error != NULL)
|
||||
return (0);
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&error, fmt, ap);
|
||||
@@ -1129,7 +1141,6 @@ yyerror(const char *fmt, ...)
|
||||
|
||||
ps->error = cmd_parse_get_error(pi->file, pi->line, error);
|
||||
free(error);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -1272,6 +1283,16 @@ yylex(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == '\r') {
|
||||
/*
|
||||
* Treat \r\n as \n.
|
||||
*/
|
||||
ch = yylex_getc();
|
||||
if (ch != '\n') {
|
||||
yylex_ungetc(ch);
|
||||
ch = '\r';
|
||||
}
|
||||
}
|
||||
if (ch == '\n') {
|
||||
/*
|
||||
* End of line. Update the line number.
|
||||
@@ -1602,6 +1623,7 @@ yylex_token_tilde(char **buf, size_t *len)
|
||||
static char *
|
||||
yylex_token(int ch)
|
||||
{
|
||||
struct cmd_parse_state *ps = &parse_state;
|
||||
char *buf;
|
||||
size_t len;
|
||||
enum { START,
|
||||
@@ -1614,13 +1636,34 @@ yylex_token(int ch)
|
||||
|
||||
for (;;) {
|
||||
/* 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;
|
||||
}
|
||||
if (state == NONE && ch == '\r') {
|
||||
ch = yylex_getc();
|
||||
if (ch != '\n') {
|
||||
yylex_ungetc(ch);
|
||||
ch = '\r';
|
||||
}
|
||||
}
|
||||
if (ch == '\n') {
|
||||
if (state == NONE) {
|
||||
log_debug("%s: end at EOL", __func__);
|
||||
break;
|
||||
}
|
||||
ps->input->line++;
|
||||
}
|
||||
|
||||
/* Whitespace or ; or } ends a token unless inside quotes. */
|
||||
if ((ch == ' ' || ch == '\t' || ch == ';' || ch == '}') &&
|
||||
state == NONE)
|
||||
if (state == NONE && (ch == ' ' || ch == '\t')) {
|
||||
log_debug("%s: end at WS", __func__);
|
||||
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
|
||||
|
||||
@@ -33,8 +33,8 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.name = "paste-buffer",
|
||||
.alias = "pasteb",
|
||||
|
||||
.args = { "db:prs:t:", 0, 0, NULL },
|
||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
||||
.args = { "db:prSs:t:", 0, 0, NULL },
|
||||
.usage = "[-dprS] [-s separator] " CMD_BUFFER_USAGE " "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -43,6 +43,17 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.exec = cmd_paste_buffer_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_paste_buffer_paste(struct window_pane *wp, const char *buf, size_t len)
|
||||
{
|
||||
char *cp;
|
||||
size_t n;
|
||||
|
||||
n = utf8_stravisx(&cp, buf, len, VIS_SAFE|VIS_NOSLASH);
|
||||
bufferevent_write(wp->event, cp, n);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -51,9 +62,14 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window_pane *wp = target->wp;
|
||||
struct paste_buffer *pb;
|
||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
||||
size_t seplen, bufsize;
|
||||
size_t seplen, bufsize, len;
|
||||
int bracket = args_has(args, 'p');
|
||||
|
||||
if (window_pane_exited(wp)) {
|
||||
cmdq_error(item, "target pane has exited");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
bufname = NULL;
|
||||
if (args_has(args, 'b'))
|
||||
bufname = args_get(args, 'b');
|
||||
@@ -88,14 +104,22 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
line = memchr(bufdata, '\n', bufend - bufdata);
|
||||
if (line == NULL)
|
||||
break;
|
||||
|
||||
bufferevent_write(wp->event, bufdata, line - bufdata);
|
||||
len = line - bufdata;
|
||||
if (args_has(args, 'S'))
|
||||
bufferevent_write(wp->event, bufdata, len);
|
||||
else
|
||||
cmd_paste_buffer_paste(wp, bufdata, len);
|
||||
bufferevent_write(wp->event, sepstr, seplen);
|
||||
|
||||
bufdata = line + 1;
|
||||
}
|
||||
if (bufdata != bufend)
|
||||
bufferevent_write(wp->event, bufdata, bufend - bufdata);
|
||||
if (bufdata != bufend) {
|
||||
len = bufend - bufdata;
|
||||
if (args_has(args, 'S'))
|
||||
bufferevent_write(wp->event, bufdata, len);
|
||||
else
|
||||
cmd_paste_buffer_paste(wp, bufdata, len);
|
||||
}
|
||||
|
||||
if (bracket && (wp->screen->mode & MODE_BRACKETPASTE))
|
||||
bufferevent_write(wp->event, "\033[201~", 6);
|
||||
|
||||
@@ -68,7 +68,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
sigset_t set, oldset;
|
||||
|
||||
/* Do nothing if pane is dead. */
|
||||
if (wp->fd == -1 || (wp->flags & PANE_EXITED)) {
|
||||
if (window_pane_exited(wp)) {
|
||||
cmdq_error(item, "target pane has exited");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
/* Fork the child. */
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
switch (fork()) {
|
||||
switch ((wp->pipe_pid = fork())) {
|
||||
case -1:
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
||||
@@ -136,6 +136,9 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[0]);
|
||||
|
||||
if (setpgid(0, 0) == -1)
|
||||
_exit(1);
|
||||
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY);
|
||||
if (out) {
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||
|
||||
74
cmd-queue.c
74
cmd-queue.c
@@ -236,8 +236,10 @@ cmdq_link_state(struct cmdq_state *state)
|
||||
|
||||
/* Make a copy of a 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));
|
||||
}
|
||||
|
||||
@@ -662,9 +664,18 @@ cmdq_fire_command(struct cmdq_item *item)
|
||||
|
||||
out:
|
||||
item->client = saved;
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
if (retval == CMD_RETURN_ERROR) {
|
||||
fsp = NULL;
|
||||
if (cmd_find_valid_state(&item->target))
|
||||
fsp = &item->target;
|
||||
else if (cmd_find_valid_state(&item->state->current))
|
||||
fsp = &item->state->current;
|
||||
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
|
||||
fsp = &fs;
|
||||
cmdq_insert_hook(fsp != NULL ? fsp->s : NULL, item, fsp,
|
||||
"command-error");
|
||||
cmdq_guard(item, "error", flags);
|
||||
else
|
||||
} else
|
||||
cmdq_guard(item, "end", flags);
|
||||
return (retval);
|
||||
}
|
||||
@@ -803,10 +814,10 @@ cmdq_running(struct client *c)
|
||||
struct cmdq_list *queue = cmdq_get(c);
|
||||
|
||||
if (queue->item == NULL)
|
||||
return (NULL);
|
||||
if (queue->item->flags & CMDQ_WAITING)
|
||||
return (NULL);
|
||||
return (queue->item);
|
||||
return (NULL);
|
||||
if (queue->item->flags & CMDQ_WAITING)
|
||||
return (NULL);
|
||||
return (queue->item);
|
||||
}
|
||||
|
||||
/* Print a guard line. */
|
||||
@@ -821,45 +832,30 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
||||
control_write(c, "%%%s %ld %u %d", guard, t, number, flags);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print_data(struct cmdq_item *item, struct evbuffer *evb)
|
||||
{
|
||||
server_client_print(item->client, 1, evb);
|
||||
}
|
||||
|
||||
/* Show message from command. */
|
||||
void
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
va_list ap;
|
||||
char *tmp, *msg;
|
||||
va_list ap;
|
||||
struct evbuffer *evb;
|
||||
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&msg, fmt, ap);
|
||||
evbuffer_add_vprintf(evb, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
log_debug("%s: %s", __func__, msg);
|
||||
|
||||
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, 0, "%s", msg);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
cmdq_print_data(item, evb);
|
||||
evbuffer_free(evb);
|
||||
}
|
||||
|
||||
/* Show error from command. */
|
||||
@@ -896,7 +892,7 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
|
||||
c->retval = 1;
|
||||
} else {
|
||||
*msg = toupper((u_char) *msg);
|
||||
status_message_set(c, -1, 1, 0, "%s", msg);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", msg);
|
||||
}
|
||||
|
||||
free(msg);
|
||||
|
||||
@@ -34,9 +34,10 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.name = "refresh-client",
|
||||
.alias = "refresh",
|
||||
|
||||
.args = { "A:B:cC:Df:F:l::LRSt:U", 0, 1, NULL },
|
||||
.args = { "A:B:cC:Df:r:F:lLRSt:U", 0, 1, NULL },
|
||||
.usage = "[-cDlLRSU] [-A pane:state] [-B name:what:format] "
|
||||
"[-C XxY] [-f flags] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
||||
"[-C XxY] [-f flags] [-r pane:report] " CMD_TARGET_CLIENT_USAGE
|
||||
" [adjustment]",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
.exec = cmd_refresh_client_exec
|
||||
@@ -162,35 +163,32 @@ out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_refresh_client_clipboard(struct cmd *self, struct cmdq_item *item)
|
||||
static void
|
||||
cmd_refresh_report(struct tty *tty, const char *value)
|
||||
{
|
||||
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;
|
||||
struct window_pane *wp;
|
||||
u_int pane;
|
||||
size_t size = 0;
|
||||
char *copy, *split;
|
||||
|
||||
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);
|
||||
if (*value != '%')
|
||||
return;
|
||||
copy = xstrdup(value);
|
||||
if ((split = strchr(copy, ':')) == NULL)
|
||||
goto out;
|
||||
*split++ = '\0';
|
||||
|
||||
if (sscanf(copy, "%%%u", &pane) != 1)
|
||||
goto out;
|
||||
wp = window_pane_find_by_id(pane);
|
||||
if (wp == NULL)
|
||||
goto out;
|
||||
|
||||
tty_keys_colours(tty, split, strlen(split), &size, &wp->control_fg,
|
||||
&wp->control_bg);
|
||||
|
||||
out:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -255,13 +253,17 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'l'))
|
||||
return (cmd_refresh_client_clipboard(self, item));
|
||||
if (args_has(args, 'l')) {
|
||||
tty_clipboard_query(&tc->tty);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'F')) /* -F is an alias for -f */
|
||||
server_client_set_flags(tc, args_get(args, 'F'));
|
||||
if (args_has(args, 'f'))
|
||||
server_client_set_flags(tc, args_get(args, 'f'));
|
||||
if (args_has(args, 'r'))
|
||||
cmd_refresh_report(tty, args_get(args, 'r'));
|
||||
|
||||
if (args_has(args, 'A')) {
|
||||
if (~tc->flags & CLIENT_CONTROL)
|
||||
|
||||
@@ -87,7 +87,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (args_has(args, 'Z')) {
|
||||
if (w->flags & WINDOW_ZOOMED)
|
||||
window_unzoom(w);
|
||||
window_unzoom(w, 1);
|
||||
else
|
||||
window_zoom(wp);
|
||||
server_redraw_window(w);
|
||||
|
||||
@@ -53,8 +53,7 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s = target->s;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust, sx, sy;
|
||||
int xpixel = -1, ypixel = -1;
|
||||
u_int adjust, sx, sy, xpixel = 0, ypixel = 0;
|
||||
|
||||
if (args_count(args) == 0)
|
||||
adjust = 1;
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
|
||||
.args = { "c:e:kt:", 0, -1, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
CMD_TARGET_PANE_USAGE " [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
|
||||
.args = { "c:e:kt:", 0, -1, NULL },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_WINDOW_USAGE " [shell-command]",
|
||||
CMD_TARGET_WINDOW_USAGE " [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
|
||||
@@ -44,8 +44,9 @@ const struct cmd_entry cmd_run_shell_entry = {
|
||||
.name = "run-shell",
|
||||
.alias = "run",
|
||||
|
||||
.args = { "bd:Ct:", 0, 1, cmd_run_shell_args_parse },
|
||||
.usage = "[-bC] [-d delay] " CMD_TARGET_PANE_USAGE " [shell-command]",
|
||||
.args = { "bd:Ct:Es:c:", 0, 1, cmd_run_shell_args_parse },
|
||||
.usage = "[-bCE] [-c start-directory] [-d delay] " CMD_TARGET_PANE_USAGE
|
||||
" [shell-command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
@@ -84,12 +85,18 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
|
||||
if (cdata->wp_id != -1)
|
||||
wp = window_pane_find_by_id(cdata->wp_id);
|
||||
if (wp == NULL && cdata->item != NULL)
|
||||
wp = server_client_get_pane(cdata->client);
|
||||
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
|
||||
wp = fs.wp;
|
||||
if (wp == NULL)
|
||||
return;
|
||||
if (wp == NULL) {
|
||||
if (cdata->item != NULL) {
|
||||
cmdq_print(cdata->item, "%s", msg);
|
||||
return;
|
||||
}
|
||||
if (cdata->item != NULL && cdata->client != NULL)
|
||||
wp = server_client_get_pane(cdata->client);
|
||||
if (wp == NULL && cmd_find_from_nothing(&fs, 0) == 0)
|
||||
wp = fs.wp;
|
||||
if (wp == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
@@ -103,6 +110,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
struct cmd_run_shell_data *cdata;
|
||||
struct client *c = cmdq_get_client(item);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct session *s = target->s;
|
||||
struct window_pane *wp = target->wp;
|
||||
@@ -137,7 +145,7 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->wp_id = -1;
|
||||
|
||||
if (wait) {
|
||||
cdata->client = cmdq_get_client(item);
|
||||
cdata->client = c;
|
||||
cdata->item = item;
|
||||
} else {
|
||||
cdata->client = tc;
|
||||
@@ -145,8 +153,13 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
if (cdata->client != NULL)
|
||||
cdata->client->references++;
|
||||
if (args_has(args, 'c'))
|
||||
cdata->cwd = xstrdup(args_get(args, 'c'));
|
||||
else
|
||||
cdata->cwd = xstrdup(server_client_get_cwd(c, s));
|
||||
|
||||
cdata->cwd = xstrdup(server_client_get_cwd(cmdq_get_client(item), s));
|
||||
if (args_has(args, 'E'))
|
||||
cdata->flags |= JOB_SHOWSTDERR;
|
||||
|
||||
cdata->s = s;
|
||||
if (s != NULL)
|
||||
@@ -194,7 +207,7 @@ cmd_run_shell_timer(__unused int fd, __unused short events, void* arg)
|
||||
if (cmdlist == NULL) {
|
||||
if (cdata->item == NULL) {
|
||||
*error = toupper((u_char)*error);
|
||||
status_message_set(c, -1, 1, 0, "%s", error);
|
||||
status_message_set(c, -1, 1, 0, 0, "%s", error);
|
||||
} else
|
||||
cmdq_error(cdata->item, "%s", error);
|
||||
free(error);
|
||||
|
||||
@@ -65,7 +65,7 @@ cmd_save_buffer_done(__unused struct client *c, const char *path, int error,
|
||||
return;
|
||||
|
||||
if (error != 0)
|
||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
||||
cmdq_error(item, "%s: %s", strerror(error), path);
|
||||
cmdq_continue(item);
|
||||
}
|
||||
|
||||
@@ -78,7 +78,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int flags;
|
||||
const char *bufname = args_get(args, 'b'), *bufdata;
|
||||
size_t bufsize;
|
||||
char *path, *tmp;
|
||||
char *path;
|
||||
struct evbuffer *evb;
|
||||
|
||||
if (bufname == NULL) {
|
||||
if ((pb = paste_get_top(NULL)) == NULL) {
|
||||
@@ -96,10 +97,12 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (cmd_get_entry(self) == &cmd_show_buffer_entry) {
|
||||
if (c->session != NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
utf8_stravisx(&tmp, bufdata, bufsize,
|
||||
VIS_OCTAL|VIS_CSTYLE|VIS_TAB);
|
||||
cmdq_print(item, "%s", tmp);
|
||||
free(tmp);
|
||||
evb = evbuffer_new();
|
||||
if (evb == NULL)
|
||||
fatalx("out of memory");
|
||||
evbuffer_add(evb, bufdata, bufsize);
|
||||
cmdq_print_data(item, evb);
|
||||
evbuffer_free(evb);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
path = xstrdup("-");
|
||||
|
||||
@@ -98,7 +98,11 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct options_entry *o;
|
||||
|
||||
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) {
|
||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
||||
if (lastwp == NULL)
|
||||
@@ -145,12 +149,14 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
markedwp = marked_pane.wp;
|
||||
|
||||
if (lastwp != NULL) {
|
||||
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
lastwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|
|
||||
PANE_THEMECHANGED);
|
||||
server_redraw_window_borders(lastwp->window);
|
||||
server_status_window(lastwp->window);
|
||||
}
|
||||
if (markedwp != NULL) {
|
||||
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
markedwp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|
|
||||
PANE_THEMECHANGED);
|
||||
server_redraw_window_borders(markedwp->window);
|
||||
server_status_window(markedwp->window);
|
||||
}
|
||||
@@ -165,7 +171,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
options_set_string(oo, "window-active-style", 0, "%s", style);
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED);
|
||||
wp->flags |= (PANE_REDRAW|PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
}
|
||||
if (args_has(args, 'g')) {
|
||||
cmdq_print(item, "%s", options_get_string(oo, "window-style"));
|
||||
|
||||
@@ -33,13 +33,14 @@ const struct cmd_entry cmd_send_keys_entry = {
|
||||
.name = "send-keys",
|
||||
.alias = "send",
|
||||
|
||||
.args = { "FHlMN:Rt:X", 0, -1, NULL },
|
||||
.usage = "[-FHlMRX] [-N repeat-count] " CMD_TARGET_PANE_USAGE
|
||||
" key ...",
|
||||
.args = { "c:FHKlMN:Rt:X", 0, -1, NULL },
|
||||
.usage = "[-FHKlMRX] [-c target-client] [-N repeat-count] "
|
||||
CMD_TARGET_PANE_USAGE " [key ...]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_CFLAG|CMD_CLIENT_CANFAIL|
|
||||
CMD_READONLY,
|
||||
.exec = cmd_send_keys_exec
|
||||
};
|
||||
|
||||
@@ -58,7 +59,7 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
||||
|
||||
static struct cmdq_item *
|
||||
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 client *tc = cmdq_get_target_client(item);
|
||||
@@ -66,8 +67,22 @@ cmd_send_keys_inject_key(struct cmdq_item *item, struct cmdq_item *after,
|
||||
struct winlink *wl = target->wl;
|
||||
struct window_pane *wp = target->wp;
|
||||
struct window_mode_entry *wme;
|
||||
struct key_table *table;
|
||||
struct key_table *table = NULL;
|
||||
struct key_binding *bd;
|
||||
struct key_event *event;
|
||||
|
||||
if (args_has(args, 'K')) {
|
||||
if (tc == NULL)
|
||||
return (item);
|
||||
event = xcalloc(1, sizeof *event);
|
||||
event->key = key|KEYC_SENT;
|
||||
memset(&event->m, 0, sizeof event->m);
|
||||
if (server_client_handle_key(tc, event) == 0) {
|
||||
free(event->buf);
|
||||
free(event);
|
||||
}
|
||||
return (item);
|
||||
}
|
||||
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode->key_table == NULL) {
|
||||
@@ -102,14 +117,16 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
||||
n = strtol(s, &endptr, 16);
|
||||
if (*s =='\0' || n < 0 || n > 0xff || *endptr != '\0')
|
||||
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');
|
||||
if (!literal) {
|
||||
key = key_string_lookup_string(s);
|
||||
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)
|
||||
return (after);
|
||||
}
|
||||
@@ -125,7 +142,8 @@ cmd_send_keys_inject_string(struct cmdq_item *item, struct cmdq_item *after,
|
||||
continue;
|
||||
key = uc;
|
||||
}
|
||||
after = cmd_send_keys_inject_key(item, after, key);
|
||||
after = cmd_send_keys_inject_key(item, after, args,
|
||||
key);
|
||||
}
|
||||
free(ud);
|
||||
}
|
||||
@@ -150,8 +168,14 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
u_int count = args_count(args);
|
||||
char *cause = NULL;
|
||||
|
||||
if (tc != NULL && tc->flags & CLIENT_READONLY && !args_has(args, 'X')) {
|
||||
cmdq_error(item, "client is read-only");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
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) {
|
||||
cmdq_error(item, "repeat count %s", cause);
|
||||
free(cause);
|
||||
@@ -192,21 +216,21 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
key = options_get_number(s->options, "prefix2");
|
||||
else
|
||||
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);
|
||||
}
|
||||
|
||||
if (args_has(args, 'R')) {
|
||||
colour_palette_clear(&wp->palette);
|
||||
input_reset(wp->ictx, 1);
|
||||
wp->flags |= (PANE_STYLECHANGED|PANE_REDRAW);
|
||||
wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED|PANE_REDRAW);
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
if (args_has(args, 'N') || args_has(args, 'R'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
for (; np != 0; np--)
|
||||
cmd_send_keys_inject_key(item, NULL, event->key);
|
||||
cmd_send_keys_inject_key(item, NULL, args, event->key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@ cmd_server_access_exec(struct cmd *self, struct cmdq_item *item)
|
||||
pw = getpwnam(name);
|
||||
if (pw == NULL) {
|
||||
cmdq_error(item, "unknown user: %s", name);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(name);
|
||||
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_set_buffer_entry = {
|
||||
|
||||
.args = { "ab:t:n:w", 0, 1, NULL },
|
||||
.usage = "[-aw] " CMD_BUFFER_USAGE " [-n new-buffer-name] "
|
||||
CMD_TARGET_CLIENT_USAGE " data",
|
||||
CMD_TARGET_CLIENT_USAGE " [data]",
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
||||
.exec = cmd_set_buffer_exec
|
||||
@@ -57,53 +57,59 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = cmd_get_args(self);
|
||||
struct client *tc = cmdq_get_target_client(item);
|
||||
struct paste_buffer *pb;
|
||||
char *bufdata, *cause;
|
||||
const char *bufname, *olddata;
|
||||
size_t bufsize, newsize;
|
||||
struct paste_buffer *pb = NULL;
|
||||
char *bufname = NULL, *bufdata = NULL, *cause = NULL;
|
||||
const char *olddata;
|
||||
size_t bufsize = 0, newsize;
|
||||
|
||||
bufname = args_get(args, 'b');
|
||||
if (bufname == NULL)
|
||||
pb = NULL;
|
||||
else
|
||||
if (args_get(args, 'b') != NULL) {
|
||||
bufname = xstrdup(args_get(args, 'b'));
|
||||
pb = paste_get_name(bufname);
|
||||
}
|
||||
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
pb = paste_get_top(&bufname);
|
||||
}
|
||||
if (pb == NULL) {
|
||||
cmdq_error(item, "no buffer");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
paste_free(pb);
|
||||
free(bufname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'n')) {
|
||||
if (pb == NULL)
|
||||
if (pb == NULL) {
|
||||
if (bufname != NULL) {
|
||||
cmdq_error(item, "unknown buffer: %s", bufname);
|
||||
goto fail;
|
||||
}
|
||||
pb = paste_get_top(&bufname);
|
||||
}
|
||||
if (pb == NULL) {
|
||||
cmdq_error(item, "no buffer");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
if (paste_rename(bufname, args_get(args, 'n'), &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_count(args) != 1) {
|
||||
cmdq_error(item, "no data specified");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
if ((newsize = strlen(args_string(args, 0))) == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
bufsize = 0;
|
||||
bufdata = NULL;
|
||||
|
||||
if (args_has(args, 'a') && pb != NULL) {
|
||||
olddata = paste_buffer_data(pb, &bufsize);
|
||||
bufdata = xmalloc(bufsize);
|
||||
@@ -116,12 +122,16 @@ cmd_set_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (paste_set(bufdata, bufsize, bufname, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(bufdata);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
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);
|
||||
|
||||
fail:
|
||||
free(bufdata);
|
||||
free(bufname);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
.alias = "setenv",
|
||||
|
||||
.args = { "Fhgrt:u", 1, 2, NULL },
|
||||
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||
.usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " variable [value]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_show_environment_entry = {
|
||||
.alias = "showenv",
|
||||
|
||||
.args = { "hgst:", 0, 1, NULL },
|
||||
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]",
|
||||
.usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [variable]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_messages_entry = {
|
||||
.args = { "JTt:", 0, 0, NULL },
|
||||
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG,
|
||||
.flags = CMD_AFTERHOOK|CMD_CLIENT_TFLAG|CMD_CLIENT_CANFAIL,
|
||||
.exec = cmd_show_messages_exec
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ cmd_show_messages_terminals(struct cmd *self, struct cmdq_item *item, int blank)
|
||||
|
||||
n = 0;
|
||||
LIST_FOREACH(term, &tty_terms, entry) {
|
||||
if (args_has(args, 't') && term != tc->tty.term)
|
||||
if (args_has(args, 't') && tc != NULL && term != tc->tty.term)
|
||||
continue;
|
||||
if (blank) {
|
||||
cmdq_print(item, "%s", "");
|
||||
|
||||
@@ -65,7 +65,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "gpt:w", 0, 1, NULL },
|
||||
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE,
|
||||
.usage = "[-gpw] " CMD_TARGET_PANE_USAGE " [hook]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_show_prompt_history_entry = {
|
||||
.alias = "showphist",
|
||||
|
||||
.args = { "T:", 0, 0, NULL },
|
||||
.usage = "[-T type]",
|
||||
.usage = "[-T prompt-type]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_prompt_history_exec
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_clear_prompt_history_entry = {
|
||||
.alias = "clearphist",
|
||||
|
||||
.args = { "T:", 0, 0, NULL },
|
||||
.usage = "[-T type]",
|
||||
.usage = "[-T prompt-type]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_prompt_history_exec
|
||||
@@ -60,6 +60,9 @@ cmd_show_prompt_history_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (cmd_get_entry(self) == &cmd_clear_prompt_history_entry) {
|
||||
if (typestr == NULL) {
|
||||
for (tidx = 0; tidx < PROMPT_NTYPES; tidx++) {
|
||||
for (hidx = 0; hidx < status_prompt_hsize[tidx];
|
||||
hidx++)
|
||||
free(status_prompt_hlist[tidx][hidx]);
|
||||
free(status_prompt_hlist[tidx]);
|
||||
status_prompt_hlist[tidx] = NULL;
|
||||
status_prompt_hsize[tidx] = 0;
|
||||
@@ -70,6 +73,8 @@ cmd_show_prompt_history_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "invalid type: %s", typestr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
for (hidx = 0; hidx < status_prompt_hsize[type]; hidx++)
|
||||
free(status_prompt_hlist[type][hidx]);
|
||||
free(status_prompt_hlist[type]);
|
||||
status_prompt_hlist[type] = NULL;
|
||||
status_prompt_hsize[type] = 0;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <glob.h>
|
||||
#include <stdlib.h>
|
||||
@@ -29,14 +30,19 @@
|
||||
* Sources a configuration file.
|
||||
*/
|
||||
|
||||
#define CMD_SOURCE_FILE_DEPTH_LIMIT 50
|
||||
static u_int cmd_source_file_depth;
|
||||
|
||||
static enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_source_file_entry = {
|
||||
.name = "source-file",
|
||||
.alias = "source",
|
||||
|
||||
.args = { "Fnqv", 1, -1, NULL },
|
||||
.usage = "[-Fnqv] path ...",
|
||||
.args = { "t:Fnqv", 1, -1, NULL },
|
||||
.usage = "[-Fnqv] " CMD_TARGET_PANE_USAGE " path ...",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_source_file_exec
|
||||
@@ -57,6 +63,16 @@ struct cmd_source_file_data {
|
||||
static enum cmd_retval
|
||||
cmd_source_file_complete_cb(struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
struct client *c = cmdq_get_client(item);
|
||||
|
||||
if (c == NULL) {
|
||||
cmd_source_file_depth--;
|
||||
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
|
||||
} else {
|
||||
c->source_file_depth--;
|
||||
log_debug("%s: depth now %u", __func__, c->source_file_depth);
|
||||
}
|
||||
|
||||
cfg_print_causes(item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -92,15 +108,16 @@ cmd_source_file_done(struct client *c, const char *path, int error,
|
||||
size_t bsize = EVBUFFER_LENGTH(buffer);
|
||||
u_int n;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmd_find_state *target = cmdq_get_target(item);
|
||||
|
||||
if (!closed)
|
||||
return;
|
||||
|
||||
if (error != 0)
|
||||
cmdq_error(item, "%s: %s", path, strerror(error));
|
||||
cmdq_error(item, "%s: %s", strerror(error), path);
|
||||
else if (bsize != 0) {
|
||||
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;
|
||||
else if (new_item != NULL)
|
||||
cdata->after = new_item;
|
||||
@@ -124,6 +141,21 @@ cmd_source_file_add(struct cmd_source_file_data *cdata, const char *path)
|
||||
cdata->files[cdata->nfiles++] = xstrdup(path);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_source_file_quote_for_glob(const char *path)
|
||||
{
|
||||
char *quoted = xmalloc(2 * strlen(path) + 1), *q = quoted;
|
||||
const char *p = path;
|
||||
|
||||
while (*p != '\0') {
|
||||
if ((u_char)*p < 128 && !isalnum((u_char)*p) && *p != '/')
|
||||
*q++ = '\\';
|
||||
*q++ = *p++;
|
||||
}
|
||||
*q = '\0';
|
||||
return (quoted);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -134,9 +166,25 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
char *pattern, *cwd, *expanded = NULL;
|
||||
const char *path, *error;
|
||||
glob_t g;
|
||||
int result;
|
||||
int result, parse_flags;
|
||||
u_int i, j;
|
||||
|
||||
if (c == NULL) {
|
||||
if (cmd_source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
|
||||
cmdq_error(item, "too many nested files");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmd_source_file_depth++;
|
||||
log_debug("%s: depth now %u", __func__, cmd_source_file_depth);
|
||||
} else {
|
||||
if (c->source_file_depth >= CMD_SOURCE_FILE_DEPTH_LIMIT) {
|
||||
cmdq_error(item, "too many nested files");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
c->source_file_depth++;
|
||||
log_debug("%s: depth now %u", __func__, c->source_file_depth);
|
||||
}
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->item = item;
|
||||
|
||||
@@ -144,10 +192,13 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->flags |= CMD_PARSE_QUIET;
|
||||
if (args_has(args, 'n'))
|
||||
cdata->flags |= CMD_PARSE_PARSEONLY;
|
||||
if (args_has(args, 'v'))
|
||||
cdata->flags |= CMD_PARSE_VERBOSE;
|
||||
if (c == NULL || ~c->flags & CLIENT_CONTROL) {
|
||||
parse_flags = cmd_get_parse_flags(self);
|
||||
if (args_has(args, 'v') || (parse_flags & CMD_PARSE_VERBOSE))
|
||||
cdata->flags |= CMD_PARSE_VERBOSE;
|
||||
}
|
||||
|
||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||
cwd = cmd_source_file_quote_for_glob(server_client_get_cwd(c, NULL));
|
||||
|
||||
for (i = 0; i < args_count(args); i++) {
|
||||
path = args_string(args, i);
|
||||
@@ -176,7 +227,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
error = strerror(ENOMEM);
|
||||
else
|
||||
error = strerror(EINVAL);
|
||||
cmdq_error(item, "%s: %s", path, error);
|
||||
cmdq_error(item, "%s: %s", error, path);
|
||||
retval = CMD_RETURN_ERROR;
|
||||
}
|
||||
globfree(&g);
|
||||
|
||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
.args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1, NULL },
|
||||
.usage = "[-bdefhIPvZ] [-c start-directory] [-e environment] "
|
||||
"[-F format] [-l size] " CMD_TARGET_PANE_USAGE
|
||||
"[shell-command]",
|
||||
" [shell-command [argument ...]]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -65,67 +65,46 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
struct cmd_find_state fs;
|
||||
int size, percentage, flags, input;
|
||||
const char *template, *errstr, *p;
|
||||
char *cause, *cp, *copy;
|
||||
size_t plen;
|
||||
int size, flags, input;
|
||||
const char *template;
|
||||
char *cause = NULL, *cp;
|
||||
struct args_value *av;
|
||||
u_int count = args_count(args);
|
||||
u_int count = args_count(args), curval = 0;
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
else
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if ((p = args_get(args, 'l')) != NULL) {
|
||||
plen = strlen(p);
|
||||
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 (args_has(args, 'f')) {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (w->sy * percentage) / 100;
|
||||
else
|
||||
size = (w->sx * percentage) / 100;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
}
|
||||
} else {
|
||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "lines %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "create pane failed: -p %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
size = (w->sy * percentage) / 100;
|
||||
curval = w->sy;
|
||||
else
|
||||
size = (w->sx * percentage) / 100;
|
||||
curval = w->sx;
|
||||
} else {
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
curval = wp->sy;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
curval = wp->sx;
|
||||
}
|
||||
} else
|
||||
size = -1;
|
||||
}
|
||||
|
||||
size = -1;
|
||||
if (args_has(args, 'l')) {
|
||||
size = args_percentage_and_expand(args, 'l', 0, INT_MAX, curval,
|
||||
item, &cause);
|
||||
} else if (args_has(args, 'p')) {
|
||||
size = args_strtonum_and_expand(args, 'p', 0, 100, item,
|
||||
&cause);
|
||||
if (cause == NULL)
|
||||
size = curval * size / 100;
|
||||
}
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "size %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
window_push_zoom(wp->window, 1, args_has(args, 'Z'));
|
||||
input = (args_has(args, 'I') && count == 0);
|
||||
|
||||
@@ -101,10 +101,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
src_wp->window = dst_w;
|
||||
options_set_parent(src_wp->options, dst_w->options);
|
||||
src_wp->flags |= PANE_STYLECHANGED;
|
||||
src_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
dst_wp->window = src_w;
|
||||
options_set_parent(dst_wp->options, src_w->options);
|
||||
dst_wp->flags |= PANE_STYLECHANGED;
|
||||
dst_wp->flags |= (PANE_STYLECHANGED|PANE_THEMECHANGED);
|
||||
|
||||
sx = src_wp->sx; sy = src_wp->sy;
|
||||
xoff = src_wp->xoff; yoff = src_wp->yoff;
|
||||
@@ -128,13 +128,16 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
window_set_active_pane(dst_w, src_wp, 1);
|
||||
}
|
||||
if (src_w != dst_w) {
|
||||
if (src_w->last == src_wp)
|
||||
src_w->last = NULL;
|
||||
if (dst_w->last == dst_wp)
|
||||
dst_w->last = NULL;
|
||||
window_pane_stack_remove(&src_w->last_panes, src_wp);
|
||||
window_pane_stack_remove(&dst_w->last_panes, dst_wp);
|
||||
colour_palette_from_option(&src_wp->palette, src_wp->options);
|
||||
colour_palette_from_option(&dst_wp->palette, dst_wp->options);
|
||||
layout_fix_panes(src_w, NULL);
|
||||
server_redraw_window(src_w);
|
||||
}
|
||||
server_redraw_window(src_w);
|
||||
layout_fix_panes(dst_w, NULL);
|
||||
server_redraw_window(dst_w);
|
||||
|
||||
notify_window("window-layout-changed", src_w);
|
||||
if (src_w != dst_w)
|
||||
notify_window("window-layout-changed", dst_w);
|
||||
|
||||
@@ -77,6 +77,8 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
wl_src->window = w_dst;
|
||||
TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry);
|
||||
|
||||
if (marked_pane.wl == wl_src)
|
||||
marked_pane.wl = wl_dst;
|
||||
if (args_has(args, 'd')) {
|
||||
session_select(dst, wl_dst->idx);
|
||||
if (src != dst)
|
||||
|
||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
.name = "switch-client",
|
||||
.alias = "switchc",
|
||||
|
||||
.args = { "lc:EFnpt:rT:Z", 0, 0, NULL },
|
||||
.args = { "c:EFlnO:pt:rT:Z", 0, 0, NULL },
|
||||
.usage = "[-ElnprZ] [-c target-client] [-t target-session] "
|
||||
"[-T key-table]",
|
||||
"[-T key-table] [-O order]",
|
||||
|
||||
/* -t is special */
|
||||
|
||||
@@ -60,8 +60,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window_pane *wp;
|
||||
const char *tablename;
|
||||
struct key_table *table;
|
||||
struct sort_criteria sort_crit;
|
||||
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.%")] != '\0') {
|
||||
if (tflag != NULL &&
|
||||
(tflag[strcspn(tflag, ":.%")] != '\0' || strcmp(tflag, "=") == 0)) {
|
||||
type = CMD_FIND_PANE;
|
||||
flags = 0;
|
||||
} else {
|
||||
@@ -94,13 +96,22 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
sort_crit.order = sort_order_from_string(args_get(args, 'O'));
|
||||
if (sort_crit.order == SORT_END && args_has(args, 'O')) {
|
||||
cmdq_error(item, "invalid sort order");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
sort_crit.reversed = args_has(args, 'r');
|
||||
|
||||
if (args_has(args, 'n')) {
|
||||
if ((s = session_next_session(tc->session)) == NULL) {
|
||||
s = session_next_session(tc->session, &sort_crit);
|
||||
if (s == NULL) {
|
||||
cmdq_error(item, "can't find next session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
if ((s = session_previous_session(tc->session)) == NULL) {
|
||||
s = session_previous_session(tc->session, &sort_crit);
|
||||
if (s == NULL) {
|
||||
cmdq_error(item, "can't find previous session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
52
cmd.c
52
cmd.c
@@ -47,7 +47,6 @@ extern const struct cmd_entry cmd_display_menu_entry;
|
||||
extern const struct cmd_entry cmd_display_message_entry;
|
||||
extern const struct cmd_entry cmd_display_popup_entry;
|
||||
extern const struct cmd_entry cmd_display_panes_entry;
|
||||
extern const struct cmd_entry cmd_down_pane_entry;
|
||||
extern const struct cmd_entry cmd_find_window_entry;
|
||||
extern const struct cmd_entry cmd_has_session_entry;
|
||||
extern const struct cmd_entry cmd_if_shell_entry;
|
||||
@@ -117,7 +116,6 @@ extern const struct cmd_entry cmd_swap_window_entry;
|
||||
extern const struct cmd_entry cmd_switch_client_entry;
|
||||
extern const struct cmd_entry cmd_unbind_key_entry;
|
||||
extern const struct cmd_entry cmd_unlink_window_entry;
|
||||
extern const struct cmd_entry cmd_up_pane_entry;
|
||||
extern const struct cmd_entry cmd_wait_for_entry;
|
||||
|
||||
const struct cmd_entry *cmd_table[] = {
|
||||
@@ -222,6 +220,7 @@ struct cmd {
|
||||
|
||||
char *file;
|
||||
u_int line;
|
||||
int parse_flags;
|
||||
|
||||
TAILQ_ENTRY(cmd) qentry;
|
||||
};
|
||||
@@ -414,6 +413,13 @@ cmd_get_source(struct cmd *cmd, const char **file, u_int *line)
|
||||
*line = cmd->line;
|
||||
}
|
||||
|
||||
/* Get parse flags for command. */
|
||||
int
|
||||
cmd_get_parse_flags(struct cmd *cmd)
|
||||
{
|
||||
return (cmd->parse_flags);
|
||||
}
|
||||
|
||||
/* Look for an alias for a command. */
|
||||
char *
|
||||
cmd_get_alias(const char *name)
|
||||
@@ -446,7 +452,7 @@ cmd_get_alias(const char *name)
|
||||
}
|
||||
|
||||
/* Look up a command entry by name. */
|
||||
static const struct cmd_entry *
|
||||
const struct cmd_entry *
|
||||
cmd_find(const char *name, char **cause)
|
||||
{
|
||||
const struct cmd_entry **loop, *entry, *found = NULL;
|
||||
@@ -498,7 +504,7 @@ ambiguous:
|
||||
/* Parse a single command from an argument vector. */
|
||||
struct cmd *
|
||||
cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
|
||||
char **cause)
|
||||
int parse_flags, char **cause)
|
||||
{
|
||||
const struct cmd_entry *entry;
|
||||
struct cmd *cmd;
|
||||
@@ -527,6 +533,7 @@ cmd_parse(struct args_value *values, u_int count, const char *file, u_int line,
|
||||
cmd = xcalloc(1, sizeof *cmd);
|
||||
cmd->entry = entry;
|
||||
cmd->args = args;
|
||||
cmd->parse_flags = parse_flags;
|
||||
|
||||
if (file != NULL)
|
||||
cmd->file = xstrdup(file);
|
||||
@@ -638,7 +645,7 @@ cmd_list_free(struct cmd_list *cmdlist)
|
||||
|
||||
/* Copy a command list, expanding %s in arguments. */
|
||||
struct cmd_list *
|
||||
cmd_list_copy(struct cmd_list *cmdlist, int argc, char **argv)
|
||||
cmd_list_copy(const struct cmd_list *cmdlist, int argc, char **argv)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *new_cmdlist;
|
||||
@@ -669,11 +676,16 @@ cmd_list_copy(struct cmd_list *cmdlist, int argc, char **argv)
|
||||
|
||||
/* Get a command list as a string. */
|
||||
char *
|
||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
cmd_list_print(const struct cmd_list *cmdlist, int flags)
|
||||
{
|
||||
struct cmd *cmd, *next;
|
||||
char *buf, *this;
|
||||
size_t len;
|
||||
const char *separator;
|
||||
int escaped = flags & CMD_LIST_PRINT_ESCAPED;
|
||||
int no_groups = flags & CMD_LIST_PRINT_NO_GROUPS;
|
||||
const char *single_separator = escaped ? " \\; " : " ; ";
|
||||
const char *double_separator = escaped ? " \\;\\; " : " ;; ";
|
||||
|
||||
len = 1;
|
||||
buf = xcalloc(1, len);
|
||||
@@ -688,17 +700,11 @@ cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
|
||||
next = TAILQ_NEXT(cmd, qentry);
|
||||
if (next != NULL) {
|
||||
if (cmd->group != next->group) {
|
||||
if (escaped)
|
||||
strlcat(buf, " \\;\\; ", len);
|
||||
else
|
||||
strlcat(buf, " ;; ", len);
|
||||
} else {
|
||||
if (escaped)
|
||||
strlcat(buf, " \\; ", len);
|
||||
else
|
||||
strlcat(buf, " ; ", len);
|
||||
}
|
||||
if (!no_groups && cmd->group != next->group)
|
||||
separator = double_separator;
|
||||
else
|
||||
separator = single_separator;
|
||||
strlcat(buf, separator, len);
|
||||
}
|
||||
|
||||
free(this);
|
||||
@@ -812,10 +818,14 @@ cmd_mouse_pane(struct mouse_event *m, struct session **sp,
|
||||
|
||||
if ((wl = cmd_mouse_window(m, sp)) == NULL)
|
||||
return (NULL);
|
||||
if ((wp = window_pane_find_by_id(m->wp)) == NULL)
|
||||
return (NULL);
|
||||
if (!window_has_pane(wl->window, wp))
|
||||
return (NULL);
|
||||
if (m->wp == -1)
|
||||
wp = wl->window->active;
|
||||
else {
|
||||
if ((wp = window_pane_find_by_id(m->wp)) == NULL)
|
||||
return (NULL);
|
||||
if (!window_has_pane(wl->window, wp))
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (wlp != NULL)
|
||||
*wlp = wl;
|
||||
|
||||
124
colour.c
124
colour.c
@@ -182,6 +182,46 @@ colour_tostring(int c)
|
||||
return ("invalid");
|
||||
}
|
||||
|
||||
/* Convert background colour to theme. */
|
||||
enum client_theme
|
||||
colour_totheme(int c)
|
||||
{
|
||||
int r, g, b, brightness;
|
||||
|
||||
if (c == -1)
|
||||
return (THEME_UNKNOWN);
|
||||
|
||||
if (c & COLOUR_FLAG_RGB) {
|
||||
r = (c >> 16) & 0xff;
|
||||
g = (c >> 8) & 0xff;
|
||||
b = (c >> 0) & 0xff;
|
||||
|
||||
brightness = r + g + b;
|
||||
if (brightness > 382)
|
||||
return (THEME_LIGHT);
|
||||
return (THEME_DARK);
|
||||
}
|
||||
|
||||
if (c & COLOUR_FLAG_256)
|
||||
return (colour_totheme(colour_256toRGB(c)));
|
||||
|
||||
switch (c) {
|
||||
case 0:
|
||||
case 90:
|
||||
return (THEME_DARK);
|
||||
case 7:
|
||||
case 97:
|
||||
return (THEME_LIGHT);
|
||||
default:
|
||||
if (c >= 0 && c <= 7)
|
||||
return (colour_totheme(colour_256toRGB(c)));
|
||||
if (c >= 90 && c <= 97)
|
||||
return (colour_totheme(colour_256toRGB(8 + c - 90)));
|
||||
break;
|
||||
}
|
||||
return (THEME_UNKNOWN);
|
||||
}
|
||||
|
||||
/* Convert colour from string. */
|
||||
int
|
||||
colour_fromstring(const char *s)
|
||||
@@ -942,13 +982,18 @@ colour_byname(const char *name)
|
||||
{ "yellow3", 0xcdcd00 },
|
||||
{ "yellow4", 0x8b8b00 }
|
||||
};
|
||||
u_int i;
|
||||
int c;
|
||||
u_int i;
|
||||
int c;
|
||||
const char *errstr;
|
||||
|
||||
if (strncmp(name, "grey", 4) == 0 || strncmp(name, "gray", 4) == 0) {
|
||||
if (!isdigit((u_char)name[4]))
|
||||
if (strncasecmp(name, "grey", 4) == 0 ||
|
||||
strncasecmp(name, "gray", 4) == 0) {
|
||||
if (name[4] == '\0')
|
||||
return (0xbebebe|COLOUR_FLAG_RGB);
|
||||
c = round(2.55 * atoi(name + 4));
|
||||
c = strtonum(name + 4, 0, 100, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
c = round(2.55 * c);
|
||||
if (c < 0 || c > 255)
|
||||
return (-1);
|
||||
return (colour_join_rgb(c, c, c));
|
||||
@@ -960,6 +1005,47 @@ colour_byname(const char *name)
|
||||
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)
|
||||
@@ -996,22 +1082,22 @@ colour_palette_free(struct colour_palette *p)
|
||||
|
||||
/* Get a colour from a palette. */
|
||||
int
|
||||
colour_palette_get(struct colour_palette *p, int c)
|
||||
colour_palette_get(struct colour_palette *p, int n)
|
||||
{
|
||||
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)
|
||||
if (n >= 90 && n <= 97)
|
||||
n = 8 + n - 90;
|
||||
else if (n & COLOUR_FLAG_256)
|
||||
n &= ~COLOUR_FLAG_256;
|
||||
else if (n >= 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]);
|
||||
if (p->palette != NULL && p->palette[n] != -1)
|
||||
return (p->palette[n]);
|
||||
if (p->default_palette != NULL && p->default_palette[n] != -1)
|
||||
return (p->default_palette[n]);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -1021,15 +1107,14 @@ colour_palette_set(struct colour_palette *p, int n, int c)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
if (p == NULL || n > 255)
|
||||
if (p == NULL || n < 0 || 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);
|
||||
if (p->palette == NULL) {
|
||||
p->palette = xcalloc(256, sizeof *p->palette);
|
||||
for (i = 0; i < 256; i++)
|
||||
p->palette[i] = -1;
|
||||
}
|
||||
@@ -1069,5 +1154,4 @@ colour_palette_from_option(struct colour_palette *p, struct options *oo)
|
||||
}
|
||||
a = options_array_next(a);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
compat.h
39
compat.h
@@ -38,6 +38,14 @@
|
||||
#include <event2/bufferevent_compat.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#ifndef EVBUFFER_EOL_LF
|
||||
/*
|
||||
* This doesn't really work because evbuffer_readline is broken, but gets us to
|
||||
* build with very old (older than 1.4.14) libevent.
|
||||
*/
|
||||
#define EVBUFFER_EOL_LF
|
||||
#define evbuffer_readln(a, b, c) evbuffer_readline(a)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MALLOC_TRIM
|
||||
@@ -289,6 +297,11 @@ void explicit_bzero(void *, size_t);
|
||||
int getdtablecount(void);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETDTABLESIZE
|
||||
/* getdtablesize.c */
|
||||
int getdtablesize(void);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_CLOSEFROM
|
||||
/* closefrom.c */
|
||||
void closefrom(int);
|
||||
@@ -334,6 +347,18 @@ char *strndup(const char *, size_t);
|
||||
void *memmem(const void *, size_t, const void *, size_t);
|
||||
#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 *);
|
||||
@@ -363,7 +388,7 @@ int clock_gettime(int, struct timespec *);
|
||||
/* base64.c */
|
||||
#undef b64_ntop
|
||||
#undef b64_pton
|
||||
int b64_ntop(const char *, size_t, char *, size_t);
|
||||
int b64_ntop(const u_char *, size_t, char *, size_t);
|
||||
int b64_pton(const char *, u_char *, size_t);
|
||||
#endif
|
||||
|
||||
@@ -423,7 +448,9 @@ void *recallocarray(void *, size_t, size_t, size_t);
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
/* systemd.c */
|
||||
int systemd_activated(void);
|
||||
int systemd_create_socket(int, char **);
|
||||
int systemd_move_to_new_cgroup(char **);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTF8PROC
|
||||
@@ -439,11 +466,11 @@ int utf8proc_wctomb(char *, wchar_t);
|
||||
#endif
|
||||
|
||||
/* getopt.c */
|
||||
extern int BSDopterr;
|
||||
extern int BSDoptind;
|
||||
extern int BSDoptopt;
|
||||
extern int BSDoptreset;
|
||||
extern char *BSDoptarg;
|
||||
extern int BSDopterr;
|
||||
extern int BSDoptind;
|
||||
extern int BSDoptopt;
|
||||
extern int BSDoptreset;
|
||||
extern char *BSDoptarg;
|
||||
int BSDgetopt(int, char *const *, const char *);
|
||||
#define getopt(ac, av, o) BSDgetopt(ac, av, o)
|
||||
#define opterr BSDopterr
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: base64.c,v 1.8 2015/01/16 16:48:51 deraadt Exp $ */
|
||||
/* $OpenBSD: base64.c,v 1.15 2021/10/25 14:41:09 jca Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 by Internet Software Consortium.
|
||||
@@ -46,15 +46,15 @@
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <arpa/nameser.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <resolv.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
static const char Base64[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
static const char Pad64 = '=';
|
||||
@@ -107,9 +107,9 @@ static const char Pad64 = '=';
|
||||
end of the data is performed using the '=' character.
|
||||
|
||||
Since all base64 input is an integral number of octets, only the
|
||||
-------------------------------------------------
|
||||
-------------------------------------------------
|
||||
following cases can arise:
|
||||
|
||||
|
||||
(1) the final quantum of encoding input is an integral
|
||||
multiple of 24 bits; here, the final unit of encoded
|
||||
output will be an integral multiple of 4 characters
|
||||
@@ -123,15 +123,12 @@ static const char Pad64 = '=';
|
||||
*/
|
||||
|
||||
int
|
||||
b64_ntop(src, srclength, target, targsize)
|
||||
u_char const *src;
|
||||
size_t srclength;
|
||||
char *target;
|
||||
size_t targsize;
|
||||
b64_ntop(unsigned char const *src, size_t srclength, char *target,
|
||||
size_t targsize)
|
||||
{
|
||||
size_t datalength = 0;
|
||||
u_char input[3];
|
||||
u_char output[4];
|
||||
unsigned char input[3];
|
||||
unsigned char output[4];
|
||||
int i;
|
||||
|
||||
while (2 < srclength) {
|
||||
@@ -152,14 +149,14 @@ b64_ntop(src, srclength, target, targsize)
|
||||
target[datalength++] = Base64[output[2]];
|
||||
target[datalength++] = Base64[output[3]];
|
||||
}
|
||||
|
||||
|
||||
/* Now we worry about padding. */
|
||||
if (0 != srclength) {
|
||||
/* Get what's left. */
|
||||
input[0] = input[1] = input[2] = '\0';
|
||||
for (i = 0; i < srclength; i++)
|
||||
input[i] = *src++;
|
||||
|
||||
|
||||
output[0] = input[0] >> 2;
|
||||
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
|
||||
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
|
||||
@@ -187,13 +184,10 @@ b64_ntop(src, srclength, target, targsize)
|
||||
*/
|
||||
|
||||
int
|
||||
b64_pton(src, target, targsize)
|
||||
char const *src;
|
||||
u_char *target;
|
||||
size_t targsize;
|
||||
b64_pton(char const *src, unsigned char *target, size_t targsize)
|
||||
{
|
||||
int tarindex, state, ch;
|
||||
u_char nextbyte;
|
||||
unsigned char nextbyte;
|
||||
char *pos;
|
||||
|
||||
state = 0;
|
||||
@@ -207,7 +201,7 @@ b64_pton(src, target, targsize)
|
||||
break;
|
||||
|
||||
pos = strchr(Base64, ch);
|
||||
if (pos == 0) /* A non-base64 character. */
|
||||
if (pos == 0) /* A non-base64 character. */
|
||||
return (-1);
|
||||
|
||||
switch (state) {
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#endif
|
||||
|
||||
int
|
||||
clock_gettime(int clock, struct timespec *ts)
|
||||
clock_gettime(__unused int clock, struct timespec *ts)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
|
||||
@@ -49,12 +49,12 @@
|
||||
|
||||
#include <mach/mach.h>
|
||||
|
||||
#include <Availability.h>
|
||||
#include <AvailabilityMacros.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void daemon_darwin(void);
|
||||
|
||||
#ifdef __MAC_10_10
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
|
||||
|
||||
extern kern_return_t bootstrap_look_up_per_user(mach_port_t, const char *,
|
||||
uid_t, mach_port_t *);
|
||||
|
||||
@@ -18,13 +18,28 @@
|
||||
|
||||
#include <glob.h>
|
||||
#include <unistd.h>
|
||||
#if defined(HAVE_LIBPROC_H)
|
||||
#include <libproc.h>
|
||||
#endif
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
#ifdef HAVE_PROC_PID
|
||||
#if defined(HAVE_LIBPROC_H) && defined(HAVE_PROC_PIDINFO)
|
||||
int
|
||||
getdtablecount(void)
|
||||
{
|
||||
int sz;
|
||||
pid_t pid = getpid();
|
||||
|
||||
sz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
|
||||
if (sz == -1)
|
||||
return (0);
|
||||
return (sz / PROC_PIDLISTFD_SIZE);
|
||||
}
|
||||
#elif defined(HAVE_PROC_PID)
|
||||
int
|
||||
getdtablecount(void)
|
||||
{
|
||||
|
||||
115
compat/getopt.c
115
compat/getopt.c
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt.c */
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int BSDopterr = 1, /* if error message should be printed */
|
||||
BSDoptind = 1, /* index into parent argv vector */
|
||||
BSDoptopt, /* character checked for validity */
|
||||
BSDoptreset; /* reset getopt */
|
||||
char *BSDoptarg; /* argument associated with option */
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
#define EMSG ""
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
BSDgetopt(int nargc, char *const *nargv, const char *ostr)
|
||||
{
|
||||
static const char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
|
||||
if (ostr == NULL)
|
||||
return (-1);
|
||||
|
||||
if (BSDoptreset || !*place) { /* update scanning pointer */
|
||||
BSDoptreset = 0;
|
||||
if (BSDoptind >= nargc || *(place = nargv[BSDoptind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
if (place[1])
|
||||
return (BADCH);
|
||||
++BSDoptind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((BSDoptopt = (int)*place++) == (int)':' ||
|
||||
!(oli = strchr(ostr, BSDoptopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (BSDoptopt == (int)'-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++BSDoptind;
|
||||
if (BSDopterr && *ostr != ':')
|
||||
(void)fprintf(stderr,
|
||||
"%s: unknown option -- %c\n", getprogname(),
|
||||
BSDoptopt);
|
||||
return (BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
BSDoptarg = NULL;
|
||||
if (!*place)
|
||||
++BSDoptind;
|
||||
}
|
||||
else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
BSDoptarg = (char *)place;
|
||||
else if (nargc <= ++BSDoptind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (BSDopterr)
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
getprogname(), BSDoptopt);
|
||||
return (BADCH);
|
||||
}
|
||||
else /* white space */
|
||||
BSDoptarg = nargv[BSDoptind];
|
||||
place = EMSG;
|
||||
++BSDoptind;
|
||||
}
|
||||
return (BSDoptopt); /* dump back option letter */
|
||||
}
|
||||
577
compat/getopt_long.c
Normal file
577
compat/getopt_long.c
Normal file
@@ -0,0 +1,577 @@
|
||||
/* This file is obtained from OpenSSH:
|
||||
* Repository: https://github.com/openssh/openssh-portable
|
||||
* Commit: b5b405fee7f3e79d44e2d2971a4b6b4cc53f112e
|
||||
* File: /openbsd-compat/getopt_long.c */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
* Sponsored in part by the Defense Advanced Research Projects
|
||||
* Agency (DARPA) and Air Force Research Laboratory, Air Force
|
||||
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
|
||||
*/
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Dieter Baron and Thomas Klausner.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* OPENBSD ORIGINAL: lib/libc/stdlib/getopt_long.c */
|
||||
#include "compat.h"
|
||||
|
||||
/* The following macro constants are taken from getopt.h of OpenSSH:
|
||||
* Repository: https://github.com/openssh/openssh-portable
|
||||
* Commit: b5b405fee7f3e79d44e2d2971a4b6b4cc53f112e
|
||||
* File: /openbsd-compat/getopt.h
|
||||
*
|
||||
* ---- BEGIN - Copyright notice and license of getopt.h ----
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Dieter Baron and Thomas Klausner.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
* ---- END ----
|
||||
*/
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
#if !defined(HAVE_GETOPT) || !defined(HAVE_GETOPT_OPTRESET)
|
||||
|
||||
#if 0
|
||||
#include <err.h>
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
struct option {
|
||||
/* name of long option */
|
||||
const char *name;
|
||||
/*
|
||||
* one of no_argument, required_argument, and optional_argument:
|
||||
* whether option takes an argument
|
||||
*/
|
||||
int has_arg;
|
||||
/* if not NULL, set *flag to val when option found */
|
||||
int *flag;
|
||||
/* if flag not NULL, value to set *flag to; else return value */
|
||||
int val;
|
||||
};
|
||||
|
||||
int opterr = 1; /* if error message should be printed */
|
||||
int optind = 1; /* index into parent argv vector */
|
||||
int optopt = '?'; /* character checked for validity */
|
||||
int optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
#define PRINT_ERROR ((opterr) && (*options != ':'))
|
||||
|
||||
#define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */
|
||||
#define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */
|
||||
#define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */
|
||||
|
||||
/* return values */
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG ((*options == ':') ? (int)':' : (int)'?')
|
||||
#define INORDER (int)1
|
||||
|
||||
#define EMSG (char *)""
|
||||
|
||||
static int getopt_internal(int, char * const *, const char *,
|
||||
const struct option *, int *, int);
|
||||
static int parse_long_options(char * const *, const char *,
|
||||
const struct option *, int *, int);
|
||||
static int gcd(int, int);
|
||||
static void permute_args(int, int, int, char * const *);
|
||||
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
|
||||
/* XXX: set optreset to 1 rather than these two */
|
||||
static int nonopt_start = -1; /* first non option argument (for permute) */
|
||||
static int nonopt_end = -1; /* first option after non options (for permute) */
|
||||
|
||||
/* Error messages */
|
||||
static const char recargchar[] = "option requires an argument -- %c";
|
||||
static const char recargstring[] = "option requires an argument -- %s";
|
||||
static const char ambig[] = "ambiguous option -- %.*s";
|
||||
static const char noarg[] = "option doesn't take an argument -- %.*s";
|
||||
static const char illoptchar[] = "unknown option -- %c";
|
||||
static const char illoptstring[] = "unknown option -- %s";
|
||||
|
||||
/*
|
||||
* Compute the greatest common divisor of a and b.
|
||||
*/
|
||||
static int
|
||||
gcd(int a, int b)
|
||||
{
|
||||
int c;
|
||||
|
||||
c = a % b;
|
||||
while (c != 0) {
|
||||
a = b;
|
||||
b = c;
|
||||
c = a % b;
|
||||
}
|
||||
|
||||
return (b);
|
||||
}
|
||||
|
||||
/*
|
||||
* Exchange the block from nonopt_start to nonopt_end with the block
|
||||
* from nonopt_end to opt_end (keeping the same order of arguments
|
||||
* in each block).
|
||||
*/
|
||||
static void
|
||||
permute_args(int panonopt_start, int panonopt_end, int opt_end,
|
||||
char * const *nargv)
|
||||
{
|
||||
int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
|
||||
char *swap;
|
||||
|
||||
/*
|
||||
* compute lengths of blocks and number and size of cycles
|
||||
*/
|
||||
nnonopts = panonopt_end - panonopt_start;
|
||||
nopts = opt_end - panonopt_end;
|
||||
ncycle = gcd(nnonopts, nopts);
|
||||
cyclelen = (opt_end - panonopt_start) / ncycle;
|
||||
|
||||
for (i = 0; i < ncycle; i++) {
|
||||
cstart = panonopt_end+i;
|
||||
pos = cstart;
|
||||
for (j = 0; j < cyclelen; j++) {
|
||||
if (pos >= panonopt_end)
|
||||
pos -= nnonopts;
|
||||
else
|
||||
pos += nopts;
|
||||
swap = nargv[pos];
|
||||
/* LINTED const cast */
|
||||
((char **) nargv)[pos] = nargv[cstart];
|
||||
/* LINTED const cast */
|
||||
((char **)nargv)[cstart] = swap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* parse_long_options --
|
||||
* Parse long options in argc/argv argument vector.
|
||||
* Returns -1 if short_too is set and the option does not match long_options.
|
||||
*/
|
||||
static int
|
||||
parse_long_options(char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx, int short_too)
|
||||
{
|
||||
char *current_argv, *has_equal;
|
||||
size_t current_argv_len;
|
||||
int i, match;
|
||||
|
||||
current_argv = place;
|
||||
match = -1;
|
||||
|
||||
optind++;
|
||||
|
||||
if ((has_equal = strchr(current_argv, '=')) != NULL) {
|
||||
/* argument found (--option=arg) */
|
||||
current_argv_len = has_equal - current_argv;
|
||||
has_equal++;
|
||||
} else
|
||||
current_argv_len = strlen(current_argv);
|
||||
|
||||
for (i = 0; long_options[i].name; i++) {
|
||||
/* find matching long option */
|
||||
if (strncmp(current_argv, long_options[i].name,
|
||||
current_argv_len))
|
||||
continue;
|
||||
|
||||
if (strlen(long_options[i].name) == current_argv_len) {
|
||||
/* exact match */
|
||||
match = i;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* If this is a known short option, don't allow
|
||||
* a partial match of a single character.
|
||||
*/
|
||||
if (short_too && current_argv_len == 1)
|
||||
continue;
|
||||
|
||||
if (match == -1) /* partial match */
|
||||
match = i;
|
||||
else {
|
||||
/* ambiguous abbreviation */
|
||||
if (PRINT_ERROR)
|
||||
warnx(ambig, (int)current_argv_len,
|
||||
current_argv);
|
||||
optopt = 0;
|
||||
return (BADCH);
|
||||
}
|
||||
}
|
||||
if (match != -1) { /* option found */
|
||||
if (long_options[match].has_arg == no_argument
|
||||
&& has_equal) {
|
||||
if (PRINT_ERROR)
|
||||
warnx(noarg, (int)current_argv_len,
|
||||
current_argv);
|
||||
/*
|
||||
* XXX: GNU sets optopt to val regardless of flag
|
||||
*/
|
||||
if (long_options[match].flag == NULL)
|
||||
optopt = long_options[match].val;
|
||||
else
|
||||
optopt = 0;
|
||||
return (BADARG);
|
||||
}
|
||||
if (long_options[match].has_arg == required_argument ||
|
||||
long_options[match].has_arg == optional_argument) {
|
||||
if (has_equal)
|
||||
optarg = has_equal;
|
||||
else if (long_options[match].has_arg ==
|
||||
required_argument) {
|
||||
/*
|
||||
* optional argument doesn't use next nargv
|
||||
*/
|
||||
optarg = nargv[optind++];
|
||||
}
|
||||
}
|
||||
if ((long_options[match].has_arg == required_argument)
|
||||
&& (optarg == NULL)) {
|
||||
/*
|
||||
* Missing argument; leading ':' indicates no error
|
||||
* should be generated.
|
||||
*/
|
||||
if (PRINT_ERROR)
|
||||
warnx(recargstring,
|
||||
current_argv);
|
||||
/*
|
||||
* XXX: GNU sets optopt to val regardless of flag
|
||||
*/
|
||||
if (long_options[match].flag == NULL)
|
||||
optopt = long_options[match].val;
|
||||
else
|
||||
optopt = 0;
|
||||
--optind;
|
||||
return (BADARG);
|
||||
}
|
||||
} else { /* unknown option */
|
||||
if (short_too) {
|
||||
--optind;
|
||||
return (-1);
|
||||
}
|
||||
if (PRINT_ERROR)
|
||||
warnx(illoptstring, current_argv);
|
||||
optopt = 0;
|
||||
return (BADCH);
|
||||
}
|
||||
if (idx)
|
||||
*idx = match;
|
||||
if (long_options[match].flag) {
|
||||
*long_options[match].flag = long_options[match].val;
|
||||
return (0);
|
||||
} else
|
||||
return (long_options[match].val);
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt_internal --
|
||||
* Parse argc/argv argument vector. Called by user level routines.
|
||||
*/
|
||||
static int
|
||||
getopt_internal(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx, int flags)
|
||||
{
|
||||
char *oli; /* option letter list index */
|
||||
int optchar, short_too;
|
||||
static int posixly_correct = -1;
|
||||
|
||||
if (options == NULL)
|
||||
return (-1);
|
||||
|
||||
/*
|
||||
* XXX Some GNU programs (like cvs) set optind to 0 instead of
|
||||
* XXX using optreset. Work around this braindamage.
|
||||
*/
|
||||
if (optind == 0)
|
||||
optind = optreset = 1;
|
||||
|
||||
/*
|
||||
* Disable GNU extensions if POSIXLY_CORRECT is set or options
|
||||
* string begins with a '+'.
|
||||
*/
|
||||
if (posixly_correct == -1 || optreset)
|
||||
posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
|
||||
if (*options == '-')
|
||||
flags |= FLAG_ALLARGS;
|
||||
else if (posixly_correct || *options == '+')
|
||||
flags &= ~FLAG_PERMUTE;
|
||||
if (*options == '+' || *options == '-')
|
||||
options++;
|
||||
|
||||
optarg = NULL;
|
||||
if (optreset)
|
||||
nonopt_start = nonopt_end = -1;
|
||||
start:
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc) { /* end of argument vector */
|
||||
place = EMSG;
|
||||
if (nonopt_end != -1) {
|
||||
/* do permutation, if we have to */
|
||||
permute_args(nonopt_start, nonopt_end,
|
||||
optind, nargv);
|
||||
optind -= nonopt_end - nonopt_start;
|
||||
}
|
||||
else if (nonopt_start != -1) {
|
||||
/*
|
||||
* If we skipped non-options, set optind
|
||||
* to the first of them.
|
||||
*/
|
||||
optind = nonopt_start;
|
||||
}
|
||||
nonopt_start = nonopt_end = -1;
|
||||
return (-1);
|
||||
}
|
||||
if (*(place = nargv[optind]) != '-' ||
|
||||
(place[1] == '\0' && strchr(options, '-') == NULL)) {
|
||||
place = EMSG; /* found non-option */
|
||||
if (flags & FLAG_ALLARGS) {
|
||||
/*
|
||||
* GNU extension:
|
||||
* return non-option as argument to option 1
|
||||
*/
|
||||
optarg = nargv[optind++];
|
||||
return (INORDER);
|
||||
}
|
||||
if (!(flags & FLAG_PERMUTE)) {
|
||||
/*
|
||||
* If no permutation wanted, stop parsing
|
||||
* at first non-option.
|
||||
*/
|
||||
return (-1);
|
||||
}
|
||||
/* do permutation */
|
||||
if (nonopt_start == -1)
|
||||
nonopt_start = optind;
|
||||
else if (nonopt_end != -1) {
|
||||
permute_args(nonopt_start, nonopt_end,
|
||||
optind, nargv);
|
||||
nonopt_start = optind -
|
||||
(nonopt_end - nonopt_start);
|
||||
nonopt_end = -1;
|
||||
}
|
||||
optind++;
|
||||
/* process next argument */
|
||||
goto start;
|
||||
}
|
||||
if (nonopt_start != -1 && nonopt_end == -1)
|
||||
nonopt_end = optind;
|
||||
|
||||
/*
|
||||
* If we have "-" do nothing, if "--" we are done.
|
||||
*/
|
||||
if (place[1] != '\0' && *++place == '-' && place[1] == '\0') {
|
||||
optind++;
|
||||
place = EMSG;
|
||||
/*
|
||||
* We found an option (--), so if we skipped
|
||||
* non-options, we have to permute.
|
||||
*/
|
||||
if (nonopt_end != -1) {
|
||||
permute_args(nonopt_start, nonopt_end,
|
||||
optind, nargv);
|
||||
optind -= nonopt_end - nonopt_start;
|
||||
}
|
||||
nonopt_start = nonopt_end = -1;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check long options if:
|
||||
* 1) we were passed some
|
||||
* 2) the arg is not just "-"
|
||||
* 3) either the arg starts with -- we are getopt_long_only()
|
||||
*/
|
||||
if (long_options != NULL && place != nargv[optind] &&
|
||||
(*place == '-' || (flags & FLAG_LONGONLY))) {
|
||||
short_too = 0;
|
||||
if (*place == '-')
|
||||
place++; /* --foo long option */
|
||||
else if (*place != ':' && strchr(options, *place) != NULL)
|
||||
short_too = 1; /* could be short option too */
|
||||
|
||||
optchar = parse_long_options(nargv, options, long_options,
|
||||
idx, short_too);
|
||||
if (optchar != -1) {
|
||||
place = EMSG;
|
||||
return (optchar);
|
||||
}
|
||||
}
|
||||
|
||||
if ((optchar = (int)*place++) == (int)':' ||
|
||||
(optchar == (int)'-' && *place != '\0') ||
|
||||
(oli = strchr(options, optchar)) == NULL) {
|
||||
/*
|
||||
* If the user specified "-" and '-' isn't listed in
|
||||
* options, return -1 (non-option) as per POSIX.
|
||||
* Otherwise, it is an unknown option character (or ':').
|
||||
*/
|
||||
if (optchar == (int)'-' && *place == '\0')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (PRINT_ERROR)
|
||||
warnx(illoptchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADCH);
|
||||
}
|
||||
if (long_options != NULL && optchar == 'W' && oli[1] == ';') {
|
||||
/* -W long-option */
|
||||
if (*place) /* no space */
|
||||
/* NOTHING */;
|
||||
else if (++optind >= nargc) { /* no arg */
|
||||
place = EMSG;
|
||||
if (PRINT_ERROR)
|
||||
warnx(recargchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADARG);
|
||||
} else /* white space */
|
||||
place = nargv[optind];
|
||||
optchar = parse_long_options(nargv, options, long_options,
|
||||
idx, 0);
|
||||
place = EMSG;
|
||||
return (optchar);
|
||||
}
|
||||
if (*++oli != ':') { /* doesn't take argument */
|
||||
if (!*place)
|
||||
++optind;
|
||||
} else { /* takes (optional) argument */
|
||||
optarg = NULL;
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (oli[1] != ':') { /* arg not optional */
|
||||
if (++optind >= nargc) { /* no arg */
|
||||
place = EMSG;
|
||||
if (PRINT_ERROR)
|
||||
warnx(recargchar, optchar);
|
||||
optopt = optchar;
|
||||
return (BADARG);
|
||||
} else
|
||||
optarg = nargv[optind];
|
||||
}
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
/* dump back option letter */
|
||||
return (optchar);
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*
|
||||
* [eventually this will replace the BSD getopt]
|
||||
*/
|
||||
int
|
||||
getopt(int nargc, char * const *nargv, const char *options)
|
||||
{
|
||||
|
||||
/*
|
||||
* We don't pass FLAG_PERMUTE to getopt_internal() since
|
||||
* the BSD getopt(3) (unlike GNU) has never done this.
|
||||
*
|
||||
* Furthermore, since many privileged programs call getopt()
|
||||
* before dropping privileges it makes sense to keep things
|
||||
* as simple (and bug-free) as possible.
|
||||
*/
|
||||
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* getopt_long --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_long(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx)
|
||||
{
|
||||
|
||||
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||
FLAG_PERMUTE));
|
||||
}
|
||||
|
||||
/*
|
||||
* getopt_long_only --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_long_only(int nargc, char * const *nargv, const char *options,
|
||||
const struct option *long_options, int *idx)
|
||||
{
|
||||
|
||||
return (getopt_internal(nargc, nargv, options, long_options, idx,
|
||||
FLAG_PERMUTE|FLAG_LONGONLY));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !defined(HAVE_GETOPT) || !defined(HAVE_OPTRESET) */
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef HAVE_UCRED_H
|
||||
#include <ucred.h>
|
||||
@@ -38,9 +39,6 @@ getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
*gid = uc.gid;
|
||||
return (0);
|
||||
#elif defined(HAVE_GETPEERUCRED)
|
||||
int
|
||||
getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
{
|
||||
ucred_t *ucred = NULL;
|
||||
|
||||
if (getpeerucred(s, &ucred) == -1)
|
||||
@@ -51,8 +49,9 @@ getpeereid(int s, uid_t *uid, gid_t *gid)
|
||||
return (-1);
|
||||
ucred_free(ucred);
|
||||
return (0);
|
||||
}
|
||||
#else
|
||||
return (getuid());
|
||||
*uid = geteuid();
|
||||
*gid = getegid();
|
||||
return (0);
|
||||
#endif
|
||||
}
|
||||
|
||||
31
compat/htonll.c
Normal file
31
compat/htonll.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 <arpa/inet.h>
|
||||
#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);
|
||||
}
|
||||
1055
compat/imsg-buffer.c
1055
compat/imsg-buffer.c
File diff suppressed because it is too large
Load Diff
538
compat/imsg.c
538
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.42 2025/06/16 13:56:11 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
@@ -21,6 +22,7 @@
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@@ -28,213 +30,365 @@
|
||||
#include "compat.h"
|
||||
#include "imsg.h"
|
||||
|
||||
int imsg_fd_overhead = 0;
|
||||
#define IMSG_ALLOW_FDPASS 0x01
|
||||
#define IMSG_FD_MARK 0x80000000U
|
||||
|
||||
static int imsg_get_fd(struct imsgbuf *);
|
||||
static struct ibuf *imsg_parse_hdr(struct ibuf *, void *, int *);
|
||||
|
||||
int
|
||||
imsgbuf_init(struct imsgbuf *imsgbuf, int fd)
|
||||
{
|
||||
imsgbuf->w = msgbuf_new_reader(IMSG_HEADER_SIZE, imsg_parse_hdr,
|
||||
imsgbuf);
|
||||
if (imsgbuf->w == NULL)
|
||||
return (-1);
|
||||
imsgbuf->pid = getpid();
|
||||
imsgbuf->maxsize = MAX_IMSGSIZE;
|
||||
imsgbuf->fd = fd;
|
||||
imsgbuf->flags = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||
imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
msgbuf_init(&ibuf->w);
|
||||
memset(&ibuf->r, 0, sizeof(ibuf->r));
|
||||
ibuf->fd = fd;
|
||||
ibuf->w.fd = fd;
|
||||
ibuf->pid = getpid();
|
||||
TAILQ_INIT(&ibuf->fds);
|
||||
imsgbuf->flags |= IMSG_ALLOW_FDPASS;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
imsg_read(struct imsgbuf *ibuf)
|
||||
int
|
||||
imsgbuf_set_maxsize(struct imsgbuf *imsgbuf, uint32_t max)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct cmsghdr *cmsg;
|
||||
union {
|
||||
struct cmsghdr hdr;
|
||||
char buf[CMSG_SPACE(sizeof(int) * 1)];
|
||||
} cmsgbuf;
|
||||
struct iovec iov;
|
||||
ssize_t n = -1;
|
||||
int fd;
|
||||
struct imsg_fd *ifd;
|
||||
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
|
||||
|
||||
iov.iov_base = ibuf->r.buf + ibuf->r.wpos;
|
||||
iov.iov_len = sizeof(ibuf->r.buf) - ibuf->r.wpos;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = &cmsgbuf.buf;
|
||||
msg.msg_controllen = sizeof(cmsgbuf.buf);
|
||||
|
||||
if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL)
|
||||
return (-1);
|
||||
|
||||
again:
|
||||
if (getdtablecount() + imsg_fd_overhead +
|
||||
(int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
|
||||
>= getdtablesize()) {
|
||||
errno = EAGAIN;
|
||||
free(ifd);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
|
||||
if (errno == EINTR)
|
||||
goto again;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ibuf->r.wpos += n;
|
||||
|
||||
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
|
||||
cmsg = CMSG_NXTHDR(&msg, cmsg)) {
|
||||
if (cmsg->cmsg_level == SOL_SOCKET &&
|
||||
cmsg->cmsg_type == SCM_RIGHTS) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
/*
|
||||
* We only accept one file descriptor. Due to C
|
||||
* padding rules, our control buffer might contain
|
||||
* more than one fd, and we must close them.
|
||||
*/
|
||||
j = ((char *)cmsg + cmsg->cmsg_len -
|
||||
(char *)CMSG_DATA(cmsg)) / sizeof(int);
|
||||
for (i = 0; i < j; i++) {
|
||||
fd = ((int *)CMSG_DATA(cmsg))[i];
|
||||
if (ifd != NULL) {
|
||||
ifd->fd = fd;
|
||||
TAILQ_INSERT_TAIL(&ibuf->fds, ifd,
|
||||
entry);
|
||||
ifd = NULL;
|
||||
} else
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
/* we do not handle other ctl data level */
|
||||
}
|
||||
|
||||
fail:
|
||||
free(ifd);
|
||||
return (n);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
|
||||
{
|
||||
size_t av, left, datalen;
|
||||
|
||||
av = ibuf->r.wpos;
|
||||
|
||||
if (IMSG_HEADER_SIZE > av)
|
||||
return (0);
|
||||
|
||||
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
|
||||
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
|
||||
imsg->hdr.len > MAX_IMSGSIZE) {
|
||||
if (max > UINT32_MAX - IMSG_HEADER_SIZE) {
|
||||
errno = ERANGE;
|
||||
return (-1);
|
||||
}
|
||||
if (imsg->hdr.len > av)
|
||||
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)
|
||||
max += IMSG_HEADER_SIZE;
|
||||
if (max & IMSG_FD_MARK) {
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
|
||||
if (imsg->hdr.flags & IMSGF_HASFD)
|
||||
imsg->fd = imsg_get_fd(ibuf);
|
||||
else
|
||||
imsg->fd = -1;
|
||||
|
||||
memcpy(imsg->data, ibuf->r.rptr, datalen);
|
||||
|
||||
if (imsg->hdr.len < av) {
|
||||
left = av - imsg->hdr.len;
|
||||
memmove(&ibuf->r.buf, ibuf->r.buf + imsg->hdr.len, left);
|
||||
ibuf->r.wpos = left;
|
||||
} else
|
||||
ibuf->r.wpos = 0;
|
||||
|
||||
return (datalen + IMSG_HEADER_SIZE);
|
||||
}
|
||||
imsgbuf->maxsize = max;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_compose(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
int fd, const void *data, uint16_t datalen)
|
||||
imsgbuf_read(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
if (imsgbuf->flags & IMSG_ALLOW_FDPASS)
|
||||
return msgbuf_read(imsgbuf->fd, imsgbuf->w);
|
||||
else
|
||||
return ibuf_read(imsgbuf->fd, imsgbuf->w);
|
||||
}
|
||||
|
||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||
int
|
||||
imsgbuf_write(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
if (imsgbuf->flags & IMSG_ALLOW_FDPASS)
|
||||
return msgbuf_write(imsgbuf->fd, imsgbuf->w);
|
||||
else
|
||||
return ibuf_write(imsgbuf->fd, imsgbuf->w);
|
||||
}
|
||||
|
||||
int
|
||||
imsgbuf_flush(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
while (imsgbuf_queuelen(imsgbuf) > 0) {
|
||||
if (imsgbuf_write(imsgbuf) == -1)
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
imsgbuf_clear(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
msgbuf_free(imsgbuf->w);
|
||||
imsgbuf->w = NULL;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
imsgbuf_queuelen(struct imsgbuf *imsgbuf)
|
||||
{
|
||||
return msgbuf_queuelen(imsgbuf->w);
|
||||
}
|
||||
|
||||
int
|
||||
imsgbuf_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
|
||||
{
|
||||
struct imsg m;
|
||||
struct ibuf *buf;
|
||||
|
||||
if ((buf = msgbuf_get(imsgbuf->w)) == NULL)
|
||||
return (0);
|
||||
|
||||
if (ibuf_get(buf, &m.hdr, sizeof(m.hdr)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (imsg_add(wbuf, data, datalen) == -1)
|
||||
return (-1);
|
||||
|
||||
wbuf->fd = fd;
|
||||
|
||||
imsg_close(ibuf, wbuf);
|
||||
if (ibuf_size(buf))
|
||||
m.data = ibuf_data(buf);
|
||||
else
|
||||
m.data = NULL;
|
||||
m.buf = buf;
|
||||
m.hdr.len &= ~IMSG_FD_MARK;
|
||||
|
||||
*imsg = m;
|
||||
return (1);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
imsg_get(struct imsgbuf *imsgbuf, struct imsg *imsg)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if ((rv = imsgbuf_get(imsgbuf, imsg)) != 1)
|
||||
return rv;
|
||||
return (imsg_get_len(imsg) + IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_composev(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
imsg_ibufq_pop(struct ibufqueue *bufq, struct imsg *imsg)
|
||||
{
|
||||
struct imsg m;
|
||||
struct ibuf *buf;
|
||||
|
||||
if ((buf = ibufq_pop(bufq)) == NULL)
|
||||
return (0);
|
||||
|
||||
if (ibuf_get(buf, &m.hdr, sizeof(m.hdr)) == -1)
|
||||
return (-1);
|
||||
|
||||
if (ibuf_size(buf))
|
||||
m.data = ibuf_data(buf);
|
||||
else
|
||||
m.data = NULL;
|
||||
m.buf = buf;
|
||||
m.hdr.len &= ~IMSG_FD_MARK;
|
||||
|
||||
*imsg = m;
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_ibufq_push(struct ibufqueue *bufq, struct imsg *imsg)
|
||||
{
|
||||
ibuf_rewind(imsg->buf);
|
||||
ibufq_push(bufq, imsg->buf);
|
||||
memset(imsg, 0, sizeof(*imsg));
|
||||
}
|
||||
|
||||
int
|
||||
imsg_get_ibuf(struct imsg *imsg, struct ibuf *ibuf)
|
||||
{
|
||||
if (ibuf_size(imsg->buf) == 0) {
|
||||
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 (ibuf_size(imsg->buf) != len) {
|
||||
errno = EBADMSG;
|
||||
return (-1);
|
||||
}
|
||||
return ibuf_get(imsg->buf, data, len);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_get_buf(struct imsg *imsg, void *data, size_t len)
|
||||
{
|
||||
return ibuf_get(imsg->buf, data, len);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_get_strbuf(struct imsg *imsg, char *str, size_t len)
|
||||
{
|
||||
return ibuf_get_strbuf(imsg->buf, str, len);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_get_fd(struct imsg *imsg)
|
||||
{
|
||||
return ibuf_fd_get(imsg->buf);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
imsg_get_id(struct imsg *imsg)
|
||||
{
|
||||
return (imsg->hdr.peerid);
|
||||
}
|
||||
|
||||
size_t
|
||||
imsg_get_len(struct imsg *imsg)
|
||||
{
|
||||
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;
|
||||
|
||||
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
|
||||
goto fail;
|
||||
|
||||
if (ibuf_add(wbuf, data, datalen) == -1)
|
||||
goto fail;
|
||||
|
||||
ibuf_fd_set(wbuf, fd);
|
||||
imsg_close(imsgbuf, wbuf);
|
||||
|
||||
return (1);
|
||||
|
||||
fail:
|
||||
ibuf_free(wbuf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_composev(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
|
||||
int fd, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
int i, datalen = 0;
|
||||
int i;
|
||||
size_t datalen = 0;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
datalen += iov[i].iov_len;
|
||||
|
||||
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
|
||||
return (-1);
|
||||
if ((wbuf = imsg_create(imsgbuf, type, id, pid, datalen)) == NULL)
|
||||
goto fail;
|
||||
|
||||
for (i = 0; i < iovcnt; i++)
|
||||
if (imsg_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
|
||||
if (ibuf_add(wbuf, iov[i].iov_base, iov[i].iov_len) == -1)
|
||||
goto fail;
|
||||
|
||||
ibuf_fd_set(wbuf, fd);
|
||||
imsg_close(imsgbuf, wbuf);
|
||||
|
||||
return (1);
|
||||
|
||||
fail:
|
||||
ibuf_free(wbuf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
if (ibuf_size(buf) + IMSG_HEADER_SIZE > imsgbuf->maxsize) {
|
||||
errno = ERANGE;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
hdr.type = type;
|
||||
hdr.len = ibuf_size(buf) + IMSG_HEADER_SIZE;
|
||||
hdr.peerid = id;
|
||||
if ((hdr.pid = pid) == 0)
|
||||
hdr.pid = imsgbuf->pid;
|
||||
|
||||
if ((hdrbuf = ibuf_open(IMSG_HEADER_SIZE)) == NULL)
|
||||
goto fail;
|
||||
if (ibuf_add(hdrbuf, &hdr, sizeof(hdr)) == -1)
|
||||
goto fail;
|
||||
|
||||
ibuf_close(imsgbuf->w, hdrbuf);
|
||||
ibuf_close(imsgbuf->w, buf);
|
||||
return (1);
|
||||
|
||||
fail:
|
||||
ibuf_free(buf);
|
||||
ibuf_free(hdrbuf);
|
||||
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;
|
||||
|
||||
ibuf_rewind(msg->buf);
|
||||
ibuf_skip(msg->buf, sizeof(msg->hdr));
|
||||
len = ibuf_size(msg->buf);
|
||||
|
||||
if ((wbuf = imsg_create(imsgbuf, msg->hdr.type, msg->hdr.peerid,
|
||||
msg->hdr.pid, len)) == NULL)
|
||||
return (-1);
|
||||
|
||||
if (len != 0) {
|
||||
if (ibuf_add_ibuf(wbuf, msg->buf) == -1) {
|
||||
ibuf_free(wbuf);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
wbuf->fd = fd;
|
||||
|
||||
imsg_close(ibuf, wbuf);
|
||||
|
||||
imsg_close(imsgbuf, wbuf);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
struct ibuf *
|
||||
imsg_create(struct imsgbuf *ibuf, uint32_t type, uint32_t peerid, pid_t pid,
|
||||
uint16_t datalen)
|
||||
imsg_create(struct imsgbuf *imsgbuf, uint32_t type, uint32_t id, pid_t pid,
|
||||
size_t datalen)
|
||||
{
|
||||
struct ibuf *wbuf;
|
||||
struct imsg_hdr hdr;
|
||||
|
||||
datalen += IMSG_HEADER_SIZE;
|
||||
if (datalen > MAX_IMSGSIZE) {
|
||||
if (datalen > imsgbuf->maxsize) {
|
||||
errno = ERANGE;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
hdr.len = 0;
|
||||
hdr.type = type;
|
||||
hdr.flags = 0;
|
||||
hdr.peerid = peerid;
|
||||
hdr.peerid = id;
|
||||
if ((hdr.pid = pid) == 0)
|
||||
hdr.pid = ibuf->pid;
|
||||
if ((wbuf = ibuf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
||||
return (NULL);
|
||||
hdr.pid = imsgbuf->pid;
|
||||
if ((wbuf = ibuf_dynamic(datalen, imsgbuf->maxsize)) == NULL)
|
||||
goto fail;
|
||||
if (ibuf_add(wbuf, &hdr, sizeof(hdr)) == -1)
|
||||
goto fail;
|
||||
|
||||
return (wbuf);
|
||||
|
||||
fail:
|
||||
ibuf_free(wbuf);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
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 (ibuf_add(msg, data, datalen) == -1) {
|
||||
@@ -245,58 +399,56 @@ imsg_add(struct ibuf *msg, const void *data, uint16_t datalen)
|
||||
}
|
||||
|
||||
void
|
||||
imsg_close(struct imsgbuf *ibuf, struct ibuf *msg)
|
||||
imsg_close(struct imsgbuf *imsgbuf, struct ibuf *msg)
|
||||
{
|
||||
struct imsg_hdr *hdr;
|
||||
uint32_t len;
|
||||
|
||||
hdr = (struct imsg_hdr *)msg->buf;
|
||||
|
||||
hdr->flags &= ~IMSGF_HASFD;
|
||||
if (msg->fd != -1)
|
||||
hdr->flags |= IMSGF_HASFD;
|
||||
|
||||
hdr->len = (uint16_t)msg->wpos;
|
||||
|
||||
ibuf_close(&ibuf->w, msg);
|
||||
len = ibuf_size(msg);
|
||||
if (ibuf_fd_avail(msg))
|
||||
len |= IMSG_FD_MARK;
|
||||
(void)ibuf_set_h32(msg, offsetof(struct imsg_hdr, len), len);
|
||||
ibuf_close(imsgbuf->w, msg);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_free(struct imsg *imsg)
|
||||
{
|
||||
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
static int
|
||||
imsg_get_fd(struct imsgbuf *ibuf)
|
||||
{
|
||||
int fd;
|
||||
struct imsg_fd *ifd;
|
||||
|
||||
if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL)
|
||||
return (-1);
|
||||
|
||||
fd = ifd->fd;
|
||||
TAILQ_REMOVE(&ibuf->fds, ifd, entry);
|
||||
free(ifd);
|
||||
|
||||
return (fd);
|
||||
ibuf_free(imsg->buf);
|
||||
}
|
||||
|
||||
int
|
||||
imsg_flush(struct imsgbuf *ibuf)
|
||||
imsg_set_maxsize(struct ibuf *msg, size_t max)
|
||||
{
|
||||
while (ibuf->w.queued)
|
||||
if (msgbuf_write(&ibuf->w) <= 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
if (max > UINT32_MAX - IMSG_HEADER_SIZE) {
|
||||
errno = ERANGE;
|
||||
return (-1);
|
||||
}
|
||||
return ibuf_set_maxsize(msg, max + IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
void
|
||||
imsg_clear(struct imsgbuf *ibuf)
|
||||
static struct ibuf *
|
||||
imsg_parse_hdr(struct ibuf *buf, void *arg, int *fd)
|
||||
{
|
||||
int fd;
|
||||
struct imsgbuf *imsgbuf = arg;
|
||||
struct imsg_hdr hdr;
|
||||
struct ibuf *b;
|
||||
uint32_t len;
|
||||
|
||||
msgbuf_clear(&ibuf->w);
|
||||
while ((fd = imsg_get_fd(ibuf)) != -1)
|
||||
close(fd);
|
||||
if (ibuf_get(buf, &hdr, sizeof(hdr)) == -1)
|
||||
return (NULL);
|
||||
|
||||
len = hdr.len & ~IMSG_FD_MARK;
|
||||
|
||||
if (len < IMSG_HEADER_SIZE || len > imsgbuf->maxsize) {
|
||||
errno = ERANGE;
|
||||
return (NULL);
|
||||
}
|
||||
if ((b = ibuf_open(len)) == NULL)
|
||||
return (NULL);
|
||||
if (hdr.len & IMSG_FD_MARK) {
|
||||
ibuf_fd_set(b, *fd);
|
||||
*fd = -1;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
142
compat/imsg.h
142
compat/imsg.h
@@ -1,6 +1,7 @@
|
||||
/* $OpenBSD: imsg.h,v 1.5 2019/01/20 02:50:03 bcook Exp $ */
|
||||
/* $OpenBSD: imsg.h,v 1.24 2025/06/05 08:55:07 tb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2023 Claudio Jeker <claudio@openbsd.org>
|
||||
* Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
|
||||
* Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@@ -21,7 +22,8 @@
|
||||
#ifndef _IMSG_H_
|
||||
#define _IMSG_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define IBUF_READ_SIZE 65535
|
||||
#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
|
||||
@@ -37,77 +39,135 @@ struct ibuf {
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct msgbuf {
|
||||
TAILQ_HEAD(, ibuf) bufs;
|
||||
uint32_t queued;
|
||||
int fd;
|
||||
};
|
||||
|
||||
struct ibuf_read {
|
||||
unsigned char buf[IBUF_READ_SIZE];
|
||||
unsigned char *rptr;
|
||||
size_t wpos;
|
||||
};
|
||||
|
||||
struct imsg_fd {
|
||||
TAILQ_ENTRY(imsg_fd) entry;
|
||||
int fd;
|
||||
};
|
||||
struct ibufqueue;
|
||||
struct msgbuf;
|
||||
|
||||
struct imsgbuf {
|
||||
TAILQ_HEAD(, imsg_fd) fds;
|
||||
struct ibuf_read r;
|
||||
struct msgbuf w;
|
||||
int fd;
|
||||
struct msgbuf *w;
|
||||
pid_t pid;
|
||||
uint32_t maxsize;
|
||||
int fd;
|
||||
int flags;
|
||||
};
|
||||
|
||||
#define IMSGF_HASFD 1
|
||||
|
||||
struct imsg_hdr {
|
||||
uint32_t type;
|
||||
uint16_t len;
|
||||
uint16_t flags;
|
||||
uint32_t len;
|
||||
uint32_t peerid;
|
||||
uint32_t pid;
|
||||
};
|
||||
|
||||
struct imsg {
|
||||
struct imsg_hdr hdr;
|
||||
int fd;
|
||||
void *data;
|
||||
struct ibuf *buf;
|
||||
};
|
||||
|
||||
struct iovec;
|
||||
|
||||
/* buffer.c */
|
||||
/* imsg-buffer.c */
|
||||
struct ibuf *ibuf_open(size_t);
|
||||
struct ibuf *ibuf_dynamic(size_t, size_t);
|
||||
int ibuf_add(struct ibuf *, const void *, size_t);
|
||||
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);
|
||||
int ibuf_add_strbuf(struct ibuf *, const char *, size_t);
|
||||
void *ibuf_reserve(struct ibuf *, size_t);
|
||||
void *ibuf_seek(struct ibuf *, size_t, size_t);
|
||||
size_t ibuf_size(struct ibuf *);
|
||||
size_t ibuf_left(struct ibuf *);
|
||||
int ibuf_set(struct ibuf *, size_t, const void *, size_t);
|
||||
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);
|
||||
int ibuf_set_maxsize(struct ibuf *, size_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 *);
|
||||
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 *);
|
||||
char *ibuf_get_string(struct ibuf *, size_t);
|
||||
int ibuf_get_strbuf(struct ibuf *, char *, size_t);
|
||||
int ibuf_skip(struct ibuf *, size_t);
|
||||
void ibuf_free(struct ibuf *);
|
||||
void msgbuf_init(struct msgbuf *);
|
||||
int ibuf_fd_avail(struct ibuf *);
|
||||
int ibuf_fd_get(struct ibuf *);
|
||||
void ibuf_fd_set(struct ibuf *, int);
|
||||
struct msgbuf *msgbuf_new(void);
|
||||
struct msgbuf *msgbuf_new_reader(size_t,
|
||||
struct ibuf *(*)(struct ibuf *, void *, int *), void *);
|
||||
void msgbuf_free(struct msgbuf *);
|
||||
void msgbuf_clear(struct msgbuf *);
|
||||
int msgbuf_write(struct msgbuf *);
|
||||
void msgbuf_drain(struct msgbuf *, size_t);
|
||||
void msgbuf_concat(struct msgbuf *, struct ibufqueue *);
|
||||
uint32_t msgbuf_queuelen(struct msgbuf *);
|
||||
int ibuf_write(int, struct msgbuf *);
|
||||
int msgbuf_write(int, struct msgbuf *);
|
||||
int ibuf_read(int, struct msgbuf *);
|
||||
int msgbuf_read(int, struct msgbuf *);
|
||||
struct ibuf *msgbuf_get(struct msgbuf *);
|
||||
|
||||
struct ibufqueue *ibufq_new(void);
|
||||
void ibufq_free(struct ibufqueue *);
|
||||
struct ibuf *ibufq_pop(struct ibufqueue *bufq);
|
||||
void ibufq_push(struct ibufqueue *, struct ibuf *);
|
||||
uint32_t ibufq_queuelen(struct ibufqueue *);
|
||||
void ibufq_concat(struct ibufqueue *, struct ibufqueue *);
|
||||
void ibufq_flush(struct ibufqueue *);
|
||||
|
||||
/* imsg.c */
|
||||
void imsg_init(struct imsgbuf *, int);
|
||||
ssize_t imsg_read(struct imsgbuf *);
|
||||
int imsgbuf_init(struct imsgbuf *, int);
|
||||
void imsgbuf_allow_fdpass(struct imsgbuf *imsgbuf);
|
||||
int imsgbuf_set_maxsize(struct imsgbuf *, uint32_t);
|
||||
int imsgbuf_read(struct imsgbuf *);
|
||||
int imsgbuf_write(struct imsgbuf *);
|
||||
int imsgbuf_flush(struct imsgbuf *);
|
||||
void imsgbuf_clear(struct imsgbuf *);
|
||||
uint32_t imsgbuf_queuelen(struct imsgbuf *);
|
||||
int imsgbuf_get(struct imsgbuf *, struct imsg *);
|
||||
ssize_t imsg_get(struct imsgbuf *, struct imsg *);
|
||||
int imsg_ibufq_pop(struct ibufqueue *, struct imsg *);
|
||||
void imsg_ibufq_push(struct ibufqueue *, struct imsg *);
|
||||
int imsg_get_ibuf(struct imsg *, struct ibuf *);
|
||||
int imsg_get_data(struct imsg *, void *, size_t);
|
||||
int imsg_get_buf(struct imsg *, void *, size_t);
|
||||
int imsg_get_strbuf(struct imsg *, char *, size_t);
|
||||
int imsg_get_fd(struct imsg *);
|
||||
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,
|
||||
const void *, uint16_t);
|
||||
const void *, size_t);
|
||||
int imsg_composev(struct imsgbuf *, uint32_t, uint32_t, pid_t, int,
|
||||
const struct iovec *, int);
|
||||
struct ibuf *imsg_create(struct imsgbuf *, uint32_t, uint32_t, pid_t, uint16_t);
|
||||
int imsg_add(struct ibuf *, const void *, uint16_t);
|
||||
int imsg_compose_ibuf(struct imsgbuf *, uint32_t, uint32_t, pid_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_free(struct imsg *);
|
||||
int imsg_flush(struct imsgbuf *);
|
||||
void imsg_clear(struct imsgbuf *);
|
||||
int imsg_set_maxsize(struct ibuf *, size_t);
|
||||
|
||||
#endif
|
||||
|
||||
31
compat/ntohll.c
Normal file
31
compat/ntohll.c
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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 <arpa/inet.h>
|
||||
#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);
|
||||
}
|
||||
@@ -32,8 +32,8 @@
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
*/
|
||||
|
||||
#ifndef _SYS_QUEUE_H_
|
||||
#define _SYS_QUEUE_H_
|
||||
#ifndef _COMPAT_QUEUE_H_
|
||||
#define _COMPAT_QUEUE_H_
|
||||
|
||||
/*
|
||||
* This file defines five types of data structures: singly-linked lists,
|
||||
@@ -530,4 +530,4 @@ struct { \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif /* !_SYS_QUEUE_H_ */
|
||||
#endif /* !_COMPAT_QUEUE_H_ */
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
270
compat/systemd.c
270
compat/systemd.c
@@ -19,17 +19,35 @@
|
||||
#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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#ifndef SD_ID128_UUID_FORMAT_STR
|
||||
#define SD_ID128_UUID_FORMAT_STR \
|
||||
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"
|
||||
#endif
|
||||
|
||||
int
|
||||
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;
|
||||
int addrlen = sizeof sa;
|
||||
socklen_t addrlen = sizeof sa;
|
||||
|
||||
fds = sd_listen_fds(0);
|
||||
if (fds > 1) { /* too many file descriptors */
|
||||
@@ -56,3 +74,253 @@ fail:
|
||||
xasprintf(cause, "systemd socket error (%s)", strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
struct systemd_job_watch {
|
||||
const char *path;
|
||||
int done;
|
||||
};
|
||||
|
||||
static int
|
||||
job_removed_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error)
|
||||
{
|
||||
struct systemd_job_watch *watch = userdata;
|
||||
const char *path = NULL;
|
||||
uint32_t id;
|
||||
int r;
|
||||
|
||||
/* This handler could be called during the sd_bus_call. */
|
||||
if (watch->path == NULL)
|
||||
return 0;
|
||||
|
||||
r = sd_bus_message_read(m, "uo", &id, &path);
|
||||
if (r < 0)
|
||||
return (r);
|
||||
|
||||
if (strcmp(path, watch->path) == 0)
|
||||
watch->done = 1;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
systemd_move_to_new_cgroup(char **cause)
|
||||
{
|
||||
sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
sd_bus_message *m = NULL, *reply = NULL;
|
||||
sd_bus *bus = NULL;
|
||||
sd_bus_slot *slot = NULL;
|
||||
char *name, *desc, *slice;
|
||||
sd_id128_t uuid;
|
||||
int r;
|
||||
uint64_t elapsed_usec;
|
||||
pid_t pid, parent_pid;
|
||||
struct timeval start, now;
|
||||
struct systemd_job_watch watch = {};
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
/* Connect to the session bus. */
|
||||
r = sd_bus_default_user(&bus);
|
||||
if (r < 0) {
|
||||
xasprintf(cause, "failed to connect to session bus: %s",
|
||||
strerror(-r));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Start watching for JobRemoved events */
|
||||
r = sd_bus_match_signal(bus, &slot,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"JobRemoved",
|
||||
job_removed_handler,
|
||||
&watch);
|
||||
if (r < 0) {
|
||||
xasprintf(cause, "failed to create match signal: %s",
|
||||
strerror(-r));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/* Start building the method call. */
|
||||
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;
|
||||
}
|
||||
|
||||
pid = getpid();
|
||||
parent_pid = getppid();
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Make sure that the session shells are terminated with SIGHUP since
|
||||
* bash and friends tend to ignore SIGTERM.
|
||||
*/
|
||||
r = sd_bus_message_append(m, "(sv)", "SendSIGHUP", "b", 1);
|
||||
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;
|
||||
}
|
||||
|
||||
/* Get the job (object path) from the reply */
|
||||
r = sd_bus_message_read(reply, "o", &watch.path);
|
||||
if (r < 0) {
|
||||
xasprintf(cause, "failed to parse method reply: %s",
|
||||
strerror(-r));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
while (!watch.done) {
|
||||
/* Process events including callbacks. */
|
||||
r = sd_bus_process(bus, NULL);
|
||||
if (r < 0) {
|
||||
xasprintf(cause,
|
||||
"failed waiting for cgroup allocation: %s",
|
||||
strerror(-r));
|
||||
goto finish;
|
||||
}
|
||||
|
||||
/*
|
||||
* A positive return means we handled an event and should keep
|
||||
* processing; zero indicates no events available, so wait.
|
||||
*/
|
||||
if (r > 0)
|
||||
continue;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
elapsed_usec = (now.tv_sec - start.tv_sec) * 1000000 +
|
||||
now.tv_usec - start.tv_usec;
|
||||
|
||||
if (elapsed_usec >= 1000000) {
|
||||
xasprintf(cause,
|
||||
"timeout waiting for cgroup allocation");
|
||||
goto finish;
|
||||
}
|
||||
|
||||
r = sd_bus_wait(bus, 1000000 - elapsed_usec);
|
||||
if (r < 0) {
|
||||
xasprintf(cause,
|
||||
"failed waiting for cgroup allocation: %s",
|
||||
strerror(-r));
|
||||
goto finish;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
sd_bus_error_free(&error);
|
||||
sd_bus_message_unref(m);
|
||||
sd_bus_message_unref(reply);
|
||||
sd_bus_slot_unref(slot);
|
||||
sd_bus_unref(bus);
|
||||
|
||||
return (r);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ utf8proc_mbtowc(wchar_t *pwc, const char *s, size_t n)
|
||||
* *pwc == -1 indicates invalid codepoint
|
||||
* slen < 0 indicates an error
|
||||
*/
|
||||
slen = utf8proc_iterate(s, n, pwc);
|
||||
slen = utf8proc_iterate(s, n, (utf8proc_int32_t*)pwc);
|
||||
if (*pwc == (wchar_t)-1 || slen < 0)
|
||||
return (-1);
|
||||
return (slen);
|
||||
|
||||
135
configure.ac
135
configure.ac
@@ -1,6 +1,6 @@
|
||||
# configure.ac
|
||||
|
||||
AC_INIT([tmux], 3.3)
|
||||
AC_INIT([tmux], next-3.7)
|
||||
AC_PREREQ([2.60])
|
||||
|
||||
AC_CONFIG_AUX_DIR(etc)
|
||||
@@ -44,7 +44,7 @@ fi
|
||||
# Set up the compiler in two different ways and say yes we may want to install.
|
||||
AC_PROG_CC
|
||||
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_EGREP
|
||||
AC_PROG_INSTALL
|
||||
@@ -56,13 +56,23 @@ AC_USE_SYSTEM_EXTENSIONS
|
||||
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
||||
|
||||
# Is this --enable-debug?
|
||||
case "x$VERSION" in xnext*) enable_debug=yes;; esac
|
||||
AC_ARG_ENABLE(
|
||||
debug,
|
||||
AS_HELP_STRING(--enable-debug, enable debug build flags),
|
||||
,
|
||||
[case "x$VERSION" in xnext*) enable_debug=yes;; esac]
|
||||
)
|
||||
AM_CONDITIONAL(IS_DEBUG, test "x$enable_debug" = xyes)
|
||||
|
||||
# Is this --enable-optimizations?
|
||||
AC_ARG_ENABLE(
|
||||
optimizations,
|
||||
AS_HELP_STRING(--enable-optimizations, enable optimization build flags),
|
||||
,
|
||||
enable_optimizations=yes
|
||||
)
|
||||
AM_CONDITIONAL(IS_OPTIMIZED, test "x$enable_optimizations" = xyes)
|
||||
|
||||
# Is this a static build?
|
||||
AC_ARG_ENABLE(
|
||||
static,
|
||||
@@ -148,7 +158,7 @@ AC_CHECK_FUNCS([ \
|
||||
prctl \
|
||||
proc_pidinfo \
|
||||
getpeerucred \
|
||||
sysconf \
|
||||
sysconf
|
||||
])
|
||||
|
||||
# Check for functions with a compatibility implementation.
|
||||
@@ -165,7 +175,9 @@ AC_REPLACE_FUNCS([ \
|
||||
getpeereid \
|
||||
getline \
|
||||
getprogname \
|
||||
htonll \
|
||||
memmem \
|
||||
ntohll \
|
||||
setenv \
|
||||
setproctitle \
|
||||
strcasestr \
|
||||
@@ -216,7 +228,7 @@ AC_SEARCH_LIBS(clock_gettime, rt)
|
||||
# musl does not set optarg to NULL for flags without arguments (although it is
|
||||
# not required to, but it is helpful) 3) there are probably other weird
|
||||
# implementations.
|
||||
AC_LIBOBJ(getopt)
|
||||
AC_LIBOBJ(getopt_long)
|
||||
|
||||
# Look for libevent. Try libevent_core or libevent with pkg-config first then
|
||||
# look for the library.
|
||||
@@ -267,6 +279,12 @@ if test "x$found_libevent" = xno; then
|
||||
AC_MSG_ERROR("libevent not found")
|
||||
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
|
||||
# library.
|
||||
PKG_CHECK_MODULES(
|
||||
@@ -309,7 +327,7 @@ fi
|
||||
if test "x$found_ncurses" = xno; then
|
||||
AC_SEARCH_LIBS(
|
||||
setupterm,
|
||||
[tinfo ncurses ncursesw],
|
||||
[tinfo terminfo ncurses ncursesw],
|
||||
found_ncurses=yes,
|
||||
found_ncurses=no
|
||||
)
|
||||
@@ -344,6 +362,10 @@ else
|
||||
AC_MSG_ERROR("curses not found")
|
||||
fi
|
||||
fi
|
||||
AC_CHECK_FUNCS([ \
|
||||
tiparm \
|
||||
tiparm_s \
|
||||
])
|
||||
|
||||
# Look for utempter.
|
||||
AC_ARG_ENABLE(
|
||||
@@ -373,6 +395,15 @@ AC_ARG_ENABLE(
|
||||
AS_HELP_STRING(--enable-utf8proc, use utf8proc if it is installed)
|
||||
)
|
||||
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)
|
||||
if test "x$enable_utf8proc" = xyes; then
|
||||
AC_SEARCH_LIBS(
|
||||
@@ -414,10 +445,54 @@ if test x"$enable_systemd" = xyes; then
|
||||
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-images,
|
||||
AS_HELP_STRING(--enable-sixel-images, enable sixel images)
|
||||
)
|
||||
|
||||
AC_ARG_ENABLE(
|
||||
sixel,
|
||||
AS_HELP_STRING(--enable-sixel support),
|
||||
[
|
||||
enable_sixel_images="$enableval"
|
||||
]
|
||||
)
|
||||
|
||||
if test "x$enable_sixel_images" = xyes; then
|
||||
AC_DEFINE(ENABLE_SIXEL_IMAGES)
|
||||
fi
|
||||
AM_CONDITIONAL(ENABLE_SIXEL_IMAGES, [test "x$enable_sixel_images" = xyes])
|
||||
|
||||
# Enable kitty graphics protocol support.
|
||||
AC_ARG_ENABLE(
|
||||
kitty-images,
|
||||
AS_HELP_STRING(--enable-kitty-images, enable kitty terminal graphics)
|
||||
)
|
||||
if test "x$enable_kitty_images" = xyes; then
|
||||
AC_DEFINE(ENABLE_KITTY_IMAGES)
|
||||
fi
|
||||
AM_CONDITIONAL(ENABLE_KITTY_IMAGES, [test "x$enable_kitty_images" = xyes])
|
||||
|
||||
# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
|
||||
AC_MSG_CHECKING(for b64_ntop)
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(
|
||||
[
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
@@ -502,6 +577,24 @@ if test "x$found_malloc_trim" = xyes; then
|
||||
AC_DEFINE(HAVE_MALLOC_TRIM)
|
||||
fi
|
||||
|
||||
# Build against jemalloc if requested.
|
||||
AC_ARG_ENABLE(
|
||||
jemalloc,
|
||||
AS_HELP_STRING(--enable-jemalloc, use jemalloc if it is installed)
|
||||
)
|
||||
if test "x$enable_jemalloc" = xyes; then
|
||||
PKG_CHECK_MODULES(
|
||||
JEMALLOC,
|
||||
jemalloc,
|
||||
[
|
||||
AM_CPPFLAGS="$JEMALLOC_CFLAGS $AM_CPPFLAGS"
|
||||
CPPFLAGS="$AM_CPPFLAGS $SAVED_CPPFLAGS"
|
||||
LIBS="$LIBS $JEMALLOC_LIBS"
|
||||
],
|
||||
AC_MSG_ERROR("jemalloc not found")
|
||||
)
|
||||
fi
|
||||
|
||||
# Check for CMSG_DATA. On some platforms like HP-UX this requires UNIX 95
|
||||
# (_XOPEN_SOURCE and _XOPEN_SOURCE_EXTENDED) (see xopen_networking(7)). On
|
||||
# others, UNIX 03 (_XOPEN_SOURCE 600, see standards(7) on Solaris).
|
||||
@@ -573,9 +666,9 @@ else
|
||||
AC_LIBOBJ(err)
|
||||
fi
|
||||
|
||||
# Look for imsg_init in libutil.
|
||||
AC_SEARCH_LIBS(imsg_init, util, found_imsg_init=yes, found_imsg_init=no)
|
||||
if test "x$found_imsg_init" = xyes; then
|
||||
# Look for imsg_add in libutil.
|
||||
AC_SEARCH_LIBS(imsg_add, util, found_imsg_add=yes, found_imsg_add=no)
|
||||
if test "x$found_imsg_add" = xyes; then
|
||||
AC_DEFINE(HAVE_IMSG)
|
||||
else
|
||||
AC_LIBOBJ(imsg)
|
||||
@@ -880,8 +973,13 @@ case "$host_os" in
|
||||
MANFORMAT=mdoc
|
||||
;;
|
||||
*)
|
||||
# Solaris 2.0 to 11.3 use AT&T nroff.
|
||||
MANFORMAT=man
|
||||
if test `uname -o 2>/dev/null` = illumos; then
|
||||
# Illumos uses mandoc.
|
||||
MANFORMAT=mdoc
|
||||
else
|
||||
# Solaris 2.0 to 11.3 use AT&T nroff.
|
||||
MANFORMAT=man
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
@@ -912,9 +1010,22 @@ AM_CONDITIONAL(IS_NETBSD, test "x$PLATFORM" = xnetbsd)
|
||||
AM_CONDITIONAL(IS_OPENBSD, test "x$PLATFORM" = xopenbsd)
|
||||
AM_CONDITIONAL(IS_SUNOS, test "x$PLATFORM" = xsunos)
|
||||
AM_CONDITIONAL(IS_HPUX, test "x$PLATFORM" = xhpux)
|
||||
AM_CONDITIONAL(IS_CYGWIN, test "x$PLATFORM" = xcygwin)
|
||||
AM_CONDITIONAL(IS_HAIKU, test "x$PLATFORM" = xhaiku)
|
||||
AM_CONDITIONAL(IS_UNKNOWN, test "x$PLATFORM" = xunknown)
|
||||
|
||||
# Set the default lock command
|
||||
DEFAULT_LOCK_CMD="lock -np"
|
||||
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_CHECKING(lock-command)
|
||||
AC_MSG_RESULT($DEFAULT_LOCK_CMD)
|
||||
AC_SUBST(DEFAULT_LOCK_CMD)
|
||||
|
||||
# Save our CFLAGS/CPPFLAGS/LDFLAGS for the Makefile and restore the old user
|
||||
# variables.
|
||||
AC_SUBST(AM_CPPFLAGS)
|
||||
|
||||
@@ -51,29 +51,24 @@ control_notify_window_layout_changed(struct window *w)
|
||||
template = "%layout-change #{window_id} #{window_layout} "
|
||||
"#{window_visible_layout} #{window_raw_flags}";
|
||||
|
||||
/*
|
||||
* When the last pane in a window is closed it won't have a layout root
|
||||
* and we don't need to inform the client about the layout change
|
||||
* because the whole window will go away soon.
|
||||
*/
|
||||
wl = TAILQ_FIRST(&w->winlinks);
|
||||
if (wl == NULL || w->layout_root == NULL)
|
||||
return;
|
||||
cp = format_single(NULL, template, NULL, NULL, wl, NULL);
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
continue;
|
||||
s = c->session;
|
||||
|
||||
if (winlink_find_by_window_id(&s->windows, w->id) == NULL)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* When the last pane in a window is closed it won't have a
|
||||
* layout root and we don't need to inform the client about the
|
||||
* layout change because the whole window will go away soon.
|
||||
*/
|
||||
if (w->layout_root == NULL)
|
||||
continue;
|
||||
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
if (wl != NULL) {
|
||||
cp = format_single(NULL, template, c, NULL, wl, NULL);
|
||||
if (winlink_find_by_window_id(&s->windows, w->id) != NULL)
|
||||
control_write(c, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
}
|
||||
free(cp);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -234,3 +229,29 @@ control_notify_session_window_changed(struct session *s)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
216
control.c
216
control.c
@@ -610,7 +610,7 @@ control_append_data(struct client *c, struct control_pane *cp, uint64_t age,
|
||||
struct evbuffer *message, struct window_pane *wp, size_t size)
|
||||
{
|
||||
u_char *new_data;
|
||||
size_t new_size;
|
||||
size_t new_size, start;
|
||||
u_int i;
|
||||
|
||||
if (message == NULL) {
|
||||
@@ -629,10 +629,16 @@ control_append_data(struct client *c, struct control_pane *cp, uint64_t age,
|
||||
if (new_size < size)
|
||||
fatalx("not enough data: %zu < %zu", new_size, size);
|
||||
for (i = 0; i < size; i++) {
|
||||
if (new_data[i] < ' ' || new_data[i] == '\\')
|
||||
if (new_data[i] < ' ' || new_data[i] == '\\') {
|
||||
evbuffer_add_printf(message, "\\%03o", new_data[i]);
|
||||
else
|
||||
evbuffer_add_printf(message, "%c", new_data[i]);
|
||||
} else {
|
||||
start = i;
|
||||
while (i + 1 < size &&
|
||||
new_data[i + 1] >= ' ' &&
|
||||
new_data[i + 1] != '\\')
|
||||
i++;
|
||||
evbuffer_add(message, new_data + start, i - start + 1);
|
||||
}
|
||||
}
|
||||
window_pane_update_used_data(wp, &cp->offset, size);
|
||||
return (message);
|
||||
@@ -775,13 +781,16 @@ control_start(struct client *c)
|
||||
|
||||
cs->read_event = bufferevent_new(c->fd, control_read_callback,
|
||||
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)
|
||||
cs->write_event = cs->read_event;
|
||||
else {
|
||||
cs->write_event = bufferevent_new(c->out_fd, NULL,
|
||||
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,
|
||||
0);
|
||||
@@ -792,6 +801,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. */
|
||||
void
|
||||
control_discard(struct client *c)
|
||||
@@ -830,15 +846,13 @@ control_stop(struct client *c)
|
||||
|
||||
/* Check session subscription. */
|
||||
static void
|
||||
control_check_subs_session(struct client *c, struct control_sub *csub)
|
||||
control_check_subs_session(struct client *c, struct control_sub *csub,
|
||||
struct format_tree *ft)
|
||||
{
|
||||
struct session *s = c->session;
|
||||
struct format_tree *ft;
|
||||
char *value;
|
||||
|
||||
ft = format_create_defaults(NULL, c, s, NULL, NULL);
|
||||
value = format_expand(ft, csub->format);
|
||||
format_free(ft);
|
||||
|
||||
if (csub->last != NULL && strcmp(value, csub->last) == 0) {
|
||||
free(value);
|
||||
@@ -899,48 +913,38 @@ control_check_subs_pane(struct client *c, struct control_sub *csub)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check all panes subscription. */
|
||||
/* Check all-panes subscription for a pane. */
|
||||
static void
|
||||
control_check_subs_all_panes(struct client *c, struct control_sub *csub)
|
||||
control_check_subs_all_panes_one(struct client *c, struct control_sub *csub,
|
||||
struct format_tree *ft, struct winlink *wl, struct window_pane *wp)
|
||||
{
|
||||
struct session *s = c->session;
|
||||
struct window_pane *wp;
|
||||
struct window *w;
|
||||
struct winlink *wl;
|
||||
struct format_tree *ft;
|
||||
struct window *w = wl->window;
|
||||
char *value;
|
||||
struct control_sub_pane *csp, find;
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
ft = format_create_defaults(NULL, c, s, wl, wp);
|
||||
value = format_expand(ft, csub->format);
|
||||
format_free(ft);
|
||||
value = format_expand(ft, csub->format);
|
||||
|
||||
find.pane = wp->id;
|
||||
find.idx = wl->idx;
|
||||
find.pane = wp->id;
|
||||
find.idx = wl->idx;
|
||||
|
||||
csp = RB_FIND(control_sub_panes, &csub->panes, &find);
|
||||
if (csp == NULL) {
|
||||
csp = xcalloc(1, sizeof *csp);
|
||||
csp->pane = wp->id;
|
||||
csp->idx = wl->idx;
|
||||
RB_INSERT(control_sub_panes, &csub->panes, csp);
|
||||
}
|
||||
|
||||
if (csp->last != NULL &&
|
||||
strcmp(value, csp->last) == 0) {
|
||||
free(value);
|
||||
continue;
|
||||
}
|
||||
control_write(c,
|
||||
"%%subscription-changed %s $%u @%u %u %%%u : %s",
|
||||
csub->name, s->id, w->id, wl->idx, wp->id, value);
|
||||
free(csp->last);
|
||||
csp->last = value;
|
||||
}
|
||||
csp = RB_FIND(control_sub_panes, &csub->panes, &find);
|
||||
if (csp == NULL) {
|
||||
csp = xcalloc(1, sizeof *csp);
|
||||
csp->pane = wp->id;
|
||||
csp->idx = wl->idx;
|
||||
RB_INSERT(control_sub_panes, &csub->panes, csp);
|
||||
}
|
||||
|
||||
if (csp->last != NULL && strcmp(value, csp->last) == 0) {
|
||||
free(value);
|
||||
return;
|
||||
}
|
||||
control_write(c,
|
||||
"%%subscription-changed %s $%u @%u %u %%%u : %s",
|
||||
csub->name, s->id, w->id, wl->idx, wp->id, value);
|
||||
free(csp->last);
|
||||
csp->last = value;
|
||||
}
|
||||
|
||||
/* Check window subscription. */
|
||||
@@ -989,45 +993,38 @@ control_check_subs_window(struct client *c, struct control_sub *csub)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check all windows subscription. */
|
||||
/* Check all-windows subscription for a window. */
|
||||
static void
|
||||
control_check_subs_all_windows(struct client *c, struct control_sub *csub)
|
||||
control_check_subs_all_windows_one(struct client *c, struct control_sub *csub,
|
||||
struct format_tree *ft, struct winlink *wl)
|
||||
{
|
||||
struct session *s = c->session;
|
||||
struct window *w;
|
||||
struct winlink *wl;
|
||||
struct format_tree *ft;
|
||||
struct window *w = wl->window;
|
||||
char *value;
|
||||
struct control_sub_window *csw, find;
|
||||
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
w = wl->window;
|
||||
value = format_expand(ft, csub->format);
|
||||
|
||||
ft = format_create_defaults(NULL, c, s, wl, NULL);
|
||||
value = format_expand(ft, csub->format);
|
||||
format_free(ft);
|
||||
find.window = w->id;
|
||||
find.idx = wl->idx;
|
||||
|
||||
find.window = w->id;
|
||||
find.idx = wl->idx;
|
||||
|
||||
csw = RB_FIND(control_sub_windows, &csub->windows, &find);
|
||||
if (csw == NULL) {
|
||||
csw = xcalloc(1, sizeof *csw);
|
||||
csw->window = w->id;
|
||||
csw->idx = wl->idx;
|
||||
RB_INSERT(control_sub_windows, &csub->windows, csw);
|
||||
}
|
||||
|
||||
if (csw->last != NULL && strcmp(value, csw->last) == 0) {
|
||||
free(value);
|
||||
continue;
|
||||
}
|
||||
control_write(c,
|
||||
"%%subscription-changed %s $%u @%u %u - : %s",
|
||||
csub->name, s->id, w->id, wl->idx, value);
|
||||
free(csw->last);
|
||||
csw->last = value;
|
||||
csw = RB_FIND(control_sub_windows, &csub->windows, &find);
|
||||
if (csw == NULL) {
|
||||
csw = xcalloc(1, sizeof *csw);
|
||||
csw->window = w->id;
|
||||
csw->idx = wl->idx;
|
||||
RB_INSERT(control_sub_windows, &csub->windows, csw);
|
||||
}
|
||||
|
||||
if (csw->last != NULL && strcmp(value, csw->last) == 0) {
|
||||
free(value);
|
||||
return;
|
||||
}
|
||||
control_write(c,
|
||||
"%%subscription-changed %s $%u @%u %u - : %s",
|
||||
csub->name, s->id, w->id, wl->idx, value);
|
||||
free(csw->last);
|
||||
csw->last = value;
|
||||
}
|
||||
|
||||
/* Check subscriptions timer. */
|
||||
@@ -1037,30 +1034,91 @@ control_check_subs_timer(__unused int fd, __unused short events, void *data)
|
||||
struct client *c = data;
|
||||
struct control_state *cs = c->control_state;
|
||||
struct control_sub *csub, *csub1;
|
||||
struct session *s = c->session;
|
||||
struct format_tree *ft;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
struct timeval tv = { .tv_sec = 1 };
|
||||
int have_session = 0, have_all_panes = 0;
|
||||
int have_all_windows = 0;
|
||||
|
||||
log_debug("%s: timer fired", __func__);
|
||||
evtimer_add(&cs->subs_timer, &tv);
|
||||
|
||||
RB_FOREACH_SAFE(csub, control_subs, &cs->subs, csub1) {
|
||||
/* Find which subscription types are present. */
|
||||
RB_FOREACH(csub, control_subs, &cs->subs) {
|
||||
switch (csub->type) {
|
||||
case CONTROL_SUB_SESSION:
|
||||
control_check_subs_session(c, csub);
|
||||
break;
|
||||
case CONTROL_SUB_PANE:
|
||||
control_check_subs_pane(c, csub);
|
||||
have_session = 1;
|
||||
break;
|
||||
case CONTROL_SUB_ALL_PANES:
|
||||
control_check_subs_all_panes(c, csub);
|
||||
have_all_panes = 1;
|
||||
break;
|
||||
case CONTROL_SUB_ALL_WINDOWS:
|
||||
have_all_windows = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check session subscriptions. */
|
||||
if (have_session) {
|
||||
ft = format_create_defaults(NULL, c, s, NULL, NULL);
|
||||
RB_FOREACH_SAFE(csub, control_subs, &cs->subs, csub1) {
|
||||
if (csub->type == CONTROL_SUB_SESSION)
|
||||
control_check_subs_session(c, csub, ft);
|
||||
}
|
||||
format_free(ft);
|
||||
}
|
||||
|
||||
/* Check pane and window subscriptions. */
|
||||
RB_FOREACH_SAFE(csub, control_subs, &cs->subs, csub1) {
|
||||
switch (csub->type) {
|
||||
case CONTROL_SUB_PANE:
|
||||
control_check_subs_pane(c, csub);
|
||||
break;
|
||||
case CONTROL_SUB_WINDOW:
|
||||
control_check_subs_window(c, csub);
|
||||
break;
|
||||
case CONTROL_SUB_SESSION:
|
||||
case CONTROL_SUB_ALL_PANES:
|
||||
case CONTROL_SUB_ALL_WINDOWS:
|
||||
control_check_subs_all_windows(c, csub);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check all-panes subscriptions. */
|
||||
if (have_all_panes) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
ft = format_create_defaults(NULL, c, s, wl, wp);
|
||||
RB_FOREACH_SAFE(csub, control_subs, &cs->subs,
|
||||
csub1) {
|
||||
if (csub->type != CONTROL_SUB_ALL_PANES)
|
||||
continue;
|
||||
control_check_subs_all_panes_one(c,
|
||||
csub, ft, wl, wp);
|
||||
}
|
||||
format_free(ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check all-windows subscriptions. */
|
||||
if (have_all_windows) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
ft = format_create_defaults(NULL, c, s, wl, NULL);
|
||||
RB_FOREACH_SAFE(csub, control_subs, &cs->subs,
|
||||
csub1) {
|
||||
if (csub->type != CONTROL_SUB_ALL_WINDOWS)
|
||||
continue;
|
||||
control_check_subs_all_windows_one(c, csub, ft,
|
||||
wl);
|
||||
}
|
||||
format_free(ft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a subscription. */
|
||||
|
||||
25
environ.c
25
environ.c
@@ -57,6 +57,9 @@ environ_free(struct environ *env)
|
||||
{
|
||||
struct environ_entry *envent, *envent1;
|
||||
|
||||
if (env == NULL)
|
||||
return;
|
||||
|
||||
RB_FOREACH_SAFE(envent, environ, env, envent1) {
|
||||
RB_REMOVE(environ, env, envent);
|
||||
free(envent->name);
|
||||
@@ -182,9 +185,11 @@ void
|
||||
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
struct environ_entry *envent1;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
union options_value *ov;
|
||||
int found;
|
||||
|
||||
o = options_get(oo, "update-environment");
|
||||
if (o == NULL)
|
||||
@@ -192,14 +197,15 @@ environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
ov = options_array_item_value(a);
|
||||
RB_FOREACH(envent, environ, src) {
|
||||
if (fnmatch(ov->string, envent->name, 0) == 0)
|
||||
break;
|
||||
found = 0;
|
||||
RB_FOREACH_SAFE(envent, environ, src, envent1) {
|
||||
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);
|
||||
else
|
||||
environ_set(dst, envent->name, 0, "%s", envent->value);
|
||||
a = options_array_next(a);
|
||||
}
|
||||
}
|
||||
@@ -259,8 +265,15 @@ environ_for_session(struct session *s, int no_TERM)
|
||||
environ_set(env, "TERM", 0, "%s", value);
|
||||
environ_set(env, "TERM_PROGRAM", 0, "%s", "tmux");
|
||||
environ_set(env, "TERM_PROGRAM_VERSION", 0, "%s", getversion());
|
||||
environ_set(env, "COLORTERM", 0, "truecolor");
|
||||
}
|
||||
|
||||
#ifdef HAVE_SYSTEMD
|
||||
environ_clear(env, "LISTEN_PID");
|
||||
environ_clear(env, "LISTEN_FDS");
|
||||
environ_clear(env, "LISTEN_FDNAMES");
|
||||
#endif
|
||||
|
||||
if (s != NULL)
|
||||
idx = s->id;
|
||||
else
|
||||
|
||||
@@ -14,7 +14,7 @@ set -g status-bg red
|
||||
%endif
|
||||
|
||||
# Enable RGB colour if running in xterm(1)
|
||||
set-option -sa terminal-overrides ",xterm*:Tc"
|
||||
set-option -sa terminal-features ",xterm*:RGB"
|
||||
|
||||
# Change the default $TERM to tmux-256color
|
||||
set -g default-terminal "tmux-256color"
|
||||
|
||||
78
file.c
78
file.c
@@ -41,13 +41,22 @@ RB_GENERATE(client_files, client_file, entry, file_cmp);
|
||||
static char *
|
||||
file_get_path(struct client *c, const char *file)
|
||||
{
|
||||
char *path;
|
||||
const char *home;
|
||||
char *path, *full_path;
|
||||
|
||||
if (*file == '/')
|
||||
if (strncmp(file, "~/", 2) != 0)
|
||||
path = xstrdup(file);
|
||||
else
|
||||
xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file);
|
||||
return (path);
|
||||
else {
|
||||
home = find_home();
|
||||
if (home == NULL)
|
||||
home = "";
|
||||
xasprintf(&path, "%s%s", home, file + 1);
|
||||
}
|
||||
if (*path == '/')
|
||||
return (path);
|
||||
xasprintf(&full_path, "%s/%s", server_client_get_cwd(c, NULL), path);
|
||||
free(path);
|
||||
return (full_path);
|
||||
}
|
||||
|
||||
/* Tree comparison function. */
|
||||
@@ -149,7 +158,8 @@ file_fire_done_cb(__unused int fd, __unused short events, void *arg)
|
||||
struct client_file *cf = arg;
|
||||
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);
|
||||
file_free(cf);
|
||||
}
|
||||
@@ -173,9 +183,9 @@ file_fire_read(struct client_file *cf)
|
||||
int
|
||||
file_can_print(struct client *c)
|
||||
{
|
||||
if (c == NULL)
|
||||
return (0);
|
||||
if (c->session != NULL && (~c->flags & CLIENT_CONTROL))
|
||||
if (c == NULL ||
|
||||
(c->flags & CLIENT_ATTACHED) ||
|
||||
(c->flags & CLIENT_CONTROL))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
@@ -352,7 +362,7 @@ done:
|
||||
}
|
||||
|
||||
/* Read a file. */
|
||||
void
|
||||
struct client_file *
|
||||
file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
|
||||
{
|
||||
struct client_file *cf;
|
||||
@@ -360,7 +370,7 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
|
||||
size_t msglen;
|
||||
int fd = -1;
|
||||
u_int stream = file_next_stream++;
|
||||
FILE *f;
|
||||
FILE *f = NULL;
|
||||
size_t size;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
@@ -400,7 +410,6 @@ file_read(struct client *c, const char *path, client_file_cb cb, void *cbdata)
|
||||
cf->error = EIO;
|
||||
goto done;
|
||||
}
|
||||
fclose(f);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -420,10 +429,29 @@ skip:
|
||||
goto done;
|
||||
}
|
||||
free(msg);
|
||||
return;
|
||||
return cf;
|
||||
|
||||
done:
|
||||
if (f != NULL)
|
||||
fclose(f);
|
||||
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. */
|
||||
@@ -585,6 +613,8 @@ file_write_open(struct client_files *files, struct tmuxpeer *peer,
|
||||
|
||||
cf->event = bufferevent_new(cf->fd, NULL, file_write_callback,
|
||||
file_write_error_callback, cf);
|
||||
if (cf->event == NULL)
|
||||
fatalx("out of memory");
|
||||
bufferevent_enable(cf->event, EV_WRITE);
|
||||
goto reply;
|
||||
|
||||
@@ -744,6 +774,8 @@ file_read_open(struct client_files *files, struct tmuxpeer *peer,
|
||||
|
||||
cf->event = bufferevent_new(cf->fd, file_read_callback, NULL,
|
||||
file_read_error_callback, cf);
|
||||
if (cf->event == NULL)
|
||||
fatalx("out of memory");
|
||||
bufferevent_enable(cf->event, EV_READ);
|
||||
return;
|
||||
|
||||
@@ -753,6 +785,24 @@ 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). */
|
||||
void
|
||||
file_write_ready(struct client_files *files, struct imsg *imsg)
|
||||
@@ -790,7 +840,7 @@ file_read_data(struct client_files *files, struct imsg *imsg)
|
||||
return;
|
||||
|
||||
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) {
|
||||
cf->error = ENOMEM;
|
||||
file_fire_done(cf);
|
||||
|
||||
@@ -33,6 +33,7 @@ struct format_range {
|
||||
|
||||
enum style_range_type type;
|
||||
u_int argument;
|
||||
char string[16];
|
||||
|
||||
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)
|
||||
return (0);
|
||||
if (fr->type == STYLE_RANGE_WINDOW &&
|
||||
fr->argument != sy->range_argument)
|
||||
return (0);
|
||||
switch (fr->type) {
|
||||
case STYLE_RANGE_NONE:
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -709,7 +719,7 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
int focus_start = -1, focus_end = -1;
|
||||
int list_state = -1, fill = -1, even;
|
||||
enum style_align list_align = STYLE_ALIGN_DEFAULT;
|
||||
struct grid_cell gc, current_default;
|
||||
struct grid_cell gc, current_default, base_default;
|
||||
struct style sy, saved_sy;
|
||||
struct utf8_data *ud = &sy.gc.data;
|
||||
const char *cp, *end;
|
||||
@@ -719,7 +729,9 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
struct format_ranges frs;
|
||||
struct style_range *sr;
|
||||
|
||||
memcpy(&base_default, base, sizeof base_default);
|
||||
memcpy(¤t_default, base, sizeof current_default);
|
||||
base = &base_default;
|
||||
style_set(&sy, ¤t_default);
|
||||
TAILQ_INIT(&frs);
|
||||
log_debug("%s: %s", __func__, expanded);
|
||||
@@ -837,6 +849,12 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
} else if (sy.default_type == STYLE_DEFAULT_POP) {
|
||||
memcpy(¤t_default, base, sizeof current_default);
|
||||
sy.default_type = STYLE_DEFAULT_BASE;
|
||||
} else if (sy.default_type == STYLE_DEFAULT_SET) {
|
||||
memcpy(&base_default, &saved_sy.gc,
|
||||
sizeof base_default);
|
||||
memcpy(¤t_default, &saved_sy.gc,
|
||||
sizeof current_default);
|
||||
sy.default_type = STYLE_DEFAULT_BASE;
|
||||
}
|
||||
|
||||
/* Check the list state. */
|
||||
@@ -942,6 +960,8 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
|
||||
fr->type = sy.range_type;
|
||||
fr->argument = sy.range_argument;
|
||||
strlcpy(fr->string, sy.range_string,
|
||||
sizeof fr->string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1013,13 +1033,39 @@ format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
sr = xcalloc(1, sizeof *sr);
|
||||
sr->type = fr->type;
|
||||
sr->argument = fr->argument;
|
||||
strlcpy(sr->string, fr->string, sizeof sr->string);
|
||||
sr->start = fr->start;
|
||||
sr->end = fr->end;
|
||||
TAILQ_INSERT_TAIL(srs, sr, entry);
|
||||
|
||||
log_debug("%s: range %d|%u at %u-%u", __func__, sr->type,
|
||||
sr->argument, sr->start, sr->end);
|
||||
|
||||
switch (sr->type) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -1058,8 +1104,6 @@ format_width(const char *expanded)
|
||||
more = utf8_append(&ud, *cp);
|
||||
if (more == UTF8_DONE)
|
||||
width += ud.width;
|
||||
else
|
||||
cp -= ud.have;
|
||||
} else if (*cp > 0x1f && *cp < 0x7f) {
|
||||
width++;
|
||||
cp++;
|
||||
@@ -1083,7 +1127,7 @@ format_trim_left(const char *expanded, u_int limit)
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
out = copy = xcalloc(1, strlen(expanded) + 1);
|
||||
out = copy = xcalloc(2, strlen(expanded) + 1);
|
||||
while (*cp != '\0') {
|
||||
if (width >= limit)
|
||||
break;
|
||||
@@ -1150,7 +1194,7 @@ format_trim_right(const char *expanded, u_int limit)
|
||||
return (xstrdup(expanded));
|
||||
skip = total_width - limit;
|
||||
|
||||
out = copy = xcalloc(1, strlen(expanded) + 1);
|
||||
out = copy = xcalloc(2, strlen(expanded) + 1);
|
||||
while (*cp != '\0') {
|
||||
if (*cp == '#') {
|
||||
end = format_leading_hashes(cp, &n, &leading_width);
|
||||
|
||||
@@ -35,7 +35,7 @@ LLVMFuzzerTestOneInput(const u_char *data, size_t size)
|
||||
int error;
|
||||
|
||||
/*
|
||||
* Since AFL doesn't support -max_len paramenter we have to
|
||||
* Since AFL doesn't support -max_len parameter we have to
|
||||
* discard long inputs manually.
|
||||
*/
|
||||
if (size > FUZZER_MAXLEN)
|
||||
@@ -44,7 +44,7 @@ LLVMFuzzerTestOneInput(const u_char *data, size_t size)
|
||||
w = window_create(PANE_WIDTH, PANE_HEIGHT, 0, 0);
|
||||
wp = window_add_pane(w, NULL, 0, 0);
|
||||
bufferevent_pair_new(libevent, BEV_OPT_CLOSE_ON_FREE, vpty);
|
||||
wp->ictx = input_init(wp, vpty[0], NULL);
|
||||
wp->ictx = input_init(wp, vpty[0], NULL, NULL);
|
||||
window_add_ref(w, __func__);
|
||||
|
||||
wp->fd = open("/dev/null", O_WRONLY);
|
||||
|
||||
@@ -180,19 +180,14 @@ grid_reader_handle_wrap(struct grid_reader *gr, u_int *xx, u_int *yy)
|
||||
int
|
||||
grid_reader_in_set(struct grid_reader *gr, const char *set)
|
||||
{
|
||||
struct grid_cell gc;
|
||||
|
||||
grid_get_cell(gr->gd, gr->cx, gr->cy, &gc);
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
return (0);
|
||||
return (utf8_cstrhas(set, &gc.data));
|
||||
return (grid_in_set(gr->gd, gr->cx, gr->cy, set));
|
||||
}
|
||||
|
||||
/* Move cursor to the start of the next word. */
|
||||
void
|
||||
grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
||||
{
|
||||
u_int xx, yy;
|
||||
u_int xx, yy, width;
|
||||
|
||||
/* Do not break up wrapped words. */
|
||||
if (grid_get_line(gr->gd, gr->cy)->flags & GRID_LINE_WRAPPED)
|
||||
@@ -229,8 +224,8 @@ grid_reader_cursor_next_word(struct grid_reader *gr, const char *separators)
|
||||
}
|
||||
}
|
||||
while (grid_reader_handle_wrap(gr, &xx, &yy) &&
|
||||
grid_reader_in_set(gr, WHITESPACE))
|
||||
gr->cx++;
|
||||
(width = grid_reader_in_set(gr, WHITESPACE)))
|
||||
gr->cx += width;
|
||||
}
|
||||
|
||||
/* Move cursor to the end of the next word. */
|
||||
@@ -338,6 +333,20 @@ grid_reader_cursor_previous_word(struct grid_reader *gr, const char *separators,
|
||||
gr->cy = oldy;
|
||||
}
|
||||
|
||||
/* Compare grid cell to UTF-8 data. Return 1 if equal, 0 if not. */
|
||||
static int
|
||||
grid_reader_cell_equals_data(const struct grid_cell *gc,
|
||||
const struct utf8_data *ud)
|
||||
{
|
||||
if (gc->flags & GRID_FLAG_PADDING)
|
||||
return (0);
|
||||
if (gc->flags & GRID_FLAG_TAB && ud->size == 1 && *ud->data == '\t')
|
||||
return (1);
|
||||
if (gc->data.size != ud->size)
|
||||
return (0);
|
||||
return (memcmp(gc->data.data, ud->data, gc->data.size) == 0);
|
||||
}
|
||||
|
||||
/* Jump forward to character. */
|
||||
int
|
||||
grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
|
||||
@@ -352,9 +361,7 @@ grid_reader_cursor_jump(struct grid_reader *gr, const struct utf8_data *jc)
|
||||
xx = grid_line_length(gr->gd, py);
|
||||
while (px < xx) {
|
||||
grid_get_cell(gr->gd, px, py, &gc);
|
||||
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
||||
gc.data.size == jc->size &&
|
||||
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||
if (grid_reader_cell_equals_data(&gc, jc)) {
|
||||
gr->cx = px;
|
||||
gr->cy = py;
|
||||
return (1);
|
||||
@@ -382,9 +389,7 @@ grid_reader_cursor_jump_back(struct grid_reader *gr, const struct utf8_data *jc)
|
||||
for (py = gr->cy + 1; py > 0; py--) {
|
||||
for (px = xx; px > 0; px--) {
|
||||
grid_get_cell(gr->gd, px - 1, py - 1, &gc);
|
||||
if (!(gc.flags & GRID_FLAG_PADDING) &&
|
||||
gc.data.size == jc->size &&
|
||||
memcmp(gc.data.data, jc->data, gc.data.size) == 0) {
|
||||
if (grid_reader_cell_equals_data(&gc, jc)) {
|
||||
gr->cx = px - 1;
|
||||
gr->cy = py - 1;
|
||||
return (1);
|
||||
@@ -415,7 +420,9 @@ grid_reader_cursor_back_to_indentation(struct grid_reader *gr)
|
||||
xx = grid_line_length(gr->gd, py);
|
||||
for (px = 0; px < xx; px++) {
|
||||
grid_get_cell(gr->gd, px, py, &gc);
|
||||
if (gc.data.size != 1 || *gc.data.data != ' ') {
|
||||
if ((gc.data.size != 1 || *gc.data.data != ' ') &&
|
||||
~gc.flags & GRID_FLAG_TAB &&
|
||||
~gc.flags & GRID_FLAG_PADDING) {
|
||||
gr->cx = px;
|
||||
gr->cy = py;
|
||||
return;
|
||||
|
||||
10
grid-view.c
10
grid-view.c
@@ -82,7 +82,7 @@ grid_view_clear_history(struct grid *gd, u_int bg)
|
||||
|
||||
/* Scroll the lines into the history. */
|
||||
for (yy = 0; yy < last; yy++) {
|
||||
grid_collect_history(gd);
|
||||
grid_collect_history(gd, 0);
|
||||
grid_scroll_history(gd, bg);
|
||||
}
|
||||
if (last < gd->sy)
|
||||
@@ -107,7 +107,7 @@ grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower,
|
||||
u_int bg)
|
||||
{
|
||||
if (gd->flags & GRID_HISTORY) {
|
||||
grid_collect_history(gd);
|
||||
grid_collect_history(gd, 0);
|
||||
if (rupper == 0 && rlower == gd->sy - 1)
|
||||
grid_scroll_history(gd, bg);
|
||||
else {
|
||||
@@ -173,7 +173,7 @@ grid_view_delete_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
||||
sy = grid_view_y(gd, gd->sy);
|
||||
|
||||
grid_move_lines(gd, py, py + ny, sy - py - ny, bg);
|
||||
grid_clear(gd, 0, sy - ny, gd->sx, py + ny - (sy - ny), bg);
|
||||
grid_clear(gd, 0, sy - ny, gd->sx, ny, bg);
|
||||
}
|
||||
|
||||
/* Delete lines inside scroll region. */
|
||||
@@ -221,7 +221,7 @@ grid_view_delete_cells(struct grid *gd, u_int px, u_int py, u_int nx, u_int bg)
|
||||
sx = grid_view_x(gd, gd->sx);
|
||||
|
||||
grid_move_cells(gd, px, px + nx, py, sx - px - nx, bg);
|
||||
grid_clear(gd, sx - nx, py, px + nx - (sx - nx), 1, bg);
|
||||
grid_clear(gd, sx - nx, py, nx, 1, bg);
|
||||
}
|
||||
|
||||
/* Convert cells into a string. */
|
||||
@@ -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);
|
||||
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));
|
||||
}
|
||||
|
||||
266
grid.c
266
grid.c
@@ -37,7 +37,7 @@
|
||||
|
||||
/* Default grid cell data. */
|
||||
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.
|
||||
*/
|
||||
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. */
|
||||
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 = {
|
||||
GRID_FLAG_CLEARED, { .data = { 0, 8, 8, ' ' } }
|
||||
{ .data = { 0, 8, 8, ' ' } }, GRID_FLAG_CLEARED
|
||||
};
|
||||
|
||||
/* Store cell in entry. */
|
||||
@@ -84,11 +84,15 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
|
||||
return (1);
|
||||
if (gc->attr > 0xff)
|
||||
return (1);
|
||||
if (gc->data.size != 1 || gc->data.width != 1)
|
||||
if (gc->data.size > 1 || gc->data.width > 1)
|
||||
return (1);
|
||||
if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB))
|
||||
return (1);
|
||||
if (gc->us != 0) /* only supports 256 or RGB */
|
||||
if (gc->us != 8) /* only supports 256 or RGB */
|
||||
return (1);
|
||||
if (gc->link != 0)
|
||||
return (1);
|
||||
if (gc->flags & GRID_FLAG_TAB)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
@@ -122,7 +126,10 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
fatalx("offset too big");
|
||||
gl->flags |= GRID_LINE_EXTENDED;
|
||||
|
||||
utf8_from_data(&gc->data, &uc);
|
||||
if (gc->flags & GRID_FLAG_TAB)
|
||||
uc = gc->data.width;
|
||||
else
|
||||
utf8_from_data(&gc->data, &uc);
|
||||
|
||||
gee = &gl->extddata[gce->offset];
|
||||
gee->data = uc;
|
||||
@@ -131,6 +138,7 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
gee->fg = gc->fg;
|
||||
gee->bg = gc->bg;
|
||||
gee->us = gc->us;
|
||||
gee->link = gc->link;
|
||||
return (gee);
|
||||
}
|
||||
|
||||
@@ -197,9 +205,17 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
||||
struct grid_line *gl = &gd->linedata[py];
|
||||
struct grid_cell_entry *gce = &gl->celldata[px];
|
||||
struct grid_extd_entry *gee;
|
||||
u_int old_offset = gce->offset;
|
||||
int had_extd = (gce->flags & GRID_FLAG_EXTENDED);
|
||||
|
||||
memcpy(gce, &grid_cleared_entry, sizeof *gce);
|
||||
if (bg != 8) {
|
||||
if (had_extd && old_offset < gl->extdsize) {
|
||||
gce->flags |= GRID_FLAG_EXTENDED;
|
||||
gce->offset = old_offset;
|
||||
gee = grid_extended_cell(gl, gce, &grid_cleared_cell);
|
||||
if (bg != 8)
|
||||
gee->bg = bg;
|
||||
} else if (bg != 8) {
|
||||
if (bg & COLOUR_FLAG_RGB) {
|
||||
grid_get_extended_cell(gl, gce, gce->flags);
|
||||
gee = grid_extended_cell(gl, gce, &grid_cleared_cell);
|
||||
@@ -227,9 +243,15 @@ grid_check_y(struct grid *gd, const char *from, u_int py)
|
||||
int
|
||||
grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
|
||||
{
|
||||
int flags1 = gc1->flags, flags2 = gc2->flags;
|
||||
|
||||
if (gc1->fg != gc2->fg || gc1->bg != gc2->bg)
|
||||
return (0);
|
||||
if (gc1->attr != gc2->attr || gc1->flags != gc2->flags)
|
||||
if (gc1->attr != gc2->attr)
|
||||
return (0);
|
||||
if ((flags1 & ~GRID_FLAG_CLEARED) != (flags2 & ~GRID_FLAG_CLEARED))
|
||||
return (0);
|
||||
if (gc1->link != gc2->link)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
@@ -247,6 +269,17 @@ grid_cells_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
|
||||
return (memcmp(gc1->data.data, gc2->data.data, gc1->data.size) == 0);
|
||||
}
|
||||
|
||||
/* Set grid cell to a tab. */
|
||||
void
|
||||
grid_set_tab(struct grid_cell *gc, u_int width)
|
||||
{
|
||||
memset(gc->data.data, 0, sizeof gc->data.data);
|
||||
gc->flags |= GRID_FLAG_TAB;
|
||||
gc->flags &= ~GRID_FLAG_PADDING;
|
||||
gc->data.width = gc->data.size = gc->data.have = width;
|
||||
memset(gc->data.data, ' ', gc->data.size);
|
||||
}
|
||||
|
||||
/* Free one line. */
|
||||
static void
|
||||
grid_free_line(struct grid *gd, u_int py)
|
||||
@@ -336,9 +369,13 @@ grid_compare(struct grid *ga, struct grid *gb)
|
||||
static void
|
||||
grid_trim_history(struct grid *gd, u_int ny)
|
||||
{
|
||||
u_int remaining;
|
||||
|
||||
grid_free_lines(gd, 0, ny);
|
||||
remaining = gd->hsize + gd->sy - ny;
|
||||
memmove(&gd->linedata[0], &gd->linedata[ny],
|
||||
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
|
||||
remaining * (sizeof *gd->linedata));
|
||||
memset(&gd->linedata[remaining], 0, ny * (sizeof *gd->linedata));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -346,14 +383,17 @@ grid_trim_history(struct grid *gd, u_int ny)
|
||||
* and shift up.
|
||||
*/
|
||||
void
|
||||
grid_collect_history(struct grid *gd)
|
||||
grid_collect_history(struct grid *gd, int all)
|
||||
{
|
||||
u_int ny;
|
||||
|
||||
if (gd->hsize == 0 || gd->hsize < gd->hlimit)
|
||||
return;
|
||||
|
||||
ny = gd->hlimit / 10;
|
||||
if (all)
|
||||
ny = gd->hsize - gd->hlimit;
|
||||
else
|
||||
ny = gd->hlimit / 10;
|
||||
if (ny < 1)
|
||||
ny = 1;
|
||||
if (ny > gd->hsize)
|
||||
@@ -399,6 +439,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
||||
|
||||
gd->hscrolled++;
|
||||
grid_compact_line(&gd->linedata[gd->hsize]);
|
||||
gd->linedata[gd->hsize].time = current_time;
|
||||
gd->hsize++;
|
||||
}
|
||||
|
||||
@@ -438,6 +479,7 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg)
|
||||
|
||||
/* Move the line into the history. */
|
||||
memcpy(gl_history, gl_upper, sizeof *gl_history);
|
||||
gl_history->time = current_time;
|
||||
|
||||
/* Then move the region up and clear the bottom line. */
|
||||
memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper);
|
||||
@@ -453,7 +495,7 @@ static void
|
||||
grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
|
||||
{
|
||||
struct grid_line *gl;
|
||||
u_int xx;
|
||||
u_int xx, old_cellsize;
|
||||
|
||||
gl = &gd->linedata[py];
|
||||
if (sx <= gl->cellsize)
|
||||
@@ -466,8 +508,10 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx, u_int bg)
|
||||
else if (gd->sx > sx)
|
||||
sx = gd->sx;
|
||||
|
||||
gl->celldata = xreallocarray(gl->celldata, sx, sizeof *gl->celldata);
|
||||
for (xx = gl->cellsize; xx < sx; xx++)
|
||||
old_cellsize = gl->cellsize;
|
||||
gl->celldata = xrecallocarray(gl->celldata, old_cellsize, sx,
|
||||
sizeof *gl->celldata);
|
||||
for (xx = old_cellsize; xx < sx; xx++)
|
||||
grid_clear_cell(gd, xx, py, bg);
|
||||
gl->cellsize = sx;
|
||||
}
|
||||
@@ -507,7 +551,12 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
||||
gc->fg = gee->fg;
|
||||
gc->bg = gee->bg;
|
||||
gc->us = gee->us;
|
||||
utf8_to_data(gee->data, &gc->data);
|
||||
gc->link = gee->link;
|
||||
|
||||
if (gc->flags & GRID_FLAG_TAB)
|
||||
grid_set_tab(gc, gee->data);
|
||||
else
|
||||
utf8_to_data(gee->data, &gc->data);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -520,8 +569,9 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
||||
gc->bg = gce->data.bg;
|
||||
if (gce->flags & GRID_FLAG_BG256)
|
||||
gc->bg |= COLOUR_FLAG_256;
|
||||
gc->us = 0;
|
||||
gc->us = 8;
|
||||
utf8_set(&gc->data, gce->data.data);
|
||||
gc->link = 0;
|
||||
}
|
||||
|
||||
/* Get cell for reading. */
|
||||
@@ -852,28 +902,60 @@ grid_string_cells_us(const struct grid_cell *gc, int *values)
|
||||
/* Add on SGR code. */
|
||||
static void
|
||||
grid_string_cells_add_code(char *buf, size_t len, u_int n, int *s, int *newc,
|
||||
int *oldc, size_t nnewc, size_t noldc, int escape_c0)
|
||||
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 &&
|
||||
(nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0))) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
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
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -882,14 +964,16 @@ grid_string_cells_add_code(char *buf, size_t len, u_int n, int *s, int *newc,
|
||||
*/
|
||||
static void
|
||||
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];
|
||||
size_t noldc, nnewc, n, i;
|
||||
u_int attr = gc->attr, lastattr = lastgc->attr;
|
||||
char tmp[64];
|
||||
int oldc[64], newc[64], s[128];
|
||||
size_t noldc, nnewc, n, i;
|
||||
u_int attr = gc->attr, lastattr = lastgc->attr;
|
||||
char tmp[64];
|
||||
const char *uri, *id;
|
||||
|
||||
struct {
|
||||
static const struct {
|
||||
u_int mask;
|
||||
u_int code;
|
||||
} attrs[] = {
|
||||
@@ -913,7 +997,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
for (i = 0; i < nitems(attrs); i++) {
|
||||
if (((~attr & attrs[i].mask) &&
|
||||
(lastattr & attrs[i].mask)) ||
|
||||
(lastgc->us != 0 && gc->us == 0)) {
|
||||
(lastgc->us != 8 && gc->us == 8)) {
|
||||
s[n++] = 0;
|
||||
lastattr &= GRID_ATTR_CHARSET;
|
||||
break;
|
||||
@@ -928,7 +1012,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
/* Write the attributes. */
|
||||
*buf = '\0';
|
||||
if (n > 0) {
|
||||
if (escape_c0)
|
||||
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
@@ -950,46 +1034,59 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
nnewc = grid_string_cells_fg(gc, newc);
|
||||
noldc = grid_string_cells_fg(lastgc, oldc);
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
flags);
|
||||
|
||||
/* If the background colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_bg(gc, newc);
|
||||
noldc = grid_string_cells_bg(lastgc, oldc);
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
flags);
|
||||
|
||||
/* If the underscore colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_us(gc, newc);
|
||||
noldc = grid_string_cells_us(lastgc, oldc);
|
||||
grid_string_cells_add_code(buf, len, n, s, newc, oldc, nnewc, noldc,
|
||||
escape_c0);
|
||||
flags);
|
||||
|
||||
/* Append shift in/shift out if needed. */
|
||||
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
||||
if (escape_c0)
|
||||
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||
strlcat(buf, "\\016", len); /* SO */
|
||||
else
|
||||
strlcat(buf, "\016", len); /* SO */
|
||||
}
|
||||
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
|
||||
if (escape_c0)
|
||||
if (flags & GRID_STRING_ESCAPE_SEQUENCES)
|
||||
strlcat(buf, "\\017", len); /* SI */
|
||||
else
|
||||
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. */
|
||||
char *
|
||||
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;
|
||||
static struct grid_cell lastgc1;
|
||||
const char *data;
|
||||
char *buf, code[128];
|
||||
char *buf, code[8192];
|
||||
size_t len, off, size, codelen;
|
||||
u_int xx;
|
||||
u_int xx, end;
|
||||
int has_link = 0;
|
||||
const struct grid_line *gl;
|
||||
|
||||
if (lastgc != NULL && *lastgc == NULL) {
|
||||
@@ -1002,26 +1099,41 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||
off = 0;
|
||||
|
||||
gl = grid_peek_line(gd, py);
|
||||
if (gl == NULL) {
|
||||
buf[0] = '\0';
|
||||
return (buf);
|
||||
}
|
||||
if (flags & GRID_STRING_EMPTY_CELLS)
|
||||
end = gl->cellsize;
|
||||
else
|
||||
end = gl->cellused;
|
||||
for (xx = px; xx < px + nx; xx++) {
|
||||
if (gl == NULL || xx >= gl->cellused)
|
||||
if (xx >= end)
|
||||
break;
|
||||
grid_get_cell(gd, xx, py, &gc);
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
continue;
|
||||
|
||||
if (with_codes) {
|
||||
if (flags & GRID_STRING_WITH_SEQUENCES) {
|
||||
grid_string_cells_code(*lastgc, &gc, code, sizeof code,
|
||||
escape_c0);
|
||||
flags, s, &has_link);
|
||||
codelen = strlen(code);
|
||||
memcpy(*lastgc, &gc, sizeof **lastgc);
|
||||
} else
|
||||
codelen = 0;
|
||||
|
||||
data = gc.data.data;
|
||||
size = gc.data.size;
|
||||
if (escape_c0 && size == 1 && *data == '\\') {
|
||||
data = "\\\\";
|
||||
size = 2;
|
||||
if (gc.flags & GRID_FLAG_TAB) {
|
||||
data = "\t";
|
||||
size = 1;
|
||||
} else {
|
||||
data = gc.data.data;
|
||||
size = gc.data.size;
|
||||
if ((flags & GRID_STRING_ESCAPE_SEQUENCES) &&
|
||||
size == 1 &&
|
||||
*data == '\\') {
|
||||
data = "\\\\";
|
||||
size = 2;
|
||||
}
|
||||
}
|
||||
|
||||
while (len < off + size + codelen + 1) {
|
||||
@@ -1037,7 +1149,19 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||
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] == ' ')
|
||||
off--;
|
||||
}
|
||||
@@ -1201,7 +1325,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
if (!wrapped || want != from->cellused || width == sx)
|
||||
break;
|
||||
}
|
||||
if (lines == 0)
|
||||
if (lines == 0 || from == NULL)
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -1459,3 +1583,27 @@ grid_line_length(struct grid *gd, u_int py)
|
||||
}
|
||||
return (px);
|
||||
}
|
||||
|
||||
/* Check if character is in set. */
|
||||
int
|
||||
grid_in_set(struct grid *gd, u_int px, u_int py, const char *set)
|
||||
{
|
||||
struct grid_cell gc, tmp_gc;
|
||||
u_int pxx;
|
||||
|
||||
grid_get_cell(gd, px, py, &gc);
|
||||
if (strchr(set, '\t')) {
|
||||
if (gc.flags & GRID_FLAG_PADDING) {
|
||||
pxx = px;
|
||||
do
|
||||
grid_get_cell(gd, --pxx, py, &tmp_gc);
|
||||
while (pxx > 0 && tmp_gc.flags & GRID_FLAG_PADDING);
|
||||
if (tmp_gc.flags & GRID_FLAG_TAB)
|
||||
return (tmp_gc.data.width - (px - pxx));
|
||||
} else if (gc.flags & GRID_FLAG_TAB)
|
||||
return (gc.data.width);
|
||||
}
|
||||
if (gc.flags & GRID_FLAG_PADDING)
|
||||
return (0);
|
||||
return (utf8_cstrhas(set, &gc.data));
|
||||
}
|
||||
|
||||
239
hyperlinks.c
Normal file
239
hyperlinks.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/* $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;
|
||||
u_int references;
|
||||
};
|
||||
|
||||
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);
|
||||
hl->references = 1;
|
||||
return (hl);
|
||||
}
|
||||
|
||||
/* Copy hyperlink set. */
|
||||
struct hyperlinks *
|
||||
hyperlinks_copy(struct hyperlinks *hl)
|
||||
{
|
||||
hl->references++;
|
||||
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)
|
||||
{
|
||||
if (--hl->references == 0) {
|
||||
hyperlinks_reset(hl);
|
||||
free(hl);
|
||||
}
|
||||
}
|
||||
325
image-kitty.c
Normal file
325
image-kitty.c
Normal file
@@ -0,0 +1,325 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2026 Thomas Adam <thomas@xteddy.org>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* kitty_image stores the raw decoded pixel data and metadata from a kitty
|
||||
* graphics protocol APC sequence. It is used to re-emit the sequence to the
|
||||
* outer terminal on redraw.
|
||||
*/
|
||||
struct kitty_image {
|
||||
/* Control-data fields parsed from the APC sequence. */
|
||||
char action; /* a=: 'T'=transmit+display, 't', 'p', 'd' */
|
||||
u_int format; /* f=: 32=RGBA, 24=RGB, 100=PNG */
|
||||
char medium; /* t=: 'd'=direct, 'f'=file, 't'=tmp, 's'=shm */
|
||||
u_int pixel_w; /* s=: source image pixel width */
|
||||
u_int pixel_h; /* v=: source image pixel height */
|
||||
u_int cols; /* c=: display columns (0=auto) */
|
||||
u_int rows; /* r=: display rows (0=auto) */
|
||||
u_int image_id; /* i=: image id (0=unassigned) */
|
||||
u_int image_num; /* I=: image number */
|
||||
u_int placement_id; /* p=: placement id */
|
||||
u_int more; /* m=: 1=more chunks coming, 0=last */
|
||||
u_int quiet; /* q=: suppress responses */
|
||||
int z_index; /* z=: z-index */
|
||||
char compression; /* o=: 'z'=zlib, 0=none */
|
||||
char delete_what; /* d=: delete target (used with a=d) */
|
||||
|
||||
/* Cell size at the time of parsing (from the owning window). */
|
||||
u_int xpixel;
|
||||
u_int ypixel;
|
||||
|
||||
/* Original base64-encoded payload (concatenated across all chunks). */
|
||||
char *encoded;
|
||||
size_t encodedlen;
|
||||
|
||||
char *ctrl;
|
||||
size_t ctrllen;
|
||||
};
|
||||
|
||||
/*
|
||||
* Parse control-data key=value pairs from a kitty APC sequence.
|
||||
* Format: key=value,key=value,...
|
||||
*/
|
||||
static int
|
||||
kitty_parse_control(const char *ctrl, size_t ctrllen, struct kitty_image *ki)
|
||||
{
|
||||
const char *p = ctrl, *end = ctrl + ctrllen, *errstr;
|
||||
char key[4], val[32];
|
||||
size_t klen, vlen;
|
||||
|
||||
while (p < end) {
|
||||
klen = 0;
|
||||
while (p < end && *p != '=' && klen < sizeof(key) - 1)
|
||||
key[klen++] = *p++;
|
||||
key[klen] = '\0';
|
||||
if (p >= end || *p != '=')
|
||||
return (-1);
|
||||
p++;
|
||||
|
||||
vlen = 0;
|
||||
while (p < end && *p != ',' && vlen < sizeof(val) - 1)
|
||||
val[vlen++] = *p++;
|
||||
val[vlen] = '\0';
|
||||
if (p < end && *p == ',')
|
||||
p++;
|
||||
|
||||
if (klen != 1)
|
||||
continue;
|
||||
|
||||
switch (key[0]) {
|
||||
case 'a':
|
||||
ki->action = val[0];
|
||||
break;
|
||||
case 'f':
|
||||
ki->format = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 't':
|
||||
ki->medium = val[0];
|
||||
break;
|
||||
case 's':
|
||||
ki->pixel_w = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'v':
|
||||
ki->pixel_h = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'c':
|
||||
ki->cols = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'r':
|
||||
ki->rows = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'i':
|
||||
ki->image_id = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'I':
|
||||
ki->image_num = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'p':
|
||||
ki->placement_id = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'm':
|
||||
ki->more = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'q':
|
||||
ki->quiet = strtonum(val, 0, UINT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'z':
|
||||
ki->z_index = strtonum(val, INT_MIN, INT_MAX, &errstr);
|
||||
if (errstr != NULL)
|
||||
return (-1);
|
||||
break;
|
||||
case 'o':
|
||||
ki->compression = val[0];
|
||||
break;
|
||||
case 'd':
|
||||
ki->delete_what = val[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse a kitty APC body (after the leading 'G').
|
||||
* Stores the original control string and base64 payload verbatim for
|
||||
* pass-through re-emission to the outer terminal.
|
||||
*/
|
||||
struct kitty_image *
|
||||
kitty_parse(const u_char *buf, size_t len, u_int xpixel, u_int ypixel)
|
||||
{
|
||||
struct kitty_image *ki;
|
||||
const u_char *semi;
|
||||
const char *ctrl;
|
||||
size_t ctrllen, paylen;
|
||||
|
||||
if (len == 0)
|
||||
return (NULL);
|
||||
|
||||
semi = memchr(buf, ';', len);
|
||||
if (semi != NULL) {
|
||||
ctrl = (const char *)buf;
|
||||
ctrllen = semi - buf;
|
||||
paylen = len - ctrllen - 1;
|
||||
} else {
|
||||
ctrl = (const char *)buf;
|
||||
ctrllen = len;
|
||||
paylen = 0;
|
||||
}
|
||||
|
||||
ki = xcalloc(1, sizeof *ki);
|
||||
ki->xpixel = xpixel;
|
||||
ki->ypixel = ypixel;
|
||||
ki->action = 'T';
|
||||
ki->format = 32;
|
||||
ki->medium = 'd';
|
||||
|
||||
if (kitty_parse_control(ctrl, ctrllen, ki) != 0) {
|
||||
free(ki);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (paylen > 0) {
|
||||
ki->encoded = xmalloc(paylen + 1);
|
||||
memcpy(ki->encoded, semi + 1, paylen);
|
||||
ki->encoded[paylen] = '\0';
|
||||
ki->encodedlen = paylen;
|
||||
}
|
||||
|
||||
ki->ctrl = xmalloc(ctrllen + 1);
|
||||
memcpy(ki->ctrl, ctrl, ctrllen);
|
||||
ki->ctrl[ctrllen] = '\0';
|
||||
ki->ctrllen = ctrllen;
|
||||
|
||||
return (ki);
|
||||
}
|
||||
|
||||
void
|
||||
kitty_free(struct kitty_image *ki)
|
||||
{
|
||||
if (ki == NULL)
|
||||
return;
|
||||
free(ki->encoded);
|
||||
free(ki->ctrl);
|
||||
free(ki);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the size in cells of a kitty image. If cols/rows are 0 (auto),
|
||||
* calculate from pixel dimensions. Returns size via sx/sy pointers.
|
||||
*/
|
||||
void
|
||||
kitty_size_in_cells(struct kitty_image *ki, u_int *sx, u_int *sy)
|
||||
{
|
||||
*sx = ki->cols;
|
||||
*sy = ki->rows;
|
||||
|
||||
/*
|
||||
* If cols/rows are 0, they mean "auto" - calculate from
|
||||
* pixel dimensions.
|
||||
*/
|
||||
if (*sx == 0 && ki->pixel_w > 0 && ki->xpixel > 0) {
|
||||
*sx = (ki->pixel_w + ki->xpixel - 1) / ki->xpixel;
|
||||
}
|
||||
if (*sy == 0 && ki->pixel_h > 0 && ki->ypixel > 0) {
|
||||
*sy = (ki->pixel_h + ki->ypixel - 1) / ki->ypixel;
|
||||
}
|
||||
|
||||
/* If still 0, use a reasonable default */
|
||||
if (*sx == 0)
|
||||
*sx = 10;
|
||||
if (*sy == 0)
|
||||
*sy = 10;
|
||||
}
|
||||
|
||||
char
|
||||
kitty_get_action(struct kitty_image *ki)
|
||||
{
|
||||
return (ki->action);
|
||||
}
|
||||
|
||||
u_int
|
||||
kitty_get_image_id(struct kitty_image *ki)
|
||||
{
|
||||
return (ki->image_id);
|
||||
}
|
||||
|
||||
u_int
|
||||
kitty_get_rows(struct kitty_image *ki)
|
||||
{
|
||||
return (ki->rows);
|
||||
}
|
||||
|
||||
/*
|
||||
* Serialize a kitty_image back into an APC escape sequence for transmission
|
||||
* to the terminal. This recreates the original command that was parsed.
|
||||
*/
|
||||
char *
|
||||
kitty_print(struct kitty_image *ki, size_t *outlen)
|
||||
{
|
||||
char *out;
|
||||
size_t total, pos;
|
||||
|
||||
if (ki == NULL || ki->ctrl == NULL)
|
||||
return (NULL);
|
||||
|
||||
/* Calculate total length: ESC _ G + ctrl + ; + encoded + ESC \ */
|
||||
total = 3 + ki->ctrllen; /* \033_G + ctrl */
|
||||
if (ki->encoded != NULL && ki->encodedlen > 0) {
|
||||
total += 1 + ki->encodedlen; /* ; + encoded */
|
||||
}
|
||||
total += 2; /* \033\\ */
|
||||
|
||||
out = xmalloc(total + 1);
|
||||
*outlen = total;
|
||||
|
||||
/* Build the sequence */
|
||||
pos = 0;
|
||||
memcpy(out + pos, "\033_G", 3);
|
||||
pos += 3;
|
||||
memcpy(out + pos, ki->ctrl, ki->ctrllen);
|
||||
pos += ki->ctrllen;
|
||||
|
||||
if (ki->encoded != NULL && ki->encodedlen > 0) {
|
||||
out[pos++] = ';';
|
||||
memcpy(out + pos, ki->encoded, ki->encodedlen);
|
||||
pos += ki->encodedlen;
|
||||
}
|
||||
|
||||
memcpy(out + pos, "\033\\", 2);
|
||||
pos += 2;
|
||||
out[pos] = '\0';
|
||||
|
||||
return (out);
|
||||
}
|
||||
|
||||
char *
|
||||
kitty_delete_all(size_t *outlen)
|
||||
{
|
||||
char *out;
|
||||
|
||||
out = xstrdup("\033_Ga=d,d=a\033\\");
|
||||
*outlen = strlen(out);
|
||||
return (out);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user