mirror of
https://github.com/tmux/tmux.git
synced 2026-03-11 11:05:46 +00:00
Compare commits
726 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
01918cb017 | ||
|
|
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 | ||
|
|
8a81993ae1 | ||
|
|
b5c0b2cae2 | ||
|
|
803b8815bd | ||
|
|
785ce66ab9 | ||
|
|
640d97afd0 | ||
|
|
194e9f611b | ||
|
|
ea295ac397 | ||
|
|
5512de6a61 | ||
|
|
26792b9035 | ||
|
|
919f55ac4a | ||
|
|
2cd0ba5057 | ||
|
|
80283f99fb | ||
|
|
ced74bd72c | ||
|
|
50e3e3e72f | ||
|
|
c8a706117f | ||
|
|
0b3911631b | ||
|
|
0ca78ee51f | ||
|
|
f87d80737e | ||
|
|
9fd9952752 | ||
|
|
19f3a5c612 | ||
|
|
3c451a64b5 | ||
|
|
85c48aafff | ||
|
|
61ea49c6dd | ||
|
|
3b8f92359d | ||
|
|
182357f24b | ||
|
|
0ca9664ecf | ||
|
|
508e2f0b3a | ||
|
|
f5a37d0071 | ||
|
|
4d72b8fff7 | ||
|
|
9464b94f64 | ||
|
|
c2aa40449c | ||
|
|
3f3f13fbd7 | ||
|
|
e97daead43 | ||
|
|
623f4b12d3 | ||
|
|
5a44e18490 | ||
|
|
ab6f0bb348 | ||
|
|
4e8b1b9ac2 | ||
|
|
d81aec2439 | ||
|
|
6ae04dd5a0 | ||
|
|
968296bb07 | ||
|
|
320abba341 | ||
|
|
88711e885e | ||
|
|
7f4513ec34 | ||
|
|
2d5101621b | ||
|
|
0817132f97 | ||
|
|
24abfb72eb | ||
|
|
fe7a871a23 | ||
|
|
4e4c500879 | ||
|
|
0407d847a4 | ||
|
|
19afd842bf | ||
|
|
17d4c39f24 | ||
|
|
d9e740f86d | ||
|
|
c9037fde1c | ||
|
|
84ddc72744 | ||
|
|
75842bfe66 | ||
|
|
5849b73b81 | ||
|
|
58e9d12f23 | ||
|
|
53b25635da | ||
|
|
481703d669 | ||
|
|
b0c1cefeda | ||
|
|
2c5a6f9af5 | ||
|
|
c03565611e | ||
|
|
f32fd2df69 | ||
|
|
829fe38ab1 | ||
|
|
06684c93de | ||
|
|
d17c90583a | ||
|
|
fe26f977e6 | ||
|
|
6e99a2f4bb | ||
|
|
c9896d9554 | ||
|
|
ad417f6eb7 | ||
|
|
299c552e33 | ||
|
|
cd46568ebe | ||
|
|
937f8ed095 | ||
|
|
6ce8fe0537 | ||
|
|
c363c236aa | ||
|
|
e19df0e869 | ||
|
|
7ba5ad4cfb | ||
|
|
5c82432200 | ||
|
|
74ecc866cf | ||
|
|
b20a00f93e | ||
|
|
641a885af8 | ||
|
|
62144b9f57 | ||
|
|
43a1294ed9 | ||
|
|
58f6456af7 | ||
|
|
2c6af068d7 | ||
|
|
695dc5a153 | ||
|
|
5fddddbe21 | ||
|
|
e5ae9dd53d | ||
|
|
102df8dc80 | ||
|
|
e58d16b2df | ||
|
|
e755ca37b3 | ||
|
|
3b649d2fcd | ||
|
|
533a5719c5 | ||
|
|
aeda2e5808 | ||
|
|
392da897ff | ||
|
|
d81fa579c3 | ||
|
|
515da63d2b | ||
|
|
384736e955 | ||
|
|
6f3b6c8d92 | ||
|
|
a2681ffcee | ||
|
|
50a5f84cb4 | ||
|
|
24c387206c | ||
|
|
ba93a647f1 | ||
|
|
e1606172dd | ||
|
|
c9ec33d0d0 | ||
|
|
43264dfbf4 | ||
|
|
8d37f699ad | ||
|
|
8c29f7413b | ||
|
|
17655e5ba6 | ||
|
|
95850e1aca | ||
|
|
c1f62f1fde | ||
|
|
3887d95bca | ||
|
|
cf782c4f54 | ||
|
|
e91e8a2a6c | ||
|
|
d36ac3db15 | ||
|
|
be4c01697c | ||
|
|
0072bc65e6 | ||
|
|
37f83adca8 | ||
|
|
578a63bbc9 | ||
|
|
6b83ca0077 | ||
|
|
78ae4ee82c | ||
|
|
d6edd06749 | ||
|
|
6e8d29e9a2 | ||
|
|
8dd776106d | ||
|
|
e85213a944 | ||
|
|
26f1857154 | ||
|
|
f7a037ba26 | ||
|
|
61114c6c72 | ||
|
|
d3e8709ab5 | ||
|
|
37531673a3 | ||
|
|
31901e3c07 | ||
|
|
a34de2e378 | ||
|
|
2f6935a630 | ||
|
|
a5fd5782f8 | ||
|
|
fb02df66cc | ||
|
|
d10def5b0b | ||
|
|
2357bfb254 | ||
|
|
87babfa473 | ||
|
|
eb9839fd32 | ||
|
|
6e5121be7e | ||
|
|
4efd41f3af | ||
|
|
99351c9cae | ||
|
|
60074a6bc6 | ||
|
|
a3967de9a5 | ||
|
|
044019d9d6 | ||
|
|
db44151a37 | ||
|
|
ceab7154d4 | ||
|
|
0b4c408168 | ||
|
|
f069c0ba09 | ||
|
|
9c4caf49a2 | ||
|
|
2be01ab4ec | ||
|
|
b462063cd5 | ||
|
|
8aaf86a6ea | ||
|
|
bd71cbbe27 | ||
|
|
88517ceebb | ||
|
|
6a292f09ba | ||
|
|
71ec616e4d | ||
|
|
ff526e43de | ||
|
|
d563aa7c7b | ||
|
|
ae5a62a514 | ||
|
|
c86d83f835 | ||
|
|
9a1b9f15a1 | ||
|
|
af2c7ce646 | ||
|
|
b541a97821 | ||
|
|
a8b84b7cfa | ||
|
|
495e2ed17f | ||
|
|
d8c397d1b7 | ||
|
|
d8d6c2746e | ||
|
|
6fdaaa0637 | ||
|
|
034b19b734 | ||
|
|
cb8eba1530 | ||
|
|
7aa8b8a25c | ||
|
|
abcbfcb0e8 | ||
|
|
70bc07a358 | ||
|
|
7f83b53027 | ||
|
|
8405fcdd9b | ||
|
|
f56f09ea38 | ||
|
|
c62cfe64c8 | ||
|
|
78cf3c14ca | ||
|
|
89e057dc4a | ||
|
|
466066c3a1 | ||
|
|
ff3d05d92f | ||
|
|
eadd79acec | ||
|
|
d019821281 | ||
|
|
f4848b437f | ||
|
|
e941e532fa | ||
|
|
a1986c5973 | ||
|
|
6e2b3f435a | ||
|
|
07d3c4d882 | ||
|
|
f81e87f1e2 | ||
|
|
6abfd9b8ff | ||
|
|
07c679b52d | ||
|
|
b4c633cc40 | ||
|
|
54c5070767 | ||
|
|
17cf1b21c6 | ||
|
|
8f364053ca | ||
|
|
2e4e521629 | ||
|
|
fa20f19494 | ||
|
|
c1d8b0f74e | ||
|
|
3815e4f05e | ||
|
|
72488b526b | ||
|
|
5fec6c598e | ||
|
|
dee6bb5a31 | ||
|
|
566b9623b3 | ||
|
|
3f3fb43850 | ||
|
|
2248b886fe | ||
|
|
82b30f2322 | ||
|
|
6b841a036a | ||
|
|
a7d1ee5433 | ||
|
|
0f7160eb2f | ||
|
|
91d6bff8b8 | ||
|
|
5cdccf78a1 | ||
|
|
5fc0be5045 | ||
|
|
9852bd743c | ||
|
|
7d3bf6453e | ||
|
|
fe4467ad2b | ||
|
|
b2322b3893 | ||
|
|
fccfc4e4be | ||
|
|
e65cc09276 | ||
|
|
25cf126de8 | ||
|
|
1492c9d7d9 | ||
|
|
3c63ad4a9c | ||
|
|
3b40f8e42c | ||
|
|
08b125194e | ||
|
|
1d60dd5872 | ||
|
|
f0ce29c341 | ||
|
|
e1b3dc89d2 | ||
|
|
0f708dd6e2 | ||
|
|
730312e60f | ||
|
|
bbe9da063e | ||
|
|
7ec2a2b9ce | ||
|
|
ccdc369025 | ||
|
|
768740ae98 | ||
|
|
07a13697e1 | ||
|
|
8daa1d5f54 | ||
|
|
de86bf1856 | ||
|
|
2103a09430 | ||
|
|
c6a8ad23a1 | ||
|
|
c1ec28a34b | ||
|
|
0824850bbc | ||
|
|
27c3852103 | ||
|
|
ac2ba0961b | ||
|
|
237b7a50f4 | ||
|
|
5dd5543fe4 | ||
|
|
4bb5bb9450 | ||
|
|
31b06571aa | ||
|
|
e7b1e05bbd | ||
|
|
6f9b9655d7 | ||
|
|
45ee118b26 | ||
|
|
0d6fc7eb1e | ||
|
|
ed8ddf2449 | ||
|
|
b4c9f6edba | ||
|
|
a704f57971 | ||
|
|
6b60a5c6d6 | ||
|
|
147740ed40 | ||
|
|
3df7c91f1a | ||
|
|
58744de3eb | ||
|
|
b1bd0c7fc1 | ||
|
|
76887b1d27 | ||
|
|
06a2644ab2 | ||
|
|
ef9afddd1a | ||
|
|
3065b21375 | ||
|
|
358df10191 | ||
|
|
3bb426d92c | ||
|
|
26db50d6df | ||
|
|
8c6ad55320 | ||
|
|
e0d49ad758 | ||
|
|
e725b96a59 | ||
|
|
11e2af6df7 | ||
|
|
acbbc93501 | ||
|
|
932f6cfbfc | ||
|
|
1265e212e4 | ||
|
|
e4cd8751a2 | ||
|
|
2678fe53f5 | ||
|
|
e3698e6e1f | ||
|
|
8b84fc177c | ||
|
|
5122f3477f | ||
|
|
1076a2e26c | ||
|
|
fba6140a4a | ||
|
|
51112221ee | ||
|
|
0453ad0146 | ||
|
|
ed3cfaafb2 | ||
|
|
d0d42dc4cb | ||
|
|
fbbf5a108b | ||
|
|
58b796608f | ||
|
|
05062e7d2d | ||
|
|
bfaa885f10 | ||
|
|
9913cce3ba | ||
|
|
1029f2b277 | ||
|
|
1f7ca973c5 | ||
|
|
6b1ceca86a | ||
|
|
53d4ed22e8 | ||
|
|
feb044bd2d | ||
|
|
bedf8bd437 | ||
|
|
6cb4a3bb19 | ||
|
|
4039802fce | ||
|
|
5e98770936 | ||
|
|
6ee0afb579 | ||
|
|
4e01036cb6 | ||
|
|
28687f2d55 | ||
|
|
42285ac989 | ||
|
|
6fba9a39b7 | ||
|
|
fa677fc0e1 | ||
|
|
b565644c81 | ||
|
|
7247553c77 | ||
|
|
f059fe3ef2 | ||
|
|
8b0fd63ddb | ||
|
|
336beeb09a | ||
|
|
a00b0d13ed | ||
|
|
1ca920bbeb | ||
|
|
1e376be13d | ||
|
|
6995497e5b | ||
|
|
95ed7d48c8 | ||
|
|
a61200776d | ||
|
|
a67df17763 | ||
|
|
233bae6992 | ||
|
|
d685604d04 | ||
|
|
91dec25fc9 | ||
|
|
af93453190 | ||
|
|
6e57401610 | ||
|
|
dec00d3579 | ||
|
|
154c95d0c9 | ||
|
|
ac7080b31b | ||
|
|
a073d11c3e | ||
|
|
e028ab3476 | ||
|
|
5362f956f0 | ||
|
|
8037159f93 | ||
|
|
4dbab75855 | ||
|
|
adcd5aff6f | ||
|
|
bab4da5133 | ||
|
|
3ec28ceb9b | ||
|
|
ed45052d6d | ||
|
|
411640c032 | ||
|
|
eea93638c6 | ||
|
|
a2ca51c27a | ||
|
|
e640907d24 | ||
|
|
74b2deae1c | ||
|
|
143ccd27b4 | ||
|
|
a4d2fa1b6d | ||
|
|
065c360730 | ||
|
|
738d9aece7 | ||
|
|
8c38409aef | ||
|
|
61ed6425bd | ||
|
|
6e8c93afdd | ||
|
|
8c4ae1c938 | ||
|
|
4aa02c3743 | ||
|
|
356fab7bcb | ||
|
|
9543f076fd | ||
|
|
86d6666fe7 | ||
|
|
405cc337f3 | ||
|
|
772dacc89b | ||
|
|
696d2889f4 | ||
|
|
9316b9b57a | ||
|
|
fb288ef9a7 | ||
|
|
7077980055 | ||
|
|
50b27c8c0d | ||
|
|
bbc35b0b19 | ||
|
|
d7280917da | ||
|
|
78352fdd32 | ||
|
|
63f8a2cb89 | ||
|
|
e1686c26dd | ||
|
|
a999f6f876 | ||
|
|
e62e17d046 | ||
|
|
2f04108f3a | ||
|
|
1c83c0ebcd | ||
|
|
8ec6c323b6 | ||
|
|
c5b7faaefc | ||
|
|
467ece53e6 | ||
|
|
8149bc3fa6 | ||
|
|
adf5628087 | ||
|
|
67cd496b39 | ||
|
|
184039044a | ||
|
|
757eb060cd | ||
|
|
3442066054 | ||
|
|
80235d6fdd | ||
|
|
493a1846d0 | ||
|
|
73b9328c1f | ||
|
|
248aa54bfd | ||
|
|
70cc8f2c7e | ||
|
|
92d86586b7 | ||
|
|
a8e0363914 | ||
|
|
35008200bd | ||
|
|
113356c848 | ||
|
|
b3d0ed4057 | ||
|
|
61c0189bb1 | ||
|
|
f17ecaa495 | ||
|
|
9c4d0d454a | ||
|
|
d60663ea86 | ||
|
|
ea6428a5d2 | ||
|
|
80c6b487dc | ||
|
|
7eb496c00c | ||
|
|
aad4e4ddb1 | ||
|
|
cea83c0e1f | ||
|
|
bd39fcbeea | ||
|
|
0d073907b5 | ||
|
|
5ee6dc2120 | ||
|
|
64552ae304 | ||
|
|
b95e5827c1 | ||
|
|
8a214b2f8e | ||
|
|
5bc5fe5e7e | ||
|
|
a2ace9da24 | ||
|
|
d3959a2118 | ||
|
|
1257501499 | ||
|
|
bfd7209053 | ||
|
|
1883d299bf | ||
|
|
15253448af | ||
|
|
b017dc7e32 | ||
|
|
b5a6458cde | ||
|
|
caa90735cf | ||
|
|
de45957c42 | ||
|
|
f4a42738af | ||
|
|
d5158620bb | ||
|
|
bf5a196c78 | ||
|
|
5d7dfefa36 | ||
|
|
dbc8cae18c | ||
|
|
1e1e0f1fbb | ||
|
|
385bf084a5 | ||
|
|
eb1f362687 | ||
|
|
5386e6583d | ||
|
|
d1497527c6 | ||
|
|
91d202da7e | ||
|
|
3888bf9d12 | ||
|
|
3df4e78492 | ||
|
|
b74b6dc77f | ||
|
|
31625c2d17 | ||
|
|
dcdaf5c8b9 | ||
|
|
36181775cd | ||
|
|
1ba7f1d03f | ||
|
|
b160de5cb4 | ||
|
|
7edaedf3a1 | ||
|
|
cb5fcb3d22 | ||
|
|
58f8421eac | ||
|
|
7a4c66b7f5 | ||
|
|
d58c3793d6 | ||
|
|
ea190d862a | ||
|
|
0f26739c9f | ||
|
|
ae2c5ad768 | ||
|
|
9f9f8c8e76 | ||
|
|
50f1f1dce9 | ||
|
|
0264ef094a | ||
|
|
f688653710 | ||
|
|
886d896098 | ||
|
|
8331000764 | ||
|
|
0cd74723e1 | ||
|
|
2bff5e7867 | ||
|
|
90f2a417af | ||
|
|
7c07f5f640 | ||
|
|
20e30593a5 | ||
|
|
e2a18e2b37 | ||
|
|
da724fe1c0 | ||
|
|
ffd8beb6f6 | ||
|
|
5d3cf2ff15 | ||
|
|
7f813dcb6a | ||
|
|
18bab30792 | ||
|
|
60f7b05c0c | ||
|
|
7f626c8959 | ||
|
|
886d50dcab | ||
|
|
7d3e2c83d4 | ||
|
|
1cdc4568bd | ||
|
|
69df38f8d8 | ||
|
|
5e30b81825 | ||
|
|
99582befc4 | ||
|
|
c0d3f204b0 | ||
|
|
989cdca95f | ||
|
|
def8f852e3 | ||
|
|
349cdd6110 | ||
|
|
c54a5b3690 | ||
|
|
6d961d672d | ||
|
|
247ec2ad88 | ||
|
|
8ab2753521 | ||
|
|
2dc9bfd93a | ||
|
|
9dc6946ebf | ||
|
|
0868512bbc | ||
|
|
b519551153 | ||
|
|
f8b3f1622d | ||
|
|
0e3c5ebe1a | ||
|
|
daef51e038 | ||
|
|
e82c42661b | ||
|
|
3a47dec424 | ||
|
|
7b17618890 | ||
|
|
71bc255e6f | ||
|
|
8f990c573c | ||
|
|
3f1d6102f3 | ||
|
|
3712b41aba | ||
|
|
4bcb64f8c1 | ||
|
|
a651b08a2f | ||
|
|
3b35daacf7 | ||
|
|
18f36906a9 | ||
|
|
5fee4638e0 | ||
|
|
d52f579fd5 | ||
|
|
2fef10b9ac | ||
|
|
f3221941f2 | ||
|
|
d98d316903 | ||
|
|
97ecb4f9d8 | ||
|
|
ca6a121e63 | ||
|
|
e354b0e40f | ||
|
|
0ccfb61bb0 | ||
|
|
4b39120d22 | ||
|
|
76950a6401 | ||
|
|
909d962d3a | ||
|
|
dde53cfde1 | ||
|
|
0adb60b3a6 | ||
|
|
a2dd7daf4e | ||
|
|
3a8e56b282 | ||
|
|
36202a63e9 | ||
|
|
abad809e7a | ||
|
|
0f2f783584 | ||
|
|
bcd6b41674 | ||
|
|
92053cb492 | ||
|
|
14cb489a3b | ||
|
|
54e2205e54 | ||
|
|
99b0f48b2e | ||
|
|
c12711affd | ||
|
|
e4b4125310 | ||
|
|
6b2d850e54 | ||
|
|
0daeefefdb | ||
|
|
d520dae6ac | ||
|
|
03d01eabb5 | ||
|
|
65d6278f88 | ||
|
|
c48d09ec88 | ||
|
|
4a51a9d9d5 | ||
|
|
b938212563 | ||
|
|
accaff8ac0 | ||
|
|
45965fb020 | ||
|
|
6ac39d5cdb | ||
|
|
9794c03537 | ||
|
|
1b221a56ea | ||
|
|
eb6fd6ff80 | ||
|
|
9d041d8e6c | ||
|
|
5172014668 | ||
|
|
b853054e71 | ||
|
|
a6a294c8f8 | ||
|
|
1e0eb914d9 | ||
|
|
ae1a6c2fc5 | ||
|
|
e802b683ea | ||
|
|
55cd4c7bc7 | ||
|
|
a4eaac359a | ||
|
|
ee45a8a149 | ||
|
|
b08e451c91 | ||
|
|
2c0f826c36 | ||
|
|
bcab77e266 | ||
|
|
d8398af770 | ||
|
|
30348edc7c | ||
|
|
59ff9b8128 | ||
|
|
2c9bdd9e32 | ||
|
|
21240c1a8f | ||
|
|
c8ecbf38ab | ||
|
|
194a121ef6 | ||
|
|
8867951144 | ||
|
|
fd13731049 | ||
|
|
c68ceca8cd | ||
|
|
efaf4c16cf | ||
|
|
2ad09ab5af | ||
|
|
1f209ed030 | ||
|
|
3c876235cc | ||
|
|
afa4e3ed9c | ||
|
|
c376c5a817 | ||
|
|
92a77e7654 | ||
|
|
4612419c14 | ||
|
|
c799425069 | ||
|
|
428be9803c | ||
|
|
bba588752f | ||
|
|
311dad8c28 | ||
|
|
93062ad099 | ||
|
|
22e594fcea | ||
|
|
02580ac134 | ||
|
|
b723f50e65 | ||
|
|
4a2e75fc8c | ||
|
|
9420758127 | ||
|
|
87997efe8d | ||
|
|
69e0f28333 | ||
|
|
51a0dbb172 | ||
|
|
7934e7a6b5 | ||
|
|
aebbb15fe2 | ||
|
|
48371216df | ||
|
|
e30f9dc1fa | ||
|
|
21993105e5 | ||
|
|
0f25ad3ca3 | ||
|
|
f9c7c50a93 | ||
|
|
0b44ad99b5 | ||
|
|
78d707dc83 | ||
|
|
3385159c94 | ||
|
|
f184c6f06c | ||
|
|
5a551ac57f | ||
|
|
53fde21bb8 | ||
|
|
689f4bfac2 | ||
|
|
85af9c9c9d | ||
|
|
95c38087db | ||
|
|
fa6deb5866 | ||
|
|
a71c262d5f | ||
|
|
f731ae4a2d | ||
|
|
8c8ce08d79 | ||
|
|
de4f817bd6 | ||
|
|
623e35f594 |
321
CHANGES
321
CHANGES
@@ -1,4 +1,298 @@
|
||||
CHANGES FROM 2.3 to 2.4 20 April 2017
|
||||
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.
|
||||
|
||||
* Fixes for hooks at server exit.
|
||||
|
||||
* Remove SGR 10 (was equivalent to SGR 0 but no other terminal seems to do
|
||||
this).
|
||||
|
||||
* Expand formats in window and session names.
|
||||
|
||||
* Add -Z flag to choose-tree, choose-client, choose-buffer to automatically
|
||||
zoom the pane when the mode is entered and unzoom when it exits, assuming the
|
||||
pane is not already zoomed. This is now part of the default key bindings.
|
||||
|
||||
* Add C-g to exit modes with emacs keys.
|
||||
|
||||
* Add exit-empty option to exit server if no sessions (defaults to on).
|
||||
|
||||
* Show if a filter is present in choose modes.
|
||||
|
||||
* Add pipe-pane -I to to connect stdin of the child process.
|
||||
|
||||
* Performance improvements for reflow.
|
||||
|
||||
* Use RGB terminfo(5) capability to detect RGB colour terminals (the existing
|
||||
Tc extension remains unchanged).
|
||||
|
||||
* Support for ISO colon-separated SGR sequences.
|
||||
|
||||
* Add select-layout -E to spread panes out evenly (bound to E key).
|
||||
|
||||
* Support wide characters properly when reflowing.
|
||||
|
||||
* Pass PWD to new panes as a hint to shells, as well as calling chdir().
|
||||
|
||||
* Performance improvements for the various choose modes.
|
||||
|
||||
* Only show first member of session groups in tree mode (-G flag to choose-tree
|
||||
to show all).
|
||||
|
||||
* Support %else in config files to match %if; from Brad Town in GitHub issue
|
||||
1071.
|
||||
|
||||
* Fix "kind" terminfo(5) capability to be S-Down not S-Up.
|
||||
|
||||
* Add a box around the preview label in tree mode.
|
||||
|
||||
* Show exit status and time in the remain-on-exit pane text; from Timo
|
||||
Boettcher in GitHub issue 1103.
|
||||
|
||||
* Correctly use pane-base-index in tree mode.
|
||||
|
||||
* Change the allow-rename option default to off.
|
||||
|
||||
* Support for xterm(1) title stack escape sequences (GitHub issue 1075 from
|
||||
Brad Town).
|
||||
|
||||
* Correctly remove padding cells to fix a UTF-8 display problem (GitHub issue
|
||||
1090).
|
||||
|
||||
CHANGES FROM 2.5 TO 2.6, 05 October 2017
|
||||
|
||||
* Add select-pane -T to set pane title.
|
||||
|
||||
* Fix memory leak when lines with BCE are removed from history.
|
||||
|
||||
* Fix (again) the "prefer unattached" behaviour of attach-session.
|
||||
|
||||
* Reorder how keys are checked to allow keys to be specified that have a
|
||||
leading escape. GitHub issue 1048.
|
||||
|
||||
* Support REP escape sequence (\033[b).
|
||||
|
||||
* Run alert hooks based on options rather than always, and allow further bells
|
||||
even if there is an existing bell.
|
||||
|
||||
* Add -d flag to display-panes to override display-panes-time.
|
||||
|
||||
* Add selection_present format when in copy mode (allows key bindings that do
|
||||
something different if there is a selection).
|
||||
|
||||
* Add pane_at_left, pane_at_right, pane_at_top and pane_at_bottom formats.
|
||||
|
||||
* Make bell, activity and silence alerting more consistent by: removing the
|
||||
bell-on-alert option; adding activity-action and silence-action options with
|
||||
the same possible values as the existing bell-action; adding a "both" value
|
||||
for the visual-bell, visual-activity and visual-silence options to trigger
|
||||
both a bell and a message.
|
||||
|
||||
* Add a pane_pipe format to show if pipe-pane is active.
|
||||
|
||||
* Block signals between forking and resetting signal handlers so that the
|
||||
libevent signal handler doesn't get called in the child and incorrectly write
|
||||
into the signal pipe that it still shares with the parent. GitHub issue 1001.
|
||||
|
||||
* Allow punctuation in pane_current_command.
|
||||
|
||||
* Add -c for respawn-pane and respawn-window.
|
||||
|
||||
* Wait for any remaining data to flush when a pane is closed while pipe-pane is
|
||||
in use.
|
||||
|
||||
* Fix working out current client with no target. GitHub issue 995.
|
||||
|
||||
* Try to fallback to C.UTF-8 as well as en_US.UTF-8 when looking for a UTF-8
|
||||
locale.
|
||||
|
||||
* Add user-keys option for user-defined key escape sequences (mapped to User0
|
||||
to User999 keys).
|
||||
|
||||
* Add pane-set-clipboard hook.
|
||||
|
||||
* FAQ file has moved out of repository to online.
|
||||
|
||||
* Fix problem with high CPU usage when a client dies unexpectedly. GitHub issue
|
||||
941.
|
||||
|
||||
* Do a dance on OS X 10.10 and above to return tmux to the user namespace,
|
||||
allowing access to the clipboard.
|
||||
|
||||
* Do not allow escape sequences which expect a specific terminator (APC, DSC,
|
||||
OSC) to wait for forever - use a small timeout. This reduces the chance of
|
||||
the pane locking up completely when sent garbage (cat /dev/random or
|
||||
similar).
|
||||
|
||||
* Support SIGUSR2 to toggle logging on a running server, also generate the
|
||||
"out" log file with -vv not -vvvv.
|
||||
|
||||
* Make set-clipboard a three state option: on (tmux both sends to outside
|
||||
terminal and accepts from applications inside); external (tmux sends outside
|
||||
but does not accept inside); and off.
|
||||
|
||||
* Fix OSC 4 palette setting for bright foreground colours. GitHub issue 954.
|
||||
|
||||
* Use setrgbf and setrgbb terminfo(5) capabilities to set RGB colours, if they
|
||||
are available. (Tc is still supported as well.)
|
||||
|
||||
* Fix redrawing panes when they are resized several times but end up with the
|
||||
size unchanged (for example, splitw/resizep -Z/breakp).
|
||||
|
||||
* Major rewrite of choose mode. Now includes preview, sorting, searching and
|
||||
tagging; commands that can be executed directly from the mode (for example,
|
||||
to delete one or more buffers); and filtering in tree mode.
|
||||
|
||||
* choose-window and choose-session are now aliases of choose-tree (in the
|
||||
command-alias option).
|
||||
|
||||
* Support OSC 10 and OSC 11 to set foreground and background colours.
|
||||
|
||||
* Check the U8 capability to determine whether to use UTF-8 line drawing
|
||||
characters for ACS.
|
||||
|
||||
* Some missing notifications for layout changes.
|
||||
|
||||
* Control mode clients now do not affect session sizes until they issue
|
||||
refresh-client -C. new-session -x and -y works with control clients even if
|
||||
the session is not detached.
|
||||
|
||||
* All new sessions that are unattached (whether with -d or started with no
|
||||
terminal) are now created with size 80 x 24. Whether the status line is on or
|
||||
off does not affect the size of new sessions until they are attached.
|
||||
|
||||
* Expand formats in option names and add -F flag to expand them in option values.
|
||||
|
||||
* Remember the search string for a pane even if copy mode is exited and entered
|
||||
again.
|
||||
|
||||
* Some further BCE fixes (scroll up, reverse index).
|
||||
|
||||
* Improvements to how terminals are cleared (entirely or partially).
|
||||
|
||||
CHANGES FROM 2.4 TO 2.5, 09 May 2017
|
||||
|
||||
* Reset updated flag when restarting #() command so that new output is properly
|
||||
recognised. GitHub issue 922.
|
||||
|
||||
* Fix ECH with a background colour.
|
||||
|
||||
* Do not rely on the terminal not moving the cursor after DL or EL.
|
||||
|
||||
* Fix send-keys and send-prefix in copy-mode (so C-b C-b works). GitHub issue
|
||||
905.
|
||||
|
||||
* Set the current pane for rotate-window so it works in command sequences.
|
||||
|
||||
* Add pane_mode format.
|
||||
|
||||
* Differentiate M-Up from Escape+Up when possible (that is, in terminals with
|
||||
xterm(1) style function keys). GitHub issue 907.
|
||||
|
||||
* Add session_stack and window_stack_index formats.
|
||||
|
||||
* Some new control mode notifications and corresponding hooks:
|
||||
pane-mode-changed, window-pane-changed, client-session-changed,
|
||||
session-window-changed.
|
||||
|
||||
* Format pane_search_string for last search term while in copy mode (useful
|
||||
with command-prompt -I).
|
||||
|
||||
* Fix a problem with high CPU usage and multiple clients with #(). GitHub issue
|
||||
889.
|
||||
|
||||
* Fix UTF-8 combining characters in column 0.
|
||||
|
||||
* Fix reference counting so that panes are properly destroyed and their
|
||||
processes killed.
|
||||
|
||||
* Clamp SU (CSI S) parameter to work around a bug in Konsole.
|
||||
|
||||
* Tweak line wrapping in full width panes to play more nicely with terminal
|
||||
copy and paste.
|
||||
|
||||
* Fix when we emit SGR 0 in capture-pane -e.
|
||||
|
||||
* Do not change TERM until after config file parsing has finished, so that
|
||||
commands run inside the config file can use it to make decisions (typically
|
||||
about default-terminal).
|
||||
|
||||
* Make the initial client wait until config file parsing has finished to avoid
|
||||
racing with commands.
|
||||
|
||||
* Fix core when if-shell fails.
|
||||
|
||||
* Only use ED to clear screen if the pane is at the bottom.
|
||||
|
||||
* Fix multibyte UTF-8 output.
|
||||
|
||||
* Code improvements around target (-t) resolution.
|
||||
|
||||
* Change how the default target (for commands without -t) is managed across
|
||||
command sequences: now it is set up at the start and commands are required
|
||||
to update it if needed. Fixes binding command sequences to mouse keys.
|
||||
|
||||
* Make if-shell from the config file work correctly.
|
||||
|
||||
* Change to always check the root key table if no binding is found in the
|
||||
current table (prefix table or copy-mode table or whatever). This means that
|
||||
root key bindings will take effect even in copy mode, if not overridden by a
|
||||
copy mode key binding.
|
||||
|
||||
* Fix so that the history file works again.
|
||||
|
||||
* Run config file without a client rather than using the first client, restores
|
||||
previous behaviour.
|
||||
|
||||
* If a #() command doesn't exit, continue to read from it and use its last full
|
||||
line of output.
|
||||
|
||||
* Handle slow terminals and fast output better: when the amount of data
|
||||
outstanding gets too large, discard output until it is drained and we are
|
||||
able to do a full redraw. Prevents tmux sitting on a huge buffer that the
|
||||
terminal will take forever to consume.
|
||||
|
||||
* 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
|
||||
====================
|
||||
@@ -23,12 +317,12 @@ Incompatible Changes
|
||||
bind -Tcopy-mode C-Up send -X scroll-up
|
||||
bind -Tcopy-mode WheelUpPane send -N5 -X scroll-up
|
||||
|
||||
This changes allows the full command parser (including command sequences) and
|
||||
These changes allows the full command parser (including command sequences) and
|
||||
command set to be used - for example, the normal command prompt with editing
|
||||
and history is now used for searching, jumping, and so on instead of a custom
|
||||
one. The default C-r binding is now:
|
||||
|
||||
bind -Tcopy-mode C-r command-prompt -p'search up' "send -X search-backward '%%'"
|
||||
bind -Tcopy-mode C-r command-prompt -i -p'search up' "send -X search-backward-incremental '%%'"
|
||||
|
||||
There are also some new commmands available with send -X, such as
|
||||
copy-pipe-and-cancel.
|
||||
@@ -78,7 +372,7 @@ Normal Changes
|
||||
set -ag syntax should work without change).
|
||||
* There have been substantial performance improvements.
|
||||
|
||||
CHANGES FROM 2.2 to 2.3 29 September 2016
|
||||
CHANGES FROM 2.2 TO 2.3, 29 September 2016
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
@@ -99,7 +393,7 @@ Normal Changes
|
||||
* 'display-panes' can now accept a command to run, rather than always
|
||||
selecting the pane.
|
||||
|
||||
CHANGES FROM 2.1 to 2.2 10 April 2016
|
||||
CHANGES FROM 2.1 TO 2.2, 10 April 2016
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
@@ -164,8 +458,7 @@ Normal Changes
|
||||
* RGB (24bit) colour support. The 'Tc' flag must be set in the external TERM
|
||||
entry (using terminal-overrides or a custom terminfo entry).
|
||||
|
||||
|
||||
CHANGES FROM 2.0 to 2.1 18 October 2015
|
||||
CHANGES FROM 2.0 TO 2.1, 18 October 2015
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
@@ -216,7 +509,7 @@ Normal Changes
|
||||
* Copy mode is exited if the history is cleared whilst in copy-mode.
|
||||
* 'copy-mode' learned '-e' to exit copy-mode when scrolling to end.
|
||||
|
||||
CHANGES FROM 1.9a to 2.0 6 March 2015
|
||||
CHANGES FROM 1.9a TO 2.0, 06 March 2015
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
@@ -275,9 +568,9 @@ Normal Changes
|
||||
* 'split-window' and 'join-window' understand -b to create the pane to the left
|
||||
or above the target pane.
|
||||
|
||||
CHANGES FROM 1.9 to 1.9a 22 February 2014
|
||||
CHANGES FROM 1.9 TO 1.9a, 22 February 2014
|
||||
|
||||
NOTE: This is a bug-fix release to address some important bugs which just
|
||||
NOTE: This is a bug-fix release to address some important bugs which just
|
||||
missed the 1.9 deadline, but were found afterwards.
|
||||
|
||||
Normal Changes
|
||||
@@ -286,7 +579,7 @@ Normal Changes
|
||||
* Fix crash due to uninitialized lastwp member of layout_cell
|
||||
* Fix -fg/-bg/-style with 256 colour terminals.
|
||||
|
||||
CHANGES FROM 1.8 to 1.9, 20 February 2014
|
||||
CHANGES FROM 1.8 TO 1.9, 20 February 2014
|
||||
|
||||
NOTE: This release has bumped the tmux protocol version. It is therefore
|
||||
advised that the prior tmux server is restarted when this version of tmux is
|
||||
@@ -341,7 +634,7 @@ Normal Changes
|
||||
* tmux now supports 256 colours running under fbterm.
|
||||
* Many bug fixes!
|
||||
|
||||
CHANGES FROM 1.7 to 1.8, 26 March 2013
|
||||
CHANGES FROM 1.7 TO 1.8, 26 March 2013
|
||||
|
||||
Incompatible Changes
|
||||
====================
|
||||
@@ -392,7 +685,7 @@ Normal Changes
|
||||
* Lots and lots of bug fixes, fixing memory-leaks, etc.
|
||||
* Various manpage improvements.
|
||||
|
||||
CHANGES FROM 1.6 to 1.7, 13 October 2012
|
||||
CHANGES FROM 1.6 TO 1.7, 13 October 2012
|
||||
|
||||
* tmux configuration files now support line-continuation with a "\" at the
|
||||
end of a line.
|
||||
@@ -783,7 +1076,7 @@ CHANGES FROM 1.0 TO 1.1, 05 November 2009
|
||||
* xterm-keys rewrite.
|
||||
* Additional code reduction, and bug fixes.
|
||||
|
||||
CHANGES FROM 0.9 TO 1.0, 20 Sept 2009
|
||||
CHANGES FROM 0.9 TO 1.0, 20 September 2009
|
||||
|
||||
* Option to alter the format of the window title set by tmux.
|
||||
* Backoff for a while after multiple incorrect password attempts.
|
||||
|
||||
@@ -27,7 +27,7 @@ case before opening an issue.
|
||||
To run tmux without a config and get logs, run:
|
||||
|
||||
tmux -Ltest kill-server
|
||||
tmux -vvvv -Ltest -f/dev/null new
|
||||
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.
|
||||
|
||||
462
FAQ
462
FAQ
@@ -1,462 +0,0 @@
|
||||
tmux frequently asked questions
|
||||
|
||||
******************************************************************************
|
||||
* PLEASE NOTE: most display problems are due to incorrect TERM! Before *
|
||||
* reporting problems make SURE that TERM settings are correct inside and *
|
||||
* outside tmux. *
|
||||
* *
|
||||
* Inside tmux TERM must be "screen" or similar (such as "screen-256color"). *
|
||||
* Don't bother reporting problems where it isn't! *
|
||||
* *
|
||||
* Outside, it must match your terminal: particularly, use "rxvt" for rxvt *
|
||||
* and derivatives. *
|
||||
******************************************************************************
|
||||
|
||||
* How is tmux different from GNU screen?
|
||||
|
||||
tmux and GNU screen have many similarities. Some of the main differences I am
|
||||
aware of are (bearing in mind I haven't used screen for a few years now):
|
||||
|
||||
- tmux uses a client-server model. Each server has single Unix domain socket in
|
||||
/tmp and within one server there are multiple sessions which may be attached
|
||||
to multiple clients (terminals).
|
||||
|
||||
This has advantages, notably: windows may be linked simultaneously to
|
||||
multiple sessions; windows may be moved freely between sessions; and a client
|
||||
may be switched between sessions easily (C-b D). There is one major
|
||||
disadvantage: if the server crashes, game over, all sessions die. In
|
||||
practice, however, tmux is quite stable and gets more so as people report any
|
||||
bugs they hit :-).
|
||||
|
||||
This model is different from screen, where typically each new screen instance
|
||||
is independent. tmux supports the same behaviour by using multiple servers
|
||||
with the -L option but it is not typically recommended.
|
||||
|
||||
- Different command interfaces. One of the goals of tmux is that the shell
|
||||
should be easily usable as a scripting language - almost all tmux commands
|
||||
can be used from the shell and behave identically whether used from the
|
||||
shell, from a key binding or from the command prompt. Personally I also find
|
||||
tmux's command interface much more consistent and clearer, but this is
|
||||
subjective.
|
||||
|
||||
- tmux calls window names (what you see in the status line) "names", screen
|
||||
calls them "titles".
|
||||
|
||||
- tmux has a multiple paste buffers. Not a major one but comes in handy quite a
|
||||
lot.
|
||||
|
||||
- tmux supports automatically renaming windows to the running application
|
||||
without gross hacks using escape sequences. Its even on by default.
|
||||
|
||||
- tmux has a choice of vi or emacs key layouts. Again, not major, but I use
|
||||
emacs so if tmux did support only one key set it would be emacs and then all
|
||||
the vi users would get humpy. Key bindings may be completely reconfigured in
|
||||
any case.
|
||||
|
||||
- tmux has an option to limit the window size.
|
||||
|
||||
- tmux has search in windows (C-b f).
|
||||
|
||||
- The window split (pane) model is different. tmux has two objects, windows and
|
||||
panes; screen has just windows. This difference has several implications:
|
||||
|
||||
* In screen you can have a window appear in several layouts, in tmux a pane
|
||||
can only be in one window (fixing this is a big todo item but quite
|
||||
invasive).
|
||||
|
||||
* tmux layouts are immutable and do not get changed unless you modify them.
|
||||
|
||||
* In tmux, all panes are closed when you kill a window.
|
||||
|
||||
* tmux panes do not have individual names, titles and so on.
|
||||
|
||||
I think tmux's model is much easier to manage and navigate within a window,
|
||||
but breaking panes off from and joining them to windows is more clumsy.
|
||||
|
||||
tmux also has support for preset pane layouts.
|
||||
|
||||
- tmux's status line syntax is more readable and easier to use. I think it'd be
|
||||
hard for anyone to argue with this. tmux doesn't support running a command
|
||||
constantly and always using the last line of its output, commands must be run
|
||||
again each time.
|
||||
|
||||
- tmux has modern, easily extended code. Again hard to argue screen is better
|
||||
if you have looked at the code.
|
||||
|
||||
- tmux depends on libevent. I don't see this as a disadvantage: libevent is
|
||||
small and portable, and on modern systems with current package management
|
||||
systems dependencies are not an issue. libevent brings advantages in code
|
||||
simplicity and performance.
|
||||
|
||||
- screen allows the window to be bigger than the terminal and can pan around
|
||||
it. tmux limits the size to the largest attached client. This is a big todo
|
||||
item for tmux but it is not trivial.
|
||||
|
||||
- screen has builtin serial and telnet support; this is bloat and is unlikely
|
||||
to be added to tmux.
|
||||
|
||||
- Environment handling is different.
|
||||
|
||||
- tmux tends to be more demanding on the terminal so tends to show up terminal
|
||||
and application bugs which screen does not.
|
||||
|
||||
- screen has wider platform support, for example IRIX, and for odd terminals.
|
||||
|
||||
* I found a bug! What do I do?
|
||||
|
||||
Check the latest version of tmux from Git to see if the problem is still
|
||||
reproducible. Sometimes the length of time between releases means a lot of
|
||||
fixes can be sitting in Git and the problem might already be fixed.
|
||||
|
||||
Please send bug reports by email to nicholas.marriott@gmail.com or
|
||||
tmux-users@googlegroups.com. Please include as much of the following
|
||||
information as possible:
|
||||
|
||||
- the version of tmux you are running;
|
||||
- the operating system you are using and its version;
|
||||
- the terminal emulator you are using and the TERM setting when tmux was
|
||||
started;
|
||||
- a description of the problem;
|
||||
- if the problem is repeatable, the steps to repeat the problem;
|
||||
- for screen corruption issues, a screenshot and the output of "infocmp $TERM"
|
||||
from outside tmux are often very useful.
|
||||
|
||||
* Why doesn't tmux do $x?
|
||||
|
||||
Please send feature requests by email to tmux-users@googlegroups.com.
|
||||
|
||||
* Why do you use the screen terminal description inside tmux? It sucks.
|
||||
|
||||
It is already widely available. It is planned to change to something else such
|
||||
as xterm-xfree86 at some point, if possible.
|
||||
|
||||
* I don't see any colour in my terminal! Help!
|
||||
|
||||
On some platforms, common terminal descriptions such as xterm do not include
|
||||
colour. screen ignores this, tmux does not. If the terminal emulator in use
|
||||
supports colour, use a value for TERM which correctly lists this, such as
|
||||
xterm-color.
|
||||
|
||||
* tmux freezes my terminal when I attach to a session. I even have to kill -9
|
||||
the shell it was started from to recover!
|
||||
|
||||
Some consoles really really don't like attempts to set the window title. Tell
|
||||
tmux not to do this by turning off the "set-titles" option (you can do this
|
||||
in .tmux.conf):
|
||||
|
||||
set -g set-titles off
|
||||
|
||||
If this doesn't fix it, send a bug report.
|
||||
|
||||
* Why is C-b the prefix key? How do I change it?
|
||||
|
||||
The default key is C-b because the prototype of tmux was originally developed
|
||||
inside screen and C-b was chosen not to clash with the screen meta key. It
|
||||
also has the advantage of not interfering with the use of C-a for start-of-line
|
||||
in emacs and the shell (although it does interfere with previous-character).
|
||||
|
||||
Changing is simple: change the "prefix-key" option, and - if required - move
|
||||
the binding of the "send-prefix" command from C-b (C-b C-b sends C-b by
|
||||
default) to the new key. For example:
|
||||
|
||||
set -g prefix C-a
|
||||
unbind C-b
|
||||
bind C-a send-prefix
|
||||
|
||||
* How do I use UTF-8?
|
||||
|
||||
When running tmux in a UTF-8 capable terminal, UTF-8 must be turned on in tmux;
|
||||
as of release 0.9, tmux attempts to autodetect a UTF-8-capable terminal by
|
||||
checking the LC_ALL, LC_CTYPE and LANG environment variables. list-clients may
|
||||
be used to check if this is detected correctly; if not, the -u command-line
|
||||
flag may be specified when creating or attaching a client to a tmux session:
|
||||
|
||||
$ tmux -u new
|
||||
|
||||
Since the 1.0 release, tmux will turn on UTF-8 related options automatically
|
||||
(ie status-utf8, and utf8) if the above conditions are met.
|
||||
|
||||
* How do I use a 256 colour terminal?
|
||||
|
||||
Provided the underlying terminal supports 256 colours, it is usually sufficient
|
||||
to add the following to ~/.tmux.conf:
|
||||
|
||||
set -g default-terminal "screen-256color"
|
||||
|
||||
Note that some platforms do not support "screen-256color" ("infocmp
|
||||
screen-256color" will return an error) - in this case see the next entry in
|
||||
this FAQ.
|
||||
|
||||
tmux attempts to detect a 256 colour terminal both by looking at the colors
|
||||
terminfo entry and by looking for the string "256col" in the TERM environment
|
||||
variable.
|
||||
|
||||
If both these methods fail, the -2 flag may be passed to tmux when attaching
|
||||
to a session to indicate the terminal supports 256 colours.
|
||||
|
||||
* vim or $otherprogram doesn't display 256 colours. What's up?
|
||||
|
||||
Some programs attempt to detect the number of colours a terminal is capable of
|
||||
by checking the colors terminfo or Co termcap entry. However, this is not
|
||||
reliable, and in any case is missing from the "screen" terminal description
|
||||
used inside tmux.
|
||||
|
||||
There are two options (aside from using "screen-256color") to allow programs to
|
||||
recognise they are running on a 256-colour terminal inside tmux:
|
||||
|
||||
- Manually force the application to use 256 colours always or if TERM is set to
|
||||
screen. For vim, you can do this by overriding the t_Co option, see
|
||||
http://vim.wikia.com/wiki/256_colors_in_vim.
|
||||
- Creating a custom terminfo file that includes colors#256 in ~/.terminfo and
|
||||
using it instead. These may be compiled with tic(1).
|
||||
|
||||
* How do I make Ctrl-PgUp and Ctrl-PgDn work in vim?
|
||||
|
||||
tmux supports passing through ctrl (and where supported by the client terminal,
|
||||
alt and shift) modifiers to function keys using xterm(1)-style key sequences.
|
||||
This may be enabled per window, or globally with the tmux command:
|
||||
|
||||
setw -g xterm-keys on
|
||||
|
||||
Because the TERM variable inside tmux must be set to "screen", vim will not
|
||||
automatically detect these keys are available; however, the appropriate key
|
||||
sequences can be overridden in .vimrc using the following:
|
||||
|
||||
if &term == "screen"
|
||||
set t_kN=^[[6;*~
|
||||
set t_kP=^[[5;*~
|
||||
endif
|
||||
|
||||
And similarly for any other keys for which modifiers are desired.
|
||||
|
||||
Please note that the "xterm-keys" setting may affect other programs, in the
|
||||
same way as running them in a standard xterm; for example most shells do not
|
||||
expect to receive xterm(1)-style key sequences so this setting may prevent keys
|
||||
such as ctrl-left and ctrl-right working correctly. tmux also passes through
|
||||
the ctrl (bit 5 set, for example ^[[5~ to ^[[5^) modifier in non-xterm(1) mode;
|
||||
it may be possible to configure vim to accept these, an example of how to do so
|
||||
would be welcome.
|
||||
|
||||
vim users may also want to set the "ttyfast" option inside tmux.
|
||||
|
||||
* How do I make ctrl and shift arrow keys work in emacs?
|
||||
|
||||
The terminal-init-screen function in term/screen.el is called for new frames,
|
||||
but it doesn't configure any function keys.
|
||||
|
||||
If the tmux xterm-keys option is on, it is enough to define the same keys as
|
||||
xterm. Add the following to init.el or .emacs to do this:
|
||||
|
||||
(defadvice terminal-init-screen
|
||||
;; The advice is named `tmux', and is run before `terminal-init-screen' runs.
|
||||
(before tmux activate)
|
||||
;; Docstring. This describes the advice and is made available inside emacs;
|
||||
;; for example when doing C-h f terminal-init-screen RET
|
||||
"Apply xterm keymap, allowing use of keys passed through tmux."
|
||||
;; This is the elisp code that is run before `terminal-init-screen'.
|
||||
(if (getenv "TMUX")
|
||||
(let ((map (copy-keymap xterm-function-map)))
|
||||
(set-keymap-parent map (keymap-parent input-decode-map))
|
||||
(set-keymap-parent input-decode-map map))))
|
||||
|
||||
And ensure .tmux.conf contains "set -g xterm-keys on".
|
||||
|
||||
Alternatively, the screen.el file can be copied to the load path and
|
||||
customized.
|
||||
|
||||
* Why doesn't elinks set the window title inside tmux?
|
||||
|
||||
There isn't a way to detect if a terminal supports setting the window title, so
|
||||
elinks attempts to guess by looking at the environment. Rather than looking for
|
||||
TERM=screen, it uses the STY variable to detect if it is running in screen;
|
||||
tmux does not use this so the check fails. A workaround is to set STY before
|
||||
running elinks.
|
||||
|
||||
The following shell function does this, and also clears the window title on
|
||||
exit (elinks, for some strange reason, sets it to the value of TERM):
|
||||
|
||||
elinks() {
|
||||
STY= `which elinks` $*
|
||||
echo -ne \\033]0\;\\007;
|
||||
}
|
||||
|
||||
* What is the proper way to escape characters with #(command)?
|
||||
|
||||
When using the #(command) construction to include the output from a command in
|
||||
the status line, the command will be parsed twice. First, when it's read by the
|
||||
configuration file or the command-prompt parser, and second when the status
|
||||
line is being drawn and the command is passed to the shell. For example, to
|
||||
echo the string "(test)" to the status line, either single or double quotes
|
||||
could be used:
|
||||
|
||||
set -g status-right "#(echo \\\\(test\\\\))"
|
||||
set -g status-right '#(echo \\\(test\\\))'
|
||||
|
||||
In both cases, the status-right option will be set to the string "#(echo
|
||||
\\(test\\))" and the command executed will be "echo \(test\)".
|
||||
|
||||
* tmux uses too much CPU. What do I do?
|
||||
|
||||
Automatic window renaming may use a lot of CPU, particularly on slow computers:
|
||||
if this is a problem, turn it off with "setw -g automatic-rename off". If this
|
||||
doesn't fix it, please report the problem.
|
||||
|
||||
* I use PuTTY and my tmux window pane separators are all qqqqqqqqq's!
|
||||
|
||||
PuTTY is using a character set translation that doesn't support ACS line
|
||||
drawing. With a Unicode font, try setting PuTTY to use a different translation
|
||||
on the Window -> Translation configuration page. For example, change UTF-8 to
|
||||
ISO-8859-1 or CP437. It may also be necessary to adjust the way PuTTY treats
|
||||
line drawing characters in the lower part of the same configuration page.
|
||||
|
||||
* What is the best way to display the load average? Why no #L?
|
||||
|
||||
It isn't possible to get the load average portably in code and it is preferable
|
||||
not to add portability goop. The following works on at least Linux, *BSD and OS
|
||||
X:
|
||||
|
||||
uptime|awk '{split(substr($0, index($0, "load")), a, ":"); print a[2]}'
|
||||
|
||||
* How do I attach the same session to multiple clients but with a different
|
||||
current window, like screen -x?
|
||||
|
||||
One or more of the windows can be linked into multiple sessions manually with
|
||||
link-window, or a grouped session with all the windows can be created with
|
||||
new-session -t.
|
||||
|
||||
* Ctrl and arrow keys doesn't work in putty! What do I do?
|
||||
|
||||
putty inverts the sense of the cursor key mode on ctrl, which is a bit hard for
|
||||
tmux to detect properly. To get ctrl keys right, change the terminfo settings
|
||||
so kUP5 (Ctrl-Up etc) are the adjusted versions, and disable smkx/rmkx so tmux
|
||||
doesn't change the mode. For example with this line in .tmux.conf (assuming you
|
||||
have TERM set to xterm):
|
||||
|
||||
set -g terminal-overrides "xterm*:kLFT5=\eOD:kRIT5=\eOC:kUP5=\eOA:kDN5=\eOB:smkx@:rmkx@"
|
||||
|
||||
Note that this will only work in tmux 1.2 and above.
|
||||
|
||||
* How can I blank the tmux window?
|
||||
|
||||
GNU screen has a feature whereby it will blank the screen after a period of
|
||||
inactivity. To do the same thing in tmux, use the lock-command setting, for
|
||||
example (with GNU bash):
|
||||
|
||||
set -g lock-command 'tput civis && read -s -n1'
|
||||
|
||||
This will remove the cursor and tell the shell to quit once a key has been
|
||||
pressed. For zsh, use "read -s -k1".
|
||||
|
||||
In addition, it's possible to have both blanking and locking (for instance via
|
||||
lock(1) or vlock(1)) by using the following:
|
||||
|
||||
bind x set lock-command '/usr/bin/vlock' \; lock-client \; set lock-command 'tput civis && read -s -n1'
|
||||
|
||||
* I don't see italics! Or less and vim show italics and reverse the wrong way round!
|
||||
|
||||
GNU screen does not support italics and the "screen" terminfo description uses
|
||||
the italics escape sequence incorrectly.
|
||||
|
||||
As of tmux 2.1, if default-terminal is set to "screen" or matches "screen-*",
|
||||
tmux will behave like screen and italics will be disabled.
|
||||
|
||||
To enable italics, create a new terminfo entry called "tmux" (some platforms
|
||||
may already have this, you can check with "infocmp tmux"):
|
||||
|
||||
$ cat <<EOF|tic -x -
|
||||
tmux|tmux terminal multiplexer,
|
||||
ritm=\E[23m, rmso=\E[27m, sitm=\E[3m, smso=\E[7m, Ms@,
|
||||
use=xterm+tmux, use=screen,
|
||||
|
||||
tmux-256color|tmux with 256 colors,
|
||||
use=xterm+256setaf, use=tmux,
|
||||
EOF
|
||||
$
|
||||
|
||||
And tell tmux to use it in ~/.tmux.conf:
|
||||
|
||||
set -g default-terminal "tmux"
|
||||
|
||||
If using urxvt, make sure you have an italics capable font enabled. for
|
||||
example, add to ~/.Xdefaults:
|
||||
|
||||
urxvt.italicFont: xft:Bitstream Vera Sans Mono:italic:autohint=true
|
||||
|
||||
* How can I make tmux use my terminal's scrollback buffer?
|
||||
|
||||
Normally, tmux enables the terminal's "alternate screen". Most terminals (such
|
||||
as xterm) do not save scrollback for the alternate screen. You might prefer
|
||||
tmux to use the normal screen, so it uses your terminal's scrollback
|
||||
buffer. This way, you can access the scrollback buffer as usual, for example
|
||||
using the mouse wheel - although there is no guarantee output inside tmux will
|
||||
always (or ever) be added to the scrollback.
|
||||
|
||||
You can make tmux use the normal screen by telling it that your terminal does
|
||||
not have an alternate screen. Put the following in ~/.tmux.conf:
|
||||
|
||||
set -ga terminal-overrides ',xterm*:smcup@:rmcup@'
|
||||
|
||||
Adjust if your $TERM does not start with xterm.
|
||||
|
||||
tmux will still emulate the alternate screen for applications run under tmux,
|
||||
so you don't really lose anything with this setting. The only disadvantage is
|
||||
that when you exit tmux, it will not restore whatever was there before you
|
||||
started.
|
||||
|
||||
* How do I see the default configuration?
|
||||
|
||||
Show the default session options by starting a new tmux server with no
|
||||
configuration file:
|
||||
|
||||
$ tmux -Lfoo -f/dev/null start\; show -g
|
||||
|
||||
Or the default window options:
|
||||
|
||||
$ tmux -Lfoo -f/dev/null start\; show -gw
|
||||
|
||||
* How do I copy a selection from tmux to the system's clipboard?
|
||||
|
||||
When running in xterm(1), tmux can automatically send copied text to the
|
||||
clipboard. This is controlled by the set-clipboard option and also needs this
|
||||
X resource to be set:
|
||||
|
||||
XTerm*disallowedWindowOps: 20,21,SetXprop
|
||||
|
||||
For rxvt-unicode (urxvt), there is an unofficial Perl extension here:
|
||||
|
||||
http://anti.teamidiot.de/static/nei/*/Code/urxvt/
|
||||
|
||||
Otherwise a key binding for copy mode using xclip (or xsel) works:
|
||||
|
||||
bind -temacs-copy C-y copy-pipe "xclip -i >/dev/null"
|
||||
|
||||
Or for inside and outside copy mode with the prefix key:
|
||||
|
||||
bind C-y run -b "tmux save-buffer - | xclip -i"
|
||||
|
||||
On OS X, look at the pbcopy(1) and pbpaste(1) commands.
|
||||
|
||||
* Why don't some commands work inside tmux on OS X?
|
||||
|
||||
Apple requires some undocumented, unsupported fiddling to allow commands that
|
||||
interact with the GUI to work. Neither tmux itself nor most shells do this, so
|
||||
an external program is required. This can be found here:
|
||||
|
||||
https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard
|
||||
|
||||
Affected commands may include say(1), pbcopy(1), pbpaste(1) and ssh(1).
|
||||
|
||||
* Why do I see dots around a session when I attach to it?
|
||||
|
||||
tmux limits the size of the window to the smallest attached session. If
|
||||
it didn't do this then it would be impossible to see the entire window.
|
||||
The dots mark the size of the window tmux can display.
|
||||
|
||||
To avoid this, detach all other clients when attaching:
|
||||
|
||||
$ tmux attach -d
|
||||
|
||||
Or from inside tmux by detaching individual clients with C-b D or all
|
||||
using:
|
||||
|
||||
C-b : attach -d
|
||||
13
Makefile.am
13
Makefile.am
@@ -6,10 +6,8 @@ CLEANFILES = tmux.1.mdoc tmux.1.man
|
||||
|
||||
# Distribution tarball options.
|
||||
EXTRA_DIST = \
|
||||
CHANGES FAQ README TODO COPYING example_tmux.conf compat/*.[ch] \
|
||||
CHANGES README README.ja COPYING example_tmux.conf compat/*.[ch] \
|
||||
osdep-*.c mdoc2man.awk tmux.1
|
||||
dist-hook:
|
||||
grep "^#enable_debug=" configure
|
||||
|
||||
# Preprocessor flags.
|
||||
AM_CPPFLAGS += @XOPEN_DEFINES@ -DTMUX_CONF="\"$(sysconfdir)/tmux.conf\""
|
||||
@@ -68,8 +66,6 @@ dist_tmux_SOURCES = \
|
||||
cmd-bind-key.c \
|
||||
cmd-break-pane.c \
|
||||
cmd-capture-pane.c \
|
||||
cmd-choose-buffer.c \
|
||||
cmd-choose-client.c \
|
||||
cmd-choose-tree.c \
|
||||
cmd-command-prompt.c \
|
||||
cmd-confirm-before.c \
|
||||
@@ -147,13 +143,13 @@ dist_tmux_SOURCES = \
|
||||
layout-set.c \
|
||||
layout.c \
|
||||
log.c \
|
||||
mode-tree.c \
|
||||
names.c \
|
||||
notify.c \
|
||||
options-table.c \
|
||||
options.c \
|
||||
paste.c \
|
||||
proc.c \
|
||||
pty.c \
|
||||
resize.c \
|
||||
screen-redraw.c \
|
||||
screen-write.c \
|
||||
@@ -162,7 +158,6 @@ dist_tmux_SOURCES = \
|
||||
server-fn.c \
|
||||
server.c \
|
||||
session.c \
|
||||
signal.c \
|
||||
status.c \
|
||||
style.c \
|
||||
tmux.c \
|
||||
@@ -172,9 +167,11 @@ dist_tmux_SOURCES = \
|
||||
tty-term.c \
|
||||
tty.c \
|
||||
utf8.c \
|
||||
window-choose.c \
|
||||
window-buffer.c \
|
||||
window-client.c \
|
||||
window-clock.c \
|
||||
window-copy.c \
|
||||
window-tree.c \
|
||||
window.c \
|
||||
xmalloc.c \
|
||||
xmalloc.h \
|
||||
|
||||
20
README
20
README
@@ -1,8 +1,8 @@
|
||||
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.
|
||||
|
||||
@@ -29,21 +29,19 @@ To get and build the latest from version control:
|
||||
$ 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.)
|
||||
|
||||
For more information see http://git-scm.com. Patches should be sent by email to
|
||||
the mailing list at tmux-users@googlegroups.com.
|
||||
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
|
||||
|
||||
Some common questions are answered in the FAQ file, a rough todo list is in the
|
||||
TODO file and an example configuration in example_tmux.conf.
|
||||
|
||||
A vim(1) syntax file is available at:
|
||||
|
||||
https://github.com/ericpruitt/tmux.vim
|
||||
https://raw.githubusercontent.com/ericpruitt/tmux.vim/master/vim/syntax/tmux.vim
|
||||
A small example configuration in example_tmux.conf.
|
||||
|
||||
And a bash(1) completion file at:
|
||||
|
||||
|
||||
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>
|
||||
19
SYNCING
19
SYNCING
@@ -140,15 +140,13 @@ to compat/ as and when appropriate.
|
||||
Release tmux for next version
|
||||
=============================
|
||||
|
||||
1. Comment the "enable_debug=yes" line in configure.ac, since releases
|
||||
don't have debugging enabled, otherwise make(1) aborts when
|
||||
preparing the distribution.
|
||||
|
||||
2. Update and commit README and CHANGES. The former should be checked for
|
||||
1. Update and commit README and CHANGES. The former should be checked for
|
||||
anything outdated and updated with a list of things that might break
|
||||
upgrades and the latter should mention all the major changes since
|
||||
the last version.
|
||||
|
||||
2. Make sure configure.ac has the new version number.
|
||||
|
||||
3. Tag with:
|
||||
|
||||
% git tag -a 2.X
|
||||
@@ -157,7 +155,7 @@ Release tmux for next version
|
||||
|
||||
Push the tag out with:
|
||||
|
||||
% git push 2.X
|
||||
% git push --tags
|
||||
|
||||
4. Build the tarball with 'make dist'.
|
||||
|
||||
@@ -168,9 +166,8 @@ Release tmux for next version
|
||||
Click the "Add release notes", upload the tarball and add a link in the
|
||||
description field to the CHANGES file.
|
||||
|
||||
7. Clone the tmux.github.io repository, and change the RELEASE version in
|
||||
the Makefile. Commit it, and run 'make' to replace %%VERSION%%. Push
|
||||
the result out.
|
||||
6. Clone the tmux.github.io repository, and change the RELEASE version in the
|
||||
Makefile. Commit it, and run 'make' to replace %%RELEASE%%. Push the
|
||||
result out.
|
||||
|
||||
8. Bump version in tmux/tmux.git configure.ac and uncomment "enable_debug=yes" to
|
||||
create a debug build by default.
|
||||
7. Change version back to master in configure.ac.
|
||||
|
||||
39
TODO
39
TODO
@@ -1,7 +1,6 @@
|
||||
- command bits and pieces:
|
||||
* allow multiple targets: fnmatch for -t/-c, for example detach all
|
||||
clients with -t*
|
||||
* add -c for new-session like new-window
|
||||
* ' and " should be parsed the same (eg "\e" vs '\e') in config
|
||||
and command prompt
|
||||
* last-pane across sessions
|
||||
@@ -22,14 +21,8 @@
|
||||
* formats to show if a window is linked into multiple sessions, into
|
||||
multiple attached sessions, and is the active window in multiple
|
||||
attached sessions?
|
||||
|
||||
- choose mode improvements:
|
||||
* choose-pane command (augment choose-tree to do this?)
|
||||
* flag to choose-* for sort order
|
||||
* two choices (first one then second, for swap-pane and join-pane)
|
||||
* choose modes should ditch the key bindings and just have fixed keys, and
|
||||
be more customized to their purpose (d to delete a buffer for choose-buffer,
|
||||
a preview of buffer contents, etc)
|
||||
* comparison operators like < and > (for #{version}?)
|
||||
* %else statement in config file
|
||||
|
||||
- improve monitor-*:
|
||||
* straighten out rules for multiple clients
|
||||
@@ -53,8 +46,10 @@
|
||||
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)
|
||||
* 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
|
||||
@@ -70,6 +65,8 @@
|
||||
* 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
|
||||
@@ -100,7 +97,6 @@
|
||||
client w/o a session else cmd_current_client
|
||||
|
||||
- miscellaneous
|
||||
* way to keep a job running just read its last line of output for #()
|
||||
* link panes into multiple windows
|
||||
* live update: server started with -U connects to server, requests
|
||||
sessions and windows, receives file descriptors
|
||||
@@ -113,10 +109,25 @@
|
||||
* 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
|
||||
* 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
|
||||
* for session_closed, if no sessions at all, perhaps fake up a
|
||||
temporary one
|
||||
|
||||
183
alerts.c
183
alerts.c
@@ -30,13 +30,13 @@ static int alerts_enabled(struct window *, int);
|
||||
static void alerts_callback(int, short, void *);
|
||||
static void alerts_reset(struct window *);
|
||||
|
||||
static int alerts_action_applies(struct winlink *, const char *);
|
||||
static int alerts_check_all(struct window *);
|
||||
static int alerts_check_bell(struct window *);
|
||||
static int alerts_check_activity(struct window *);
|
||||
static int alerts_check_silence(struct window *);
|
||||
static void printflike(2, 3) alerts_set_message(struct session *, const char *,
|
||||
...);
|
||||
static void alerts_ring_bell(struct session *);
|
||||
static void alerts_set_message(struct winlink *, const char *,
|
||||
const char *);
|
||||
|
||||
static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);
|
||||
|
||||
@@ -46,7 +46,6 @@ alerts_timer(__unused int fd, __unused short events, void *arg)
|
||||
struct window *w = arg;
|
||||
|
||||
log_debug("@%u alerts timer expired", w->id);
|
||||
alerts_reset(w);
|
||||
alerts_queue(w, WINDOW_SILENCE);
|
||||
}
|
||||
|
||||
@@ -64,17 +63,38 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
|
||||
TAILQ_REMOVE(&alerts_list, w, alerts_entry);
|
||||
|
||||
w->flags &= ~WINDOW_ALERTFLAGS;
|
||||
window_remove_ref(w);
|
||||
window_remove_ref(w, __func__);
|
||||
}
|
||||
alerts_fired = 0;
|
||||
}
|
||||
|
||||
static int
|
||||
alerts_action_applies(struct winlink *wl, const char *name)
|
||||
{
|
||||
int action;
|
||||
|
||||
/*
|
||||
* {bell,activity,silence}-action determines when to alert: none means
|
||||
* nothing happens, current means only do something for the current
|
||||
* window and other means only for windows other than the current.
|
||||
*/
|
||||
|
||||
action = options_get_number(wl->session->options, name);
|
||||
if (action == ALERT_ANY)
|
||||
return (1);
|
||||
if (action == ALERT_CURRENT)
|
||||
return (wl == wl->session->curw);
|
||||
if (action == ALERT_OTHER)
|
||||
return (wl != wl->session->curw);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
alerts_check_all(struct window *w)
|
||||
{
|
||||
int alerts;
|
||||
|
||||
alerts = alerts_check_bell(w);
|
||||
alerts = alerts_check_bell(w);
|
||||
alerts |= alerts_check_activity(w);
|
||||
alerts |= alerts_check_silence(w);
|
||||
return (alerts);
|
||||
@@ -92,8 +112,10 @@ alerts_check_session(struct session *s)
|
||||
static int
|
||||
alerts_enabled(struct window *w, int flags)
|
||||
{
|
||||
if (flags & WINDOW_BELL)
|
||||
return (1);
|
||||
if (flags & WINDOW_BELL) {
|
||||
if (options_get_number(w->options, "monitor-bell"))
|
||||
return (1);
|
||||
}
|
||||
if (flags & WINDOW_ACTIVITY) {
|
||||
if (options_get_number(w->options, "monitor-activity"))
|
||||
return (1);
|
||||
@@ -119,6 +141,9 @@ alerts_reset(struct window *w)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
if (!event_initialized(&w->alerts_timer))
|
||||
evtimer_set(&w->alerts_timer, alerts_timer, w);
|
||||
|
||||
w->flags &= ~WINDOW_SILENCE;
|
||||
event_del(&w->alerts_timer);
|
||||
|
||||
@@ -133,85 +158,61 @@ alerts_reset(struct window *w)
|
||||
void
|
||||
alerts_queue(struct window *w, int flags)
|
||||
{
|
||||
if (w->flags & WINDOW_ACTIVITY)
|
||||
alerts_reset(w);
|
||||
|
||||
if (!event_initialized(&w->alerts_timer))
|
||||
evtimer_set(&w->alerts_timer, alerts_timer, w);
|
||||
alerts_reset(w);
|
||||
|
||||
if ((w->flags & flags) != flags) {
|
||||
w->flags |= flags;
|
||||
log_debug("@%u alerts flags added %#x", w->id, flags);
|
||||
}
|
||||
|
||||
if (!w->alerts_queued) {
|
||||
w->alerts_queued = 1;
|
||||
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
|
||||
w->references++;
|
||||
}
|
||||
if (alerts_enabled(w, flags)) {
|
||||
if (!w->alerts_queued) {
|
||||
w->alerts_queued = 1;
|
||||
TAILQ_INSERT_TAIL(&alerts_list, w, alerts_entry);
|
||||
window_add_ref(w, __func__);
|
||||
}
|
||||
|
||||
if (!alerts_fired && alerts_enabled(w, flags)) {
|
||||
log_debug("alerts check queued (by @%u)", w->id);
|
||||
event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
|
||||
alerts_fired = 1;
|
||||
if (!alerts_fired) {
|
||||
log_debug("alerts check queued (by @%u)", w->id);
|
||||
event_once(-1, EV_TIMEOUT, alerts_callback, NULL, NULL);
|
||||
alerts_fired = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
alerts_check_bell(struct window *w)
|
||||
{
|
||||
struct window *ws;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct client *c;
|
||||
int action, visual;
|
||||
|
||||
if (~w->flags & WINDOW_BELL)
|
||||
return (0);
|
||||
if (!options_get_number(w->options, "monitor-bell"))
|
||||
return (0);
|
||||
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
||||
wl->session->flags &= ~SESSION_ALERTED;
|
||||
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry) {
|
||||
if (wl->flags & WINLINK_BELL)
|
||||
continue;
|
||||
/*
|
||||
* Bells are allowed even if there is an existing bell (so do
|
||||
* not check WINLINK_BELL).
|
||||
*/
|
||||
s = wl->session;
|
||||
if (s->curw != wl) {
|
||||
wl->flags |= WINLINK_BELL;
|
||||
notify_winlink("alert-bell", s, wl);
|
||||
server_status_session(s);
|
||||
}
|
||||
if (!alerts_action_applies(wl, "bell-action"))
|
||||
continue;
|
||||
notify_winlink("alert-bell", wl);
|
||||
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
action = options_get_number(s->options, "bell-action");
|
||||
if (action == BELL_NONE)
|
||||
return (0);
|
||||
|
||||
visual = options_get_number(s->options, "visual-bell");
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s || c->flags & CLIENT_CONTROL)
|
||||
continue;
|
||||
ws = c->session->curw->window;
|
||||
|
||||
if (action == BELL_CURRENT && ws != w)
|
||||
action = BELL_NONE;
|
||||
if (action == BELL_OTHER && ws != w)
|
||||
action = BELL_NONE;
|
||||
|
||||
if (!visual) {
|
||||
if (action != BELL_NONE)
|
||||
tty_putcode(&c->tty, TTYC_BEL);
|
||||
continue;
|
||||
}
|
||||
if (action == BELL_CURRENT)
|
||||
status_message_set(c, "Bell in current window");
|
||||
else if (action != BELL_NONE) {
|
||||
status_message_set(c, "Bell in window %d",
|
||||
wl->idx);
|
||||
}
|
||||
}
|
||||
alerts_set_message(wl, "Bell", "visual-bell");
|
||||
}
|
||||
|
||||
return (WINDOW_BELL);
|
||||
@@ -235,20 +236,19 @@ alerts_check_activity(struct window *w)
|
||||
if (wl->flags & WINLINK_ACTIVITY)
|
||||
continue;
|
||||
s = wl->session;
|
||||
if (s->curw == wl)
|
||||
if (s->curw != wl) {
|
||||
wl->flags |= WINLINK_ACTIVITY;
|
||||
server_status_session(s);
|
||||
}
|
||||
if (!alerts_action_applies(wl, "activity-action"))
|
||||
continue;
|
||||
|
||||
wl->flags |= WINLINK_ACTIVITY;
|
||||
notify_winlink("alert-activity", s, wl);
|
||||
notify_winlink("alert-activity", wl);
|
||||
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
if (options_get_number(s->options, "visual-activity"))
|
||||
alerts_set_message(s, "Activity in window %d", wl->idx);
|
||||
alerts_set_message(wl, "Activity", "visual-activity");
|
||||
}
|
||||
|
||||
return (WINDOW_ACTIVITY);
|
||||
@@ -262,7 +262,7 @@ alerts_check_silence(struct window *w)
|
||||
|
||||
if (~w->flags & WINDOW_SILENCE)
|
||||
return (0);
|
||||
if (!options_get_number(w->options, "monitor-silence"))
|
||||
if (options_get_number(w->options, "monitor-silence") == 0)
|
||||
return (0);
|
||||
|
||||
TAILQ_FOREACH(wl, &w->winlinks, wentry)
|
||||
@@ -272,51 +272,52 @@ alerts_check_silence(struct window *w)
|
||||
if (wl->flags & WINLINK_SILENCE)
|
||||
continue;
|
||||
s = wl->session;
|
||||
if (s->curw == wl)
|
||||
if (s->curw != wl) {
|
||||
wl->flags |= WINLINK_SILENCE;
|
||||
server_status_session(s);
|
||||
}
|
||||
if (!alerts_action_applies(wl, "silence-action"))
|
||||
continue;
|
||||
wl->flags |= WINLINK_SILENCE;
|
||||
notify_winlink("alert-silence", s, wl);
|
||||
notify_winlink("alert-silence", wl);
|
||||
|
||||
if (s->flags & SESSION_ALERTED)
|
||||
continue;
|
||||
s->flags |= SESSION_ALERTED;
|
||||
|
||||
if (options_get_number(s->options, "bell-on-alert"))
|
||||
alerts_ring_bell(s);
|
||||
|
||||
if (!options_get_number(s->options, "visual-silence"))
|
||||
alerts_set_message(s, "Silence in window %d", wl->idx);
|
||||
alerts_set_message(wl, "Silence", "visual-silence");
|
||||
}
|
||||
|
||||
return (WINDOW_SILENCE);
|
||||
}
|
||||
|
||||
static void
|
||||
alerts_set_message(struct session *s, const char *fmt, ...)
|
||||
alerts_set_message(struct winlink *wl, const char *type, const char *option)
|
||||
{
|
||||
struct client *c;
|
||||
va_list ap;
|
||||
char *message;
|
||||
int visual;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&message, fmt, ap);
|
||||
va_end(ap);
|
||||
/*
|
||||
* We have found an alert (bell, activity or silence), so we need to
|
||||
* pass it on to the user. For each client attached to this session,
|
||||
* decide whether a bell, message or both is needed.
|
||||
*
|
||||
* If visual-{bell,activity,silence} is on, then a message is
|
||||
* substituted for a bell; if it is off, a bell is sent as normal; both
|
||||
* mean both a bell and message is sent.
|
||||
*/
|
||||
|
||||
visual = options_get_number(wl->session->options, option);
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == s)
|
||||
status_message_set(c, "%s", message);
|
||||
}
|
||||
if (c->session != wl->session || c->flags & CLIENT_CONTROL)
|
||||
continue;
|
||||
|
||||
free(message);
|
||||
}
|
||||
|
||||
static void
|
||||
alerts_ring_bell(struct session *s)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session == s && !(c->flags & CLIENT_CONTROL))
|
||||
if (visual == VISUAL_OFF || visual == VISUAL_BOTH)
|
||||
tty_putcode(&c->tty, TTYC_BEL);
|
||||
if (visual == VISUAL_OFF)
|
||||
continue;
|
||||
if (c->session->curw == wl)
|
||||
status_message_set(c, "%s in current window", type);
|
||||
else
|
||||
status_message_set(c, "%s in window %d", type, wl->idx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ struct args_entry {
|
||||
RB_ENTRY(args_entry) entry;
|
||||
};
|
||||
|
||||
static void args_set(struct args *, u_char, const char *);
|
||||
static struct args_entry *args_find(struct args *, u_char);
|
||||
|
||||
static int args_cmp(struct args_entry *, struct args_entry *);
|
||||
@@ -191,11 +190,11 @@ args_print(struct args *args)
|
||||
int
|
||||
args_has(struct args *args, u_char ch)
|
||||
{
|
||||
return (args_find(args, ch) == NULL ? 0 : 1);
|
||||
return (args_find(args, ch) != NULL);
|
||||
}
|
||||
|
||||
/* Set argument value in the arguments tree. */
|
||||
static void
|
||||
void
|
||||
args_set(struct args *args, u_char ch, const char *value)
|
||||
{
|
||||
struct args_entry *entry;
|
||||
|
||||
227
cfg.c
227
cfg.c
@@ -23,15 +23,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
static char *cfg_file;
|
||||
int cfg_finished;
|
||||
static char **cfg_causes;
|
||||
static u_int cfg_ncauses;
|
||||
struct client *cfg_client;
|
||||
/* 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);
|
||||
|
||||
static char *cfg_file;
|
||||
int cfg_finished;
|
||||
static char **cfg_causes;
|
||||
static u_int cfg_ncauses;
|
||||
static struct cmdq_item *cfg_item;
|
||||
|
||||
static enum cmd_retval
|
||||
cfg_client_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
{
|
||||
if (!cfg_finished)
|
||||
return (CMD_RETURN_WAIT);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
@@ -43,8 +61,11 @@ cfg_done(__unused struct cmdq_item *item, __unused void *data)
|
||||
if (!RB_EMPTY(&sessions))
|
||||
cfg_show_causes(RB_MIN(sessions, &sessions));
|
||||
|
||||
if (cfg_client != NULL)
|
||||
server_client_unref(cfg_client);
|
||||
if (cfg_item != NULL)
|
||||
cfg_item->flags &= ~CMDQ_WAITING;
|
||||
|
||||
status_prompt_load_history();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -60,21 +81,153 @@ start_cfg(void)
|
||||
{
|
||||
const char *home;
|
||||
int quiet = 0;
|
||||
struct client *c;
|
||||
|
||||
cfg_client = TAILQ_FIRST(&clients);
|
||||
if (cfg_client != NULL)
|
||||
cfg_client->references++;
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
* However, we must block the initial client (but just the initial
|
||||
* client) so that its command runs after the configuration is loaded.
|
||||
* Because start_cfg() is called so early, we can be sure the client's
|
||||
* 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);
|
||||
if (c != NULL) {
|
||||
cfg_item = cmdq_get_callback(cfg_client_done, NULL);
|
||||
cmdq_append(c, cfg_item);
|
||||
}
|
||||
|
||||
load_cfg(TMUX_CONF, cfg_client, NULL, 1);
|
||||
load_cfg(TMUX_CONF, NULL, NULL, 1);
|
||||
|
||||
if (cfg_file == NULL && (home = find_home()) != NULL) {
|
||||
xasprintf(&cfg_file, "%s/.tmux.conf", home);
|
||||
quiet = 1;
|
||||
}
|
||||
if (cfg_file != NULL)
|
||||
load_cfg(cfg_file, cfg_client, NULL, quiet);
|
||||
load_cfg(cfg_file, NULL, NULL, quiet);
|
||||
|
||||
cmdq_append(cfg_client, cmdq_get_callback(cfg_done, 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
|
||||
@@ -84,11 +237,13 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
const char delim[3] = { '\\', '\\', '\0' };
|
||||
u_int found = 0;
|
||||
size_t line = 0;
|
||||
char *buf, *cause1, *p, *q, *s;
|
||||
char *buf, *cause1, *p, *q;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
int condition = 0;
|
||||
struct format_tree *ft;
|
||||
struct cfg_cond *cond, *cond1;
|
||||
struct cfg_conds conds;
|
||||
|
||||
TAILQ_INIT(&conds);
|
||||
|
||||
log_debug("loading %s", path);
|
||||
if ((f = fopen(path, "rb")) == NULL) {
|
||||
@@ -112,32 +267,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
while (q != p && isspace((u_char)*q))
|
||||
*q-- = '\0';
|
||||
|
||||
if (condition != 0 && strcmp(p, "%endif") == 0) {
|
||||
condition = 0;
|
||||
if (*p == '%') {
|
||||
cfg_handle_directive(p, path, line, &conds);
|
||||
continue;
|
||||
}
|
||||
if (strncmp(p, "%if ", 4) == 0) {
|
||||
if (condition != 0) {
|
||||
cfg_add_cause("%s:%zu: nested %%if", path,
|
||||
line);
|
||||
continue;
|
||||
}
|
||||
ft = format_create(NULL, FORMAT_NONE, FORMAT_NOJOBS);
|
||||
|
||||
s = p + 3;
|
||||
while (isspace((u_char)*s))
|
||||
s++;
|
||||
s = format_expand(ft, s);
|
||||
if (*s != '\0' && (s[0] != '0' || s[1] != '\0'))
|
||||
condition = 1;
|
||||
else
|
||||
condition = -1;
|
||||
free(s);
|
||||
|
||||
format_free(ft);
|
||||
continue;
|
||||
}
|
||||
if (condition == -1)
|
||||
cond = TAILQ_FIRST(&conds);
|
||||
if (cond != NULL && !cond->met)
|
||||
continue;
|
||||
|
||||
cmdlist = cmd_string_parse(p, path, line, &cause1);
|
||||
@@ -151,8 +286,6 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
}
|
||||
free(buf);
|
||||
|
||||
if (cmdlist == NULL)
|
||||
continue;
|
||||
new_item = cmdq_get_command(cmdlist, NULL, NULL, 0);
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item);
|
||||
@@ -164,6 +297,12 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int quiet)
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
return (found);
|
||||
}
|
||||
|
||||
@@ -207,7 +346,7 @@ cfg_show_causes(struct session *s)
|
||||
return;
|
||||
wp = s->curw->window->active;
|
||||
|
||||
window_pane_set_mode(wp, &window_copy_mode);
|
||||
window_pane_set_mode(wp, &window_copy_mode, NULL, NULL);
|
||||
window_copy_init_for_output(wp);
|
||||
for (i = 0; i < cfg_ncauses; i++) {
|
||||
window_copy_add(wp, "%s", cfg_causes[i]);
|
||||
|
||||
43
client.c
43
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>
|
||||
@@ -63,7 +62,7 @@ static void client_write(int, const char *, size_t);
|
||||
static void client_signal(int);
|
||||
static void client_dispatch(struct imsg *, void *);
|
||||
static void client_dispatch_attached(struct imsg *);
|
||||
static void client_dispatch_wait(struct imsg *, const char *);
|
||||
static void client_dispatch_wait(struct imsg *);
|
||||
static const char *client_exit_message(void);
|
||||
|
||||
/*
|
||||
@@ -156,7 +155,7 @@ retry:
|
||||
close(lockfd);
|
||||
return (-1);
|
||||
}
|
||||
fd = server_start(base, lockfd, lockfile);
|
||||
fd = server_start(client_proc, base, lockfd, lockfile);
|
||||
}
|
||||
|
||||
if (locked && lockfd >= 0) {
|
||||
@@ -214,8 +213,7 @@ client_exit_message(void)
|
||||
|
||||
/* Client main loop. */
|
||||
int
|
||||
client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
const char *shellcmd)
|
||||
client_main(struct event_base *base, int argc, char **argv, int flags)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmd_list *cmdlist;
|
||||
@@ -236,7 +234,7 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
|
||||
/* Set up the initial command. */
|
||||
cmdflags = 0;
|
||||
if (shellcmd != NULL) {
|
||||
if (shell_command != NULL) {
|
||||
msg = MSG_SHELL;
|
||||
cmdflags = CMD_STARTSERVER;
|
||||
} else if (argc == 0) {
|
||||
@@ -261,7 +259,8 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
}
|
||||
|
||||
/* Create client process structure (starts logging). */
|
||||
client_proc = proc_start("client", base, 0, client_signal);
|
||||
client_proc = proc_start("client");
|
||||
proc_set_signals(client_proc, client_signal);
|
||||
|
||||
/* Initialize the client socket and start the server. */
|
||||
fd = client_connect(base, socket_path, cmdflags & CMD_STARTSERVER);
|
||||
@@ -275,14 +274,13 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch,
|
||||
(void *)shellcmd);
|
||||
client_peer = proc_add_peer(client_proc, fd, client_dispatch, NULL);
|
||||
|
||||
/* Save these before pledge(). */
|
||||
if ((cwd = getcwd(path, sizeof path)) == NULL) {
|
||||
if ((cwd = find_home()) == NULL)
|
||||
cwd = "/";
|
||||
}
|
||||
if ((cwd = getenv("PWD")) == NULL &&
|
||||
(cwd = getcwd(path, sizeof path)) == NULL &&
|
||||
(cwd = find_home()) == NULL)
|
||||
cwd = "/";
|
||||
if ((ttynam = ttyname(STDIN_FILENO)) == NULL)
|
||||
ttynam = "";
|
||||
|
||||
@@ -339,6 +337,10 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
size = 0;
|
||||
for (i = 0; i < argc; i++)
|
||||
size += strlen(argv[i]) + 1;
|
||||
if (size > MAX_IMSGSIZE - (sizeof *data)) {
|
||||
fprintf(stderr, "command too long\n");
|
||||
return (1);
|
||||
}
|
||||
data = xmalloc((sizeof *data) + size);
|
||||
|
||||
/* Prepare command for server. */
|
||||
@@ -367,7 +369,6 @@ client_main(struct event_base *base, int argc, char **argv, int flags,
|
||||
if (client_exittype == MSG_EXEC) {
|
||||
if (client_flags & CLIENT_CONTROLCONTROL)
|
||||
tcsetattr(STDOUT_FILENO, TCSAFLUSH, &saved_tio);
|
||||
clear_signals(0);
|
||||
client_exec(client_execshell, client_execcmd);
|
||||
}
|
||||
|
||||
@@ -451,6 +452,7 @@ client_write(int fd, const char *data, size_t size)
|
||||
{
|
||||
ssize_t used;
|
||||
|
||||
log_debug("%s: %.*s", __func__, (int)size, data);
|
||||
while (size != 0) {
|
||||
used = write(fd, data, size);
|
||||
if (used == -1) {
|
||||
@@ -483,6 +485,8 @@ client_exec(const char *shell, const char *shellcmd)
|
||||
xasprintf(&argv0, "%s", name);
|
||||
setenv("SHELL", shell, 1);
|
||||
|
||||
proc_clear_signals(client_proc, 1);
|
||||
|
||||
setblocking(STDIN_FILENO, 1);
|
||||
setblocking(STDOUT_FILENO, 1);
|
||||
setblocking(STDERR_FILENO, 1);
|
||||
@@ -534,7 +538,7 @@ client_signal(int sig)
|
||||
|
||||
/* Callback for client read events. */
|
||||
static void
|
||||
client_dispatch(struct imsg *imsg, void *arg)
|
||||
client_dispatch(struct imsg *imsg, __unused void *arg)
|
||||
{
|
||||
if (imsg == NULL) {
|
||||
client_exitreason = CLIENT_EXIT_LOST_SERVER;
|
||||
@@ -546,12 +550,12 @@ client_dispatch(struct imsg *imsg, void *arg)
|
||||
if (client_attached)
|
||||
client_dispatch_attached(imsg);
|
||||
else
|
||||
client_dispatch_wait(imsg, arg);
|
||||
client_dispatch_wait(imsg);
|
||||
}
|
||||
|
||||
/* Dispatch imsgs when in wait state (before MSG_READY). */
|
||||
static void
|
||||
client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
client_dispatch_wait(struct imsg *imsg)
|
||||
{
|
||||
char *data;
|
||||
ssize_t datalen;
|
||||
@@ -630,8 +634,7 @@ client_dispatch_wait(struct imsg *imsg, const char *shellcmd)
|
||||
if (datalen == 0 || data[datalen - 1] != '\0')
|
||||
fatalx("bad MSG_SHELL string");
|
||||
|
||||
clear_signals(0);
|
||||
client_exec(data, shellcmd);
|
||||
client_exec(data, shell_command);
|
||||
/* NOTREACHED */
|
||||
case MSG_DETACH:
|
||||
case MSG_DETACHKILL:
|
||||
|
||||
@@ -40,20 +40,23 @@ const struct cmd_entry cmd_attach_session_entry = {
|
||||
.args = { "c:dErt:", 0, 0 },
|
||||
.usage = "[-dEr] [-c working-directory] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION_WITHPANE,
|
||||
/* -t is special */
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.exec = cmd_attach_session_exec
|
||||
};
|
||||
|
||||
enum cmd_retval
|
||||
cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
const char *cflag, int Eflag)
|
||||
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
|
||||
int rflag, const char *cflag, int Eflag)
|
||||
{
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
enum cmd_find_type type;
|
||||
int flags;
|
||||
struct client *c = item->client, *c_loop;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
char *cause;
|
||||
|
||||
if (RB_EMPTY(&sessions)) {
|
||||
@@ -69,10 +72,27 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
type = CMD_FIND_PANE;
|
||||
flags = 0;
|
||||
} else {
|
||||
type = CMD_FIND_SESSION;
|
||||
flags = CMD_FIND_PREFER_UNATTACHED;
|
||||
}
|
||||
if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
s = item->target.s;
|
||||
wl = item->target.wl;
|
||||
wp = item->target.wp;
|
||||
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
session_set_current(s, wl);
|
||||
if (wp != NULL)
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
else
|
||||
cmd_find_from_winlink(current, wl, 0);
|
||||
}
|
||||
|
||||
if (cflag != NULL) {
|
||||
@@ -80,6 +100,7 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
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) {
|
||||
@@ -92,7 +113,7 @@ cmd_attach_session(struct cmdq_item *item, int dflag, int rflag,
|
||||
environ_update(s->options, c->environ, s->environ);
|
||||
|
||||
c->session = s;
|
||||
if (!item->repeat)
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
@@ -145,6 +166,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
|
||||
return (cmd_attach_session(item, args_has(args, 'd'),
|
||||
args_has(args, 'r'), args_get(args, 'c'), args_has(args, 'E')));
|
||||
return (cmd_attach_session(item, args_get(args, 't'),
|
||||
args_has(args, 'd'), args_has(args, 'r'), args_get(args, 'c'),
|
||||
args_has(args, 'E')));
|
||||
}
|
||||
|
||||
@@ -35,10 +35,11 @@ const struct cmd_entry cmd_break_pane_entry = {
|
||||
.alias = "breakp",
|
||||
|
||||
.args = { "dPF:n:s:t:", 0, 0 },
|
||||
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] [-t dst-window]",
|
||||
.usage = "[-dP] [-F format] [-n window-name] [-s src-pane] "
|
||||
"[-t dst-window]",
|
||||
|
||||
.sflag = CMD_PANE,
|
||||
.tflag = CMD_WINDOW_INDEX,
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_break_pane_exec
|
||||
@@ -48,14 +49,15 @@ static enum cmd_retval
|
||||
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.sflag.wl;
|
||||
struct session *src_s = item->state.sflag.s;
|
||||
struct session *dst_s = item->state.tflag.s;
|
||||
struct window_pane *wp = item->state.sflag.wp;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct winlink *wl = item->source.wl;
|
||||
struct session *src_s = item->source.s;
|
||||
struct session *dst_s = item->target.s;
|
||||
struct window_pane *wp = item->source.wp;
|
||||
struct window *w = wl->window;
|
||||
char *name, *cause;
|
||||
int idx = item->state.tflag.idx;
|
||||
int idx = item->target.idx;
|
||||
const char *template;
|
||||
char *cp;
|
||||
|
||||
@@ -93,8 +95,10 @@ cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(dst_s->options, "base-index");
|
||||
wl = session_attach(dst_s, w, idx, &cause); /* can't fail */
|
||||
if (!args_has(self->args, 'd'))
|
||||
if (!args_has(self->args, 'd')) {
|
||||
session_select(dst_s, wl->idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
}
|
||||
|
||||
server_redraw_session(src_s);
|
||||
if (src_s != dst_s)
|
||||
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_capture_pane_entry = {
|
||||
.usage = "[-aCeJpPq] " CMD_BUFFER_USAGE " [-E end-line] "
|
||||
"[-S start-line]" CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
@@ -56,7 +56,7 @@ const struct cmd_entry cmd_clear_history_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_capture_pane_exec
|
||||
@@ -193,7 +193,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
char *buf, *cause;
|
||||
const char *bufname;
|
||||
size_t len;
|
||||
|
||||
@@ -1,101 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010 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 <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter choice mode to choose a buffer.
|
||||
*/
|
||||
|
||||
#define CHOOSE_BUFFER_TEMPLATE \
|
||||
"#{buffer_name}: #{buffer_size} bytes: #{buffer_sample}"
|
||||
|
||||
static enum cmd_retval cmd_choose_buffer_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.name = "choose-buffer",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:t:", 0, 1 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_buffer_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_choose_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_choose_data *cdata;
|
||||
struct paste_buffer *pb;
|
||||
char *action, *action_data;
|
||||
const char *template;
|
||||
u_int idx;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = CHOOSE_BUFFER_TEMPLATE;
|
||||
|
||||
if (paste_get_top(NULL) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if (args->argc != 0)
|
||||
action = xstrdup(args->argv[0]);
|
||||
else
|
||||
action = xstrdup("paste-buffer -b '%%'");
|
||||
|
||||
idx = 0;
|
||||
pb = NULL;
|
||||
while ((pb = paste_walk(pb)) != NULL) {
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = idx;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
format_defaults_paste_buffer(cdata->ft, pb);
|
||||
|
||||
xasprintf(&action_data, "%s", paste_buffer_name(pb));
|
||||
cdata->command = cmd_template_replace(action, action_data, 1);
|
||||
free(action_data);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
idx++;
|
||||
}
|
||||
free(action);
|
||||
|
||||
window_choose_ready(wl->window->active, 0, NULL);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 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 <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
* Enter choice mode to choose a client.
|
||||
*/
|
||||
|
||||
#define CHOOSE_CLIENT_TEMPLATE \
|
||||
"#{client_name}: #{session_name} " \
|
||||
"[#{client_width}x#{client_height} #{client_termname}]" \
|
||||
"#{?client_utf8, (utf8),}#{?client_readonly, (ro),} " \
|
||||
"(last used #{t:client_activity})"
|
||||
|
||||
static enum cmd_retval cmd_choose_client_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static void cmd_choose_client_callback(struct window_choose_data *);
|
||||
|
||||
const struct cmd_entry cmd_choose_client_entry = {
|
||||
.name = "choose-client",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:t:", 0, 1 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_client_exec
|
||||
};
|
||||
|
||||
struct cmd_choose_client_data {
|
||||
struct client *client;
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_choose_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c1;
|
||||
struct window_choose_data *cdata;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
const char *template;
|
||||
char *action;
|
||||
u_int idx, cur;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = CHOOSE_CLIENT_TEMPLATE;
|
||||
|
||||
if (args->argc != 0)
|
||||
action = xstrdup(args->argv[0]);
|
||||
else
|
||||
action = xstrdup("detach-client -t '%%'");
|
||||
|
||||
cur = idx = 0;
|
||||
TAILQ_FOREACH(c1, &clients, entry) {
|
||||
if (c1->session == NULL)
|
||||
continue;
|
||||
if (c1 == item->client)
|
||||
cur = idx;
|
||||
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = idx;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
format_add(cdata->ft, "line", "%u", idx);
|
||||
format_defaults(cdata->ft, c1, NULL, NULL, NULL);
|
||||
|
||||
cdata->command = cmd_template_replace(action, c1->name, 1);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
|
||||
idx++;
|
||||
}
|
||||
free(action);
|
||||
|
||||
window_choose_ready(wl->window->active, cur,
|
||||
cmd_choose_client_callback);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_choose_client_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
struct client *c;
|
||||
u_int idx;
|
||||
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
if (cdata->start_client->flags & CLIENT_DEAD)
|
||||
return;
|
||||
|
||||
idx = 0;
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (idx == cdata->idx)
|
||||
break;
|
||||
idx++;
|
||||
}
|
||||
if (c == NULL || c->session == NULL)
|
||||
return;
|
||||
|
||||
window_choose_data_run(cdata);
|
||||
}
|
||||
@@ -18,66 +18,51 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#define CMD_CHOOSE_TREE_WINDOW_ACTION "select-window -t '%%'"
|
||||
#define CMD_CHOOSE_TREE_SESSION_ACTION "switch-client -t '%%'"
|
||||
|
||||
/*
|
||||
* Enter choice mode to choose a session and/or window.
|
||||
* Enter a mode.
|
||||
*/
|
||||
|
||||
#define CHOOSE_TREE_SESSION_TEMPLATE \
|
||||
"#{session_name}: #{session_windows} windows" \
|
||||
"#{?session_grouped, (group ,}" \
|
||||
"#{session_group}#{?session_grouped,),}" \
|
||||
"#{?session_attached, (attached),}"
|
||||
#define CHOOSE_TREE_WINDOW_TEMPLATE \
|
||||
"#{window_index}: #{window_name}#{window_flags} " \
|
||||
"\"#{pane_title}\""
|
||||
|
||||
static enum cmd_retval cmd_choose_tree_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
const struct cmd_entry cmd_choose_tree_entry = {
|
||||
.name = "choose-tree",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "S:W:swub:c:t:", 0, 1 },
|
||||
.usage = "[-suw] [-b session-template] [-c window template] "
|
||||
"[-S format] [-W format] " CMD_TARGET_WINDOW_USAGE,
|
||||
.args = { "F:Gf:NO:st:wZ", 0, 1 },
|
||||
.usage = "[-GNsw] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_choose_session_entry = {
|
||||
.name = "choose-session",
|
||||
const struct cmd_entry cmd_choose_client_entry = {
|
||||
.name = "choose-client",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:t:", 0, 1 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " [-F format] [template]",
|
||||
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_tree_exec
|
||||
};
|
||||
|
||||
const struct cmd_entry cmd_choose_window_entry = {
|
||||
.name = "choose-window",
|
||||
const struct cmd_entry cmd_choose_buffer_entry = {
|
||||
.name = "choose-buffer",
|
||||
.alias = NULL,
|
||||
|
||||
.args = { "F:t:", 0, 1 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE "[-F format] [template]",
|
||||
.args = { "F:f:NO:t:Z", 0, 1 },
|
||||
.usage = "[-N] [-F format] [-f filter] [-O sort-order] "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_choose_tree_exec
|
||||
@@ -87,167 +72,20 @@ static enum cmd_retval
|
||||
cmd_choose_tree_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct winlink *wl = item->state.tflag.wl, *wm;
|
||||
struct session *s = item->state.tflag.s, *s2;
|
||||
struct window_choose_data *wcd = NULL;
|
||||
const char *ses_template, *win_template;
|
||||
char *final_win_action, *cur_win_template;
|
||||
char *final_win_template_middle;
|
||||
char *final_win_template_last;
|
||||
const char *ses_action, *win_action;
|
||||
u_int cur_win, idx_ses, win_ses, win_max;
|
||||
u_int wflag, sflag;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const struct window_mode *mode;
|
||||
|
||||
ses_template = win_template = NULL;
|
||||
ses_action = win_action = NULL;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/* Sort out which command this is. */
|
||||
wflag = sflag = 0;
|
||||
if (self->entry == &cmd_choose_session_entry) {
|
||||
sflag = 1;
|
||||
if ((ses_template = args_get(args, 'F')) == NULL)
|
||||
ses_template = CHOOSE_TREE_SESSION_TEMPLATE;
|
||||
|
||||
if (args->argc != 0)
|
||||
ses_action = args->argv[0];
|
||||
else
|
||||
ses_action = CMD_CHOOSE_TREE_SESSION_ACTION;
|
||||
} else if (self->entry == &cmd_choose_window_entry) {
|
||||
wflag = 1;
|
||||
if ((win_template = args_get(args, 'F')) == NULL)
|
||||
win_template = CHOOSE_TREE_WINDOW_TEMPLATE;
|
||||
|
||||
if (args->argc != 0)
|
||||
win_action = args->argv[0];
|
||||
else
|
||||
win_action = CMD_CHOOSE_TREE_WINDOW_ACTION;
|
||||
} else {
|
||||
wflag = args_has(args, 'w');
|
||||
sflag = args_has(args, 's');
|
||||
|
||||
if ((ses_action = args_get(args, 'b')) == NULL)
|
||||
ses_action = CMD_CHOOSE_TREE_SESSION_ACTION;
|
||||
|
||||
if ((win_action = args_get(args, 'c')) == NULL)
|
||||
win_action = CMD_CHOOSE_TREE_WINDOW_ACTION;
|
||||
|
||||
if ((ses_template = args_get(args, 'S')) == NULL)
|
||||
ses_template = CHOOSE_TREE_SESSION_TEMPLATE;
|
||||
|
||||
if ((win_template = args_get(args, 'W')) == NULL)
|
||||
win_template = CHOOSE_TREE_WINDOW_TEMPLATE;
|
||||
}
|
||||
|
||||
/*
|
||||
* If not asking for windows and sessions, assume no "-ws" given and
|
||||
* hence display the entire tree outright.
|
||||
*/
|
||||
if (!wflag && !sflag)
|
||||
wflag = sflag = 1;
|
||||
|
||||
/*
|
||||
* If we're drawing in tree mode, including sessions, then pad the
|
||||
* window template, otherwise just render the windows as a flat list
|
||||
* without any padding.
|
||||
*/
|
||||
if (wflag && sflag) {
|
||||
xasprintf(&final_win_template_middle,
|
||||
" \001tq\001> %s", win_template);
|
||||
xasprintf(&final_win_template_last,
|
||||
" \001mq\001> %s", win_template);
|
||||
} else if (wflag) {
|
||||
final_win_template_middle = xstrdup(win_template);
|
||||
final_win_template_last = xstrdup(win_template);
|
||||
if (self->entry == &cmd_choose_buffer_entry) {
|
||||
if (paste_get_top(NULL) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_buffer_mode;
|
||||
} else if (self->entry == &cmd_choose_client_entry) {
|
||||
if (server_client_how_many() == 0)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
mode = &window_client_mode;
|
||||
} else
|
||||
final_win_template_middle = final_win_template_last = NULL;
|
||||
|
||||
idx_ses = cur_win = -1;
|
||||
RB_FOREACH(s2, sessions, &sessions) {
|
||||
idx_ses++;
|
||||
|
||||
/*
|
||||
* If we're just choosing windows, jump straight there. Note
|
||||
* that this implies the current session, so only choose
|
||||
* windows when the session matches this one.
|
||||
*/
|
||||
if (wflag && !sflag) {
|
||||
if (s != s2)
|
||||
continue;
|
||||
goto windows_only;
|
||||
}
|
||||
|
||||
wcd = window_choose_add_session(wl->window->active,
|
||||
c, s2, ses_template, ses_action, idx_ses);
|
||||
|
||||
/* If we're just choosing sessions, skip choosing windows. */
|
||||
if (sflag && !wflag) {
|
||||
if (s == s2)
|
||||
cur_win = idx_ses;
|
||||
continue;
|
||||
}
|
||||
windows_only:
|
||||
win_ses = win_max = -1;
|
||||
RB_FOREACH(wm, winlinks, &s2->windows)
|
||||
win_max++;
|
||||
RB_FOREACH(wm, winlinks, &s2->windows) {
|
||||
win_ses++;
|
||||
if (sflag && wflag)
|
||||
idx_ses++;
|
||||
|
||||
if (wm == s2->curw && s == s2) {
|
||||
if (wflag && !sflag) {
|
||||
/*
|
||||
* Then we're only counting windows.
|
||||
* So remember which is the current
|
||||
* window in the list.
|
||||
*/
|
||||
cur_win = win_ses;
|
||||
} else
|
||||
cur_win = idx_ses;
|
||||
}
|
||||
|
||||
xasprintf(&final_win_action, "%s %s %s",
|
||||
wcd != NULL ? wcd->command : "",
|
||||
wcd != NULL ? ";" : "", win_action);
|
||||
|
||||
if (win_ses != win_max)
|
||||
cur_win_template = final_win_template_middle;
|
||||
else
|
||||
cur_win_template = final_win_template_last;
|
||||
|
||||
window_choose_add_window(wl->window->active,
|
||||
c, s2, wm, cur_win_template,
|
||||
final_win_action,
|
||||
(wflag && !sflag) ? win_ses : idx_ses);
|
||||
|
||||
free(final_win_action);
|
||||
}
|
||||
|
||||
/*
|
||||
* If we're just drawing windows, don't consider moving on to
|
||||
* other sessions as we only list windows in this session.
|
||||
*/
|
||||
if (wflag && !sflag)
|
||||
break;
|
||||
}
|
||||
free(final_win_template_middle);
|
||||
free(final_win_template_last);
|
||||
|
||||
window_choose_ready(wl->window->active, cur_win, NULL);
|
||||
|
||||
if (args_has(args, 'u')) {
|
||||
window_choose_expand_all(wl->window->active);
|
||||
window_choose_set_current(wl->window->active, cur_win);
|
||||
}
|
||||
mode = &window_tree_mode;
|
||||
|
||||
window_pane_set_mode(wp, mode, &item->target, args);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,8 @@
|
||||
static enum cmd_retval cmd_command_prompt_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static int cmd_command_prompt_callback(void *, const char *, int);
|
||||
static int cmd_command_prompt_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
static void cmd_command_prompt_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_command_prompt_entry = {
|
||||
@@ -43,24 +44,21 @@ const struct cmd_entry cmd_command_prompt_entry = {
|
||||
.usage = "[-1Ni] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
|
||||
"[template]",
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_command_prompt_exec
|
||||
};
|
||||
|
||||
struct cmd_command_prompt_cdata {
|
||||
struct client *c;
|
||||
int flags;
|
||||
int flags;
|
||||
|
||||
char *inputs;
|
||||
char *next_input;
|
||||
char *inputs;
|
||||
char *next_input;
|
||||
|
||||
char *prompts;
|
||||
char *next_prompt;
|
||||
char *prompts;
|
||||
char *next_prompt;
|
||||
|
||||
char *template;
|
||||
int idx;
|
||||
char *template;
|
||||
int idx;
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -69,15 +67,17 @@ cmd_command_prompt_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct args *args = self->args;
|
||||
const char *inputs, *prompts;
|
||||
struct cmd_command_prompt_cdata *cdata;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c;
|
||||
char *prompt, *ptr, *input = NULL;
|
||||
size_t n;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (c->prompt_string != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->c = c;
|
||||
|
||||
cdata->inputs = NULL;
|
||||
cdata->next_input = NULL;
|
||||
@@ -141,10 +141,10 @@ cmd_command_prompt_error(struct cmdq_item *item, void *data)
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_command_prompt_callback(void *data, const char *s, int done)
|
||||
cmd_command_prompt_callback(struct client *c, void *data, const char *s,
|
||||
int done)
|
||||
{
|
||||
struct cmd_command_prompt_cdata *cdata = data;
|
||||
struct client *c = cdata->c;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause, *new_template, *prompt, *ptr;
|
||||
@@ -192,7 +192,7 @@ cmd_command_prompt_callback(void *data, const char *s, int done)
|
||||
|
||||
if (!done)
|
||||
free(new_template);
|
||||
if (c->prompt_callbackfn != (void *)&cmd_command_prompt_callback)
|
||||
if (c->prompt_inputcb != cmd_command_prompt_callback)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
static enum cmd_retval cmd_confirm_before_exec(struct cmd *,
|
||||
struct cmdq_item *);
|
||||
|
||||
static int cmd_confirm_before_callback(void *, const char *, int);
|
||||
static int cmd_confirm_before_callback(struct client *, void *,
|
||||
const char *, int);
|
||||
static void cmd_confirm_before_free(void *);
|
||||
|
||||
const struct cmd_entry cmd_confirm_before_entry = {
|
||||
@@ -41,15 +42,12 @@ const struct cmd_entry cmd_confirm_before_entry = {
|
||||
.args = { "p:t:", 1, 1 },
|
||||
.usage = "[-p prompt] " CMD_TARGET_CLIENT_USAGE " command",
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_confirm_before_exec
|
||||
};
|
||||
|
||||
struct cmd_confirm_before_data {
|
||||
char *cmd;
|
||||
struct client *client;
|
||||
char *cmd;
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -57,10 +55,13 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_confirm_before_data *cdata;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c;
|
||||
char *cmd, *copy, *new_prompt, *ptr;
|
||||
const char *prompt;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if ((prompt = args_get(args, 'p')) != NULL)
|
||||
xasprintf(&new_prompt, "%s ", prompt);
|
||||
else {
|
||||
@@ -73,9 +74,6 @@ cmd_confirm_before_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata = xmalloc(sizeof *cdata);
|
||||
cdata->cmd = xstrdup(args->argv[0]);
|
||||
|
||||
cdata->client = c;
|
||||
cdata->client->references++;
|
||||
|
||||
status_prompt_set(c, new_prompt, NULL,
|
||||
cmd_confirm_before_callback, cmd_confirm_before_free, cdata,
|
||||
PROMPT_SINGLE);
|
||||
@@ -96,10 +94,10 @@ cmd_confirm_before_error(struct cmdq_item *item, void *data)
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_confirm_before_callback(void *data, const char *s, __unused int done)
|
||||
cmd_confirm_before_callback(struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct client *c = cdata->client;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
char *cause;
|
||||
@@ -134,9 +132,6 @@ static void
|
||||
cmd_confirm_before_free(void *data)
|
||||
{
|
||||
struct cmd_confirm_before_data *cdata = data;
|
||||
struct client *c = cdata->client;
|
||||
|
||||
server_client_unref(c);
|
||||
|
||||
free(cdata->cmd);
|
||||
free(cdata);
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_copy_mode_entry = {
|
||||
.args = { "Met:u", 0, 0 },
|
||||
.usage = "[-Mu] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_copy_mode_exec
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_clock_mode_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_copy_mode_exec
|
||||
@@ -56,31 +56,34 @@ static enum cmd_retval
|
||||
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct client *c = item->client;
|
||||
struct session *s;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
int flag;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if ((wp = cmd_mouse_pane(&item->mouse, &s, NULL)) == NULL)
|
||||
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (c == NULL || c->session != s)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_clock_mode_entry) {
|
||||
window_pane_set_mode(wp, &window_clock_mode);
|
||||
window_pane_set_mode(wp, &window_clock_mode, NULL, NULL);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (wp->mode != &window_copy_mode) {
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) != 0)
|
||||
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 (args_has(args, 'M')) {
|
||||
if (wp->mode != NULL && wp->mode != &window_copy_mode)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
window_copy_start_drag(c, &item->mouse);
|
||||
window_copy_start_drag(c, &shared->mouse);
|
||||
}
|
||||
if (wp->mode == &window_copy_mode && args_has(self->args, 'u'))
|
||||
window_copy_pageup(wp, 0);
|
||||
|
||||
@@ -37,8 +37,7 @@ const struct cmd_entry cmd_detach_client_entry = {
|
||||
.usage = "[-aP] [-E shell-command] "
|
||||
"[-s target-session] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.sflag = CMD_SESSION,
|
||||
.tflag = CMD_CLIENT,
|
||||
.source = { 's', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_READONLY,
|
||||
.exec = cmd_detach_client_exec
|
||||
@@ -51,8 +50,6 @@ const struct cmd_entry cmd_suspend_client_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_detach_client_exec
|
||||
};
|
||||
@@ -61,15 +58,16 @@ static enum cmd_retval
|
||||
cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c, *cloop;
|
||||
struct client *c, *cloop;
|
||||
struct session *s;
|
||||
enum msgtype msgtype;
|
||||
const char *cmd = args_get(args, 'E');
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (self->entry == &cmd_suspend_client_entry) {
|
||||
tty_stop_tty(&c->tty);
|
||||
c->flags |= CLIENT_SUSPENDED;
|
||||
proc_send(c->peer, MSG_SUSPEND, -1, NULL, 0);
|
||||
server_client_suspend(c);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -79,7 +77,9 @@ cmd_detach_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
msgtype = MSG_DETACH;
|
||||
|
||||
if (args_has(args, 's')) {
|
||||
s = item->state.sflag.s;
|
||||
s = item->source.s;
|
||||
if (s == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
TAILQ_FOREACH(cloop, &clients, entry) {
|
||||
if (cloop->session == s) {
|
||||
if (cmd != NULL)
|
||||
|
||||
@@ -43,8 +43,7 @@ const struct cmd_entry cmd_display_message_entry = {
|
||||
.usage = "[-p] [-c target-client] [-F format] "
|
||||
CMD_TARGET_PANE_USAGE " [message]",
|
||||
|
||||
.cflag = CMD_CLIENT_CANFAIL,
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_message_exec
|
||||
@@ -54,10 +53,10 @@ static enum cmd_retval
|
||||
cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
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;
|
||||
struct format_tree *ft;
|
||||
@@ -73,8 +72,19 @@ cmd_display_message_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (template == NULL)
|
||||
template = DISPLAY_MESSAGE_TEMPLATE;
|
||||
|
||||
ft = format_create(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);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, target_c, s, wl, wp);
|
||||
|
||||
msg = format_expand_time(ft, template, time(NULL));
|
||||
if (args_has(self->args, 'p'))
|
||||
|
||||
@@ -37,10 +37,8 @@ const struct cmd_entry cmd_display_panes_entry = {
|
||||
.name = "display-panes",
|
||||
.alias = "displayp",
|
||||
|
||||
.args = { "t:", 0, 1 },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
.args = { "d:t:", 0, 1 },
|
||||
.usage = "[-d duration] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_display_panes_exec
|
||||
@@ -50,7 +48,14 @@ static enum cmd_retval
|
||||
cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
u_int delay;
|
||||
char *cause;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
s = c->session;
|
||||
|
||||
if (c->identify_callback != NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -60,10 +65,20 @@ cmd_display_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
c->identify_callback_data = xstrdup(args->argv[0]);
|
||||
else
|
||||
c->identify_callback_data = xstrdup("select-pane -t '%%'");
|
||||
c->identify_callback_item = item;
|
||||
|
||||
server_client_set_identify(c);
|
||||
if (args_has(args, 'd')) {
|
||||
delay = args_strtonum(args, 'd', 0, UINT_MAX, &cause);
|
||||
if (cause != NULL) {
|
||||
cmdq_error(item, "delay %s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
} else
|
||||
delay = options_get_number(s->options, "display-panes-time");
|
||||
server_client_set_identify(c, delay);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
@@ -82,34 +97,36 @@ 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;
|
||||
char *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);
|
||||
cmd = cmd_template_replace(c->identify_callback_data, 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 {
|
||||
if (cmdlist == NULL && cause != NULL)
|
||||
new_item = cmdq_get_callback(cmd_display_panes_error, cause);
|
||||
else if (cmdlist == NULL)
|
||||
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);
|
||||
cmdq_insert_after(c->identify_callback_item, new_item);
|
||||
|
||||
free(cmd);
|
||||
free(expanded);
|
||||
|
||||
out:
|
||||
c->identify_callback_item->flags &= ~CMDQ_WAITING;
|
||||
c->identify_callback_item = NULL;
|
||||
|
||||
free(c->identify_callback_data);
|
||||
c->identify_callback_data = NULL;
|
||||
|
||||
c->identify_callback = NULL;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
@@ -28,213 +26,69 @@
|
||||
* Find window containing text.
|
||||
*/
|
||||
|
||||
#define FIND_WINDOW_TEMPLATE \
|
||||
"#{window_index}: #{window_name} " \
|
||||
"[#{window_width}x#{window_height}] " \
|
||||
"(#{window_panes} panes) #{window_find_matches}"
|
||||
|
||||
static enum cmd_retval cmd_find_window_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_find_window_callback(struct window_choose_data *);
|
||||
|
||||
/* Flags for determining matching behavior. */
|
||||
#define CMD_FIND_WINDOW_BY_TITLE 0x1
|
||||
#define CMD_FIND_WINDOW_BY_CONTENT 0x2
|
||||
#define CMD_FIND_WINDOW_BY_NAME 0x4
|
||||
|
||||
#define CMD_FIND_WINDOW_ALL \
|
||||
(CMD_FIND_WINDOW_BY_TITLE | \
|
||||
CMD_FIND_WINDOW_BY_CONTENT | \
|
||||
CMD_FIND_WINDOW_BY_NAME)
|
||||
|
||||
const struct cmd_entry cmd_find_window_entry = {
|
||||
.name = "find-window",
|
||||
.alias = "findw",
|
||||
|
||||
.args = { "F:CNt:T", 1, 4 },
|
||||
.usage = "[-CNT] [-F format] " CMD_TARGET_WINDOW_USAGE " match-string",
|
||||
.args = { "CNt:T", 1, 1 },
|
||||
.usage = "[-CNT] " CMD_TARGET_PANE_USAGE " match-string",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_find_window_exec
|
||||
};
|
||||
|
||||
struct cmd_find_window_data {
|
||||
struct winlink *wl;
|
||||
char *list_ctx;
|
||||
u_int pane_id;
|
||||
TAILQ_ENTRY(cmd_find_window_data) entry;
|
||||
};
|
||||
TAILQ_HEAD(cmd_find_window_list, cmd_find_window_data);
|
||||
|
||||
static u_int cmd_find_window_match_flags(struct args *);
|
||||
static void cmd_find_window_match(struct cmd_find_window_list *, int,
|
||||
struct winlink *, const char *, const char *);
|
||||
|
||||
static u_int
|
||||
cmd_find_window_match_flags(struct args *args)
|
||||
{
|
||||
u_int match_flags = 0;
|
||||
|
||||
/* Turn on flags based on the options. */
|
||||
if (args_has(args, 'T'))
|
||||
match_flags |= CMD_FIND_WINDOW_BY_TITLE;
|
||||
if (args_has(args, 'C'))
|
||||
match_flags |= CMD_FIND_WINDOW_BY_CONTENT;
|
||||
if (args_has(args, 'N'))
|
||||
match_flags |= CMD_FIND_WINDOW_BY_NAME;
|
||||
|
||||
/* If none of the flags were set, default to matching anything. */
|
||||
if (match_flags == 0)
|
||||
match_flags = CMD_FIND_WINDOW_ALL;
|
||||
|
||||
return (match_flags);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_find_window_match(struct cmd_find_window_list *find_list,
|
||||
int match_flags, struct winlink *wl, const char *str,
|
||||
const char *searchstr)
|
||||
{
|
||||
struct cmd_find_window_data *find_data;
|
||||
struct window_pane *wp;
|
||||
u_int i, line;
|
||||
char *sres;
|
||||
|
||||
find_data = xcalloc(1, sizeof *find_data);
|
||||
|
||||
i = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
i++;
|
||||
|
||||
if ((match_flags & CMD_FIND_WINDOW_BY_NAME) &&
|
||||
fnmatch(searchstr, wl->window->name, 0) == 0) {
|
||||
find_data->list_ctx = xstrdup("");
|
||||
break;
|
||||
}
|
||||
|
||||
if ((match_flags & CMD_FIND_WINDOW_BY_TITLE) &&
|
||||
fnmatch(searchstr, wp->base.title, 0) == 0) {
|
||||
xasprintf(&find_data->list_ctx,
|
||||
"pane %u title: \"%s\"", i - 1, wp->base.title);
|
||||
break;
|
||||
}
|
||||
|
||||
if (match_flags & CMD_FIND_WINDOW_BY_CONTENT &&
|
||||
(sres = window_pane_search(wp, str, &line)) != NULL) {
|
||||
xasprintf(&find_data->list_ctx,
|
||||
"pane %u line %u: \"%s\"", i - 1, line + 1, sres);
|
||||
free(sres);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (find_data->list_ctx != NULL) {
|
||||
find_data->wl = wl;
|
||||
find_data->pane_id = i - 1;
|
||||
TAILQ_INSERT_TAIL(find_list, find_data, entry);
|
||||
} else
|
||||
free(find_data);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_find_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct window_choose_data *cdata;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl, *wm;
|
||||
struct cmd_find_window_list find_list;
|
||||
struct cmd_find_window_data *find_data;
|
||||
struct cmd_find_window_data *find_data1;
|
||||
char *str, *searchstr;
|
||||
const char *template;
|
||||
u_int i, match_flags;
|
||||
struct args *args = self->args, *new_args;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *s = args->argv[0];
|
||||
char *filter, *argv = { NULL };
|
||||
int C, N, T;
|
||||
|
||||
if (c == NULL) {
|
||||
cmdq_error(item, "no client available");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
C = args_has(args, 'C');
|
||||
N = args_has(args, 'N');
|
||||
T = args_has(args, 'T');
|
||||
|
||||
if ((template = args_get(args, 'F')) == NULL)
|
||||
template = FIND_WINDOW_TEMPLATE;
|
||||
if (!C && !N && !T)
|
||||
C = N = T = 1;
|
||||
|
||||
match_flags = cmd_find_window_match_flags(args);
|
||||
str = args->argv[0];
|
||||
if (C && N && T) {
|
||||
xasprintf(&filter,
|
||||
"#{||:"
|
||||
"#{C:%s},#{||:#{m:*%s*,#{window_name}},"
|
||||
"#{m:*%s*,#{pane_title}}}}",
|
||||
s, s, s);
|
||||
} else if (C && N) {
|
||||
xasprintf(&filter,
|
||||
"#{||:#{C:%s},#{m:*%s*,#{window_name}}}",
|
||||
s, s);
|
||||
} else if (C && T) {
|
||||
xasprintf(&filter,
|
||||
"#{||:#{C:%s},#{m:*%s*,#{pane_title}}}",
|
||||
s, s);
|
||||
} else if (N && T) {
|
||||
xasprintf(&filter,
|
||||
"#{||:#{m:*%s*,#{window_name}},#{m:*%s*,#{pane_title}}}",
|
||||
s, s);
|
||||
} else if (C)
|
||||
xasprintf(&filter, "#{C:%s}", s);
|
||||
else if (N)
|
||||
xasprintf(&filter, "#{m:*%s*,#{window_name}}", s);
|
||||
else
|
||||
xasprintf(&filter, "#{m:*%s*,#{pane_title}}", s);
|
||||
|
||||
TAILQ_INIT(&find_list);
|
||||
new_args = args_parse("", 1, &argv);
|
||||
args_set(new_args, 'f', filter);
|
||||
|
||||
xasprintf(&searchstr, "*%s*", str);
|
||||
RB_FOREACH(wm, winlinks, &s->windows)
|
||||
cmd_find_window_match(&find_list, match_flags, wm, str, searchstr);
|
||||
free(searchstr);
|
||||
window_pane_set_mode(wp, &window_tree_mode, &item->target, new_args);
|
||||
|
||||
if (TAILQ_EMPTY(&find_list)) {
|
||||
cmdq_error(item, "no windows matching: %s", str);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
args_free(new_args);
|
||||
free(filter);
|
||||
|
||||
if (TAILQ_NEXT(TAILQ_FIRST(&find_list), entry) == NULL) {
|
||||
if (session_select(s, TAILQ_FIRST(&find_list)->wl->idx) == 0)
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wl->window->active, &window_choose_mode) != 0)
|
||||
goto out;
|
||||
|
||||
i = 0;
|
||||
TAILQ_FOREACH(find_data, &find_list, entry) {
|
||||
cdata = window_choose_data_create(TREE_OTHER, c, c->session);
|
||||
cdata->idx = find_data->wl->idx;
|
||||
cdata->wl = find_data->wl;
|
||||
|
||||
cdata->ft_template = xstrdup(template);
|
||||
cdata->pane_id = find_data->pane_id;
|
||||
|
||||
format_add(cdata->ft, "line", "%u", i);
|
||||
format_add(cdata->ft, "window_find_matches", "%s",
|
||||
find_data->list_ctx);
|
||||
format_defaults(cdata->ft, NULL, s, find_data->wl, NULL);
|
||||
|
||||
window_choose_add(wl->window->active, cdata);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
window_choose_ready(wl->window->active, 0, cmd_find_window_callback);
|
||||
|
||||
out:
|
||||
TAILQ_FOREACH_SAFE(find_data, &find_list, entry, find_data1) {
|
||||
free(find_data->list_ctx);
|
||||
TAILQ_REMOVE(&find_list, find_data, entry);
|
||||
free(find_data);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_find_window_callback(struct window_choose_data *cdata)
|
||||
{
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
|
||||
if (cdata == NULL)
|
||||
return;
|
||||
|
||||
s = cdata->start_session;
|
||||
if (!session_alive(s))
|
||||
return;
|
||||
|
||||
wp = window_pane_at_index(cdata->wl->window, cdata->pane_id);
|
||||
if (wp != NULL && window_pane_visible(wp))
|
||||
window_set_active_pane(cdata->wl->window, wp);
|
||||
|
||||
if (session_select(s, cdata->idx) == 0) {
|
||||
server_redraw_session(s);
|
||||
recalculate_sizes();
|
||||
}
|
||||
}
|
||||
|
||||
548
cmd-find.c
548
cmd-find.c
@@ -26,21 +26,15 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
static struct session *cmd_find_try_TMUX(struct client *, struct window *);
|
||||
static int cmd_find_client_better(struct client *, struct client *);
|
||||
static struct client *cmd_find_best_client(struct client **, u_int);
|
||||
static int cmd_find_session_better(struct session *, struct session *,
|
||||
int);
|
||||
static struct session *cmd_find_best_session(struct session **, u_int, int);
|
||||
static int cmd_find_best_session_with_window(struct cmd_find_state *);
|
||||
static int cmd_find_best_winlink_with_window(struct cmd_find_state *);
|
||||
|
||||
static int cmd_find_current_session_with_client(struct cmd_find_state *);
|
||||
static int cmd_find_current_session(struct cmd_find_state *);
|
||||
static struct client *cmd_find_current_client(struct cmdq_item *);
|
||||
|
||||
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 *,
|
||||
@@ -83,7 +77,7 @@ static const char *cmd_find_pane_table[][2] = {
|
||||
|
||||
/* Get session from TMUX if present. */
|
||||
static struct session *
|
||||
cmd_find_try_TMUX(struct client *c, struct window *w)
|
||||
cmd_find_try_TMUX(struct client *c)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
char tmp[256];
|
||||
@@ -99,15 +93,33 @@ cmd_find_try_TMUX(struct client *c, struct window *w)
|
||||
return (NULL);
|
||||
if (pid != getpid())
|
||||
return (NULL);
|
||||
log_debug("client %p TMUX is %s (session @%u)", c, envent->value,
|
||||
session);
|
||||
log_debug("%s: client %p TMUX %s (session $%u)", __func__, c,
|
||||
envent->value, session);
|
||||
|
||||
s = session_find_by_id(session);
|
||||
if (s == NULL || (w != NULL && !session_has(s, w)))
|
||||
return (NULL);
|
||||
if (s != NULL)
|
||||
log_debug("%s: session $%u still exists", __func__, s->id);
|
||||
return (s);
|
||||
}
|
||||
|
||||
/* Find pane containing client if any. */
|
||||
static struct window_pane *
|
||||
cmd_find_inside_pane(struct client *c)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
|
||||
if (c == NULL)
|
||||
return (NULL);
|
||||
|
||||
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
||||
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);
|
||||
}
|
||||
|
||||
/* Is this client better? */
|
||||
static int
|
||||
cmd_find_client_better(struct client *c, struct client *than)
|
||||
@@ -117,28 +129,23 @@ cmd_find_client_better(struct client *c, struct client *than)
|
||||
return (timercmp(&c->activity_time, &than->activity_time, >));
|
||||
}
|
||||
|
||||
/* Find best client from a list, or all if list is NULL. */
|
||||
static struct client *
|
||||
cmd_find_best_client(struct client **clist, u_int csize)
|
||||
/* Find best client for session. */
|
||||
struct client *
|
||||
cmd_find_best_client(struct session *s)
|
||||
{
|
||||
struct client *c_loop, *c;
|
||||
u_int i;
|
||||
|
||||
if (s->flags & SESSION_UNATTACHED)
|
||||
s = NULL;
|
||||
|
||||
c = NULL;
|
||||
if (clist != NULL) {
|
||||
for (i = 0; i < csize; i++) {
|
||||
if (clist[i]->session == NULL)
|
||||
continue;
|
||||
if (cmd_find_client_better(clist[i], c))
|
||||
c = clist[i];
|
||||
}
|
||||
} else {
|
||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||
if (c_loop->session == NULL)
|
||||
continue;
|
||||
if (cmd_find_client_better(c_loop, c))
|
||||
c = c_loop;
|
||||
}
|
||||
TAILQ_FOREACH(c_loop, &clients, entry) {
|
||||
if (c_loop->session == NULL)
|
||||
continue;
|
||||
if (s != NULL && c_loop->session != s)
|
||||
continue;
|
||||
if (cmd_find_client_better(c_loop, c))
|
||||
c = c_loop;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
@@ -168,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++) {
|
||||
@@ -191,11 +200,7 @@ cmd_find_best_session_with_window(struct cmd_find_state *fs)
|
||||
u_int ssize;
|
||||
struct session *s;
|
||||
|
||||
if (fs->item != NULL && fs->item->client != NULL) {
|
||||
fs->s = cmd_find_try_TMUX(fs->item->client, fs->w);
|
||||
if (fs->s != NULL)
|
||||
return (cmd_find_best_winlink_with_window(fs));
|
||||
}
|
||||
log_debug("%s: window is @%u", __func__, fs->w->id);
|
||||
|
||||
ssize = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
@@ -218,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
|
||||
@@ -226,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;
|
||||
@@ -244,146 +251,6 @@ cmd_find_best_winlink_with_window(struct cmd_find_state *fs)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find current session when we have an unattached client. */
|
||||
static int
|
||||
cmd_find_current_session_with_client(struct cmd_find_state *fs)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
|
||||
/*
|
||||
* If this is running in a pane, we can use that to limit the list of
|
||||
* sessions to those containing that pane (we still use the current
|
||||
* window in the best session).
|
||||
*/
|
||||
if (fs->item != NULL) {
|
||||
RB_FOREACH(wp, window_pane_tree, &all_window_panes) {
|
||||
if (strcmp(wp->tty, fs->item->client->ttyname) == 0)
|
||||
break;
|
||||
}
|
||||
} else
|
||||
wp = NULL;
|
||||
|
||||
/* Not running in a pane. We know nothing. Find the best session. */
|
||||
if (wp == NULL)
|
||||
goto unknown_pane;
|
||||
|
||||
/* Find the best session and winlink containing this pane. */
|
||||
fs->w = wp->window;
|
||||
if (cmd_find_best_session_with_window(fs) != 0) {
|
||||
if (wp != NULL) {
|
||||
/*
|
||||
* The window may have been destroyed but the pane
|
||||
* still on all_window_panes due to something else
|
||||
* holding a reference.
|
||||
*/
|
||||
goto unknown_pane;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Use the current window and pane from this session. */
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
return (0);
|
||||
|
||||
unknown_pane:
|
||||
fs->s = NULL;
|
||||
if (fs->item != NULL)
|
||||
fs->s = cmd_find_try_TMUX(fs->item->client, NULL);
|
||||
if (fs->s == NULL)
|
||||
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
|
||||
if (fs->s == NULL)
|
||||
return (-1);
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Work out the best current state. If this function succeeds, the state is
|
||||
* guaranteed to be completely filled in.
|
||||
*/
|
||||
static int
|
||||
cmd_find_current_session(struct cmd_find_state *fs)
|
||||
{
|
||||
/* If we know the current client, use it. */
|
||||
if (fs->item != NULL && fs->item->client != NULL) {
|
||||
log_debug("%s: have client %p%s", __func__, fs->item->client,
|
||||
fs->item->client->session == NULL ? "" : " (with session)");
|
||||
if (fs->item->client->session == NULL)
|
||||
return (cmd_find_current_session_with_client(fs));
|
||||
fs->s = fs->item->client->session;
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* We know nothing, find the best session and client. */
|
||||
fs->s = cmd_find_best_session(NULL, 0, fs->flags);
|
||||
if (fs->s == NULL)
|
||||
return (-1);
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Work out the best current client. */
|
||||
static struct client *
|
||||
cmd_find_current_client(struct cmdq_item *item)
|
||||
{
|
||||
struct cmd_find_state current;
|
||||
struct session *s;
|
||||
struct client *c, **clist = NULL;
|
||||
u_int csize;
|
||||
|
||||
/* If the queue client has a session, use it. */
|
||||
if (item->client != NULL && item->client->session != NULL) {
|
||||
log_debug("%s: using item %p client %p", __func__, item,
|
||||
item->client);
|
||||
return (item->client);
|
||||
}
|
||||
|
||||
/* Otherwise find the current session. */
|
||||
cmd_find_clear_state(¤t, item, 0);
|
||||
if (cmd_find_current_session(¤t) != 0)
|
||||
return (NULL);
|
||||
|
||||
/* If it is attached, find the best of it's clients. */
|
||||
s = current.s;
|
||||
log_debug("%s: current session $%u %s", __func__, s->id, s->name);
|
||||
if (~s->flags & SESSION_UNATTACHED) {
|
||||
csize = 0;
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != s)
|
||||
continue;
|
||||
clist = xreallocarray(clist, csize + 1, sizeof *clist);
|
||||
clist[csize++] = c;
|
||||
}
|
||||
if (csize != 0) {
|
||||
c = cmd_find_best_client(clist, csize);
|
||||
if (c != NULL) {
|
||||
free(clist);
|
||||
return (c);
|
||||
}
|
||||
}
|
||||
free(clist);
|
||||
}
|
||||
|
||||
/* Otherwise pick best of all clients. */
|
||||
return (cmd_find_best_client(NULL, 0));
|
||||
}
|
||||
|
||||
/* Maps string in table. */
|
||||
static const char *
|
||||
cmd_find_map_table(const char *table[][2], const char *s)
|
||||
@@ -537,7 +404,7 @@ cmd_find_get_window_with_session(struct cmd_find_state *fs, const char *window)
|
||||
return (-1);
|
||||
fs->idx = s->curw->idx + n;
|
||||
} else {
|
||||
if (n < s->curw->idx)
|
||||
if (n > s->curw->idx)
|
||||
return (-1);
|
||||
fs->idx = s->curw->idx - n;
|
||||
}
|
||||
@@ -584,15 +451,15 @@ 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->w = fs->wl->window;
|
||||
return (0);
|
||||
}
|
||||
if (fs->flags & CMD_FIND_WINDOW_INDEX) {
|
||||
fs->idx = idx;
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,7 +524,7 @@ cmd_find_get_pane(struct cmd_find_state *fs, const char *pane, int only)
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
fs->w = fs->wp->window;
|
||||
return (cmd_find_best_session_with_window(fs));
|
||||
@@ -694,7 +561,7 @@ cmd_find_get_pane_with_session(struct cmd_find_state *fs, const char *pane)
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
fs->w = fs->wp->window;
|
||||
return (cmd_find_best_winlink_with_window(fs));
|
||||
@@ -726,7 +593,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
/* Check for pane ids starting with %. */
|
||||
if (*pane == '%') {
|
||||
fs->wp = window_pane_find_by_id_str(pane);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
if (fs->wp->window != fs->w)
|
||||
return (-1);
|
||||
@@ -735,30 +602,28 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
|
||||
/* Try special characters. */
|
||||
if (strcmp(pane, "!") == 0) {
|
||||
if (fs->w->last == NULL)
|
||||
return (-1);
|
||||
fs->wp = fs->w->last;
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{up-of}") == 0) {
|
||||
fs->wp = window_pane_find_up(fs->w->active);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{down-of}") == 0) {
|
||||
fs->wp = window_pane_find_down(fs->w->active);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{left-of}") == 0) {
|
||||
fs->wp = window_pane_find_left(fs->w->active);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
} else if (strcmp(pane, "{right-of}") == 0) {
|
||||
fs->wp = window_pane_find_right(fs->w->active);
|
||||
if (fs->wp == NULL || window_pane_outside(fs->wp))
|
||||
if (fs->wp == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
@@ -774,7 +639,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
fs->wp = window_pane_next_by_number(fs->w, wp, n);
|
||||
else
|
||||
fs->wp = window_pane_previous_by_number(fs->w, wp, n);
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
if (fs->wp != NULL)
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -782,13 +647,13 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
idx = strtonum(pane, 0, INT_MAX, &errstr);
|
||||
if (errstr == NULL) {
|
||||
fs->wp = window_pane_at_index(fs->w, idx);
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
if (fs->wp != NULL)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Try as a description. */
|
||||
fs->wp = window_find_string(fs->w, pane);
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
if (fs->wp != NULL)
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
@@ -796,18 +661,16 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)
|
||||
|
||||
/* Clear state. */
|
||||
void
|
||||
cmd_find_clear_state(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
int flags)
|
||||
cmd_find_clear_state(struct cmd_find_state *fs, int flags)
|
||||
{
|
||||
memset(fs, 0, sizeof *fs);
|
||||
|
||||
fs->item = item;
|
||||
fs->flags = flags;
|
||||
|
||||
fs->idx = -1;
|
||||
}
|
||||
|
||||
/* Check if state is empty/ */
|
||||
/* Check if state is empty. */
|
||||
int
|
||||
cmd_find_empty_state(struct cmd_find_state *fs)
|
||||
{
|
||||
@@ -838,9 +701,7 @@ cmd_find_valid_state(struct cmd_find_state *fs)
|
||||
if (fs->w != fs->wl->window)
|
||||
return (0);
|
||||
|
||||
if (!window_has_pane(fs->w, fs->wp))
|
||||
return (0);
|
||||
return (!window_pane_outside(fs->wp));
|
||||
return (window_has_pane(fs->w, fs->wp));
|
||||
}
|
||||
|
||||
/* Copy a state. */
|
||||
@@ -855,11 +716,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) {
|
||||
@@ -878,10 +739,10 @@ cmd_find_log_state(const char *prefix, struct cmd_find_state *fs)
|
||||
}
|
||||
|
||||
/* Find state from a session. */
|
||||
int
|
||||
cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
|
||||
void
|
||||
cmd_find_from_session(struct cmd_find_state *fs, struct session *s, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->s = s;
|
||||
fs->wl = fs->s->curw;
|
||||
@@ -889,36 +750,35 @@ cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from a winlink. */
|
||||
int
|
||||
cmd_find_from_winlink(struct cmd_find_state *fs, struct session *s,
|
||||
struct winlink *wl)
|
||||
void
|
||||
cmd_find_from_winlink(struct cmd_find_state *fs, struct winlink *wl, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->s = s;
|
||||
fs->s = wl->session;
|
||||
fs->wl = wl;
|
||||
fs->w = wl->window;
|
||||
fs->wp = wl->window->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from a session and window. */
|
||||
int
|
||||
cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s,
|
||||
struct window *w)
|
||||
struct window *w, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->s = s;
|
||||
fs->w = w;
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0)
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0) {
|
||||
cmd_find_clear_state(fs, flags);
|
||||
return (-1);
|
||||
}
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
@@ -927,28 +787,46 @@ cmd_find_from_session_window(struct cmd_find_state *fs, struct session *s,
|
||||
|
||||
/* Find state from a window. */
|
||||
int
|
||||
cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
|
||||
cmd_find_from_window(struct cmd_find_state *fs, struct window *w, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->w = w;
|
||||
if (cmd_find_best_session_with_window(fs) != 0)
|
||||
if (cmd_find_best_session_with_window(fs) != 0) {
|
||||
cmd_find_clear_state(fs, flags);
|
||||
return (-1);
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0)
|
||||
}
|
||||
if (cmd_find_best_winlink_with_window(fs) != 0) {
|
||||
cmd_find_clear_state(fs, flags);
|
||||
return (-1);
|
||||
}
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from a winlink and pane. */
|
||||
void
|
||||
cmd_find_from_winlink_pane(struct cmd_find_state *fs, struct winlink *wl,
|
||||
struct window_pane *wp, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->s = wl->session;
|
||||
fs->wl = wl;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = wp;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
}
|
||||
|
||||
/* Find state from a pane. */
|
||||
int
|
||||
cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
|
||||
cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp, int flags)
|
||||
{
|
||||
if (cmd_find_from_window(fs, wp->window) != 0)
|
||||
return (-1);
|
||||
if (window_pane_outside(wp))
|
||||
if (cmd_find_from_window(fs, wp->window, flags) != 0)
|
||||
return (-1);
|
||||
fs->wp = wp;
|
||||
|
||||
@@ -956,56 +834,184 @@ cmd_find_from_pane(struct cmd_find_state *fs, struct window_pane *wp)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find current state. */
|
||||
/* Find state from nothing. */
|
||||
int
|
||||
cmd_find_current(struct cmd_find_state *fs, struct cmdq_item *item, int flags)
|
||||
cmd_find_from_nothing(struct cmd_find_state *fs, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, item, flags);
|
||||
if (cmd_find_current_session(fs) != 0) {
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(item, "no current session");
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
fs->s = cmd_find_best_session(NULL, 0, flags);
|
||||
if (fs->s == NULL) {
|
||||
cmd_find_clear_state(fs, flags);
|
||||
return (-1);
|
||||
}
|
||||
fs->wl = fs->s->curw;
|
||||
fs->idx = fs->wl->idx;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from mouse. */
|
||||
int
|
||||
cmd_find_from_mouse(struct cmd_find_state *fs, struct mouse_event *m, int flags)
|
||||
{
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
if (!m->valid)
|
||||
return (-1);
|
||||
|
||||
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
|
||||
if (fs->wp == NULL) {
|
||||
cmd_find_clear_state(fs, flags);
|
||||
return (-1);
|
||||
}
|
||||
fs->w = fs->wl->window;
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Find state from client. */
|
||||
int
|
||||
cmd_find_from_client(struct cmd_find_state *fs, struct client *c, int flags)
|
||||
{
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
|
||||
/* If no client, treat as from nothing. */
|
||||
if (c == NULL)
|
||||
return (cmd_find_from_nothing(fs, flags));
|
||||
|
||||
/* If this is an attached client, all done. */
|
||||
if (c->session != NULL) {
|
||||
cmd_find_from_session(fs, c->session, flags);
|
||||
return (0);
|
||||
}
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
/*
|
||||
* If this is an unattached client running in a pane, we can use that
|
||||
* to limit the list of sessions to those containing that pane.
|
||||
*/
|
||||
wp = cmd_find_inside_pane(c);
|
||||
if (wp == NULL)
|
||||
goto unknown_pane;
|
||||
|
||||
/* If we have a session in TMUX, see if it has this pane. */
|
||||
s = cmd_find_try_TMUX(c);
|
||||
if (s != NULL) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
if (window_has_pane(wl->window, wp))
|
||||
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;
|
||||
fs->wp = fs->w->active; /* use active pane */
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
} else {
|
||||
log_debug("%s: session $%u does not have pane %%%u",
|
||||
__func__, s->id, wp->id);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't have a session, or it doesn't have this pane. Try all
|
||||
* sessions.
|
||||
*/
|
||||
fs->w = wp->window;
|
||||
if (cmd_find_best_session_with_window(fs) != 0) {
|
||||
/*
|
||||
* The window may have been destroyed but the pane
|
||||
* still on all_window_panes due to something else
|
||||
* holding a reference.
|
||||
*/
|
||||
goto unknown_pane;
|
||||
}
|
||||
fs->wl = fs->s->curw;
|
||||
fs->w = fs->wl->window;
|
||||
fs->wp = fs->w->active; /* use active pane */
|
||||
|
||||
cmd_find_log_state(__func__, fs);
|
||||
return (0);
|
||||
|
||||
unknown_pane:
|
||||
/*
|
||||
* We're not running in a known pane, but maybe this client has TMUX
|
||||
* in the environment. That'd give us a session.
|
||||
*/
|
||||
s = cmd_find_try_TMUX(c);
|
||||
if (s != NULL) {
|
||||
cmd_find_from_session(fs, s, flags);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Otherwise we need to guess. */
|
||||
return (cmd_find_from_nothing(fs, flags));
|
||||
}
|
||||
|
||||
/*
|
||||
* Split target into pieces and resolve for the given type. Fills in the given
|
||||
* state. Returns 0 on success or -1 on error.
|
||||
*/
|
||||
int
|
||||
cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
struct cmdq_item *item, const char *target, enum cmd_find_type type,
|
||||
int flags)
|
||||
cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
|
||||
const char *target, enum cmd_find_type type, int flags)
|
||||
{
|
||||
struct mouse_event *m;
|
||||
struct cmd_find_state current;
|
||||
char *colon, *period, *copy = NULL;
|
||||
const char *session, *window, *pane;
|
||||
const char *session, *window, *pane, *s;
|
||||
int window_only = 0, pane_only = 0;
|
||||
|
||||
/* Can fail flag implies quiet. */
|
||||
if (flags & CMD_FIND_CANFAIL)
|
||||
flags |= CMD_FIND_QUIET;
|
||||
|
||||
/* Log the arguments. */
|
||||
if (target == NULL)
|
||||
log_debug("%s: target none, type %d", __func__, type);
|
||||
if (type == CMD_FIND_PANE)
|
||||
s = "pane";
|
||||
else if (type == CMD_FIND_WINDOW)
|
||||
s = "window";
|
||||
else if (type == CMD_FIND_SESSION)
|
||||
s = "session";
|
||||
else
|
||||
log_debug("%s: target %s, type %d", __func__, target, type);
|
||||
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);
|
||||
|
||||
/* Clear new state. */
|
||||
cmd_find_clear_state(fs, item, flags);
|
||||
cmd_find_clear_state(fs, flags);
|
||||
|
||||
/* Find current state. */
|
||||
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
|
||||
fs->current = &marked_pane;
|
||||
log_debug("%s: current is marked pane", __func__);
|
||||
} else if (cmd_find_valid_state(&item->current)) {
|
||||
fs->current = &item->current;
|
||||
} else if (cmd_find_valid_state(&item->shared->current)) {
|
||||
fs->current = &item->shared->current;
|
||||
log_debug("%s: current is from queue", __func__);
|
||||
} else if (cmd_find_from_client(¤t, item->client, flags) == 0) {
|
||||
fs->current = ¤t;
|
||||
log_debug("%s: current is from client", __func__);
|
||||
} else {
|
||||
fs->current = current;
|
||||
log_debug("%s: current is from argument", __func__);
|
||||
if (~flags & CMD_FIND_QUIET)
|
||||
cmdq_error(item, "no current target");
|
||||
goto error;
|
||||
}
|
||||
if (!cmd_find_empty_state(fs->current) &&
|
||||
!cmd_find_valid_state(fs->current))
|
||||
if (!cmd_find_valid_state(fs->current))
|
||||
fatalx("invalid current find state");
|
||||
|
||||
/* An empty or NULL target is the current. */
|
||||
@@ -1014,11 +1020,11 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
|
||||
/* Mouse target is a plain = or {mouse}. */
|
||||
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
|
||||
m = &item->mouse;
|
||||
m = &item->shared->mouse;
|
||||
switch (type) {
|
||||
case CMD_FIND_PANE:
|
||||
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);
|
||||
if (fs->wp != NULL && !window_pane_outside(fs->wp))
|
||||
if (fs->wp != NULL)
|
||||
fs->w = fs->wl->window;
|
||||
break;
|
||||
case CMD_FIND_WINDOW:
|
||||
@@ -1125,8 +1131,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
if (pane != NULL)
|
||||
pane = cmd_find_map_table(cmd_find_pane_table, pane);
|
||||
|
||||
log_debug("target %s (flags %#x): session=%s, window=%s, pane=%s",
|
||||
target, flags, session == NULL ? "none" : session,
|
||||
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);
|
||||
|
||||
/* No pane is allowed if want an index. */
|
||||
@@ -1156,7 +1162,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -1196,7 +1203,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmd_find_state *current,
|
||||
/* 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;
|
||||
}
|
||||
|
||||
@@ -1220,6 +1228,8 @@ error:
|
||||
log_debug("%s: error", __func__);
|
||||
|
||||
free(copy);
|
||||
if (flags & CMD_FIND_CANFAIL)
|
||||
return (0);
|
||||
return (-1);
|
||||
|
||||
found:
|
||||
@@ -1245,6 +1255,35 @@ no_pane:
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Find the current client. */
|
||||
static struct client *
|
||||
cmd_find_current_client(struct cmdq_item *item, int quiet)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (item->client != NULL && item->client->session != NULL)
|
||||
return (item->client);
|
||||
|
||||
c = NULL;
|
||||
if ((wp = cmd_find_inside_pane(item->client)) != NULL) {
|
||||
cmd_find_clear_state(&fs, CMD_FIND_QUIET);
|
||||
fs.w = wp->window;
|
||||
if (cmd_find_best_session_with_window(&fs) == 0)
|
||||
c = cmd_find_best_client(fs.s);
|
||||
} else {
|
||||
s = cmd_find_best_session(NULL, 0, CMD_FIND_QUIET);
|
||||
if (s != NULL)
|
||||
c = cmd_find_best_client(s);
|
||||
}
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(item, "no current client");
|
||||
log_debug("%s: no target, return %p", __func__, c);
|
||||
return (c);
|
||||
}
|
||||
|
||||
/* Find the target client or report an error and return NULL. */
|
||||
struct client *
|
||||
cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
|
||||
@@ -1254,13 +1293,8 @@ cmd_find_client(struct cmdq_item *item, const char *target, int quiet)
|
||||
size_t size;
|
||||
|
||||
/* A NULL argument means the current client. */
|
||||
if (item != NULL && target == NULL) {
|
||||
c = cmd_find_current_client(item);
|
||||
if (c == NULL && !quiet)
|
||||
cmdq_error(item, "no current client");
|
||||
log_debug("%s: no target, return %p", __func__, c);
|
||||
return (c);
|
||||
}
|
||||
if (target == NULL)
|
||||
return (cmd_find_current_client(item, quiet));
|
||||
copy = xstrdup(target);
|
||||
|
||||
/* Trim a single trailing colon if any. */
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
|
||||
static enum cmd_retval cmd_if_shell_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static enum cmd_retval cmd_if_shell_error(struct cmdq_item *, void *);
|
||||
static void cmd_if_shell_callback(struct job *);
|
||||
static void cmd_if_shell_free(void *);
|
||||
|
||||
@@ -43,7 +42,7 @@ const struct cmd_entry cmd_if_shell_entry = {
|
||||
.usage = "[-bF] " CMD_TARGET_PANE_USAGE " shell-command command "
|
||||
"[command]",
|
||||
|
||||
.tflag = CMD_PANE_CANFAIL,
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_if_shell_exec
|
||||
@@ -65,22 +64,15 @@ 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 cmd_if_shell_data *cdata;
|
||||
char *shellcmd, *cmd, *cause;
|
||||
struct cmd_list *cmdlist;
|
||||
struct cmdq_item *new_item;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.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 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;
|
||||
|
||||
shellcmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
if (args_has(args, 'F')) {
|
||||
@@ -100,7 +92,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &item->mouse, 0);
|
||||
new_item = cmdq_get_command(cmdlist, NULL, &shared->mouse, 0);
|
||||
cmdq_insert_after(item, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -119,16 +111,17 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cdata->cmd_else = NULL;
|
||||
|
||||
cdata->client = item->client;
|
||||
cdata->client->references++;
|
||||
if (cdata->client != NULL)
|
||||
cdata->client->references++;
|
||||
|
||||
if (!args_has(args, 'b'))
|
||||
cdata->item = item;
|
||||
else
|
||||
cdata->item = NULL;
|
||||
memcpy(&cdata->mouse, &item->mouse, sizeof cdata->mouse);
|
||||
memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse);
|
||||
|
||||
job_run(shellcmd, s, cwd, cmd_if_shell_callback, cmd_if_shell_free,
|
||||
cdata);
|
||||
job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||
cmd_if_shell_callback, cmd_if_shell_free, cdata, 0);
|
||||
free(shellcmd);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
@@ -136,17 +129,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_WAIT);
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_if_shell_error(struct cmdq_item *item, void *data)
|
||||
{
|
||||
char *error = data;
|
||||
|
||||
cmdq_error(item, "%s", error);
|
||||
free(error);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_if_shell_callback(struct job *job)
|
||||
{
|
||||
@@ -166,10 +148,10 @@ cmd_if_shell_callback(struct job *job)
|
||||
|
||||
cmdlist = cmd_string_parse(cmd, file, line, &cause);
|
||||
if (cmdlist == NULL) {
|
||||
if (cause != NULL)
|
||||
new_item = cmdq_get_callback(cmd_if_shell_error, cause);
|
||||
else
|
||||
new_item = 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);
|
||||
@@ -192,7 +174,8 @@ cmd_if_shell_free(void *data)
|
||||
{
|
||||
struct cmd_if_shell_data *cdata = data;
|
||||
|
||||
server_client_unref(cdata->client);
|
||||
if (cdata->client != NULL)
|
||||
server_client_unref(cdata->client);
|
||||
|
||||
free(cdata->cmd_else);
|
||||
free(cdata->cmd_if);
|
||||
|
||||
@@ -37,8 +37,8 @@ const struct cmd_entry cmd_join_pane_entry = {
|
||||
.args = { "bdhvp:l:s:t:", 0, 0 },
|
||||
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.sflag = CMD_PANE_MARKED,
|
||||
.tflag = CMD_PANE,
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_join_pane_exec
|
||||
@@ -51,8 +51,8 @@ const struct cmd_entry cmd_move_pane_entry = {
|
||||
.args = { "bdhvp:l:s:t:", 0, 0 },
|
||||
.usage = "[-bdhv] [-p percentage|-l size] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.sflag = CMD_PANE,
|
||||
.tflag = CMD_PANE,
|
||||
.source = { 's', CMD_FIND_PANE, 0 },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_join_pane_exec
|
||||
@@ -62,6 +62,7 @@ static enum cmd_retval
|
||||
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct session *dst_s;
|
||||
struct winlink *src_wl, *dst_wl;
|
||||
struct window *src_w, *dst_w;
|
||||
@@ -77,15 +78,15 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
not_same_window = 0;
|
||||
|
||||
dst_s = item->state.tflag.s;
|
||||
dst_wl = item->state.tflag.wl;
|
||||
dst_wp = item->state.tflag.wp;
|
||||
dst_s = item->target.s;
|
||||
dst_wl = item->target.wl;
|
||||
dst_wp = item->target.wp;
|
||||
dst_w = dst_wl->window;
|
||||
dst_idx = dst_wl->idx;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
src_wl = item->state.sflag.wl;
|
||||
src_wp = item->state.sflag.wp;
|
||||
src_wl = item->source.wl;
|
||||
src_wp = item->source.wp;
|
||||
src_w = src_wl->window;
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
@@ -145,6 +146,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!args_has(args, 'd')) {
|
||||
window_set_active_pane(dst_w, src_wp);
|
||||
session_select(dst_s, dst_idx);
|
||||
cmd_find_from_session(current, dst_s, 0);
|
||||
server_redraw_session(dst_s);
|
||||
} else
|
||||
server_status_session(dst_s);
|
||||
|
||||
@@ -35,7 +35,7 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
.args = { "at:", 0, 0 },
|
||||
.usage = "[-a] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_pane_exec
|
||||
@@ -44,12 +44,11 @@ const struct cmd_entry cmd_kill_pane_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = item->state.tflag.wp;
|
||||
|
||||
server_unzoom_window(wl->window);
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window_pane *loopwp, *tmpwp, *wp = item->target.wp;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_kill_session_entry = {
|
||||
.args = { "aCt:", 0, 0 },
|
||||
.usage = "[-aC] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_session_exec
|
||||
@@ -49,7 +49,7 @@ cmd_kill_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct session *s, *sloop, *stmp;
|
||||
struct winlink *wl;
|
||||
|
||||
s = item->state.tflag.s;
|
||||
s = item->target.s;
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
@@ -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);
|
||||
session_destroy(sloop, __func__);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
server_destroy_session(s);
|
||||
session_destroy(s);
|
||||
session_destroy(s, __func__);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ const struct cmd_entry cmd_kill_window_entry = {
|
||||
.args = { "at:", 0, 0 },
|
||||
.usage = "[-a] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_window_exec
|
||||
@@ -46,7 +46,7 @@ const struct cmd_entry cmd_unlink_window_entry = {
|
||||
.args = { "kt:", 0, 0 },
|
||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_kill_window_exec
|
||||
@@ -56,9 +56,9 @@ static enum cmd_retval
|
||||
cmd_kill_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->state.tflag.wl, *wl2, *wl3;
|
||||
struct winlink *wl = item->target.wl, *wl2, *wl3;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct session *s = item->target.s;
|
||||
|
||||
if (self->entry == &cmd_unlink_window_entry) {
|
||||
if (!args_has(self->args, 'k') && !session_is_linked(s, w)) {
|
||||
|
||||
@@ -57,7 +57,7 @@ cmd_list_buffers_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
pb = NULL;
|
||||
while ((pb = paste_walk(pb)) != NULL) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_defaults_paste_buffer(ft, pb);
|
||||
|
||||
line = format_expand(ft, template);
|
||||
|
||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_list_clients_entry = {
|
||||
.args = { "F:t:", 0, 0 },
|
||||
.usage = "[-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_READONLY|CMD_AFTERHOOK,
|
||||
.exec = cmd_list_clients_exec
|
||||
@@ -60,7 +60,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
char *line;
|
||||
|
||||
if (args_has(args, 't'))
|
||||
s = item->state.tflag.s;
|
||||
s = item->target.s;
|
||||
else
|
||||
s = NULL;
|
||||
|
||||
@@ -72,7 +72,7 @@ cmd_list_clients_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (c->session == NULL || (s != NULL && s != c->session))
|
||||
continue;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", idx);
|
||||
format_defaults(ft, c, NULL, NULL, NULL);
|
||||
|
||||
|
||||
@@ -75,13 +75,17 @@ 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) {
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
key = key_string_lookup_key(bd->key);
|
||||
|
||||
if (bd->can_repeat)
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
repeat = 1;
|
||||
|
||||
width = utf8_cstrwidth(table->name);
|
||||
@@ -90,18 +94,25 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
width = utf8_cstrwidth(key);
|
||||
if (width > keywidth)
|
||||
keywidth = width;
|
||||
|
||||
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) {
|
||||
}
|
||||
bd = key_bindings_first(table);
|
||||
while (bd != NULL) {
|
||||
key = key_string_lookup_key(bd->key);
|
||||
|
||||
if (!repeat)
|
||||
r = "";
|
||||
else if (bd->can_repeat)
|
||||
else if (bd->flags & KEY_BINDING_REPEAT)
|
||||
r = "-r ";
|
||||
else
|
||||
r = " ";
|
||||
@@ -122,7 +133,9 @@ cmd_list_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cp);
|
||||
|
||||
cmdq_print(item, "bind-key %s", tmp);
|
||||
bd = key_bindings_next(table, bd);
|
||||
}
|
||||
table = key_bindings_next_table(table);
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
@@ -144,7 +157,7 @@ cmd_list_keys_commands(struct cmd *self, struct cmdq_item *item)
|
||||
"#{command_list_usage}";
|
||||
}
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, NULL, NULL, NULL, NULL);
|
||||
|
||||
for (entryp = cmd_table; *entryp != NULL; entryp++) {
|
||||
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_list_panes_entry = {
|
||||
.args = { "asF:t:", 0, 0 },
|
||||
.usage = "[-as] [-F format] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_panes_exec
|
||||
@@ -51,8 +51,8 @@ static enum cmd_retval
|
||||
cmd_list_panes_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_panes_server(self, item);
|
||||
@@ -123,7 +123,7 @@ cmd_list_panes_window(struct cmd *self, struct session *s, struct winlink *wl,
|
||||
|
||||
n = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, wp);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ cmd_list_sessions_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, NULL, NULL);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ const struct cmd_entry cmd_list_windows_entry = {
|
||||
.args = { "F:at:", 0, 0 },
|
||||
.usage = "[-a] [-F format] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_list_windows_exec
|
||||
@@ -66,7 +66,7 @@ cmd_list_windows_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'a'))
|
||||
cmd_list_windows_server(self, item);
|
||||
else
|
||||
cmd_list_windows_session(self, item->state.tflag.s, item, 0);
|
||||
cmd_list_windows_session(self, item->target.s, item, 0);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -86,7 +86,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
u_int n;
|
||||
u_int n;
|
||||
struct format_tree *ft;
|
||||
const char *template;
|
||||
char *line;
|
||||
@@ -105,7 +105,7 @@ cmd_list_windows_session(struct cmd *self, struct session *s,
|
||||
|
||||
n = 0;
|
||||
RB_FOREACH(wl, winlinks, &s->windows) {
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
format_add(ft, "line", "%u", n);
|
||||
format_defaults(ft, NULL, s, wl, NULL);
|
||||
|
||||
|
||||
@@ -56,10 +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;
|
||||
char *pdata, *new_pdata, *cause, *file;
|
||||
const char *bufname;
|
||||
char *pdata = NULL, *new_pdata, *cause;
|
||||
char *path, *file;
|
||||
size_t psize;
|
||||
int ch, error;
|
||||
|
||||
@@ -67,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;
|
||||
|
||||
@@ -78,7 +85,7 @@ 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);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -86,11 +93,12 @@ cmd_load_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
file = server_client_get_path(c, path);
|
||||
free(path);
|
||||
|
||||
f = fopen(file, "rb");
|
||||
if (f == NULL) {
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
free(file);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
|
||||
pdata = NULL;
|
||||
@@ -127,6 +135,7 @@ error:
|
||||
free(pdata);
|
||||
if (f != NULL)
|
||||
fclose(f);
|
||||
free(file);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_lock_session_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
@@ -57,22 +57,25 @@ const struct cmd_entry cmd_lock_client_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_lock_server_exec
|
||||
};
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_lock_server_exec(struct cmd *self, __unused struct cmdq_item *item)
|
||||
cmd_lock_server_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c;
|
||||
|
||||
if (self->entry == &cmd_lock_server_entry)
|
||||
server_lock();
|
||||
else if (self->entry == &cmd_lock_session_entry)
|
||||
server_lock_session(item->state.tflag.s);
|
||||
else
|
||||
server_lock_client(item->state.c);
|
||||
|
||||
server_lock_session(item->target.s);
|
||||
else {
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_lock_client(c);
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -35,8 +35,8 @@ const struct cmd_entry cmd_move_window_entry = {
|
||||
.args = { "adkrs:t:", 0, 0 },
|
||||
.usage = "[-dkr] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.sflag = CMD_WINDOW,
|
||||
.tflag = CMD_MOVEW_R,
|
||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||
/* -t is special */
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_move_window_exec
|
||||
@@ -49,8 +49,8 @@ const struct cmd_entry cmd_link_window_entry = {
|
||||
.args = { "adks:t:", 0, 0 },
|
||||
.usage = "[-dk] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.sflag = CMD_WINDOW,
|
||||
.tflag = CMD_WINDOW_INDEX,
|
||||
.source = { 's', CMD_FIND_WINDOW, 0 },
|
||||
/* -t is special */
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_move_window_exec
|
||||
@@ -60,18 +60,31 @@ static enum cmd_retval
|
||||
cmd_move_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *src = item->state.sflag.s;
|
||||
struct session *dst = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.sflag.wl;
|
||||
const char *tflag = args_get(args, 't');
|
||||
struct session *src;
|
||||
struct session *dst;
|
||||
struct winlink *wl;
|
||||
char *cause;
|
||||
int idx = item->state.tflag.idx, kflag, dflag, sflag;
|
||||
int idx, kflag, dflag, sflag;
|
||||
|
||||
if (args_has(args, 'r')) {
|
||||
session_renumber_windows(dst);
|
||||
if (cmd_find_target(&item->target, item, tflag,
|
||||
CMD_FIND_SESSION, CMD_FIND_QUIET) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
session_renumber_windows(item->target.s);
|
||||
recalculate_sizes();
|
||||
server_status_session(item->target.s);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
if (cmd_find_target(&item->target, item, tflag, CMD_FIND_WINDOW,
|
||||
CMD_FIND_WINDOW_INDEX) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src = item->source.s;
|
||||
dst = item->target.s;
|
||||
wl = item->source.wl;
|
||||
idx = item->target.idx;
|
||||
|
||||
kflag = args_has(self->args, 'k');
|
||||
dflag = args_has(self->args, 'd');
|
||||
|
||||
@@ -44,7 +44,7 @@ const struct cmd_entry cmd_new_session_entry = {
|
||||
"[-s session-name] " CMD_TARGET_SESSION_USAGE " [-x width] "
|
||||
"[-y height] [command]",
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_STARTSERVER,
|
||||
.exec = cmd_new_session_exec
|
||||
@@ -57,7 +57,7 @@ const struct cmd_entry cmd_has_session_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_new_session_exec
|
||||
@@ -73,18 +73,20 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct environ *env;
|
||||
struct termios tio, *tiop;
|
||||
struct session_group *sg;
|
||||
const char *newname, *errstr, *template, *group, *prefix;
|
||||
const char *path, *cmd, *cwd, *to_free = NULL;
|
||||
char **argv, *cause, *cp;
|
||||
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;
|
||||
enum cmd_retval retval;
|
||||
|
||||
if (self->entry == &cmd_has_session_entry) {
|
||||
/*
|
||||
* cmd_prepare() will fail if the session cannot be found,
|
||||
* hence always return success here.
|
||||
* cmd_find_target() will fail if the session cannot be found,
|
||||
* so always return success here.
|
||||
*/
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
@@ -94,34 +96,31 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
newname = args_get(args, 's');
|
||||
if (newname != NULL) {
|
||||
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);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
if ((as = session_find(newname)) != NULL) {
|
||||
if (args_has(args, 'A')) {
|
||||
/*
|
||||
* This item is now destined for
|
||||
* attach-session. Because attach-session will
|
||||
* have already been prepared, copy this
|
||||
* session into its tflag so it can be used.
|
||||
*/
|
||||
cmd_find_from_session(&item->state.tflag, as);
|
||||
return (cmd_attach_session(item,
|
||||
args_has(args, 'D'), 0, NULL,
|
||||
args_has(args, 'E')));
|
||||
retval = cmd_attach_session(item,
|
||||
newname, args_has(args, 'D'),
|
||||
0, NULL, args_has(args, 'E'));
|
||||
free(newname);
|
||||
return (retval);
|
||||
}
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* Is this going to be part of a session group? */
|
||||
group = args_get(args, 't');
|
||||
if (group != NULL) {
|
||||
groupwith = item->state.tflag.s;
|
||||
groupwith = item->target.s;
|
||||
if (groupwith == NULL) {
|
||||
if (!session_check_name(group)) {
|
||||
cmdq_error(item, "bad group name: %s", group);
|
||||
@@ -146,6 +145,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
detached = args_has(args, 'd');
|
||||
if (c == NULL)
|
||||
detached = 1;
|
||||
else if (c->flags & CLIENT_CONTROL)
|
||||
is_control = 1;
|
||||
|
||||
/* Is this client already attached? */
|
||||
already_attached = 0;
|
||||
@@ -153,13 +154,10 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
already_attached = 1;
|
||||
|
||||
/* Get the new session working directory. */
|
||||
if (args_has(args, 'c')) {
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, NULL, NULL, NULL);
|
||||
} else if (c != NULL && c->session == NULL && c->cwd != NULL)
|
||||
cwd = c->cwd;
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, NULL, NULL, NULL);
|
||||
else
|
||||
cwd = ".";
|
||||
cwd = xstrdup(server_client_get_cwd(c, NULL));
|
||||
|
||||
/*
|
||||
* If this is a new client, check for nesting and save the termios
|
||||
@@ -192,29 +190,43 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
/* Find new session size. */
|
||||
if (c != NULL) {
|
||||
if (!detached) {
|
||||
sx = c->tty.sx;
|
||||
sy = c->tty.sy;
|
||||
if (!is_control &&
|
||||
sy > 0 &&
|
||||
options_get_number(global_s_options, "status"))
|
||||
sy--;
|
||||
} else {
|
||||
sx = 80;
|
||||
sy = 24;
|
||||
}
|
||||
if (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, 'x')) {
|
||||
tmp = args_get(args, 'x');
|
||||
if (strcmp(tmp, "-") == 0) {
|
||||
if (c != NULL)
|
||||
sx = c->tty.sx;
|
||||
} else {
|
||||
sx = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "width %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (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;
|
||||
if ((is_control || detached) && args_has(args, 'y')) {
|
||||
tmp = args_get(args, 'y');
|
||||
if (strcmp(tmp, "-") == 0) {
|
||||
if (c != NULL)
|
||||
sy = c->tty.sy;
|
||||
} else {
|
||||
sy = strtonum(tmp, 1, USHRT_MAX, &errstr);
|
||||
if (errstr != NULL) {
|
||||
cmdq_error(item, "height %s", errstr);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sy > 0 && options_get_number(global_s_options, "status"))
|
||||
sy--;
|
||||
if (sx == 0)
|
||||
sx = 1;
|
||||
if (sy == 0)
|
||||
@@ -262,10 +274,12 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
/* Set the initial window name if one given. */
|
||||
if (argc >= 0 && args_has(args, 'n')) {
|
||||
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, args_get(args, 'n'));
|
||||
window_set_name(w, cp);
|
||||
options_set_number(w->options, "automatic-rename", 0);
|
||||
free(cp);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -297,7 +311,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
} else if (c->session != NULL)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
if (!item->repeat)
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
@@ -324,19 +338,20 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cp);
|
||||
}
|
||||
|
||||
if (!detached)
|
||||
if (!detached) {
|
||||
c->flags |= CLIENT_ATTACHED;
|
||||
cmd_find_from_session(&item->shared->current, s, 0);
|
||||
}
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_from_session(&fs, s);
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-session");
|
||||
|
||||
free(cwd);
|
||||
free(newname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
free(cwd);
|
||||
free(newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_new_window_entry = {
|
||||
.usage = "[-adkP] [-c start-directory] [-F format] [-n window-name] "
|
||||
CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
|
||||
.tflag = CMD_WINDOW_INDEX,
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_WINDOW_INDEX },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_new_window_exec
|
||||
@@ -52,17 +52,18 @@ static enum cmd_retval
|
||||
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct client *c = item->state.c;
|
||||
int idx = item->state.tflag.idx;
|
||||
const char *cmd, *path, *template, *cwd, *to_free;
|
||||
char **argv, *cause, *cp;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
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 cmd_find_state fs;
|
||||
|
||||
if (args_has(args, 'a')) {
|
||||
if (args_has(args, 'a') && wl != NULL) {
|
||||
if ((idx = winlink_shuffle_up(s, wl)) == -1) {
|
||||
cmdq_error(item, "no free window indexes");
|
||||
return (CMD_RETURN_ERROR);
|
||||
@@ -92,16 +93,16 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||
else
|
||||
cwd = s->cwd;
|
||||
cwd = xstrdup(server_client_get_cwd(item->client, s));
|
||||
|
||||
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')) {
|
||||
@@ -123,7 +124,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
|
||||
if (idx == -1)
|
||||
idx = -1 - options_get_number(s->options, "base-index");
|
||||
wl = session_new(s, args_get(args, 'n'), argc, argv, path, cwd, idx,
|
||||
wl = session_new(s, name, argc, argv, path, cwd, idx,
|
||||
&cause);
|
||||
if (wl == NULL) {
|
||||
cmdq_error(item, "create window failed: %s", cause);
|
||||
@@ -132,6 +133,7 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
if (!detached) {
|
||||
session_select(s, wl->idx);
|
||||
cmd_find_from_winlink(current, wl, 0);
|
||||
server_redraw_session_group(s);
|
||||
} else
|
||||
server_status_session_group(s);
|
||||
@@ -144,16 +146,15 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
free(cp);
|
||||
}
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_from_winlink(&fs, s, wl);
|
||||
cmd_find_from_winlink(&fs, wl, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-new-window");
|
||||
|
||||
free(name);
|
||||
free(cwd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
free(name);
|
||||
free(cwd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_paste_buffer_entry = {
|
||||
.usage = "[-dpr] [-s separator] " CMD_BUFFER_USAGE " "
|
||||
CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_paste_buffer_exec
|
||||
@@ -47,7 +47,7 @@ static enum cmd_retval
|
||||
cmd_paste_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct paste_buffer *pb;
|
||||
const char *sepstr, *bufname, *bufdata, *bufend, *line;
|
||||
size_t seplen, bufsize;
|
||||
|
||||
115
cmd-pipe-pane.c
115
cmd-pipe-pane.c
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
@@ -34,16 +35,18 @@
|
||||
|
||||
static enum cmd_retval cmd_pipe_pane_exec(struct cmd *, struct cmdq_item *);
|
||||
|
||||
static void cmd_pipe_pane_read_callback(struct bufferevent *, void *);
|
||||
static void cmd_pipe_pane_write_callback(struct bufferevent *, void *);
|
||||
static void cmd_pipe_pane_error_callback(struct bufferevent *, short, void *);
|
||||
|
||||
const struct cmd_entry cmd_pipe_pane_entry = {
|
||||
.name = "pipe-pane",
|
||||
.alias = "pipep",
|
||||
|
||||
.args = { "ot:", 0, 1 },
|
||||
.usage = "[-o] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
.args = { "IOot:", 0, 1 },
|
||||
.usage = "[-IOo] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_pipe_pane_exec
|
||||
@@ -53,13 +56,14 @@ static enum cmd_retval
|
||||
cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
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;
|
||||
char *cmd;
|
||||
int old_fd, pipe_fd[2], null_fd;
|
||||
int old_fd, pipe_fd[2], null_fd, in, out;
|
||||
struct format_tree *ft;
|
||||
sigset_t set, oldset;
|
||||
|
||||
/* Destroy the old pipe. */
|
||||
old_fd = wp->pipe_fd;
|
||||
@@ -67,6 +71,11 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
bufferevent_free(wp->pipe_event);
|
||||
close(wp->pipe_fd);
|
||||
wp->pipe_fd = -1;
|
||||
|
||||
if (window_pane_destroy_ready(wp)) {
|
||||
server_destroy_pane(wp, 1);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
/* If no pipe command, that is enough. */
|
||||
@@ -82,6 +91,15 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(self->args, 'o') && old_fd != -1)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
/* What do we want to do? Neither -I or -O is -O. */
|
||||
if (args_has(self->args, 'I')) {
|
||||
in = 1;
|
||||
out = args_has(self->args, 'O');
|
||||
} else {
|
||||
in = 0;
|
||||
out = 1;
|
||||
}
|
||||
|
||||
/* Open the new pipe. */
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pipe_fd) != 0) {
|
||||
cmdq_error(item, "socketpair error: %s", strerror(errno));
|
||||
@@ -89,65 +107,114 @@ cmd_pipe_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
|
||||
/* Expand the command. */
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
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));
|
||||
format_free(ft);
|
||||
|
||||
/* Fork the child. */
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
switch (fork()) {
|
||||
case -1:
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
cmdq_error(item, "fork error: %s", strerror(errno));
|
||||
|
||||
free(cmd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
case 0:
|
||||
/* Child process. */
|
||||
proc_clear_signals(server_proc, 1);
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[0]);
|
||||
clear_signals(1);
|
||||
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (pipe_fd[1] != STDIN_FILENO)
|
||||
close(pipe_fd[1]);
|
||||
|
||||
null_fd = open(_PATH_DEVNULL, O_WRONLY, 0);
|
||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (out) {
|
||||
if (dup2(pipe_fd[1], STDIN_FILENO) == -1)
|
||||
_exit(1);
|
||||
} else {
|
||||
if (dup2(null_fd, STDIN_FILENO) == -1)
|
||||
_exit(1);
|
||||
}
|
||||
if (in) {
|
||||
if (dup2(pipe_fd[1], STDOUT_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (pipe_fd[1] != STDOUT_FILENO)
|
||||
close(pipe_fd[1]);
|
||||
} else {
|
||||
if (dup2(null_fd, STDOUT_FILENO) == -1)
|
||||
_exit(1);
|
||||
}
|
||||
if (dup2(null_fd, STDERR_FILENO) == -1)
|
||||
_exit(1);
|
||||
if (null_fd != STDOUT_FILENO && null_fd != STDERR_FILENO)
|
||||
close(null_fd);
|
||||
|
||||
closefrom(STDERR_FILENO + 1);
|
||||
|
||||
execl(_PATH_BSHELL, "sh", "-c", cmd, (char *) NULL);
|
||||
_exit(1);
|
||||
default:
|
||||
/* Parent process. */
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
close(pipe_fd[1]);
|
||||
|
||||
wp->pipe_fd = pipe_fd[0];
|
||||
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input);
|
||||
|
||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||
NULL, NULL, cmd_pipe_pane_error_callback, wp);
|
||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||
|
||||
setblocking(wp->pipe_fd, 0);
|
||||
wp->pipe_event = bufferevent_new(wp->pipe_fd,
|
||||
cmd_pipe_pane_read_callback,
|
||||
cmd_pipe_pane_write_callback,
|
||||
cmd_pipe_pane_error_callback,
|
||||
wp);
|
||||
if (out)
|
||||
bufferevent_enable(wp->pipe_event, EV_WRITE);
|
||||
if (in)
|
||||
bufferevent_enable(wp->pipe_event, EV_READ);
|
||||
|
||||
free(cmd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_pipe_pane_read_callback(__unused struct bufferevent *bufev, void *data)
|
||||
{
|
||||
struct window_pane *wp = data;
|
||||
struct evbuffer *evb = wp->pipe_event->input;
|
||||
size_t available;
|
||||
|
||||
available = EVBUFFER_LENGTH(evb);
|
||||
log_debug("%%%u pipe read %zu", wp->id, available);
|
||||
|
||||
bufferevent_write(wp->event, EVBUFFER_DATA(evb), available);
|
||||
evbuffer_drain(evb, available);
|
||||
|
||||
if (window_pane_destroy_ready(wp))
|
||||
server_destroy_pane(wp, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_pipe_pane_write_callback(__unused struct bufferevent *bufev, void *data)
|
||||
{
|
||||
struct window_pane *wp = data;
|
||||
|
||||
log_debug("%%%u pipe empty", wp->id);
|
||||
|
||||
if (window_pane_destroy_ready(wp))
|
||||
server_destroy_pane(wp, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
cmd_pipe_pane_error_callback(__unused struct bufferevent *bufev,
|
||||
__unused short what, void *data)
|
||||
{
|
||||
struct window_pane *wp = data;
|
||||
|
||||
log_debug("%%%u pipe error", wp->id);
|
||||
|
||||
bufferevent_free(wp->pipe_event);
|
||||
close(wp->pipe_fd);
|
||||
wp->pipe_fd = -1;
|
||||
|
||||
if (window_pane_destroy_ready(wp))
|
||||
server_destroy_pane(wp, 1);
|
||||
}
|
||||
|
||||
96
cmd-queue.c
96
cmd-queue.c
@@ -102,8 +102,11 @@ cmdq_insert_after(struct cmdq_item *after, struct cmdq_item *item)
|
||||
static void
|
||||
cmdq_remove(struct cmdq_item *item)
|
||||
{
|
||||
if (item->formats != NULL)
|
||||
format_free(item->formats);
|
||||
if (item->shared != NULL && --item->shared->references == 0) {
|
||||
if (item->shared->formats != NULL)
|
||||
format_free(item->shared->formats);
|
||||
free(item->shared);
|
||||
}
|
||||
|
||||
if (item->client != NULL)
|
||||
server_client_unref(item->client);
|
||||
@@ -150,6 +153,15 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
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);
|
||||
|
||||
TAILQ_FOREACH(cmd, &cmdlist->list, qentry) {
|
||||
xasprintf(&tmp, "command[%s]", cmd->entry->name);
|
||||
@@ -161,13 +173,11 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
item->group = group;
|
||||
item->flags = flags;
|
||||
|
||||
item->shared = shared;
|
||||
item->cmdlist = cmdlist;
|
||||
item->cmd = cmd;
|
||||
|
||||
if (current != NULL)
|
||||
cmd_find_copy_state(&item->current, current);
|
||||
if (m != NULL)
|
||||
memcpy(&item->mouse, m, sizeof item->mouse);
|
||||
shared->references++;
|
||||
cmdlist->references++;
|
||||
|
||||
if (first == NULL)
|
||||
@@ -179,41 +189,63 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
|
||||
return (first);
|
||||
}
|
||||
|
||||
/* Fill in flag for a command. */
|
||||
static enum cmd_retval
|
||||
cmdq_find_flag(struct cmdq_item *item, struct cmd_find_state *fs,
|
||||
const struct cmd_entry_flag *flag)
|
||||
{
|
||||
const char *value;
|
||||
|
||||
if (flag->flag == 0) {
|
||||
cmd_find_clear_state(fs, 0);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
value = args_get(item->cmd->args, flag->flag);
|
||||
if (cmd_find_target(fs, item, value, flag->type, flag->flags) != 0) {
|
||||
cmd_find_clear_state(fs, 0);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
/* Fire command on command queue. */
|
||||
static enum cmd_retval
|
||||
cmdq_fire_command(struct cmdq_item *item)
|
||||
{
|
||||
struct client *c = item->client;
|
||||
struct cmd *cmd = item->cmd;
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
enum cmd_retval retval;
|
||||
const char *name;
|
||||
struct cmd_find_state *fsp, fs;
|
||||
int flags;
|
||||
|
||||
flags = !!(cmd->flags & CMD_CONTROL);
|
||||
cmdq_guard(item, "begin", flags);
|
||||
|
||||
if (cmd_prepare_state(cmd, item) != 0) {
|
||||
retval = CMD_RETURN_ERROR;
|
||||
goto out;
|
||||
}
|
||||
if (item->client == NULL)
|
||||
item->client = cmd_find_client(item, NULL, CMD_FIND_QUIET);
|
||||
|
||||
retval = cmd->entry->exec(cmd, item);
|
||||
item->client = cmd_find_client(item, NULL, 1);
|
||||
retval = cmdq_find_flag(item, &item->source, &entry->source);
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
goto out;
|
||||
retval = cmdq_find_flag(item, &item->target, &entry->target);
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
goto out;
|
||||
|
||||
if (cmd->entry->flags & CMD_AFTERHOOK) {
|
||||
name = cmd->entry->name;
|
||||
if (cmd_find_valid_state(&item->state.tflag))
|
||||
fsp = &item->state.tflag;
|
||||
else {
|
||||
if (cmd_find_current(&fs, item, CMD_FIND_QUIET) != 0)
|
||||
goto out;
|
||||
retval = entry->exec(cmd, item);
|
||||
if (retval == CMD_RETURN_ERROR)
|
||||
goto out;
|
||||
|
||||
if (entry->flags & CMD_AFTERHOOK) {
|
||||
if (cmd_find_valid_state(&item->target))
|
||||
fsp = &item->target;
|
||||
else if (cmd_find_valid_state(&item->shared->current))
|
||||
fsp = &item->shared->current;
|
||||
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
|
||||
fsp = &fs;
|
||||
}
|
||||
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", name);
|
||||
else
|
||||
goto out;
|
||||
hooks_insert(fsp->s->hooks, item, fsp, "after-%s", entry->name);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -258,19 +290,17 @@ cmdq_fire_callback(struct cmdq_item *item)
|
||||
void
|
||||
cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
|
||||
{
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
va_list ap;
|
||||
struct cmdq_item *loop;
|
||||
char *value;
|
||||
|
||||
va_start(ap, fmt);
|
||||
xvasprintf(&value, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
for (loop = item; loop != NULL; loop = item->next) {
|
||||
if (loop->formats == NULL)
|
||||
loop->formats = format_create(NULL, FORMAT_NONE, 0);
|
||||
format_add(loop->formats, key, "%s", value);
|
||||
}
|
||||
if (shared->formats == NULL)
|
||||
shared->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
|
||||
format_add(shared->formats, key, "%s", value);
|
||||
|
||||
free(value);
|
||||
}
|
||||
@@ -319,8 +349,7 @@ cmdq_next(struct client *c)
|
||||
item->time = time(NULL);
|
||||
item->number = ++number;
|
||||
|
||||
switch (item->type)
|
||||
{
|
||||
switch (item->type) {
|
||||
case CMDQ_COMMAND:
|
||||
retval = cmdq_fire_command(item);
|
||||
|
||||
@@ -399,7 +428,8 @@ cmdq_print(struct cmdq_item *item, const char *fmt, ...)
|
||||
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);
|
||||
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);
|
||||
@@ -423,6 +453,8 @@ cmdq_error(struct cmdq_item *item, const char *fmt, ...)
|
||||
msglen = xvasprintf(&msg, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
log_debug("%s: %s", __func__, msg);
|
||||
|
||||
if (c == NULL)
|
||||
cfg_add_cause("%s:%u: %s", cmd->file, cmd->line, msg);
|
||||
else if (c->session == NULL || (c->flags & CLIENT_CONTROL)) {
|
||||
|
||||
@@ -34,8 +34,6 @@ const struct cmd_entry cmd_refresh_client_entry = {
|
||||
.args = { "C:St:", 0, 0 },
|
||||
.usage = "[-S] [-C size] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_refresh_client_exec
|
||||
};
|
||||
@@ -44,10 +42,13 @@ static enum cmd_retval
|
||||
cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c;
|
||||
const char *size;
|
||||
u_int w, h;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (args_has(args, 'C')) {
|
||||
if ((size = args_get(args, 'C')) == NULL) {
|
||||
cmdq_error(item, "missing size");
|
||||
@@ -66,8 +67,9 @@ cmd_refresh_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "not a control client");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (tty_set_size(&c->tty, w, h))
|
||||
recalculate_sizes();
|
||||
tty_set_size(&c->tty, w, h);
|
||||
c->flags |= CLIENT_SIZECHANGED;
|
||||
recalculate_sizes();
|
||||
} else if (args_has(args, 'S')) {
|
||||
c->flags |= CLIENT_STATUSFORCE;
|
||||
server_status_client(c);
|
||||
|
||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
.args = { "t:", 1, 1 },
|
||||
.usage = CMD_TARGET_SESSION_USAGE " new-name",
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_session_exec
|
||||
@@ -46,26 +46,31 @@ const struct cmd_entry cmd_rename_session_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_rename_session_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = item->state.tflag.s;
|
||||
const char *newname;
|
||||
struct args *args = self->args;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
char *newname;
|
||||
|
||||
newname = args->argv[0];
|
||||
if (strcmp(newname, s->name) == 0)
|
||||
newname = format_single(item, args->argv[0], c, s, NULL, NULL);
|
||||
if (strcmp(newname, s->name) == 0) {
|
||||
free(newname);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (!session_check_name(newname)) {
|
||||
cmdq_error(item, "bad session name: %s", newname);
|
||||
free(newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (session_find(newname) != NULL) {
|
||||
cmdq_error(item, "duplicate session: %s", newname);
|
||||
free(newname);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
RB_REMOVE(sessions, &sessions, s);
|
||||
free(s->name);
|
||||
s->name = xstrdup(newname);
|
||||
s->name = newname;
|
||||
RB_INSERT(sessions, &sessions, s);
|
||||
|
||||
server_status_session(s);
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_rename_window_entry = {
|
||||
.args = { "t:", 1, 1 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE " new-name",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_rename_window_exec
|
||||
@@ -46,12 +46,17 @@ static enum cmd_retval
|
||||
cmd_rename_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct winlink *wl = item->target.wl;
|
||||
char *newname;
|
||||
|
||||
window_set_name(wl->window, args->argv[0]);
|
||||
newname = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
window_set_name(wl->window, newname);
|
||||
options_set_number(wl->window->options, "automatic-rename", 0);
|
||||
|
||||
server_status_window(wl->window);
|
||||
free(newname);
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ const struct cmd_entry cmd_resize_pane_entry = {
|
||||
.usage = "[-DLMRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " "
|
||||
"[adjustment]",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_resize_pane_exec
|
||||
@@ -49,23 +49,24 @@ static enum cmd_retval
|
||||
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct cmdq_shared *shared = item->shared;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct client *c = item->client;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct session *s = item->target.s;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
u_int adjust;
|
||||
int x, y;
|
||||
|
||||
if (args_has(args, 'M')) {
|
||||
if (cmd_mouse_window(&item->mouse, &s) == NULL)
|
||||
if (cmd_mouse_window(&shared->mouse, &s) == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (c == NULL || c->session != s)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
|
||||
cmd_resize_pane_mouse_update(c, &item->mouse);
|
||||
cmd_resize_pane_mouse_update(c, &shared->mouse);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -128,47 +129,64 @@ static void
|
||||
cmd_resize_pane_mouse_update(struct client *c, struct mouse_event *m)
|
||||
{
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
int found;
|
||||
u_int y, ly;
|
||||
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;
|
||||
y = m->y; x = m->x;
|
||||
if (m->statusat == 0 && y > 0)
|
||||
y--;
|
||||
else if (m->statusat > 0 && y >= (u_int)m->statusat)
|
||||
y = m->statusat - 1;
|
||||
ly = m->ly;
|
||||
ly = m->ly; lx = m->lx;
|
||||
if (m->statusat == 0 && ly > 0)
|
||||
ly--;
|
||||
else if (m->statusat > 0 && ly >= (u_int)m->statusat)
|
||||
ly = m->statusat - 1;
|
||||
|
||||
found = 0;
|
||||
TAILQ_FOREACH(wp, &wl->window->panes, entry) {
|
||||
if (!window_pane_visible(wp))
|
||||
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;
|
||||
|
||||
if (wp->xoff + wp->sx == m->lx &&
|
||||
wp->yoff <= 1 + ly &&
|
||||
wp->yoff + wp->sy >= ly) {
|
||||
layout_resize_pane(wp, LAYOUT_LEFTRIGHT, m->x - m->lx, 0);
|
||||
found = 1;
|
||||
for (j = 0; j < ncells; j++) {
|
||||
if (cells[j] == lc) {
|
||||
lc = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (wp->yoff + wp->sy == ly &&
|
||||
wp->xoff <= 1 + m->lx &&
|
||||
wp->xoff + wp->sx >= m->lx) {
|
||||
layout_resize_pane(wp, LAYOUT_TOPBOTTOM, y - ly, 0);
|
||||
found = 1;
|
||||
if (lc == NULL)
|
||||
continue;
|
||||
|
||||
cells[ncells] = lc;
|
||||
ncells++;
|
||||
}
|
||||
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 (found)
|
||||
server_redraw_window(wl->window);
|
||||
else
|
||||
c->tty.mouse_drag_update = NULL;
|
||||
if (resizes != 0)
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
@@ -34,10 +34,11 @@ const struct cmd_entry cmd_respawn_pane_entry = {
|
||||
.name = "respawn-pane",
|
||||
.alias = "respawnp",
|
||||
|
||||
.args = { "kt:", 0, -1 },
|
||||
.usage = "[-k] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
.args = { "c:kt:", 0, -1 },
|
||||
.usage = "[-c start-directory] [-k] " CMD_TARGET_PANE_USAGE
|
||||
" [command]",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_respawn_pane_exec
|
||||
@@ -47,13 +48,14 @@ static enum cmd_retval
|
||||
cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct session *s = item->target.s;
|
||||
struct environ *env;
|
||||
const char *path;
|
||||
char *cause;
|
||||
const char *path = NULL, *cp;
|
||||
char *cause, *cwd = NULL;
|
||||
u_int idx;
|
||||
struct environ_entry *envent;
|
||||
|
||||
@@ -69,7 +71,6 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
|
||||
path = NULL;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
@@ -77,15 +78,20 @@ cmd_respawn_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
||||
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) {
|
||||
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);
|
||||
|
||||
@@ -34,10 +34,11 @@ const struct cmd_entry cmd_respawn_window_entry = {
|
||||
.name = "respawn-window",
|
||||
.alias = "respawnw",
|
||||
|
||||
.args = { "kt:", 0, -1 },
|
||||
.usage = "[-k] " CMD_TARGET_WINDOW_USAGE " [command]",
|
||||
.args = { "c:kt:", 0, -1 },
|
||||
.usage = "[-c start-directory] [-k] " CMD_TARGET_WINDOW_USAGE
|
||||
" [command]",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_respawn_window_exec
|
||||
@@ -47,13 +48,14 @@ static enum cmd_retval
|
||||
cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
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;
|
||||
char *cause;
|
||||
const char *path = NULL, *cp;
|
||||
char *cause, *cwd = NULL;
|
||||
struct environ_entry *envent;
|
||||
|
||||
if (!args_has(self->args, 'k')) {
|
||||
@@ -73,7 +75,6 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
|
||||
path = NULL;
|
||||
if (item->client != NULL && item->client->session == NULL)
|
||||
envent = environ_find(item->client->environ, "PATH");
|
||||
else
|
||||
@@ -81,16 +82,22 @@ cmd_respawn_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
if (window_pane_spawn(wp, args->argc, args->argv, path, NULL, NULL, env,
|
||||
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) {
|
||||
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);
|
||||
|
||||
@@ -34,7 +34,7 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
.args = { "Dt:U", 0, 0 },
|
||||
.usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_rotate_window_exec
|
||||
@@ -43,7 +43,8 @@ const struct cmd_entry cmd_rotate_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp, *wp2;
|
||||
struct layout_cell *lc;
|
||||
@@ -77,6 +78,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);
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
server_redraw_window(w);
|
||||
} else {
|
||||
wp = TAILQ_FIRST(&w->panes);
|
||||
@@ -104,6 +106,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);
|
||||
cmd_find_from_winlink_pane(current, wl, wp, 0);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ const struct cmd_entry cmd_run_shell_entry = {
|
||||
.args = { "bt:", 1, 1 },
|
||||
.usage = "[-b] " CMD_TARGET_PANE_USAGE " shell-command",
|
||||
|
||||
.tflag = CMD_PANE_CANFAIL,
|
||||
.target = { 't', CMD_FIND_PANE, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_run_shell_exec
|
||||
@@ -68,14 +68,14 @@ cmd_run_shell_print(struct job *job, const char *msg)
|
||||
cmdq_print(cdata->item, "%s", msg);
|
||||
return;
|
||||
}
|
||||
if (cmd_find_current (&fs, NULL, CMD_FIND_QUIET) != 0)
|
||||
if (cmd_find_from_nothing(&fs, 0) != 0)
|
||||
return;
|
||||
wp = fs.wp;
|
||||
if (wp == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
if (window_pane_set_mode(wp, &window_copy_mode) == 0)
|
||||
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);
|
||||
@@ -86,18 +86,10 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_run_shell_data *cdata;
|
||||
struct client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window_pane *wp = item->state.tflag.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 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;
|
||||
|
||||
cdata = xcalloc(1, sizeof *cdata);
|
||||
cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp);
|
||||
@@ -110,8 +102,8 @@ 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, cmd_run_shell_callback, cmd_run_shell_free,
|
||||
cdata);
|
||||
job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL,
|
||||
cmd_run_shell_callback, cmd_run_shell_free, cdata, 0);
|
||||
|
||||
if (args_has(args, 'b'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
@@ -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);
|
||||
@@ -101,6 +105,8 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
flags = "ab";
|
||||
|
||||
file = server_client_get_path(c, path);
|
||||
free(path);
|
||||
|
||||
f = fopen(file, flags);
|
||||
if (f == NULL) {
|
||||
cmdq_error(item, "%s: %s", file, strerror(errno));
|
||||
@@ -111,6 +117,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (fwrite(bufdata, 1, bufsize, f) != bufsize) {
|
||||
cmdq_error(item, "%s: write error", file);
|
||||
fclose(f);
|
||||
free(file);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,10 @@ const struct cmd_entry cmd_select_layout_entry = {
|
||||
.name = "select-layout",
|
||||
.alias = "selectl",
|
||||
|
||||
.args = { "nopt:", 0, 1 },
|
||||
.usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
|
||||
.args = { "Enopt:", 0, 1 },
|
||||
.usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_layout_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
@@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_select_layout_exec
|
||||
@@ -71,14 +71,14 @@ const struct cmd_entry cmd_previous_layout_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct window *w;
|
||||
const char *layoutname;
|
||||
char *oldlayout;
|
||||
int next, previous, layout;
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct window_pane *wp = item->target.wp;
|
||||
const char *layoutname;
|
||||
char *oldlayout;
|
||||
int next, previous, layout;
|
||||
|
||||
w = wl->window;
|
||||
server_unzoom_window(w);
|
||||
|
||||
next = self->entry == &cmd_next_layout_entry;
|
||||
@@ -99,6 +99,11 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
goto changed;
|
||||
}
|
||||
|
||||
if (args_has(args, 'E')) {
|
||||
layout_spread_out(wp);
|
||||
goto changed;
|
||||
}
|
||||
|
||||
if (!args_has(args, 'o')) {
|
||||
if (args->argc == 0)
|
||||
layout = w->lastlayout;
|
||||
@@ -131,6 +136,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
|
||||
changed:
|
||||
free(oldlayout);
|
||||
server_redraw_window(w);
|
||||
notify_window("window-layout-changed", w);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
/*
|
||||
@@ -30,10 +32,10 @@ const struct cmd_entry cmd_select_pane_entry = {
|
||||
.name = "select-pane",
|
||||
.alias = "selectp",
|
||||
|
||||
.args = { "DdegLlMmP:Rt:U", 0, 0 },
|
||||
.usage = "[-DdegLlMmRU] [-P style] " CMD_TARGET_PANE_USAGE,
|
||||
.args = { "DdegLlMmP:RT:t:U", 0, 0 },
|
||||
.usage = "[-DdegLlMmRU] [-P style] [-T title] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_pane_exec
|
||||
@@ -46,7 +48,7 @@ const struct cmd_entry cmd_last_pane_entry = {
|
||||
.args = { "det:", 0, 0 },
|
||||
.usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_pane_exec
|
||||
@@ -56,31 +58,39 @@ static enum cmd_retval
|
||||
cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct client *c = cmd_find_client(item, NULL, 1);
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct window *w = wl->window;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct window_pane *wp = item->state.tflag.wp, *lastwp, *markedwp;
|
||||
struct session *s = item->target.s;
|
||||
struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
|
||||
char *pane_title;
|
||||
const char *style;
|
||||
|
||||
if (self->entry == &cmd_last_pane_entry || args_has(args, 'l')) {
|
||||
if (wl->window->last == NULL) {
|
||||
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);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'e'))
|
||||
w->last->flags &= ~PANE_INPUTOFF;
|
||||
lastwp->flags &= ~PANE_INPUTOFF;
|
||||
else if (args_has(self->args, 'd'))
|
||||
w->last->flags |= PANE_INPUTOFF;
|
||||
lastwp->flags |= PANE_INPUTOFF;
|
||||
else {
|
||||
server_unzoom_window(w);
|
||||
window_redraw_active_switch(w, w->last);
|
||||
if (window_set_active_pane(w, w->last)) {
|
||||
window_redraw_active_switch(w, lastwp);
|
||||
if (window_set_active_pane(w, lastwp)) {
|
||||
cmd_find_from_winlink(current, wl, 0);
|
||||
server_status_window(w);
|
||||
server_redraw_window_borders(w);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -146,6 +156,15 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'T')) {
|
||||
pane_title = format_single(item, args_get(self->args, 'T'),
|
||||
c, s, wl, wp);
|
||||
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);
|
||||
@@ -155,6 +174,8 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
window_redraw_active_switch(w, wp);
|
||||
if (window_set_active_pane(w, wp)) {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_select_window_entry = {
|
||||
.args = { "lnpTt:", 0, 0 },
|
||||
.usage = "[-lnpT] " CMD_TARGET_WINDOW_USAGE,
|
||||
|
||||
.tflag = CMD_WINDOW,
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_window_exec
|
||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_next_window_entry = {
|
||||
.args = { "at:", 0, 0 },
|
||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_window_exec
|
||||
@@ -62,7 +62,7 @@ const struct cmd_entry cmd_previous_window_entry = {
|
||||
.args = { "at:", 0, 0 },
|
||||
.usage = "[-a] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_window_exec
|
||||
@@ -75,7 +75,7 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
.args = { "t:", 0, 0 },
|
||||
.usage = CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_select_window_exec
|
||||
@@ -84,9 +84,10 @@ const struct cmd_entry cmd_last_window_entry = {
|
||||
static enum cmd_retval
|
||||
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
struct session *s = item->state.tflag.s;
|
||||
int next, previous, last, activity;
|
||||
struct cmd_find_state *current = &item->shared->current;
|
||||
struct winlink *wl = item->target.wl;
|
||||
struct session *s = item->target.s;
|
||||
int next, previous, last, activity;
|
||||
|
||||
next = self->entry == &cmd_next_window_entry;
|
||||
if (args_has(self->args, 'n'))
|
||||
@@ -116,8 +117,9 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
hooks_insert(s->hooks, item, current, "after-select-window");
|
||||
} else {
|
||||
/*
|
||||
* If -T and select-window is invoked on same window as
|
||||
@@ -128,9 +130,14 @@ cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no last window");
|
||||
return (-1);
|
||||
}
|
||||
if (current->s == s)
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
} else if (session_select(s, wl->idx) == 0)
|
||||
} else if (session_select(s, wl->idx) == 0) {
|
||||
cmd_find_from_session(current, s, 0);
|
||||
server_redraw_session(s);
|
||||
}
|
||||
hooks_insert(s->hooks, item, current, "after-select-window");
|
||||
}
|
||||
recalculate_sizes();
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ const struct cmd_entry cmd_send_keys_entry = {
|
||||
.args = { "lXRMN:t:", 0, -1 },
|
||||
.usage = "[-lXRM] [-N repeat-count] " CMD_TARGET_PANE_USAGE " key ...",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_send_keys_exec
|
||||
@@ -49,20 +49,44 @@ const struct cmd_entry cmd_send_prefix_entry = {
|
||||
.args = { "2t:", 0, 0 },
|
||||
.usage = "[-2] " CMD_TARGET_PANE_USAGE,
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_send_keys_exec
|
||||
};
|
||||
|
||||
static void
|
||||
cmd_send_keys_inject(struct client *c, 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;
|
||||
|
||||
if (wp->mode == NULL || wp->mode->key_table == NULL) {
|
||||
if (options_get_number(wp->window->options, "xterm-keys"))
|
||||
key |= KEYC_XTERM;
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
return;
|
||||
}
|
||||
table = key_bindings_get_table(wp->mode->key_table(wp), 1);
|
||||
|
||||
bd = key_bindings_get(table, key & ~KEYC_XTERM);
|
||||
if (bd != NULL) {
|
||||
table->references++;
|
||||
key_bindings_dispatch(bd, item, c, NULL, &item->target);
|
||||
key_bindings_unref_table(table);
|
||||
}
|
||||
}
|
||||
|
||||
static enum cmd_retval
|
||||
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct window_pane *wp = item->state.tflag.wp;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct mouse_event *m = &item->mouse;
|
||||
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;
|
||||
@@ -108,7 +132,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");
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
cmd_send_keys_inject(c, item, key);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
|
||||
@@ -123,7 +147,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (!literal) {
|
||||
key = key_string_lookup_string(args->argv[i]);
|
||||
if (key != KEYC_NONE && key != KEYC_UNKNOWN)
|
||||
window_pane_key(wp, NULL, s, key, NULL);
|
||||
cmd_send_keys_inject(c, item, key);
|
||||
else
|
||||
literal = 1;
|
||||
}
|
||||
@@ -132,7 +156,7 @@ 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;
|
||||
window_pane_key(wp, NULL, s, wc, NULL);
|
||||
cmd_send_keys_inject(c, item, wc);
|
||||
}
|
||||
free(ud);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ const struct cmd_entry cmd_set_environment_entry = {
|
||||
.args = { "grt:u", 1, 2 },
|
||||
.usage = "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_environment_exec
|
||||
@@ -68,7 +68,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
if (item->target.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
@@ -76,7 +76,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
env = item->state.tflag.s->environ;
|
||||
env = item->target.s->environ;
|
||||
}
|
||||
|
||||
if (args_has(self->args, 'u')) {
|
||||
|
||||
@@ -33,10 +33,10 @@ 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]",
|
||||
.args = { "gRt:u", 1, 2 },
|
||||
.usage = "[-gRu] " CMD_TARGET_SESSION_USAGE " hook-name [command]",
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
@@ -49,7 +49,7 @@ const struct cmd_entry cmd_show_hooks_entry = {
|
||||
.args = { "gt:", 0, 1 },
|
||||
.usage = "[-g] " CMD_TARGET_SESSION_USAGE,
|
||||
|
||||
.tflag = CMD_SESSION,
|
||||
.target = { 't', CMD_FIND_SESSION, 0 },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_hook_exec
|
||||
@@ -68,7 +68,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(args, 'g'))
|
||||
hooks = global_hooks;
|
||||
else {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
if (item->target.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
@@ -76,7 +76,7 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
hooks = item->state.tflag.s->hooks;
|
||||
hooks = item->target.s->hooks;
|
||||
}
|
||||
|
||||
if (self->entry == &cmd_show_hooks_entry) {
|
||||
@@ -101,18 +101,21 @@ cmd_set_hook_exec(struct cmd *self, struct cmdq_item *item)
|
||||
else
|
||||
cmd = args->argv[1];
|
||||
|
||||
if (cmd != NULL && (args_has(args, 'R') || args_has(args, 'u'))) {
|
||||
cmdq_error(item, "no command allowed");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
if (args_has(args, 'R')) {
|
||||
notify_hook(item, name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
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);
|
||||
cmdq_error(item, "no command given");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
cmdlist = cmd_string_parse(cmd, NULL, 0, &cause);
|
||||
|
||||
102
cmd-set-option.c
102
cmd-set-option.c
@@ -42,10 +42,10 @@ const struct cmd_entry cmd_set_option_entry = {
|
||||
.name = "set-option",
|
||||
.alias = "set",
|
||||
|
||||
.args = { "agoqst:uw", 1, 2 },
|
||||
.usage = "[-agosquw] [-t target-window] option [value]",
|
||||
.args = { "aFgoqst:uw", 1, 2 },
|
||||
.usage = "[-aFgosquw] [-t target-window] option [value]",
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_option_exec
|
||||
@@ -55,10 +55,10 @@ const struct cmd_entry cmd_set_window_option_entry = {
|
||||
.name = "set-window-option",
|
||||
.alias = "setw",
|
||||
|
||||
.args = { "agoqt:u", 1, 2 },
|
||||
.usage = "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
.args = { "aFgoqt:u", 1, 2 },
|
||||
.usage = "[-aFgoqu] " CMD_TARGET_WINDOW_USAGE " option [value]",
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_set_option_exec
|
||||
@@ -69,33 +69,39 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
int append = args_has(args, 'a');
|
||||
struct cmd_find_state *fs = &item->state.tflag;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct client *c, *loop;
|
||||
struct session *s = fs->s;
|
||||
struct winlink *wl = fs->wl;
|
||||
struct window *w;
|
||||
struct client *c;
|
||||
enum options_table_scope scope;
|
||||
struct options *oo;
|
||||
struct options_entry *parent, *o;
|
||||
const char *name, *value, *target;
|
||||
char *name, *argument, *value = NULL, *cause;
|
||||
const char *target;
|
||||
int window, idx, already, error, ambiguous;
|
||||
char *cause;
|
||||
|
||||
/* Expand argument. */
|
||||
c = cmd_find_client(item, NULL, 1);
|
||||
argument = format_single(item, args->argv[0], c, s, wl, NULL);
|
||||
|
||||
/* Parse option name and index. */
|
||||
name = options_match(args->argv[0], &idx, &ambiguous);
|
||||
name = options_match(argument, &idx, &ambiguous);
|
||||
if (name == NULL) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
goto out;
|
||||
if (ambiguous)
|
||||
cmdq_error(item, "ambiguous option: %s", args->argv[0]);
|
||||
cmdq_error(item, "ambiguous option: %s", argument);
|
||||
else
|
||||
cmdq_error(item, "invalid option: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmdq_error(item, "invalid option: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
if (args->argc < 2)
|
||||
value = NULL;
|
||||
else if (args_has(args, 'F'))
|
||||
value = format_single(item, args->argv[1], c, s, wl, NULL);
|
||||
else
|
||||
value = args->argv[1];
|
||||
value = xstrdup(args->argv[1]);
|
||||
|
||||
/*
|
||||
* Figure out the scope: for user options it comes from the arguments,
|
||||
@@ -113,15 +119,15 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
scope = OPTIONS_TABLE_WINDOW;
|
||||
else {
|
||||
scope = OPTIONS_TABLE_NONE;
|
||||
xasprintf(&cause, "unknown option: %s", args->argv[0]);
|
||||
xasprintf(&cause, "unknown option: %s", argument);
|
||||
}
|
||||
}
|
||||
if (scope == OPTIONS_TABLE_NONE) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
goto out;
|
||||
cmdq_error(item, "%s", cause);
|
||||
free(cause);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
/* Which table should this option go into? */
|
||||
@@ -136,7 +142,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
else
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
} else
|
||||
oo = s->options;
|
||||
} else if (scope == OPTIONS_TABLE_WINDOW) {
|
||||
@@ -148,7 +154,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no such window: %s", target);
|
||||
else
|
||||
cmdq_error(item, "no current window");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
} else
|
||||
oo = wl->window->options;
|
||||
}
|
||||
@@ -158,8 +164,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
/* 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", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmdq_error(item, "not an array: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,18 +181,20 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
if (already) {
|
||||
if (args_has(args, 'q'))
|
||||
return (CMD_RETURN_NORMAL);
|
||||
cmdq_error(item, "already set: %s", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto out;
|
||||
cmdq_error(item, "already set: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
/* Change the option. */
|
||||
if (args_has(args, 'u')) {
|
||||
if (o == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
goto out;
|
||||
if (idx == -1) {
|
||||
if (oo == global_options ||
|
||||
if (*name == '@')
|
||||
options_remove(o);
|
||||
else if (oo == global_options ||
|
||||
oo == global_s_options ||
|
||||
oo == global_w_options)
|
||||
options_default(oo, options_table_entry(o));
|
||||
@@ -197,17 +205,17 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
} else if (*name == '@') {
|
||||
if (value == NULL) {
|
||||
cmdq_error(item, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
options_set_string(oo, name, append, "%s", value);
|
||||
} else if (idx == -1 && options_array_size(parent, NULL) == -1) {
|
||||
error = cmd_set_option_set(self, item, oo, parent, value);
|
||||
if (error != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
} else {
|
||||
if (value == NULL) {
|
||||
cmdq_error(item, "empty value");
|
||||
return (CMD_RETURN_ERROR);
|
||||
goto fail;
|
||||
}
|
||||
if (o == NULL)
|
||||
o = options_empty(oo, options_table_entry(parent));
|
||||
@@ -216,8 +224,8 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
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", args->argv[0]);
|
||||
return (CMD_RETURN_ERROR);
|
||||
cmdq_error(item, "invalid index: %s", argument);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,8 +239,14 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
}
|
||||
if (strcmp(name, "key-table") == 0) {
|
||||
TAILQ_FOREACH(c, &clients, entry)
|
||||
server_client_set_key_table(c, NULL);
|
||||
TAILQ_FOREACH(loop, &clients, entry)
|
||||
server_client_set_key_table(loop, NULL);
|
||||
}
|
||||
if (strcmp(name, "user-keys") == 0) {
|
||||
TAILQ_FOREACH(loop, &clients, entry) {
|
||||
if (loop->tty.flags & TTY_OPENED)
|
||||
tty_keys_build(&loop->tty);
|
||||
}
|
||||
}
|
||||
if (strcmp(name, "status") == 0 ||
|
||||
strcmp(name, "status-interval") == 0)
|
||||
@@ -248,7 +262,7 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
RB_FOREACH(w, windows, &windows)
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
}
|
||||
RB_FOREACH (s, sessions, &sessions)
|
||||
RB_FOREACH(s, sessions, &sessions)
|
||||
status_update_saved(s);
|
||||
|
||||
/*
|
||||
@@ -256,12 +270,22 @@ cmd_set_option_exec(struct cmd *self, struct cmdq_item *item)
|
||||
* anyway.
|
||||
*/
|
||||
recalculate_sizes();
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->session != NULL)
|
||||
server_redraw_client(c);
|
||||
TAILQ_FOREACH(loop, &clients, entry) {
|
||||
if (loop->session != NULL)
|
||||
server_redraw_client(loop);
|
||||
}
|
||||
|
||||
out:
|
||||
free(argument);
|
||||
free(value);
|
||||
free(name);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
fail:
|
||||
free(argument);
|
||||
free(value);
|
||||
free(name);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_environment_entry = {
|
||||
.args = { "gst:", 0, 1 },
|
||||
.usage = "[-gs] " CMD_TARGET_SESSION_USAGE " [name]",
|
||||
|
||||
.tflag = CMD_SESSION_CANFAIL,
|
||||
.target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_environment_exec
|
||||
@@ -97,7 +97,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
const char *target;
|
||||
|
||||
if ((target = args_get(args, 't')) != NULL) {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
if (item->target.s == NULL) {
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (args_has(self->args, 'g'))
|
||||
env = global_environ;
|
||||
else {
|
||||
if (item->state.tflag.s == NULL) {
|
||||
if (item->target.s == NULL) {
|
||||
target = args_get(args, 't');
|
||||
if (target != NULL)
|
||||
cmdq_error(item, "no such session: %s", target);
|
||||
@@ -114,7 +114,7 @@ cmd_show_environment_exec(struct cmd *self, struct cmdq_item *item)
|
||||
cmdq_error(item, "no current session");
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
env = item->state.tflag.s->environ;
|
||||
env = item->target.s->environ;
|
||||
}
|
||||
|
||||
if (args->argc != 0) {
|
||||
|
||||
@@ -38,8 +38,6 @@ const struct cmd_entry cmd_show_messages_entry = {
|
||||
.args = { "JTt:", 0, 0 },
|
||||
.usage = "[-JT] " CMD_TARGET_CLIENT_USAGE,
|
||||
|
||||
.tflag = CMD_CLIENT,
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_messages_exec
|
||||
};
|
||||
@@ -75,7 +73,7 @@ cmd_show_messages_jobs(struct cmdq_item *item, int blank)
|
||||
u_int n;
|
||||
|
||||
n = 0;
|
||||
LIST_FOREACH(job, &all_jobs, lentry) {
|
||||
LIST_FOREACH(job, &all_jobs, entry) {
|
||||
if (blank) {
|
||||
cmdq_print(item, "%s", "");
|
||||
blank = 0;
|
||||
@@ -91,11 +89,14 @@ static enum cmd_retval
|
||||
cmd_show_messages_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct client *c = item->state.c;
|
||||
struct client *c;
|
||||
struct message_entry *msg;
|
||||
char *tim;
|
||||
int done, blank;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 't'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
done = blank = 0;
|
||||
if (args_has(args, 'T')) {
|
||||
blank = cmd_show_messages_terminals(item, blank);
|
||||
|
||||
@@ -41,7 +41,7 @@ const struct cmd_entry cmd_show_options_entry = {
|
||||
.args = { "gqst:vw", 0, 1 },
|
||||
.usage = "[-gqsvw] [-t target-session|target-window] [option]",
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_options_exec
|
||||
@@ -54,7 +54,7 @@ const struct cmd_entry cmd_show_window_options_entry = {
|
||||
.args = { "gvt:", 0, 1 },
|
||||
.usage = "[-gv] " CMD_TARGET_WINDOW_USAGE " [option]",
|
||||
|
||||
.tflag = CMD_WINDOW_CANFAIL,
|
||||
.target = { 't', CMD_FIND_WINDOW, CMD_FIND_CANFAIL },
|
||||
|
||||
.flags = CMD_AFTERHOOK,
|
||||
.exec = cmd_show_options_exec
|
||||
@@ -64,7 +64,7 @@ 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->state.tflag;
|
||||
struct cmd_find_state *fs = &item->target;
|
||||
struct options *oo;
|
||||
enum options_table_scope scope;
|
||||
char *cause;
|
||||
@@ -127,25 +127,36 @@ 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;
|
||||
const char *name = args->argv[0];
|
||||
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'))
|
||||
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)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (*path == '/')
|
||||
pattern = xstrdup(path);
|
||||
else {
|
||||
utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB);
|
||||
utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB);
|
||||
xasprintf(&pattern, "%s/%s", tmp, path);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ const struct cmd_entry cmd_split_window_entry = {
|
||||
.usage = "[-bdfhvP] [-c start-directory] [-F format] "
|
||||
"[-p percentage|-l size] " CMD_TARGET_PANE_USAGE " [command]",
|
||||
|
||||
.tflag = CMD_PANE,
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_split_window_exec
|
||||
@@ -52,17 +52,18 @@ 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 client *c = item->state.c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
struct winlink *wl = item->state.tflag.wl;
|
||||
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->state.tflag.wp, *new_wp = NULL;
|
||||
struct window_pane *wp = item->target.wp, *new_wp = NULL;
|
||||
struct environ *env;
|
||||
const char *cmd, *path, *shell, *template, *cwd, *to_free;
|
||||
char **argv, *cause, *new_cause, *cp;
|
||||
const char *cmd, *path, *shell, *template, *tmp;
|
||||
char **argv, *cause, *new_cause, *cp, *cwd;
|
||||
u_int hlimit;
|
||||
int argc, size, percentage;
|
||||
int argc, size, percentage, before;
|
||||
enum layout_type type;
|
||||
struct layout_cell *lc;
|
||||
struct environ_entry *envent;
|
||||
@@ -84,18 +85,15 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
argv = args->argv;
|
||||
}
|
||||
|
||||
to_free = NULL;
|
||||
if (args_has(args, 'c')) {
|
||||
cwd = args_get(args, 'c');
|
||||
to_free = cwd = format_single(item, cwd, c, s, NULL, NULL);
|
||||
} else if (item->client != NULL && item->client->session == NULL)
|
||||
cwd = item->client->cwd;
|
||||
if ((tmp = args_get(args, 'c')) != NULL)
|
||||
cwd = format_single(item, tmp, c, s, NULL, NULL);
|
||||
else
|
||||
cwd = s->cwd;
|
||||
cwd = xstrdup(server_client_get_cwd(item->client, s));
|
||||
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
if (args_has(args, 'h'))
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
before = args_has(args, 'b');
|
||||
|
||||
size = -1;
|
||||
if (args_has(args, 'l')) {
|
||||
@@ -125,14 +123,13 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (*shell == '\0' || areshell(shell))
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
lc = layout_split_pane(wp, type, size, args_has(args, 'b'),
|
||||
args_has(args, 'f'));
|
||||
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, args_has(args, 'b'), hlimit);
|
||||
layout_assign_pane(lc, new_wp);
|
||||
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)
|
||||
@@ -142,7 +139,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (envent != NULL)
|
||||
path = envent->value;
|
||||
|
||||
env = environ_for_session(s);
|
||||
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);
|
||||
@@ -150,11 +147,13 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
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);
|
||||
@@ -168,17 +167,10 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
}
|
||||
notify_window("window-layout-changed", w);
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
|
||||
cmd_find_clear_state(&fs, NULL, 0);
|
||||
fs.s = s;
|
||||
fs.wl = wl;
|
||||
fs.w = w;
|
||||
fs.wp = new_wp;
|
||||
cmd_find_log_state(__func__, &fs);
|
||||
cmd_find_from_winlink_pane(&fs, wl, new_wp, 0);
|
||||
hooks_insert(s->hooks, item, &fs, "after-split-window");
|
||||
|
||||
free(cwd);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
||||
error:
|
||||
@@ -189,7 +181,6 @@ error:
|
||||
cmdq_error(item, "create pane failed: %s", cause);
|
||||
free(cause);
|
||||
|
||||
if (to_free != NULL)
|
||||
free((void *)to_free);
|
||||
free(cwd);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
12
cmd-string.c
12
cmd-string.c
@@ -159,21 +159,19 @@ cmd_string_parse(const char *s, const char *file, u_int line, char **cause)
|
||||
char **argv;
|
||||
|
||||
*cause = NULL;
|
||||
if (cmd_string_split(s, &argc, &argv) != 0)
|
||||
goto error;
|
||||
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);
|
||||
goto error;
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
cmd_free_argv(argc, argv);
|
||||
return (cmdlist);
|
||||
|
||||
error:
|
||||
xasprintf(cause, "invalid or unknown command: %s", s);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_pane_entry = {
|
||||
.args = { "dDs:t:U", 0, 0 },
|
||||
.usage = "[-dDU] " CMD_SRCDST_PANE_USAGE,
|
||||
|
||||
.sflag = CMD_PANE_MARKED,
|
||||
.tflag = CMD_PANE,
|
||||
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
|
||||
.target = { 't', CMD_FIND_PANE, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_swap_pane_exec
|
||||
@@ -50,10 +50,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct layout_cell *src_lc, *dst_lc;
|
||||
u_int sx, sy, xoff, yoff;
|
||||
|
||||
dst_w = item->state.tflag.wl->window;
|
||||
dst_wp = item->state.tflag.wp;
|
||||
src_w = item->state.sflag.wl->window;
|
||||
src_wp = item->state.sflag.wp;
|
||||
dst_w = item->target.wl->window;
|
||||
dst_wp = item->target.wp;
|
||||
src_w = item->source.wl->window;
|
||||
src_wp = item->source.wp;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
if (args_has(self->args, 'D')) {
|
||||
|
||||
@@ -35,8 +35,8 @@ const struct cmd_entry cmd_swap_window_entry = {
|
||||
.args = { "ds:t:", 0, 0 },
|
||||
.usage = "[-d] " CMD_SRCDST_WINDOW_USAGE,
|
||||
|
||||
.sflag = CMD_WINDOW_MARKED,
|
||||
.tflag = CMD_WINDOW,
|
||||
.source = { 's', CMD_FIND_WINDOW, CMD_FIND_DEFAULT_MARKED },
|
||||
.target = { 't', CMD_FIND_WINDOW, 0 },
|
||||
|
||||
.flags = 0,
|
||||
.exec = cmd_swap_window_exec
|
||||
@@ -50,12 +50,12 @@ cmd_swap_window_exec(struct cmd *self, struct cmdq_item *item)
|
||||
struct winlink *wl_src, *wl_dst;
|
||||
struct window *w_src, *w_dst;
|
||||
|
||||
wl_src = item->state.sflag.wl;
|
||||
src = item->state.sflag.s;
|
||||
wl_src = item->source.wl;
|
||||
src = item->source.s;
|
||||
sg_src = session_group_contains(src);
|
||||
|
||||
wl_dst = item->state.tflag.wl;
|
||||
dst = item->state.tflag.s;
|
||||
wl_dst = item->target.wl;
|
||||
dst = item->target.s;
|
||||
sg_dst = session_group_contains(dst);
|
||||
|
||||
if (src != dst && sg_src != NULL && sg_dst != NULL &&
|
||||
|
||||
@@ -38,8 +38,7 @@ const struct cmd_entry cmd_switch_client_entry = {
|
||||
.usage = "[-Elnpr] [-c target-client] [-t target-session] "
|
||||
"[-T key-table]",
|
||||
|
||||
.cflag = CMD_CLIENT,
|
||||
.tflag = CMD_SESSION_WITHPANE,
|
||||
/* -t is special */
|
||||
|
||||
.flags = CMD_READONLY,
|
||||
.exec = cmd_switch_client_exec
|
||||
@@ -49,13 +48,32 @@ static enum cmd_retval
|
||||
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct cmd_state *state = &item->state;
|
||||
struct client *c = state->c;
|
||||
struct session *s = item->state.tflag.s;
|
||||
const char *tflag = args_get(args, 't');
|
||||
enum cmd_find_type type;
|
||||
int flags;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
struct window_pane *wp;
|
||||
const char *tablename;
|
||||
struct key_table *table;
|
||||
|
||||
if ((c = cmd_find_client(item, args_get(args, 'c'), 0)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
if (tflag != NULL && tflag[strcspn(tflag, ":.")] != '\0') {
|
||||
type = CMD_FIND_PANE;
|
||||
flags = 0;
|
||||
} else {
|
||||
type = CMD_FIND_SESSION;
|
||||
flags = CMD_FIND_PREFER_UNATTACHED;
|
||||
}
|
||||
if (cmd_find_target(&item->target, item, tflag, type, flags) != 0)
|
||||
return (CMD_RETURN_ERROR);
|
||||
s = item->target.s;
|
||||
wl = item->target.wl;
|
||||
wp = item->target.wp;
|
||||
|
||||
if (args_has(args, 'r'))
|
||||
c->flags ^= CLIENT_READONLY;
|
||||
|
||||
@@ -94,11 +112,11 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
} else {
|
||||
if (item->client == NULL)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
if (state->tflag.wl != NULL) {
|
||||
wp = state->tflag.wp;
|
||||
if (wl != NULL) {
|
||||
if (wp != NULL)
|
||||
window_set_active_pane(wp->window, wp);
|
||||
session_set_current(s, state->tflag.wl);
|
||||
session_set_current(s, wl);
|
||||
cmd_find_from_session(&item->shared->current, s, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +126,10 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
|
||||
if (c->session != NULL && c->session != s)
|
||||
c->last_session = c->session;
|
||||
c->session = s;
|
||||
if (!item->repeat)
|
||||
if (~item->shared->flags & CMDQ_SHARED_REPEAT)
|
||||
server_client_set_key_table(c, NULL);
|
||||
status_timer_start(c);
|
||||
notify_client("client-session-changed", c);
|
||||
session_update_activity(s, NULL);
|
||||
gettimeofday(&s->last_attached_time, NULL);
|
||||
|
||||
|
||||
201
cmd.c
201
cmd.c
@@ -33,9 +33,7 @@ extern const struct cmd_entry cmd_break_pane_entry;
|
||||
extern const struct cmd_entry cmd_capture_pane_entry;
|
||||
extern const struct cmd_entry cmd_choose_buffer_entry;
|
||||
extern const struct cmd_entry cmd_choose_client_entry;
|
||||
extern const struct cmd_entry cmd_choose_session_entry;
|
||||
extern const struct cmd_entry cmd_choose_tree_entry;
|
||||
extern const struct cmd_entry cmd_choose_window_entry;
|
||||
extern const struct cmd_entry cmd_clear_history_entry;
|
||||
extern const struct cmd_entry cmd_clock_mode_entry;
|
||||
extern const struct cmd_entry cmd_command_prompt_entry;
|
||||
@@ -122,9 +120,7 @@ const struct cmd_entry *cmd_table[] = {
|
||||
&cmd_capture_pane_entry,
|
||||
&cmd_choose_buffer_entry,
|
||||
&cmd_choose_client_entry,
|
||||
&cmd_choose_session_entry,
|
||||
&cmd_choose_tree_entry,
|
||||
&cmd_choose_window_entry,
|
||||
&cmd_clear_history_entry,
|
||||
&cmd_clock_mode_entry,
|
||||
&cmd_command_prompt_entry,
|
||||
@@ -204,6 +200,15 @@ const struct cmd_entry *cmd_table[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
void
|
||||
cmd_log_argv(int argc, char **argv, const char *prefix)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
log_debug("%s: argv[%d]=%s", prefix, i, argv[i]);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
{
|
||||
@@ -212,6 +217,7 @@ cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
|
||||
|
||||
if (argc == 0)
|
||||
return (0);
|
||||
cmd_log_argv(argc, argv, __func__);
|
||||
|
||||
*buf = '\0';
|
||||
for (i = 0; i < argc; i++) {
|
||||
@@ -244,9 +250,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, __func__);
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -405,6 +413,7 @@ retry:
|
||||
xasprintf(cause, "unknown command: %s", name);
|
||||
return (NULL);
|
||||
}
|
||||
cmd_log_argv(argc, argv, entry->name);
|
||||
|
||||
args = args_parse(entry->args.template, argc, argv);
|
||||
if (args == NULL)
|
||||
@@ -447,190 +456,6 @@ usage:
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
cmd_prepare_state_flag(char c, const char *target, enum cmd_entry_flag flag,
|
||||
struct cmdq_item *item)
|
||||
{
|
||||
int targetflags, error;
|
||||
struct cmd_find_state *fs = NULL;
|
||||
struct cmd_find_state current;
|
||||
|
||||
if (flag == CMD_NONE ||
|
||||
flag == CMD_CLIENT ||
|
||||
flag == CMD_CLIENT_CANFAIL)
|
||||
return (0);
|
||||
|
||||
if (c == 't')
|
||||
fs = &item->state.tflag;
|
||||
else if (c == 's')
|
||||
fs = &item->state.sflag;
|
||||
|
||||
if (flag == CMD_SESSION_WITHPANE) {
|
||||
if (target != NULL && target[strcspn(target, ":.")] != '\0')
|
||||
flag = CMD_PANE;
|
||||
else
|
||||
flag = CMD_SESSION_PREFERUNATTACHED;
|
||||
}
|
||||
|
||||
targetflags = 0;
|
||||
switch (flag) {
|
||||
case CMD_SESSION:
|
||||
case CMD_SESSION_CANFAIL:
|
||||
case CMD_SESSION_PREFERUNATTACHED:
|
||||
case CMD_SESSION_WITHPANE:
|
||||
if (flag == CMD_SESSION_CANFAIL)
|
||||
targetflags |= CMD_FIND_QUIET;
|
||||
if (flag == CMD_SESSION_PREFERUNATTACHED)
|
||||
targetflags |= CMD_FIND_PREFER_UNATTACHED;
|
||||
break;
|
||||
case CMD_MOVEW_R:
|
||||
flag = CMD_WINDOW_INDEX;
|
||||
/* FALLTHROUGH */
|
||||
case CMD_WINDOW:
|
||||
case CMD_WINDOW_CANFAIL:
|
||||
case CMD_WINDOW_MARKED:
|
||||
case CMD_WINDOW_INDEX:
|
||||
if (flag == CMD_WINDOW_CANFAIL)
|
||||
targetflags |= CMD_FIND_QUIET;
|
||||
if (flag == CMD_WINDOW_MARKED)
|
||||
targetflags |= CMD_FIND_DEFAULT_MARKED;
|
||||
if (flag == CMD_WINDOW_INDEX)
|
||||
targetflags |= CMD_FIND_WINDOW_INDEX;
|
||||
break;
|
||||
case CMD_PANE:
|
||||
case CMD_PANE_CANFAIL:
|
||||
case CMD_PANE_MARKED:
|
||||
if (flag == CMD_PANE_CANFAIL)
|
||||
targetflags |= CMD_FIND_QUIET;
|
||||
if (flag == CMD_PANE_MARKED)
|
||||
targetflags |= CMD_FIND_DEFAULT_MARKED;
|
||||
break;
|
||||
default:
|
||||
fatalx("unknown %cflag %d", c, flag);
|
||||
}
|
||||
log_debug("%s: flag %c %d %#x", __func__, c, flag, targetflags);
|
||||
|
||||
error = cmd_find_current(¤t, item, targetflags);
|
||||
if (error != 0) {
|
||||
if (~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
cmd_find_clear_state(¤t, NULL, 0);
|
||||
}
|
||||
if (!cmd_find_empty_state(¤t) && !cmd_find_valid_state(¤t))
|
||||
fatalx("invalid current state");
|
||||
|
||||
switch (flag) {
|
||||
case CMD_NONE:
|
||||
case CMD_CLIENT:
|
||||
case CMD_CLIENT_CANFAIL:
|
||||
return (0);
|
||||
case CMD_SESSION:
|
||||
case CMD_SESSION_CANFAIL:
|
||||
case CMD_SESSION_PREFERUNATTACHED:
|
||||
case CMD_SESSION_WITHPANE:
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_SESSION, targetflags);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
case CMD_MOVEW_R:
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_SESSION, CMD_FIND_QUIET);
|
||||
if (error == 0)
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case CMD_WINDOW:
|
||||
case CMD_WINDOW_CANFAIL:
|
||||
case CMD_WINDOW_MARKED:
|
||||
case CMD_WINDOW_INDEX:
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_WINDOW, targetflags);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
case CMD_PANE:
|
||||
case CMD_PANE_CANFAIL:
|
||||
case CMD_PANE_MARKED:
|
||||
error = cmd_find_target(fs, ¤t, item, target,
|
||||
CMD_FIND_PANE, targetflags);
|
||||
if (error != 0)
|
||||
goto error;
|
||||
break;
|
||||
default:
|
||||
fatalx("unknown %cflag %d", c, flag);
|
||||
}
|
||||
return (0);
|
||||
|
||||
error:
|
||||
if (~targetflags & CMD_FIND_QUIET)
|
||||
return (-1);
|
||||
cmd_find_clear_state(fs, NULL, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
cmd_prepare_state(struct cmd *cmd, struct cmdq_item *item)
|
||||
{
|
||||
const struct cmd_entry *entry = cmd->entry;
|
||||
struct cmd_state *state = &item->state;
|
||||
char *tmp;
|
||||
enum cmd_entry_flag flag;
|
||||
const char *s;
|
||||
int error;
|
||||
|
||||
tmp = cmd_print(cmd);
|
||||
log_debug("preparing state for %s (client %p)", tmp, item->client);
|
||||
free(tmp);
|
||||
|
||||
state->c = NULL;
|
||||
cmd_find_clear_state(&state->tflag, NULL, 0);
|
||||
cmd_find_clear_state(&state->sflag, NULL, 0);
|
||||
|
||||
flag = cmd->entry->cflag;
|
||||
if (flag == CMD_NONE) {
|
||||
flag = cmd->entry->tflag;
|
||||
if (flag == CMD_CLIENT || flag == CMD_CLIENT_CANFAIL)
|
||||
s = args_get(cmd->args, 't');
|
||||
else
|
||||
s = NULL;
|
||||
} else
|
||||
s = args_get(cmd->args, 'c');
|
||||
switch (flag) {
|
||||
case CMD_CLIENT:
|
||||
state->c = cmd_find_client(item, s, 0);
|
||||
if (state->c == NULL)
|
||||
return (-1);
|
||||
break;
|
||||
default:
|
||||
state->c = cmd_find_client(item, s, 1);
|
||||
break;
|
||||
}
|
||||
log_debug("using client %p", state->c);
|
||||
|
||||
s = args_get(cmd->args, 't');
|
||||
log_debug("preparing -t state: target %s", s == NULL ? "none" : s);
|
||||
|
||||
error = cmd_prepare_state_flag('t', s, entry->tflag, item);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
s = args_get(cmd->args, 's');
|
||||
log_debug("preparing -s state: target %s", s == NULL ? "none" : s);
|
||||
|
||||
error = cmd_prepare_state_flag('s', s, entry->sflag, item);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
if (!cmd_find_empty_state(&state->tflag) &&
|
||||
!cmd_find_valid_state(&state->tflag))
|
||||
fatalx("invalid -t state");
|
||||
if (!cmd_find_empty_state(&state->sflag) &&
|
||||
!cmd_find_valid_state(&state->sflag))
|
||||
fatalx("invalid -s state");
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *
|
||||
cmd_print(struct cmd *cmd)
|
||||
{
|
||||
|
||||
22
compat.h
22
compat.h
@@ -18,6 +18,7 @@
|
||||
#define COMPAT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
#include <limits.h>
|
||||
@@ -100,17 +101,17 @@ void warnx(const char *, ...);
|
||||
#include <paths.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FORKPTY
|
||||
#ifdef HAVE_LIBUTIL_H
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PTY_H
|
||||
#include <pty.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UTIL_H
|
||||
#include <util.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_VIS
|
||||
#include <vis.h>
|
||||
@@ -260,6 +261,11 @@ size_t strnlen(const char *, size_t);
|
||||
char *strndup(const char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_MEMMEM
|
||||
/* memmem.c */
|
||||
void *memmem(const void *, size_t, const void *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DAEMON
|
||||
/* daemon.c */
|
||||
int daemon(int, int);
|
||||
@@ -283,9 +289,15 @@ int b64_ntop(const char *, size_t, char *, size_t);
|
||||
int b64_pton(const char *, u_char *, size_t);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FDFORKPTY
|
||||
/* fdforkpty.c */
|
||||
int getptmfd(void);
|
||||
pid_t fdforkpty(int, int *, char *, struct termios *,
|
||||
struct winsize *);
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FORKPTY
|
||||
/* forkpty.c */
|
||||
#include <sys/ioctl.h>
|
||||
pid_t forkpty(int *, char *, struct termios *, struct winsize *);
|
||||
#endif
|
||||
|
||||
@@ -337,9 +349,7 @@ int utf8proc_mbtowc(wchar_t *, const char *, size_t);
|
||||
int utf8proc_wctomb(char *, wchar_t);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETOPT
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#ifndef HAVE_GETOPT
|
||||
/* getopt.c */
|
||||
extern int BSDopterr;
|
||||
extern int BSDoptind;
|
||||
|
||||
85
compat/daemon-darwin.c
Normal file
85
compat/daemon-darwin.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2017 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2011-2013, Chris Johnsen <chris_johnsen@pobox.com>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <mach/mach.h>
|
||||
|
||||
#include <Availability.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void daemon_darwin(void);
|
||||
|
||||
#ifdef __MAC_10_10
|
||||
|
||||
extern kern_return_t bootstrap_look_up_per_user(mach_port_t, const char *,
|
||||
uid_t, mach_port_t *);
|
||||
extern kern_return_t bootstrap_get_root(mach_port_t, mach_port_t *);
|
||||
|
||||
void
|
||||
daemon_darwin(void)
|
||||
{
|
||||
mach_port_t root = MACH_PORT_NULL;
|
||||
mach_port_t s = MACH_PORT_NULL;
|
||||
uid_t uid;
|
||||
|
||||
uid = getuid();
|
||||
if (bootstrap_get_root(bootstrap_port, &root) == KERN_SUCCESS &&
|
||||
bootstrap_look_up_per_user(root, NULL, uid, &s) == KERN_SUCCESS &&
|
||||
task_set_bootstrap_port(mach_task_self(), s) == KERN_SUCCESS &&
|
||||
mach_port_deallocate(mach_task_self(), bootstrap_port) == KERN_SUCCESS)
|
||||
bootstrap_port = s;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void
|
||||
daemon_darwin(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -28,12 +28,18 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern void daemon_darwin(void);
|
||||
#endif
|
||||
|
||||
int
|
||||
daemon(int nochdir, int noclose)
|
||||
{
|
||||
@@ -61,5 +67,9 @@ daemon(int nochdir, int noclose)
|
||||
if (fd > 2)
|
||||
(void)close (fd);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
daemon_darwin();
|
||||
#endif
|
||||
return (0);
|
||||
}
|
||||
|
||||
34
compat/fdforkpty.c
Normal file
34
compat/fdforkpty.c
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2017 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 <limits.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
getptmfd(void)
|
||||
{
|
||||
return (INT_MAX);
|
||||
}
|
||||
|
||||
pid_t
|
||||
fdforkpty(__unused int ptmfd, int *master, char *name, struct termios *tio,
|
||||
struct winsize *ws)
|
||||
{
|
||||
return (forkpty(master, name, tio, ws));
|
||||
}
|
||||
@@ -29,7 +29,8 @@ void fatal(const char *, ...);
|
||||
void fatalx(const char *, ...);
|
||||
|
||||
pid_t
|
||||
forkpty(int *master, unused char *name, struct termios *tio, struct winsize *ws)
|
||||
forkpty(int *master, __unused char *name, struct termios *tio,
|
||||
struct winsize *ws)
|
||||
{
|
||||
int slave = -1, fd, pipe_fd[2];
|
||||
char *path, dummy;
|
||||
|
||||
@@ -30,19 +30,12 @@ getdtablecount(void)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
glob_t g;
|
||||
int n;
|
||||
int n = 0;
|
||||
|
||||
if (snprintf(path, sizeof path, "/proc/%ld/fd/*", (long)getpid()) < 0)
|
||||
fatal("snprintf overflow");
|
||||
switch (glob(path, 0, NULL, &g)) {
|
||||
case GLOB_NOMATCH:
|
||||
return (0);
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
fatal("glob(\"%s\") failed", path);
|
||||
}
|
||||
n = g.gl_pathc;
|
||||
if (glob(path, 0, NULL, &g) == 0)
|
||||
n = g.gl_pathc;
|
||||
globfree(&g);
|
||||
return (n);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
65
compat/memmem.c
Normal file
65
compat/memmem.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* $OpenBSD: memmem.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com>
|
||||
*
|
||||
* 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. 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 AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
/*
|
||||
* Find the first occurrence of the byte string s in byte string l.
|
||||
*/
|
||||
|
||||
void *
|
||||
memmem(const void *l, size_t l_len, const void *s, size_t s_len)
|
||||
{
|
||||
const char *cur, *last;
|
||||
const char *cl = l;
|
||||
const char *cs = s;
|
||||
|
||||
/* a zero length needle should just return the haystack */
|
||||
if (s_len == 0)
|
||||
return (void *)cl;
|
||||
|
||||
/* "s" must be smaller or equal to "l" */
|
||||
if (l_len < s_len)
|
||||
return NULL;
|
||||
|
||||
/* special case where s_len == 1 */
|
||||
if (s_len == 1)
|
||||
return memchr(l, *cs, l_len);
|
||||
|
||||
/* the last position where its possible to find "s" in "l" */
|
||||
last = cl + l_len - s_len;
|
||||
|
||||
for (cur = cl; cur <= last; cur++)
|
||||
if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
|
||||
return (void *)cur;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -15,13 +15,15 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compat.h"
|
||||
|
||||
int
|
||||
setenv(const char *name, const char *value, unused int overwrite)
|
||||
setenv(const char *name, const char *value, __unused int overwrite)
|
||||
{
|
||||
char *newval;
|
||||
|
||||
|
||||
48
configure.ac
48
configure.ac
@@ -1,6 +1,6 @@
|
||||
# configure.ac
|
||||
|
||||
AC_INIT(tmux, 2.4)
|
||||
AC_INIT(tmux, 2.8)
|
||||
AC_PREREQ([2.60])
|
||||
|
||||
AC_CONFIG_AUX_DIR(etc)
|
||||
@@ -35,6 +35,7 @@ AC_USE_SYSTEM_EXTENSIONS
|
||||
test "$sysconfdir" = '${prefix}/etc' && sysconfdir=/etc
|
||||
|
||||
# Is this --enable-debug?
|
||||
test "x$VERSION" = xmaster && enable_debug=yes
|
||||
AC_ARG_ENABLE(
|
||||
debug,
|
||||
AC_HELP_STRING(--enable-debug, enable debug build flags),
|
||||
@@ -103,10 +104,10 @@ AC_REPLACE_FUNCS([ \
|
||||
closefrom \
|
||||
explicit_bzero \
|
||||
fgetln \
|
||||
fparseln \
|
||||
freezero \
|
||||
getdtablecount \
|
||||
getprogname \
|
||||
memmem \
|
||||
recallocarray \
|
||||
reallocarray \
|
||||
setenv \
|
||||
@@ -175,7 +176,8 @@ if test "x$found_ncurses" = xno; then
|
||||
)
|
||||
fi
|
||||
if test "x$found_ncurses" = xyes; then
|
||||
CPPFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $CPPFLAGS"
|
||||
AM_CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $AM_CFLAGS"
|
||||
CFLAGS="$LIBNCURSES_CFLAGS $LIBTINFO_CFLAGS $CFLAGS"
|
||||
LIBS="$LIBNCURSES_LIBS $LIBTINFO_LIBS $LIBS"
|
||||
else
|
||||
# pkg-config didn't work, try ncurses.
|
||||
@@ -283,6 +285,7 @@ if test "x$found_b64_ntop" = xno; then
|
||||
AC_MSG_RESULT(no)
|
||||
|
||||
AC_MSG_CHECKING(for b64_ntop with -lresolv)
|
||||
OLD_LIBS="$LIBS"
|
||||
LIBS="$LIBS -lresolv"
|
||||
AC_TRY_LINK(
|
||||
[
|
||||
@@ -295,6 +298,7 @@ if test "x$found_b64_ntop" = xno; then
|
||||
found_b64_ntop=no
|
||||
)
|
||||
if test "x$found_b64_ntop" = xno; then
|
||||
LIBS="$OLD_LIBS"
|
||||
AC_MSG_RESULT(no)
|
||||
fi
|
||||
fi
|
||||
@@ -453,7 +457,21 @@ else
|
||||
AC_LIBOBJ(getopt)
|
||||
fi
|
||||
|
||||
# Look for forkpty in libutil. compat/forkpty-*.c is linked if not found.
|
||||
# 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
|
||||
AC_DEFINE(HAVE_FDFORKPTY)
|
||||
else
|
||||
AC_LIBOBJ(fdforkpty)
|
||||
fi
|
||||
AC_SEARCH_LIBS(forkpty, util, found_forkpty=yes, found_forkpty=no)
|
||||
if test "x$found_forkpty" = xyes; then
|
||||
AC_DEFINE(HAVE_FORKPTY)
|
||||
@@ -555,8 +573,15 @@ case "$host_os" in
|
||||
;;
|
||||
*darwin*)
|
||||
AC_MSG_RESULT(darwin)
|
||||
AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
|
||||
PLATFORM=darwin
|
||||
#
|
||||
# OS X CMSG_FIRSTHDR is broken, so redefine it with a working
|
||||
# one. daemon works but has some stupid side effects, so use
|
||||
# our internal version which has a workaround.
|
||||
#
|
||||
AC_DEFINE(BROKEN_CMSG_FIRSTHDR)
|
||||
AC_LIBOBJ(daemon)
|
||||
AC_LIBOBJ(daemon-darwin)
|
||||
;;
|
||||
*dragonfly*)
|
||||
AC_MSG_RESULT(dragonfly)
|
||||
@@ -585,13 +610,22 @@ 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)
|
||||
PLATFORM=hpux
|
||||
;;
|
||||
*cygwin*)
|
||||
*cygwin*|*msys*)
|
||||
AC_MSG_RESULT(cygwin)
|
||||
PLATFORM=cygwin
|
||||
;;
|
||||
|
||||
@@ -59,14 +59,27 @@ control_notify_input(struct client *c, struct window_pane *wp,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_pane_mode_changed(int pane)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%pane-mode-changed %%%u", pane);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_window_layout_changed(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
const char *template;
|
||||
char *cp;
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
struct winlink *wl;
|
||||
const char *template;
|
||||
char *cp;
|
||||
|
||||
template = "%layout-change #{window_id} #{window_layout} "
|
||||
"#{window_visible_layout} #{window_flags}";
|
||||
@@ -96,6 +109,20 @@ control_notify_window_layout_changed(struct window *w)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_window_pane_changed(struct window *w)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%window-pane-changed @%u %%%u", w->id,
|
||||
w->active->id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_window_unlinked(__unused struct session *s, struct window *w)
|
||||
{
|
||||
@@ -154,15 +181,27 @@ control_notify_window_renamed(struct window *w)
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_client_session_changed(struct client *c)
|
||||
control_notify_client_session_changed(struct client *cc)
|
||||
{
|
||||
struct client *c;
|
||||
struct session *s;
|
||||
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
if (cc->session == NULL)
|
||||
return;
|
||||
s = c->session;
|
||||
s = cc->session;
|
||||
|
||||
control_write(c, "%%session-changed $%u %s", s->id, s->name);
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
|
||||
continue;
|
||||
|
||||
if (cc == c) {
|
||||
control_write(c, "%%session-changed $%u %s", s->id,
|
||||
s->name);
|
||||
} else {
|
||||
control_write(c, "%%client-session-changed %s $%u %s",
|
||||
cc->name, s->id, s->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -203,3 +242,17 @@ control_notify_session_closed(__unused struct session *s)
|
||||
control_write(c, "%%sessions-changed");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
control_notify_session_window_changed(struct session *s)
|
||||
{
|
||||
struct client *c;
|
||||
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c))
|
||||
continue;
|
||||
|
||||
control_write(c, "%%session-window-changed $%u @%u", s->id,
|
||||
s->curw->window->id);
|
||||
}
|
||||
}
|
||||
|
||||
18
environ.c
18
environ.c
@@ -208,9 +208,15 @@ environ_push(struct environ *env)
|
||||
|
||||
/* Log the environment. */
|
||||
void
|
||||
environ_log(struct environ *env, const char *prefix)
|
||||
environ_log(struct environ *env, const char *fmt, ...)
|
||||
{
|
||||
struct environ_entry *envent;
|
||||
va_list ap;
|
||||
char *prefix;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vasprintf(&prefix, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
RB_FOREACH(envent, environ, env) {
|
||||
if (envent->value != NULL && *envent->name != '\0') {
|
||||
@@ -218,11 +224,13 @@ environ_log(struct environ *env, const char *prefix)
|
||||
envent->value);
|
||||
}
|
||||
}
|
||||
|
||||
free(prefix);
|
||||
}
|
||||
|
||||
/* Create initial environment for new child. */
|
||||
struct environ *
|
||||
environ_for_session(struct session *s)
|
||||
environ_for_session(struct session *s, int no_TERM)
|
||||
{
|
||||
struct environ *env;
|
||||
const char *value;
|
||||
@@ -233,8 +241,10 @@ environ_for_session(struct session *s)
|
||||
if (s != NULL)
|
||||
environ_copy(s->environ, env);
|
||||
|
||||
value = options_get_string(global_options, "default-terminal");
|
||||
environ_set(env, "TERM", "%s", value);
|
||||
if (!no_TERM) {
|
||||
value = options_get_string(global_options, "default-terminal");
|
||||
environ_set(env, "TERM", "%s", value);
|
||||
}
|
||||
|
||||
if (s != NULL)
|
||||
idx = s->id;
|
||||
|
||||
453
format.c
453
format.c
@@ -17,13 +17,12 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
#include <libgen.h>
|
||||
#include <netdb.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -40,32 +39,9 @@
|
||||
struct format_entry;
|
||||
typedef void (*format_cb)(struct format_tree *, struct format_entry *);
|
||||
|
||||
static void format_job_callback(struct job *);
|
||||
static char *format_job_get(struct format_tree *, const char *);
|
||||
static void format_job_timer(int, short, void *);
|
||||
|
||||
static void format_cb_host(struct format_tree *, struct format_entry *);
|
||||
static void format_cb_host_short(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_pid(struct format_tree *, struct format_entry *);
|
||||
static void format_cb_session_alerts(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_window_layout(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_window_visible_layout(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_start_command(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_current_command(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_history_bytes(struct format_tree *,
|
||||
struct format_entry *);
|
||||
static void format_cb_pane_tabs(struct format_tree *,
|
||||
struct format_entry *);
|
||||
|
||||
static void format_cb_current_path(struct format_tree *,
|
||||
struct format_entry *);
|
||||
|
||||
static char *format_find(struct format_tree *, const char *, int);
|
||||
static void format_add_cb(struct format_tree *, const char *, format_cb);
|
||||
static void format_add_tv(struct format_tree *, const char *,
|
||||
@@ -76,17 +52,19 @@ static int format_replace(struct format_tree *, const char *, size_t,
|
||||
static void format_defaults_session(struct format_tree *,
|
||||
struct session *);
|
||||
static void format_defaults_client(struct format_tree *, struct client *);
|
||||
static void format_defaults_winlink(struct format_tree *, struct session *,
|
||||
static void format_defaults_winlink(struct format_tree *,
|
||||
struct winlink *);
|
||||
|
||||
/* Entry in format job tree. */
|
||||
struct format_job {
|
||||
struct client *client;
|
||||
u_int tag;
|
||||
const char *cmd;
|
||||
const char *expanded;
|
||||
|
||||
time_t last;
|
||||
char *out;
|
||||
int updated;
|
||||
|
||||
struct job *job;
|
||||
int status;
|
||||
@@ -129,9 +107,11 @@ struct format_entry {
|
||||
/* Format entry tree. */
|
||||
struct format_tree {
|
||||
struct window *w;
|
||||
struct winlink *wl;
|
||||
struct session *s;
|
||||
struct window_pane *wp;
|
||||
|
||||
struct client *client;
|
||||
u_int tag;
|
||||
int flags;
|
||||
|
||||
@@ -207,17 +187,45 @@ static const char *format_lower[] = {
|
||||
NULL /* z */
|
||||
};
|
||||
|
||||
/* Format job callback. */
|
||||
/* Format job update callback. */
|
||||
static void
|
||||
format_job_callback(struct job *job)
|
||||
format_job_update(struct job *job)
|
||||
{
|
||||
struct format_job *fj = job->data;
|
||||
struct evbuffer *evb = job->event->input;
|
||||
char *line = NULL, *next;
|
||||
time_t t;
|
||||
|
||||
while ((next = evbuffer_readline(evb)) != NULL) {
|
||||
free(line);
|
||||
line = next;
|
||||
}
|
||||
if (line == NULL)
|
||||
return;
|
||||
fj->updated = 1;
|
||||
|
||||
free(fj->out);
|
||||
fj->out = line;
|
||||
|
||||
log_debug("%s: %p %s: %s", __func__, fj, fj->cmd, fj->out);
|
||||
|
||||
t = time(NULL);
|
||||
if (fj->status && fj->last != t) {
|
||||
if (fj->client != NULL)
|
||||
server_status_client(fj->client);
|
||||
fj->last = t;
|
||||
}
|
||||
}
|
||||
|
||||
/* Format job complete callback. */
|
||||
static void
|
||||
format_job_complete(struct job *job)
|
||||
{
|
||||
struct format_job *fj = job->data;
|
||||
char *line, *buf;
|
||||
size_t len;
|
||||
struct client *c;
|
||||
|
||||
fj->job = NULL;
|
||||
free(fj->out);
|
||||
|
||||
buf = NULL;
|
||||
if ((line = evbuffer_readline(job->event->input)) == NULL) {
|
||||
@@ -228,37 +236,53 @@ format_job_callback(struct job *job)
|
||||
buf[len] = '\0';
|
||||
} else
|
||||
buf = line;
|
||||
fj->out = buf;
|
||||
|
||||
log_debug("%s: %p %s: %s", __func__, fj, fj->cmd, buf);
|
||||
|
||||
if (*buf != '\0' || !fj->updated) {
|
||||
free(fj->out);
|
||||
fj->out = buf;
|
||||
} else
|
||||
free(buf);
|
||||
|
||||
if (fj->status) {
|
||||
TAILQ_FOREACH(c, &clients, entry)
|
||||
server_status_client(c);
|
||||
if (fj->client != NULL)
|
||||
server_status_client(fj->client);
|
||||
fj->status = 0;
|
||||
}
|
||||
|
||||
log_debug("%s: %s: %s", __func__, fj->cmd, fj->out);
|
||||
}
|
||||
|
||||
/* Find a job. */
|
||||
static char *
|
||||
format_job_get(struct format_tree *ft, const char *cmd)
|
||||
{
|
||||
struct format_job_tree *jobs;
|
||||
struct format_job fj0, *fj;
|
||||
time_t t;
|
||||
char *expanded;
|
||||
int force;
|
||||
|
||||
if (ft->client == NULL)
|
||||
jobs = &format_jobs;
|
||||
else if (ft->client->jobs != NULL)
|
||||
jobs = ft->client->jobs;
|
||||
else {
|
||||
jobs = ft->client->jobs = xmalloc(sizeof *ft->client->jobs);
|
||||
RB_INIT(jobs);
|
||||
}
|
||||
|
||||
fj0.tag = ft->tag;
|
||||
fj0.cmd = cmd;
|
||||
if ((fj = RB_FIND(format_job_tree, &format_jobs, &fj0)) == NULL) {
|
||||
if ((fj = RB_FIND(format_job_tree, jobs, &fj0)) == NULL) {
|
||||
fj = xcalloc(1, sizeof *fj);
|
||||
fj->client = ft->client;
|
||||
fj->tag = ft->tag;
|
||||
fj->cmd = xstrdup(cmd);
|
||||
fj->expanded = NULL;
|
||||
|
||||
xasprintf(&fj->out, "<'%s' not ready>", fj->cmd);
|
||||
|
||||
RB_INSERT(format_job_tree, &format_jobs, fj);
|
||||
RB_INSERT(format_job_tree, jobs, fj);
|
||||
}
|
||||
|
||||
expanded = format_expand(ft, cmd);
|
||||
@@ -271,13 +295,14 @@ format_job_get(struct format_tree *ft, const char *cmd)
|
||||
|
||||
t = time(NULL);
|
||||
if (fj->job == NULL && (force || fj->last != t)) {
|
||||
fj->job = job_run(expanded, NULL, NULL, format_job_callback,
|
||||
NULL, fj);
|
||||
fj->job = job_run(expanded, NULL, NULL, format_job_update,
|
||||
format_job_complete, NULL, fj, JOB_NOWAIT);
|
||||
if (fj->job == NULL) {
|
||||
free(fj->out);
|
||||
xasprintf(&fj->out, "<'%s' didn't start>", fj->cmd);
|
||||
}
|
||||
fj->last = t;
|
||||
fj->updated = 0;
|
||||
}
|
||||
|
||||
if (ft->flags & FORMAT_STATUS)
|
||||
@@ -289,17 +314,16 @@ format_job_get(struct format_tree *ft, const char *cmd)
|
||||
|
||||
/* Remove old jobs. */
|
||||
static void
|
||||
format_job_timer(__unused int fd, __unused short events, __unused void *arg)
|
||||
format_job_tidy(struct format_job_tree *jobs, int force)
|
||||
{
|
||||
struct format_job *fj, *fj1;
|
||||
time_t now;
|
||||
struct timeval tv = { .tv_sec = 60 };
|
||||
|
||||
now = time(NULL);
|
||||
RB_FOREACH_SAFE(fj, format_job_tree, &format_jobs, fj1) {
|
||||
if (fj->last > now || now - fj->last < 3600)
|
||||
RB_FOREACH_SAFE(fj, format_job_tree, jobs, fj1) {
|
||||
if (!force && (fj->last > now || now - fj->last < 3600))
|
||||
continue;
|
||||
RB_REMOVE(format_job_tree, &format_jobs, fj);
|
||||
RB_REMOVE(format_job_tree, jobs, fj);
|
||||
|
||||
log_debug("%s: %s", __func__, fj->cmd);
|
||||
|
||||
@@ -312,6 +336,29 @@ format_job_timer(__unused int fd, __unused short events, __unused void *arg)
|
||||
|
||||
free(fj);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove old jobs for client. */
|
||||
void
|
||||
format_lost_client(struct client *c)
|
||||
{
|
||||
if (c->jobs != NULL)
|
||||
format_job_tidy(c->jobs, 1);
|
||||
free(c->jobs);
|
||||
}
|
||||
|
||||
/* Remove old jobs periodically. */
|
||||
static void
|
||||
format_job_timer(__unused int fd, __unused short events, __unused void *arg)
|
||||
{
|
||||
struct client *c;
|
||||
struct timeval tv = { .tv_sec = 60 };
|
||||
|
||||
format_job_tidy(&format_jobs, 0);
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->jobs != NULL)
|
||||
format_job_tidy(c->jobs, 0);
|
||||
}
|
||||
|
||||
evtimer_del(&format_job_event);
|
||||
evtimer_add(&format_job_event, &tv);
|
||||
@@ -357,7 +404,7 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe)
|
||||
{
|
||||
struct session *s = ft->s;
|
||||
struct winlink *wl;
|
||||
char alerts[256], tmp[16];
|
||||
char alerts[1024], tmp[16];
|
||||
|
||||
if (s == NULL)
|
||||
return;
|
||||
@@ -381,6 +428,48 @@ format_cb_session_alerts(struct format_tree *ft, struct format_entry *fe)
|
||||
fe->value = xstrdup(alerts);
|
||||
}
|
||||
|
||||
/* Callback for session_stack. */
|
||||
static void
|
||||
format_cb_session_stack(struct format_tree *ft, struct format_entry *fe)
|
||||
{
|
||||
struct session *s = ft->s;
|
||||
struct winlink *wl;
|
||||
char result[1024], tmp[16];
|
||||
|
||||
if (s == NULL)
|
||||
return;
|
||||
|
||||
xsnprintf(result, sizeof result, "%u", s->curw->idx);
|
||||
TAILQ_FOREACH(wl, &s->lastw, sentry) {
|
||||
xsnprintf(tmp, sizeof tmp, "%u", wl->idx);
|
||||
|
||||
if (*result != '\0')
|
||||
strlcat(result, ",", sizeof result);
|
||||
strlcat(result, tmp, sizeof result);
|
||||
}
|
||||
fe->value = xstrdup(result);
|
||||
}
|
||||
|
||||
/* Callback for window_stack_index. */
|
||||
static void
|
||||
format_cb_window_stack_index(struct format_tree *ft, struct format_entry *fe)
|
||||
{
|
||||
struct session *s = ft->wl->session;
|
||||
struct winlink *wl;
|
||||
u_int idx;
|
||||
|
||||
idx = 0;
|
||||
TAILQ_FOREACH(wl, &s->lastw, sentry) {
|
||||
idx++;
|
||||
if (wl == ft->wl)
|
||||
break;
|
||||
}
|
||||
if (wl != NULL)
|
||||
xasprintf(&fe->value, "%u", idx);
|
||||
else
|
||||
fe->value = xstrdup("0");
|
||||
}
|
||||
|
||||
/* Callback for window_layout. */
|
||||
static void
|
||||
format_cb_window_layout(struct format_tree *ft, struct format_entry *fe)
|
||||
@@ -444,7 +533,7 @@ format_cb_current_command(struct format_tree *ft, struct format_entry *fe)
|
||||
}
|
||||
|
||||
/* Callback for pane_current_path. */
|
||||
void
|
||||
static void
|
||||
format_cb_current_path(struct format_tree *ft, struct format_entry *fe)
|
||||
{
|
||||
struct window_pane *wp = ft->wp;
|
||||
@@ -474,11 +563,11 @@ format_cb_history_bytes(struct format_tree *ft, struct format_entry *fe)
|
||||
|
||||
size = 0;
|
||||
for (i = 0; i < gd->hsize; i++) {
|
||||
gl = &gd->linedata[i];
|
||||
gl = grid_get_line(gd, i);
|
||||
size += gl->cellsize * sizeof *gl->celldata;
|
||||
size += gl->extdsize * sizeof *gl->extddata;
|
||||
}
|
||||
size += gd->hsize * sizeof *gd->linedata;
|
||||
size += gd->hsize * sizeof *gl;
|
||||
|
||||
xasprintf(&fe->value, "%llu", size);
|
||||
}
|
||||
@@ -504,8 +593,35 @@ format_cb_pane_tabs(struct format_tree *ft, struct format_entry *fe)
|
||||
evbuffer_add(buffer, ",", 1);
|
||||
evbuffer_add_printf(buffer, "%u", i);
|
||||
}
|
||||
size = EVBUFFER_LENGTH(buffer);
|
||||
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
||||
if ((size = EVBUFFER_LENGTH(buffer)) != 0)
|
||||
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
||||
evbuffer_free(buffer);
|
||||
}
|
||||
|
||||
/* Callback for session_group_list. */
|
||||
static void
|
||||
format_cb_session_group_list(struct format_tree *ft, struct format_entry *fe)
|
||||
{
|
||||
struct session *s = ft->s;
|
||||
struct session_group *sg;
|
||||
struct session *loop;
|
||||
struct evbuffer *buffer;
|
||||
int size;
|
||||
|
||||
if (s == NULL)
|
||||
return;
|
||||
sg = session_group_contains(s);
|
||||
if (sg == NULL)
|
||||
return;
|
||||
|
||||
buffer = evbuffer_new();
|
||||
TAILQ_FOREACH(loop, &sg->sessions, gentry) {
|
||||
if (EVBUFFER_LENGTH(buffer) > 0)
|
||||
evbuffer_add(buffer, ",", 1);
|
||||
evbuffer_add_printf(buffer, "%s", loop->name);
|
||||
}
|
||||
if ((size = EVBUFFER_LENGTH(buffer)) != 0)
|
||||
xasprintf(&fe->value, "%.*s", size, EVBUFFER_DATA(buffer));
|
||||
evbuffer_free(buffer);
|
||||
}
|
||||
|
||||
@@ -523,7 +639,7 @@ format_merge(struct format_tree *ft, struct format_tree *from)
|
||||
|
||||
/* Create a new tree. */
|
||||
struct format_tree *
|
||||
format_create(struct cmdq_item *item, int tag, int flags)
|
||||
format_create(struct client *c, struct cmdq_item *item, int tag, int flags)
|
||||
{
|
||||
struct format_tree *ft;
|
||||
|
||||
@@ -535,6 +651,11 @@ format_create(struct cmdq_item *item, int tag, int flags)
|
||||
ft = xcalloc(1, sizeof *ft);
|
||||
RB_INIT(&ft->tree);
|
||||
|
||||
if (c != NULL) {
|
||||
ft->client = c;
|
||||
ft->client->references++;
|
||||
}
|
||||
|
||||
ft->tag = tag;
|
||||
ft->flags = flags;
|
||||
|
||||
@@ -545,10 +666,12 @@ format_create(struct cmdq_item *item, int tag, int flags)
|
||||
format_add(ft, "socket_path", "%s", socket_path);
|
||||
format_add_tv(ft, "start_time", &start_time);
|
||||
|
||||
if (item != NULL && item->cmd != NULL)
|
||||
format_add(ft, "command", "%s", item->cmd->entry->name);
|
||||
if (item != NULL && item->formats != NULL)
|
||||
format_merge(ft, item->formats);
|
||||
if (item != NULL) {
|
||||
if (item->cmd != NULL)
|
||||
format_add(ft, "command", "%s", item->cmd->entry->name);
|
||||
if (item->shared != NULL && item->shared->formats != NULL)
|
||||
format_merge(ft, item->shared->formats);
|
||||
}
|
||||
|
||||
return (ft);
|
||||
}
|
||||
@@ -566,6 +689,8 @@ format_free(struct format_tree *ft)
|
||||
free(fe);
|
||||
}
|
||||
|
||||
if (ft->client != NULL)
|
||||
server_client_unref(ft->client);
|
||||
free(ft);
|
||||
}
|
||||
|
||||
@@ -689,8 +814,11 @@ format_find(struct format_tree *ft, const char *key, int modifiers)
|
||||
found = s;
|
||||
goto found;
|
||||
}
|
||||
if (fe->value == NULL && fe->cb != NULL)
|
||||
if (fe->value == NULL && fe->cb != NULL) {
|
||||
fe->cb(ft, fe);
|
||||
if (fe->value == NULL)
|
||||
fe->value = xstrdup("");
|
||||
}
|
||||
found = fe->value;
|
||||
goto found;
|
||||
}
|
||||
@@ -726,18 +854,22 @@ found:
|
||||
return (copy);
|
||||
}
|
||||
|
||||
/* Skip until comma. */
|
||||
static char *
|
||||
format_skip(char *s)
|
||||
/* Skip until end. */
|
||||
static const char *
|
||||
format_skip(const char *s, char end)
|
||||
{
|
||||
int brackets = 0;
|
||||
|
||||
for (; *s != '\0'; s++) {
|
||||
if (*s == '{')
|
||||
if (*s == '#' && s[1] == '{')
|
||||
brackets++;
|
||||
if (*s == '#' && strchr(",#{}", s[1]) != NULL) {
|
||||
s++;
|
||||
continue;
|
||||
}
|
||||
if (*s == '}')
|
||||
brackets--;
|
||||
if (*s == ',' && brackets == 0)
|
||||
if (*s == end && brackets == 0)
|
||||
break;
|
||||
}
|
||||
if (*s == '\0')
|
||||
@@ -751,7 +883,7 @@ format_choose(char *s, char **left, char **right)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
cp = format_skip(s);
|
||||
cp = (char *)format_skip(s, ',');
|
||||
if (cp == NULL)
|
||||
return (-1);
|
||||
*cp = '\0';
|
||||
@@ -762,7 +894,7 @@ format_choose(char *s, char **left, char **right)
|
||||
}
|
||||
|
||||
/* Is this true? */
|
||||
static int
|
||||
int
|
||||
format_true(const char *s)
|
||||
{
|
||||
if (s != NULL && *s != '\0' && (s[0] != '0' || s[1] != '\0'))
|
||||
@@ -770,19 +902,18 @@ format_true(const char *s)
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace a key/value pair in buffer. #{blah} is expanded directly,
|
||||
* #{?blah,a,b} is replace with a if blah exists and is nonzero else b.
|
||||
*/
|
||||
/* Replace a key. */
|
||||
static int
|
||||
format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
char **buf, size_t *len, size_t *off)
|
||||
{
|
||||
char *copy, *copy0, *endptr, *ptr, *found, *new, *value;
|
||||
char *from = NULL, *to = NULL, *left, *right;
|
||||
size_t valuelen, newlen, fromlen, tolen, used;
|
||||
long limit = 0;
|
||||
int modifiers = 0, compare = 0;
|
||||
struct window_pane *wp = ft->wp;
|
||||
char *copy, *copy0, *endptr, *ptr, *found, *new, sep;
|
||||
char *value, *from = NULL, *to = NULL, *left, *right;
|
||||
size_t valuelen, newlen, fromlen, tolen, used;
|
||||
long limit = 0;
|
||||
int modifiers = 0, compare = 0, search = 0;
|
||||
int literal = 0;
|
||||
|
||||
/* Make a copy of the key. */
|
||||
copy0 = copy = xmalloc(keylen + 1);
|
||||
@@ -791,6 +922,36 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
|
||||
/* Is there a length limit or whatnot? */
|
||||
switch (copy[0]) {
|
||||
case 'l':
|
||||
if (copy[1] != ':')
|
||||
break;
|
||||
literal = 1;
|
||||
copy += 2;
|
||||
break;
|
||||
case 'm':
|
||||
if (copy[1] != ':')
|
||||
break;
|
||||
compare = -2;
|
||||
copy += 2;
|
||||
break;
|
||||
case 'C':
|
||||
if (copy[1] != ':')
|
||||
break;
|
||||
search = 1;
|
||||
copy += 2;
|
||||
break;
|
||||
case '|':
|
||||
if (copy[1] != '|' || copy[2] != ':')
|
||||
break;
|
||||
compare = -3;
|
||||
copy += 3;
|
||||
break;
|
||||
case '&':
|
||||
if (copy[1] != '&' || copy[2] != ':')
|
||||
break;
|
||||
compare = -4;
|
||||
copy += 3;
|
||||
break;
|
||||
case '!':
|
||||
if (copy[1] == '=' && copy[2] == ':') {
|
||||
compare = -1;
|
||||
@@ -831,20 +992,21 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
copy += 2;
|
||||
break;
|
||||
case 's':
|
||||
if (copy[1] != '/')
|
||||
sep = copy[1];
|
||||
if (sep == ':' || !ispunct((u_char)sep))
|
||||
break;
|
||||
from = copy + 2;
|
||||
for (copy = from; *copy != '\0' && *copy != '/'; copy++)
|
||||
for (copy = from; *copy != '\0' && *copy != sep; copy++)
|
||||
/* nothing */;
|
||||
if (copy[0] != '/' || copy == from) {
|
||||
if (copy[0] != sep || copy == from) {
|
||||
copy = copy0;
|
||||
break;
|
||||
}
|
||||
copy[0] = '\0';
|
||||
to = copy + 1;
|
||||
for (copy = to; *copy != '\0' && *copy != '/'; copy++)
|
||||
for (copy = to; *copy != '\0' && *copy != sep; copy++)
|
||||
/* nothing */;
|
||||
if (copy[0] != '/' || copy[1] != ':') {
|
||||
if (copy[0] != sep || copy[1] != ':') {
|
||||
copy = copy0;
|
||||
break;
|
||||
}
|
||||
@@ -855,31 +1017,61 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
break;
|
||||
}
|
||||
|
||||
/* Is this a literal string? */
|
||||
if (literal) {
|
||||
value = xstrdup(copy);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Is this a comparison or a conditional? */
|
||||
if (compare != 0) {
|
||||
if (search) {
|
||||
/* Search in pane. */
|
||||
if (wp == NULL)
|
||||
value = xstrdup("0");
|
||||
else
|
||||
xasprintf(&value, "%u", window_pane_search(wp, copy));
|
||||
} else if (compare != 0) {
|
||||
/* Comparison: compare comma-separated left and right. */
|
||||
if (format_choose(copy, &left, &right) != 0)
|
||||
goto fail;
|
||||
left = format_expand(ft, left);
|
||||
right = format_expand(ft, right);
|
||||
if (compare == 1 && strcmp(left, right) == 0)
|
||||
if (compare == -3 &&
|
||||
(format_true(left) || format_true(right)))
|
||||
value = xstrdup("1");
|
||||
else if (compare == -4 &&
|
||||
(format_true(left) && format_true(right)))
|
||||
value = xstrdup("1");
|
||||
else if (compare == 1 && strcmp(left, right) == 0)
|
||||
value = xstrdup("1");
|
||||
else if (compare == -1 && strcmp(left, right) != 0)
|
||||
value = xstrdup("1");
|
||||
else if (compare == -2 && fnmatch(left, right, 0) == 0)
|
||||
value = xstrdup("1");
|
||||
else
|
||||
value = xstrdup("0");
|
||||
free(right);
|
||||
free(left);
|
||||
} else if (*copy == '?') {
|
||||
/* Conditional: check first and choose second or third. */
|
||||
ptr = format_skip(copy);
|
||||
ptr = (char *)format_skip(copy, ',');
|
||||
if (ptr == NULL)
|
||||
goto fail;
|
||||
*ptr = '\0';
|
||||
|
||||
found = format_find(ft, copy + 1, modifiers);
|
||||
if (found == NULL)
|
||||
if (found == NULL) {
|
||||
/*
|
||||
* If the conditional not found, try to expand it. If
|
||||
* the expansion doesn't have any effect, then assume
|
||||
* false.
|
||||
*/
|
||||
found = format_expand(ft, copy + 1);
|
||||
if (strcmp(found, copy + 1) == 0) {
|
||||
free(found);
|
||||
found = xstrdup("");
|
||||
}
|
||||
}
|
||||
if (format_choose(ptr + 1, &left, &right) != 0)
|
||||
goto fail;
|
||||
|
||||
@@ -934,6 +1126,7 @@ format_replace(struct format_tree *ft, const char *key, size_t keylen,
|
||||
value = new;
|
||||
}
|
||||
|
||||
done:
|
||||
/* Expand the buffer and copy in the value. */
|
||||
valuelen = strlen(value);
|
||||
while (*len - *off < valuelen + 1) {
|
||||
@@ -974,7 +1167,7 @@ format_expand_time(struct format_tree *ft, const char *fmt, time_t t)
|
||||
char *
|
||||
format_expand(struct format_tree *ft, const char *fmt)
|
||||
{
|
||||
char *buf, *out;
|
||||
char *buf, *out, *name;
|
||||
const char *ptr, *s, *saved = fmt;
|
||||
size_t off, len, n, outlen;
|
||||
int ch, brackets;
|
||||
@@ -1013,8 +1206,11 @@ format_expand(struct format_tree *ft, const char *fmt)
|
||||
|
||||
if (ft->flags & FORMAT_NOJOBS)
|
||||
out = xstrdup("");
|
||||
else
|
||||
out = format_job_get(ft, xstrndup(fmt, n));
|
||||
else {
|
||||
name = xstrndup(fmt, n);
|
||||
out = format_job_get(ft, name);
|
||||
free(name);
|
||||
}
|
||||
outlen = strlen(out);
|
||||
|
||||
while (len - off < outlen + 1) {
|
||||
@@ -1029,14 +1225,8 @@ format_expand(struct format_tree *ft, const char *fmt)
|
||||
fmt += n + 1;
|
||||
continue;
|
||||
case '{':
|
||||
brackets = 1;
|
||||
for (ptr = fmt; *ptr != '\0'; ptr++) {
|
||||
if (*ptr == '{')
|
||||
brackets++;
|
||||
if (*ptr == '}' && --brackets == 0)
|
||||
break;
|
||||
}
|
||||
if (*ptr != '}' || brackets != 0)
|
||||
ptr = format_skip(fmt - 2, '}');
|
||||
if (ptr == NULL)
|
||||
break;
|
||||
n = ptr - fmt;
|
||||
|
||||
@@ -1044,12 +1234,14 @@ format_expand(struct format_tree *ft, const char *fmt)
|
||||
break;
|
||||
fmt += n + 1;
|
||||
continue;
|
||||
case '}':
|
||||
case '#':
|
||||
case ',':
|
||||
while (len - off < 2) {
|
||||
buf = xreallocarray(buf, 2, len);
|
||||
len *= 2;
|
||||
}
|
||||
buf[off++] = '#';
|
||||
buf[off++] = ch;
|
||||
continue;
|
||||
default:
|
||||
s = NULL;
|
||||
@@ -1088,7 +1280,10 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c,
|
||||
struct format_tree *ft;
|
||||
char *expanded;
|
||||
|
||||
ft = format_create(item, FORMAT_NONE, 0);
|
||||
if (item != NULL)
|
||||
ft = format_create(item->client, item, FORMAT_NONE, 0);
|
||||
else
|
||||
ft = format_create(NULL, item, FORMAT_NONE, 0);
|
||||
format_defaults(ft, c, s, wl, wp);
|
||||
|
||||
expanded = format_expand(ft, fmt);
|
||||
@@ -1101,6 +1296,13 @@ void
|
||||
format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
||||
struct winlink *wl, struct window_pane *wp)
|
||||
{
|
||||
if (c != NULL && s != NULL && c->session != s)
|
||||
log_debug("%s: session does not match", __func__);
|
||||
|
||||
format_add(ft, "session_format", "%d", s != NULL);
|
||||
format_add(ft, "window_format", "%d", wl != NULL);
|
||||
format_add(ft, "pane_format", "%d", wp != NULL);
|
||||
|
||||
if (s == NULL && c != NULL)
|
||||
s = c->session;
|
||||
if (wl == NULL && s != NULL)
|
||||
@@ -1112,8 +1314,8 @@ format_defaults(struct format_tree *ft, struct client *c, struct session *s,
|
||||
format_defaults_client(ft, c);
|
||||
if (s != NULL)
|
||||
format_defaults_session(ft, s);
|
||||
if (s != NULL && wl != NULL)
|
||||
format_defaults_winlink(ft, s, wl);
|
||||
if (wl != NULL)
|
||||
format_defaults_winlink(ft, wl);
|
||||
if (wp != NULL)
|
||||
format_defaults_pane(ft, wp);
|
||||
}
|
||||
@@ -1134,8 +1336,13 @@ format_defaults_session(struct format_tree *ft, struct session *s)
|
||||
|
||||
sg = session_group_contains(s);
|
||||
format_add(ft, "session_grouped", "%d", sg != NULL);
|
||||
if (sg != NULL)
|
||||
if (sg != NULL) {
|
||||
format_add(ft, "session_group", "%s", sg->name);
|
||||
format_add(ft, "session_group_size", "%u",
|
||||
session_group_count (sg));
|
||||
format_add_cb(ft, "session_group_list",
|
||||
format_cb_session_group_list);
|
||||
}
|
||||
|
||||
format_add_tv(ft, "session_created", &s->creation_time);
|
||||
format_add_tv(ft, "session_last_attached", &s->last_attached_time);
|
||||
@@ -1145,6 +1352,7 @@ format_defaults_session(struct format_tree *ft, struct session *s)
|
||||
format_add(ft, "session_many_attached", "%d", s->attached > 1);
|
||||
|
||||
format_add_cb(ft, "session_alerts", format_cb_session_alerts);
|
||||
format_add_cb(ft, "session_stack", format_cb_session_stack);
|
||||
}
|
||||
|
||||
/* Set default format keys for a client. */
|
||||
@@ -1174,7 +1382,9 @@ format_defaults_client(struct format_tree *ft, struct client *c)
|
||||
|
||||
format_add_tv(ft, "client_created", &c->creation_time);
|
||||
format_add_tv(ft, "client_activity", &c->activity_time);
|
||||
format_add(ft, "client_written", "%zu", tty->written);
|
||||
|
||||
format_add(ft, "client_written", "%zu", c->written);
|
||||
format_add(ft, "client_discarded", "%zu", c->discarded);
|
||||
|
||||
name = server_client_get_key_table(c);
|
||||
if (strcmp(c->keytable->name, name) == 0)
|
||||
@@ -1222,21 +1432,20 @@ format_defaults_window(struct format_tree *ft, struct window *w)
|
||||
|
||||
/* Set default format keys for a winlink. */
|
||||
static void
|
||||
format_defaults_winlink(struct format_tree *ft, struct session *s,
|
||||
struct winlink *wl)
|
||||
format_defaults_winlink(struct format_tree *ft, struct winlink *wl)
|
||||
{
|
||||
struct session *s = wl->session;
|
||||
struct window *w = wl->window;
|
||||
char *flags;
|
||||
|
||||
if (ft->w == NULL)
|
||||
ft->w = wl->window;
|
||||
|
||||
flags = window_printable_flags(s, wl);
|
||||
ft->wl = wl;
|
||||
|
||||
format_defaults_window(ft, w);
|
||||
|
||||
format_add(ft, "window_index", "%d", wl->idx);
|
||||
format_add(ft, "window_flags", "%s", flags);
|
||||
format_add_cb(ft, "window_stack_index", format_cb_window_stack_index);
|
||||
format_add(ft, "window_flags", "%s", window_printable_flags(wl));
|
||||
format_add(ft, "window_active", "%d", wl == s->curw);
|
||||
|
||||
format_add(ft, "window_bell_flag", "%d",
|
||||
@@ -1248,8 +1457,6 @@ format_defaults_winlink(struct format_tree *ft, struct session *s,
|
||||
format_add(ft, "window_last_flag", "%d",
|
||||
!!(wl == TAILQ_FIRST(&s->lastw)));
|
||||
format_add(ft, "window_linked", "%d", session_is_linked(s, wl->window));
|
||||
|
||||
free(flags);
|
||||
}
|
||||
|
||||
/* Set default format keys for a window pane. */
|
||||
@@ -1257,8 +1464,8 @@ void
|
||||
format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||
{
|
||||
struct grid *gd = wp->base.grid;
|
||||
int status = wp->status;
|
||||
u_int idx;
|
||||
int status, scroll_position;
|
||||
|
||||
if (ft->w == NULL)
|
||||
ft->w = wp->window;
|
||||
@@ -1278,9 +1485,9 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||
format_add(ft, "pane_id", "%%%u", wp->id);
|
||||
format_add(ft, "pane_active", "%d", wp == wp->window->active);
|
||||
format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF));
|
||||
format_add(ft, "pane_pipe", "%d", wp->pipe_fd != -1);
|
||||
|
||||
status = wp->status;
|
||||
if (wp->fd == -1 && WIFEXITED(status))
|
||||
if ((wp->flags & PANE_STATUSREADY) && WIFEXITED(status))
|
||||
format_add(ft, "pane_dead_status", "%d", WEXITSTATUS(status));
|
||||
format_add(ft, "pane_dead", "%d", wp->fd == -1);
|
||||
|
||||
@@ -1289,11 +1496,22 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||
format_add(ft, "pane_top", "%u", wp->yoff);
|
||||
format_add(ft, "pane_right", "%u", wp->xoff + wp->sx - 1);
|
||||
format_add(ft, "pane_bottom", "%u", wp->yoff + wp->sy - 1);
|
||||
format_add(ft, "pane_at_left", "%d", wp->xoff == 0);
|
||||
format_add(ft, "pane_at_top", "%d", wp->yoff == 0);
|
||||
format_add(ft, "pane_at_right", "%d",
|
||||
wp->xoff + wp->sx == wp->window->sx);
|
||||
format_add(ft, "pane_at_bottom", "%d",
|
||||
wp->yoff + wp->sy == wp->window->sy);
|
||||
}
|
||||
|
||||
format_add(ft, "pane_in_mode", "%d", wp->screen != &wp->base);
|
||||
if (wp->mode != NULL)
|
||||
format_add(ft, "pane_mode", "%s", wp->mode->name);
|
||||
|
||||
format_add(ft, "pane_synchronized", "%d",
|
||||
!!options_get_number(wp->window->options, "synchronize-panes"));
|
||||
if (wp->searchstr != NULL)
|
||||
format_add(ft, "pane_search_string", "%s", wp->searchstr);
|
||||
|
||||
format_add(ft, "pane_tty", "%s", wp->tty);
|
||||
format_add(ft, "pane_pid", "%ld", (long) wp->pid);
|
||||
@@ -1306,9 +1524,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||
format_add(ft, "scroll_region_upper", "%u", wp->base.rupper);
|
||||
format_add(ft, "scroll_region_lower", "%u", wp->base.rlower);
|
||||
|
||||
scroll_position = window_copy_scroll_position(wp);
|
||||
if (scroll_position != -1)
|
||||
format_add(ft, "scroll_position", "%d", scroll_position);
|
||||
window_copy_add_formats(wp, ft);
|
||||
|
||||
format_add(ft, "alternate_on", "%d", wp->saved_grid ? 1 : 0);
|
||||
format_add(ft, "alternate_saved_x", "%u", wp->saved_cx);
|
||||
@@ -1341,12 +1557,17 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp)
|
||||
void
|
||||
format_defaults_paste_buffer(struct format_tree *ft, struct paste_buffer *pb)
|
||||
{
|
||||
size_t bufsize;
|
||||
char *s;
|
||||
struct timeval tv;
|
||||
size_t size;
|
||||
char *s;
|
||||
|
||||
paste_buffer_data(pb, &bufsize);
|
||||
format_add(ft, "buffer_size", "%zu", bufsize);
|
||||
timerclear(&tv);
|
||||
tv.tv_sec = paste_buffer_created(pb);
|
||||
paste_buffer_data(pb, &size);
|
||||
|
||||
format_add(ft, "buffer_size", "%zu", size);
|
||||
format_add(ft, "buffer_name", "%s", paste_buffer_name(pb));
|
||||
format_add_tv(ft, "buffer_created", &tv);
|
||||
|
||||
s = paste_make_sample(pb);
|
||||
format_add(ft, "buffer_sample", "%s", s);
|
||||
|
||||
20
grid-view.c
20
grid-view.c
@@ -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;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ grid_view_clear_history(struct grid *gd, u_int bg)
|
||||
|
||||
/* Scroll the lines into the history. */
|
||||
for (yy = 0; yy < last; yy++) {
|
||||
grid_collect_history(gd, bg);
|
||||
grid_collect_history(gd);
|
||||
grid_scroll_history(gd, bg);
|
||||
}
|
||||
if (last < gd->sy)
|
||||
@@ -96,32 +96,34 @@ grid_view_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny,
|
||||
|
||||
/* Scroll region up. */
|
||||
void
|
||||
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower)
|
||||
grid_view_scroll_region_up(struct grid *gd, u_int rupper, u_int rlower,
|
||||
u_int bg)
|
||||
{
|
||||
if (gd->flags & GRID_HISTORY) {
|
||||
grid_collect_history(gd, 8);
|
||||
grid_collect_history(gd);
|
||||
if (rupper == 0 && rlower == gd->sy - 1)
|
||||
grid_scroll_history(gd, 8);
|
||||
grid_scroll_history(gd, bg);
|
||||
else {
|
||||
rupper = grid_view_y(gd, rupper);
|
||||
rlower = grid_view_y(gd, rlower);
|
||||
grid_scroll_history_region(gd, rupper, rlower);
|
||||
grid_scroll_history_region(gd, rupper, rlower, bg);
|
||||
}
|
||||
} else {
|
||||
rupper = grid_view_y(gd, rupper);
|
||||
rlower = grid_view_y(gd, rlower);
|
||||
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, 8);
|
||||
grid_move_lines(gd, rupper, rupper + 1, rlower - rupper, bg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Scroll region down. */
|
||||
void
|
||||
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower)
|
||||
grid_view_scroll_region_down(struct grid *gd, u_int rupper, u_int rlower,
|
||||
u_int bg)
|
||||
{
|
||||
rupper = grid_view_y(gd, rupper);
|
||||
rlower = grid_view_y(gd, rlower);
|
||||
|
||||
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, 8);
|
||||
grid_move_lines(gd, rupper + 1, rupper, rlower - rupper, bg);
|
||||
}
|
||||
|
||||
/* Insert lines. */
|
||||
|
||||
764
grid.c
764
grid.c
@@ -43,22 +43,8 @@ static const struct grid_cell_entry grid_default_entry = {
|
||||
0, { .data = { 0, 8, 8, ' ' } }
|
||||
};
|
||||
|
||||
static void grid_expand_line(struct grid *, u_int, u_int, u_int);
|
||||
static void grid_empty_line(struct grid *, u_int, u_int);
|
||||
|
||||
static void grid_reflow_copy(struct grid_line *, u_int, struct grid_line *,
|
||||
u_int, u_int);
|
||||
static void grid_reflow_join(struct grid *, u_int *, struct grid_line *,
|
||||
u_int);
|
||||
static void grid_reflow_split(struct grid *, u_int *, struct grid_line *,
|
||||
u_int, u_int);
|
||||
static void grid_reflow_move(struct grid *, u_int *, struct grid_line *);
|
||||
|
||||
static size_t grid_string_cells_fg(const struct grid_cell *, int *);
|
||||
static size_t grid_string_cells_bg(const struct grid_cell *, int *);
|
||||
static void grid_string_cells_code(const struct grid_cell *,
|
||||
const struct grid_cell *, char *, size_t, int);
|
||||
|
||||
/* Store cell in entry. */
|
||||
static void
|
||||
grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
|
||||
@@ -89,11 +75,53 @@ grid_need_extended_cell(const struct grid_cell_entry *gce,
|
||||
return (1);
|
||||
if (gc->data.size != 1 || gc->data.width != 1)
|
||||
return (1);
|
||||
if ((gc->fg & COLOUR_FLAG_RGB) ||(gc->bg & COLOUR_FLAG_RGB))
|
||||
if ((gc->fg & COLOUR_FLAG_RGB) || (gc->bg & COLOUR_FLAG_RGB))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Free up unused extended cells. */
|
||||
static void
|
||||
grid_compact_line(struct grid_line *gl)
|
||||
{
|
||||
int new_extdsize = 0;
|
||||
struct grid_cell *new_extddata;
|
||||
struct grid_cell_entry *gce;
|
||||
struct grid_cell *gc;
|
||||
u_int px, idx;
|
||||
|
||||
if (gl->extdsize == 0)
|
||||
return;
|
||||
|
||||
for (px = 0; px < gl->cellsize; px++) {
|
||||
gce = &gl->celldata[px];
|
||||
if (gce->flags & GRID_FLAG_EXTENDED)
|
||||
new_extdsize++;
|
||||
}
|
||||
|
||||
if (new_extdsize == 0) {
|
||||
free(gl->extddata);
|
||||
gl->extddata = NULL;
|
||||
gl->extdsize = 0;
|
||||
return;
|
||||
}
|
||||
new_extddata = xreallocarray(NULL, new_extdsize, sizeof *gl->extddata);
|
||||
|
||||
idx = 0;
|
||||
for (px = 0; px < gl->cellsize; px++) {
|
||||
gce = &gl->celldata[px];
|
||||
if (gce->flags & GRID_FLAG_EXTENDED) {
|
||||
gc = &gl->extddata[gce->offset];
|
||||
memcpy(&new_extddata[idx], gc, sizeof *gc);
|
||||
gce->offset = idx++;
|
||||
}
|
||||
}
|
||||
|
||||
free(gl->extddata);
|
||||
gl->extddata = new_extddata;
|
||||
gl->extdsize = new_extdsize;
|
||||
}
|
||||
|
||||
/* Set cell as extended. */
|
||||
static struct grid_cell *
|
||||
grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
@@ -117,6 +145,20 @@ grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
|
||||
return (gcp);
|
||||
}
|
||||
|
||||
/* Get line data. */
|
||||
struct grid_line *
|
||||
grid_get_line(struct grid *gd, u_int line)
|
||||
{
|
||||
return (&gd->linedata[line]);
|
||||
}
|
||||
|
||||
/* 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. */
|
||||
static void
|
||||
grid_clear_cell(struct grid *gd, u_int px, u_int py, u_int bg)
|
||||
@@ -138,10 +180,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);
|
||||
if (py >= gd->hsize + gd->sy) {
|
||||
log_debug("%s: y out of range: %u", from, py);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
@@ -162,6 +204,26 @@ grid_cells_equal(const struct grid_cell *gca, const struct grid_cell *gcb)
|
||||
return (memcmp(gca->data.data, gcb->data.data, gca->data.size) == 0);
|
||||
}
|
||||
|
||||
/* Free one line. */
|
||||
static void
|
||||
grid_free_line(struct grid *gd, u_int py)
|
||||
{
|
||||
free(gd->linedata[py].celldata);
|
||||
gd->linedata[py].celldata = NULL;
|
||||
free(gd->linedata[py].extddata);
|
||||
gd->linedata[py].extddata = NULL;
|
||||
}
|
||||
|
||||
/* Free several lines. */
|
||||
static void
|
||||
grid_free_lines(struct grid *gd, u_int py, u_int ny)
|
||||
{
|
||||
u_int yy;
|
||||
|
||||
for (yy = py; yy < py + ny; yy++)
|
||||
grid_free_line(gd, yy);
|
||||
}
|
||||
|
||||
/* Create a new grid. */
|
||||
struct grid *
|
||||
grid_create(u_int sx, u_int sy, u_int hlimit)
|
||||
@@ -178,7 +240,10 @@ grid_create(u_int sx, u_int sy, u_int hlimit)
|
||||
gd->hsize = 0;
|
||||
gd->hlimit = hlimit;
|
||||
|
||||
gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
|
||||
if (gd->sy != 0)
|
||||
gd->linedata = xcalloc(gd->sy, sizeof *gd->linedata);
|
||||
else
|
||||
gd->linedata = NULL;
|
||||
|
||||
return (gd);
|
||||
}
|
||||
@@ -187,14 +252,7 @@ grid_create(u_int sx, u_int sy, u_int hlimit)
|
||||
void
|
||||
grid_destroy(struct grid *gd)
|
||||
{
|
||||
struct grid_line *gl;
|
||||
u_int yy;
|
||||
|
||||
for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
|
||||
gl = &gd->linedata[yy];
|
||||
free(gl->celldata);
|
||||
free(gl->extddata);
|
||||
}
|
||||
grid_free_lines(gd, 0, gd->hsize + gd->sy);
|
||||
|
||||
free(gd->linedata);
|
||||
|
||||
@@ -228,24 +286,40 @@ 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.
|
||||
*/
|
||||
void
|
||||
grid_collect_history(struct grid *gd, u_int bg)
|
||||
grid_collect_history(struct grid *gd)
|
||||
{
|
||||
u_int yy;
|
||||
u_int ny;
|
||||
|
||||
if (gd->hsize < gd->hlimit)
|
||||
if (gd->hsize == 0 || gd->hsize < gd->hlimit)
|
||||
return;
|
||||
|
||||
yy = gd->hlimit / 10;
|
||||
if (yy < 1)
|
||||
yy = 1;
|
||||
ny = gd->hlimit / 10;
|
||||
if (ny < 1)
|
||||
ny = 1;
|
||||
if (ny > gd->hsize)
|
||||
ny = gd->hsize;
|
||||
|
||||
grid_move_lines(gd, 0, yy, gd->hsize + gd->sy - yy, bg);
|
||||
gd->hsize -= yy;
|
||||
/*
|
||||
* Free the lines from 0 to ny then move the remaining lines over
|
||||
* them.
|
||||
*/
|
||||
grid_trim_history(gd, ny);
|
||||
|
||||
gd->hsize -= ny;
|
||||
if (gd->hscrolled > gd->hsize)
|
||||
gd->hscrolled = gd->hsize;
|
||||
}
|
||||
@@ -265,6 +339,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
||||
grid_empty_line(gd, yy, bg);
|
||||
|
||||
gd->hscrolled++;
|
||||
grid_compact_line(&gd->linedata[gd->hsize]);
|
||||
gd->hsize++;
|
||||
}
|
||||
|
||||
@@ -272,8 +347,7 @@ grid_scroll_history(struct grid *gd, u_int bg)
|
||||
void
|
||||
grid_clear_history(struct grid *gd)
|
||||
{
|
||||
grid_clear_lines(gd, 0, gd->hsize, 8);
|
||||
grid_move_lines(gd, 0, gd->hsize, gd->sy, 8);
|
||||
grid_trim_history(gd, gd->hsize);
|
||||
|
||||
gd->hscrolled = 0;
|
||||
gd->hsize = 0;
|
||||
@@ -284,9 +358,9 @@ grid_clear_history(struct grid *gd)
|
||||
|
||||
/* Scroll a region up, moving the top line into the history. */
|
||||
void
|
||||
grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
|
||||
grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower, u_int bg)
|
||||
{
|
||||
struct grid_line *gl_history, *gl_upper, *gl_lower;
|
||||
struct grid_line *gl_history, *gl_upper;
|
||||
u_int yy;
|
||||
|
||||
/* Create a space for a new line. */
|
||||
@@ -302,14 +376,13 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
|
||||
upper++;
|
||||
gl_upper = &gd->linedata[upper];
|
||||
lower++;
|
||||
gl_lower = &gd->linedata[lower];
|
||||
|
||||
/* Move the line into the history. */
|
||||
memcpy(gl_history, gl_upper, sizeof *gl_history);
|
||||
|
||||
/* Then move the region up and clear the bottom line. */
|
||||
memmove(gl_upper, gl_upper + 1, (lower - upper) * sizeof *gl_upper);
|
||||
memset(gl_lower, 0, sizeof *gl_lower);
|
||||
grid_empty_line(gd, lower, bg);
|
||||
|
||||
/* Move the history offset down over the line. */
|
||||
gd->hscrolled++;
|
||||
@@ -353,25 +426,16 @@ 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]);
|
||||
}
|
||||
|
||||
/* Get cell for reading. */
|
||||
void
|
||||
grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
||||
/* Get cell from line. */
|
||||
static void
|
||||
grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
|
||||
{
|
||||
struct grid_line *gl;
|
||||
struct grid_cell_entry *gce;
|
||||
|
||||
if (grid_check_y(gd, py) != 0 || px >= gd->linedata[py].cellsize) {
|
||||
memcpy(gc, &grid_default_cell, sizeof *gc);
|
||||
return;
|
||||
}
|
||||
|
||||
gl = &gd->linedata[py];
|
||||
gce = &gl->celldata[px];
|
||||
struct grid_cell_entry *gce = &gl->celldata[px];
|
||||
|
||||
if (gce->flags & GRID_FLAG_EXTENDED) {
|
||||
if (gce->offset >= gl->extdsize)
|
||||
@@ -392,6 +456,18 @@ grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
||||
utf8_set(&gc->data, gce->data.data);
|
||||
}
|
||||
|
||||
/* Get cell for reading. */
|
||||
void
|
||||
grid_get_cell(struct grid *gd, u_int px, u_int py, struct grid_cell *gc)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/* Set cell at relative position. */
|
||||
void
|
||||
grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
|
||||
@@ -399,7 +475,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);
|
||||
@@ -425,7 +501,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);
|
||||
@@ -458,9 +534,9 @@ 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++) {
|
||||
@@ -472,7 +548,7 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
|
||||
gd->linedata[yy].cellsize = px;
|
||||
continue;
|
||||
}
|
||||
grid_expand_line(gd, yy, px + nx, bg);
|
||||
grid_expand_line(gd, yy, px + nx, 8); /* default bg first */
|
||||
for (xx = px; xx < px + nx; xx++)
|
||||
grid_clear_cell(gd, xx, yy, bg);
|
||||
}
|
||||
@@ -482,21 +558,18 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny, u_int bg)
|
||||
void
|
||||
grid_clear_lines(struct grid *gd, u_int py, u_int ny, u_int bg)
|
||||
{
|
||||
struct grid_line *gl;
|
||||
u_int yy;
|
||||
u_int yy;
|
||||
|
||||
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++) {
|
||||
gl = &gd->linedata[yy];
|
||||
free(gl->celldata);
|
||||
free(gl->extddata);
|
||||
grid_free_line(gd, yy);
|
||||
grid_empty_line(gd, yy, bg);
|
||||
}
|
||||
}
|
||||
@@ -510,26 +583,29 @@ 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. */
|
||||
for (yy = dy; yy < dy + ny; yy++) {
|
||||
if (yy >= py && yy < py + ny)
|
||||
continue;
|
||||
grid_clear_lines(gd, yy, 1, bg);
|
||||
grid_free_line(gd, yy);
|
||||
}
|
||||
|
||||
memmove(&gd->linedata[dy], &gd->linedata[py],
|
||||
ny * (sizeof *gd->linedata));
|
||||
|
||||
/* Wipe any lines that have been moved (without freeing them). */
|
||||
/*
|
||||
* Wipe any lines that have been moved (without freeing them - they are
|
||||
* still present).
|
||||
*/
|
||||
for (yy = py; yy < py + ny; yy++) {
|
||||
if (yy < dy || yy >= dy + ny)
|
||||
grid_empty_line(gd, yy, bg);
|
||||
@@ -547,7 +623,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];
|
||||
|
||||
@@ -666,8 +742,7 @@ grid_string_cells_bg(const struct grid_cell *gc, int *values)
|
||||
|
||||
/*
|
||||
* Returns ANSI code to set particular attributes (colour, bold and so on)
|
||||
* given a current state. The output buffer must be able to hold at least 57
|
||||
* bytes.
|
||||
* given a current state.
|
||||
*/
|
||||
static void
|
||||
grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
@@ -675,8 +750,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
{
|
||||
int oldc[64], newc[64], s[128];
|
||||
size_t noldc, nnewc, n, i;
|
||||
u_int attr = gc->attr;
|
||||
u_int lastattr = lastgc->attr;
|
||||
u_int attr = gc->attr, lastattr = lastgc->attr;
|
||||
char tmp[64];
|
||||
|
||||
struct {
|
||||
@@ -708,23 +782,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
s[n++] = attrs[i].code;
|
||||
}
|
||||
|
||||
/* If the foreground colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_fg(gc, newc);
|
||||
noldc = grid_string_cells_fg(lastgc, oldc);
|
||||
if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
|
||||
for (i = 0; i < nnewc; i++)
|
||||
s[n++] = newc[i];
|
||||
}
|
||||
|
||||
/* If the background colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_bg(gc, newc);
|
||||
noldc = grid_string_cells_bg(lastgc, oldc);
|
||||
if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
|
||||
for (i = 0; i < nnewc; i++)
|
||||
s[n++] = newc[i];
|
||||
}
|
||||
|
||||
/* If there are any parameters, append an SGR code. */
|
||||
/* Write the attributes. */
|
||||
*buf = '\0';
|
||||
if (n > 0) {
|
||||
if (escape_c0)
|
||||
@@ -741,16 +799,56 @@ grid_string_cells_code(const struct grid_cell *lastgc,
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
|
||||
/* If the foreground colour changed, write its parameters. */
|
||||
nnewc = grid_string_cells_fg(gc, newc);
|
||||
noldc = grid_string_cells_fg(lastgc, oldc);
|
||||
if (nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < nnewc; i++) {
|
||||
if (i + 1 < nnewc)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
|
||||
else
|
||||
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
|
||||
strlcat(buf, tmp, len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
|
||||
/* If the background colour changed, append its parameters. */
|
||||
nnewc = grid_string_cells_bg(gc, newc);
|
||||
noldc = grid_string_cells_bg(lastgc, oldc);
|
||||
if (nnewc != noldc ||
|
||||
memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0 ||
|
||||
(n != 0 && s[0] == 0)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\033[", len);
|
||||
else
|
||||
strlcat(buf, "\033[", len);
|
||||
for (i = 0; i < nnewc; i++) {
|
||||
if (i + 1 < nnewc)
|
||||
xsnprintf(tmp, sizeof tmp, "%d;", newc[i]);
|
||||
else
|
||||
xsnprintf(tmp, sizeof tmp, "%d", newc[i]);
|
||||
strlcat(buf, tmp, len);
|
||||
}
|
||||
strlcat(buf, "m", len);
|
||||
}
|
||||
|
||||
/* Append shift in/shift out if needed. */
|
||||
if ((attr & GRID_ATTR_CHARSET) && !(lastattr & GRID_ATTR_CHARSET)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\016", len); /* SO */
|
||||
strlcat(buf, "\\016", len); /* SO */
|
||||
else
|
||||
strlcat(buf, "\016", len); /* SO */
|
||||
}
|
||||
if (!(attr & GRID_ATTR_CHARSET) && (lastattr & GRID_ATTR_CHARSET)) {
|
||||
if (escape_c0)
|
||||
strlcat(buf, "\\017", len); /* SI */
|
||||
strlcat(buf, "\\017", len); /* SI */
|
||||
else
|
||||
strlcat(buf, "\017", len); /* SI */
|
||||
}
|
||||
@@ -824,9 +922,8 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
|
||||
}
|
||||
|
||||
/*
|
||||
* Duplicate a set of lines between two grids. If there aren't enough lines in
|
||||
* either source or destination, the number of lines is limited to the number
|
||||
* available.
|
||||
* Duplicate a set of lines between two grids. Both source and destination
|
||||
* should be big enough.
|
||||
*/
|
||||
void
|
||||
grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
|
||||
@@ -839,7 +936,7 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
|
||||
ny = dst->hsize + dst->sy - dy;
|
||||
if (sy + ny > src->hsize + src->sy)
|
||||
ny = src->hsize + src->sy - sy;
|
||||
grid_clear_lines(dst, dy, ny, 8);
|
||||
grid_free_lines(dst, dy, ny);
|
||||
|
||||
for (yy = 0; yy < ny; yy++) {
|
||||
srcl = &src->linedata[sy];
|
||||
@@ -867,164 +964,327 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
|
||||
}
|
||||
}
|
||||
|
||||
/* Copy a section of a line. */
|
||||
/* Mark line as dead. */
|
||||
static void
|
||||
grid_reflow_copy(struct grid_line *dst_gl, u_int to, struct grid_line *src_gl,
|
||||
u_int from, u_int to_copy)
|
||||
grid_reflow_dead(struct grid_line *gl)
|
||||
{
|
||||
struct grid_cell_entry *gce;
|
||||
u_int i, was;
|
||||
memset(gl, 0, sizeof *gl);
|
||||
gl->flags = GRID_LINE_DEAD;
|
||||
}
|
||||
|
||||
memcpy(&dst_gl->celldata[to], &src_gl->celldata[from],
|
||||
to_copy * sizeof *dst_gl->celldata);
|
||||
/* Add lines, return the first new one. */
|
||||
static struct grid_line *
|
||||
grid_reflow_add(struct grid *gd, u_int n)
|
||||
{
|
||||
struct grid_line *gl;
|
||||
u_int sy = gd->sy + n;
|
||||
|
||||
for (i = to; i < to + to_copy; i++) {
|
||||
gce = &dst_gl->celldata[i];
|
||||
if (~gce->flags & GRID_FLAG_EXTENDED)
|
||||
gd->linedata = xreallocarray(gd->linedata, sy, sizeof *gd->linedata);
|
||||
gl = &gd->linedata[gd->sy];
|
||||
memset(gl, 0, n * (sizeof *gl));
|
||||
gd->sy = sy;
|
||||
return (gl);
|
||||
}
|
||||
|
||||
/* Move a line across. */
|
||||
static struct grid_line *
|
||||
grid_reflow_move(struct grid *gd, struct grid_line *from)
|
||||
{
|
||||
struct grid_line *to;
|
||||
|
||||
to = grid_reflow_add(gd, 1);
|
||||
memcpy(to, from, sizeof *to);
|
||||
grid_reflow_dead(from);
|
||||
return (to);
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
struct grid_line *gl, *from = NULL;
|
||||
struct grid_cell gc;
|
||||
u_int lines, left, i, to, line, want = 0;
|
||||
u_int at;
|
||||
int wrapped = 1;
|
||||
|
||||
/*
|
||||
* Add a new target line.
|
||||
*/
|
||||
if (!already) {
|
||||
to = target->sy;
|
||||
gl = grid_reflow_move(target, &gd->linedata[yy]);
|
||||
} else {
|
||||
to = target->sy - 1;
|
||||
gl = &target->linedata[to];
|
||||
}
|
||||
at = gl->cellused;
|
||||
|
||||
/*
|
||||
* Loop until no more to consume or the target line is full.
|
||||
*/
|
||||
lines = 0;
|
||||
for (;;) {
|
||||
/*
|
||||
* If this is now the last line, there is nothing more to be
|
||||
* done.
|
||||
*/
|
||||
if (yy + 1 + lines == gd->hsize + gd->sy)
|
||||
break;
|
||||
line = yy + 1 + lines;
|
||||
|
||||
/* If the next line is empty, skip it. */
|
||||
if (~gd->linedata[line].flags & GRID_LINE_WRAPPED)
|
||||
wrapped = 0;
|
||||
if (gd->linedata[line].cellused == 0) {
|
||||
if (!wrapped)
|
||||
break;
|
||||
lines++;
|
||||
continue;
|
||||
was = gce->offset;
|
||||
|
||||
dst_gl->extddata = xreallocarray(dst_gl->extddata,
|
||||
dst_gl->extdsize + 1, sizeof *dst_gl->extddata);
|
||||
gce->offset = dst_gl->extdsize++;
|
||||
memcpy(&dst_gl->extddata[gce->offset], &src_gl->extddata[was],
|
||||
sizeof *dst_gl->extddata);
|
||||
}
|
||||
}
|
||||
|
||||
/* Join line data. */
|
||||
static void
|
||||
grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
|
||||
u_int new_x)
|
||||
{
|
||||
struct grid_line *dst_gl = &dst->linedata[(*py) - 1];
|
||||
u_int left, to_copy, ox, nx;
|
||||
|
||||
/* How much is left on the old line? */
|
||||
left = new_x - dst_gl->cellused;
|
||||
|
||||
/* Work out how much to append. */
|
||||
to_copy = src_gl->cellused;
|
||||
if (to_copy > left)
|
||||
to_copy = left;
|
||||
ox = dst_gl->cellused;
|
||||
nx = ox + to_copy;
|
||||
|
||||
/* Resize the destination line. */
|
||||
dst_gl->celldata = xreallocarray(dst_gl->celldata, nx,
|
||||
sizeof *dst_gl->celldata);
|
||||
dst_gl->cellsize = dst_gl->cellused = nx;
|
||||
|
||||
/* Append as much as possible. */
|
||||
grid_reflow_copy(dst_gl, ox, src_gl, 0, to_copy);
|
||||
|
||||
/* If there is any left in the source, split it. */
|
||||
if (src_gl->cellused > to_copy) {
|
||||
dst_gl->flags |= GRID_LINE_WRAPPED;
|
||||
|
||||
src_gl->cellused -= to_copy;
|
||||
grid_reflow_split(dst, py, src_gl, new_x, to_copy);
|
||||
}
|
||||
}
|
||||
|
||||
/* Split line data. */
|
||||
static void
|
||||
grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
|
||||
u_int new_x, u_int offset)
|
||||
{
|
||||
struct grid_line *dst_gl = NULL;
|
||||
u_int to_copy;
|
||||
|
||||
/* Loop and copy sections of the source line. */
|
||||
while (src_gl->cellused > 0) {
|
||||
/* Create new line. */
|
||||
if (*py >= dst->hsize + dst->sy)
|
||||
grid_scroll_history(dst, 8);
|
||||
dst_gl = &dst->linedata[*py];
|
||||
(*py)++;
|
||||
|
||||
/* How much should we copy? */
|
||||
to_copy = new_x;
|
||||
if (to_copy > src_gl->cellused)
|
||||
to_copy = src_gl->cellused;
|
||||
|
||||
/* Expand destination line. */
|
||||
dst_gl->celldata = xreallocarray(NULL, to_copy,
|
||||
sizeof *dst_gl->celldata);
|
||||
dst_gl->cellsize = dst_gl->cellused = to_copy;
|
||||
dst_gl->flags |= GRID_LINE_WRAPPED;
|
||||
|
||||
/* Copy the data. */
|
||||
grid_reflow_copy(dst_gl, 0, src_gl, offset, to_copy);
|
||||
|
||||
/* Move offset and reduce old line size. */
|
||||
offset += to_copy;
|
||||
src_gl->cellused -= to_copy;
|
||||
}
|
||||
|
||||
/* Last line is not wrapped. */
|
||||
if (dst_gl != NULL)
|
||||
dst_gl->flags &= ~GRID_LINE_WRAPPED;
|
||||
}
|
||||
|
||||
/* Move line data. */
|
||||
static void
|
||||
grid_reflow_move(struct grid *dst, u_int *py, struct grid_line *src_gl)
|
||||
{
|
||||
struct grid_line *dst_gl;
|
||||
|
||||
/* Create new line. */
|
||||
if (*py >= dst->hsize + dst->sy)
|
||||
grid_scroll_history(dst, 8);
|
||||
dst_gl = &dst->linedata[*py];
|
||||
(*py)++;
|
||||
|
||||
/* Copy the old line. */
|
||||
memcpy(dst_gl, src_gl, sizeof *dst_gl);
|
||||
dst_gl->flags &= ~GRID_LINE_WRAPPED;
|
||||
|
||||
/* Clear old line. */
|
||||
src_gl->celldata = NULL;
|
||||
src_gl->extddata = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reflow lines from src grid into dst grid of width new_x. Returns number of
|
||||
* lines fewer in the visible area. The source grid is destroyed.
|
||||
*/
|
||||
u_int
|
||||
grid_reflow(struct grid *dst, struct grid *src, u_int new_x)
|
||||
{
|
||||
u_int py, sy, line;
|
||||
int previous_wrapped;
|
||||
struct grid_line *src_gl;
|
||||
|
||||
py = 0;
|
||||
sy = src->sy;
|
||||
|
||||
previous_wrapped = 0;
|
||||
for (line = 0; line < sy + src->hsize; line++) {
|
||||
src_gl = src->linedata + line;
|
||||
if (!previous_wrapped) {
|
||||
/* Wasn't wrapped. If smaller, move to destination. */
|
||||
if (src_gl->cellused <= new_x)
|
||||
grid_reflow_move(dst, &py, src_gl);
|
||||
else
|
||||
grid_reflow_split(dst, &py, src_gl, new_x, 0);
|
||||
} else {
|
||||
/* Previous was wrapped. Try to join. */
|
||||
grid_reflow_join(dst, &py, src_gl, new_x);
|
||||
}
|
||||
previous_wrapped = (src_gl->flags & GRID_LINE_WRAPPED);
|
||||
|
||||
/* This is where we started scrolling. */
|
||||
if (line == sy + src->hsize - src->hscrolled - 1)
|
||||
dst->hscrolled = 0;
|
||||
/*
|
||||
* Is the destination line now full? Copy the first character
|
||||
* separately because we need to leave "from" set to the last
|
||||
* line if this line is full.
|
||||
*/
|
||||
grid_get_cell1(&gd->linedata[line], 0, &gc);
|
||||
if (width + gc.data.width > sx)
|
||||
break;
|
||||
width += gc.data.width;
|
||||
grid_set_cell(target, at, to, &gc);
|
||||
at++;
|
||||
|
||||
/* Join as much more as possible onto the current line. */
|
||||
from = &gd->linedata[line];
|
||||
for (want = 1; want < from->cellused; want++) {
|
||||
grid_get_cell1(from, want, &gc);
|
||||
if (width + gc.data.width > sx)
|
||||
break;
|
||||
width += gc.data.width;
|
||||
|
||||
grid_set_cell(target, at, to, &gc);
|
||||
at++;
|
||||
}
|
||||
lines++;
|
||||
|
||||
/*
|
||||
* If this line wasn't wrapped or we didn't consume the entire
|
||||
* line, don't try to join any further lines.
|
||||
*/
|
||||
if (!wrapped || want != from->cellused || width == sx)
|
||||
break;
|
||||
}
|
||||
if (lines == 0)
|
||||
return;
|
||||
|
||||
/*
|
||||
* If we didn't consume the entire final line, then remove what we did
|
||||
* consume. If we consumed the entire line and it wasn't wrapped,
|
||||
* remove the wrap flag from this line.
|
||||
*/
|
||||
left = from->cellused - want;
|
||||
if (left != 0) {
|
||||
grid_move_cells(gd, 0, want, yy + lines, left, 8);
|
||||
from->cellsize = from->cellused = left;
|
||||
lines--;
|
||||
} else if (!wrapped)
|
||||
gl->flags &= ~GRID_LINE_WRAPPED;
|
||||
|
||||
/* Remove the lines that were completely consumed. */
|
||||
for (i = yy + 1; i < yy + 1 + lines; i++) {
|
||||
free(gd->linedata[i].celldata);
|
||||
free(gd->linedata[i].extddata);
|
||||
grid_reflow_dead(&gd->linedata[i]);
|
||||
}
|
||||
|
||||
grid_destroy(src);
|
||||
|
||||
if (py > sy)
|
||||
return (0);
|
||||
return (sy - py);
|
||||
/* Adjust cursor and scroll positions. */
|
||||
if (*cy > to + lines)
|
||||
*cy -= lines;
|
||||
else if (*cy > to)
|
||||
*cy = to;
|
||||
if (gd->hscrolled > to + lines)
|
||||
gd->hscrolled -= lines;
|
||||
else if (gd->hscrolled > to)
|
||||
gd->hscrolled = to;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
struct grid_line *gl = &gd->linedata[yy], *first;
|
||||
struct grid_cell gc;
|
||||
u_int line, lines, width, i, xx;
|
||||
u_int used = gl->cellused;
|
||||
int flags = gl->flags;
|
||||
|
||||
/* How many lines do we need to insert? We know we need at least two. */
|
||||
if (~gl->flags & GRID_LINE_EXTENDED)
|
||||
lines = 1 + (gl->cellused - 1) / sx;
|
||||
else {
|
||||
lines = 2;
|
||||
width = 0;
|
||||
for (i = at; i < used; i++) {
|
||||
grid_get_cell1(gl, i, &gc);
|
||||
if (width + gc.data.width > sx) {
|
||||
lines++;
|
||||
width = 0;
|
||||
}
|
||||
width += gc.data.width;
|
||||
}
|
||||
}
|
||||
|
||||
/* Insert new lines. */
|
||||
line = target->sy + 1;
|
||||
first = grid_reflow_add(target, lines);
|
||||
|
||||
/* Copy sections from the original line. */
|
||||
width = 0;
|
||||
xx = 0;
|
||||
for (i = at; i < used; i++) {
|
||||
grid_get_cell1(gl, i, &gc);
|
||||
if (width + gc.data.width > sx) {
|
||||
target->linedata[line].flags |= GRID_LINE_WRAPPED;
|
||||
|
||||
line++;
|
||||
width = 0;
|
||||
xx = 0;
|
||||
}
|
||||
width += gc.data.width;
|
||||
grid_set_cell(target, xx, line, &gc);
|
||||
xx++;
|
||||
}
|
||||
if (flags & GRID_LINE_WRAPPED)
|
||||
target->linedata[line].flags |= GRID_LINE_WRAPPED;
|
||||
|
||||
/* Move the remainder of the original line. */
|
||||
gl->cellsize = gl->cellused = at;
|
||||
gl->flags |= GRID_LINE_WRAPPED;
|
||||
memcpy(first, gl, sizeof *first);
|
||||
grid_reflow_dead(gl);
|
||||
|
||||
/* Adjust the cursor and scroll positions. */
|
||||
if (yy <= *cy)
|
||||
(*cy) += lines - 1;
|
||||
if (yy <= gd->hscrolled)
|
||||
gd->hscrolled += lines - 1;
|
||||
|
||||
/*
|
||||
* If the original line had the wrapped flag and there is still space
|
||||
* 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);
|
||||
}
|
||||
|
||||
/* Reflow lines on grid to new width. */
|
||||
void
|
||||
grid_reflow(struct grid *gd, u_int sx, u_int *cursor)
|
||||
{
|
||||
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);
|
||||
|
||||
/*
|
||||
* Create a destination grid. This is just used as a container for the
|
||||
* line data and may not be fully valid.
|
||||
*/
|
||||
target = grid_create(gd->sx, 0, 0);
|
||||
|
||||
/*
|
||||
* Loop over each source line.
|
||||
*/
|
||||
for (yy = 0; yy < gd->hsize + gd->sy; yy++) {
|
||||
gl = &gd->linedata[yy];
|
||||
if (gl->flags & GRID_LINE_DEAD)
|
||||
continue;
|
||||
|
||||
/*
|
||||
* Work out the width of this line. first is the width of the
|
||||
* first character, at is the point at which the available
|
||||
* width is hit, and width is the full line width.
|
||||
*/
|
||||
first = at = width = 0;
|
||||
if (~gl->flags & GRID_LINE_EXTENDED) {
|
||||
first = 1;
|
||||
width = gl->cellused;
|
||||
if (width > sx)
|
||||
at = sx;
|
||||
else
|
||||
at = width;
|
||||
} else {
|
||||
for (i = 0; i < gl->cellused; i++) {
|
||||
grid_get_cell1(gl, i, &gc);
|
||||
if (i == 0)
|
||||
first = gc.data.width;
|
||||
if (at == 0 && width + gc.data.width > sx)
|
||||
at = i;
|
||||
width += gc.data.width;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the line is exactly right or the first character is wider
|
||||
* than the targe width, just move it across unchanged.
|
||||
*/
|
||||
if (width == sx || first > sx) {
|
||||
grid_reflow_move(target, gl);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the line is too big, it needs to be split, whether or not
|
||||
* it was previously wrapped.
|
||||
*/
|
||||
if (width > sx) {
|
||||
grid_reflow_split(target, gd, sx, yy, at, &cy);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* If the line was previously wrapped, join as much as possible
|
||||
* of the next line.
|
||||
*/
|
||||
if (gl->flags & GRID_LINE_WRAPPED)
|
||||
grid_reflow_join(target, gd, sx, yy, width, &cy, 0);
|
||||
else
|
||||
grid_reflow_move(target, gl);
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace the old grid with the new.
|
||||
*/
|
||||
if (target->sy < gd->sy)
|
||||
grid_reflow_add(target, gd->sy - target->sy);
|
||||
gd->hsize = target->sy - gd->sy;
|
||||
free(gd->linedata);
|
||||
gd->linedata = target->linedata;
|
||||
free(target);
|
||||
|
||||
/*
|
||||
* Update scrolled and cursor positions.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
27
hooks.c
27
hooks.c
@@ -139,33 +139,6 @@ hooks_find(struct hooks *hooks, const char *name)
|
||||
return (hook);
|
||||
}
|
||||
|
||||
void
|
||||
hooks_run(struct hooks *hooks, struct client *c, struct cmd_find_state *fs,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
struct hook *hook;
|
||||
va_list ap;
|
||||
char *name;
|
||||
struct cmdq_item *new_item;
|
||||
|
||||
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", name);
|
||||
|
||||
new_item = cmdq_get_command(hook->cmdlist, fs, NULL, CMDQ_NOHOOKS);
|
||||
cmdq_format(new_item, "hook", "%s", name);
|
||||
cmdq_append(c, new_item);
|
||||
|
||||
free(name);
|
||||
}
|
||||
|
||||
void
|
||||
hooks_insert(struct hooks *hooks, struct cmdq_item *item,
|
||||
struct cmd_find_state *fs, const char *fmt, ...)
|
||||
|
||||
@@ -45,6 +45,10 @@ static const struct input_key_ent input_keys[] = {
|
||||
/* Backspace key. */
|
||||
{ KEYC_BSPACE, "\177", 0 },
|
||||
|
||||
/* Paste keys. */
|
||||
{ KEYC_PASTE_START, "\033[200~", 0 },
|
||||
{ KEYC_PASTE_END, "\033[201~", 0 },
|
||||
|
||||
/* Function keys. */
|
||||
{ KEYC_F1, "\033OP", 0 },
|
||||
{ KEYC_F2, "\033OQ", 0 },
|
||||
@@ -172,7 +176,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
|
||||
* If this is a normal 7-bit key, just send it, with a leading escape
|
||||
* if necessary. If it is a UTF-8 key, split it and send it.
|
||||
*/
|
||||
justkey = (key & ~KEYC_ESCAPE);
|
||||
justkey = (key & ~(KEYC_XTERM|KEYC_ESCAPE));
|
||||
if (justkey <= 0x7f) {
|
||||
if (key & KEYC_ESCAPE)
|
||||
bufferevent_write(wp->event, "\033", 1);
|
||||
@@ -200,6 +204,7 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m)
|
||||
return;
|
||||
}
|
||||
}
|
||||
key &= ~KEYC_XTERM;
|
||||
|
||||
/* Otherwise look the key up in the table. */
|
||||
for (i = 0; i < nitems(input_keys); i++) {
|
||||
|
||||
68
job.c
68
job.c
@@ -32,8 +32,9 @@
|
||||
* output.
|
||||
*/
|
||||
|
||||
static void job_callback(struct bufferevent *, short, void *);
|
||||
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 *);
|
||||
|
||||
/* All jobs list. */
|
||||
struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
@@ -41,26 +42,37 @@ struct joblist all_jobs = LIST_HEAD_INITIALIZER(all_jobs);
|
||||
/* Start a job running, if it isn't already. */
|
||||
struct job *
|
||||
job_run(const char *cmd, struct session *s, const char *cwd,
|
||||
void (*callbackfn)(struct job *), void (*freefn)(void *), void *data)
|
||||
job_update_cb updatecb, job_complete_cb completecb, job_free_cb freecb,
|
||||
void *data, int flags)
|
||||
{
|
||||
struct job *job;
|
||||
struct environ *env;
|
||||
pid_t pid;
|
||||
int nullfd, out[2];
|
||||
const char *home;
|
||||
sigset_t set, oldset;
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, out) != 0)
|
||||
return (NULL);
|
||||
|
||||
env = environ_for_session(s);
|
||||
/*
|
||||
* Do not set TERM during .tmux.conf, it is nice to be able to use
|
||||
* if-shell to decide on default-terminal based on outside TERM.
|
||||
*/
|
||||
env = environ_for_session(s, !cfg_finished);
|
||||
|
||||
sigfillset(&set);
|
||||
sigprocmask(SIG_BLOCK, &set, &oldset);
|
||||
switch (pid = fork()) {
|
||||
case -1:
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
environ_free(env);
|
||||
close(out[0]);
|
||||
close(out[1]);
|
||||
return (NULL);
|
||||
case 0: /* child */
|
||||
clear_signals(1);
|
||||
case 0:
|
||||
proc_clear_signals(server_proc, 1);
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
|
||||
if (cwd == NULL || chdir(cwd) != 0) {
|
||||
if ((home = find_home()) == NULL || chdir(home) != 0)
|
||||
@@ -92,28 +104,30 @@ job_run(const char *cmd, struct session *s, const char *cwd,
|
||||
fatal("execl failed");
|
||||
}
|
||||
|
||||
/* parent */
|
||||
sigprocmask(SIG_SETMASK, &oldset, NULL);
|
||||
environ_free(env);
|
||||
close(out[1]);
|
||||
|
||||
job = xmalloc(sizeof *job);
|
||||
job->state = JOB_RUNNING;
|
||||
job->flags = flags;
|
||||
|
||||
job->cmd = xstrdup(cmd);
|
||||
job->pid = pid;
|
||||
job->status = 0;
|
||||
|
||||
LIST_INSERT_HEAD(&all_jobs, job, lentry);
|
||||
LIST_INSERT_HEAD(&all_jobs, job, entry);
|
||||
|
||||
job->callbackfn = callbackfn;
|
||||
job->freefn = freefn;
|
||||
job->updatecb = updatecb;
|
||||
job->completecb = completecb;
|
||||
job->freecb = freecb;
|
||||
job->data = data;
|
||||
|
||||
job->fd = out[0];
|
||||
setblocking(job->fd, 0);
|
||||
|
||||
job->event = bufferevent_new(job->fd, NULL, job_write_callback,
|
||||
job_callback, job);
|
||||
job->event = bufferevent_new(job->fd, job_read_callback,
|
||||
job_write_callback, job_error_callback, job);
|
||||
bufferevent_enable(job->event, EV_READ|EV_WRITE);
|
||||
|
||||
log_debug("run job %p: %s, pid %ld", job, job->cmd, (long) job->pid);
|
||||
@@ -126,11 +140,11 @@ job_free(struct job *job)
|
||||
{
|
||||
log_debug("free job %p: %s", job, job->cmd);
|
||||
|
||||
LIST_REMOVE(job, lentry);
|
||||
LIST_REMOVE(job, entry);
|
||||
free(job->cmd);
|
||||
|
||||
if (job->freefn != NULL && job->data != NULL)
|
||||
job->freefn(job->data);
|
||||
if (job->freecb != NULL && job->data != NULL)
|
||||
job->freecb(job->data);
|
||||
|
||||
if (job->pid != -1)
|
||||
kill(job->pid, SIGTERM);
|
||||
@@ -142,7 +156,21 @@ job_free(struct job *job)
|
||||
free(job);
|
||||
}
|
||||
|
||||
/* Called when output buffer falls below low watermark (default is 0). */
|
||||
/* Job buffer read callback. */
|
||||
static void
|
||||
job_read_callback(__unused struct bufferevent *bufev, void *data)
|
||||
{
|
||||
struct job *job = data;
|
||||
|
||||
if (job->updatecb != NULL)
|
||||
job->updatecb(job);
|
||||
}
|
||||
|
||||
/*
|
||||
* Job buffer write callback. Fired when the buffer falls below watermark
|
||||
* (default is empty). If all the data has been written, disable the write
|
||||
* event.
|
||||
*/
|
||||
static void
|
||||
job_write_callback(__unused struct bufferevent *bufev, void *data)
|
||||
{
|
||||
@@ -160,7 +188,7 @@ job_write_callback(__unused struct bufferevent *bufev, void *data)
|
||||
|
||||
/* Job buffer error callback. */
|
||||
static void
|
||||
job_callback(__unused struct bufferevent *bufev, __unused short events,
|
||||
job_error_callback(__unused struct bufferevent *bufev, __unused short events,
|
||||
void *data)
|
||||
{
|
||||
struct job *job = data;
|
||||
@@ -168,8 +196,8 @@ job_callback(__unused struct bufferevent *bufev, __unused short events,
|
||||
log_debug("job error %p: %s, pid %ld", job, job->cmd, (long) job->pid);
|
||||
|
||||
if (job->state == JOB_DEAD) {
|
||||
if (job->callbackfn != NULL)
|
||||
job->callbackfn(job);
|
||||
if (job->completecb != NULL)
|
||||
job->completecb(job);
|
||||
job_free(job);
|
||||
} else {
|
||||
bufferevent_disable(job->event, EV_READ);
|
||||
@@ -186,8 +214,8 @@ job_died(struct job *job, int status)
|
||||
job->status = status;
|
||||
|
||||
if (job->state == JOB_CLOSED) {
|
||||
if (job->callbackfn != NULL)
|
||||
job->callbackfn(job);
|
||||
if (job->completecb != NULL)
|
||||
job->completecb(job);
|
||||
job_free(job);
|
||||
} else {
|
||||
job->pid = -1;
|
||||
|
||||
162
key-bindings.c
162
key-bindings.c
@@ -24,17 +24,19 @@
|
||||
|
||||
#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);
|
||||
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);
|
||||
|
||||
int
|
||||
key_table_cmp(struct key_table *e1, struct key_table *e2)
|
||||
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 +66,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,8 +97,29 @@ 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 can_repeat,
|
||||
key_bindings_add(const char *name, key_code key, int repeat,
|
||||
struct cmd_list *cmdlist)
|
||||
{
|
||||
struct key_table *table;
|
||||
@@ -92,7 +127,7 @@ key_bindings_add(const char *name, key_code key, int can_repeat,
|
||||
|
||||
table = key_bindings_get_table(name, 1);
|
||||
|
||||
bd_find.key = key;
|
||||
bd_find.key = (key & ~KEYC_XTERM);
|
||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
||||
if (bd != NULL) {
|
||||
RB_REMOVE(key_bindings, &table->key_bindings, bd);
|
||||
@@ -100,11 +135,12 @@ key_bindings_add(const char *name, key_code key, int can_repeat,
|
||||
free(bd);
|
||||
}
|
||||
|
||||
bd = xmalloc(sizeof *bd);
|
||||
bd = xcalloc(1, sizeof *bd);
|
||||
bd->key = key;
|
||||
RB_INSERT(key_bindings, &table->key_bindings, bd);
|
||||
|
||||
bd->can_repeat = can_repeat;
|
||||
if (repeat)
|
||||
bd->flags |= KEY_BINDING_REPEAT;
|
||||
bd->cmdlist = cmdlist;
|
||||
}
|
||||
|
||||
@@ -118,7 +154,7 @@ key_bindings_remove(const char *name, key_code key)
|
||||
if (table == NULL)
|
||||
return;
|
||||
|
||||
bd_find.key = key;
|
||||
bd_find.key = (key & ~KEYC_XTERM);
|
||||
bd = RB_FIND(key_bindings, &table->key_bindings, &bd_find);
|
||||
if (bd == NULL)
|
||||
return;
|
||||
@@ -137,12 +173,17 @@ void
|
||||
key_bindings_remove_table(const char *name)
|
||||
{
|
||||
struct key_table *table;
|
||||
struct client *c;
|
||||
|
||||
table = key_bindings_get_table(name, 0);
|
||||
if (table != NULL) {
|
||||
RB_REMOVE(key_tables, &key_tables, table);
|
||||
key_bindings_unref_table(table);
|
||||
}
|
||||
TAILQ_FOREACH(c, &clients, entry) {
|
||||
if (c->keytable == table)
|
||||
server_client_set_key_table(c, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -156,13 +197,13 @@ key_bindings_init(void)
|
||||
"bind ! break-pane",
|
||||
"bind '\"' split-window",
|
||||
"bind '#' list-buffers",
|
||||
"bind '$' command-prompt -I'#S' \"rename-session '%%'\"",
|
||||
"bind '$' command-prompt -I'#S' \"rename-session -- '%%'\"",
|
||||
"bind % split-window -h",
|
||||
"bind & confirm-before -p\"kill-window #W? (y/n)\" kill-window",
|
||||
"bind \"'\" command-prompt -pindex \"select-window -t ':%%'\"",
|
||||
"bind ( switch-client -p",
|
||||
"bind ) switch-client -n",
|
||||
"bind , command-prompt -I'#W' \"rename-window '%%'\"",
|
||||
"bind , command-prompt -I'#W' \"rename-window -- '%%'\"",
|
||||
"bind - delete-buffer",
|
||||
"bind . command-prompt \"move-window -t '%%'\"",
|
||||
"bind 0 select-window -t:=0",
|
||||
@@ -177,16 +218,17 @@ key_bindings_init(void)
|
||||
"bind 9 select-window -t:=9",
|
||||
"bind : command-prompt",
|
||||
"bind \\; last-pane",
|
||||
"bind = choose-buffer",
|
||||
"bind = choose-buffer -Z",
|
||||
"bind ? list-keys",
|
||||
"bind D choose-client",
|
||||
"bind D choose-client -Z",
|
||||
"bind E select-layout -E",
|
||||
"bind L switch-client -l",
|
||||
"bind M select-pane -M",
|
||||
"bind [ copy-mode",
|
||||
"bind ] paste-buffer",
|
||||
"bind c new-window",
|
||||
"bind d detach-client",
|
||||
"bind f command-prompt \"find-window '%%'\"",
|
||||
"bind f command-prompt \"find-window -- '%%'\"",
|
||||
"bind i display-message",
|
||||
"bind l last-window",
|
||||
"bind m select-pane -m",
|
||||
@@ -195,9 +237,9 @@ key_bindings_init(void)
|
||||
"bind p previous-window",
|
||||
"bind q display-panes",
|
||||
"bind r refresh-client",
|
||||
"bind s choose-tree",
|
||||
"bind s choose-tree -Zs",
|
||||
"bind t clock-mode",
|
||||
"bind w choose-window",
|
||||
"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",
|
||||
@@ -243,23 +285,23 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode C-k send -X copy-end-of-line",
|
||||
"bind -Tcopy-mode C-n send -X cursor-down",
|
||||
"bind -Tcopy-mode C-p send -X cursor-up",
|
||||
"bind -Tcopy-mode C-r command-prompt -ip'search up' 'send -X search-backward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-s command-prompt -ip'search down' 'send -X search-forward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-r command-prompt -ip'(search up)' -I'#{pane_search_string}' 'send -X search-backward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-s command-prompt -ip'(search down)' -I'#{pane_search_string}' 'send -X search-forward-incremental \"%%%\"'",
|
||||
"bind -Tcopy-mode C-v send -X page-down",
|
||||
"bind -Tcopy-mode C-w send -X copy-selection-and-cancel",
|
||||
"bind -Tcopy-mode Escape send -X cancel",
|
||||
"bind -Tcopy-mode Space send -X page-down",
|
||||
"bind -Tcopy-mode , send -X jump-reverse",
|
||||
"bind -Tcopy-mode \\; send -X jump-again",
|
||||
"bind -Tcopy-mode F command-prompt -1p'jump backward' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode N send -X search-reverse",
|
||||
"bind -Tcopy-mode R send -X rectangle-toggle",
|
||||
"bind -Tcopy-mode T command-prompt -1p'jump to backward' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode f command-prompt -1p'jump forward' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode g command-prompt -p'goto line' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode g command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode n send -X search-again",
|
||||
"bind -Tcopy-mode q send -X cancel",
|
||||
"bind -Tcopy-mode t command-prompt -1p'jump to forward' 'send -X jump-to-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode t command-prompt -1p'(jump to forward)' 'send -X jump-to-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode Home send -X start-of-line",
|
||||
"bind -Tcopy-mode End send -X end-of-line",
|
||||
"bind -Tcopy-mode MouseDown1Pane select-pane",
|
||||
@@ -275,15 +317,15 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode Down send -X cursor-down",
|
||||
"bind -Tcopy-mode Left send -X cursor-left",
|
||||
"bind -Tcopy-mode Right send -X cursor-right",
|
||||
"bind -Tcopy-mode M-1 command-prompt -Np'repeat' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-2 command-prompt -Np'repeat' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-3 command-prompt -Np'repeat' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-4 command-prompt -Np'repeat' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-5 command-prompt -Np'repeat' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-6 command-prompt -Np'repeat' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-7 command-prompt -Np'repeat' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-8 command-prompt -Np'repeat' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-9 command-prompt -Np'repeat' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode M-< send -X history-top",
|
||||
"bind -Tcopy-mode M-> send -X history-bottom",
|
||||
"bind -Tcopy-mode M-R send -X top-line",
|
||||
@@ -315,25 +357,25 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode-vi Space send -X begin-selection",
|
||||
"bind -Tcopy-mode-vi '$' send -X end-of-line",
|
||||
"bind -Tcopy-mode-vi , send -X jump-reverse",
|
||||
"bind -Tcopy-mode-vi / command-prompt -p'search down' 'send -X search-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi / command-prompt -p'(search down)' 'send -X search-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 0 send -X start-of-line",
|
||||
"bind -Tcopy-mode-vi 1 command-prompt -Np'repeat' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 2 command-prompt -Np'repeat' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 3 command-prompt -Np'repeat' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 4 command-prompt -Np'repeat' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 5 command-prompt -Np'repeat' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 6 command-prompt -Np'repeat' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 7 command-prompt -Np'repeat' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 8 command-prompt -Np'repeat' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 9 command-prompt -Np'repeat' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi : command-prompt -p'goto line' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 1 command-prompt -Np'(repeat)' -I1 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 2 command-prompt -Np'(repeat)' -I2 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 3 command-prompt -Np'(repeat)' -I3 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 4 command-prompt -Np'(repeat)' -I4 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 5 command-prompt -Np'(repeat)' -I5 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 6 command-prompt -Np'(repeat)' -I6 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 7 command-prompt -Np'(repeat)' -I7 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 8 command-prompt -Np'(repeat)' -I8 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi 9 command-prompt -Np'(repeat)' -I9 'send -N \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi : command-prompt -p'(goto line)' 'send -X goto-line \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi \\; send -X jump-again",
|
||||
"bind -Tcopy-mode-vi ? command-prompt -p'search up' 'send -X search-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi ? command-prompt -p'(search up)' 'send -X search-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi A send -X append-selection-and-cancel",
|
||||
"bind -Tcopy-mode-vi B send -X previous-space",
|
||||
"bind -Tcopy-mode-vi D send -X copy-end-of-line",
|
||||
"bind -Tcopy-mode-vi E send -X next-space-end",
|
||||
"bind -Tcopy-mode-vi F command-prompt -1p'jump backward' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi F command-prompt -1p'(jump backward)' 'send -X jump-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi G send -X history-bottom",
|
||||
"bind -Tcopy-mode-vi H send -X top-line",
|
||||
"bind -Tcopy-mode-vi J send -X scroll-down",
|
||||
@@ -341,13 +383,13 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode-vi L send -X bottom-line",
|
||||
"bind -Tcopy-mode-vi M send -X middle-line",
|
||||
"bind -Tcopy-mode-vi N send -X search-reverse",
|
||||
"bind -Tcopy-mode-vi T command-prompt -1p'jump to backward' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi T command-prompt -1p'(jump to backward)' 'send -X jump-to-backward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi V send -X select-line",
|
||||
"bind -Tcopy-mode-vi W send -X next-space",
|
||||
"bind -Tcopy-mode-vi ^ send -X back-to-indentation",
|
||||
"bind -Tcopy-mode-vi b send -X previous-word",
|
||||
"bind -Tcopy-mode-vi e send -X next-word-end",
|
||||
"bind -Tcopy-mode-vi f command-prompt -1p'jump forward' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi f command-prompt -1p'(jump forward)' 'send -X jump-forward \"%%%\"'",
|
||||
"bind -Tcopy-mode-vi g send -X history-top",
|
||||
"bind -Tcopy-mode-vi h send -X cursor-left",
|
||||
"bind -Tcopy-mode-vi j send -X cursor-down",
|
||||
@@ -356,7 +398,7 @@ key_bindings_init(void)
|
||||
"bind -Tcopy-mode-vi n send -X search-again",
|
||||
"bind -Tcopy-mode-vi o send -X other-end",
|
||||
"bind -Tcopy-mode-vi q send -X cancel",
|
||||
"bind -Tcopy-mode-vi t command-prompt -1p'jump to forward' 'send -X jump-to-forward \"%%%\"'",
|
||||
"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",
|
||||
@@ -399,11 +441,11 @@ key_bindings_read_only(struct cmdq_item *item, __unused void *data)
|
||||
}
|
||||
|
||||
void
|
||||
key_bindings_dispatch(struct key_binding *bd, struct client *c,
|
||||
struct mouse_event *m, struct cmd_find_state *fs)
|
||||
key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
|
||||
struct client *c, struct mouse_event *m, struct cmd_find_state *fs)
|
||||
{
|
||||
struct cmd *cmd;
|
||||
struct cmdq_item *item;
|
||||
struct cmdq_item *new_item;
|
||||
int readonly;
|
||||
|
||||
readonly = 1;
|
||||
@@ -412,10 +454,14 @@ key_bindings_dispatch(struct key_binding *bd, struct client *c,
|
||||
readonly = 0;
|
||||
}
|
||||
if (!readonly && (c->flags & CLIENT_READONLY))
|
||||
cmdq_append(c, cmdq_get_callback(key_bindings_read_only, NULL));
|
||||
new_item = cmdq_get_callback(key_bindings_read_only, NULL);
|
||||
else {
|
||||
item = cmdq_get_command(bd->cmdlist, fs, m, 0);
|
||||
item->repeat = bd->can_repeat;
|
||||
cmdq_append(c, item);
|
||||
new_item = cmdq_get_command(bd->cmdlist, fs, m, 0);
|
||||
if (bd->flags & KEY_BINDING_REPEAT)
|
||||
new_item->shared->flags |= CMDQ_SHARED_REPEAT;
|
||||
}
|
||||
if (item != NULL)
|
||||
cmdq_insert_after(item, new_item);
|
||||
else
|
||||
cmdq_append(c, new_item);
|
||||
}
|
||||
|
||||
20
key-string.c
20
key-string.c
@@ -110,12 +110,16 @@ static const struct {
|
||||
static key_code
|
||||
key_string_search_table(const char *string)
|
||||
{
|
||||
u_int i;
|
||||
u_int i, user;
|
||||
|
||||
for (i = 0; i < nitems(key_string_table); i++) {
|
||||
if (strcasecmp(string, key_string_table[i].string) == 0)
|
||||
return (key_string_table[i].key);
|
||||
}
|
||||
|
||||
if (sscanf(string, "User%u", &user) == 1 && user < KEYC_NUSER)
|
||||
return (KEYC_USER + user);
|
||||
|
||||
return (KEYC_UNKNOWN);
|
||||
}
|
||||
|
||||
@@ -162,9 +166,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') {
|
||||
@@ -247,10 +253,16 @@ 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)
|
||||
return ("FocusOut");
|
||||
if (key == KEYC_PASTE_START)
|
||||
return ("PasteStart");
|
||||
if (key == KEYC_PASTE_END)
|
||||
return ("PasteEnd");
|
||||
if (key == KEYC_MOUSE)
|
||||
return ("Mouse");
|
||||
if (key == KEYC_DRAGGING)
|
||||
@@ -261,6 +273,10 @@ key_string_lookup_key(key_code key)
|
||||
return ("MouseMoveStatus");
|
||||
if (key == KEYC_MOUSEMOVE_BORDER)
|
||||
return ("MouseMoveBorder");
|
||||
if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) {
|
||||
snprintf(out, sizeof out, "User%u", (u_int)(key - KEYC_USER));
|
||||
return (out);
|
||||
}
|
||||
|
||||
/*
|
||||
* Special case: display C-@ as C-Space. Could do this below in
|
||||
|
||||
87
layout-set.c
87
layout-set.c
@@ -115,11 +115,11 @@ layout_set_previous(struct window *w)
|
||||
}
|
||||
|
||||
static void
|
||||
layout_set_even_h(struct window *w)
|
||||
layout_set_even(struct window *w, enum layout_type type)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcnew;
|
||||
u_int i, n, width, xoff;
|
||||
u_int n;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
@@ -128,36 +128,23 @@ layout_set_even_h(struct window *w)
|
||||
if (n <= 1)
|
||||
return;
|
||||
|
||||
/* How many can we fit? */
|
||||
width = (w->sx - (n - 1)) / n;
|
||||
if (width < PANE_MINIMUM)
|
||||
width = PANE_MINIMUM;
|
||||
|
||||
/* 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);
|
||||
layout_make_node(lc, LAYOUT_LEFTRIGHT);
|
||||
layout_make_node(lc, type);
|
||||
|
||||
/* Build new leaf cells. */
|
||||
i = xoff = 0;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
/* Create child cell. */
|
||||
lcnew = layout_create_cell(lc);
|
||||
layout_set_size(lcnew, width, w->sy, xoff, 0);
|
||||
layout_make_leaf(lcnew, wp);
|
||||
lcnew->sx = w->sx;
|
||||
lcnew->sy = w->sy;
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
||||
|
||||
i++;
|
||||
xoff += width + 1;
|
||||
}
|
||||
|
||||
/* Allocate any remaining space. */
|
||||
if (w->sx > xoff - 1) {
|
||||
lc = TAILQ_LAST(&lc->cells, layout_cells);
|
||||
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT,
|
||||
w->sx - (xoff - 1));
|
||||
}
|
||||
/* Spread out cells. */
|
||||
layout_spread_cell(w, lc);
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
@@ -165,61 +152,20 @@ layout_set_even_h(struct window *w)
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
static void
|
||||
layout_set_even_h(struct window *w)
|
||||
{
|
||||
layout_set_even(w, LAYOUT_LEFTRIGHT);
|
||||
}
|
||||
|
||||
static void
|
||||
layout_set_even_v(struct window *w)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lc, *lcnew;
|
||||
u_int i, n, height, yoff;
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
/* Get number of panes. */
|
||||
n = window_count_panes(w);
|
||||
if (n <= 1)
|
||||
return;
|
||||
|
||||
/* How many can we fit? */
|
||||
height = (w->sy - (n - 1)) / n;
|
||||
if (height < PANE_MINIMUM)
|
||||
height = PANE_MINIMUM;
|
||||
|
||||
/* 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);
|
||||
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
||||
|
||||
/* Build new leaf cells. */
|
||||
i = yoff = 0;
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
/* Create child cell. */
|
||||
lcnew = layout_create_cell(lc);
|
||||
layout_set_size(lcnew, w->sx, height, 0, yoff);
|
||||
layout_make_leaf(lcnew, wp);
|
||||
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
||||
|
||||
i++;
|
||||
yoff += height + 1;
|
||||
}
|
||||
|
||||
/* Allocate any remaining space. */
|
||||
if (w->sy > yoff - 1) {
|
||||
lc = TAILQ_LAST(&lc->cells, layout_cells);
|
||||
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM,
|
||||
w->sy - (yoff - 1));
|
||||
}
|
||||
|
||||
/* Fix cell offsets. */
|
||||
layout_fix_offsets(lc);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
server_redraw_window(w);
|
||||
layout_set_even(w, LAYOUT_TOPBOTTOM);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -342,6 +288,7 @@ layout_set_main_h(struct window *w)
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
@@ -465,6 +412,7 @@ layout_set_main_v(struct window *w)
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
@@ -567,5 +515,6 @@ layout_set_tiled(struct window *w)
|
||||
|
||||
layout_print_cell(w->layout_root, __func__, 1);
|
||||
|
||||
notify_window("window-layout-changed", w);
|
||||
server_redraw_window(w);
|
||||
}
|
||||
|
||||
168
layout.c
168
layout.c
@@ -97,9 +97,24 @@ void
|
||||
layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
||||
{
|
||||
struct layout_cell *lcchild;
|
||||
const char *type;
|
||||
|
||||
log_debug("%s:%*s%p type %u [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
|
||||
" ", lc, lc->type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
|
||||
switch (lc->type) {
|
||||
case LAYOUT_LEFTRIGHT:
|
||||
type = "LEFTRIGHT";
|
||||
break;
|
||||
case LAYOUT_TOPBOTTOM:
|
||||
type = "TOPBOTTOM";
|
||||
break;
|
||||
case LAYOUT_WINDOWPANE:
|
||||
type = "WINDOWPANE";
|
||||
break;
|
||||
default:
|
||||
type = "UNKNOWN";
|
||||
break;
|
||||
}
|
||||
log_debug("%s:%*s%p type %s [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
|
||||
" ", lc, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
|
||||
lc->sy);
|
||||
switch (lc->type) {
|
||||
case LAYOUT_LEFTRIGHT:
|
||||
@@ -112,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)
|
||||
@@ -535,29 +586,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;
|
||||
@@ -576,9 +609,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, w->sx, w->sy);
|
||||
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. */
|
||||
@@ -983,3 +1041,61 @@ layout_close_pane(struct window_pane *wp)
|
||||
}
|
||||
notify_window("window-layout-changed", w);
|
||||
}
|
||||
|
||||
int
|
||||
layout_spread_cell(struct window *w, struct layout_cell *parent)
|
||||
{
|
||||
struct layout_cell *lc;
|
||||
u_int number, each, size;
|
||||
int change, changed;
|
||||
|
||||
number = 0;
|
||||
TAILQ_FOREACH (lc, &parent->cells, entry)
|
||||
number++;
|
||||
if (number <= 1)
|
||||
return (0);
|
||||
|
||||
if (parent->type == LAYOUT_LEFTRIGHT)
|
||||
size = parent->sx;
|
||||
else if (parent->type == LAYOUT_TOPBOTTOM)
|
||||
size = parent->sy;
|
||||
else
|
||||
return (0);
|
||||
each = (size - (number - 1)) / number;
|
||||
|
||||
changed = 0;
|
||||
TAILQ_FOREACH (lc, &parent->cells, entry) {
|
||||
if (TAILQ_NEXT(lc, entry) == NULL)
|
||||
each = size - ((each + 1) * (number - 1));
|
||||
change = 0;
|
||||
if (parent->type == LAYOUT_LEFTRIGHT) {
|
||||
change = each - (int)lc->sx;
|
||||
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change);
|
||||
} else if (parent->type == LAYOUT_TOPBOTTOM) {
|
||||
change = each - (int)lc->sy;
|
||||
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change);
|
||||
}
|
||||
if (change != 0)
|
||||
changed = 1;
|
||||
}
|
||||
return (changed);
|
||||
}
|
||||
|
||||
void
|
||||
layout_spread_out(struct window_pane *wp)
|
||||
{
|
||||
struct layout_cell *parent;
|
||||
struct window *w = wp->window;
|
||||
|
||||
parent = wp->layout_cell->parent;
|
||||
if (parent == NULL)
|
||||
return;
|
||||
|
||||
do {
|
||||
if (layout_spread_cell(w, parent)) {
|
||||
layout_fix_offsets(parent);
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
break;
|
||||
}
|
||||
} while ((parent = parent->parent) != NULL);
|
||||
}
|
||||
|
||||
21
log.c
21
log.c
@@ -61,12 +61,10 @@ log_open(const char *name)
|
||||
|
||||
if (log_level == 0)
|
||||
return;
|
||||
|
||||
if (log_file != NULL)
|
||||
fclose(log_file);
|
||||
log_close();
|
||||
|
||||
xasprintf(&path, "tmux-%s-%ld.log", name, (long)getpid());
|
||||
log_file = fopen(path, "w");
|
||||
log_file = fopen(path, "a");
|
||||
free(path);
|
||||
if (log_file == NULL)
|
||||
return;
|
||||
@@ -75,6 +73,21 @@ log_open(const char *name)
|
||||
event_set_log_callback(log_event_cb);
|
||||
}
|
||||
|
||||
/* Toggle logging. */
|
||||
void
|
||||
log_toggle(const char *name)
|
||||
{
|
||||
if (log_level == 0) {
|
||||
log_level = 1;
|
||||
log_open(name);
|
||||
log_debug("log opened");
|
||||
} else {
|
||||
log_debug("log closed");
|
||||
log_level = 0;
|
||||
log_close();
|
||||
}
|
||||
}
|
||||
|
||||
/* Close logging. */
|
||||
void
|
||||
log_close(void)
|
||||
|
||||
975
mode-tree.c
Normal file
975
mode-tree.c
Normal file
@@ -0,0 +1,975 @@
|
||||
/* $OpenBSD$ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 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 <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
struct mode_tree_item;
|
||||
TAILQ_HEAD(mode_tree_list, mode_tree_item);
|
||||
|
||||
struct mode_tree_data {
|
||||
int dead;
|
||||
u_int references;
|
||||
int zoomed;
|
||||
|
||||
struct window_pane *wp;
|
||||
void *modedata;
|
||||
|
||||
const char **sort_list;
|
||||
u_int sort_size;
|
||||
u_int sort_type;
|
||||
|
||||
mode_tree_build_cb buildcb;
|
||||
mode_tree_draw_cb drawcb;
|
||||
mode_tree_search_cb searchcb;
|
||||
|
||||
struct mode_tree_list children;
|
||||
struct mode_tree_list saved;
|
||||
|
||||
struct mode_tree_line *line_list;
|
||||
u_int line_size;
|
||||
|
||||
u_int depth;
|
||||
|
||||
u_int width;
|
||||
u_int height;
|
||||
|
||||
u_int offset;
|
||||
u_int current;
|
||||
|
||||
struct screen screen;
|
||||
|
||||
int preview;
|
||||
char *search;
|
||||
char *filter;
|
||||
int no_matches;
|
||||
};
|
||||
|
||||
struct mode_tree_item {
|
||||
struct mode_tree_item *parent;
|
||||
void *itemdata;
|
||||
u_int line;
|
||||
|
||||
uint64_t tag;
|
||||
const char *name;
|
||||
const char *text;
|
||||
|
||||
int expanded;
|
||||
int tagged;
|
||||
|
||||
struct mode_tree_list children;
|
||||
TAILQ_ENTRY(mode_tree_item) entry;
|
||||
};
|
||||
|
||||
struct mode_tree_line {
|
||||
struct mode_tree_item *item;
|
||||
u_int depth;
|
||||
int last;
|
||||
int flat;
|
||||
};
|
||||
|
||||
static void mode_tree_free_items(struct mode_tree_list *);
|
||||
|
||||
static struct mode_tree_item *
|
||||
mode_tree_find_item(struct mode_tree_list *mtl, uint64_t tag)
|
||||
{
|
||||
struct mode_tree_item *mti, *child;
|
||||
|
||||
TAILQ_FOREACH(mti, mtl, entry) {
|
||||
if (mti->tag == tag)
|
||||
return (mti);
|
||||
child = mode_tree_find_item(&mti->children, tag);
|
||||
if (child != NULL)
|
||||
return (child);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_free_item(struct mode_tree_item *mti)
|
||||
{
|
||||
mode_tree_free_items(&mti->children);
|
||||
|
||||
free((void *)mti->name);
|
||||
free((void *)mti->text);
|
||||
|
||||
free(mti);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_free_items(struct mode_tree_list *mtl)
|
||||
{
|
||||
struct mode_tree_item *mti, *mti1;
|
||||
|
||||
TAILQ_FOREACH_SAFE(mti, mtl, entry, mti1) {
|
||||
TAILQ_REMOVE(mtl, mti, entry);
|
||||
mode_tree_free_item(mti);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_check_selected(struct mode_tree_data *mtd)
|
||||
{
|
||||
/*
|
||||
* If the current line would now be off screen reset the offset to the
|
||||
* last visible line.
|
||||
*/
|
||||
if (mtd->current > mtd->height - 1)
|
||||
mtd->offset = mtd->current - mtd->height + 1;
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_clear_lines(struct mode_tree_data *mtd)
|
||||
{
|
||||
free(mtd->line_list);
|
||||
mtd->line_list = NULL;
|
||||
mtd->line_size = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_build_lines(struct mode_tree_data *mtd,
|
||||
struct mode_tree_list *mtl, u_int depth)
|
||||
{
|
||||
struct mode_tree_item *mti;
|
||||
struct mode_tree_line *line;
|
||||
u_int i;
|
||||
int flat = 1;
|
||||
|
||||
mtd->depth = depth;
|
||||
TAILQ_FOREACH(mti, mtl, entry) {
|
||||
mtd->line_list = xreallocarray(mtd->line_list,
|
||||
mtd->line_size + 1, sizeof *mtd->line_list);
|
||||
|
||||
line = &mtd->line_list[mtd->line_size++];
|
||||
line->item = mti;
|
||||
line->depth = depth;
|
||||
line->last = (mti == TAILQ_LAST(mtl, mode_tree_list));
|
||||
|
||||
mti->line = (mtd->line_size - 1);
|
||||
if (!TAILQ_EMPTY(&mti->children))
|
||||
flat = 0;
|
||||
if (mti->expanded)
|
||||
mode_tree_build_lines(mtd, &mti->children, depth + 1);
|
||||
}
|
||||
TAILQ_FOREACH(mti, mtl, entry) {
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
line = &mtd->line_list[i];
|
||||
if (line->item == mti)
|
||||
line->flat = flat;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_clear_tagged(struct mode_tree_list *mtl)
|
||||
{
|
||||
struct mode_tree_item *mti;
|
||||
|
||||
TAILQ_FOREACH(mti, mtl, entry) {
|
||||
mti->tagged = 0;
|
||||
mode_tree_clear_tagged(&mti->children);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_up(struct mode_tree_data *mtd, int wrap)
|
||||
{
|
||||
if (mtd->current == 0) {
|
||||
if (wrap) {
|
||||
mtd->current = mtd->line_size - 1;
|
||||
if (mtd->line_size >= mtd->height)
|
||||
mtd->offset = mtd->line_size - mtd->height;
|
||||
}
|
||||
} else {
|
||||
mtd->current--;
|
||||
if (mtd->current < mtd->offset)
|
||||
mtd->offset--;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_down(struct mode_tree_data *mtd, int wrap)
|
||||
{
|
||||
if (mtd->current == mtd->line_size - 1) {
|
||||
if (wrap) {
|
||||
mtd->current = 0;
|
||||
mtd->offset = 0;
|
||||
}
|
||||
} else {
|
||||
mtd->current++;
|
||||
if (mtd->current > mtd->offset + mtd->height - 1)
|
||||
mtd->offset++;
|
||||
}
|
||||
}
|
||||
|
||||
void *
|
||||
mode_tree_get_current(struct mode_tree_data *mtd)
|
||||
{
|
||||
return (mtd->line_list[mtd->current].item->itemdata);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_expand_current(struct mode_tree_data *mtd)
|
||||
{
|
||||
if (!mtd->line_list[mtd->current].item->expanded) {
|
||||
mtd->line_list[mtd->current].item->expanded = 1;
|
||||
mode_tree_build(mtd);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_set_current(struct mode_tree_data *mtd, uint64_t tag)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
if (mtd->line_list[i].item->tag == tag)
|
||||
break;
|
||||
}
|
||||
if (i != mtd->line_size) {
|
||||
mtd->current = i;
|
||||
if (mtd->current > mtd->height - 1)
|
||||
mtd->offset = mtd->current - mtd->height + 1;
|
||||
else
|
||||
mtd->offset = 0;
|
||||
} else {
|
||||
mtd->current = 0;
|
||||
mtd->offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
u_int
|
||||
mode_tree_count_tagged(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct mode_tree_item *mti;
|
||||
u_int i, tagged;
|
||||
|
||||
tagged = 0;
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
mti = mtd->line_list[i].item;
|
||||
if (mti->tagged)
|
||||
tagged++;
|
||||
}
|
||||
return (tagged);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_each_tagged(struct mode_tree_data *mtd, mode_tree_each_cb cb,
|
||||
struct client *c, key_code key, int current)
|
||||
{
|
||||
struct mode_tree_item *mti;
|
||||
u_int i;
|
||||
int fired;
|
||||
|
||||
fired = 0;
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
mti = mtd->line_list[i].item;
|
||||
if (mti->tagged) {
|
||||
fired = 1;
|
||||
cb(mtd->modedata, mti->itemdata, c, key);
|
||||
}
|
||||
}
|
||||
if (!fired && current) {
|
||||
mti = mtd->line_list[mtd->current].item;
|
||||
cb(mtd->modedata, mti->itemdata, c, key);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct mode_tree_data *mtd;
|
||||
const char *sort;
|
||||
u_int i;
|
||||
|
||||
mtd = xcalloc(1, sizeof *mtd);
|
||||
mtd->references = 1;
|
||||
|
||||
mtd->wp = wp;
|
||||
mtd->modedata = modedata;
|
||||
|
||||
mtd->sort_list = sort_list;
|
||||
mtd->sort_size = sort_size;
|
||||
mtd->sort_type = 0;
|
||||
|
||||
mtd->preview = !args_has(args, 'N');
|
||||
|
||||
sort = args_get(args, 'O');
|
||||
if (sort != NULL) {
|
||||
for (i = 0; i < sort_size; i++) {
|
||||
if (strcasecmp(sort, sort_list[i]) == 0)
|
||||
mtd->sort_type = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (args_has(args, 'f'))
|
||||
mtd->filter = xstrdup(args_get(args, 'f'));
|
||||
else
|
||||
mtd->filter = NULL;
|
||||
|
||||
mtd->buildcb = buildcb;
|
||||
mtd->drawcb = drawcb;
|
||||
mtd->searchcb = searchcb;
|
||||
|
||||
TAILQ_INIT(&mtd->children);
|
||||
|
||||
*s = &mtd->screen;
|
||||
screen_init(*s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
(*s)->mode &= ~MODE_CURSOR;
|
||||
|
||||
return (mtd);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_zoom(struct mode_tree_data *mtd, struct args *args)
|
||||
{
|
||||
struct window_pane *wp = mtd->wp;
|
||||
|
||||
if (args_has(args, 'Z')) {
|
||||
mtd->zoomed = (wp->window->flags & WINDOW_ZOOMED);
|
||||
if (!mtd->zoomed && window_zoom(wp) == 0)
|
||||
server_redraw_window(wp->window);
|
||||
} else
|
||||
mtd->zoomed = -1;
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_build(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct screen *s = &mtd->screen;
|
||||
uint64_t tag;
|
||||
|
||||
if (mtd->line_list != NULL)
|
||||
tag = mtd->line_list[mtd->current].item->tag;
|
||||
else
|
||||
tag = 0;
|
||||
|
||||
TAILQ_CONCAT(&mtd->saved, &mtd->children, entry);
|
||||
TAILQ_INIT(&mtd->children);
|
||||
|
||||
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, mtd->filter);
|
||||
mtd->no_matches = TAILQ_EMPTY(&mtd->children);
|
||||
if (mtd->no_matches)
|
||||
mtd->buildcb(mtd->modedata, mtd->sort_type, &tag, NULL);
|
||||
|
||||
mode_tree_free_items(&mtd->saved);
|
||||
TAILQ_INIT(&mtd->saved);
|
||||
|
||||
mode_tree_clear_lines(mtd);
|
||||
mode_tree_build_lines(mtd, &mtd->children, 0);
|
||||
|
||||
mode_tree_set_current(mtd, tag);
|
||||
|
||||
mtd->width = screen_size_x(s);
|
||||
if (mtd->preview) {
|
||||
mtd->height = (screen_size_y(s) / 3) * 2;
|
||||
if (mtd->height > mtd->line_size)
|
||||
mtd->height = screen_size_y(s) / 2;
|
||||
if (mtd->height < 10)
|
||||
mtd->height = screen_size_y(s);
|
||||
if (screen_size_y(s) - mtd->height < 2)
|
||||
mtd->height = screen_size_y(s);
|
||||
} else
|
||||
mtd->height = screen_size_y(s);
|
||||
mode_tree_check_selected(mtd);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_remove_ref(struct mode_tree_data *mtd)
|
||||
{
|
||||
if (--mtd->references == 0)
|
||||
free(mtd);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_free(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct window_pane *wp = mtd->wp;
|
||||
|
||||
if (mtd->zoomed == 0)
|
||||
server_unzoom_window(wp->window);
|
||||
|
||||
mode_tree_free_items(&mtd->children);
|
||||
mode_tree_clear_lines(mtd);
|
||||
screen_free(&mtd->screen);
|
||||
|
||||
free(mtd->search);
|
||||
free(mtd->filter);
|
||||
|
||||
mtd->dead = 1;
|
||||
mode_tree_remove_ref(mtd);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_resize(struct mode_tree_data *mtd, u_int sx, u_int sy)
|
||||
{
|
||||
struct screen *s = &mtd->screen;
|
||||
|
||||
screen_resize(s, sx, sy, 0);
|
||||
|
||||
mode_tree_build(mtd);
|
||||
mode_tree_draw(mtd);
|
||||
|
||||
mtd->wp->flags |= PANE_REDRAW;
|
||||
}
|
||||
|
||||
struct mode_tree_item *
|
||||
mode_tree_add(struct mode_tree_data *mtd, struct mode_tree_item *parent,
|
||||
void *itemdata, uint64_t tag, const char *name, const char *text,
|
||||
int expanded)
|
||||
{
|
||||
struct mode_tree_item *mti, *saved;
|
||||
|
||||
log_debug("%s: %llu, %s %s", __func__, (unsigned long long)tag,
|
||||
name, text);
|
||||
|
||||
mti = xcalloc(1, sizeof *mti);
|
||||
mti->parent = parent;
|
||||
mti->itemdata = itemdata;
|
||||
|
||||
mti->tag = tag;
|
||||
mti->name = xstrdup(name);
|
||||
mti->text = xstrdup(text);
|
||||
|
||||
saved = mode_tree_find_item(&mtd->saved, tag);
|
||||
if (saved != NULL) {
|
||||
if (parent == NULL || (parent != NULL && parent->expanded))
|
||||
mti->tagged = saved->tagged;
|
||||
mti->expanded = saved->expanded;
|
||||
} else if (expanded == -1)
|
||||
mti->expanded = 1;
|
||||
else
|
||||
mti->expanded = expanded;
|
||||
|
||||
TAILQ_INIT(&mti->children);
|
||||
|
||||
if (parent != NULL)
|
||||
TAILQ_INSERT_TAIL(&parent->children, mti, entry);
|
||||
else
|
||||
TAILQ_INSERT_TAIL(&mtd->children, mti, entry);
|
||||
|
||||
return (mti);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_remove(struct mode_tree_data *mtd, struct mode_tree_item *mti)
|
||||
{
|
||||
struct mode_tree_item *parent = mti->parent;
|
||||
|
||||
if (parent != NULL)
|
||||
TAILQ_REMOVE(&parent->children, mti, entry);
|
||||
else
|
||||
TAILQ_REMOVE(&mtd->children, mti, entry);
|
||||
mode_tree_free_item(mti);
|
||||
}
|
||||
|
||||
void
|
||||
mode_tree_draw(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct window_pane *wp = mtd->wp;
|
||||
struct screen *s = &mtd->screen;
|
||||
struct mode_tree_line *line;
|
||||
struct mode_tree_item *mti;
|
||||
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;
|
||||
char *text, *start, key[7];
|
||||
const char *tag, *symbol;
|
||||
size_t size, n;
|
||||
int keylen;
|
||||
|
||||
if (mtd->line_size == 0)
|
||||
return;
|
||||
|
||||
memcpy(&gc0, &grid_default_cell, sizeof gc0);
|
||||
memcpy(&gc, &grid_default_cell, sizeof gc);
|
||||
style_apply(&gc, oo, "mode-style");
|
||||
|
||||
w = mtd->width;
|
||||
h = mtd->height;
|
||||
|
||||
screen_write_start(&ctx, NULL, s);
|
||||
screen_write_clearscreen(&ctx, 8);
|
||||
|
||||
if (mtd->line_size > 10)
|
||||
keylen = 6;
|
||||
else
|
||||
keylen = 4;
|
||||
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
if (i < mtd->offset)
|
||||
continue;
|
||||
if (i > mtd->offset + h - 1)
|
||||
break;
|
||||
|
||||
line = &mtd->line_list[i];
|
||||
mti = line->item;
|
||||
|
||||
screen_write_cursormove(&ctx, 0, i - mtd->offset);
|
||||
|
||||
if (i < 10)
|
||||
snprintf(key, sizeof key, "(%c) ", '0' + i);
|
||||
else if (i < 36)
|
||||
snprintf(key, sizeof key, "(M-%c)", 'a' + (i - 10));
|
||||
else
|
||||
*key = '\0';
|
||||
|
||||
if (line->flat)
|
||||
symbol = "";
|
||||
else if (TAILQ_EMPTY(&mti->children))
|
||||
symbol = " ";
|
||||
else if (mti->expanded)
|
||||
symbol = "- ";
|
||||
else
|
||||
symbol = "+ ";
|
||||
|
||||
if (line->depth == 0)
|
||||
start = xstrdup(symbol);
|
||||
else {
|
||||
size = (4 * line->depth) + 32;
|
||||
|
||||
start = xcalloc(1, size);
|
||||
for (j = 1; j < line->depth; j++) {
|
||||
if (mti->parent != NULL &&
|
||||
mtd->line_list[mti->parent->line].last)
|
||||
strlcat(start, " ", size);
|
||||
else
|
||||
strlcat(start, "\001x\001 ", size);
|
||||
}
|
||||
if (line->last)
|
||||
strlcat(start, "\001mq\001> ", size);
|
||||
else
|
||||
strlcat(start, "\001tq\001> ", size);
|
||||
strlcat(start, symbol, size);
|
||||
}
|
||||
|
||||
if (mti->tagged)
|
||||
tag = "*";
|
||||
else
|
||||
tag = "";
|
||||
xasprintf(&text, "%-*s%s%s%s: %s", keylen, key, start,
|
||||
mti->name, tag, mti->text);
|
||||
free(start);
|
||||
|
||||
if (mti->tagged) {
|
||||
gc.attr ^= GRID_ATTR_BRIGHT;
|
||||
gc0.attr ^= GRID_ATTR_BRIGHT;
|
||||
}
|
||||
|
||||
if (i != mtd->current) {
|
||||
screen_write_nputs(&ctx, w, &gc0, "%s", text);
|
||||
screen_write_clearendofline(&ctx, 8);
|
||||
} else {
|
||||
screen_write_nputs(&ctx, w, &gc, "%s", text);
|
||||
screen_write_clearendofline(&ctx, gc.bg);
|
||||
}
|
||||
free(text);
|
||||
|
||||
if (mti->tagged) {
|
||||
gc.attr ^= GRID_ATTR_BRIGHT;
|
||||
gc0.attr ^= GRID_ATTR_BRIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
sy = screen_size_y(s);
|
||||
if (!mtd->preview || sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) {
|
||||
screen_write_stop(&ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
line = &mtd->line_list[mtd->current];
|
||||
mti = line->item;
|
||||
|
||||
screen_write_cursormove(&ctx, 0, h);
|
||||
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_puts(&ctx, &gc0, "%s", text);
|
||||
|
||||
if (mtd->no_matches)
|
||||
n = (sizeof "no matches") - 1;
|
||||
else
|
||||
n = (sizeof "active") - 1;
|
||||
if (mtd->filter != NULL && w - 2 >= strlen(text) + 10 + n + 2) {
|
||||
screen_write_puts(&ctx, &gc0, " (filter: ");
|
||||
if (mtd->no_matches)
|
||||
screen_write_puts(&ctx, &gc, "no matches");
|
||||
else
|
||||
screen_write_puts(&ctx, &gc0, "active");
|
||||
screen_write_puts(&ctx, &gc0, ") ");
|
||||
}
|
||||
}
|
||||
free(text);
|
||||
|
||||
box_x = w - 4;
|
||||
box_y = sy - h - 2;
|
||||
|
||||
if (box_x != 0 && box_y != 0) {
|
||||
screen_write_cursormove(&ctx, 2, h + 1);
|
||||
mtd->drawcb(mtd->modedata, mti->itemdata, &ctx, box_x, box_y);
|
||||
}
|
||||
|
||||
screen_write_stop(&ctx);
|
||||
}
|
||||
|
||||
static struct mode_tree_item *
|
||||
mode_tree_search_for(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct mode_tree_item *mti, *last, *next;
|
||||
|
||||
if (mtd->search == NULL)
|
||||
return (NULL);
|
||||
|
||||
mti = last = mtd->line_list[mtd->current].item;
|
||||
for (;;) {
|
||||
if (!TAILQ_EMPTY(&mti->children))
|
||||
mti = TAILQ_FIRST(&mti->children);
|
||||
else if ((next = TAILQ_NEXT(mti, entry)) != NULL)
|
||||
mti = next;
|
||||
else {
|
||||
for (;;) {
|
||||
mti = mti->parent;
|
||||
if (mti == NULL)
|
||||
break;
|
||||
if ((next = TAILQ_NEXT(mti, entry)) != NULL) {
|
||||
mti = next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mti == NULL)
|
||||
mti = TAILQ_FIRST(&mtd->children);
|
||||
if (mti == last)
|
||||
break;
|
||||
|
||||
if (mtd->searchcb == NULL) {
|
||||
if (strstr(mti->name, mtd->search) != NULL)
|
||||
return (mti);
|
||||
continue;
|
||||
}
|
||||
if (mtd->searchcb(mtd->modedata, mti->itemdata, mtd->search))
|
||||
return (mti);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_search_set(struct mode_tree_data *mtd)
|
||||
{
|
||||
struct mode_tree_item *mti, *loop;
|
||||
uint64_t tag;
|
||||
|
||||
mti = mode_tree_search_for(mtd);
|
||||
if (mti == NULL)
|
||||
return;
|
||||
tag = mti->tag;
|
||||
|
||||
loop = mti->parent;
|
||||
while (loop != NULL) {
|
||||
loop->expanded = 1;
|
||||
loop = loop->parent;
|
||||
}
|
||||
|
||||
mode_tree_build(mtd);
|
||||
mode_tree_set_current(mtd, tag);
|
||||
mode_tree_draw(mtd);
|
||||
mtd->wp->flags |= PANE_REDRAW;
|
||||
}
|
||||
|
||||
static int
|
||||
mode_tree_search_callback(__unused struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
{
|
||||
struct mode_tree_data *mtd = data;
|
||||
|
||||
if (mtd->dead)
|
||||
return (0);
|
||||
|
||||
free(mtd->search);
|
||||
if (s == NULL || *s == '\0') {
|
||||
mtd->search = NULL;
|
||||
return (0);
|
||||
}
|
||||
mtd->search = xstrdup(s);
|
||||
mode_tree_search_set(mtd);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_search_free(void *data)
|
||||
{
|
||||
mode_tree_remove_ref(data);
|
||||
}
|
||||
|
||||
static int
|
||||
mode_tree_filter_callback(__unused struct client *c, void *data, const char *s,
|
||||
__unused int done)
|
||||
{
|
||||
struct mode_tree_data *mtd = data;
|
||||
|
||||
if (mtd->dead)
|
||||
return (0);
|
||||
|
||||
if (mtd->filter != NULL)
|
||||
free(mtd->filter);
|
||||
if (s == NULL || *s == '\0')
|
||||
mtd->filter = NULL;
|
||||
else
|
||||
mtd->filter = xstrdup(s);
|
||||
|
||||
mode_tree_build(mtd);
|
||||
mode_tree_draw(mtd);
|
||||
mtd->wp->flags |= PANE_REDRAW;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
mode_tree_filter_free(void *data)
|
||||
{
|
||||
mode_tree_remove_ref(data);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct mode_tree_line *line;
|
||||
struct mode_tree_item *current, *parent;
|
||||
u_int i, x, y;
|
||||
int choice;
|
||||
key_code tmp;
|
||||
|
||||
if (KEYC_IS_MOUSE(*key)) {
|
||||
if (cmd_mouse_at(mtd->wp, m, &x, &y, 0) != 0) {
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
}
|
||||
if (xp != NULL)
|
||||
*xp = x;
|
||||
if (yp != NULL)
|
||||
*yp = y;
|
||||
if (x > mtd->width || y > mtd->height) {
|
||||
if (!mtd->preview)
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
}
|
||||
if (mtd->offset + y < mtd->line_size) {
|
||||
if (*key == KEYC_MOUSEDOWN1_PANE ||
|
||||
*key == KEYC_DOUBLECLICK1_PANE)
|
||||
mtd->current = mtd->offset + y;
|
||||
if (*key == KEYC_DOUBLECLICK1_PANE)
|
||||
*key = '\r';
|
||||
else
|
||||
*key = KEYC_NONE;
|
||||
} else
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
}
|
||||
|
||||
line = &mtd->line_list[mtd->current];
|
||||
current = line->item;
|
||||
|
||||
choice = -1;
|
||||
if (*key >= '0' && *key <= '9')
|
||||
choice = (*key) - '0';
|
||||
else if (((*key) & KEYC_MASK_MOD) == KEYC_ESCAPE) {
|
||||
tmp = (*key) & KEYC_MASK_KEY;
|
||||
if (tmp >= 'a' && tmp <= 'z')
|
||||
choice = 10 + (tmp - 'a');
|
||||
}
|
||||
if (choice != -1) {
|
||||
if ((u_int)choice > mtd->line_size - 1) {
|
||||
*key = KEYC_NONE;
|
||||
return (0);
|
||||
}
|
||||
mtd->current = choice;
|
||||
*key = '\r';
|
||||
return (0);
|
||||
}
|
||||
|
||||
switch (*key) {
|
||||
case 'q':
|
||||
case '\033': /* Escape */
|
||||
case '\007': /* C-g */
|
||||
return (1);
|
||||
case KEYC_UP:
|
||||
case 'k':
|
||||
case KEYC_WHEELUP_PANE:
|
||||
case '\020': /* C-p */
|
||||
mode_tree_up(mtd, 1);
|
||||
break;
|
||||
case KEYC_DOWN:
|
||||
case 'j':
|
||||
case KEYC_WHEELDOWN_PANE:
|
||||
case '\016': /* C-n */
|
||||
mode_tree_down(mtd, 1);
|
||||
break;
|
||||
case KEYC_PPAGE:
|
||||
case '\002': /* C-b */
|
||||
for (i = 0; i < mtd->height; i++) {
|
||||
if (mtd->current == 0)
|
||||
break;
|
||||
mode_tree_up(mtd, 1);
|
||||
}
|
||||
break;
|
||||
case KEYC_NPAGE:
|
||||
case '\006': /* C-f */
|
||||
for (i = 0; i < mtd->height; i++) {
|
||||
if (mtd->current == mtd->line_size - 1)
|
||||
break;
|
||||
mode_tree_down(mtd, 1);
|
||||
}
|
||||
break;
|
||||
case KEYC_HOME:
|
||||
mtd->current = 0;
|
||||
mtd->offset = 0;
|
||||
break;
|
||||
case KEYC_END:
|
||||
mtd->current = mtd->line_size - 1;
|
||||
if (mtd->current > mtd->height - 1)
|
||||
mtd->offset = mtd->current - mtd->height + 1;
|
||||
else
|
||||
mtd->offset = 0;
|
||||
break;
|
||||
case 't':
|
||||
/*
|
||||
* Do not allow parents and children to both be tagged: untag
|
||||
* all parents and children of current.
|
||||
*/
|
||||
if (!current->tagged) {
|
||||
parent = current->parent;
|
||||
while (parent != NULL) {
|
||||
parent->tagged = 0;
|
||||
parent = parent->parent;
|
||||
}
|
||||
mode_tree_clear_tagged(¤t->children);
|
||||
current->tagged = 1;
|
||||
} else
|
||||
current->tagged = 0;
|
||||
mode_tree_down(mtd, 0);
|
||||
break;
|
||||
case 'T':
|
||||
for (i = 0; i < mtd->line_size; i++)
|
||||
mtd->line_list[i].item->tagged = 0;
|
||||
break;
|
||||
case '\024': /* C-t */
|
||||
for (i = 0; i < mtd->line_size; i++) {
|
||||
if (mtd->line_list[i].item->parent == NULL)
|
||||
mtd->line_list[i].item->tagged = 1;
|
||||
else
|
||||
mtd->line_list[i].item->tagged = 0;
|
||||
}
|
||||
break;
|
||||
case 'O':
|
||||
mtd->sort_type++;
|
||||
if (mtd->sort_type == mtd->sort_size)
|
||||
mtd->sort_type = 0;
|
||||
mode_tree_build(mtd);
|
||||
break;
|
||||
case KEYC_LEFT:
|
||||
case 'h':
|
||||
case '-':
|
||||
if (line->flat || !current->expanded)
|
||||
current = current->parent;
|
||||
if (current == NULL)
|
||||
mode_tree_up(mtd, 0);
|
||||
else {
|
||||
current->expanded = 0;
|
||||
mtd->current = current->line;
|
||||
mode_tree_build(mtd);
|
||||
}
|
||||
break;
|
||||
case KEYC_RIGHT:
|
||||
case 'l':
|
||||
case '+':
|
||||
if (line->flat || current->expanded)
|
||||
mode_tree_down(mtd, 0);
|
||||
else if (!line->flat) {
|
||||
current->expanded = 1;
|
||||
mode_tree_build(mtd);
|
||||
}
|
||||
break;
|
||||
case '\023': /* C-s */
|
||||
mtd->references++;
|
||||
status_prompt_set(c, "(search) ", "",
|
||||
mode_tree_search_callback, mode_tree_search_free, mtd,
|
||||
PROMPT_NOFORMAT);
|
||||
break;
|
||||
case 'n':
|
||||
mode_tree_search_set(mtd);
|
||||
break;
|
||||
case 'f':
|
||||
mtd->references++;
|
||||
status_prompt_set(c, "(filter) ", mtd->filter,
|
||||
mode_tree_filter_callback, mode_tree_filter_free, mtd,
|
||||
PROMPT_NOFORMAT);
|
||||
break;
|
||||
case 'v':
|
||||
mtd->preview = !mtd->preview;
|
||||
mode_tree_build(mtd);
|
||||
if (mtd->preview)
|
||||
mode_tree_check_selected(mtd);
|
||||
break;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
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;
|
||||
|
||||
command = cmd_template_replace(template, name, 1);
|
||||
if (command == NULL || *command == '\0') {
|
||||
free(command);
|
||||
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);
|
||||
}
|
||||
free(cause);
|
||||
} else {
|
||||
new_item = cmdq_get_command(cmdlist, fs, NULL, 0);
|
||||
cmdq_append(c, new_item);
|
||||
cmd_list_free(cmdlist);
|
||||
}
|
||||
|
||||
free(command);
|
||||
}
|
||||
6
names.c
6
names.c
@@ -124,7 +124,7 @@ format_window_name(struct window *w)
|
||||
const char *fmt;
|
||||
char *name;
|
||||
|
||||
ft = format_create(NULL, FORMAT_WINDOW|w->id, 0);
|
||||
ft = format_create(NULL, NULL, FORMAT_WINDOW|w->id, 0);
|
||||
format_defaults_window(ft, w);
|
||||
format_defaults_pane(ft, w->active);
|
||||
|
||||
@@ -151,7 +151,9 @@ parse_window_name(const char *in)
|
||||
|
||||
if (*name != '\0') {
|
||||
ptr = name + strlen(name) - 1;
|
||||
while (ptr > name && !isalnum((u_char)*ptr))
|
||||
while (ptr > name &&
|
||||
!isalnum((u_char)*ptr) &&
|
||||
!ispunct((u_char)*ptr))
|
||||
*ptr-- = '\0';
|
||||
}
|
||||
|
||||
|
||||
67
notify.c
67
notify.c
@@ -35,7 +35,7 @@ struct notify_entry {
|
||||
};
|
||||
|
||||
static void
|
||||
notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
||||
notify_hook1(struct cmdq_item *item, struct notify_entry *ne)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
struct hook *hook;
|
||||
@@ -43,9 +43,9 @@ notify_hook(struct cmdq_item *item, struct notify_entry *ne)
|
||||
struct session *s = ne->session;
|
||||
struct window *w = ne->window;
|
||||
|
||||
cmd_find_clear_state(&fs, NULL, 0);
|
||||
cmd_find_clear_state(&fs, 0);
|
||||
if (cmd_find_empty_state(&ne->fs) || !cmd_find_valid_state(&ne->fs))
|
||||
cmd_find_current(&fs, item, CMD_FIND_QUIET);
|
||||
cmd_find_from_nothing(&fs, 0);
|
||||
else
|
||||
cmd_find_copy_state(&fs, &ne->fs);
|
||||
|
||||
@@ -78,8 +78,12 @@ notify_callback(struct cmdq_item *item, void *data)
|
||||
|
||||
log_debug("%s: %s", __func__, ne->name);
|
||||
|
||||
if (strcmp(ne->name, "pane-mode-changed") == 0)
|
||||
control_notify_pane_mode_changed(ne->pane);
|
||||
if (strcmp(ne->name, "window-layout-changed") == 0)
|
||||
control_notify_window_layout_changed(ne->window);
|
||||
if (strcmp(ne->name, "window-pane-changed") == 0)
|
||||
control_notify_window_pane_changed(ne->window);
|
||||
if (strcmp(ne->name, "window-unlinked") == 0)
|
||||
control_notify_window_unlinked(ne->session, ne->window);
|
||||
if (strcmp(ne->name, "window-linked") == 0)
|
||||
@@ -94,18 +98,20 @@ notify_callback(struct cmdq_item *item, void *data)
|
||||
control_notify_session_created(ne->session);
|
||||
if (strcmp(ne->name, "session-closed") == 0)
|
||||
control_notify_session_closed(ne->session);
|
||||
if (strcmp(ne->name, "session-window-changed") == 0)
|
||||
control_notify_session_window_changed(ne->session);
|
||||
|
||||
notify_hook(item, ne);
|
||||
notify_hook1(item, ne);
|
||||
|
||||
if (ne->client != NULL)
|
||||
server_client_unref(ne->client);
|
||||
if (ne->session != NULL)
|
||||
session_unref(ne->session);
|
||||
session_remove_ref(ne->session, __func__);
|
||||
if (ne->window != NULL)
|
||||
window_remove_ref(ne->window);
|
||||
window_remove_ref(ne->window, __func__);
|
||||
|
||||
if (ne->fs.s != NULL)
|
||||
session_unref(ne->fs.s);
|
||||
session_remove_ref(ne->fs.s, __func__);
|
||||
|
||||
free((void *)ne->name);
|
||||
free(ne);
|
||||
@@ -135,18 +141,36 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
|
||||
if (c != NULL)
|
||||
c->references++;
|
||||
if (s != NULL)
|
||||
s->references++;
|
||||
session_add_ref(s, __func__);
|
||||
if (w != NULL)
|
||||
w->references++;
|
||||
window_add_ref(w, __func__);
|
||||
|
||||
cmd_find_copy_state(&ne->fs, fs);
|
||||
if (ne->fs.s != NULL)
|
||||
ne->fs.s->references++; /* cmd_find_valid_state need session */
|
||||
if (ne->fs.s != NULL) /* cmd_find_valid_state needs session */
|
||||
session_add_ref(ne->fs.s, __func__);
|
||||
|
||||
new_item = cmdq_get_callback(notify_callback, ne);
|
||||
cmdq_append(NULL, new_item);
|
||||
}
|
||||
|
||||
void
|
||||
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_hook1(item, &ne);
|
||||
}
|
||||
|
||||
void
|
||||
notify_input(struct window_pane *wp, struct evbuffer *input)
|
||||
{
|
||||
@@ -163,10 +187,7 @@ notify_client(const char *name, struct client *c)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (c->session != NULL)
|
||||
cmd_find_from_session(&fs, c->session);
|
||||
else
|
||||
cmd_find_current(&fs, NULL, CMD_FIND_QUIET);
|
||||
cmd_find_from_client(&fs, c, 0);
|
||||
notify_add(name, &fs, c, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
@@ -176,19 +197,19 @@ notify_session(const char *name, struct session *s)
|
||||
struct cmd_find_state fs;
|
||||
|
||||
if (session_alive(s))
|
||||
cmd_find_from_session(&fs, s);
|
||||
cmd_find_from_session(&fs, s, 0);
|
||||
else
|
||||
cmd_find_current(&fs, NULL, CMD_FIND_QUIET);
|
||||
cmd_find_from_nothing(&fs, 0);
|
||||
notify_add(name, &fs, NULL, s, NULL, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
notify_winlink(const char *name, struct session *s, struct winlink *wl)
|
||||
notify_winlink(const char *name, struct winlink *wl)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
cmd_find_from_winlink(&fs, s, wl);
|
||||
notify_add(name, &fs, NULL, s, wl->window, NULL);
|
||||
cmd_find_from_winlink(&fs, wl, 0);
|
||||
notify_add(name, &fs, NULL, wl->session, wl->window, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -196,7 +217,7 @@ notify_session_window(const char *name, struct session *s, struct window *w)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
cmd_find_from_session_window(&fs, s, w);
|
||||
cmd_find_from_session_window(&fs, s, w, 0);
|
||||
notify_add(name, &fs, NULL, s, w, NULL);
|
||||
}
|
||||
|
||||
@@ -205,7 +226,7 @@ notify_window(const char *name, struct window *w)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
cmd_find_from_window(&fs, w);
|
||||
cmd_find_from_window(&fs, w, 0);
|
||||
notify_add(name, &fs, NULL, NULL, w, NULL);
|
||||
}
|
||||
|
||||
@@ -214,6 +235,6 @@ notify_pane(const char *name, struct window_pane *wp)
|
||||
{
|
||||
struct cmd_find_state fs;
|
||||
|
||||
cmd_find_from_pane(&fs, wp);
|
||||
cmd_find_from_pane(&fs, wp, 0);
|
||||
notify_add(name, &fs, NULL, NULL, NULL, wp);
|
||||
}
|
||||
|
||||
@@ -50,9 +50,15 @@ static const char *options_table_status_position_list[] = {
|
||||
static const char *options_table_bell_action_list[] = {
|
||||
"none", "any", "current", "other", NULL
|
||||
};
|
||||
static const char *options_table_visual_bell_list[] = {
|
||||
"off", "on", "both", NULL
|
||||
};
|
||||
static const char *options_table_pane_status_list[] = {
|
||||
"off", "top", "bottom", NULL
|
||||
};
|
||||
static const char *options_table_set_clipboard_list[] = {
|
||||
"off", "external", "on", NULL
|
||||
};
|
||||
|
||||
/* Top-level options. */
|
||||
const struct options_table_entry options_table[] = {
|
||||
@@ -61,7 +67,7 @@ const struct options_table_entry options_table[] = {
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.minimum = 1,
|
||||
.maximum = INT_MAX,
|
||||
.default_num = 20
|
||||
.default_num = 50
|
||||
},
|
||||
|
||||
{ .name = "command-alias",
|
||||
@@ -70,7 +76,9 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "split-pane=split-window,"
|
||||
"splitp=split-window,"
|
||||
"server-info=show-messages -JT,"
|
||||
"info=show-messages -JT",
|
||||
"info=show-messages -JT,"
|
||||
"choose-window=choose-tree -w,"
|
||||
"choose-session=choose-tree -s",
|
||||
.separator = ","
|
||||
},
|
||||
|
||||
@@ -88,6 +96,12 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 500
|
||||
},
|
||||
|
||||
{ .name = "exit-empty",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
{ .name = "exit-unattached",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
@@ -115,8 +129,9 @@ const struct options_table_entry options_table[] = {
|
||||
},
|
||||
|
||||
{ .name = "set-clipboard",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.choices = options_table_set_clipboard_list,
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
@@ -124,11 +139,25 @@ const struct options_table_entry options_table[] = {
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.default_str = "xterm*:XT:Ms=\\E]52;%p1%s;%p2%s\\007"
|
||||
":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
|
||||
":Cs=\\E]12;%p1%s\\007:Cr=\\E]112\\007"
|
||||
":Ss=\\E[%p1%d q:Se=\\E[2 q,screen*:XT",
|
||||
.separator = ","
|
||||
},
|
||||
|
||||
{ .name = "user-keys",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.scope = OPTIONS_TABLE_SERVER,
|
||||
.default_str = "",
|
||||
.separator = ","
|
||||
},
|
||||
|
||||
{ .name = "activity-action",
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.choices = options_table_bell_action_list,
|
||||
.default_num = ALERT_OTHER
|
||||
},
|
||||
|
||||
{ .name = "assume-paste-time",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -149,13 +178,7 @@ const struct options_table_entry options_table[] = {
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.choices = options_table_bell_action_list,
|
||||
.default_num = BELL_ANY
|
||||
},
|
||||
|
||||
{ .name = "bell-on-alert",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0
|
||||
.default_num = ALERT_ANY
|
||||
},
|
||||
|
||||
{ .name = "default-command",
|
||||
@@ -336,6 +359,13 @@ const struct options_table_entry options_table[] = {
|
||||
.default_str = "#S:#I:#W - \"#T\" #{session_alerts}"
|
||||
},
|
||||
|
||||
{ .name = "silence-action",
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.choices = options_table_bell_action_list,
|
||||
.default_num = ALERT_OTHER
|
||||
},
|
||||
|
||||
{ .name = "status",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
@@ -483,26 +513,29 @@ const struct options_table_entry options_table[] = {
|
||||
{ .name = "update-environment",
|
||||
.type = OPTIONS_TABLE_ARRAY,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_str = "DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID "
|
||||
"SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||
.default_str = "DISPLAY KRB5CCNAME SSH_ASKPASS SSH_AUTH_SOCK "
|
||||
"SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"
|
||||
},
|
||||
|
||||
{ .name = "visual-activity",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0
|
||||
.choices = options_table_visual_bell_list,
|
||||
.default_num = VISUAL_OFF
|
||||
},
|
||||
|
||||
{ .name = "visual-bell",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0
|
||||
.choices = options_table_visual_bell_list,
|
||||
.default_num = VISUAL_OFF
|
||||
},
|
||||
|
||||
{ .name = "visual-silence",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.type = OPTIONS_TABLE_CHOICE,
|
||||
.scope = OPTIONS_TABLE_SESSION,
|
||||
.default_num = 0
|
||||
.choices = options_table_visual_bell_list,
|
||||
.default_num = VISUAL_OFF
|
||||
},
|
||||
|
||||
{ .name = "word-separators",
|
||||
@@ -520,7 +553,7 @@ const struct options_table_entry options_table[] = {
|
||||
{ .name = "allow-rename",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 1
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "alternate-screen",
|
||||
@@ -539,7 +572,7 @@ const struct options_table_entry options_table[] = {
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "#{?pane_in_mode,[tmux],#{pane_current_command}}"
|
||||
"#{?pane_dead,[dead],}"
|
||||
"#{?pane_dead,[dead],}"
|
||||
},
|
||||
|
||||
{ .name = "clock-mode-colour",
|
||||
@@ -627,6 +660,12 @@ const struct options_table_entry options_table[] = {
|
||||
.default_num = 0
|
||||
},
|
||||
|
||||
{ .name = "monitor-bell",
|
||||
.type = OPTIONS_TABLE_FLAG,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_num = 1
|
||||
},
|
||||
|
||||
{ .name = "monitor-silence",
|
||||
.type = OPTIONS_TABLE_NUMBER,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
@@ -697,7 +736,7 @@ const struct options_table_entry options_table[] = {
|
||||
.type = OPTIONS_TABLE_STRING,
|
||||
.scope = OPTIONS_TABLE_WINDOW,
|
||||
.default_str = "#{?pane_active,#[reverse],}#{pane_index}#[default] "
|
||||
"\"#{pane_title}\""
|
||||
"\"#{pane_title}\""
|
||||
},
|
||||
|
||||
{ .name = "pane-border-status",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user