mirror of
https://github.com/tmux/tmux.git
synced 2026-03-12 03:25:45 +00:00
Compare commits
749 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c22470bd14 | ||
|
|
31cb95893e | ||
|
|
52b8274285 | ||
|
|
a924694820 | ||
|
|
0a94dbe051 | ||
|
|
ebc9dcb3bb | ||
|
|
f31847db62 | ||
|
|
e337c1ba7d | ||
|
|
db5a7c1740 | ||
|
|
53914e50b9 | ||
|
|
e252984993 | ||
|
|
17bc11bd15 | ||
|
|
1a3a973bd0 | ||
|
|
e4eec92852 | ||
|
|
75d112c484 | ||
|
|
a05c3a7aa6 | ||
|
|
47795d1695 | ||
|
|
7cdb1cfc8d | ||
|
|
8827b7f9a6 | ||
|
|
7eeb479705 | ||
|
|
8d137233a9 | ||
|
|
05d07413ff | ||
|
|
b8360504f3 | ||
|
|
a062650d4b | ||
|
|
f012db9be9 | ||
|
|
299d4f3aaa | ||
|
|
eba6cf61c9 | ||
|
|
0ec410689c | ||
|
|
e0fd295054 | ||
|
|
99a8469ee4 | ||
|
|
12255411f2 | ||
|
|
c0116b2c5b | ||
|
|
799a154b91 | ||
|
|
793f4d89d6 | ||
|
|
90cd045cf3 | ||
|
|
94f6488f0e | ||
|
|
d4bf4bd7c7 | ||
|
|
522d1bd309 | ||
|
|
a21de4c483 | ||
|
|
714311a696 | ||
|
|
9f0904ce6f | ||
|
|
ae3eba6e08 | ||
|
|
6b332127ca | ||
|
|
bd40d704e2 | ||
|
|
65e5e14561 | ||
|
|
103e44d936 | ||
|
|
097973e3d5 | ||
|
|
5fef946df4 | ||
|
|
023c2c5392 | ||
|
|
e90d4a6021 | ||
|
|
2e84d1cf03 | ||
|
|
6431005169 | ||
|
|
9beb3eb593 | ||
|
|
6dee409981 | ||
|
|
f3fc81b178 | ||
|
|
463bd8abb9 | ||
|
|
a65a6d62d1 | ||
|
|
207789dc2d | ||
|
|
d7586d3d65 | ||
|
|
f8d3d247d8 | ||
|
|
6b0fa14470 | ||
|
|
a69211aff5 | ||
|
|
930245d7ff | ||
|
|
0dc8b7d5d8 | ||
|
|
19a3a9ee20 | ||
|
|
f3e01ecc42 | ||
|
|
6c260af56d | ||
|
|
e817821104 | ||
|
|
f006116bac | ||
|
|
43431e7e84 | ||
|
|
eb8b51effc | ||
|
|
389cf63cbc | ||
|
|
2148fe33cd | ||
|
|
1a6540fea0 | ||
|
|
7d702f3cef | ||
|
|
d0c462f718 | ||
|
|
238d2aa870 | ||
|
|
6bb505eb73 | ||
|
|
83b9807370 | ||
|
|
3e6e533779 | ||
|
|
27bfb56ad5 | ||
|
|
c49f2a0365 | ||
|
|
3e3eb1dd0f | ||
|
|
a4fe7e81c8 | ||
|
|
4ce26b0393 | ||
|
|
82bf0f4d48 | ||
|
|
8590ee65e6 | ||
|
|
d67b99c7e4 | ||
|
|
092c7bfeb8 | ||
|
|
bf2cf33fc6 | ||
|
|
75aeb733f2 | ||
|
|
723010ba72 | ||
|
|
7ca2e2fe88 | ||
|
|
9d450cc6d0 | ||
|
|
5571d7a21c | ||
|
|
e353d0cab3 | ||
|
|
282f7fbd37 | ||
|
|
b68fc7f104 | ||
|
|
54dfe36340 | ||
|
|
c4f4904f9b | ||
|
|
d769fec8d6 | ||
|
|
f1ce611345 | ||
|
|
3856116069 | ||
|
|
afe231c94c | ||
|
|
ae4cccb4f1 | ||
|
|
98ee93bde3 | ||
|
|
87d82170a6 | ||
|
|
3a7e15511b | ||
|
|
e128c7fcd8 | ||
|
|
8db89f8efb | ||
|
|
c271cb9ff8 | ||
|
|
6e0c663a89 | ||
|
|
56246c2936 | ||
|
|
54da493476 | ||
|
|
82ebd98c5f | ||
|
|
831c67c2d8 | ||
|
|
d6f7be6345 | ||
|
|
eb064e8a62 | ||
|
|
9b83b1daa6 | ||
|
|
4acd345c6a | ||
|
|
d9ac0e7576 | ||
|
|
dcf0bc2cc9 | ||
|
|
cf4566b47b | ||
|
|
50e77536fe | ||
|
|
cd4e467751 | ||
|
|
9228fead48 | ||
|
|
38b8a198ba | ||
|
|
1eefbd28e8 | ||
|
|
1ee944a19d | ||
|
|
1b0512aa7e | ||
|
|
b5b5d35eee | ||
|
|
c5f660e33a | ||
|
|
e1e520d741 | ||
|
|
699d9d2fac | ||
|
|
c3c3927c2b | ||
|
|
00f19b7f91 | ||
|
|
42da951edf | ||
|
|
180bbab1fc | ||
|
|
69c59c52b6 | ||
|
|
19370631ea | ||
|
|
99c1853792 | ||
|
|
a131655235 | ||
|
|
677bb168a9 | ||
|
|
c91323e4d6 | ||
|
|
50d1d04913 | ||
|
|
67e2f5869a | ||
|
|
3a9c199ae7 | ||
|
|
bd6d0b3101 | ||
|
|
f1dd65cbdf | ||
|
|
c18d7c5fcb | ||
|
|
0d64531f66 | ||
|
|
f44dafd224 | ||
|
|
198b0a23a2 | ||
|
|
ad27b7decd | ||
|
|
fc00839adc | ||
|
|
aa13bd4016 | ||
|
|
d62fd78655 | ||
|
|
6dcca5fda4 | ||
|
|
c5f6ea5c0d | ||
|
|
004a9b52f0 | ||
|
|
e5f06d2cf6 | ||
|
|
cb10bfb8ef | ||
|
|
2e00d775e4 | ||
|
|
21d9750450 | ||
|
|
f431e20f3d | ||
|
|
3c68e51609 | ||
|
|
299b7289ea | ||
|
|
4bc45fc95a | ||
|
|
f9682d2e55 | ||
|
|
a384245c5a | ||
|
|
b24d7d9c95 | ||
|
|
453a62c672 | ||
|
|
89db309e10 | ||
|
|
d53d3bce59 | ||
|
|
3439c02e9d | ||
|
|
fcd0e3082b | ||
|
|
d9767b8112 | ||
|
|
85a9c2f52b | ||
|
|
69440d19b7 | ||
|
|
eac30a86d7 | ||
|
|
d4177e954c | ||
|
|
45ae9a8e35 | ||
|
|
9f75635596 | ||
|
|
4d505574dc | ||
|
|
e8e4f4ec3e | ||
|
|
4097257bef | ||
|
|
a14512e23e | ||
|
|
84e4652513 | ||
|
|
fc3d85e34b | ||
|
|
43656d4ea7 | ||
|
|
fff85d854e | ||
|
|
cf6075fb29 | ||
|
|
33298d6df6 | ||
|
|
4bb48998e0 | ||
|
|
5d9e591ae8 | ||
|
|
4d16df9312 | ||
|
|
18e554aa61 | ||
|
|
4cb13d95ba | ||
|
|
e36d6ee06a | ||
|
|
901eed7b71 | ||
|
|
750d5830c2 | ||
|
|
e286178aa7 | ||
|
|
c176361788 | ||
|
|
dc7e53897a | ||
|
|
429c4bc51b | ||
|
|
1156d91cf8 | ||
|
|
4c5b0fbbcc | ||
|
|
5a288b1efe | ||
|
|
82c789ee58 | ||
|
|
7e0f9ab3eb | ||
|
|
87bd8965c6 | ||
|
|
2aa517c805 | ||
|
|
ec81bd2399 | ||
|
|
3ab229da70 | ||
|
|
2cecabd75e | ||
|
|
c4b0da5513 | ||
|
|
5489796737 | ||
|
|
85f09f9a4c | ||
|
|
293fd0d258 | ||
|
|
dfb7bb6830 | ||
|
|
f1e14f86c4 | ||
|
|
6644d209d2 | ||
|
|
7c4a2253e8 | ||
|
|
2d65bbd941 | ||
|
|
a609e6361a | ||
|
|
32a81e197b | ||
|
|
f2c0605d6d | ||
|
|
1677bb0dea | ||
|
|
dddc544b8f | ||
|
|
643eecde86 | ||
|
|
567d3e27ab | ||
|
|
a2e08b587a | ||
|
|
cb75ec25c8 | ||
|
|
7d06216289 | ||
|
|
4ab208ecc8 | ||
|
|
6aa0bedad2 | ||
|
|
c6e39976c6 | ||
|
|
c869366133 | ||
|
|
b9022e33ea | ||
|
|
772b3b7a06 | ||
|
|
b0d7623b7e | ||
|
|
4a96f599f6 | ||
|
|
564e44adc6 | ||
|
|
6752f41c2a | ||
|
|
51c09bf2b4 | ||
|
|
d24a44230a | ||
|
|
8d752f5aaa | ||
|
|
e7827f8bc2 | ||
|
|
f980e868dd | ||
|
|
3c1f0cfc34 | ||
|
|
5b9211d827 | ||
|
|
3f189945d8 | ||
|
|
f3ab05e7cd | ||
|
|
2219f7cc73 | ||
|
|
1fd3b9ec1c | ||
|
|
da31eddadc | ||
|
|
c660e46149 | ||
|
|
e3b1358bbc | ||
|
|
5943cd1907 | ||
|
|
78287e27c8 | ||
|
|
82bc2c87a9 | ||
|
|
cd4c94f76b | ||
|
|
bba1809eac | ||
|
|
e6ee3e9504 | ||
|
|
1c1ec84aa3 | ||
|
|
f3fcf977e4 | ||
|
|
4a3ac3bd26 | ||
|
|
3c5d3a3780 | ||
|
|
fe44f90e5b | ||
|
|
031e9bc854 | ||
|
|
0cbccc90ab | ||
|
|
71d90c11dd | ||
|
|
2546572e8e | ||
|
|
835ccbac46 | ||
|
|
b5b67c5386 | ||
|
|
fbe488e4de | ||
|
|
bb629f3be7 | ||
|
|
883a428e27 | ||
|
|
e44e2c48dd | ||
|
|
ece737274e | ||
|
|
5ece386cdf | ||
|
|
7653328ce7 | ||
|
|
fc111d2b12 | ||
|
|
04402db616 | ||
|
|
1b5a8a0f09 | ||
|
|
e33b623f21 | ||
|
|
73b54a0e5f | ||
|
|
5a97af7961 | ||
|
|
f4aefb738e | ||
|
|
481c3f3f2e | ||
|
|
cb039b986e | ||
|
|
f6c54f3f03 | ||
|
|
06d58b3b7b | ||
|
|
8968acd678 | ||
|
|
c9ef144dca | ||
|
|
09f71ed1b2 | ||
|
|
f0ddc301b7 | ||
|
|
916c4c499d | ||
|
|
fac792dc27 | ||
|
|
bbcfee362f | ||
|
|
bfc1f0ca62 | ||
|
|
7bcc0d16f2 | ||
|
|
f03776c262 | ||
|
|
ffa4d48967 | ||
|
|
79c3fd4f39 | ||
|
|
6d071c468c | ||
|
|
294accea1b | ||
|
|
792fcb1dbf | ||
|
|
da359269cb | ||
|
|
92da105b58 | ||
|
|
ecc5cea09b | ||
|
|
d68a17a1df | ||
|
|
52cb7a6382 | ||
|
|
00fda57ddf | ||
|
|
405bb8435c | ||
|
|
c6c4960b35 | ||
|
|
2c4f2393ec | ||
|
|
08bc226527 | ||
|
|
6b38334b28 | ||
|
|
c1f0918f8a | ||
|
|
6861045d38 | ||
|
|
9f8d193b11 | ||
|
|
a13e57f701 | ||
|
|
e722ba38e3 | ||
|
|
b1dc2b5353 | ||
|
|
e0e08fcd2d | ||
|
|
0a913b09cf | ||
|
|
4f7a5d1e40 | ||
|
|
6ac84585e6 | ||
|
|
d21f8ecc13 | ||
|
|
5e2150cf18 | ||
|
|
a07ad6b5a3 | ||
|
|
ff4d7d541f | ||
|
|
e8f4ca6a52 | ||
|
|
a084f2dcb7 | ||
|
|
517d673dbe | ||
|
|
b4a301f8fe | ||
|
|
04a1fc9d36 | ||
|
|
0292243b29 | ||
|
|
ef38a420b2 | ||
|
|
7536d57b16 | ||
|
|
9ee1a8f701 | ||
|
|
0e0f2f765b | ||
|
|
bff957a475 | ||
|
|
ed962e7612 | ||
|
|
458b87150b | ||
|
|
ae46a19b8e | ||
|
|
3b959c05ff | ||
|
|
46f642b030 | ||
|
|
8b74e959ef | ||
|
|
320237fdb8 | ||
|
|
161b57869e | ||
|
|
92732a2540 | ||
|
|
b3eebdec48 | ||
|
|
b24c9e34a9 | ||
|
|
073d439965 | ||
|
|
f956c17c09 | ||
|
|
0406ec0ec2 | ||
|
|
f34ebfed76 | ||
|
|
962f255ee8 | ||
|
|
c62404673e | ||
|
|
979313832c | ||
|
|
1d6fe43c7b | ||
|
|
4cbf596dc5 | ||
|
|
d738d51688 | ||
|
|
acb2413852 | ||
|
|
2628af573d | ||
|
|
aa2b3472c5 | ||
|
|
ce6be7afd4 | ||
|
|
d2d43987d0 | ||
|
|
bd3332b211 | ||
|
|
3a298454ce | ||
|
|
b588b1729a | ||
|
|
818fda0363 | ||
|
|
b4f5b99e4b | ||
|
|
e8b33af780 | ||
|
|
1d306e926a | ||
|
|
33595a255f | ||
|
|
85044a634b | ||
|
|
2d71bef0ca | ||
|
|
f6d34f066c | ||
|
|
672c49d512 | ||
|
|
27578815da | ||
|
|
25e2e22791 | ||
|
|
10d60faba5 | ||
|
|
2c755e3c55 | ||
|
|
bace79a571 | ||
|
|
4206bcc10e | ||
|
|
38064e7593 | ||
|
|
1416ceb575 | ||
|
|
d58bccfc63 | ||
|
|
9bd4b96766 | ||
|
|
0b32fa81b6 | ||
|
|
0425e3178d | ||
|
|
13f9a061ac | ||
|
|
f33d2ab29e | ||
|
|
1e9f8a3523 | ||
|
|
2fbd491ff0 | ||
|
|
81b393a493 | ||
|
|
5755bfc619 | ||
|
|
10f0094be9 | ||
|
|
786f5e505e | ||
|
|
6dffbc4849 | ||
|
|
e6fd429d58 | ||
|
|
95ab1aaaec | ||
|
|
f628afc850 | ||
|
|
49f04a997a | ||
|
|
1aeac384f3 | ||
|
|
9032ac2a05 | ||
|
|
71e00c718c | ||
|
|
7a6b21de65 | ||
|
|
4f5cb88c2b | ||
|
|
0e6eda02a6 | ||
|
|
feaa5660a3 | ||
|
|
b03f58b977 | ||
|
|
b2bc34af12 | ||
|
|
400529eea0 | ||
|
|
938156d73b | ||
|
|
ba4a884d75 | ||
|
|
2796ae81d0 | ||
|
|
f3f534a3a0 | ||
|
|
6c3ee42568 | ||
|
|
2f0ffe6adb | ||
|
|
4002dbf0c1 | ||
|
|
162d3cb1f4 | ||
|
|
7d2004a8dd | ||
|
|
860acecc0d | ||
|
|
028f9d1d87 | ||
|
|
303d20a758 | ||
|
|
3f0efc050a | ||
|
|
7804fa1b82 | ||
|
|
7b819357ff | ||
|
|
595b52490e | ||
|
|
3ec05e9405 | ||
|
|
f8a30e1588 | ||
|
|
3f6bfbaf2b | ||
|
|
95d340cc4f | ||
|
|
ff4c80d53d | ||
|
|
bc72cf2f52 | ||
|
|
de730f68a4 | ||
|
|
9cc04a0f9a | ||
|
|
349aeb806a | ||
|
|
f98c66ece8 | ||
|
|
a1009e7bd3 | ||
|
|
3c24bc5617 | ||
|
|
7f093fcddc | ||
|
|
5a564a0c1a | ||
|
|
9ebd630675 | ||
|
|
5cdd578906 | ||
|
|
a870c255c4 | ||
|
|
d5c837904b | ||
|
|
fa33603dc1 | ||
|
|
fa8294436c | ||
|
|
82f0c859a2 | ||
|
|
9768091ee4 | ||
|
|
f9c396db41 | ||
|
|
bdb7e48cba | ||
|
|
c42e89a598 | ||
|
|
afd3127d89 | ||
|
|
4ab3b18b36 | ||
|
|
2ea22fce5e | ||
|
|
cd8a7fb07b | ||
|
|
cd39920abd | ||
|
|
469a9e9439 | ||
|
|
34c0807be6 | ||
|
|
c9d482ab48 | ||
|
|
bde0224deb | ||
|
|
b6cdac05c7 | ||
|
|
4e3d661284 | ||
|
|
1c5093c1c4 | ||
|
|
67254ed8df | ||
|
|
6cf2f74fe9 | ||
|
|
1ed994a6c8 | ||
|
|
40d246b29c | ||
|
|
2977317243 | ||
|
|
3a7b9d5735 | ||
|
|
2eca63b98e | ||
|
|
c4b04b1624 | ||
|
|
efd01f3bfd | ||
|
|
749f67b7d8 | ||
|
|
a7da2357a5 | ||
|
|
f103927a52 | ||
|
|
0fd73f238d | ||
|
|
50cdfc06fb | ||
|
|
3c6cdf0115 | ||
|
|
86e648d906 | ||
|
|
849d06c0df | ||
|
|
09aee53763 | ||
|
|
4efba0bf9f | ||
|
|
0c7f64458f | ||
|
|
ff77010f70 | ||
|
|
7339845c01 | ||
|
|
99072e1d81 | ||
|
|
f9881b3b5d | ||
|
|
b1ad075d11 | ||
|
|
ef904cfef2 | ||
|
|
ddffda4da5 | ||
|
|
d5b92ac37e | ||
|
|
0a54a07909 | ||
|
|
65dd7345e0 | ||
|
|
0cefdff1b6 | ||
|
|
e771f10dc6 | ||
|
|
fc41bf46ac | ||
|
|
2808f8261c | ||
|
|
c234032fcf | ||
|
|
bc6211cca5 | ||
|
|
164590e34c | ||
|
|
9feb35b7c4 | ||
|
|
f44d02c7f5 | ||
|
|
646995384d | ||
|
|
2dfdb55ace | ||
|
|
a51668ca06 | ||
|
|
bc0e527f32 | ||
|
|
f54f171d5c | ||
|
|
01918cb017 | ||
|
|
a2c52d9f26 | ||
|
|
407075d8c7 | ||
|
|
cdd8c93f54 | ||
|
|
c88e945bc5 | ||
|
|
018f1b8a80 | ||
|
|
4b9e76aaaa | ||
|
|
46847e9b2e | ||
|
|
1952b3f746 | ||
|
|
546060f340 | ||
|
|
c44bb2df17 | ||
|
|
f7c85f3ed8 | ||
|
|
5a7cf897f2 | ||
|
|
8053b65f1e | ||
|
|
a00cdcdfcb | ||
|
|
228e1a3951 | ||
|
|
ebaf54251a | ||
|
|
b74b047730 | ||
|
|
04c6db2d0f | ||
|
|
6abb62df1e | ||
|
|
7cf00d6b72 | ||
|
|
7d59f82cf9 | ||
|
|
cbf1504fca | ||
|
|
83b2d5c513 | ||
|
|
b4e74f4310 | ||
|
|
26d73a7736 | ||
|
|
57069287a1 | ||
|
|
4799f43298 | ||
|
|
7bc6c105b7 | ||
|
|
ad71e7f9d2 | ||
|
|
71d2ab184b | ||
|
|
c067af8e7d | ||
|
|
3fa538181b | ||
|
|
be2201200f | ||
|
|
84df87011c | ||
|
|
5e36d52651 | ||
|
|
bd9133b31d | ||
|
|
9b32758a0c | ||
|
|
5aa435a9f0 | ||
|
|
1b92afa799 | ||
|
|
a618271e12 | ||
|
|
8598fd1bc5 | ||
|
|
59df942e09 | ||
|
|
621bb15b83 | ||
|
|
8e24b0bb3e | ||
|
|
0c07b10b30 | ||
|
|
8f9491ddfe | ||
|
|
9bab73f489 | ||
|
|
4e867202e8 | ||
|
|
e27b588b6c | ||
|
|
479cac4896 | ||
|
|
95e3e363ff | ||
|
|
7637518b07 | ||
|
|
9263a65b5f | ||
|
|
b29028a914 | ||
|
|
1ea17a72f0 | ||
|
|
f57aa143c1 | ||
|
|
e53094bc5f | ||
|
|
18b611bc8d | ||
|
|
79d2351ce8 | ||
|
|
79a9472dbc | ||
|
|
d64daf874f | ||
|
|
1b4402c823 | ||
|
|
7fbd2f5498 | ||
|
|
45841400f2 | ||
|
|
f38b5a1b58 | ||
|
|
da5d563375 | ||
|
|
bceccc6b63 | ||
|
|
183193bdbc | ||
|
|
5b93f0fcd3 | ||
|
|
ee3e0eb183 | ||
|
|
55db3623bf | ||
|
|
db8849e7ca | ||
|
|
bfc9fb4b3b | ||
|
|
314ee137a9 | ||
|
|
f36d2ecb07 | ||
|
|
98a478ceb3 | ||
|
|
9f39470b38 | ||
|
|
458b4b7701 | ||
|
|
31508228bc | ||
|
|
1e8c9fb490 | ||
|
|
098967a085 | ||
|
|
665f046950 | ||
|
|
641191ab20 | ||
|
|
9f2db6a0af | ||
|
|
bf03197e18 | ||
|
|
cac4eadca0 | ||
|
|
3310972d75 | ||
|
|
d95fad3d5f | ||
|
|
9ecf657703 | ||
|
|
88327c7698 | ||
|
|
e811132b05 | ||
|
|
bd2896b65e | ||
|
|
522d751eee | ||
|
|
3bc08b0dc0 | ||
|
|
af679326b2 | ||
|
|
aa6e6fa0f2 | ||
|
|
9bdbe171b7 | ||
|
|
98a3c98c28 | ||
|
|
de2ddddd60 | ||
|
|
a9ffb56b65 | ||
|
|
14b97fc889 | ||
|
|
d0a600ccaa | ||
|
|
a368548645 | ||
|
|
13fe06a459 | ||
|
|
87e87030fe | ||
|
|
a5ef1f2ed6 | ||
|
|
f5d7a80272 | ||
|
|
33f9b316a3 | ||
|
|
d6ff630498 | ||
|
|
eceaa9a493 | ||
|
|
2e19a5ecb9 | ||
|
|
fb1f0fee5a | ||
|
|
6048b0f483 | ||
|
|
f12b857415 | ||
|
|
79bdca4638 | ||
|
|
21f8ac2766 | ||
|
|
89b56c3451 | ||
|
|
fe7486d43b | ||
|
|
400b807d75 | ||
|
|
5f07da6227 | ||
|
|
7eb3ef66e5 | ||
|
|
82776c456e | ||
|
|
80bdd89856 | ||
|
|
ed6327c87b | ||
|
|
b21a710de7 | ||
|
|
aa32457772 | ||
|
|
5c78b48cdf | ||
|
|
5fc2d4a4fc | ||
|
|
969af935f3 | ||
|
|
4f04b2094c | ||
|
|
0d88f8a78b | ||
|
|
6de991d855 | ||
|
|
ff67ef945d | ||
|
|
711b8164bb | ||
|
|
35985c0add | ||
|
|
cfc81692e6 | ||
|
|
a4a7c3c68d | ||
|
|
e7d53020b4 | ||
|
|
03519021b9 | ||
|
|
6f2698004e | ||
|
|
28a5bc8fae | ||
|
|
20154f391e | ||
|
|
98c4291df2 | ||
|
|
5c0ce192ed | ||
|
|
cc743dc296 | ||
|
|
d254293a6d | ||
|
|
850c26dd46 | ||
|
|
db07f33886 | ||
|
|
2fae6a5761 | ||
|
|
2ee0962c96 | ||
|
|
42935bde71 | ||
|
|
ffebf00585 | ||
|
|
ead6d652ff | ||
|
|
a14aa788d4 | ||
|
|
d8721b35a0 | ||
|
|
97738921cd | ||
|
|
486ce9b098 | ||
|
|
8fb6666f17 | ||
|
|
cb77c2aa78 | ||
|
|
0c94c3fbee | ||
|
|
94712a8b0d | ||
|
|
dec6ec9e29 | ||
|
|
9da78d72de | ||
|
|
d0c992306d | ||
|
|
54c2d48d7d | ||
|
|
e6cbeb4f38 | ||
|
|
4581240ced | ||
|
|
f6bad7efd7 | ||
|
|
713e0ddef3 | ||
|
|
ff45b2d343 | ||
|
|
91280f1fca | ||
|
|
7de25d86e1 | ||
|
|
ba31d3a88c | ||
|
|
54cd292f09 | ||
|
|
d1f5142dab | ||
|
|
058d2b94dc | ||
|
|
c177a627d2 | ||
|
|
8f8e0975f1 | ||
|
|
b602c1fb9a | ||
|
|
7448b38327 | ||
|
|
85d5a377c5 | ||
|
|
b9a6162d2f | ||
|
|
8f5903d7c3 | ||
|
|
f0ac0d6793 | ||
|
|
2a04665626 | ||
|
|
07c0970f54 | ||
|
|
546123f950 | ||
|
|
f2f9605c63 | ||
|
|
e4e060f2be | ||
|
|
e3b034fac7 | ||
|
|
82c0eed36d | ||
|
|
80994a8de1 | ||
|
|
9e1093b7d7 | ||
|
|
f2029f9d9e | ||
|
|
b2a2c3a1e9 | ||
|
|
f915a4bf0c | ||
|
|
91b220525b | ||
|
|
988c6bc433 | ||
|
|
1d858aa89e | ||
|
|
e24a077752 | ||
|
|
645fe9013f | ||
|
|
896c1da7da | ||
|
|
d24bd7394d | ||
|
|
aebb17dc75 | ||
|
|
d9d2f84a4b | ||
|
|
068d1b97b2 | ||
|
|
4bf6f2706e | ||
|
|
9f39652d87 | ||
|
|
c48440fd40 | ||
|
|
1afe71cc0a | ||
|
|
0e1b339c10 | ||
|
|
3dceddd70e | ||
|
|
2595718dd3 | ||
|
|
6ebd737590 | ||
|
|
e64d078a4c | ||
|
|
ae0b7c7d72 | ||
|
|
a770ef3e2a | ||
|
|
b95d1de8fd | ||
|
|
7e5262ae9a | ||
|
|
14ecb5032e | ||
|
|
1bd66b65a3 | ||
|
|
051a29ca03 | ||
|
|
c6975b3bb4 | ||
|
|
68bf7c532b | ||
|
|
9b73d76ddd | ||
|
|
5d616f4c72 | ||
|
|
b5c0b2cae2 | ||
|
|
803b8815bd | ||
|
|
640d97afd0 | ||
|
|
194e9f611b | ||
|
|
5512de6a61 | ||
|
|
26792b9035 | ||
|
|
919f55ac4a | ||
|
|
80283f99fb |
71
.github/CONTRIBUTING.md
vendored
Normal file
71
.github/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
## What should I do before opening an issue?
|
||||
|
||||
Before opening an issue, please ensure that:
|
||||
|
||||
- `$TERM` inside tmux is screen, screen-256color, tmux or tmux-256color. Check
|
||||
by running `echo $TERM` inside tmux.
|
||||
|
||||
- You can reproduce the problem with the latest tmux release, or a build from
|
||||
Git master.
|
||||
|
||||
- Your question or issue is not covered in the manual (run man tmux).
|
||||
|
||||
- Nobody else has opened the same issue recently.
|
||||
|
||||
## What should I include in an issue?
|
||||
|
||||
Please include the output of:
|
||||
|
||||
~~~bash
|
||||
uname -sp && tmux -V && echo $TERM
|
||||
~~~
|
||||
|
||||
Also include:
|
||||
|
||||
- Your platform (Linux, OS X, or whatever).
|
||||
|
||||
- A brief description of the problem with steps to reproduce.
|
||||
|
||||
- A minimal tmux config, if you can't reproduce without a config.
|
||||
|
||||
- Your terminal, and `$TERM` inside and outside of tmux.
|
||||
|
||||
- Logs from tmux (see below).
|
||||
|
||||
- At most one or two screenshots, if helpful.
|
||||
|
||||
## How do I test without a .tmux.conf?
|
||||
|
||||
Run a separate tmux server with `-f/dev/null` to skip loading `.tmux.conf`:
|
||||
|
||||
~~~bash
|
||||
tmux -Ltest kill-server
|
||||
tmux -Ltest -f/dev/null new
|
||||
~~~
|
||||
|
||||
## How do I get logs from tmux?
|
||||
|
||||
Add `-vv` to tmux to create three log files in the current directory. If you can
|
||||
reproduce without a configuration file:
|
||||
|
||||
~~~bash
|
||||
tmux -Ltest kill-server
|
||||
tmux -vv -Ltest -f/dev/null new
|
||||
~~~
|
||||
|
||||
Or if you need your configuration:
|
||||
|
||||
~~~base
|
||||
tmux kill-server
|
||||
tmux -vv new
|
||||
~~~
|
||||
|
||||
The log files are:
|
||||
|
||||
- `tmux-server*.log`: server log file.
|
||||
|
||||
- `tmux-client*.log`: client log file.
|
||||
|
||||
- `tmux-out*.log`: output log file.
|
||||
|
||||
Please attach the log files to your issue.
|
||||
19
.github/ISSUE_TEMPLATE.md
vendored
Normal file
19
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
### Issue description
|
||||
|
||||
Please read https://github.com/tmux/tmux/blob/master/.github/CONTRIBUTING.md
|
||||
before opening an issue.
|
||||
|
||||
Describe the problem and the steps to reproduce. Add a minimal tmux config if
|
||||
necessary. Screenshots can be helpful, but no more than one or two.
|
||||
|
||||
Do not report bugs (crashes, incorrect behaviour) without reproducing on a tmux
|
||||
built from the latest code in Git.
|
||||
|
||||
### Required information
|
||||
|
||||
Please provide the following information:
|
||||
|
||||
* tmux version (`tmux -V`).
|
||||
* Platform (`uname -sp`).
|
||||
* $TERM inside and outside of tmux (`echo $TERM`).
|
||||
* Logs from tmux (`tmux kill-server; tmux -vv new`).
|
||||
88
.github/README.md
vendored
Normal file
88
.github/README.md
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
# Welcome to tmux!
|
||||
|
||||
tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
||||
accessed, and controlled from a single screen. tmux may be detached from a
|
||||
screen and continue running in the background, then later reattached.
|
||||
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
||||
|
||||
## Dependencies
|
||||
|
||||
tmux depends on [libevent](https://libevent.org) 2.x, available from [this
|
||||
page](https://github.com/libevent/libevent/releases/latest).
|
||||
|
||||
It also depends on [ncurses](https://www.gnu.org/software/ncurses/), available
|
||||
from [this page](https://invisible-mirror.net/archives/ncurses/).
|
||||
|
||||
## Installation
|
||||
|
||||
### From release tarball
|
||||
|
||||
To build and install tmux from a release tarball, use:
|
||||
|
||||
~~~bash
|
||||
./configure && make
|
||||
sudo make install
|
||||
~~~
|
||||
|
||||
tmux can use the utempter library to update utmp(5), if it is installed - run
|
||||
configure with `--enable-utempter` to enable this.
|
||||
|
||||
### From version control
|
||||
|
||||
To get and build the latest from version control:
|
||||
|
||||
~~~bash
|
||||
git clone https://github.com/tmux/tmux.git
|
||||
cd tmux
|
||||
sh autogen.sh
|
||||
./configure && make
|
||||
~~~
|
||||
|
||||
(Note that this requires at least a working C compiler, `make`, `autoconf`,
|
||||
`automake`, `pkg-config` as well as `libevent` and `ncurses` libraries and
|
||||
headers.)
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports, feature suggestions and especially code contributions are most
|
||||
welcome. Please send by email to:
|
||||
|
||||
tmux-users@googlegroups.com
|
||||
|
||||
Or open a GitHub issue or pull request.
|
||||
|
||||
There is [a TODO list](https://github.com/tmux/tmux/wiki/Contributing) which
|
||||
explains some ideas for tmux not yet developed. Please feel free to ask for
|
||||
clarifications on the mailing list if you're thinking of working on these or
|
||||
need further information.
|
||||
|
||||
Please read the CONTRIBUTING file before opening an issue.
|
||||
|
||||
## Documentation
|
||||
|
||||
For documentation on using tmux, see the tmux.1 manpage. View it from the
|
||||
source tree with:
|
||||
|
||||
~~~bash
|
||||
nroff -mdoc tmux.1|less
|
||||
~~~
|
||||
|
||||
A small example configuration is in `example_tmux.conf`.
|
||||
|
||||
And a bash(1) completion file at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
|
||||
For debugging, run tmux with `-v` or `-vv` to generate server and client log
|
||||
files in the current directory.
|
||||
|
||||
## Support
|
||||
|
||||
The tmux mailing list for general discussion and bug reports is:
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-users
|
||||
|
||||
Subscribe by sending an email to:
|
||||
|
||||
tmux-users+subscribe@googlegroups.com
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -18,3 +18,4 @@ Makefile.in
|
||||
configure
|
||||
tmux.1.*
|
||||
*.dSYM
|
||||
cmd-parse.c
|
||||
|
||||
22
.travis.yml
22
.travis.yml
@@ -1,10 +1,16 @@
|
||||
language: c
|
||||
matrix:
|
||||
include:
|
||||
- compiler: gcc
|
||||
- compiler: clang
|
||||
env: CFLAGS="-g -O2"
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_install:
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get -y install debhelper autotools-dev dh-autoreconf file libncurses5-dev libevent-dev pkg-config libutempter-dev build-essential
|
||||
script: (CFLAGS= ./autogen.sh) && ./configure --enable-debug && make
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; fi
|
||||
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y install bison autotools-dev libncurses5-dev libevent-dev pkg-config libutempter-dev build-essential; fi
|
||||
|
||||
script:
|
||||
- ./autogen.sh && ./configure && make
|
||||
|
||||
243
CHANGES
243
CHANGES
@@ -1,9 +1,240 @@
|
||||
CHANGES FROM 2.9 to 3.0
|
||||
|
||||
* INCOMPATIBLE: Add a new {} syntax to the configuration file. This is a string
|
||||
similar to single quotes but also includes newlines and allows commands that
|
||||
take other commands as string arguments to be expressed more clearly and
|
||||
without additional escaping.
|
||||
|
||||
A literal { and } or a string containing { or } must now be escaped or
|
||||
quoted, for example '{' and '}' instead of { or }, or 'X#{foo}' instead of
|
||||
X#{foo}.
|
||||
|
||||
* New <, >, <= and >= comparison operators for formats.
|
||||
|
||||
* Improve escaping of special characters in list-keys output.
|
||||
|
||||
* INCOMPATIBLE: tmux's configuration parsing has changed to use yacc(1). There
|
||||
is one incompatible change: a \ on its own must be escaped or quoted as
|
||||
either \\ or '\' (the latter works on older tmux versions).
|
||||
|
||||
Entirely the same parser is now used for parsing the configuration file
|
||||
and for string commands. This means that constructs previously only
|
||||
available in .tmux.conf, such as %if, can now be used in string commands
|
||||
(for example, those given to if-shell - not commands invoked from the
|
||||
shell, they are still parsed by the shell itself).
|
||||
|
||||
* Add support for the overline attribute (SGR 53). The Smol capability is
|
||||
needed in terminal-overrides.
|
||||
|
||||
* Add the ability to create simple menus. Introduces new command
|
||||
display-menu. Default menus are bound to MouseDown3 on the status line;
|
||||
MouseDown3 or M-MouseDown3 on panes; MouseDown3 in tree, client and
|
||||
buffer modes; and C-b C-m and C-b M-m.
|
||||
|
||||
* Allow panes to be empty (no command). They can be created either by piping to
|
||||
split-window -I, or by passing an empty command ('') to split-window. Output
|
||||
can be sent to an existing empty window with display-message -I.
|
||||
|
||||
* Add keys to jump between matching brackets (emacs C-M-f and C-M-b, vi %).
|
||||
|
||||
* Add a -e flag to new-window, split-window, respawn-window, respawn-pane to
|
||||
pass environment variables into the newly created process.
|
||||
|
||||
* Hooks are now stored in the options tree as array options, allowing them to
|
||||
have multiple separate commands. set-hook and show-hooks remain but
|
||||
set-option and show-options can now also be used (show-options will only show
|
||||
hooks if given the -H flag). Hooks with multiple commands are run in index
|
||||
order.
|
||||
|
||||
* Automatically scroll if dragging to create a selection with the mouse and the
|
||||
cursor reaches the top or bottom line.
|
||||
|
||||
* Add -no-clear variants of copy-selection and copy-pipe which do not clear the
|
||||
selection after copying. Make copy-pipe clear the selection by default to be
|
||||
consistent with copy-selection.
|
||||
|
||||
* Add an argument to copy commands to set the prefix for the buffer name, this
|
||||
(for example) allows buffers for different sessions to be named separately.
|
||||
|
||||
* Update session activity on focus event.
|
||||
|
||||
* Pass target from source-file into the config file parser so formats in %if
|
||||
and %endif have access to more useful variables.
|
||||
|
||||
* Add the ability to infer an option type (server, session, window) from its
|
||||
name to show-options (it was already present in set-option).
|
||||
|
||||
CHANGES FROM 2.9 to 2.9a
|
||||
|
||||
* Fix bugs in select-pane and the main-horizontal and main-vertical layouts.
|
||||
|
||||
CHANGES FROM 2.8 to 2.9
|
||||
|
||||
* Attempt to preserve horizontal cursor position as well as vertical with
|
||||
reflow.
|
||||
|
||||
* Rewrite main-vertical and horizontal and change layouts to better handle the
|
||||
case where all panes won't fit into the window size, reduce problems with
|
||||
pane border status lines and fix other bugs mostly found by Thomas Sattler.
|
||||
|
||||
* Add format variables for the default formats in the various modes
|
||||
(tree_mode_format and so on) and add a -a flag to display-message to list
|
||||
variables with values.
|
||||
|
||||
* Add a -v flag to display-message to show verbose messages as the format is
|
||||
parsed, this allows formats to be debugged
|
||||
|
||||
* Add support for HPA (\033[`).
|
||||
|
||||
* Add support for origin mode (\033[?6h).
|
||||
|
||||
* No longer clear history on RIS.
|
||||
|
||||
* Extend the #[] style syntax and use that together with previous format
|
||||
changes to allow the status line to be entirely configured with a single
|
||||
option.
|
||||
|
||||
Now that it is possible to configure their content, enable the existing code
|
||||
that lets the status line be multiple lines in height. The status option can
|
||||
now take a value of 2, 3, 4 or 5 (as well as the previous on or off) to
|
||||
configure more than one line. The new status-format array option configures
|
||||
the format of each line, the default just references the existing status-*
|
||||
options, although some of the more obscure status options may be eliminated
|
||||
in time.
|
||||
|
||||
Additions to the #[] syntax are: "align" to specify alignment (left, centre,
|
||||
right), "list" for the window list and "range" to configure ranges of text
|
||||
for the mouse bindings.
|
||||
|
||||
The "align" keyword can also be used to specify alignment of entries in tree
|
||||
mode and the pane status lines.
|
||||
|
||||
* Add E: and T: format modifiers to expand a format twice (useful to expand the
|
||||
value of an option).
|
||||
|
||||
* The individual -fg, -bg and -attr options have been removed; they
|
||||
were superseded by -style options in tmux 1.9.
|
||||
|
||||
* Allow more than one mode to be opened in a pane. Modes are kept on a stack
|
||||
and retrieved if the same mode is entered again. Exiting the active mode goes
|
||||
back to the previous one.
|
||||
|
||||
* When showing command output in copy mode, call it view mode instead (affects
|
||||
pane_mode format).
|
||||
|
||||
* Add -b to display-panes like run-shell.
|
||||
|
||||
* Handle UTF-8 in word-separators option.
|
||||
|
||||
* New "terminal" colour allowing options to use the terminal default colour
|
||||
rather than inheriting the default from a parent option.
|
||||
|
||||
* Do not move the cursor in copy mode when the mouse wheel is used.
|
||||
|
||||
* Use the same working directory rules for jobs as new windows rather than
|
||||
always starting in the user's home.
|
||||
|
||||
* Allow panes to be one line or column in size.
|
||||
|
||||
* Go to last line when goto-line number is out of range in copy mode.
|
||||
|
||||
* Yank previously cut text if any with C-y in the command prompt, only use the
|
||||
buffer if no text has been cut.
|
||||
|
||||
* Add q: format modifier to quote shell special characters.
|
||||
|
||||
* Add StatusLeft and StatusRight mouse locations (keys such as
|
||||
MouseDown1StatusLeft) for the status-left and status-right areas of the
|
||||
status line.
|
||||
|
||||
* Add -Z to find-window.
|
||||
|
||||
* Support for windows larger than the client. This adds two new options,
|
||||
window-size and default-size, and a new command, resize-window. The
|
||||
force-width and force-height options and the session_width and session_height
|
||||
formats have been removed.
|
||||
|
||||
The new window-size option tells tmux how to work out the size of windows:
|
||||
largest means it picks the size of the largest session, smallest the smallest
|
||||
session (similar to the old behaviour) and manual means that it does not
|
||||
automatically resize windows. aggressive-resize modifies the choice of
|
||||
session for largest and smallest as it did before.
|
||||
|
||||
If a window is in a session attached to a client that is too small, only part
|
||||
of the window is shown. tmux attempts to keep the cursor visible, so the part
|
||||
of the window displayed is changed as the cursor moves (with a small delay,
|
||||
to try and avoid excess redrawing when applications redraw status lines or
|
||||
similar that are not currently visible).
|
||||
|
||||
Drawing windows which are larger than the client is not as efficient as those
|
||||
which fit, particularly when the cursor moves, so it is recommended to avoid
|
||||
using this on slow machines or networks (set window-size to smallest or
|
||||
manual).
|
||||
|
||||
The resize-window command can be used to resize a window manually. If it is
|
||||
used, the window-size option is automatically set to manual for the window
|
||||
(undo this with "setw -u window-size"). resize-window works in a similar way
|
||||
to resize-pane (-U -D -L -R -x -y flags) but also has -a and -A flags. -a
|
||||
sets the window to the size of the smallest client (what it would be if
|
||||
window-size was smallest) and -A the largest.
|
||||
|
||||
For the same behaviour as force-width or force-height, use resize-window -x
|
||||
or -y.
|
||||
|
||||
If the global window-size option is set to manual, the default-size option is
|
||||
used for new windows. If -x or -y is used with new-session, that sets the
|
||||
default-size option for the new session.
|
||||
|
||||
The maximum size of a window is 10000x10000. But expect applications to
|
||||
complain and higher memory use if making a window that big. The minimum size
|
||||
is the size required for the current layout including borders.
|
||||
|
||||
The refresh-client command can be used to pan around a window, -U -D -L -R
|
||||
moves up, down, left or right and -c returns to automatic cursor
|
||||
tracking. The position is reset when the current window is changed.
|
||||
|
||||
CHANGES FROM 2.7 to 2.8
|
||||
|
||||
* Make display-panes block the client until a pane is chosen or it
|
||||
times out.
|
||||
|
||||
* Clear history on RIS like most other terminals do.
|
||||
|
||||
* Add an "Any" key to run a command if a key is pressed that is not
|
||||
bound in the current key table.
|
||||
|
||||
* Expand formats in load-buffer and save-buffer.
|
||||
|
||||
* Add a rectangle_toggle format.
|
||||
|
||||
* Add set-hook -R to run a hook immediately.
|
||||
|
||||
* Add README.ja.
|
||||
|
||||
* Add pane focus hooks.
|
||||
|
||||
* Allow any punctuation as separator for s/x/y not only /.
|
||||
|
||||
* Improve resizing with the mouse (fix resizing the wrong pane in some
|
||||
layouts, and allow resizing multiple panes at the same time).
|
||||
|
||||
* Allow , and } to be escaped in formats as #, and #}.
|
||||
|
||||
* Add KRB5CCNAME to update-environment.
|
||||
|
||||
* Change meaning of -c to display-message so the client is used if it
|
||||
matches the session given to -t.
|
||||
|
||||
* Fixes to : form of SGR.
|
||||
|
||||
* Add x and X to choose-tree to kill sessions, windows or panes.
|
||||
|
||||
CHANGES FROM 2.6 TO 2.7
|
||||
|
||||
* Remove EVENT_* variables from environment on platforms where tmux uses them
|
||||
so they do not pass on to panes.
|
||||
|
||||
* Fixed for hooks at server exit.
|
||||
* Fixes for hooks at server exit.
|
||||
|
||||
* Remove SGR 10 (was equivalent to SGR 0 but no other terminal seems to do
|
||||
this).
|
||||
@@ -255,7 +486,7 @@ CHANGES FROM 2.4 TO 2.5, 09 May 2017
|
||||
|
||||
* Do not redraw a client unless we realistically think it can accept the data -
|
||||
defer redraws until the client has nothing else waiting to write.
|
||||
|
||||
|
||||
CHANGES FROM 2.3 TO 2.4, 20 April 2017
|
||||
|
||||
Incompatible Changes
|
||||
@@ -541,7 +772,7 @@ Normal Changes
|
||||
==============
|
||||
|
||||
* Fix crash due to uninitialized lastwp member of layout_cell
|
||||
* Fix -fg/-bg/-style with 256 colour terminals.
|
||||
* Fix -fg/-bg/-style with 256 colour terminals.
|
||||
|
||||
CHANGES FROM 1.8 TO 1.9, 20 February 2014
|
||||
|
||||
@@ -899,7 +1130,7 @@ CHANGES FROM 1.2 TO 1.3, 18 July 2010
|
||||
* Run job commands explicitly in the global environment (which can be modified
|
||||
with setenv -g), rather than with the environment tmux started with.
|
||||
* Use the machine's hostname as the default title, instead of an empty string.
|
||||
* Prevent double free if the window option remain-on-exit is set.
|
||||
* Prevent double free if the window option remain-on-exit is set.
|
||||
* Key string conversions rewritten.
|
||||
* Mark zombie windows as dead in the choose-window list.
|
||||
* Tiled layout added.
|
||||
@@ -1001,7 +1232,7 @@ CHANGES FROM 1.0 TO 1.1, 05 November 2009
|
||||
* New lock-client (alias lockc), and lock-session (alias locks) commands to
|
||||
lock a particular client, or all clients attached to a session.
|
||||
* Support C-n/C-p/C-v/M-v with emacs keys in choice mode.
|
||||
* Use : for goto line rather than g in vi mode.
|
||||
* Use : for goto line rather than g in vi mode.
|
||||
* Try to guess which client to use when no target client was specified. Finds
|
||||
the current session, and if only one client is present, use it. Otherwise,
|
||||
return the most recently used client.
|
||||
@@ -1132,7 +1363,7 @@ The list of older changes is below.
|
||||
|
||||
* main-horizontal layout and main-pane-height option to match vertical.
|
||||
* New window option main-pane-width to set the width of the large left pane with
|
||||
main-vertical (was left-vertical) layout.
|
||||
main-vertical (was left-vertical) layout.
|
||||
* Lots of layout cleanup. manual layout is now manual-vertical.
|
||||
|
||||
16 May 2009
|
||||
|
||||
33
CONTRIBUTING
33
CONTRIBUTING
@@ -1,33 +0,0 @@
|
||||
When reporting issues:
|
||||
|
||||
YOU MUST INCLUDE THE TMUX VERSION
|
||||
|
||||
DO NOT OPEN AN ISSUE THAT DOES NOT MENTION THE TMUX VERSION
|
||||
|
||||
Please also include:
|
||||
|
||||
- your platform (Linux, OS X, or whatever);
|
||||
- a brief description of the problem with steps to reproduce;
|
||||
- a minimal tmux config, if you can't reproduce without a config;
|
||||
- your terminal, and $TERM inside and outside of tmux;
|
||||
- logs from tmux (see below);
|
||||
- at most one or two screenshots, if helpful.
|
||||
|
||||
This should include at least the output of:
|
||||
|
||||
$ uname -sp && tmux -V && echo $TERM
|
||||
|
||||
Please do not report bugs (crashes, incorrect behaviour) without reproducing on
|
||||
a tmux built from Git master.
|
||||
|
||||
Note that TERM inside tmux must be a variant of screen or tmux (for example:
|
||||
screen or screen-256color, tmux or tmux-256color). Please ensure this is the
|
||||
case before opening an issue.
|
||||
|
||||
To run tmux without a config and get logs, run:
|
||||
|
||||
tmux -Ltest kill-server
|
||||
tmux -vv -Ltest -f/dev/null new
|
||||
|
||||
Then reproduce the problem, exit tmux, and attach the tmux-server-*.log file
|
||||
from the current directory to the issue.
|
||||
7
COPYING
7
COPYING
@@ -1,10 +1,7 @@
|
||||
THIS IS FOR INFORMATION ONLY, CODE IS UNDER THE LICENCE AT THE TOP OF ITS FILE.
|
||||
|
||||
The README, CHANGES, FAQ and TODO files are licensed under the ISC
|
||||
license. Files under examples/ remain copyright their authors unless otherwise
|
||||
stated in the file but permission has been received to distribute them with
|
||||
tmux. All other files have a license and copyright notice at their start,
|
||||
typically:
|
||||
The README, CHANGES, FAQ and TODO files are licensed under the ISC license. All
|
||||
other files have a license and copyright notice at their start, typically:
|
||||
|
||||
Copyright (c) <author>
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Please read https://raw.githubusercontent.com/tmux/tmux/master/CONTRIBUTING
|
||||
15
Makefile.am
15
Makefile.am
@@ -2,11 +2,11 @@
|
||||
|
||||
# Obvious program stuff.
|
||||
bin_PROGRAMS = tmux
|
||||
CLEANFILES = tmux.1.mdoc tmux.1.man
|
||||
CLEANFILES = tmux.1.mdoc tmux.1.man cmd-parse.c
|
||||
|
||||
# Distribution tarball options.
|
||||
EXTRA_DIST = \
|
||||
CHANGES README COPYING example_tmux.conf compat/*.[ch] \
|
||||
CHANGES README README.ja COPYING example_tmux.conf compat/*.[ch] \
|
||||
osdep-*.c mdoc2man.awk tmux.1
|
||||
|
||||
# Preprocessor flags.
|
||||
@@ -71,6 +71,7 @@ dist_tmux_SOURCES = \
|
||||
cmd-confirm-before.c \
|
||||
cmd-copy-mode.c \
|
||||
cmd-detach-client.c \
|
||||
cmd-display-menu.c \
|
||||
cmd-display-message.c \
|
||||
cmd-display-panes.c \
|
||||
cmd-find-window.c \
|
||||
@@ -93,6 +94,7 @@ dist_tmux_SOURCES = \
|
||||
cmd-move-window.c \
|
||||
cmd-new-session.c \
|
||||
cmd-new-window.c \
|
||||
cmd-parse.y \
|
||||
cmd-paste-buffer.c \
|
||||
cmd-pipe-pane.c \
|
||||
cmd-queue.c \
|
||||
@@ -100,6 +102,7 @@ dist_tmux_SOURCES = \
|
||||
cmd-rename-session.c \
|
||||
cmd-rename-window.c \
|
||||
cmd-resize-pane.c \
|
||||
cmd-resize-window.c \
|
||||
cmd-respawn-pane.c \
|
||||
cmd-respawn-window.c \
|
||||
cmd-rotate-window.c \
|
||||
@@ -111,14 +114,12 @@ dist_tmux_SOURCES = \
|
||||
cmd-send-keys.c \
|
||||
cmd-set-buffer.c \
|
||||
cmd-set-environment.c \
|
||||
cmd-set-hook.c \
|
||||
cmd-set-option.c \
|
||||
cmd-show-environment.c \
|
||||
cmd-show-messages.c \
|
||||
cmd-show-options.c \
|
||||
cmd-source-file.c \
|
||||
cmd-split-window.c \
|
||||
cmd-string.c \
|
||||
cmd-swap-pane.c \
|
||||
cmd-swap-window.c \
|
||||
cmd-switch-client.c \
|
||||
@@ -131,9 +132,9 @@ dist_tmux_SOURCES = \
|
||||
control.c \
|
||||
environ.c \
|
||||
format.c \
|
||||
format-draw.c \
|
||||
grid-view.c \
|
||||
grid.c \
|
||||
hooks.c \
|
||||
input-keys.c \
|
||||
input.c \
|
||||
job.c \
|
||||
@@ -143,6 +144,7 @@ dist_tmux_SOURCES = \
|
||||
layout-set.c \
|
||||
layout.c \
|
||||
log.c \
|
||||
menu.c \
|
||||
mode-tree.c \
|
||||
names.c \
|
||||
notify.c \
|
||||
@@ -158,6 +160,7 @@ dist_tmux_SOURCES = \
|
||||
server-fn.c \
|
||||
server.c \
|
||||
session.c \
|
||||
spawn.c \
|
||||
status.c \
|
||||
style.c \
|
||||
tmux.c \
|
||||
@@ -195,7 +198,7 @@ install-exec-hook:
|
||||
>$(srcdir)/tmux.1.mdoc; \
|
||||
else \
|
||||
sed -e "s|@SYSCONFDIR@|$(sysconfdir)|g" $(srcdir)/tmux.1| \
|
||||
$(AWK) -f$(srcdir)/mdoc2man.awk >$(srcdir)/tmux.1.man; \
|
||||
$(AWK) -f $(srcdir)/mdoc2man.awk >$(srcdir)/tmux.1.man; \
|
||||
fi
|
||||
$(mkdir_p) $(DESTDIR)$(mandir)/man1
|
||||
$(INSTALL_DATA) $(srcdir)/tmux.1.@MANFORMAT@ \
|
||||
|
||||
78
README
78
README
@@ -1,18 +1,22 @@
|
||||
Welcome to tmux!
|
||||
|
||||
tmux is a "terminal multiplexer", it enables a number of terminals (or windows)
|
||||
to be accessed and controlled from a single terminal. tmux is intended to be a
|
||||
simple, modern, BSD-licensed alternative to programs such as GNU screen.
|
||||
tmux is a terminal multiplexer: it enables a number of terminals to be created,
|
||||
accessed, and controlled from a single screen. tmux may be detached from a
|
||||
screen and continue running in the background, then later reattached.
|
||||
|
||||
This release runs on OpenBSD, FreeBSD, NetBSD, Linux, OS X and Solaris.
|
||||
|
||||
tmux depends on libevent 2.x. Download it from:
|
||||
* Dependencies
|
||||
|
||||
http://libevent.org
|
||||
tmux depends on libevent 2.x, available from:
|
||||
|
||||
https://github.com/libevent/libevent/releases/latest
|
||||
|
||||
It also depends on ncurses, available from:
|
||||
|
||||
http://invisible-island.net/ncurses/
|
||||
https://invisible-mirror.net/archives/ncurses/
|
||||
|
||||
* Installation
|
||||
|
||||
To build and install tmux from a release tarball, use:
|
||||
|
||||
@@ -32,40 +36,42 @@ To get and build the latest from version control:
|
||||
(Note that this requires at least a working C compiler, make, autoconf,
|
||||
automake, pkg-config as well as libevent and ncurses libraries and headers.)
|
||||
|
||||
For more information see http://git-scm.com. Patches should be sent by email to
|
||||
the mailing list at tmux-users@googlegroups.com or submitted through GitHub at
|
||||
https://github.com/tmux/tmux/issues.
|
||||
|
||||
For documentation on using tmux, see the tmux.1 manpage. It can be viewed from
|
||||
the source tree with:
|
||||
|
||||
$ nroff -mdoc tmux.1|less
|
||||
|
||||
A small example configuration in example_tmux.conf.
|
||||
|
||||
And a bash(1) completion file at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
|
||||
For debugging, running tmux with -v or -vv will generate server and client log
|
||||
files in the current directory.
|
||||
|
||||
tmux mailing lists are available. For general discussion and bug reports:
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-users
|
||||
|
||||
And for Git commit emails:
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-git
|
||||
|
||||
Subscribe by sending an email to <tmux-users+subscribe@googlegroups.com>.
|
||||
* Contributing
|
||||
|
||||
Bug reports, feature suggestions and especially code contributions are most
|
||||
welcome. Please send by email to:
|
||||
|
||||
tmux-users@googlegroups.com
|
||||
|
||||
This file and the CHANGES, FAQ, SYNCING and TODO files are licensed under the
|
||||
ISC license. All other files have a license and copyright notice at their start.
|
||||
Or open a GitHub issue or pull request.
|
||||
|
||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
* Documentation
|
||||
|
||||
For documentation on using tmux, see the tmux.1 manpage. View it from the
|
||||
source tree with:
|
||||
|
||||
$ nroff -mdoc tmux.1|less
|
||||
|
||||
A small example configuration is in example_tmux.conf.
|
||||
|
||||
A bash(1) completion file is at:
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
|
||||
For debugging, run tmux with -v and -vv to generate server and client log files
|
||||
in the current directory.
|
||||
|
||||
* Support
|
||||
|
||||
The tmux mailing list for general discussion and bug reports is:
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-users
|
||||
|
||||
Subscribe by sending an email to:
|
||||
|
||||
tmux-users+subscribe@googlegroups.com
|
||||
|
||||
* License
|
||||
|
||||
This file and the CHANGES files are licensed under the ISC license. All other
|
||||
files have a license and copyright notice at their start.
|
||||
|
||||
62
README.ja
Normal file
62
README.ja
Normal file
@@ -0,0 +1,62 @@
|
||||
tmuxへようこそ!
|
||||
|
||||
tmuxはターミナルマルチプレクサーです。複数のターミナルを一つのスクリーン内に作成し、操作することができます。
|
||||
バックグラウンドで処理を実行中に一度スクリーンから離れて後から復帰することも可能です。
|
||||
|
||||
OpenBSD、FreeBSD、NetBSD、Linux、OS X、Solarisで実行できます。
|
||||
|
||||
tmuxはlibevent 2.x.に依存します。 下記からダウンロードしてください。
|
||||
|
||||
http://libevent.org
|
||||
|
||||
また、ncursesも必要です。こちらからどうぞ。
|
||||
|
||||
http://invisible-island.net/ncurses/
|
||||
|
||||
tarballでのtmuxのビルドとインストール方法。
|
||||
|
||||
$ ./configure && make
|
||||
$ sudo make install
|
||||
|
||||
tmuxはutmp(5)をアップデートするためにutempterを使うことができます。もしインストール済みであればオプション「--enable-utempter」をつけて実行してください。
|
||||
|
||||
リポジトリから最新バージョンを手に入れるためには下記を実行。
|
||||
|
||||
$ git clone https://github.com/tmux/tmux.git
|
||||
$ cd tmux
|
||||
$ sh autogen.sh
|
||||
$ ./configure && make
|
||||
|
||||
(ビルドのためにはlibevent、ncurses libraries、headersに加えて、C compiler、make、autoconf、automake、pkg-configが必要です。)
|
||||
|
||||
詳しい情報はhttp://git-scm.comをご覧ください。修正はメール<tmux-users@googlegroups.com>宛、もしくはhttps://github.com/tmux/tmux/issuesにて受け付けています。
|
||||
|
||||
tmuxのドキュメントについてはtmux.1マニュアルをご覧ください。こちらのコマンドで参照可能です。
|
||||
|
||||
$ nroff -mdoc tmux.1|less
|
||||
|
||||
サンプル設定は本リポジトリのexample_tmux.confに
|
||||
また、bash-completionファイルは下記にあります。
|
||||
|
||||
https://github.com/imomaliev/tmux-bash-completion
|
||||
|
||||
「-v」や「-vv」を指定することでデバッグモードでの起動が可能です。カレントディレクトリにサーバーやクライアントのログファイルが生成されます。
|
||||
|
||||
議論やバグレポート用のメーリングリストにはこちらから参加可能です。
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-users
|
||||
|
||||
gitコミットについての連絡先
|
||||
|
||||
https://groups.google.com/forum/#!forum/tmux-git
|
||||
|
||||
購読は<tmux-users+subscribe@googlegroups.com>までメールをお願いします。
|
||||
|
||||
バグレポートや機能追加(特にコードへの貢献)は大歓迎です。こちらにご連絡ください。
|
||||
|
||||
tmux-users@googlegroups.com
|
||||
|
||||
本ファイル、CHANGES、 FAQ、SYNCINGそしてTODOはISC licenseで保護されています。
|
||||
その他のファイルのライセンスや著作権については、ファイルの上部に明記されています。
|
||||
|
||||
-- Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
133
TODO
133
TODO
@@ -1,133 +0,0 @@
|
||||
- command bits and pieces:
|
||||
* allow multiple targets: fnmatch for -t/-c, for example detach all
|
||||
clients with -t*
|
||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
||||
and command prompt
|
||||
* last-pane across sessions
|
||||
* resize-pane -p to match split-window -p
|
||||
* flag to wait-for to have a timeout and/or to stop waiting when the
|
||||
client gets a signal
|
||||
|
||||
- make command sequences more usable
|
||||
* don't require space after ;
|
||||
* options for error handling: && and ||?
|
||||
|
||||
- options bits and pieces:
|
||||
* way to set socket path from config file
|
||||
|
||||
- format improvements:
|
||||
* option to quote format (#{q:session_name})
|
||||
* some way to pad # stuff with spaces
|
||||
* formats to show if a window is linked into multiple sessions, into
|
||||
multiple attached sessions, and is the active window in multiple
|
||||
attached sessions?
|
||||
* comparison operators like < and > (for #{version}?)
|
||||
* %else statement in config file
|
||||
|
||||
- improve monitor-*:
|
||||
* straighten out rules for multiple clients
|
||||
* think about what happens across sessions
|
||||
* monitor changes within a region
|
||||
* perhaps monitor /all/ panes in the window not just one
|
||||
|
||||
- improve mouse support:
|
||||
* bind commands to mouse in different areas?
|
||||
* commands executed when clicking on a pattern (URL)
|
||||
|
||||
- warts on current naming:
|
||||
* display-time but message-fg/bg/attr
|
||||
* list-* vs show-*
|
||||
|
||||
- copy/paste improvements:
|
||||
* paste w/o trailing whitespace
|
||||
* command to toggle selection not to move it in copy-mode
|
||||
* regex searching
|
||||
* searching in copy mode should unwrap lines, so if you search for "foobar"
|
||||
then it should be found even if it is now "foo\nbar" (if the WRAP flag
|
||||
is set on the line)
|
||||
* capture-pane option to preserve spaces but not join lines
|
||||
* improve word and line selection in copy mode (for example when
|
||||
dragging it should select by word. compare how xterm works. GitHub
|
||||
issue 682)
|
||||
* key to search for word under cursor (GitHub issue 1240)
|
||||
|
||||
- layout stuff
|
||||
* way to tag a layout as a number/name
|
||||
* maybe keep last layout + size around and if size reverts just put it
|
||||
back
|
||||
* revamp layouts: they are too complicated, should be more closely
|
||||
integrated, should support hints, layout sets should just be a
|
||||
special case of custom layouts, and we should support panes that are
|
||||
not attached to a cell at all. this could be the time to introduce
|
||||
panelink to replace layout_cell
|
||||
* way to set hints/limits about pane size for resizing
|
||||
* panning over window (window larger than visible)
|
||||
* a mode where one application can cross two panes (ie x|y, width =
|
||||
COLUMNS/2 but height = ROWS * 2)
|
||||
* separate active panes for different clients
|
||||
* way to choose where the freed space goes when a pane is killed:
|
||||
option to kill-pane? GitHub issue 918
|
||||
|
||||
- code cleanup
|
||||
* instead of separate window and session options, just one master
|
||||
options list with each option having a type (window or session), then
|
||||
options on window, on session, and global. for window options we look
|
||||
window->session->global, and for session we look session->global.
|
||||
problem: what about windows in multiple sessions? there are contexts
|
||||
where we do not know which session, or where multiple choices makes
|
||||
no sense... could at least have one global list for all types of
|
||||
global options and keep separate window,session lists
|
||||
* the way pane, window, session destroy is handled is too complicated
|
||||
and the distinction between session.c, window.c and server-fn.c
|
||||
functions is not clear. could we just have kill_pane(),
|
||||
kill_window(), unlink_window(), kill_session() that fix up all data
|
||||
structures (flagging sessions as dead) and return a value to say
|
||||
whether clients need to be checked for dead sessions? sort of like
|
||||
session_detach now but more so. or some other scheme to make it
|
||||
simpler and clearer? also would be nice to remove/rename server-fn.c
|
||||
* more readable way to work out the various things commands need to
|
||||
know about the client, notably:
|
||||
- is this the config file? (cmdq->c == NULL)
|
||||
- is this a command client? (cmdq->c != NULL &&
|
||||
cmdq->c->session == NULL)
|
||||
- is this a control client?
|
||||
- can i do stdin or stdout to this client?
|
||||
or even guarantee that cmdq->c != NULL and provide a better way to
|
||||
tell when in the config file - then we use cmdq->c if we need a
|
||||
client w/o a session else cmd_current_client
|
||||
|
||||
- miscellaneous
|
||||
* link panes into multiple windows
|
||||
* live update: server started with -U connects to server, requests
|
||||
sessions and windows, receives file descriptors
|
||||
* there are inconsistencies in what we get from old shell and what
|
||||
comes from config for new sessions and windows. likewise, panes and
|
||||
jobs and run-shell and lock command all start with slightly different
|
||||
environments
|
||||
* multiline status line? separate command prompt and status line?
|
||||
* automatic pane logging
|
||||
* marks in history, automatically add (move?) one when pane is changed
|
||||
* this doesn't work, need pane reference count probably:
|
||||
bind -n DoubleClick3Status confirm-before -p "kill-window #I? (y/n)" kill-window
|
||||
* respawn -c flag same as neww etc
|
||||
* marker lines in history (GitHub issue 1042)
|
||||
* tree mode stuff: make command prompt (:) common code so all modes get it,
|
||||
predefined filters, tag-all key, ...
|
||||
* drag panes and windows around to move/swap them in choose mode
|
||||
|
||||
- hooks
|
||||
* more hooks for various things
|
||||
* finish after hooks for special commands. these do not have a hook at
|
||||
the moment:
|
||||
attach-session detach-client kill-server respawn-window
|
||||
swap-window break-pane find-window kill-session rotate-window
|
||||
switch-client choose-tree if-shell kill-window run-shell
|
||||
wait-for command-prompt join-pane move-window source-file
|
||||
confirm-before kill-pane respawn-pane swap-pane
|
||||
at the moment AFTERHOOK uses current only if target is not valid,
|
||||
but target is ALWAYS valid - it should use current if no -t flag?
|
||||
then select-* could use AFTERHOOK
|
||||
* multiple hooks with the same name?
|
||||
* finish hooks for notifys
|
||||
* for session_closed, if no sessions at all, perhaps fake up a
|
||||
temporary one
|
||||
176
arguments.c
176
arguments.c
@@ -28,9 +28,15 @@
|
||||
* Manipulate command arguments.
|
||||
*/
|
||||
|
||||
struct args_value {
|
||||
char *value;
|
||||
TAILQ_ENTRY(args_value) entry;
|
||||
};
|
||||
TAILQ_HEAD(args_values, args_value);
|
||||
|
||||
struct args_entry {
|
||||
u_char flag;
|
||||
char *value;
|
||||
struct args_values values;
|
||||
RB_ENTRY(args_entry) entry;
|
||||
};
|
||||
|
||||
@@ -92,12 +98,18 @@ args_free(struct args *args)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
struct args_entry *entry1;
|
||||
struct args_value *value;
|
||||
struct args_value *value1;
|
||||
|
||||
cmd_free_argv(args->argc, args->argv);
|
||||
|
||||
RB_FOREACH_SAFE(entry, args_tree, &args->tree, entry1) {
|
||||
RB_REMOVE(args_tree, &args->tree, entry);
|
||||
free(entry->value);
|
||||
TAILQ_FOREACH_SAFE(value, &entry->values, entry, value1) {
|
||||
TAILQ_REMOVE(&entry->values, value, entry);
|
||||
free(value->value);
|
||||
free(value);
|
||||
}
|
||||
free(entry);
|
||||
}
|
||||
|
||||
@@ -123,22 +135,53 @@ args_print_add(char **buf, size_t *len, const char *fmt, ...)
|
||||
free(s);
|
||||
}
|
||||
|
||||
/* Add value to string. */
|
||||
static void
|
||||
args_print_add_value(char **buf, size_t *len, struct args_entry *entry,
|
||||
struct args_value *value)
|
||||
{
|
||||
char *escaped;
|
||||
|
||||
if (**buf != '\0')
|
||||
args_print_add(buf, len, " -%c ", entry->flag);
|
||||
else
|
||||
args_print_add(buf, len, "-%c ", entry->flag);
|
||||
|
||||
escaped = args_escape(value->value);
|
||||
args_print_add(buf, len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
|
||||
/* Add argument to string. */
|
||||
static void
|
||||
args_print_add_argument(char **buf, size_t *len, const char *argument)
|
||||
{
|
||||
char *escaped;
|
||||
|
||||
if (**buf != '\0')
|
||||
args_print_add(buf, len, " ");
|
||||
|
||||
escaped = args_escape(argument);
|
||||
args_print_add(buf, len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
|
||||
/* Print a set of arguments. */
|
||||
char *
|
||||
args_print(struct args *args)
|
||||
{
|
||||
size_t len;
|
||||
char *buf, *escaped;
|
||||
int i, flags;
|
||||
char *buf;
|
||||
int i;
|
||||
struct args_entry *entry;
|
||||
static const char quoted[] = " #\"';$";
|
||||
struct args_value *value;
|
||||
|
||||
len = 1;
|
||||
buf = xcalloc(1, len);
|
||||
|
||||
/* Process the flags first. */
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->value != NULL)
|
||||
if (!TAILQ_EMPTY(&entry->values))
|
||||
continue;
|
||||
|
||||
if (*buf == '\0')
|
||||
@@ -148,44 +191,52 @@ args_print(struct args *args)
|
||||
|
||||
/* Then the flags with arguments. */
|
||||
RB_FOREACH(entry, args_tree, &args->tree) {
|
||||
if (entry->value == NULL)
|
||||
continue;
|
||||
|
||||
if (*buf != '\0')
|
||||
args_print_add(&buf, &len, " -%c ", entry->flag);
|
||||
else
|
||||
args_print_add(&buf, &len, "-%c ", entry->flag);
|
||||
|
||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
||||
if (entry->value[strcspn(entry->value, quoted)] != '\0')
|
||||
flags |= VIS_DQ;
|
||||
utf8_stravis(&escaped, entry->value, flags);
|
||||
if (flags & VIS_DQ)
|
||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
||||
else
|
||||
args_print_add(&buf, &len, "%s", escaped);
|
||||
free(escaped);
|
||||
TAILQ_FOREACH(value, &entry->values, entry)
|
||||
args_print_add_value(&buf, &len, entry, value);
|
||||
}
|
||||
|
||||
/* And finally the argument vector. */
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
if (*buf != '\0')
|
||||
args_print_add(&buf, &len, " ");
|
||||
|
||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
||||
if (args->argv[i][strcspn(args->argv[i], quoted)] != '\0')
|
||||
flags |= VIS_DQ;
|
||||
utf8_stravis(&escaped, args->argv[i], flags);
|
||||
if (flags & VIS_DQ)
|
||||
args_print_add(&buf, &len, "\"%s\"", escaped);
|
||||
else
|
||||
args_print_add(&buf, &len, "%s", escaped);
|
||||
free(escaped);
|
||||
}
|
||||
for (i = 0; i < args->argc; i++)
|
||||
args_print_add_argument(&buf, &len, args->argv[i]);
|
||||
|
||||
return (buf);
|
||||
}
|
||||
|
||||
/* Escape an argument. */
|
||||
char *
|
||||
args_escape(const char *s)
|
||||
{
|
||||
static const char quoted[] = " #\"';${}";
|
||||
char *escaped, *result;
|
||||
int flags;
|
||||
|
||||
if (*s == '\0')
|
||||
return (xstrdup(s));
|
||||
if ((strchr(quoted, s[0]) != NULL || s[0] == '~') && s[1] == '\0') {
|
||||
xasprintf(&escaped, "\\%c", s[0]);
|
||||
return (escaped);
|
||||
}
|
||||
|
||||
flags = VIS_OCTAL|VIS_TAB|VIS_NL;
|
||||
if (s[strcspn(s, quoted)] != '\0')
|
||||
flags |= VIS_DQ;
|
||||
utf8_stravis(&escaped, s, flags);
|
||||
|
||||
if (flags & VIS_DQ) {
|
||||
if (*escaped == '~')
|
||||
xasprintf(&result, "\"\\%s\"", escaped);
|
||||
else
|
||||
xasprintf(&result, "\"%s\"", escaped);
|
||||
} else {
|
||||
if (*escaped == '~')
|
||||
xasprintf(&result, "\\%s", escaped);
|
||||
else
|
||||
result = xstrdup(escaped);
|
||||
}
|
||||
free(escaped);
|
||||
return (result);
|
||||
}
|
||||
|
||||
/* Return if an argument is present. */
|
||||
int
|
||||
args_has(struct args *args, u_char ch)
|
||||
@@ -195,22 +246,24 @@ args_has(struct args *args, u_char ch)
|
||||
|
||||
/* Set argument value in the arguments tree. */
|
||||
void
|
||||
args_set(struct args *args, u_char ch, const char *value)
|
||||
args_set(struct args *args, u_char ch, const char *s)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
struct args_value *value;
|
||||
|
||||
/* Replace existing argument. */
|
||||
if ((entry = args_find(args, ch)) != NULL) {
|
||||
free(entry->value);
|
||||
entry->value = NULL;
|
||||
} else {
|
||||
entry = args_find(args, ch);
|
||||
if (entry == NULL) {
|
||||
entry = xcalloc(1, sizeof *entry);
|
||||
entry->flag = ch;
|
||||
TAILQ_INIT(&entry->values);
|
||||
RB_INSERT(args_tree, &args->tree, entry);
|
||||
}
|
||||
|
||||
if (value != NULL)
|
||||
entry->value = xstrdup(value);
|
||||
if (s != NULL) {
|
||||
value = xcalloc(1, sizeof *value);
|
||||
value->value = xstrdup(s);
|
||||
TAILQ_INSERT_TAIL(&entry->values, value, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get argument value. Will be NULL if it isn't present. */
|
||||
@@ -221,7 +274,34 @@ args_get(struct args *args, u_char ch)
|
||||
|
||||
if ((entry = args_find(args, ch)) == NULL)
|
||||
return (NULL);
|
||||
return (entry->value);
|
||||
return (TAILQ_LAST(&entry->values, args_values)->value);
|
||||
}
|
||||
|
||||
/* Get first value in argument. */
|
||||
const char *
|
||||
args_first_value(struct args *args, u_char ch, struct args_value **value)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
|
||||
if ((entry = args_find(args, ch)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
*value = TAILQ_FIRST(&entry->values);
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
return ((*value)->value);
|
||||
}
|
||||
|
||||
/* Get next value in argument. */
|
||||
const char *
|
||||
args_next_value(struct args_value **value)
|
||||
{
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
*value = TAILQ_NEXT(*value, entry);
|
||||
if (*value == NULL)
|
||||
return (NULL);
|
||||
return ((*value)->value);
|
||||
}
|
||||
|
||||
/* Convert an argument value to a number. */
|
||||
@@ -232,13 +312,15 @@ args_strtonum(struct args *args, u_char ch, long long minval, long long maxval,
|
||||
const char *errstr;
|
||||
long long ll;
|
||||
struct args_entry *entry;
|
||||
struct args_value *value;
|
||||
|
||||
if ((entry = args_find(args, ch)) == NULL) {
|
||||
*cause = xstrdup("missing");
|
||||
return (0);
|
||||
}
|
||||
value = TAILQ_LAST(&entry->values, args_values);
|
||||
|
||||
ll = strtonum(entry->value, minval, maxval, &errstr);
|
||||
ll = strtonum(value->value, minval, maxval, &errstr);
|
||||
if (errstr != NULL) {
|
||||
*cause = xstrdup(errstr);
|
||||
return (0);
|
||||
|
||||
58
attributes.c
58
attributes.c
@@ -25,13 +25,13 @@
|
||||
const char *
|
||||
attributes_tostring(int attr)
|
||||
{
|
||||
static char buf[128];
|
||||
static char buf[512];
|
||||
size_t len;
|
||||
|
||||
if (attr == 0)
|
||||
return ("none");
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "%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",
|
||||
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
||||
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
||||
@@ -39,7 +39,12 @@ attributes_tostring(int attr)
|
||||
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
||||
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
||||
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "");
|
||||
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "",
|
||||
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "",
|
||||
(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," : "");
|
||||
if (len > 0)
|
||||
buf[len - 1] = '\0';
|
||||
|
||||
@@ -52,6 +57,26 @@ attributes_fromstring(const char *str)
|
||||
const char delimiters[] = " ,|";
|
||||
int attr;
|
||||
size_t end;
|
||||
u_int i;
|
||||
struct {
|
||||
const char* name;
|
||||
int attr;
|
||||
} table[] = {
|
||||
{ "bright", GRID_ATTR_BRIGHT },
|
||||
{ "bold", GRID_ATTR_BRIGHT },
|
||||
{ "dim", GRID_ATTR_DIM },
|
||||
{ "underscore", GRID_ATTR_UNDERSCORE },
|
||||
{ "blink", GRID_ATTR_BLINK },
|
||||
{ "reverse", GRID_ATTR_REVERSE },
|
||||
{ "hidden", GRID_ATTR_HIDDEN },
|
||||
{ "italics", GRID_ATTR_ITALICS },
|
||||
{ "strikethrough", GRID_ATTR_STRIKETHROUGH },
|
||||
{ "double-underscore", GRID_ATTR_UNDERSCORE_2 },
|
||||
{ "curly-underscore", GRID_ATTR_UNDERSCORE_3 },
|
||||
{ "dotted-underscore", GRID_ATTR_UNDERSCORE_4 },
|
||||
{ "dashed-underscore", GRID_ATTR_UNDERSCORE_5 },
|
||||
{ "overline", GRID_ATTR_OVERLINE }
|
||||
};
|
||||
|
||||
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
||||
return (-1);
|
||||
@@ -64,24 +89,15 @@ attributes_fromstring(const char *str)
|
||||
attr = 0;
|
||||
do {
|
||||
end = strcspn(str, delimiters);
|
||||
if ((end == 6 && strncasecmp(str, "bright", end) == 0) ||
|
||||
(end == 4 && strncasecmp(str, "bold", end) == 0))
|
||||
attr |= GRID_ATTR_BRIGHT;
|
||||
else if (end == 3 && strncasecmp(str, "dim", end) == 0)
|
||||
attr |= GRID_ATTR_DIM;
|
||||
else if (end == 10 && strncasecmp(str, "underscore", end) == 0)
|
||||
attr |= GRID_ATTR_UNDERSCORE;
|
||||
else if (end == 5 && strncasecmp(str, "blink", end) == 0)
|
||||
attr |= GRID_ATTR_BLINK;
|
||||
else if (end == 7 && strncasecmp(str, "reverse", end) == 0)
|
||||
attr |= GRID_ATTR_REVERSE;
|
||||
else if (end == 6 && strncasecmp(str, "hidden", end) == 0)
|
||||
attr |= GRID_ATTR_HIDDEN;
|
||||
else if (end == 7 && strncasecmp(str, "italics", end) == 0)
|
||||
attr |= GRID_ATTR_ITALICS;
|
||||
else if (end == 13 && strncasecmp(str, "strikethrough", end) == 0)
|
||||
attr |= GRID_ATTR_STRIKETHROUGH;
|
||||
else
|
||||
for (i = 0; i < nitems(table); i++) {
|
||||
if (end != strlen(table[i].name))
|
||||
continue;
|
||||
if (strncasecmp(str, table[i].name, end) == 0) {
|
||||
attr |= table[i].attr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == nitems(table))
|
||||
return (-1);
|
||||
str += end + strspn(str + end, delimiters);
|
||||
} while (*str != '\0');
|
||||
|
||||
247
cfg.c
247
cfg.c
@@ -26,17 +26,7 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Condition for %if, %elif, %else and %endif. */
|
||||
struct cfg_cond {
|
||||
size_t line; /* line number of %if */
|
||||
int met; /* condition was met */
|
||||
int skip; /* skip later %elif/%else */
|
||||
int saw_else; /* saw a %else */
|
||||
|
||||
TAILQ_ENTRY(cfg_cond) entry;
|
||||
};
|
||||
TAILQ_HEAD(cfg_conds, cfg_cond);
|
||||
|
||||
struct client *cfg_client;
|
||||
static char *cfg_file;
|
||||
int cfg_finished;
|
||||
static char **cfg_causes;
|
||||
@@ -80,13 +70,12 @@ void
|
||||
start_cfg(void)
|
||||
{
|
||||
const char *home;
|
||||
int quiet = 0;
|
||||
int flags = 0;
|
||||
struct client *c;
|
||||
|
||||
/*
|
||||
* Configuration files are loaded without a client, so NULL is passed
|
||||
* into load_cfg() and commands run in the global queue with
|
||||
* item->client NULL.
|
||||
* Configuration files are loaded without a client, so commands are run
|
||||
* in the global queue with item->client NULL.
|
||||
*
|
||||
* However, we must block the initial client (but just the initial
|
||||
* client) so that its command runs after the configuration is loaded.
|
||||
@@ -94,216 +83,74 @@ start_cfg(void)
|
||||
* command queue is currently empty and our callback will be at the
|
||||
* front - we need to get in before MSG_COMMAND.
|
||||
*/
|
||||
c = TAILQ_FIRST(&clients);
|
||||
cfg_client = c = TAILQ_FIRST(&clients);
|
||||
if (c != NULL) {
|
||||
cfg_item = cmdq_get_callback(cfg_client_done, NULL);
|
||||
cmdq_append(c, cfg_item);
|
||||
}
|
||||
|
||||
load_cfg(TMUX_CONF, NULL, NULL, 1);
|
||||
if (cfg_file == NULL)
|
||||
load_cfg(TMUX_CONF, NULL, NULL, CMD_PARSE_QUIET, NULL);
|
||||
|
||||
if (cfg_file == NULL && (home = find_home()) != NULL) {
|
||||
xasprintf(&cfg_file, "%s/.tmux.conf", home);
|
||||
quiet = 1;
|
||||
flags = CMD_PARSE_QUIET;
|
||||
}
|
||||
if (cfg_file != NULL)
|
||||
load_cfg(cfg_file, NULL, NULL, quiet);
|
||||
load_cfg(cfg_file, NULL, NULL, flags, NULL);
|
||||
|
||||
cmdq_append(NULL, cmdq_get_callback(cfg_done, NULL));
|
||||
}
|
||||
|
||||
static int
|
||||
cfg_check_condition(const char *path, size_t line, const char *p, int *skip)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
char *s;
|
||||
int result;
|
||||
|
||||
while (isspace((u_char)*p))
|
||||
p++;
|
||||
if (p[0] == '\0') {
|
||||
cfg_add_cause("%s:%zu: invalid condition", path, line);
|
||||
*skip = 1;
|
||||
return (0);
|
||||
}
|
||||
|
||||
ft = format_create(NULL, NULL, FORMAT_NONE, FORMAT_NOJOBS);
|
||||
s = format_expand(ft, p);
|
||||
result = format_true(s);
|
||||
free(s);
|
||||
format_free(ft);
|
||||
|
||||
*skip = result;
|
||||
return (result);
|
||||
}
|
||||
|
||||
static void
|
||||
cfg_handle_if(const char *path, size_t line, struct cfg_conds *conds,
|
||||
const char *p)
|
||||
{
|
||||
struct cfg_cond *cond;
|
||||
struct cfg_cond *parent = TAILQ_FIRST(conds);
|
||||
|
||||
/*
|
||||
* Add a new condition. If a previous condition exists and isn't
|
||||
* currently met, this new one also can't be met.
|
||||
*/
|
||||
cond = xcalloc(1, sizeof *cond);
|
||||
cond->line = line;
|
||||
if (parent == NULL || parent->met)
|
||||
cond->met = cfg_check_condition(path, line, p, &cond->skip);
|
||||
else
|
||||
cond->skip = 1;
|
||||
cond->saw_else = 0;
|
||||
TAILQ_INSERT_HEAD(conds, cond, entry);
|
||||
}
|
||||
|
||||
static void
|
||||
cfg_handle_elif(const char *path, size_t line, struct cfg_conds *conds,
|
||||
const char *p)
|
||||
{
|
||||
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||
|
||||
/*
|
||||
* If a previous condition exists and wasn't met, check this
|
||||
* one instead and change the state.
|
||||
*/
|
||||
if (cond == NULL || cond->saw_else)
|
||||
cfg_add_cause("%s:%zu: unexpected %%elif", path, line);
|
||||
else if (!cond->skip)
|
||||
cond->met = cfg_check_condition(path, line, p, &cond->skip);
|
||||
else
|
||||
cond->met = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
cfg_handle_else(const char *path, size_t line, struct cfg_conds *conds)
|
||||
{
|
||||
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||
|
||||
/*
|
||||
* If a previous condition exists and wasn't met and wasn't already
|
||||
* %else, use this one instead.
|
||||
*/
|
||||
if (cond == NULL || cond->saw_else) {
|
||||
cfg_add_cause("%s:%zu: unexpected %%else", path, line);
|
||||
return;
|
||||
}
|
||||
cond->saw_else = 1;
|
||||
cond->met = !cond->skip;
|
||||
cond->skip = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
cfg_handle_endif(const char *path, size_t line, struct cfg_conds *conds)
|
||||
{
|
||||
struct cfg_cond *cond = TAILQ_FIRST(conds);
|
||||
|
||||
/*
|
||||
* Remove previous condition if one exists.
|
||||
*/
|
||||
if (cond == NULL) {
|
||||
cfg_add_cause("%s:%zu: unexpected %%endif", path, line);
|
||||
return;
|
||||
}
|
||||
TAILQ_REMOVE(conds, cond, entry);
|
||||
free(cond);
|
||||
}
|
||||
|
||||
static void
|
||||
cfg_handle_directive(const char *p, const char *path, size_t line,
|
||||
struct cfg_conds *conds)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
while (p[n] != '\0' && !isspace((u_char)p[n]))
|
||||
n++;
|
||||
if (strncmp(p, "%if", n) == 0)
|
||||
cfg_handle_if(path, line, conds, p + n);
|
||||
else if (strncmp(p, "%elif", n) == 0)
|
||||
cfg_handle_elif(path, line, conds, p + n);
|
||||
else if (strcmp(p, "%else") == 0)
|
||||
cfg_handle_else(path, line, conds);
|
||||
else if (strcmp(p, "%endif") == 0)
|
||||
cfg_handle_endif(path, line, conds);
|
||||
else
|
||||
cfg_add_cause("%s:%zu: invalid directive: %s", path, line, p);
|
||||
}
|
||||
|
||||
int
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
|
||||
struct cmdq_item **new_item)
|
||||
{
|
||||
FILE *f;
|
||||
const char delim[3] = { '\\', '\\', '\0' };
|
||||
u_int found = 0;
|
||||
size_t line = 0;
|
||||
char *buf, *cause1, *p, *q;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
struct cfg_cond *cond, *cond1;
|
||||
struct cfg_conds conds;
|
||||
struct cmd_parse_input pi;
|
||||
struct cmd_parse_result *pr;
|
||||
struct cmdq_item *new_item0;
|
||||
|
||||
TAILQ_INIT(&conds);
|
||||
if (new_item != NULL)
|
||||
*new_item = NULL;
|
||||
|
||||
log_debug("loading %s", path);
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
if (errno == ENOENT && quiet)
|
||||
if (errno == ENOENT && (flags & CMD_PARSE_QUIET))
|
||||
return (0);
|
||||
cfg_add_cause("%s: %s", path, strerror(errno));
|
||||
return (-1);
|
||||
}
|
||||
|
||||
while ((buf = fparseln(f, NULL, &line, delim, 0)) != NULL) {
|
||||
log_debug("%s: %s", path, buf);
|
||||
memset(&pi, 0, sizeof pi);
|
||||
pi.flags = flags;
|
||||
pi.file = path;
|
||||
pi.line = 1;
|
||||
|
||||
p = buf;
|
||||
while (isspace((u_char)*p))
|
||||
p++;
|
||||
if (*p == '\0') {
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
q = p + strlen(p) - 1;
|
||||
while (q != p && isspace((u_char)*q))
|
||||
*q-- = '\0';
|
||||
|
||||
if (*p == '%') {
|
||||
cfg_handle_directive(p, path, line, &conds);
|
||||
continue;
|
||||
}
|
||||
cond = TAILQ_FIRST(&conds);
|
||||
if (cond != NULL && !cond->met)
|
||||
continue;
|
||||
|
||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
||||
if (cmdlist == NULL) {
|
||||
free(buf);
|
||||
if (cause1 == NULL)
|
||||
continue;
|
||||
cfg_add_cause("%s:%zu: %s", path, line, cause1);
|
||||
free(cause1);
|
||||
continue;
|
||||
}
|
||||
free(buf);
|
||||
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item);
|
||||
else
|
||||
cmdq_append(c, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
found++;
|
||||
}
|
||||
pr = cmd_parse_from_file(f, &pi);
|
||||
fclose(f);
|
||||
|
||||
TAILQ_FOREACH_REVERSE_SAFE(cond, &conds, cfg_conds, entry, cond1) {
|
||||
cfg_add_cause("%s:%zu: unterminated %%if", path, cond->line);
|
||||
TAILQ_REMOVE(&conds, cond, entry);
|
||||
free(cond);
|
||||
if (pr->status == CMD_PARSE_EMPTY)
|
||||
return (0);
|
||||
if (pr->status == CMD_PARSE_ERROR) {
|
||||
cfg_add_cause("%s", pr->error);
|
||||
free(pr->error);
|
||||
return (-1);
|
||||
}
|
||||
if (flags & CMD_PARSE_PARSEONLY) {
|
||||
cmd_list_free(pr->cmdlist);
|
||||
return (0);
|
||||
}
|
||||
|
||||
return (found);
|
||||
new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item0);
|
||||
else
|
||||
cmdq_append(c, new_item0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
|
||||
if (new_item != NULL)
|
||||
*new_item = new_item0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -339,15 +186,17 @@ cfg_print_causes(struct cmdq_item *item)
|
||||
void
|
||||
cfg_show_causes(struct session *s)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
u_int i;
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
u_int i;
|
||||
|
||||
if (s == NULL || cfg_ncauses == 0)
|
||||
return;
|
||||
wp = s->curw->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_copy_mode, NULL, NULL);
|
||||
window_copy_init_for_output(wp);
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
||||
free(cfg_causes[i]);
|
||||
|
||||
21
client.c
21
client.c
@@ -17,11 +17,10 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/file.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <event.h>
|
||||
@@ -216,14 +215,13 @@ client_exit_message(void)
|
||||
int
|
||||
client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
{
|
||||
struct cmd_parse_result *pr;
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
struct msg_command_data *data;
|
||||
int cmdflags, fd, i;
|
||||
const char *ttynam, *cwd;
|
||||
pid_t ppid;
|
||||
enum msgtype msg;
|
||||
char *cause, path[PATH_MAX];
|
||||
struct termios tio, saved_tio;
|
||||
size_t size;
|
||||
|
||||
@@ -249,14 +247,15 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
* later in server) but it is necessary to get the start server
|
||||
* flag.
|
||||
*/
|
||||
cmdlist = cmd_list_parse(argc, argv, NULL, 0, &cause);
|
||||
if (cmdlist != NULL) {
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
pr = cmd_parse_from_arguments(argc, argv, NULL);
|
||||
if (pr->status == CMD_PARSE_SUCCESS) {
|
||||
TAILQ_FOREACH(cmd, &pr->cmdlist->list, qentry) {
|
||||
if (cmd->entry->flags & CMD_STARTSERVER)
|
||||
cmdflags |= CMD_STARTSERVER;
|
||||
}
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
cmd_list_free(pr->cmdlist);
|
||||
} else
|
||||
free(pr->error);
|
||||
}
|
||||
|
||||
/* Create client process structure (starts logging). */
|
||||
@@ -278,9 +277,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
||||
|
||||
/* Save these before pledge(). */
|
||||
if ((cwd = getenv("PWD")) == NULL &&
|
||||
(cwd = getcwd(path, sizeof path)) == NULL &&
|
||||
(cwd = find_home()) == NULL)
|
||||
if ((cwd = find_cwd()) == NULL && (cwd = find_home()) == NULL)
|
||||
cwd = "/";
|
||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||
ttynam = "";
|
||||
|
||||
@@ -87,7 +87,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
window_set_active_pane(wp->window, wp, 1);
|
||||
session_set_current(s, wl);
|
||||
if (wp != NULL)
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
@@ -100,6 +100,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
s->cwd = format_single(item, cflag, c, s, wl, wp);
|
||||
}
|
||||
|
||||
c->last_session = c->session;
|
||||
if (c->session != NULL) {
|
||||
if (dflag) {
|
||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||
@@ -114,6 +115,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
c->session = s;
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
@@ -141,6 +143,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
|
||||
c->session = s;
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
|
||||
@@ -44,15 +44,16 @@ const struct cmd_entry cmd_bind_key_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
char *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
key_code key;
|
||||
const char *tablename;
|
||||
struct args *args = self->args;
|
||||
key_code key;
|
||||
const char *tablename;
|
||||
struct cmd_parse_result *pr;
|
||||
char **argv = args->argv;
|
||||
int argc = args->argc;
|
||||
|
||||
key = key_string_lookup_string(args->argv[0]);
|
||||
key = key_string_lookup_string(argv[0]);
|
||||
if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
|
||||
cmdq_error(item, "unknown key: %s", args->argv[0]);
|
||||
cmdq_error(item, "unknown key: %s", argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -63,14 +64,21 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
tablename = "prefix";
|
||||
|
||||
cmdlist = cmd_list_parse(args->argc - 1, args->argv + 1, NULL, 0,
|
||||
&cause);
|
||||
if (cmdlist == NULL) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
if (argc == 2)
|
||||
pr = cmd_parse_from_string(argv[1], NULL);
|
||||
else
|
||||
pr = cmd_parse_from_arguments(argc - 1, argv + 1, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
cmdq_error(item, "empty command");
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
|
||||
key_bindings_add(tablename, key, args_has(args, 'r'), cmdlist);
|
||||
key_bindings_add(tablename, key, args_has(args, 'r'), pr->cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
window_lost_pane(w, wp);
|
||||
layout_close_pane(wp);
|
||||
|
||||
w = wp->window = window_create(dst_s->sx, dst_s->sy);
|
||||
w = wp->window = window_create(w->sx, w->sy);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
w->active = wp;
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
||||
|
||||
.args = { "ab:CeE:JpPqS:t:", 0, 0 },
|
||||
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
"[-S start-line]" CMD_TARGET_PANE_USAGE,
|
||||
"[-S start-line] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -199,8 +199,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
size_t len;
|
||||
|
||||
if (self->entry == &cmd_clear_history_entry) {
|
||||
if (wp->mode == &window_copy_mode)
|
||||
window_pane_reset_mode(wp);
|
||||
window_pane_reset_mode_all(wp);
|
||||
grid_clear_history(wp->base.grid);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const struct cmd_entry cmd_choose_tree_entry = {
|
||||
|
||||
.args = { "F:Gf:NO:st:wZ", 0, 1 },
|
||||
.usage = "[-GNsw] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_choose_client_entry = {
|
||||
|
||||
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -60,7 +60,7 @@ const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
|
||||
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
CMD_TARGET_PANE_USAGE " [template]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
|
||||
@@ -129,26 +129,15 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_command_prompt_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
int done)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause, *new_template, *prompt, *ptr;
|
||||
char *new_template, *prompt, *ptr;
|
||||
char *input = NULL;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (s == NULL)
|
||||
return (0);
|
||||
@@ -175,20 +164,22 @@ cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
return (1);
|
||||
}
|
||||
|
||||
cmdlist = cmd_string_parse(new_template, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_command_prompt_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
if (new_item != NULL)
|
||||
pr = cmd_parse_from_string(new_template, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
new_item = NULL;
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
new_item = cmdq_get_error(pr->error);
|
||||
free(pr->error);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!done)
|
||||
free(new_template);
|
||||
|
||||
@@ -82,48 +82,38 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_confirm_before_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (c->flags & CLIENT_DEAD)
|
||||
return (0);
|
||||
|
||||
if (s == NULL || *s == '\0')
|
||||
return (0);
|
||||
if (tolower((u_char) s[0]) != 'y' || s[1] != '\0')
|
||||
if (tolower((u_char)s[0]) != 'y' || s[1] != '\0')
|
||||
return (0);
|
||||
|
||||
cmdlist = cmd_string_parse(cdata->cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_confirm_before_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
if (new_item != NULL)
|
||||
pr = cmd_parse_from_string(cdata->cmd, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
new_item = NULL;
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
new_item = cmdq_get_error(pr->error);
|
||||
free(pr->error);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct client *c = item->client;
|
||||
struct session *s;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
int flag;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)
|
||||
@@ -74,18 +73,11 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (wp->mode != &window_copy_mode) {
|
||||
flag = window_pane_set_mode(wp, &window_copy_mode, NULL, NULL);
|
||||
if (flag != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_init_from_pane(wp, args_has(self->args, 'e'));
|
||||
if (!window_pane_set_mode(wp, &window_copy_mode, NULL, args)) {
|
||||
if (args_has(args, 'M'))
|
||||
window_copy_start_drag(c, &shared->mouse);
|
||||
}
|
||||
if (args_has(args, 'M')) {
|
||||
if (wp->mode != NULL && wp->mode != &window_copy_mode)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_start_drag(c, &shared->mouse);
|
||||
}
|
||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||
if (args_has(self->args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
178
cmd-display-menu.c
Normal file
178
cmd-display-menu.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Display a menu on a client.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_display_menu_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_display_menu_entry = {
|
||||
.name = "display-menu",
|
||||
.alias = "menu",
|
||||
|
||||
.args = { "c:t:T:x:y:", 1, -1 },
|
||||
.usage = "[-c target-client] " CMD_TARGET_PANE_USAGE " [-T title] "
|
||||
"[-x position] [-y position] name key command ...",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_menu_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct menu *menu = NULL;
|
||||
struct style_range *sr;
|
||||
struct menu_item menu_item;
|
||||
const char *xp, *yp, *key;
|
||||
char *title, *name;
|
||||
int at, flags, i;
|
||||
u_int px, py, ox, oy, sx, sy;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
if (c->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
at = status_at_line(c);
|
||||
|
||||
if (args_has(args, 'T'))
|
||||
title = format_single(NULL, args_get(args, 'T'), c, s, wl, wp);
|
||||
else
|
||||
title = xstrdup("");
|
||||
|
||||
menu = menu_create(title);
|
||||
|
||||
for (i = 0; i != args->argc; /* nothing */) {
|
||||
name = args->argv[i++];
|
||||
if (*name == '\0') {
|
||||
menu_add_item(menu, NULL, item, c, fs);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (args->argc - i < 2) {
|
||||
cmdq_error(item, "not enough arguments");
|
||||
free(title);
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
key = args->argv[i++];
|
||||
|
||||
menu_item.name = name;
|
||||
menu_item.key = key_string_lookup_string(key);
|
||||
menu_item.command = args->argv[i++];
|
||||
|
||||
menu_add_item(menu, &menu_item, item, c, fs);
|
||||
}
|
||||
free(title);
|
||||
if (menu == NULL) {
|
||||
cmdq_error(item, "invalid menu arguments");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (menu->count == 0) {
|
||||
menu_free(menu);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
xp = args_get(args, 'x');
|
||||
if (xp == NULL)
|
||||
px = 0;
|
||||
else if (strcmp(xp, "R") == 0)
|
||||
px = c->tty.sx - 1;
|
||||
else if (strcmp(xp, "P") == 0) {
|
||||
tty_window_offset(&c->tty, &ox, &oy, &sx, &sy);
|
||||
if (wp->xoff >= ox)
|
||||
px = wp->xoff - ox;
|
||||
else
|
||||
px = 0;
|
||||
} else if (strcmp(xp, "M") == 0 && item->shared->mouse.valid) {
|
||||
if (item->shared->mouse.x > (menu->width + 4) / 2)
|
||||
px = item->shared->mouse.x - (menu->width + 4) / 2;
|
||||
else
|
||||
px = 0;
|
||||
}
|
||||
else if (strcmp(xp, "W") == 0) {
|
||||
if (at == -1)
|
||||
px = 0;
|
||||
else {
|
||||
TAILQ_FOREACH(sr, &c->status.entries[0].ranges, entry) {
|
||||
if (sr->type != STYLE_RANGE_WINDOW)
|
||||
continue;
|
||||
if (sr->argument == (u_int)wl->idx)
|
||||
break;
|
||||
}
|
||||
if (sr != NULL)
|
||||
px = sr->start;
|
||||
else
|
||||
px = 0;
|
||||
}
|
||||
} else
|
||||
px = strtoul(xp, NULL, 10);
|
||||
if (px + menu->width + 4 >= c->tty.sx)
|
||||
px = c->tty.sx - menu->width - 4;
|
||||
|
||||
yp = args_get(args, 'y');
|
||||
if (yp == NULL)
|
||||
py = 0;
|
||||
else if (strcmp(yp, "P") == 0) {
|
||||
tty_window_offset(&c->tty, &ox, &oy, &sx, &sy);
|
||||
if (wp->yoff + wp->sy >= oy)
|
||||
py = wp->yoff + wp->sy - oy;
|
||||
else
|
||||
py = 0;
|
||||
} else if (strcmp(yp, "M") == 0 && item->shared->mouse.valid)
|
||||
py = item->shared->mouse.y + menu->count + 2;
|
||||
else if (strcmp(yp, "S") == 0) {
|
||||
if (at == -1)
|
||||
py = c->tty.sy;
|
||||
else if (at == 0)
|
||||
py = status_line_size(c) + menu->count + 2;
|
||||
else
|
||||
py = at;
|
||||
} else
|
||||
py = strtoul(yp, NULL, 10);
|
||||
if (py < menu->count + 2)
|
||||
py = 0;
|
||||
else
|
||||
py -= menu->count + 2;
|
||||
if (py + menu->count + 2 >= c->tty.sy)
|
||||
py = c->tty.sy - menu->count - 2;
|
||||
|
||||
flags = 0;
|
||||
if (!item->shared->mouse.valid)
|
||||
flags |= MENU_NOMOUSE;
|
||||
if (menu_display(menu, flags, item, px, py, c, fs, NULL, NULL) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
@@ -39,8 +39,8 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.name = "display-message",
|
||||
.alias = "display",
|
||||
|
||||
.args = { "c:pt:F:", 0, 1 },
|
||||
.usage = "[-p] [-c target-client] [-F format] "
|
||||
.args = { "ac:Ipt:F:v", 0, 1 },
|
||||
.usage = "[-aIpv] [-c target-client] [-F format] "
|
||||
CMD_TARGET_PANE_USAGE " [message]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
@@ -49,23 +49,40 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.exec = cmd_display_message_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_display_message_each(const char *key, const char *value, void *arg)
|
||||
{
|
||||
struct cmdq_item *item = arg;
|
||||
|
||||
cmdq_print(item, "%s=%s", key, value);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct client *c, *target_c;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *template;
|
||||
char *msg;
|
||||
char *msg, *cause;
|
||||
struct format_tree *ft;
|
||||
int flags;
|
||||
|
||||
if (args_has(args, 'I')) {
|
||||
if (window_pane_start_input(wp, item, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
if (args_has(args, 'F') && args->argc != 0) {
|
||||
cmdq_error(item, "only one of -F or argument must be given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
||||
|
||||
template = args_get(args, 'F');
|
||||
if (args->argc != 0)
|
||||
@@ -73,10 +90,31 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (template == NULL)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
/*
|
||||
* -c is intended to be the client where the message should be
|
||||
* displayed if -p is not given. But it makes sense to use it for the
|
||||
* formats too, assuming it matches the session. If it doesn't, use the
|
||||
* best client for the session.
|
||||
*/
|
||||
c = cmd_find_client(item, args_get(args, 'c'), 1);
|
||||
if (c != NULL && c->session == s)
|
||||
target_c = c;
|
||||
else
|
||||
target_c = cmd_find_best_client(s);
|
||||
if (args_has(self->args, 'v'))
|
||||
flags = FORMAT_VERBOSE;
|
||||
else
|
||||
flags = 0;
|
||||
ft = format_create(item->client, item, FORMAT_NONE, flags);
|
||||
format_defaults(ft, target_c, s, wl, wp);
|
||||
|
||||
msg = format_expand_time(ft, template, time(NULL));
|
||||
if (args_has(args, 'a')) {
|
||||
if (item != NULL)
|
||||
format_each(ft, cmd_display_message_each, item);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
msg = format_expand_time(ft, template);
|
||||
if (args_has(self->args, 'p'))
|
||||
cmdq_print(item, "%s", msg);
|
||||
else if (c != NULL)
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -30,42 +30,229 @@
|
||||
static enum cmd_retval cmd_display_panes_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_display_panes_callback(struct client *,
|
||||
struct window_pane *);
|
||||
|
||||
const struct cmd_entry cmd_display_panes_entry = {
|
||||
.name = "display-panes",
|
||||
.alias = "displayp",
|
||||
|
||||
.args = { "d:t:", 0, 1 },
|
||||
.usage = "[-d duration] " CMD_TARGET_CLIENT_USAGE,
|
||||
.args = { "bd:t:", 0, 1 },
|
||||
.usage = "[-b] [-d duration] " CMD_TARGET_CLIENT_USAGE " [template]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_panes_exec
|
||||
};
|
||||
|
||||
struct cmd_display_panes_data {
|
||||
struct cmdq_item *item;
|
||||
char *command;
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
|
||||
struct window_pane *wp)
|
||||
{
|
||||
struct client *c = ctx->c;
|
||||
struct tty *tty = &c->tty;
|
||||
struct session *s = c->session;
|
||||
struct options *oo = s->options;
|
||||
struct window *w = wp->window;
|
||||
struct grid_cell gc;
|
||||
u_int idx, px, py, i, j, xoff, yoff, sx, sy;
|
||||
int colour, active_colour;
|
||||
char buf[16], *ptr;
|
||||
size_t len;
|
||||
|
||||
if (wp->xoff + wp->sx <= ctx->ox ||
|
||||
wp->xoff >= ctx->ox + ctx->sx ||
|
||||
wp->yoff + wp->sy <= ctx->oy ||
|
||||
wp->yoff >= ctx->oy + ctx->sy)
|
||||
return;
|
||||
|
||||
if (wp->xoff >= ctx->ox && wp->xoff + wp->sx <= ctx->ox + ctx->sx) {
|
||||
/* All visible. */
|
||||
xoff = wp->xoff - ctx->ox;
|
||||
sx = wp->sx;
|
||||
} else if (wp->xoff < ctx->ox &&
|
||||
wp->xoff + wp->sx > ctx->ox + ctx->sx) {
|
||||
/* Both left and right not visible. */
|
||||
xoff = 0;
|
||||
sx = ctx->sx;
|
||||
} else if (wp->xoff < ctx->ox) {
|
||||
/* Left not visible. */
|
||||
xoff = 0;
|
||||
sx = wp->sx - (ctx->ox - wp->xoff);
|
||||
} else {
|
||||
/* Right not visible. */
|
||||
xoff = wp->xoff - ctx->ox;
|
||||
sx = wp->sx - xoff;
|
||||
}
|
||||
if (wp->yoff >= ctx->oy && wp->yoff + wp->sy <= ctx->oy + ctx->sy) {
|
||||
/* All visible. */
|
||||
yoff = wp->yoff - ctx->oy;
|
||||
sy = wp->sy;
|
||||
} else if (wp->yoff < ctx->oy &&
|
||||
wp->yoff + wp->sy > ctx->oy + ctx->sy) {
|
||||
/* Both top and bottom not visible. */
|
||||
yoff = 0;
|
||||
sy = ctx->sy;
|
||||
} else if (wp->yoff < ctx->oy) {
|
||||
/* Top not visible. */
|
||||
yoff = 0;
|
||||
sy = wp->sy - (ctx->oy - wp->yoff);
|
||||
} else {
|
||||
/* Bottom not visible. */
|
||||
yoff = wp->yoff - ctx->oy;
|
||||
sy = wp->sy - yoff;
|
||||
}
|
||||
|
||||
if (ctx->statustop)
|
||||
yoff += ctx->statuslines;
|
||||
px = sx / 2;
|
||||
py = sy / 2;
|
||||
|
||||
if (window_pane_index(wp, &idx) != 0)
|
||||
fatalx("index not found");
|
||||
len = xsnprintf(buf, sizeof buf, "%u", idx);
|
||||
|
||||
if (sx < len)
|
||||
return;
|
||||
colour = options_get_number(oo, "display-panes-colour");
|
||||
active_colour = options_get_number(oo, "display-panes-active-colour");
|
||||
|
||||
if (sx < len * 6 || sy < 5) {
|
||||
tty_cursor(tty, xoff + px - len / 2, yoff + py);
|
||||
goto draw_text;
|
||||
}
|
||||
|
||||
px -= len * 3;
|
||||
py -= 2;
|
||||
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
if (w->active == wp)
|
||||
gc.bg = active_colour;
|
||||
else
|
||||
gc.bg = colour;
|
||||
gc.flags |= GRID_FLAG_NOPALETTE;
|
||||
|
||||
tty_attributes(tty, &gc, wp);
|
||||
for (ptr = buf; *ptr != '\0'; ptr++) {
|
||||
if (*ptr < '0' || *ptr > '9')
|
||||
continue;
|
||||
idx = *ptr - '0';
|
||||
|
||||
for (j = 0; j < 5; j++) {
|
||||
for (i = px; i < px + 5; i++) {
|
||||
tty_cursor(tty, xoff + i, yoff + py + j);
|
||||
if (window_clock_table[idx][j][i - px])
|
||||
tty_putc(tty, ' ');
|
||||
}
|
||||
}
|
||||
px += 6;
|
||||
}
|
||||
|
||||
len = xsnprintf(buf, sizeof buf, "%ux%u", wp->sx, wp->sy);
|
||||
if (sx < len || sy < 6)
|
||||
return;
|
||||
tty_cursor(tty, xoff + sx - len, yoff);
|
||||
|
||||
draw_text:
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
if (w->active == wp)
|
||||
gc.fg = active_colour;
|
||||
else
|
||||
gc.fg = colour;
|
||||
gc.flags |= GRID_FLAG_NOPALETTE;
|
||||
|
||||
tty_attributes(tty, &gc, wp);
|
||||
tty_puts(tty, buf);
|
||||
|
||||
tty_cursor(tty, 0, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_draw(struct client *c, struct screen_redraw_ctx *ctx)
|
||||
{
|
||||
struct window *w = c->session->curw->window;
|
||||
struct window_pane *wp;
|
||||
|
||||
log_debug("%s: %s @%u", __func__, c->name, w->id);
|
||||
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (window_pane_visible(wp))
|
||||
cmd_display_panes_draw_pane(ctx, wp);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_free(struct client *c)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
||||
|
||||
if (cdata->item != NULL)
|
||||
cdata->item->flags &= ~CMDQ_WAITING;
|
||||
free(cdata->command);
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_display_panes_key(struct client *c, struct key_event *event)
|
||||
{
|
||||
struct cmd_display_panes_data *cdata = c->overlay_data;
|
||||
struct cmdq_item *new_item;
|
||||
char *cmd, *expanded;
|
||||
struct window *w = c->session->curw->window;
|
||||
struct window_pane *wp;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (event->key < '0' || event->key > '9')
|
||||
return (1);
|
||||
|
||||
wp = window_pane_at_index(w, event->key - '0');
|
||||
if (wp == NULL)
|
||||
return (1);
|
||||
window_unzoom(w);
|
||||
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(cdata->command, expanded, 1);
|
||||
|
||||
pr = cmd_parse_from_string(cmd, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
new_item = NULL;
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
new_item = cmdq_get_error(pr->error);
|
||||
free(pr->error);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
}
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
u_int delay;
|
||||
char *cause;
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
u_int delay;
|
||||
char *cause;
|
||||
struct cmd_display_panes_data *cdata;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (c->identify_callback != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
c->identify_callback = cmd_display_panes_callback;
|
||||
if (args->argc != 0)
|
||||
c->identify_callback_data = xstrdup(args->argv[0]);
|
||||
else
|
||||
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
||||
s = c->session;
|
||||
|
||||
if (c->overlay_draw != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (args_has(args, 'd')) {
|
||||
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
@@ -75,55 +262,21 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
} else
|
||||
delay = options_get_number(s->options, "display-panes-time");
|
||||
server_client_set_identify(c, delay);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_display_panes_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_display_panes_callback(struct client *c, struct window_pane *wp)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *template, *cmd, *expanded, *cause;
|
||||
|
||||
template = c->identify_callback_data;
|
||||
if (wp == NULL)
|
||||
goto out;
|
||||
xasprintf(&expanded, "%%%u", wp->id);
|
||||
cmd = cmd_template_replace(template, expanded, 1);
|
||||
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
new_item = cmdq_get_callback(cmd_display_panes_error,
|
||||
cause);
|
||||
} else
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
if (new_item != NULL)
|
||||
cmdq_append(c, new_item);
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
|
||||
out:
|
||||
free(c->identify_callback_data);
|
||||
c->identify_callback_data = NULL;
|
||||
c->identify_callback = NULL;
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
if (args->argc != 0)
|
||||
cdata->command = xstrdup(args->argv[0]);
|
||||
else
|
||||
cdata->command = xstrdup("select-pane -t '%%'");
|
||||
if (args_has(args, 'b'))
|
||||
cdata->item = NULL;
|
||||
else
|
||||
cdata->item = item;
|
||||
|
||||
server_client_set_overlay(c, delay, cmd_display_panes_draw,
|
||||
cmd_display_panes_key, cmd_display_panes_free, cdata);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ const struct cmd_entry cmd_find_window_entry = {
|
||||
.name = "find-window",
|
||||
.alias = "findw",
|
||||
|
||||
.args = { "CNt:T", 1, 1 },
|
||||
.usage = "[-CNT] " CMD_TARGET_PANE_USAGE " match-string",
|
||||
.args = { "CNt:TZ", 1, 1 },
|
||||
.usage = "[-CNTZ] " CMD_TARGET_PANE_USAGE " match-string",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -83,6 +83,8 @@ cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s);
|
||||
|
||||
new_args = args_parse("", 1, &argv);
|
||||
if (args_has(args, 'Z'))
|
||||
args_set(new_args, 'Z', NULL);
|
||||
args_set(new_args, 'f', filter);
|
||||
|
||||
window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args);
|
||||
|
||||
113
cmd-find.c
113
cmd-find.c
@@ -34,6 +34,7 @@ static int cmd_find_best_winlink_with_window(struct cmd_find_state *);
|
||||
|
||||
static const char *cmd_find_map_table(const char *[][2], const char *);
|
||||
|
||||
static void cmd_find_log_state(const char *, struct cmd_find_state *);
|
||||
static int cmd_find_get_session(struct cmd_find_state *, const char *);
|
||||
static int cmd_find_get_window(struct cmd_find_state *, const char *, int);
|
||||
static int cmd_find_get_window_with_session(struct cmd_find_state *,
|
||||
@@ -82,6 +83,7 @@ cmd_find_try_TMUX(struct client *c)
|
||||
char tmp[256];
|
||||
long long pid;
|
||||
u_int session;
|
||||
struct session *s;
|
||||
|
||||
envent = environ_find(c->environ, "TMUX");
|
||||
if (envent == NULL)
|
||||
@@ -91,8 +93,13 @@ cmd_find_try_TMUX(struct client *c)
|
||||
return (NULL);
|
||||
if (pid != getpid())
|
||||
return (NULL);
|
||||
log_debug("client %p TMUX %s (session @%u)", c, envent->value, session);
|
||||
return (session_find_by_id(session));
|
||||
log_debug("%s: client %p TMUX %s (session $%u)", __func__, c,
|
||||
envent->value, session);
|
||||
|
||||
s = session_find_by_id(session);
|
||||
if (s != NULL)
|
||||
log_debug("%s: session $%u still exists", __func__, s->id);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* Find pane containing client if any. */
|
||||
@@ -105,9 +112,11 @@ cmd_find_inside_pane(struct client *c)
|
||||
return (NULL);
|
||||
|
||||
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
||||
if (strcmp(wp->tty, c->ttyname) == 0)
|
||||
if (wp->fd != -1 && strcmp(wp->tty, c->ttyname) == 0)
|
||||
break;
|
||||
}
|
||||
if (wp != NULL)
|
||||
log_debug("%s: got pane %%%u (%s)", __func__, wp->id, wp->tty);
|
||||
return (wp);
|
||||
}
|
||||
|
||||
@@ -121,12 +130,12 @@ cmd_find_client_better(struct client *c, struct client *than)
|
||||
}
|
||||
|
||||
/* Find best client for session. */
|
||||
static struct client *
|
||||
struct client *
|
||||
cmd_find_best_client(struct session *s)
|
||||
{
|
||||
struct client *c_loop, *c;
|
||||
|
||||
if (s->flags & SESSION_UNATTACHED)
|
||||
if (s->attached == 0)
|
||||
s = NULL;
|
||||
|
||||
c = NULL;
|
||||
@@ -150,10 +159,10 @@ cmd_find_session_better(struct session *s, struct session *than, int flags)
|
||||
if (than == NULL)
|
||||
return (1);
|
||||
if (flags & CMD_FIND_PREFER_UNATTACHED) {
|
||||
attached = (~than->flags & SESSION_UNATTACHED);
|
||||
if (attached && (s->flags & SESSION_UNATTACHED))
|
||||
attached = (than->attached != 0);
|
||||
if (attached && s->attached == 0)
|
||||
return (1);
|
||||
else if (!attached && (~s->flags & SESSION_UNATTACHED))
|
||||
else if (!attached && s->attached != 0)
|
||||
return (0);
|
||||
}
|
||||
return (timercmp(&s->activity_time, &than->activity_time, >));
|
||||
@@ -166,6 +175,8 @@ cmd_find_best_session(struct session **slist, u_int ssize, int flags)
|
||||
struct session *s_loop, *s;
|
||||
u_int i;
|
||||
|
||||
log_debug("%s: %u sessions to try", __func__, ssize);
|
||||
|
||||
s = NULL;
|
||||
if (slist != NULL) {
|
||||
for (i = 0; i < ssize; i++) {
|
||||
@@ -189,6 +200,8 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs)
|
||||
u_int ssize;
|
||||
struct session *s;
|
||||
|
||||
log_debug("%s: window is @%u", __func__, fs->w->id);
|
||||
|
||||
ssize = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
if (!session_has(s, fs->w))
|
||||
@@ -210,7 +223,7 @@ fail:
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the best winlink for a window (the current if it contains the pane,
|
||||
* Find the best winlink for a window (the current if it contains the window,
|
||||
* otherwise the first).
|
||||
*/
|
||||
static int
|
||||
@@ -218,6 +231,8 @@ cmd_find_best_winlink_with_window(struct cmd_find_state *fs)
|
||||
{
|
||||
struct winlink *wl, *wl_loop;
|
||||
|
||||
log_debug("%s: window is @%u", __func__, fs->w->id);
|
||||
|
||||
wl = NULL;
|
||||
if (fs->s->curw != NULL && fs->s->curw->window == fs->w)
|
||||
wl = fs->s->curw;
|
||||
@@ -436,15 +451,16 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
||||
if (window[0] != '+' && window[0] != '-') {
|
||||
idx = strtonum(window, 0, INT_MAX, &errstr);
|
||||
if (errstr == NULL) {
|
||||
if (fs->flags & CMD_FIND_WINDOW_INDEX) {
|
||||
fs->idx = idx;
|
||||
return (0);
|
||||
}
|
||||
fs->wl = winlink_find_by_index(&fs->s->windows, idx);
|
||||
if (fs->wl != NULL) {
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
return (0);
|
||||
}
|
||||
if (fs->flags & CMD_FIND_WINDOW_INDEX) {
|
||||
fs->idx = idx;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,11 +717,11 @@ cmd_find_copy_state(struct cmd_find_state *dst, struct cmd_find_state *src)
|
||||
}
|
||||
|
||||
/* Log the result. */
|
||||
void
|
||||
static void
|
||||
cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
|
||||
{
|
||||
if (fs->s != NULL)
|
||||
log_debug("%s: s=$%u", prefix, fs->s->id);
|
||||
log_debug("%s: s=$%u %s", prefix, fs->s->id, fs->s->name);
|
||||
else
|
||||
log_debug("%s: s=none", prefix);
|
||||
if (fs->wl != NULL) {
|
||||
@@ -894,6 +910,9 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
||||
break;
|
||||
}
|
||||
if (wl != NULL) {
|
||||
log_debug("%s: session $%u has pane %%%u", __func__,
|
||||
s->id, wp->id);
|
||||
|
||||
fs->s = s;
|
||||
fs->wl = s->curw; /* use current session */
|
||||
fs->w = fs->wl->window;
|
||||
@@ -901,6 +920,9 @@ cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
} else {
|
||||
log_debug("%s: session $%u does not have pane %%%u",
|
||||
__func__, s->id, wp->id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,7 +971,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
{
|
||||
struct mouse_event *m;
|
||||
struct cmd_find_state current;
|
||||
char *colon, *period, *copy = NULL;
|
||||
char *colon, *period, *copy = NULL, tmp[256];
|
||||
const char *session, *window, *pane, *s;
|
||||
int window_only = 0, pane_only = 0;
|
||||
|
||||
@@ -966,11 +988,25 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
s = "session";
|
||||
else
|
||||
s = "unknown";
|
||||
if (target == NULL)
|
||||
log_debug("%s: target none, type %s", __func__, s);
|
||||
else
|
||||
log_debug("%s: target %s, type %s", __func__, target, s);
|
||||
log_debug("%s: item %p, flags %#x", __func__, item, flags);
|
||||
*tmp = '\0';
|
||||
if (flags & CMD_FIND_PREFER_UNATTACHED)
|
||||
strlcat(tmp, "PREFER_UNATTACHED,", sizeof tmp);
|
||||
if (flags & CMD_FIND_QUIET)
|
||||
strlcat(tmp, "QUIET,", sizeof tmp);
|
||||
if (flags & CMD_FIND_WINDOW_INDEX)
|
||||
strlcat(tmp, "WINDOW_INDEX,", sizeof tmp);
|
||||
if (flags & CMD_FIND_DEFAULT_MARKED)
|
||||
strlcat(tmp, "DEFAULT_MARKED,", sizeof tmp);
|
||||
if (flags & CMD_FIND_EXACT_SESSION)
|
||||
strlcat(tmp, "EXACT_SESSION,", sizeof tmp);
|
||||
if (flags & CMD_FIND_EXACT_WINDOW)
|
||||
strlcat(tmp, "EXACT_WINDOW,", sizeof tmp);
|
||||
if (flags & CMD_FIND_CANFAIL)
|
||||
strlcat(tmp, "CANFAIL,", sizeof tmp);
|
||||
if (*tmp != '\0')
|
||||
tmp[strlen(tmp) - 1] = '\0';
|
||||
log_debug("%s: target %s, type %s, item %p, flags %s", __func__,
|
||||
target == NULL ? "none" : target, s, item, tmp);
|
||||
|
||||
/* Clear new state. */
|
||||
cmd_find_clear_state(fs, flags);
|
||||
@@ -1003,12 +1039,16 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
switch (type) {
|
||||
case CMD_FIND_PANE:
|
||||
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
|
||||
if (fs->wp != NULL)
|
||||
if (fs->wp != NULL) {
|
||||
fs->w = fs->wl->window;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
case CMD_FIND_WINDOW:
|
||||
case CMD_FIND_SESSION:
|
||||
fs->wl = cmd_mouse_window(m, &fs->s);
|
||||
if (fs->wl == NULL && fs->s != NULL)
|
||||
fs->wl = fs->s->curw;
|
||||
if (fs->wl != NULL) {
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
@@ -1110,9 +1150,16 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
if (pane != NULL)
|
||||
pane = cmd_find_map_table(cmd_find_pane_table, pane);
|
||||
|
||||
log_debug("%s: target %s (flags %#x): session=%s, window=%s, pane=%s",
|
||||
__func__, target, flags, session == NULL ? "none" : session,
|
||||
window == NULL ? "none" : window, pane == NULL ? "none" : pane);
|
||||
if (session != NULL || window != NULL || pane != NULL) {
|
||||
log_debug("%s: target %s is %s%s%s%s%s%s",
|
||||
__func__, target,
|
||||
session == NULL ? "" : "session ",
|
||||
session == NULL ? "" : session,
|
||||
window == NULL ? "" : "window ",
|
||||
window == NULL ? "" : window,
|
||||
pane == NULL ? "" : "pane ",
|
||||
pane == NULL ? "" : pane);
|
||||
}
|
||||
|
||||
/* No pane is allowed if want an index. */
|
||||
if (pane != NULL && (flags & CMD_FIND_WINDOW_INDEX)) {
|
||||
@@ -1141,7 +1188,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
/* This will fill in winlink and window. */
|
||||
if (cmd_find_get_window_with_session(fs, window) != 0)
|
||||
goto no_window;
|
||||
fs->wp = fs->wl->window->active;
|
||||
if (fs->wl != NULL) /* can be NULL if index only */
|
||||
fs->wp = fs->wl->window->active;
|
||||
goto found;
|
||||
}
|
||||
|
||||
@@ -1181,7 +1229,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
/* This will fill in session, winlink and window. */
|
||||
if (cmd_find_get_window(fs, window, window_only) != 0)
|
||||
goto no_window;
|
||||
fs->wp = fs->wl->window->active;
|
||||
if (fs->wl != NULL) /* can be NULL if index only */
|
||||
fs->wp = fs->wl->window->active;
|
||||
goto found;
|
||||
}
|
||||
|
||||
@@ -1218,17 +1267,17 @@ found:
|
||||
|
||||
no_session:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(item, "can't find session %s", session);
|
||||
cmdq_error(item, "can't find session: %s", session);
|
||||
goto error;
|
||||
|
||||
no_window:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(item, "can't find window %s", window);
|
||||
cmdq_error(item, "can't find window: %s", window);
|
||||
goto error;
|
||||
|
||||
no_pane:
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(item, "can't find pane %s", pane);
|
||||
cmdq_error(item, "can't find pane: %s", pane);
|
||||
goto error;
|
||||
}
|
||||
|
||||
@@ -1298,7 +1347,7 @@ cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
|
||||
|
||||
/* If no client found, report an error. */
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(item, "can't find client %s", copy);
|
||||
cmdq_error(item, "can't find client: %s", copy);
|
||||
|
||||
free(copy);
|
||||
log_debug("%s: target %s, return %p", __func__, target, c);
|
||||
|
||||
118
cmd-if-shell.c
118
cmd-if-shell.c
@@ -49,8 +49,7 @@ const struct cmd_entry cmd_if_shell_entry = {
|
||||
};
|
||||
|
||||
struct cmd_if_shell_data {
|
||||
char *file;
|
||||
u_int line;
|
||||
struct cmd_parse_input input;
|
||||
|
||||
char *cmd_if;
|
||||
char *cmd_else;
|
||||
@@ -64,59 +63,62 @@ static enum cmd_retval
|
||||
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct mouse_event *m = &item->shared->mouse;
|
||||
struct cmd_if_shell_data *cdata;
|
||||
char *shellcmd, *cmd, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
char *shellcmd, *cmd;
|
||||
struct cmdq_item *new_item;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *cwd;
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = NULL;
|
||||
struct cmd_parse_input pi;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (args_has(args, 'F')) {
|
||||
cmd = NULL;
|
||||
if (*shellcmd != '0' && *shellcmd != '\0')
|
||||
cmd = args->argv[1];
|
||||
else if (args->argc == 3)
|
||||
cmd = args->argv[2];
|
||||
else
|
||||
cmd = NULL;
|
||||
free(shellcmd);
|
||||
if (cmd == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
|
||||
memset(&pi, 0, sizeof pi);
|
||||
if (self->file != NULL)
|
||||
pi.file = self->file;
|
||||
pi.line = self->line;
|
||||
pi.item = item;
|
||||
pi.c = c;
|
||||
cmd_find_copy_state(&pi.fs, &item->target);
|
||||
|
||||
pr = cmd_parse_from_string(cmd, &pi);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
cmdq_error(item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, NULL, m, 0);
|
||||
cmdq_insert_after(item, new_item);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
break;
|
||||
}
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &shared->mouse, 0);
|
||||
cmdq_insert_after(item, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
if (self->file != NULL) {
|
||||
cdata->file = xstrdup(self->file);
|
||||
cdata->line = self->line;
|
||||
}
|
||||
|
||||
cdata->cmd_if = xstrdup(args->argv[1]);
|
||||
if (args->argc == 3)
|
||||
cdata->cmd_else = xstrdup(args->argv[2]);
|
||||
else
|
||||
cdata->cmd_else = NULL;
|
||||
memcpy(&cdata->mouse, m, sizeof cdata->mouse);
|
||||
|
||||
cdata->client = item->client;
|
||||
if (cdata->client != NULL)
|
||||
@@ -126,10 +128,24 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->item = item;
|
||||
else
|
||||
cdata->item = NULL;
|
||||
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
|
||||
|
||||
job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback,
|
||||
cmd_if_shell_free, cdata, 0);
|
||||
memset(&cdata->input, 0, sizeof cdata->input);
|
||||
if (self->file != NULL)
|
||||
cdata->input.file = xstrdup(self->file);
|
||||
cdata->input.line = self->line;
|
||||
cdata->input.item = cdata->item;
|
||||
cdata->input.c = c;
|
||||
if (cdata->input.c != NULL)
|
||||
cdata->input.c->references++;
|
||||
cmd_find_copy_state(&cdata->input.fs, &item->target);
|
||||
|
||||
if (job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0) == NULL) {
|
||||
cmdq_error(item, "failed to run command: %s", shellcmd);
|
||||
free(shellcmd);
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
free(shellcmd);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
@@ -140,31 +156,36 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
static void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = job->data;
|
||||
struct cmd_if_shell_data *cdata = job_get_data(job);
|
||||
struct client *c = cdata->client;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause, *cmd, *file = cdata->file;
|
||||
u_int line = cdata->line;
|
||||
struct mouse_event *m = &cdata->mouse;
|
||||
struct cmdq_item *new_item = NULL;
|
||||
char *cmd;
|
||||
int status;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (!WIFEXITED(job->status) || WEXITSTATUS(job->status) != 0)
|
||||
status = job_get_status(job);
|
||||
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
cmd = cdata->cmd_else;
|
||||
else
|
||||
cmd = cdata->cmd_if;
|
||||
if (cmd == NULL)
|
||||
goto out;
|
||||
|
||||
cmdlist = cmd_string_parse(cmd, file, line, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL && cdata->item != NULL)
|
||||
cmdq_error(cdata->item, "%s", cause);
|
||||
free(cause);
|
||||
new_item = NULL;
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &cdata->mouse, 0);
|
||||
cmd_list_free(cmdlist);
|
||||
pr = cmd_parse_from_string(cmd, &cdata->input);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
if (cdata->item != NULL)
|
||||
cmdq_error(cdata->item, "%s", pr->error);
|
||||
free(pr->error);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, NULL, m, 0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
break;
|
||||
}
|
||||
|
||||
if (new_item != NULL) {
|
||||
if (cdata->item == NULL)
|
||||
cmdq_append(c, new_item);
|
||||
@@ -188,6 +209,9 @@ cmd_if_shell_free(void *data)
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
|
||||
free(cdata->file);
|
||||
if (cdata->input.c != NULL)
|
||||
server_client_unref(cdata->input.c);
|
||||
free((void *)cdata->input.file);
|
||||
|
||||
free(cdata);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
int size, percentage, dst_idx;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
int not_same_window;
|
||||
int not_same_window, flags;
|
||||
|
||||
if (self->entry == &cmd_join_pane_entry)
|
||||
not_same_window = 1;
|
||||
@@ -123,7 +123,11 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
size = (dst_wp->sx * percentage) / 100;
|
||||
}
|
||||
lc = layout_split_pane(dst_wp, type, size, args_has(args, 'b'), 0);
|
||||
if (args_has(args, 'b'))
|
||||
flags = SPAWN_BEFORE;
|
||||
else
|
||||
flags = 0;
|
||||
lc = layout_split_pane(dst_wp, type, size, flags);
|
||||
if (lc == NULL) {
|
||||
cmdq_error(item, "create pane failed: pane too small");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -144,7 +148,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
server_redraw_window(dst_w);
|
||||
|
||||
if (!args_has(args, 'd')) {
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
window_set_active_pane(dst_w, src_wp, 1);
|
||||
session_select(dst_s, dst_idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
server_redraw_session(dst_s);
|
||||
|
||||
@@ -47,9 +47,8 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
||||
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
if (args_has(self->args, 'a')) {
|
||||
server_unzoom_window(wl->window);
|
||||
TAILQ_FOREACH_SAFE(loopwp, &wl->window->panes, entry, tmpwp) {
|
||||
if (loopwp == wp)
|
||||
continue;
|
||||
@@ -60,13 +59,6 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
server_kill_window(wl->window);
|
||||
recalculate_sizes();
|
||||
} else {
|
||||
layout_close_pane(wp);
|
||||
window_remove_pane(wl->window, wp);
|
||||
server_redraw_window(wl->window);
|
||||
}
|
||||
server_kill_pane(wp);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
RB_FOREACH_SAFE(sloop, sessions, &sessions, stmp) {
|
||||
if (sloop != s) {
|
||||
server_destroy_session(sloop);
|
||||
session_destroy(sloop, __func__);
|
||||
session_destroy(sloop, 1, __func__);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server_destroy_session(s);
|
||||
session_destroy(s, __func__);
|
||||
session_destroy(s, 1, __func__);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = self->args;
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
const char *key, *tablename, *r;
|
||||
char *cp, tmp[BUFSIZ];
|
||||
const char *tablename, *r;
|
||||
char *key, *cp, tmp[BUFSIZ];
|
||||
int repeat, width, tablewidth, keywidth;
|
||||
|
||||
if (self->entry == &cmd_list_commands_entry)
|
||||
@@ -75,11 +75,15 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
repeat = 0;
|
||||
tablewidth = keywidth = 0;
|
||||
RB_FOREACH(table, key_tables, &key_tables) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
||||
table = key_bindings_first_table ();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
continue;
|
||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
||||
key = key_string_lookup_key(bd->key);
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
key = args_escape(key_string_lookup_key(bd->key));
|
||||
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
repeat = 1;
|
||||
@@ -90,14 +94,22 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
width = utf8_cstrwidth(key);
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
|
||||
free(key);
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
table = key_bindings_next_table(table);
|
||||
}
|
||||
|
||||
RB_FOREACH(table, key_tables, &key_tables) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0)
|
||||
table = key_bindings_first_table ();
|
||||
while (table != NULL) {
|
||||
if (tablename != NULL && strcmp(table->name, tablename) != 0) {
|
||||
table = key_bindings_next_table(table);
|
||||
continue;
|
||||
RB_FOREACH(bd, key_bindings, &table->key_bindings) {
|
||||
key = key_string_lookup_key(bd->key);
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
key = args_escape(key_string_lookup_key(bd->key));
|
||||
|
||||
if (!repeat)
|
||||
r = "";
|
||||
@@ -117,12 +129,16 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
strlcat(tmp, " ", sizeof tmp);
|
||||
free(cp);
|
||||
|
||||
cp = cmd_list_print(bd->cmdlist);
|
||||
cp = cmd_list_print(bd->cmdlist, 1);
|
||||
strlcat(tmp, cp, sizeof tmp);
|
||||
free(cp);
|
||||
|
||||
cmdq_print(item, "bind-key %s", tmp);
|
||||
|
||||
free(key);
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
table = key_bindings_next_table(table);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
|
||||
#define LIST_SESSIONS_TEMPLATE \
|
||||
"#{session_name}: #{session_windows} windows " \
|
||||
"(created #{t:session_created}) " \
|
||||
"[#{session_width}x#{session_height}]" \
|
||||
"(created #{t:session_created})" \
|
||||
"#{?session_grouped, (group ,}" \
|
||||
"#{session_group}#{?session_grouped,),}" \
|
||||
"#{?session_attached, (attached),}"
|
||||
|
||||
85
cmd-list.c
85
cmd-list.c
@@ -23,62 +23,37 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
static u_int cmd_list_next_group = 1;
|
||||
|
||||
struct cmd_list *
|
||||
cmd_list_parse(int argc, char **argv, const char *file, u_int line,
|
||||
char **cause)
|
||||
cmd_list_new(void)
|
||||
{
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
int i, lastsplit;
|
||||
size_t arglen, new_argc;
|
||||
char **copy_argv, **new_argv;
|
||||
|
||||
copy_argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
cmdlist = xcalloc(1, sizeof *cmdlist);
|
||||
cmdlist->references = 1;
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
TAILQ_INIT(&cmdlist->list);
|
||||
|
||||
lastsplit = 0;
|
||||
for (i = 0; i < argc; i++) {
|
||||
arglen = strlen(copy_argv[i]);
|
||||
if (arglen == 0 || copy_argv[i][arglen - 1] != ';')
|
||||
continue;
|
||||
copy_argv[i][arglen - 1] = '\0';
|
||||
|
||||
if (arglen > 1 && copy_argv[i][arglen - 2] == '\\') {
|
||||
copy_argv[i][arglen - 2] = ';';
|
||||
continue;
|
||||
}
|
||||
|
||||
new_argc = i - lastsplit;
|
||||
new_argv = copy_argv + lastsplit;
|
||||
if (arglen != 1)
|
||||
new_argc++;
|
||||
|
||||
cmd = cmd_parse(new_argc, new_argv, file, line, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
|
||||
lastsplit = i + 1;
|
||||
}
|
||||
|
||||
if (lastsplit != argc) {
|
||||
cmd = cmd_parse(argc - lastsplit, copy_argv + lastsplit,
|
||||
file, line, cause);
|
||||
if (cmd == NULL)
|
||||
goto bad;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
}
|
||||
|
||||
cmd_free_argv(argc, copy_argv);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
bad:
|
||||
cmd_list_free(cmdlist);
|
||||
cmd_free_argv(argc, copy_argv);
|
||||
return (NULL);
|
||||
void
|
||||
cmd_list_append(struct cmd_list *cmdlist, struct cmd *cmd)
|
||||
{
|
||||
cmd->group = cmdlist->group;
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_list_move(struct cmd_list *cmdlist, struct cmd_list *from)
|
||||
{
|
||||
struct cmd *cmd, *cmd1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &from->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&from->list, cmd, qentry);
|
||||
TAILQ_INSERT_TAIL(&cmdlist->list, cmd, qentry);
|
||||
}
|
||||
cmdlist->group = cmd_list_next_group++;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -91,16 +66,14 @@ cmd_list_free(struct cmd_list *cmdlist)
|
||||
|
||||
TAILQ_FOREACH_SAFE(cmd, &cmdlist->list, qentry, cmd1) {
|
||||
TAILQ_REMOVE(&cmdlist->list, cmd, qentry);
|
||||
args_free(cmd->args);
|
||||
free(cmd->file);
|
||||
free(cmd);
|
||||
cmd_free(cmd);
|
||||
}
|
||||
|
||||
free(cmdlist);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_list_print(struct cmd_list *cmdlist)
|
||||
cmd_list_print(struct cmd_list *cmdlist, int escaped)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
char *buf, *this;
|
||||
@@ -112,12 +85,16 @@ cmd_list_print(struct cmd_list *cmdlist)
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
this = cmd_print(cmd);
|
||||
|
||||
len += strlen(this) + 3;
|
||||
len += strlen(this) + 4;
|
||||
buf = xrealloc(buf, len);
|
||||
|
||||
strlcat(buf, this, len);
|
||||
if (TAILQ_NEXT(cmd, qentry) != NULL)
|
||||
strlcat(buf, " ; ", len);
|
||||
if (TAILQ_NEXT(cmd, qentry) != NULL) {
|
||||
if (escaped)
|
||||
strlcat(buf, " \\; ", len);
|
||||
else
|
||||
strlcat(buf, " ; ", len);
|
||||
}
|
||||
|
||||
free(this);
|
||||
}
|
||||
|
||||
@@ -56,11 +56,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_load_buffer_data *cdata;
|
||||
struct client *c = item->client;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
FILE *f;
|
||||
const char *path, *bufname;
|
||||
const char *bufname;
|
||||
char *pdata = NULL, *new_pdata, *cause;
|
||||
char *file;
|
||||
char *path, *file;
|
||||
size_t psize;
|
||||
int ch, error;
|
||||
|
||||
@@ -68,8 +71,11 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'b'))
|
||||
bufname = args_get(args, 'b');
|
||||
|
||||
path = args->argv[0];
|
||||
path = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (strcmp(path, "-") == 0) {
|
||||
free(path);
|
||||
c = item->client;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->item = item;
|
||||
|
||||
@@ -79,14 +85,17 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
error = server_set_stdin_callback(c, cmd_load_buffer_callback,
|
||||
cdata, &cause);
|
||||
if (error != 0) {
|
||||
cmdq_error(item, "%s: %s", path, cause);
|
||||
cmdq_error(item, "-: %s", cause);
|
||||
free(cause);
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
file = server_client_get_path(c, path);
|
||||
file = server_client_get_path(item->client, path);
|
||||
free(path);
|
||||
|
||||
f = fopen(file, "rb");
|
||||
if (f == NULL) {
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
|
||||
@@ -69,19 +69,17 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->client;
|
||||
struct session *s, *as, *groupwith;
|
||||
struct window *w;
|
||||
struct environ *env;
|
||||
struct options *oo;
|
||||
struct termios tio, *tiop;
|
||||
struct session_group *sg;
|
||||
const char *errstr, *template, *group, *prefix;
|
||||
const char *path, *cmd, *tmp;
|
||||
char **argv, *cause, *cp, *newname, *cwd = NULL;
|
||||
int detached, already_attached, idx, argc;
|
||||
int is_control = 0;
|
||||
u_int sx, sy;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
const char *errstr, *template, *group, *prefix, *tmp;
|
||||
char *cause, *cwd = NULL, *cp, *newname = NULL;
|
||||
int detached, already_attached, is_control = 0;
|
||||
u_int sx, sy, dsx, dsy;
|
||||
struct spawn_context sc;
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (self->entry == &cmd_has_session_entry) {
|
||||
/*
|
||||
@@ -96,13 +94,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
newname = NULL;
|
||||
if (args_has(args, 's')) {
|
||||
newname = format_single(item, args_get(args, 's'), c, NULL,
|
||||
NULL, NULL);
|
||||
if (!session_check_name(newname)) {
|
||||
cmdq_error(item, "bad session name: %s", newname);
|
||||
goto error;
|
||||
goto fail;
|
||||
}
|
||||
if ((as = session_find(newname)) != NULL) {
|
||||
if (args_has(args, 'A')) {
|
||||
@@ -113,7 +110,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (retval);
|
||||
}
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
goto error;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,7 +121,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (groupwith == NULL) {
|
||||
if (!session_check_name(group)) {
|
||||
cmdq_error(item, "bad group name: %s", group);
|
||||
goto error;
|
||||
goto fail;
|
||||
}
|
||||
sg = session_group_find(group);
|
||||
} else
|
||||
@@ -156,10 +153,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
/* Get the new session working directory. */
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||
else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = xstrdup(c->cwd);
|
||||
else
|
||||
cwd = xstrdup(".");
|
||||
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
||||
|
||||
/*
|
||||
* If this is a new client, check for nesting and save the termios
|
||||
@@ -174,7 +169,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (server_client_check_nested(item->client)) {
|
||||
cmdq_error(item, "sessions should be nested with care, "
|
||||
"unset $TMUX to force");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
if (tcgetattr(c->tty.fd, &tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
@@ -187,89 +182,97 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (server_client_open(c, &cause) != 0) {
|
||||
cmdq_error(item, "open terminal failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get default session size. */
|
||||
if (args_has(args, 'x')) {
|
||||
tmp = args_get(args, 'x');
|
||||
if (strcmp(tmp, "-") == 0) {
|
||||
if (c != NULL)
|
||||
dsx = c->tty.sx;
|
||||
else
|
||||
dsx = 80;
|
||||
} else {
|
||||
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "width %s", errstr);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
tmp = args_get(args, 'y');
|
||||
if (strcmp(tmp, "-") == 0) {
|
||||
if (c != NULL)
|
||||
dsy = c->tty.sy;
|
||||
else
|
||||
dsy = 24;
|
||||
} else {
|
||||
dsy = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "height %s", errstr);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Find new session size. */
|
||||
if (!detached) {
|
||||
if (!detached && !is_control) {
|
||||
sx = c->tty.sx;
|
||||
sy = c->tty.sy;
|
||||
if (!is_control &&
|
||||
sy > 0 &&
|
||||
options_get_number(global_s_options, "status"))
|
||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
||||
sy--;
|
||||
} else {
|
||||
sx = 80;
|
||||
sy = 24;
|
||||
}
|
||||
if ((is_control || detached) && args_has(args, 'x')) {
|
||||
sx = strtonum(args_get(args, 'x'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "width %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if ((is_control || detached) && args_has(args, 'y')) {
|
||||
sy = strtonum(args_get(args, 'y'), 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "height %s", errstr);
|
||||
goto error;
|
||||
tmp = options_get_string(global_s_options, "default-size");
|
||||
if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) {
|
||||
sx = 80;
|
||||
sy = 24;
|
||||
}
|
||||
if (args_has(args, 'x'))
|
||||
sx = dsx;
|
||||
if (args_has(args, 'y'))
|
||||
sy = dsy;
|
||||
}
|
||||
if (sx == 0)
|
||||
sx = 1;
|
||||
if (sy == 0)
|
||||
sy = 1;
|
||||
|
||||
/* Figure out the command for the new window. */
|
||||
argc = -1;
|
||||
argv = NULL;
|
||||
if (!args_has(args, 't') && args->argc != 0) {
|
||||
argc = args->argc;
|
||||
argv = args->argv;
|
||||
} else if (sg == NULL && groupwith == NULL) {
|
||||
cmd = options_get_string(global_s_options, "default-command");
|
||||
if (cmd != NULL && *cmd != '\0') {
|
||||
argc = 1;
|
||||
argv = (char **)&cmd;
|
||||
} else {
|
||||
argc = 0;
|
||||
argv = NULL;
|
||||
}
|
||||
/* Create the new session. */
|
||||
oo = options_create(global_s_options);
|
||||
if (args_has(args, 'x') || args_has(args, 'y')) {
|
||||
if (!args_has(args, 'x'))
|
||||
dsx = sx;
|
||||
if (!args_has(args, 'y'))
|
||||
dsy = sy;
|
||||
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy);
|
||||
}
|
||||
|
||||
path = NULL;
|
||||
if (c != NULL && c->session == NULL)
|
||||
envent = environ_find(c->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(global_environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
/* Construct the environment. */
|
||||
env = environ_create();
|
||||
if (c != NULL && !args_has(args, 'E'))
|
||||
environ_update(global_s_options, c->environ, env);
|
||||
s = session_create(prefix, newname, cwd, env, oo, tiop);
|
||||
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(global_s_options, "base-index");
|
||||
s = session_create(prefix, newname, argc, argv, path, cwd, env, tiop,
|
||||
idx, sx, sy, &cause);
|
||||
environ_free(env);
|
||||
if (s == NULL) {
|
||||
cmdq_error(item, "create session failed: %s", cause);
|
||||
/* Spawn the initial window. */
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
|
||||
sc.name = args_get(args, 'n');
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
sc.flags = 0;
|
||||
|
||||
if (spawn_window(&sc, &cause) == NULL) {
|
||||
session_destroy(s, 0, __func__);
|
||||
cmdq_error(item, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Set the initial window name if one given. */
|
||||
if (argc >= 0 && (tmp = args_get(args, 'n')) != NULL) {
|
||||
cp = format_single(item, tmp, c, s, NULL, NULL);
|
||||
w = s->curw->window;
|
||||
window_set_name(w, cp);
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
free(cp);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -303,6 +306,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
c->session = s;
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
@@ -334,13 +338,13 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-session");
|
||||
|
||||
free(cwd);
|
||||
free(newname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
fail:
|
||||
free(cwd);
|
||||
free(newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
123
cmd-new-window.c
123
cmd-new-window.c
@@ -38,9 +38,9 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
.name = "new-window",
|
||||
.alias = "neww",
|
||||
|
||||
.args = { "ac:dF:kn:Pt:", 0, -1 },
|
||||
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
|
||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
.args = { "ac:de:F:kn:Pt:", 0, -1 },
|
||||
.usage = "[-adkP] [-c start-directory] [-e environment] [-F format] "
|
||||
"[-n window-name] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
@@ -53,90 +53,53 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct spawn_context sc;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
int idx = item->target.idx;
|
||||
const char *cmd, *path, *template, *tmp;
|
||||
char **argv, *cause, *cp, *cwd, *name;
|
||||
int argc, detached;
|
||||
struct environ_entry *envent;
|
||||
struct winlink *new_wl;
|
||||
char *cause = NULL, *cp;
|
||||
const char *template, *add;
|
||||
struct cmd_find_state fs;
|
||||
struct args_value *value;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
||||
cmdq_error(item, "no free window indexes");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
detached = args_has(args, 'd');
|
||||
|
||||
if (args->argc == 0) {
|
||||
cmd = options_get_string(s->options, "default-command");
|
||||
if (cmd != NULL && *cmd != '\0') {
|
||||
argc = 1;
|
||||
argv = (char **)&cmd;
|
||||
} else {
|
||||
argc = 0;
|
||||
argv = NULL;
|
||||
}
|
||||
} else {
|
||||
argc = args->argc;
|
||||
argv = args->argv;
|
||||
if (args_has(args, 'a') && (idx = winlink_shuffle_up(s, wl)) == -1) {
|
||||
cmdq_error(item, "couldn't get a window index");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
path = NULL;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||
else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = xstrdup(item->client->cwd);
|
||||
else
|
||||
cwd = xstrdup(s->cwd);
|
||||
sc.name = args_get(args, 'n');
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
sc.environ = environ_create();
|
||||
|
||||
if ((tmp = args_get(args, 'n')) != NULL)
|
||||
name = format_single(item, tmp, c, s, NULL, NULL);
|
||||
else
|
||||
name = NULL;
|
||||
|
||||
wl = NULL;
|
||||
if (idx != -1)
|
||||
wl = winlink_find_by_index(&s->windows, idx);
|
||||
if (wl != NULL && args_has(args, 'k')) {
|
||||
/*
|
||||
* Can't use session_detach as it will destroy session if this
|
||||
* makes it empty.
|
||||
*/
|
||||
notify_session_window("window-unlinked", s, wl->window);
|
||||
wl->flags &= ~WINLINK_ALERTFLAGS;
|
||||
winlink_stack_remove(&s->lastw, wl);
|
||||
winlink_remove(&s->windows, wl);
|
||||
|
||||
/* Force select/redraw if current. */
|
||||
if (wl == s->curw) {
|
||||
detached = 0;
|
||||
s->curw = NULL;
|
||||
}
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add);
|
||||
add = args_next_value(&value);
|
||||
}
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(s->options, "base-index");
|
||||
wl = session_new(s, name, argc, argv, path, cwd, idx,
|
||||
&cause);
|
||||
if (wl == NULL) {
|
||||
sc.idx = idx;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
sc.flags = 0;
|
||||
if (args_has(args, 'd'))
|
||||
sc.flags |= SPAWN_DETACHED;
|
||||
if (args_has(args, 'k'))
|
||||
sc.flags |= SPAWN_KILL;
|
||||
|
||||
if ((new_wl = spawn_window(&sc, &cause)) == NULL) {
|
||||
cmdq_error(item, "create window failed: %s", cause);
|
||||
free(cause);
|
||||
goto error;
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!detached) {
|
||||
session_select(s, wl->idx);
|
||||
cmd_find_from_winlink(current, wl, 0);
|
||||
if (!args_has(args, 'd') || new_wl == s->curw) {
|
||||
cmd_find_from_winlink(current, new_wl, 0);
|
||||
server_redraw_session_group(s);
|
||||
} else
|
||||
server_status_session_group(s);
|
||||
@@ -144,20 +107,14 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = NEW_WINDOW_TEMPLATE;
|
||||
cp = format_single(item, template, c, s, wl, NULL);
|
||||
cp = format_single(item, template, c, s, new_wl, NULL);
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
cmd_find_from_winlink(&fs, wl, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
||||
cmd_find_from_winlink(&fs, new_wl, 0);
|
||||
cmdq_insert_hook(s, item, &fs, "after-new-window");
|
||||
|
||||
free(name);
|
||||
free(cwd);
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
free(name);
|
||||
free(cwd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
1471
cmd-parse.y
Normal file
1471
cmd-parse.y
Normal file
File diff suppressed because it is too large
Load Diff
@@ -109,7 +109,7 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
/* Expand the command. */
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
cmd = format_expand_time(ft, args->argv[0], time(NULL));
|
||||
cmd = format_expand_time(ft, args->argv[0]);
|
||||
format_free(ft);
|
||||
|
||||
/* Fork the child. */
|
||||
@@ -157,7 +157,10 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
close(pipe_fd[1]);
|
||||
|
||||
wp->pipe_fd = pipe_fd[0];
|
||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||
if (wp->fd != -1)
|
||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||
else
|
||||
wp->pipe_off = 0;
|
||||
|
||||
setblocking(wp->pipe_fd, 0);
|
||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||
@@ -165,6 +168,8 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_pipe_pane_write_callback,
|
||||
cmd_pipe_pane_error_callback,
|
||||
wp);
|
||||
if (wp->pipe_event == NULL)
|
||||
fatalx("out of memory");
|
||||
if (out)
|
||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||
if (in)
|
||||
|
||||
178
cmd-queue.c
178
cmd-queue.c
@@ -32,11 +32,14 @@ static struct cmdq_list global_queue = TAILQ_HEAD_INITIALIZER(global_queue);
|
||||
static const char *
|
||||
cmdq_name(struct client *c)
|
||||
{
|
||||
static char s[32];
|
||||
static char s[256];
|
||||
|
||||
if (c == NULL)
|
||||
return ("<global>");
|
||||
xsnprintf(s, sizeof s, "<%p>", c);
|
||||
if (c->name != NULL)
|
||||
xsnprintf(s, sizeof s, "<%s>", c->name);
|
||||
else
|
||||
xsnprintf(s, sizeof s, "<%p>", c);
|
||||
return (s);
|
||||
}
|
||||
|
||||
@@ -66,6 +69,7 @@ cmdq_append(struct client *c, struct cmdq_item *item)
|
||||
|
||||
item->queue = queue;
|
||||
TAILQ_INSERT_TAIL(queue, item, entry);
|
||||
log_debug("%s %s: %s", __func__, cmdq_name(c), item->name);
|
||||
|
||||
item = next;
|
||||
} while (item != NULL);
|
||||
@@ -81,23 +85,77 @@ cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
|
||||
|
||||
do {
|
||||
next = item->next;
|
||||
item->next = NULL;
|
||||
item->next = after->next;
|
||||
after->next = item;
|
||||
|
||||
if (c != NULL)
|
||||
c->references++;
|
||||
item->client = c;
|
||||
|
||||
item->queue = queue;
|
||||
if (after->next != NULL)
|
||||
TAILQ_INSERT_AFTER(queue, after->next, item, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(queue, after, item, entry);
|
||||
after->next = item;
|
||||
TAILQ_INSERT_AFTER(queue, after, item, entry);
|
||||
log_debug("%s %s: %s after %s", __func__, cmdq_name(c),
|
||||
item->name, after->name);
|
||||
|
||||
after = item;
|
||||
item = next;
|
||||
} while (item != NULL);
|
||||
}
|
||||
|
||||
|
||||
/* Insert a hook. */
|
||||
void
|
||||
cmdq_insert_hook(struct session *s, struct cmdq_item *item,
|
||||
struct cmd_find_state *fs, const char *fmt, ...)
|
||||
{
|
||||
struct options *oo;
|
||||
va_list ap;
|
||||
char *name;
|
||||
struct cmdq_item *new_item;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
if (item->flags & CMDQ_NOHOOKS)
|
||||
return;
|
||||
if (s == NULL)
|
||||
oo = global_s_options;
|
||||
else
|
||||
oo = s->options;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&name, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
o = options_get(oo, name);
|
||||
if (o == NULL) {
|
||||
free(name);
|
||||
return;
|
||||
}
|
||||
log_debug("running hook %s (parent %p)", name, item);
|
||||
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
cmdlist = options_array_item_value(a)->cmdlist;
|
||||
if (cmdlist == NULL) {
|
||||
a = options_array_next(a);
|
||||
continue;
|
||||
}
|
||||
|
||||
new_item = cmdq_get_command(cmdlist, fs, NULL, CMDQ_NOHOOKS);
|
||||
cmdq_format(new_item, "hook", "%s", name);
|
||||
if (item != NULL) {
|
||||
cmdq_insert_after(item, new_item);
|
||||
item = new_item;
|
||||
} else
|
||||
cmdq_append(NULL, new_item);
|
||||
|
||||
a = options_array_next(a);
|
||||
}
|
||||
|
||||
free(name);
|
||||
}
|
||||
|
||||
/* Remove an item. */
|
||||
static void
|
||||
cmdq_remove(struct cmdq_item *item)
|
||||
@@ -111,30 +169,23 @@ cmdq_remove(struct cmdq_item *item)
|
||||
if (item->client != NULL)
|
||||
server_client_unref(item->client);
|
||||
|
||||
if (item->type == CMDQ_COMMAND)
|
||||
if (item->cmdlist != NULL)
|
||||
cmd_list_free(item->cmdlist);
|
||||
|
||||
TAILQ_REMOVE(item->queue, item, entry);
|
||||
|
||||
free((void *)item->name);
|
||||
free(item->name);
|
||||
free(item);
|
||||
}
|
||||
|
||||
/* Set command group. */
|
||||
static u_int
|
||||
cmdq_next_group(void)
|
||||
{
|
||||
static u_int group;
|
||||
|
||||
return (++group);
|
||||
}
|
||||
|
||||
/* Remove all subsequent items that match this item's group. */
|
||||
static void
|
||||
cmdq_remove_group(struct cmdq_item *item)
|
||||
{
|
||||
struct cmdq_item *this, *next;
|
||||
|
||||
if (item->group == 0)
|
||||
return;
|
||||
this = TAILQ_NEXT(item, entry);
|
||||
while (this != NULL) {
|
||||
next = TAILQ_NEXT(this, entry);
|
||||
@@ -151,32 +202,34 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
{
|
||||
struct cmdq_item *item, *first = NULL, *last = NULL;
|
||||
struct cmd *cmd;
|
||||
u_int group = cmdq_next_group();
|
||||
char *tmp;
|
||||
struct cmdq_shared *shared;
|
||||
|
||||
shared = xcalloc(1, sizeof *shared);
|
||||
if (current != NULL)
|
||||
cmd_find_copy_state(&shared->current, current);
|
||||
else
|
||||
cmd_find_clear_state(&shared->current, 0);
|
||||
if (m != NULL)
|
||||
memcpy(&shared->mouse, m, sizeof shared->mouse);
|
||||
struct cmdq_shared *shared = NULL;
|
||||
u_int group = 0;
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
xasprintf(&tmp, "command[%s]", cmd->entry->name);
|
||||
if (cmd->group != group) {
|
||||
shared = xcalloc(1, sizeof *shared);
|
||||
if (current != NULL)
|
||||
cmd_find_copy_state(&shared->current, current);
|
||||
else
|
||||
cmd_find_clear_state(&shared->current, 0);
|
||||
if (m != NULL)
|
||||
memcpy(&shared->mouse, m, sizeof shared->mouse);
|
||||
group = cmd->group;
|
||||
}
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->name = tmp;
|
||||
xasprintf(&item->name, "[%s/%p]", cmd->entry->name, item);
|
||||
item->type = CMDQ_COMMAND;
|
||||
|
||||
item->group = group;
|
||||
item->group = cmd->group;
|
||||
item->flags = flags;
|
||||
|
||||
item->shared = shared;
|
||||
item->cmdlist = cmdlist;
|
||||
item->cmd = cmd;
|
||||
|
||||
log_debug("%s: %s group %u", __func__, item->name, item->group);
|
||||
|
||||
shared->references++;
|
||||
cmdlist->references++;
|
||||
|
||||
@@ -214,13 +267,22 @@ static enum cmd_retval
|
||||
cmdq_fire_command(struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
const char *name = cmdq_name(c);
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct cmd *cmd = item->cmd;
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
enum cmd_retval retval;
|
||||
struct cmd_find_state *fsp, fs;
|
||||
int flags;
|
||||
char *tmp;
|
||||
|
||||
flags = !!(cmd->flags & CMD_CONTROL);
|
||||
if (log_get_level() > 1) {
|
||||
tmp = cmd_print(cmd);
|
||||
log_debug("%s %s: (%u) %s", __func__, name, item->group, tmp);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
flags = !!(shared->flags & CMDQ_SHARED_CONTROL);
|
||||
cmdq_guard(item, "begin", flags);
|
||||
|
||||
if (item->client == NULL)
|
||||
@@ -245,7 +307,7 @@ cmdq_fire_command(struct cmdq_item *item)
|
||||
fsp = &fs;
|
||||
else
|
||||
goto out;
|
||||
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
|
||||
cmdq_insert_hook(fsp->s, item, fsp, "after-%s", entry->name);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -262,12 +324,9 @@ struct cmdq_item *
|
||||
cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
|
||||
{
|
||||
struct cmdq_item *item;
|
||||
char *tmp;
|
||||
|
||||
xasprintf(&tmp, "callback[%s]", name);
|
||||
|
||||
item = xcalloc(1, sizeof *item);
|
||||
item->name = tmp;
|
||||
xasprintf(&item->name, "[%s/%p]", name, item);
|
||||
item->type = CMDQ_CALLBACK;
|
||||
|
||||
item->group = 0;
|
||||
@@ -279,6 +338,25 @@ cmdq_get_callback1(const char *name, cmdq_cb cb, void *data)
|
||||
return (item);
|
||||
}
|
||||
|
||||
/* Generic error callback. */
|
||||
static enum cmd_retval
|
||||
cmdq_error_callback(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Get an error callback for the command queue. */
|
||||
struct cmdq_item *
|
||||
cmdq_get_error(const char *error)
|
||||
{
|
||||
return (cmdq_get_callback(cmdq_error_callback, xstrdup(error)));
|
||||
}
|
||||
|
||||
/* Fire callback on callback queue. */
|
||||
static enum cmd_retval
|
||||
cmdq_fire_callback(struct cmdq_item *item)
|
||||
@@ -404,10 +482,11 @@ cmdq_guard(struct cmdq_item *item, const char *guard, int flags)
|
||||
void
|
||||
cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct window *w;
|
||||
va_list ap;
|
||||
char *tmp, *msg;
|
||||
struct client *c = item->client;
|
||||
struct window_pane *wp;
|
||||
struct window_mode_entry *wme;
|
||||
va_list ap;
|
||||
char *tmp, *msg;
|
||||
|
||||
va_start(ap, fmt);
|
||||
|
||||
@@ -425,14 +504,11 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
evbuffer_add(c->stdout_data, "\n", 1);
|
||||
server_client_push_stdout(c);
|
||||
} else {
|
||||
w = c->session->curw->window;
|
||||
if (w->active->mode != &window_copy_mode) {
|
||||
window_pane_reset_mode(w->active);
|
||||
window_pane_set_mode(w->active, &window_copy_mode, NULL,
|
||||
NULL);
|
||||
window_copy_init_for_output(w->active);
|
||||
}
|
||||
window_copy_vadd(w->active, fmt, ap);
|
||||
wp = c->session->curw->window->active;
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
||||
window_copy_vadd(wp, fmt, ap);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -31,8 +33,8 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.name = "refresh-client",
|
||||
.alias = "refresh",
|
||||
|
||||
.args = { "C:St:", 0, 0 },
|
||||
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
|
||||
.args = { "cC:DlLRSt:U", 0, 1 },
|
||||
.usage = "[-cDlLRSU] [-C size] " CMD_TARGET_CLIENT_USAGE " [adjustment]",
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_refresh_client_exec
|
||||
@@ -43,23 +45,80 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
const char *size;
|
||||
u_int w, h;
|
||||
struct tty *tty;
|
||||
struct window *w;
|
||||
const char *size, *errstr;
|
||||
u_int x, y, adjust;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
tty = &c->tty;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
if (args_has(args, 'c') ||
|
||||
args_has(args, 'L') ||
|
||||
args_has(args, 'R') ||
|
||||
args_has(args, 'U') ||
|
||||
args_has(args, 'D'))
|
||||
{
|
||||
if (args->argc == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'c'))
|
||||
c->pan_window = NULL;
|
||||
else {
|
||||
w = c->session->curw->window;
|
||||
if (c->pan_window != w) {
|
||||
c->pan_window = w;
|
||||
c->pan_ox = tty->oox;
|
||||
c->pan_oy = tty->ooy;
|
||||
}
|
||||
if (args_has(args, 'L')) {
|
||||
if (c->pan_ox > adjust)
|
||||
c->pan_ox -= adjust;
|
||||
else
|
||||
c->pan_ox = 0;
|
||||
} else if (args_has(args, 'R')) {
|
||||
c->pan_ox += adjust;
|
||||
if (c->pan_ox > w->sx - tty->osx)
|
||||
c->pan_ox = w->sx - tty->osx;
|
||||
} else if (args_has(args, 'U')) {
|
||||
if (c->pan_oy > adjust)
|
||||
c->pan_oy -= adjust;
|
||||
else
|
||||
c->pan_oy = 0;
|
||||
} else if (args_has(args, 'D')) {
|
||||
c->pan_oy += adjust;
|
||||
if (c->pan_oy > w->sy - tty->osy)
|
||||
c->pan_oy = w->sy - tty->osy;
|
||||
}
|
||||
}
|
||||
tty_update_client_offset(c);
|
||||
server_redraw_client(c);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'l')) {
|
||||
if (c->session != NULL)
|
||||
tty_putcode_ptr2(&c->tty, TTYC_MS, "", "?");
|
||||
} else if (args_has(args, 'C')) {
|
||||
if ((size = args_get(args, 'C')) == NULL) {
|
||||
cmdq_error(item, "missing size");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (sscanf(size, "%u,%u", &w, &h) != 2) {
|
||||
if (sscanf(size, "%u,%u", &x, &y) != 2 &&
|
||||
sscanf(size, "%ux%u", &x, &y)) {
|
||||
cmdq_error(item, "bad size argument");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (w < PANE_MINIMUM || w > 5000 ||
|
||||
h < PANE_MINIMUM || h > 5000) {
|
||||
if (x < WINDOW_MINIMUM || x > WINDOW_MAXIMUM ||
|
||||
y < WINDOW_MINIMUM || y > WINDOW_MAXIMUM) {
|
||||
cmdq_error(item, "size too small or too big");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -67,16 +126,18 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "not a control client");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
tty_set_size(&c->tty, w, h);
|
||||
tty_set_size(&c->tty, x, y);
|
||||
c->flags |= CLIENT_SIZECHANGED;
|
||||
recalculate_sizes();
|
||||
} else if (args_has(args, 'S')) {
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(args, 'S')) {
|
||||
c->flags |= CLIENT_STATUSFORCE;
|
||||
server_status_client(c);
|
||||
} else {
|
||||
c->flags |= CLIENT_STATUSFORCE;
|
||||
server_redraw_client(c);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ static enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmd_find_client(item, NULL, 0);
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
char *newname;
|
||||
|
||||
|
||||
@@ -91,9 +91,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'x')) {
|
||||
x = args_strtonum(self->args, 'x', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (args_has(args, 'x')) {
|
||||
x = args_strtonum(args, 'x', PANE_MINIMUM, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "width %s", cause);
|
||||
free(cause);
|
||||
@@ -101,9 +100,8 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
layout_resize_pane_to(wp, LAYOUT_LEFTRIGHT, x);
|
||||
}
|
||||
if (args_has(self->args, 'y')) {
|
||||
y = args_strtonum(self->args, 'y', PANE_MINIMUM, INT_MAX,
|
||||
&cause);
|
||||
if (args_has(args, 'y')) {
|
||||
y = args_strtonum(args, 'y', PANE_MINIMUM, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
free(cause);
|
||||
@@ -112,13 +110,13 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
layout_resize_pane_to(wp, LAYOUT_TOPBOTTOM, y);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'L'))
|
||||
if (args_has(args, 'L'))
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, -adjust, 1);
|
||||
else if (args_has(self->args, 'R'))
|
||||
else if (args_has(args, 'R'))
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust, 1);
|
||||
else if (args_has(self->args, 'U'))
|
||||
else if (args_has(args, 'U'))
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, -adjust, 1);
|
||||
else if (args_has(self->args, 'D'))
|
||||
else if (args_has(args, 'D'))
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust, 1);
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
@@ -129,57 +127,64 @@ static void
|
||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
||||
{
|
||||
struct winlink *wl;
|
||||
struct window_pane *loop, *wp_x, *wp_y;
|
||||
u_int y, ly, x, lx, sx, sy, ex, ey;
|
||||
struct window *w;
|
||||
u_int y, ly, x, lx;
|
||||
static const int offsets[][2] = {
|
||||
{ 0, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 },
|
||||
};
|
||||
struct layout_cell *cells[nitems(offsets)], *lc;
|
||||
u_int ncells = 0, i, j, resizes = 0;
|
||||
enum layout_type type;
|
||||
|
||||
wl = cmd_mouse_window(m, NULL);
|
||||
if (wl == NULL) {
|
||||
c->tty.mouse_drag_update = NULL;
|
||||
return;
|
||||
}
|
||||
w = wl->window;
|
||||
|
||||
y = m->y; x = m->x;
|
||||
y = m->y + m->oy; x = m->x + m->ox;
|
||||
if (m->statusat == 0 && y > 0)
|
||||
y--;
|
||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
||||
y = m->statusat - 1;
|
||||
ly = m->ly; lx = m->lx;
|
||||
ly = m->ly + m->oy; lx = m->lx + m->ox;
|
||||
if (m->statusat == 0 && ly > 0)
|
||||
ly--;
|
||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
||||
ly = m->statusat - 1;
|
||||
|
||||
wp_x = wp_y = NULL;
|
||||
TAILQ_FOREACH(loop, &wl->window->panes, entry) {
|
||||
if (!window_pane_visible(loop))
|
||||
for (i = 0; i < nitems(cells); i++) {
|
||||
lc = layout_search_by_border(w->layout_root, lx + offsets[i][0],
|
||||
ly + offsets[i][1]);
|
||||
if (lc == NULL)
|
||||
continue;
|
||||
|
||||
sx = loop->xoff;
|
||||
if (sx != 0)
|
||||
sx--;
|
||||
ex = loop->xoff + loop->sx;
|
||||
for (j = 0; j < ncells; j++) {
|
||||
if (cells[j] == lc) {
|
||||
lc = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lc == NULL)
|
||||
continue;
|
||||
|
||||
sy = loop->yoff;
|
||||
if (sy != 0)
|
||||
sy--;
|
||||
ey = loop->yoff + loop->sy;
|
||||
|
||||
if ((lx == sx || lx == ex) &&
|
||||
(ly >= sy && ly <= ey) &&
|
||||
(wp_x == NULL || loop->sy > wp_x->sy))
|
||||
wp_x = loop;
|
||||
if ((ly == sy || ly == ey) &&
|
||||
(lx >= sx && lx <= ex) &&
|
||||
(wp_y == NULL || loop->sx > wp_y->sx))
|
||||
wp_y = loop;
|
||||
cells[ncells] = lc;
|
||||
ncells++;
|
||||
}
|
||||
if (wp_x == NULL && wp_y == NULL) {
|
||||
c->tty.mouse_drag_update = NULL;
|
||||
if (ncells == 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ncells; i++) {
|
||||
type = cells[i]->parent->type;
|
||||
if (y != ly && type == LAYOUT_TOPBOTTOM) {
|
||||
layout_resize_layout(w, cells[i], type, y - ly, 0);
|
||||
resizes++;
|
||||
} else if (x != lx && type == LAYOUT_LEFTRIGHT) {
|
||||
layout_resize_layout(w, cells[i], type, x - lx, 0);
|
||||
resizes++;
|
||||
}
|
||||
}
|
||||
if (wp_x != NULL)
|
||||
layout_resize_pane(wp_x, LAYOUT_LEFTRIGHT, x - lx, 0);
|
||||
if (wp_y != NULL)
|
||||
layout_resize_pane(wp_y, LAYOUT_TOPBOTTOM, y - ly, 0);
|
||||
server_redraw_window(wl->window);
|
||||
if (resizes != 0)
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
109
cmd-resize-window.c
Normal file
109
cmd-resize-window.c
Normal file
@@ -0,0 +1,109 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018 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 "tmux.h"
|
||||
|
||||
/*
|
||||
* Increase or decrease window size.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_resize_window_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_resize_window_entry = {
|
||||
.name = "resize-window",
|
||||
.alias = "resizew",
|
||||
|
||||
.args = { "aADLRt:Ux:y:", 0, 1 },
|
||||
.usage = "[-aADLRU] [-x width] [-y height] " CMD_TARGET_WINDOW_USAGE " "
|
||||
"[adjustment]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_resize_window_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->target.s;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust, sx, sy;
|
||||
|
||||
if (args->argc == 0)
|
||||
adjust = 1;
|
||||
else {
|
||||
adjust = strtonum(args->argv[0], 1, INT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "adjustment %s", errstr);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
sx = w->sx;
|
||||
sy = w->sy;
|
||||
|
||||
if (args_has(args, 'x')) {
|
||||
sx = args_strtonum(args, 'x', WINDOW_MINIMUM, WINDOW_MAXIMUM,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "width %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
sy = args_strtonum(args, 'y', WINDOW_MINIMUM, WINDOW_MAXIMUM,
|
||||
&cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "height %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'L')) {
|
||||
if (sx >= adjust)
|
||||
sx -= adjust;
|
||||
} else if (args_has(args, 'R'))
|
||||
sx += adjust;
|
||||
else if (args_has(args, 'U')) {
|
||||
if (sy >= adjust)
|
||||
sy -= adjust;
|
||||
} else if (args_has(args, 'D'))
|
||||
sy += adjust;
|
||||
|
||||
if (args_has(args, 'A'))
|
||||
default_window_size(s, w, &sx, &sy, WINDOW_SIZE_LARGEST);
|
||||
else if (args_has(args, 'a'))
|
||||
default_window_size(s, w, &sx, &sy, WINDOW_SIZE_SMALLEST);
|
||||
|
||||
options_set_number(w->options, "window-size", WINDOW_SIZE_MANUAL);
|
||||
resize_window(w, sx, sy);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
.name = "respawn-pane",
|
||||
.alias = "respawnp",
|
||||
|
||||
.args = { "c:kt:", 0, -1 },
|
||||
.usage = "[-c start-directory] [-k] " CMD_TARGET_PANE_USAGE
|
||||
" [command]",
|
||||
.args = { "c:e:kt:", 0, -1 },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_PANE_USAGE " [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -48,53 +48,49 @@ static enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct spawn_context sc;
|
||||
struct session *s = item->target.s;
|
||||
struct environ *env;
|
||||
const char *path = NULL, *cp;
|
||||
char *cause, *cwd = NULL;
|
||||
u_int idx;
|
||||
struct environ_entry *envent;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
char *cause = NULL;
|
||||
const char *add;
|
||||
struct args_value *value;
|
||||
|
||||
if (!args_has(self->args, 'k') && wp->fd != -1) {
|
||||
if (window_pane_index(wp, &idx) != 0)
|
||||
fatalx("index not found");
|
||||
cmdq_error(item, "pane still active: %s:%d.%u",
|
||||
s->name, wl->idx, idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
|
||||
sc.wp0 = wp;
|
||||
sc.lc = NULL;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add);
|
||||
add = args_next_value(&value);
|
||||
}
|
||||
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
sc.flags = SPAWN_RESPAWN;
|
||||
if (args_has(args, 'k'))
|
||||
sc.flags |= SPAWN_KILL;
|
||||
|
||||
if ((cp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, cp, c, s, NULL, NULL);
|
||||
|
||||
env = environ_for_session(s, 0);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, cwd, env,
|
||||
s->tio, &cause) != 0) {
|
||||
if (spawn_pane(&sc, &cause) == NULL) {
|
||||
cmdq_error(item, "respawn pane failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
|
||||
wp->flags |= PANE_REDRAW;
|
||||
server_status_window(w);
|
||||
server_status_window(wp->window);
|
||||
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -34,9 +34,9 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.name = "respawn-window",
|
||||
.alias = "respawnw",
|
||||
|
||||
.args = { "c:kt:", 0, -1 },
|
||||
.usage = "[-c start-directory] [-k] " CMD_TARGET_WINDOW_USAGE
|
||||
" [command]",
|
||||
.args = { "c:e:kt:", 0, -1 },
|
||||
.usage = "[-k] [-c start-directory] [-e environment] "
|
||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
@@ -48,64 +48,44 @@ static enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct spawn_context sc;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct environ *env;
|
||||
const char *path = NULL, *cp;
|
||||
char *cause, *cwd = NULL;
|
||||
struct environ_entry *envent;
|
||||
char *cause = NULL;
|
||||
const char *add;
|
||||
struct args_value *value;
|
||||
|
||||
if (!args_has(self->args, 'k')) {
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->fd == -1)
|
||||
continue;
|
||||
cmdq_error(item, "window still active: %s:%d", s->name,
|
||||
wl->idx);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add);
|
||||
add = args_next_value(&value);
|
||||
}
|
||||
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
layout_free(w);
|
||||
window_destroy_panes(w);
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
sc.flags = SPAWN_RESPAWN;
|
||||
if (args_has(args, 'k'))
|
||||
sc.flags |= SPAWN_KILL;
|
||||
|
||||
if ((cp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, cp, c, s, NULL, NULL);
|
||||
|
||||
env = environ_for_session(s, 0);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, cwd, env,
|
||||
s->tio, &cause) != 0) {
|
||||
if (spawn_window(&sc, &cause) == NULL) {
|
||||
cmdq_error(item, "respawn window failed: %s", cause);
|
||||
free(cause);
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
server_destroy_pane(wp, 0);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
environ_free(env);
|
||||
free(cwd);
|
||||
|
||||
layout_init(w, wp);
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
window_set_active_pane(w, wp);
|
||||
|
||||
recalculate_sizes();
|
||||
server_redraw_window(w);
|
||||
server_redraw_window(wl->window);
|
||||
|
||||
environ_free(sc.environ);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
|
||||
wp = TAILQ_LAST(&w->panes, window_panes);
|
||||
window_set_active_pane(w, wp);
|
||||
window_set_active_pane(w, wp, 1);
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
server_redraw_window(w);
|
||||
} else {
|
||||
@@ -105,7 +105,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
window_set_active_pane(w, wp);
|
||||
window_set_active_pane(w, wp, 1);
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
@@ -57,9 +57,10 @@ struct cmd_run_shell_data {
|
||||
static void
|
||||
cmd_run_shell_print(struct job *job, const char *msg)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
||||
struct window_pane *wp = NULL;
|
||||
struct cmd_find_state fs;
|
||||
struct window_mode_entry *wme;
|
||||
|
||||
if (cdata->wp_id != -1)
|
||||
wp = window_pane_find_by_id(cdata->wp_id);
|
||||
@@ -75,10 +76,10 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wp, &window_copy_mode, NULL, NULL) == 0)
|
||||
window_copy_init_for_output(wp);
|
||||
if (wp->mode == &window_copy_mode)
|
||||
window_copy_add(wp, "%s", msg);
|
||||
wme = TAILQ_FIRST(&wp->modes);
|
||||
if (wme == NULL || wme->mode != &window_view_mode)
|
||||
window_pane_set_mode(wp, &window_view_mode, NULL, NULL);
|
||||
window_copy_add(wp, "%s", msg);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -90,14 +91,6 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *cwd;
|
||||
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
else if (s != NULL)
|
||||
cwd = s->cwd;
|
||||
else
|
||||
cwd = NULL;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
@@ -110,8 +103,12 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
|
||||
job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback,
|
||||
cmd_run_shell_free, cdata, 0);
|
||||
if (job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||
cmd_run_shell_callback, cmd_run_shell_free, cdata, 0) == NULL) {
|
||||
cmdq_error(item, "failed to run command: %s", cdata->cmd);
|
||||
free(cdata);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -121,22 +118,23 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
static void
|
||||
cmd_run_shell_callback(struct job *job)
|
||||
{
|
||||
struct cmd_run_shell_data *cdata = job->data;
|
||||
char *cmd = cdata->cmd, *msg, *line;
|
||||
struct cmd_run_shell_data *cdata = job_get_data(job);
|
||||
struct bufferevent *event = job_get_event(job);
|
||||
char *cmd = cdata->cmd, *msg = NULL, *line;
|
||||
size_t size;
|
||||
int retcode;
|
||||
int retcode, status;
|
||||
|
||||
do {
|
||||
if ((line = evbuffer_readline(job->event->input)) != NULL) {
|
||||
if ((line = evbuffer_readline(event->input)) != NULL) {
|
||||
cmd_run_shell_print(job, line);
|
||||
free(line);
|
||||
}
|
||||
} while (line != NULL);
|
||||
|
||||
size = EVBUFFER_LENGTH(job->event->input);
|
||||
size = EVBUFFER_LENGTH(event->input);
|
||||
if (size != 0) {
|
||||
line = xmalloc(size + 1);
|
||||
memcpy(line, EVBUFFER_DATA(job->event->input), size);
|
||||
memcpy(line, EVBUFFER_DATA(event->input), size);
|
||||
line[size] = '\0';
|
||||
|
||||
cmd_run_shell_print(job, line);
|
||||
@@ -144,12 +142,12 @@ cmd_run_shell_callback(struct job *job)
|
||||
free(line);
|
||||
}
|
||||
|
||||
msg = NULL;
|
||||
if (WIFEXITED(job->status)) {
|
||||
if ((retcode = WEXITSTATUS(job->status)) != 0)
|
||||
status = job_get_status(job);
|
||||
if (WIFEXITED(status)) {
|
||||
if ((retcode = WEXITSTATUS(status)) != 0)
|
||||
xasprintf(&msg, "'%s' returned %d", cmd, retcode);
|
||||
} else if (WIFSIGNALED(job->status)) {
|
||||
retcode = WTERMSIG(job->status);
|
||||
} else if (WIFSIGNALED(status)) {
|
||||
retcode = WTERMSIG(status);
|
||||
xasprintf(&msg, "'%s' terminated by signal %d", cmd, retcode);
|
||||
}
|
||||
if (msg != NULL)
|
||||
|
||||
@@ -59,11 +59,13 @@ static enum cmd_retval
|
||||
cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->client;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct paste_buffer *pb;
|
||||
const char *path, *bufname, *bufdata, *start, *end;
|
||||
const char *flags;
|
||||
char *msg, *file;
|
||||
const char *bufname, *bufdata, *start, *end, *flags;
|
||||
char *msg, *path, *file;
|
||||
size_t size, used, msglen, bufsize;
|
||||
FILE *f;
|
||||
|
||||
@@ -83,10 +85,12 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
bufdata = paste_buffer_data(pb, &bufsize);
|
||||
|
||||
if (self->entry == &cmd_show_buffer_entry)
|
||||
path = "-";
|
||||
path = xstrdup("-");
|
||||
else
|
||||
path = args->argv[0];
|
||||
path = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (strcmp(path, "-") == 0) {
|
||||
free(path);
|
||||
c = item->client;
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "can't write to stdout");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -100,7 +104,9 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(self->args, 'a'))
|
||||
flags = "ab";
|
||||
|
||||
file = server_client_get_path(c, path);
|
||||
file = server_client_get_path(item->client, path);
|
||||
free(path);
|
||||
|
||||
f = fopen(file, flags);
|
||||
if (f == NULL) {
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
|
||||
@@ -135,7 +135,9 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
changed:
|
||||
free(oldlayout);
|
||||
recalculate_sizes();
|
||||
server_redraw_window(w);
|
||||
notify_window("window-layout-changed", w);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -54,6 +55,31 @@ const struct cmd_entry cmd_last_pane_entry = {
|
||||
.exec = cmd_select_pane_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_select_pane_redraw(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
/*
|
||||
* Redraw entire window if it is bigger than the client (the
|
||||
* offset may change), otherwise just draw borders.
|
||||
*/
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == NULL || (c->flags & CLIENT_CONTROL))
|
||||
continue;
|
||||
if (c->session->curw->window == w && tty_window_bigger(&c->tty))
|
||||
server_redraw_client(c);
|
||||
else {
|
||||
if (c->session->curw->window == w)
|
||||
c->flags |= CLIENT_REDRAWBORDERS;
|
||||
if (session_has(c->session, w))
|
||||
c->flags |= CLIENT_REDRAWSTATUS;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -64,11 +90,17 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->target.s;
|
||||
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
||||
struct style *sy = &wp->style;
|
||||
char *pane_title;
|
||||
const char *style;
|
||||
|
||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
lastwp = w->last;
|
||||
if (lastwp == NULL && window_count_panes(w) == 2) {
|
||||
lastwp = TAILQ_PREV(w->active, window_panes, entry);
|
||||
if (lastwp == NULL)
|
||||
lastwp = TAILQ_NEXT(w->active, entry);
|
||||
}
|
||||
if (lastwp == NULL) {
|
||||
cmdq_error(item, "no last pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -80,10 +112,9 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else {
|
||||
server_unzoom_window(w);
|
||||
window_redraw_active_switch(w, lastwp);
|
||||
if (window_set_active_pane(w, lastwp)) {
|
||||
if (window_set_active_pane(w, lastwp, 1)) {
|
||||
cmd_find_from_winlink(current, wl, 0);
|
||||
server_status_window(w);
|
||||
server_redraw_window_borders(w);
|
||||
cmd_select_pane_redraw(w);
|
||||
}
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -112,17 +143,16 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
|
||||
if (args_has(args, 'P')) {
|
||||
style = args_get(args, 'P');
|
||||
if (style_parse(&grid_default_cell, &wp->colgc,
|
||||
style) == -1) {
|
||||
if ((style = args_get(args, 'P')) != NULL) {
|
||||
style_set(sy, &grid_default_cell);
|
||||
if (style_parse(sy, &grid_default_cell, style) == -1) {
|
||||
cmdq_error(item, "bad style: %s", style);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
wp->flags |= PANE_REDRAW;
|
||||
}
|
||||
if (args_has(self->args, 'g'))
|
||||
cmdq_print(item, "%s", style_tostring(&wp->colgc));
|
||||
cmdq_print(item, "%s", style_tostring(sy));
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -157,21 +187,17 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
screen_set_title(&wp->base, pane_title);
|
||||
server_status_window(wp->window);
|
||||
free(pane_title);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (wp == w->active)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
server_unzoom_window(wp->window);
|
||||
if (!window_pane_visible(wp)) {
|
||||
cmdq_error(item, "pane not visible");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
window_redraw_active_switch(w, wp);
|
||||
if (window_set_active_pane(w, wp)) {
|
||||
if (window_set_active_pane(w, wp, 1)) {
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
hooks_insert(s->hooks, item, current, "after-select-pane");
|
||||
server_status_window(w);
|
||||
server_redraw_window_borders(w);
|
||||
cmdq_insert_hook(s, item, current, "after-select-pane");
|
||||
cmd_select_pane_redraw(w);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -119,7 +119,7 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
hooks_insert(s->hooks, item, current, "after-select-window");
|
||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
||||
} else {
|
||||
/*
|
||||
* If -T and select-window is invoked on same window as
|
||||
@@ -137,7 +137,7 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
}
|
||||
hooks_insert(s->hooks, item, current, "after-select-window");
|
||||
cmdq_insert_hook(s, item, current, "after-select-window");
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
|
||||
@@ -55,45 +55,49 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
||||
.exec = cmd_send_keys_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_send_keys_inject(struct client *c, struct cmdq_item *item, key_code key)
|
||||
static struct cmdq_item *
|
||||
cmd_send_keys_inject(struct client *c, struct cmd_find_state *fs,
|
||||
struct cmdq_item *item, key_code key)
|
||||
{
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct session *s = item->target.s;
|
||||
struct key_table *table;
|
||||
struct key_binding *bd, bd_find;
|
||||
struct window_mode_entry *wme;
|
||||
struct key_table *table;
|
||||
struct key_binding *bd;
|
||||
|
||||
if (wp->mode == NULL || wp->mode->key_table == NULL) {
|
||||
if (options_get_number(wp->window->options, "xterm-keys"))
|
||||
wme = TAILQ_FIRST(&fs->wp->modes);
|
||||
if (wme == NULL || wme->mode->key_table == NULL) {
|
||||
if (options_get_number(fs->wp->window->options, "xterm-keys"))
|
||||
key |= KEYC_XTERM;
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
return;
|
||||
window_pane_key(fs->wp, item->client, fs->s, fs->wl, key, NULL);
|
||||
return (item);
|
||||
}
|
||||
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
|
||||
table = key_bindings_get_table(wme->mode->key_table(wme), 1);
|
||||
|
||||
bd_find.key = (key & ~KEYC_XTERM);
|
||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
||||
bd = key_bindings_get(table, key & ~KEYC_XTERM);
|
||||
if (bd != NULL) {
|
||||
table->references++;
|
||||
key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
||||
item = key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
||||
key_bindings_unref_table(table);
|
||||
}
|
||||
return (item);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct session *s = item->target.s;
|
||||
struct mouse_event *m = &item->shared->mouse;
|
||||
struct utf8_data *ud, *uc;
|
||||
wchar_t wc;
|
||||
int i, literal;
|
||||
key_code key;
|
||||
u_int np = 1;
|
||||
char *cause = NULL;
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct mouse_event *m = &item->shared->mouse;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
|
||||
struct utf8_data *ud, *uc;
|
||||
wchar_t wc;
|
||||
int i, literal;
|
||||
key_code key;
|
||||
u_int np = 1;
|
||||
char *cause = NULL;
|
||||
|
||||
if (args_has(args, 'N')) {
|
||||
np = args_strtonum(args, 'N', 1, UINT_MAX, &cause);
|
||||
@@ -102,19 +106,23 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(args, 'X') || args->argc == 0)
|
||||
wp->modeprefix = np;
|
||||
if (wme != NULL && (args_has(args, 'X') || args->argc == 0)) {
|
||||
if (wme == NULL || wme->mode->command == NULL) {
|
||||
cmdq_error(item, "not in a mode");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
wme->prefix = np;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'X')) {
|
||||
if (wp->mode == NULL || wp->mode->command == NULL) {
|
||||
if (wme == NULL || wme->mode->command == NULL) {
|
||||
cmdq_error(item, "not in a mode");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!m->valid)
|
||||
wp->mode->command(wp, c, s, args, NULL);
|
||||
else
|
||||
wp->mode->command(wp, c, s, args, m);
|
||||
m = NULL;
|
||||
wme->mode->command(wme, c, s, wl, args, m);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -124,7 +132,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no mouse target");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
window_pane_key(wp, NULL, s, m->key, m);
|
||||
window_pane_key(wp, item->client, s, wl, m->key, m);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -133,7 +141,7 @@ 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(c, item, key);
|
||||
cmd_send_keys_inject(c, fs, item, key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -147,9 +155,10 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
literal = args_has(args, 'l');
|
||||
if (!literal) {
|
||||
key = key_string_lookup_string(args->argv[i]);
|
||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN)
|
||||
cmd_send_keys_inject(c, item, key);
|
||||
else
|
||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN) {
|
||||
item = cmd_send_keys_inject(c, fs, item,
|
||||
key);
|
||||
} else
|
||||
literal = 1;
|
||||
}
|
||||
if (literal) {
|
||||
@@ -157,7 +166,8 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
for (uc = ud; uc->size != 0; uc++) {
|
||||
if (utf8_combine(uc, &wc) != UTF8_DONE)
|
||||
continue;
|
||||
cmd_send_keys_inject(c, item, wc);
|
||||
item = cmd_send_keys_inject(c, fs, item,
|
||||
wc);
|
||||
}
|
||||
free(ud);
|
||||
}
|
||||
|
||||
130
cmd-set-hook.c
130
cmd-set-hook.c
@@ -1,130 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012 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"
|
||||
|
||||
/*
|
||||
* Set or show global or session hooks.
|
||||
*/
|
||||
|
||||
static enum cmd_retval cmd_set_hook_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_set_hook_entry = {
|
||||
.name = "set-hook",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "gt:u", 1, 2 },
|
||||
.usage = "[-gu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_show_hooks_entry = {
|
||||
.name = "show-hooks",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "gt:", 0, 1 },
|
||||
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_list *cmdlist;
|
||||
struct hooks *hooks;
|
||||
struct hook *hook;
|
||||
char *cause, *tmp;
|
||||
const char *name, *cmd, *target;
|
||||
|
||||
if (args_has(args, 'g'))
|
||||
hooks = global_hooks;
|
||||
else {
|
||||
if (item->target.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
hooks = item->target.s->hooks;
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_show_hooks_entry) {
|
||||
hook = hooks_first(hooks);
|
||||
while (hook != NULL) {
|
||||
tmp = cmd_list_print(hook->cmdlist);
|
||||
cmdq_print(item, "%s -> %s", hook->name, tmp);
|
||||
free(tmp);
|
||||
|
||||
hook = hooks_next(hook);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
name = args->argv[0];
|
||||
if (*name == '\0') {
|
||||
cmdq_error(item, "invalid hook name");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args->argc < 2)
|
||||
cmd = NULL;
|
||||
else
|
||||
cmd = args->argv[1];
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
if (cmd != NULL) {
|
||||
cmdq_error(item, "command passed to unset hook: %s",
|
||||
name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
hooks_remove(hooks, name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (cmd == NULL) {
|
||||
cmdq_error(item, "no command to set hook: %s", name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
}
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
hooks_add(hooks, name, cmdlist);
|
||||
cmd_list_free(cmdlist);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -64,6 +65,19 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
||||
.exec = cmd_set_option_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_set_hook_entry = {
|
||||
.name = "set-hook",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "agRt:u", 1, 2 },
|
||||
.usage = "[-agRu] " CMD_TARGET_SESSION_USAGE " hook [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_option_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -80,11 +94,17 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
char *name, *argument, *value = NULL, *cause;
|
||||
const char *target;
|
||||
int window, idx, already, error, ambiguous;
|
||||
struct style *sy;
|
||||
|
||||
/* Expand argument. */
|
||||
c = cmd_find_client(item, NULL, 1);
|
||||
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
|
||||
if (self->entry == &cmd_set_hook_entry && args_has(args, 'R')) {
|
||||
notify_hook(item, argument);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Parse option name and index. */
|
||||
name = options_match(argument, &idx, &ambiguous);
|
||||
if (name == NULL) {
|
||||
@@ -162,11 +182,9 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
parent = options_get(oo, name);
|
||||
|
||||
/* Check that array options and indexes match up. */
|
||||
if (idx != -1) {
|
||||
if (*name == '@' || options_array_size(parent, NULL) == -1) {
|
||||
cmdq_error(item, "not an array: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
if (idx != -1 && (*name == '@' || !options_isarray(parent))) {
|
||||
cmdq_error(item, "not an array: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* With -o, check this option is not already set. */
|
||||
@@ -200,15 +218,18 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
options_default(oo, options_table_entry(o));
|
||||
else
|
||||
options_remove(o);
|
||||
} else
|
||||
options_array_set(o, idx, NULL, 0);
|
||||
} else if (options_array_set(o, idx, NULL, 0, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
goto fail;
|
||||
}
|
||||
} else if (*name == '@') {
|
||||
if (value == NULL) {
|
||||
cmdq_error(item, "empty value");
|
||||
goto fail;
|
||||
}
|
||||
options_set_string(oo, name, append, "%s", value);
|
||||
} else if (idx == -1 && options_array_size(parent, NULL) == -1) {
|
||||
} else if (idx == -1 && !options_isarray(parent)) {
|
||||
error = cmd_set_option_set(self, item, oo, parent, value);
|
||||
if (error != 0)
|
||||
goto fail;
|
||||
@@ -222,9 +243,15 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (idx == -1) {
|
||||
if (!append)
|
||||
options_array_clear(o);
|
||||
options_array_assign(o, value);
|
||||
} else if (options_array_set(o, idx, value, append) != 0) {
|
||||
cmdq_error(item, "invalid index: %s", argument);
|
||||
if (options_array_assign(o, value, &cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
goto fail;
|
||||
}
|
||||
} else if (options_array_set(o, idx, value, append,
|
||||
&cause) != 0) {
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -248,6 +275,16 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
tty_keys_build(&loop->tty);
|
||||
}
|
||||
}
|
||||
if (strcmp(name, "status-fg") == 0 || strcmp(name, "status-bg") == 0) {
|
||||
sy = options_get_style(oo, "status-style");
|
||||
sy->gc.fg = options_get_number(oo, "status-fg");
|
||||
sy->gc.bg = options_get_number(oo, "status-bg");
|
||||
}
|
||||
if (strcmp(name, "status-style") == 0) {
|
||||
sy = options_get_style(oo, "status-style");
|
||||
options_set_number(oo, "status-fg", sy->gc.fg);
|
||||
options_set_number(oo, "status-bg", sy->gc.bg);
|
||||
}
|
||||
if (strcmp(name, "status") == 0 ||
|
||||
strcmp(name, "status-interval") == 0)
|
||||
status_timer_start_all();
|
||||
@@ -260,10 +297,10 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
if (strcmp(name, "pane-border-status") == 0) {
|
||||
RB_FOREACH(w, windows, &windows)
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
}
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
status_update_saved(s);
|
||||
status_update_cache(s);
|
||||
|
||||
/*
|
||||
* Update sizes and redraw. May not always be necessary but do it
|
||||
@@ -297,7 +334,8 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
int append = args_has(args, 'a');
|
||||
struct options_entry *o;
|
||||
long long number;
|
||||
const char *errstr;
|
||||
const char *errstr, *new;
|
||||
char *old;
|
||||
key_code key;
|
||||
|
||||
oe = options_table_entry(parent);
|
||||
@@ -310,7 +348,16 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_STRING:
|
||||
old = xstrdup(options_get_string(oo, oe->name));
|
||||
options_set_string(oo, oe->name, append, "%s", value);
|
||||
new = options_get_string(oo, oe->name);
|
||||
if (oe->pattern != NULL && fnmatch(oe->pattern, new, 0) != 0) {
|
||||
options_set_string(oo, oe->name, 0, "%s", old);
|
||||
free(old);
|
||||
cmdq_error(item, "value is invalid: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
free(old);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_NUMBER:
|
||||
number = strtonum(value, oe->minimum, oe->maximum, &errstr);
|
||||
@@ -333,16 +380,7 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
cmdq_error(item, "bad colour: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
o = options_set_number(oo, oe->name, number);
|
||||
options_style_update_new(oo, o);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_ATTRIBUTES:
|
||||
if ((number = attributes_fromstring(value)) == -1) {
|
||||
cmdq_error(item, "bad attributes: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
o = options_set_number(oo, oe->name, number);
|
||||
options_style_update_new(oo, o);
|
||||
options_set_number(oo, oe->name, number);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
return (cmd_set_option_flag(item, oe, oo, value));
|
||||
@@ -354,9 +392,8 @@ cmd_set_option_set(struct cmd *self, struct cmdq_item *item, struct options *oo,
|
||||
cmdq_error(item, "bad style: %s", value);
|
||||
return (-1);
|
||||
}
|
||||
options_style_update_old(oo, o);
|
||||
return (0);
|
||||
case OPTIONS_TABLE_ARRAY:
|
||||
case OPTIONS_TABLE_COMMAND:
|
||||
break;
|
||||
}
|
||||
return (-1);
|
||||
|
||||
@@ -43,7 +43,6 @@ const struct cmd_entry cmd_show_messages_entry = {
|
||||
};
|
||||
|
||||
static int cmd_show_messages_terminals(struct cmdq_item *, int);
|
||||
static int cmd_show_messages_jobs(struct cmdq_item *, int);
|
||||
|
||||
static int
|
||||
cmd_show_messages_terminals(struct cmdq_item *item, int blank)
|
||||
@@ -66,25 +65,6 @@ cmd_show_messages_terminals(struct cmdq_item *item, int blank)
|
||||
return (n != 0);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_show_messages_jobs(struct cmdq_item *item, int blank)
|
||||
{
|
||||
struct job *job;
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if (blank) {
|
||||
cmdq_print(item, "%s", "");
|
||||
blank = 0;
|
||||
}
|
||||
cmdq_print(item, "Job %u: %s [fd=%d, pid=%ld, status=%d]",
|
||||
n, job->cmd, job->fd, (long)job->pid, job->status);
|
||||
n++;
|
||||
}
|
||||
return (n != 0);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
@@ -103,7 +83,7 @@ cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
||||
done = 1;
|
||||
}
|
||||
if (args_has(args, 'J')) {
|
||||
cmd_show_messages_jobs(item, blank);
|
||||
job_print_summary(item, blank);
|
||||
done = 1;
|
||||
}
|
||||
if (done)
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
|
||||
static enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static enum cmd_retval cmd_show_options_one(struct cmd *, struct cmdq_item *,
|
||||
struct options *);
|
||||
static void cmd_show_options_print(struct cmd *, struct cmdq_item *,
|
||||
struct options_entry *, int);
|
||||
static enum cmd_retval cmd_show_options_all(struct cmd *, struct cmdq_item *,
|
||||
struct options *);
|
||||
|
||||
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_show_options_entry = {
|
||||
.name = "show-options",
|
||||
.alias = "show",
|
||||
|
||||
.args = { "gqst:vw", 0, 1 },
|
||||
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
|
||||
.args = { "gHqst:vw", 0, 1 },
|
||||
.usage = "[-gHqsvw] [-t target-session|target-window] [option]",
|
||||
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
|
||||
@@ -60,128 +60,196 @@ const struct cmd_entry cmd_show_window_options_entry = {
|
||||
.exec = cmd_show_options_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_show_hooks_entry = {
|
||||
.name = "show-hooks",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "gt:", 0, 1 },
|
||||
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_options_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_options_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct options *oo;
|
||||
enum options_table_scope scope;
|
||||
char *cause;
|
||||
int window;
|
||||
char *argument, *name = NULL, *cause;
|
||||
const char *target;
|
||||
int window, idx, ambiguous;
|
||||
struct options_entry *o;
|
||||
|
||||
window = (self->entry == &cmd_show_window_options_entry);
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
if (args->argc == 0) {
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (cmd_show_options_all(self, item, oo));
|
||||
}
|
||||
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
|
||||
name = options_match(argument, &idx, &ambiguous);
|
||||
if (name == NULL) {
|
||||
if (args_has(args, 'q'))
|
||||
goto fail;
|
||||
if (ambiguous)
|
||||
cmdq_error(item, "ambiguous option: %s", argument);
|
||||
else
|
||||
cmdq_error(item, "invalid option: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
if (*name == '@')
|
||||
scope = options_scope_from_flags(args, window, fs, &oo, &cause);
|
||||
else {
|
||||
if (options_get_only(global_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_SERVER;
|
||||
else if (options_get_only(global_s_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_SESSION;
|
||||
else if (options_get_only(global_w_options, name) != NULL)
|
||||
scope = OPTIONS_TABLE_WINDOW;
|
||||
else {
|
||||
scope = OPTIONS_TABLE_NONE;
|
||||
xasprintf(&cause, "unknown option: %s", argument);
|
||||
}
|
||||
if (scope == OPTIONS_TABLE_SERVER)
|
||||
oo = global_options;
|
||||
else if (scope == OPTIONS_TABLE_SESSION) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_s_options;
|
||||
else if (s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(item, "no such session: %s",
|
||||
target);
|
||||
} else
|
||||
cmdq_error(item, "no current session");
|
||||
goto fail;
|
||||
} else
|
||||
oo = s->options;
|
||||
} else if (scope == OPTIONS_TABLE_WINDOW) {
|
||||
if (args_has(self->args, 'g'))
|
||||
oo = global_w_options;
|
||||
else if (wl == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL) {
|
||||
cmdq_error(item, "no such window: %s",
|
||||
target);
|
||||
} else
|
||||
cmdq_error(item, "no current window");
|
||||
goto fail;
|
||||
} else
|
||||
oo = wl->window->options;
|
||||
}
|
||||
}
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
if (args_has(args, 'q'))
|
||||
goto fail;
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
o = options_get_only(oo, name);
|
||||
if (o != NULL)
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
|
||||
if (args->argc == 0)
|
||||
return (cmd_show_options_all(self, item, oo));
|
||||
else
|
||||
return (cmd_show_options_one(self, item, oo));
|
||||
free(name);
|
||||
free(argument);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(name);
|
||||
free(argument);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_show_options_print(struct cmd *self, struct cmdq_item *item,
|
||||
struct options_entry *o, int idx)
|
||||
{
|
||||
const char *name;
|
||||
const char *value;
|
||||
char *tmp, *escaped;
|
||||
u_int size, i;
|
||||
struct options_array_item *a;
|
||||
const char *name = options_name(o);
|
||||
char *value, *tmp = NULL, *escaped;
|
||||
|
||||
if (idx != -1) {
|
||||
xasprintf(&tmp, "%s[%d]", options_name(o), idx);
|
||||
xasprintf(&tmp, "%s[%d]", name, idx);
|
||||
name = tmp;
|
||||
} else {
|
||||
if (options_array_size(o, &size) != -1) {
|
||||
for (i = 0; i < size; i++) {
|
||||
if (options_array_get(o, i) == NULL)
|
||||
continue;
|
||||
cmd_show_options_print(self, item, o, i);
|
||||
if (options_isarray(o)) {
|
||||
a = options_array_first(o);
|
||||
if (a == NULL) {
|
||||
if (!args_has(self->args, 'v'))
|
||||
cmdq_print(item, "%s", name);
|
||||
return;
|
||||
}
|
||||
while (a != NULL) {
|
||||
idx = options_array_item_index(a);
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
a = options_array_next(a);
|
||||
}
|
||||
return;
|
||||
}
|
||||
tmp = NULL;
|
||||
name = options_name(o);
|
||||
}
|
||||
|
||||
value = options_tostring(o, idx, 0);
|
||||
if (args_has(self->args, 'v'))
|
||||
cmdq_print(item, "%s", value);
|
||||
else if (options_isstring(o)) {
|
||||
utf8_stravis(&escaped, value, VIS_OCTAL|VIS_TAB|VIS_NL|VIS_DQ);
|
||||
cmdq_print(item, "%s \"%s\"", name, escaped);
|
||||
escaped = args_escape(value);
|
||||
cmdq_print(item, "%s %s", name, escaped);
|
||||
free(escaped);
|
||||
} else
|
||||
cmdq_print(item, "%s %s", name, value);
|
||||
free(value);
|
||||
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_options_one(struct cmd *self, struct cmdq_item *item,
|
||||
struct options *oo)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct options_entry *o;
|
||||
int idx, ambiguous;
|
||||
char *name;
|
||||
|
||||
name = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
o = options_match_get(oo, name, &idx, 1, &ambiguous);
|
||||
if (o == NULL) {
|
||||
if (args_has(args, 'q')) {
|
||||
free(name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (ambiguous) {
|
||||
cmdq_error(item, "ambiguous option: %s", name);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (*name != '@' &&
|
||||
options_match_get(oo, name, &idx, 0, &ambiguous) != NULL) {
|
||||
free(name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
cmdq_error(item, "unknown option: %s", name);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
free(name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_show_options_all(struct cmd *self, struct cmdq_item *item,
|
||||
struct options *oo)
|
||||
{
|
||||
struct options_entry *o;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
u_int idx;
|
||||
const struct options_table_entry *oe;
|
||||
u_int size, idx;
|
||||
|
||||
o = options_first(oo);
|
||||
while (o != NULL) {
|
||||
oe = options_table_entry(o);
|
||||
if (oe != NULL && oe->style != NULL) {
|
||||
if ((self->entry != &cmd_show_hooks_entry &&
|
||||
!args_has(self->args, 'H') &&
|
||||
oe != NULL &&
|
||||
(oe->flags & OPTIONS_TABLE_IS_HOOK)) ||
|
||||
(self->entry == &cmd_show_hooks_entry &&
|
||||
(oe == NULL ||
|
||||
(~oe->flags & OPTIONS_TABLE_IS_HOOK)))) {
|
||||
o = options_next(o);
|
||||
continue;
|
||||
}
|
||||
if (options_array_size(o, &size) == -1)
|
||||
if (!options_isarray(o))
|
||||
cmd_show_options_print(self, item, o, -1);
|
||||
else {
|
||||
for (idx = 0; idx < size; idx++) {
|
||||
if (options_array_get(o, idx) == NULL)
|
||||
continue;
|
||||
else if ((a = options_array_first(o)) == NULL) {
|
||||
if (!args_has(self->args, 'v'))
|
||||
cmdq_print(item, "%s", options_name(o));
|
||||
} else {
|
||||
while (a != NULL) {
|
||||
idx = options_array_item_index(a);
|
||||
cmd_show_options_print(self, item, o, idx);
|
||||
a = options_array_next(a);
|
||||
}
|
||||
}
|
||||
o = options_next(o);
|
||||
|
||||
@@ -37,8 +37,8 @@ const struct cmd_entry cmd_source_file_entry = {
|
||||
.name = "source-file",
|
||||
.alias = "source",
|
||||
|
||||
.args = { "q", 1, 1 },
|
||||
.usage = "[-q] path",
|
||||
.args = { "nq", 1, -1 },
|
||||
.usage = "[-nq] path ...",
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_source_file_exec
|
||||
@@ -48,45 +48,60 @@ static enum cmd_retval
|
||||
cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
int quiet = args_has(args, 'q');
|
||||
int flags = 0;
|
||||
struct client *c = item->client;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmdq_item *new_item, *after;
|
||||
enum cmd_retval retval;
|
||||
char *pattern, *tmp;
|
||||
const char *path = args->argv[0];
|
||||
char *pattern, *cwd;
|
||||
const char *path, *error;
|
||||
glob_t g;
|
||||
u_int i;
|
||||
int i;
|
||||
u_int j;
|
||||
|
||||
if (*path == '/')
|
||||
pattern = xstrdup(path);
|
||||
else {
|
||||
utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB);
|
||||
xasprintf(&pattern, "%s/%s", tmp, path);
|
||||
free(tmp);
|
||||
}
|
||||
log_debug("%s: %s", __func__, pattern);
|
||||
if (args_has(args, 'q'))
|
||||
flags |= CMD_PARSE_QUIET;
|
||||
if (args_has(args, 'n'))
|
||||
flags |= CMD_PARSE_PARSEONLY;
|
||||
utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||
|
||||
retval = CMD_RETURN_NORMAL;
|
||||
if (glob(pattern, 0, NULL, &g) != 0) {
|
||||
if (!quiet || errno != ENOENT) {
|
||||
cmdq_error(item, "%s: %s", path, strerror(errno));
|
||||
retval = CMD_RETURN_ERROR;
|
||||
for (i = 0; i < args->argc; i++) {
|
||||
path = args->argv[i];
|
||||
if (*path == '/')
|
||||
pattern = xstrdup(path);
|
||||
else
|
||||
xasprintf(&pattern, "%s/%s", cwd, path);
|
||||
log_debug("%s: %s", __func__, pattern);
|
||||
|
||||
if (glob(pattern, 0, NULL, &g) != 0) {
|
||||
error = strerror(errno);
|
||||
if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) {
|
||||
cmdq_error(item, "%s: %s", path, error);
|
||||
retval = CMD_RETURN_ERROR;
|
||||
}
|
||||
free(pattern);
|
||||
continue;
|
||||
}
|
||||
free(pattern);
|
||||
return (retval);
|
||||
}
|
||||
free(pattern);
|
||||
|
||||
for (i = 0; i < (u_int)g.gl_pathc; i++) {
|
||||
if (load_cfg(g.gl_pathv[i], c, item, quiet) < 0)
|
||||
retval = CMD_RETURN_ERROR;
|
||||
after = item;
|
||||
for (j = 0; j < g.gl_pathc; j++) {
|
||||
path = g.gl_pathv[j];
|
||||
if (load_cfg(path, c, after, flags, &new_item) < 0)
|
||||
retval = CMD_RETURN_ERROR;
|
||||
else if (new_item != NULL)
|
||||
after = new_item;
|
||||
}
|
||||
globfree(&g);
|
||||
}
|
||||
if (cfg_finished) {
|
||||
if (retval == CMD_RETURN_ERROR && c->session == NULL)
|
||||
c->retval = 1;
|
||||
new_item = cmdq_get_callback(cmd_source_file_done, NULL);
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
globfree(&g);
|
||||
free(cwd);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,10 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
.name = "split-window",
|
||||
.alias = "splitw",
|
||||
|
||||
.args = { "bc:dfF:l:hp:Pt:v", 0, -1 },
|
||||
.usage = "[-bdfhvP] [-c start-directory] [-F format] "
|
||||
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
.args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 },
|
||||
.usage = "[-bdefhIPv] [-c start-directory] [-e environment] "
|
||||
"[-F format] [-p percentage|-l size] " CMD_TARGET_PANE_USAGE
|
||||
" [command]",
|
||||
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
@@ -52,113 +53,106 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct args *args = self->args;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct spawn_context sc;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = item->target.wp, *new_wp = NULL;
|
||||
struct environ *env;
|
||||
const char *cmd, *path, *shell, *template, *tmp;
|
||||
char **argv, *cause, *new_cause, *cp, *cwd;
|
||||
u_int hlimit;
|
||||
int argc, size, percentage, before;
|
||||
struct window_pane *wp = item->target.wp, *new_wp;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
struct environ_entry *envent;
|
||||
struct cmd_find_state fs;
|
||||
struct cmd_find_state fs;
|
||||
int size, percentage, flags, input;
|
||||
const char *template, *add;
|
||||
char *cause, *cp;
|
||||
struct args_value *value;
|
||||
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args->argc == 0) {
|
||||
cmd = options_get_string(s->options, "default-command");
|
||||
if (cmd != NULL && *cmd != '\0') {
|
||||
argc = 1;
|
||||
argv = (char **)&cmd;
|
||||
} else {
|
||||
argc = 0;
|
||||
argv = NULL;
|
||||
}
|
||||
} else {
|
||||
argc = args->argc;
|
||||
argv = args->argv;
|
||||
}
|
||||
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||
else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = xstrdup(item->client->cwd);
|
||||
else
|
||||
cwd = xstrdup(s->cwd);
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
before = args_has(args, 'b');
|
||||
|
||||
size = -1;
|
||||
else
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'l')) {
|
||||
size = args_strtonum(args, 'l', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
xasprintf(&new_cause, "size %s", cause);
|
||||
cmdq_error(item, "create pane failed: -l %s", cause);
|
||||
free(cause);
|
||||
cause = new_cause;
|
||||
goto error;
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else if (args_has(args, 'p')) {
|
||||
percentage = args_strtonum(args, 'p', 0, INT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
xasprintf(&new_cause, "percentage %s", cause);
|
||||
cmdq_error(item, "create pane failed: -p %s", cause);
|
||||
free(cause);
|
||||
cause = new_cause;
|
||||
goto error;
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
size = (wp->sy * percentage) / 100;
|
||||
else
|
||||
size = (wp->sx * percentage) / 100;
|
||||
}
|
||||
hlimit = options_get_number(s->options, "history-limit");
|
||||
|
||||
shell = options_get_string(s->options, "default-shell");
|
||||
if (*shell == '\0' || areshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
lc = layout_split_pane(wp, type, size, before, args_has(args, 'f'));
|
||||
if (lc == NULL) {
|
||||
cause = xstrdup("pane too small");
|
||||
goto error;
|
||||
}
|
||||
new_wp = window_add_pane(w, wp, before, args_has(args, 'f'), hlimit);
|
||||
layout_make_leaf(lc, new_wp);
|
||||
|
||||
path = NULL;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
envent = environ_find(s->environ, "PATH");
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s, 0);
|
||||
if (window_pane_spawn(new_wp, argc, argv, path, shell, cwd, env,
|
||||
s->tio, &cause) != 0) {
|
||||
environ_free(env);
|
||||
goto error;
|
||||
}
|
||||
environ_free(env);
|
||||
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
server_redraw_window(w);
|
||||
|
||||
if (!args_has(args, 'd')) {
|
||||
window_set_active_pane(w, new_wp);
|
||||
session_select(s, wl->idx);
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
} else
|
||||
server_status_session(s);
|
||||
size = -1;
|
||||
|
||||
server_unzoom_window(wp->window);
|
||||
input = (args_has(args, 'I') && args->argc == 0);
|
||||
|
||||
flags = 0;
|
||||
if (args_has(args, 'b'))
|
||||
flags |= SPAWN_BEFORE;
|
||||
if (args_has(args, 'f'))
|
||||
flags |= SPAWN_FULLSIZE;
|
||||
if (input || (args->argc == 1 && *args->argv[0] == '\0'))
|
||||
flags |= SPAWN_EMPTY;
|
||||
|
||||
lc = layout_split_pane(wp, type, size, flags);
|
||||
if (lc == NULL) {
|
||||
cmdq_error(item, "no space for new pane");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
memset(&sc, 0, sizeof sc);
|
||||
sc.item = item;
|
||||
sc.s = s;
|
||||
sc.wl = wl;
|
||||
|
||||
sc.wp0 = wp;
|
||||
sc.lc = lc;
|
||||
|
||||
sc.name = NULL;
|
||||
sc.argc = args->argc;
|
||||
sc.argv = args->argv;
|
||||
sc.environ = environ_create();
|
||||
|
||||
add = args_first_value(args, 'e', &value);
|
||||
while (add != NULL) {
|
||||
environ_put(sc.environ, add);
|
||||
add = args_next_value(&value);
|
||||
}
|
||||
|
||||
sc.idx = -1;
|
||||
sc.cwd = args_get(args, 'c');
|
||||
|
||||
sc.flags = flags;
|
||||
if (args_has(args, 'd'))
|
||||
sc.flags |= SPAWN_DETACHED;
|
||||
|
||||
if ((new_wp = spawn_pane(&sc, &cause)) == NULL) {
|
||||
layout_close_pane(new_wp);
|
||||
cmdq_error(item, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (input && window_pane_start_input(new_wp, item, &cause) != 0) {
|
||||
layout_close_pane(new_wp);
|
||||
window_remove_pane(wp->window, new_wp);
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (!args_has(args, 'd'))
|
||||
cmd_find_from_winlink_pane(current, wl, new_wp, 0);
|
||||
server_redraw_window(wp->window);
|
||||
server_status_session(s);
|
||||
|
||||
if (args_has(args, 'P')) {
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
@@ -167,22 +161,12 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_print(item, "%s", cp);
|
||||
free(cp);
|
||||
}
|
||||
notify_window("window-layout-changed", w);
|
||||
|
||||
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
||||
cmdq_insert_hook(s, item, &fs, "after-split-window");
|
||||
|
||||
free(cwd);
|
||||
environ_free(sc.environ);
|
||||
if (input)
|
||||
return (CMD_RETURN_WAIT);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
if (new_wp != NULL) {
|
||||
layout_close_pane(new_wp);
|
||||
window_remove_pane(w, new_wp);
|
||||
}
|
||||
cmdq_error(item, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
|
||||
free(cwd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
363
cmd-string.c
363
cmd-string.c
@@ -1,363 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 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 <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Parse a command from a string.
|
||||
*/
|
||||
|
||||
static int cmd_string_getc(const char *, size_t *);
|
||||
static void cmd_string_ungetc(size_t *);
|
||||
static void cmd_string_copy(char **, char *, size_t *);
|
||||
static char *cmd_string_string(const char *, size_t *, char, int);
|
||||
static char *cmd_string_variable(const char *, size_t *);
|
||||
static char *cmd_string_expand_tilde(const char *, size_t *);
|
||||
|
||||
static int
|
||||
cmd_string_getc(const char *s, size_t *p)
|
||||
{
|
||||
const u_char *ucs = s;
|
||||
|
||||
if (ucs[*p] == '\0')
|
||||
return (EOF);
|
||||
return (ucs[(*p)++]);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_string_ungetc(size_t *p)
|
||||
{
|
||||
(*p)--;
|
||||
}
|
||||
|
||||
int
|
||||
cmd_string_split(const char *s, int *rargc, char ***rargv)
|
||||
{
|
||||
size_t p = 0;
|
||||
int ch, argc = 0, append = 0;
|
||||
char **argv = NULL, *buf = NULL, *t;
|
||||
const char *whitespace, *equals;
|
||||
size_t len = 0;
|
||||
|
||||
for (;;) {
|
||||
ch = cmd_string_getc(s, &p);
|
||||
switch (ch) {
|
||||
case '\'':
|
||||
if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '"':
|
||||
if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '$':
|
||||
if ((t = cmd_string_variable(s, &p)) == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
case '#':
|
||||
/* Comment: discard rest of line. */
|
||||
while ((ch = cmd_string_getc(s, &p)) != EOF)
|
||||
;
|
||||
/* FALLTHROUGH */
|
||||
case EOF:
|
||||
case ' ':
|
||||
case '\t':
|
||||
if (buf != NULL) {
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len] = '\0';
|
||||
|
||||
argv = xreallocarray(argv, argc + 1,
|
||||
sizeof *argv);
|
||||
argv[argc++] = buf;
|
||||
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
}
|
||||
|
||||
if (ch != EOF)
|
||||
break;
|
||||
|
||||
while (argc != 0) {
|
||||
equals = strchr(argv[0], '=');
|
||||
whitespace = argv[0] + strcspn(argv[0], " \t");
|
||||
if (equals == NULL || equals > whitespace)
|
||||
break;
|
||||
environ_put(global_environ, argv[0]);
|
||||
argc--;
|
||||
memmove(argv, argv + 1, argc * (sizeof *argv));
|
||||
}
|
||||
goto done;
|
||||
case '~':
|
||||
if (buf != NULL) {
|
||||
append = 1;
|
||||
break;
|
||||
}
|
||||
t = cmd_string_expand_tilde(s, &p);
|
||||
if (t == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
break;
|
||||
default:
|
||||
append = 1;
|
||||
break;
|
||||
}
|
||||
if (append) {
|
||||
if (len >= SIZE_MAX - 2)
|
||||
goto error;
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
}
|
||||
append = 0;
|
||||
}
|
||||
|
||||
done:
|
||||
*rargc = argc;
|
||||
*rargv = argv;
|
||||
|
||||
free(buf);
|
||||
return (0);
|
||||
|
||||
error:
|
||||
if (argv != NULL)
|
||||
cmd_free_argv(argc, argv);
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
struct cmd_list *
|
||||
cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
|
||||
{
|
||||
struct cmd_list *cmdlist = NULL;
|
||||
int argc;
|
||||
char **argv;
|
||||
|
||||
*cause = NULL;
|
||||
if (cmd_string_split(s, &argc, &argv) != 0) {
|
||||
xasprintf(cause, "invalid or unknown command: %s", s);
|
||||
return (NULL);
|
||||
}
|
||||
if (argc != 0) {
|
||||
cmdlist = cmd_list_parse(argc, argv, file, line, cause);
|
||||
if (cmdlist == NULL) {
|
||||
cmd_free_argv(argc, argv);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
cmd_free_argv(argc, argv);
|
||||
return (cmdlist);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_string_copy(char **dst, char *src, size_t *len)
|
||||
{
|
||||
size_t srclen;
|
||||
|
||||
srclen = strlen(src);
|
||||
|
||||
*dst = xrealloc(*dst, *len + srclen + 1);
|
||||
strlcpy(*dst + *len, src, srclen + 1);
|
||||
|
||||
*len += srclen;
|
||||
free(src);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_string_string(const char *s, size_t *p, char endch, int esc)
|
||||
{
|
||||
int ch;
|
||||
char *buf, *t;
|
||||
size_t len;
|
||||
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
|
||||
while ((ch = cmd_string_getc(s, p)) != endch) {
|
||||
switch (ch) {
|
||||
case EOF:
|
||||
goto error;
|
||||
case '\\':
|
||||
if (!esc)
|
||||
break;
|
||||
switch (ch = cmd_string_getc(s, p)) {
|
||||
case EOF:
|
||||
goto error;
|
||||
case 'e':
|
||||
ch = '\033';
|
||||
break;
|
||||
case 'r':
|
||||
ch = '\r';
|
||||
break;
|
||||
case 'n':
|
||||
ch = '\n';
|
||||
break;
|
||||
case 't':
|
||||
ch = '\t';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case '$':
|
||||
if (!esc)
|
||||
break;
|
||||
if ((t = cmd_string_variable(s, p)) == NULL)
|
||||
goto error;
|
||||
cmd_string_copy(&buf, t, &len);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len >= SIZE_MAX - 2)
|
||||
goto error;
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
}
|
||||
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len] = '\0';
|
||||
return (buf);
|
||||
|
||||
error:
|
||||
free(buf);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_string_variable(const char *s, size_t *p)
|
||||
{
|
||||
int ch, fch;
|
||||
char *buf, *t;
|
||||
size_t len;
|
||||
struct environ_entry *envent;
|
||||
|
||||
#define cmd_string_first(ch) ((ch) == '_' || \
|
||||
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z'))
|
||||
#define cmd_string_other(ch) ((ch) == '_' || \
|
||||
((ch) >= 'a' && (ch) <= 'z') || ((ch) >= 'A' && (ch) <= 'Z') || \
|
||||
((ch) >= '0' && (ch) <= '9'))
|
||||
|
||||
buf = NULL;
|
||||
len = 0;
|
||||
|
||||
fch = EOF;
|
||||
switch (ch = cmd_string_getc(s, p)) {
|
||||
case EOF:
|
||||
goto error;
|
||||
case '{':
|
||||
fch = '{';
|
||||
|
||||
ch = cmd_string_getc(s, p);
|
||||
if (!cmd_string_first(ch))
|
||||
goto error;
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
if (!cmd_string_first(ch)) {
|
||||
xasprintf(&t, "$%c", ch);
|
||||
return (t);
|
||||
}
|
||||
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
|
||||
for (;;) {
|
||||
ch = cmd_string_getc(s, p);
|
||||
if (ch == EOF || !cmd_string_other(ch))
|
||||
break;
|
||||
else {
|
||||
if (len >= SIZE_MAX - 3)
|
||||
goto error;
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len++] = ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fch == '{' && ch != '}')
|
||||
goto error;
|
||||
if (ch != EOF && fch != '{')
|
||||
cmd_string_ungetc(p); /* ch */
|
||||
|
||||
buf = xrealloc(buf, len + 1);
|
||||
buf[len] = '\0';
|
||||
|
||||
envent = environ_find(global_environ, buf);
|
||||
free(buf);
|
||||
if (envent == NULL)
|
||||
return (xstrdup(""));
|
||||
return (xstrdup(envent->value));
|
||||
|
||||
error:
|
||||
free(buf);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static char *
|
||||
cmd_string_expand_tilde(const char *s, size_t *p)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct environ_entry *envent;
|
||||
char *home, *path, *user, *cp;
|
||||
int last;
|
||||
|
||||
home = NULL;
|
||||
|
||||
last = cmd_string_getc(s, p);
|
||||
if (last == EOF || last == '/' || last == ' '|| last == '\t') {
|
||||
envent = environ_find(global_environ, "HOME");
|
||||
if (envent != NULL && *envent->value != '\0')
|
||||
home = envent->value;
|
||||
else if ((pw = getpwuid(getuid())) != NULL)
|
||||
home = pw->pw_dir;
|
||||
} else {
|
||||
cmd_string_ungetc(p);
|
||||
|
||||
cp = user = xmalloc(strlen(s));
|
||||
for (;;) {
|
||||
last = cmd_string_getc(s, p);
|
||||
if (last == EOF ||
|
||||
last == '/' ||
|
||||
last == ' '||
|
||||
last == '\t')
|
||||
break;
|
||||
*cp++ = last;
|
||||
}
|
||||
*cp = '\0';
|
||||
|
||||
if ((pw = getpwnam(user)) != NULL)
|
||||
home = pw->pw_dir;
|
||||
free(user);
|
||||
}
|
||||
|
||||
if (home == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (last != EOF)
|
||||
xasprintf(&path, "%s%c", home, last);
|
||||
else
|
||||
xasprintf(&path, "%s", home);
|
||||
return (path);
|
||||
}
|
||||
@@ -101,19 +101,17 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (!args_has(self->args, 'd')) {
|
||||
if (src_w != dst_w) {
|
||||
window_set_active_pane(src_w, dst_wp);
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
window_set_active_pane(src_w, dst_wp, 1);
|
||||
window_set_active_pane(dst_w, src_wp, 1);
|
||||
} else {
|
||||
tmp_wp = dst_wp;
|
||||
if (!window_pane_visible(tmp_wp))
|
||||
tmp_wp = src_wp;
|
||||
window_set_active_pane(src_w, tmp_wp);
|
||||
window_set_active_pane(src_w, tmp_wp, 1);
|
||||
}
|
||||
} else {
|
||||
if (src_w->active == src_wp)
|
||||
window_set_active_pane(src_w, dst_wp);
|
||||
window_set_active_pane(src_w, dst_wp, 1);
|
||||
if (dst_w->active == dst_wp)
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
window_set_active_pane(dst_w, src_wp, 1);
|
||||
}
|
||||
if (src_w != dst_w) {
|
||||
if (src_w->last == src_wp)
|
||||
|
||||
@@ -78,9 +78,9 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
TAILQ_INSERT_TAIL(&w_dst->winlinks, wl_src, wentry);
|
||||
|
||||
if (!args_has(self->args, 'd')) {
|
||||
session_select(dst, wl_dst->idx);
|
||||
session_select(src, wl_src->idx);
|
||||
if (src != dst)
|
||||
session_select(src, wl_src->idx);
|
||||
session_select(dst, wl_dst->idx);
|
||||
}
|
||||
session_group_synchronize_from(src);
|
||||
server_redraw_session_group(src);
|
||||
|
||||
@@ -61,7 +61,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.%")] != '\0') {
|
||||
type = CMD_FIND_PANE;
|
||||
flags = 0;
|
||||
} else {
|
||||
@@ -113,8 +113,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (item->client == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
server_unzoom_window(wl->window);
|
||||
if (wp != NULL) {
|
||||
window_redraw_active_switch(wp->window, wp);
|
||||
window_set_active_pane(wp->window, wp, 1);
|
||||
}
|
||||
session_set_current(s, wl);
|
||||
cmd_find_from_session(&item->shared->current, s, 0);
|
||||
}
|
||||
@@ -128,6 +131,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
c->session = s;
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
tty_update_client_offset(c);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
|
||||
@@ -170,7 +170,7 @@ cmd_wait_for_wait(struct cmdq_item *item, const char *name,
|
||||
struct client *c = item->client;
|
||||
struct wait_item *wi;
|
||||
|
||||
if (c == NULL || c->session != NULL) {
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "not able to wait");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -198,7 +198,7 @@ cmd_wait_for_lock(struct cmdq_item *item, const char *name,
|
||||
{
|
||||
struct wait_item *wi;
|
||||
|
||||
if (item->client == NULL || item->client->session != NULL) {
|
||||
if (item->client == NULL) {
|
||||
cmdq_error(item, "not able to lock");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
253
cmd.c
253
cmd.c
@@ -41,6 +41,7 @@ extern const struct cmd_entry cmd_confirm_before_entry;
|
||||
extern const struct cmd_entry cmd_copy_mode_entry;
|
||||
extern const struct cmd_entry cmd_delete_buffer_entry;
|
||||
extern const struct cmd_entry cmd_detach_client_entry;
|
||||
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_panes_entry;
|
||||
extern const struct cmd_entry cmd_down_pane_entry;
|
||||
@@ -80,6 +81,7 @@ extern const struct cmd_entry cmd_refresh_client_entry;
|
||||
extern const struct cmd_entry cmd_rename_session_entry;
|
||||
extern const struct cmd_entry cmd_rename_window_entry;
|
||||
extern const struct cmd_entry cmd_resize_pane_entry;
|
||||
extern const struct cmd_entry cmd_resize_window_entry;
|
||||
extern const struct cmd_entry cmd_respawn_pane_entry;
|
||||
extern const struct cmd_entry cmd_respawn_window_entry;
|
||||
extern const struct cmd_entry cmd_rotate_window_entry;
|
||||
@@ -128,6 +130,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_copy_mode_entry,
|
||||
&cmd_delete_buffer_entry,
|
||||
&cmd_detach_client_entry,
|
||||
&cmd_display_menu_entry,
|
||||
&cmd_display_message_entry,
|
||||
&cmd_display_panes_entry,
|
||||
&cmd_find_window_entry,
|
||||
@@ -166,6 +169,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_rename_session_entry,
|
||||
&cmd_rename_window_entry,
|
||||
&cmd_resize_pane_entry,
|
||||
&cmd_resize_window_entry,
|
||||
&cmd_respawn_pane_entry,
|
||||
&cmd_respawn_window_entry,
|
||||
&cmd_rotate_window_entry,
|
||||
@@ -200,6 +204,45 @@ const struct cmd_entry *cmd_table[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
void printflike(3, 4)
|
||||
cmd_log_argv(int argc, char **argv, const char *fmt, ...)
|
||||
{
|
||||
char *prefix;
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&prefix, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
log_debug("%s: argv[%d]=%s", prefix, i, argv[i]);
|
||||
free(prefix);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_prepend_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
char **new_argv;
|
||||
int i;
|
||||
|
||||
new_argv = xreallocarray(NULL, (*argc) + 1, sizeof *new_argv);
|
||||
new_argv[0] = xstrdup(arg);
|
||||
for (i = 0; i < *argc; i++)
|
||||
new_argv[1 + i] = (*argv)[i];
|
||||
|
||||
free(*argv);
|
||||
*argv = new_argv;
|
||||
(*argc)++;
|
||||
}
|
||||
|
||||
void
|
||||
cmd_append_argv(int *argc, char ***argv, char *arg)
|
||||
{
|
||||
*argv = xreallocarray(*argv, (*argc) + 1, sizeof **argv);
|
||||
(*argv)[(*argc)++] = xstrdup(arg);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
{
|
||||
@@ -208,6 +251,7 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
|
||||
if (argc == 0)
|
||||
return (0);
|
||||
cmd_log_argv(argc, argv, "%s", __func__);
|
||||
|
||||
*buf = '\0';
|
||||
for (i = 0; i < argc; i++) {
|
||||
@@ -240,9 +284,11 @@ cmd_unpack_argv(char *buf, size_t len, int argc, char ***argv)
|
||||
|
||||
arglen = strlen(buf) + 1;
|
||||
(*argv)[i] = xstrdup(buf);
|
||||
|
||||
buf += arglen;
|
||||
len -= arglen;
|
||||
}
|
||||
cmd_log_argv(argc, *argv, "%s", __func__);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -301,106 +347,103 @@ cmd_stringify_argv(int argc, char **argv)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_try_alias(int *argc, char ***argv)
|
||||
char *
|
||||
cmd_get_alias(const char *name)
|
||||
{
|
||||
struct options_entry *o;
|
||||
int old_argc = *argc, new_argc;
|
||||
char **old_argv = *argv, **new_argv;
|
||||
u_int size, idx;
|
||||
int i;
|
||||
size_t wanted;
|
||||
const char *s, *cp = NULL;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
union options_value *ov;
|
||||
size_t wanted, n;
|
||||
const char *equals;
|
||||
|
||||
o = options_get_only(global_options, "command-alias");
|
||||
if (o == NULL || options_array_size(o, &size) == -1 || size == 0)
|
||||
return (-1);
|
||||
if (o == NULL)
|
||||
return (NULL);
|
||||
wanted = strlen(name);
|
||||
|
||||
wanted = strlen(old_argv[0]);
|
||||
for (idx = 0; idx < size; idx++) {
|
||||
s = options_array_get(o, idx);
|
||||
if (s == NULL)
|
||||
continue;
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
ov = options_array_item_value(a);
|
||||
|
||||
cp = strchr(s, '=');
|
||||
if (cp == NULL || (size_t)(cp - s) != wanted)
|
||||
equals = strchr(ov->string, '=');
|
||||
if (equals != NULL) {
|
||||
n = equals - ov->string;
|
||||
if (n == wanted && strncmp(name, ov->string, n) == 0)
|
||||
return (xstrdup(equals + 1));
|
||||
}
|
||||
|
||||
a = options_array_next(a);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static const struct cmd_entry *
|
||||
cmd_find(const char *name, char **cause)
|
||||
{
|
||||
const struct cmd_entry **loop, *entry, *found = NULL;
|
||||
int ambiguous;
|
||||
char s[BUFSIZ];
|
||||
|
||||
ambiguous = 0;
|
||||
for (loop = cmd_table; *loop != NULL; loop++) {
|
||||
entry = *loop;
|
||||
if (entry->alias != NULL && strcmp(entry->alias, name) == 0) {
|
||||
ambiguous = 0;
|
||||
found = entry;
|
||||
break;
|
||||
}
|
||||
|
||||
if (strncmp(entry->name, name, strlen(name)) != 0)
|
||||
continue;
|
||||
if (strncmp(old_argv[0], s, wanted) == 0)
|
||||
if (found != NULL)
|
||||
ambiguous = 1;
|
||||
found = entry;
|
||||
|
||||
if (strcmp(entry->name, name) == 0)
|
||||
break;
|
||||
}
|
||||
if (idx == size)
|
||||
return (-1);
|
||||
if (ambiguous)
|
||||
goto ambiguous;
|
||||
if (found == NULL) {
|
||||
xasprintf(cause, "unknown command: %s", name);
|
||||
return (NULL);
|
||||
}
|
||||
return (found);
|
||||
|
||||
if (cmd_string_split(cp + 1, &new_argc, &new_argv) != 0)
|
||||
return (-1);
|
||||
|
||||
*argc = new_argc + old_argc - 1;
|
||||
*argv = xcalloc((*argc) + 1, sizeof **argv);
|
||||
|
||||
for (i = 0; i < new_argc; i++)
|
||||
(*argv)[i] = xstrdup(new_argv[i]);
|
||||
for (i = 1; i < old_argc; i++)
|
||||
(*argv)[new_argc + i - 1] = xstrdup(old_argv[i]);
|
||||
|
||||
log_debug("alias: %s=%s", old_argv[0], cp + 1);
|
||||
for (i = 0; i < *argc; i++)
|
||||
log_debug("alias: argv[%d] = %s", i, (*argv)[i]);
|
||||
|
||||
cmd_free_argv(new_argc, new_argv);
|
||||
return (0);
|
||||
ambiguous:
|
||||
*s = '\0';
|
||||
for (loop = cmd_table; *loop != NULL; loop++) {
|
||||
entry = *loop;
|
||||
if (strncmp(entry->name, name, strlen(name)) != 0)
|
||||
continue;
|
||||
if (strlcat(s, entry->name, sizeof s) >= sizeof s)
|
||||
break;
|
||||
if (strlcat(s, ", ", sizeof s) >= sizeof s)
|
||||
break;
|
||||
}
|
||||
s[strlen(s) - 2] = '\0';
|
||||
xasprintf(cause, "ambiguous command: %s, could be: %s", name, s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
struct cmd *
|
||||
cmd_parse(int argc, char **argv, const char *file, u_int line, char **cause)
|
||||
{
|
||||
const struct cmd_entry *entry;
|
||||
const char *name;
|
||||
const struct cmd_entry **entryp, *entry;
|
||||
struct cmd *cmd;
|
||||
struct args *args;
|
||||
char s[BUFSIZ];
|
||||
int ambiguous, allocated = 0;
|
||||
|
||||
*cause = NULL;
|
||||
if (argc == 0) {
|
||||
xasprintf(cause, "no command");
|
||||
return (NULL);
|
||||
}
|
||||
name = argv[0];
|
||||
|
||||
retry:
|
||||
ambiguous = 0;
|
||||
entry = NULL;
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
if ((*entryp)->alias != NULL &&
|
||||
strcmp((*entryp)->alias, argv[0]) == 0) {
|
||||
ambiguous = 0;
|
||||
entry = *entryp;
|
||||
break;
|
||||
}
|
||||
|
||||
if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
|
||||
continue;
|
||||
if (entry != NULL)
|
||||
ambiguous = 1;
|
||||
entry = *entryp;
|
||||
|
||||
/* Bail now if an exact match. */
|
||||
if (strcmp(entry->name, argv[0]) == 0)
|
||||
break;
|
||||
}
|
||||
if ((ambiguous || entry == NULL) &&
|
||||
server_proc != NULL &&
|
||||
!allocated &&
|
||||
cmd_try_alias(&argc, &argv) == 0) {
|
||||
allocated = 1;
|
||||
goto retry;
|
||||
}
|
||||
if (ambiguous)
|
||||
goto ambiguous;
|
||||
if (entry == NULL) {
|
||||
xasprintf(cause, "unknown command: %s", name);
|
||||
entry = cmd_find(name, cause);
|
||||
if (entry == NULL)
|
||||
return (NULL);
|
||||
}
|
||||
cmd_log_argv(argc, argv, "%s: %s", __func__, entry->name);
|
||||
|
||||
args = args_parse(entry->args.template, argc, argv);
|
||||
if (args == NULL)
|
||||
@@ -418,23 +461,11 @@ retry:
|
||||
cmd->file = xstrdup(file);
|
||||
cmd->line = line;
|
||||
|
||||
if (allocated)
|
||||
cmd_free_argv(argc, argv);
|
||||
return (cmd);
|
||||
cmd->alias = NULL;
|
||||
cmd->argc = argc;
|
||||
cmd->argv = cmd_copy_argv(argc, argv);
|
||||
|
||||
ambiguous:
|
||||
*s = '\0';
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
if (strncmp((*entryp)->name, argv[0], strlen(argv[0])) != 0)
|
||||
continue;
|
||||
if (strlcat(s, (*entryp)->name, sizeof s) >= sizeof s)
|
||||
break;
|
||||
if (strlcat(s, ", ", sizeof s) >= sizeof s)
|
||||
break;
|
||||
}
|
||||
s[strlen(s) - 2] = '\0';
|
||||
xasprintf(cause, "ambiguous command: %s, could be: %s", name, s);
|
||||
return (NULL);
|
||||
return (cmd);
|
||||
|
||||
usage:
|
||||
if (args != NULL)
|
||||
@@ -443,6 +474,18 @@ usage:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
cmd_free(struct cmd *cmd)
|
||||
{
|
||||
free(cmd->alias);
|
||||
cmd_free_argv(cmd->argc, cmd->argv);
|
||||
|
||||
free(cmd->file);
|
||||
|
||||
args_free(cmd->args);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_print(struct cmd *cmd)
|
||||
{
|
||||
@@ -466,17 +509,16 @@ cmd_mouse_at(struct window_pane *wp, struct mouse_event *m, u_int *xp,
|
||||
u_int x, y;
|
||||
|
||||
if (last) {
|
||||
x = m->lx;
|
||||
y = m->ly;
|
||||
x = m->lx + m->ox;
|
||||
y = m->ly + m->oy;
|
||||
} else {
|
||||
x = m->x;
|
||||
y = m->y;
|
||||
x = m->x + m->ox;
|
||||
y = m->y + m->oy;
|
||||
}
|
||||
log_debug("%s: x=%u, y=%u%s", __func__, x, y, last ? " (last)" : "");
|
||||
|
||||
if (m->statusat == 0 && y > 0)
|
||||
y--;
|
||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
||||
y = m->statusat - 1;
|
||||
|
||||
if (x < wp->xoff || x >= wp->xoff + wp->sx)
|
||||
return (-1);
|
||||
@@ -496,17 +538,22 @@ cmd_mouse_window(struct mouse_event *m, struct session **sp)
|
||||
{
|
||||
struct session *s;
|
||||
struct window *w;
|
||||
struct winlink *wl;
|
||||
|
||||
if (!m->valid || m->s == -1 || m->w == -1)
|
||||
if (!m->valid)
|
||||
return (NULL);
|
||||
if ((s = session_find_by_id(m->s)) == NULL)
|
||||
if (m->s == -1 || (s = session_find_by_id(m->s)) == NULL)
|
||||
return (NULL);
|
||||
if ((w = window_find_by_id(m->w)) == NULL)
|
||||
return (NULL);
|
||||
|
||||
if (m->w == -1)
|
||||
wl = s->curw;
|
||||
else {
|
||||
if ((w = window_find_by_id(m->w)) == NULL)
|
||||
return (NULL);
|
||||
wl = winlink_find_by_window(&s->windows, w);
|
||||
}
|
||||
if (sp != NULL)
|
||||
*sp = s;
|
||||
return (winlink_find_by_window(&s->windows, w));
|
||||
return (wl);
|
||||
}
|
||||
|
||||
/* Get current mouse pane if any. */
|
||||
|
||||
11
colour.c
11
colour.c
@@ -141,6 +141,8 @@ colour_tostring(int c)
|
||||
return ("white");
|
||||
case 8:
|
||||
return ("default");
|
||||
case 9:
|
||||
return ("terminal");
|
||||
case 90:
|
||||
return ("brightblack");
|
||||
case 91:
|
||||
@@ -158,7 +160,7 @@ colour_tostring(int c)
|
||||
case 97:
|
||||
return ("brightwhite");
|
||||
}
|
||||
return (NULL);
|
||||
return ("invalid");
|
||||
}
|
||||
|
||||
/* Convert colour from string. */
|
||||
@@ -188,6 +190,11 @@ colour_fromstring(const char *s)
|
||||
return (n | COLOUR_FLAG_256);
|
||||
}
|
||||
|
||||
if (strcasecmp(s, "default") == 0)
|
||||
return (8);
|
||||
if (strcasecmp(s, "terminal") == 0)
|
||||
return (9);
|
||||
|
||||
if (strcasecmp(s, "black") == 0 || strcmp(s, "0") == 0)
|
||||
return (0);
|
||||
if (strcasecmp(s, "red") == 0 || strcmp(s, "1") == 0)
|
||||
@@ -204,8 +211,6 @@ colour_fromstring(const char *s)
|
||||
return (6);
|
||||
if (strcasecmp(s, "white") == 0 || strcmp(s, "7") == 0)
|
||||
return (7);
|
||||
if (strcasecmp(s, "default") == 0 || strcmp(s, "8") == 0)
|
||||
return (8);
|
||||
if (strcasecmp(s, "brightblack") == 0 || strcmp(s, "90") == 0)
|
||||
return (90);
|
||||
if (strcasecmp(s, "brightred") == 0 || strcmp(s, "91") == 0)
|
||||
|
||||
5
compat.h
5
compat.h
@@ -67,6 +67,7 @@ void warnx(const char *, ...);
|
||||
#define _PATH_DEVNULL "/dev/null"
|
||||
#define _PATH_TTY "/dev/tty"
|
||||
#define _PATH_DEV "/dev/"
|
||||
#define _PATH_DEFPATH "/usr/bin:/bin"
|
||||
#endif
|
||||
|
||||
#ifndef __OpenBSD__
|
||||
@@ -312,10 +313,6 @@ int vasprintf(char **, const char *, va_list);
|
||||
char *fgetln(FILE *, size_t *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FPARSELN
|
||||
char *fparseln(FILE *, size_t *, size_t *, const char *, int);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_SETENV
|
||||
/* setenv.c */
|
||||
int setenv(const char *, const char *, int);
|
||||
|
||||
@@ -1,221 +0,0 @@
|
||||
/* $OpenBSD: fparseln.c,v 1.6 2005/08/02 21:46:23 espie Exp $ */
|
||||
/* $NetBSD: fparseln.c,v 1.7 1999/07/02 15:49:12 simonb Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Christos Zoulas. 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. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Christos Zoulas.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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/libutil/fparseln.c */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* fparseln() specific operation flags.
|
||||
*/
|
||||
#define FPARSELN_UNESCESC 0x01
|
||||
#define FPARSELN_UNESCCONT 0x02
|
||||
#define FPARSELN_UNESCCOMM 0x04
|
||||
#define FPARSELN_UNESCREST 0x08
|
||||
#define FPARSELN_UNESCALL 0x0f
|
||||
|
||||
static int isescaped(const char *, const char *, int);
|
||||
|
||||
/* isescaped():
|
||||
* Return true if the character in *p that belongs to a string
|
||||
* that starts in *sp, is escaped by the escape character esc.
|
||||
*/
|
||||
static int
|
||||
isescaped(const char *sp, const char *p, int esc)
|
||||
{
|
||||
const char *cp;
|
||||
size_t ne;
|
||||
|
||||
/* No escape character */
|
||||
if (esc == '\0')
|
||||
return 1;
|
||||
|
||||
/* Count the number of escape characters that precede ours */
|
||||
for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
|
||||
continue;
|
||||
|
||||
/* Return true if odd number of escape characters */
|
||||
return (ne & 1) != 0;
|
||||
}
|
||||
|
||||
|
||||
/* fparseln():
|
||||
* Read a line from a file parsing continuations ending in \
|
||||
* and eliminating trailing newlines, or comments starting with
|
||||
* the comment char.
|
||||
*/
|
||||
char *
|
||||
fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3],
|
||||
int flags)
|
||||
{
|
||||
static const char dstr[3] = { '\\', '\\', '#' };
|
||||
char *buf = NULL, *ptr, *cp, esc, con, nl, com;
|
||||
size_t s, len = 0;
|
||||
int cnt = 1;
|
||||
|
||||
if (str == NULL)
|
||||
str = dstr;
|
||||
|
||||
esc = str[0];
|
||||
con = str[1];
|
||||
com = str[2];
|
||||
|
||||
/*
|
||||
* XXX: it would be cool to be able to specify the newline character,
|
||||
* but unfortunately, fgetln does not let us
|
||||
*/
|
||||
nl = '\n';
|
||||
|
||||
while (cnt) {
|
||||
cnt = 0;
|
||||
|
||||
if (lineno)
|
||||
(*lineno)++;
|
||||
|
||||
if ((ptr = fgetln(fp, &s)) == NULL)
|
||||
break;
|
||||
|
||||
if (s && com) { /* Check and eliminate comments */
|
||||
for (cp = ptr; cp < ptr + s; cp++)
|
||||
if (*cp == com && !isescaped(ptr, cp, esc)) {
|
||||
s = cp - ptr;
|
||||
cnt = s == 0 && buf == NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (s && nl) { /* Check and eliminate newlines */
|
||||
cp = &ptr[s - 1];
|
||||
|
||||
if (*cp == nl)
|
||||
s--; /* forget newline */
|
||||
}
|
||||
|
||||
if (s && con) { /* Check and eliminate continuations */
|
||||
cp = &ptr[s - 1];
|
||||
|
||||
if (*cp == con && !isescaped(ptr, cp, esc)) {
|
||||
s--; /* forget escape */
|
||||
cnt = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (s == 0 && buf != NULL)
|
||||
continue;
|
||||
|
||||
if ((cp = realloc(buf, len + s + 1)) == NULL) {
|
||||
free(buf);
|
||||
return NULL;
|
||||
}
|
||||
buf = cp;
|
||||
|
||||
(void) memcpy(buf + len, ptr, s);
|
||||
len += s;
|
||||
buf[len] = '\0';
|
||||
}
|
||||
|
||||
if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
|
||||
strchr(buf, esc) != NULL) {
|
||||
ptr = cp = buf;
|
||||
while (cp[0] != '\0') {
|
||||
int skipesc;
|
||||
|
||||
while (cp[0] != '\0' && cp[0] != esc)
|
||||
*ptr++ = *cp++;
|
||||
if (cp[0] == '\0' || cp[1] == '\0')
|
||||
break;
|
||||
|
||||
skipesc = 0;
|
||||
if (cp[1] == com)
|
||||
skipesc += (flags & FPARSELN_UNESCCOMM);
|
||||
if (cp[1] == con)
|
||||
skipesc += (flags & FPARSELN_UNESCCONT);
|
||||
if (cp[1] == esc)
|
||||
skipesc += (flags & FPARSELN_UNESCESC);
|
||||
if (cp[1] != com && cp[1] != con && cp[1] != esc)
|
||||
skipesc = (flags & FPARSELN_UNESCREST);
|
||||
|
||||
if (skipesc)
|
||||
cp++;
|
||||
else
|
||||
*ptr++ = *cp++;
|
||||
*ptr++ = *cp++;
|
||||
}
|
||||
*ptr = '\0';
|
||||
len = strlen(buf);
|
||||
}
|
||||
|
||||
if (size)
|
||||
*size = len;
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
int main(int, char **);
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *ptr;
|
||||
size_t size, line;
|
||||
|
||||
line = 0;
|
||||
while ((ptr = fparseln(stdin, &size, &line, NULL,
|
||||
FPARSELN_UNESCALL)) != NULL)
|
||||
printf("line %d (%d) |%s|\n", line, size, ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
# This is a test
|
||||
line 1
|
||||
line 2 \
|
||||
line 3 # Comment
|
||||
line 4 \# Not comment \\\\
|
||||
|
||||
# And a comment \
|
||||
line 5 \\\
|
||||
line 6
|
||||
|
||||
*/
|
||||
|
||||
#endif /* TEST */
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: imsg-buffer.c,v 1.10 2017/04/11 09:57:19 reyk Exp $ */
|
||||
/* $OpenBSD: imsg-buffer.c,v 1.11 2017/12/14 09:27:44 kettenis Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@@ -29,9 +29,9 @@
|
||||
#include "compat.h"
|
||||
#include "imsg.h"
|
||||
|
||||
int ibuf_realloc(struct ibuf *, size_t);
|
||||
void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
||||
void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
||||
static int ibuf_realloc(struct ibuf *, size_t);
|
||||
static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
|
||||
static void ibuf_dequeue(struct msgbuf *, struct ibuf *);
|
||||
|
||||
struct ibuf *
|
||||
ibuf_open(size_t len)
|
||||
@@ -67,7 +67,7 @@ ibuf_dynamic(size_t len, size_t max)
|
||||
return (buf);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
ibuf_realloc(struct ibuf *buf, size_t len)
|
||||
{
|
||||
u_char *b;
|
||||
@@ -289,14 +289,14 @@ again:
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||
{
|
||||
TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry);
|
||||
msgbuf->queued++;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf)
|
||||
{
|
||||
TAILQ_REMOVE(&msgbuf->bufs, buf, entry);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: imsg.c,v 1.15 2017/04/11 09:57:19 reyk Exp $ */
|
||||
/* $OpenBSD: imsg.c,v 1.16 2017/12/14 09:27:44 kettenis Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
int imsg_fd_overhead = 0;
|
||||
|
||||
int imsg_get_fd(struct imsgbuf *);
|
||||
static int imsg_get_fd(struct imsgbuf *);
|
||||
|
||||
void
|
||||
imsg_init(struct imsgbuf *ibuf, int fd)
|
||||
@@ -266,7 +266,7 @@ imsg_free(struct imsg *imsg)
|
||||
freezero(imsg->data, imsg->hdr.len - IMSG_HEADER_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
imsg_get_fd(struct imsgbuf *ibuf)
|
||||
{
|
||||
int fd;
|
||||
|
||||
27
configure.ac
27
configure.ac
@@ -1,6 +1,6 @@
|
||||
# configure.ac
|
||||
|
||||
AC_INIT(tmux, 2.7-rc)
|
||||
AC_INIT([tmux], 3.0-rc3)
|
||||
AC_PREREQ([2.60])
|
||||
|
||||
AC_CONFIG_AUX_DIR(etc)
|
||||
@@ -28,6 +28,7 @@ AC_PROG_CC_C99
|
||||
AC_PROG_CPP
|
||||
AC_PROG_EGREP
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_YACC
|
||||
PKG_PROG_PKG_CONFIG
|
||||
AC_USE_SYSTEM_EXTENSIONS
|
||||
|
||||
@@ -35,7 +36,7 @@ AC_USE_SYSTEM_EXTENSIONS
|
||||
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
||||
|
||||
# Is this --enable-debug?
|
||||
test "x$VERSION" = xmaster && enable_debug=yes
|
||||
case "x$VERSION" in xnext*) enable_debug=yes;; esac
|
||||
AC_ARG_ENABLE(
|
||||
debug,
|
||||
AC_HELP_STRING(--enable-debug, enable debug build flags),
|
||||
@@ -457,14 +458,6 @@ else
|
||||
AC_LIBOBJ(getopt)
|
||||
fi
|
||||
|
||||
# Look for fparseln in libutil.
|
||||
AC_SEARCH_LIBS(fparseln, util, found_fparseln=yes, found_fparseln=no)
|
||||
if test "x$found_fparseln" = xyes; then
|
||||
AC_DEFINE(HAVE_FPARSELN)
|
||||
else
|
||||
AC_LIBOBJ(fparseln)
|
||||
fi
|
||||
|
||||
# Look for fdforkpty and forkpty in libutil.
|
||||
AC_SEARCH_LIBS(fdforkpty, util, found_fdforkpty=yes, found_fdforkpty=no)
|
||||
if test "x$found_fdforkpty" = xyes; then
|
||||
@@ -478,6 +471,9 @@ if test "x$found_forkpty" = xyes; then
|
||||
fi
|
||||
AM_CONDITIONAL(NEED_FORKPTY, test "x$found_forkpty" = xno)
|
||||
|
||||
# Look for kinfo_getfile in libutil.
|
||||
AC_SEARCH_LIBS(kinfo_getfile, [util util-freebsd])
|
||||
|
||||
# Look for a suitable queue.h.
|
||||
AC_CHECK_DECL(
|
||||
TAILQ_CONCAT,
|
||||
@@ -610,7 +606,16 @@ case "$host_os" in
|
||||
*solaris*)
|
||||
AC_MSG_RESULT(sunos)
|
||||
PLATFORM=sunos
|
||||
MANFORMAT=man
|
||||
case `/usr/bin/nroff --version 2>&1` in
|
||||
*GNU*)
|
||||
# Solaris 11.4 and later use GNU groff.
|
||||
MANFORMAT=mdoc
|
||||
;;
|
||||
*)
|
||||
# Solaris 2.0 to 11.3 use AT&T nroff.
|
||||
MANFORMAT=man
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*hpux*)
|
||||
AC_MSG_RESULT(hpux)
|
||||
|
||||
@@ -28,25 +28,22 @@
|
||||
|
||||
void
|
||||
control_notify_input(struct client *c, struct window_pane *wp,
|
||||
struct evbuffer *input)
|
||||
const u_char *buf, size_t len)
|
||||
{
|
||||
u_char *buf;
|
||||
size_t len;
|
||||
struct evbuffer *message;
|
||||
u_int i;
|
||||
|
||||
if (c->session == NULL)
|
||||
return;
|
||||
|
||||
buf = EVBUFFER_DATA(input);
|
||||
len = EVBUFFER_LENGTH(input);
|
||||
|
||||
/*
|
||||
* Only write input if the window pane is linked to a window belonging
|
||||
* to the client's session.
|
||||
*/
|
||||
if (winlink_find_by_window(&c->session->windows, wp->window) != NULL) {
|
||||
message = evbuffer_new();
|
||||
if (message == NULL)
|
||||
fatalx("out of memory");
|
||||
evbuffer_add_printf(message, "%%output %%%u ", wp->id);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (buf[i] < ' ' || buf[i] == '\\')
|
||||
|
||||
25
control.c
25
control.c
@@ -68,10 +68,9 @@ control_error(struct cmdq_item *item, void *data)
|
||||
void
|
||||
control_callback(struct client *c, int closed, __unused void *data)
|
||||
{
|
||||
char *line, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmd *cmd;
|
||||
char *line;
|
||||
struct cmdq_item *item;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (closed)
|
||||
c->flags |= CLIENT_EXIT;
|
||||
@@ -85,16 +84,20 @@ control_callback(struct client *c, int closed, __unused void *data)
|
||||
break;
|
||||
}
|
||||
|
||||
cmdlist = cmd_string_parse(line, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
item = cmdq_get_callback(control_error, cause);
|
||||
pr = cmd_parse_from_string(line, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
item = cmdq_get_callback(control_error, pr->error);
|
||||
cmdq_append(c, item);
|
||||
} else {
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry)
|
||||
cmd->flags |= CMD_CONTROL;
|
||||
item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
|
||||
item->shared->flags |= CMDQ_SHARED_CONTROL;
|
||||
cmdq_append(c, item);
|
||||
cmd_list_free(cmdlist);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
break;
|
||||
}
|
||||
|
||||
free(line);
|
||||
|
||||
22
environ.c
22
environ.c
@@ -174,22 +174,22 @@ environ_unset(struct environ *env, const char *name)
|
||||
void
|
||||
environ_update(struct options *oo, struct environ *src, struct environ *dst)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
struct options_entry *o;
|
||||
u_int size, idx;
|
||||
const char *value;
|
||||
struct environ_entry *envent;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
union options_value *ov;
|
||||
|
||||
o = options_get(oo, "update-environment");
|
||||
if (o == NULL || options_array_size(o, &size) == -1)
|
||||
if (o == NULL)
|
||||
return;
|
||||
for (idx = 0; idx < size; idx++) {
|
||||
value = options_array_get(o, idx);
|
||||
if (value == NULL)
|
||||
continue;
|
||||
if ((envent = environ_find(src, value)) == NULL)
|
||||
environ_clear(dst, value);
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
ov = options_array_item_value(a);
|
||||
if ((envent = environ_find(src, ov->string)) == NULL)
|
||||
environ_clear(dst, ov->string);
|
||||
else
|
||||
environ_set(dst, envent->name, "%s", envent->value);
|
||||
a = options_array_next(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
# Some tweaks to the status line
|
||||
set -g status-right "%H:%M"
|
||||
set -g window-status-current-attr "underscore"
|
||||
set -g window-status-current-style "underscore"
|
||||
|
||||
# If running inside tmux ($TMUX is set), then change the status line to red
|
||||
%if #{TMUX}
|
||||
@@ -49,11 +49,15 @@ bind F10 selectw -t:19
|
||||
bind F11 selectw -t:20
|
||||
bind F12 selectw -t:21
|
||||
|
||||
# Keys to toggle monitoring activity in a window, and synchronize-panes
|
||||
# A key to toggle between smallest and largest sizes if a window is visible in
|
||||
# multiple places
|
||||
bind F set -w window-size
|
||||
|
||||
# Keys to toggle monitoring activity in a window and the synchronize-panes option
|
||||
bind m set monitor-activity
|
||||
bind y set synchronize-panes\; display 'synchronize-panes #{?synchronize-panes,on,off}'
|
||||
|
||||
# Create a single default session, because a session is created here, tmux
|
||||
# Create a single default session - because a session is created here, tmux
|
||||
# should be started with "tmux attach" rather than "tmux new"
|
||||
new -d -s0 -nirssi 'exec irssi'
|
||||
set -t0:0 monitor-activity on
|
||||
|
||||
886
format-draw.c
Normal file
886
format-draw.c
Normal file
@@ -0,0 +1,886 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/* Format range. */
|
||||
struct format_range {
|
||||
u_int index;
|
||||
struct screen *s;
|
||||
|
||||
u_int start;
|
||||
u_int end;
|
||||
|
||||
enum style_range_type type;
|
||||
u_int argument;
|
||||
|
||||
TAILQ_ENTRY(format_range) entry;
|
||||
};
|
||||
TAILQ_HEAD(format_ranges, format_range);
|
||||
|
||||
/* Does this range match this style? */
|
||||
static int
|
||||
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);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Free a range. */
|
||||
static void
|
||||
format_free_range(struct format_ranges *frs, struct format_range *fr)
|
||||
{
|
||||
TAILQ_REMOVE(frs, fr, entry);
|
||||
free(fr);
|
||||
}
|
||||
|
||||
/* Fix range positions. */
|
||||
static void
|
||||
format_update_ranges(struct format_ranges *frs, struct screen *s, u_int offset,
|
||||
u_int start, u_int width)
|
||||
{
|
||||
struct format_range *fr, *fr1;
|
||||
|
||||
if (frs == NULL)
|
||||
return;
|
||||
|
||||
TAILQ_FOREACH_SAFE(fr, frs, entry, fr1) {
|
||||
if (fr->s != s)
|
||||
continue;
|
||||
|
||||
if (fr->end <= start || fr->start >= start + width) {
|
||||
format_free_range(frs, fr);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fr->start < start)
|
||||
fr->start = start;
|
||||
if (fr->end > start + width)
|
||||
fr->end = start + width;
|
||||
if (fr->start == fr->end) {
|
||||
format_free_range(frs, fr);
|
||||
continue;
|
||||
}
|
||||
|
||||
fr->start -= start;
|
||||
fr->end -= start;
|
||||
|
||||
fr->start += offset;
|
||||
fr->end += offset;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw a part of the format. */
|
||||
static void
|
||||
format_draw_put(struct screen_write_ctx *octx, u_int ocx, u_int ocy,
|
||||
struct screen *s, struct format_ranges *frs, u_int offset, u_int start,
|
||||
u_int width)
|
||||
{
|
||||
/*
|
||||
* The offset is how far from the cursor on the target screen; start
|
||||
* and width how much to copy from the source screen.
|
||||
*/
|
||||
screen_write_cursormove(octx, ocx + offset, ocy, 0);
|
||||
screen_write_fast_copy(octx, s, start, 0, width, 1);
|
||||
format_update_ranges(frs, s, offset, start, width);
|
||||
}
|
||||
|
||||
/* Draw list part of format. */
|
||||
static void
|
||||
format_draw_put_list(struct screen_write_ctx *octx,
|
||||
u_int ocx, u_int ocy, u_int offset, u_int width, struct screen *list,
|
||||
struct screen *list_left, struct screen *list_right, int focus_start,
|
||||
int focus_end, struct format_ranges *frs)
|
||||
{
|
||||
u_int start, focus_centre;
|
||||
|
||||
/* If there is enough space for the list, draw it entirely. */
|
||||
if (width >= list->cx) {
|
||||
format_draw_put(octx, ocx, ocy, list, frs, offset, 0, width);
|
||||
return;
|
||||
}
|
||||
|
||||
/* The list needs to be trimmed. Try to keep the focus visible. */
|
||||
focus_centre = focus_start + (focus_end - focus_start) / 2;
|
||||
if (focus_centre < width / 2)
|
||||
start = 0;
|
||||
else
|
||||
start = focus_centre - width / 2;
|
||||
if (start + width > list->cx)
|
||||
start = list->cx - width;
|
||||
|
||||
/* Draw <> markers at either side if needed. */
|
||||
if (start != 0 && width > list_left->cx) {
|
||||
screen_write_cursormove(octx, ocx + offset, ocy, 0);
|
||||
screen_write_fast_copy(octx, list_left, 0, 0, list_left->cx, 1);
|
||||
offset += list_left->cx;
|
||||
start += list_left->cx;
|
||||
width -= list_left->cx;
|
||||
}
|
||||
if (start + width < list->cx && width > list_right->cx) {
|
||||
screen_write_cursormove(octx, ocx + offset + width - 1, ocy, 0);
|
||||
screen_write_fast_copy(octx, list_right, 0, 0, list_right->cx,
|
||||
1);
|
||||
width -= list_right->cx;
|
||||
}
|
||||
|
||||
/* Draw the list screen itself. */
|
||||
format_draw_put(octx, ocx, ocy, list, frs, offset, start, width);
|
||||
}
|
||||
|
||||
/* Draw format with no list. */
|
||||
static void
|
||||
format_draw_none(struct screen_write_ctx *octx, u_int available, u_int ocx,
|
||||
u_int ocy, struct screen *left, struct screen *centre, struct screen *right,
|
||||
struct format_ranges *frs)
|
||||
{
|
||||
u_int width_left, width_centre, width_right;
|
||||
|
||||
width_left = left->cx;
|
||||
width_centre = centre->cx;
|
||||
width_right = right->cx;
|
||||
|
||||
/*
|
||||
* Try to keep as much of the left and right as possible at the expense
|
||||
* of the centre.
|
||||
*/
|
||||
while (width_left + width_centre + width_right > available) {
|
||||
if (width_centre > 0)
|
||||
width_centre--;
|
||||
else if (width_right > 0)
|
||||
width_right--;
|
||||
else
|
||||
width_left--;
|
||||
}
|
||||
|
||||
/* Write left. */
|
||||
format_draw_put(octx, ocx, ocy, left, frs, 0, 0, width_left);
|
||||
|
||||
/* Write right at available - width_right. */
|
||||
format_draw_put(octx, ocx, ocy, right, frs,
|
||||
available - width_right,
|
||||
right->cx - width_right,
|
||||
width_right);
|
||||
|
||||
/*
|
||||
* Write centre halfway between
|
||||
* width_left
|
||||
* and
|
||||
* available - width_right.
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, centre, frs,
|
||||
width_left
|
||||
+ ((available - width_right) - width_left) / 2
|
||||
- width_centre / 2,
|
||||
centre->cx / 2 - width_centre / 2,
|
||||
width_centre);
|
||||
}
|
||||
|
||||
/* Draw format with list on the left. */
|
||||
static void
|
||||
format_draw_left(struct screen_write_ctx *octx, u_int available, u_int ocx,
|
||||
u_int ocy, struct screen *left, struct screen *centre, struct screen *right,
|
||||
struct screen *list, struct screen *list_left, struct screen *list_right,
|
||||
struct screen *after, int focus_start, int focus_end,
|
||||
struct format_ranges *frs)
|
||||
{
|
||||
u_int width_left, width_centre, width_right;
|
||||
u_int width_list, width_after;
|
||||
struct screen_write_ctx ctx;
|
||||
|
||||
width_left = left->cx;
|
||||
width_centre = centre->cx;
|
||||
width_right = right->cx;
|
||||
width_list = list->cx;
|
||||
width_after = after->cx;
|
||||
|
||||
/*
|
||||
* Trim first the centre, then the list, then the right, then after the
|
||||
* list, then the left.
|
||||
*/
|
||||
while (width_left +
|
||||
width_centre +
|
||||
width_right +
|
||||
width_list +
|
||||
width_after > available) {
|
||||
if (width_centre > 0)
|
||||
width_centre--;
|
||||
else if (width_list > 0)
|
||||
width_list--;
|
||||
else if (width_right > 0)
|
||||
width_right--;
|
||||
else if (width_after > 0)
|
||||
width_after--;
|
||||
else
|
||||
width_left--;
|
||||
}
|
||||
|
||||
/* If there is no list left, pass off to the no list function. */
|
||||
if (width_list == 0) {
|
||||
screen_write_start(&ctx, NULL, left);
|
||||
screen_write_fast_copy(&ctx, after, 0, 0, width_after, 1);
|
||||
screen_write_stop(&ctx);
|
||||
|
||||
format_draw_none(octx, available, ocx, ocy, left, centre,
|
||||
right, frs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write left at 0. */
|
||||
format_draw_put(octx, ocx, ocy, left, frs, 0, 0, width_left);
|
||||
|
||||
/* Write right at available - width_right. */
|
||||
format_draw_put(octx, ocx, ocy, right, frs,
|
||||
available - width_right,
|
||||
right->cx - width_right,
|
||||
width_right);
|
||||
|
||||
/* Write after at width_left + width_list. */
|
||||
format_draw_put(octx, ocx, ocy, after, frs,
|
||||
width_left + width_list,
|
||||
0,
|
||||
width_after);
|
||||
|
||||
/*
|
||||
* Write centre halfway between
|
||||
* width_left + width_list + width_after
|
||||
* and
|
||||
* available - width_right.
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, centre, frs,
|
||||
(width_left + width_list + width_after)
|
||||
+ ((available - width_right)
|
||||
- (width_left + width_list + width_after)) / 2
|
||||
- width_centre / 2,
|
||||
centre->cx / 2 - width_centre / 2,
|
||||
width_centre);
|
||||
|
||||
/*
|
||||
* The list now goes from
|
||||
* width_left
|
||||
* to
|
||||
* width_left + width_list.
|
||||
* If there is no focus given, keep the left in focus.
|
||||
*/
|
||||
if (focus_start == -1 || focus_end == -1)
|
||||
focus_start = focus_end = 0;
|
||||
format_draw_put_list(octx, ocx, ocy, width_left, width_list, list,
|
||||
list_left, list_right, focus_start, focus_end, frs);
|
||||
}
|
||||
|
||||
/* Draw format with list in the centre. */
|
||||
static void
|
||||
format_draw_centre(struct screen_write_ctx *octx, u_int available, u_int ocx,
|
||||
u_int ocy, struct screen *left, struct screen *centre, struct screen *right,
|
||||
struct screen *list, struct screen *list_left, struct screen *list_right,
|
||||
struct screen *after, int focus_start, int focus_end,
|
||||
struct format_ranges *frs)
|
||||
{
|
||||
u_int width_left, width_centre, width_right;
|
||||
u_int width_list, width_after, middle;
|
||||
struct screen_write_ctx ctx;
|
||||
|
||||
width_left = left->cx;
|
||||
width_centre = centre->cx;
|
||||
width_right = right->cx;
|
||||
width_list = list->cx;
|
||||
width_after = after->cx;
|
||||
|
||||
/*
|
||||
* Trim first the list, then after the list, then the centre, then the
|
||||
* right, then the left.
|
||||
*/
|
||||
while (width_left +
|
||||
width_centre +
|
||||
width_right +
|
||||
width_list +
|
||||
width_after > available) {
|
||||
if (width_list > 0)
|
||||
width_list--;
|
||||
else if (width_after > 0)
|
||||
width_after--;
|
||||
else if (width_centre > 0)
|
||||
width_centre--;
|
||||
else if (width_right > 0)
|
||||
width_right--;
|
||||
else
|
||||
width_left--;
|
||||
}
|
||||
|
||||
/* If there is no list left, pass off to the no list function. */
|
||||
if (width_list == 0) {
|
||||
screen_write_start(&ctx, NULL, centre);
|
||||
screen_write_fast_copy(&ctx, after, 0, 0, width_after, 1);
|
||||
screen_write_stop(&ctx);
|
||||
|
||||
format_draw_none(octx, available, ocx, ocy, left, centre,
|
||||
right, frs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write left at 0. */
|
||||
format_draw_put(octx, ocx, ocy, left, frs, 0, 0, width_left);
|
||||
|
||||
/* Write right at available - width_right. */
|
||||
format_draw_put(octx, ocx, ocy, right, frs,
|
||||
available - width_right,
|
||||
right->cx - width_right,
|
||||
width_right);
|
||||
|
||||
/*
|
||||
* All three centre sections are offset from the middle of the
|
||||
* available space.
|
||||
*/
|
||||
middle = (width_left + ((available - width_right) - width_left) / 2);
|
||||
|
||||
/*
|
||||
* Write centre at
|
||||
* middle - width_list / 2 - width_centre.
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, centre, frs,
|
||||
middle - width_list / 2 - width_centre,
|
||||
0,
|
||||
width_centre);
|
||||
|
||||
/*
|
||||
* Write after at
|
||||
* middle - width_list / 2 + width_list
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, after, frs,
|
||||
middle - width_list / 2 + width_list,
|
||||
0,
|
||||
width_after);
|
||||
|
||||
/*
|
||||
* The list now goes from
|
||||
* middle - width_list / 2
|
||||
* to
|
||||
* middle + width_list / 2
|
||||
* If there is no focus given, keep the centre in focus.
|
||||
*/
|
||||
if (focus_start == -1 || focus_end == -1)
|
||||
focus_start = focus_end = list->cx / 2;
|
||||
format_draw_put_list(octx, ocx, ocy, middle - width_list / 2,
|
||||
width_list, list, list_left, list_right, focus_start, focus_end,
|
||||
frs);
|
||||
}
|
||||
|
||||
/* Draw format with list on the right. */
|
||||
static void
|
||||
format_draw_right(struct screen_write_ctx *octx, u_int available, u_int ocx,
|
||||
u_int ocy, struct screen *left, struct screen *centre, struct screen *right,
|
||||
struct screen *list, struct screen *list_left, struct screen *list_right,
|
||||
struct screen *after, int focus_start, int focus_end,
|
||||
struct format_ranges *frs)
|
||||
{
|
||||
u_int width_left, width_centre, width_right;
|
||||
u_int width_list, width_after;
|
||||
struct screen_write_ctx ctx;
|
||||
|
||||
width_left = left->cx;
|
||||
width_centre = centre->cx;
|
||||
width_right = right->cx;
|
||||
width_list = list->cx;
|
||||
width_after = after->cx;
|
||||
|
||||
/*
|
||||
* Trim first the centre, then the list, then the right, then
|
||||
* after the list, then the left.
|
||||
*/
|
||||
while (width_left +
|
||||
width_centre +
|
||||
width_right +
|
||||
width_list +
|
||||
width_after > available) {
|
||||
if (width_centre > 0)
|
||||
width_centre--;
|
||||
else if (width_list > 0)
|
||||
width_list--;
|
||||
else if (width_right > 0)
|
||||
width_right--;
|
||||
else if (width_after > 0)
|
||||
width_after--;
|
||||
else
|
||||
width_left--;
|
||||
}
|
||||
|
||||
/* If there is no list left, pass off to the no list function. */
|
||||
if (width_list == 0) {
|
||||
screen_write_start(&ctx, NULL, right);
|
||||
screen_write_fast_copy(&ctx, after, 0, 0, width_after, 1);
|
||||
screen_write_stop(&ctx);
|
||||
|
||||
format_draw_none(octx, available, ocx, ocy, left, centre,
|
||||
right, frs);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write left at 0. */
|
||||
format_draw_put(octx, ocx, ocy, left, frs, 0, 0, width_left);
|
||||
|
||||
/* Write after at available - width_after. */
|
||||
format_draw_put(octx, ocx, ocy, after, frs,
|
||||
available - width_after,
|
||||
after->cx - width_after,
|
||||
width_after);
|
||||
|
||||
/*
|
||||
* Write right at
|
||||
* available - width_right - width_list - width_after.
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, right, frs,
|
||||
available - width_right - width_list - width_after,
|
||||
0,
|
||||
width_right);
|
||||
|
||||
/*
|
||||
* Write centre halfway between
|
||||
* width_left
|
||||
* and
|
||||
* available - width_right - width_list - width_after.
|
||||
*/
|
||||
format_draw_put(octx, ocx, ocy, centre, frs,
|
||||
width_left
|
||||
+ ((available - width_right - width_list - width_after)
|
||||
- width_left) / 2
|
||||
- width_centre / 2,
|
||||
centre->cx / 2 - width_centre / 2,
|
||||
width_centre);
|
||||
|
||||
/*
|
||||
* The list now goes from
|
||||
* available - width_list - width_after
|
||||
* to
|
||||
* available - width_after
|
||||
* If there is no focus given, keep the right in focus.
|
||||
*/
|
||||
if (focus_start == -1 || focus_end == -1)
|
||||
focus_start = focus_end = 0;
|
||||
format_draw_put_list(octx, ocx, ocy, available - width_list -
|
||||
width_after, width_list, list, list_left, list_right, focus_start,
|
||||
focus_end, frs);
|
||||
}
|
||||
|
||||
/* Draw a format to a screen. */
|
||||
void
|
||||
format_draw(struct screen_write_ctx *octx, const struct grid_cell *base,
|
||||
u_int available, const char *expanded, struct style_ranges *srs)
|
||||
{
|
||||
enum { LEFT,
|
||||
CENTRE,
|
||||
RIGHT,
|
||||
LIST,
|
||||
LIST_LEFT,
|
||||
LIST_RIGHT,
|
||||
AFTER,
|
||||
TOTAL } current = LEFT, last = LEFT;
|
||||
const char *names[] = { "LEFT",
|
||||
"CENTRE",
|
||||
"RIGHT",
|
||||
"LIST",
|
||||
"LIST_LEFT",
|
||||
"LIST_RIGHT",
|
||||
"AFTER" };
|
||||
size_t size = strlen(expanded);
|
||||
struct screen *os = octx->s, s[TOTAL];
|
||||
struct screen_write_ctx ctx[TOTAL];
|
||||
u_int ocx = os->cx, ocy = os->cy, i, width[TOTAL];
|
||||
u_int map[] = { LEFT, LEFT, CENTRE, RIGHT };
|
||||
int focus_start = -1, focus_end = -1;
|
||||
int list_state = -1;
|
||||
enum style_align list_align = STYLE_ALIGN_DEFAULT;
|
||||
struct style sy;
|
||||
struct utf8_data *ud = &sy.gc.data;
|
||||
const char *cp, *end;
|
||||
enum utf8_state more;
|
||||
char *tmp;
|
||||
struct format_range *fr = NULL, *fr1;
|
||||
struct format_ranges frs;
|
||||
struct style_range *sr;
|
||||
|
||||
style_set(&sy, base);
|
||||
TAILQ_INIT(&frs);
|
||||
log_debug("%s: %s", __func__, expanded);
|
||||
|
||||
/*
|
||||
* We build three screens for left, right, centre alignment, one for
|
||||
* the list, one for anything after the list and two for the list left
|
||||
* and right markers.
|
||||
*/
|
||||
for (i = 0; i < TOTAL; i++) {
|
||||
screen_init(&s[i], size, 1, 0);
|
||||
screen_write_start(&ctx[i], NULL, &s[i]);
|
||||
screen_write_clearendofline(&ctx[i], base->bg);
|
||||
width[i] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Walk the string and add to the corresponding screens,
|
||||
* parsing styles as we go.
|
||||
*/
|
||||
cp = expanded;
|
||||
while (*cp != '\0') {
|
||||
if (cp[0] != '#' || cp[1] != '[') {
|
||||
/* See if this is a UTF-8 character. */
|
||||
if ((more = utf8_open(ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(ud, *cp);
|
||||
if (more != UTF8_DONE)
|
||||
cp -= ud->have;
|
||||
}
|
||||
|
||||
/* Not a UTF-8 character - ASCII or not valid. */
|
||||
if (more != UTF8_DONE) {
|
||||
if (*cp < 0x20 || *cp > 0x7e) {
|
||||
/* Ignore nonprintable characters. */
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
utf8_set(ud, *cp);
|
||||
cp++;
|
||||
}
|
||||
|
||||
/* Draw the cell to th current screen. */
|
||||
screen_write_cell(&ctx[current], &sy.gc);
|
||||
width[current] += ud->width;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* This is a style. Work out where the end is and parse it. */
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL) {
|
||||
log_debug("%s: no terminating ] at '%s'", __func__,
|
||||
cp + 2);
|
||||
TAILQ_FOREACH_SAFE(fr, &frs, entry, fr1)
|
||||
format_free_range(&frs, fr);
|
||||
goto out;
|
||||
}
|
||||
tmp = xstrndup(cp + 2, end - (cp + 2));
|
||||
if (style_parse(&sy, base, tmp) != 0) {
|
||||
log_debug("%s: invalid style '%s'", __func__, tmp);
|
||||
free(tmp);
|
||||
cp = end + 1;
|
||||
continue;
|
||||
}
|
||||
log_debug("%s: style '%s' -> '%s'", __func__, tmp,
|
||||
style_tostring(&sy));
|
||||
free(tmp);
|
||||
|
||||
/* Check the list state. */
|
||||
switch (sy.list) {
|
||||
case STYLE_LIST_ON:
|
||||
/*
|
||||
* Entering the list, exiting a marker, or exiting the
|
||||
* focus.
|
||||
*/
|
||||
if (list_state != 0) {
|
||||
if (fr != NULL) { /* abort any region */
|
||||
free(fr);
|
||||
fr = NULL;
|
||||
}
|
||||
list_state = 0;
|
||||
list_align = sy.align;
|
||||
}
|
||||
|
||||
/* End the focus if started. */
|
||||
if (focus_start != -1 && focus_end == -1)
|
||||
focus_end = s[LIST].cx;
|
||||
|
||||
current = LIST;
|
||||
break;
|
||||
case STYLE_LIST_FOCUS:
|
||||
/* Entering the focus. */
|
||||
if (list_state != 0) /* not inside the list */
|
||||
break;
|
||||
if (focus_start == -1) /* focus already started */
|
||||
focus_start = s[LIST].cx;
|
||||
break;
|
||||
case STYLE_LIST_OFF:
|
||||
/* Exiting or outside the list. */
|
||||
if (list_state == 0) {
|
||||
if (fr != NULL) { /* abort any region */
|
||||
free(fr);
|
||||
fr = NULL;
|
||||
}
|
||||
if (focus_start != -1 && focus_end == -1)
|
||||
focus_end = s[LIST].cx;
|
||||
|
||||
map[list_align] = AFTER;
|
||||
if (list_align == STYLE_ALIGN_LEFT)
|
||||
map[STYLE_ALIGN_DEFAULT] = AFTER;
|
||||
list_state = 1;
|
||||
}
|
||||
current = map[sy.align];
|
||||
break;
|
||||
case STYLE_LIST_LEFT_MARKER:
|
||||
/* Entering left marker. */
|
||||
if (list_state != 0) /* not inside the list */
|
||||
break;
|
||||
if (s[LIST_LEFT].cx != 0) /* already have marker */
|
||||
break;
|
||||
if (fr != NULL) { /* abort any region */
|
||||
free(fr);
|
||||
fr = NULL;
|
||||
}
|
||||
if (focus_start != -1 && focus_end == -1)
|
||||
focus_start = focus_end = -1;
|
||||
current = LIST_LEFT;
|
||||
break;
|
||||
case STYLE_LIST_RIGHT_MARKER:
|
||||
/* Entering right marker. */
|
||||
if (list_state != 0) /* not inside the list */
|
||||
break;
|
||||
if (s[LIST_RIGHT].cx != 0) /* already have marker */
|
||||
break;
|
||||
if (fr != NULL) { /* abort any region */
|
||||
free(fr);
|
||||
fr = NULL;
|
||||
}
|
||||
if (focus_start != -1 && focus_end == -1)
|
||||
focus_start = focus_end = -1;
|
||||
current = LIST_RIGHT;
|
||||
break;
|
||||
}
|
||||
if (current != last) {
|
||||
log_debug("%s: change %s -> %s", __func__,
|
||||
names[last], names[current]);
|
||||
last = current;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if the range style has changed and if so end the
|
||||
* current range and start a new one if needed.
|
||||
*/
|
||||
if (srs != NULL) {
|
||||
if (fr != NULL && !format_is_type(fr, &sy)) {
|
||||
if (s[current].cx != fr->start) {
|
||||
fr->end = s[current].cx + 1;
|
||||
TAILQ_INSERT_TAIL(&frs, fr, entry);
|
||||
} else
|
||||
free(fr);
|
||||
fr = NULL;
|
||||
}
|
||||
if (fr == NULL && sy.range_type != STYLE_RANGE_NONE) {
|
||||
fr = xcalloc(1, sizeof *fr);
|
||||
fr->index = current;
|
||||
|
||||
fr->s = &s[current];
|
||||
fr->start = s[current].cx;
|
||||
|
||||
fr->type = sy.range_type;
|
||||
fr->argument = sy.range_argument;
|
||||
}
|
||||
}
|
||||
|
||||
cp = end + 1;
|
||||
}
|
||||
free(fr);
|
||||
|
||||
for (i = 0; i < TOTAL; i++) {
|
||||
screen_write_stop(&ctx[i]);
|
||||
log_debug("%s: width %s is %u", __func__, names[i], width[i]);
|
||||
}
|
||||
if (focus_start != -1 && focus_end != -1)
|
||||
log_debug("%s: focus %d-%d", __func__, focus_start, focus_end);
|
||||
TAILQ_FOREACH(fr, &frs, entry) {
|
||||
log_debug("%s: range %d|%u is %s %u-%u", __func__, fr->type,
|
||||
fr->argument, names[fr->index], fr->start, fr->end);
|
||||
}
|
||||
|
||||
/*
|
||||
* Draw the screens. How they are arranged depends on where the list
|
||||
* appearsq.
|
||||
*/
|
||||
switch (list_align) {
|
||||
case STYLE_ALIGN_DEFAULT:
|
||||
/* No list. */
|
||||
format_draw_none(octx, available, ocx, ocy, &s[LEFT],
|
||||
&s[CENTRE], &s[RIGHT], &frs);
|
||||
break;
|
||||
case STYLE_ALIGN_LEFT:
|
||||
/* List is part of the left. */
|
||||
format_draw_left(octx, available, ocx, ocy, &s[LEFT],
|
||||
&s[CENTRE], &s[RIGHT], &s[LIST], &s[LIST_LEFT],
|
||||
&s[LIST_RIGHT], &s[AFTER], focus_start, focus_end, &frs);
|
||||
break;
|
||||
case STYLE_ALIGN_CENTRE:
|
||||
/* List is part of the centre. */
|
||||
format_draw_centre(octx, available, ocx, ocy, &s[LEFT],
|
||||
&s[CENTRE], &s[RIGHT], &s[LIST], &s[LIST_LEFT],
|
||||
&s[LIST_RIGHT], &s[AFTER], focus_start, focus_end, &frs);
|
||||
break;
|
||||
case STYLE_ALIGN_RIGHT:
|
||||
/* List is part of the right. */
|
||||
format_draw_right(octx, available, ocx, ocy, &s[LEFT],
|
||||
&s[CENTRE], &s[RIGHT], &s[LIST], &s[LIST_LEFT],
|
||||
&s[LIST_RIGHT], &s[AFTER], focus_start, focus_end, &frs);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Create ranges to return. */
|
||||
TAILQ_FOREACH_SAFE(fr, &frs, entry, fr1) {
|
||||
sr = xcalloc(1, sizeof *sr);
|
||||
sr->type = fr->type;
|
||||
sr->argument = fr->argument;
|
||||
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);
|
||||
|
||||
format_free_range(&frs, fr);
|
||||
}
|
||||
|
||||
out:
|
||||
/* Free the screens. */
|
||||
for (i = 0; i < TOTAL; i++)
|
||||
screen_free(&s[i]);
|
||||
|
||||
/* Restore the original cursor position. */
|
||||
screen_write_cursormove(octx, ocx, ocy, 0);
|
||||
}
|
||||
|
||||
/* Get width, taking #[] into account. */
|
||||
u_int
|
||||
format_width(const char *expanded)
|
||||
{
|
||||
const char *cp, *end;
|
||||
u_int width = 0;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
cp = expanded;
|
||||
while (*cp != '\0') {
|
||||
if (cp[0] == '#' && cp[1] == '[') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
return 0;
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
if (more == UTF8_DONE)
|
||||
width += ud.width;
|
||||
else
|
||||
cp -= ud.have;
|
||||
} else if (*cp > 0x1f && *cp < 0x7f) {
|
||||
width++;
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
return (width);
|
||||
}
|
||||
|
||||
/* Trim on the left, taking #[] into account. */
|
||||
char *
|
||||
format_trim_left(const char *expanded, u_int limit)
|
||||
{
|
||||
char *copy, *out;
|
||||
const char *cp = expanded, *end;
|
||||
u_int width = 0;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
out = copy = xmalloc(strlen(expanded) + 1);
|
||||
while (*cp != '\0') {
|
||||
if (cp[0] == '#' && cp[1] == '[') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
break;
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
if (more == UTF8_DONE) {
|
||||
if (width + ud.width <= limit) {
|
||||
memcpy(out, ud.data, ud.size);
|
||||
out += ud.size;
|
||||
}
|
||||
width += ud.width;
|
||||
} else
|
||||
cp -= ud.have;
|
||||
} else if (*cp > 0x1f && *cp < 0x7f) {
|
||||
if (width + 1 <= limit)
|
||||
*out++ = *cp;
|
||||
width++;
|
||||
cp++;
|
||||
} else
|
||||
cp++;
|
||||
}
|
||||
*out = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
||||
/* Trim on the right, taking #[] into account. */
|
||||
char *
|
||||
format_trim_right(const char *expanded, u_int limit)
|
||||
{
|
||||
char *copy, *out;
|
||||
const char *cp = expanded, *end;
|
||||
u_int width = 0, total_width, skip;
|
||||
struct utf8_data ud;
|
||||
enum utf8_state more;
|
||||
|
||||
total_width = format_width(expanded);
|
||||
if (total_width <= limit)
|
||||
return (xstrdup(expanded));
|
||||
skip = total_width - limit;
|
||||
|
||||
out = copy = xmalloc(strlen(expanded) + 1);
|
||||
while (*cp != '\0') {
|
||||
if (cp[0] == '#' && cp[1] == '[') {
|
||||
end = format_skip(cp + 2, "]");
|
||||
if (end == NULL)
|
||||
break;
|
||||
memcpy(out, cp, end + 1 - cp);
|
||||
out += (end + 1 - cp);
|
||||
cp = end + 1;
|
||||
} else if ((more = utf8_open(&ud, *cp)) == UTF8_MORE) {
|
||||
while (*++cp != '\0' && more == UTF8_MORE)
|
||||
more = utf8_append(&ud, *cp);
|
||||
if (more == UTF8_DONE) {
|
||||
if (width >= skip) {
|
||||
memcpy(out, ud.data, ud.size);
|
||||
out += ud.size;
|
||||
}
|
||||
width += ud.width;
|
||||
} else
|
||||
cp -= ud.have;
|
||||
} else if (*cp > 0x1f && *cp < 0x7f) {
|
||||
if (width >= skip)
|
||||
*out++ = *cp;
|
||||
width++;
|
||||
cp++;
|
||||
} else
|
||||
cp++;
|
||||
}
|
||||
*out = '\0';
|
||||
return (copy);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ grid_view_clear_history(struct grid *gd, u_int bg)
|
||||
/* Find the last used line. */
|
||||
last = 0;
|
||||
for (yy = 0; yy < gd->sy; yy++) {
|
||||
gl = &gd->linedata[grid_view_y(gd, yy)];
|
||||
gl = grid_get_line(gd, grid_view_y(gd, yy));
|
||||
if (gl->cellused != 0)
|
||||
last = yy + 1;
|
||||
}
|
||||
|
||||
298
grid.c
298
grid.c
@@ -39,8 +39,13 @@
|
||||
const struct grid_cell grid_default_cell = {
|
||||
0, 0, 8, 8, { { ' ' }, 0, 1, 1 }
|
||||
};
|
||||
static const struct grid_cell_entry grid_default_entry = {
|
||||
0, { .data = { 0, 8, 8, ' ' } }
|
||||
|
||||
/* Cleared grid cell data. */
|
||||
const struct grid_cell grid_cleared_cell = {
|
||||
GRID_FLAG_CLEARED, 0, 8, 8, { { ' ' }, 0, 1, 1 }
|
||||
};
|
||||
static const struct grid_cell_entry grid_cleared_entry = {
|
||||
GRID_FLAG_CLEARED, { .data = { 0, 8, 8, ' ' } }
|
||||
};
|
||||
|
||||
static void grid_empty_line(struct grid *, u_int, u_int);
|
||||
@@ -50,7 +55,7 @@ static void
|
||||
grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
|
||||
u_char c)
|
||||
{
|
||||
gce->flags = gc->flags;
|
||||
gce->flags = (gc->flags & ~GRID_FLAG_CLEARED);
|
||||
|
||||
gce->data.fg = gc->fg & 0xff;
|
||||
if (gc->fg & COLOUR_FLAG_256)
|
||||
@@ -64,7 +69,7 @@ grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
|
||||
gce->data.data = c;
|
||||
}
|
||||
|
||||
/* Check if a cell should be extended. */
|
||||
/* Check if a cell should be an extended cell. */
|
||||
static int
|
||||
grid_need_extended_cell(const struct grid_cell_entry *gce,
|
||||
const struct grid_cell *gc)
|
||||
@@ -80,6 +85,40 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Get an extended cell. */
|
||||
static void
|
||||
grid_get_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
int flags)
|
||||
{
|
||||
u_int at = gl->extdsize + 1;
|
||||
|
||||
gl->extddata = xreallocarray(gl->extddata, at, sizeof *gl->extddata);
|
||||
gl->extdsize = at;
|
||||
|
||||
gce->offset = at - 1;
|
||||
gce->flags = (flags | GRID_FLAG_EXTENDED);
|
||||
}
|
||||
|
||||
/* Set cell as extended. */
|
||||
static struct grid_cell *
|
||||
grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
const struct grid_cell *gc)
|
||||
{
|
||||
struct grid_cell *gcp;
|
||||
int flags = (gc->flags & ~GRID_FLAG_CLEARED);
|
||||
|
||||
if (~gce->flags & GRID_FLAG_EXTENDED)
|
||||
grid_get_extended_cell(gl, gce, flags);
|
||||
else if (gce->offset >= gl->extdsize)
|
||||
fatalx("offset too big");
|
||||
gl->flags |= GRID_LINE_EXTENDED;
|
||||
|
||||
gcp = &gl->extddata[gce->offset];
|
||||
memcpy(gcp, gc, sizeof *gcp);
|
||||
gcp->flags = flags;
|
||||
return (gcp);
|
||||
}
|
||||
|
||||
/* Free up unused extended cells. */
|
||||
static void
|
||||
grid_compact_line(struct grid_line *gl)
|
||||
@@ -122,27 +161,18 @@ grid_compact_line(struct grid_line *gl)
|
||||
gl->extdsize = new_extdsize;
|
||||
}
|
||||
|
||||
/* Set cell as extended. */
|
||||
static struct grid_cell *
|
||||
grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
const struct grid_cell *gc)
|
||||
/* Get line data. */
|
||||
struct grid_line *
|
||||
grid_get_line(struct grid *gd, u_int line)
|
||||
{
|
||||
struct grid_cell *gcp;
|
||||
return (&gd->linedata[line]);
|
||||
}
|
||||
|
||||
gl->flags |= GRID_LINE_EXTENDED;
|
||||
|
||||
if (~gce->flags & GRID_FLAG_EXTENDED) {
|
||||
gl->extddata = xreallocarray(gl->extddata, gl->extdsize + 1,
|
||||
sizeof *gl->extddata);
|
||||
gce->offset = gl->extdsize++;
|
||||
gce->flags = gc->flags | GRID_FLAG_EXTENDED;
|
||||
}
|
||||
if (gce->offset >= gl->extdsize)
|
||||
fatalx("offset too big");
|
||||
|
||||
gcp = &gl->extddata[gce->offset];
|
||||
memcpy(gcp, gc, sizeof *gcp);
|
||||
return (gcp);
|
||||
/* Adjust number of lines. */
|
||||
void
|
||||
grid_adjust_lines(struct grid *gd, u_int lines)
|
||||
{
|
||||
gd->linedata = xreallocarray(gd->linedata, lines, sizeof *gd->linedata);
|
||||
}
|
||||
|
||||
/* Copy default into a cell. */
|
||||
@@ -153,9 +183,13 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
||||
struct grid_cell_entry *gce = &gl->celldata[px];
|
||||
struct grid_cell *gc;
|
||||
|
||||
memcpy(gce, &grid_default_entry, sizeof *gce);
|
||||
memcpy(gce, &grid_cleared_entry, sizeof *gce);
|
||||
if (bg & COLOUR_FLAG_RGB) {
|
||||
gc = grid_extended_cell(gl, gce, &grid_default_cell);
|
||||
grid_get_extended_cell(gl, gce, gce->flags);
|
||||
gl->flags |= GRID_LINE_EXTENDED;
|
||||
|
||||
gc = &gl->extddata[gce->offset];
|
||||
memcpy(gc, &grid_cleared_cell, sizeof *gc);
|
||||
gc->bg = bg;
|
||||
} else {
|
||||
if (bg & COLOUR_FLAG_256)
|
||||
@@ -166,10 +200,10 @@ grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
||||
|
||||
/* Check grid y position. */
|
||||
static int
|
||||
grid_check_y(struct grid *gd, u_int py)
|
||||
grid_check_y(struct grid *gd, const char* from, u_int py)
|
||||
{
|
||||
if (py >= gd->hsize + gd->sy) {
|
||||
log_debug("y out of range: %u", py);
|
||||
log_debug("%s: y out of range: %u", from, py);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
@@ -272,6 +306,15 @@ grid_compare(struct grid *ga, struct grid *gb)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Trim lines from the history. */
|
||||
static void
|
||||
grid_trim_history(struct grid *gd, u_int ny)
|
||||
{
|
||||
grid_free_lines(gd, 0, ny);
|
||||
memmove(&gd->linedata[0], &gd->linedata[ny],
|
||||
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
|
||||
}
|
||||
|
||||
/*
|
||||
* Collect lines from the history if at the limit. Free the top (oldest) 10%
|
||||
* and shift up.
|
||||
@@ -294,9 +337,7 @@ grid_collect_history(struct grid *gd)
|
||||
* Free the lines from 0 to ny then move the remaining lines over
|
||||
* them.
|
||||
*/
|
||||
grid_free_lines(gd, 0, ny);
|
||||
memmove(&gd->linedata[0], &gd->linedata[ny],
|
||||
(gd->hsize + gd->sy - ny) * (sizeof *gd->linedata));
|
||||
grid_trim_history(gd, ny);
|
||||
|
||||
gd->hsize -= ny;
|
||||
if (gd->hscrolled > gd->hsize)
|
||||
@@ -326,9 +367,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
||||
void
|
||||
grid_clear_history(struct grid *gd)
|
||||
{
|
||||
grid_free_lines(gd, 0, gd->hsize);
|
||||
memmove(&gd->linedata[0], &gd->linedata[gd->hsize],
|
||||
gd->sy * (sizeof *gd->linedata));
|
||||
grid_trim_history(gd, gd->hsize);
|
||||
|
||||
gd->hscrolled = 0;
|
||||
gd->hsize = 0;
|
||||
@@ -399,7 +438,7 @@ static void
|
||||
grid_empty_line(struct grid *gd, u_int py, u_int bg)
|
||||
{
|
||||
memset(&gd->linedata[py], 0, sizeof gd->linedata[py]);
|
||||
if (bg != 8)
|
||||
if (!COLOUR_DEFAULT(bg))
|
||||
grid_expand_line(gd, py, gd->sx, bg);
|
||||
}
|
||||
|
||||
@@ -407,7 +446,7 @@ grid_empty_line(struct grid *gd, u_int py, u_int bg)
|
||||
const struct grid_line *
|
||||
grid_peek_line(struct grid *gd, u_int py)
|
||||
{
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return (NULL);
|
||||
return (&gd->linedata[py]);
|
||||
}
|
||||
@@ -441,11 +480,11 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
||||
void
|
||||
grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
||||
{
|
||||
if (grid_check_y(gd, py) != 0 || px >= gd->linedata[py].cellsize) {
|
||||
if (grid_check_y(gd, __func__, py) != 0 ||
|
||||
px >= gd->linedata[py].cellsize)
|
||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||
return;
|
||||
}
|
||||
return (grid_get_cell1(&gd->linedata[py], px, gc));
|
||||
else
|
||||
grid_get_cell1(&gd->linedata[py], px, gc);
|
||||
}
|
||||
|
||||
/* Set cell at relative position. */
|
||||
@@ -455,7 +494,7 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
||||
struct grid_line *gl;
|
||||
struct grid_cell_entry *gce;
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
|
||||
grid_expand_line(gd, py, px + 1, 8);
|
||||
@@ -481,7 +520,7 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
|
||||
struct grid_cell *gcp;
|
||||
u_int i;
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
|
||||
grid_expand_line(gd, py, px + slen, 8);
|
||||
@@ -504,7 +543,8 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
|
||||
void
|
||||
grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
|
||||
{
|
||||
u_int xx, yy;
|
||||
struct grid_line *gl;
|
||||
u_int xx, yy;
|
||||
|
||||
if (nx == 0 || ny == 0)
|
||||
return;
|
||||
@@ -514,18 +554,19 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
|
||||
return;
|
||||
}
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
||||
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||
return;
|
||||
|
||||
for (yy = py; yy < py + ny; yy++) {
|
||||
if (px + nx >= gd->sx && px < gd->linedata[yy].cellused)
|
||||
gd->linedata[yy].cellused = px;
|
||||
if (px > gd->linedata[yy].cellsize && bg == 8)
|
||||
gl = &gd->linedata[yy];
|
||||
if (px + nx >= gd->sx && px < gl->cellused)
|
||||
gl->cellused = px;
|
||||
if (px > gl->cellsize && COLOUR_DEFAULT(bg))
|
||||
continue;
|
||||
if (px + nx >= gd->linedata[yy].cellsize && bg == 8) {
|
||||
gd->linedata[yy].cellsize = px;
|
||||
if (px + nx >= gl->cellsize && COLOUR_DEFAULT(bg)) {
|
||||
gl->cellsize = px;
|
||||
continue;
|
||||
}
|
||||
grid_expand_line(gd, yy, px + nx, 8); /* default bg first */
|
||||
@@ -543,9 +584,9 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
||||
if (ny == 0)
|
||||
return;
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
||||
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||
return;
|
||||
|
||||
for (yy = py; yy < py + ny; yy++) {
|
||||
@@ -563,13 +604,13 @@ grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny, u_int bg)
|
||||
if (ny == 0 || py == dy)
|
||||
return;
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
if (grid_check_y(gd, py + ny - 1) != 0)
|
||||
if (grid_check_y(gd, __func__, py + ny - 1) != 0)
|
||||
return;
|
||||
if (grid_check_y(gd, dy) != 0)
|
||||
if (grid_check_y(gd, __func__, dy) != 0)
|
||||
return;
|
||||
if (grid_check_y(gd, dy + ny - 1) != 0)
|
||||
if (grid_check_y(gd, __func__, dy + ny - 1) != 0)
|
||||
return;
|
||||
|
||||
/* Free any lines which are being replaced. */
|
||||
@@ -603,7 +644,7 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx,
|
||||
if (nx == 0 || px == dx)
|
||||
return;
|
||||
|
||||
if (grid_check_y(gd, py) != 0)
|
||||
if (grid_check_y(gd, __func__, py) != 0)
|
||||
return;
|
||||
gl = &gd->linedata[py];
|
||||
|
||||
@@ -744,7 +785,12 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
{ GRID_ATTR_BLINK, 5 },
|
||||
{ GRID_ATTR_REVERSE, 7 },
|
||||
{ GRID_ATTR_HIDDEN, 8 },
|
||||
{ GRID_ATTR_STRIKETHROUGH, 9 }
|
||||
{ GRID_ATTR_STRIKETHROUGH, 9 },
|
||||
{ GRID_ATTR_UNDERSCORE_2, 42 },
|
||||
{ GRID_ATTR_UNDERSCORE_3, 43 },
|
||||
{ GRID_ATTR_UNDERSCORE_4, 44 },
|
||||
{ GRID_ATTR_UNDERSCORE_5, 45 },
|
||||
{ GRID_ATTR_OVERLINE, 53 },
|
||||
};
|
||||
n = 0;
|
||||
|
||||
@@ -770,11 +816,15 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < n; i++) {
|
||||
if (i + 1 < n)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", s[i]);
|
||||
else
|
||||
if (s[i] < 10)
|
||||
xsnprintf(tmp, sizeof tmp, "%d", s[i]);
|
||||
else {
|
||||
xsnprintf(tmp, sizeof tmp, "%d:%d", s[i] / 10,
|
||||
s[i] % 10);
|
||||
}
|
||||
strlcat(buf, tmp, len);
|
||||
if (i + 1 < n)
|
||||
strlcat(buf, ";", len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
@@ -981,11 +1031,11 @@ grid_reflow_move(struct grid *gd, struct grid_line *from)
|
||||
/* Join line below onto this one. */
|
||||
static void
|
||||
grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
u_int width, u_int *cy, int already)
|
||||
u_int width, int already)
|
||||
{
|
||||
struct grid_line *gl, *from;
|
||||
struct grid_line *gl, *from = NULL;
|
||||
struct grid_cell gc;
|
||||
u_int lines, want, left, i, to, line;
|
||||
u_int lines, left, i, to, line, want = 0;
|
||||
u_int at;
|
||||
int wrapped = 1;
|
||||
|
||||
@@ -1010,7 +1060,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
* If this is now the last line, there is nothing more to be
|
||||
* done.
|
||||
*/
|
||||
if (yy + lines == gd->hsize + gd->sy)
|
||||
if (yy + 1 + lines == gd->hsize + gd->sy)
|
||||
break;
|
||||
line = yy + 1 + lines;
|
||||
|
||||
@@ -1020,6 +1070,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
if (gd->linedata[line].cellused == 0) {
|
||||
if (!wrapped)
|
||||
break;
|
||||
lines++;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1078,11 +1129,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
grid_reflow_dead(&gd->linedata[i]);
|
||||
}
|
||||
|
||||
/* Adjust cursor and scroll positions. */
|
||||
if (*cy > to + lines)
|
||||
*cy -= lines;
|
||||
else if (*cy > to)
|
||||
*cy = to;
|
||||
/* Adjust scroll position. */
|
||||
if (gd->hscrolled > to + lines)
|
||||
gd->hscrolled -= lines;
|
||||
else if (gd->hscrolled > to)
|
||||
@@ -1092,7 +1139,7 @@ grid_reflow_join(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
/* Split this line into several new ones */
|
||||
static void
|
||||
grid_reflow_split(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
u_int at, u_int *cy)
|
||||
u_int at)
|
||||
{
|
||||
struct grid_line *gl = &gd->linedata[yy], *first;
|
||||
struct grid_cell gc;
|
||||
@@ -1145,9 +1192,7 @@ grid_reflow_split(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
memcpy(first, gl, sizeof *first);
|
||||
grid_reflow_dead(gl);
|
||||
|
||||
/* Adjust the cursor and scroll positions. */
|
||||
if (yy <= *cy)
|
||||
(*cy) += lines - 1;
|
||||
/* Adjust the scroll position. */
|
||||
if (yy <= gd->hscrolled)
|
||||
gd->hscrolled += lines - 1;
|
||||
|
||||
@@ -1156,24 +1201,17 @@ grid_reflow_split(struct grid *target, struct grid *gd, u_int sx, u_int yy,
|
||||
* in the last new line, try to join with the next lines.
|
||||
*/
|
||||
if (width < sx && (flags & GRID_LINE_WRAPPED))
|
||||
grid_reflow_join(target, gd, sx, yy, width, cy, 1);
|
||||
grid_reflow_join(target, gd, sx, yy, width, 1);
|
||||
}
|
||||
|
||||
/* Reflow lines on grid to new width. */
|
||||
void
|
||||
grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||
grid_reflow(struct grid *gd, u_int sx)
|
||||
{
|
||||
struct grid *target;
|
||||
struct grid_line *gl;
|
||||
struct grid_cell gc;
|
||||
u_int yy, cy, width, i, at, first;
|
||||
struct timeval start, tv;
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
log_debug("%s: %u lines, new width %u", __func__, gd->hsize + gd->sy,
|
||||
sx);
|
||||
cy = gd->hsize + (*cursor);
|
||||
u_int yy, width, i, at, first;
|
||||
|
||||
/*
|
||||
* Create a destination grid. This is just used as a container for the
|
||||
@@ -1227,7 +1265,7 @@ grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||
* it was previously wrapped.
|
||||
*/
|
||||
if (width > sx) {
|
||||
grid_reflow_split(target, gd, sx, yy, at, &cy);
|
||||
grid_reflow_split(target, gd, sx, yy, at);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1236,7 +1274,7 @@ grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||
* of the next line.
|
||||
*/
|
||||
if (gl->flags & GRID_LINE_WRAPPED)
|
||||
grid_reflow_join(target, gd, sx, yy, width, &cy, 0);
|
||||
grid_reflow_join(target, gd, sx, yy, width, 0);
|
||||
else
|
||||
grid_reflow_move(target, gl);
|
||||
}
|
||||
@@ -1247,23 +1285,87 @@ grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||
if (target->sy < gd->sy)
|
||||
grid_reflow_add(target, gd->sy - target->sy);
|
||||
gd->hsize = target->sy - gd->sy;
|
||||
if (gd->hscrolled > gd->hsize)
|
||||
gd->hscrolled = gd->hsize;
|
||||
free(gd->linedata);
|
||||
gd->linedata = target->linedata;
|
||||
free(target);
|
||||
}
|
||||
|
||||
/* Convert to position based on wrapped lines. */
|
||||
void
|
||||
grid_wrap_position(struct grid *gd, u_int px, u_int py, u_int *wx, u_int *wy)
|
||||
{
|
||||
u_int ax = 0, ay = 0, yy;
|
||||
|
||||
for (yy = 0; yy < py; yy++) {
|
||||
if (gd->linedata[yy].flags & GRID_LINE_WRAPPED)
|
||||
ax += gd->linedata[yy].cellused;
|
||||
else {
|
||||
ax = 0;
|
||||
ay++;
|
||||
}
|
||||
}
|
||||
if (px >= gd->linedata[yy].cellused)
|
||||
ax = UINT_MAX;
|
||||
else
|
||||
ax += px;
|
||||
*wx = ax;
|
||||
*wy = ay;
|
||||
}
|
||||
|
||||
/* Convert position based on wrapped lines back. */
|
||||
void
|
||||
grid_unwrap_position(struct grid *gd, u_int *px, u_int *py, u_int wx, u_int wy)
|
||||
{
|
||||
u_int yy, ax = 0, ay = 0;
|
||||
|
||||
for (yy = 0; yy < gd->hsize + gd->sy - 1; yy++) {
|
||||
if (ay == wy)
|
||||
break;
|
||||
if (gd->linedata[yy].flags & GRID_LINE_WRAPPED)
|
||||
ax += gd->linedata[yy].cellused;
|
||||
else {
|
||||
ax = 0;
|
||||
ay++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Update scrolled and cursor positions.
|
||||
* yy is now 0 on the unwrapped line which contains wx. Walk forwards
|
||||
* until we find the end or the line now containing wx.
|
||||
*/
|
||||
if (gd->hscrolled > gd->hsize)
|
||||
gd->hscrolled = gd->hsize;
|
||||
if (cy < gd->hsize)
|
||||
*cursor = 0;
|
||||
else
|
||||
*cursor = cy - gd->hsize;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
timersub(&tv, &start, &tv);
|
||||
log_debug("%s: now %u lines (in %llu.%06u seconds)", __func__,
|
||||
gd->hsize + gd->sy, (unsigned long long)tv.tv_sec,
|
||||
(u_int)tv.tv_usec);
|
||||
if (wx == UINT_MAX) {
|
||||
while (gd->linedata[yy].flags & GRID_LINE_WRAPPED)
|
||||
yy++;
|
||||
wx = gd->linedata[yy].cellused;
|
||||
} else {
|
||||
while (gd->linedata[yy].flags & GRID_LINE_WRAPPED) {
|
||||
if (wx < gd->linedata[yy].cellused)
|
||||
break;
|
||||
wx -= gd->linedata[yy].cellused;
|
||||
yy++;
|
||||
}
|
||||
}
|
||||
*px = wx;
|
||||
*py = yy;
|
||||
}
|
||||
|
||||
/* Get length of line. */
|
||||
u_int
|
||||
grid_line_length(struct grid *gd, u_int py)
|
||||
{
|
||||
struct grid_cell gc;
|
||||
u_int px;
|
||||
|
||||
px = grid_get_line(gd, py)->cellsize;
|
||||
if (px > gd->sx)
|
||||
px = gd->sx;
|
||||
while (px > 0) {
|
||||
grid_get_cell(gd, px - 1, py, &gc);
|
||||
if (gc.data.size != 1 || *gc.data.data != ' ')
|
||||
break;
|
||||
px--;
|
||||
}
|
||||
return (px);
|
||||
}
|
||||
|
||||
173
hooks.c
173
hooks.c
@@ -1,173 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2012 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"
|
||||
|
||||
struct hooks {
|
||||
RB_HEAD(hooks_tree, hook) tree;
|
||||
struct hooks *parent;
|
||||
};
|
||||
|
||||
static int hooks_cmp(struct hook *, struct hook *);
|
||||
RB_GENERATE_STATIC(hooks_tree, hook, entry, hooks_cmp);
|
||||
|
||||
static struct hook *hooks_find1(struct hooks *, const char *);
|
||||
static void hooks_free1(struct hooks *, struct hook *);
|
||||
|
||||
static int
|
||||
hooks_cmp(struct hook *hook1, struct hook *hook2)
|
||||
{
|
||||
return (strcmp(hook1->name, hook2->name));
|
||||
}
|
||||
|
||||
struct hooks *
|
||||
hooks_get(struct session *s)
|
||||
{
|
||||
if (s != NULL)
|
||||
return (s->hooks);
|
||||
return (global_hooks);
|
||||
}
|
||||
|
||||
struct hooks *
|
||||
hooks_create(struct hooks *parent)
|
||||
{
|
||||
struct hooks *hooks;
|
||||
|
||||
hooks = xcalloc(1, sizeof *hooks);
|
||||
RB_INIT(&hooks->tree);
|
||||
hooks->parent = parent;
|
||||
return (hooks);
|
||||
}
|
||||
|
||||
static void
|
||||
hooks_free1(struct hooks *hooks, struct hook *hook)
|
||||
{
|
||||
RB_REMOVE(hooks_tree, &hooks->tree, hook);
|
||||
cmd_list_free(hook->cmdlist);
|
||||
free((char *)hook->name);
|
||||
free(hook);
|
||||
}
|
||||
|
||||
void
|
||||
hooks_free(struct hooks *hooks)
|
||||
{
|
||||
struct hook *hook, *hook1;
|
||||
|
||||
RB_FOREACH_SAFE(hook, hooks_tree, &hooks->tree, hook1)
|
||||
hooks_free1(hooks, hook);
|
||||
free(hooks);
|
||||
}
|
||||
|
||||
struct hook *
|
||||
hooks_first(struct hooks *hooks)
|
||||
{
|
||||
return (RB_MIN(hooks_tree, &hooks->tree));
|
||||
}
|
||||
|
||||
struct hook *
|
||||
hooks_next(struct hook *hook)
|
||||
{
|
||||
return (RB_NEXT(hooks_tree, &hooks->tree, hook));
|
||||
}
|
||||
|
||||
void
|
||||
hooks_add(struct hooks *hooks, const char *name, struct cmd_list *cmdlist)
|
||||
{
|
||||
struct hook *hook;
|
||||
|
||||
if ((hook = hooks_find1(hooks, name)) != NULL)
|
||||
hooks_free1(hooks, hook);
|
||||
|
||||
hook = xcalloc(1, sizeof *hook);
|
||||
hook->name = xstrdup(name);
|
||||
hook->cmdlist = cmdlist;
|
||||
hook->cmdlist->references++;
|
||||
RB_INSERT(hooks_tree, &hooks->tree, hook);
|
||||
}
|
||||
|
||||
void
|
||||
hooks_remove(struct hooks *hooks, const char *name)
|
||||
{
|
||||
struct hook *hook;
|
||||
|
||||
if ((hook = hooks_find1(hooks, name)) != NULL)
|
||||
hooks_free1(hooks, hook);
|
||||
}
|
||||
|
||||
static struct hook *
|
||||
hooks_find1(struct hooks *hooks, const char *name)
|
||||
{
|
||||
struct hook hook;
|
||||
|
||||
hook.name = name;
|
||||
return (RB_FIND(hooks_tree, &hooks->tree, &hook));
|
||||
}
|
||||
|
||||
struct hook *
|
||||
hooks_find(struct hooks *hooks, const char *name)
|
||||
{
|
||||
struct hook hook0, *hook;
|
||||
|
||||
hook0.name = name;
|
||||
hook = RB_FIND(hooks_tree, &hooks->tree, &hook0);
|
||||
while (hook == NULL) {
|
||||
hooks = hooks->parent;
|
||||
if (hooks == NULL)
|
||||
break;
|
||||
hook = RB_FIND(hooks_tree, &hooks->tree, &hook0);
|
||||
}
|
||||
return (hook);
|
||||
}
|
||||
|
||||
void
|
||||
hooks_insert(struct hooks *hooks, struct cmdq_item *item,
|
||||
struct cmd_find_state *fs, const char *fmt, ...)
|
||||
{
|
||||
struct hook *hook;
|
||||
va_list ap;
|
||||
char *name;
|
||||
struct cmdq_item *new_item;
|
||||
|
||||
if (item->flags & CMDQ_NOHOOKS)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&name, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
hook = hooks_find(hooks, name);
|
||||
if (hook == NULL) {
|
||||
free(name);
|
||||
return;
|
||||
}
|
||||
log_debug("running hook %s (parent %p)", name, item);
|
||||
|
||||
new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS);
|
||||
cmdq_format(new_item, "hook", "%s", name);
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item);
|
||||
else
|
||||
cmdq_append(NULL, new_item);
|
||||
|
||||
free(name);
|
||||
}
|
||||
@@ -247,10 +247,10 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
|
||||
|
||||
if ((mode & ALL_MOUSE_MODES) == 0)
|
||||
return;
|
||||
if (!window_pane_visible(wp))
|
||||
return;
|
||||
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
|
||||
return;
|
||||
if (!window_pane_visible(wp))
|
||||
return;
|
||||
|
||||
/* If this pane is not in button or all mode, discard motion events. */
|
||||
if (MOUSE_DRAG(m->b) &&
|
||||
|
||||
436
input.c
436
input.c
@@ -30,7 +30,7 @@
|
||||
/*
|
||||
* Based on the description by Paul Williams at:
|
||||
*
|
||||
* http://vt100.net/emu/dec_ansi_parser
|
||||
* https://vt100.net/emu/dec_ansi_parser
|
||||
*
|
||||
* With the following changes:
|
||||
*
|
||||
@@ -81,6 +81,7 @@ struct input_ctx {
|
||||
struct input_cell old_cell;
|
||||
u_int old_cx;
|
||||
u_int old_cy;
|
||||
int old_mode;
|
||||
|
||||
u_char interm_buf[4];
|
||||
size_t interm_len;
|
||||
@@ -93,6 +94,10 @@ struct input_ctx {
|
||||
u_char *input_buf;
|
||||
size_t input_len;
|
||||
size_t input_space;
|
||||
enum {
|
||||
INPUT_END_ST,
|
||||
INPUT_END_BEL
|
||||
} input_end;
|
||||
|
||||
struct input_param param_list[24];
|
||||
u_int param_list_len;
|
||||
@@ -126,11 +131,11 @@ static void input_set_state(struct window_pane *,
|
||||
const struct input_transition *);
|
||||
static void input_reset_cell(struct input_ctx *);
|
||||
|
||||
static void input_osc_4(struct window_pane *, const char *);
|
||||
static void input_osc_10(struct window_pane *, const char *);
|
||||
static void input_osc_11(struct window_pane *, const char *);
|
||||
static void input_osc_52(struct window_pane *, const char *);
|
||||
static void input_osc_104(struct window_pane *, const char *);
|
||||
static void input_osc_4(struct input_ctx *, const char *);
|
||||
static void input_osc_10(struct input_ctx *, const char *);
|
||||
static void input_osc_11(struct input_ctx *, const char *);
|
||||
static void input_osc_52(struct input_ctx *, const char *);
|
||||
static void input_osc_104(struct input_ctx *, const char *);
|
||||
|
||||
/* Transition entry/exit handlers. */
|
||||
static void input_clear(struct input_ctx *);
|
||||
@@ -161,6 +166,7 @@ static void input_csi_dispatch_sgr_rgb(struct input_ctx *, int, u_int *);
|
||||
static void input_csi_dispatch_sgr(struct input_ctx *);
|
||||
static int input_dcs_dispatch(struct input_ctx *);
|
||||
static int input_top_bit_set(struct input_ctx *);
|
||||
static int input_end_bel(struct input_ctx *);
|
||||
|
||||
/* Command table comparison function. */
|
||||
static int input_table_compare(const void *, const void *);
|
||||
@@ -266,6 +272,7 @@ static const struct input_table_entry input_csi_table[] = {
|
||||
{ 'S', "", INPUT_CSI_SU },
|
||||
{ 'X', "", INPUT_CSI_ECH },
|
||||
{ 'Z', "", INPUT_CSI_CBT },
|
||||
{ '`', "", INPUT_CSI_HPA },
|
||||
{ 'b', "", INPUT_CSI_REP },
|
||||
{ 'c', "", INPUT_CSI_DA },
|
||||
{ 'c', ">", INPUT_CSI_DA_TWO },
|
||||
@@ -487,7 +494,7 @@ static const struct input_transition input_state_esc_enter_table[] = {
|
||||
{ -1, -1, NULL, NULL }
|
||||
};
|
||||
|
||||
/* esc_interm state table. */
|
||||
/* esc_intermediate state table. */
|
||||
static const struct input_transition input_state_esc_intermediate_table[] = {
|
||||
INPUT_STATE_ANYWHERE,
|
||||
|
||||
@@ -602,7 +609,7 @@ static const struct input_transition input_state_dcs_parameter_table[] = {
|
||||
{ -1, -1, NULL, NULL }
|
||||
};
|
||||
|
||||
/* dcs_interm state table. */
|
||||
/* dcs_intermediate state table. */
|
||||
static const struct input_transition input_state_dcs_intermediate_table[] = {
|
||||
INPUT_STATE_ANYWHERE,
|
||||
|
||||
@@ -655,12 +662,12 @@ static const struct input_transition input_state_dcs_ignore_table[] = {
|
||||
static const struct input_transition input_state_osc_string_table[] = {
|
||||
INPUT_STATE_ANYWHERE,
|
||||
|
||||
{ 0x00, 0x06, NULL, NULL },
|
||||
{ 0x07, 0x07, NULL, &input_state_ground },
|
||||
{ 0x08, 0x17, NULL, NULL },
|
||||
{ 0x19, 0x19, NULL, NULL },
|
||||
{ 0x1c, 0x1f, NULL, NULL },
|
||||
{ 0x20, 0xff, input_input, NULL },
|
||||
{ 0x00, 0x06, NULL, NULL },
|
||||
{ 0x07, 0x07, input_end_bel, &input_state_ground },
|
||||
{ 0x08, 0x17, NULL, NULL },
|
||||
{ 0x19, 0x19, NULL, NULL },
|
||||
{ 0x1c, 0x1f, NULL, NULL },
|
||||
{ 0x20, 0xff, input_input, NULL },
|
||||
|
||||
{ -1, -1, NULL, NULL }
|
||||
};
|
||||
@@ -750,6 +757,32 @@ input_reset_cell(struct input_ctx *ictx)
|
||||
ictx->old_cy = 0;
|
||||
}
|
||||
|
||||
/* Save screen state. */
|
||||
static void
|
||||
input_save_state(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct screen *s = sctx->s;
|
||||
|
||||
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
|
||||
ictx->old_cx = s->cx;
|
||||
ictx->old_cy = s->cy;
|
||||
ictx->old_mode = s->mode;
|
||||
}
|
||||
|
||||
static void
|
||||
input_restore_state(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
|
||||
memcpy(&ictx->cell, &ictx->old_cell, sizeof ictx->cell);
|
||||
if (ictx->old_mode & MODE_ORIGIN)
|
||||
screen_write_mode_set(sctx, MODE_ORIGIN);
|
||||
else
|
||||
screen_write_mode_clear(sctx, MODE_ORIGIN);
|
||||
screen_write_cursormove(sctx, ictx->old_cx, ictx->old_cy, 0);
|
||||
}
|
||||
|
||||
/* Initialise input parser. */
|
||||
void
|
||||
input_init(struct window_pane *wp)
|
||||
@@ -762,6 +795,8 @@ input_init(struct window_pane *wp)
|
||||
ictx->input_buf = xmalloc(INPUT_BUF_START);
|
||||
|
||||
ictx->since_ground = evbuffer_new();
|
||||
if (ictx->since_ground == NULL)
|
||||
fatalx("out of memory");
|
||||
|
||||
evtimer_set(&ictx->timer, input_timer_callback, ictx);
|
||||
|
||||
@@ -794,16 +829,17 @@ void
|
||||
input_reset(struct window_pane *wp, int clear)
|
||||
{
|
||||
struct input_ctx *ictx = wp->ictx;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
|
||||
input_reset_cell(ictx);
|
||||
|
||||
if (clear) {
|
||||
if (wp->mode == NULL)
|
||||
screen_write_start(&ictx->ctx, wp, &wp->base);
|
||||
if (TAILQ_EMPTY(&wp->modes))
|
||||
screen_write_start(sctx, wp, &wp->base);
|
||||
else
|
||||
screen_write_start(&ictx->ctx, NULL, &wp->base);
|
||||
screen_write_reset(&ictx->ctx);
|
||||
screen_write_stop(&ictx->ctx);
|
||||
screen_write_start(sctx, NULL, &wp->base);
|
||||
screen_write_reset(sctx);
|
||||
screen_write_stop(sctx);
|
||||
}
|
||||
|
||||
input_clear(ictx);
|
||||
@@ -838,34 +874,38 @@ input_set_state(struct window_pane *wp, const struct input_transition *itr)
|
||||
void
|
||||
input_parse(struct window_pane *wp)
|
||||
{
|
||||
struct input_ctx *ictx = wp->ictx;
|
||||
const struct input_transition *itr;
|
||||
struct evbuffer *evb = wp->event->input;
|
||||
u_char *buf;
|
||||
size_t len, off;
|
||||
struct evbuffer *evb = wp->event->input;
|
||||
|
||||
if (EVBUFFER_LENGTH(evb) == 0)
|
||||
input_parse_buffer(wp, EVBUFFER_DATA(evb), EVBUFFER_LENGTH(evb));
|
||||
evbuffer_drain(evb, EVBUFFER_LENGTH(evb));
|
||||
}
|
||||
|
||||
/* Parse given input. */
|
||||
void
|
||||
input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
|
||||
{
|
||||
struct input_ctx *ictx = wp->ictx;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
const struct input_transition *itr;
|
||||
size_t off = 0;
|
||||
|
||||
if (len == 0)
|
||||
return;
|
||||
|
||||
window_update_activity(wp->window);
|
||||
wp->flags |= PANE_CHANGED;
|
||||
notify_input(wp, buf, len);
|
||||
|
||||
/*
|
||||
* Open the screen. Use NULL wp if there is a mode set as don't want to
|
||||
* update the tty.
|
||||
*/
|
||||
if (wp->mode == NULL)
|
||||
screen_write_start(&ictx->ctx, wp, &wp->base);
|
||||
if (TAILQ_EMPTY(&wp->modes))
|
||||
screen_write_start(sctx, wp, &wp->base);
|
||||
else
|
||||
screen_write_start(&ictx->ctx, NULL, &wp->base);
|
||||
screen_write_start(sctx, NULL, &wp->base);
|
||||
ictx->wp = wp;
|
||||
|
||||
buf = EVBUFFER_DATA(evb);
|
||||
len = EVBUFFER_LENGTH(evb);
|
||||
off = 0;
|
||||
|
||||
notify_input(wp, evb);
|
||||
|
||||
log_debug("%s: %%%u %s, %zu bytes: %.*s", __func__, wp->id,
|
||||
ictx->state->name, len, (int)len, buf);
|
||||
|
||||
@@ -893,7 +933,7 @@ input_parse(struct window_pane *wp)
|
||||
* be the minority.
|
||||
*/
|
||||
if (itr->handler != input_print)
|
||||
screen_write_collect_end(&ictx->ctx);
|
||||
screen_write_collect_end(sctx);
|
||||
|
||||
/*
|
||||
* Execute the handler, if any. Don't switch state if it
|
||||
@@ -912,9 +952,7 @@ input_parse(struct window_pane *wp)
|
||||
}
|
||||
|
||||
/* Close the screen. */
|
||||
screen_write_stop(&ictx->ctx);
|
||||
|
||||
evbuffer_drain(evb, len);
|
||||
screen_write_stop(sctx);
|
||||
}
|
||||
|
||||
/* Split the parameter list (if any). */
|
||||
@@ -993,8 +1031,8 @@ input_get(struct input_ctx *ictx, u_int validx, int minval, int defval)
|
||||
static void
|
||||
input_reply(struct input_ctx *ictx, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char *reply;
|
||||
va_list ap;
|
||||
char *reply;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&reply, fmt, ap);
|
||||
@@ -1019,6 +1057,8 @@ input_clear(struct input_ctx *ictx)
|
||||
*ictx->input_buf = '\0';
|
||||
ictx->input_len = 0;
|
||||
|
||||
ictx->input_end = INPUT_END_ST;
|
||||
|
||||
ictx->flags &= ~INPUT_DISCARD;
|
||||
}
|
||||
|
||||
@@ -1039,7 +1079,8 @@ input_ground(struct input_ctx *ictx)
|
||||
static int
|
||||
input_print(struct input_ctx *ictx)
|
||||
{
|
||||
int set;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
int set;
|
||||
|
||||
ictx->utf8started = 0; /* can't be valid UTF-8 */
|
||||
|
||||
@@ -1050,7 +1091,7 @@ input_print(struct input_ctx *ictx)
|
||||
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;
|
||||
|
||||
utf8_set(&ictx->cell.cell.data, ictx->ch);
|
||||
screen_write_collect_add(&ictx->ctx, &ictx->cell.cell);
|
||||
screen_write_collect_add(sctx, &ictx->cell.cell);
|
||||
ictx->last = ictx->ch;
|
||||
|
||||
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;
|
||||
@@ -1145,6 +1186,8 @@ input_c0_dispatch(struct input_ctx *ictx)
|
||||
case '\013': /* VT */
|
||||
case '\014': /* FF */
|
||||
screen_write_linefeed(sctx, 0, ictx->cell.cell.bg);
|
||||
if (s->mode & MODE_CRLF)
|
||||
screen_write_carriagereturn(sctx);
|
||||
break;
|
||||
case '\015': /* CR */
|
||||
screen_write_carriagereturn(sctx);
|
||||
@@ -1210,13 +1253,10 @@ input_esc_dispatch(struct input_ctx *ictx)
|
||||
screen_write_mode_clear(sctx, MODE_KKEYPAD);
|
||||
break;
|
||||
case INPUT_ESC_DECSC:
|
||||
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
|
||||
ictx->old_cx = s->cx;
|
||||
ictx->old_cy = s->cy;
|
||||
input_save_state(ictx);
|
||||
break;
|
||||
case INPUT_ESC_DECRC:
|
||||
memcpy(&ictx->cell, &ictx->old_cell, sizeof ictx->cell);
|
||||
screen_write_cursormove(sctx, ictx->old_cx, ictx->old_cy);
|
||||
input_restore_state(ictx);
|
||||
break;
|
||||
case INPUT_ESC_DECALN:
|
||||
screen_write_alignmenttest(sctx);
|
||||
@@ -1303,7 +1343,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
n = input_get(ictx, 0, 1, 1);
|
||||
m = input_get(ictx, 1, 1, 1);
|
||||
if (n != -1 && m != -1)
|
||||
screen_write_cursormove(sctx, m - 1, n - 1);
|
||||
screen_write_cursormove(sctx, m - 1, n - 1, 1);
|
||||
break;
|
||||
case INPUT_CSI_WINOPS:
|
||||
input_csi_dispatch_winops(ictx);
|
||||
@@ -1435,7 +1475,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
case INPUT_CSI_HPA:
|
||||
n = input_get(ictx, 0, 1, 1);
|
||||
if (n != -1)
|
||||
screen_write_cursormove(sctx, n - 1, s->cy);
|
||||
screen_write_cursormove(sctx, n - 1, -1, 1);
|
||||
break;
|
||||
case INPUT_CSI_ICH:
|
||||
n = input_get(ictx, 0, 1, 1);
|
||||
@@ -1460,8 +1500,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
input_print(ictx);
|
||||
break;
|
||||
case INPUT_CSI_RCP:
|
||||
memcpy(&ictx->cell, &ictx->old_cell, sizeof ictx->cell);
|
||||
screen_write_cursormove(sctx, ictx->old_cx, ictx->old_cy);
|
||||
input_restore_state(ictx);
|
||||
break;
|
||||
case INPUT_CSI_RM:
|
||||
input_csi_dispatch_rm(ictx);
|
||||
@@ -1470,9 +1509,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
input_csi_dispatch_rm_private(ictx);
|
||||
break;
|
||||
case INPUT_CSI_SCP:
|
||||
memcpy(&ictx->old_cell, &ictx->cell, sizeof ictx->old_cell);
|
||||
ictx->old_cx = s->cx;
|
||||
ictx->old_cy = s->cy;
|
||||
input_save_state(ictx);
|
||||
break;
|
||||
case INPUT_CSI_SGR:
|
||||
input_csi_dispatch_sgr(ictx);
|
||||
@@ -1507,7 +1544,7 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
case INPUT_CSI_VPA:
|
||||
n = input_get(ictx, 0, 1, 1);
|
||||
if (n != -1)
|
||||
screen_write_cursormove(sctx, s->cx, n - 1);
|
||||
screen_write_cursormove(sctx, -1, n - 1, 1);
|
||||
break;
|
||||
case INPUT_CSI_DECSCUSR:
|
||||
n = input_get(ictx, 0, 0, 0);
|
||||
@@ -1524,17 +1561,18 @@ input_csi_dispatch(struct input_ctx *ictx)
|
||||
static void
|
||||
input_csi_dispatch_rm(struct input_ctx *ictx)
|
||||
{
|
||||
u_int i;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ictx->param_list_len; i++) {
|
||||
switch (input_get(ictx, i, 0, -1)) {
|
||||
case -1:
|
||||
break;
|
||||
case 4: /* IRM */
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_INSERT);
|
||||
screen_write_mode_clear(sctx, MODE_INSERT);
|
||||
break;
|
||||
case 34:
|
||||
screen_write_mode_set(&ictx->ctx, MODE_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_BLINKING);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1547,6 +1585,7 @@ input_csi_dispatch_rm(struct input_ctx *ictx)
|
||||
static void
|
||||
input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
u_int i;
|
||||
|
||||
@@ -1555,36 +1594,39 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
||||
case -1:
|
||||
break;
|
||||
case 1: /* DECCKM */
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR);
|
||||
screen_write_mode_clear(sctx, MODE_KCURSOR);
|
||||
break;
|
||||
case 3: /* DECCOLM */
|
||||
screen_write_cursormove(&ictx->ctx, 0, 0);
|
||||
screen_write_clearscreen(&ictx->ctx,
|
||||
ictx->cell.cell.bg);
|
||||
screen_write_cursormove(sctx, 0, 0, 1);
|
||||
screen_write_clearscreen(sctx, ictx->cell.cell.bg);
|
||||
break;
|
||||
case 6: /* DECOM */
|
||||
screen_write_mode_clear(sctx, MODE_ORIGIN);
|
||||
screen_write_cursormove(sctx, 0, 0, 1);
|
||||
break;
|
||||
case 7: /* DECAWM */
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_WRAP);
|
||||
screen_write_mode_clear(sctx, MODE_WRAP);
|
||||
break;
|
||||
case 12:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_BLINKING);
|
||||
screen_write_mode_clear(sctx, MODE_BLINKING);
|
||||
break;
|
||||
case 25: /* TCEM */
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_CURSOR);
|
||||
screen_write_mode_clear(sctx, MODE_CURSOR);
|
||||
break;
|
||||
case 1000:
|
||||
case 1001:
|
||||
case 1002:
|
||||
case 1003:
|
||||
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
|
||||
break;
|
||||
case 1004:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_FOCUSON);
|
||||
screen_write_mode_clear(sctx, MODE_FOCUSON);
|
||||
break;
|
||||
case 1005:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_UTF8);
|
||||
screen_write_mode_clear(sctx, MODE_MOUSE_UTF8);
|
||||
break;
|
||||
case 1006:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_SGR);
|
||||
screen_write_mode_clear(sctx, MODE_MOUSE_SGR);
|
||||
break;
|
||||
case 47:
|
||||
case 1047:
|
||||
@@ -1594,7 +1636,7 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
||||
window_pane_alternate_off(wp, &ictx->cell.cell, 1);
|
||||
break;
|
||||
case 2004:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_BRACKETPASTE);
|
||||
screen_write_mode_clear(sctx, MODE_BRACKETPASTE);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1607,17 +1649,18 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
|
||||
static void
|
||||
input_csi_dispatch_sm(struct input_ctx *ictx)
|
||||
{
|
||||
u_int i;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < ictx->param_list_len; i++) {
|
||||
switch (input_get(ictx, i, 0, -1)) {
|
||||
case -1:
|
||||
break;
|
||||
case 4: /* IRM */
|
||||
screen_write_mode_set(&ictx->ctx, MODE_INSERT);
|
||||
screen_write_mode_set(sctx, MODE_INSERT);
|
||||
break;
|
||||
case 34:
|
||||
screen_write_mode_clear(&ictx->ctx, MODE_BLINKING);
|
||||
screen_write_mode_clear(sctx, MODE_BLINKING);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1630,6 +1673,7 @@ input_csi_dispatch_sm(struct input_ctx *ictx)
|
||||
static void
|
||||
input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
u_int i;
|
||||
|
||||
@@ -1638,45 +1682,48 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
case -1:
|
||||
break;
|
||||
case 1: /* DECCKM */
|
||||
screen_write_mode_set(&ictx->ctx, MODE_KCURSOR);
|
||||
screen_write_mode_set(sctx, MODE_KCURSOR);
|
||||
break;
|
||||
case 3: /* DECCOLM */
|
||||
screen_write_cursormove(&ictx->ctx, 0, 0);
|
||||
screen_write_clearscreen(&ictx->ctx,
|
||||
ictx->cell.cell.bg);
|
||||
screen_write_cursormove(sctx, 0, 0, 1);
|
||||
screen_write_clearscreen(sctx, ictx->cell.cell.bg);
|
||||
break;
|
||||
case 6: /* DECOM */
|
||||
screen_write_mode_set(sctx, MODE_ORIGIN);
|
||||
screen_write_cursormove(sctx, 0, 0, 1);
|
||||
break;
|
||||
case 7: /* DECAWM */
|
||||
screen_write_mode_set(&ictx->ctx, MODE_WRAP);
|
||||
screen_write_mode_set(sctx, MODE_WRAP);
|
||||
break;
|
||||
case 12:
|
||||
screen_write_mode_set(&ictx->ctx, MODE_BLINKING);
|
||||
screen_write_mode_set(sctx, MODE_BLINKING);
|
||||
break;
|
||||
case 25: /* TCEM */
|
||||
screen_write_mode_set(&ictx->ctx, MODE_CURSOR);
|
||||
screen_write_mode_set(sctx, MODE_CURSOR);
|
||||
break;
|
||||
case 1000:
|
||||
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_STANDARD);
|
||||
screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_STANDARD);
|
||||
break;
|
||||
case 1002:
|
||||
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_BUTTON);
|
||||
screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_BUTTON);
|
||||
break;
|
||||
case 1003:
|
||||
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_ALL);
|
||||
screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_ALL);
|
||||
break;
|
||||
case 1004:
|
||||
if (ictx->ctx.s->mode & MODE_FOCUSON)
|
||||
if (sctx->s->mode & MODE_FOCUSON)
|
||||
break;
|
||||
screen_write_mode_set(&ictx->ctx, MODE_FOCUSON);
|
||||
screen_write_mode_set(sctx, MODE_FOCUSON);
|
||||
wp->flags |= PANE_FOCUSPUSH; /* force update */
|
||||
break;
|
||||
case 1005:
|
||||
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_UTF8);
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_UTF8);
|
||||
break;
|
||||
case 1006:
|
||||
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_SGR);
|
||||
screen_write_mode_set(sctx, MODE_MOUSE_SGR);
|
||||
break;
|
||||
case 47:
|
||||
case 1047:
|
||||
@@ -1686,7 +1733,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
window_pane_alternate_on(wp, &ictx->cell.cell, 1);
|
||||
break;
|
||||
case 2004:
|
||||
screen_write_mode_set(&ictx->ctx, MODE_BRACKETPASTE);
|
||||
screen_write_mode_set(sctx, MODE_BRACKETPASTE);
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%c'", __func__, ictx->ch);
|
||||
@@ -1699,6 +1746,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
|
||||
static void
|
||||
input_csi_dispatch_winops(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
int n, m;
|
||||
|
||||
@@ -1738,7 +1786,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
|
||||
return;
|
||||
case 0:
|
||||
case 2:
|
||||
screen_push_title(ictx->ctx.s);
|
||||
screen_push_title(sctx->s);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -1749,7 +1797,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
|
||||
return;
|
||||
case 0:
|
||||
case 2:
|
||||
screen_pop_title(ictx->ctx.s);
|
||||
screen_pop_title(sctx->s);
|
||||
server_status_window(ictx->wp->window);
|
||||
break;
|
||||
}
|
||||
@@ -1834,10 +1882,11 @@ input_csi_dispatch_sgr_rgb(struct input_ctx *ictx, int fgbg, u_int *i)
|
||||
static void
|
||||
input_csi_dispatch_sgr_colon(struct input_ctx *ictx, u_int i)
|
||||
{
|
||||
char *s = ictx->param_list[i].str, *copy, *ptr, *out;
|
||||
int p[8];
|
||||
u_int n;
|
||||
const char *errstr;
|
||||
struct grid_cell *gc = &ictx->cell.cell;
|
||||
char *s = ictx->param_list[i].str, *copy, *ptr, *out;
|
||||
int p[8];
|
||||
u_int n;
|
||||
const char *errstr;
|
||||
|
||||
for (n = 0; n < nitems(p); n++)
|
||||
p[n] = -1;
|
||||
@@ -1845,25 +1894,67 @@ input_csi_dispatch_sgr_colon(struct input_ctx *ictx, u_int i)
|
||||
|
||||
ptr = copy = xstrdup(s);
|
||||
while ((out = strsep(&ptr, ":")) != NULL) {
|
||||
p[n++] = strtonum(out, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL || n == nitems(p)) {
|
||||
free(copy);
|
||||
return;
|
||||
}
|
||||
if (*out != '\0') {
|
||||
p[n++] = strtonum(out, 0, INT_MAX, &errstr);
|
||||
if (errstr != NULL || n == nitems(p)) {
|
||||
free(copy);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
n++;
|
||||
log_debug("%s: %u = %d", __func__, n - 1, p[n - 1]);
|
||||
}
|
||||
free(copy);
|
||||
|
||||
if (n == 0 || (p[0] != 38 && p[0] != 48))
|
||||
if (n == 0)
|
||||
return;
|
||||
if (p[0] == 4) {
|
||||
if (n != 2)
|
||||
return;
|
||||
switch (p[1]) {
|
||||
case 0:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
break;
|
||||
case 1:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE;
|
||||
break;
|
||||
case 2:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE_2;
|
||||
break;
|
||||
case 3:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE_3;
|
||||
break;
|
||||
case 4:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE_4;
|
||||
break;
|
||||
case 5:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE_5;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (n < 2 || (p[0] != 38 && p[0] != 48))
|
||||
return;
|
||||
switch (p[1]) {
|
||||
case 2:
|
||||
if (n != 5)
|
||||
if (n < 3)
|
||||
break;
|
||||
input_csi_dispatch_sgr_rgb_do(ictx, p[0], p[2], p[3], p[4]);
|
||||
if (n == 5)
|
||||
i = 2;
|
||||
else
|
||||
i = 3;
|
||||
if (n < i + 3)
|
||||
break;
|
||||
input_csi_dispatch_sgr_rgb_do(ictx, p[0], p[i], p[i + 1],
|
||||
p[i + 2]);
|
||||
break;
|
||||
case 5:
|
||||
if (n != 3)
|
||||
if (n < 3)
|
||||
break;
|
||||
input_csi_dispatch_sgr_256_do(ictx, p[0], p[2]);
|
||||
break;
|
||||
@@ -1919,6 +2010,7 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
||||
gc->attr |= GRID_ATTR_ITALICS;
|
||||
break;
|
||||
case 4:
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
gc->attr |= GRID_ATTR_UNDERSCORE;
|
||||
break;
|
||||
case 5:
|
||||
@@ -1940,7 +2032,7 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
||||
gc->attr &= ~GRID_ATTR_ITALICS;
|
||||
break;
|
||||
case 24:
|
||||
gc->attr &= ~GRID_ATTR_UNDERSCORE;
|
||||
gc->attr &= ~GRID_ATTR_ALL_UNDERSCORE;
|
||||
break;
|
||||
case 25:
|
||||
gc->attr &= ~GRID_ATTR_BLINK;
|
||||
@@ -1980,6 +2072,12 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
||||
case 49:
|
||||
gc->bg = 8;
|
||||
break;
|
||||
case 53:
|
||||
gc->attr |= GRID_ATTR_OVERLINE;
|
||||
break;
|
||||
case 55:
|
||||
gc->attr &= ~GRID_ATTR_OVERLINE;
|
||||
break;
|
||||
case 90:
|
||||
case 91:
|
||||
case 92:
|
||||
@@ -2004,6 +2102,17 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
|
||||
}
|
||||
}
|
||||
|
||||
/* End of input with BEL. */
|
||||
static int
|
||||
input_end_bel(struct input_ctx *ictx)
|
||||
{
|
||||
log_debug("%s", __func__);
|
||||
|
||||
ictx->input_end = INPUT_END_BEL;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* DCS string started. */
|
||||
static void
|
||||
input_enter_dcs(struct input_ctx *ictx)
|
||||
@@ -2019,20 +2128,19 @@ input_enter_dcs(struct input_ctx *ictx)
|
||||
static int
|
||||
input_dcs_dispatch(struct input_ctx *ictx)
|
||||
{
|
||||
const char prefix[] = "tmux;";
|
||||
const u_int prefix_len = (sizeof prefix) - 1;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
u_char *buf = ictx->input_buf;
|
||||
size_t len = ictx->input_len;
|
||||
const char prefix[] = "tmux;";
|
||||
const u_int prefixlen = (sizeof prefix) - 1;
|
||||
|
||||
if (ictx->flags & INPUT_DISCARD)
|
||||
return (0);
|
||||
|
||||
log_debug("%s: \"%s\"", __func__, ictx->input_buf);
|
||||
log_debug("%s: \"%s\"", __func__, buf);
|
||||
|
||||
/* Check for tmux prefix. */
|
||||
if (ictx->input_len >= prefix_len &&
|
||||
strncmp(ictx->input_buf, prefix, prefix_len) == 0) {
|
||||
screen_write_rawstring(&ictx->ctx,
|
||||
ictx->input_buf + prefix_len, ictx->input_len - prefix_len);
|
||||
}
|
||||
if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0)
|
||||
screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -2052,15 +2160,17 @@ input_enter_osc(struct input_ctx *ictx)
|
||||
static void
|
||||
input_exit_osc(struct input_ctx *ictx)
|
||||
{
|
||||
u_char *p = ictx->input_buf;
|
||||
u_int option;
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
u_char *p = ictx->input_buf;
|
||||
u_int option;
|
||||
|
||||
if (ictx->flags & INPUT_DISCARD)
|
||||
return;
|
||||
if (ictx->input_len < 1 || *p < '0' || *p > '9')
|
||||
return;
|
||||
|
||||
log_debug("%s: \"%s\"", __func__, p);
|
||||
log_debug("%s: \"%s\" (end %s)", __func__, p,
|
||||
ictx->input_end == INPUT_END_ST ? "ST" : "BEL");
|
||||
|
||||
option = 0;
|
||||
while (*p >= '0' && *p <= '9')
|
||||
@@ -2072,32 +2182,32 @@ input_exit_osc(struct input_ctx *ictx)
|
||||
case 0:
|
||||
case 2:
|
||||
if (utf8_isvalid(p)) {
|
||||
screen_set_title(ictx->ctx.s, p);
|
||||
screen_set_title(sctx->s, p);
|
||||
server_status_window(ictx->wp->window);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
input_osc_4(ictx->wp, p);
|
||||
input_osc_4(ictx, p);
|
||||
break;
|
||||
case 10:
|
||||
input_osc_10(ictx->wp, p);
|
||||
input_osc_10(ictx, p);
|
||||
break;
|
||||
case 11:
|
||||
input_osc_11(ictx->wp, p);
|
||||
input_osc_11(ictx, p);
|
||||
break;
|
||||
case 12:
|
||||
if (utf8_isvalid(p) && *p != '?') /* ? is colour request */
|
||||
screen_set_cursor_colour(ictx->ctx.s, p);
|
||||
screen_set_cursor_colour(sctx->s, p);
|
||||
break;
|
||||
case 52:
|
||||
input_osc_52(ictx->wp, p);
|
||||
input_osc_52(ictx, p);
|
||||
break;
|
||||
case 104:
|
||||
input_osc_104(ictx->wp, p);
|
||||
input_osc_104(ictx, p);
|
||||
break;
|
||||
case 112:
|
||||
if (*p == '\0') /* no arguments allowed */
|
||||
screen_set_cursor_colour(ictx->ctx.s, "");
|
||||
screen_set_cursor_colour(sctx->s, "");
|
||||
break;
|
||||
default:
|
||||
log_debug("%s: unknown '%u'", __func__, option);
|
||||
@@ -2120,13 +2230,15 @@ input_enter_apc(struct input_ctx *ictx)
|
||||
static void
|
||||
input_exit_apc(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
|
||||
if (ictx->flags & INPUT_DISCARD)
|
||||
return;
|
||||
log_debug("%s: \"%s\"", __func__, ictx->input_buf);
|
||||
|
||||
if (!utf8_isvalid(ictx->input_buf))
|
||||
return;
|
||||
screen_set_title(ictx->ctx.s, ictx->input_buf);
|
||||
screen_set_title(sctx->s, ictx->input_buf);
|
||||
server_status_window(ictx->wp->window);
|
||||
}
|
||||
|
||||
@@ -2162,6 +2274,7 @@ input_exit_rename(struct input_ctx *ictx)
|
||||
static int
|
||||
input_top_bit_set(struct input_ctx *ictx)
|
||||
{
|
||||
struct screen_write_ctx *sctx = &ictx->ctx;
|
||||
struct utf8_data *ud = &ictx->utf8data;
|
||||
|
||||
ictx->last = -1;
|
||||
@@ -2188,18 +2301,19 @@ input_top_bit_set(struct input_ctx *ictx)
|
||||
(int)ud->size, ud->data, ud->width);
|
||||
|
||||
utf8_copy(&ictx->cell.cell.data, ud);
|
||||
screen_write_collect_add(&ictx->ctx, &ictx->cell.cell);
|
||||
screen_write_collect_add(sctx, &ictx->cell.cell);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Handle the OSC 4 sequence for setting (multiple) palette entries. */
|
||||
static void
|
||||
input_osc_4(struct window_pane *wp, const char *p)
|
||||
input_osc_4(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
char *copy, *s, *next = NULL;
|
||||
long idx;
|
||||
u_int r, g, b;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *copy, *s, *next = NULL;
|
||||
long idx;
|
||||
u_int r, g, b;
|
||||
|
||||
copy = s = xstrdup(p);
|
||||
while (s != NULL && *s != '\0') {
|
||||
@@ -2227,16 +2341,17 @@ bad:
|
||||
free(copy);
|
||||
}
|
||||
|
||||
/* Handle the OSC 10 sequence for setting background colour. */
|
||||
/* Handle the OSC 10 sequence for setting foreground colour. */
|
||||
static void
|
||||
input_osc_10(struct window_pane *wp, const char *p)
|
||||
input_osc_10(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
u_int r, g, b;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
u_int r, g, b;
|
||||
|
||||
if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
|
||||
goto bad;
|
||||
|
||||
wp->colgc.fg = colour_join_rgb(r, g, b);
|
||||
wp->style.gc.fg = colour_join_rgb(r, g, b);
|
||||
wp->flags |= PANE_REDRAW;
|
||||
|
||||
return;
|
||||
@@ -2247,14 +2362,15 @@ bad:
|
||||
|
||||
/* Handle the OSC 11 sequence for setting background colour. */
|
||||
static void
|
||||
input_osc_11(struct window_pane *wp, const char *p)
|
||||
input_osc_11(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
u_int r, g, b;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
u_int r, g, b;
|
||||
|
||||
if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
|
||||
goto bad;
|
||||
|
||||
wp->colgc.bg = colour_join_rgb(r, g, b);
|
||||
wp->style.gc.bg = colour_join_rgb(r, g, b);
|
||||
wp->flags |= PANE_REDRAW;
|
||||
|
||||
return;
|
||||
@@ -2265,13 +2381,16 @@ bad:
|
||||
|
||||
/* Handle the OSC 52 sequence for setting the clipboard. */
|
||||
static void
|
||||
input_osc_52(struct window_pane *wp, const char *p)
|
||||
input_osc_52(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *end;
|
||||
const char *buf;
|
||||
size_t len;
|
||||
u_char *out;
|
||||
int outlen, state;
|
||||
struct screen_write_ctx ctx;
|
||||
struct paste_buffer *pb;
|
||||
|
||||
state = options_get_number(global_options, "set-clipboard");
|
||||
if (state != 2)
|
||||
@@ -2282,6 +2401,32 @@ input_osc_52(struct window_pane *wp, const char *p)
|
||||
end++;
|
||||
if (*end == '\0')
|
||||
return;
|
||||
log_debug("%s: %s", __func__, end);
|
||||
|
||||
if (strcmp(end, "?") == 0) {
|
||||
if ((pb = paste_get_top(NULL)) != NULL) {
|
||||
buf = paste_buffer_data(pb, &len);
|
||||
outlen = 4 * ((len + 2) / 3) + 1;
|
||||
out = xmalloc(outlen);
|
||||
if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
|
||||
abort();
|
||||
free(out);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
outlen = 0;
|
||||
out = NULL;
|
||||
}
|
||||
bufferevent_write(wp->event, "\033]52;;", 6);
|
||||
if (outlen != 0)
|
||||
bufferevent_write(wp->event, out, outlen);
|
||||
if (ictx->input_end == INPUT_END_BEL)
|
||||
bufferevent_write(wp->event, "\007", 1);
|
||||
else
|
||||
bufferevent_write(wp->event, "\033\\", 2);
|
||||
free(out);
|
||||
return;
|
||||
}
|
||||
|
||||
len = (strlen(end) / 4) * 3;
|
||||
if (len == 0)
|
||||
@@ -2298,15 +2443,16 @@ input_osc_52(struct window_pane *wp, const char *p)
|
||||
screen_write_stop(&ctx);
|
||||
notify_pane("pane-set-clipboard", wp);
|
||||
|
||||
paste_add(out, outlen);
|
||||
paste_add(NULL, out, outlen);
|
||||
}
|
||||
|
||||
/* Handle the OSC 104 sequence for unsetting (multiple) palette entries. */
|
||||
static void
|
||||
input_osc_104(struct window_pane *wp, const char *p)
|
||||
input_osc_104(struct input_ctx *ictx, const char *p)
|
||||
{
|
||||
char *copy, *s;
|
||||
long idx;
|
||||
struct window_pane *wp = ictx->wp;
|
||||
char *copy, *s;
|
||||
long idx;
|
||||
|
||||
if (*p == '\0') {
|
||||
window_pane_reset_palette(wp);
|
||||
|
||||
104
job.c
104
job.c
@@ -36,8 +36,33 @@ static void job_read_callback(struct bufferevent *, void *);
|
||||
static void job_write_callback(struct bufferevent *, void *);
|
||||
static void job_error_callback(struct bufferevent *, short, void *);
|
||||
|
||||
/* A single job. */
|
||||
struct job {
|
||||
enum {
|
||||
JOB_RUNNING,
|
||||
JOB_DEAD,
|
||||
JOB_CLOSED
|
||||
} state;
|
||||
|
||||
int flags;
|
||||
|
||||
char *cmd;
|
||||
pid_t pid;
|
||||
int status;
|
||||
|
||||
int fd;
|
||||
struct bufferevent *event;
|
||||
|
||||
job_update_cb updatecb;
|
||||
job_complete_cb completecb;
|
||||
job_free_cb freecb;
|
||||
void *data;
|
||||
|
||||
LIST_ENTRY(job) entry;
|
||||
};
|
||||
|
||||
/* All jobs list. */
|
||||
struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
static LIST_HEAD(joblist, job) all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
|
||||
/* Start a job running, if it isn't already. */
|
||||
struct job *
|
||||
@@ -54,6 +79,7 @@ job_run(const char *cmd, struct session *s, const char *cwd,
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
|
||||
return (NULL);
|
||||
log_debug("%s: cmd=%s, cwd=%s", __func__, cmd, cwd == NULL ? "" : cwd);
|
||||
|
||||
/*
|
||||
* Do not set TERM during .tmux.conf, it is nice to be able to use
|
||||
@@ -128,6 +154,8 @@ job_run(const char *cmd, struct session *s, const char *cwd,
|
||||
|
||||
job->event = bufferevent_new(job->fd, job_read_callback,
|
||||
job_write_callback, job_error_callback, job);
|
||||
if (job->event == NULL)
|
||||
fatalx("out of memory");
|
||||
bufferevent_enable(job->event, EV_READ|EV_WRITE);
|
||||
|
||||
log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
|
||||
@@ -207,8 +235,16 @@ job_error_callback(__unused struct bufferevent *bufev, __unused short events,
|
||||
|
||||
/* Job died (waitpid() returned its pid). */
|
||||
void
|
||||
job_died(struct job *job, int status)
|
||||
job_check_died(pid_t pid, int status)
|
||||
{
|
||||
struct job *job;
|
||||
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if (pid == job->pid)
|
||||
break;
|
||||
}
|
||||
if (job == NULL)
|
||||
return;
|
||||
log_debug("job died %p: %s, pid %ld", job, job->cmd, (long) job->pid);
|
||||
|
||||
job->status = status;
|
||||
@@ -222,3 +258,67 @@ job_died(struct job *job, int status)
|
||||
job->state = JOB_DEAD;
|
||||
}
|
||||
}
|
||||
|
||||
/* Get job status. */
|
||||
int
|
||||
job_get_status(struct job *job)
|
||||
{
|
||||
return (job->status);
|
||||
}
|
||||
|
||||
/* Get job data. */
|
||||
void *
|
||||
job_get_data(struct job *job)
|
||||
{
|
||||
return (job->data);
|
||||
}
|
||||
|
||||
/* Get job event. */
|
||||
struct bufferevent *
|
||||
job_get_event(struct job *job)
|
||||
{
|
||||
return (job->event);
|
||||
}
|
||||
|
||||
/* Kill all jobs. */
|
||||
void
|
||||
job_kill_all(void)
|
||||
{
|
||||
struct job *job;
|
||||
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if (job->pid != -1)
|
||||
kill(job->pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
|
||||
/* Are any jobs still running? */
|
||||
int
|
||||
job_still_running(void)
|
||||
{
|
||||
struct job *job;
|
||||
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if ((~job->flags & JOB_NOWAIT) && job->state == JOB_RUNNING)
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Print job summary. */
|
||||
void
|
||||
job_print_summary(struct cmdq_item *item, int blank)
|
||||
{
|
||||
struct job *job;
|
||||
u_int n = 0;
|
||||
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if (blank) {
|
||||
cmdq_print(item, "%s", "");
|
||||
blank = 0;
|
||||
}
|
||||
cmdq_print(item, "Job %u: %s [fd=%d, pid=%ld, status=%d]",
|
||||
n, job->cmd, job->fd, (long)job->pid, job->status);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
145
key-bindings.c
145
key-bindings.c
@@ -24,17 +24,65 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
RB_GENERATE(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||
RB_GENERATE(key_tables, key_table, entry, key_table_cmp);
|
||||
struct key_tables key_tables = RB_INITIALIZER(&key_tables);
|
||||
#define DEFAULT_CLIENT_MENU \
|
||||
" 'Detach' 'd' {detach-client}" \
|
||||
" 'Detach & Kill' 'X' {detach-client -P}" \
|
||||
" 'Detach Others' 'o' {detach-client -a}" \
|
||||
" ''" \
|
||||
" 'Lock' 'l' {lock-client}"
|
||||
#define DEFAULT_SESSION_MENU \
|
||||
" 'Next' 'n' {switch-client -n}" \
|
||||
" 'Previous' 'p' {switch-client -p}" \
|
||||
" ''" \
|
||||
" 'Renumber' 'N' {move-window -r}" \
|
||||
" 'Rename' 'n' {command-prompt -I \"#S\" \"rename-session -- '%%'\"}" \
|
||||
" ''" \
|
||||
" 'New Session' 's' {new-session}" \
|
||||
" 'New Window' 'w' {new-window}"
|
||||
#define DEFAULT_WINDOW_MENU \
|
||||
" 'Swap Left' 'l' {swap-window -t:-1}" \
|
||||
" 'Swap Right' 'r' {swap-window -t:+1}" \
|
||||
" '#{?pane_marked_set,,-}Swap Marked' 's' {swap-window}" \
|
||||
" ''" \
|
||||
" 'Kill' 'X' {kill-window}" \
|
||||
" 'Respawn' 'R' {respawn-window -k}" \
|
||||
" '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
|
||||
" 'Rename' 'n' {command-prompt -I \"#W\" \"rename-window -- '%%'\"}" \
|
||||
" ''" \
|
||||
" 'New After' 'w' {new-window -a}" \
|
||||
" 'New At End' 'W' {new-window}"
|
||||
#define DEFAULT_PANE_MENU \
|
||||
" '#{?mouse_word,Search For #[underscore]#{=/9/...:mouse_word},}' 'C-r' {copy-mode -t=; send -Xt= search-backward \"#{q:mouse_word}\"}" \
|
||||
" '#{?mouse_word,Type #[underscore]#{=/9/...:mouse_word},}' 'C-y' {send-keys -l -- \"#{q:mouse_word}\"}" \
|
||||
" '#{?mouse_word,Copy #[underscore]#{=/9/...:mouse_word},}' 'c' {set-buffer -- \"#{q:mouse_word}\"}" \
|
||||
" '#{?mouse_line,Copy Line,}' 'l' {set-buffer -- \"#{q:mouse_line}\"}" \
|
||||
" ''" \
|
||||
" 'Horizontal Split' 'h' {split-window -h}" \
|
||||
" 'Vertical Split' 'v' {split-window -v}" \
|
||||
" ''" \
|
||||
" 'Swap Up' 'u' {swap-pane -U}" \
|
||||
" 'Swap Down' 'd' {swap-pane -D}" \
|
||||
" '#{?pane_marked_set,,-}Swap Marked' 's' {swap-pane}" \
|
||||
" ''" \
|
||||
" 'Kill' 'X' {kill-pane}" \
|
||||
" 'Respawn' 'R' {respawn-pane -k}" \
|
||||
" '#{?pane_marked,Unmark,Mark}' 'm' {select-pane -m}" \
|
||||
" '#{?window_zoomed_flag,Unzoom,Zoom}' 'z' {resize-pane -Z}"
|
||||
|
||||
int
|
||||
key_table_cmp(struct key_table *e1, struct key_table *e2)
|
||||
|
||||
static int key_bindings_cmp(struct key_binding *, struct key_binding *);
|
||||
RB_GENERATE_STATIC(key_bindings, key_binding, entry, key_bindings_cmp);
|
||||
static int key_table_cmp(struct key_table *, struct key_table *);
|
||||
RB_GENERATE_STATIC(key_tables, key_table, entry, key_table_cmp);
|
||||
static struct key_tables key_tables = RB_INITIALIZER(&key_tables);
|
||||
|
||||
static int
|
||||
key_table_cmp(struct key_table *table1, struct key_table *table2)
|
||||
{
|
||||
return (strcmp(e1->name, e2->name));
|
||||
return (strcmp(table1->name, table2->name));
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
key_bindings_cmp(struct key_binding *bd1, struct key_binding *bd2)
|
||||
{
|
||||
if (bd1->key < bd2->key)
|
||||
@@ -64,6 +112,18 @@ key_bindings_get_table(const char *name, int create)
|
||||
return (table);
|
||||
}
|
||||
|
||||
struct key_table *
|
||||
key_bindings_first_table(void)
|
||||
{
|
||||
return (RB_MIN(key_tables, &key_tables));
|
||||
}
|
||||
|
||||
struct key_table *
|
||||
key_bindings_next_table(struct key_table *table)
|
||||
{
|
||||
return (RB_NEXT(key_tables, &key_tables, table));
|
||||
}
|
||||
|
||||
void
|
||||
key_bindings_unref_table(struct key_table *table)
|
||||
{
|
||||
@@ -83,6 +143,27 @@ key_bindings_unref_table(struct key_table *table)
|
||||
free(table);
|
||||
}
|
||||
|
||||
struct key_binding *
|
||||
key_bindings_get(struct key_table *table, key_code key)
|
||||
{
|
||||
struct key_binding bd;
|
||||
|
||||
bd.key = key;
|
||||
return (RB_FIND(key_bindings, &table->key_bindings, &bd));
|
||||
}
|
||||
|
||||
struct key_binding *
|
||||
key_bindings_first(struct key_table *table)
|
||||
{
|
||||
return (RB_MIN(key_bindings, &table->key_bindings));
|
||||
}
|
||||
|
||||
struct key_binding *
|
||||
key_bindings_next(__unused struct key_table *table, struct key_binding *bd)
|
||||
{
|
||||
return (RB_NEXT(key_bindings, &table->key_bindings, bd));
|
||||
}
|
||||
|
||||
void
|
||||
key_bindings_add(const char *name, key_code key, int repeat,
|
||||
struct cmd_list *cmdlist)
|
||||
@@ -193,7 +274,7 @@ key_bindings_init(void)
|
||||
"bind ] paste-buffer",
|
||||
"bind c new-window",
|
||||
"bind d detach-client",
|
||||
"bind f command-prompt \"find-window -- '%%'\"",
|
||||
"bind f command-prompt \"find-window -Z -- '%%'\"",
|
||||
"bind i display-message",
|
||||
"bind l last-window",
|
||||
"bind m select-pane -m",
|
||||
@@ -207,8 +288,8 @@ key_bindings_init(void)
|
||||
"bind w choose-tree -Zw",
|
||||
"bind x confirm-before -p\"kill-pane #P? (y/n)\" kill-pane",
|
||||
"bind z resize-pane -Z",
|
||||
"bind { swap-pane -U",
|
||||
"bind } swap-pane -D",
|
||||
"bind '{' swap-pane -U",
|
||||
"bind '}' swap-pane -D",
|
||||
"bind '~' show-messages",
|
||||
"bind PPage copy-mode -u",
|
||||
"bind -r Up select-pane -U",
|
||||
@@ -223,6 +304,11 @@ key_bindings_init(void)
|
||||
"bind M-n next-window -a",
|
||||
"bind M-o rotate-window -D",
|
||||
"bind M-p previous-window -a",
|
||||
"bind -r S-Up refresh-client -U 10",
|
||||
"bind -r S-Down refresh-client -D 10",
|
||||
"bind -r S-Left refresh-client -L 10",
|
||||
"bind -r S-Right refresh-client -R 10",
|
||||
"bind -r DC refresh-client -c",
|
||||
"bind -r M-Up resize-pane -U 5",
|
||||
"bind -r M-Down resize-pane -D 5",
|
||||
"bind -r M-Left resize-pane -L 5",
|
||||
@@ -231,14 +317,22 @@ key_bindings_init(void)
|
||||
"bind -r C-Down resize-pane -D",
|
||||
"bind -r C-Left resize-pane -L",
|
||||
"bind -r C-Right resize-pane -R",
|
||||
|
||||
"bind -n MouseDown1Pane select-pane -t=\\; send-keys -M",
|
||||
"bind -n MouseDrag1Border resize-pane -M",
|
||||
"bind -n MouseDown1Status select-window -t=",
|
||||
"bind -n WheelDownStatus next-window",
|
||||
"bind -n WheelUpStatus previous-window",
|
||||
"bind -n MouseDrag1Pane if -Ft= '#{mouse_any_flag}' 'if -Ft= \"#{pane_in_mode}\" \"copy-mode -M\" \"send-keys -M\"' 'copy-mode -M'",
|
||||
"bind -n MouseDown3Pane if-shell -Ft= '#{mouse_any_flag}' 'select-pane -t=; send-keys -M' 'select-pane -mt='",
|
||||
"bind -n WheelUpPane if-shell -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'",
|
||||
"bind -n WheelUpPane if -Ft= '#{mouse_any_flag}' 'send-keys -M' 'if -Ft= \"#{pane_in_mode}\" \"send-keys -M\" \"copy-mode -et=\"'",
|
||||
|
||||
"bind -n MouseDown3StatusRight display-menu -t= -xM -yS -T \"#[align=centre]#{client_name}\" " DEFAULT_CLIENT_MENU,
|
||||
"bind -n MouseDown3StatusLeft display-menu -t= -xM -yS -T \"#[align=centre]#{session_name}\" " DEFAULT_SESSION_MENU,
|
||||
"bind -n MouseDown3Status display-menu -t= -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU,
|
||||
"bind C-m display-menu -xW -yS -T \"#[align=centre]#{window_index}:#{window_name}\" " DEFAULT_WINDOW_MENU,
|
||||
"bind -n MouseDown3Pane if -Ft= '#{||:#{mouse_any_flag},#{pane_in_mode}}' 'select-pane -t=; send-keys -M' {display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU "}",
|
||||
"bind -n M-MouseDown3Pane display-menu -t= -xM -yM -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU,
|
||||
"bind M-m display-menu -xP -yP -T \"#[align=centre]#{pane_index} (#{pane_id})\" " DEFAULT_PANE_MENU,
|
||||
|
||||
"bind -Tcopy-mode C-Space send -X begin-selection",
|
||||
"bind -Tcopy-mode C-a send -X start-of-line",
|
||||
@@ -295,13 +389,15 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode M-> send -X history-bottom",
|
||||
"bind -Tcopy-mode M-R send -X top-line",
|
||||
"bind -Tcopy-mode M-b send -X previous-word",
|
||||
"bind -Tcopy-mode C-M-b send -X previous-matching-bracket",
|
||||
"bind -Tcopy-mode M-f send -X next-word-end",
|
||||
"bind -Tcopy-mode C-M-f send -X next-matching-bracket",
|
||||
"bind -Tcopy-mode M-m send -X back-to-indentation",
|
||||
"bind -Tcopy-mode M-r send -X middle-line",
|
||||
"bind -Tcopy-mode M-v send -X page-up",
|
||||
"bind -Tcopy-mode M-w send -X copy-selection-and-cancel",
|
||||
"bind -Tcopy-mode M-{ send -X previous-paragraph",
|
||||
"bind -Tcopy-mode M-} send -X next-paragraph",
|
||||
"bind -Tcopy-mode 'M-{' send -X previous-paragraph",
|
||||
"bind -Tcopy-mode 'M-}' send -X next-paragraph",
|
||||
"bind -Tcopy-mode M-Up send -X halfpage-up",
|
||||
"bind -Tcopy-mode M-Down send -X halfpage-down",
|
||||
"bind -Tcopy-mode C-Up send -X scroll-up",
|
||||
@@ -366,8 +462,9 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode-vi t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi v send -X rectangle-toggle",
|
||||
"bind -Tcopy-mode-vi w send -X next-word",
|
||||
"bind -Tcopy-mode-vi { send -X previous-paragraph",
|
||||
"bind -Tcopy-mode-vi } send -X next-paragraph",
|
||||
"bind -Tcopy-mode-vi '{' send -X previous-paragraph",
|
||||
"bind -Tcopy-mode-vi '}' send -X next-paragraph",
|
||||
"bind -Tcopy-mode-vi % send -X next-matching-bracket",
|
||||
"bind -Tcopy-mode-vi MouseDown1Pane select-pane",
|
||||
"bind -Tcopy-mode-vi MouseDrag1Pane select-pane\\; send -X begin-selection",
|
||||
"bind -Tcopy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel",
|
||||
@@ -385,16 +482,15 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode-vi C-Up send -X scroll-up",
|
||||
"bind -Tcopy-mode-vi C-Down send -X scroll-down",
|
||||
};
|
||||
u_int i;
|
||||
struct cmd_list *cmdlist;
|
||||
char *cause;
|
||||
u_int i;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
for (i = 0; i < nitems(defaults); i++) {
|
||||
cmdlist = cmd_string_parse(defaults[i], "<default>", i, &cause);
|
||||
if (cmdlist == NULL)
|
||||
pr = cmd_parse_from_string(defaults[i], NULL);
|
||||
if (pr->status != CMD_PARSE_SUCCESS)
|
||||
fatalx("bad default key: %s", defaults[i]);
|
||||
cmdq_append(NULL, cmdq_get_command(cmdlist, NULL, NULL, 0));
|
||||
cmd_list_free(cmdlist);
|
||||
cmdq_append(NULL, cmdq_get_command(pr->cmdlist, NULL, NULL, 0));
|
||||
cmd_list_free(pr->cmdlist);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +501,7 @@ key_bindings_read_only(struct cmdq_item *item, __unused void *data)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
void
|
||||
struct cmdq_item *
|
||||
key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
|
||||
struct client *c, struct mouse_event *m, struct cmd_find_state *fs)
|
||||
{
|
||||
@@ -429,4 +525,5 @@ key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
|
||||
cmdq_insert_after(item, new_item);
|
||||
else
|
||||
cmdq_append(c, new_item);
|
||||
return (new_item);
|
||||
}
|
||||
|
||||
12
key-string.c
12
key-string.c
@@ -43,7 +43,9 @@ static const struct {
|
||||
{ "F11", KEYC_F11 },
|
||||
{ "F12", KEYC_F12 },
|
||||
{ "IC", KEYC_IC },
|
||||
{ "Insert", KEYC_IC },
|
||||
{ "DC", KEYC_DC },
|
||||
{ "Delete", KEYC_DC },
|
||||
{ "Home", KEYC_HOME },
|
||||
{ "End", KEYC_END },
|
||||
{ "NPage", KEYC_NPAGE },
|
||||
@@ -166,9 +168,11 @@ key_string_lookup_string(const char *string)
|
||||
enum utf8_state more;
|
||||
wchar_t wc;
|
||||
|
||||
/* Is this no key? */
|
||||
/* Is this no key or any key? */
|
||||
if (strcasecmp(string, "None") == 0)
|
||||
return (KEYC_NONE);
|
||||
if (strcasecmp(string, "Any") == 0)
|
||||
return (KEYC_ANY);
|
||||
|
||||
/* Is this a hexadecimal value? */
|
||||
if (string[0] == '0' && string[1] == 'x') {
|
||||
@@ -251,6 +255,8 @@ key_string_lookup_key(key_code key)
|
||||
/* Handle special keys. */
|
||||
if (key == KEYC_UNKNOWN)
|
||||
return ("Unknown");
|
||||
if (key == KEYC_ANY)
|
||||
return ("Any");
|
||||
if (key == KEYC_FOCUS_IN)
|
||||
return ("FocusIn");
|
||||
if (key == KEYC_FOCUS_OUT)
|
||||
@@ -267,6 +273,10 @@ key_string_lookup_key(key_code key)
|
||||
return ("MouseMovePane");
|
||||
if (key == KEYC_MOUSEMOVE_STATUS)
|
||||
return ("MouseMoveStatus");
|
||||
if (key == KEYC_MOUSEMOVE_STATUS_LEFT)
|
||||
return ("MouseMoveStatusLeft");
|
||||
if (key == KEYC_MOUSEMOVE_STATUS_RIGHT)
|
||||
return ("MouseMoveStatusRight");
|
||||
if (key == KEYC_MOUSEMOVE_BORDER)
|
||||
return ("MouseMoveBorder");
|
||||
if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) {
|
||||
|
||||
@@ -167,7 +167,7 @@ layout_parse(struct window *w, const char *layout)
|
||||
|
||||
/* Update pane offsets and sizes. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, lc->sx, lc->sy);
|
||||
layout_fix_panes(w);
|
||||
|
||||
/* Then resize the layout back to the original window size. */
|
||||
layout_resize(w, sx, sy);
|
||||
|
||||
294
layout-set.c
294
layout-set.c
@@ -119,7 +119,7 @@ layout_set_even(struct window *w, enum layout_type type)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcnew;
|
||||
u_int n;
|
||||
u_int n, sx, sy;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
@@ -131,7 +131,18 @@ layout_set_even(struct window *w, enum layout_type type)
|
||||
/* Free the old root and construct a new. */
|
||||
layout_free(w);
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
||||
if (type == LAYOUT_LEFTRIGHT) {
|
||||
sx = (n * (PANE_MINIMUM + 1)) - 1;
|
||||
if (sx < w->sx)
|
||||
sx = w->sx;
|
||||
sy = w->sy;
|
||||
} else {
|
||||
sy = (n * (PANE_MINIMUM + 1)) - 1;
|
||||
if (sy < w->sy)
|
||||
sy = w->sy;
|
||||
sx = w->sx;
|
||||
}
|
||||
layout_set_size(lc, sx, sy, 0, 0);
|
||||
layout_make_node(lc, type);
|
||||
|
||||
/* Build new leaf cells. */
|
||||
@@ -148,10 +159,11 @@ layout_set_even(struct window *w, enum layout_type type)
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
window_resize(w, lc->sx, lc->sy);
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
@@ -172,9 +184,8 @@ static void
|
||||
layout_set_main_h(struct window *w)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcmain, *lcrow, *lcchild;
|
||||
u_int n, mainheight, otherheight, width, height;
|
||||
u_int used, i, j, columns, rows, totalrows;
|
||||
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
|
||||
u_int n, mainh, otherh, sx, sy;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
@@ -184,110 +195,74 @@ layout_set_main_h(struct window *w)
|
||||
return;
|
||||
n--; /* take off main pane */
|
||||
|
||||
/* How many rows and columns will be needed, not counting main? */
|
||||
columns = (w->sx + 1) / (PANE_MINIMUM + 1); /* maximum columns */
|
||||
if (columns == 0)
|
||||
columns = 1;
|
||||
rows = 1 + (n - 1) / columns;
|
||||
columns = 1 + (n - 1) / rows;
|
||||
width = (w->sx - (n - 1)) / columns;
|
||||
/* Find available height - take off one line for the border. */
|
||||
sy = w->sy - 1;
|
||||
|
||||
/* Get the main pane height and add one for separator line. */
|
||||
mainheight = options_get_number(w->options, "main-pane-height") + 1;
|
||||
|
||||
/* Get the optional other pane height and add one for separator line. */
|
||||
otherheight = options_get_number(w->options, "other-pane-height") + 1;
|
||||
|
||||
/*
|
||||
* If an other pane height was specified, honour it so long as it
|
||||
* doesn't shrink the main height to less than the main-pane-height
|
||||
*/
|
||||
if (otherheight > 1 && w->sy - otherheight > mainheight)
|
||||
mainheight = w->sy - otherheight;
|
||||
if (mainheight < PANE_MINIMUM + 1)
|
||||
mainheight = PANE_MINIMUM + 1;
|
||||
|
||||
/* Try and make everything fit. */
|
||||
totalrows = rows * (PANE_MINIMUM + 1) - 1;
|
||||
if (mainheight + totalrows > w->sy) {
|
||||
if (totalrows + PANE_MINIMUM + 1 > w->sy)
|
||||
mainheight = PANE_MINIMUM + 2;
|
||||
/* Get the main pane height and work out the other pane height. */
|
||||
mainh = options_get_number(w->options, "main-pane-height");
|
||||
if (mainh + PANE_MINIMUM >= sy) {
|
||||
if (sy <= PANE_MINIMUM + PANE_MINIMUM)
|
||||
mainh = PANE_MINIMUM;
|
||||
else
|
||||
mainheight = w->sy - totalrows;
|
||||
height = PANE_MINIMUM;
|
||||
} else
|
||||
height = (w->sy - mainheight - (rows - 1)) / rows;
|
||||
mainh = sy - PANE_MINIMUM;
|
||||
otherh = PANE_MINIMUM;
|
||||
} else {
|
||||
otherh = options_get_number(w->options, "other-pane-height");
|
||||
if (otherh == 0)
|
||||
otherh = sy - mainh;
|
||||
else if (otherh > sy || sy - otherh < mainh)
|
||||
otherh = sy - mainh;
|
||||
else
|
||||
mainh = sy - otherh;
|
||||
}
|
||||
|
||||
/* Work out what width is needed. */
|
||||
sx = (n * (PANE_MINIMUM + 1)) - 1;
|
||||
if (sx < w->sx)
|
||||
sx = w->sx;
|
||||
|
||||
/* Free old tree and create a new root. */
|
||||
layout_free(w);
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, w->sx, mainheight + rows * (height + 1) - 1, 0, 0);
|
||||
layout_set_size(lc, sx, mainh + otherh + 1, 0, 0);
|
||||
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
||||
|
||||
/* Create the main pane. */
|
||||
lcmain = layout_create_cell(lc);
|
||||
layout_set_size(lcmain, w->sx, mainheight - 1, 0, 0);
|
||||
layout_set_size(lcmain, sx, mainh, 0, 0);
|
||||
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
|
||||
|
||||
/* Create a grid of the remaining cells. */
|
||||
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
||||
for (j = 0; j < rows; j++) {
|
||||
/* If this is the last cell, all done. */
|
||||
if (wp == NULL)
|
||||
break;
|
||||
/* Create the other pane. */
|
||||
lcother = layout_create_cell(lc);
|
||||
layout_set_size(lcother, sx, otherh, 0, 0);
|
||||
if (n == 1) {
|
||||
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
||||
layout_make_leaf(lcother, wp);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
||||
} else {
|
||||
layout_make_node(lcother, LAYOUT_LEFTRIGHT);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
||||
|
||||
/* Create the new row. */
|
||||
lcrow = layout_create_cell(lc);
|
||||
layout_set_size(lcrow, w->sx, height, 0, 0);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcrow, entry);
|
||||
|
||||
/* If only one column, just use the row directly. */
|
||||
if (columns == 1) {
|
||||
layout_make_leaf(lcrow, wp);
|
||||
wp = TAILQ_NEXT(wp, entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Add in the columns. */
|
||||
layout_make_node(lcrow, LAYOUT_LEFTRIGHT);
|
||||
for (i = 0; i < columns; i++) {
|
||||
/* Create and add a pane cell. */
|
||||
lcchild = layout_create_cell(lcrow);
|
||||
layout_set_size(lcchild, width, height, 0, 0);
|
||||
/* Add the remaining panes as children. */
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp == TAILQ_FIRST(&w->panes))
|
||||
continue;
|
||||
lcchild = layout_create_cell(lcother);
|
||||
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
|
||||
layout_make_leaf(lcchild, wp);
|
||||
TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry);
|
||||
|
||||
/* Move to the next cell. */
|
||||
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
|
||||
break;
|
||||
TAILQ_INSERT_TAIL(&lcother->cells, lcchild, entry);
|
||||
}
|
||||
|
||||
/* Adjust the row to fit the full width if necessary. */
|
||||
if (i == columns)
|
||||
i--;
|
||||
used = ((i + 1) * (width + 1)) - 1;
|
||||
if (w->sx <= used)
|
||||
continue;
|
||||
lcchild = TAILQ_LAST(&lcrow->cells, layout_cells);
|
||||
layout_resize_adjust(w, lcchild, LAYOUT_LEFTRIGHT,
|
||||
w->sx - used);
|
||||
}
|
||||
|
||||
/* Adjust the last row height to fit if necessary. */
|
||||
used = mainheight + (rows * height) + rows - 1;
|
||||
if (w->sy > used) {
|
||||
lcrow = TAILQ_LAST(&lc->cells, layout_cells);
|
||||
layout_resize_adjust(w, lcrow, LAYOUT_TOPBOTTOM,
|
||||
w->sy - used);
|
||||
layout_spread_cell(w, lcother);
|
||||
}
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
window_resize(w, lc->sx, lc->sy);
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
@@ -296,9 +271,8 @@ static void
|
||||
layout_set_main_v(struct window *w)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcmain, *lccolumn, *lcchild;
|
||||
u_int n, mainwidth, otherwidth, width, height;
|
||||
u_int used, i, j, columns, rows, totalcolumns;
|
||||
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
|
||||
u_int n, mainw, otherw, sx, sy;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
@@ -308,110 +282,74 @@ layout_set_main_v(struct window *w)
|
||||
return;
|
||||
n--; /* take off main pane */
|
||||
|
||||
/* How many rows and columns will be needed, not counting main? */
|
||||
rows = (w->sy + 1) / (PANE_MINIMUM + 1); /* maximum rows */
|
||||
if (rows == 0)
|
||||
rows = 1;
|
||||
columns = 1 + (n - 1) / rows;
|
||||
rows = 1 + (n - 1) / columns;
|
||||
height = (w->sy - (n - 1)) / rows;
|
||||
/* Find available width - take off one line for the border. */
|
||||
sx = w->sx - 1;
|
||||
|
||||
/* Get the main pane width and add one for separator line. */
|
||||
mainwidth = options_get_number(w->options, "main-pane-width") + 1;
|
||||
|
||||
/* Get the optional other pane width and add one for separator line. */
|
||||
otherwidth = options_get_number(w->options, "other-pane-width") + 1;
|
||||
|
||||
/*
|
||||
* If an other pane width was specified, honour it so long as it
|
||||
* doesn't shrink the main width to less than the main-pane-width
|
||||
*/
|
||||
if (otherwidth > 1 && w->sx - otherwidth > mainwidth)
|
||||
mainwidth = w->sx - otherwidth;
|
||||
if (mainwidth < PANE_MINIMUM + 1)
|
||||
mainwidth = PANE_MINIMUM + 1;
|
||||
|
||||
/* Try and make everything fit. */
|
||||
totalcolumns = columns * (PANE_MINIMUM + 1) - 1;
|
||||
if (mainwidth + totalcolumns > w->sx) {
|
||||
if (totalcolumns + PANE_MINIMUM + 1 > w->sx)
|
||||
mainwidth = PANE_MINIMUM + 2;
|
||||
/* Get the main pane width and work out the other pane width. */
|
||||
mainw = options_get_number(w->options, "main-pane-width");
|
||||
if (mainw + PANE_MINIMUM >= sx) {
|
||||
if (sx <= PANE_MINIMUM + PANE_MINIMUM)
|
||||
mainw = PANE_MINIMUM;
|
||||
else
|
||||
mainwidth = w->sx - totalcolumns;
|
||||
width = PANE_MINIMUM;
|
||||
} else
|
||||
width = (w->sx - mainwidth - (columns - 1)) / columns;
|
||||
mainw = sx - PANE_MINIMUM;
|
||||
otherw = PANE_MINIMUM;
|
||||
} else {
|
||||
otherw = options_get_number(w->options, "other-pane-width");
|
||||
if (otherw == 0)
|
||||
otherw = sx - mainw;
|
||||
else if (otherw > sx || sx - otherw < mainw)
|
||||
otherw = sx - mainw;
|
||||
else
|
||||
mainw = sx - otherw;
|
||||
}
|
||||
|
||||
/* Work out what height is needed. */
|
||||
sy = (n * (PANE_MINIMUM + 1)) - 1;
|
||||
if (sy < w->sy)
|
||||
sy = w->sy;
|
||||
|
||||
/* Free old tree and create a new root. */
|
||||
layout_free(w);
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, mainwidth + columns * (width + 1) - 1, w->sy, 0, 0);
|
||||
layout_set_size(lc, mainw + otherw + 1, sy, 0, 0);
|
||||
layout_make_node(lc, LAYOUT_LEFTRIGHT);
|
||||
|
||||
/* Create the main pane. */
|
||||
lcmain = layout_create_cell(lc);
|
||||
layout_set_size(lcmain, mainwidth - 1, w->sy, 0, 0);
|
||||
layout_set_size(lcmain, mainw, sy, 0, 0);
|
||||
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
|
||||
|
||||
/* Create a grid of the remaining cells. */
|
||||
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
||||
for (j = 0; j < columns; j++) {
|
||||
/* If this is the last cell, all done. */
|
||||
if (wp == NULL)
|
||||
break;
|
||||
/* Create the other pane. */
|
||||
lcother = layout_create_cell(lc);
|
||||
layout_set_size(lcother, otherw, sy, 0, 0);
|
||||
if (n == 1) {
|
||||
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
||||
layout_make_leaf(lcother, wp);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
||||
} else {
|
||||
layout_make_node(lcother, LAYOUT_TOPBOTTOM);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
||||
|
||||
/* Create the new column. */
|
||||
lccolumn = layout_create_cell(lc);
|
||||
layout_set_size(lccolumn, width, w->sy, 0, 0);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lccolumn, entry);
|
||||
|
||||
/* If only one row, just use the row directly. */
|
||||
if (rows == 1) {
|
||||
layout_make_leaf(lccolumn, wp);
|
||||
wp = TAILQ_NEXT(wp, entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Add in the rows. */
|
||||
layout_make_node(lccolumn, LAYOUT_TOPBOTTOM);
|
||||
for (i = 0; i < rows; i++) {
|
||||
/* Create and add a pane cell. */
|
||||
lcchild = layout_create_cell(lccolumn);
|
||||
layout_set_size(lcchild, width, height, 0, 0);
|
||||
/* Add the remaining panes as children. */
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp == TAILQ_FIRST(&w->panes))
|
||||
continue;
|
||||
lcchild = layout_create_cell(lcother);
|
||||
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
|
||||
layout_make_leaf(lcchild, wp);
|
||||
TAILQ_INSERT_TAIL(&lccolumn->cells, lcchild, entry);
|
||||
|
||||
/* Move to the next cell. */
|
||||
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
|
||||
break;
|
||||
TAILQ_INSERT_TAIL(&lcother->cells, lcchild, entry);
|
||||
}
|
||||
|
||||
/* Adjust the column to fit the full height if necessary. */
|
||||
if (i == rows)
|
||||
i--;
|
||||
used = ((i + 1) * (height + 1)) - 1;
|
||||
if (w->sy <= used)
|
||||
continue;
|
||||
lcchild = TAILQ_LAST(&lccolumn->cells, layout_cells);
|
||||
layout_resize_adjust(w, lcchild, LAYOUT_TOPBOTTOM,
|
||||
w->sy - used);
|
||||
}
|
||||
|
||||
/* Adjust the last column width to fit if necessary. */
|
||||
used = mainwidth + (columns * width) + columns - 1;
|
||||
if (w->sx > used) {
|
||||
lccolumn = TAILQ_LAST(&lc->cells, layout_cells);
|
||||
layout_resize_adjust(w, lccolumn, LAYOUT_LEFTRIGHT,
|
||||
w->sx - used);
|
||||
layout_spread_cell(w, lcother);
|
||||
}
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
window_resize(w, lc->sx, lc->sy);
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
@@ -421,7 +359,7 @@ layout_set_tiled(struct window *w)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcrow, *lcchild;
|
||||
u_int n, width, height, used;
|
||||
u_int n, width, height, used, sx, sy;
|
||||
u_int i, j, columns, rows;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
@@ -450,8 +388,13 @@ layout_set_tiled(struct window *w)
|
||||
/* Free old tree and create a new root. */
|
||||
layout_free(w);
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, (width + 1) * columns - 1,
|
||||
(height + 1) * rows - 1, 0, 0);
|
||||
sx = ((width + 1) * columns) - 1;
|
||||
if (sx < w->sx)
|
||||
sx = w->sx;
|
||||
sy = ((height + 1) * rows) - 1;
|
||||
if (sy < w->sy)
|
||||
sy = w->sy;
|
||||
layout_set_size(lc, sx, sy, 0, 0);
|
||||
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
||||
|
||||
/* Create a grid of the cells. */
|
||||
@@ -511,10 +454,11 @@ layout_set_tiled(struct window *w)
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
window_resize(w, lc->sx, lc->sy);
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
233
layout.c
233
layout.c
@@ -127,6 +127,42 @@ layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
||||
}
|
||||
}
|
||||
|
||||
struct layout_cell *
|
||||
layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
|
||||
{
|
||||
struct layout_cell *lcchild, *last = NULL;
|
||||
|
||||
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
||||
if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx &&
|
||||
y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) {
|
||||
/* Inside the cell - recurse. */
|
||||
return (layout_search_by_border(lcchild, x, y));
|
||||
}
|
||||
|
||||
if (last == NULL) {
|
||||
last = lcchild;
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (lc->type) {
|
||||
case LAYOUT_LEFTRIGHT:
|
||||
if (x < lcchild->xoff && x >= last->xoff + last->sx)
|
||||
return (last);
|
||||
break;
|
||||
case LAYOUT_TOPBOTTOM:
|
||||
if (y < lcchild->yoff && y >= last->yoff + last->sy)
|
||||
return (last);
|
||||
break;
|
||||
case LAYOUT_WINDOWPANE:
|
||||
break;
|
||||
}
|
||||
|
||||
last = lcchild;
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
|
||||
u_int yoff)
|
||||
@@ -200,7 +236,7 @@ layout_need_status(struct layout_cell *lc, int at_top)
|
||||
{
|
||||
struct layout_cell *first_lc;
|
||||
|
||||
if (lc->parent) {
|
||||
if (lc->parent != NULL) {
|
||||
if (lc->parent->type == LAYOUT_LEFTRIGHT)
|
||||
return (layout_need_status(lc->parent, at_top));
|
||||
|
||||
@@ -217,71 +253,29 @@ layout_need_status(struct layout_cell *lc, int at_top)
|
||||
|
||||
/* Update pane offsets and sizes based on their cells. */
|
||||
void
|
||||
layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
|
||||
layout_fix_panes(struct window *w)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc;
|
||||
u_int sx, sy;
|
||||
int shift, status, at_top;
|
||||
int shift, status;
|
||||
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
at_top = (status == 1);
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if ((lc = wp->layout_cell) == NULL)
|
||||
continue;
|
||||
|
||||
if (status != 0)
|
||||
shift = layout_need_status(lc, at_top);
|
||||
shift = layout_need_status(lc, status == 1);
|
||||
else
|
||||
shift = 0;
|
||||
|
||||
wp->xoff = lc->xoff;
|
||||
wp->yoff = lc->yoff;
|
||||
|
||||
if (shift && at_top)
|
||||
if (shift && status == 1)
|
||||
wp->yoff += 1;
|
||||
|
||||
/*
|
||||
* Layout cells are limited by the smallest size of other cells
|
||||
* within the same row or column; if this isn't the case
|
||||
* resizing becomes difficult.
|
||||
*
|
||||
* However, panes do not have to take up their entire cell, so
|
||||
* they can be cropped to the window edge if the layout
|
||||
* overflows and they are partly visible.
|
||||
*
|
||||
* This stops cells being hidden unnecessarily.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Work out the horizontal size. If the pane is actually
|
||||
* outside the window or the entire pane is already visible,
|
||||
* don't crop.
|
||||
*/
|
||||
if (lc->xoff >= wsx || lc->xoff + lc->sx < wsx)
|
||||
sx = lc->sx;
|
||||
else {
|
||||
sx = wsx - lc->xoff;
|
||||
if (sx < 1)
|
||||
sx = lc->sx;
|
||||
}
|
||||
|
||||
/*
|
||||
* Similarly for the vertical size; the minimum vertical size
|
||||
* is two because scroll regions cannot be one line.
|
||||
*/
|
||||
if (lc->yoff >= wsy || lc->yoff + lc->sy < wsy)
|
||||
sy = lc->sy;
|
||||
else {
|
||||
sy = wsy - lc->yoff;
|
||||
if (sy < 2)
|
||||
sy = lc->sy;
|
||||
}
|
||||
|
||||
if (shift)
|
||||
sy -= 1;
|
||||
|
||||
window_pane_resize(wp, sx, sy);
|
||||
window_pane_resize(wp, lc->sx, lc->sy - shift);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,7 +307,9 @@ layout_resize_check(struct window *w, struct layout_cell *lc,
|
||||
{
|
||||
struct layout_cell *lcchild;
|
||||
u_int available, minimum;
|
||||
int status;
|
||||
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
if (lc->type == LAYOUT_WINDOWPANE) {
|
||||
/* Space available in this cell only. */
|
||||
minimum = PANE_MINIMUM;
|
||||
@@ -321,9 +317,8 @@ layout_resize_check(struct window *w, struct layout_cell *lc,
|
||||
available = lc->sx;
|
||||
else {
|
||||
available = lc->sy;
|
||||
minimum += layout_need_status(lc,
|
||||
options_get_number(w->options,
|
||||
"pane-border-status") == 1);
|
||||
if (status != 0)
|
||||
minimum += layout_need_status(lc, status == 1);
|
||||
}
|
||||
if (available > minimum)
|
||||
available -= minimum;
|
||||
@@ -419,9 +414,9 @@ layout_destroy_cell(struct window *w, struct layout_cell *lc,
|
||||
lcother = TAILQ_NEXT(lc, entry);
|
||||
else
|
||||
lcother = TAILQ_PREV(lc, layout_cells, entry);
|
||||
if (lcparent->type == LAYOUT_LEFTRIGHT)
|
||||
if (lcother != NULL && lcparent->type == LAYOUT_LEFTRIGHT)
|
||||
layout_resize_adjust(w, lcother, lcparent->type, lc->sx + 1);
|
||||
else
|
||||
else if (lcother != NULL)
|
||||
layout_resize_adjust(w, lcother, lcparent->type, lc->sy + 1);
|
||||
|
||||
/* Remove this from the parent's list. */
|
||||
@@ -455,8 +450,7 @@ layout_init(struct window *w, struct window_pane *wp)
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
||||
layout_make_leaf(lc, wp);
|
||||
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -485,7 +479,7 @@ layout_resize(struct window *w, u_int sx, u_int sy)
|
||||
* out proportionately - this should leave the layout fitting the new
|
||||
* window size.
|
||||
*/
|
||||
xchange = sx - w->sx;
|
||||
xchange = sx - lc->sx;
|
||||
xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT);
|
||||
if (xchange < 0 && xchange < -xlimit)
|
||||
xchange = -xlimit;
|
||||
@@ -499,7 +493,7 @@ layout_resize(struct window *w, u_int sx, u_int sy)
|
||||
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, xchange);
|
||||
|
||||
/* Adjust vertically in a similar fashion. */
|
||||
ychange = sy - w->sy;
|
||||
ychange = sy - lc->sy;
|
||||
ylimit = layout_resize_check(w, lc, LAYOUT_TOPBOTTOM);
|
||||
if (ychange < 0 && ychange < -ylimit)
|
||||
ychange = -ylimit;
|
||||
@@ -514,7 +508,7 @@ layout_resize(struct window *w, u_int sx, u_int sy)
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, sx, sy);
|
||||
layout_fix_panes(w);
|
||||
}
|
||||
|
||||
/* Resize a pane to an absolute size. */
|
||||
@@ -550,29 +544,11 @@ layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
|
||||
layout_resize_pane(wp, type, change, 1);
|
||||
}
|
||||
|
||||
/* Resize a single pane within the layout. */
|
||||
void
|
||||
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
||||
int opposite)
|
||||
layout_resize_layout(struct window *w, struct layout_cell *lc,
|
||||
enum layout_type type, int change, int opposite)
|
||||
{
|
||||
struct window *w = wp->window;
|
||||
struct layout_cell *lc, *lcparent;
|
||||
int needed, size;
|
||||
|
||||
lc = wp->layout_cell;
|
||||
|
||||
/* Find next parent of the same type. */
|
||||
lcparent = lc->parent;
|
||||
while (lcparent != NULL && lcparent->type != type) {
|
||||
lc = lcparent;
|
||||
lcparent = lc->parent;
|
||||
}
|
||||
if (lcparent == NULL)
|
||||
return;
|
||||
|
||||
/* If this is the last cell, move back one. */
|
||||
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
||||
lc = TAILQ_PREV(lc, layout_cells, entry);
|
||||
int needed, size;
|
||||
|
||||
/* Grow or shrink the cell. */
|
||||
needed = change;
|
||||
@@ -591,9 +567,34 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
||||
}
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(wp->window->layout_root);
|
||||
layout_fix_panes(wp->window, wp->window->sx, wp->window->sy);
|
||||
notify_window("window-layout-changed", wp->window);
|
||||
layout_fix_offsets(w->layout_root);
|
||||
layout_fix_panes(w);
|
||||
notify_window("window-layout-changed", w);
|
||||
}
|
||||
|
||||
/* Resize a single pane within the layout. */
|
||||
void
|
||||
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
||||
int opposite)
|
||||
{
|
||||
struct layout_cell *lc, *lcparent;
|
||||
|
||||
lc = wp->layout_cell;
|
||||
|
||||
/* Find next parent of the same type. */
|
||||
lcparent = lc->parent;
|
||||
while (lcparent != NULL && lcparent->type != type) {
|
||||
lc = lcparent;
|
||||
lcparent = lc->parent;
|
||||
}
|
||||
if (lcparent == NULL)
|
||||
return;
|
||||
|
||||
/* If this is the last cell, move back one. */
|
||||
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
||||
lc = TAILQ_PREV(lc, layout_cells, entry);
|
||||
|
||||
layout_resize_layout(wp->window, lc, type, change, opposite);
|
||||
}
|
||||
|
||||
/* Helper function to grow pane. */
|
||||
@@ -674,7 +675,7 @@ void
|
||||
layout_assign_pane(struct layout_cell *lc, struct window_pane *wp)
|
||||
{
|
||||
layout_make_leaf(lc, wp);
|
||||
layout_fix_panes(wp->window, wp->window->sx, wp->window->sy);
|
||||
layout_fix_panes(wp->window);
|
||||
}
|
||||
|
||||
/* Calculate the new pane size for resized parent. */
|
||||
@@ -721,7 +722,7 @@ layout_set_size_check(struct window *w, struct layout_cell *lc,
|
||||
enum layout_type type, int size)
|
||||
{
|
||||
struct layout_cell *lcchild;
|
||||
u_int new_size, available, previous, count, idx;
|
||||
u_int new_size, available, previous, count, idx;
|
||||
|
||||
/* Cells with no children must just be bigger than minimum. */
|
||||
if (lc->type == LAYOUT_WINDOWPANE)
|
||||
@@ -735,6 +736,9 @@ layout_set_size_check(struct window *w, struct layout_cell *lc,
|
||||
|
||||
/* Check new size will work for each child. */
|
||||
if (lc->type == type) {
|
||||
if (available < (count * 2) - 1)
|
||||
return (0);
|
||||
|
||||
if (type == LAYOUT_LEFTRIGHT)
|
||||
previous = lc->sx;
|
||||
else
|
||||
@@ -744,13 +748,17 @@ layout_set_size_check(struct window *w, struct layout_cell *lc,
|
||||
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
||||
new_size = layout_new_pane_size(w, previous, lcchild,
|
||||
type, size, count - idx, available);
|
||||
if (new_size > available)
|
||||
return (0);
|
||||
|
||||
available -= (new_size + 1);
|
||||
if (idx == count - 1) {
|
||||
if (new_size > available)
|
||||
return (0);
|
||||
available -= new_size;
|
||||
} else {
|
||||
if (new_size + 1 > available)
|
||||
return (0);
|
||||
available -= new_size + 1;
|
||||
}
|
||||
if (!layout_set_size_check(w, lcchild, type, new_size))
|
||||
return (0);
|
||||
|
||||
idx++;
|
||||
}
|
||||
} else {
|
||||
@@ -823,11 +831,12 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
|
||||
*/
|
||||
struct layout_cell *
|
||||
layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
int insert_before, int full_size)
|
||||
int flags)
|
||||
{
|
||||
struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2;
|
||||
u_int sx, sy, xoff, yoff, size1, size2;
|
||||
u_int sx, sy, xoff, yoff, size1, size2, minimum;
|
||||
u_int new_size, saved_size, resize_first = 0;
|
||||
int full_size = (flags & SPAWN_FULLSIZE), status;
|
||||
|
||||
/*
|
||||
* If full_size is specified, add a new cell at the top of the window
|
||||
@@ -837,6 +846,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
lc = wp->window->layout_root;
|
||||
else
|
||||
lc = wp->layout_cell;
|
||||
status = options_get_number(wp->window->options, "pane-border-status");
|
||||
|
||||
/* Copy the old cell size. */
|
||||
sx = lc->sx;
|
||||
@@ -851,7 +861,10 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
return (NULL);
|
||||
break;
|
||||
case LAYOUT_TOPBOTTOM:
|
||||
if (sy < PANE_MINIMUM * 2 + 1)
|
||||
minimum = PANE_MINIMUM * 2 + 1;
|
||||
if (status != 0)
|
||||
minimum += layout_need_status(lc, status == 1);
|
||||
if (sy < minimum)
|
||||
return (NULL);
|
||||
break;
|
||||
default:
|
||||
@@ -868,7 +881,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
saved_size = sy;
|
||||
if (size < 0)
|
||||
size2 = ((saved_size + 1) / 2) - 1;
|
||||
else if (insert_before)
|
||||
else if (flags & SPAWN_BEFORE)
|
||||
size2 = saved_size - size - 1;
|
||||
else
|
||||
size2 = size;
|
||||
@@ -879,7 +892,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
size1 = saved_size - 1 - size2;
|
||||
|
||||
/* Which size are we using? */
|
||||
if (insert_before)
|
||||
if (flags & SPAWN_BEFORE)
|
||||
new_size = size2;
|
||||
else
|
||||
new_size = size1;
|
||||
@@ -895,7 +908,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
*/
|
||||
lcparent = lc->parent;
|
||||
lcnew = layout_create_cell(lcparent);
|
||||
if (insert_before)
|
||||
if (flags & SPAWN_BEFORE)
|
||||
TAILQ_INSERT_BEFORE(lc, lcnew, entry);
|
||||
else
|
||||
TAILQ_INSERT_AFTER(&lcparent->cells, lc, lcnew, entry);
|
||||
@@ -924,7 +937,7 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
layout_set_size(lcnew, size, sy, 0, 0);
|
||||
else if (lc->type == LAYOUT_TOPBOTTOM)
|
||||
layout_set_size(lcnew, sx, size, 0, 0);
|
||||
if (insert_before)
|
||||
if (flags & SPAWN_BEFORE)
|
||||
TAILQ_INSERT_HEAD(&lc->cells, lcnew, entry);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
||||
@@ -948,12 +961,12 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
|
||||
/* Create the new child cell. */
|
||||
lcnew = layout_create_cell(lcparent);
|
||||
if (insert_before)
|
||||
if (flags & SPAWN_BEFORE)
|
||||
TAILQ_INSERT_HEAD(&lcparent->cells, lcnew, entry);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
|
||||
}
|
||||
if (insert_before) {
|
||||
if (flags & SPAWN_BEFORE) {
|
||||
lc1 = lcnew;
|
||||
lc2 = lc;
|
||||
} else {
|
||||
@@ -994,7 +1007,7 @@ layout_close_pane(struct window_pane *wp)
|
||||
/* Fix pane offsets and sizes. */
|
||||
if (w->layout_root != NULL) {
|
||||
layout_fix_offsets(w->layout_root);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
}
|
||||
notify_window("window-layout-changed", w);
|
||||
}
|
||||
@@ -1003,22 +1016,29 @@ int
|
||||
layout_spread_cell(struct window *w, struct layout_cell *parent)
|
||||
{
|
||||
struct layout_cell *lc;
|
||||
u_int number, each, size;
|
||||
int change, changed;
|
||||
u_int number, each, size, this;
|
||||
int change, changed, status;
|
||||
|
||||
number = 0;
|
||||
TAILQ_FOREACH (lc, &parent->cells, entry)
|
||||
number++;
|
||||
if (number <= 1)
|
||||
return (0);
|
||||
status = options_get_number(w->options, "pane-border-status");
|
||||
|
||||
if (parent->type == LAYOUT_LEFTRIGHT)
|
||||
size = parent->sx;
|
||||
else if (parent->type == LAYOUT_TOPBOTTOM)
|
||||
else if (parent->type == LAYOUT_TOPBOTTOM) {
|
||||
size = parent->sy;
|
||||
else
|
||||
if (status != 0)
|
||||
size -= layout_need_status(parent, status == 1);
|
||||
} else
|
||||
return (0);
|
||||
if (size < number - 1)
|
||||
return (0);
|
||||
each = (size - (number - 1)) / number;
|
||||
if (each == 0)
|
||||
return (0);
|
||||
|
||||
changed = 0;
|
||||
TAILQ_FOREACH (lc, &parent->cells, entry) {
|
||||
@@ -1029,7 +1049,10 @@ layout_spread_cell(struct window *w, struct layout_cell *parent)
|
||||
change = each - (int)lc->sx;
|
||||
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change);
|
||||
} else if (parent->type == LAYOUT_TOPBOTTOM) {
|
||||
change = each - (int)lc->sy;
|
||||
this = each;
|
||||
if (status != 0)
|
||||
this += layout_need_status(lc, status == 1);
|
||||
change = this - (int)lc->sy;
|
||||
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change);
|
||||
}
|
||||
if (change != 0)
|
||||
@@ -1051,7 +1074,7 @@ layout_spread_out(struct window_pane *wp)
|
||||
do {
|
||||
if (layout_spread_cell(w, parent)) {
|
||||
layout_fix_offsets(parent);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
layout_fix_panes(w);
|
||||
break;
|
||||
}
|
||||
} while ((parent = parent->parent) != NULL);
|
||||
|
||||
318
menu.c
Normal file
318
menu.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct menu_data {
|
||||
struct cmdq_item *item;
|
||||
int flags;
|
||||
|
||||
struct cmd_find_state fs;
|
||||
struct screen s;
|
||||
|
||||
u_int px;
|
||||
u_int py;
|
||||
|
||||
struct menu *menu;
|
||||
int choice;
|
||||
|
||||
menu_choice_cb cb;
|
||||
void *data;
|
||||
};
|
||||
|
||||
void
|
||||
menu_add_items(struct menu *menu, const struct menu_item *items,
|
||||
struct cmdq_item *qitem, struct client *c, struct cmd_find_state *fs)
|
||||
{
|
||||
const struct menu_item *loop;
|
||||
|
||||
for (loop = items; loop->name != NULL; loop++)
|
||||
menu_add_item(menu, loop, qitem, c, fs);
|
||||
}
|
||||
|
||||
void
|
||||
menu_add_item(struct menu *menu, const struct menu_item *item,
|
||||
struct cmdq_item *qitem, struct client *c, struct cmd_find_state *fs)
|
||||
{
|
||||
struct menu_item *new_item;
|
||||
const char *key, *cmd;
|
||||
char *s, *name;
|
||||
u_int width;
|
||||
int line;
|
||||
|
||||
line = (item == NULL || item->name == NULL || *item->name == '\0');
|
||||
if (line && menu->count == 0)
|
||||
return;
|
||||
|
||||
menu->items = xreallocarray(menu->items, menu->count + 1,
|
||||
sizeof *menu->items);
|
||||
new_item = &menu->items[menu->count++];
|
||||
memset(new_item, 0, sizeof *new_item);
|
||||
|
||||
if (line)
|
||||
return;
|
||||
|
||||
if (fs != NULL)
|
||||
s = format_single(qitem, item->name, c, fs->s, fs->wl, fs->wp);
|
||||
else
|
||||
s = format_single(qitem, item->name, c, NULL, NULL, NULL);
|
||||
if (*s == '\0') { /* no item if empty after format expanded */
|
||||
menu->count--;
|
||||
return;
|
||||
}
|
||||
if (*s != '-' && item->key != KEYC_UNKNOWN && item->key != KEYC_NONE) {
|
||||
key = key_string_lookup_key(item->key);
|
||||
xasprintf(&name, "%s#[default] #[align=right](%s)", s, key);
|
||||
} else
|
||||
xasprintf(&name, "%s", s);
|
||||
new_item->name = name;
|
||||
free(s);
|
||||
|
||||
cmd = item->command;
|
||||
if (cmd != NULL) {
|
||||
if (fs != NULL)
|
||||
s = format_single(qitem, cmd, c, fs->s, fs->wl, fs->wp);
|
||||
else
|
||||
s = format_single(qitem, cmd, c, NULL, NULL, NULL);
|
||||
} else
|
||||
s = NULL;
|
||||
new_item->command = s;
|
||||
new_item->key = item->key;
|
||||
|
||||
width = format_width(new_item->name);
|
||||
if (width > menu->width)
|
||||
menu->width = width;
|
||||
}
|
||||
|
||||
struct menu *
|
||||
menu_create(const char *title)
|
||||
{
|
||||
struct menu *menu;
|
||||
|
||||
menu = xcalloc(1, sizeof *menu);
|
||||
menu->title = xstrdup(title);
|
||||
|
||||
return (menu);
|
||||
}
|
||||
|
||||
void
|
||||
menu_free(struct menu *menu)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < menu->count; i++) {
|
||||
free((void *)menu->items[i].name);
|
||||
free((void *)menu->items[i].command);
|
||||
}
|
||||
free(menu->items);
|
||||
|
||||
free((void *)menu->title);
|
||||
free(menu);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_draw_cb(struct client *c, __unused struct screen_redraw_ctx *ctx0)
|
||||
{
|
||||
struct menu_data *md = c->overlay_data;
|
||||
struct tty *tty = &c->tty;
|
||||
struct screen *s = &md->s;
|
||||
struct menu *menu = md->menu;
|
||||
struct screen_write_ctx ctx;
|
||||
u_int i, px, py;
|
||||
|
||||
screen_write_start(&ctx, NULL, s);
|
||||
screen_write_clearscreen(&ctx, 8);
|
||||
screen_write_menu(&ctx, menu, md->choice);
|
||||
screen_write_stop(&ctx);
|
||||
|
||||
px = md->px;
|
||||
py = md->py;
|
||||
|
||||
for (i = 0; i < screen_size_y(&md->s); i++)
|
||||
tty_draw_line(tty, NULL, s, 0, i, menu->width + 4, px, py + i);
|
||||
|
||||
if (~md->flags & MENU_NOMOUSE)
|
||||
tty_update_mode(tty, MODE_MOUSE_ALL, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
menu_free_cb(struct client *c)
|
||||
{
|
||||
struct menu_data *md = c->overlay_data;
|
||||
|
||||
if (md->item != NULL)
|
||||
md->item->flags &= ~CMDQ_WAITING;
|
||||
|
||||
if (md->cb != NULL)
|
||||
md->cb(md->menu, UINT_MAX, KEYC_NONE, md->data);
|
||||
|
||||
screen_free(&md->s);
|
||||
menu_free(md->menu);
|
||||
free(md);
|
||||
}
|
||||
|
||||
static int
|
||||
menu_key_cb(struct client *c, struct key_event *event)
|
||||
{
|
||||
struct menu_data *md = c->overlay_data;
|
||||
struct menu *menu = md->menu;
|
||||
struct mouse_event *m = &event->m;
|
||||
u_int i;
|
||||
int count = menu->count, old = md->choice;
|
||||
const struct menu_item *item;
|
||||
struct cmdq_item *new_item;
|
||||
struct cmd_parse_result *pr;
|
||||
const char *name;
|
||||
|
||||
if (KEYC_IS_MOUSE(event->key)) {
|
||||
if (md->flags & MENU_NOMOUSE)
|
||||
return (0);
|
||||
if (m->x < md->px ||
|
||||
m->x > md->px + 4 + menu->width ||
|
||||
m->y < md->py + 1 ||
|
||||
m->y > md->py + 1 + count - 1) {
|
||||
if (MOUSE_RELEASE(m->b))
|
||||
return (1);
|
||||
if (md->choice != -1) {
|
||||
md->choice = -1;
|
||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
if (MOUSE_RELEASE(m->b))
|
||||
goto chosen;
|
||||
md->choice = m->y - (md->py + 1);
|
||||
if (md->choice != old)
|
||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||
return (0);
|
||||
}
|
||||
switch (event->key) {
|
||||
case KEYC_UP:
|
||||
if (old == -1)
|
||||
old = 0;
|
||||
do {
|
||||
if (md->choice == -1 || md->choice == 0)
|
||||
md->choice = count - 1;
|
||||
else
|
||||
md->choice--;
|
||||
name = menu->items[md->choice].name;
|
||||
} while ((name == NULL || *name == '-') && md->choice != old);
|
||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||
return (0);
|
||||
case KEYC_DOWN:
|
||||
if (old == -1)
|
||||
old = 0;
|
||||
do {
|
||||
if (md->choice == -1 || md->choice == count - 1)
|
||||
md->choice = 0;
|
||||
else
|
||||
md->choice++;
|
||||
name = menu->items[md->choice].name;
|
||||
} while ((name == NULL || *name == '-') && md->choice != old);
|
||||
c->flags |= CLIENT_REDRAWOVERLAY;
|
||||
return (0);
|
||||
case '\r':
|
||||
goto chosen;
|
||||
case '\033': /* Escape */
|
||||
case '\003': /* C-c */
|
||||
case '\007': /* C-g */
|
||||
case 'q':
|
||||
return (1);
|
||||
}
|
||||
for (i = 0; i < (u_int)count; i++) {
|
||||
name = menu->items[i].name;
|
||||
if (name == NULL || *name == '-')
|
||||
continue;
|
||||
if (event->key == menu->items[i].key) {
|
||||
md->choice = i;
|
||||
goto chosen;
|
||||
}
|
||||
}
|
||||
return (0);
|
||||
|
||||
chosen:
|
||||
if (md->choice == -1)
|
||||
return (1);
|
||||
item = &menu->items[md->choice];
|
||||
if (item->name == NULL || *item->name == '-')
|
||||
return (1);
|
||||
if (md->cb != NULL) {
|
||||
md->cb(md->menu, md->choice, item->key, md->data);
|
||||
md->cb = NULL;
|
||||
return (1);
|
||||
}
|
||||
|
||||
pr = cmd_parse_from_string(item->command, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
new_item = NULL;
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
new_item = cmdq_get_error(pr->error);
|
||||
free(pr->error);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
if (md->item != NULL)
|
||||
m = &md->item->shared->mouse;
|
||||
else
|
||||
m = NULL;
|
||||
new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
cmdq_append(c, new_item);
|
||||
break;
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
menu_display(struct menu *menu, int flags, struct cmdq_item *item, u_int px,
|
||||
u_int py, struct client *c, struct cmd_find_state *fs, menu_choice_cb cb,
|
||||
void *data)
|
||||
{
|
||||
struct menu_data *md;
|
||||
|
||||
if (c->tty.sx < menu->width + 4 || c->tty.sy < menu->count + 2)
|
||||
return (-1);
|
||||
|
||||
md = xcalloc(1, sizeof *md);
|
||||
md->item = item;
|
||||
md->flags = flags;
|
||||
|
||||
if (fs != NULL)
|
||||
cmd_find_copy_state(&md->fs, fs);
|
||||
screen_init(&md->s, menu->width + 4, menu->count + 2, 0);
|
||||
|
||||
md->px = px;
|
||||
md->py = py;
|
||||
|
||||
md->menu = menu;
|
||||
md->choice = -1;
|
||||
|
||||
md->cb = cb;
|
||||
md->data = data;
|
||||
|
||||
server_client_set_overlay(c, 0, menu_draw_cb, menu_key_cb, menu_free_cb,
|
||||
md);
|
||||
return (0);
|
||||
}
|
||||
161
mode-tree.c
161
mode-tree.c
@@ -35,6 +35,7 @@ struct mode_tree_data {
|
||||
|
||||
struct window_pane *wp;
|
||||
void *modedata;
|
||||
const struct menu_item *menu;
|
||||
|
||||
const char **sort_list;
|
||||
u_int sort_size;
|
||||
@@ -43,6 +44,7 @@ struct mode_tree_data {
|
||||
mode_tree_build_cb buildcb;
|
||||
mode_tree_draw_cb drawcb;
|
||||
mode_tree_search_cb searchcb;
|
||||
mode_tree_menu_cb menucb;
|
||||
|
||||
struct mode_tree_list children;
|
||||
struct mode_tree_list saved;
|
||||
@@ -89,8 +91,24 @@ struct mode_tree_line {
|
||||
int flat;
|
||||
};
|
||||
|
||||
struct mode_tree_menu {
|
||||
struct mode_tree_data *data;
|
||||
struct client *c;
|
||||
u_int line;
|
||||
void *itemdata;
|
||||
};
|
||||
|
||||
static void mode_tree_free_items(struct mode_tree_list *);
|
||||
|
||||
static const struct menu_item mode_tree_menu_items[] = {
|
||||
{ "Scroll Left", '<', NULL },
|
||||
{ "Scroll Right", '>', NULL },
|
||||
{ "", KEYC_NONE, NULL },
|
||||
{ "Cancel", 'q', NULL },
|
||||
|
||||
{ NULL, KEYC_NONE, NULL }
|
||||
};
|
||||
|
||||
static struct mode_tree_item *
|
||||
mode_tree_find_item(struct mode_tree_list *mtl, uint64_t tag)
|
||||
{
|
||||
@@ -192,7 +210,7 @@ mode_tree_clear_tagged(struct mode_tree_list *mtl)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
mode_tree_up(struct mode_tree_data *mtd, int wrap)
|
||||
{
|
||||
if (mtd->current == 0) {
|
||||
@@ -299,8 +317,9 @@ mode_tree_each_tagged(struct mode_tree_data *mtd, mode_tree_each_cb cb,
|
||||
struct mode_tree_data *
|
||||
mode_tree_start(struct window_pane *wp, struct args *args,
|
||||
mode_tree_build_cb buildcb, mode_tree_draw_cb drawcb,
|
||||
mode_tree_search_cb searchcb, void *modedata, const char **sort_list,
|
||||
u_int sort_size, struct screen **s)
|
||||
mode_tree_search_cb searchcb, mode_tree_menu_cb menucb, void *modedata,
|
||||
const struct menu_item *menu, const char **sort_list, u_int sort_size,
|
||||
struct screen **s)
|
||||
{
|
||||
struct mode_tree_data *mtd;
|
||||
const char *sort;
|
||||
@@ -311,6 +330,7 @@ mode_tree_start(struct window_pane *wp, struct args *args,
|
||||
|
||||
mtd->wp = wp;
|
||||
mtd->modedata = modedata;
|
||||
mtd->menu = menu;
|
||||
|
||||
mtd->sort_list = sort_list;
|
||||
mtd->sort_size = sort_size;
|
||||
@@ -334,6 +354,7 @@ mode_tree_start(struct window_pane *wp, struct args *args,
|
||||
mtd->buildcb = buildcb;
|
||||
mtd->drawcb = drawcb;
|
||||
mtd->searchcb = searchcb;
|
||||
mtd->menucb = menucb;
|
||||
|
||||
TAILQ_INIT(&mtd->children);
|
||||
|
||||
@@ -366,7 +387,7 @@ mode_tree_build(struct mode_tree_data *mtd)
|
||||
if (mtd->line_list != NULL)
|
||||
tag = mtd->line_list[mtd->current].item->tag;
|
||||
else
|
||||
tag = 0;
|
||||
tag = UINT64_MAX;
|
||||
|
||||
TAILQ_CONCAT(&mtd->saved, &mtd->children, entry);
|
||||
TAILQ_INIT(&mtd->children);
|
||||
@@ -382,6 +403,8 @@ mode_tree_build(struct mode_tree_data *mtd)
|
||||
mode_tree_clear_lines(mtd);
|
||||
mode_tree_build_lines(mtd, &mtd->children, 0);
|
||||
|
||||
if (tag == UINT64_MAX)
|
||||
tag = mtd->line_list[mtd->current].item->tag;
|
||||
mode_tree_set_current(mtd, tag);
|
||||
|
||||
mtd->width = screen_size_x(s);
|
||||
@@ -497,7 +520,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
struct options *oo = wp->window->options;
|
||||
struct screen_write_ctx ctx;
|
||||
struct grid_cell gc0, gc;
|
||||
u_int w, h, i, j, sy, box_x, box_y;
|
||||
u_int w, h, i, j, sy, box_x, box_y, width;
|
||||
char *text, *start, key[7];
|
||||
const char *tag, *symbol;
|
||||
size_t size, n;
|
||||
@@ -530,7 +553,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
line = &mtd->line_list[i];
|
||||
mti = line->item;
|
||||
|
||||
screen_write_cursormove(&ctx, 0, i - mtd->offset);
|
||||
screen_write_cursormove(&ctx, 0, i - mtd->offset, 0);
|
||||
|
||||
if (i < 10)
|
||||
snprintf(key, sizeof key, "(%c) ", '0' + i);
|
||||
@@ -572,8 +595,9 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
tag = "*";
|
||||
else
|
||||
tag = "";
|
||||
xasprintf(&text, "%-*s%s%s%s: %s", keylen, key, start,
|
||||
mti->name, tag, mti->text);
|
||||
xasprintf(&text, "%-*s%s%s%s: ", keylen, key, start, mti->name,
|
||||
tag);
|
||||
width = utf8_cstrwidth(text);
|
||||
free(start);
|
||||
|
||||
if (mti->tagged) {
|
||||
@@ -582,11 +606,13 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
}
|
||||
|
||||
if (i != mtd->current) {
|
||||
screen_write_nputs(&ctx, w, &gc0, "%s", text);
|
||||
screen_write_clearendofline(&ctx, 8);
|
||||
screen_write_puts(&ctx, &gc0, "%s", text);
|
||||
format_draw(&ctx, &gc0, w - width, mti->text, NULL);
|
||||
} else {
|
||||
screen_write_nputs(&ctx, w, &gc, "%s", text);
|
||||
screen_write_clearendofline(&ctx, gc.bg);
|
||||
screen_write_puts(&ctx, &gc, "%s", text);
|
||||
format_draw(&ctx, &gc, w - width, mti->text, NULL);
|
||||
}
|
||||
free(text);
|
||||
|
||||
@@ -605,13 +631,13 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
line = &mtd->line_list[mtd->current];
|
||||
mti = line->item;
|
||||
|
||||
screen_write_cursormove(&ctx, 0, h);
|
||||
screen_write_cursormove(&ctx, 0, h, 0);
|
||||
screen_write_box(&ctx, w, sy - h);
|
||||
|
||||
xasprintf(&text, " %s (sort: %s)", mti->name,
|
||||
mtd->sort_list[mtd->sort_type]);
|
||||
if (w - 2 >= strlen(text)) {
|
||||
screen_write_cursormove(&ctx, 1, h);
|
||||
screen_write_cursormove(&ctx, 1, h, 0);
|
||||
screen_write_puts(&ctx, &gc0, "%s", text);
|
||||
|
||||
if (mtd->no_matches)
|
||||
@@ -633,7 +659,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
|
||||
box_y = sy - h - 2;
|
||||
|
||||
if (box_x != 0 && box_y != 0) {
|
||||
screen_write_cursormove(&ctx, 2, h + 1);
|
||||
screen_write_cursormove(&ctx, 2, h + 1, 0);
|
||||
mtd->drawcb(mtd->modedata, mti->itemdata, &ctx, box_x, box_y);
|
||||
}
|
||||
|
||||
@@ -759,6 +785,70 @@ mode_tree_filter_free(void *data)
|
||||
mode_tree_remove_ref(data);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_menu_callback(__unused struct menu *menu, __unused u_int idx,
|
||||
key_code key, void *data)
|
||||
{
|
||||
struct mode_tree_menu *mtm = data;
|
||||
struct mode_tree_data *mtd = mtm->data;
|
||||
struct mode_tree_item *mti;
|
||||
|
||||
if (mtd->dead || key == KEYC_NONE)
|
||||
goto out;
|
||||
|
||||
if (mtm->line >= mtd->line_size)
|
||||
goto out;
|
||||
mti = mtd->line_list[mtm->line].item;
|
||||
if (mti->itemdata != mtm->itemdata)
|
||||
goto out;
|
||||
mtd->current = mtm->line;
|
||||
mtd->menucb (mtd->modedata, mtm->c, key);
|
||||
|
||||
out:
|
||||
mode_tree_remove_ref(mtd);
|
||||
free(mtm);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_display_menu(struct mode_tree_data *mtd, struct client *c, u_int x,
|
||||
u_int y, int outside)
|
||||
{
|
||||
struct mode_tree_item *mti;
|
||||
struct menu *menu;
|
||||
const struct menu_item *items;
|
||||
struct mode_tree_menu *mtm;
|
||||
char *title;
|
||||
u_int line;
|
||||
|
||||
if (mtd->offset + y > mtd->line_size - 1)
|
||||
line = mtd->current;
|
||||
else
|
||||
line = mtd->offset + y;
|
||||
mti = mtd->line_list[line].item;
|
||||
|
||||
if (!outside) {
|
||||
items = mtd->menu;
|
||||
xasprintf(&title, "#[align=centre]%s", mti->name);
|
||||
} else {
|
||||
items = mode_tree_menu_items;
|
||||
title = xstrdup("");
|
||||
}
|
||||
menu = menu_create(title);
|
||||
menu_add_items(menu, items, NULL, NULL, NULL);
|
||||
free(title);
|
||||
|
||||
mtm = xmalloc(sizeof *mtm);
|
||||
mtm->data = mtd;
|
||||
mtm->c = c;
|
||||
mtm->line = line;
|
||||
mtm->itemdata = mti->itemdata;
|
||||
mtd->references++;
|
||||
|
||||
if (menu_display(menu, 0, NULL, x, y, c, NULL, mode_tree_menu_callback,
|
||||
mtm) != 0)
|
||||
menu_free(menu);
|
||||
}
|
||||
|
||||
int
|
||||
mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
||||
struct mouse_event *m, u_int *xp, u_int *yp)
|
||||
@@ -769,7 +859,7 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
||||
int choice;
|
||||
key_code tmp;
|
||||
|
||||
if (KEYC_IS_MOUSE(*key)) {
|
||||
if (KEYC_IS_MOUSE(*key) && m != NULL) {
|
||||
if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
@@ -779,20 +869,29 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
||||
if (yp != NULL)
|
||||
*yp = y;
|
||||
if (x > mtd->width || y > mtd->height) {
|
||||
if (*key == KEYC_MOUSEDOWN3_PANE)
|
||||
mode_tree_display_menu(mtd, c, x, y, 1);
|
||||
if (!mtd->preview)
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
}
|
||||
if (mtd->offset + y < mtd->line_size) {
|
||||
if (*key == KEYC_MOUSEDOWN1_PANE ||
|
||||
*key == KEYC_MOUSEDOWN3_PANE ||
|
||||
*key == KEYC_DOUBLECLICK1_PANE)
|
||||
mtd->current = mtd->offset + y;
|
||||
if (*key == KEYC_DOUBLECLICK1_PANE)
|
||||
*key = '\r';
|
||||
else
|
||||
else {
|
||||
if (*key == KEYC_MOUSEDOWN3_PANE)
|
||||
mode_tree_display_menu(mtd, c, x, y, 0);
|
||||
*key = KEYC_NONE;
|
||||
} else
|
||||
}
|
||||
} else {
|
||||
if (*key == KEYC_MOUSEDOWN3_PANE)
|
||||
mode_tree_display_menu(mtd, c, x, y, 0);
|
||||
*key = KEYC_NONE;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -876,7 +975,8 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
|
||||
current->tagged = 1;
|
||||
} else
|
||||
current->tagged = 0;
|
||||
mode_tree_down(mtd, 0);
|
||||
if (m != NULL)
|
||||
mode_tree_down(mtd, 0);
|
||||
break;
|
||||
case 'T':
|
||||
for (i = 0; i < mtd->line_size; i++)
|
||||
@@ -949,8 +1049,8 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
|
||||
const char *template, const char *name)
|
||||
{
|
||||
struct cmdq_item *new_item;
|
||||
struct cmd_list *cmdlist;
|
||||
char *command, *cause;
|
||||
char *command;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
command = cmd_template_replace(template, name, 1);
|
||||
if (command == NULL || *command == '\0') {
|
||||
@@ -958,17 +1058,22 @@ mode_tree_run_command(struct client *c, struct cmd_find_state *fs,
|
||||
return;
|
||||
}
|
||||
|
||||
cmdlist = cmd_string_parse(command, NULL, 0, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL && c != NULL) {
|
||||
*cause = toupper((u_char)*cause);
|
||||
status_message_set(c, "%s", cause);
|
||||
pr = cmd_parse_from_string(command, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
break;
|
||||
case CMD_PARSE_ERROR:
|
||||
if (c != NULL) {
|
||||
*pr->error = toupper((u_char)*pr->error);
|
||||
status_message_set(c, "%s", pr->error);
|
||||
}
|
||||
free(cause);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, fs, NULL, 0);
|
||||
free(pr->error);
|
||||
break;
|
||||
case CMD_PARSE_SUCCESS:
|
||||
new_item = cmdq_get_command(pr->cmdlist, fs, NULL, 0);
|
||||
cmdq_append(c, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
cmd_list_free(pr->cmdlist);
|
||||
break;
|
||||
}
|
||||
|
||||
free(command);
|
||||
|
||||
94
notify.c
94
notify.c
@@ -35,13 +35,34 @@ struct notify_entry {
|
||||
};
|
||||
|
||||
static void
|
||||
notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
||||
notify_hook_formats(struct cmdq_item *item, struct session *s, struct window *w,
|
||||
int pane)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
struct hook *hook;
|
||||
struct cmdq_item *new_item;
|
||||
struct session *s = ne->session;
|
||||
struct window *w = ne->window;
|
||||
if (s != NULL) {
|
||||
cmdq_format(item, "hook_session", "$%u", s->id);
|
||||
cmdq_format(item, "hook_session_name", "%s", s->name);
|
||||
}
|
||||
if (w != NULL) {
|
||||
cmdq_format(item, "hook_window", "@%u", w->id);
|
||||
cmdq_format(item, "hook_window_name", "%s", w->name);
|
||||
}
|
||||
if (pane != -1)
|
||||
cmdq_format(item, "hook_pane", "%%%d", pane);
|
||||
}
|
||||
|
||||
static void
|
||||
notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
struct options *oo;
|
||||
struct cmdq_item *new_item;
|
||||
struct session *s = ne->session;
|
||||
struct window *w = ne->window;
|
||||
struct options_entry *o;
|
||||
struct options_array_item *a;
|
||||
struct cmd_list *cmdlist;
|
||||
|
||||
log_debug("%s: %s", __func__, ne->name);
|
||||
|
||||
cmd_find_clear_state(&fs, 0);
|
||||
if (cmd_find_empty_state(&ne->fs) || !cmd_find_valid_state(&ne->fs))
|
||||
@@ -49,26 +70,31 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
||||
else
|
||||
cmd_find_copy_state(&fs, &ne->fs);
|
||||
|
||||
hook = hooks_find(hooks_get(fs.s), ne->name);
|
||||
if (hook == NULL)
|
||||
if (fs.s == NULL)
|
||||
oo = global_s_options;
|
||||
else
|
||||
oo = fs.s->options;
|
||||
o = options_get(oo, ne->name);
|
||||
if (o == NULL)
|
||||
return;
|
||||
log_debug("notify hook %s", ne->name);
|
||||
|
||||
new_item = cmdq_get_command(hook->cmdlist, &fs, NULL, CMDQ_NOHOOKS);
|
||||
cmdq_format(new_item, "hook", "%s", ne->name);
|
||||
a = options_array_first(o);
|
||||
while (a != NULL) {
|
||||
cmdlist = options_array_item_value(a)->cmdlist;
|
||||
if (cmdlist == NULL) {
|
||||
a = options_array_next(a);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (s != NULL) {
|
||||
cmdq_format(new_item, "hook_session", "$%u", s->id);
|
||||
cmdq_format(new_item, "hook_session_name", "%s", s->name);
|
||||
new_item = cmdq_get_command(cmdlist, &fs, NULL, CMDQ_NOHOOKS);
|
||||
cmdq_format(new_item, "hook", "%s", ne->name);
|
||||
notify_hook_formats(new_item, s, w, ne->pane);
|
||||
|
||||
cmdq_insert_after(item, new_item);
|
||||
item = new_item;
|
||||
|
||||
a = options_array_next(a);
|
||||
}
|
||||
if (w != NULL) {
|
||||
cmdq_format(new_item, "hook_window", "@%u", w->id);
|
||||
cmdq_format(new_item, "hook_window_name", "%s", w->name);
|
||||
}
|
||||
if (ne->pane != -1)
|
||||
cmdq_format(new_item, "hook_pane", "%%%d", ne->pane);
|
||||
|
||||
cmdq_insert_after(item, new_item);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -101,7 +127,7 @@ notify_callback(struct cmdq_item *item, void *data)
|
||||
if (strcmp(ne->name, "session-window-changed") == 0)
|
||||
control_notify_session_window_changed(ne->session);
|
||||
|
||||
notify_hook(item, ne);
|
||||
notify_insert_hook(item, ne);
|
||||
|
||||
if (ne->client != NULL)
|
||||
server_client_unref(ne->client);
|
||||
@@ -154,13 +180,31 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
|
||||
}
|
||||
|
||||
void
|
||||
notify_input(struct window_pane *wp, struct evbuffer *input)
|
||||
notify_hook(struct cmdq_item *item, const char *name)
|
||||
{
|
||||
struct notify_entry ne;
|
||||
|
||||
memset(&ne, 0, sizeof ne);
|
||||
|
||||
ne.name = name;
|
||||
cmd_find_copy_state(&ne.fs, &item->target);
|
||||
|
||||
ne.client = item->client;
|
||||
ne.session = item->target.s;
|
||||
ne.window = item->target.w;
|
||||
ne.pane = item->target.wp->id;
|
||||
|
||||
notify_insert_hook(item, &ne);
|
||||
}
|
||||
|
||||
void
|
||||
notify_input(struct window_pane *wp, const u_char *buf, size_t len)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->flags & CLIENT_CONTROL)
|
||||
control_notify_input(c, wp, input);
|
||||
control_notify_input(c, wp, buf, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
452
options-table.c
452
options-table.c
@@ -38,6 +38,9 @@ static const char *options_table_mode_keys_list[] = {
|
||||
static const char *options_table_clock_mode_style_list[] = {
|
||||
"12", "24", NULL
|
||||
};
|
||||
static const char *options_table_status_list[] = {
|
||||
"off", "on", "2", "3", "4", "5", NULL
|
||||
};
|
||||
static const char *options_table_status_keys_list[] = {
|
||||
"emacs", "vi", NULL
|
||||
};
|
||||
@@ -59,9 +62,86 @@ static const char *options_table_pane_status_list[] = {
|
||||
static const char *options_table_set_clipboard_list[] = {
|
||||
"off", "external", "on", NULL
|
||||
};
|
||||
static const char *options_table_window_size_list[] = {
|
||||
"largest", "smallest", "manual", NULL
|
||||
};
|
||||
|
||||
/* Status line format. */
|
||||
#define OPTIONS_TABLE_STATUS_FORMAT1 \
|
||||
"#[align=left range=left #{status-left-style}]" \
|
||||
"#{T;=/#{status-left-length}:status-left}#[norange default]" \
|
||||
"#[list=on align=#{status-justify}]" \
|
||||
"#[list=left-marker]<#[list=right-marker]>#[list=on]" \
|
||||
"#{W:" \
|
||||
"#[range=window|#{window_index} " \
|
||||
"#{window-status-style}" \
|
||||
"#{?#{&&:#{window_last_flag}," \
|
||||
"#{!=:#{window-status-last-style},default}}, " \
|
||||
"#{window-status-last-style}," \
|
||||
"}" \
|
||||
"#{?#{&&:#{window_bell_flag}," \
|
||||
"#{!=:#{window-status-bell-style},default}}, " \
|
||||
"#{window-status-bell-style}," \
|
||||
"#{?#{&&:#{||:#{window_activity_flag}," \
|
||||
"#{window_silence_flag}}," \
|
||||
"#{!=:" \
|
||||
"#{window-status-activity-style}," \
|
||||
"default}}, " \
|
||||
"#{window-status-activity-style}," \
|
||||
"}" \
|
||||
"}" \
|
||||
"]" \
|
||||
"#{T:window-status-format}" \
|
||||
"#[norange default]" \
|
||||
"#{?window_end_flag,,#{window-status-separator}}" \
|
||||
"," \
|
||||
"#[range=window|#{window_index} list=focus " \
|
||||
"#{?#{!=:#{window-status-current-style},default}," \
|
||||
"#{window-status-current-style}," \
|
||||
"#{window-status-style}" \
|
||||
"}" \
|
||||
"#{?#{&&:#{window_last_flag}," \
|
||||
"#{!=:#{window-status-last-style},default}}, " \
|
||||
"#{window-status-last-style}," \
|
||||
"}" \
|
||||
"#{?#{&&:#{window_bell_flag}," \
|
||||
"#{!=:#{window-status-bell-style},default}}, " \
|
||||
"#{window-status-bell-style}," \
|
||||
"#{?#{&&:#{||:#{window_activity_flag}," \
|
||||
"#{window_silence_flag}}," \
|
||||
"#{!=:" \
|
||||
"#{window-status-activity-style}," \
|
||||
"default}}, " \
|
||||
"#{window-status-activity-style}," \
|
||||
"}" \
|
||||
"}" \
|
||||
"]" \
|
||||
"#{T:window-status-current-format}" \
|
||||
"#[norange list=on default]" \
|
||||
"#{?window_end_flag,,#{window-status-separator}}" \
|
||||
"}" \
|
||||
"#[nolist align=right range=right #{status-right-style}]" \
|
||||
"#{T;=/#{status-right-length}:status-right}#[norange default]"
|
||||
#define OPTIONS_TABLE_STATUS_FORMAT2 \
|
||||
"#[align=centre]#{P:#{?pane_active,#[reverse],}" \
|
||||
"#{pane_index}[#{pane_width}x#{pane_height}]#[default] }"
|
||||
static const char *options_table_status_format_default[] = {
|
||||
OPTIONS_TABLE_STATUS_FORMAT1, OPTIONS_TABLE_STATUS_FORMAT2, NULL
|
||||
};
|
||||
|
||||
/* Helper for hook options. */
|
||||
#define OPTIONS_TABLE_HOOK(hook_name, default_value) \
|
||||
{ .name = hook_name, \
|
||||
.type = OPTIONS_TABLE_COMMAND, \
|
||||
.scope = OPTIONS_TABLE_SESSION, \
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY|OPTIONS_TABLE_IS_HOOK, \
|
||||
.default_str = default_value, \
|
||||
.separator = "" \
|
||||
}
|
||||
|
||||
/* Top-level options. */
|
||||
const struct options_table_entry options_table[] = {
|
||||
/* Server options. */
|
||||
{ .name = "buffer-limit",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
@@ -71,8 +151,9 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "command-alias",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||
.default_str = "split-pane=split-window,"
|
||||
"splitp=split-window,"
|
||||
"server-info=show-messages -JT,"
|
||||
@@ -136,8 +217,9 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "terminal-overrides",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||
.default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
|
||||
":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
|
||||
":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT",
|
||||
@@ -145,12 +227,14 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "user-keys",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||
.default_str = "",
|
||||
.separator = ","
|
||||
},
|
||||
|
||||
/* Session options. */
|
||||
{ .name = "activity-action",
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -193,6 +277,13 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = _PATH_BSHELL
|
||||
},
|
||||
|
||||
{ .name = "default-size",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.pattern = "[0-9]*x[0-9]*",
|
||||
.default_str = "80x24"
|
||||
},
|
||||
|
||||
{ .name = "destroy-unattached",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -261,54 +352,12 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "lock -np"
|
||||
},
|
||||
|
||||
{ .name = "message-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "message-style"
|
||||
},
|
||||
|
||||
{ .name = "message-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 3,
|
||||
.style = "message-style"
|
||||
},
|
||||
|
||||
{ .name = "message-command-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "message-command-style"
|
||||
},
|
||||
|
||||
{ .name = "message-command-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "message-command-style"
|
||||
},
|
||||
|
||||
{ .name = "message-command-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 3,
|
||||
.style = "message-command-style"
|
||||
},
|
||||
|
||||
{ .name = "message-command-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_str = "bg=black,fg=yellow"
|
||||
},
|
||||
|
||||
{ .name = "message-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "message-style"
|
||||
},
|
||||
|
||||
{ .name = "message-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -367,30 +416,29 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "status",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.choices = options_table_status_list,
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
{ .name = "status-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "status-style"
|
||||
},
|
||||
|
||||
{ .name = "status-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 2,
|
||||
.style = "status-style"
|
||||
},
|
||||
|
||||
{ .name = "status-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "status-style"
|
||||
},
|
||||
|
||||
{ .name = "status-format",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||
.default_arr = options_table_status_format_default,
|
||||
},
|
||||
|
||||
{ .name = "status-interval",
|
||||
@@ -421,27 +469,6 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "[#S] "
|
||||
},
|
||||
|
||||
{ .name = "status-left-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "status-left-style"
|
||||
},
|
||||
|
||||
{ .name = "status-left-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 8,
|
||||
.style = "status-left-style"
|
||||
},
|
||||
|
||||
{ .name = "status-left-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 8,
|
||||
.style = "status-left-style"
|
||||
},
|
||||
|
||||
{ .name = "status-left-length",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -466,28 +493,9 @@ const struct options_table_entry options_table[] = {
|
||||
{ .name = "status-right",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_str = " \"#{=21:pane_title}\" %H:%M %d-%b-%y"
|
||||
},
|
||||
|
||||
{ .name = "status-right-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0,
|
||||
.style = "status-right-style"
|
||||
},
|
||||
|
||||
{ .name = "status-right-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 8,
|
||||
.style = "status-right-style"
|
||||
},
|
||||
|
||||
{ .name = "status-right-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 8,
|
||||
.style = "status-right-style"
|
||||
.default_str = "#{?window_bigger,"
|
||||
"[#{window_offset_x}#,#{window_offset_y}] ,}"
|
||||
"\"#{=21:pane_title}\" %H:%M %d-%b-%y"
|
||||
},
|
||||
|
||||
{ .name = "status-right-length",
|
||||
@@ -511,10 +519,11 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "update-environment",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
|
||||
"SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||
.flags = OPTIONS_TABLE_IS_ARRAY,
|
||||
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK "
|
||||
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||
},
|
||||
|
||||
{ .name = "visual-activity",
|
||||
@@ -541,9 +550,10 @@ const struct options_table_entry options_table[] = {
|
||||
{ .name = "word-separators",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_str = " -_@"
|
||||
.default_str = " "
|
||||
},
|
||||
|
||||
/* Window options. */
|
||||
{ .name = "aggressive-resize",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -588,22 +598,6 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
{ .name = "force-height",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.minimum = 0,
|
||||
.maximum = INT_MAX,
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "force-width",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.minimum = 0,
|
||||
.maximum = INT_MAX,
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "main-pane-height",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -620,27 +614,6 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 80
|
||||
},
|
||||
|
||||
{ .name = "mode-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 0,
|
||||
.style = "mode-style"
|
||||
},
|
||||
|
||||
{ .name = "mode-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 3,
|
||||
.style = "mode-style"
|
||||
},
|
||||
|
||||
{ .name = "mode-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 0,
|
||||
.style = "mode-style"
|
||||
},
|
||||
|
||||
{ .name = "mode-keys",
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -690,20 +663,6 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "pane-active-border-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "pane-active-border-style"
|
||||
},
|
||||
|
||||
{ .name = "pane-active-border-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 2,
|
||||
.style = "pane-active-border-style"
|
||||
},
|
||||
|
||||
{ .name = "pane-active-border-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -718,20 +677,6 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "pane-border-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "pane-border-style"
|
||||
},
|
||||
|
||||
{ .name = "pane-border-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "pane-border-style"
|
||||
},
|
||||
|
||||
{ .name = "pane-border-format",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -770,101 +715,31 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "default"
|
||||
},
|
||||
|
||||
{ .name = "window-size",
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.choices = options_table_window_size_list,
|
||||
.default_num = WINDOW_SIZE_SMALLEST
|
||||
},
|
||||
|
||||
{ .name = "window-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "default"
|
||||
},
|
||||
|
||||
{ .name = "window-status-activity-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = GRID_ATTR_REVERSE,
|
||||
.style = "window-status-activity-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-activity-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-activity-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-activity-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-activity-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-activity-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "reverse"
|
||||
},
|
||||
|
||||
{ .name = "window-status-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 0,
|
||||
.style = "window-status-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-bell-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = GRID_ATTR_REVERSE,
|
||||
.style = "window-status-bell-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-bell-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-bell-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-bell-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-bell-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-bell-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "reverse"
|
||||
},
|
||||
|
||||
{ .name = "window-status-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-current-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 0,
|
||||
.style = "window-status-current-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-current-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-current-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-current-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-current-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-current-format",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -877,40 +752,12 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "default"
|
||||
},
|
||||
|
||||
{ .name = "window-status-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-format",
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "#I:#W#{?window_flags,#{window_flags}, }"
|
||||
},
|
||||
|
||||
{ .name = "window-status-last-attr",
|
||||
.type = OPTIONS_TABLE_ATTRIBUTES,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 0,
|
||||
.style = "window-status-last-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-last-bg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-last-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-last-fg",
|
||||
.type = OPTIONS_TABLE_COLOUR,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 8,
|
||||
.style = "window-status-last-style"
|
||||
},
|
||||
|
||||
{ .name = "window-status-last-style",
|
||||
.type = OPTIONS_TABLE_STYLE,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -941,5 +788,66 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
/* Hook options. */
|
||||
OPTIONS_TABLE_HOOK("after-bind-key", ""),
|
||||
OPTIONS_TABLE_HOOK("after-capture-pane", ""),
|
||||
OPTIONS_TABLE_HOOK("after-copy-mode", ""),
|
||||
OPTIONS_TABLE_HOOK("after-display-message", ""),
|
||||
OPTIONS_TABLE_HOOK("after-display-panes", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-buffers", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-clients", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-keys", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-panes", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-sessions", ""),
|
||||
OPTIONS_TABLE_HOOK("after-list-windows", ""),
|
||||
OPTIONS_TABLE_HOOK("after-load-buffer", ""),
|
||||
OPTIONS_TABLE_HOOK("after-lock-server", ""),
|
||||
OPTIONS_TABLE_HOOK("after-new-session", ""),
|
||||
OPTIONS_TABLE_HOOK("after-new-window", ""),
|
||||
OPTIONS_TABLE_HOOK("after-paste-buffer", ""),
|
||||
OPTIONS_TABLE_HOOK("after-pipe-pane", ""),
|
||||
OPTIONS_TABLE_HOOK("after-queue", ""),
|
||||
OPTIONS_TABLE_HOOK("after-refresh-client", ""),
|
||||
OPTIONS_TABLE_HOOK("after-rename-session", ""),
|
||||
OPTIONS_TABLE_HOOK("after-rename-window", ""),
|
||||
OPTIONS_TABLE_HOOK("after-resize-pane", ""),
|
||||
OPTIONS_TABLE_HOOK("after-resize-window", ""),
|
||||
OPTIONS_TABLE_HOOK("after-save-buffer", ""),
|
||||
OPTIONS_TABLE_HOOK("after-select-layout", ""),
|
||||
OPTIONS_TABLE_HOOK("after-select-pane", ""),
|
||||
OPTIONS_TABLE_HOOK("after-select-window", ""),
|
||||
OPTIONS_TABLE_HOOK("after-send-keys", ""),
|
||||
OPTIONS_TABLE_HOOK("after-set-buffer", ""),
|
||||
OPTIONS_TABLE_HOOK("after-set-environment", ""),
|
||||
OPTIONS_TABLE_HOOK("after-set-hook", ""),
|
||||
OPTIONS_TABLE_HOOK("after-set-option", ""),
|
||||
OPTIONS_TABLE_HOOK("after-show-environment", ""),
|
||||
OPTIONS_TABLE_HOOK("after-show-messages", ""),
|
||||
OPTIONS_TABLE_HOOK("after-show-options", ""),
|
||||
OPTIONS_TABLE_HOOK("after-split-window", ""),
|
||||
OPTIONS_TABLE_HOOK("after-unbind-key", ""),
|
||||
OPTIONS_TABLE_HOOK("alert-activity", ""),
|
||||
OPTIONS_TABLE_HOOK("alert-bell", ""),
|
||||
OPTIONS_TABLE_HOOK("alert-silence", ""),
|
||||
OPTIONS_TABLE_HOOK("client-attached", ""),
|
||||
OPTIONS_TABLE_HOOK("client-detached", ""),
|
||||
OPTIONS_TABLE_HOOK("client-resized", ""),
|
||||
OPTIONS_TABLE_HOOK("client-session-changed", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-died", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-exited", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-focus-in", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-focus-out", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-mode-changed", ""),
|
||||
OPTIONS_TABLE_HOOK("pane-set-clipboard", ""),
|
||||
OPTIONS_TABLE_HOOK("session-closed", ""),
|
||||
OPTIONS_TABLE_HOOK("session-created", ""),
|
||||
OPTIONS_TABLE_HOOK("session-renamed", ""),
|
||||
OPTIONS_TABLE_HOOK("session-window-changed", ""),
|
||||
OPTIONS_TABLE_HOOK("window-layout-changed", ""),
|
||||
OPTIONS_TABLE_HOOK("window-linked", ""),
|
||||
OPTIONS_TABLE_HOOK("window-pane-changed", ""),
|
||||
OPTIONS_TABLE_HOOK("window-renamed", ""),
|
||||
OPTIONS_TABLE_HOOK("window-unlinked", ""),
|
||||
|
||||
{ .name = NULL }
|
||||
};
|
||||
|
||||
437
options.c
437
options.c
@@ -30,23 +30,30 @@
|
||||
* a red-black tree.
|
||||
*/
|
||||
|
||||
struct options_array_item {
|
||||
u_int index;
|
||||
union options_value value;
|
||||
RB_ENTRY(options_array_item) entry;
|
||||
};
|
||||
static int
|
||||
options_array_cmp(struct options_array_item *a1, struct options_array_item *a2)
|
||||
{
|
||||
if (a1->index < a2->index)
|
||||
return (-1);
|
||||
if (a1->index > a2->index)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
RB_GENERATE_STATIC(options_array, options_array_item, entry, options_array_cmp);
|
||||
|
||||
struct options_entry {
|
||||
struct options *owner;
|
||||
struct options *owner;
|
||||
|
||||
const char *name;
|
||||
const struct options_table_entry *tableentry;
|
||||
const char *name;
|
||||
const struct options_table_entry *tableentry;
|
||||
union options_value value;
|
||||
|
||||
union {
|
||||
char *string;
|
||||
long long number;
|
||||
struct grid_cell style;
|
||||
struct {
|
||||
const char **array;
|
||||
u_int arraysize;
|
||||
};
|
||||
};
|
||||
|
||||
RB_ENTRY(options_entry) entry;
|
||||
RB_ENTRY(options_entry) entry;
|
||||
};
|
||||
|
||||
struct options {
|
||||
@@ -56,8 +63,6 @@ struct options {
|
||||
|
||||
static struct options_entry *options_add(struct options *, const char *);
|
||||
|
||||
#define OPTIONS_ARRAY_LIMIT 1000
|
||||
|
||||
#define OPTIONS_IS_STRING(o) \
|
||||
((o)->tableentry == NULL || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_STRING)
|
||||
@@ -66,15 +71,18 @@ static struct options_entry *options_add(struct options *, const char *);
|
||||
((o)->tableentry->type == OPTIONS_TABLE_NUMBER || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_KEY || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_COLOUR || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_ATTRIBUTES || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_FLAG || \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_CHOICE))
|
||||
#define OPTIONS_IS_STYLE(o) \
|
||||
((o)->tableentry != NULL && \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_STYLE)
|
||||
#define OPTIONS_IS_ARRAY(o) \
|
||||
#define OPTIONS_IS_COMMAND(o) \
|
||||
((o)->tableentry != NULL && \
|
||||
(o)->tableentry->type == OPTIONS_TABLE_ARRAY)
|
||||
(o)->tableentry->type == OPTIONS_TABLE_COMMAND)
|
||||
|
||||
#define OPTIONS_IS_ARRAY(o) \
|
||||
((o)->tableentry != NULL && \
|
||||
((o)->tableentry->flags & OPTIONS_TABLE_IS_ARRAY))
|
||||
|
||||
static int options_cmp(struct options_entry *, struct options_entry *);
|
||||
RB_GENERATE_STATIC(options_tree, options_entry, entry, options_cmp);
|
||||
@@ -98,6 +106,57 @@ options_parent_table_entry(struct options *oo, const char *s)
|
||||
return (o->tableentry);
|
||||
}
|
||||
|
||||
static void
|
||||
options_value_free(struct options_entry *o, union options_value *ov)
|
||||
{
|
||||
if (OPTIONS_IS_STRING(o))
|
||||
free(ov->string);
|
||||
if (OPTIONS_IS_COMMAND(o) && ov->cmdlist != NULL)
|
||||
cmd_list_free(ov->cmdlist);
|
||||
}
|
||||
|
||||
static char *
|
||||
options_value_tostring(struct options_entry *o, union options_value *ov,
|
||||
int numeric)
|
||||
{
|
||||
char *s;
|
||||
|
||||
if (OPTIONS_IS_COMMAND(o))
|
||||
return (cmd_list_print(ov->cmdlist, 0));
|
||||
if (OPTIONS_IS_STYLE(o))
|
||||
return (xstrdup(style_tostring(&ov->style)));
|
||||
if (OPTIONS_IS_NUMBER(o)) {
|
||||
switch (o->tableentry->type) {
|
||||
case OPTIONS_TABLE_NUMBER:
|
||||
xasprintf(&s, "%lld", ov->number);
|
||||
break;
|
||||
case OPTIONS_TABLE_KEY:
|
||||
s = xstrdup(key_string_lookup_key(ov->number));
|
||||
break;
|
||||
case OPTIONS_TABLE_COLOUR:
|
||||
s = xstrdup(colour_tostring(ov->number));
|
||||
break;
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
if (numeric)
|
||||
xasprintf(&s, "%lld", ov->number);
|
||||
else
|
||||
s = xstrdup(ov->number ? "on" : "off");
|
||||
break;
|
||||
case OPTIONS_TABLE_CHOICE:
|
||||
s = xstrdup(o->tableentry->choices[ov->number]);
|
||||
break;
|
||||
case OPTIONS_TABLE_STRING:
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
case OPTIONS_TABLE_COMMAND:
|
||||
fatalx("not a number option type");
|
||||
}
|
||||
return (s);
|
||||
}
|
||||
if (OPTIONS_IS_STRING(o))
|
||||
return (xstrdup(ov->string));
|
||||
return (xstrdup(""));
|
||||
}
|
||||
|
||||
struct options *
|
||||
options_create(struct options *parent)
|
||||
{
|
||||
@@ -163,6 +222,9 @@ options_empty(struct options *oo, const struct options_table_entry *oe)
|
||||
o = options_add(oo, oe->name);
|
||||
o->tableentry = oe;
|
||||
|
||||
if (oe->flags & OPTIONS_TABLE_IS_ARRAY)
|
||||
RB_INIT(&o->value.array);
|
||||
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -170,17 +232,34 @@ struct options_entry *
|
||||
options_default(struct options *oo, const struct options_table_entry *oe)
|
||||
{
|
||||
struct options_entry *o;
|
||||
union options_value *ov;
|
||||
u_int i;
|
||||
|
||||
o = options_empty(oo, oe);
|
||||
if (oe->type == OPTIONS_TABLE_ARRAY)
|
||||
options_array_assign(o, oe->default_str);
|
||||
else if (oe->type == OPTIONS_TABLE_STRING)
|
||||
o->string = xstrdup(oe->default_str);
|
||||
else if (oe->type == OPTIONS_TABLE_STYLE) {
|
||||
memcpy(&o->style, &grid_default_cell, sizeof o->style);
|
||||
style_parse(&grid_default_cell, &o->style, oe->default_str);
|
||||
} else
|
||||
o->number = oe->default_num;
|
||||
ov = &o->value;
|
||||
|
||||
if (oe->flags & OPTIONS_TABLE_IS_ARRAY) {
|
||||
if (oe->default_arr == NULL) {
|
||||
options_array_assign(o, oe->default_str, NULL);
|
||||
return (o);
|
||||
}
|
||||
for (i = 0; oe->default_arr[i] != NULL; i++)
|
||||
options_array_set(o, i, oe->default_arr[i], 0, NULL);
|
||||
return (o);
|
||||
}
|
||||
|
||||
switch (oe->type) {
|
||||
case OPTIONS_TABLE_STRING:
|
||||
ov->string = xstrdup(oe->default_str);
|
||||
break;
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
style_set(&ov->style, &grid_default_cell);
|
||||
style_parse(&ov->style, &grid_default_cell, oe->default_str);
|
||||
break;
|
||||
default:
|
||||
ov->number = oe->default_num;
|
||||
break;
|
||||
}
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -205,16 +284,11 @@ void
|
||||
options_remove(struct options_entry *o)
|
||||
{
|
||||
struct options *oo = o->owner;
|
||||
u_int i;
|
||||
|
||||
if (OPTIONS_IS_STRING(o))
|
||||
free((void *)o->string);
|
||||
else if (OPTIONS_IS_ARRAY(o)) {
|
||||
for (i = 0; i < o->arraysize; i++)
|
||||
free((void *)o->array[i]);
|
||||
free(o->array);
|
||||
}
|
||||
|
||||
if (OPTIONS_IS_ARRAY(o))
|
||||
options_array_clear(o);
|
||||
else
|
||||
options_value_free(o, &o->value);
|
||||
RB_REMOVE(options_tree, &oo->tree, o);
|
||||
free(o);
|
||||
}
|
||||
@@ -231,67 +305,109 @@ options_table_entry(struct options_entry *o)
|
||||
return (o->tableentry);
|
||||
}
|
||||
|
||||
static struct options_array_item *
|
||||
options_array_item(struct options_entry *o, u_int idx)
|
||||
{
|
||||
struct options_array_item a;
|
||||
|
||||
a.index = idx;
|
||||
return (RB_FIND(options_array, &o->value.array, &a));
|
||||
}
|
||||
|
||||
static void
|
||||
options_array_free(struct options_entry *o, struct options_array_item *a)
|
||||
{
|
||||
options_value_free(o, &a->value);
|
||||
RB_REMOVE(options_array, &o->value.array, a);
|
||||
free(a);
|
||||
}
|
||||
|
||||
void
|
||||
options_array_clear(struct options_entry *o)
|
||||
{
|
||||
if (OPTIONS_IS_ARRAY(o))
|
||||
o->arraysize = 0;
|
||||
struct options_array_item *a, *a1;
|
||||
|
||||
if (!OPTIONS_IS_ARRAY(o))
|
||||
return;
|
||||
|
||||
RB_FOREACH_SAFE(a, options_array, &o->value.array, a1)
|
||||
options_array_free(o, a);
|
||||
}
|
||||
|
||||
const char *
|
||||
union options_value *
|
||||
options_array_get(struct options_entry *o, u_int idx)
|
||||
{
|
||||
struct options_array_item *a;
|
||||
|
||||
if (!OPTIONS_IS_ARRAY(o))
|
||||
return (NULL);
|
||||
if (idx >= o->arraysize)
|
||||
a = options_array_item(o, idx);
|
||||
if (a == NULL)
|
||||
return (NULL);
|
||||
return (o->array[idx]);
|
||||
return (&a->value);
|
||||
}
|
||||
|
||||
int
|
||||
options_array_set(struct options_entry *o, u_int idx, const char *value,
|
||||
int append)
|
||||
int append, char **cause)
|
||||
{
|
||||
char *new;
|
||||
u_int i;
|
||||
struct options_array_item *a;
|
||||
char *new;
|
||||
struct cmd_parse_result *pr;
|
||||
|
||||
if (!OPTIONS_IS_ARRAY(o))
|
||||
if (!OPTIONS_IS_ARRAY(o)) {
|
||||
if (cause != NULL)
|
||||
*cause = xstrdup("not an array");
|
||||
return (-1);
|
||||
|
||||
if (idx >= OPTIONS_ARRAY_LIMIT)
|
||||
return (-1);
|
||||
if (idx >= o->arraysize) {
|
||||
o->array = xreallocarray(o->array, idx + 1, sizeof *o->array);
|
||||
for (i = o->arraysize; i < idx + 1; i++)
|
||||
o->array[i] = NULL;
|
||||
o->arraysize = idx + 1;
|
||||
}
|
||||
|
||||
new = NULL;
|
||||
if (value != NULL) {
|
||||
if (o->array[idx] != NULL && append)
|
||||
xasprintf(&new, "%s%s", o->array[idx], value);
|
||||
if (OPTIONS_IS_COMMAND(o) && value != NULL) {
|
||||
pr = cmd_parse_from_string(value, NULL);
|
||||
switch (pr->status) {
|
||||
case CMD_PARSE_EMPTY:
|
||||
*cause = xstrdup("empty command");
|
||||
return (-1);
|
||||
case CMD_PARSE_ERROR:
|
||||
if (cause != NULL)
|
||||
*cause = pr->error;
|
||||
else
|
||||
free(pr->error);
|
||||
return (-1);
|
||||
case CMD_PARSE_SUCCESS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
a = options_array_item(o, idx);
|
||||
if (value == NULL) {
|
||||
if (a != NULL)
|
||||
options_array_free(o, a);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (OPTIONS_IS_STRING(o)) {
|
||||
if (a != NULL && append)
|
||||
xasprintf(&new, "%s%s", a->value.string, value);
|
||||
else
|
||||
new = xstrdup(value);
|
||||
}
|
||||
|
||||
free((void *)o->array[idx]);
|
||||
o->array[idx] = new;
|
||||
if (a == NULL) {
|
||||
a = xcalloc(1, sizeof *a);
|
||||
a->index = idx;
|
||||
RB_INSERT(options_array, &o->value.array, a);
|
||||
} else
|
||||
options_value_free(o, &a->value);
|
||||
|
||||
if (OPTIONS_IS_STRING(o))
|
||||
a->value.string = new;
|
||||
else if (OPTIONS_IS_COMMAND(o))
|
||||
a->value.cmdlist = pr->cmdlist;
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
options_array_size(struct options_entry *o, u_int *size)
|
||||
{
|
||||
if (!OPTIONS_IS_ARRAY(o))
|
||||
return (-1);
|
||||
if (size != NULL)
|
||||
*size = o->arraysize;
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
options_array_assign(struct options_entry *o, const char *s)
|
||||
options_array_assign(struct options_entry *o, const char *s, char **cause)
|
||||
{
|
||||
const char *separator;
|
||||
char *copy, *next, *string;
|
||||
@@ -300,81 +416,89 @@ options_array_assign(struct options_entry *o, const char *s)
|
||||
separator = o->tableentry->separator;
|
||||
if (separator == NULL)
|
||||
separator = " ,";
|
||||
if (*separator == '\0') {
|
||||
if (*s == '\0')
|
||||
return (0);
|
||||
for (i = 0; i < UINT_MAX; i++) {
|
||||
if (options_array_item(o, i) == NULL)
|
||||
break;
|
||||
}
|
||||
return (options_array_set(o, i, s, 0, cause));
|
||||
}
|
||||
|
||||
if (*s == '\0')
|
||||
return (0);
|
||||
copy = string = xstrdup(s);
|
||||
while ((next = strsep(&string, separator)) != NULL) {
|
||||
if (*next == '\0')
|
||||
continue;
|
||||
for (i = 0; i < OPTIONS_ARRAY_LIMIT; i++) {
|
||||
if (i >= o->arraysize || o->array[i] == NULL)
|
||||
for (i = 0; i < UINT_MAX; i++) {
|
||||
if (options_array_item(o, i) == NULL)
|
||||
break;
|
||||
}
|
||||
if (i == OPTIONS_ARRAY_LIMIT)
|
||||
if (i == UINT_MAX)
|
||||
break;
|
||||
options_array_set(o, i, next, 0);
|
||||
if (options_array_set(o, i, next, 0, cause) != 0) {
|
||||
free(copy);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
free(copy);
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct options_array_item *
|
||||
options_array_first(struct options_entry *o)
|
||||
{
|
||||
if (!OPTIONS_IS_ARRAY(o))
|
||||
return (NULL);
|
||||
return (RB_MIN(options_array, &o->value.array));
|
||||
}
|
||||
|
||||
struct options_array_item *
|
||||
options_array_next(struct options_array_item *a)
|
||||
{
|
||||
return (RB_NEXT(options_array, &o->value.array, a));
|
||||
}
|
||||
|
||||
u_int
|
||||
options_array_item_index(struct options_array_item *a)
|
||||
{
|
||||
return (a->index);
|
||||
}
|
||||
|
||||
union options_value *
|
||||
options_array_item_value(struct options_array_item *a)
|
||||
{
|
||||
return (&a->value);
|
||||
}
|
||||
|
||||
int
|
||||
options_isarray(struct options_entry *o)
|
||||
{
|
||||
return (OPTIONS_IS_ARRAY(o));
|
||||
}
|
||||
|
||||
int
|
||||
options_isstring(struct options_entry *o)
|
||||
{
|
||||
if (o->tableentry == NULL)
|
||||
return (1);
|
||||
return (OPTIONS_IS_STRING(o) || OPTIONS_IS_ARRAY(o));
|
||||
return (OPTIONS_IS_STRING(o));
|
||||
}
|
||||
|
||||
const char *
|
||||
char *
|
||||
options_tostring(struct options_entry *o, int idx, int numeric)
|
||||
{
|
||||
static char s[1024];
|
||||
const char *tmp;
|
||||
struct options_array_item *a;
|
||||
|
||||
if (OPTIONS_IS_ARRAY(o)) {
|
||||
if (idx == -1)
|
||||
return (NULL);
|
||||
if ((u_int)idx >= o->arraysize || o->array[idx] == NULL)
|
||||
return ("");
|
||||
return (o->array[idx]);
|
||||
return (xstrdup(""));
|
||||
a = options_array_item(o, idx);
|
||||
if (a == NULL)
|
||||
return (xstrdup(""));
|
||||
return (options_value_tostring(o, &a->value, numeric));
|
||||
}
|
||||
if (OPTIONS_IS_STYLE(o))
|
||||
return (style_tostring(&o->style));
|
||||
if (OPTIONS_IS_NUMBER(o)) {
|
||||
tmp = NULL;
|
||||
switch (o->tableentry->type) {
|
||||
case OPTIONS_TABLE_NUMBER:
|
||||
xsnprintf(s, sizeof s, "%lld", o->number);
|
||||
break;
|
||||
case OPTIONS_TABLE_KEY:
|
||||
tmp = key_string_lookup_key(o->number);
|
||||
break;
|
||||
case OPTIONS_TABLE_COLOUR:
|
||||
tmp = colour_tostring(o->number);
|
||||
break;
|
||||
case OPTIONS_TABLE_ATTRIBUTES:
|
||||
tmp = attributes_tostring(o->number);
|
||||
break;
|
||||
case OPTIONS_TABLE_FLAG:
|
||||
if (numeric)
|
||||
xsnprintf(s, sizeof s, "%lld", o->number);
|
||||
else
|
||||
tmp = (o->number ? "on" : "off");
|
||||
break;
|
||||
case OPTIONS_TABLE_CHOICE:
|
||||
tmp = o->tableentry->choices[o->number];
|
||||
break;
|
||||
case OPTIONS_TABLE_STRING:
|
||||
case OPTIONS_TABLE_STYLE:
|
||||
case OPTIONS_TABLE_ARRAY:
|
||||
break;
|
||||
}
|
||||
if (tmp != NULL)
|
||||
xsnprintf(s, sizeof s, "%s", tmp);
|
||||
return (s);
|
||||
}
|
||||
if (OPTIONS_IS_STRING(o))
|
||||
return (o->string);
|
||||
return (NULL);
|
||||
return (options_value_tostring(o, &o->value, numeric));
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -488,7 +612,7 @@ options_get_string(struct options *oo, const char *name)
|
||||
fatalx("missing option %s", name);
|
||||
if (!OPTIONS_IS_STRING(o))
|
||||
fatalx("option %s is not a string", name);
|
||||
return (o->string);
|
||||
return (o->value.string);
|
||||
}
|
||||
|
||||
long long
|
||||
@@ -501,10 +625,10 @@ options_get_number(struct options *oo, const char *name)
|
||||
fatalx("missing option %s", name);
|
||||
if (!OPTIONS_IS_NUMBER(o))
|
||||
fatalx("option %s is not a number", name);
|
||||
return (o->number);
|
||||
return (o->value.number);
|
||||
}
|
||||
|
||||
const struct grid_cell *
|
||||
struct style *
|
||||
options_get_style(struct options *oo, const char *name)
|
||||
{
|
||||
struct options_entry *o;
|
||||
@@ -514,7 +638,7 @@ options_get_style(struct options *oo, const char *name)
|
||||
fatalx("missing option %s", name);
|
||||
if (!OPTIONS_IS_STYLE(o))
|
||||
fatalx("option %s is not a style", name);
|
||||
return (&o->style);
|
||||
return (&o->value.style);
|
||||
}
|
||||
|
||||
struct options_entry *
|
||||
@@ -531,7 +655,7 @@ options_set_string(struct options *oo, const char *name, int append,
|
||||
|
||||
o = options_get_only(oo, name);
|
||||
if (o != NULL && append && OPTIONS_IS_STRING(o)) {
|
||||
xasprintf(&value, "%s%s", o->string, s);
|
||||
xasprintf(&value, "%s%s", o->value.string, s);
|
||||
free(s);
|
||||
} else
|
||||
value = s;
|
||||
@@ -545,8 +669,8 @@ options_set_string(struct options *oo, const char *name, int append,
|
||||
|
||||
if (!OPTIONS_IS_STRING(o))
|
||||
fatalx("option %s is not a string", name);
|
||||
free(o->string);
|
||||
o->string = value;
|
||||
free(o->value.string);
|
||||
o->value.string = value;
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -567,7 +691,7 @@ options_set_number(struct options *oo, const char *name, long long value)
|
||||
|
||||
if (!OPTIONS_IS_NUMBER(o))
|
||||
fatalx("option %s is not a number", name);
|
||||
o->number = value;
|
||||
o->value.number = value;
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -576,17 +700,17 @@ options_set_style(struct options *oo, const char *name, int append,
|
||||
const char *value)
|
||||
{
|
||||
struct options_entry *o;
|
||||
struct grid_cell gc;
|
||||
struct style sy;
|
||||
|
||||
if (*name == '@')
|
||||
fatalx("user option %s must be a string", name);
|
||||
|
||||
o = options_get_only(oo, name);
|
||||
if (o != NULL && append && OPTIONS_IS_STYLE(o))
|
||||
memcpy(&gc, &o->style, sizeof gc);
|
||||
style_copy(&sy, &o->value.style);
|
||||
else
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
if (style_parse(&grid_default_cell, &gc, value) == -1)
|
||||
style_set(&sy, &grid_default_cell);
|
||||
if (style_parse(&sy, &grid_default_cell, value) == -1)
|
||||
return (NULL);
|
||||
if (o == NULL) {
|
||||
o = options_default(oo, options_parent_table_entry(oo, name));
|
||||
@@ -596,7 +720,7 @@ options_set_style(struct options *oo, const char *name, int append,
|
||||
|
||||
if (!OPTIONS_IS_STYLE(o))
|
||||
fatalx("option %s is not a style", name);
|
||||
memcpy(&o->style, &gc, sizeof o->style);
|
||||
style_copy(&o->value.style, &sy);
|
||||
return (o);
|
||||
}
|
||||
|
||||
@@ -643,44 +767,3 @@ options_scope_from_flags(struct args *args, int window,
|
||||
return (OPTIONS_TABLE_SESSION);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
options_style_update_new(struct options *oo, struct options_entry *o)
|
||||
{
|
||||
const char *newname = o->tableentry->style;
|
||||
struct options_entry *new;
|
||||
|
||||
if (newname == NULL)
|
||||
return;
|
||||
new = options_get_only(oo, newname);
|
||||
if (new == NULL)
|
||||
new = options_set_style(oo, newname, 0, "default");
|
||||
|
||||
if (strstr(o->name, "-bg") != NULL)
|
||||
new->style.bg = o->number;
|
||||
else if (strstr(o->name, "-fg") != NULL)
|
||||
new->style.fg = o->number;
|
||||
else if (strstr(o->name, "-attr") != NULL)
|
||||
new->style.attr = o->number;
|
||||
}
|
||||
|
||||
void
|
||||
options_style_update_old(struct options *oo, struct options_entry *o)
|
||||
{
|
||||
char newname[128];
|
||||
int size;
|
||||
|
||||
size = strrchr(o->name, '-') - o->name;
|
||||
|
||||
xsnprintf(newname, sizeof newname, "%.*s-bg", size, o->name);
|
||||
if (options_get(oo, newname) != NULL)
|
||||
options_set_number(oo, newname, o->style.bg);
|
||||
|
||||
xsnprintf(newname, sizeof newname, "%.*s-fg", size, o->name);
|
||||
if (options_get(oo, newname) != NULL)
|
||||
options_set_number(oo, newname, o->style.fg);
|
||||
|
||||
xsnprintf(newname, sizeof newname, "%.*s-attr", size, o->name);
|
||||
if (options_get(oo, newname) != NULL)
|
||||
options_set_number(oo, newname, o->style.attr);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,9 @@ char *osdep_get_name(int, char *);
|
||||
char *osdep_get_cwd(int);
|
||||
struct event_base *osdep_event_init(void);
|
||||
|
||||
#ifndef __unused
|
||||
#define __unused __attribute__ ((__unused__))
|
||||
#endif
|
||||
|
||||
char *
|
||||
osdep_get_name(int fd, __unused char *tty)
|
||||
@@ -47,6 +49,7 @@ osdep_get_name(int fd, __unused char *tty)
|
||||
&bsdinfo, sizeof bsdinfo);
|
||||
if (ret == sizeof bsdinfo && *bsdinfo.pbsi_comm != '\0')
|
||||
return (strdup(bsdinfo.pbsi_comm));
|
||||
return (NULL);
|
||||
#else
|
||||
int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
|
||||
size_t size;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <unistd.h>
|
||||
#include <libutil.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
struct kinfo_proc *cmp_procs(struct kinfo_proc *, struct kinfo_proc *);
|
||||
char *osdep_get_name(int, char *);
|
||||
char *osdep_get_cwd(int);
|
||||
|
||||
@@ -23,14 +23,17 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <event.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#define is_runnable(p) \
|
||||
((p)->p_stat == LSRUN || (p)->p_stat == SIDL)
|
||||
((p)->p_stat == LSRUN || (p)->p_stat == SIDL)
|
||||
#define is_stopped(p) \
|
||||
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB)
|
||||
((p)->p_stat == SSTOP || (p)->p_stat == SZOMB)
|
||||
|
||||
struct kinfo_proc2 *cmp_procs(struct kinfo_proc2 *, struct kinfo_proc2 *);
|
||||
char *osdep_get_name(int, char *);
|
||||
@@ -129,6 +132,22 @@ error:
|
||||
char *
|
||||
osdep_get_cwd(int fd)
|
||||
{
|
||||
static char target[PATH_MAX + 1];
|
||||
char *path;
|
||||
pid_t pgrp;
|
||||
ssize_t n;
|
||||
|
||||
if ((pgrp = tcgetpgrp(fd)) == -1)
|
||||
return (NULL);
|
||||
|
||||
xasprintf(&path, "/proc/%lld/cwd", (long long) pgrp);
|
||||
n = readlink(path, target, sizeof(target) - 1);
|
||||
free(path);
|
||||
if (n > 0) {
|
||||
target[n] = '\0';
|
||||
return (target);
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
||||
9
paste.c
9
paste.c
@@ -157,11 +157,14 @@ paste_free(struct paste_buffer *pb)
|
||||
* that the caller is responsible for allocating data.
|
||||
*/
|
||||
void
|
||||
paste_add(char *data, size_t size)
|
||||
paste_add(const char *prefix, char *data, size_t size)
|
||||
{
|
||||
struct paste_buffer *pb, *pb1;
|
||||
u_int limit;
|
||||
|
||||
if (prefix == NULL)
|
||||
prefix = "buffer";
|
||||
|
||||
if (size == 0) {
|
||||
free(data);
|
||||
return;
|
||||
@@ -180,7 +183,7 @@ paste_add(char *data, size_t size)
|
||||
pb->name = NULL;
|
||||
do {
|
||||
free(pb->name);
|
||||
xasprintf(&pb->name, "buffer%04u", paste_next_index);
|
||||
xasprintf(&pb->name, "%s%u", prefix, paste_next_index);
|
||||
paste_next_index++;
|
||||
} while (paste_get_name(pb->name) != NULL);
|
||||
|
||||
@@ -262,7 +265,7 @@ paste_set(char *data, size_t size, const char *name, char **cause)
|
||||
return (0);
|
||||
}
|
||||
if (name == NULL) {
|
||||
paste_add(data, size);
|
||||
paste_add(NULL, data, size);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user