mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-09 11:53:47 -05:00
Compare commits
1453 Commits
0.17.1
...
leverage-b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
38040d43e4 | ||
|
|
4161403a1d | ||
|
|
53bcdc4294 | ||
|
|
30a8ef28cd | ||
|
|
855f90727a | ||
|
|
2191a44e36 | ||
|
|
952276dc2d | ||
|
|
2286edb329 | ||
|
|
a0f28583e7 | ||
|
|
8af0af3400 | ||
|
|
769e5cbb2d | ||
|
|
fc69308057 | ||
|
|
c6d620c99e | ||
|
|
f510a4def6 | ||
|
|
4ae3069c6f | ||
|
|
c0f27751d3 | ||
|
|
efbcd5a683 | ||
|
|
6a67712944 | ||
|
|
e8a690928d | ||
|
|
0eee95af57 | ||
|
|
a09c6e991a | ||
|
|
d06c5ab990 | ||
|
|
e0924d27b8 | ||
|
|
2775b771f2 | ||
|
|
cf7a3c6a0e | ||
|
|
230cc6acc3 | ||
|
|
626a23a585 | ||
|
|
74f196eebb | ||
|
|
cf2242aea3 | ||
|
|
8cb59e6fca | ||
|
|
5cce17e80a | ||
|
|
ee5302fb2d | ||
|
|
387c6ef664 | ||
|
|
581734c369 | ||
|
|
d90a969c00 | ||
|
|
2c8a96bb27 | ||
|
|
5da168db30 | ||
|
|
e215e2daf3 | ||
|
|
e28f5aa45b | ||
|
|
a2d0e8f233 | ||
|
|
303d04106a | ||
|
|
c423c496a1 | ||
|
|
4e85f72f0e | ||
|
|
dd0737aac0 | ||
|
|
f90985845d | ||
|
|
af4917dbb6 | ||
|
|
d9404fcce4 | ||
|
|
5c01fee5a9 | ||
|
|
9b27d68a37 | ||
|
|
b99d884e57 | ||
|
|
587df594b8 | ||
|
|
b896e0d314 | ||
|
|
559fb7ee45 | ||
|
|
62545cd983 | ||
|
|
c50812518e | ||
|
|
4cc5609d8b | ||
|
|
50fa90dfb8 | ||
|
|
a2c365e710 | ||
|
|
b4ddffdc61 | ||
|
|
8d4d184fc6 | ||
|
|
ea23539b59 | ||
|
|
9e92b6f11e | ||
|
|
6cbde812f6 | ||
|
|
3b2e932c13 | ||
|
|
8ff4e52641 | ||
|
|
2dbc874e3d | ||
|
|
039a2f1d04 | ||
|
|
4ef1cf5b35 | ||
|
|
b44ab9e33c | ||
|
|
8f4c23f1c4 | ||
|
|
23a391e715 | ||
|
|
035b0be29f | ||
|
|
e1fcdbc337 | ||
|
|
cfc149e994 | ||
|
|
2faffbd1b7 | ||
|
|
8db65704b9 | ||
|
|
797a01aed4 | ||
|
|
bf515a3d32 | ||
|
|
a06745826a | ||
|
|
0420ed4f2a | ||
|
|
3b944addd4 | ||
|
|
70bf8bc35d | ||
|
|
724f8a1d45 | ||
|
|
cc2b2146ee | ||
|
|
8689f5f230 | ||
|
|
e9e0011f1d | ||
|
|
5b52833785 | ||
|
|
1525768094 | ||
|
|
a70ea4654e | ||
|
|
b02bf9b6bb | ||
|
|
bee7bc5324 | ||
|
|
7c2ffd3fef | ||
|
|
db01e7dab6 | ||
|
|
2326c74eb2 | ||
|
|
b9d15569e8 | ||
|
|
c3cc378d89 | ||
|
|
27d1f5e0a8 | ||
|
|
540632bb9e | ||
|
|
d9c028c934 | ||
|
|
c54ad82e8d | ||
|
|
295b89631b | ||
|
|
6179faf778 | ||
|
|
16dc236a25 | ||
|
|
61ae9d75b6 | ||
|
|
e2401aca68 | ||
|
|
59943cbb48 | ||
|
|
02634d404d | ||
|
|
ed12925f7d | ||
|
|
e0ddb97ab4 | ||
|
|
b8c01af0fc | ||
|
|
6de0a7ddc1 | ||
|
|
79196c025d | ||
|
|
94c33ac020 | ||
|
|
b2ecb6352c | ||
|
|
9dc3ed638a | ||
|
|
0acace1ace | ||
|
|
1a2d37e1e6 | ||
|
|
22adb6494f | ||
|
|
e023736c30 | ||
|
|
dca2262fe6 | ||
|
|
0684a20ea3 | ||
|
|
a1a72bb8d1 | ||
|
|
144d55a5be | ||
|
|
7fc13c5cfd | ||
|
|
dfee7af57b | ||
|
|
9b0e2daf02 | ||
|
|
590060a16b | ||
|
|
368294edf6 | ||
|
|
c4a9ccd6af | ||
|
|
cbf91f2ed3 | ||
|
|
b1460d4787 | ||
|
|
7dc9e14874 | ||
|
|
1616ed543d | ||
|
|
dc73fba188 | ||
|
|
ef148dfd37 | ||
|
|
93bbb3032d | ||
|
|
4c83d8596d | ||
|
|
d453e6d7db | ||
|
|
c29533994f | ||
|
|
1afe13b5b5 | ||
|
|
36600eaaa9 | ||
|
|
3ee1fc2034 | ||
|
|
e2f93e5a2d | ||
|
|
cfdf2f1153 | ||
|
|
e042143e3f | ||
|
|
7c613d0d9b | ||
|
|
b00d46bc14 | ||
|
|
555b0d235b | ||
|
|
564daf9a7d | ||
|
|
41bcbe342f | ||
|
|
dbe8dc344e | ||
|
|
e33fb59da1 | ||
|
|
7aa88aa115 | ||
|
|
2b6d600879 | ||
|
|
05c765d442 | ||
|
|
49b496269c | ||
|
|
7405925952 | ||
|
|
3afd543a7e | ||
|
|
b4f2cde5ac | ||
|
|
ed53ef7cee | ||
|
|
12630b124d | ||
|
|
1d59ac09d2 | ||
|
|
a8f3a0dd59 | ||
|
|
124cd70710 | ||
|
|
782de139c8 | ||
|
|
32eb32ee5e | ||
|
|
2f51eb2b41 | ||
|
|
0ccbd79e10 | ||
|
|
99bd6de541 | ||
|
|
1fef36e4bc | ||
|
|
89375005b5 | ||
|
|
88e78c9193 | ||
|
|
29a19ad080 | ||
|
|
2a039ab746 | ||
|
|
7e9a0fcdbd | ||
|
|
7a97532547 | ||
|
|
996abb2831 | ||
|
|
da500a358f | ||
|
|
c36b846acc | ||
|
|
d9b5c9b2be | ||
|
|
3dee8778d0 | ||
|
|
d4216b0dcc | ||
|
|
bfe2bf4dce | ||
|
|
561f9291fd | ||
|
|
b5b0d6b3ea | ||
|
|
a90426b7ca | ||
|
|
303c3bae7f | ||
|
|
6b4358f641 | ||
|
|
552158f3ad | ||
|
|
7205203dc8 | ||
|
|
0cadf70072 | ||
|
|
076b3d0a9a | ||
|
|
7b0c9e04d3 | ||
|
|
573df524fe | ||
|
|
aee417c46a | ||
|
|
04db44067d | ||
|
|
5b204c54f9 | ||
|
|
daa602422d | ||
|
|
04dfb14e32 | ||
|
|
c24256cba3 | ||
|
|
685fb71d89 | ||
|
|
83b6033906 | ||
|
|
01e7668915 | ||
|
|
0994d9c881 | ||
|
|
030428ba43 | ||
|
|
8a110e02b9 | ||
|
|
86d92c17c4 | ||
|
|
c4cc7891b4 | ||
|
|
218843b9f1 | ||
|
|
d274d093af | ||
|
|
6432f00f0d | ||
|
|
4e9e842aa4 | ||
|
|
07880ca441 | ||
|
|
bcda25a513 | ||
|
|
8256fcde15 | ||
|
|
af65aa298a | ||
|
|
6834d17844 | ||
|
|
ed511d7867 | ||
|
|
cd8d736a9f | ||
|
|
0952b2dfd4 | ||
|
|
4bedd33c59 | ||
|
|
c5fb0c43f9 | ||
|
|
9e4780510e | ||
|
|
e8405f40fe | ||
|
|
065b9e6fb2 | ||
|
|
98141ca7d8 | ||
|
|
501577ab28 | ||
|
|
5669f48343 | ||
|
|
24ff66d4a9 | ||
|
|
bf184449bc | ||
|
|
7b98c2c653 | ||
|
|
b6add2a257 | ||
|
|
2bd41f1330 | ||
|
|
c37cd11ca5 | ||
|
|
9dee8edc0c | ||
|
|
f6aa28c380 | ||
|
|
dba1644518 | ||
|
|
260a65b0fb | ||
|
|
835d2fb98c | ||
|
|
a9811addaa | ||
|
|
ee9d88b637 | ||
|
|
194a763c46 | ||
|
|
8d74446bef | ||
|
|
7ed6c7905c | ||
|
|
159a37fa37 | ||
|
|
f39ae0e7c1 | ||
|
|
4a68eac99b | ||
|
|
2665580120 | ||
|
|
a4391aeedd | ||
|
|
b86a967ee2 | ||
|
|
608232568b | ||
|
|
7f85beccb5 | ||
|
|
767f1255ab | ||
|
|
fddbfe7b0e | ||
|
|
4ab7fdc28e | ||
|
|
e352b68878 | ||
|
|
207deeadba | ||
|
|
d18d92f925 | ||
|
|
af3ce47c44 | ||
|
|
d8bfb6712d | ||
|
|
f864f8b5f7 | ||
|
|
31d72efba7 | ||
|
|
d169c951f3 | ||
|
|
90d7e38909 | ||
|
|
938f23e429 | ||
|
|
f97d275413 | ||
|
|
3acb4ca90e | ||
|
|
e86b81bbf5 | ||
|
|
a5447b8b75 | ||
|
|
7ce6452d83 | ||
|
|
5643a306bd | ||
|
|
3c877c504b | ||
|
|
892d1acccb | ||
|
|
1a9c282f76 | ||
|
|
fd1ba46f77 | ||
|
|
a4745626dd | ||
|
|
17bb7ad278 | ||
|
|
152988c17b | ||
|
|
4cd37fc02b | ||
|
|
69b9d674a3 | ||
|
|
bad8061547 | ||
|
|
62963dcefd | ||
|
|
68a35e4735 | ||
|
|
9b9ad77e1c | ||
|
|
118b4d4a01 | ||
|
|
da14ab6f16 | ||
|
|
09a4ca6ab5 | ||
|
|
8a2df79711 | ||
|
|
c30e486b64 | ||
|
|
a575c0c54b | ||
|
|
77fe96ac0d | ||
|
|
5234c3759a | ||
|
|
41b3511ad9 | ||
|
|
128e4a2e8d | ||
|
|
07ac90d798 | ||
|
|
7de87a9b2c | ||
|
|
dff865239a | ||
|
|
07f8f70c5b | ||
|
|
f625c5aabe | ||
|
|
8a74976c1f | ||
|
|
b6bfd4a5cb | ||
|
|
008fb9d258 | ||
|
|
db6db49ed6 | ||
|
|
05453881c3 | ||
|
|
5e47ab9431 | ||
|
|
ec70acd0b9 | ||
|
|
25e61056b6 | ||
|
|
d579e335b5 | ||
|
|
7e344ceb85 | ||
|
|
0145b82ea0 | ||
|
|
b4efe7aab7 | ||
|
|
9ffe951f6d | ||
|
|
a5ea4f57bd | ||
|
|
88f4c16755 | ||
|
|
c7ee071efa | ||
|
|
0740ef7ceb | ||
|
|
b29bd809ac | ||
|
|
8977c9257a | ||
|
|
091b7eacba | ||
|
|
e74b1251c0 | ||
|
|
d282a1649d | ||
|
|
6ce8d49d1b | ||
|
|
c5b197078a | ||
|
|
0494f20d62 | ||
|
|
73aff476dd | ||
|
|
98ee5e651a | ||
|
|
01871ea383 | ||
|
|
1dbdb9438f | ||
|
|
c70f0eadb8 | ||
|
|
26244ad8c2 | ||
|
|
fa0aa5510d | ||
|
|
eec557b6aa | ||
|
|
0cc27c3cc1 | ||
|
|
507089d7b2 | ||
|
|
a6b3517b75 | ||
|
|
2d6beb7813 | ||
|
|
61bc129e1d | ||
|
|
52210a57f0 | ||
|
|
8061a2f108 | ||
|
|
7444eff6d4 | ||
|
|
f35a9da99a | ||
|
|
c3098e9ab2 | ||
|
|
686f9288fc | ||
|
|
1833670fb9 | ||
|
|
3dd42f5aa2 | ||
|
|
99a7beba57 | ||
|
|
edee2b753c | ||
|
|
545d5770be | ||
|
|
ca747a2b54 | ||
|
|
17da165cfe | ||
|
|
5e6788c679 | ||
|
|
425deadca9 | ||
|
|
2c8e9dd3a5 | ||
|
|
7a72f1a253 | ||
|
|
208e556332 | ||
|
|
c65d11bfb5 | ||
|
|
3b5b52d89a | ||
|
|
a4f6c8f990 | ||
|
|
670c329852 | ||
|
|
f3551c8422 | ||
|
|
90b8187882 | ||
|
|
1a43259989 | ||
|
|
3c0a630475 | ||
|
|
2a1e5a9729 | ||
|
|
413c66beba | ||
|
|
1416e696b1 | ||
|
|
d373cf89c7 | ||
|
|
dd886d22f0 | ||
|
|
472569a27c | ||
|
|
76cf6559cc | ||
|
|
a34e8dcdc9 | ||
|
|
da752fc9a4 | ||
|
|
beb2de2dd9 | ||
|
|
2a8b65e105 | ||
|
|
62a916bc24 | ||
|
|
c47b833e7b | ||
|
|
09b0958b5f | ||
|
|
3a4c3d3e58 | ||
|
|
7484292e63 | ||
|
|
687c2741b8 | ||
|
|
2fb285e530 | ||
|
|
16f6473938 | ||
|
|
66546208b2 | ||
|
|
532274045e | ||
|
|
9347c72fb6 | ||
|
|
e90bb7169c | ||
|
|
8a2c41e183 | ||
|
|
59fb65293a | ||
|
|
e7718b92b7 | ||
|
|
cdfaf761df | ||
|
|
1a9ea6f738 | ||
|
|
945c1c8597 | ||
|
|
e4d0f7acd5 | ||
|
|
250496c953 | ||
|
|
e47dc758c9 | ||
|
|
b92a843c5f | ||
|
|
91bea9c5b3 | ||
|
|
d75bb5cbe1 | ||
|
|
2671259fdb | ||
|
|
2024010119 | ||
|
|
412040f77e | ||
|
|
d210660ce8 | ||
|
|
863a12562b | ||
|
|
5da606a9ac | ||
|
|
8d20f3d5c4 | ||
|
|
5d360180af | ||
|
|
f0fbed6007 | ||
|
|
519de7c833 | ||
|
|
97ccef1a04 | ||
|
|
c4df0dd06e | ||
|
|
cd114c6818 | ||
|
|
1707b8cdba | ||
|
|
41d4d70b98 | ||
|
|
0e999482cb | ||
|
|
65b2c06027 | ||
|
|
d7b61ede07 | ||
|
|
87fc1c84b8 | ||
|
|
d4b5f12383 | ||
|
|
eb62b0d665 | ||
|
|
91387a741b | ||
|
|
e8b34cb00d | ||
|
|
82954258c1 | ||
|
|
50f092551b | ||
|
|
c36a64be68 | ||
|
|
a343b20775 | ||
|
|
a714e76ae1 | ||
|
|
d21d5c9510 | ||
|
|
cd6788a2bb | ||
|
|
6b99399c41 | ||
|
|
952b6af445 | ||
|
|
7c674ad7fa | ||
|
|
d7d2ac3951 | ||
|
|
29e67d307a | ||
|
|
7320b7df62 | ||
|
|
11fb4233f7 | ||
|
|
84bb350b14 | ||
|
|
38e3694d1c | ||
|
|
1084935241 | ||
|
|
f5f0b9ecaa | ||
|
|
230fc49ae2 | ||
|
|
250d507bdf | ||
|
|
a818653174 | ||
|
|
5c3b044740 | ||
|
|
c5aa8729a1 | ||
|
|
3f78d76da1 | ||
|
|
70c19ccf16 | ||
|
|
68db9cb499 | ||
|
|
d0466fa777 | ||
|
|
21ab64e962 | ||
|
|
a0145cebf2 | ||
|
|
69176fc5f4 | ||
|
|
278dce9ba6 | ||
|
|
1cfa3ee4c7 | ||
|
|
9a95cd5794 | ||
|
|
a62fe3df6f | ||
|
|
7701244a08 | ||
|
|
96e31e4b78 | ||
|
|
ec208af474 | ||
|
|
242641264d | ||
|
|
d3a9a0615b | ||
|
|
3277e8c89c | ||
|
|
d02b9442a5 | ||
|
|
bac385b59c | ||
|
|
b1a0ab8086 | ||
|
|
a33749eb71 | ||
|
|
f5e4ee90e4 | ||
|
|
690d5e6dbd | ||
|
|
a76c055b63 | ||
|
|
70c461c60b | ||
|
|
d51b71ee80 | ||
|
|
3666448ca6 | ||
|
|
d3311d9f43 | ||
|
|
3e1735b06e | ||
|
|
de7ef7eace | ||
|
|
7e89458a3b | ||
|
|
f212bafe46 | ||
|
|
86fe40708b | ||
|
|
d718747c5b | ||
|
|
46ee9ac41c | ||
|
|
f1d306feab | ||
|
|
2d0db98e83 | ||
|
|
3df06a1c68 | ||
|
|
a8f9432a3a | ||
|
|
561e0b04a8 | ||
|
|
404b6a864b | ||
|
|
4feaf31225 | ||
|
|
391aa14845 | ||
|
|
a0d61b4c37 | ||
|
|
2952737755 | ||
|
|
f103aa4753 | ||
|
|
884856023a | ||
|
|
d8188fce7b | ||
|
|
0f15f1ab73 | ||
|
|
488a236b7a | ||
|
|
e833823e15 | ||
|
|
ee4ba104e7 | ||
|
|
4fdc08295b | ||
|
|
a3ff49aaf1 | ||
|
|
76364ea767 | ||
|
|
8eec50d764 | ||
|
|
32b659b346 | ||
|
|
00809909ae | ||
|
|
9f7684f6fe | ||
|
|
2bed7d370e | ||
|
|
d2b852f7cb | ||
|
|
901939bd96 | ||
|
|
edfdcc8cee | ||
|
|
3982c9a552 | ||
|
|
4490b2d209 | ||
|
|
eb4bbf3294 | ||
|
|
dc97d48491 | ||
|
|
0f50dc848e | ||
|
|
c5e4b83de3 | ||
|
|
a08ab46713 | ||
|
|
f50a7058d6 | ||
|
|
2c74f0a040 | ||
|
|
58835e40f3 | ||
|
|
8befa5918a | ||
|
|
df80f7ff2a | ||
|
|
5f66786ef1 | ||
|
|
3a965856a5 | ||
|
|
03df609d77 | ||
|
|
178581b560 | ||
|
|
ffd2314120 | ||
|
|
815b595d2f | ||
|
|
11e56403dd | ||
|
|
4baadecda5 | ||
|
|
cf552b5f3b | ||
|
|
1894304d33 | ||
|
|
9d5392fb02 | ||
|
|
c280645671 | ||
|
|
45f92e6b38 | ||
|
|
6509f09961 | ||
|
|
3c279a6f0e | ||
|
|
9ec3f03871 | ||
|
|
84a9c2c112 | ||
|
|
af368119cb | ||
|
|
89b9189efa | ||
|
|
dd59b8c7b9 | ||
|
|
f83491274f | ||
|
|
c0435fdff4 | ||
|
|
3c09c77269 | ||
|
|
547e101f1d | ||
|
|
0130f64934 | ||
|
|
361e0543ee | ||
|
|
63aa5d3b4e | ||
|
|
01302d097c | ||
|
|
e6095cb7e8 | ||
|
|
b876b8af11 | ||
|
|
a7c41f3fcd | ||
|
|
4772bd8d4c | ||
|
|
d471067e3f | ||
|
|
d0b7780239 | ||
|
|
e627ca6bd7 | ||
|
|
c97172bdd4 | ||
|
|
ce8a745fb4 | ||
|
|
3e9efd1401 | ||
|
|
20340190b5 | ||
|
|
265040a78c | ||
|
|
448d7e0c5a | ||
|
|
6eb1874c5a | ||
|
|
4c70745cc1 | ||
|
|
7795748a3f | ||
|
|
098ef4d7cf | ||
|
|
e3f91bfe1b | ||
|
|
7374fe73a3 | ||
|
|
d2bde205f0 | ||
|
|
5620f70f9a | ||
|
|
37f258b1bf | ||
|
|
e2dd2a133e | ||
|
|
7514644e07 | ||
|
|
16b0aeda7d | ||
|
|
86e4f4a841 | ||
|
|
607eacf8c7 | ||
|
|
7a049644a8 | ||
|
|
17a13f00f8 | ||
|
|
43436e48e0 | ||
|
|
5a39102405 | ||
|
|
94999101e3 | ||
|
|
e619b7c4f4 | ||
|
|
b7c2e8cb67 | ||
|
|
fb76893e18 | ||
|
|
88d812fe82 | ||
|
|
77f9f4664a | ||
|
|
5c2f85c39e | ||
|
|
ac4d22cd12 | ||
|
|
cf95e44cb4 | ||
|
|
65dd2bb429 | ||
|
|
6be855be6a | ||
|
|
b6e3f4423b | ||
|
|
0c61d81713 | ||
|
|
7c6f5dba63 | ||
|
|
44cfc7e62a | ||
|
|
96670d5f16 | ||
|
|
36b971ee4e | ||
|
|
f1a9629652 | ||
|
|
20230402d0 | ||
|
|
5c2c3a6c88 | ||
|
|
fb019d43bf | ||
|
|
025aa33773 | ||
|
|
302e21fd58 | ||
|
|
211512ae64 | ||
|
|
8ec917b1c3 | ||
|
|
1c7534f009 | ||
|
|
ae745d9397 | ||
|
|
60f37aae2f | ||
|
|
d7daf5f724 | ||
|
|
e5103d9429 | ||
|
|
8fecb29848 | ||
|
|
290ea6179d | ||
|
|
9695a40fc9 | ||
|
|
1913b95227 | ||
|
|
a874aea692 | ||
|
|
69c52099e7 | ||
|
|
cfc0747d5d | ||
|
|
fcd7e8768d | ||
|
|
3c34dd8275 | ||
|
|
1116e481be | ||
|
|
63cf9d04de | ||
|
|
3364d4d147 | ||
|
|
57ad21e4bd | ||
|
|
414f87981f | ||
|
|
b1459c79cf | ||
|
|
352ea07226 | ||
|
|
27018787af | ||
|
|
4e305eca26 | ||
|
|
9e9c0ceaf4 | ||
|
|
b3bf18b1c0 | ||
|
|
b1619f675f | ||
|
|
96c3de12eb | ||
|
|
719dbb8bae | ||
|
|
f38a7f7f8f | ||
|
|
6ea38b4438 | ||
|
|
f7447aece1 | ||
|
|
aa2b9ec476 | ||
|
|
3ee00f8bc2 | ||
|
|
fccab60a5c | ||
|
|
0f4af38457 | ||
|
|
aef39f1160 | ||
|
|
2023012408 | ||
|
|
95a7661bb1 | ||
|
|
618d317803 | ||
|
|
ae897c8cdb | ||
|
|
d0a0f3c052 | ||
|
|
91b9591b10 | ||
|
|
aa7361337d | ||
|
|
284d77fe2e | ||
|
|
826178f1e2 | ||
|
|
acccf8a9b8 | ||
|
|
57c066f0be | ||
|
|
e44f64ae92 | ||
|
|
d51980a3f5 | ||
|
|
c3d73e7ecb | ||
|
|
b077f6821d | ||
|
|
a79de11af7 | ||
|
|
2023011763 | ||
|
|
b46e40e86b | ||
|
|
a6d6cdd165 | ||
|
|
dc8da605f9 | ||
|
|
8b299a29c7 | ||
|
|
3109b865d2 | ||
|
|
0c5956c43c | ||
|
|
1c83b39691 | ||
|
|
77874b473c | ||
|
|
b7cce7be15 | ||
|
|
3cd3362417 | ||
|
|
e97e925efb | ||
|
|
0f032235cf | ||
|
|
e0f0984da7 | ||
|
|
4d22b5aaef | ||
|
|
80b8846318 | ||
|
|
bf641faafa | ||
|
|
23d8b78ce1 | ||
|
|
3b2244077d | ||
|
|
ee5cdb9713 | ||
|
|
03d02d67f7 | ||
|
|
5798145581 | ||
|
|
51ef0b7f66 | ||
|
|
97b4542c73 | ||
|
|
c1cd0c09a2 | ||
|
|
1fc1f47d80 | ||
|
|
ec471a5bc2 | ||
|
|
a893fc0ca2 | ||
|
|
3761dc0433 | ||
|
|
aa71a07fbe | ||
|
|
088293f5e7 | ||
|
|
7c660aa86e | ||
|
|
435d8fa0a2 | ||
|
|
5cd6f1d064 | ||
|
|
ec20dfe312 | ||
|
|
924ffb5a35 | ||
|
|
62c7f59b94 | ||
|
|
e97176b1d7 | ||
|
|
d649f5d826 | ||
|
|
6c37177cf5 | ||
|
|
14775aa975 | ||
|
|
44b6336372 | ||
|
|
36d2bb332b | ||
|
|
4dbe45640a | ||
|
|
4b3f0b9f08 | ||
|
|
12af069dca | ||
|
|
d42e708d31 | ||
|
|
b7bb973118 | ||
|
|
750b2a6313 | ||
|
|
de0da86bd7 | ||
|
|
8e283f512a | ||
|
|
73162a4bc3 | ||
|
|
1a9761736e | ||
|
|
fd1f7665a7 | ||
|
|
6d14573fd0 | ||
|
|
cf69b836ac | ||
|
|
a7a771b92b | ||
|
|
def011c029 | ||
|
|
4b055bf260 | ||
|
|
1ba7484d60 | ||
|
|
51c518da1e | ||
|
|
a3b6b03dfb | ||
|
|
18e3b38c69 | ||
|
|
0ad30063ff | ||
|
|
7812c64a31 | ||
|
|
3d2376ab52 | ||
|
|
6b207bbf2b | ||
|
|
3f079ba7c6 | ||
|
|
8f4c89f50e | ||
|
|
6b7a543c82 | ||
|
|
2ba68d24f2 | ||
|
|
46877e0a92 | ||
|
|
b55f555487 | ||
|
|
a38b63be18 | ||
|
|
1bebd6f4f5 | ||
|
|
3da63f394d | ||
|
|
2a54e3d770 | ||
|
|
06b02ba46e | ||
|
|
d01ae55109 | ||
|
|
8868d7d188 | ||
|
|
2eec9892be | ||
|
|
01ae621f11 | ||
|
|
f984aa0d2c | ||
|
|
0881a6bc17 | ||
|
|
2c6a73546d | ||
|
|
a29944660e | ||
|
|
f6ce624c6f | ||
|
|
c09ec8e4d1 | ||
|
|
31bbaad06e | ||
|
|
b9ca1fe830 | ||
|
|
e61585f2f3 | ||
|
|
0de1aacb0c | ||
|
|
168829b555 | ||
|
|
170fc517d0 | ||
|
|
0fbf1c7c71 | ||
|
|
694be39c71 | ||
|
|
dad26d81df | ||
|
|
bcaea097ea | ||
|
|
d56fe74e24 | ||
|
|
4603d540c3 | ||
|
|
f9d53303bb | ||
|
|
d04faa6505 | ||
|
|
07da058eae | ||
|
|
cefa6b9878 | ||
|
|
04d0b0223f | ||
|
|
78ad6d2d88 | ||
|
|
22cbd9fa58 | ||
|
|
984049586a | ||
|
|
cdfc2b92e3 | ||
|
|
4530abe8df | ||
|
|
586020b8b6 | ||
|
|
3a8626fd04 | ||
|
|
a6e483a434 | ||
|
|
6a942e56b1 | ||
|
|
87c91550ad | ||
|
|
731daf0f37 | ||
|
|
f931e53890 | ||
|
|
b5efc68737 | ||
|
|
b9e6e7926c | ||
|
|
845034c81c | ||
|
|
54d42e3f40 | ||
|
|
e03ac3136e | ||
|
|
6fb41a202a | ||
|
|
4bef330ce1 | ||
|
|
8a5f719964 | ||
|
|
209d5e8e90 | ||
|
|
9d041aa582 | ||
|
|
6532b3e655 | ||
|
|
c1c355160d | ||
|
|
83515d5610 | ||
|
|
aa10dccf90 | ||
|
|
f4fd53211a | ||
|
|
4993d19466 | ||
|
|
19f9bbca0d | ||
|
|
779d8e1627 | ||
|
|
bb07410448 | ||
|
|
d826f9e72f | ||
|
|
6a6130615d | ||
|
|
a8e7021be2 | ||
|
|
38259d0382 | ||
|
|
f7e7259910 | ||
|
|
f0bfeba733 | ||
|
|
c3a7a24eea | ||
|
|
bbbcd780c9 | ||
|
|
475469a2e7 | ||
|
|
3a7447dcb6 | ||
|
|
e5d8cbd383 | ||
|
|
3c08dca7e7 | ||
|
|
d083f01d22 | ||
|
|
68cf393644 | ||
|
|
18f7230662 | ||
|
|
728f735281 | ||
|
|
ecc418ba77 | ||
|
|
3af5b7f2ac | ||
|
|
7a7cfcacbe | ||
|
|
52594355bf | ||
|
|
0d06c28b19 | ||
|
|
ccc4677252 | ||
|
|
821fc9feed | ||
|
|
82b46726fc | ||
|
|
8df872a482 | ||
|
|
c79c306adb | ||
|
|
51fdaad002 | ||
|
|
885cd8ff04 | ||
|
|
2707af403a | ||
|
|
2d227e5222 | ||
|
|
70529878e2 | ||
|
|
3b7a962dc6 | ||
|
|
6dcf5c3d7d | ||
|
|
b089bb5e7b | ||
|
|
a91a67668e | ||
|
|
220a908118 | ||
|
|
54841248e7 | ||
|
|
a0b42e6538 | ||
|
|
3312cf525d | ||
|
|
2093667548 | ||
|
|
3c868d7961 | ||
|
|
707f4f5816 | ||
|
|
b3ab6311c5 | ||
|
|
d56f605b63 | ||
|
|
f8b713f425 | ||
|
|
5209e95bc7 | ||
|
|
ef67a45702 | ||
|
|
b88eb72ac2 | ||
|
|
32847f7254 | ||
|
|
71df93b534 | ||
|
|
bb028191f8 | ||
|
|
19af8fc7d8 | ||
|
|
a06671b47f | ||
|
|
5f385d88e0 | ||
|
|
9cb7a364a3 | ||
|
|
f68cbc577d | ||
|
|
dc975e8974 | ||
|
|
4311ade535 | ||
|
|
cd23401411 | ||
|
|
176ee6910f | ||
|
|
13c8f3d3aa | ||
|
|
ce9af687bc | ||
|
|
43f0d0cacd | ||
|
|
20b4e6953e | ||
|
|
7da287e3aa | ||
|
|
205f885d69 | ||
|
|
3715cd349d | ||
|
|
e4c3ecc57e | ||
|
|
673c5d886d | ||
|
|
f799b568d1 | ||
|
|
7bff4661f6 | ||
|
|
ffd8bef808 | ||
|
|
02cee2234d | ||
|
|
e0dd2be3fb | ||
|
|
a33c011c21 | ||
|
|
7c3f42bbba | ||
|
|
edac9820b5 | ||
|
|
84a47f7102 | ||
|
|
97ae8afb6f | ||
|
|
4138333f5c | ||
|
|
61339a8ae2 | ||
|
|
50eb2e3855 | ||
|
|
5fc78e4584 | ||
|
|
2736a2f69e | ||
|
|
179993f0cd | ||
|
|
b734f657f9 | ||
|
|
c29d7d02c2 | ||
|
|
3df6b2a58c | ||
|
|
b8aa2d2c32 | ||
|
|
0ff885461b | ||
|
|
ca43f95fb1 | ||
|
|
09700f676b | ||
|
|
4271e9cffa | ||
|
|
f3dc8a10d5 | ||
|
|
00fb486f6a | ||
|
|
4173e94c6f | ||
|
|
261d3d3340 | ||
|
|
15e20fcae1 | ||
|
|
f4f47f5fe3 | ||
|
|
71d11de7ca | ||
|
|
88d74a15aa | ||
|
|
0f02fc0c77 | ||
|
|
3f90fb42d8 | ||
|
|
9bd8988300 | ||
|
|
3c804bcfec | ||
|
|
cca4cdc4f1 | ||
|
|
8f899aaf8a | ||
|
|
e53b4bb439 | ||
|
|
ab247a1309 | ||
|
|
c21e9edad4 | ||
|
|
9c21a20f8b | ||
|
|
7191ebb615 | ||
|
|
a74731d7f5 | ||
|
|
e086f0b3fe | ||
|
|
8255aa23f4 | ||
|
|
a4bc08f5a3 | ||
|
|
7e5aa1e2a5 | ||
|
|
0818dbc36a | ||
|
|
347c4b2625 | ||
|
|
34f0d4d0c4 | ||
|
|
cbedb57511 | ||
|
|
9ef825d2fd | ||
|
|
85ae745910 | ||
|
|
7411da8d5a | ||
|
|
3f75a8369f | ||
|
|
4cd621e877 | ||
|
|
6e3a2fe0bf | ||
|
|
8b0e1f941a | ||
|
|
c7c5e7670a | ||
|
|
f6c621ef1b | ||
|
|
faf32d451d | ||
|
|
252fd7ecb1 | ||
|
|
7fa89dddb4 | ||
|
|
fefdb8c84e | ||
|
|
a6cc05936e | ||
|
|
b209843545 | ||
|
|
19759ed36e | ||
|
|
1a7ae8e7b9 | ||
|
|
da1f645670 | ||
|
|
3a2015ee26 | ||
|
|
c440418ce6 | ||
|
|
3d37a5ba1d | ||
|
|
15f4cfb6d9 | ||
|
|
be36de2482 | ||
|
|
391237f7df | ||
|
|
977e5effd9 | ||
|
|
8b36a4cb19 | ||
|
|
c8cd94a772 | ||
|
|
764316a53d | ||
|
|
2048fd4042 | ||
|
|
f84b3de24b | ||
|
|
6a1f3ec08b | ||
|
|
2e353aee96 | ||
|
|
8edfd14a37 | ||
|
|
1a191ec6f7 | ||
|
|
e7171e94b4 | ||
|
|
398d937419 | ||
|
|
34fe5ab143 | ||
|
|
1b08f43f82 | ||
|
|
b24a2e2fdc | ||
|
|
4c4c6e626e | ||
|
|
7310370a31 | ||
|
|
8ae94f0059 | ||
|
|
8fccf20892 | ||
|
|
5a874ae241 | ||
|
|
f4e1ed25f2 | ||
|
|
cbfbb49ab4 | ||
|
|
489b16efce | ||
|
|
b82c1693c0 | ||
|
|
019bfc4e35 | ||
|
|
dfda5c054a | ||
|
|
f657169616 | ||
|
|
4c06da8b70 | ||
|
|
9fe2393a00 | ||
|
|
e2e8d94b14 | ||
|
|
4f9a7f8c87 | ||
|
|
bb0502ff44 | ||
|
|
c256442245 | ||
|
|
1137404190 | ||
|
|
d57c6d0284 | ||
|
|
76bbf57b3d | ||
|
|
806a47a7cc | ||
|
|
29851c18aa | ||
|
|
dea950c2c8 | ||
|
|
a367dfb22e | ||
|
|
9fe1a7b373 | ||
|
|
8e2d21c548 | ||
|
|
bedf1cd357 | ||
|
|
13f180a70c | ||
|
|
6654239c94 | ||
|
|
1b61e5e9e9 | ||
|
|
43b3b907f8 | ||
|
|
fcd896508b | ||
|
|
f55c990e86 | ||
|
|
d110372f99 | ||
|
|
c862af09f2 | ||
|
|
1cfeec0ca3 | ||
|
|
a0649edc1e | ||
|
|
0e0bcb3e10 | ||
|
|
686528d627 | ||
|
|
3afa920151 | ||
|
|
32c493e994 | ||
|
|
1a76bdf891 | ||
|
|
af48b3df29 | ||
|
|
58ac1fb2fa | ||
|
|
e922704f72 | ||
|
|
c6115735c7 | ||
|
|
9ddf5c72be | ||
|
|
cc5640326b | ||
|
|
bf447d7703 | ||
|
|
cbb008c938 | ||
|
|
eaa0c52b45 | ||
|
|
82791f7efc | ||
|
|
8c533e34ea | ||
|
|
37708ad9cd | ||
|
|
090dee857f | ||
|
|
d779ff7e6d | ||
|
|
fd8858f8c9 | ||
|
|
b234647a63 | ||
|
|
6e93eefc82 | ||
|
|
38fca30125 | ||
|
|
012ee9ca85 | ||
|
|
151252e33a | ||
|
|
7136cfc68b | ||
|
|
408c04f25f | ||
|
|
7f8e0dbc40 | ||
|
|
0de7ab18f6 | ||
|
|
e9bc7331bd | ||
|
|
797dd7c449 | ||
|
|
f37ccaa64f | ||
|
|
ab3937ee5a | ||
|
|
00f4551a7b | ||
|
|
257ddd028d | ||
|
|
e0a22e76f8 | ||
|
|
00a3610331 | ||
|
|
f502725120 | ||
|
|
b62a74b315 | ||
|
|
2ec382ae0e | ||
|
|
cbfee31593 | ||
|
|
6d647e13ff | ||
|
|
d2af3ff98d | ||
|
|
052d17e66a | ||
|
|
a9bc954e17 | ||
|
|
2983426771 | ||
|
|
c61eb94b3f | ||
|
|
3829eab1cf | ||
|
|
3fe8eeedc5 | ||
|
|
1efef88b6e | ||
|
|
7acdaf0b43 | ||
|
|
1ed25d76ba | ||
|
|
474c1f5e32 | ||
|
|
8b71fea5dc | ||
|
|
7bd99a22ee | ||
|
|
75b8cca3b3 | ||
|
|
ef2c29d5d4 | ||
|
|
218b3c8274 | ||
|
|
db9cb2ddda | ||
|
|
722d66e85a | ||
|
|
f6269f0193 | ||
|
|
520eae817a | ||
|
|
d099941360 | ||
|
|
e3e76fa8c5 | ||
|
|
2553806e79 | ||
|
|
1bcbc5a353 | ||
|
|
15d351b0f0 | ||
|
|
c144c95cda | ||
|
|
f08f4fd87d | ||
|
|
f8aaeef218 | ||
|
|
7915e365b3 | ||
|
|
1c68f81c37 | ||
|
|
d4c9db0a27 | ||
|
|
b5e0e29ec6 | ||
|
|
569be4c6c9 | ||
|
|
e7ca237b07 | ||
|
|
a7d3b72117 | ||
|
|
3ba7b5cf2d | ||
|
|
254e9765fe | ||
|
|
3304f284a5 | ||
|
|
0d5f862daf | ||
|
|
51dfacd542 | ||
|
|
c691d52fa7 | ||
|
|
de3d09fe79 | ||
|
|
eaa413c566 | ||
|
|
407205e52b | ||
|
|
552414978e | ||
|
|
607081bbaa | ||
|
|
e73383fbbb | ||
|
|
2e8e63fb0b | ||
|
|
874f7dd416 | ||
|
|
8b0e3b1624 | ||
|
|
9b946f2b7a | ||
|
|
11841f688b | ||
|
|
03c4f04246 | ||
|
|
a1f06ae27f | ||
|
|
69dffd78a6 | ||
|
|
2750e19657 | ||
|
|
b0987f727b | ||
|
|
a4d9b0b468 | ||
|
|
e2b87e0d74 | ||
|
|
2166b4ca17 | ||
|
|
d2d4d68585 | ||
|
|
faf68dbc5c | ||
|
|
305896fcb3 | ||
|
|
6c9adea0d3 | ||
|
|
fc7630a66d | ||
|
|
3248153d9f | ||
|
|
246b9f3130 | ||
|
|
865144850d | ||
|
|
d9752a4c21 | ||
|
|
dba14d2630 | ||
|
|
2986e64a49 | ||
|
|
1d8bd11b67 | ||
|
|
bafb99d520 | ||
|
|
3cc8a74a91 | ||
|
|
c0aa5a438f | ||
|
|
825d401403 | ||
|
|
9dfca77c36 | ||
|
|
82c4af2902 | ||
|
|
736344e151 | ||
|
|
6f9663da62 | ||
|
|
f8ae1786dd | ||
|
|
c60ed17583 | ||
|
|
e0f0b5bcf9 | ||
|
|
9e96073128 | ||
|
|
0db65c22d3 | ||
|
|
d785135606 | ||
|
|
ae15eda546 | ||
|
|
f2d44ab5a7 | ||
|
|
43798fc2e8 | ||
|
|
9dc4b40d7a | ||
|
|
1cb19dbf65 | ||
|
|
1ab4289ad6 | ||
|
|
e2ae1b249c | ||
|
|
92b7efafca | ||
|
|
f092e4038f | ||
|
|
aa5dae391b | ||
|
|
08a6fd4ad4 | ||
|
|
a61150a96c | ||
|
|
0f9cb5590e | ||
|
|
c0a83b27eb | ||
|
|
f79b1f71b8 | ||
|
|
8e027c445f | ||
|
|
dda3e3c39a | ||
|
|
fd5157998c | ||
|
|
e0217e8c79 | ||
|
|
3ab1c42266 | ||
|
|
d1676776aa | ||
|
|
bdde69d011 | ||
|
|
6dec42a33a | ||
|
|
199bc3f0ad | ||
|
|
17dd833925 | ||
|
|
4ec144c969 | ||
|
|
3e36f2b0ac | ||
|
|
07a03b3e73 | ||
|
|
c33258832e | ||
|
|
a7aa08ce07 | ||
|
|
06d63a862e | ||
|
|
43d1c4c4b5 | ||
|
|
f81feb1e69 | ||
|
|
01cf01e084 | ||
|
|
97a725fbd0 | ||
|
|
ace92ba281 | ||
|
|
d631c76e8d | ||
|
|
e6d33f77da | ||
|
|
a6d3e3687b | ||
|
|
08c2bcb952 | ||
|
|
98ca4bdede | ||
|
|
3f8e741562 | ||
|
|
6e464ebd9b | ||
|
|
c329279339 | ||
|
|
cf04753ad7 | ||
|
|
69e7eab11f | ||
|
|
dea206b023 | ||
|
|
5deaf58928 | ||
|
|
15e2952a2b | ||
|
|
a9fba1c849 | ||
|
|
71e573d082 | ||
|
|
334a4fa159 | ||
|
|
21f94ee800 | ||
|
|
540bfd7a72 | ||
|
|
8fbed2b13a | ||
|
|
aa17510e0a | ||
|
|
bf65e8cd12 | ||
|
|
0f5c6e8f04 | ||
|
|
b1b916ce15 | ||
|
|
a6a732e1fc | ||
|
|
a5c2f28539 | ||
|
|
18261fe31c | ||
|
|
079046863c | ||
|
|
07b965bba1 | ||
|
|
c39113ee41 | ||
|
|
14f90502a4 | ||
|
|
b0673c3563 | ||
|
|
373c6d8d55 | ||
|
|
b8fc828955 | ||
|
|
b43b040512 | ||
|
|
50b7608f9d | ||
|
|
7085e5b629 | ||
|
|
7d5985baf9 | ||
|
|
7c40a424c0 | ||
|
|
baf882ace7 | ||
|
|
ba82f0bef9 | ||
|
|
d9c6a0305b | ||
|
|
d9b1211191 | ||
|
|
99f1e02766 | ||
|
|
242c0db26b | ||
|
|
dd49e41c42 | ||
|
|
6db15e8693 | ||
|
|
4c9cab3f8a | ||
|
|
b2c0413a98 | ||
|
|
e34c7c00b1 | ||
|
|
7c447bbdc7 | ||
|
|
7bf1f2cc84 | ||
|
|
afa2c4e0af | ||
|
|
2ff7db1b36 | ||
|
|
9f0626da64 | ||
|
|
d8cb5c1cf5 | ||
|
|
dca56da0ef | ||
|
|
ec75d16ea8 | ||
|
|
5cae8ea733 | ||
|
|
1ccd8f6a64 | ||
|
|
9c293bb82b | ||
|
|
9897ee9591 | ||
|
|
5215415315 | ||
|
|
54891d11e0 | ||
|
|
567c8303bf | ||
|
|
2a60edcd52 | ||
|
|
d61ac32d7b | ||
|
|
b57e6cff7e | ||
|
|
5b99f19dac | ||
|
|
6c03571887 | ||
|
|
4fb410a93c | ||
|
|
5e1db9fdd3 | ||
|
|
9d7480ae3c | ||
|
|
f39cf6d855 | ||
|
|
001d116884 | ||
|
|
02c5e62efe | ||
|
|
446df07b62 | ||
|
|
8583b150c9 | ||
|
|
a859aa72ee | ||
|
|
0896036266 | ||
|
|
311b78ae82 | ||
|
|
f5cf4fc8fb | ||
|
|
7ceb58b2aa | ||
|
|
293dd76af1 | ||
|
|
3918c45ced | ||
|
|
4ec403347c | ||
|
|
e01266ffcb | ||
|
|
f246fb2fc2 | ||
|
|
f7b26b34cb | ||
|
|
a1bcdc225e | ||
|
|
7771241cc0 | ||
|
|
6e3af646b2 | ||
|
|
82bf8c138d | ||
|
|
e21b001116 | ||
|
|
577024f1e9 | ||
|
|
d4ad4a25db | ||
|
|
30577b0c17 | ||
|
|
212de25409 | ||
|
|
5da8bbf45a | ||
|
|
aa0e10ead7 | ||
|
|
a9906c7c29 | ||
|
|
9fefe08b3f | ||
|
|
684bfff713 | ||
|
|
3db6b88d82 | ||
|
|
8ae96774df | ||
|
|
f68017d21e | ||
|
|
2b725a4db5 | ||
|
|
af1a5f130b | ||
|
|
86e3994e87 | ||
|
|
1e6ac5590e | ||
|
|
5e42b1c9f8 | ||
|
|
9d842630c9 | ||
|
|
77cb906dfe | ||
|
|
a59e846f74 | ||
|
|
6e6340a0c9 | ||
|
|
357e82e51b | ||
|
|
394d8cfd18 | ||
|
|
ef80bd401f | ||
|
|
f51d61d57a | ||
|
|
1dd256a68a | ||
|
|
85644aa3fb | ||
|
|
effbc258bb | ||
|
|
e615600ff1 | ||
|
|
60465c4664 | ||
|
|
c03c058bd5 | ||
|
|
7238c8944d | ||
|
|
9a41fd5327 | ||
|
|
b471042037 | ||
|
|
2886f06977 | ||
|
|
d630484eeb | ||
|
|
e24299239e | ||
|
|
d2fa470165 | ||
|
|
168453da71 | ||
|
|
23a06d63ac | ||
|
|
751aa1944a | ||
|
|
05b5f3f845 | ||
|
|
16fc6862a8 | ||
|
|
7e1c0f39e7 | ||
|
|
deccf20a35 | ||
|
|
73c0a645e0 | ||
|
|
e975bd0c8d | ||
|
|
78da928727 | ||
|
|
11962dabba | ||
|
|
dceb5d09cd | ||
|
|
b4cccf23d4 | ||
|
|
b911af200c | ||
|
|
68683c444f | ||
|
|
a185593d65 | ||
|
|
525040238e | ||
|
|
33f89a08f3 | ||
|
|
11645e1fac | ||
|
|
6390140539 | ||
|
|
072066c49c | ||
|
|
a2e9366c84 | ||
|
|
391669a451 | ||
|
|
0c6c76e081 | ||
|
|
f1520bdde6 | ||
|
|
3089880f18 | ||
|
|
ab11b74be4 | ||
|
|
a5a97be017 | ||
|
|
80b5bc1b68 | ||
|
|
5c7dcaffe8 | ||
|
|
5095899245 | ||
|
|
4800e5d2ae | ||
|
|
3b1e37f718 | ||
|
|
6577388250 | ||
|
|
3b9dbd4146 | ||
|
|
a1260feeed | ||
|
|
7322504ad0 | ||
|
|
de569f0052 | ||
|
|
e7097a9d25 | ||
|
|
c1dbc800e5 | ||
|
|
951746297e | ||
|
|
984304568d | ||
|
|
723217bdea | ||
|
|
0fdb71f7e4 | ||
|
|
12ce76b56a | ||
|
|
0030d18448 | ||
|
|
0e3e6ac442 | ||
|
|
430e8193e0 | ||
|
|
03e8ed4d88 | ||
|
|
ef492f6178 | ||
|
|
8eea45ef50 | ||
|
|
ff951341c9 | ||
|
|
df570afd52 | ||
|
|
07d755df11 | ||
|
|
37585bd5a5 | ||
|
|
89e24bf8f2 | ||
|
|
8d2fcd3518 | ||
|
|
f39ab3875e | ||
|
|
82efe6c60d | ||
|
|
75972d59a8 | ||
|
|
e7d60aac9c | ||
|
|
a0bfbdd49c | ||
|
|
ba594982f0 | ||
|
|
2157f4f193 | ||
|
|
309bae423c | ||
|
|
4f8bf2ae78 | ||
|
|
85c1f8a9e0 | ||
|
|
e00e7e1e56 | ||
|
|
1a6defdbcc | ||
|
|
ef577a6509 | ||
|
|
b7c6838e45 | ||
|
|
91d04cec5c | ||
|
|
3bd8441079 | ||
|
|
8cf45a5197 | ||
|
|
8dc1377efb | ||
|
|
6c32148f90 | ||
|
|
315e568de0 | ||
|
|
5d16b28869 | ||
|
|
5624a89231 | ||
|
|
63c42b14f2 | ||
|
|
6f1eaa9b39 | ||
|
|
ca42e5e00a | ||
|
|
61feee690c | ||
|
|
d4ed955aee | ||
|
|
b46227dcb6 | ||
|
|
fd8d371ac7 | ||
|
|
0e06e298d4 | ||
|
|
72df905902 | ||
|
|
0d748a0699 | ||
|
|
27c40dc6b0 | ||
|
|
8e34e6fbb4 | ||
|
|
3bc98ed623 | ||
|
|
70a92a858a | ||
|
|
49d04374a4 | ||
|
|
8540902a35 | ||
|
|
8c6fcee3ca | ||
|
|
13803d0dbb | ||
|
|
423986996a | ||
|
|
1c9e7b7ea6 | ||
|
|
6de1ad9d3d | ||
|
|
5004ae3457 | ||
|
|
e67cc75063 | ||
|
|
0edbcbdf19 | ||
|
|
f0fe79dd3b | ||
|
|
daa1958f86 | ||
|
|
2c26f02f5c | ||
|
|
af87650bc4 | ||
|
|
2b19c0bc68 | ||
|
|
76a2dcb5a9 | ||
|
|
68ec3d1c10 | ||
|
|
2ff19084ca | ||
|
|
62f062ecfa | ||
|
|
cce17ad0a0 | ||
|
|
b8296a91b9 | ||
|
|
6e9452b06e | ||
|
|
888fd35689 | ||
|
|
1fb0fbca58 | ||
|
|
ddd2a109e4 | ||
|
|
87504a528e | ||
|
|
6eac4af7db | ||
|
|
89de1340af | ||
|
|
9e753a0d44 | ||
|
|
f57920ad90 | ||
|
|
7dbbbef51a | ||
|
|
7add75126d | ||
|
|
d207672bd5 | ||
|
|
851fa38251 | ||
|
|
43345fb642 | ||
|
|
9ff33814ea | ||
|
|
21b94d2de5 | ||
|
|
24236860c8 | ||
|
|
3f868fd792 | ||
|
|
417bca03df | ||
|
|
cce6aef557 | ||
|
|
eb3afc03b5 | ||
|
|
7f0caf0683 | ||
|
|
7f606665cb | ||
|
|
202872c2dc | ||
|
|
93aeae1985 | ||
|
|
5c34ab6692 | ||
|
|
390b49653b | ||
|
|
b877c385f0 | ||
|
|
9c47739c0e | ||
|
|
04aa2992e7 | ||
|
|
2f1edeff78 | ||
|
|
306d51cdcf | ||
|
|
54a026525a | ||
|
|
d6588fc835 | ||
|
|
5a7b41a2cf | ||
|
|
338a73d764 | ||
|
|
c20954f020 | ||
|
|
1e8e1d3c9d | ||
|
|
f6b1962056 | ||
|
|
b3b101a89c | ||
|
|
9615c4edf1 | ||
|
|
85a75ee035 | ||
|
|
1e5bd55672 | ||
|
|
37d4015d56 | ||
|
|
6b27554cdb | ||
|
|
fc1b119159 | ||
|
|
2cd0d4a9f7 | ||
|
|
fd03aabeb2 | ||
|
|
8068c975c2 | ||
|
|
a6d2ab3360 | ||
|
|
fe7b91dfd9 | ||
|
|
5784101bea | ||
|
|
eaf6eb8978 | ||
|
|
3af63bcf1f | ||
|
|
80a21f7a75 |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
github: junegunn
|
||||||
30
.github/ISSUE_TEMPLATE.md
vendored
30
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,30 +0,0 @@
|
|||||||
<!-- Check all that apply [x] -->
|
|
||||||
- Category
|
|
||||||
- [ ] fzf binary
|
|
||||||
- [ ] fzf-tmux script
|
|
||||||
- [ ] Key bindings
|
|
||||||
- [ ] Completion
|
|
||||||
- [ ] Vim
|
|
||||||
- [ ] Neovim
|
|
||||||
- [ ] Etc.
|
|
||||||
- OS
|
|
||||||
- [ ] Linux
|
|
||||||
- [ ] Mac OS X
|
|
||||||
- [ ] Windows
|
|
||||||
- [ ] Windows Subsystem for Linux
|
|
||||||
- [ ] Etc.
|
|
||||||
- Shell
|
|
||||||
- [ ] bash
|
|
||||||
- [ ] zsh
|
|
||||||
- [ ] fish
|
|
||||||
|
|
||||||
<!--
|
|
||||||
### Before submitting
|
|
||||||
|
|
||||||
- Make sure that you have the latest version of fzf
|
|
||||||
- If you use tmux, make sure $TERM is set to screen or screen-256color
|
|
||||||
- For more Vim stuff, check out https://github.com/junegunn/fzf.vim
|
|
||||||
|
|
||||||
Describe your problem or suggestion from here ...
|
|
||||||
-->
|
|
||||||
|
|
||||||
49
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
Normal file
49
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
---
|
||||||
|
name: Issue Template
|
||||||
|
description: Report a problem or bug related to fzf to help us improve
|
||||||
|
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: ISSUES NOT FOLLOWING THIS TEMPLATE WILL BE CLOSED AND DELETED
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Checklist
|
||||||
|
options:
|
||||||
|
- label: I have read through the manual page (`man fzf`)
|
||||||
|
required: true
|
||||||
|
- label: I have searched through the existing issues
|
||||||
|
required: true
|
||||||
|
- label: For bug reports, I have checked if the bug is reproducible in the latest version of fzf
|
||||||
|
required: false
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Output of `fzf --version`
|
||||||
|
placeholder: e.g. 0.48.1 (d579e33)
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: OS
|
||||||
|
options:
|
||||||
|
- label: Linux
|
||||||
|
- label: macOS
|
||||||
|
- label: Windows
|
||||||
|
- label: Etc.
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Shell
|
||||||
|
options:
|
||||||
|
- label: bash
|
||||||
|
- label: zsh
|
||||||
|
- label: fish
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Problem / Steps to reproduce
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
10
.github/dependabot.yml
vendored
Normal file
10
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "gomod"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
44
.github/workflows/codeql-analysis.yml
vendored
Normal file
44
.github/workflows/codeql-analysis.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning
|
||||||
|
name: CodeQL
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, devel ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
analyze:
|
||||||
|
permissions:
|
||||||
|
actions: read # for github/codeql-action/init to get workflow details
|
||||||
|
contents: read # for actions/checkout to fetch code
|
||||||
|
security-events: write # for github/codeql-action/autobuild to send a status report
|
||||||
|
name: Analyze
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
language: ['go']
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v3
|
||||||
|
with:
|
||||||
|
languages: ${{ matrix.language }}
|
||||||
|
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v3
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v3
|
||||||
14
.github/workflows/depsreview.yaml
vendored
Normal file
14
.github/workflows/depsreview.yaml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name: 'Dependency Review'
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dependency-review:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: 'Checkout Repository'
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: 'Dependency Review'
|
||||||
|
uses: actions/dependency-review-action@v4
|
||||||
48
.github/workflows/linux.yml
vendored
Normal file
48
.github/workflows/linux.yml
vendored
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
---
|
||||||
|
name: Test fzf on Linux
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, devel ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
LANG: C.UTF-8
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: "1.20"
|
||||||
|
|
||||||
|
- name: Setup Ruby
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 3.1.0
|
||||||
|
|
||||||
|
- name: Install packages
|
||||||
|
run: sudo apt-get install --yes zsh fish tmux
|
||||||
|
|
||||||
|
- name: Install Ruby gems
|
||||||
|
run: sudo gem install --no-document minitest:5.25.1 rubocop:1.65.0 rubocop-minitest:0.35.1 rubocop-performance:1.21.1
|
||||||
|
|
||||||
|
- name: Rubocop
|
||||||
|
run: rubocop --require rubocop-minitest --require rubocop-performance
|
||||||
|
|
||||||
|
- name: Unit test
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
- name: Integration test
|
||||||
|
run: make install && ./install --all && tmux new-session -d && ruby test/test_go.rb --verbose
|
||||||
45
.github/workflows/macos.yml
vendored
Normal file
45
.github/workflows/macos.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
name: Test fzf on macOS
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master, devel ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: macos-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
go-version: "1.20"
|
||||||
|
|
||||||
|
- name: Setup Ruby
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 3.0.0
|
||||||
|
|
||||||
|
- name: Install packages
|
||||||
|
run: HOMEBREW_NO_INSTALL_CLEANUP=1 brew install fish zsh tmux
|
||||||
|
|
||||||
|
- name: Install Ruby gems
|
||||||
|
run: gem install --no-document minitest:5.14.2 rubocop:1.0.0 rubocop-minitest:0.10.1 rubocop-performance:1.8.1
|
||||||
|
|
||||||
|
- name: Rubocop
|
||||||
|
run: rubocop --require rubocop-minitest --require rubocop-performance
|
||||||
|
|
||||||
|
- name: Unit test
|
||||||
|
run: make test
|
||||||
|
|
||||||
|
- name: Integration test
|
||||||
|
run: make install && ./install --all && LC_ALL=C tmux new-session -d && ruby test/test_go.rb --verbose
|
||||||
24
.github/workflows/sponsors.yml
vendored
Normal file
24
.github/workflows/sponsors.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
name: Generate Sponsors README
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
schedule:
|
||||||
|
- cron: 0 0 * * 0
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout 🛎️
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Generate Sponsors 💖
|
||||||
|
uses: JamesIves/github-sponsors-readme-action@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.SPONSORS_TOKEN }}
|
||||||
|
file: 'README.md'
|
||||||
|
|
||||||
|
- name: Deploy to GitHub Pages 🚀
|
||||||
|
uses: JamesIves/github-pages-deploy-action@v4
|
||||||
|
with:
|
||||||
|
branch: master
|
||||||
|
folder: '.'
|
||||||
10
.github/workflows/typos.yml
vendored
Normal file
10
.github/workflows/typos.yml
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
name: "Spell Check"
|
||||||
|
on: [pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
typos:
|
||||||
|
name: Spell Check with Typos
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: crate-ci/typos@v1.24.1
|
||||||
14
.github/workflows/winget.yml
vendored
Normal file
14
.github/workflows/winget.yml
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
name: Publish to Winget
|
||||||
|
on:
|
||||||
|
release:
|
||||||
|
types: [released]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: vedantmgoyal2009/winget-releaser@v2
|
||||||
|
with:
|
||||||
|
identifier: junegunn.fzf
|
||||||
|
installers-regex: '-windows_(armv7|arm64|amd64)\.zip$'
|
||||||
|
token: ${{ secrets.WINGET_TOKEN }}
|
||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
bin/fzf
|
bin/fzf
|
||||||
|
bin/fzf.exe
|
||||||
|
dist
|
||||||
target
|
target
|
||||||
pkg
|
pkg
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
@@ -6,3 +8,7 @@ Gemfile.lock
|
|||||||
doc/tags
|
doc/tags
|
||||||
vendor
|
vendor
|
||||||
gopath
|
gopath
|
||||||
|
*.zwc
|
||||||
|
fzf
|
||||||
|
tmp
|
||||||
|
*.patch
|
||||||
|
|||||||
104
.goreleaser.yml
Normal file
104
.goreleaser.yml
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
---
|
||||||
|
version: 2
|
||||||
|
project_name: fzf
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- go mod download
|
||||||
|
|
||||||
|
builds:
|
||||||
|
- id: fzf
|
||||||
|
goos:
|
||||||
|
- darwin
|
||||||
|
- linux
|
||||||
|
- windows
|
||||||
|
- freebsd
|
||||||
|
- openbsd
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm
|
||||||
|
- arm64
|
||||||
|
- loong64
|
||||||
|
- ppc64le
|
||||||
|
- s390x
|
||||||
|
goarm:
|
||||||
|
- 5
|
||||||
|
- 6
|
||||||
|
- 7
|
||||||
|
flags:
|
||||||
|
- -trimpath
|
||||||
|
ldflags:
|
||||||
|
- "-s -w -X main.version={{ .Version }} -X main.revision={{ .ShortCommit }}"
|
||||||
|
ignore:
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
- goos: openbsd
|
||||||
|
goarch: arm
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm64
|
||||||
|
- goos: openbsd
|
||||||
|
goarch: arm64
|
||||||
|
|
||||||
|
# .goreleaser.yaml
|
||||||
|
notarize:
|
||||||
|
macos:
|
||||||
|
- # Whether this configuration is enabled or not.
|
||||||
|
#
|
||||||
|
# Default: false.
|
||||||
|
# Templates: allowed.
|
||||||
|
enabled: "{{ not .IsSnapshot }}"
|
||||||
|
|
||||||
|
# Before notarizing, we need to sign the binary.
|
||||||
|
# This blocks defines the configuration for doing so.
|
||||||
|
sign:
|
||||||
|
# The .p12 certificate file path or its base64'd contents.
|
||||||
|
certificate: "{{.Env.MACOS_SIGN_P12}}"
|
||||||
|
|
||||||
|
# The password to be used to open the certificate.
|
||||||
|
password: "{{.Env.MACOS_SIGN_PASSWORD}}"
|
||||||
|
|
||||||
|
# Then, we notarize the binaries.
|
||||||
|
notarize:
|
||||||
|
# The issuer ID.
|
||||||
|
# Its the UUID you see when creating the App Store Connect key.
|
||||||
|
issuer_id: "{{.Env.MACOS_NOTARY_ISSUER_ID}}"
|
||||||
|
|
||||||
|
# Key ID.
|
||||||
|
# You can see it in the list of App Store Connect Keys.
|
||||||
|
# It will also be in the ApiKey filename.
|
||||||
|
key_id: "{{.Env.MACOS_NOTARY_KEY_ID}}"
|
||||||
|
|
||||||
|
# The .p8 key file path or its base64'd contents.
|
||||||
|
key: "{{.Env.MACOS_NOTARY_KEY}}"
|
||||||
|
|
||||||
|
# Whether to wait for the notarization to finish.
|
||||||
|
# Not recommended, as it could take a really long time.
|
||||||
|
wait: true
|
||||||
|
|
||||||
|
archives:
|
||||||
|
- name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
|
||||||
|
builds:
|
||||||
|
- fzf
|
||||||
|
format: tar.gz
|
||||||
|
format_overrides:
|
||||||
|
- goos: windows
|
||||||
|
format: zip
|
||||||
|
files:
|
||||||
|
- non-existent*
|
||||||
|
|
||||||
|
release:
|
||||||
|
github:
|
||||||
|
owner: junegunn
|
||||||
|
name: fzf
|
||||||
|
prerelease: auto
|
||||||
|
name_template: '{{ .Version }}'
|
||||||
|
|
||||||
|
snapshot:
|
||||||
|
name_template: "{{ .Version }}-devel"
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- README
|
||||||
|
- test
|
||||||
32
.rubocop.yml
Normal file
32
.rubocop.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
Layout/LineLength:
|
||||||
|
Enabled: false
|
||||||
|
Metrics:
|
||||||
|
Enabled: false
|
||||||
|
Lint/ShadowingOuterLocalVariable:
|
||||||
|
Enabled: false
|
||||||
|
Style/MethodCallWithArgsParentheses:
|
||||||
|
Enabled: true
|
||||||
|
AllowedMethods:
|
||||||
|
- assert
|
||||||
|
- exit
|
||||||
|
- paste
|
||||||
|
- puts
|
||||||
|
- raise
|
||||||
|
- refute
|
||||||
|
- require
|
||||||
|
- send_keys
|
||||||
|
AllowedPatterns:
|
||||||
|
- ^assert_
|
||||||
|
- ^refute_
|
||||||
|
Style/NumericPredicate:
|
||||||
|
Enabled: false
|
||||||
|
Style/StringConcatenation:
|
||||||
|
Enabled: false
|
||||||
|
Style/OptionalBooleanParameter:
|
||||||
|
Enabled: false
|
||||||
|
Style/WordArray:
|
||||||
|
MinSize: 1
|
||||||
|
Minitest/AssertEqual:
|
||||||
|
Enabled: false
|
||||||
|
Naming/VariableNumber:
|
||||||
|
Enabled: false
|
||||||
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@@ -0,0 +1 @@
|
|||||||
|
golang 1.20.13
|
||||||
20
.travis.yml
20
.travis.yml
@@ -1,20 +0,0 @@
|
|||||||
language: ruby
|
|
||||||
dist: trusty
|
|
||||||
sudo: required
|
|
||||||
matrix:
|
|
||||||
include:
|
|
||||||
- env: TAGS=
|
|
||||||
rvm: 2.3.3
|
|
||||||
# - env: TAGS=tcell
|
|
||||||
# rvm: 2.3.3
|
|
||||||
|
|
||||||
install:
|
|
||||||
- sudo add-apt-repository -y ppa:pi-rho/dev
|
|
||||||
- sudo apt-add-repository -y ppa:fish-shell/release-2
|
|
||||||
- sudo apt-get update
|
|
||||||
- sudo apt-get install -y tmux zsh fish
|
|
||||||
|
|
||||||
script: |
|
|
||||||
make test install &&
|
|
||||||
./install --all &&
|
|
||||||
tmux new "ruby test/test_go.rb > out && touch ok" && cat out && [ -e ok ]
|
|
||||||
676
ADVANCED.md
Normal file
676
ADVANCED.md
Normal file
@@ -0,0 +1,676 @@
|
|||||||
|
Advanced fzf examples
|
||||||
|
======================
|
||||||
|
|
||||||
|
* *Last update: 2024/06/24*
|
||||||
|
* *Requires fzf 0.54.0 or later*
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc GFM -->
|
||||||
|
|
||||||
|
* [Introduction](#introduction)
|
||||||
|
* [Display modes](#display-modes)
|
||||||
|
* [`--height`](#--height)
|
||||||
|
* [`--tmux`](#--tmux)
|
||||||
|
* [Dynamic reloading of the list](#dynamic-reloading-of-the-list)
|
||||||
|
* [Updating the list of processes by pressing CTRL-R](#updating-the-list-of-processes-by-pressing-ctrl-r)
|
||||||
|
* [Toggling between data sources](#toggling-between-data-sources)
|
||||||
|
* [Toggling with a single key binding](#toggling-with-a-single-key-binding)
|
||||||
|
* [Ripgrep integration](#ripgrep-integration)
|
||||||
|
* [Using fzf as the secondary filter](#using-fzf-as-the-secondary-filter)
|
||||||
|
* [Using fzf as interactive Ripgrep launcher](#using-fzf-as-interactive-ripgrep-launcher)
|
||||||
|
* [Switching to fzf-only search mode](#switching-to-fzf-only-search-mode)
|
||||||
|
* [Switching between Ripgrep mode and fzf mode](#switching-between-ripgrep-mode-and-fzf-mode)
|
||||||
|
* [Switching between Ripgrep mode and fzf mode using a single key binding](#switching-between-ripgrep-mode-and-fzf-mode-using-a-single-key-binding)
|
||||||
|
* [Log tailing](#log-tailing)
|
||||||
|
* [Key bindings for git objects](#key-bindings-for-git-objects)
|
||||||
|
* [Files listed in `git status`](#files-listed-in-git-status)
|
||||||
|
* [Branches](#branches)
|
||||||
|
* [Commit hashes](#commit-hashes)
|
||||||
|
* [Color themes](#color-themes)
|
||||||
|
* [fzf Theme Playground](#fzf-theme-playground)
|
||||||
|
* [Generating fzf color theme from Vim color schemes](#generating-fzf-color-theme-from-vim-color-schemes)
|
||||||
|
|
||||||
|
<!-- vim-markdown-toc -->
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
------------
|
||||||
|
|
||||||
|
fzf is an interactive [Unix filter][filter] program that is designed to be
|
||||||
|
used with other Unix tools. It reads a list of items from the standard input,
|
||||||
|
allows you to select a subset of the items, and prints the selected ones to
|
||||||
|
the standard output. You can think of it as an interactive version of *grep*,
|
||||||
|
and it's already useful even if you don't know any of its options.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# 1. ps: Feed the list of processes to fzf
|
||||||
|
# 2. fzf: Interactively select a process using fuzzy matching algorithm
|
||||||
|
# 3. awk: Take the PID from the selected line
|
||||||
|
# 3. kill: Kill the process with the PID
|
||||||
|
ps -ef | fzf | awk '{print $2}' | xargs kill -9
|
||||||
|
```
|
||||||
|
|
||||||
|
[filter]: https://en.wikipedia.org/wiki/Filter_(software)
|
||||||
|
|
||||||
|
While the above example succinctly summarizes the fundamental concept of fzf,
|
||||||
|
you can build much more sophisticated interactive workflows using fzf once you
|
||||||
|
learn its wide variety of features.
|
||||||
|
|
||||||
|
- To see the full list of options and features, see `man fzf`
|
||||||
|
- To see the latest additions, see [CHANGELOG.md](CHANGELOG.md)
|
||||||
|
|
||||||
|
This document will guide you through some examples that will familiarize you
|
||||||
|
with the advanced features of fzf.
|
||||||
|
|
||||||
|
Display modes
|
||||||
|
-------------
|
||||||
|
|
||||||
|
### `--height`
|
||||||
|
|
||||||
|
fzf by default opens in fullscreen mode, but it's not always desirable.
|
||||||
|
Oftentimes, you want to see the current context of the terminal while using
|
||||||
|
fzf. `--height` is an option for opening fzf below the cursor in
|
||||||
|
non-fullscreen mode so you can still see the previous commands and their
|
||||||
|
results above it.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fzf --height=40%
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
You might also want to experiment with other layout options such as
|
||||||
|
`--layout=reverse`, `--info=inline`, `--border`, `--margin`, etc.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fzf --height=40% --layout=reverse
|
||||||
|
fzf --height=40% --layout=reverse --info=inline
|
||||||
|
fzf --height=40% --layout=reverse --info=inline --border
|
||||||
|
fzf --height=40% --layout=reverse --info=inline --border --margin=1
|
||||||
|
fzf --height=40% --layout=reverse --info=inline --border --margin=1 --padding=1
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
*(See `Layout` section of the man page to see the full list of options)*
|
||||||
|
|
||||||
|
But you definitely don't want to repeat `--height=40% --layout=reverse
|
||||||
|
--info=inline --border --margin=1 --padding=1` every time you use fzf. You
|
||||||
|
could write a wrapper script or shell alias, but there is an easier option.
|
||||||
|
Define `$FZF_DEFAULT_OPTS` like so:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
export FZF_DEFAULT_OPTS="--height=40% --layout=reverse --info=inline --border --margin=1 --padding=1"
|
||||||
|
```
|
||||||
|
|
||||||
|
### `--tmux`
|
||||||
|
|
||||||
|
(Requires tmux 3.3 or later)
|
||||||
|
|
||||||
|
If you're using tmux, you can open fzf in a tmux popup using `--tmux` option.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Open fzf in a tmux popup at the center of the screen with 70% width and height
|
||||||
|
fzf --tmux 70%
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
`--tmux` option is silently ignored if you're not on tmux. So if you're trying
|
||||||
|
to avoid opening fzf in fullscreen, try specifying both `--height` and `--tmux`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# --tmux is specified later so it takes precedence over --height when on tmux.
|
||||||
|
# If you're not on tmux, --tmux is ignored and --height is used instead.
|
||||||
|
fzf --height 70% --tmux 70%
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also specify the position, width, and height of the popup window in
|
||||||
|
the following format:
|
||||||
|
|
||||||
|
* `[center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]`
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# 100% width and 60% height
|
||||||
|
fzf --tmux 100%,60% --border horizontal
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# On the right (50% width)
|
||||||
|
fzf --tmux right
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# On the left (40% width and 70% height)
|
||||||
|
fzf --tmux left,40%,70%
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> [!TIP]
|
||||||
|
> You might also want to check out my tmux plugins which support this popup
|
||||||
|
> window layout.
|
||||||
|
>
|
||||||
|
> - https://github.com/junegunn/tmux-fzf-url
|
||||||
|
> - https://github.com/junegunn/tmux-fzf-maccy
|
||||||
|
|
||||||
|
Dynamic reloading of the list
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
fzf can dynamically update the candidate list using an arbitrary program with
|
||||||
|
`reload` bindings (The design document for `reload` can be found
|
||||||
|
[here][reload]).
|
||||||
|
|
||||||
|
[reload]: https://github.com/junegunn/fzf/issues/1750
|
||||||
|
|
||||||
|
### Updating the list of processes by pressing CTRL-R
|
||||||
|
|
||||||
|
This example shows how you can set up a binding for dynamically updating the
|
||||||
|
list without restarting fzf.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
(date; ps -ef) |
|
||||||
|
fzf --bind='ctrl-r:reload(date; ps -ef)' \
|
||||||
|
--header=$'Press CTRL-R to reload\n\n' --header-lines=2 \
|
||||||
|
--preview='echo {}' --preview-window=down,3,wrap \
|
||||||
|
--layout=reverse --height=80% | awk '{print $2}' | xargs kill -9
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- The initial command is `(date; ps -ef)`. It prints the current date and
|
||||||
|
time, and the list of the processes.
|
||||||
|
- With `--header` option, you can show any message as the fixed header.
|
||||||
|
- To disallow selecting the first two lines (`date` and `ps` header), we use
|
||||||
|
`--header-lines=2` option.
|
||||||
|
- `--bind='ctrl-r:reload(date; ps -ef)'` binds CTRL-R to `reload` action that
|
||||||
|
runs `date; ps -ef`, so we can update the list of the processes by pressing
|
||||||
|
CTRL-R.
|
||||||
|
- We use simple `echo {}` preview option, so we can see the entire line on the
|
||||||
|
preview window below even if it's too long
|
||||||
|
|
||||||
|
### Toggling between data sources
|
||||||
|
|
||||||
|
You're not limited to just one reload binding. Set up multiple bindings so
|
||||||
|
you can switch between data sources.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
find * | fzf --prompt 'All> ' \
|
||||||
|
--header 'CTRL-D: Directories / CTRL-F: Files' \
|
||||||
|
--bind 'ctrl-d:change-prompt(Directories> )+reload(find * -type d)' \
|
||||||
|
--bind 'ctrl-f:change-prompt(Files> )+reload(find * -type f)'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Toggling with a single key binding
|
||||||
|
|
||||||
|
The above example uses two different key bindings to toggle between two modes,
|
||||||
|
but can we just use a single key binding?
|
||||||
|
|
||||||
|
To make a key binding behave differently each time it is pressed, we need:
|
||||||
|
|
||||||
|
1. a way to store the current state. i.e. "which mode are we in?"
|
||||||
|
2. and a way to dynamically perform different actions depending on the state.
|
||||||
|
|
||||||
|
The following example shows how to 1. store the current mode in the prompt
|
||||||
|
string, 2. and use this information (`$FZF_PROMPT`) to determine which
|
||||||
|
actions to perform using the `transform` action.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
fd --type file |
|
||||||
|
fzf --prompt 'Files> ' \
|
||||||
|
--header 'CTRL-T: Switch between Files/Directories' \
|
||||||
|
--bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ Files ]] &&
|
||||||
|
echo "change-prompt(Files> )+reload(fd --type file)" ||
|
||||||
|
echo "change-prompt(Directories> )+reload(fd --type directory)"' \
|
||||||
|
--preview '[[ $FZF_PROMPT =~ Files ]] && bat --color=always {} || tree -C {}'
|
||||||
|
```
|
||||||
|
|
||||||
|
Ripgrep integration
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
### Using fzf as the secondary filter
|
||||||
|
|
||||||
|
* Requires [bat][bat]
|
||||||
|
* Requires [Ripgrep][rg]
|
||||||
|
|
||||||
|
[bat]: https://github.com/sharkdp/bat
|
||||||
|
[rg]: https://github.com/BurntSushi/ripgrep
|
||||||
|
|
||||||
|
fzf is pretty fast for filtering a list that you will rarely have to think
|
||||||
|
about its performance. But it is not the right tool for searching for text
|
||||||
|
inside many large files, and in that case you should definitely use something
|
||||||
|
like [Ripgrep][rg].
|
||||||
|
|
||||||
|
In the next example, Ripgrep is the primary filter that searches for the given
|
||||||
|
text in files, and fzf is used as the secondary fuzzy filter that adds
|
||||||
|
interactivity to the workflow. And we use [bat][bat] to show the matching line in
|
||||||
|
the preview window.
|
||||||
|
|
||||||
|
This is a bash script and it will not run as expected on other non-compliant
|
||||||
|
shells. To avoid the compatibility issue, let's save this snippet as a script
|
||||||
|
file called `rfv`.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# 1. Search for text in files using Ripgrep
|
||||||
|
# 2. Interactively narrow down the list using fzf
|
||||||
|
# 3. Open the file in Vim
|
||||||
|
rg --color=always --line-number --no-heading --smart-case "${*:-}" |
|
||||||
|
fzf --ansi \
|
||||||
|
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||||
|
--delimiter : \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
|
And run it with an initial query string.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Make the script executable
|
||||||
|
chmod +x rfv
|
||||||
|
|
||||||
|
# Run it with the initial query "algo"
|
||||||
|
./rfv algo
|
||||||
|
```
|
||||||
|
|
||||||
|
> Ripgrep will perform the initial search and list all the lines that contain
|
||||||
|
`algo`. Then we further narrow down the list on fzf.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
I know it's a lot to digest, let's try to break down the code.
|
||||||
|
|
||||||
|
- Ripgrep prints the matching lines in the following format
|
||||||
|
```
|
||||||
|
man/man1/fzf.1:54:.BI "--algo=" TYPE
|
||||||
|
man/man1/fzf.1:55:Fuzzy matching algorithm (default: v2)
|
||||||
|
man/man1/fzf.1:58:.BR v2 " Optimal scoring algorithm (quality)"
|
||||||
|
src/pattern_test.go:7: "github.com/junegunn/fzf/src/algo"
|
||||||
|
```
|
||||||
|
The first token delimited by `:` is the file path, and the second token is
|
||||||
|
the line number of the matching line. They respectively correspond to `{1}`
|
||||||
|
and `{2}` in the preview command.
|
||||||
|
- `--preview 'bat --color=always {1} --highlight-line {2}'`
|
||||||
|
- As we run `rg` with `--color=always` option, we should tell fzf to parse
|
||||||
|
ANSI color codes in the input by setting `--ansi`.
|
||||||
|
- We customize how fzf colors various text elements using `--color` option.
|
||||||
|
`-1` tells fzf to keep the original color from the input. See `man fzf` for
|
||||||
|
available color options.
|
||||||
|
- The value of `--preview-window` option consists of 5 components delimited
|
||||||
|
by `,`
|
||||||
|
1. `up` — Position of the preview window
|
||||||
|
1. `60%` — Size of the preview window
|
||||||
|
1. `border-bottom` — Preview window border only on the bottom side
|
||||||
|
1. `+{2}+3/3` — Scroll offset of the preview contents
|
||||||
|
1. `~3` — Fixed header
|
||||||
|
- Let's break down the latter two. We want to display the bat output in the
|
||||||
|
preview window with a certain scroll offset so that the matching line is
|
||||||
|
positioned near the center of the preview window.
|
||||||
|
- `+{2}` — The base offset is extracted from the second token
|
||||||
|
- `+3` — We add 3 lines to the base offset to compensate for the header
|
||||||
|
part of `bat` output
|
||||||
|
- ```
|
||||||
|
───────┬──────────────────────────────────────────────────────────
|
||||||
|
│ File: CHANGELOG.md
|
||||||
|
───────┼──────────────────────────────────────────────────────────
|
||||||
|
1 │ CHANGELOG
|
||||||
|
2 │ =========
|
||||||
|
3 │
|
||||||
|
4 │ 0.26.0
|
||||||
|
5 │ ------
|
||||||
|
```
|
||||||
|
- `/3` adjusts the offset so that the matching line is shown at a third
|
||||||
|
position in the window
|
||||||
|
- `~3` makes the top three lines fixed header so that they are always
|
||||||
|
visible regardless of the scroll offset
|
||||||
|
- Instead of using shell script to process the final output of fzf, we use
|
||||||
|
`become(...)` action which was added in [fzf 0.38.0][0.38.0] to turn fzf
|
||||||
|
into a new process that opens the file with `vim` (`vim {1}`) and move the
|
||||||
|
cursor to the line (`+{2}`).
|
||||||
|
|
||||||
|
[0.38.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0380
|
||||||
|
|
||||||
|
### Using fzf as interactive Ripgrep launcher
|
||||||
|
|
||||||
|
We have learned that we can bind `reload` action to a key (e.g.
|
||||||
|
`--bind=ctrl-r:execute(ps -ef)`). In the next example, we are going to **bind
|
||||||
|
`reload` action to `change` event** so that whenever the user *changes* the
|
||||||
|
query string on fzf, `reload` action is triggered.
|
||||||
|
|
||||||
|
Here is a variation of the above `rfv` script. fzf will restart Ripgrep every
|
||||||
|
time the user updates the query string on fzf. Searching and filtering is
|
||||||
|
completely done by Ripgrep, and fzf merely provides the interactive interface.
|
||||||
|
So we lose the "fuzziness", but the performance will be better on larger
|
||||||
|
projects, and it will free up memory as you narrow down the results.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# 1. Search for text in files using Ripgrep
|
||||||
|
# 2. Interactively restart Ripgrep with reload action
|
||||||
|
# 3. Open the file in Vim
|
||||||
|
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
|
||||||
|
INITIAL_QUERY="${*:-}"
|
||||||
|
fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
||||||
|
--bind "start:reload:$RG_PREFIX {q}" \
|
||||||
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
||||||
|
--delimiter : \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- Instead of starting fzf in the usual `rg ... | fzf` form, we make it start
|
||||||
|
the initial Ripgrep process immediately via `start:reload` binding for the
|
||||||
|
consistency of the code.
|
||||||
|
- Filtering is no longer a responsibility of fzf; hence `--disabled`
|
||||||
|
- `{q}` in the reload command evaluates to the query string on fzf prompt.
|
||||||
|
- `sleep 0.1` in the reload command is for "debouncing". This small delay will
|
||||||
|
reduce the number of intermediate Ripgrep processes while we're typing in
|
||||||
|
a query.
|
||||||
|
|
||||||
|
### Switching to fzf-only search mode
|
||||||
|
|
||||||
|
In the previous example, we lost fuzzy matching capability as we completely
|
||||||
|
delegated search functionality to Ripgrep. But we can dynamically switch to
|
||||||
|
fzf-only search mode by *"unbinding"* `reload` action from `change` event.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Two-phase filtering with Ripgrep and fzf
|
||||||
|
#
|
||||||
|
# 1. Search for text in files using Ripgrep
|
||||||
|
# 2. Interactively restart Ripgrep with reload action
|
||||||
|
# * Press alt-enter to switch to fzf-only filtering
|
||||||
|
# 3. Open the file in Vim
|
||||||
|
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
|
||||||
|
INITIAL_QUERY="${*:-}"
|
||||||
|
fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
||||||
|
--bind "start:reload:$RG_PREFIX {q}" \
|
||||||
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
||||||
|
--bind "alt-enter:unbind(change,alt-enter)+change-prompt(2. fzf> )+enable-search+clear-query" \
|
||||||
|
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||||
|
--prompt '1. ripgrep> ' \
|
||||||
|
--delimiter : \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
|
* Phase 1. Filtering with Ripgrep
|
||||||
|

|
||||||
|
* Phase 2. Filtering with fzf
|
||||||
|

|
||||||
|
|
||||||
|
- We added `--prompt` option to show that fzf is initially running in "Ripgrep
|
||||||
|
launcher mode".
|
||||||
|
- We added `alt-enter` binding that
|
||||||
|
1. unbinds `change` event, so Ripgrep is no longer restarted on key press
|
||||||
|
2. changes the prompt to `2. fzf>`
|
||||||
|
3. enables search functionality of fzf
|
||||||
|
4. clears the current query string that was used to start Ripgrep process
|
||||||
|
5. and unbinds `alt-enter` itself as this is a one-off event
|
||||||
|
- We reverted `--color` option for customizing how the matching chunks are
|
||||||
|
displayed in the second phase
|
||||||
|
|
||||||
|
### Switching between Ripgrep mode and fzf mode
|
||||||
|
|
||||||
|
[fzf 0.30.0][0.30.0] added `rebind` action so we can "rebind" the bindings
|
||||||
|
that were previously "unbound" via `unbind`.
|
||||||
|
|
||||||
|
This is an improved version of the previous example that allows us to switch
|
||||||
|
between Ripgrep launcher mode and fzf-only filtering mode via CTRL-R and
|
||||||
|
CTRL-F.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)
|
||||||
|
rm -f /tmp/rg-fzf-{r,f}
|
||||||
|
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
|
||||||
|
INITIAL_QUERY="${*:-}"
|
||||||
|
fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
||||||
|
--bind "start:reload($RG_PREFIX {q})+unbind(ctrl-r)" \
|
||||||
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
||||||
|
--bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+rebind(ctrl-r)+transform-query(echo {q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f)" \
|
||||||
|
--bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)+transform-query(echo {q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r)" \
|
||||||
|
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||||
|
--prompt '1. ripgrep> ' \
|
||||||
|
--delimiter : \
|
||||||
|
--header '╱ CTRL-R (ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
|
- To restore the query string when switching between modes, we store the
|
||||||
|
current query in `/tmp/rg-fzf-{r,f}` files and restore the query using
|
||||||
|
`transform-query` action which was added in [fzf 0.36.0][0.36.0].
|
||||||
|
- Also note that we unbind `ctrl-r` binding on `start` event which is
|
||||||
|
triggered once when fzf starts.
|
||||||
|
|
||||||
|
[0.30.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0300
|
||||||
|
[0.36.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0360
|
||||||
|
|
||||||
|
### Switching between Ripgrep mode and fzf mode using a single key binding
|
||||||
|
|
||||||
|
In contrast to the previous version, we use just one hotkey to toggle between
|
||||||
|
ripgrep and fzf mode. This is achieved by using the `$FZF_PROMPT` as a state
|
||||||
|
within the `transform` action, a feature introduced in [fzf 0.45.0][0.45.0]. A
|
||||||
|
more detailed explanation of this feature can be found in a previous section -
|
||||||
|
[Toggling with a single keybinding](#toggling-with-a-single-key-binding).
|
||||||
|
|
||||||
|
[0.45.0]: https://github.com/junegunn/fzf/blob/master/CHANGELOG.md#0450
|
||||||
|
|
||||||
|
When using the `transform` action, the placeholder (`\{q}`) should be escaped to
|
||||||
|
prevent immediate evaluation.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Switch between Ripgrep mode and fzf filtering mode (CTRL-T)
|
||||||
|
rm -f /tmp/rg-fzf-{r,f}
|
||||||
|
RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
|
||||||
|
INITIAL_QUERY="${*:-}"
|
||||||
|
fzf --ansi --disabled --query "$INITIAL_QUERY" \
|
||||||
|
--bind "start:reload:$RG_PREFIX {q}" \
|
||||||
|
--bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
|
||||||
|
--bind 'ctrl-t:transform:[[ ! $FZF_PROMPT =~ ripgrep ]] &&
|
||||||
|
echo "rebind(change)+change-prompt(1. ripgrep> )+disable-search+transform-query:echo \{q} > /tmp/rg-fzf-f; cat /tmp/rg-fzf-r" ||
|
||||||
|
echo "unbind(change)+change-prompt(2. fzf> )+enable-search+transform-query:echo \{q} > /tmp/rg-fzf-r; cat /tmp/rg-fzf-f"' \
|
||||||
|
--color "hl:-1:underline,hl+:-1:underline:reverse" \
|
||||||
|
--prompt '1. ripgrep> ' \
|
||||||
|
--delimiter : \
|
||||||
|
--header 'CTRL-T: Switch between ripgrep/fzf' \
|
||||||
|
--preview 'bat --color=always {1} --highlight-line {2}' \
|
||||||
|
--preview-window 'up,60%,border-bottom,+{2}+3/3,~3' \
|
||||||
|
--bind 'enter:become(vim {1} +{2})'
|
||||||
|
```
|
||||||
|
|
||||||
|
Log tailing
|
||||||
|
-----------
|
||||||
|
|
||||||
|
fzf can run long-running preview commands and render partial results before
|
||||||
|
completion. And when you specify `follow` flag in `--preview-window` option,
|
||||||
|
fzf will "`tail -f`" the result, automatically scrolling to the bottom.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# With "follow", preview window will automatically scroll to the bottom.
|
||||||
|
# "\033[2J" is an ANSI escape sequence for clearing the screen.
|
||||||
|
# When fzf reads this code it clears the previous preview contents.
|
||||||
|
fzf --preview-window follow --preview 'for i in $(seq 100000); do
|
||||||
|
echo "$i"
|
||||||
|
sleep 0.01
|
||||||
|
(( i % 300 == 0 )) && printf "\033[2J"
|
||||||
|
done'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Admittedly, that was a silly example. Here's a practical one for browsing
|
||||||
|
Kubernetes pods.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pods() {
|
||||||
|
command='kubectl get pods --all-namespaces' fzf \
|
||||||
|
--info=inline --layout=reverse --header-lines=1 \
|
||||||
|
--prompt "$(kubectl config current-context | sed 's/-context$//')> " \
|
||||||
|
--header $'╱ Enter (kubectl exec) ╱ CTRL-O (open log in editor) ╱ CTRL-R (reload) ╱\n\n' \
|
||||||
|
--bind 'start:reload:$command' \
|
||||||
|
--bind 'ctrl-r:reload:$command' \
|
||||||
|
--bind 'ctrl-/:change-preview-window(80%,border-bottom|hidden|)' \
|
||||||
|
--bind 'enter:execute:kubectl exec -it --namespace {1} {2} -- bash' \
|
||||||
|
--bind 'ctrl-o:execute:${EDITOR:-vim} <(kubectl logs --all-containers --namespace {1} {2})' \
|
||||||
|
--preview-window up:follow \
|
||||||
|
--preview 'kubectl logs --follow --all-containers --tail=10000 --namespace {1} {2}' "$@"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
- The preview window will *"log tail"* the pod
|
||||||
|
- Holding on to a large amount of log will consume a lot of memory. So we
|
||||||
|
limited the initial log amount with `--tail=10000`.
|
||||||
|
- `execute` bindings allow you to run any command without leaving fzf
|
||||||
|
- Press enter key on a pod to `kubectl exec` into it
|
||||||
|
- Press CTRL-O to open the log in your editor
|
||||||
|
- Press CTRL-R to reload the pod list
|
||||||
|
- Press CTRL-/ repeatedly to rotate through a different sets of preview
|
||||||
|
window options
|
||||||
|
1. `80%,border-bottom`
|
||||||
|
1. `hidden`
|
||||||
|
1. Empty string after `|` translates to the default options from `--preview-window`
|
||||||
|
|
||||||
|
Key bindings for git objects
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
Oftentimes, you want to put the identifiers of various Git object to the
|
||||||
|
command-line. For example, it is common to write commands like these:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git checkout [SOME_COMMIT_HASH or BRANCH or TAG]
|
||||||
|
git diff [SOME_COMMIT_HASH or BRANCH or TAG] [SOME_COMMIT_HASH or BRANCH or TAG]
|
||||||
|
```
|
||||||
|
|
||||||
|
[fzf-git.sh](https://github.com/junegunn/fzf-git.sh) project defines a set of
|
||||||
|
fzf-based key bindings for Git objects. I strongly recommend that you check
|
||||||
|
them out because they are seriously useful.
|
||||||
|
|
||||||
|
### Files listed in `git status`
|
||||||
|
|
||||||
|
<kbd>CTRL-G</kbd><kbd>CTRL-F</kbd>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Branches
|
||||||
|
|
||||||
|
<kbd>CTRL-G</kbd><kbd>CTRL-B</kbd>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Commit hashes
|
||||||
|
|
||||||
|
<kbd>CTRL-G</kbd><kbd>CTRL-H</kbd>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Color themes
|
||||||
|
------------
|
||||||
|
|
||||||
|
You can customize how fzf colors the text elements with `--color` option. Here
|
||||||
|
are a few color themes. Note that you need a terminal emulator that can
|
||||||
|
display 24-bit colors.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# junegunn/seoul256.vim (dark)
|
||||||
|
export FZF_DEFAULT_OPTS='--color=bg+:#3F3F3F,bg:#4B4B4B,border:#6B6B6B,spinner:#98BC99,hl:#719872,fg:#D9D9D9,header:#719872,info:#BDBB72,pointer:#E12672,marker:#E17899,fg+:#D9D9D9,preview-bg:#3F3F3F,prompt:#98BEDE,hl+:#98BC99'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# junegunn/seoul256.vim (light)
|
||||||
|
export FZF_DEFAULT_OPTS='--color=bg+:#D9D9D9,bg:#E1E1E1,border:#C8C8C8,spinner:#719899,hl:#719872,fg:#616161,header:#719872,info:#727100,pointer:#E12672,marker:#E17899,fg+:#616161,preview-bg:#D9D9D9,prompt:#0099BD,hl+:#719899'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# morhetz/gruvbox
|
||||||
|
export FZF_DEFAULT_OPTS='--color=bg+:#3c3836,bg:#32302f,spinner:#fb4934,hl:#928374,fg:#ebdbb2,header:#928374,info:#8ec07c,pointer:#fb4934,marker:#fb4934,fg+:#ebdbb2,prompt:#fb4934,hl+:#fb4934'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# arcticicestudio/nord-vim
|
||||||
|
export FZF_DEFAULT_OPTS='--color=bg+:#3B4252,bg:#2E3440,spinner:#81A1C1,hl:#616E88,fg:#D8DEE9,header:#616E88,info:#81A1C1,pointer:#81A1C1,marker:#81A1C1,fg+:#D8DEE9,prompt:#81A1C1,hl+:#81A1C1'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```sh
|
||||||
|
# tomasr/molokai
|
||||||
|
export FZF_DEFAULT_OPTS='--color=bg+:#293739,bg:#1B1D1E,border:#808080,spinner:#E6DB74,hl:#7E8E91,fg:#F8F8F2,header:#7E8E91,info:#A6E22E,pointer:#A6E22E,marker:#F92672,fg+:#F8F8F2,prompt:#F92672,hl+:#F92672'
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### fzf Theme Playground
|
||||||
|
|
||||||
|
[fzf Theme Playground](https://vitormv.github.io/fzf-themes/) created by
|
||||||
|
[Vitor Mello](https://github.com/vitormv) is a webpage where you can
|
||||||
|
interactively create fzf themes.
|
||||||
|
|
||||||
|
### Generating fzf color theme from Vim color schemes
|
||||||
|
|
||||||
|
The Vim plugin of fzf can generate `--color` option from the current color
|
||||||
|
scheme according to `g:fzf_colors` variable. You can find the detailed
|
||||||
|
explanation [here](https://github.com/junegunn/fzf/blob/master/README-VIM.md#explanation-of-gfzf_colors).
|
||||||
|
|
||||||
|
Here is an example. Add this to your Vim configuration file.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:fzf_colors =
|
||||||
|
\ { 'fg': ['fg', 'Normal'],
|
||||||
|
\ 'bg': ['bg', 'Normal'],
|
||||||
|
\ 'preview-bg': ['bg', 'NormalFloat'],
|
||||||
|
\ 'hl': ['fg', 'Comment'],
|
||||||
|
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
|
||||||
|
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
|
||||||
|
\ 'hl+': ['fg', 'Statement'],
|
||||||
|
\ 'info': ['fg', 'PreProc'],
|
||||||
|
\ 'border': ['fg', 'Ignore'],
|
||||||
|
\ 'prompt': ['fg', 'Conditional'],
|
||||||
|
\ 'pointer': ['fg', 'Exception'],
|
||||||
|
\ 'marker': ['fg', 'Keyword'],
|
||||||
|
\ 'spinner': ['fg', 'Label'],
|
||||||
|
\ 'header': ['fg', 'Comment'] }
|
||||||
|
```
|
||||||
|
|
||||||
|
Then you can see how the `--color` option is generated by printing the result
|
||||||
|
of `fzf#wrap()`.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:echo fzf#wrap()
|
||||||
|
```
|
||||||
|
|
||||||
|
Use this command to append `export FZF_DEFAULT_OPTS="..."` line to the end of
|
||||||
|
the current file.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:call append('$', printf('export FZF_DEFAULT_OPTS="%s"', matchstr(fzf#wrap().options, "--color[^']*")))
|
||||||
|
```
|
||||||
40
BUILD.md
40
BUILD.md
@@ -6,12 +6,10 @@ Build instructions
|
|||||||
|
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
|
|
||||||
- `go` executable in $PATH
|
- Go 1.20 or above
|
||||||
|
|
||||||
### Using Makefile
|
### Using Makefile
|
||||||
|
|
||||||
Makefile will set up and use its own `$GOPATH` under the project root.
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Build fzf binary for your platform in target
|
# Build fzf binary for your platform in target
|
||||||
make
|
make
|
||||||
@@ -19,33 +17,43 @@ make
|
|||||||
# Build fzf binary and copy it to bin directory
|
# Build fzf binary and copy it to bin directory
|
||||||
make install
|
make install
|
||||||
|
|
||||||
# Build 32-bit and 64-bit executables and tarballs in target
|
# Build fzf binaries and archives for all platforms using goreleaser
|
||||||
|
make build
|
||||||
|
|
||||||
|
# Publish GitHub release
|
||||||
make release
|
make release
|
||||||
|
|
||||||
# Make release archives for all supported platforms in target
|
|
||||||
make release-all
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Using `go get`
|
> [!WARNING]
|
||||||
|
> Makefile uses git commands to determine the version and the revision
|
||||||
|
> information for `fzf --version`. So if you're building fzf from an
|
||||||
|
> environment where its git information is not available, you have to manually
|
||||||
|
> set `$FZF_VERSION` and `$FZF_REVISION`.
|
||||||
|
>
|
||||||
|
> e.g. `FZF_VERSION=0.24.0 FZF_REVISION=tarball make`
|
||||||
|
|
||||||
Alternatively, you can build fzf directly with `go get` command without
|
> [!TIP]
|
||||||
manually cloning the repository.
|
> To build fzf with profiling options enabled, set `TAGS=pprof`
|
||||||
|
>
|
||||||
```sh
|
> ```sh
|
||||||
go get -u github.com/junegunn/fzf
|
> TAGS=pprof make clean install
|
||||||
```
|
> fzf --profile-cpu /tmp/cpu.pprof --profile-mem /tmp/mem.pprof \
|
||||||
|
> --profile-block /tmp/block.pprof --profile-mutex /tmp/mutex.pprof
|
||||||
|
> ```
|
||||||
|
|
||||||
Third-party libraries used
|
Third-party libraries used
|
||||||
--------------------------
|
--------------------------
|
||||||
|
|
||||||
- [mattn/go-runewidth](https://github.com/mattn/go-runewidth)
|
- [rivo/uniseg](https://github.com/rivo/uniseg)
|
||||||
- Licensed under [MIT](http://mattn.mit-license.org)
|
- Licensed under [MIT](https://raw.githubusercontent.com/rivo/uniseg/master/LICENSE.txt)
|
||||||
- [mattn/go-shellwords](https://github.com/mattn/go-shellwords)
|
- [mattn/go-shellwords](https://github.com/mattn/go-shellwords)
|
||||||
- Licensed under [MIT](http://mattn.mit-license.org)
|
- Licensed under [MIT](http://mattn.mit-license.org)
|
||||||
- [mattn/go-isatty](https://github.com/mattn/go-isatty)
|
- [mattn/go-isatty](https://github.com/mattn/go-isatty)
|
||||||
- Licensed under [MIT](http://mattn.mit-license.org)
|
- Licensed under [MIT](http://mattn.mit-license.org)
|
||||||
- [tcell](https://github.com/gdamore/tcell)
|
- [tcell](https://github.com/gdamore/tcell)
|
||||||
- Licensed under [Apache License 2.0](https://github.com/gdamore/tcell/blob/master/LICENSE)
|
- Licensed under [Apache License 2.0](https://github.com/gdamore/tcell/blob/master/LICENSE)
|
||||||
|
- [fastwalk](https://github.com/charlievieth/fastwalk)
|
||||||
|
- Licensed under [MIT](https://raw.githubusercontent.com/charlievieth/fastwalk/master/LICENSE)
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|||||||
1630
CHANGELOG.md
1630
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
12
Dockerfile
Normal file
12
Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM ubuntu:24.04
|
||||||
|
RUN apt-get update -y && apt install -y git make golang zsh fish ruby tmux
|
||||||
|
RUN gem install --no-document -v 5.22.3 minitest
|
||||||
|
RUN echo '. /usr/share/bash-completion/completions/git' >> ~/.bashrc
|
||||||
|
RUN echo '. ~/.bashrc' >> ~/.bash_profile
|
||||||
|
|
||||||
|
# Do not set default PS1
|
||||||
|
RUN rm -f /etc/bash.bashrc
|
||||||
|
COPY . /fzf
|
||||||
|
RUN cd /fzf && make install && ./install --all
|
||||||
|
ENV LANG C.UTF-8
|
||||||
|
CMD tmux new 'set -o pipefail; ruby /fzf/test/test_go.rb | tee out && touch ok' && cat out && [ -e ok ]
|
||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2016 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
222
Makefile
222
Makefile
@@ -1,41 +1,42 @@
|
|||||||
ifndef GOOS
|
SHELL := bash
|
||||||
UNAME_S := $(shell uname -s)
|
GO ?= go
|
||||||
ifeq ($(UNAME_S),Darwin)
|
GOOS ?= $(shell $(GO) env GOOS)
|
||||||
GOOS := darwin
|
|
||||||
else ifeq ($(UNAME_S),Linux)
|
|
||||||
GOOS := linux
|
|
||||||
else
|
|
||||||
$(error "$$GOOS is not defined.")
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
MAKEFILE := $(realpath $(lastword $(MAKEFILE_LIST)))
|
||||||
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
ROOT_DIR := $(shell dirname $(MAKEFILE))
|
||||||
GOPATH := $(ROOT_DIR)/gopath
|
SOURCES := $(wildcard *.go src/*.go src/*/*.go shell/*sh man/man1/*.1) $(MAKEFILE)
|
||||||
SRC_LINK := $(GOPATH)/src/github.com/junegunn/fzf/src
|
|
||||||
VENDOR_LINK := $(GOPATH)/src/github.com/junegunn/fzf/vendor
|
|
||||||
export GOPATH
|
|
||||||
|
|
||||||
GLIDE_YAML := glide.yaml
|
ifdef FZF_VERSION
|
||||||
GLIDE_LOCK := glide.lock
|
VERSION := $(FZF_VERSION)
|
||||||
SOURCES := $(wildcard *.go src/*.go src/*/*.go) $(SRC_LINK) $(VENDOR_LINK) $(GLIDE_LOCK) $(MAKEFILE)
|
else
|
||||||
|
VERSION := $(shell git describe --abbrev=0 2> /dev/null | sed "s/^v//")
|
||||||
|
endif
|
||||||
|
ifeq ($(VERSION),)
|
||||||
|
$(error Not on git repository; cannot determine $$FZF_VERSION)
|
||||||
|
endif
|
||||||
|
VERSION_TRIM := $(shell sed "s/^v//; s/-.*//" <<< $(VERSION))
|
||||||
|
VERSION_REGEX := $(subst .,\.,$(VERSION_TRIM))
|
||||||
|
|
||||||
REVISION := $(shell git log -n 1 --pretty=format:%h -- $(SOURCES))
|
ifdef FZF_REVISION
|
||||||
BUILD_FLAGS := -a -ldflags "-X main.revision=$(REVISION) -w -extldflags=$(LDFLAGS)" -tags "$(TAGS)"
|
REVISION := $(FZF_REVISION)
|
||||||
|
else
|
||||||
|
REVISION := $(shell git log -n 1 --pretty=format:%h --abbrev=8 -- $(SOURCES) 2> /dev/null)
|
||||||
|
endif
|
||||||
|
ifeq ($(REVISION),)
|
||||||
|
$(error Not on git repository; cannot determine $$FZF_REVISION)
|
||||||
|
endif
|
||||||
|
BUILD_FLAGS := -a -ldflags "-s -w -X main.version=$(VERSION) -X main.revision=$(REVISION)" -tags "$(TAGS)" -trimpath
|
||||||
|
|
||||||
BINARY32 := fzf-$(GOOS)_386
|
BINARY32 := fzf-$(GOOS)_386
|
||||||
BINARY64 := fzf-$(GOOS)_amd64
|
BINARY64 := fzf-$(GOOS)_amd64
|
||||||
|
BINARYS390 := fzf-$(GOOS)_s390x
|
||||||
BINARYARM5 := fzf-$(GOOS)_arm5
|
BINARYARM5 := fzf-$(GOOS)_arm5
|
||||||
BINARYARM6 := fzf-$(GOOS)_arm6
|
BINARYARM6 := fzf-$(GOOS)_arm6
|
||||||
BINARYARM7 := fzf-$(GOOS)_arm7
|
BINARYARM7 := fzf-$(GOOS)_arm7
|
||||||
BINARYARM8 := fzf-$(GOOS)_arm8
|
BINARYARM8 := fzf-$(GOOS)_arm8
|
||||||
VERSION := $(shell awk -F= '/version =/ {print $$2}' src/constants.go | tr -d "\" ")
|
BINARYPPC64LE := fzf-$(GOOS)_ppc64le
|
||||||
RELEASE32 := fzf-$(VERSION)-$(GOOS)_386
|
BINARYRISCV64 := fzf-$(GOOS)_riscv64
|
||||||
RELEASE64 := fzf-$(VERSION)-$(GOOS)_amd64
|
BINARYLOONG64 := fzf-$(GOOS)_loong64
|
||||||
RELEASEARM5 := fzf-$(VERSION)-$(GOOS)_arm5
|
|
||||||
RELEASEARM6 := fzf-$(VERSION)-$(GOOS)_arm6
|
|
||||||
RELEASEARM7 := fzf-$(VERSION)-$(GOOS)_arm7
|
|
||||||
RELEASEARM8 := fzf-$(VERSION)-$(GOOS)_arm8
|
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/Uname
|
# https://en.wikipedia.org/wiki/Uname
|
||||||
UNAME_M := $(shell uname -m)
|
UNAME_M := $(shell uname -m)
|
||||||
@@ -43,6 +44,8 @@ ifeq ($(UNAME_M),x86_64)
|
|||||||
BINARY := $(BINARY64)
|
BINARY := $(BINARY64)
|
||||||
else ifeq ($(UNAME_M),amd64)
|
else ifeq ($(UNAME_M),amd64)
|
||||||
BINARY := $(BINARY64)
|
BINARY := $(BINARY64)
|
||||||
|
else ifeq ($(UNAME_M),s390x)
|
||||||
|
BINARY := $(BINARYS390)
|
||||||
else ifeq ($(UNAME_M),i686)
|
else ifeq ($(UNAME_M),i686)
|
||||||
BINARY := $(BINARY32)
|
BINARY := $(BINARY32)
|
||||||
else ifeq ($(UNAME_M),i386)
|
else ifeq ($(UNAME_M),i386)
|
||||||
@@ -53,86 +56,135 @@ else ifeq ($(UNAME_M),armv6l)
|
|||||||
BINARY := $(BINARYARM6)
|
BINARY := $(BINARYARM6)
|
||||||
else ifeq ($(UNAME_M),armv7l)
|
else ifeq ($(UNAME_M),armv7l)
|
||||||
BINARY := $(BINARYARM7)
|
BINARY := $(BINARYARM7)
|
||||||
|
else ifeq ($(UNAME_M),armv8l)
|
||||||
|
# armv8l is always 32-bit and should implement the armv7 ISA, so
|
||||||
|
# just use the same filename as for armv7.
|
||||||
|
BINARY := $(BINARYARM7)
|
||||||
|
else ifeq ($(UNAME_M),arm64)
|
||||||
|
BINARY := $(BINARYARM8)
|
||||||
|
else ifeq ($(UNAME_M),aarch64)
|
||||||
|
BINARY := $(BINARYARM8)
|
||||||
|
else ifeq ($(UNAME_M),ppc64le)
|
||||||
|
BINARY := $(BINARYPPC64LE)
|
||||||
|
else ifeq ($(UNAME_M),riscv64)
|
||||||
|
BINARY := $(BINARYRISCV64)
|
||||||
|
else ifeq ($(UNAME_M),loongarch64)
|
||||||
|
BINARY := $(BINARYLOONG64)
|
||||||
else
|
else
|
||||||
$(error "Build on $(UNAME_M) is not supported, yet.")
|
$(error Build on $(UNAME_M) is not supported, yet.)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: target/$(BINARY)
|
all: target/$(BINARY)
|
||||||
|
|
||||||
target:
|
test: $(SOURCES)
|
||||||
mkdir -p $@
|
SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" \
|
||||||
|
|
||||||
ifeq ($(GOOS),windows)
|
|
||||||
release: target/$(BINARY32) target/$(BINARY64)
|
|
||||||
cd target && cp -f $(BINARY32) fzf.exe && zip $(RELEASE32).zip fzf.exe
|
|
||||||
cd target && cp -f $(BINARY64) fzf.exe && zip $(RELEASE64).zip fzf.exe
|
|
||||||
cd target && rm -f fzf.exe
|
|
||||||
else ifeq ($(GOOS),linux)
|
|
||||||
release: target/$(BINARY32) target/$(BINARY64) target/$(BINARYARM5) target/$(BINARYARM6) target/$(BINARYARM7) target/$(BINARYARM8)
|
|
||||||
cd target && cp -f $(BINARY32) fzf && tar -czf $(RELEASE32).tgz fzf
|
|
||||||
cd target && cp -f $(BINARY64) fzf && tar -czf $(RELEASE64).tgz fzf
|
|
||||||
cd target && cp -f $(BINARYARM5) fzf && tar -czf $(RELEASEARM5).tgz fzf
|
|
||||||
cd target && cp -f $(BINARYARM6) fzf && tar -czf $(RELEASEARM6).tgz fzf
|
|
||||||
cd target && cp -f $(BINARYARM7) fzf && tar -czf $(RELEASEARM7).tgz fzf
|
|
||||||
cd target && cp -f $(BINARYARM8) fzf && tar -czf $(RELEASEARM8).tgz fzf
|
|
||||||
cd target && rm -f fzf
|
|
||||||
else
|
|
||||||
release: target/$(BINARY32) target/$(BINARY64)
|
|
||||||
cd target && cp -f $(BINARY32) fzf && tar -czf $(RELEASE32).tgz fzf
|
|
||||||
cd target && cp -f $(BINARY64) fzf && tar -czf $(RELEASE64).tgz fzf
|
|
||||||
cd target && rm -f fzf
|
|
||||||
endif
|
|
||||||
|
|
||||||
release-all: clean test
|
|
||||||
GOOS=darwin make release
|
|
||||||
GOOS=linux make release
|
|
||||||
GOOS=freebsd make release
|
|
||||||
GOOS=openbsd make release
|
|
||||||
GOOS=windows make release
|
|
||||||
|
|
||||||
$(SRC_LINK):
|
|
||||||
mkdir -p $(shell dirname $(SRC_LINK))
|
|
||||||
ln -sf $(ROOT_DIR)/src $(SRC_LINK)
|
|
||||||
|
|
||||||
$(VENDOR_LINK):
|
|
||||||
mkdir -p $(shell dirname $(VENDOR_LINK))
|
|
||||||
ln -sf $(ROOT_DIR)/vendor $(VENDOR_LINK)
|
|
||||||
|
|
||||||
vendor: $(GLIDE_YAML)
|
|
||||||
go get -u github.com/Masterminds/glide && $(GOPATH)/bin/glide install && touch $@
|
|
||||||
|
|
||||||
test: $(SOURCES) vendor
|
|
||||||
SHELL=/bin/sh GOOS= go test -v -tags "$(TAGS)" \
|
|
||||||
github.com/junegunn/fzf/src \
|
github.com/junegunn/fzf/src \
|
||||||
github.com/junegunn/fzf/src/algo \
|
github.com/junegunn/fzf/src/algo \
|
||||||
github.com/junegunn/fzf/src/tui \
|
github.com/junegunn/fzf/src/tui \
|
||||||
github.com/junegunn/fzf/src/util
|
github.com/junegunn/fzf/src/util
|
||||||
|
|
||||||
|
bench:
|
||||||
|
cd src && SHELL=/bin/sh GOOS= $(GO) test -v -tags "$(TAGS)" -run=Bench -bench=. -benchmem
|
||||||
|
|
||||||
|
lint: $(SOURCES) test/test_go.rb
|
||||||
|
[ -z "$$(gofmt -s -d src)" ] || (gofmt -s -d src; exit 1)
|
||||||
|
rubocop --require rubocop-minitest --require rubocop-performance
|
||||||
|
|
||||||
install: bin/fzf
|
install: bin/fzf
|
||||||
|
|
||||||
|
generate:
|
||||||
|
PATH=$(PATH):$(GOPATH)/bin $(GO) generate ./...
|
||||||
|
|
||||||
|
build:
|
||||||
|
goreleaser build --clean --snapshot --skip=post-hooks
|
||||||
|
|
||||||
|
release:
|
||||||
|
# Make sure that the tests pass and the build works
|
||||||
|
TAGS=tcell make test
|
||||||
|
make test build clean
|
||||||
|
|
||||||
|
ifndef GITHUB_TOKEN
|
||||||
|
$(error GITHUB_TOKEN is not defined)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Check if we are on master branch
|
||||||
|
ifneq ($(shell git symbolic-ref --short HEAD),master)
|
||||||
|
$(error Not on master branch)
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Check if version numbers are properly updated
|
||||||
|
grep -q ^$(VERSION_REGEX)$$ CHANGELOG.md
|
||||||
|
grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf.1
|
||||||
|
grep -qF '"fzf $(VERSION_TRIM)"' man/man1/fzf-tmux.1
|
||||||
|
grep -qF $(VERSION) install
|
||||||
|
grep -qF $(VERSION) install.ps1
|
||||||
|
|
||||||
|
# Make release note out of CHANGELOG.md
|
||||||
|
mkdir -p tmp
|
||||||
|
sed -n '/^$(VERSION_REGEX)$$/,/^[0-9]/p' CHANGELOG.md | tail -r | \
|
||||||
|
sed '1,/^ *$$/d' | tail -r | sed 1,2d | tee tmp/release-note
|
||||||
|
|
||||||
|
# Push to temp branch first so that install scripts always works on master branch
|
||||||
|
git checkout -B temp master
|
||||||
|
git push origin temp --follow-tags --force
|
||||||
|
|
||||||
|
# Make a GitHub release
|
||||||
|
goreleaser --clean --release-notes tmp/release-note
|
||||||
|
|
||||||
|
# Push to master
|
||||||
|
git checkout master
|
||||||
|
git push origin master
|
||||||
|
|
||||||
|
# Delete temp branch
|
||||||
|
git push origin --delete temp
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf target
|
$(RM) -r dist target
|
||||||
|
|
||||||
target/$(BINARY32): $(SOURCES) vendor
|
target/$(BINARY32): $(SOURCES)
|
||||||
GOARCH=386 go build $(BUILD_FLAGS) -o $@
|
GOARCH=386 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
target/$(BINARY64): $(SOURCES) vendor
|
target/$(BINARY64): $(SOURCES)
|
||||||
GOARCH=amd64 go build $(BUILD_FLAGS) -o $@
|
GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
|
target/$(BINARYS390): $(SOURCES)
|
||||||
|
GOARCH=s390x $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
# https://github.com/golang/go/wiki/GoArm
|
# https://github.com/golang/go/wiki/GoArm
|
||||||
target/$(BINARYARM5): $(SOURCES) vendor
|
target/$(BINARYARM5): $(SOURCES)
|
||||||
GOARCH=arm GOARM=5 go build $(BUILD_FLAGS) -o $@
|
GOARCH=arm GOARM=5 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
target/$(BINARYARM6): $(SOURCES) vendor
|
target/$(BINARYARM6): $(SOURCES)
|
||||||
GOARCH=arm GOARM=6 go build $(BUILD_FLAGS) -o $@
|
GOARCH=arm GOARM=6 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
target/$(BINARYARM7): $(SOURCES) vendor
|
target/$(BINARYARM7): $(SOURCES)
|
||||||
GOARCH=arm GOARM=7 go build $(BUILD_FLAGS) -o $@
|
GOARCH=arm GOARM=7 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
target/$(BINARYARM8): $(SOURCES) vendor
|
target/$(BINARYARM8): $(SOURCES)
|
||||||
GOARCH=arm64 go build $(BUILD_FLAGS) -o $@
|
GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
|
target/$(BINARYPPC64LE): $(SOURCES)
|
||||||
|
GOARCH=ppc64le $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
|
target/$(BINARYRISCV64): $(SOURCES)
|
||||||
|
GOARCH=riscv64 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
|
target/$(BINARYLOONG64): $(SOURCES)
|
||||||
|
GOARCH=loong64 $(GO) build $(BUILD_FLAGS) -o $@
|
||||||
|
|
||||||
bin/fzf: target/$(BINARY) | bin
|
bin/fzf: target/$(BINARY) | bin
|
||||||
|
-rm -f bin/fzf
|
||||||
cp -f target/$(BINARY) bin/fzf
|
cp -f target/$(BINARY) bin/fzf
|
||||||
|
|
||||||
.PHONY: all release release-all test install clean
|
docker:
|
||||||
|
docker build -t fzf-ubuntu .
|
||||||
|
docker run -it fzf-ubuntu tmux
|
||||||
|
|
||||||
|
docker-test:
|
||||||
|
docker build -t fzf-ubuntu .
|
||||||
|
docker run -it fzf-ubuntu
|
||||||
|
|
||||||
|
update:
|
||||||
|
$(GO) get -u
|
||||||
|
$(GO) mod tidy
|
||||||
|
|
||||||
|
.PHONY: all generate build release test bench lint install clean docker docker-test update
|
||||||
|
|||||||
423
README-VIM.md
423
README-VIM.md
@@ -1,16 +1,83 @@
|
|||||||
FZF Vim integration
|
FZF Vim integration
|
||||||
===================
|
===================
|
||||||
|
|
||||||
This repository only enables basic integration with Vim. If you're looking for
|
Installation
|
||||||
more, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
------------
|
||||||
|
|
||||||
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
Once you have fzf installed, you can enable it inside Vim simply by adding the
|
||||||
|
directory to `&runtimepath` in your Vim configuration file. The path may
|
||||||
|
differ depending on the package manager.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" If installed using Homebrew
|
||||||
|
set rtp+=/usr/local/opt/fzf
|
||||||
|
|
||||||
|
" If installed using Homebrew on Apple Silicon
|
||||||
|
set rtp+=/opt/homebrew/opt/fzf
|
||||||
|
|
||||||
|
" If you have cloned fzf on ~/.fzf directory
|
||||||
|
set rtp+=~/.fzf
|
||||||
|
```
|
||||||
|
|
||||||
|
If you use [vim-plug](https://github.com/junegunn/vim-plug), the same can be
|
||||||
|
written as:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" If installed using Homebrew
|
||||||
|
Plug '/usr/local/opt/fzf'
|
||||||
|
|
||||||
|
" If installed using Homebrew on Apple Silicon
|
||||||
|
Plug '/opt/homebrew/opt/fzf'
|
||||||
|
|
||||||
|
" If you have cloned fzf on ~/.fzf directory
|
||||||
|
Plug '~/.fzf'
|
||||||
|
```
|
||||||
|
|
||||||
|
But if you want the latest Vim plugin file from GitHub rather than the one
|
||||||
|
included in the package, write:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
Plug 'junegunn/fzf'
|
||||||
|
```
|
||||||
|
|
||||||
|
The Vim plugin will pick up fzf binary available on the system. If fzf is not
|
||||||
|
found on `$PATH`, it will ask you if it should download the latest binary for
|
||||||
|
you.
|
||||||
|
|
||||||
|
To make sure that you have the latest version of the binary, set up
|
||||||
|
post-update hook like so:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
||||||
|
```
|
||||||
|
|
||||||
|
Summary
|
||||||
|
-------
|
||||||
|
|
||||||
|
The Vim plugin of fzf provides two core functions, and `:FZF` command which is
|
||||||
|
the basic file selector command built on top of them.
|
||||||
|
|
||||||
|
1. **`fzf#run([spec dict])`**
|
||||||
|
- Starts fzf inside Vim with the given spec
|
||||||
|
- `:call fzf#run({'source': 'ls'})`
|
||||||
|
2. **`fzf#wrap([spec dict]) -> (dict)`**
|
||||||
|
- Takes a spec for `fzf#run` and returns an extended version of it with
|
||||||
|
additional options for addressing global preferences (`g:fzf_xxx`)
|
||||||
|
- `:echo fzf#wrap({'source': 'ls'})`
|
||||||
|
- We usually *wrap* a spec with `fzf#wrap` before passing it to `fzf#run`
|
||||||
|
- `:call fzf#run(fzf#wrap({'source': 'ls'}))`
|
||||||
|
3. **`:FZF [fzf_options string] [path string]`**
|
||||||
|
- Basic fuzzy file selector
|
||||||
|
- A reference implementation for those who don't want to write VimScript
|
||||||
|
to implement custom commands
|
||||||
|
- If you're looking for more such commands, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
||||||
|
|
||||||
|
The most important of all is `fzf#run`, but it would be easier to understand
|
||||||
|
the whole if we start off with `:FZF` command.
|
||||||
|
|
||||||
`:FZF[!]`
|
`:FZF[!]`
|
||||||
---------
|
---------
|
||||||
|
|
||||||
If you have set up fzf for Vim, `:FZF` command will be added.
|
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Look for files under current directory
|
" Look for files under current directory
|
||||||
:FZF
|
:FZF
|
||||||
@@ -18,8 +85,8 @@ If you have set up fzf for Vim, `:FZF` command will be added.
|
|||||||
" Look for files under your home directory
|
" Look for files under your home directory
|
||||||
:FZF ~
|
:FZF ~
|
||||||
|
|
||||||
" With options
|
" With fzf command-line options
|
||||||
:FZF --no-sort --reverse --inline-info /tmp
|
:FZF --reverse --info=inline /tmp
|
||||||
|
|
||||||
" Bang version starts fzf in fullscreen mode
|
" Bang version starts fzf in fullscreen mode
|
||||||
:FZF!
|
:FZF!
|
||||||
@@ -42,9 +109,6 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
|||||||
- Customizes fzf colors to match the current color scheme
|
- Customizes fzf colors to match the current color scheme
|
||||||
- `g:fzf_history_dir`
|
- `g:fzf_history_dir`
|
||||||
- Enables history feature
|
- Enables history feature
|
||||||
- `g:fzf_launcher`
|
|
||||||
- (Only in GVim) Terminal emulator to open fzf with
|
|
||||||
- `g:Fzf_launcher` for function reference
|
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
@@ -57,7 +121,7 @@ let g:fzf_action = {
|
|||||||
|
|
||||||
" An action can be a reference to a function that processes selected lines
|
" An action can be a reference to a function that processes selected lines
|
||||||
function! s:build_quickfix_list(lines)
|
function! s:build_quickfix_list(lines)
|
||||||
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
|
call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": 1 }'))
|
||||||
copen
|
copen
|
||||||
cc
|
cc
|
||||||
endfunction
|
endfunction
|
||||||
@@ -69,15 +133,25 @@ let g:fzf_action = {
|
|||||||
\ 'ctrl-v': 'vsplit' }
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
" Default fzf layout
|
" Default fzf layout
|
||||||
" - down / up / left / right
|
" - Popup window (center of the screen)
|
||||||
let g:fzf_layout = { 'down': '~40%' }
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
|
||||||
" You can set up fzf window using a Vim command (Neovim or latest Vim 8 required)
|
" - Popup window (center of the current window)
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } }
|
||||||
|
|
||||||
|
" - Popup window (anchored to the bottom of the current window)
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } }
|
||||||
|
|
||||||
|
" - down / up / left / right
|
||||||
|
let g:fzf_layout = { 'down': '40%' }
|
||||||
|
|
||||||
|
" - Window using a Vim command
|
||||||
let g:fzf_layout = { 'window': 'enew' }
|
let g:fzf_layout = { 'window': 'enew' }
|
||||||
let g:fzf_layout = { 'window': '-tabnew' }
|
let g:fzf_layout = { 'window': '-tabnew' }
|
||||||
let g:fzf_layout = { 'window': '10split enew' }
|
let g:fzf_layout = { 'window': '10new' }
|
||||||
|
|
||||||
" Customize fzf colors to match your color scheme
|
" Customize fzf colors to match your color scheme
|
||||||
|
" - fzf#wrap translates this to a set of `--color` options
|
||||||
let g:fzf_colors =
|
let g:fzf_colors =
|
||||||
\ { 'fg': ['fg', 'Normal'],
|
\ { 'fg': ['fg', 'Normal'],
|
||||||
\ 'bg': ['bg', 'Normal'],
|
\ 'bg': ['bg', 'Normal'],
|
||||||
@@ -93,82 +167,329 @@ let g:fzf_colors =
|
|||||||
\ 'spinner': ['fg', 'Label'],
|
\ 'spinner': ['fg', 'Label'],
|
||||||
\ 'header': ['fg', 'Comment'] }
|
\ 'header': ['fg', 'Comment'] }
|
||||||
|
|
||||||
" Enable per-command history.
|
" Enable per-command history
|
||||||
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
" - History files will be stored in the specified directory
|
||||||
" previous-history instead of down and up. If you don't like the change,
|
" - When set, CTRL-N and CTRL-P will be bound to 'next-history' and
|
||||||
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
" 'previous-history' instead of 'down' and 'up'.
|
||||||
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### Explanation of `g:fzf_colors`
|
||||||
|
|
||||||
|
`g:fzf_colors` is a dictionary mapping fzf elements to a color specification
|
||||||
|
list:
|
||||||
|
|
||||||
|
element: [ component, group1 [, group2, ...] ]
|
||||||
|
|
||||||
|
- `element` is an fzf element to apply a color to:
|
||||||
|
|
||||||
|
| Element | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `fg` / `bg` / `hl` | Item (foreground / background / highlight) |
|
||||||
|
| `fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight) |
|
||||||
|
| `preview-fg` / `preview-bg` | Preview window text and background |
|
||||||
|
| `hl` / `hl+` | Highlighted substrings (normal / current) |
|
||||||
|
| `gutter` | Background of the gutter on the left |
|
||||||
|
| `pointer` | Pointer to the current line (`>`) |
|
||||||
|
| `marker` | Multi-select marker (`>`) |
|
||||||
|
| `border` | Border around the window (`--border` and `--preview`) |
|
||||||
|
| `header` | Header (`--header` or `--header-lines`) |
|
||||||
|
| `info` | Info line (match counters) |
|
||||||
|
| `spinner` | Streaming input indicator |
|
||||||
|
| `query` | Query string |
|
||||||
|
| `disabled` | Query string when search is disabled |
|
||||||
|
| `prompt` | Prompt before query (`> `) |
|
||||||
|
| `pointer` | Pointer to the current line (`>`) |
|
||||||
|
|
||||||
|
- `component` specifies the component (`fg` / `bg`) from which to extract the
|
||||||
|
color when considering each of the following highlight groups
|
||||||
|
|
||||||
|
- `group1 [, group2, ...]` is a list of highlight groups that are searched (in
|
||||||
|
order) for a matching color definition
|
||||||
|
|
||||||
|
For example, consider the following specification:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
'prompt': ['fg', 'Conditional', 'Comment'],
|
||||||
|
```
|
||||||
|
|
||||||
|
This means we color the **prompt**
|
||||||
|
- using the `fg` attribute of the `Conditional` if it exists,
|
||||||
|
- otherwise use the `fg` attribute of the `Comment` highlight group if it exists,
|
||||||
|
- otherwise fall back to the default color settings for the **prompt**.
|
||||||
|
|
||||||
|
You can examine the color option generated according the setting by printing
|
||||||
|
the result of `fzf#wrap()` function like so:
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:echo fzf#wrap()
|
||||||
|
```
|
||||||
|
|
||||||
`fzf#run`
|
`fzf#run`
|
||||||
---------
|
---------
|
||||||
|
|
||||||
For more advanced uses, you can use `fzf#run([options])` function with the
|
`fzf#run()` function is the core of Vim integration. It takes a single
|
||||||
following options.
|
dictionary argument, *a spec*, and starts fzf process accordingly. At the very
|
||||||
|
least, specify `sink` option to tell what it should do with the selected
|
||||||
|
entry.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'sink': 'e'})
|
||||||
|
```
|
||||||
|
|
||||||
|
We haven't specified the `source`, so this is equivalent to starting fzf on
|
||||||
|
command line without standard input pipe; fzf will traverse the file system
|
||||||
|
under the current directory to get the list of files. (If
|
||||||
|
`$FZF_DEFAULT_COMMAND` is set, fzf will use the output of the command
|
||||||
|
instead.) When you select one, it will open it with the sink, `:e` command. If
|
||||||
|
you want to open it in a new tab, you can pass `:tabedit` command instead as
|
||||||
|
the sink.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'sink': 'tabedit'})
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use any shell command as the source to generate the list. The
|
||||||
|
following example will list the files managed by git. It's equivalent to
|
||||||
|
running `git ls-files | fzf` on shell.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e'})
|
||||||
|
```
|
||||||
|
|
||||||
|
fzf options can be specified as `options` entry in spec dictionary.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'sink': 'tabedit', 'options': '--multi --reverse'})
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also pass a layout option if you don't want fzf window to take up the
|
||||||
|
entire screen.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" up / down / left / right / window are allowed
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'left': '40%'})
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'window': '30vnew'})
|
||||||
|
```
|
||||||
|
|
||||||
|
`source` doesn't have to be an external shell command, you can pass a Vim
|
||||||
|
array as the source. In the next example, we pass the names of color
|
||||||
|
schemes as the source to implement a color scheme selector.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'source': map(split(globpath(&rtp, 'colors/*.vim')),
|
||||||
|
\ 'fnamemodify(v:val, ":t:r")'),
|
||||||
|
\ 'sink': 'colo', 'left': '25%'})
|
||||||
|
```
|
||||||
|
|
||||||
|
The following table summarizes the available options.
|
||||||
|
|
||||||
| Option name | Type | Description |
|
| Option name | Type | Description |
|
||||||
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
||||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||||
| `source` | list | Vim list as input to fzf |
|
| `source` | list | Vim list as input to fzf |
|
||||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
||||||
| `sink` | funcref | Reference to function to process each selected item |
|
| `sink` | funcref | Function to be called with each selected item |
|
||||||
| `sink*` | funcref | Similar to `sink`, but takes the list of output lines at once |
|
| `sinklist` (or `sink*`) | funcref | Similar to `sink`, but takes the list of output lines at once |
|
||||||
|
| `exit` | funcref | Function to be called with the exit status of fzf (e.g. 0, 1, 2, 130) |
|
||||||
| `options` | string/list | Options to fzf |
|
| `options` | string/list | Options to fzf |
|
||||||
| `dir` | string | Working directory |
|
| `dir` | string | Working directory |
|
||||||
| `up`/`down`/`left`/`right` | number/string | Use tmux pane with the given size (e.g. `20`, `50%`) |
|
| `up`/`down`/`left`/`right` | number/string | (Layout) Window position and size (e.g. `20`, `50%`) |
|
||||||
| `window` (Vim 8 / Neovim) | string | Command to open fzf window (e.g. `vertical aboveleft 30new`) |
|
| `tmux` | string | (Layout) `--tmux` options (e.g. `90%,70%`) |
|
||||||
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
|
| `window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new`) |
|
||||||
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |
|
| `window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}`) |
|
||||||
|
|
||||||
`options` entry can be either a string or a list. For simple cases, string
|
`options` entry can be either a string or a list. For simple cases, string
|
||||||
should suffice, but prefer to use list type if you're concerned about escaping
|
should suffice, but prefer to use list type to avoid escaping issues.
|
||||||
issues on different platforms.
|
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
||||||
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When `window` entry is a dictionary, fzf will start in a popup window. The
|
||||||
|
following options are allowed:
|
||||||
|
|
||||||
|
- Required:
|
||||||
|
- `width` [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
||||||
|
- `height` [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
||||||
|
- Optional:
|
||||||
|
- `yoffset` [float default 0.5 range [0 ~ 1]]
|
||||||
|
- `xoffset` [float default 0.5 range [0 ~ 1]]
|
||||||
|
- `relative` [boolean default v:false]
|
||||||
|
- `border` [string default `rounded` (`sharp` on Windows)]: Border style
|
||||||
|
- `rounded` / `sharp` / `horizontal` / `vertical` / `top` / `bottom` / `left` / `right` / `no[ne]`
|
||||||
|
|
||||||
`fzf#wrap`
|
`fzf#wrap`
|
||||||
----------
|
----------
|
||||||
|
|
||||||
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
We have seen that several aspects of `:FZF` command can be configured with
|
||||||
function that decorates the options dictionary so that it understands
|
a set of global option variables; different ways to open files
|
||||||
`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
|
(`g:fzf_action`), window position and size (`g:fzf_layout`), color palette
|
||||||
`:FZF`.
|
(`g:fzf_colors`), etc.
|
||||||
|
|
||||||
|
So how can we make our custom `fzf#run` calls also respect those variables?
|
||||||
|
Simply by *"wrapping"* the spec dictionary with `fzf#wrap` before passing it
|
||||||
|
to `fzf#run`.
|
||||||
|
|
||||||
|
- **`fzf#wrap([name string], [spec dict], [fullscreen bool]) -> (dict)`**
|
||||||
|
- All arguments are optional. Usually we only need to pass a spec dictionary.
|
||||||
|
- `name` is for managing history files. It is ignored if
|
||||||
|
`g:fzf_history_dir` is not defined.
|
||||||
|
- `fullscreen` can be either `0` or `1` (default: 0).
|
||||||
|
|
||||||
|
`fzf#wrap` takes a spec and returns an extended version of it (also
|
||||||
|
a dictionary) with additional options for addressing global preferences. You
|
||||||
|
can examine the return value of it like so:
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
command! -bang MyStuff
|
echo fzf#wrap({'source': 'ls'})
|
||||||
\ call fzf#run(fzf#wrap('my-stuff', {'dir': '~/my-stuff'}, <bang>0))
|
|
||||||
```
|
```
|
||||||
|
|
||||||
GVim
|
After we *"wrap"* our spec, we pass it to `fzf#run`.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run(fzf#wrap({'source': 'ls'}))
|
||||||
|
```
|
||||||
|
|
||||||
|
Now it supports `CTRL-T`, `CTRL-V`, and `CTRL-X` key bindings (configurable
|
||||||
|
via `g:fzf_action`) and it opens fzf window according to `g:fzf_layout`
|
||||||
|
setting.
|
||||||
|
|
||||||
|
To make it easier to use, let's define `LS` command.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
command! LS call fzf#run(fzf#wrap({'source': 'ls'}))
|
||||||
|
```
|
||||||
|
|
||||||
|
Type `:LS` and see how it works.
|
||||||
|
|
||||||
|
We would like to make `:LS!` (bang version) open fzf in fullscreen, just like
|
||||||
|
`:FZF!`. Add `-bang` to command definition, and use `<bang>` value to set
|
||||||
|
the last `fullscreen` argument of `fzf#wrap` (see `:help <bang>`).
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" On :LS!, <bang> evaluates to '!', and '!0' becomes 1
|
||||||
|
command! -bang LS call fzf#run(fzf#wrap({'source': 'ls'}, <bang>0))
|
||||||
|
```
|
||||||
|
|
||||||
|
Our `:LS` command will be much more useful if we can pass a directory argument
|
||||||
|
to it, so that something like `:LS /tmp` is possible.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
command! -bang -complete=dir -nargs=? LS
|
||||||
|
\ call fzf#run(fzf#wrap({'source': 'ls', 'dir': <q-args>}, <bang>0))
|
||||||
|
```
|
||||||
|
|
||||||
|
Lastly, if you have enabled `g:fzf_history_dir`, you might want to assign
|
||||||
|
a unique name to our command and pass it as the first argument to `fzf#wrap`.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" The query history for this command will be stored as 'ls' inside g:fzf_history_dir.
|
||||||
|
" The name is ignored if g:fzf_history_dir is not defined.
|
||||||
|
command! -bang -complete=dir -nargs=? LS
|
||||||
|
\ call fzf#run(fzf#wrap('ls', {'source': 'ls', 'dir': <q-args>}, <bang>0))
|
||||||
|
```
|
||||||
|
|
||||||
|
### Global options supported by `fzf#wrap`
|
||||||
|
|
||||||
|
- `g:fzf_layout`
|
||||||
|
- `g:fzf_action`
|
||||||
|
- **Works only when no custom `sink` (or `sinklist`) is provided**
|
||||||
|
- Having custom sink usually means that each entry is not an ordinary
|
||||||
|
file path (e.g. name of color scheme), so we can't blindly apply the
|
||||||
|
same strategy (i.e. `tabedit some-color-scheme` doesn't make sense)
|
||||||
|
- `g:fzf_colors`
|
||||||
|
- `g:fzf_history_dir`
|
||||||
|
|
||||||
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
With the latest version of GVim, fzf will start inside the builtin terminal
|
### fzf inside terminal buffer
|
||||||
emulator of Vim. Please note that this terminal feature of Vim is still young
|
|
||||||
and unstable and you may run into some issues.
|
|
||||||
|
|
||||||
If you have an older version of GVim, you need an external terminal emulator
|
On the latest versions of Vim and Neovim, fzf will start in a terminal buffer.
|
||||||
to start fzf with. `xterm` command is used by default, but you can customize
|
If you find the default ANSI colors to be different, consider configuring the
|
||||||
it with `g:fzf_launcher`.
|
colors using `g:terminal_ansi_colors` in regular Vim or `g:terminal_color_x`
|
||||||
|
in Neovim.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" This is the default. %s is replaced with fzf command
|
" Terminal colors for seoul256 color scheme
|
||||||
let g:fzf_launcher = 'xterm -e bash -ic %s'
|
if has('nvim')
|
||||||
|
let g:terminal_color_0 = '#4e4e4e'
|
||||||
" Use urxvt instead
|
let g:terminal_color_1 = '#d68787'
|
||||||
let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s'
|
let g:terminal_color_2 = '#5f865f'
|
||||||
|
let g:terminal_color_3 = '#d8af5f'
|
||||||
|
let g:terminal_color_4 = '#85add4'
|
||||||
|
let g:terminal_color_5 = '#d7afaf'
|
||||||
|
let g:terminal_color_6 = '#87afaf'
|
||||||
|
let g:terminal_color_7 = '#d0d0d0'
|
||||||
|
let g:terminal_color_8 = '#626262'
|
||||||
|
let g:terminal_color_9 = '#d75f87'
|
||||||
|
let g:terminal_color_10 = '#87af87'
|
||||||
|
let g:terminal_color_11 = '#ffd787'
|
||||||
|
let g:terminal_color_12 = '#add4fb'
|
||||||
|
let g:terminal_color_13 = '#ffafaf'
|
||||||
|
let g:terminal_color_14 = '#87d7d7'
|
||||||
|
let g:terminal_color_15 = '#e4e4e4'
|
||||||
|
else
|
||||||
|
let g:terminal_ansi_colors = [
|
||||||
|
\ '#4e4e4e', '#d68787', '#5f865f', '#d8af5f',
|
||||||
|
\ '#85add4', '#d7afaf', '#87afaf', '#d0d0d0',
|
||||||
|
\ '#626262', '#d75f87', '#87af87', '#ffd787',
|
||||||
|
\ '#add4fb', '#ffafaf', '#87d7d7', '#e4e4e4'
|
||||||
|
\ ]
|
||||||
|
endif
|
||||||
```
|
```
|
||||||
|
|
||||||
If you're running MacVim on OSX, I recommend you to use iTerm2 as the
|
### Starting fzf in a popup window
|
||||||
launcher. Refer to the [this wiki page][macvim-iterm2] to see how to set up.
|
|
||||||
|
|
||||||
[macvim-iterm2]: https://github.com/junegunn/fzf/wiki/On-MacVim-with-iTerm2
|
```vim
|
||||||
|
" Required:
|
||||||
|
" - width [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
||||||
|
" - height [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
||||||
|
"
|
||||||
|
" Optional:
|
||||||
|
" - xoffset [float default 0.5 range [0 ~ 1]]
|
||||||
|
" - yoffset [float default 0.5 range [0 ~ 1]]
|
||||||
|
" - relative [boolean default v:false]
|
||||||
|
" - border [string default 'rounded']: Border style
|
||||||
|
" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2
|
||||||
|
or above) by putting `--tmux` option value in `tmux` key.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" See `--tmux` option in `man fzf` for available options
|
||||||
|
" [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
|
||||||
|
if exists('$TMUX')
|
||||||
|
let g:fzf_layout = { 'tmux': '90%,70%' }
|
||||||
|
else
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
endif
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hide statusline
|
||||||
|
|
||||||
|
When fzf starts in a terminal buffer, the file type of the buffer is set to
|
||||||
|
`fzf`. So you can set up `FileType fzf` autocmd to customize the settings of
|
||||||
|
the window.
|
||||||
|
|
||||||
|
For example, if you open fzf on the bottom on the screen (e.g. `{'down':
|
||||||
|
'40%'}`), you might want to temporarily disable the statusline for a cleaner
|
||||||
|
look.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:fzf_layout = { 'down': '30%' }
|
||||||
|
autocmd! FileType fzf
|
||||||
|
autocmd FileType fzf set laststatus=0 noshowmode noruler
|
||||||
|
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
|
||||||
|
```
|
||||||
|
|
||||||
[License](LICENSE)
|
[License](LICENSE)
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|||||||
74
bin/fzf-preview.sh
Executable file
74
bin/fzf-preview.sh
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# The purpose of this script is to demonstrate how to preview a file or an
|
||||||
|
# image in the preview window of fzf.
|
||||||
|
#
|
||||||
|
# Dependencies:
|
||||||
|
# - https://github.com/sharkdp/bat
|
||||||
|
# - https://github.com/hpjansson/chafa
|
||||||
|
# - https://iterm2.com/utilities/imgcat
|
||||||
|
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
|
>&2 echo "usage: $0 FILENAME"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
file=${1/#\~\//$HOME/}
|
||||||
|
type=$(file --dereference --mime -- "$file")
|
||||||
|
|
||||||
|
if [[ ! $type =~ image/ ]]; then
|
||||||
|
if [[ $type =~ =binary ]]; then
|
||||||
|
file "$1"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Sometimes bat is installed as batcat.
|
||||||
|
if command -v batcat > /dev/null; then
|
||||||
|
batname="batcat"
|
||||||
|
elif command -v bat > /dev/null; then
|
||||||
|
batname="bat"
|
||||||
|
else
|
||||||
|
cat "$1"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
dim=${FZF_PREVIEW_COLUMNS}x${FZF_PREVIEW_LINES}
|
||||||
|
if [[ $dim = x ]]; then
|
||||||
|
dim=$(stty size < /dev/tty | awk '{print $2 "x" $1}')
|
||||||
|
elif ! [[ $KITTY_WINDOW_ID ]] && (( FZF_PREVIEW_TOP + FZF_PREVIEW_LINES == $(stty size < /dev/tty | awk '{print $1}') )); then
|
||||||
|
# Avoid scrolling issue when the Sixel image touches the bottom of the screen
|
||||||
|
# * https://github.com/junegunn/fzf/issues/2544
|
||||||
|
dim=${FZF_PREVIEW_COLUMNS}x$((FZF_PREVIEW_LINES - 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 1. Use kitty icat on kitty terminal
|
||||||
|
if [[ $KITTY_WINDOW_ID ]]; then
|
||||||
|
# 1. 'memory' is the fastest option but if you want the image to be scrollable,
|
||||||
|
# you have to use 'stream'.
|
||||||
|
#
|
||||||
|
# 2. The last line of the output is the ANSI reset code without newline.
|
||||||
|
# This confuses fzf and makes it render scroll offset indicator.
|
||||||
|
# So we remove the last line and append the reset code to its previous line.
|
||||||
|
kitty icat --clear --transfer-mode=memory --unicode-placeholder --stdin=no --place="$dim@0x0" "$file" | sed '$d' | sed $'$s/$/\e[m/'
|
||||||
|
|
||||||
|
# 2. Use chafa with Sixel output
|
||||||
|
elif command -v chafa > /dev/null; then
|
||||||
|
chafa -s "$dim" "$file"
|
||||||
|
# Add a new line character so that fzf can display multiple images in the preview window
|
||||||
|
echo
|
||||||
|
|
||||||
|
# 3. If chafa is not found but imgcat is available, use it on iTerm2
|
||||||
|
elif command -v imgcat > /dev/null; then
|
||||||
|
# NOTE: We should use https://iterm2.com/utilities/it2check to check if the
|
||||||
|
# user is running iTerm2. But for the sake of simplicity, we just assume
|
||||||
|
# that's the case here.
|
||||||
|
imgcat -W "${dim%%x*}" -H "${dim##*x}" "$file"
|
||||||
|
|
||||||
|
# 4. Cannot find any suitable method to preview the image
|
||||||
|
else
|
||||||
|
file "$file"
|
||||||
|
fi
|
||||||
148
bin/fzf-tmux
148
bin/fzf-tmux
@@ -1,13 +1,13 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# fzf-tmux: starts fzf in a tmux pane
|
# fzf-tmux: starts fzf in a tmux pane
|
||||||
# usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
# usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||||
|
|
||||||
fail() {
|
fail() {
|
||||||
>&2 echo "$1"
|
>&2 echo "$1"
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fzf="$(command -v fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
fzf="$(command which fzf)" || fzf="$(dirname "$0")/fzf"
|
||||||
[[ -x "$fzf" ]] || fail 'fzf executable not found'
|
[[ -x "$fzf" ]] || fail 'fzf executable not found'
|
||||||
|
|
||||||
args=()
|
args=()
|
||||||
@@ -19,16 +19,27 @@ term=""
|
|||||||
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")
|
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines) || lines=$(tmux display-message -p "#{pane_height}")
|
||||||
[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")
|
[[ -n "$COLUMNS" ]] && columns=$COLUMNS || columns=$(tput cols) || columns=$(tmux display-message -p "#{pane_width}")
|
||||||
|
|
||||||
help() {
|
tmux_version=$(tmux -V | sed 's/[^0-9.]//g')
|
||||||
>&2 echo 'usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
tmux_32=$(awk '{print ($1 >= 3.2)}' <<< "$tmux_version" 2> /dev/null || bc -l <<< "$tmux_version >= 3.2")
|
||||||
|
|
||||||
Layout
|
help() {
|
||||||
|
>&2 echo 'usage: fzf-tmux [LAYOUT OPTIONS] [--] [FZF OPTIONS]
|
||||||
|
|
||||||
|
LAYOUT OPTIONS:
|
||||||
|
(default layout: -d 50%)
|
||||||
|
|
||||||
|
Popup window (requires tmux 3.2 or above):
|
||||||
|
-p [WIDTH[%][,HEIGHT[%]]] (default: 50%)
|
||||||
|
-w WIDTH[%]
|
||||||
|
-h HEIGHT[%]
|
||||||
|
-x COL
|
||||||
|
-y ROW
|
||||||
|
|
||||||
|
Split pane:
|
||||||
-u [HEIGHT[%]] Split above (up)
|
-u [HEIGHT[%]] Split above (up)
|
||||||
-d [HEIGHT[%]] Split below (down)
|
-d [HEIGHT[%]] Split below (down)
|
||||||
-l [WIDTH[%]] Split left
|
-l [WIDTH[%]] Split left
|
||||||
-r [WIDTH[%]] Split right
|
-r [WIDTH[%]] Split right
|
||||||
|
|
||||||
(default: -d 50%)
|
|
||||||
'
|
'
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
@@ -47,8 +58,10 @@ while [[ $# -gt 0 ]]; do
|
|||||||
echo "fzf-tmux (with fzf $("$fzf" --version))"
|
echo "fzf-tmux (with fzf $("$fzf" --version))"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
-w*|-h*|-d*|-u*|-r*|-l*)
|
-p*|-w*|-h*|-x*|-y*|-d*|-u*|-r*|-l*)
|
||||||
if [[ "$arg" =~ ^.[lrw] ]]; then
|
if [[ "$arg" =~ ^-[pwhxy] ]]; then
|
||||||
|
[[ "$opt" =~ "-E" ]] || opt="-E"
|
||||||
|
elif [[ "$arg" =~ ^.[lr] ]]; then
|
||||||
opt="-h"
|
opt="-h"
|
||||||
if [[ "$arg" =~ ^.l ]]; then
|
if [[ "$arg" =~ ^.l ]]; then
|
||||||
opt="$opt -d"
|
opt="$opt -d"
|
||||||
@@ -66,7 +79,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
if [[ ${#arg} -gt 2 ]]; then
|
if [[ ${#arg} -gt 2 ]]; then
|
||||||
size="${arg:2}"
|
size="${arg:2}"
|
||||||
else
|
else
|
||||||
if [[ "$1" =~ ^[0-9]+%?$ ]]; then
|
if [[ "$1" =~ ^[0-9%,]+$ ]] || [[ "$1" =~ ^[A-Z]$ ]]; then
|
||||||
size="$1"
|
size="$1"
|
||||||
shift
|
shift
|
||||||
else
|
else
|
||||||
@@ -74,13 +87,29 @@ while [[ $# -gt 0 ]]; do
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$size" =~ %$ ]]; then
|
if [[ "$arg" =~ ^-p ]]; then
|
||||||
|
if [[ -n "$size" ]]; then
|
||||||
|
w=${size%%,*}
|
||||||
|
h=${size##*,}
|
||||||
|
opt="$opt -w$w -h$h"
|
||||||
|
fi
|
||||||
|
elif [[ "$arg" =~ ^-[whxy] ]]; then
|
||||||
|
opt="$opt ${arg:0:2}$size"
|
||||||
|
elif [[ "$size" =~ %$ ]]; then
|
||||||
size=${size:0:((${#size}-1))}
|
size=${size:0:((${#size}-1))}
|
||||||
|
if [[ $tmux_32 = 1 ]]; then
|
||||||
|
if [[ -n "$swap" ]]; then
|
||||||
|
opt="$opt -l $(( 100 - size ))%"
|
||||||
|
else
|
||||||
|
opt="$opt -l $size%"
|
||||||
|
fi
|
||||||
|
else
|
||||||
if [[ -n "$swap" ]]; then
|
if [[ -n "$swap" ]]; then
|
||||||
opt="$opt -p $(( 100 - size ))"
|
opt="$opt -p $(( 100 - size ))"
|
||||||
else
|
else
|
||||||
opt="$opt -p $size"
|
opt="$opt -p $size"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
if [[ -n "$swap" ]]; then
|
if [[ -n "$swap" ]]; then
|
||||||
if [[ "$arg" =~ ^.l ]]; then
|
if [[ "$arg" =~ ^.l ]]; then
|
||||||
@@ -109,17 +138,19 @@ while [[ $# -gt 0 ]]; do
|
|||||||
[[ -n "$skip" ]] && args+=("$arg")
|
[[ -n "$skip" ]] && args+=("$arg")
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z "$TMUX" || "$opt" =~ ^-h && "$columns" -le 40 || ! "$opt" =~ ^-h && "$lines" -le 15 ]]; then
|
if [[ -z "$TMUX" ]]; then
|
||||||
"$fzf" "${args[@]}"
|
"$fzf" "${args[@]}"
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --height option is not allowed
|
# * --height option is not allowed
|
||||||
args+=("--no-height")
|
# * CTRL-Z is also disabled
|
||||||
|
# * fzf-tmux script is not compatible with --tmux option in fzf 0.53.0 or later
|
||||||
|
args=("${args[@]}" "--no-height" "--bind=ctrl-z:ignore" "--no-tmux")
|
||||||
|
|
||||||
# Handle zoomed tmux pane by moving it to a temp window
|
# Handle zoomed tmux pane without popup options by moving it to a temp window
|
||||||
if tmux list-panes -F '#F' | grep -q Z; then
|
if [[ ! "$opt" =~ "-E" ]] && tmux list-panes -F '#F' | grep -q Z; then
|
||||||
zoomed=1
|
zoomed_without_popup=1
|
||||||
original_window=$(tmux display-message -p "#{window_id}")
|
original_window=$(tmux display-message -p "#{window_id}")
|
||||||
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
||||||
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
||||||
@@ -133,11 +164,23 @@ argsf="${TMPDIR:-/tmp}/fzf-args-$id"
|
|||||||
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
|
fifo1="${TMPDIR:-/tmp}/fzf-fifo1-$id"
|
||||||
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
||||||
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
||||||
|
if tmux_win_opts=$(tmux show-options -p remain-on-exit \; show-options -p synchronize-panes 2> /dev/null); then
|
||||||
|
tmux_win_opts=( $(sed '/ off/d; s/synchronize-panes/set-option -p synchronize-panes/; s/remain-on-exit/set-option -p remain-on-exit/; s/$/ \\;/' <<< "$tmux_win_opts") )
|
||||||
|
tmux_off_opts='; set-option -p synchronize-panes off ; set-option -p remain-on-exit off'
|
||||||
|
else
|
||||||
|
tmux_win_opts=( $(tmux show-window-options remain-on-exit \; show-window-options synchronize-panes | sed '/ off/d; s/^/set-window-option /; s/$/ \\;/') )
|
||||||
|
tmux_off_opts='; set-window-option synchronize-panes off ; set-window-option remain-on-exit off'
|
||||||
|
fi
|
||||||
cleanup() {
|
cleanup() {
|
||||||
\rm -f $argsf $fifo1 $fifo2 $fifo3
|
\rm -f $argsf $fifo1 $fifo2 $fifo3
|
||||||
|
|
||||||
# Remove temp window if we were zoomed
|
# Restore tmux window options
|
||||||
if [[ -n "$zoomed" ]]; then
|
if [[ "${#tmux_win_opts[@]}" -gt 1 ]]; then
|
||||||
|
eval "tmux ${tmux_win_opts[*]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove temp window if we were zoomed without popup options
|
||||||
|
if [[ -n "$zoomed_without_popup" ]]; then
|
||||||
tmux display-message -p "#{window_id}" > /dev/null
|
tmux display-message -p "#{window_id}" > /dev/null
|
||||||
tmux swap-pane -t $original_window \; \
|
tmux swap-pane -t $original_window \; \
|
||||||
select-window -t $original_window \; \
|
select-window -t $original_window \; \
|
||||||
@@ -145,7 +188,7 @@ cleanup() {
|
|||||||
resize-pane -Z
|
resize-pane -Z
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $# -gt 0 ]; then
|
if [[ $# -gt 0 ]]; then
|
||||||
trap - EXIT
|
trap - EXIT
|
||||||
exit 130
|
exit 130
|
||||||
fi
|
fi
|
||||||
@@ -153,42 +196,59 @@ cleanup() {
|
|||||||
trap 'cleanup 1' SIGUSR1
|
trap 'cleanup 1' SIGUSR1
|
||||||
trap 'cleanup' EXIT
|
trap 'cleanup' EXIT
|
||||||
|
|
||||||
envs="env TERM=$TERM "
|
envs="export TERM=$TERM "
|
||||||
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
if [[ "$opt" =~ "-E" ]]; then
|
||||||
[[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
if [[ $tmux_version = 3.2 ]]; then
|
||||||
|
FZF_DEFAULT_OPTS="--margin 0,1 $FZF_DEFAULT_OPTS"
|
||||||
mkfifo -m o+w $fifo2
|
elif [[ $tmux_32 = 1 ]]; then
|
||||||
mkfifo -m o+w $fifo3
|
FZF_DEFAULT_OPTS="--border $FZF_DEFAULT_OPTS"
|
||||||
|
opt="-B $opt"
|
||||||
|
else
|
||||||
|
echo "fzf-tmux: tmux 3.2 or above is required for popup mode" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
||||||
|
envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
||||||
|
envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")"
|
||||||
|
[[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")"
|
||||||
|
[[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")"
|
||||||
|
echo "$envs;" > "$argsf"
|
||||||
|
|
||||||
# Build arguments to fzf
|
# Build arguments to fzf
|
||||||
opts=""
|
opts=$(printf "%q " "${args[@]}")
|
||||||
for arg in "${args[@]}"; do
|
|
||||||
arg="${arg//\\/\\\\}"
|
|
||||||
arg="${arg//\"/\\\"}"
|
|
||||||
arg="${arg//\`/\\\`}"
|
|
||||||
arg="${arg//$/\\$}"
|
|
||||||
opts="$opts \"$arg\""
|
|
||||||
done
|
|
||||||
|
|
||||||
pppid=$$
|
pppid=$$
|
||||||
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" > $argsf
|
echo -n "trap 'kill -SIGUSR1 -$pppid' EXIT SIGINT SIGTERM;" >> $argsf
|
||||||
close="; trap - EXIT SIGINT SIGTERM $close"
|
close="; trap - EXIT SIGINT SIGTERM $close"
|
||||||
|
|
||||||
|
export TMUX=$(cut -d , -f 1,2 <<< "$TMUX")
|
||||||
|
mkfifo -m o+w $fifo2
|
||||||
|
if [[ "$opt" =~ "-E" ]]; then
|
||||||
|
cat $fifo2 &
|
||||||
|
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||||
|
cat <<< "\"$fzf\" $opts > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||||
|
else
|
||||||
|
mkfifo $fifo1
|
||||||
|
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; out=\$? $close; exit \$out" >> $argsf
|
||||||
|
cat <&0 > $fifo1 &
|
||||||
|
fi
|
||||||
|
|
||||||
|
tmux popup -d "$PWD" $opt "bash $argsf" > /dev/null 2>&1
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkfifo -m o+w $fifo3
|
||||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||||
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||||
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
|
||||||
set-window-option remain-on-exit off \;\
|
|
||||||
split-window $opt "$envs bash -c 'cd $(printf %q "$PWD"); exec -a fzf bash $argsf'" $swap \
|
|
||||||
> /dev/null 2>&1
|
|
||||||
else
|
else
|
||||||
mkfifo $fifo1
|
mkfifo $fifo1
|
||||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" >> $argsf
|
||||||
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
|
||||||
set-window-option remain-on-exit off \;\
|
|
||||||
split-window $opt "$envs bash -c 'exec -a fzf bash $argsf'" $swap \
|
|
||||||
> /dev/null 2>&1
|
|
||||||
cat <&0 > $fifo1 &
|
cat <&0 > $fifo1 &
|
||||||
fi
|
fi
|
||||||
|
tmux \
|
||||||
|
split-window -c "$PWD" $opt "bash -c 'exec -a fzf bash $argsf'" $swap \
|
||||||
|
$tmux_off_opts \
|
||||||
|
> /dev/null 2>&1 || { "$fzf" "${args[@]}"; exit $?; }
|
||||||
cat $fifo2
|
cat $fifo2
|
||||||
exit "$(cat $fifo3)"
|
exit "$(cat $fifo3)"
|
||||||
|
|
||||||
|
|||||||
450
doc/fzf.txt
450
doc/fzf.txt
@@ -1,33 +1,104 @@
|
|||||||
fzf.txt fzf Last change: September 29 2017
|
fzf.txt fzf Last change: February 15 2024
|
||||||
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
|
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
FZF Vim integration
|
FZF Vim integration |fzf-vim-integration|
|
||||||
:FZF[!]
|
Installation |fzf-installation|
|
||||||
Configuration
|
Summary |fzf-summary|
|
||||||
Examples
|
:FZF[!] |:FZF|
|
||||||
fzf#run
|
Configuration |fzf-configuration|
|
||||||
fzf#wrap
|
Examples |fzf-examples|
|
||||||
GVim
|
Explanation of g:fzf_colors |fzf-explanation-of-gfzfcolors|
|
||||||
License
|
fzf#run |fzf#run|
|
||||||
|
fzf#wrap |fzf#wrap|
|
||||||
|
Global options supported by fzf#wrap |fzf-global-options-supported-by-fzf#wrap|
|
||||||
|
Tips |fzf-tips|
|
||||||
|
fzf inside terminal buffer |fzf-inside-terminal-buffer|
|
||||||
|
Starting fzf in a popup window |fzf-starting-fzf-in-a-popup-window|
|
||||||
|
Hide statusline |fzf-hide-statusline|
|
||||||
|
License |fzf-license|
|
||||||
|
|
||||||
FZF VIM INTEGRATION *fzf-vim-integration*
|
FZF VIM INTEGRATION *fzf-vim-integration*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
This repository only enables basic integration with Vim. If you're looking for
|
|
||||||
more, check out {fzf.vim}{1} project.
|
|
||||||
|
|
||||||
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
INSTALLATION *fzf-installation*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
{1} https://github.com/junegunn/fzf.vim
|
Once you have fzf installed, you can enable it inside Vim simply by adding the
|
||||||
|
directory to 'runtimepath' in your Vim configuration file. The path may differ
|
||||||
|
depending on the package manager.
|
||||||
|
>
|
||||||
|
" If installed using Homebrew
|
||||||
|
set rtp+=/usr/local/opt/fzf
|
||||||
|
|
||||||
|
" If installed using Homebrew on Apple Silicon
|
||||||
|
set rtp+=/opt/homebrew/opt/fzf
|
||||||
|
|
||||||
|
" If you have cloned fzf on ~/.fzf directory
|
||||||
|
set rtp+=~/.fzf
|
||||||
|
<
|
||||||
|
If you use {vim-plug}{1}, the same can be written as:
|
||||||
|
>
|
||||||
|
" If installed using Homebrew
|
||||||
|
Plug '/usr/local/opt/fzf'
|
||||||
|
|
||||||
|
" If installed using Homebrew on Apple Silicon
|
||||||
|
Plug '/opt/homebrew/opt/fzf'
|
||||||
|
|
||||||
|
" If you have cloned fzf on ~/.fzf directory
|
||||||
|
Plug '~/.fzf'
|
||||||
|
<
|
||||||
|
But if you want the latest Vim plugin file from GitHub rather than the one
|
||||||
|
included in the package, write:
|
||||||
|
>
|
||||||
|
Plug 'junegunn/fzf'
|
||||||
|
<
|
||||||
|
The Vim plugin will pick up fzf binary available on the system. If fzf is not
|
||||||
|
found on `$PATH`, it will ask you if it should download the latest binary for
|
||||||
|
you.
|
||||||
|
|
||||||
|
To make sure that you have the latest version of the binary, set up
|
||||||
|
post-update hook like so:
|
||||||
|
|
||||||
|
*fzf#install*
|
||||||
|
>
|
||||||
|
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
||||||
|
<
|
||||||
|
{1} https://github.com/junegunn/vim-plug
|
||||||
|
|
||||||
|
|
||||||
|
SUMMARY *fzf-summary*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
The Vim plugin of fzf provides two core functions, and `:FZF` command which is
|
||||||
|
the basic file selector command built on top of them.
|
||||||
|
|
||||||
|
1. `fzf#run([spec dict])`
|
||||||
|
- Starts fzf inside Vim with the given spec
|
||||||
|
- `:call fzf#run({'source': 'ls'})`
|
||||||
|
2. `fzf#wrap([spec dict]) -> (dict)`
|
||||||
|
- Takes a spec for `fzf#run` and returns an extended version of it with
|
||||||
|
additional options for addressing global preferences (`g:fzf_xxx`)
|
||||||
|
- `:echo fzf#wrap({'source': 'ls'})`
|
||||||
|
- We usually wrap a spec with `fzf#wrap` before passing it to `fzf#run`
|
||||||
|
- `:call fzf#run(fzf#wrap({'source': 'ls'}))`
|
||||||
|
3. `:FZF [fzf_options string] [path string]`
|
||||||
|
- Basic fuzzy file selector
|
||||||
|
- A reference implementation for those who don't want to write VimScript to
|
||||||
|
implement custom commands
|
||||||
|
- If you're looking for more such commands, check out {fzf.vim}{2} project.
|
||||||
|
|
||||||
|
The most important of all is `fzf#run`, but it would be easier to understand
|
||||||
|
the whole if we start off with `:FZF` command.
|
||||||
|
|
||||||
|
{2} https://github.com/junegunn/fzf.vim
|
||||||
|
|
||||||
|
|
||||||
:FZF[!]
|
:FZF[!]
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
*:FZF*
|
*:FZF*
|
||||||
|
|
||||||
If you have set up fzf for Vim, `:FZF` command will be added.
|
|
||||||
>
|
>
|
||||||
" Look for files under current directory
|
" Look for files under current directory
|
||||||
:FZF
|
:FZF
|
||||||
@@ -35,27 +106,26 @@ If you have set up fzf for Vim, `:FZF` command will be added.
|
|||||||
" Look for files under your home directory
|
" Look for files under your home directory
|
||||||
:FZF ~
|
:FZF ~
|
||||||
|
|
||||||
" With options
|
" With fzf command-line options
|
||||||
:FZF --no-sort --reverse --inline-info /tmp
|
:FZF --reverse --info=inline /tmp
|
||||||
|
|
||||||
" Bang version starts fzf in fullscreen mode
|
" Bang version starts fzf in fullscreen mode
|
||||||
:FZF!
|
:FZF!
|
||||||
<
|
<
|
||||||
Similarly to {ctrlp.vim}{2}, use enter key, CTRL-T, CTRL-X or CTRL-V to open
|
Similarly to {ctrlp.vim}{3}, use enter key, CTRL-T, CTRL-X or CTRL-V to open
|
||||||
selected files in the current window, in new tabs, in horizontal splits, or in
|
selected files in the current window, in new tabs, in horizontal splits, or in
|
||||||
vertical splits respectively.
|
vertical splits respectively.
|
||||||
|
|
||||||
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
||||||
`FZF_DEFAULT_OPTS` also apply here.
|
`FZF_DEFAULT_OPTS` also apply here.
|
||||||
|
|
||||||
{2} https://github.com/kien/ctrlp.vim
|
{3} https://github.com/kien/ctrlp.vim
|
||||||
|
|
||||||
|
|
||||||
< Configuration >_____________________________________________________________~
|
< Configuration >_____________________________________________________________~
|
||||||
*fzf-configuration*
|
*fzf-configuration*
|
||||||
|
|
||||||
*g:fzf_action* *g:fzf_layout* *g:fzf_colors* *g:fzf_history_dir* *g:fzf_launcher*
|
*g:fzf_action* *g:fzf_layout* *g:fzf_colors* *g:fzf_history_dir*
|
||||||
*g:Fzf_launcher*
|
|
||||||
|
|
||||||
- `g:fzf_action`
|
- `g:fzf_action`
|
||||||
- Customizable extra key bindings for opening selected files in different
|
- Customizable extra key bindings for opening selected files in different
|
||||||
@@ -66,9 +136,6 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
|||||||
- Customizes fzf colors to match the current color scheme
|
- Customizes fzf colors to match the current color scheme
|
||||||
- `g:fzf_history_dir`
|
- `g:fzf_history_dir`
|
||||||
- Enables history feature
|
- Enables history feature
|
||||||
- `g:fzf_launcher`
|
|
||||||
- (Only in GVim) Terminal emulator to open fzf with
|
|
||||||
- `g:Fzf_launcher` for function reference
|
|
||||||
|
|
||||||
|
|
||||||
Examples~
|
Examples~
|
||||||
@@ -82,7 +149,7 @@ Examples~
|
|||||||
|
|
||||||
" An action can be a reference to a function that processes selected lines
|
" An action can be a reference to a function that processes selected lines
|
||||||
function! s:build_quickfix_list(lines)
|
function! s:build_quickfix_list(lines)
|
||||||
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
|
call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": 1 }'))
|
||||||
copen
|
copen
|
||||||
cc
|
cc
|
||||||
endfunction
|
endfunction
|
||||||
@@ -94,15 +161,25 @@ Examples~
|
|||||||
\ 'ctrl-v': 'vsplit' }
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
" Default fzf layout
|
" Default fzf layout
|
||||||
" - down / up / left / right
|
" - Popup window (center of the screen)
|
||||||
let g:fzf_layout = { 'down': '~40%' }
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
|
||||||
" You can set up fzf window using a Vim command (Neovim or latest Vim 8 required)
|
" - Popup window (center of the current window)
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true } }
|
||||||
|
|
||||||
|
" - Popup window (anchored to the bottom of the current window)
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6, 'relative': v:true, 'yoffset': 1.0 } }
|
||||||
|
|
||||||
|
" - down / up / left / right
|
||||||
|
let g:fzf_layout = { 'down': '40%' }
|
||||||
|
|
||||||
|
" - Window using a Vim command
|
||||||
let g:fzf_layout = { 'window': 'enew' }
|
let g:fzf_layout = { 'window': 'enew' }
|
||||||
let g:fzf_layout = { 'window': '-tabnew' }
|
let g:fzf_layout = { 'window': '-tabnew' }
|
||||||
let g:fzf_layout = { 'window': '10split enew' }
|
let g:fzf_layout = { 'window': '10new' }
|
||||||
|
|
||||||
" Customize fzf colors to match your color scheme
|
" Customize fzf colors to match your color scheme
|
||||||
|
" - fzf#wrap translates this to a set of `--color` options
|
||||||
let g:fzf_colors =
|
let g:fzf_colors =
|
||||||
\ { 'fg': ['fg', 'Normal'],
|
\ { 'fg': ['fg', 'Normal'],
|
||||||
\ 'bg': ['bg', 'Normal'],
|
\ 'bg': ['bg', 'Normal'],
|
||||||
@@ -118,84 +195,315 @@ Examples~
|
|||||||
\ 'spinner': ['fg', 'Label'],
|
\ 'spinner': ['fg', 'Label'],
|
||||||
\ 'header': ['fg', 'Comment'] }
|
\ 'header': ['fg', 'Comment'] }
|
||||||
|
|
||||||
" Enable per-command history.
|
" Enable per-command history
|
||||||
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
" - History files will be stored in the specified directory
|
||||||
" previous-history instead of down and up. If you don't like the change,
|
" - When set, CTRL-N and CTRL-P will be bound to 'next-history' and
|
||||||
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
" 'previous-history' instead of 'down' and 'up'.
|
||||||
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||||
<
|
<
|
||||||
|
|
||||||
FZF#RUN *fzf#run*
|
Explanation of g:fzf_colors~
|
||||||
|
*fzf-explanation-of-gfzfcolors*
|
||||||
|
|
||||||
|
`g:fzf_colors` is a dictionary mapping fzf elements to a color specification
|
||||||
|
list:
|
||||||
|
>
|
||||||
|
element: [ component, group1 [, group2, ...] ]
|
||||||
|
<
|
||||||
|
- `element` is an fzf element to apply a color to:
|
||||||
|
|
||||||
|
----------------------------+------------------------------------------------------
|
||||||
|
Element | Description ~
|
||||||
|
----------------------------+------------------------------------------------------
|
||||||
|
`fg` / `bg` / `hl` | Item (foreground / background / highlight)
|
||||||
|
`fg+` / `bg+` / `hl+` | Current item (foreground / background / highlight)
|
||||||
|
`preview-fg` / `preview-bg` | Preview window text and background
|
||||||
|
`hl` / `hl+` | Highlighted substrings (normal / current)
|
||||||
|
`gutter` | Background of the gutter on the left
|
||||||
|
`pointer` | Pointer to the current line ( `>` )
|
||||||
|
`marker` | Multi-select marker ( `>` )
|
||||||
|
`border` | Border around the window ( `--border` and `--preview` )
|
||||||
|
`header` | Header ( `--header` or `--header-lines` )
|
||||||
|
`info` | Info line (match counters)
|
||||||
|
`spinner` | Streaming input indicator
|
||||||
|
`query` | Query string
|
||||||
|
`disabled` | Query string when search is disabled
|
||||||
|
`prompt` | Prompt before query ( `> ` )
|
||||||
|
`pointer` | Pointer to the current line ( `>` )
|
||||||
|
----------------------------+------------------------------------------------------
|
||||||
|
- `component` specifies the component (`fg` / `bg`) from which to extract the
|
||||||
|
color when considering each of the following highlight groups
|
||||||
|
- `group1 [, group2, ...]` is a list of highlight groups that are searched (in
|
||||||
|
order) for a matching color definition
|
||||||
|
|
||||||
|
For example, consider the following specification:
|
||||||
|
>
|
||||||
|
'prompt': ['fg', 'Conditional', 'Comment'],
|
||||||
|
<
|
||||||
|
This means we color the prompt - using the `fg` attribute of the `Conditional`
|
||||||
|
if it exists, - otherwise use the `fg` attribute of the `Comment` highlight
|
||||||
|
group if it exists, - otherwise fall back to the default color settings for
|
||||||
|
the prompt.
|
||||||
|
|
||||||
|
You can examine the color option generated according the setting by printing
|
||||||
|
the result of `fzf#wrap()` function like so:
|
||||||
|
>
|
||||||
|
:echo fzf#wrap()
|
||||||
|
<
|
||||||
|
|
||||||
|
FZF#RUN
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
For more advanced uses, you can use `fzf#run([options])` function with the
|
*fzf#run*
|
||||||
following options.
|
|
||||||
|
|
||||||
---------------------------+---------------+--------------------------------------------------------------
|
`fzf#run()` function is the core of Vim integration. It takes a single
|
||||||
|
dictionary argument, a spec, and starts fzf process accordingly. At the very
|
||||||
|
least, specify `sink` option to tell what it should do with the selected
|
||||||
|
entry.
|
||||||
|
>
|
||||||
|
call fzf#run({'sink': 'e'})
|
||||||
|
<
|
||||||
|
We haven't specified the `source`, so this is equivalent to starting fzf on
|
||||||
|
command line without standard input pipe; fzf will traverse the file system
|
||||||
|
under the current directory to get the list of files. (If
|
||||||
|
`$FZF_DEFAULT_COMMAND` is set, fzf will use the output of the command
|
||||||
|
instead.) When you select one, it will open it with the sink, `:e` command. If
|
||||||
|
you want to open it in a new tab, you can pass `:tabedit` command instead as
|
||||||
|
the sink.
|
||||||
|
>
|
||||||
|
call fzf#run({'sink': 'tabedit'})
|
||||||
|
<
|
||||||
|
You can use any shell command as the source to generate the list. The
|
||||||
|
following example will list the files managed by git. It's equivalent to
|
||||||
|
running `git ls-files | fzf` on shell.
|
||||||
|
>
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e'})
|
||||||
|
<
|
||||||
|
fzf options can be specified as `options` entry in spec dictionary.
|
||||||
|
>
|
||||||
|
call fzf#run({'sink': 'tabedit', 'options': '--multi --reverse'})
|
||||||
|
<
|
||||||
|
You can also pass a layout option if you don't want fzf window to take up the
|
||||||
|
entire screen.
|
||||||
|
>
|
||||||
|
" up / down / left / right / window are allowed
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'left': '40%'})
|
||||||
|
call fzf#run({'source': 'git ls-files', 'sink': 'e', 'window': '30vnew'})
|
||||||
|
<
|
||||||
|
`source` doesn't have to be an external shell command, you can pass a Vim
|
||||||
|
array as the source. In the next example, we pass the names of color schemes
|
||||||
|
as the source to implement a color scheme selector.
|
||||||
|
>
|
||||||
|
call fzf#run({'source': map(split(globpath(&rtp, 'colors/*.vim')),
|
||||||
|
\ 'fnamemodify(v:val, ":t:r")'),
|
||||||
|
\ 'sink': 'colo', 'left': '25%'})
|
||||||
|
<
|
||||||
|
The following table summarizes the available options.
|
||||||
|
|
||||||
|
---------------------------+---------------+----------------------------------------------------------------------
|
||||||
Option name | Type | Description ~
|
Option name | Type | Description ~
|
||||||
---------------------------+---------------+--------------------------------------------------------------
|
---------------------------+---------------+----------------------------------------------------------------------
|
||||||
`source` | string | External command to generate input to fzf (e.g. `find .` )
|
`source` | string | External command to generate input to fzf (e.g. `find .` )
|
||||||
`source` | list | Vim list as input to fzf
|
`source` | list | Vim list as input to fzf
|
||||||
`sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` )
|
`sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` )
|
||||||
`sink` | funcref | Reference to function to process each selected item
|
`sink` | funcref | Function to be called with each selected item
|
||||||
`sink*` | funcref | Similar to `sink` , but takes the list of output lines at once
|
`sinklist` (or `sink*` ) | funcref | Similar to `sink` , but takes the list of output lines at once
|
||||||
|
`exit` | funcref | Function to be called with the exit status of fzf (e.g. 0, 1, 2, 130)
|
||||||
`options` | string/list | Options to fzf
|
`options` | string/list | Options to fzf
|
||||||
`dir` | string | Working directory
|
`dir` | string | Working directory
|
||||||
`up` / `down` / `left` / `right` | number/string | Use tmux pane with the given size (e.g. `20` , `50%` )
|
`up` / `down` / `left` / `right` | number/string | (Layout) Window position and size (e.g. `20` , `50%` )
|
||||||
`window` (Vim 8 / Neovim) | string | Command to open fzf window (e.g. `vertical aboveleft 30new` )
|
`tmux` | string | (Layout) `--tmux` options (e.g. `90%,70%` )
|
||||||
`launcher` | string | External terminal emulator to start fzf with (GVim only)
|
`window` (Vim 8 / Neovim) | string | (Layout) Command to open fzf window (e.g. `vertical aboveleft 30new` )
|
||||||
`launcher` | funcref | Function for generating `launcher` string (GVim only)
|
`window` (Vim 8 / Neovim) | dict | (Layout) Popup window settings (e.g. `{'width': 0.9, 'height': 0.6}` )
|
||||||
---------------------------+---------------+--------------------------------------------------------------
|
---------------------------+---------------+----------------------------------------------------------------------
|
||||||
|
|
||||||
`options` entry can be either a string or a list. For simple cases, string
|
`options` entry can be either a string or a list. For simple cases, string
|
||||||
should suffice, but prefer to use list type if you're concerned about escaping
|
should suffice, but prefer to use list type to avoid escaping issues.
|
||||||
issues on different platforms.
|
|
||||||
>
|
>
|
||||||
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
||||||
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
||||||
<
|
<
|
||||||
|
When `window` entry is a dictionary, fzf will start in a popup window. The
|
||||||
|
following options are allowed:
|
||||||
|
|
||||||
FZF#WRAP *fzf#wrap*
|
- Required:
|
||||||
|
- `width` [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
||||||
|
- `height` [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
||||||
|
- Optional:
|
||||||
|
- `yoffset` [float default 0.5 range [0 ~ 1]]
|
||||||
|
- `xoffset` [float default 0.5 range [0 ~ 1]]
|
||||||
|
- `relative` [boolean default v:false]
|
||||||
|
- `border` [string default `rounded` (`sharp` on Windows)]: Border style
|
||||||
|
- `rounded` / `sharp` / `horizontal` / `vertical` / `top` / `bottom` / `left` / `right` / `no[ne]`
|
||||||
|
|
||||||
|
|
||||||
|
FZF#WRAP
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
*fzf#wrap*
|
||||||
function that decorates the options dictionary so that it understands
|
|
||||||
`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
|
We have seen that several aspects of `:FZF` command can be configured with a
|
||||||
`:FZF`.
|
set of global option variables; different ways to open files (`g:fzf_action`),
|
||||||
|
window position and size (`g:fzf_layout`), color palette (`g:fzf_colors`),
|
||||||
|
etc.
|
||||||
|
|
||||||
|
So how can we make our custom `fzf#run` calls also respect those variables?
|
||||||
|
Simply by "wrapping" the spec dictionary with `fzf#wrap` before passing it to
|
||||||
|
`fzf#run`.
|
||||||
|
|
||||||
|
- `fzf#wrap([name string], [spec dict], [fullscreen bool]) -> (dict)`
|
||||||
|
- All arguments are optional. Usually we only need to pass a spec
|
||||||
|
dictionary.
|
||||||
|
- `name` is for managing history files. It is ignored if `g:fzf_history_dir`
|
||||||
|
is not defined.
|
||||||
|
- `fullscreen` can be either `0` or `1` (default: 0).
|
||||||
|
|
||||||
|
`fzf#wrap` takes a spec and returns an extended version of it (also a
|
||||||
|
dictionary) with additional options for addressing global preferences. You can
|
||||||
|
examine the return value of it like so:
|
||||||
>
|
>
|
||||||
command! -bang MyStuff
|
echo fzf#wrap({'source': 'ls'})
|
||||||
\ call fzf#run(fzf#wrap('my-stuff', {'dir': '~/my-stuff'}, <bang>0))
|
<
|
||||||
|
After we "wrap" our spec, we pass it to `fzf#run`.
|
||||||
|
>
|
||||||
|
call fzf#run(fzf#wrap({'source': 'ls'}))
|
||||||
|
<
|
||||||
|
Now it supports CTRL-T, CTRL-V, and CTRL-X key bindings (configurable via
|
||||||
|
`g:fzf_action`) and it opens fzf window according to `g:fzf_layout` setting.
|
||||||
|
|
||||||
|
To make it easier to use, let's define `LS` command.
|
||||||
|
>
|
||||||
|
command! LS call fzf#run(fzf#wrap({'source': 'ls'}))
|
||||||
|
<
|
||||||
|
Type `:LS` and see how it works.
|
||||||
|
|
||||||
|
We would like to make `:LS!` (bang version) open fzf in fullscreen, just like
|
||||||
|
`:FZF!`. Add `-bang` to command definition, and use <bang> value to set the
|
||||||
|
last `fullscreen` argument of `fzf#wrap` (see :help <bang>).
|
||||||
|
>
|
||||||
|
" On :LS!, <bang> evaluates to '!', and '!0' becomes 1
|
||||||
|
command! -bang LS call fzf#run(fzf#wrap({'source': 'ls'}, <bang>0))
|
||||||
|
<
|
||||||
|
Our `:LS` command will be much more useful if we can pass a directory argument
|
||||||
|
to it, so that something like `:LS /tmp` is possible.
|
||||||
|
>
|
||||||
|
command! -bang -complete=dir -nargs=? LS
|
||||||
|
\ call fzf#run(fzf#wrap({'source': 'ls', 'dir': <q-args>}, <bang>0))
|
||||||
|
<
|
||||||
|
Lastly, if you have enabled `g:fzf_history_dir`, you might want to assign a
|
||||||
|
unique name to our command and pass it as the first argument to `fzf#wrap`.
|
||||||
|
>
|
||||||
|
" The query history for this command will be stored as 'ls' inside g:fzf_history_dir.
|
||||||
|
" The name is ignored if g:fzf_history_dir is not defined.
|
||||||
|
command! -bang -complete=dir -nargs=? LS
|
||||||
|
\ call fzf#run(fzf#wrap('ls', {'source': 'ls', 'dir': <q-args>}, <bang>0))
|
||||||
<
|
<
|
||||||
|
|
||||||
GVIM *fzf-gvim*
|
< Global options supported by fzf#wrap >______________________________________~
|
||||||
|
*fzf-global-options-supported-by-fzf#wrap*
|
||||||
|
|
||||||
|
- `g:fzf_layout`
|
||||||
|
- `g:fzf_action`
|
||||||
|
- Works only when no custom `sink` (or `sinklist`) is provided
|
||||||
|
- Having custom sink usually means that each entry is not an ordinary
|
||||||
|
file path (e.g. name of color scheme), so we can't blindly apply the
|
||||||
|
same strategy (i.e. `tabedit some-color-scheme` doesn't make sense)
|
||||||
|
- `g:fzf_colors`
|
||||||
|
- `g:fzf_history_dir`
|
||||||
|
|
||||||
|
|
||||||
|
TIPS *fzf-tips*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
With the latest version of GVim, fzf will start inside the builtin terminal
|
|
||||||
emulator of Vim. Please note that this terminal feature of Vim is still young
|
|
||||||
and unstable and you may run into some issues.
|
|
||||||
|
|
||||||
If you have an older version of GVim, you need an external terminal emulator
|
< fzf inside terminal buffer >________________________________________________~
|
||||||
to start fzf with. `xterm` command is used by default, but you can customize
|
*fzf-inside-terminal-buffer*
|
||||||
it with `g:fzf_launcher`.
|
|
||||||
|
|
||||||
|
On the latest versions of Vim and Neovim, fzf will start in a terminal buffer.
|
||||||
|
If you find the default ANSI colors to be different, consider configuring the
|
||||||
|
colors using `g:terminal_ansi_colors` in regular Vim or `g:terminal_color_x`
|
||||||
|
in Neovim.
|
||||||
|
|
||||||
>
|
>
|
||||||
" This is the default. %s is replaced with fzf command
|
" Terminal colors for seoul256 color scheme
|
||||||
let g:fzf_launcher = 'xterm -e bash -ic %s'
|
if has('nvim')
|
||||||
|
let g:terminal_color_0 = '#4e4e4e'
|
||||||
" Use urxvt instead
|
let g:terminal_color_1 = '#d68787'
|
||||||
let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s'
|
let g:terminal_color_2 = '#5f865f'
|
||||||
|
let g:terminal_color_3 = '#d8af5f'
|
||||||
|
let g:terminal_color_4 = '#85add4'
|
||||||
|
let g:terminal_color_5 = '#d7afaf'
|
||||||
|
let g:terminal_color_6 = '#87afaf'
|
||||||
|
let g:terminal_color_7 = '#d0d0d0'
|
||||||
|
let g:terminal_color_8 = '#626262'
|
||||||
|
let g:terminal_color_9 = '#d75f87'
|
||||||
|
let g:terminal_color_10 = '#87af87'
|
||||||
|
let g:terminal_color_11 = '#ffd787'
|
||||||
|
let g:terminal_color_12 = '#add4fb'
|
||||||
|
let g:terminal_color_13 = '#ffafaf'
|
||||||
|
let g:terminal_color_14 = '#87d7d7'
|
||||||
|
let g:terminal_color_15 = '#e4e4e4'
|
||||||
|
else
|
||||||
|
let g:terminal_ansi_colors = [
|
||||||
|
\ '#4e4e4e', '#d68787', '#5f865f', '#d8af5f',
|
||||||
|
\ '#85add4', '#d7afaf', '#87afaf', '#d0d0d0',
|
||||||
|
\ '#626262', '#d75f87', '#87af87', '#ffd787',
|
||||||
|
\ '#add4fb', '#ffafaf', '#87d7d7', '#e4e4e4'
|
||||||
|
\ ]
|
||||||
|
endif
|
||||||
<
|
<
|
||||||
If you're running MacVim on OSX, I recommend you to use iTerm2 as the
|
|
||||||
launcher. Refer to the {this wiki page}{3} to see how to set up.
|
|
||||||
|
|
||||||
{3} https://github.com/junegunn/fzf/wiki/On-MacVim-with-iTerm2
|
< Starting fzf in a popup window >____________________________________________~
|
||||||
|
*fzf-starting-fzf-in-a-popup-window*
|
||||||
|
>
|
||||||
|
" Required:
|
||||||
|
" - width [float range [0 ~ 1]] or [integer range [8 ~ ]]
|
||||||
|
" - height [float range [0 ~ 1]] or [integer range [4 ~ ]]
|
||||||
|
"
|
||||||
|
" Optional:
|
||||||
|
" - xoffset [float default 0.5 range [0 ~ 1]]
|
||||||
|
" - yoffset [float default 0.5 range [0 ~ 1]]
|
||||||
|
" - relative [boolean default v:false]
|
||||||
|
" - border [string default 'rounded']: Border style
|
||||||
|
" - 'rounded' / 'sharp' / 'horizontal' / 'vertical' / 'top' / 'bottom' / 'left' / 'right'
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
<
|
||||||
|
Alternatively, you can make fzf open in a tmux popup window (requires tmux 3.2
|
||||||
|
or above) by putting `--tmux` options in `tmux` key.
|
||||||
|
>
|
||||||
|
" See `--tmux` option in `man fzf` for available options
|
||||||
|
" [center|top|bottom|left|right][,SIZE[%]][,SIZE[%]]
|
||||||
|
if exists('$TMUX')
|
||||||
|
let g:fzf_layout = { 'tmux': '90%,70%' }
|
||||||
|
else
|
||||||
|
let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
endif
|
||||||
|
<
|
||||||
|
|
||||||
|
< Hide statusline >___________________________________________________________~
|
||||||
|
*fzf-hide-statusline*
|
||||||
|
|
||||||
|
When fzf starts in a terminal buffer, the file type of the buffer is set to
|
||||||
|
`fzf`. So you can set up `FileType fzf` autocmd to customize the settings of
|
||||||
|
the window.
|
||||||
|
|
||||||
|
For example, if you open fzf on the bottom on the screen (e.g. `{'down':
|
||||||
|
'40%'}`), you might want to temporarily disable the statusline for a cleaner
|
||||||
|
look.
|
||||||
|
>
|
||||||
|
let g:fzf_layout = { 'down': '30%' }
|
||||||
|
autocmd! FileType fzf
|
||||||
|
autocmd FileType fzf set laststatus=0 noshowmode noruler
|
||||||
|
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
|
||||||
|
<
|
||||||
|
|
||||||
LICENSE *fzf-license*
|
LICENSE *fzf-license*
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
||||||
|
|||||||
38
glide.lock
generated
38
glide.lock
generated
@@ -1,38 +0,0 @@
|
|||||||
hash: d68dd0bd779ac4ffca1e0c49ca38d85f90d5d68fa8e2d5d7db70a8ce8c662ec1
|
|
||||||
updated: 2017-06-01T15:48:41.653745249-07:00
|
|
||||||
imports:
|
|
||||||
- name: github.com/gdamore/encoding
|
|
||||||
version: b23993cbb6353f0e6aa98d0ee318a34728f628b9
|
|
||||||
- name: github.com/gdamore/tcell
|
|
||||||
version: 44772c121bb7838819d3ba4a7e84c0c2d617328e
|
|
||||||
subpackages:
|
|
||||||
- encoding
|
|
||||||
- name: github.com/lucasb-eyer/go-colorful
|
|
||||||
version: c900de9dbbc73129068f5af6a823068fc5f2308c
|
|
||||||
- name: github.com/mattn/go-isatty
|
|
||||||
version: 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
|
||||||
- name: github.com/mattn/go-runewidth
|
|
||||||
version: 14207d285c6c197daabb5c9793d63e7af9ab2d50
|
|
||||||
- name: github.com/mattn/go-shellwords
|
|
||||||
version: 02e3cf038dcea8290e44424da473dd12be796a8a
|
|
||||||
- name: golang.org/x/crypto
|
|
||||||
version: e1a4589e7d3ea14a3352255d04b6f1a418845e5e
|
|
||||||
subpackages:
|
|
||||||
- ssh/terminal
|
|
||||||
- name: golang.org/x/sys
|
|
||||||
version: b90f89a1e7a9c1f6b918820b3daa7f08488c8594
|
|
||||||
subpackages:
|
|
||||||
- unix
|
|
||||||
- name: golang.org/x/text
|
|
||||||
version: 4ee4af566555f5fbe026368b75596286a312663a
|
|
||||||
subpackages:
|
|
||||||
- encoding
|
|
||||||
- encoding/charmap
|
|
||||||
- encoding/internal
|
|
||||||
- encoding/internal/identifier
|
|
||||||
- encoding/japanese
|
|
||||||
- encoding/korean
|
|
||||||
- encoding/simplifiedchinese
|
|
||||||
- encoding/traditionalchinese
|
|
||||||
- transform
|
|
||||||
testImports: []
|
|
||||||
16
glide.yaml
16
glide.yaml
@@ -1,16 +0,0 @@
|
|||||||
package: github.com/junegunn/fzf
|
|
||||||
import:
|
|
||||||
- package: github.com/mattn/go-isatty
|
|
||||||
version: 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
|
||||||
- package: github.com/mattn/go-runewidth
|
|
||||||
version: 14207d285c6c197daabb5c9793d63e7af9ab2d50
|
|
||||||
- package: github.com/mattn/go-shellwords
|
|
||||||
version: 02e3cf038dcea8290e44424da473dd12be796a8a
|
|
||||||
- package: github.com/gdamore/tcell
|
|
||||||
version: 44772c121bb7838819d3ba4a7e84c0c2d617328e
|
|
||||||
subpackages:
|
|
||||||
- encoding
|
|
||||||
- package: golang.org/x/crypto
|
|
||||||
version: e1a4589e7d3ea14a3352255d04b6f1a418845e5e
|
|
||||||
subpackages:
|
|
||||||
- ssh/terminal
|
|
||||||
20
go.mod
Normal file
20
go.mod
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
module github.com/junegunn/fzf
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/charlievieth/fastwalk v1.0.8
|
||||||
|
github.com/gdamore/tcell/v2 v2.7.4
|
||||||
|
github.com/junegunn/go-shellwords v0.0.0-20240813092932-a62c48c52e97
|
||||||
|
github.com/mattn/go-isatty v0.0.20
|
||||||
|
github.com/rivo/uniseg v0.4.7
|
||||||
|
golang.org/x/sys v0.25.0
|
||||||
|
golang.org/x/term v0.24.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gdamore/encoding v1.0.0 // indirect
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||||
|
github.com/mattn/go-runewidth v0.0.15 // indirect
|
||||||
|
golang.org/x/text v0.14.0 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
go 1.20
|
||||||
57
go.sum
Normal file
57
go.sum
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
github.com/charlievieth/fastwalk v1.0.8 h1:uaoH6cAKSk73aK7aKXqs0+bL+J3Txzd3NGH8tRXgHko=
|
||||||
|
github.com/charlievieth/fastwalk v1.0.8/go.mod h1:yGy1zbxog41ZVMcKA/i8ojXLFsuayX5VvwhQVoj9PBI=
|
||||||
|
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||||
|
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
|
||||||
|
github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU=
|
||||||
|
github.com/gdamore/tcell/v2 v2.7.4/go.mod h1:dSXtXTSK0VsW1biw65DZLZ2NKr7j0qP/0J7ONmsraWg=
|
||||||
|
github.com/junegunn/go-shellwords v0.0.0-20240813092932-a62c48c52e97 h1:rqzLixVo1c/GQW6px9j1xQmlvQIn+lf/V6M1UQ7IFzw=
|
||||||
|
github.com/junegunn/go-shellwords v0.0.0-20240813092932-a62c48c52e97/go.mod h1:6EILKtGpo5t+KLb85LNZLAF6P9LKp78hJI80PXMcn3c=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
|
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||||
|
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||||
|
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
|
||||||
|
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||||
|
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||||
|
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||||
|
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||||
|
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
||||||
|
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
|
||||||
|
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
153
install
153
install
@@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
version=0.17.1
|
version=0.55.0
|
||||||
auto_completion=
|
auto_completion=
|
||||||
key_bindings=
|
key_bindings=
|
||||||
update_config=2
|
update_config=2
|
||||||
binary_arch=
|
|
||||||
allow_legacy=
|
|
||||||
shells="bash zsh fish"
|
shells="bash zsh fish"
|
||||||
|
prefix='~/.fzf'
|
||||||
|
prefix_expand=~/.fzf
|
||||||
|
fish_dir=${XDG_CONFIG_HOME:-$HOME/.config}/fish
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
@@ -18,6 +19,7 @@ usage: $0 [OPTIONS]
|
|||||||
--bin Download fzf binary only; Do not generate ~/.fzf.{bash,zsh}
|
--bin Download fzf binary only; Do not generate ~/.fzf.{bash,zsh}
|
||||||
--all Download fzf binary and update configuration files
|
--all Download fzf binary and update configuration files
|
||||||
to enable key bindings and fuzzy completion
|
to enable key bindings and fuzzy completion
|
||||||
|
--xdg Generate files under \$XDG_CONFIG_HOME/fzf
|
||||||
--[no-]key-bindings Enable/disable key bindings (CTRL-T, CTRL-R, ALT-C)
|
--[no-]key-bindings Enable/disable key bindings (CTRL-T, CTRL-R, ALT-C)
|
||||||
--[no-]completion Enable/disable fuzzy completion (bash & zsh)
|
--[no-]completion Enable/disable fuzzy completion (bash & zsh)
|
||||||
--[no-]update-rc Whether or not to update shell configuration files
|
--[no-]update-rc Whether or not to update shell configuration files
|
||||||
@@ -25,9 +27,6 @@ usage: $0 [OPTIONS]
|
|||||||
--no-bash Do not set up bash configuration
|
--no-bash Do not set up bash configuration
|
||||||
--no-zsh Do not set up zsh configuration
|
--no-zsh Do not set up zsh configuration
|
||||||
--no-fish Do not set up fish configuration
|
--no-fish Do not set up fish configuration
|
||||||
|
|
||||||
--32 Download 32-bit binary
|
|
||||||
--64 Download 64-bit binary
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +40,11 @@ for opt in "$@"; do
|
|||||||
auto_completion=1
|
auto_completion=1
|
||||||
key_bindings=1
|
key_bindings=1
|
||||||
update_config=1
|
update_config=1
|
||||||
allow_legacy=1
|
;;
|
||||||
|
--xdg)
|
||||||
|
prefix='"${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf'
|
||||||
|
prefix_expand=${XDG_CONFIG_HOME:-$HOME/.config}/fzf/fzf
|
||||||
|
mkdir -p "${XDG_CONFIG_HOME:-$HOME/.config}/fzf"
|
||||||
;;
|
;;
|
||||||
--key-bindings) key_bindings=1 ;;
|
--key-bindings) key_bindings=1 ;;
|
||||||
--no-key-bindings) key_bindings=0 ;;
|
--no-key-bindings) key_bindings=0 ;;
|
||||||
@@ -49,8 +52,6 @@ for opt in "$@"; do
|
|||||||
--no-completion) auto_completion=0 ;;
|
--no-completion) auto_completion=0 ;;
|
||||||
--update-rc) update_config=1 ;;
|
--update-rc) update_config=1 ;;
|
||||||
--no-update-rc) update_config=0 ;;
|
--no-update-rc) update_config=0 ;;
|
||||||
--32) binary_arch=386 ;;
|
|
||||||
--64) binary_arch=amd64 ;;
|
|
||||||
--bin) ;;
|
--bin) ;;
|
||||||
--no-bash) shells=${shells/bash/} ;;
|
--no-bash) shells=${shells/bash/} ;;
|
||||||
--no-zsh) shells=${shells/zsh/} ;;
|
--no-zsh) shells=${shells/zsh/} ;;
|
||||||
@@ -64,11 +65,13 @@ for opt in "$@"; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
fzf_base="$(pwd)"
|
fzf_base=$(pwd)
|
||||||
|
fzf_base_esc=$(printf %q "$fzf_base")
|
||||||
|
|
||||||
ask() {
|
ask() {
|
||||||
while true; do
|
while true; do
|
||||||
read -p "$1 ([y]/n) " -r
|
read -p "$1 ([y]/n) " -r
|
||||||
|
REPLY=${REPLY:-"y"}
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
return 1
|
return 1
|
||||||
elif [[ $REPLY =~ ^[Nn]$ ]]; then
|
elif [[ $REPLY =~ ^[Nn]$ ]]; then
|
||||||
@@ -80,11 +83,13 @@ ask() {
|
|||||||
check_binary() {
|
check_binary() {
|
||||||
echo -n " - Checking fzf executable ... "
|
echo -n " - Checking fzf executable ... "
|
||||||
local output
|
local output
|
||||||
output=$("$fzf_base"/bin/fzf --version 2>&1 | awk '{print $1}')
|
output=$("$fzf_base"/bin/fzf --version 2>&1)
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: $output"
|
echo "Error: $output"
|
||||||
binary_error="Invalid binary"
|
binary_error="Invalid binary"
|
||||||
elif [ "$version" != "$output" ]; then
|
else
|
||||||
|
output=${output/ */}
|
||||||
|
if [ "$version" != "$output" ]; then
|
||||||
echo "$output != $version"
|
echo "$output != $version"
|
||||||
binary_error="Invalid version"
|
binary_error="Invalid version"
|
||||||
else
|
else
|
||||||
@@ -92,6 +97,7 @@ check_binary() {
|
|||||||
binary_error=""
|
binary_error=""
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
rm -f "$fzf_base"/bin/fzf
|
rm -f "$fzf_base"/bin/fzf
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
@@ -99,7 +105,7 @@ check_binary() {
|
|||||||
link_fzf_in_path() {
|
link_fzf_in_path() {
|
||||||
if which_fzf="$(command -v fzf)"; then
|
if which_fzf="$(command -v fzf)"; then
|
||||||
echo " - Found in \$PATH"
|
echo " - Found in \$PATH"
|
||||||
echo " - Creating symlink: $which_fzf -> bin/fzf"
|
echo " - Creating symlink: bin/fzf -> $which_fzf"
|
||||||
(cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf)
|
(cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf)
|
||||||
check_binary && return
|
check_binary && return
|
||||||
fi
|
fi
|
||||||
@@ -108,8 +114,8 @@ link_fzf_in_path() {
|
|||||||
|
|
||||||
try_curl() {
|
try_curl() {
|
||||||
command -v curl > /dev/null &&
|
command -v curl > /dev/null &&
|
||||||
if [[ $1 =~ tgz$ ]]; then
|
if [[ $1 =~ tar.gz$ ]]; then
|
||||||
curl -fL $1 | tar -xzf -
|
curl -fL $1 | tar --no-same-owner -xzf -
|
||||||
else
|
else
|
||||||
local temp=${TMPDIR:-/tmp}/fzf.zip
|
local temp=${TMPDIR:-/tmp}/fzf.zip
|
||||||
curl -fLo "$temp" $1 && unzip -o "$temp" && rm -f "$temp"
|
curl -fLo "$temp" $1 && unzip -o "$temp" && rm -f "$temp"
|
||||||
@@ -118,8 +124,8 @@ try_curl() {
|
|||||||
|
|
||||||
try_wget() {
|
try_wget() {
|
||||||
command -v wget > /dev/null &&
|
command -v wget > /dev/null &&
|
||||||
if [[ $1 =~ tgz$ ]]; then
|
if [[ $1 =~ tar.gz$ ]]; then
|
||||||
wget -O - $1 | tar -xzf -
|
wget -O - $1 | tar --no-same-owner -xzf -
|
||||||
else
|
else
|
||||||
local temp=${TMPDIR:-/tmp}/fzf.zip
|
local temp=${TMPDIR:-/tmp}/fzf.zip
|
||||||
wget -O "$temp" $1 && unzip -o "$temp" && rm -f "$temp"
|
wget -O "$temp" $1 && unzip -o "$temp" && rm -f "$temp"
|
||||||
@@ -128,13 +134,11 @@ try_wget() {
|
|||||||
|
|
||||||
download() {
|
download() {
|
||||||
echo "Downloading bin/fzf ..."
|
echo "Downloading bin/fzf ..."
|
||||||
if [[ ! "$version" =~ alpha ]]; then
|
|
||||||
if [ -x "$fzf_base"/bin/fzf ]; then
|
if [ -x "$fzf_base"/bin/fzf ]; then
|
||||||
echo " - Already exists"
|
echo " - Already exists"
|
||||||
check_binary && return
|
check_binary && return
|
||||||
fi
|
fi
|
||||||
link_fzf_in_path && return
|
link_fzf_in_path && return
|
||||||
fi
|
|
||||||
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
|
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
binary_error="Failed to create bin directory"
|
binary_error="Failed to create bin directory"
|
||||||
@@ -142,9 +146,7 @@ download() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local url
|
local url
|
||||||
[[ "$version" =~ alpha ]] &&
|
url=https://github.com/junegunn/fzf/releases/download/v$version/${1}
|
||||||
url=https://github.com/junegunn/fzf-bin/releases/download/alpha/${1} ||
|
|
||||||
url=https://github.com/junegunn/fzf-bin/releases/download/$version/${1}
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
if ! (try_curl $url || try_wget $url); then
|
if ! (try_curl $url || try_wget $url); then
|
||||||
set +o pipefail
|
set +o pipefail
|
||||||
@@ -166,22 +168,23 @@ archi=$(uname -sm)
|
|||||||
binary_available=1
|
binary_available=1
|
||||||
binary_error=""
|
binary_error=""
|
||||||
case "$archi" in
|
case "$archi" in
|
||||||
Darwin\ *64) download fzf-$version-darwin_${binary_arch:-amd64}.tgz ;;
|
Darwin\ arm64) download fzf-$version-darwin_arm64.tar.gz ;;
|
||||||
Darwin\ *86) download fzf-$version-darwin_${binary_arch:-386}.tgz ;;
|
Darwin\ x86_64) download fzf-$version-darwin_amd64.tar.gz ;;
|
||||||
Linux\ *64) download fzf-$version-linux_${binary_arch:-amd64}.tgz ;;
|
Linux\ armv5*) download fzf-$version-linux_armv5.tar.gz ;;
|
||||||
Linux\ *86) download fzf-$version-linux_${binary_arch:-386}.tgz ;;
|
Linux\ armv6*) download fzf-$version-linux_armv6.tar.gz ;;
|
||||||
Linux\ armv5*) download fzf-$version-linux_${binary_arch:-arm5}.tgz ;;
|
Linux\ armv7*) download fzf-$version-linux_armv7.tar.gz ;;
|
||||||
Linux\ armv6*) download fzf-$version-linux_${binary_arch:-arm6}.tgz ;;
|
Linux\ armv8*) download fzf-$version-linux_arm64.tar.gz ;;
|
||||||
Linux\ armv7*) download fzf-$version-linux_${binary_arch:-arm7}.tgz ;;
|
Linux\ aarch64*) download fzf-$version-linux_arm64.tar.gz ;;
|
||||||
Linux\ armv8*) download fzf-$version-linux_${binary_arch:-arm8}.tgz ;;
|
Linux\ loongarch64) download fzf-$version-linux_loong64.tar.gz ;;
|
||||||
Linux\ aarch64*) download fzf-$version-linux_${binary_arch:-arm8}.tgz ;;
|
Linux\ ppc64le) download fzf-$version-linux_ppc64le.tar.gz ;;
|
||||||
FreeBSD\ *64) download fzf-$version-freebsd_${binary_arch:-amd64}.tgz ;;
|
Linux\ *64) download fzf-$version-linux_amd64.tar.gz ;;
|
||||||
FreeBSD\ *86) download fzf-$version-freebsd_${binary_arch:-386}.tgz ;;
|
Linux\ s390x) download fzf-$version-linux_s390x.tar.gz ;;
|
||||||
OpenBSD\ *64) download fzf-$version-openbsd_${binary_arch:-amd64}.tgz ;;
|
FreeBSD\ *64) download fzf-$version-freebsd_amd64.tar.gz ;;
|
||||||
OpenBSD\ *86) download fzf-$version-openbsd_${binary_arch:-386}.tgz ;;
|
OpenBSD\ *64) download fzf-$version-openbsd_amd64.tar.gz ;;
|
||||||
CYGWIN*\ *64) download fzf-$version-windows_${binary_arch:-amd64}.zip ;;
|
CYGWIN*\ *64) download fzf-$version-windows_amd64.zip ;;
|
||||||
MINGW*\ *86) download fzf-$version-windows_${binary_arch:-386}.zip ;;
|
MINGW*\ *64) download fzf-$version-windows_amd64.zip ;;
|
||||||
MINGW*\ *64) download fzf-$version-windows_${binary_arch:-amd64}.zip ;;
|
MSYS*\ *64) download fzf-$version-windows_amd64.zip ;;
|
||||||
|
Windows*\ *64) download fzf-$version-windows_amd64.zip ;;
|
||||||
*) binary_available=0 binary_error=1 ;;
|
*) binary_available=0 binary_error=1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -193,12 +196,12 @@ if [ -n "$binary_error" ]; then
|
|||||||
echo " - $binary_error !!!"
|
echo " - $binary_error !!!"
|
||||||
fi
|
fi
|
||||||
if command -v go > /dev/null; then
|
if command -v go > /dev/null; then
|
||||||
echo -n "Building binary (go get -u github.com/junegunn/fzf) ... "
|
echo -n "Building binary (go install github.com/junegunn/fzf) ... "
|
||||||
if [ -z "${GOPATH-}" ]; then
|
if [ -z "${GOPATH-}" ]; then
|
||||||
export GOPATH="${TMPDIR:-/tmp}/fzf-gopath"
|
export GOPATH="${TMPDIR:-/tmp}/fzf-gopath"
|
||||||
mkdir -p "$GOPATH"
|
mkdir -p "$GOPATH"
|
||||||
fi
|
fi
|
||||||
if go get -u github.com/junegunn/fzf; then
|
if go install -ldflags "-s -w -X main.version=$version -X main.revision=go-install" github.com/junegunn/fzf; then
|
||||||
echo "OK"
|
echo "OK"
|
||||||
cp "$GOPATH/bin/fzf" "$fzf_base/bin/"
|
cp "$GOPATH/bin/fzf" "$fzf_base/bin/"
|
||||||
else
|
else
|
||||||
@@ -239,10 +242,10 @@ fi
|
|||||||
echo
|
echo
|
||||||
for shell in $shells; do
|
for shell in $shells; do
|
||||||
[[ "$shell" = fish ]] && continue
|
[[ "$shell" = fish ]] && continue
|
||||||
echo -n "Generate ~/.fzf.$shell ... "
|
src=${prefix_expand}.${shell}
|
||||||
src=~/.fzf.${shell}
|
echo -n "Generate $src ... "
|
||||||
|
|
||||||
fzf_completion="[[ \$- == *i* ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
|
fzf_completion="source \"$fzf_base/shell/completion.${shell}\""
|
||||||
if [ $auto_completion -eq 0 ]; then
|
if [ $auto_completion -eq 0 ]; then
|
||||||
fzf_completion="# $fzf_completion"
|
fzf_completion="# $fzf_completion"
|
||||||
fi
|
fi
|
||||||
@@ -252,13 +255,23 @@ for shell in $shells; do
|
|||||||
fzf_key_bindings="# $fzf_key_bindings"
|
fzf_key_bindings="# $fzf_key_bindings"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat > $src << EOF
|
cat > "$src" << EOF
|
||||||
# Setup fzf
|
# Setup fzf
|
||||||
# ---------
|
# ---------
|
||||||
if [[ ! "\$PATH" == *$fzf_base/bin* ]]; then
|
if [[ ! "\$PATH" == *$fzf_base_esc/bin* ]]; then
|
||||||
export PATH="\$PATH:$fzf_base/bin"
|
PATH="\${PATH:+\${PATH}:}$fzf_base/bin"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [[ $auto_completion -eq 1 ]] && [[ $key_bindings -eq 1 ]]; then
|
||||||
|
if [[ "$shell" = zsh ]]; then
|
||||||
|
echo "source <(fzf --$shell)" >> "$src"
|
||||||
|
else
|
||||||
|
echo "eval \"\$(fzf --$shell)\"" >> "$src"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
cat >> "$src" << EOF
|
||||||
# Auto-completion
|
# Auto-completion
|
||||||
# ---------------
|
# ---------------
|
||||||
$fzf_completion
|
$fzf_completion
|
||||||
@@ -266,8 +279,8 @@ $fzf_completion
|
|||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
$fzf_key_bindings
|
$fzf_key_bindings
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
echo "OK"
|
echo "OK"
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -275,27 +288,10 @@ done
|
|||||||
if [[ "$shells" =~ fish ]]; then
|
if [[ "$shells" =~ fish ]]; then
|
||||||
echo -n "Update fish_user_paths ... "
|
echo -n "Update fish_user_paths ... "
|
||||||
fish << EOF
|
fish << EOF
|
||||||
echo \$fish_user_paths | \grep $fzf_base/bin > /dev/null
|
echo \$fish_user_paths | \grep "$fzf_base"/bin > /dev/null
|
||||||
or set --universal fish_user_paths \$fish_user_paths $fzf_base/bin
|
or set --universal fish_user_paths \$fish_user_paths "$fzf_base"/bin
|
||||||
EOF
|
EOF
|
||||||
[ $? -eq 0 ] && echo "OK" || echo "Failed"
|
[ $? -eq 0 ] && echo "OK" || echo "Failed"
|
||||||
|
|
||||||
mkdir -p ~/.config/fish/functions
|
|
||||||
if [ -e ~/.config/fish/functions/fzf.fish ]; then
|
|
||||||
echo -n "Remove unnecessary ~/.config/fish/functions/fzf.fish ... "
|
|
||||||
rm -f ~/.config/fish/functions/fzf.fish && echo "OK" || echo "Failed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
fish_binding=~/.config/fish/functions/fzf_key_bindings.fish
|
|
||||||
if [ $key_bindings -ne 0 ]; then
|
|
||||||
echo -n "Symlink $fish_binding ... "
|
|
||||||
ln -sf "$fzf_base/shell/key-bindings.fish" \
|
|
||||||
"$fish_binding" && echo "OK" || echo "Failed"
|
|
||||||
else
|
|
||||||
echo -n "Removing $fish_binding ... "
|
|
||||||
rm -f "$fish_binding"
|
|
||||||
echo "OK"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
append_line() {
|
append_line() {
|
||||||
@@ -352,24 +348,39 @@ echo
|
|||||||
for shell in $shells; do
|
for shell in $shells; do
|
||||||
[[ "$shell" = fish ]] && continue
|
[[ "$shell" = fish ]] && continue
|
||||||
[ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc
|
[ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc
|
||||||
append_line $update_config "[ -f ~/.fzf.${shell} ] && source ~/.fzf.${shell}" "$dest" "~/.fzf.${shell}"
|
append_line $update_config "[ -f ${prefix}.${shell} ] && source ${prefix}.${shell}" "$dest" "${prefix}.${shell}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then
|
if [ $key_bindings -eq 1 ] && [[ "$shells" =~ fish ]]; then
|
||||||
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
bind_file="${fish_dir}/functions/fish_user_key_bindings.fish"
|
||||||
if [ ! -e "$bind_file" ]; then
|
if [ ! -e "$bind_file" ]; then
|
||||||
|
mkdir -p "${fish_dir}/functions"
|
||||||
create_file "$bind_file" \
|
create_file "$bind_file" \
|
||||||
'function fish_user_key_bindings' \
|
'function fish_user_key_bindings' \
|
||||||
' fzf_key_bindings' \
|
' fzf --fish | source' \
|
||||||
'end'
|
'end'
|
||||||
else
|
else
|
||||||
append_line $update_config "fzf_key_bindings" "$bind_file"
|
echo "Check $bind_file:"
|
||||||
|
lno=$(\grep -nF "fzf_key_bindings" "$bind_file" | sed 's/:.*//' | tr '\n' ' ')
|
||||||
|
if [[ -n $lno ]]; then
|
||||||
|
echo " ** Found 'fzf_key_bindings' in line #$lno"
|
||||||
|
echo " ** You have to replace the line to 'fzf --fish | source'"
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo " - Clear"
|
||||||
|
echo
|
||||||
|
append_line $update_config "fzf --fish | source" "$bind_file"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $update_config -eq 1 ]; then
|
if [ $update_config -eq 1 ]; then
|
||||||
echo 'Finished. Restart your shell or reload config file.'
|
echo 'Finished. Restart your shell or reload config file.'
|
||||||
[[ "$shells" =~ bash ]] && echo ' source ~/.bashrc # bash'
|
if [[ "$shells" =~ bash ]]; then
|
||||||
|
echo -n ' source ~/.bashrc # bash'
|
||||||
|
[[ "$archi" =~ Darwin ]] && echo -n ' (.bashrc should be loaded from .bash_profile)'
|
||||||
|
echo
|
||||||
|
fi
|
||||||
[[ "$shells" =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"
|
[[ "$shells" =~ zsh ]] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"
|
||||||
[[ "$shells" =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'
|
[[ "$shells" =~ fish ]] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'
|
||||||
echo
|
echo
|
||||||
|
|||||||
65
install.ps1
Normal file
65
install.ps1
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
$version="0.55.0"
|
||||||
|
|
||||||
|
$fzf_base=Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||||
|
|
||||||
|
function check_binary () {
|
||||||
|
Write-Host " - Checking fzf executable ... " -NoNewline
|
||||||
|
$output=cmd /c $fzf_base\bin\fzf.exe --version 2>&1
|
||||||
|
if (-not $?) {
|
||||||
|
Write-Host "Error: $output"
|
||||||
|
$binary_error="Invalid binary"
|
||||||
|
} else {
|
||||||
|
$output=(-Split $output)[0]
|
||||||
|
if ($version -ne $output) {
|
||||||
|
Write-Host "$output != $version"
|
||||||
|
$binary_error="Invalid version"
|
||||||
|
} else {
|
||||||
|
Write-Host "$output"
|
||||||
|
$binary_error=""
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Remove-Item "$fzf_base\bin\fzf.exe"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
function download {
|
||||||
|
param($file)
|
||||||
|
Write-Host "Downloading bin/fzf ..."
|
||||||
|
if (Test-Path "$fzf_base\bin\fzf.exe") {
|
||||||
|
Write-Host " - Already exists"
|
||||||
|
if (check_binary) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (-not (Test-Path "$fzf_base\bin")) {
|
||||||
|
md "$fzf_base\bin"
|
||||||
|
}
|
||||||
|
if (-not $?) {
|
||||||
|
$binary_error="Failed to create bin directory"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cd "$fzf_base\bin"
|
||||||
|
$url="https://github.com/junegunn/fzf/releases/download/v$version/$file"
|
||||||
|
$temp=$env:TMP + "\fzf.zip"
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
|
if ($PSVersionTable.PSVersion.Major -ge 3) {
|
||||||
|
Invoke-WebRequest -Uri $url -OutFile $temp
|
||||||
|
} else {
|
||||||
|
(New-Object Net.WebClient).DownloadFile($url, $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath("$temp"))
|
||||||
|
}
|
||||||
|
if ($?) {
|
||||||
|
(Microsoft.PowerShell.Archive\Expand-Archive -Path $temp -DestinationPath .); (Remove-Item $temp)
|
||||||
|
} else {
|
||||||
|
$binary_error="Failed to download with powershell"
|
||||||
|
}
|
||||||
|
if (-not (Test-Path fzf.exe)) {
|
||||||
|
$binary_error="Failed to download $file"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
echo y | icacls $fzf_base\bin\fzf.exe /grant Administrator:F ; check_binary >$null
|
||||||
|
}
|
||||||
|
|
||||||
|
download "fzf-$version-windows_amd64.zip"
|
||||||
|
|
||||||
|
Write-Host 'For more information, see: https://github.com/junegunn/fzf'
|
||||||
98
main.go
98
main.go
@@ -1,9 +1,101 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/junegunn/fzf/src"
|
import (
|
||||||
|
_ "embed"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
var revision string
|
fzf "github.com/junegunn/fzf/src"
|
||||||
|
"github.com/junegunn/fzf/src/protector"
|
||||||
|
)
|
||||||
|
|
||||||
|
var version = "0.55"
|
||||||
|
var revision = "devel"
|
||||||
|
|
||||||
|
//go:embed shell/key-bindings.bash
|
||||||
|
var bashKeyBindings []byte
|
||||||
|
|
||||||
|
//go:embed shell/completion.bash
|
||||||
|
var bashCompletion []byte
|
||||||
|
|
||||||
|
//go:embed shell/key-bindings.zsh
|
||||||
|
var zshKeyBindings []byte
|
||||||
|
|
||||||
|
//go:embed shell/completion.zsh
|
||||||
|
var zshCompletion []byte
|
||||||
|
|
||||||
|
//go:embed shell/key-bindings.fish
|
||||||
|
var fishKeyBindings []byte
|
||||||
|
|
||||||
|
//go:embed man/man1/fzf.1
|
||||||
|
var manPage []byte
|
||||||
|
|
||||||
|
func printScript(label string, content []byte) {
|
||||||
|
fmt.Println("### " + label + " ###")
|
||||||
|
fmt.Println(strings.TrimSpace(string(content)))
|
||||||
|
fmt.Println("### end: " + label + " ###")
|
||||||
|
}
|
||||||
|
|
||||||
|
func exit(code int, err error) {
|
||||||
|
if code == fzf.ExitError && err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, err.Error())
|
||||||
|
}
|
||||||
|
os.Exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fzf.Run(fzf.ParseOptions(), revision)
|
protector.Protect()
|
||||||
|
|
||||||
|
options, err := fzf.ParseOptions(true, os.Args[1:])
|
||||||
|
if err != nil {
|
||||||
|
exit(fzf.ExitError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Bash {
|
||||||
|
printScript("key-bindings.bash", bashKeyBindings)
|
||||||
|
printScript("completion.bash", bashCompletion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Zsh {
|
||||||
|
printScript("key-bindings.zsh", zshKeyBindings)
|
||||||
|
printScript("completion.zsh", zshCompletion)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Fish {
|
||||||
|
printScript("key-bindings.fish", fishKeyBindings)
|
||||||
|
fmt.Println("fzf_key_bindings")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Help {
|
||||||
|
fmt.Print(fzf.Usage)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Version {
|
||||||
|
if len(revision) > 0 {
|
||||||
|
fmt.Printf("%s (%s)\n", version, revision)
|
||||||
|
} else {
|
||||||
|
fmt.Println(version)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if options.Man {
|
||||||
|
file := fzf.WriteTemporaryFile([]string{string(manPage)}, "\n")
|
||||||
|
if len(file) == 0 {
|
||||||
|
fmt.Print(string(manPage))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer os.Remove(file)
|
||||||
|
cmd := exec.Command("man", file)
|
||||||
|
cmd.Stdin = os.Stdin
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
fmt.Print(string(manPage))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
code, err := fzf.Run(options)
|
||||||
|
exit(code, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
.ig
|
.ig
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -21,34 +21,48 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf-tmux 1 "Oct 2017" "fzf 0.17.1" "fzf-tmux - open fzf in tmux split pane"
|
.TH fzf\-tmux 1 "Aug 2024" "fzf 0.55.0" "fzf\-tmux - open fzf in tmux split pane"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf-tmux - open fzf in tmux split pane
|
fzf\-tmux - open fzf in tmux split pane
|
||||||
|
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.B fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
.B fzf\-tmux [\fILAYOUT OPTIONS\fR] [\-\-] [\fIFZF OPTIONS\fR]
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
fzf-tmux is a wrapper script for fzf that opens fzf in a tmux split pane. It is
|
fzf\-tmux is a wrapper script for fzf that opens fzf in a tmux split pane or in
|
||||||
designed to work just like fzf except that it does not take up the whole
|
a tmux popup window. It is designed to work just like fzf except that it does
|
||||||
screen. You can safely use fzf-tmux instead of fzf in your scripts as the extra
|
not take up the whole screen. You can safely use fzf\-tmux instead of fzf in
|
||||||
options will be silently ignored if you're not on tmux.
|
your scripts as the extra options will be silently ignored if you're not on
|
||||||
|
tmux.
|
||||||
|
|
||||||
.SH OPTIONS
|
.SH LAYOUT OPTIONS
|
||||||
.SS Layout
|
|
||||||
|
|
||||||
(default: \fB-d 50%\fR)
|
(default layout: \fB\-d 50%\fR)
|
||||||
|
|
||||||
|
.SS Popup window
|
||||||
|
(requires tmux 3.2 or above)
|
||||||
.TP
|
.TP
|
||||||
.B "-u [height[%]]"
|
.B "\-p [WIDTH[%][,HEIGHT[%]]]"
|
||||||
|
.TP
|
||||||
|
.B "\-w WIDTH[%]"
|
||||||
|
.TP
|
||||||
|
.B "\-h WIDTH[%]"
|
||||||
|
.TP
|
||||||
|
.B "\-x COL"
|
||||||
|
.TP
|
||||||
|
.B "\-y ROW"
|
||||||
|
|
||||||
|
.SS Split pane
|
||||||
|
.TP
|
||||||
|
.B "\-u [height[%]]"
|
||||||
Split above (up)
|
Split above (up)
|
||||||
.TP
|
.TP
|
||||||
.B "-d [height[%]]"
|
.B "\-d [height[%]]"
|
||||||
Split below (down)
|
Split below (down)
|
||||||
.TP
|
.TP
|
||||||
.B "-l [width[%]]"
|
.B "\-l [width[%]]"
|
||||||
Split left
|
Split left
|
||||||
.TP
|
.TP
|
||||||
.B "-r [width[%]]"
|
.B "\-r [width[%]]"
|
||||||
Split right
|
Split right
|
||||||
|
|||||||
1591
man/man1/fzf.1
1591
man/man1/fzf.1
File diff suppressed because it is too large
Load Diff
611
plugin/fzf.vim
611
plugin/fzf.vim
@@ -1,4 +1,4 @@
|
|||||||
" Copyright (c) 2017 Junegunn Choi
|
" Copyright (c) 2013-2024 Junegunn Choi
|
||||||
"
|
"
|
||||||
" MIT License
|
" MIT License
|
||||||
"
|
"
|
||||||
@@ -49,10 +49,20 @@ if s:is_win
|
|||||||
|
|
||||||
" Use utf-8 for fzf.vim commands
|
" Use utf-8 for fzf.vim commands
|
||||||
" Return array of shell commands for cmd.exe
|
" Return array of shell commands for cmd.exe
|
||||||
|
function! s:enc_to_cp(str)
|
||||||
|
if !has('iconv')
|
||||||
|
return a:str
|
||||||
|
endif
|
||||||
|
if !exists('s:codepage')
|
||||||
|
let s:codepage = libcallnr('kernel32.dll', 'GetACP', 0)
|
||||||
|
endif
|
||||||
|
return iconv(a:str, &encoding, 'cp'.s:codepage)
|
||||||
|
endfunction
|
||||||
function! s:wrap_cmds(cmds)
|
function! s:wrap_cmds(cmds)
|
||||||
return ['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +
|
return map(['@echo off']
|
||||||
\ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +
|
\ + (has('gui_running') ? ['set TERM= > nul'] : [])
|
||||||
\ ['chcp %origchcp% > nul']
|
\ + (type(a:cmds) == type([]) ? a:cmds : [a:cmds]),
|
||||||
|
\ '<SID>enc_to_cp(v:val."\r")')
|
||||||
endfunction
|
endfunction
|
||||||
else
|
else
|
||||||
let s:term_marker = ";#FZF"
|
let s:term_marker = ";#FZF"
|
||||||
@@ -64,22 +74,41 @@ else
|
|||||||
function! s:wrap_cmds(cmds)
|
function! s:wrap_cmds(cmds)
|
||||||
return a:cmds
|
return a:cmds
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:enc_to_cp(str)
|
||||||
|
return a:str
|
||||||
|
endfunction
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:shellesc_cmd(arg)
|
function! s:shellesc_cmd(arg)
|
||||||
let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')
|
let e = '"'
|
||||||
let escaped = substitute(escaped, '%', '%%', 'g')
|
let slashes = 0
|
||||||
let escaped = substitute(escaped, '"', '\\^&', 'g')
|
for c in split(a:arg, '\zs')
|
||||||
let escaped = substitute(escaped, '\(\\\+\)\(\\^\)', '\1\1\2', 'g')
|
if c ==# '\'
|
||||||
return '^"'.substitute(escaped, '\(\\\+\)$', '\1\1', '').'^"'
|
let slashes += 1
|
||||||
|
elseif c ==# '"'
|
||||||
|
let e .= repeat('\', slashes + 1)
|
||||||
|
let slashes = 0
|
||||||
|
else
|
||||||
|
let slashes = 0
|
||||||
|
endif
|
||||||
|
let e .= c
|
||||||
|
endfor
|
||||||
|
let e .= repeat('\', slashes) .'"'
|
||||||
|
return substitute(substitute(e, '[&|<>()^!"]', '^&', 'g'), '%', '%%', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#shellescape(arg, ...)
|
function! fzf#shellescape(arg, ...)
|
||||||
let shell = get(a:000, 0, &shell)
|
let shell = get(a:000, 0, s:is_win ? 'cmd.exe' : 'sh')
|
||||||
if shell =~# 'cmd.exe$'
|
if shell =~# 'cmd.exe$'
|
||||||
return s:shellesc_cmd(a:arg)
|
return s:shellesc_cmd(a:arg)
|
||||||
endif
|
endif
|
||||||
|
try
|
||||||
|
let [shell, &shell] = [&shell, shell]
|
||||||
return s:fzf_call('shellescape', a:arg)
|
return s:fzf_call('shellescape', a:arg)
|
||||||
|
finally
|
||||||
|
let [shell, &shell] = [&shell, shell]
|
||||||
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:fzf_getcwd()
|
function! s:fzf_getcwd()
|
||||||
@@ -98,45 +127,136 @@ function! s:fzf_tempname()
|
|||||||
return s:fzf_call('tempname')
|
return s:fzf_call('tempname')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:default_layout = { 'down': '~40%' }
|
let s:layout_keys = ['window', 'tmux', 'up', 'down', 'left', 'right']
|
||||||
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
|
||||||
let s:fzf_go = s:base_dir.'/bin/fzf'
|
let s:fzf_go = s:base_dir.'/bin/fzf'
|
||||||
let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'
|
let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'
|
||||||
let s:install = s:base_dir.'/install'
|
|
||||||
let s:installed = 0
|
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
|
|
||||||
function! s:fzf_exec()
|
function! s:popup_support()
|
||||||
|
return has('nvim') ? has('nvim-0.4') : has('popupwin') && has('patch-8.2.191')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:default_layout()
|
||||||
|
return s:popup_support()
|
||||||
|
\ ? { 'window' : { 'width': 0.9, 'height': 0.6 } }
|
||||||
|
\ : { 'down': '~40%' }
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! fzf#install()
|
||||||
|
if s:is_win && !has('win32unix')
|
||||||
|
let script = s:base_dir.'/install.ps1'
|
||||||
|
if !filereadable(script)
|
||||||
|
throw script.' not found'
|
||||||
|
endif
|
||||||
|
let script = 'powershell -ExecutionPolicy Bypass -file ' . shellescape(script)
|
||||||
|
else
|
||||||
|
let script = s:base_dir.'/install'
|
||||||
|
if !executable(script)
|
||||||
|
throw script.' not found'
|
||||||
|
endif
|
||||||
|
let script .= ' --bin'
|
||||||
|
endif
|
||||||
|
|
||||||
|
call s:warn('Running fzf installer ...')
|
||||||
|
call system(script)
|
||||||
|
if v:shell_error
|
||||||
|
throw 'Failed to download fzf: '.script
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:versions = {}
|
||||||
|
function s:get_version(bin)
|
||||||
|
if has_key(s:versions, a:bin)
|
||||||
|
return s:versions[a:bin]
|
||||||
|
end
|
||||||
|
let command = (&shell =~ 'powershell\|pwsh' ? '&' : '') . s:fzf_call('shellescape', a:bin) . ' --version --no-height'
|
||||||
|
let output = systemlist(command)
|
||||||
|
if v:shell_error || empty(output)
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let ver = matchstr(output[-1], '[0-9.]\+')
|
||||||
|
let s:versions[a:bin] = ver
|
||||||
|
return ver
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:compare_versions(a, b)
|
||||||
|
let a = split(a:a, '\.')
|
||||||
|
let b = split(a:b, '\.')
|
||||||
|
for idx in range(0, max([len(a), len(b)]) - 1)
|
||||||
|
let v1 = str2nr(get(a, idx, 0))
|
||||||
|
let v2 = str2nr(get(b, idx, 0))
|
||||||
|
if v1 < v2 | return -1
|
||||||
|
elseif v1 > v2 | return 1
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:compare_binary_versions(a, b)
|
||||||
|
return s:compare_versions(s:get_version(a:a), s:get_version(a:b))
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:min_version = '0.53.0'
|
||||||
|
let s:checked = {}
|
||||||
|
function! fzf#exec(...)
|
||||||
if !exists('s:exec')
|
if !exists('s:exec')
|
||||||
|
let binaries = []
|
||||||
|
if executable('fzf')
|
||||||
|
call add(binaries, 'fzf')
|
||||||
|
endif
|
||||||
if executable(s:fzf_go)
|
if executable(s:fzf_go)
|
||||||
let s:exec = s:fzf_go
|
call add(binaries, s:fzf_go)
|
||||||
elseif executable('fzf')
|
endif
|
||||||
let s:exec = 'fzf'
|
|
||||||
elseif s:is_win && !has('win32unix')
|
if empty(binaries)
|
||||||
call s:warn('fzf executable not found.')
|
if input('fzf executable not found. Download binary? (y/n) ') =~? '^y'
|
||||||
call s:warn('Download fzf binary for Windows from https://github.com/junegunn/fzf-bin/releases/')
|
|
||||||
call s:warn('and place it as '.s:base_dir.'\bin\fzf.exe')
|
|
||||||
throw 'fzf executable not found'
|
|
||||||
elseif !s:installed && executable(s:install) &&
|
|
||||||
\ input('fzf executable not found. Download binary? (y/n) ') =~? '^y'
|
|
||||||
redraw
|
redraw
|
||||||
echo
|
call fzf#install()
|
||||||
call s:warn('Downloading fzf binary. Please wait ...')
|
return fzf#exec()
|
||||||
let s:installed = 1
|
|
||||||
call system(s:install.' --bin')
|
|
||||||
return s:fzf_exec()
|
|
||||||
else
|
else
|
||||||
redraw
|
redraw
|
||||||
throw 'fzf executable not found'
|
throw 'fzf executable not found'
|
||||||
endif
|
endif
|
||||||
|
elseif len(binaries) > 1
|
||||||
|
call sort(binaries, 's:compare_binary_versions')
|
||||||
endif
|
endif
|
||||||
return fzf#shellescape(s:exec)
|
|
||||||
|
let s:exec = binaries[-1]
|
||||||
|
endif
|
||||||
|
|
||||||
|
let min_version = s:min_version
|
||||||
|
if a:0 && s:compare_versions(a:1, min_version) > 0
|
||||||
|
let min_version = a:1
|
||||||
|
endif
|
||||||
|
if !has_key(s:checked, min_version)
|
||||||
|
let fzf_version = s:get_version(s:exec)
|
||||||
|
if empty(fzf_version)
|
||||||
|
let message = printf('Failed to run "%s --version"', s:exec)
|
||||||
|
unlet s:exec
|
||||||
|
throw message
|
||||||
|
end
|
||||||
|
|
||||||
|
if s:compare_versions(fzf_version, min_version) >= 0
|
||||||
|
let s:checked[min_version] = 1
|
||||||
|
return s:exec
|
||||||
|
elseif a:0 < 2 && input(printf('You need fzf %s or above. Found: %s. Download binary? (y/n) ', min_version, fzf_version)) =~? '^y'
|
||||||
|
let s:versions = {}
|
||||||
|
unlet s:exec
|
||||||
|
redraw
|
||||||
|
call fzf#install()
|
||||||
|
return fzf#exec(min_version, 1)
|
||||||
|
else
|
||||||
|
throw printf('You need to upgrade fzf (required: %s or above)', min_version)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
return s:exec
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tmux_enabled()
|
function! s:tmux_enabled()
|
||||||
if has('gui_running')
|
if has('gui_running') || !exists('$TMUX')
|
||||||
return 0
|
return 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -145,10 +265,16 @@ function! s:tmux_enabled()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let s:tmux = 0
|
let s:tmux = 0
|
||||||
if exists('$TMUX') && executable(s:fzf_tmux)
|
if !executable(s:fzf_tmux)
|
||||||
|
if executable('fzf-tmux')
|
||||||
|
let s:fzf_tmux = 'fzf-tmux'
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
let output = system('tmux -V')
|
let output = system('tmux -V')
|
||||||
let s:tmux = !v:shell_error && output >= 'tmux 1.7'
|
let s:tmux = !v:shell_error && output >= 'tmux 1.7'
|
||||||
endif
|
|
||||||
return s:tmux
|
return s:tmux
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -157,21 +283,6 @@ function! s:escape(path)
|
|||||||
return s:is_win ? escape(path, '$') : path
|
return s:is_win ? escape(path, '$') : path
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Upgrade legacy options
|
|
||||||
function! s:upgrade(dict)
|
|
||||||
let copy = copy(a:dict)
|
|
||||||
if has_key(copy, 'tmux')
|
|
||||||
let copy.down = remove(copy, 'tmux')
|
|
||||||
endif
|
|
||||||
if has_key(copy, 'tmux_height')
|
|
||||||
let copy.down = remove(copy, 'tmux_height')
|
|
||||||
endif
|
|
||||||
if has_key(copy, 'tmux_width')
|
|
||||||
let copy.right = remove(copy, 'tmux_width')
|
|
||||||
endif
|
|
||||||
return copy
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:error(msg)
|
function! s:error(msg)
|
||||||
echohl ErrorMsg
|
echohl ErrorMsg
|
||||||
echom a:msg
|
echom a:msg
|
||||||
@@ -217,9 +328,17 @@ function! s:common_sink(action, lines) abort
|
|||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified
|
let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified
|
||||||
let autochdir = &autochdir
|
" Preserve the current working directory in case it's changed during
|
||||||
set noautochdir
|
" the execution (e.g. `set autochdir` or `autocmd BufEnter * lcd ...`)
|
||||||
|
let cwd = exists('w:fzf_pushd') ? w:fzf_pushd.dir : expand('%:p:h')
|
||||||
for item in a:lines
|
for item in a:lines
|
||||||
|
if has('win32unix') && item !~ '/'
|
||||||
|
let item = substitute(item, '\', '/', 'g')
|
||||||
|
end
|
||||||
|
if item[0] != '~' && item !~ (s:is_win ? '^\([A-Z]:\)\?\' : '^/')
|
||||||
|
let sep = s:is_win ? '\' : '/'
|
||||||
|
let item = join([cwd, item], cwd[len(cwd)-1] == sep ? '' : sep)
|
||||||
|
endif
|
||||||
if empty
|
if empty
|
||||||
execute 'e' s:escape(item)
|
execute 'e' s:escape(item)
|
||||||
let empty = 0
|
let empty = 0
|
||||||
@@ -231,14 +350,15 @@ function! s:common_sink(action, lines) abort
|
|||||||
doautocmd BufEnter
|
doautocmd BufEnter
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
catch /^Vim:Interrupt$/
|
||||||
finally
|
finally
|
||||||
let &autochdir = autochdir
|
|
||||||
silent! autocmd! fzf_swap
|
silent! autocmd! fzf_swap
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:get_color(attr, ...)
|
function! s:get_color(attr, ...)
|
||||||
let gui = has('termguicolors') && &termguicolors
|
" Force 24 bit colors: g:fzf_force_termguicolors (temporary workaround for https://github.com/junegunn/fzf.vim/issues/1152)
|
||||||
|
let gui = get(g:, 'fzf_force_termguicolors', 0) || (!s:is_win && !has('win32unix') && has('termguicolors') && &termguicolors)
|
||||||
let fam = gui ? 'gui' : 'cterm'
|
let fam = gui ? 'gui' : 'cterm'
|
||||||
let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'
|
let pat = gui ? '^#[a-f0-9]\+' : '^[0-9]\+$'
|
||||||
for group in a:000
|
for group in a:000
|
||||||
@@ -253,7 +373,7 @@ endfunction
|
|||||||
function! s:defaults()
|
function! s:defaults()
|
||||||
let rules = copy(get(g:, 'fzf_colors', {}))
|
let rules = copy(get(g:, 'fzf_colors', {}))
|
||||||
let colors = join(map(items(filter(map(rules, 'call("s:get_color", v:val)'), '!empty(v:val)')), 'join(v:val, ":")'), ',')
|
let colors = join(map(items(filter(map(rules, 'call("s:get_color", v:val)'), '!empty(v:val)')), 'join(v:val, ":")'), ',')
|
||||||
return empty(colors) ? '' : ('--color='.colors)
|
return empty(colors) ? '' : fzf#shellescape('--color='.colors)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:validate_layout(layout)
|
function! s:validate_layout(layout)
|
||||||
@@ -277,7 +397,7 @@ function! fzf#wrap(...)
|
|||||||
let expects = map(copy(args), 'type(v:val)')
|
let expects = map(copy(args), 'type(v:val)')
|
||||||
let tidx = 0
|
let tidx = 0
|
||||||
for arg in copy(a:000)
|
for arg in copy(a:000)
|
||||||
let tidx = index(expects, type(arg), tidx)
|
let tidx = index(expects, type(arg) == 6 ? type(0) : type(arg), tidx)
|
||||||
if tidx < 0
|
if tidx < 0
|
||||||
throw 'Invalid arguments (expected: [name string] [opts dict] [fullscreen boolean])'
|
throw 'Invalid arguments (expected: [name string] [opts dict] [fullscreen boolean])'
|
||||||
endif
|
endif
|
||||||
@@ -302,7 +422,7 @@ function! fzf#wrap(...)
|
|||||||
if !exists('g:fzf_layout') && exists('g:fzf_height')
|
if !exists('g:fzf_layout') && exists('g:fzf_height')
|
||||||
let opts.down = g:fzf_height
|
let opts.down = g:fzf_height
|
||||||
else
|
else
|
||||||
let opts = extend(opts, s:validate_layout(get(g:, 'fzf_layout', s:default_layout)))
|
let opts = extend(opts, s:validate_layout(get(g:, 'fzf_layout', s:default_layout())))
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@@ -320,55 +440,83 @@ function! fzf#wrap(...)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Action: g:fzf_action
|
" Action: g:fzf_action
|
||||||
if !s:has_any(opts, ['sink', 'sink*'])
|
if !s:has_any(opts, ['sink', 'sinklist', 'sink*'])
|
||||||
let opts._action = get(g:, 'fzf_action', s:default_action)
|
let opts._action = get(g:, 'fzf_action', s:default_action)
|
||||||
let opts.options .= ' --expect='.join(keys(opts._action), ',')
|
let opts.options .= ' --expect='.join(keys(opts._action), ',')
|
||||||
function! opts.sink(lines) abort
|
function! opts.sinklist(lines) abort
|
||||||
return s:common_sink(self._action, a:lines)
|
return s:common_sink(self._action, a:lines)
|
||||||
endfunction
|
endfunction
|
||||||
let opts['sink*'] = remove(opts, 'sink')
|
let opts['sink*'] = opts.sinklist " For backward compatibility
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:use_sh()
|
function! s:use_sh()
|
||||||
let [shell, shellslash] = [&shell, &shellslash]
|
let [shell, shellslash, shellcmdflag, shellxquote] = [&shell, &shellslash, &shellcmdflag, &shellxquote]
|
||||||
if s:is_win
|
if s:is_win
|
||||||
set shell=cmd.exe
|
set shell=cmd.exe
|
||||||
set noshellslash
|
set noshellslash
|
||||||
|
let &shellcmdflag = has('nvim') ? '/s /c' : '/c'
|
||||||
|
let &shellxquote = has('nvim') ? '"' : '('
|
||||||
else
|
else
|
||||||
set shell=sh
|
set shell=sh
|
||||||
endif
|
endif
|
||||||
return [shell, shellslash]
|
return [shell, shellslash, shellcmdflag, shellxquote]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:writefile(...)
|
||||||
|
if call('writefile', a:000) == -1
|
||||||
|
throw 'Failed to write temporary file. Check if you can write to the path tempname() returns.'
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:extract_option(opts, name)
|
||||||
|
let opt = ''
|
||||||
|
let expect = 0
|
||||||
|
" There are a few cases where this function doesn't work as expected.
|
||||||
|
" Let's just assume such cases are extremely unlikely in real world.
|
||||||
|
" e.g. --query --border
|
||||||
|
for word in split(a:opts)
|
||||||
|
if expect && word !~ '^"\=-'
|
||||||
|
let opt = opt . ' ' . word
|
||||||
|
let expect = 0
|
||||||
|
elseif word == '--no-'.a:name
|
||||||
|
let opt = ''
|
||||||
|
elseif word =~ '^--'.a:name.'='
|
||||||
|
let opt = word
|
||||||
|
elseif word =~ '^--'.a:name.'$'
|
||||||
|
let opt = word
|
||||||
|
let expect = 1
|
||||||
|
elseif expect
|
||||||
|
let expect = 0
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return opt
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
let s:need_cmd_window = has('win32unix') && $TERM_PROGRAM ==# 'mintty' && s:compare_versions($TERM_PROGRAM_VERSION, '3.4.5') < 0 && !executable('winpty')
|
||||||
|
|
||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
try
|
try
|
||||||
let [shell, shellslash] = s:use_sh()
|
let [shell, shellslash, shellcmdflag, shellxquote] = s:use_sh()
|
||||||
|
|
||||||
let dict = exists('a:1') ? s:upgrade(a:1) : {}
|
let dict = exists('a:1') ? copy(a:1) : {}
|
||||||
let temps = { 'result': s:fzf_tempname() }
|
let temps = { 'result': s:fzf_tempname() }
|
||||||
let optstr = s:evaluate_opts(get(dict, 'options', ''))
|
let optstr = s:evaluate_opts(get(dict, 'options', ''))
|
||||||
try
|
try
|
||||||
let fzf_exec = s:fzf_exec()
|
let fzf_exec = shellescape(fzf#exec())
|
||||||
catch
|
catch
|
||||||
throw v:exception
|
throw v:exception
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
if has('nvim') && !has_key(dict, 'dir')
|
if !s:present(dict, 'dir')
|
||||||
let dict.dir = s:fzf_getcwd()
|
let dict.dir = s:fzf_getcwd()
|
||||||
endif
|
endif
|
||||||
if has('win32unix') && has_key(dict, 'dir')
|
if has('win32unix') && s:present(dict, 'dir')
|
||||||
let dict.dir = fnamemodify(dict.dir, ':p')
|
let dict.dir = fnamemodify(dict.dir, ':p')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND) && !s:is_win
|
|
||||||
let temps.source = s:fzf_tempname()
|
|
||||||
call writefile(s:wrap_cmds(split($FZF_DEFAULT_COMMAND, "\n")), temps.source)
|
|
||||||
let dict.source = (empty($SHELL) ? &shell : $SHELL).' '.fzf#shellescape(temps.source)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if has_key(dict, 'source')
|
if has_key(dict, 'source')
|
||||||
let source = dict.source
|
let source = dict.source
|
||||||
let type = type(source)
|
let type = type(source)
|
||||||
@@ -376,8 +524,8 @@ try
|
|||||||
let prefix = '('.source.')|'
|
let prefix = '('.source.')|'
|
||||||
elseif type == 3
|
elseif type == 3
|
||||||
let temps.input = s:fzf_tempname()
|
let temps.input = s:fzf_tempname()
|
||||||
call writefile(source, temps.input)
|
call s:writefile(source, temps.input)
|
||||||
let prefix = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input).'|'
|
let prefix = (s:is_win ? 'type ' : 'command cat ').fzf#shellescape(temps.input).'|'
|
||||||
else
|
else
|
||||||
throw 'Invalid source type'
|
throw 'Invalid source type'
|
||||||
endif
|
endif
|
||||||
@@ -385,25 +533,28 @@ try
|
|||||||
let prefix = ''
|
let prefix = ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)
|
let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0) || has_key(dict, 'tmux')
|
||||||
let use_height = has_key(dict, 'down') && !has('gui_running') &&
|
let use_height = has_key(dict, 'down') && !has('gui_running') &&
|
||||||
\ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right', 'window')) &&
|
\ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right', 'window')) &&
|
||||||
\ executable('tput') && filereadable('/dev/tty')
|
\ executable('tput') && filereadable('/dev/tty')
|
||||||
let has_vim8_term = has('terminal') && has('patch-8.0.995')
|
let has_vim8_term = has('terminal') && has('patch-8.0.995')
|
||||||
let has_nvim_term = has('nvim-0.2.1') || has('nvim') && !s:is_win
|
let has_nvim_term = has('nvim-0.2.1') || has('nvim') && !s:is_win
|
||||||
let use_term = has_nvim_term ||
|
let use_term = has_nvim_term || has_vim8_term
|
||||||
\ has_vim8_term && (has('gui_running') || s:is_win || !use_height && s:present(dict, 'down', 'up', 'left', 'right', 'window'))
|
\ && !s:need_cmd_window
|
||||||
let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)
|
\ && (has('gui_running') || s:is_win || s:present(dict, 'down', 'up', 'left', 'right', 'window'))
|
||||||
|
let use_tmux = (has_key(dict, 'tmux') || (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:splittable(dict)) && s:tmux_enabled()
|
||||||
if prefer_tmux && use_tmux
|
if prefer_tmux && use_tmux
|
||||||
let use_height = 0
|
let use_height = 0
|
||||||
let use_term = 0
|
let use_term = 0
|
||||||
endif
|
endif
|
||||||
if use_height
|
if use_term
|
||||||
|
let optstr .= ' --no-height --no-tmux'
|
||||||
|
elseif use_height
|
||||||
let height = s:calc_size(&lines, dict.down, dict)
|
let height = s:calc_size(&lines, dict.down, dict)
|
||||||
let optstr .= ' --height='.height
|
let optstr .= ' --no-tmux --height='.height
|
||||||
elseif use_term
|
|
||||||
let optstr .= ' --no-height'
|
|
||||||
endif
|
endif
|
||||||
|
" Respect --border option given in $FZF_DEFAULT_OPTS and 'options'
|
||||||
|
let optstr = join([s:border_opt(get(dict, 'window', 0)), s:extract_option($FZF_DEFAULT_OPTS, 'border'), optstr])
|
||||||
let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result
|
let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result
|
||||||
|
|
||||||
if use_term
|
if use_term
|
||||||
@@ -415,7 +566,7 @@ try
|
|||||||
call s:callback(dict, lines)
|
call s:callback(dict, lines)
|
||||||
return lines
|
return lines
|
||||||
finally
|
finally
|
||||||
let [&shell, &shellslash] = [shell, shellslash]
|
let [&shell, &shellslash, &shellcmdflag, &shellxquote] = [shell, shellslash, shellcmdflag, shellxquote]
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -429,21 +580,25 @@ function! s:present(dict, ...)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:fzf_tmux(dict)
|
function! s:fzf_tmux(dict)
|
||||||
let size = ''
|
let size = get(a:dict, 'tmux', '')
|
||||||
|
if empty(size)
|
||||||
for o in ['up', 'down', 'left', 'right']
|
for o in ['up', 'down', 'left', 'right']
|
||||||
if s:present(a:dict, o)
|
if s:present(a:dict, o)
|
||||||
let spec = a:dict[o]
|
let size = o . ',' . a:dict[o]
|
||||||
if (o == 'up' || o == 'down') && spec[0] == '~'
|
|
||||||
let size = '-'.o[0].s:calc_size(&lines, spec, a:dict)
|
|
||||||
else
|
|
||||||
" Legacy boolean option
|
|
||||||
let size = '-'.o[0].(spec == 1 ? '' : substitute(spec, '^\~', '', ''))
|
|
||||||
endif
|
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Legacy fzf-tmux options
|
||||||
|
if size =~ '-'
|
||||||
return printf('LINES=%d COLUMNS=%d %s %s %s --',
|
return printf('LINES=%d COLUMNS=%d %s %s %s --',
|
||||||
\ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))
|
\ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))
|
||||||
|
end
|
||||||
|
|
||||||
|
" Using native --tmux option
|
||||||
|
let in = (has_key(a:dict, 'source') ? '' : ' --force-tty-in')
|
||||||
|
return printf('%s --tmux %s%s', fzf#shellescape(fzf#exec()), size, in)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:splittable(dict)
|
function! s:splittable(dict)
|
||||||
@@ -454,15 +609,18 @@ endfunction
|
|||||||
function! s:pushd(dict)
|
function! s:pushd(dict)
|
||||||
if s:present(a:dict, 'dir')
|
if s:present(a:dict, 'dir')
|
||||||
let cwd = s:fzf_getcwd()
|
let cwd = s:fzf_getcwd()
|
||||||
if get(a:dict, 'prev_dir', '') ==# cwd
|
let w:fzf_pushd = {
|
||||||
return 1
|
\ 'command': haslocaldir() ? 'lcd' : (exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd'),
|
||||||
endif
|
\ 'origin': cwd,
|
||||||
let a:dict.prev_dir = cwd
|
\ 'bufname': bufname('')
|
||||||
|
\ }
|
||||||
execute 'lcd' s:escape(a:dict.dir)
|
execute 'lcd' s:escape(a:dict.dir)
|
||||||
let a:dict.dir = s:fzf_getcwd()
|
let cwd = s:fzf_getcwd()
|
||||||
return 1
|
let w:fzf_pushd.dir = cwd
|
||||||
|
let a:dict.pushd = w:fzf_pushd
|
||||||
|
return cwd
|
||||||
endif
|
endif
|
||||||
return 0
|
return ''
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
augroup fzf_popd
|
augroup fzf_popd
|
||||||
@@ -471,20 +629,38 @@ augroup fzf_popd
|
|||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
function! s:dopopd()
|
function! s:dopopd()
|
||||||
if !exists('w:fzf_dir') || s:fzf_getcwd() != w:fzf_dir[1]
|
if !exists('w:fzf_pushd')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
execute 'lcd' s:escape(w:fzf_dir[0])
|
|
||||||
unlet w:fzf_dir
|
" FIXME: We temporarily change the working directory to 'dir' entry
|
||||||
|
" of options dictionary (set to the current working directory if not given)
|
||||||
|
" before running fzf.
|
||||||
|
"
|
||||||
|
" e.g. call fzf#run({'dir': '/tmp', 'source': 'ls', 'sink': 'e'})
|
||||||
|
"
|
||||||
|
" After processing the sink function, we have to restore the current working
|
||||||
|
" directory. But doing so may not be desirable if the function changed the
|
||||||
|
" working directory on purpose.
|
||||||
|
"
|
||||||
|
" So how can we tell if we should do it or not? A simple heuristic we use
|
||||||
|
" here is that we change directory only if the current working directory
|
||||||
|
" matches 'dir' entry. However, it is possible that the sink function did
|
||||||
|
" change the directory to 'dir'. In that case, the user will have an
|
||||||
|
" unexpected result.
|
||||||
|
if s:fzf_getcwd() ==# w:fzf_pushd.dir && (!&autochdir || w:fzf_pushd.bufname ==# bufname(''))
|
||||||
|
execute w:fzf_pushd.command s:escape(w:fzf_pushd.origin)
|
||||||
|
endif
|
||||||
|
unlet! w:fzf_pushd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:xterm_launcher()
|
function! s:xterm_launcher()
|
||||||
let fmt = 'xterm -T "[fzf]" -bg "\%s" -fg "\%s" -geometry %dx%d+%d+%d -e bash -ic %%s'
|
let fmt = 'xterm -T "[fzf]" -bg "%s" -fg "%s" -geometry %dx%d+%d+%d -e bash -ic %%s'
|
||||||
if has('gui_macvim')
|
if has('gui_macvim')
|
||||||
let fmt .= '&& osascript -e "tell application \"MacVim\" to activate"'
|
let fmt .= '&& osascript -e "tell application \"MacVim\" to activate"'
|
||||||
endif
|
endif
|
||||||
return printf(fmt,
|
return printf(fmt,
|
||||||
\ synIDattr(hlID("Normal"), "bg"), synIDattr(hlID("Normal"), "fg"),
|
\ escape(synIDattr(hlID("Normal"), "bg"), '#'), escape(synIDattr(hlID("Normal"), "fg"), '#'),
|
||||||
\ &columns, &lines/2, getwinposx(), getwinposy())
|
\ &columns, &lines/2, getwinposx(), getwinposy())
|
||||||
endfunction
|
endfunction
|
||||||
unlet! s:launcher
|
unlet! s:launcher
|
||||||
@@ -494,17 +670,17 @@ else
|
|||||||
let s:launcher = function('s:xterm_launcher')
|
let s:launcher = function('s:xterm_launcher')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:exit_handler(code, command, ...)
|
function! s:exit_handler(dict, code, command, ...)
|
||||||
if a:code == 130
|
if has_key(a:dict, 'exit')
|
||||||
return 0
|
call a:dict.exit(a:code)
|
||||||
elseif a:code > 1
|
endif
|
||||||
|
if a:code == 2
|
||||||
call s:error('Error running ' . a:command)
|
call s:error('Error running ' . a:command)
|
||||||
if !empty(a:000)
|
if !empty(a:000)
|
||||||
sleep
|
sleep
|
||||||
endif
|
endif
|
||||||
return 0
|
|
||||||
endif
|
endif
|
||||||
return 1
|
return a:code
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute(dict, command, use_height, temps) abort
|
function! s:execute(dict, command, use_height, temps) abort
|
||||||
@@ -525,7 +701,7 @@ function! s:execute(dict, command, use_height, temps) abort
|
|||||||
endif
|
endif
|
||||||
if s:is_win
|
if s:is_win
|
||||||
let batchfile = s:fzf_tempname().'.bat'
|
let batchfile = s:fzf_tempname().'.bat'
|
||||||
call writefile(s:wrap_cmds(command), batchfile)
|
call s:writefile(s:wrap_cmds(command), batchfile)
|
||||||
let command = batchfile
|
let command = batchfile
|
||||||
let a:temps.batchfile = batchfile
|
let a:temps.batchfile = batchfile
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
@@ -533,9 +709,7 @@ function! s:execute(dict, command, use_height, temps) abort
|
|||||||
let fzf.dict = a:dict
|
let fzf.dict = a:dict
|
||||||
let fzf.temps = a:temps
|
let fzf.temps = a:temps
|
||||||
function! fzf.on_exit(job_id, exit_status, event) dict
|
function! fzf.on_exit(job_id, exit_status, event) dict
|
||||||
if s:present(self.dict, 'dir')
|
call s:pushd(self.dict)
|
||||||
execute 'lcd' s:escape(self.dict.dir)
|
|
||||||
endif
|
|
||||||
let lines = s:collect(self.temps)
|
let lines = s:collect(self.temps)
|
||||||
call s:callback(self.dict, lines)
|
call s:callback(self.dict, lines)
|
||||||
endfunction
|
endfunction
|
||||||
@@ -543,10 +717,10 @@ function! s:execute(dict, command, use_height, temps) abort
|
|||||||
call jobstart(cmd, fzf)
|
call jobstart(cmd, fzf)
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
elseif has('win32unix') && $TERM !=# 'cygwin'
|
elseif s:need_cmd_window
|
||||||
let shellscript = s:fzf_tempname()
|
let shellscript = s:fzf_tempname()
|
||||||
call writefile([command], shellscript)
|
call s:writefile([command], shellscript)
|
||||||
let command = 'cmd.exe /C '.fzf#shellescape('set "TERM=" & start /WAIT sh -c '.shellscript)
|
let command = 'start //WAIT sh -c '.shellscript
|
||||||
let a:temps.shellscript = shellscript
|
let a:temps.shellscript = shellscript
|
||||||
endif
|
endif
|
||||||
if a:use_height
|
if a:use_height
|
||||||
@@ -557,20 +731,23 @@ function! s:execute(dict, command, use_height, temps) abort
|
|||||||
endif
|
endif
|
||||||
let exit_status = v:shell_error
|
let exit_status = v:shell_error
|
||||||
redraw!
|
redraw!
|
||||||
return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []
|
let lines = s:collect(a:temps)
|
||||||
|
return s:exit_handler(a:dict, exit_status, command) < 2 ? lines : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute_tmux(dict, command, temps) abort
|
function! s:execute_tmux(dict, command, temps) abort
|
||||||
let command = a:command
|
let command = a:command
|
||||||
if s:pushd(a:dict)
|
let cwd = s:pushd(a:dict)
|
||||||
|
if len(cwd)
|
||||||
" -c '#{pane_current_path}' is only available on tmux 1.9 or above
|
" -c '#{pane_current_path}' is only available on tmux 1.9 or above
|
||||||
let command = join(['cd', fzf#shellescape(a:dict.dir), '&&', command])
|
let command = join(['cd', fzf#shellescape(cwd), '&&', command])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call system(command)
|
call system(command)
|
||||||
let exit_status = v:shell_error
|
let exit_status = v:shell_error
|
||||||
redraw!
|
redraw!
|
||||||
return s:exit_handler(exit_status, command) ? s:collect(a:temps) : []
|
let lines = s:collect(a:temps)
|
||||||
|
return s:exit_handler(a:dict, exit_status, command) < 2 ? lines : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:calc_size(max, val, dict)
|
function! s:calc_size(max, val, dict)
|
||||||
@@ -586,14 +763,46 @@ function! s:calc_size(max, val, dict)
|
|||||||
let srcsz = len(a:dict.source)
|
let srcsz = len(a:dict.source)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS
|
let opts = $FZF_DEFAULT_OPTS.' '.s:evaluate_opts(get(a:dict, 'options', ''))
|
||||||
let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2
|
if opts =~ 'preview'
|
||||||
let margin += stridx(opts, '--header') > stridx(opts, '--no-header')
|
return size
|
||||||
|
endif
|
||||||
|
let margin = match(opts, '--inline-info\|--info[^-]\{-}inline') > match(opts, '--no-inline-info\|--info[^-]\{-}\(default\|hidden\)') ? 1 : 2
|
||||||
|
let margin += match(opts, '--border\([^-]\|$\)') > match(opts, '--no-border\([^-]\|$\)') ? 2 : 0
|
||||||
|
if stridx(opts, '--header') > stridx(opts, '--no-header')
|
||||||
|
let margin += len(split(opts, "\n"))
|
||||||
|
endif
|
||||||
return srcsz >= 0 ? min([srcsz + margin, size]) : size
|
return srcsz >= 0 ? min([srcsz + margin, size]) : size
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:getpos()
|
function! s:getpos()
|
||||||
return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')}
|
return {'tab': tabpagenr(), 'win': winnr(), 'winid': win_getid(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')}
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:border_opt(window)
|
||||||
|
if type(a:window) != type({})
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Border style
|
||||||
|
let style = tolower(get(a:window, 'border', ''))
|
||||||
|
if !has_key(a:window, 'border') && has_key(a:window, 'rounded')
|
||||||
|
let style = a:window.rounded ? 'rounded' : 'sharp'
|
||||||
|
endif
|
||||||
|
if style == 'none' || style == 'no'
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
|
||||||
|
" For --border styles, we need fzf 0.24.0 or above
|
||||||
|
call fzf#exec('0.24.0')
|
||||||
|
let opt = ' --border ' . style
|
||||||
|
if has_key(a:window, 'highlight')
|
||||||
|
let color = s:get_color('fg', a:window.highlight)
|
||||||
|
if len(color)
|
||||||
|
let opt .= ' --color=border:' . color
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
return opt
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:split(dict)
|
function! s:split(dict)
|
||||||
@@ -603,9 +812,18 @@ function! s:split(dict)
|
|||||||
\ 'left': ['vertical topleft', 'vertical resize', &columns],
|
\ 'left': ['vertical topleft', 'vertical resize', &columns],
|
||||||
\ 'right': ['vertical botright', 'vertical resize', &columns] }
|
\ 'right': ['vertical botright', 'vertical resize', &columns] }
|
||||||
let ppos = s:getpos()
|
let ppos = s:getpos()
|
||||||
|
let is_popup = 0
|
||||||
try
|
try
|
||||||
if s:present(a:dict, 'window')
|
if s:present(a:dict, 'window')
|
||||||
|
if type(a:dict.window) == type({})
|
||||||
|
if !s:popup_support()
|
||||||
|
throw 'Nvim 0.4+ or Vim 8.2.191+ with popupwin feature is required for pop-up window'
|
||||||
|
end
|
||||||
|
call s:popup(a:dict.window)
|
||||||
|
let is_popup = 1
|
||||||
|
else
|
||||||
execute 'keepalt' a:dict.window
|
execute 'keepalt' a:dict.window
|
||||||
|
endif
|
||||||
elseif !s:splittable(a:dict)
|
elseif !s:splittable(a:dict)
|
||||||
execute (tabpagenr()-1).'tabnew'
|
execute (tabpagenr()-1).'tabnew'
|
||||||
else
|
else
|
||||||
@@ -620,20 +838,40 @@ function! s:split(dict)
|
|||||||
endif
|
endif
|
||||||
execute cmd sz.'new'
|
execute cmd sz.'new'
|
||||||
execute resz sz
|
execute resz sz
|
||||||
return [ppos, {}]
|
return [ppos, {}, is_popup]
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]
|
return [ppos, is_popup ? {} : { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }, is_popup]
|
||||||
finally
|
finally
|
||||||
|
if !is_popup
|
||||||
setlocal winfixwidth winfixheight
|
setlocal winfixwidth winfixheight
|
||||||
|
endif
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
nnoremap <silent> <Plug>(fzf-insert) i
|
||||||
|
nnoremap <silent> <Plug>(fzf-normal) <Nop>
|
||||||
|
if exists(':tnoremap')
|
||||||
|
tnoremap <silent> <Plug>(fzf-insert) <C-\><C-n>i
|
||||||
|
tnoremap <silent> <Plug>(fzf-normal) <C-\><C-n>
|
||||||
|
endif
|
||||||
|
|
||||||
|
let s:warned = 0
|
||||||
|
function! s:handle_ambidouble(dict)
|
||||||
|
if &ambiwidth == 'double'
|
||||||
|
let a:dict.env = { 'RUNEWIDTH_EASTASIAN': '1' }
|
||||||
|
elseif !s:warned && $RUNEWIDTH_EASTASIAN == '1' && &ambiwidth !=# 'double'
|
||||||
|
call s:warn("$RUNEWIDTH_EASTASIAN is '1' but &ambiwidth is not 'double'")
|
||||||
|
2sleep
|
||||||
|
let s:warned = 1
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:execute_term(dict, command, temps) abort
|
function! s:execute_term(dict, command, temps) abort
|
||||||
let winrest = winrestcmd()
|
let winrest = winrestcmd()
|
||||||
let pbuf = bufnr('')
|
let pbuf = bufnr('')
|
||||||
let [ppos, winopts] = s:split(a:dict)
|
let [ppos, winopts, is_popup] = s:split(a:dict)
|
||||||
call s:use_sh()
|
call s:use_sh()
|
||||||
let b:fzf = a:dict
|
let b:fzf = a:dict
|
||||||
let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
|
let fzf = { 'buf': bufnr(''), 'pbuf': pbuf, 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
|
||||||
@@ -642,7 +880,7 @@ function! s:execute_term(dict, command, temps) abort
|
|||||||
function! fzf.switch_back(inplace)
|
function! fzf.switch_back(inplace)
|
||||||
if a:inplace && bufnr('') == self.buf
|
if a:inplace && bufnr('') == self.buf
|
||||||
if bufexists(self.pbuf)
|
if bufexists(self.pbuf)
|
||||||
execute 'keepalt b' self.pbuf
|
execute 'keepalt keepjumps b' self.pbuf
|
||||||
endif
|
endif
|
||||||
" No other listed buffer
|
" No other listed buffer
|
||||||
if bufnr('') == self.buf
|
if bufnr('') == self.buf
|
||||||
@@ -662,8 +900,8 @@ function! s:execute_term(dict, command, temps) abort
|
|||||||
" there's no other listed buffer (nvim +'set nobuflisted')
|
" there's no other listed buffer (nvim +'set nobuflisted')
|
||||||
close
|
close
|
||||||
endif
|
endif
|
||||||
execute 'tabnext' self.ppos.tab
|
silent! execute 'tabnext' self.ppos.tab
|
||||||
execute self.ppos.win.'wincmd w'
|
silent! execute self.ppos.win.'wincmd w'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if bufexists(self.buf)
|
if bufexists(self.buf)
|
||||||
@@ -674,41 +912,58 @@ function! s:execute_term(dict, command, temps) abort
|
|||||||
execute self.winrest
|
execute self.winrest
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:exit_handler(a:code, self.command, 1)
|
let lines = s:collect(self.temps)
|
||||||
|
if s:exit_handler(self.dict, a:code, self.command, 1) >= 2
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:pushd(self.dict)
|
call s:pushd(self.dict)
|
||||||
let lines = s:collect(self.temps)
|
|
||||||
call s:callback(self.dict, lines)
|
call s:callback(self.dict, lines)
|
||||||
call self.switch_back(s:getpos() == self.ppos)
|
call self.switch_back(s:getpos() == self.ppos)
|
||||||
|
|
||||||
|
if &buftype == 'terminal'
|
||||||
|
call feedkeys(&filetype == 'fzf' ? "\<Plug>(fzf-insert)" : "\<Plug>(fzf-normal)")
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
try
|
try
|
||||||
if s:present(a:dict, 'dir')
|
call s:pushd(a:dict)
|
||||||
execute 'lcd' s:escape(a:dict.dir)
|
|
||||||
endif
|
|
||||||
if s:is_win
|
if s:is_win
|
||||||
let fzf.temps.batchfile = s:fzf_tempname().'.bat'
|
let fzf.temps.batchfile = s:fzf_tempname().'.bat'
|
||||||
call writefile(s:wrap_cmds(a:command), fzf.temps.batchfile)
|
call s:writefile(s:wrap_cmds(a:command), fzf.temps.batchfile)
|
||||||
let command = fzf.temps.batchfile
|
let command = fzf.temps.batchfile
|
||||||
else
|
else
|
||||||
let command = a:command
|
let command = a:command
|
||||||
endif
|
endif
|
||||||
let command .= s:term_marker
|
let command .= s:term_marker
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
|
call s:handle_ambidouble(fzf)
|
||||||
call termopen(command, fzf)
|
call termopen(command, fzf)
|
||||||
else
|
else
|
||||||
let t = term_start([&shell, &shellcmdflag, command], {'curwin': fzf.buf, 'exit_cb': function(fzf.on_exit)})
|
let term_opts = {'exit_cb': function(fzf.on_exit)}
|
||||||
" FIXME: https://github.com/vim/vim/issues/1998
|
if v:version >= 802
|
||||||
if !has('nvim') && !s:is_win
|
let term_opts.term_kill = 'term'
|
||||||
call term_wait(t, 20)
|
|
||||||
endif
|
endif
|
||||||
|
if is_popup
|
||||||
|
let term_opts.hidden = 1
|
||||||
|
else
|
||||||
|
let term_opts.curwin = 1
|
||||||
|
endif
|
||||||
|
call s:handle_ambidouble(term_opts)
|
||||||
|
keepjumps let fzf.buf = term_start([&shell, &shellcmdflag, command], term_opts)
|
||||||
|
if is_popup && exists('#TerminalWinOpen')
|
||||||
|
doautocmd <nomodeline> TerminalWinOpen
|
||||||
|
endif
|
||||||
|
if !has('patch-8.0.1261') && !s:is_win
|
||||||
|
call term_wait(fzf.buf, 20)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
tnoremap <buffer> <c-z> <nop>
|
||||||
|
if exists('&termwinkey') && (empty(&termwinkey) || &termwinkey =~? '<c-w>')
|
||||||
|
tnoremap <buffer> <c-w> <c-w>.
|
||||||
endif
|
endif
|
||||||
finally
|
finally
|
||||||
if s:present(a:dict, 'dir')
|
call s:dopopd()
|
||||||
lcd -
|
|
||||||
endif
|
|
||||||
endtry
|
endtry
|
||||||
setlocal nospell bufhidden=wipe nobuflisted nonumber
|
setlocal nospell bufhidden=wipe nobuflisted nonumber
|
||||||
setf fzf
|
setf fzf
|
||||||
@@ -727,21 +982,9 @@ function! s:collect(temps) abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:callback(dict, lines) abort
|
function! s:callback(dict, lines) abort
|
||||||
" Since anything can be done in the sink function, there is no telling that
|
let popd = has_key(a:dict, 'pushd')
|
||||||
" the change of the working directory was made by &autochdir setting.
|
|
||||||
"
|
|
||||||
" We use the following heuristic to determine whether to restore CWD:
|
|
||||||
" - Always restore the current directory when &autochdir is disabled.
|
|
||||||
" FIXME This makes it impossible to change directory from inside the sink
|
|
||||||
" function when &autochdir is not used.
|
|
||||||
" - In case of an error or an interrupt, a:lines will be empty.
|
|
||||||
" And it will be an array of a single empty string when fzf was finished
|
|
||||||
" without a match. In these cases, we presume that the change of the
|
|
||||||
" directory is not expected and should be undone.
|
|
||||||
let popd = has_key(a:dict, 'prev_dir') &&
|
|
||||||
\ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))
|
|
||||||
if popd
|
if popd
|
||||||
let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]
|
let w:fzf_pushd = a:dict.pushd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -756,6 +999,8 @@ function! s:callback(dict, lines) abort
|
|||||||
endif
|
endif
|
||||||
if has_key(a:dict, 'sink*')
|
if has_key(a:dict, 'sink*')
|
||||||
call a:dict['sink*'](a:lines)
|
call a:dict['sink*'](a:lines)
|
||||||
|
elseif has_key(a:dict, 'sinklist')
|
||||||
|
call a:dict['sinklist'](a:lines)
|
||||||
endif
|
endif
|
||||||
catch
|
catch
|
||||||
if stridx(v:exception, ':E325:') < 0
|
if stridx(v:exception, ':E325:') < 0
|
||||||
@@ -765,11 +1010,61 @@ function! s:callback(dict, lines) abort
|
|||||||
|
|
||||||
" We may have opened a new window or tab
|
" We may have opened a new window or tab
|
||||||
if popd
|
if popd
|
||||||
let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]
|
let w:fzf_pushd = a:dict.pushd
|
||||||
call s:dopopd()
|
call s:dopopd()
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
if has('nvim')
|
||||||
|
function s:create_popup(opts) abort
|
||||||
|
let buf = nvim_create_buf(v:false, v:true)
|
||||||
|
let opts = extend({'relative': 'editor', 'style': 'minimal'}, a:opts)
|
||||||
|
let win = nvim_open_win(buf, v:true, opts)
|
||||||
|
silent! call setwinvar(win, '&winhighlight', 'Pmenu:,Normal:Normal')
|
||||||
|
call setwinvar(win, '&colorcolumn', '')
|
||||||
|
return buf
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:create_popup(opts) abort
|
||||||
|
let s:popup_create = {buf -> popup_create(buf, #{
|
||||||
|
\ line: a:opts.row,
|
||||||
|
\ col: a:opts.col,
|
||||||
|
\ minwidth: a:opts.width,
|
||||||
|
\ maxwidth: a:opts.width,
|
||||||
|
\ minheight: a:opts.height,
|
||||||
|
\ maxheight: a:opts.height,
|
||||||
|
\ zindex: 1000,
|
||||||
|
\ })}
|
||||||
|
autocmd TerminalOpen * ++once call s:popup_create(str2nr(expand('<abuf>')))
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:popup(opts) abort
|
||||||
|
let xoffset = get(a:opts, 'xoffset', 0.5)
|
||||||
|
let yoffset = get(a:opts, 'yoffset', 0.5)
|
||||||
|
let relative = get(a:opts, 'relative', 0)
|
||||||
|
|
||||||
|
" Use current window size for positioning relatively positioned popups
|
||||||
|
let columns = relative ? winwidth(0) : &columns
|
||||||
|
let lines = relative ? winheight(0) : (&lines - has('nvim'))
|
||||||
|
|
||||||
|
" Size and position
|
||||||
|
let width = min([max([8, a:opts.width > 1 ? a:opts.width : float2nr(columns * a:opts.width)]), columns])
|
||||||
|
let height = min([max([4, a:opts.height > 1 ? a:opts.height : float2nr(lines * a:opts.height)]), lines])
|
||||||
|
let row = float2nr(yoffset * (lines - height)) + (relative ? win_screenpos(0)[0] - 1 : 0)
|
||||||
|
let col = float2nr(xoffset * (columns - width)) + (relative ? win_screenpos(0)[1] - 1 : 0)
|
||||||
|
|
||||||
|
" Managing the differences
|
||||||
|
let row = min([max([0, row]), &lines - has('nvim') - height])
|
||||||
|
let col = min([max([0, col]), &columns - width])
|
||||||
|
let row += !has('nvim')
|
||||||
|
let col += !has('nvim')
|
||||||
|
|
||||||
|
call s:create_popup({
|
||||||
|
\ 'row': row, 'col': col, 'width': width, 'height': height
|
||||||
|
\ })
|
||||||
|
endfunction
|
||||||
|
|
||||||
let s:default_action = {
|
let s:default_action = {
|
||||||
\ 'ctrl-t': 'tab split',
|
\ 'ctrl-t': 'tab split',
|
||||||
\ 'ctrl-x': 'split',
|
\ 'ctrl-x': 'split',
|
||||||
|
|||||||
@@ -1,46 +1,98 @@
|
|||||||
#!/bin/bash
|
|
||||||
# ____ ____
|
# ____ ____
|
||||||
# / __/___ / __/
|
# / __/___ / __/
|
||||||
# / /_/_ / / /_
|
# / /_/_ / / /_
|
||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/-completion.bash
|
# /_/ /___/_/ completion.bash
|
||||||
#
|
#
|
||||||
# - $FZF_TMUX (default: 0)
|
# - $FZF_TMUX (default: 0)
|
||||||
# - $FZF_TMUX_HEIGHT (default: '40%')
|
# - $FZF_TMUX_OPTS (default: empty)
|
||||||
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
||||||
# - $FZF_COMPLETION_OPTS (default: empty)
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
||||||
|
# - $FZF_COMPLETION_PATH_OPTS (default: empty)
|
||||||
|
# - $FZF_COMPLETION_DIR_OPTS (default: empty)
|
||||||
|
|
||||||
|
if [[ $- =~ i ]]; then
|
||||||
|
|
||||||
|
|
||||||
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
||||||
if ! declare -f _fzf_compgen_path > /dev/null; then
|
#
|
||||||
_fzf_compgen_path() {
|
# _fzf_compgen_path() {
|
||||||
echo "$1"
|
# echo "$1"
|
||||||
command find -L "$1" \
|
# command find -L "$1" \
|
||||||
-name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
||||||
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'
|
||||||
}
|
# }
|
||||||
fi
|
#
|
||||||
|
# _fzf_compgen_dir() {
|
||||||
if ! declare -f _fzf_compgen_dir > /dev/null; then
|
# command find -L "$1" \
|
||||||
_fzf_compgen_dir() {
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \
|
||||||
command find -L "$1" \
|
# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'
|
||||||
-name .git -prune -o -name .svn -prune -o -type d \
|
# }
|
||||||
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
# To redraw line after fzf closes (printf '\e[5n')
|
# To redraw line after fzf closes (printf '\e[5n')
|
||||||
bind '"\e[0n": redraw-current-line'
|
bind '"\e[0n": redraw-current-line' 2> /dev/null
|
||||||
|
|
||||||
__fzfcmd_complete() {
|
__fzf_defaults() {
|
||||||
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] &&
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
||||||
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_orig_completion_filter() {
|
__fzf_comprun() {
|
||||||
sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |
|
if [[ "$(type -t _fzf_comprun 2>&1)" = function ]]; then
|
||||||
awk -F= '{gsub(/[^A-Za-z0-9_= ;]/, "_", $1); print $1"="$2}'
|
_fzf_comprun "$@"
|
||||||
|
elif [[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; }; then
|
||||||
|
shift
|
||||||
|
fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"
|
||||||
|
else
|
||||||
|
shift
|
||||||
|
fzf "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
__fzf_orig_completion() {
|
||||||
|
local l comp f cmd
|
||||||
|
while read -r l; do
|
||||||
|
if [[ "$l" =~ ^(.*\ -F)\ *([^ ]*).*\ ([^ ]*)$ ]]; then
|
||||||
|
comp="${BASH_REMATCH[1]}"
|
||||||
|
f="${BASH_REMATCH[2]}"
|
||||||
|
cmd="${BASH_REMATCH[3]}"
|
||||||
|
[[ "$f" = _fzf_* ]] && continue
|
||||||
|
printf -v "_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}" "%s" "${comp} %s ${cmd} #${f}"
|
||||||
|
if [[ "$l" = *" -o nospace "* ]] && [[ ! "${__fzf_nospace_commands-}" = *" $cmd "* ]]; then
|
||||||
|
__fzf_nospace_commands="${__fzf_nospace_commands-} $cmd "
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# @param $1 cmd - Command name for which the original completion is searched
|
||||||
|
# @var[out] REPLY - Original function name is returned
|
||||||
|
__fzf_orig_completion_get_orig_func() {
|
||||||
|
local cmd orig_var orig
|
||||||
|
cmd=$1
|
||||||
|
orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"
|
||||||
|
orig="${!orig_var-}"
|
||||||
|
REPLY="${orig##*#}"
|
||||||
|
[[ $REPLY ]] && type "$REPLY" &> /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# @param $1 cmd - Command name for which the original completion is searched
|
||||||
|
# @param $2 func - Fzf's completion function to replace the original function
|
||||||
|
# @var[out] REPLY - Completion setting is returned as a string to "eval"
|
||||||
|
__fzf_orig_completion_instantiate() {
|
||||||
|
local cmd func orig_var orig
|
||||||
|
cmd=$1
|
||||||
|
func=$2
|
||||||
|
orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"
|
||||||
|
orig="${!orig_var-}"
|
||||||
|
orig="${orig%#*}"
|
||||||
|
[[ $orig == *' %s '* ]] || return 1
|
||||||
|
printf -v REPLY "$orig" "$func"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_opts_completion() {
|
_fzf_opts_completion() {
|
||||||
@@ -49,57 +101,143 @@ _fzf_opts_completion() {
|
|||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
opts="
|
opts="
|
||||||
-x --extended
|
+c --no-color
|
||||||
-e --exact
|
+i --no-ignore-case
|
||||||
--algo
|
|
||||||
-i +i
|
|
||||||
-n --nth
|
|
||||||
--with-nth
|
|
||||||
-d --delimiter
|
|
||||||
+s --no-sort
|
+s --no-sort
|
||||||
--tac
|
+x --no-extended
|
||||||
--tiebreak
|
|
||||||
-m --multi
|
|
||||||
--no-mouse
|
|
||||||
--bind
|
|
||||||
--cycle
|
|
||||||
--no-hscroll
|
|
||||||
--jump-labels
|
|
||||||
--height
|
|
||||||
--literal
|
|
||||||
--reverse
|
|
||||||
--margin
|
|
||||||
--inline-info
|
|
||||||
--prompt
|
|
||||||
--header
|
|
||||||
--header-lines
|
|
||||||
--ansi
|
--ansi
|
||||||
--tabstop
|
--bash
|
||||||
|
--bind
|
||||||
|
--border
|
||||||
|
--border-label
|
||||||
|
--border-label-pos
|
||||||
--color
|
--color
|
||||||
--no-bold
|
--cycle
|
||||||
|
--disabled
|
||||||
|
--ellipsis
|
||||||
|
--expect
|
||||||
|
--filepath-word
|
||||||
|
--fish
|
||||||
|
--header
|
||||||
|
--header-first
|
||||||
|
--header-lines
|
||||||
|
--height
|
||||||
|
--highlight-line
|
||||||
--history
|
--history
|
||||||
--history-size
|
--history-size
|
||||||
|
--hscroll-off
|
||||||
|
--info
|
||||||
|
--jump-labels
|
||||||
|
--keep-right
|
||||||
|
--layout
|
||||||
|
--listen
|
||||||
|
--listen-unsafe
|
||||||
|
--literal
|
||||||
|
--man
|
||||||
|
--margin
|
||||||
|
--marker
|
||||||
|
--min-height
|
||||||
|
--no-bold
|
||||||
|
--no-clear
|
||||||
|
--no-hscroll
|
||||||
|
--no-mouse
|
||||||
|
--no-scrollbar
|
||||||
|
--no-separator
|
||||||
|
--no-unicode
|
||||||
|
--padding
|
||||||
|
--pointer
|
||||||
--preview
|
--preview
|
||||||
|
--preview-label
|
||||||
|
--preview-label-pos
|
||||||
--preview-window
|
--preview-window
|
||||||
-q --query
|
|
||||||
-1 --select-1
|
|
||||||
-0 --exit-0
|
|
||||||
-f --filter
|
|
||||||
--print-query
|
--print-query
|
||||||
--expect
|
--print0
|
||||||
--sync"
|
--prompt
|
||||||
|
--read0
|
||||||
|
--reverse
|
||||||
|
--scheme
|
||||||
|
--scroll-off
|
||||||
|
--separator
|
||||||
|
--sync
|
||||||
|
--tabstop
|
||||||
|
--tac
|
||||||
|
--tiebreak
|
||||||
|
--tmux
|
||||||
|
--track
|
||||||
|
--version
|
||||||
|
--with-nth
|
||||||
|
--with-shell
|
||||||
|
--wrap
|
||||||
|
--zsh
|
||||||
|
-0 --exit-0
|
||||||
|
-1 --select-1
|
||||||
|
-d --delimiter
|
||||||
|
-e --exact
|
||||||
|
-f --filter
|
||||||
|
-h --help
|
||||||
|
-i --ignore-case
|
||||||
|
-m --multi
|
||||||
|
-n --nth
|
||||||
|
-q --query
|
||||||
|
--"
|
||||||
|
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
|
--scheme)
|
||||||
|
COMPREPLY=( $(compgen -W "default path history" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
--tiebreak)
|
--tiebreak)
|
||||||
COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )
|
COMPREPLY=( $(compgen -W "length chunk begin end index" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--color)
|
--color)
|
||||||
COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )
|
COMPREPLY=( $(compgen -W "dark light 16 bw no" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--history)
|
--layout)
|
||||||
COMPREPLY=()
|
COMPREPLY=( $(compgen -W "default reverse reverse-list" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--info)
|
||||||
|
COMPREPLY=( $(compgen -W "default right hidden inline inline-right" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--preview-window)
|
||||||
|
COMPREPLY=( $(compgen -W "
|
||||||
|
default
|
||||||
|
hidden
|
||||||
|
nohidden
|
||||||
|
wrap
|
||||||
|
nowrap
|
||||||
|
cycle
|
||||||
|
nocycle
|
||||||
|
up top
|
||||||
|
down bottom
|
||||||
|
left
|
||||||
|
right
|
||||||
|
rounded border border-rounded
|
||||||
|
sharp border-sharp
|
||||||
|
border-bold
|
||||||
|
border-block
|
||||||
|
border-thinblock
|
||||||
|
border-double
|
||||||
|
noborder border-none
|
||||||
|
border-horizontal
|
||||||
|
border-vertical
|
||||||
|
border-up border-top
|
||||||
|
border-down border-bottom
|
||||||
|
border-left
|
||||||
|
border-right
|
||||||
|
follow
|
||||||
|
nofollow" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--border)
|
||||||
|
COMPREPLY=( $(compgen -W "rounded sharp bold block thinblock double horizontal vertical top bottom left right none" -- "$cur") )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--border-label-pos|--preview-label-pos)
|
||||||
|
COMPREPLY=( $(compgen -W "center bottom top" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -113,46 +251,93 @@ _fzf_opts_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_handle_dynamic_completion() {
|
_fzf_handle_dynamic_completion() {
|
||||||
local cmd orig_var orig ret orig_cmd
|
local cmd ret REPLY orig_cmd orig_complete
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
shift
|
shift
|
||||||
orig_cmd="$1"
|
orig_cmd="$1"
|
||||||
orig_var="_fzf_orig_completion_$cmd"
|
if __fzf_orig_completion_get_orig_func "$cmd"; then
|
||||||
orig="${!orig_var##*#}"
|
"$REPLY" "$@"
|
||||||
if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then
|
elif [[ -n "${_fzf_completion_loader-}" ]]; then
|
||||||
$orig "$@"
|
orig_complete=$(complete -p "$orig_cmd" 2> /dev/null)
|
||||||
elif [ -n "$_fzf_completion_loader" ]; then
|
$_fzf_completion_loader "$@"
|
||||||
_completion_loader "$@"
|
|
||||||
ret=$?
|
ret=$?
|
||||||
eval "$(complete | command grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)"
|
# _completion_loader may not have updated completion for the command
|
||||||
source "${BASH_SOURCE[0]}"
|
if [[ "$(complete -p "$orig_cmd" 2> /dev/null)" != "$orig_complete" ]]; then
|
||||||
|
__fzf_orig_completion < <(complete -p "$orig_cmd" 2> /dev/null)
|
||||||
|
__fzf_orig_completion_get_orig_func "$cmd" || ret=1
|
||||||
|
|
||||||
|
# Update orig_complete by _fzf_orig_completion entry
|
||||||
|
[[ $orig_complete =~ ' -F '(_fzf_[^ ]+)' ' ]] &&
|
||||||
|
__fzf_orig_completion_instantiate "$cmd" "${BASH_REMATCH[1]}" &&
|
||||||
|
orig_complete=$REPLY
|
||||||
|
|
||||||
|
if [[ "${__fzf_nospace_commands-}" = *" $orig_cmd "* ]]; then
|
||||||
|
eval "${orig_complete/ -F / -o nospace -F }"
|
||||||
|
else
|
||||||
|
eval "$orig_complete"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
[[ $ret -eq 0 ]] && return 124
|
||||||
return $ret
|
return $ret
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_generic_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local cur base dir leftover matches trigger cmd fzf
|
local cur base dir leftover matches trigger cmd rest
|
||||||
fzf="$(__fzfcmd_complete)"
|
cmd="${COMP_WORDS[0]}"
|
||||||
cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"
|
if [[ $cmd == \\* ]]; then
|
||||||
|
cmd="${cmd:1}"
|
||||||
|
fi
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
[[ $COMP_CWORD -ge 0 ]] && cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ "$cur" == *"$trigger" ]]; then
|
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
|
||||||
base=${cur:0:${#cur}-${#trigger}}
|
base=${cur:0:${#cur}-${#trigger}}
|
||||||
eval "base=$base"
|
eval "base=$base" 2> /dev/null || return
|
||||||
|
|
||||||
dir="$base"
|
# Try to leverage existing completion
|
||||||
|
rest=("${@:4}")
|
||||||
|
unset 'rest[${#rest[@]}-2]'
|
||||||
|
COMP_LINE=${COMP_LINE:0:${#COMP_LINE}-${#trigger}}
|
||||||
|
COMP_POINT=$((COMP_POINT-${#trigger}))
|
||||||
|
COMP_WORDS[$COMP_CWORD]=$base
|
||||||
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
||||||
|
[[ $? -ne 0 ]] &&
|
||||||
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
||||||
|
|
||||||
|
dir=
|
||||||
|
[[ $base = *"/"* ]] && dir="$base"
|
||||||
while true; do
|
while true; do
|
||||||
if [ -z "$dir" ] || [ -d "$dir" ]; then
|
if [[ -z "$dir" ]] || [[ -d "$dir" ]]; then
|
||||||
leftover=${base/#"$dir"}
|
leftover=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ -z "$dir" ] && dir='.'
|
[[ -z "$dir" ]] && dir='.'
|
||||||
[ "$dir" != "/" ] && dir="${dir/%\//}"
|
[[ "$dir" != "/" ]] && dir="${dir/%\//}"
|
||||||
matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" $fzf $2 -q "$leftover" | while read -r item; do
|
matches=$(
|
||||||
printf "%q$3 " "$item"
|
export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")
|
||||||
done)
|
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
|
||||||
|
if [[ ${#COMPREPLY[@]} -gt 0 ]]; then
|
||||||
|
for h in "${COMPREPLY[@]}"; do
|
||||||
|
echo "$h"
|
||||||
|
done | command sort -u | __fzf_comprun "$4" -q "$leftover"
|
||||||
|
elif declare -F "$1" > /dev/null; then
|
||||||
|
eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover"
|
||||||
|
else
|
||||||
|
if [[ $1 =~ dir ]]; then
|
||||||
|
walker=dir,follow
|
||||||
|
rest=${FZF_COMPLETION_DIR_OPTS-}
|
||||||
|
else
|
||||||
|
walker=file,dir,follow,hidden
|
||||||
|
rest=${FZF_COMPLETION_PATH_OPTS-}
|
||||||
|
fi
|
||||||
|
__fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" $rest
|
||||||
|
fi | while read -r item; do
|
||||||
|
printf "%q " "${item%$3}$3"
|
||||||
|
done
|
||||||
|
)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
if [ -n "$matches" ]; then
|
[[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "
|
||||||
|
if [[ -n "$matches" ]]; then
|
||||||
COMPREPLY=( "$matches" )
|
COMPREPLY=( "$matches" )
|
||||||
else
|
else
|
||||||
COMPREPLY=( "$cur" )
|
COMPREPLY=( "$cur" )
|
||||||
@@ -160,7 +345,7 @@ __fzf_generic_path_completion() {
|
|||||||
printf '\e[5n'
|
printf '\e[5n'
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
dir=$(dirname "$dir")
|
dir=$(command dirname "$dir")
|
||||||
[[ "$dir" =~ /$ ]] || dir="$dir"/
|
[[ "$dir" =~ /$ ]] || dir="$dir"/
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
@@ -172,28 +357,64 @@ __fzf_generic_path_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete() {
|
_fzf_complete() {
|
||||||
local cur selected trigger cmd fzf post
|
# Split arguments around --
|
||||||
post="$(caller 0 | awk '{print $2}')_post"
|
local args rest str_arg i sep
|
||||||
type -t "$post" > /dev/null 2>&1 || post=cat
|
args=("$@")
|
||||||
fzf="$(__fzfcmd_complete)"
|
sep=
|
||||||
|
for i in "${!args[@]}"; do
|
||||||
|
if [[ "${args[$i]}" = -- ]]; then
|
||||||
|
sep=$i
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ -n "$sep" ]]; then
|
||||||
|
str_arg=
|
||||||
|
rest=("${args[@]:$((sep + 1)):${#args[@]}}")
|
||||||
|
args=("${args[@]:0:$sep}")
|
||||||
|
else
|
||||||
|
str_arg=$1
|
||||||
|
args=()
|
||||||
|
shift
|
||||||
|
rest=("$@")
|
||||||
|
fi
|
||||||
|
|
||||||
|
local cur selected trigger cmd post
|
||||||
|
post="$(caller 0 | command awk '{print $2}')_post"
|
||||||
|
type -t "$post" > /dev/null 2>&1 || post='command cat'
|
||||||
|
|
||||||
cmd="${COMP_WORDS[0]//[^A-Za-z0-9_=]/_}"
|
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
|
cmd="${COMP_WORDS[0]}"
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ "$cur" == *"$trigger" ]]; then
|
if [[ "$cur" == *"$trigger" ]] && [[ $cur != *'$('* ]] && [[ $cur != *':='* ]] && [[ $cur != *'`'* ]]; then
|
||||||
cur=${cur:0:${#cur}-${#trigger}}
|
cur=${cur:0:${#cur}-${#trigger}}
|
||||||
|
|
||||||
selected=$(cat | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" $fzf $1 -q "$cur" | $post | tr '\n' ' ')
|
# Try to leverage existing completion
|
||||||
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
COMP_LINE=${COMP_LINE:0:${#COMP_LINE}-${#trigger}}
|
||||||
printf '\e[5n'
|
COMP_POINT=$((COMP_POINT-${#trigger}))
|
||||||
|
unset 'rest[${#rest[@]}-2]'
|
||||||
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
||||||
|
[[ $? -ne 0 ]] &&
|
||||||
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
||||||
|
|
||||||
if [ -n "$selected" ]; then
|
selected=$(
|
||||||
|
(if [[ ${#COMPREPLY[@]} -gt 0 ]]; then
|
||||||
|
for h in "${COMPREPLY[@]}"; do
|
||||||
|
echo "$h"
|
||||||
|
done
|
||||||
|
fi; cat) | command sort -u |
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' \
|
||||||
|
__fzf_comprun "${rest[0]}" "${args[@]}" -q "$cur" | $post | command tr '\n' ' ')
|
||||||
|
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
||||||
|
if [[ -n "$selected" ]]; then
|
||||||
COMPREPLY=("$selected")
|
COMPREPLY=("$selected")
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
shift
|
COMPREPLY=("$cur")
|
||||||
_fzf_handle_dynamic_completion "$cmd" "$@"
|
fi
|
||||||
|
printf '\e[5n'
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
_fzf_handle_dynamic_completion "$cmd" "${rest[@]}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,87 +432,146 @@ _fzf_dir_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_kill() {
|
_fzf_complete_kill() {
|
||||||
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
_fzf_proc_completion "$@"
|
||||||
|
}
|
||||||
|
|
||||||
local selected fzf
|
_fzf_proc_completion() {
|
||||||
fzf="$(__fzfcmd_complete)"
|
_fzf_complete -m --header-lines=1 --no-preview --wrap -- "$@" < <(
|
||||||
selected=$(ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS --preview 'echo {}' --preview-window down:3:wrap $FZF_COMPLETION_OPTS" $fzf -m | awk '{print $2}' | tr '\n' ' ')
|
command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||
|
||||||
printf '\e[5n'
|
command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox
|
||||||
|
command ps --everyone --full --windows # For cygwin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if [ -n "$selected" ]; then
|
_fzf_proc_completion_post() {
|
||||||
COMPREPLY=( "$selected" )
|
command awk '{print $2}'
|
||||||
return 0
|
}
|
||||||
|
|
||||||
|
# To use custom hostname lists, override __fzf_list_hosts.
|
||||||
|
# The function is expected to print hostnames, one per line as well as in the
|
||||||
|
# desired sorting and with any duplicates removed, to standard output.
|
||||||
|
#
|
||||||
|
# e.g.
|
||||||
|
# # Use bash-completions’s _known_hosts_real() for getting the list of hosts
|
||||||
|
# __fzf_list_hosts() {
|
||||||
|
# # Set the local attribute for any non-local variable that is set by _known_hosts_real()
|
||||||
|
# local COMPREPLY=()
|
||||||
|
# _known_hosts_real ''
|
||||||
|
# printf '%s\n' "${COMPREPLY[@]}" | command sort -u --version-sort
|
||||||
|
# }
|
||||||
|
if ! declare -F __fzf_list_hosts > /dev/null; then
|
||||||
|
__fzf_list_hosts() {
|
||||||
|
command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | command awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \
|
||||||
|
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | command tr ',' '\n' | command tr -d '[' | command awk '{ print $1 " " $1 }') \
|
||||||
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |
|
||||||
|
command awk '{for (i = 2; i <= NF; i++) print $i}' | command sort -u
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_fzf_host_completion() {
|
||||||
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_telnet() {
|
# Values for $1 $2 $3 are described here
|
||||||
_fzf_complete '+m' "$@" < <(
|
# https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html
|
||||||
command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' |
|
# > the first argument ($1) is the name of the command whose arguments are being completed,
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
# > the second argument ($2) is the word being completed,
|
||||||
)
|
# > and the third argument ($3) is the word preceding the word being completed on the current command line.
|
||||||
}
|
|
||||||
|
|
||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
case $3 in
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \
|
-i|-F|-E)
|
||||||
<(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
_fzf_path_completion "$@"
|
||||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
;;
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
*)
|
||||||
|
local user=
|
||||||
|
[[ "$2" =~ '@' ]] && user="${2%%@*}@"
|
||||||
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts | command awk -v user="$user" '{print user $0}')
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
_fzf_var_completion() {
|
||||||
|
_fzf_complete -m -- "$@" < <(
|
||||||
|
declare -xp | command sed -En 's|^declare [^ ]+ ([^=]+).*|\1|p'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_unset() {
|
_fzf_alias_completion() {
|
||||||
_fzf_complete '-m' "$@" < <(
|
_fzf_complete -m -- "$@" < <(
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
alias | command sed -En 's|^alias ([^=]+).*|\1|p'
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
_fzf_complete_export() {
|
|
||||||
_fzf_complete '-m' "$@" < <(
|
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
_fzf_complete_unalias() {
|
|
||||||
_fzf_complete '-m' "$@" < <(
|
|
||||||
alias | sed 's/=.*//' | sed 's/.* //'
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
# fzf options
|
# fzf options
|
||||||
complete -o default -F _fzf_opts_completion fzf
|
complete -o default -F _fzf_opts_completion fzf
|
||||||
|
# fzf-tmux is a thin fzf wrapper that has only a few more options than fzf
|
||||||
|
# itself. As a quick improvement we take fzf's completion. Adding the few extra
|
||||||
|
# fzf-tmux specific options (like `-w WIDTH`) are left as a future patch.
|
||||||
|
complete -o default -F _fzf_opts_completion fzf-tmux
|
||||||
|
|
||||||
d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"
|
# Default path completion
|
||||||
a_cmds="
|
__fzf_default_completion() {
|
||||||
awk cat diff diff3
|
__fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"
|
||||||
emacs emacsclient ex file ftp g++ gcc gvim head hg java
|
|
||||||
|
# Dynamic completion loader has updated the completion for the command
|
||||||
|
if [[ $? -eq 124 ]]; then
|
||||||
|
# We trigger _fzf_setup_completion so that fuzzy completion for the command
|
||||||
|
# still works. However, loader can update the completion for multiple
|
||||||
|
# commands at once, and fuzzy completion will no longer work for those
|
||||||
|
# other commands. e.g. pytest -> py.test, pytest-2, pytest-3, etc
|
||||||
|
_fzf_setup_completion path "$1"
|
||||||
|
return 124
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set fuzzy path completion as the default completion for all commands.
|
||||||
|
# We can't set up default completion,
|
||||||
|
# 1. if it's already set up by another script
|
||||||
|
# 2. or if the current version of bash doesn't support -D option
|
||||||
|
complete | command grep -q __fzf_default_completion ||
|
||||||
|
complete | command grep -- '-D$' | command grep -qv _comp_complete_load ||
|
||||||
|
complete -D -F __fzf_default_completion -o default -o bashdefault 2> /dev/null
|
||||||
|
|
||||||
|
d_cmds="${FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir}"
|
||||||
|
|
||||||
|
# NOTE: $FZF_COMPLETION_PATH_COMMANDS and $FZF_COMPLETION_VAR_COMMANDS are
|
||||||
|
# undocumented and subject to change in the future.
|
||||||
|
#
|
||||||
|
# NOTE: Although we have default completion, we still need to set up completion
|
||||||
|
# for each command in case they already have completion set up by another script.
|
||||||
|
a_cmds="${FZF_COMPLETION_PATH_COMMANDS-"
|
||||||
|
awk bat cat code diff diff3
|
||||||
|
emacs emacsclient ex file ftp g++ gcc gvim head hg hx java
|
||||||
javac ld less more mvim nvim patch perl python ruby
|
javac ld less more mvim nvim patch perl python ruby
|
||||||
sed sftp sort source tail tee uniq vi view vim wc xdg-open
|
sed sftp sort source tail tee uniq vi view vim wc xdg-open
|
||||||
basename bunzip2 bzip2 chmod chown curl cp dirname du
|
basename bunzip2 bzip2 chmod chown curl cp dirname du
|
||||||
find git grep gunzip gzip hg jar
|
find git grep gunzip gzip hg jar
|
||||||
ln ls mv open rm rsync scp
|
ln ls mv open rm rsync scp
|
||||||
svn tar unzip zip"
|
svn tar unzip zip"}"
|
||||||
x_cmds="kill ssh telnet unset unalias export"
|
v_cmds="${FZF_COMPLETION_VAR_COMMANDS-export unset printenv}"
|
||||||
|
|
||||||
# Preserve existing completion
|
# Preserve existing completion
|
||||||
eval $(complete |
|
__fzf_orig_completion < <(complete -p $d_cmds $a_cmds $v_cmds unalias kill ssh 2> /dev/null)
|
||||||
sed -E '/-F/!d; / _fzf/d; '"/ ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g; s/+/\\+/g'))$/"'!d' |
|
|
||||||
_fzf_orig_completion_filter)
|
|
||||||
|
|
||||||
if type _completion_loader > /dev/null 2>&1; then
|
if type _comp_load > /dev/null 2>&1; then
|
||||||
_fzf_completion_loader=1
|
# _comp_load was added in bash-completion 2.12 to replace _completion_loader.
|
||||||
|
# We use it without -D option so that it does not use _comp_complete_minimal as the fallback.
|
||||||
|
_fzf_completion_loader=_comp_load
|
||||||
|
elif type __load_completion > /dev/null 2>&1; then
|
||||||
|
# In bash-completion 2.11, _completion_loader internally calls __load_completion
|
||||||
|
# and if it returns a non-zero status, it sets the default 'minimal' completion.
|
||||||
|
_fzf_completion_loader=__load_completion
|
||||||
|
elif type _completion_loader > /dev/null 2>&1; then
|
||||||
|
_fzf_completion_loader=_completion_loader
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_fzf_defc() {
|
__fzf_defc() {
|
||||||
local cmd func opts orig_var orig def
|
local cmd func opts REPLY
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
func="$2"
|
func="$2"
|
||||||
opts="$3"
|
opts="$3"
|
||||||
orig_var="_fzf_orig_completion_${cmd//[^A-Za-z0-9_]/_}"
|
if __fzf_orig_completion_instantiate "$cmd" "$func"; then
|
||||||
orig="${!orig_var}"
|
eval "$REPLY"
|
||||||
if [ -n "$orig" ]; then
|
|
||||||
printf -v def "$orig" "$func"
|
|
||||||
eval "$def"
|
|
||||||
else
|
else
|
||||||
complete -F "$func" $opts "$cmd"
|
complete -F "$func" $opts "$cmd"
|
||||||
fi
|
fi
|
||||||
@@ -299,26 +579,48 @@ _fzf_defc() {
|
|||||||
|
|
||||||
# Anything
|
# Anything
|
||||||
for cmd in $a_cmds; do
|
for cmd in $a_cmds; do
|
||||||
_fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"
|
__fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Directory
|
# Directory
|
||||||
for cmd in $d_cmds; do
|
for cmd in $d_cmds; do
|
||||||
_fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames"
|
__fzf_defc "$cmd" _fzf_dir_completion "-o bashdefault -o nospace -o dirnames"
|
||||||
done
|
done
|
||||||
|
|
||||||
unset _fzf_defc
|
# Variables
|
||||||
|
for cmd in $v_cmds; do
|
||||||
|
__fzf_defc "$cmd" _fzf_var_completion "-o default -o nospace -v"
|
||||||
|
done
|
||||||
|
|
||||||
# Kill completion
|
# Aliases
|
||||||
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
|
__fzf_defc unalias _fzf_alias_completion "-a"
|
||||||
|
|
||||||
# Host completion
|
# Processes
|
||||||
complete -F _fzf_complete_ssh -o default -o bashdefault ssh
|
__fzf_defc kill _fzf_proc_completion "-o default -o bashdefault"
|
||||||
complete -F _fzf_complete_telnet -o default -o bashdefault telnet
|
|
||||||
|
|
||||||
# Environment variables / Aliases
|
# ssh
|
||||||
complete -F _fzf_complete_unset -o default -o bashdefault unset
|
__fzf_defc ssh _fzf_complete_ssh "-o default -o bashdefault"
|
||||||
complete -F _fzf_complete_export -o default -o bashdefault export
|
|
||||||
complete -F _fzf_complete_unalias -o default -o bashdefault unalias
|
|
||||||
|
|
||||||
unset cmd d_cmds a_cmds x_cmds
|
unset cmd d_cmds a_cmds v_cmds
|
||||||
|
|
||||||
|
_fzf_setup_completion() {
|
||||||
|
local kind fn cmd
|
||||||
|
kind=$1
|
||||||
|
fn=_fzf_${1}_completion
|
||||||
|
if [[ $# -lt 2 ]] || ! type -t "$fn" > /dev/null; then
|
||||||
|
echo "usage: ${FUNCNAME[0]} path|dir|var|alias|host|proc COMMANDS..."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
__fzf_orig_completion < <(complete -p "$@" 2> /dev/null)
|
||||||
|
for cmd in "$@"; do
|
||||||
|
case "$kind" in
|
||||||
|
dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;
|
||||||
|
var) __fzf_defc "$cmd" "$fn" "-o default -o nospace -v" ;;
|
||||||
|
alias) __fzf_defc "$cmd" "$fn" "-a" ;;
|
||||||
|
*) __fzf_defc "$cmd" "$fn" "-o default -o bashdefault" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
fi
|
||||||
|
|||||||
@@ -1,69 +1,186 @@
|
|||||||
#!/bin/zsh
|
|
||||||
# ____ ____
|
# ____ ____
|
||||||
# / __/___ / __/
|
# / __/___ / __/
|
||||||
# / /_/_ / / /_
|
# / /_/_ / / /_
|
||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/-completion.zsh
|
# /_/ /___/_/ completion.zsh
|
||||||
#
|
#
|
||||||
# - $FZF_TMUX (default: 0)
|
# - $FZF_TMUX (default: 0)
|
||||||
# - $FZF_TMUX_HEIGHT (default: '40%')
|
# - $FZF_TMUX_OPTS (default: empty)
|
||||||
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
||||||
# - $FZF_COMPLETION_OPTS (default: empty)
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
||||||
|
# - $FZF_COMPLETION_PATH_OPTS (default: empty)
|
||||||
|
# - $FZF_COMPLETION_DIR_OPTS (default: empty)
|
||||||
|
|
||||||
|
|
||||||
|
# Both branches of the following `if` do the same thing -- define
|
||||||
|
# __fzf_completion_options such that `eval $__fzf_completion_options` sets
|
||||||
|
# all options to the same values they currently have. We'll do just that at
|
||||||
|
# the bottom of the file after changing options to what we prefer.
|
||||||
|
#
|
||||||
|
# IMPORTANT: Until we get to the `emulate` line, all words that *can* be quoted
|
||||||
|
# *must* be quoted in order to prevent alias expansion. In addition, code must
|
||||||
|
# be written in a way works with any set of zsh options. This is very tricky, so
|
||||||
|
# careful when you change it.
|
||||||
|
#
|
||||||
|
# Start by loading the builtin zsh/parameter module. It provides `options`
|
||||||
|
# associative array that stores current shell options.
|
||||||
|
if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then
|
||||||
|
# This is the fast branch and it gets taken on virtually all Zsh installations.
|
||||||
|
#
|
||||||
|
# ${(kv)options[@]} expands to array of keys (option names) and values ("on"
|
||||||
|
# or "off"). The subsequent expansion# with (j: :) flag joins all elements
|
||||||
|
# together separated by spaces. __fzf_completion_options ends up with a value
|
||||||
|
# like this: "options=(shwordsplit off aliases on ...)".
|
||||||
|
__fzf_completion_options="options=(${(j: :)${(kv)options[@]}})"
|
||||||
|
else
|
||||||
|
# This branch is much slower because it forks to get the names of all
|
||||||
|
# zsh options. It's possible to eliminate this fork but it's not worth the
|
||||||
|
# trouble because this branch gets taken only on very ancient or broken
|
||||||
|
# zsh installations.
|
||||||
|
() {
|
||||||
|
# That `()` above defines an anonymous function. This is essentially a scope
|
||||||
|
# for local parameters. We use it to avoid polluting global scope.
|
||||||
|
'local' '__fzf_opt'
|
||||||
|
__fzf_completion_options="setopt"
|
||||||
|
# `set -o` prints one line for every zsh option. Each line contains option
|
||||||
|
# name, some spaces, and then either "on" or "off". We just want option names.
|
||||||
|
# Expansion with (@f) flag splits a string into lines. The outer expansion
|
||||||
|
# removes spaces and everything that follow them on every line. __fzf_opt
|
||||||
|
# ends up iterating over option names: shwordsplit, aliases, etc.
|
||||||
|
for __fzf_opt in "${(@)${(@f)$(set -o)}%% *}"; do
|
||||||
|
if [[ -o "$__fzf_opt" ]]; then
|
||||||
|
# Option $__fzf_opt is currently on, so remember to set it back on.
|
||||||
|
__fzf_completion_options+=" -o $__fzf_opt"
|
||||||
|
else
|
||||||
|
# Option $__fzf_opt is currently off, so remember to set it back off.
|
||||||
|
__fzf_completion_options+=" +o $__fzf_opt"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# The value of __fzf_completion_options here looks like this:
|
||||||
|
# "setopt +o shwordsplit -o aliases ..."
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Enable the default zsh options (those marked with <Z> in `man zshoptions`)
|
||||||
|
# but without `aliases`. Aliases in functions are expanded when functions are
|
||||||
|
# defined, so if we disable aliases here, we'll be sure to have no pesky
|
||||||
|
# aliases in any of our functions. This way we won't need prefix every
|
||||||
|
# command with `command` or to quote every word to defend against global
|
||||||
|
# aliases. Note that `aliases` is not the only option that's important to
|
||||||
|
# control. There are several others that could wreck havoc if they are set
|
||||||
|
# to values we don't expect. With the following `emulate` command we
|
||||||
|
# sidestep this issue entirely.
|
||||||
|
'builtin' 'emulate' 'zsh' && 'builtin' 'setopt' 'no_aliases'
|
||||||
|
|
||||||
|
# This brace is the start of try-always block. The `always` part is like
|
||||||
|
# `finally` in lesser languages. We use it to *always* restore user options.
|
||||||
|
{
|
||||||
|
# The 'emulate' command should not be placed inside the interactive if check;
|
||||||
|
# placing it there fails to disable alias expansion. See #3731.
|
||||||
|
if [[ -o interactive ]]; then
|
||||||
|
|
||||||
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
||||||
if ! declare -f _fzf_compgen_path > /dev/null; then
|
#
|
||||||
_fzf_compgen_path() {
|
# _fzf_compgen_path() {
|
||||||
echo "$1"
|
# echo "$1"
|
||||||
command find -L "$1" \
|
# command find -L "$1" \
|
||||||
-name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
||||||
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
}
|
# }
|
||||||
fi
|
#
|
||||||
|
# _fzf_compgen_dir() {
|
||||||
if ! declare -f _fzf_compgen_dir > /dev/null; then
|
# command find -L "$1" \
|
||||||
_fzf_compgen_dir() {
|
# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \
|
||||||
command find -L "$1" \
|
# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
-name .git -prune -o -name .svn -prune -o -type d \
|
# }
|
||||||
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
|
||||||
}
|
|
||||||
fi
|
|
||||||
|
|
||||||
###########################################################
|
###########################################################
|
||||||
|
|
||||||
__fzfcmd_complete() {
|
__fzf_defaults() {
|
||||||
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] &&
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
||||||
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
|
}
|
||||||
|
|
||||||
|
__fzf_comprun() {
|
||||||
|
if [[ "$(type _fzf_comprun 2>&1)" =~ function ]]; then
|
||||||
|
_fzf_comprun "$@"
|
||||||
|
elif [ -n "${TMUX_PANE-}" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "${FZF_TMUX_OPTS-}" ]; }; then
|
||||||
|
shift
|
||||||
|
if [ -n "${FZF_TMUX_OPTS-}" ]; then
|
||||||
|
fzf-tmux ${(Q)${(Z+n+)FZF_TMUX_OPTS}} -- "$@"
|
||||||
|
else
|
||||||
|
fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%} -- "$@"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
shift
|
||||||
|
fzf "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extract the name of the command. e.g. foo=1 bar baz**<tab>
|
||||||
|
__fzf_extract_command() {
|
||||||
|
local token tokens
|
||||||
|
tokens=(${(z)1})
|
||||||
|
for token in $tokens; do
|
||||||
|
token=${(Q)token}
|
||||||
|
if [[ "$token" =~ [[:alnum:]] && ! "$token" =~ "=" ]]; then
|
||||||
|
echo "$token"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "${tokens[1]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_generic_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local base lbuf compgen fzf_opts suffix tail fzf dir leftover matches
|
local base lbuf cmd compgen fzf_opts suffix tail dir leftover matches
|
||||||
# (Q) flag removes a quoting level: "foo\ bar" => "foo bar"
|
base=$1
|
||||||
base=${(Q)1}
|
|
||||||
lbuf=$2
|
lbuf=$2
|
||||||
|
cmd=$(__fzf_extract_command "$lbuf")
|
||||||
compgen=$3
|
compgen=$3
|
||||||
fzf_opts=$4
|
fzf_opts=$4
|
||||||
suffix=$5
|
suffix=$5
|
||||||
tail=$6
|
tail=$6
|
||||||
fzf="$(__fzfcmd_complete)"
|
|
||||||
|
|
||||||
setopt localoptions nonomatch
|
setopt localoptions nonomatch
|
||||||
dir="$base"
|
if [[ $base = *'$('* ]] || [[ $base = *'<('* ]] || [[ $base = *'>('* ]] || [[ $base = *':='* ]] || [[ $base = *'`'* ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
eval "base=$base" 2> /dev/null || return
|
||||||
|
[[ $base = *"/"* ]] && dir="$base"
|
||||||
while [ 1 ]; do
|
while [ 1 ]; do
|
||||||
if [[ -z "$dir" || -d ${~dir} ]]; then
|
if [[ -z "$dir" || -d ${dir} ]]; then
|
||||||
leftover=${base/#"$dir"}
|
leftover=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ -z "$dir" ] && dir='.'
|
[ -z "$dir" ] && dir='.'
|
||||||
[ "$dir" != "/" ] && dir="${dir/%\//}"
|
[ "$dir" != "/" ] && dir="${dir/%\//}"
|
||||||
dir=${~dir}
|
matches=$(
|
||||||
matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "$leftover" | while read item; do
|
export FZF_DEFAULT_OPTS
|
||||||
echo -n "${(q)item}$suffix "
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-}")
|
||||||
done)
|
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
|
||||||
|
if declare -f "$compgen" > /dev/null; then
|
||||||
|
eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
|
||||||
|
else
|
||||||
|
if [[ $compgen =~ dir ]]; then
|
||||||
|
walker=dir,follow
|
||||||
|
rest=${FZF_COMPLETION_DIR_OPTS-}
|
||||||
|
else
|
||||||
|
walker=file,dir,follow,hidden
|
||||||
|
rest=${FZF_COMPLETION_PATH_OPTS-}
|
||||||
|
fi
|
||||||
|
__fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" ${(Q)${(Z+n+)rest}} < /dev/tty
|
||||||
|
fi | while read -r item; do
|
||||||
|
item="${item%$suffix}$suffix"
|
||||||
|
echo -n -E "${(q)item} "
|
||||||
|
done
|
||||||
|
)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
LBUFFER="$lbuf$matches$tail"
|
LBUFFER="$lbuf$matches$tail"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle reset-prompt
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
dir=$(dirname "$dir")
|
dir=$(dirname "$dir")
|
||||||
@@ -81,68 +198,119 @@ _fzf_dir_completion() {
|
|||||||
"" "/" ""
|
"" "/" ""
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_feed_fifo() (
|
_fzf_feed_fifo() {
|
||||||
command rm -f "$1"
|
command rm -f "$1"
|
||||||
mkfifo "$1"
|
mkfifo "$1"
|
||||||
cat <&0 > "$1" &
|
cat <&0 > "$1" &|
|
||||||
)
|
}
|
||||||
|
|
||||||
_fzf_complete() {
|
_fzf_complete() {
|
||||||
local fifo fzf_opts lbuf fzf matches post
|
setopt localoptions ksh_arrays
|
||||||
|
# Split arguments around --
|
||||||
|
local args rest str_arg i sep
|
||||||
|
args=("$@")
|
||||||
|
sep=
|
||||||
|
for i in {0..${#args[@]}}; do
|
||||||
|
if [[ "${args[$i]-}" = -- ]]; then
|
||||||
|
sep=$i
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [[ -n "$sep" ]]; then
|
||||||
|
str_arg=
|
||||||
|
rest=("${args[@]:$((sep + 1)):${#args[@]}}")
|
||||||
|
args=("${args[@]:0:$sep}")
|
||||||
|
else
|
||||||
|
str_arg=$1
|
||||||
|
args=()
|
||||||
|
shift
|
||||||
|
rest=("$@")
|
||||||
|
fi
|
||||||
|
|
||||||
|
local fifo lbuf cmd matches post
|
||||||
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
||||||
fzf_opts=$1
|
lbuf=${rest[0]}
|
||||||
lbuf=$2
|
cmd=$(__fzf_extract_command "$lbuf")
|
||||||
post="${funcstack[2]}_post"
|
post="${funcstack[1]}_post"
|
||||||
type $post > /dev/null 2>&1 || post=cat
|
type $post > /dev/null 2>&1 || post=cat
|
||||||
|
|
||||||
fzf="$(__fzfcmd_complete)"
|
|
||||||
|
|
||||||
_fzf_feed_fifo "$fifo"
|
_fzf_feed_fifo "$fifo"
|
||||||
matches=$(cat "$fifo" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_COMPLETION_OPTS" ${=fzf} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ')
|
matches=$(
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse" "${FZF_COMPLETION_OPTS-} $str_arg") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' \
|
||||||
|
__fzf_comprun "$cmd" "${args[@]}" -q "${(Q)prefix}" < "$fifo" | $post | tr '\n' ' ')
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
LBUFFER="$lbuf$matches"
|
LBUFFER="$lbuf$matches"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
||||||
command rm -f "$fifo"
|
command rm -f "$fifo"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# To use custom hostname lists, override __fzf_list_hosts.
|
||||||
|
# The function is expected to print hostnames, one per line as well as in the
|
||||||
|
# desired sorting and with any duplicates removed, to standard output.
|
||||||
|
if ! declare -f __fzf_list_hosts > /dev/null; then
|
||||||
|
__fzf_list_hosts() {
|
||||||
|
setopt localoptions nonomatch
|
||||||
|
command cat <(command tail -n +1 ~/.ssh/config ~/.ssh/config.d/* /etc/ssh/ssh_config 2> /dev/null | command grep -i '^\s*host\(name\)\? ' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}' | command grep -v '[*?%]') \
|
||||||
|
<(command grep -oE '^[[a-z0-9.,:-]+' ~/.ssh/known_hosts 2> /dev/null | tr ',' '\n' | tr -d '[' | awk '{ print $1 " " $1 }') \
|
||||||
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts 2> /dev/null | command grep -Fv '0.0.0.0' | command sed 's/#.*//') |
|
||||||
|
awk '{for (i = 2; i <= NF; i++) print $i}' | sort -u
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
_fzf_complete_telnet() {
|
_fzf_complete_telnet() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts)
|
||||||
command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' |
|
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The first and the only argument is the LBUFFER without the current word that contains the trigger.
|
||||||
|
# The current word without the trigger is in the $prefix variable passed from the caller.
|
||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
local -a tokens
|
||||||
command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*' | awk '{for (i = 2; i <= NF; i++) print $1 " " $i}') \
|
tokens=(${(z)1})
|
||||||
<(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
case ${tokens[-1]} in
|
||||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
-i|-F|-E)
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
_fzf_path_completion "$prefix" "$1"
|
||||||
)
|
;;
|
||||||
|
*)
|
||||||
|
local user
|
||||||
|
[[ $prefix =~ @ ]] && user="${prefix%%@*}@"
|
||||||
|
_fzf_complete +m -- "$@" < <(__fzf_list_hosts | awk -v user="$user" '{print user $0}')
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_export() {
|
_fzf_complete_export() {
|
||||||
_fzf_complete '-m' "$@" < <(
|
_fzf_complete -m -- "$@" < <(
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_unset() {
|
_fzf_complete_unset() {
|
||||||
_fzf_complete '-m' "$@" < <(
|
_fzf_complete -m -- "$@" < <(
|
||||||
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
declare -xp | sed 's/=.*//' | sed 's/.* //'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_unalias() {
|
_fzf_complete_unalias() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete +m -- "$@" < <(
|
||||||
alias | sed 's/=.*//'
|
alias | sed 's/=.*//'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_fzf_complete_kill() {
|
||||||
|
_fzf_complete -m --header-lines=1 --no-preview --wrap -- "$@" < <(
|
||||||
|
command ps -eo user,pid,ppid,start,time,command 2> /dev/null ||
|
||||||
|
command ps -eo user,pid,ppid,time,args 2> /dev/null || # For BusyBox
|
||||||
|
command ps --everyone --full --windows # For cygwin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
_fzf_complete_kill_post() {
|
||||||
|
awk '{print $2}'
|
||||||
|
}
|
||||||
|
|
||||||
fzf-completion() {
|
fzf-completion() {
|
||||||
local tokens cmd prefix trigger tail fzf matches lbuf d_cmds
|
local tokens cmd prefix trigger tail matches lbuf d_cmds
|
||||||
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
|
setopt localoptions noshwordsplit noksh_arrays noposixbuiltins
|
||||||
|
|
||||||
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
|
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
|
||||||
@@ -153,31 +321,34 @@ fzf-completion() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cmd=${tokens[1]}
|
cmd=$(__fzf_extract_command "$LBUFFER")
|
||||||
|
|
||||||
# Explicitly allow for empty trigger.
|
# Explicitly allow for empty trigger.
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
[ -z "$trigger" -a ${LBUFFER[-1]} = ' ' ] && tokens+=("")
|
[ -z "$trigger" -a ${LBUFFER[-1]} = ' ' ] && tokens+=("")
|
||||||
|
|
||||||
tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))}
|
# When the trigger starts with ';', it becomes a separate token
|
||||||
# Kill completion (do not require trigger sequence)
|
if [[ ${LBUFFER} = *"${tokens[-2]-}${tokens[-1]}" ]]; then
|
||||||
if [ $cmd = kill -a ${LBUFFER[-1]} = ' ' ]; then
|
tokens[-2]="${tokens[-2]-}${tokens[-1]}"
|
||||||
fzf="$(__fzfcmd_complete)"
|
tokens=(${tokens[0,-2]})
|
||||||
matches=$(ps -ef | sed 1d | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-50%} --min-height 15 --reverse $FZF_DEFAULT_OPTS --preview 'echo {}' --preview-window down:3:wrap $FZF_COMPLETION_OPTS" ${=fzf} -m | awk '{print $2}' | tr '\n' ' ')
|
|
||||||
if [ -n "$matches" ]; then
|
|
||||||
LBUFFER="$LBUFFER$matches"
|
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
lbuf=$LBUFFER
|
||||||
|
tail=${LBUFFER:$(( ${#LBUFFER} - ${#trigger} ))}
|
||||||
|
|
||||||
# Trigger sequence given
|
# Trigger sequence given
|
||||||
elif [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
|
if [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
|
||||||
d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir})
|
d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS-cd pushd rmdir})
|
||||||
|
|
||||||
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
||||||
[ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}}
|
if [[ $prefix = *'$('* ]] || [[ $prefix = *'<('* ]] || [[ $prefix = *'>('* ]] || [[ $prefix = *':='* ]] || [[ $prefix = *'`'* ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
[ -n "${tokens[-1]}" ] && lbuf=${lbuf:0:-${#tokens[-1]}}
|
||||||
|
|
||||||
if eval "type _fzf_complete_${cmd} > /dev/null"; then
|
if eval "type _fzf_complete_${cmd} > /dev/null"; then
|
||||||
eval "prefix=\"$prefix\" _fzf_complete_${cmd} \"$lbuf\""
|
prefix="$prefix" eval _fzf_complete_${cmd} ${(q)lbuf}
|
||||||
|
zle reset-prompt
|
||||||
elif [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then
|
elif [ ${d_cmds[(i)$cmd]} -le ${#d_cmds} ]; then
|
||||||
_fzf_dir_completion "$prefix" "$lbuf"
|
_fzf_dir_completion "$prefix" "$lbuf"
|
||||||
else
|
else
|
||||||
@@ -197,3 +368,10 @@ fzf-completion() {
|
|||||||
|
|
||||||
zle -N fzf-completion
|
zle -N fzf-completion
|
||||||
bindkey '^I' fzf-completion
|
bindkey '^I' fzf-completion
|
||||||
|
fi
|
||||||
|
|
||||||
|
} always {
|
||||||
|
# Restore the original options.
|
||||||
|
eval $__fzf_completion_options
|
||||||
|
'unset' '__fzf_completion_options'
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,121 +1,146 @@
|
|||||||
# Key bindings
|
# ____ ____
|
||||||
# ------------
|
# / __/___ / __/
|
||||||
__fzf_select__() {
|
# / /_/_ / / /_
|
||||||
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
# / __/ / /_/ __/
|
||||||
-o -type f -print \
|
# /_/ /___/_/ key-bindings.bash
|
||||||
-o -type d -print \
|
#
|
||||||
-o -type l -print 2> /dev/null | cut -b3-"}"
|
# - $FZF_TMUX_OPTS
|
||||||
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do
|
# - $FZF_CTRL_T_COMMAND
|
||||||
printf '%q ' "$item"
|
# - $FZF_CTRL_T_OPTS
|
||||||
done
|
# - $FZF_CTRL_R_OPTS
|
||||||
echo
|
# - $FZF_ALT_C_COMMAND
|
||||||
}
|
# - $FZF_ALT_C_OPTS
|
||||||
|
|
||||||
if [[ $- =~ i ]]; then
|
if [[ $- =~ i ]]; then
|
||||||
|
|
||||||
__fzf_use_tmux__() {
|
|
||||||
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
# Key bindings
|
||||||
|
# ------------
|
||||||
|
|
||||||
|
__fzf_defaults() {
|
||||||
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
||||||
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
|
}
|
||||||
|
|
||||||
|
__fzf_select__() {
|
||||||
|
FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" |
|
||||||
|
while read -r item; do
|
||||||
|
printf '%q ' "$item" # escape special chars
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzfcmd() {
|
__fzfcmd() {
|
||||||
__fzf_use_tmux__ &&
|
[[ -n "${TMUX_PANE-}" ]] && { [[ "${FZF_TMUX:-0}" != 0 ]] || [[ -n "${FZF_TMUX_OPTS-}" ]]; } &&
|
||||||
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
|
||||||
}
|
|
||||||
|
|
||||||
__fzf_select_tmux__() {
|
|
||||||
local height
|
|
||||||
height=${FZF_TMUX_HEIGHT:-40%}
|
|
||||||
if [[ $height =~ %$ ]]; then
|
|
||||||
height="-p ${height%\%}"
|
|
||||||
else
|
|
||||||
height="-l $height"
|
|
||||||
fi
|
|
||||||
|
|
||||||
tmux split-window $height "cd $(printf %q "$PWD"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__ --no-height)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fzf-file-widget() {
|
fzf-file-widget() {
|
||||||
if __fzf_use_tmux__; then
|
local selected="$(__fzf_select__ "$@")"
|
||||||
__fzf_select_tmux__
|
|
||||||
else
|
|
||||||
local selected="$(__fzf_select__)"
|
|
||||||
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
|
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
|
||||||
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
|
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_cd__() {
|
__fzf_cd__() {
|
||||||
local cmd dir
|
local dir
|
||||||
cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
dir=$(
|
||||||
-o -type d -print 2> /dev/null | cut -b3-"}"
|
FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \
|
||||||
dir=$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m) && printf 'cd %q' "$dir"
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd)
|
||||||
|
) && printf 'builtin cd -- %q' "$(builtin unset CDPATH && builtin cd -- "$dir" && builtin pwd)"
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_history__() (
|
if command -v perl > /dev/null; then
|
||||||
local line
|
__fzf_history__() {
|
||||||
shopt -u nocaseglob nocasematch
|
local output script
|
||||||
line=$(
|
script='BEGIN { getc; $/ = "\n\t"; $HISTCOUNT = $ENV{last_hist} + 1 } s/^[ *]//; s/\n/\n\t/gm; print $HISTCOUNT - $. . "\t$_" if !$seen{$_}++'
|
||||||
HISTTIMEFORMAT= history |
|
output=$(
|
||||||
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m" $(__fzfcmd) |
|
set +o pipefail
|
||||||
command grep '^ *[0-9]') &&
|
builtin fc -lnr -2147483648 |
|
||||||
if [[ $- =~ H ]]; then
|
last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" |
|
||||||
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
|
||||||
|
) || return
|
||||||
|
READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output")
|
||||||
|
if [[ -z "$READLINE_POINT" ]]; then
|
||||||
|
echo "$READLINE_LINE"
|
||||||
else
|
else
|
||||||
sed 's/^ *\([0-9]*\)\** *//' <<< "$line"
|
READLINE_POINT=0x7fffffff
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
else # awk - fallback for POSIX systems
|
||||||
|
__fzf_history__() {
|
||||||
|
local output script n x y z d
|
||||||
|
if [[ -z $__fzf_awk ]]; then
|
||||||
|
__fzf_awk=awk
|
||||||
|
# choose the faster mawk if: it's installed && build date >= 20230322 && version >= 1.3.4
|
||||||
|
IFS=' .' read n x y z d <<< $(command mawk -W version 2> /dev/null)
|
||||||
|
[[ $n == mawk ]] && (( d >= 20230302 && (x *1000 +y) *1000 +z >= 1003004 )) && __fzf_awk=mawk
|
||||||
|
fi
|
||||||
|
[[ $(HISTTIMEFORMAT='' builtin history 1) =~ [[:digit:]]+ ]] # how many history entries
|
||||||
|
script='function P(b) { ++n; sub(/^[ *]/, "", b); if (!seen[b]++) { printf "%d\t%s%c", '$((BASH_REMATCH + 1))' - n, b, 0 } }
|
||||||
|
NR==1 { b = substr($0, 2); next }
|
||||||
|
/^\t/ { P(b); b = substr($0, 2); next }
|
||||||
|
{ b = b RS $0 }
|
||||||
|
END { if (NR) P(b) }'
|
||||||
|
output=$(
|
||||||
|
set +o pipefail
|
||||||
|
builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '<lines>$'\n' )* ; <lines> ::= [^\n]* ( $'\n'<lines> )*
|
||||||
|
command $__fzf_awk "$script" | # ( <counter>$'\t'<lines>$'\000' )*
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE"
|
||||||
|
) || return
|
||||||
|
READLINE_LINE=${output#*$'\t'}
|
||||||
|
if [[ -z "$READLINE_POINT" ]]; then
|
||||||
|
echo "$READLINE_LINE"
|
||||||
|
else
|
||||||
|
READLINE_POINT=0x7fffffff
|
||||||
|
fi
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
)
|
|
||||||
|
|
||||||
if [[ ! -o vi ]]; then
|
|
||||||
# Required to refresh the prompt after fzf
|
# Required to refresh the prompt after fzf
|
||||||
bind '"\er": redraw-current-line'
|
bind -m emacs-standard '"\er": redraw-current-line'
|
||||||
bind '"\e^": history-expand-line'
|
|
||||||
|
|
||||||
|
bind -m vi-command '"\C-z": emacs-editing-mode'
|
||||||
|
bind -m vi-insert '"\C-z": emacs-editing-mode'
|
||||||
|
bind -m emacs-standard '"\C-z": vi-editing-mode'
|
||||||
|
|
||||||
|
if (( BASH_VERSINFO[0] < 4 )); then
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
if [ $BASH_VERSINFO -gt 3 ]; then
|
if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then
|
||||||
bind -x '"\C-t": "fzf-file-widget"'
|
bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
|
||||||
elif __fzf_use_tmux__; then
|
bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'
|
||||||
bind '"\C-t": " \C-u \C-a\C-k`__fzf_select_tmux__`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'
|
bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'
|
||||||
else
|
|
||||||
bind '"\C-t": " \C-u \C-a\C-k`__fzf_select__`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": " \C-e\C-u`__fzf_history__`\e\C-e\e^\er"'
|
bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"'
|
||||||
|
bind -m vi-command '"\C-r": "\C-z\C-r\C-z"'
|
||||||
# ALT-C - cd into the selected directory
|
bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"'
|
||||||
bind '"\ec": " \C-e\C-u`__fzf_cd__`\e\C-e\er\C-m"'
|
|
||||||
else
|
else
|
||||||
# We'd usually use "\e" to enter vi-movement-mode so we can do our magic,
|
|
||||||
# but this incurs a very noticeable delay of a half second or so,
|
|
||||||
# because many other commands start with "\e".
|
|
||||||
# Instead, we bind an unused key, "\C-x\C-a",
|
|
||||||
# to also enter vi-movement-mode,
|
|
||||||
# and then use that thereafter.
|
|
||||||
# (We imagine that "\C-x\C-a" is relatively unlikely to be in use.)
|
|
||||||
bind '"\C-x\C-a": vi-movement-mode'
|
|
||||||
|
|
||||||
bind '"\C-x\C-e": shell-expand-line'
|
|
||||||
bind '"\C-x\C-r": redraw-current-line'
|
|
||||||
bind '"\C-x^": history-expand-line'
|
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
# - FIXME: Selected items are attached to the end regardless of cursor position
|
if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then
|
||||||
if [ $BASH_VERSINFO -gt 3 ]; then
|
bind -m emacs-standard -x '"\C-t": fzf-file-widget'
|
||||||
bind -x '"\C-t": "fzf-file-widget"'
|
bind -m vi-command -x '"\C-t": fzf-file-widget'
|
||||||
elif __fzf_use_tmux__; then
|
bind -m vi-insert -x '"\C-t": fzf-file-widget'
|
||||||
bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select_tmux__`\C-x\C-e\C-x\C-a0P$xa"'
|
|
||||||
else
|
|
||||||
bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select__`\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "'
|
|
||||||
fi
|
fi
|
||||||
bind -m vi-command '"\C-t": "i\C-t"'
|
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": "\C-x\C-addi`__fzf_history__`\C-x\C-e\C-x^\C-x\C-a$a\C-x\C-r"'
|
bind -m emacs-standard -x '"\C-r": __fzf_history__'
|
||||||
bind -m vi-command '"\C-r": "i\C-r"'
|
bind -m vi-command -x '"\C-r": __fzf_history__'
|
||||||
|
bind -m vi-insert -x '"\C-r": __fzf_history__'
|
||||||
|
fi
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
bind '"\ec": "\C-x\C-addi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'
|
if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then
|
||||||
bind -m vi-command '"\ec": "ddi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'
|
bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"'
|
||||||
|
bind -m vi-command '"\ec": "\C-z\ec\C-z"'
|
||||||
|
bind -m vi-insert '"\ec": "\C-z\ec\C-z"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,25 +1,45 @@
|
|||||||
|
# ____ ____
|
||||||
|
# / __/___ / __/
|
||||||
|
# / /_/_ / / /_
|
||||||
|
# / __/ / /_/ __/
|
||||||
|
# /_/ /___/_/ key-bindings.fish
|
||||||
|
#
|
||||||
|
# - $FZF_TMUX_OPTS
|
||||||
|
# - $FZF_CTRL_T_COMMAND
|
||||||
|
# - $FZF_CTRL_T_OPTS
|
||||||
|
# - $FZF_CTRL_R_OPTS
|
||||||
|
# - $FZF_ALT_C_COMMAND
|
||||||
|
# - $FZF_ALT_C_OPTS
|
||||||
|
|
||||||
|
status is-interactive; or exit 0
|
||||||
|
|
||||||
|
|
||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
function fzf_key_bindings
|
function fzf_key_bindings
|
||||||
|
|
||||||
|
function __fzf_defaults
|
||||||
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
|
echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
|
||||||
|
command cat "$FZF_DEFAULT_OPTS_FILE" 2> /dev/null
|
||||||
|
echo $FZF_DEFAULT_OPTS $argv[2]
|
||||||
|
end
|
||||||
|
|
||||||
# Store current token in $dir as root for the 'find' command
|
# Store current token in $dir as root for the 'find' command
|
||||||
function fzf-file-widget -d "List files and folders"
|
function fzf-file-widget -d "List files and folders"
|
||||||
set -l commandline (__fzf_parse_commandline)
|
set -l commandline (__fzf_parse_commandline)
|
||||||
set -l dir $commandline[1]
|
set -lx dir $commandline[1]
|
||||||
set -l fzf_query $commandline[2]
|
set -l fzf_query $commandline[2]
|
||||||
|
set -l prefix $commandline[3]
|
||||||
|
|
||||||
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
# $dir itself, even if hidden.
|
|
||||||
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
|
||||||
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
|
||||||
-o -type f -print \
|
|
||||||
-o -type d -print \
|
|
||||||
-o -type l -print 2> /dev/null | sed 's@^\./@@'"
|
|
||||||
|
|
||||||
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
begin
|
begin
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
|
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_CTRL_T_OPTS")
|
||||||
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
|
set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"
|
||||||
|
set -lx FZF_DEFAULT_OPTS_FILE ''
|
||||||
|
eval (__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end
|
||||||
end
|
end
|
||||||
if [ -z "$result" ]
|
if [ -z "$result" ]
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
@@ -29,6 +49,7 @@ function fzf_key_bindings
|
|||||||
commandline -t ""
|
commandline -t ""
|
||||||
end
|
end
|
||||||
for i in $result
|
for i in $result
|
||||||
|
commandline -it -- $prefix
|
||||||
commandline -it -- (string escape $i)
|
commandline -it -- (string escape $i)
|
||||||
commandline -it -- ' '
|
commandline -it -- ' '
|
||||||
end
|
end
|
||||||
@@ -36,21 +57,33 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
|
|
||||||
function fzf-history-widget -d "Show command history"
|
function fzf-history-widget -d "Show command history"
|
||||||
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
begin
|
begin
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT $FZF_DEFAULT_OPTS --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS +m"
|
set -l FISH_MAJOR (echo $version | cut -f1 -d.)
|
||||||
|
set -l FISH_MINOR (echo $version | cut -f2 -d.)
|
||||||
|
|
||||||
set -l FISH_MAJOR (echo $FISH_VERSION | cut -f1 -d.)
|
# merge history from other sessions before searching
|
||||||
set -l FISH_MINOR (echo $FISH_VERSION | cut -f2 -d.)
|
if test -z "$fish_private_mode"
|
||||||
|
builtin history merge
|
||||||
|
end
|
||||||
|
|
||||||
# history's -z flag is needed for multi-line support.
|
# history's -z flag is needed for multi-line support.
|
||||||
# history's -z flag was added in fish 2.4.0, so don't use it for versions
|
# history's -z flag was added in fish 2.4.0, so don't use it for versions
|
||||||
# before 2.4.0.
|
# before 2.4.0.
|
||||||
if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
|
if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
|
||||||
history -z | eval (__fzfcmd) --read0 -q '(commandline)' | perl -pe 'chomp if eof' | read -lz result
|
if type -P perl > /dev/null 2>&1
|
||||||
|
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
|
||||||
|
set -lx FZF_DEFAULT_OPTS_FILE ''
|
||||||
|
builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | command perl -pe 's/^\d*\t//' | read -lz result
|
||||||
and commandline -- $result
|
and commandline -- $result
|
||||||
else
|
else
|
||||||
history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
|
||||||
|
set -lx FZF_DEFAULT_OPTS_FILE ''
|
||||||
|
builtin history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
|
||||||
|
and commandline -- $result
|
||||||
|
end
|
||||||
|
else
|
||||||
|
builtin history | eval (__fzfcmd) -q '(commandline)' | read -l result
|
||||||
and commandline -- $result
|
and commandline -- $result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -59,22 +92,23 @@ function fzf_key_bindings
|
|||||||
|
|
||||||
function fzf-cd-widget -d "Change directory"
|
function fzf-cd-widget -d "Change directory"
|
||||||
set -l commandline (__fzf_parse_commandline)
|
set -l commandline (__fzf_parse_commandline)
|
||||||
set -l dir $commandline[1]
|
set -lx dir $commandline[1]
|
||||||
set -l fzf_query $commandline[2]
|
set -l fzf_query $commandline[2]
|
||||||
|
set -l prefix $commandline[3]
|
||||||
|
|
||||||
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
|
|
||||||
-o -type d -print 2> /dev/null | sed 's@^\./@@'"
|
|
||||||
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
|
||||||
begin
|
begin
|
||||||
set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"
|
set -lx FZF_DEFAULT_OPTS (__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path --walker-root='$dir'" "$FZF_ALT_C_OPTS")
|
||||||
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
|
set -lx FZF_DEFAULT_OPTS_FILE ''
|
||||||
|
set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"
|
||||||
|
eval (__fzfcmd)' +m --query "'$fzf_query'"' | read -l result
|
||||||
|
|
||||||
if [ -n "$result" ]
|
if [ -n "$result" ]
|
||||||
cd $result
|
cd -- $result
|
||||||
|
|
||||||
# Remove last token from commandline.
|
# Remove last token from commandline.
|
||||||
commandline -t ""
|
commandline -t ""
|
||||||
|
commandline -it -- $prefix
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -82,28 +116,44 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
|
|
||||||
function __fzfcmd
|
function __fzfcmd
|
||||||
set -q FZF_TMUX; or set FZF_TMUX 0
|
test -n "$FZF_TMUX"; or set FZF_TMUX 0
|
||||||
set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%
|
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
|
||||||
if [ $FZF_TMUX -eq 1 ]
|
if [ -n "$FZF_TMUX_OPTS" ]
|
||||||
echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
|
echo "fzf-tmux $FZF_TMUX_OPTS -- "
|
||||||
|
else if [ $FZF_TMUX -eq 1 ]
|
||||||
|
echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
|
||||||
else
|
else
|
||||||
echo "fzf"
|
echo "fzf"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
bind \ct fzf-file-widget
|
|
||||||
bind \cr fzf-history-widget
|
bind \cr fzf-history-widget
|
||||||
|
if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
|
||||||
|
bind \ct fzf-file-widget
|
||||||
|
end
|
||||||
|
if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
|
||||||
bind \ec fzf-cd-widget
|
bind \ec fzf-cd-widget
|
||||||
|
|
||||||
if bind -M insert > /dev/null 2>&1
|
|
||||||
bind -M insert \ct fzf-file-widget
|
|
||||||
bind -M insert \cr fzf-history-widget
|
|
||||||
bind -M insert \ec fzf-cd-widget
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token'
|
if bind -M insert > /dev/null 2>&1
|
||||||
|
bind -M insert \cr fzf-history-widget
|
||||||
|
if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
|
||||||
|
bind -M insert \ct fzf-file-widget
|
||||||
|
end
|
||||||
|
if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"
|
||||||
|
bind -M insert \ec fzf-cd-widget
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
|
||||||
|
set -l commandline (commandline -t)
|
||||||
|
|
||||||
|
# strip -option= from token if present
|
||||||
|
set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
|
||||||
|
set commandline (string replace -- "$prefix" '' $commandline)
|
||||||
|
|
||||||
# eval is used to do shell expansion on paths
|
# eval is used to do shell expansion on paths
|
||||||
set -l commandline (eval "printf '%s' "(commandline -t))
|
eval set commandline $commandline
|
||||||
|
|
||||||
if [ -z $commandline ]
|
if [ -z $commandline ]
|
||||||
# Default to current directory with no --query
|
# Default to current directory with no --query
|
||||||
@@ -112,32 +162,33 @@ function fzf_key_bindings
|
|||||||
else
|
else
|
||||||
set dir (__fzf_get_dir $commandline)
|
set dir (__fzf_get_dir $commandline)
|
||||||
|
|
||||||
if [ "$dir" = "." -a (string sub -l 1 $commandline) != '.' ]
|
if [ "$dir" = "." -a (string sub -l 1 -- $commandline) != '.' ]
|
||||||
# if $dir is "." but commandline is not a relative path, this means no file path found
|
# if $dir is "." but commandline is not a relative path, this means no file path found
|
||||||
set fzf_query $commandline
|
set fzf_query $commandline
|
||||||
else
|
else
|
||||||
# Also remove trailing slash after dir, to "split" input properly
|
# Also remove trailing slash after dir, to "split" input properly
|
||||||
set fzf_query (string replace -r "^$dir/?" '' "$commandline")
|
set fzf_query (string replace -r "^$dir/?" -- '' "$commandline")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
echo $dir
|
echo $dir
|
||||||
echo $fzf_query
|
echo $fzf_query
|
||||||
|
echo $prefix
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
function __fzf_get_dir -d 'Find the longest existing filepath from input string'
|
||||||
set dir $argv
|
set dir $argv
|
||||||
|
|
||||||
# Strip all trailing slashes. Ignore if $dir is root dir (/)
|
# Strip all trailing slashes. Ignore if $dir is root dir (/)
|
||||||
if [ (string length $dir) -gt 1 ]
|
if [ (string length -- $dir) -gt 1 ]
|
||||||
set dir (string replace -r '/*$' '' $dir)
|
set dir (string replace -r '/*$' -- '' $dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iteratively check if dir exists and strip tail end of path
|
# Iteratively check if dir exists and strip tail end of path
|
||||||
while [ ! -d "$dir" ]
|
while [ ! -d "$dir" ]
|
||||||
# If path is absolute, this can keep going until ends up at /
|
# If path is absolute, this can keep going until ends up at /
|
||||||
# If path is relative, this can keep going until entire input is consumed, dirname returns "."
|
# If path is relative, this can keep going until entire input is consumed, dirname returns "."
|
||||||
set dir (dirname "$dir")
|
set dir (dirname -- "$dir")
|
||||||
end
|
end
|
||||||
|
|
||||||
echo $dir
|
echo $dir
|
||||||
|
|||||||
@@ -1,78 +1,143 @@
|
|||||||
|
# ____ ____
|
||||||
|
# / __/___ / __/
|
||||||
|
# / /_/_ / / /_
|
||||||
|
# / __/ / /_/ __/
|
||||||
|
# /_/ /___/_/ key-bindings.zsh
|
||||||
|
#
|
||||||
|
# - $FZF_TMUX_OPTS
|
||||||
|
# - $FZF_CTRL_T_COMMAND
|
||||||
|
# - $FZF_CTRL_T_OPTS
|
||||||
|
# - $FZF_CTRL_R_OPTS
|
||||||
|
# - $FZF_ALT_C_COMMAND
|
||||||
|
# - $FZF_ALT_C_OPTS
|
||||||
|
|
||||||
|
|
||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
if [[ $- == *i* ]]; then
|
|
||||||
|
# The code at the top and the bottom of this file is the same as in completion.zsh.
|
||||||
|
# Refer to that file for explanation.
|
||||||
|
if 'zmodload' 'zsh/parameter' 2>'/dev/null' && (( ${+options} )); then
|
||||||
|
__fzf_key_bindings_options="options=(${(j: :)${(kv)options[@]}})"
|
||||||
|
else
|
||||||
|
() {
|
||||||
|
__fzf_key_bindings_options="setopt"
|
||||||
|
'local' '__fzf_opt'
|
||||||
|
for __fzf_opt in "${(@)${(@f)$(set -o)}%% *}"; do
|
||||||
|
if [[ -o "$__fzf_opt" ]]; then
|
||||||
|
__fzf_key_bindings_options+=" -o $__fzf_opt"
|
||||||
|
else
|
||||||
|
__fzf_key_bindings_options+=" +o $__fzf_opt"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
'builtin' 'emulate' 'zsh' && 'builtin' 'setopt' 'no_aliases'
|
||||||
|
|
||||||
|
{
|
||||||
|
if [[ -o interactive ]]; then
|
||||||
|
|
||||||
|
__fzf_defaults() {
|
||||||
|
# $1: Prepend to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
|
||||||
|
echo "--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore $1"
|
||||||
|
command cat "${FZF_DEFAULT_OPTS_FILE-}" 2> /dev/null
|
||||||
|
echo "${FZF_DEFAULT_OPTS-} $2"
|
||||||
|
}
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path(s) into the command line
|
# CTRL-T - Paste the selected file path(s) into the command line
|
||||||
__fsel() {
|
__fzf_select() {
|
||||||
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
setopt localoptions pipefail no_aliases 2> /dev/null
|
||||||
-o -type f -print \
|
local item
|
||||||
-o -type d -print \
|
FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} \
|
||||||
-o -type l -print 2> /dev/null | cut -b3-"}"
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=file,dir,follow,hidden --scheme=path" "${FZF_CTRL_T_OPTS-} -m") \
|
||||||
setopt localoptions pipefail 2> /dev/null
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) "$@" < /dev/tty | while read -r item; do
|
||||||
eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read item; do
|
echo -n -E "${(q)item} "
|
||||||
echo -n "${(q)item} "
|
|
||||||
done
|
done
|
||||||
local ret=$?
|
local ret=$?
|
||||||
echo
|
echo
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_use_tmux__() {
|
|
||||||
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
|
||||||
}
|
|
||||||
|
|
||||||
__fzfcmd() {
|
__fzfcmd() {
|
||||||
__fzf_use_tmux__ &&
|
[ -n "${TMUX_PANE-}" ] && { [ "${FZF_TMUX:-0}" != 0 ] || [ -n "${FZF_TMUX_OPTS-}" ]; } &&
|
||||||
echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
|
||||||
}
|
}
|
||||||
|
|
||||||
fzf-file-widget() {
|
fzf-file-widget() {
|
||||||
LBUFFER="${LBUFFER}$(__fsel)"
|
LBUFFER="${LBUFFER}$(__fzf_select)"
|
||||||
local ret=$?
|
local ret=$?
|
||||||
zle redisplay
|
zle reset-prompt
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then
|
||||||
zle -N fzf-file-widget
|
zle -N fzf-file-widget
|
||||||
bindkey '^T' fzf-file-widget
|
bindkey -M emacs '^T' fzf-file-widget
|
||||||
|
bindkey -M vicmd '^T' fzf-file-widget
|
||||||
|
bindkey -M viins '^T' fzf-file-widget
|
||||||
|
fi
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
fzf-cd-widget() {
|
fzf-cd-widget() {
|
||||||
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \
|
setopt localoptions pipefail no_aliases 2> /dev/null
|
||||||
-o -type d -print 2> /dev/null | cut -b3-"}"
|
local dir="$(
|
||||||
setopt localoptions pipefail 2> /dev/null
|
FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} \
|
||||||
local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --walker=dir,follow,hidden --scheme=path" "${FZF_ALT_C_OPTS-} +m") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) < /dev/tty)"
|
||||||
if [[ -z "$dir" ]]; then
|
if [[ -z "$dir" ]]; then
|
||||||
zle redisplay
|
zle redisplay
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
cd "$dir"
|
zle push-line # Clear buffer. Auto-restored on next prompt.
|
||||||
|
BUFFER="builtin cd -- ${(q)dir:a}"
|
||||||
|
zle accept-line
|
||||||
local ret=$?
|
local ret=$?
|
||||||
|
unset dir # ensure this doesn't end up appearing in prompt expansion
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then
|
||||||
zle -N fzf-cd-widget
|
zle -N fzf-cd-widget
|
||||||
bindkey '\ec' fzf-cd-widget
|
bindkey -M emacs '\ec' fzf-cd-widget
|
||||||
|
bindkey -M vicmd '\ec' fzf-cd-widget
|
||||||
|
bindkey -M viins '\ec' fzf-cd-widget
|
||||||
|
fi
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
fzf-history-widget() {
|
fzf-history-widget() {
|
||||||
local selected num
|
local selected
|
||||||
setopt localoptions noglobsubst noposixbuiltins pipefail 2> /dev/null
|
setopt localoptions noglobsubst noposixbuiltins pipefail no_aliases noglob nobash_rematch 2> /dev/null
|
||||||
selected=( $(fc -l 1 |
|
# Ensure the associative history array, which maps event numbers to the full
|
||||||
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $FZF_CTRL_R_OPTS --query=${(qqq)LBUFFER} +m" $(__fzfcmd)) )
|
# history lines, is loaded, and that Perl is installed for multi-line output.
|
||||||
|
if zmodload -F zsh/parameter p:history 2>/dev/null && (( ${#commands[perl]} )); then
|
||||||
|
selected="$(printf '%s\t%s\000' "${(kv)history[@]}" |
|
||||||
|
perl -0 -ne 'if (!$seen{(/^\s*[0-9]+\**\t(.*)/s, $1)}++) { s/\n/\n\t/g; print; }' |
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m --read0") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))"
|
||||||
|
else
|
||||||
|
selected="$(fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' |
|
||||||
|
FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m") \
|
||||||
|
FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))"
|
||||||
|
fi
|
||||||
local ret=$?
|
local ret=$?
|
||||||
if [ -n "$selected" ]; then
|
if [ -n "$selected" ]; then
|
||||||
num=$selected[1]
|
if [[ $(awk '{print $1; exit}' <<< "$selected") =~ ^[1-9][0-9]* ]]; then
|
||||||
if [ -n "$num" ]; then
|
zle vi-fetch-history -n $MATCH
|
||||||
zle vi-fetch-history -n $num
|
else # selected is a custom query, not from history
|
||||||
|
LBUFFER="$selected"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle reset-prompt
|
||||||
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
zle -N fzf-history-widget
|
zle -N fzf-history-widget
|
||||||
bindkey '^R' fzf-history-widget
|
bindkey -M emacs '^R' fzf-history-widget
|
||||||
|
bindkey -M vicmd '^R' fzf-history-widget
|
||||||
|
bindkey -M viins '^R' fzf-history-widget
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
} always {
|
||||||
|
eval $__fzf_key_bindings_options
|
||||||
|
'unset' '__fzf_key_bindings_options'
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2017 Junegunn Choi
|
Copyright (c) 2013-2024 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
135
src/actiontype_string.go
Normal file
135
src/actiontype_string.go
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
// Code generated by "stringer -type=actionType"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[actIgnore-0]
|
||||||
|
_ = x[actStart-1]
|
||||||
|
_ = x[actClick-2]
|
||||||
|
_ = x[actInvalid-3]
|
||||||
|
_ = x[actChar-4]
|
||||||
|
_ = x[actMouse-5]
|
||||||
|
_ = x[actBeginningOfLine-6]
|
||||||
|
_ = x[actAbort-7]
|
||||||
|
_ = x[actAccept-8]
|
||||||
|
_ = x[actAcceptNonEmpty-9]
|
||||||
|
_ = x[actAcceptOrPrintQuery-10]
|
||||||
|
_ = x[actBackwardChar-11]
|
||||||
|
_ = x[actBackwardDeleteChar-12]
|
||||||
|
_ = x[actBackwardDeleteCharEof-13]
|
||||||
|
_ = x[actBackwardWord-14]
|
||||||
|
_ = x[actCancel-15]
|
||||||
|
_ = x[actChangeBorderLabel-16]
|
||||||
|
_ = x[actChangeHeader-17]
|
||||||
|
_ = x[actChangeMulti-18]
|
||||||
|
_ = x[actChangePreviewLabel-19]
|
||||||
|
_ = x[actChangePrompt-20]
|
||||||
|
_ = x[actChangeQuery-21]
|
||||||
|
_ = x[actClearScreen-22]
|
||||||
|
_ = x[actClearQuery-23]
|
||||||
|
_ = x[actClearSelection-24]
|
||||||
|
_ = x[actClose-25]
|
||||||
|
_ = x[actDeleteChar-26]
|
||||||
|
_ = x[actDeleteCharEof-27]
|
||||||
|
_ = x[actEndOfLine-28]
|
||||||
|
_ = x[actFatal-29]
|
||||||
|
_ = x[actForwardChar-30]
|
||||||
|
_ = x[actForwardWord-31]
|
||||||
|
_ = x[actKillLine-32]
|
||||||
|
_ = x[actKillWord-33]
|
||||||
|
_ = x[actUnixLineDiscard-34]
|
||||||
|
_ = x[actUnixWordRubout-35]
|
||||||
|
_ = x[actYank-36]
|
||||||
|
_ = x[actBackwardKillWord-37]
|
||||||
|
_ = x[actSelectAll-38]
|
||||||
|
_ = x[actDeselectAll-39]
|
||||||
|
_ = x[actToggle-40]
|
||||||
|
_ = x[actToggleSearch-41]
|
||||||
|
_ = x[actToggleAll-42]
|
||||||
|
_ = x[actToggleDown-43]
|
||||||
|
_ = x[actToggleUp-44]
|
||||||
|
_ = x[actToggleIn-45]
|
||||||
|
_ = x[actToggleOut-46]
|
||||||
|
_ = x[actToggleTrack-47]
|
||||||
|
_ = x[actToggleTrackCurrent-48]
|
||||||
|
_ = x[actToggleHeader-49]
|
||||||
|
_ = x[actToggleWrap-50]
|
||||||
|
_ = x[actTrackCurrent-51]
|
||||||
|
_ = x[actUntrackCurrent-52]
|
||||||
|
_ = x[actDown-53]
|
||||||
|
_ = x[actUp-54]
|
||||||
|
_ = x[actPageUp-55]
|
||||||
|
_ = x[actPageDown-56]
|
||||||
|
_ = x[actPosition-57]
|
||||||
|
_ = x[actHalfPageUp-58]
|
||||||
|
_ = x[actHalfPageDown-59]
|
||||||
|
_ = x[actOffsetUp-60]
|
||||||
|
_ = x[actOffsetDown-61]
|
||||||
|
_ = x[actOffsetMiddle-62]
|
||||||
|
_ = x[actJump-63]
|
||||||
|
_ = x[actJumpAccept-64]
|
||||||
|
_ = x[actPrintQuery-65]
|
||||||
|
_ = x[actRefreshPreview-66]
|
||||||
|
_ = x[actReplaceQuery-67]
|
||||||
|
_ = x[actToggleSort-68]
|
||||||
|
_ = x[actShowPreview-69]
|
||||||
|
_ = x[actHidePreview-70]
|
||||||
|
_ = x[actTogglePreview-71]
|
||||||
|
_ = x[actTogglePreviewWrap-72]
|
||||||
|
_ = x[actTransform-73]
|
||||||
|
_ = x[actTransformBorderLabel-74]
|
||||||
|
_ = x[actTransformHeader-75]
|
||||||
|
_ = x[actTransformPreviewLabel-76]
|
||||||
|
_ = x[actTransformPrompt-77]
|
||||||
|
_ = x[actTransformQuery-78]
|
||||||
|
_ = x[actPreview-79]
|
||||||
|
_ = x[actChangePreview-80]
|
||||||
|
_ = x[actChangePreviewWindow-81]
|
||||||
|
_ = x[actPreviewTop-82]
|
||||||
|
_ = x[actPreviewBottom-83]
|
||||||
|
_ = x[actPreviewUp-84]
|
||||||
|
_ = x[actPreviewDown-85]
|
||||||
|
_ = x[actPreviewPageUp-86]
|
||||||
|
_ = x[actPreviewPageDown-87]
|
||||||
|
_ = x[actPreviewHalfPageUp-88]
|
||||||
|
_ = x[actPreviewHalfPageDown-89]
|
||||||
|
_ = x[actPrevHistory-90]
|
||||||
|
_ = x[actPrevSelected-91]
|
||||||
|
_ = x[actPrint-92]
|
||||||
|
_ = x[actPut-93]
|
||||||
|
_ = x[actNextHistory-94]
|
||||||
|
_ = x[actNextSelected-95]
|
||||||
|
_ = x[actExecute-96]
|
||||||
|
_ = x[actExecuteSilent-97]
|
||||||
|
_ = x[actExecuteMulti-98]
|
||||||
|
_ = x[actSigStop-99]
|
||||||
|
_ = x[actFirst-100]
|
||||||
|
_ = x[actLast-101]
|
||||||
|
_ = x[actReload-102]
|
||||||
|
_ = x[actReloadSync-103]
|
||||||
|
_ = x[actDisableSearch-104]
|
||||||
|
_ = x[actEnableSearch-105]
|
||||||
|
_ = x[actSelect-106]
|
||||||
|
_ = x[actDeselect-107]
|
||||||
|
_ = x[actUnbind-108]
|
||||||
|
_ = x[actRebind-109]
|
||||||
|
_ = x[actBecome-110]
|
||||||
|
_ = x[actShowHeader-111]
|
||||||
|
_ = x[actHideHeader-112]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _actionType_name = "actIgnoreactStartactClickactInvalidactCharactMouseactBeginningOfLineactAbortactAcceptactAcceptNonEmptyactAcceptOrPrintQueryactBackwardCharactBackwardDeleteCharactBackwardDeleteCharEofactBackwardWordactCancelactChangeBorderLabelactChangeHeaderactChangeMultiactChangePreviewLabelactChangePromptactChangeQueryactClearScreenactClearQueryactClearSelectionactCloseactDeleteCharactDeleteCharEofactEndOfLineactFatalactForwardCharactForwardWordactKillLineactKillWordactUnixLineDiscardactUnixWordRuboutactYankactBackwardKillWordactSelectAllactDeselectAllactToggleactToggleSearchactToggleAllactToggleDownactToggleUpactToggleInactToggleOutactToggleTrackactToggleTrackCurrentactToggleHeaderactToggleWrapactTrackCurrentactUntrackCurrentactDownactUpactPageUpactPageDownactPositionactHalfPageUpactHalfPageDownactOffsetUpactOffsetDownactOffsetMiddleactJumpactJumpAcceptactPrintQueryactRefreshPreviewactReplaceQueryactToggleSortactShowPreviewactHidePreviewactTogglePreviewactTogglePreviewWrapactTransformactTransformBorderLabelactTransformHeaderactTransformPreviewLabelactTransformPromptactTransformQueryactPreviewactChangePreviewactChangePreviewWindowactPreviewTopactPreviewBottomactPreviewUpactPreviewDownactPreviewPageUpactPreviewPageDownactPreviewHalfPageUpactPreviewHalfPageDownactPrevHistoryactPrevSelectedactPrintactPutactNextHistoryactNextSelectedactExecuteactExecuteSilentactExecuteMultiactSigStopactFirstactLastactReloadactReloadSyncactDisableSearchactEnableSearchactSelectactDeselectactUnbindactRebindactBecomeactShowHeaderactHideHeader"
|
||||||
|
|
||||||
|
var _actionType_index = [...]uint16{0, 9, 17, 25, 35, 42, 50, 68, 76, 85, 102, 123, 138, 159, 183, 198, 207, 227, 242, 256, 277, 292, 306, 320, 333, 350, 358, 371, 387, 399, 407, 421, 435, 446, 457, 475, 492, 499, 518, 530, 544, 553, 568, 580, 593, 604, 615, 627, 641, 662, 677, 690, 705, 722, 729, 734, 743, 754, 765, 778, 793, 804, 817, 832, 839, 852, 865, 882, 897, 910, 924, 938, 954, 974, 986, 1009, 1027, 1051, 1069, 1086, 1096, 1112, 1134, 1147, 1163, 1175, 1189, 1205, 1223, 1243, 1265, 1279, 1294, 1302, 1308, 1322, 1337, 1347, 1363, 1378, 1388, 1396, 1403, 1412, 1425, 1441, 1456, 1465, 1476, 1485, 1494, 1503, 1516, 1529}
|
||||||
|
|
||||||
|
func (i actionType) String() string {
|
||||||
|
if i < 0 || i >= actionType(len(_actionType_index)-1) {
|
||||||
|
return "actionType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _actionType_name[_actionType_index[i]:_actionType_index[i+1]]
|
||||||
|
}
|
||||||
319
src/algo/algo.go
319
src/algo/algo.go
@@ -80,6 +80,7 @@ Scoring criteria
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -89,6 +90,10 @@ import (
|
|||||||
|
|
||||||
var DEBUG bool
|
var DEBUG bool
|
||||||
|
|
||||||
|
var delimiterChars = "/,:;|"
|
||||||
|
|
||||||
|
const whiteChars = " \t\n\v\f\r\x85\xA0"
|
||||||
|
|
||||||
func indexAt(index int, max int, forward bool) int {
|
func indexAt(index int, max int, forward bool) int {
|
||||||
if forward {
|
if forward {
|
||||||
return index
|
return index
|
||||||
@@ -107,7 +112,7 @@ type Result struct {
|
|||||||
const (
|
const (
|
||||||
scoreMatch = 16
|
scoreMatch = 16
|
||||||
scoreGapStart = -3
|
scoreGapStart = -3
|
||||||
scoreGapExtention = -1
|
scoreGapExtension = -1
|
||||||
|
|
||||||
// We prefer matches at the beginning of a word, but the bonus should not be
|
// We prefer matches at the beginning of a word, but the bonus should not be
|
||||||
// too great to prevent the longer acronym matches from always winning over
|
// too great to prevent the longer acronym matches from always winning over
|
||||||
@@ -125,31 +130,93 @@ const (
|
|||||||
// Edge-triggered bonus for matches in camelCase words.
|
// Edge-triggered bonus for matches in camelCase words.
|
||||||
// Compared to word-boundary case, they don't accompany single-character gaps
|
// Compared to word-boundary case, they don't accompany single-character gaps
|
||||||
// (e.g. FooBar vs. foo-bar), so we deduct bonus point accordingly.
|
// (e.g. FooBar vs. foo-bar), so we deduct bonus point accordingly.
|
||||||
bonusCamel123 = bonusBoundary + scoreGapExtention
|
bonusCamel123 = bonusBoundary + scoreGapExtension
|
||||||
|
|
||||||
// Minimum bonus point given to characters in consecutive chunks.
|
// Minimum bonus point given to characters in consecutive chunks.
|
||||||
// Note that bonus points for consecutive matches shouldn't have needed if we
|
// Note that bonus points for consecutive matches shouldn't have needed if we
|
||||||
// used fixed match score as in the original algorithm.
|
// used fixed match score as in the original algorithm.
|
||||||
bonusConsecutive = -(scoreGapStart + scoreGapExtention)
|
bonusConsecutive = -(scoreGapStart + scoreGapExtension)
|
||||||
|
|
||||||
// The first character in the typed pattern usually has more significance
|
// The first character in the typed pattern usually has more significance
|
||||||
// than the rest so it's important that it appears at special positions where
|
// than the rest so it's important that it appears at special positions where
|
||||||
// bonus points are given. e.g. "to-go" vs. "ongoing" on "og" or on "ogo".
|
// bonus points are given, e.g. "to-go" vs. "ongoing" on "og" or on "ogo".
|
||||||
// The amount of the extra bonus should be limited so that the gap penalty is
|
// The amount of the extra bonus should be limited so that the gap penalty is
|
||||||
// still respected.
|
// still respected.
|
||||||
bonusFirstCharMultiplier = 2
|
bonusFirstCharMultiplier = 2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Extra bonus for word boundary after whitespace character or beginning of the string
|
||||||
|
bonusBoundaryWhite int16 = bonusBoundary + 2
|
||||||
|
|
||||||
|
// Extra bonus for word boundary after slash, colon, semi-colon, and comma
|
||||||
|
bonusBoundaryDelimiter int16 = bonusBoundary + 1
|
||||||
|
|
||||||
|
initialCharClass = charWhite
|
||||||
|
|
||||||
|
// A minor optimization that can give 15%+ performance boost
|
||||||
|
asciiCharClasses [unicode.MaxASCII + 1]charClass
|
||||||
|
|
||||||
|
// A minor optimization that can give yet another 5% performance boost
|
||||||
|
bonusMatrix [charNumber + 1][charNumber + 1]int16
|
||||||
|
)
|
||||||
|
|
||||||
type charClass int
|
type charClass int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
charNonWord charClass = iota
|
charWhite charClass = iota
|
||||||
|
charNonWord
|
||||||
|
charDelimiter
|
||||||
charLower
|
charLower
|
||||||
charUpper
|
charUpper
|
||||||
charLetter
|
charLetter
|
||||||
charNumber
|
charNumber
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func Init(scheme string) bool {
|
||||||
|
switch scheme {
|
||||||
|
case "default":
|
||||||
|
bonusBoundaryWhite = bonusBoundary + 2
|
||||||
|
bonusBoundaryDelimiter = bonusBoundary + 1
|
||||||
|
case "path":
|
||||||
|
bonusBoundaryWhite = bonusBoundary
|
||||||
|
bonusBoundaryDelimiter = bonusBoundary + 1
|
||||||
|
if os.PathSeparator == '/' {
|
||||||
|
delimiterChars = "/"
|
||||||
|
} else {
|
||||||
|
delimiterChars = string([]rune{os.PathSeparator, '/'})
|
||||||
|
}
|
||||||
|
initialCharClass = charDelimiter
|
||||||
|
case "history":
|
||||||
|
bonusBoundaryWhite = bonusBoundary
|
||||||
|
bonusBoundaryDelimiter = bonusBoundary
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for i := 0; i <= unicode.MaxASCII; i++ {
|
||||||
|
char := rune(i)
|
||||||
|
c := charNonWord
|
||||||
|
if char >= 'a' && char <= 'z' {
|
||||||
|
c = charLower
|
||||||
|
} else if char >= 'A' && char <= 'Z' {
|
||||||
|
c = charUpper
|
||||||
|
} else if char >= '0' && char <= '9' {
|
||||||
|
c = charNumber
|
||||||
|
} else if strings.ContainsRune(whiteChars, char) {
|
||||||
|
c = charWhite
|
||||||
|
} else if strings.ContainsRune(delimiterChars, char) {
|
||||||
|
c = charDelimiter
|
||||||
|
}
|
||||||
|
asciiCharClasses[i] = c
|
||||||
|
}
|
||||||
|
for i := 0; i <= int(charNumber); i++ {
|
||||||
|
for j := 0; j <= int(charNumber); j++ {
|
||||||
|
bonusMatrix[i][j] = bonusFor(charClass(i), charClass(j))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func posArray(withPos bool, len int) *[]int {
|
func posArray(withPos bool, len int) *[]int {
|
||||||
if withPos {
|
if withPos {
|
||||||
pos := make([]int, 0, len)
|
pos := make([]int, 0, len)
|
||||||
@@ -174,17 +241,6 @@ func alloc32(offset int, slab *util.Slab, size int) (int, []int32) {
|
|||||||
return offset, make([]int32, size)
|
return offset, make([]int32, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func charClassOfAscii(char rune) charClass {
|
|
||||||
if char >= 'a' && char <= 'z' {
|
|
||||||
return charLower
|
|
||||||
} else if char >= 'A' && char <= 'Z' {
|
|
||||||
return charUpper
|
|
||||||
} else if char >= '0' && char <= '9' {
|
|
||||||
return charNumber
|
|
||||||
}
|
|
||||||
return charNonWord
|
|
||||||
}
|
|
||||||
|
|
||||||
func charClassOfNonAscii(char rune) charClass {
|
func charClassOfNonAscii(char rune) charClass {
|
||||||
if unicode.IsLower(char) {
|
if unicode.IsLower(char) {
|
||||||
return charLower
|
return charLower
|
||||||
@@ -194,36 +250,56 @@ func charClassOfNonAscii(char rune) charClass {
|
|||||||
return charNumber
|
return charNumber
|
||||||
} else if unicode.IsLetter(char) {
|
} else if unicode.IsLetter(char) {
|
||||||
return charLetter
|
return charLetter
|
||||||
|
} else if unicode.IsSpace(char) {
|
||||||
|
return charWhite
|
||||||
|
} else if strings.ContainsRune(delimiterChars, char) {
|
||||||
|
return charDelimiter
|
||||||
}
|
}
|
||||||
return charNonWord
|
return charNonWord
|
||||||
}
|
}
|
||||||
|
|
||||||
func charClassOf(char rune) charClass {
|
func charClassOf(char rune) charClass {
|
||||||
if char <= unicode.MaxASCII {
|
if char <= unicode.MaxASCII {
|
||||||
return charClassOfAscii(char)
|
return asciiCharClasses[char]
|
||||||
}
|
}
|
||||||
return charClassOfNonAscii(char)
|
return charClassOfNonAscii(char)
|
||||||
}
|
}
|
||||||
|
|
||||||
func bonusFor(prevClass charClass, class charClass) int16 {
|
func bonusFor(prevClass charClass, class charClass) int16 {
|
||||||
if prevClass == charNonWord && class != charNonWord {
|
if class > charNonWord {
|
||||||
|
switch prevClass {
|
||||||
|
case charWhite:
|
||||||
|
// Word boundary after whitespace
|
||||||
|
return bonusBoundaryWhite
|
||||||
|
case charDelimiter:
|
||||||
|
// Word boundary after a delimiter character
|
||||||
|
return bonusBoundaryDelimiter
|
||||||
|
case charNonWord:
|
||||||
// Word boundary
|
// Word boundary
|
||||||
return bonusBoundary
|
return bonusBoundary
|
||||||
} else if prevClass == charLower && class == charUpper ||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if prevClass == charLower && class == charUpper ||
|
||||||
prevClass != charNumber && class == charNumber {
|
prevClass != charNumber && class == charNumber {
|
||||||
// camelCase letter123
|
// camelCase letter123
|
||||||
return bonusCamel123
|
return bonusCamel123
|
||||||
} else if class == charNonWord {
|
}
|
||||||
|
|
||||||
|
switch class {
|
||||||
|
case charNonWord, charDelimiter:
|
||||||
return bonusNonWord
|
return bonusNonWord
|
||||||
|
case charWhite:
|
||||||
|
return bonusBoundaryWhite
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func bonusAt(input *util.Chars, idx int) int16 {
|
func bonusAt(input *util.Chars, idx int) int16 {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
return bonusBoundary
|
return bonusBoundaryWhite
|
||||||
}
|
}
|
||||||
return bonusFor(charClassOf(input.Get(idx-1)), charClassOf(input.Get(idx)))
|
return bonusMatrix[charClassOf(input.Get(idx-1))][charClassOf(input.Get(idx))]
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeRune(r rune) rune {
|
func normalizeRune(r rune) rune {
|
||||||
@@ -276,30 +352,45 @@ func isAscii(runes []rune) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func asciiFuzzyIndex(input *util.Chars, pattern []rune, caseSensitive bool) int {
|
func asciiFuzzyIndex(input *util.Chars, pattern []rune, caseSensitive bool) (int, int) {
|
||||||
// Can't determine
|
// Can't determine
|
||||||
if !input.IsBytes() {
|
if !input.IsBytes() {
|
||||||
return 0
|
return 0, input.Length()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not possible
|
// Not possible
|
||||||
if !isAscii(pattern) {
|
if !isAscii(pattern) {
|
||||||
return -1
|
return -1, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
firstIdx, idx := 0, 0
|
firstIdx, idx, lastIdx := 0, 0, 0
|
||||||
|
var b byte
|
||||||
for pidx := 0; pidx < len(pattern); pidx++ {
|
for pidx := 0; pidx < len(pattern); pidx++ {
|
||||||
idx = trySkip(input, caseSensitive, byte(pattern[pidx]), idx)
|
b = byte(pattern[pidx])
|
||||||
|
idx = trySkip(input, caseSensitive, b, idx)
|
||||||
if idx < 0 {
|
if idx < 0 {
|
||||||
return -1
|
return -1, -1
|
||||||
}
|
}
|
||||||
if pidx == 0 && idx > 0 {
|
if pidx == 0 && idx > 0 {
|
||||||
// Step back to find the right bonus point
|
// Step back to find the right bonus point
|
||||||
firstIdx = idx - 1
|
firstIdx = idx - 1
|
||||||
}
|
}
|
||||||
|
lastIdx = idx
|
||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
return firstIdx
|
|
||||||
|
// Find the last appearance of the last character of the pattern to limit the search scope
|
||||||
|
bu := b
|
||||||
|
if !caseSensitive && b >= 'a' && b <= 'z' {
|
||||||
|
bu = b - 32
|
||||||
|
}
|
||||||
|
scope := input.Bytes()[lastIdx:]
|
||||||
|
for offset := len(scope) - 1; offset > 0; offset-- {
|
||||||
|
if scope[offset] == b || scope[offset] == bu {
|
||||||
|
return firstIdx, lastIdx + offset + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return firstIdx, lastIdx + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
func debugV2(T []rune, pattern []rune, F []int32, lastIdx int, H []int16, C []int16) {
|
func debugV2(T []rune, pattern []rune, F []int32, lastIdx int, H []int16, C []int16) {
|
||||||
@@ -348,6 +439,9 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
return Result{0, 0, 0}, posArray(withPos, M)
|
return Result{0, 0, 0}, posArray(withPos, M)
|
||||||
}
|
}
|
||||||
N := input.Length()
|
N := input.Length()
|
||||||
|
if M > N {
|
||||||
|
return Result{-1, -1, 0}, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Since O(nm) algorithm can be prohibitively expensive for large input,
|
// Since O(nm) algorithm can be prohibitively expensive for large input,
|
||||||
// we fall back to the greedy algorithm.
|
// we fall back to the greedy algorithm.
|
||||||
@@ -356,10 +450,12 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Phase 1. Optimized search for ASCII string
|
// Phase 1. Optimized search for ASCII string
|
||||||
idx := asciiFuzzyIndex(input, pattern, caseSensitive)
|
minIdx, maxIdx := asciiFuzzyIndex(input, pattern, caseSensitive)
|
||||||
if idx < 0 {
|
if minIdx < 0 {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
// fmt.Println(N, maxIdx, idx, maxIdx-idx, input.ToString())
|
||||||
|
N = maxIdx - minIdx
|
||||||
|
|
||||||
// Reuse pre-allocated integer slice to avoid unnecessary sweeping of garbages
|
// Reuse pre-allocated integer slice to avoid unnecessary sweeping of garbages
|
||||||
offset16 := 0
|
offset16 := 0
|
||||||
@@ -371,21 +467,20 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
// The first occurrence of each character in the pattern
|
// The first occurrence of each character in the pattern
|
||||||
offset32, F := alloc32(offset32, slab, M)
|
offset32, F := alloc32(offset32, slab, M)
|
||||||
// Rune array
|
// Rune array
|
||||||
offset32, T := alloc32(offset32, slab, N)
|
_, T := alloc32(offset32, slab, N)
|
||||||
input.CopyRunes(T)
|
input.CopyRunes(T, minIdx)
|
||||||
|
|
||||||
// Phase 2. Calculate bonus for each point
|
// Phase 2. Calculate bonus for each point
|
||||||
maxScore, maxScorePos := int16(0), 0
|
maxScore, maxScorePos := int16(0), 0
|
||||||
pidx, lastIdx := 0, 0
|
pidx, lastIdx := 0, 0
|
||||||
pchar0, pchar, prevH0, prevClass, inGap := pattern[0], pattern[0], int16(0), charNonWord, false
|
pchar0, pchar, prevH0, prevClass, inGap := pattern[0], pattern[0], int16(0), initialCharClass, false
|
||||||
Tsub := T[idx:]
|
for off, char := range T {
|
||||||
H0sub, C0sub, Bsub := H0[idx:][:len(Tsub)], C0[idx:][:len(Tsub)], B[idx:][:len(Tsub)]
|
|
||||||
for off, char := range Tsub {
|
|
||||||
var class charClass
|
var class charClass
|
||||||
if char <= unicode.MaxASCII {
|
if char <= unicode.MaxASCII {
|
||||||
class = charClassOfAscii(char)
|
class = asciiCharClasses[char]
|
||||||
if !caseSensitive && class == charUpper {
|
if !caseSensitive && class == charUpper {
|
||||||
char += 32
|
char += 32
|
||||||
|
T[off] = char
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
class = charClassOfNonAscii(char)
|
class = charClassOfNonAscii(char)
|
||||||
@@ -395,53 +490,53 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
if normalize {
|
if normalize {
|
||||||
char = normalizeRune(char)
|
char = normalizeRune(char)
|
||||||
}
|
}
|
||||||
|
T[off] = char
|
||||||
}
|
}
|
||||||
|
|
||||||
Tsub[off] = char
|
bonus := bonusMatrix[prevClass][class]
|
||||||
bonus := bonusFor(prevClass, class)
|
B[off] = bonus
|
||||||
Bsub[off] = bonus
|
|
||||||
prevClass = class
|
prevClass = class
|
||||||
|
|
||||||
if char == pchar {
|
if char == pchar {
|
||||||
if pidx < M {
|
if pidx < M {
|
||||||
F[pidx] = int32(idx + off)
|
F[pidx] = int32(off)
|
||||||
pidx++
|
pidx++
|
||||||
pchar = pattern[util.Min(pidx, M-1)]
|
pchar = pattern[util.Min(pidx, M-1)]
|
||||||
}
|
}
|
||||||
lastIdx = idx + off
|
lastIdx = off
|
||||||
}
|
}
|
||||||
|
|
||||||
if char == pchar0 {
|
if char == pchar0 {
|
||||||
score := scoreMatch + bonus*bonusFirstCharMultiplier
|
score := scoreMatch + bonus*bonusFirstCharMultiplier
|
||||||
H0sub[off] = score
|
H0[off] = score
|
||||||
C0sub[off] = 1
|
C0[off] = 1
|
||||||
if M == 1 && (forward && score > maxScore || !forward && score >= maxScore) {
|
if M == 1 && (forward && score > maxScore || !forward && score >= maxScore) {
|
||||||
maxScore, maxScorePos = score, idx+off
|
maxScore, maxScorePos = score, off
|
||||||
if forward && bonus == bonusBoundary {
|
if forward && bonus >= bonusBoundary {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inGap = false
|
inGap = false
|
||||||
} else {
|
} else {
|
||||||
if inGap {
|
if inGap {
|
||||||
H0sub[off] = util.Max16(prevH0+scoreGapExtention, 0)
|
H0[off] = util.Max16(prevH0+scoreGapExtension, 0)
|
||||||
} else {
|
} else {
|
||||||
H0sub[off] = util.Max16(prevH0+scoreGapStart, 0)
|
H0[off] = util.Max16(prevH0+scoreGapStart, 0)
|
||||||
}
|
}
|
||||||
C0sub[off] = 0
|
C0[off] = 0
|
||||||
inGap = true
|
inGap = true
|
||||||
}
|
}
|
||||||
prevH0 = H0sub[off]
|
prevH0 = H0[off]
|
||||||
}
|
}
|
||||||
if pidx != M {
|
if pidx != M {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
if M == 1 {
|
if M == 1 {
|
||||||
result := Result{maxScorePos, maxScorePos + 1, int(maxScore)}
|
result := Result{minIdx + maxScorePos, minIdx + maxScorePos + 1, int(maxScore)}
|
||||||
if !withPos {
|
if !withPos {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
pos := []int{maxScorePos}
|
pos := []int{minIdx + maxScorePos}
|
||||||
return result, &pos
|
return result, &pos
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +548,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
copy(H, H0[f0:lastIdx+1])
|
copy(H, H0[f0:lastIdx+1])
|
||||||
|
|
||||||
// Possible length of consecutive chunk at each position.
|
// Possible length of consecutive chunk at each position.
|
||||||
offset16, C := alloc16(offset16, slab, width*M)
|
_, C := alloc16(offset16, slab, width*M)
|
||||||
copy(C, C0[f0:lastIdx+1])
|
copy(C, C0[f0:lastIdx+1])
|
||||||
|
|
||||||
Fsub := F[1:]
|
Fsub := F[1:]
|
||||||
@@ -477,7 +572,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
var s1, s2, consecutive int16
|
var s1, s2, consecutive int16
|
||||||
|
|
||||||
if inGap {
|
if inGap {
|
||||||
s2 = Hleft[off] + scoreGapExtention
|
s2 = Hleft[off] + scoreGapExtension
|
||||||
} else {
|
} else {
|
||||||
s2 = Hleft[off] + scoreGapStart
|
s2 = Hleft[off] + scoreGapStart
|
||||||
}
|
}
|
||||||
@@ -486,11 +581,14 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
s1 = Hdiag[off] + scoreMatch
|
s1 = Hdiag[off] + scoreMatch
|
||||||
b := Bsub[off]
|
b := Bsub[off]
|
||||||
consecutive = Cdiag[off] + 1
|
consecutive = Cdiag[off] + 1
|
||||||
|
if consecutive > 1 {
|
||||||
|
fb := B[col-int(consecutive)+1]
|
||||||
// Break consecutive chunk
|
// Break consecutive chunk
|
||||||
if b == bonusBoundary {
|
if b >= bonusBoundary && b > fb {
|
||||||
consecutive = 1
|
consecutive = 1
|
||||||
} else if consecutive > 1 {
|
} else {
|
||||||
b = util.Max16(b, util.Max16(bonusConsecutive, B[col-int(consecutive)+1]))
|
b = util.Max16(b, util.Max16(bonusConsecutive, fb))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if s1+b < s2 {
|
if s1+b < s2 {
|
||||||
s1 += Bsub[off]
|
s1 += Bsub[off]
|
||||||
@@ -535,7 +633,7 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s > s1 && (s > s2 || s == s2 && preferMatch) {
|
if s > s1 && (s > s2 || s == s2 && preferMatch) {
|
||||||
*pos = append(*pos, j)
|
*pos = append(*pos, j+minIdx)
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -548,14 +646,14 @@ func FuzzyMatchV2(caseSensitive bool, normalize bool, forward bool, input *util.
|
|||||||
// Start offset we return here is only relevant when begin tiebreak is used.
|
// Start offset we return here is only relevant when begin tiebreak is used.
|
||||||
// However finding the accurate offset requires backtracking, and we don't
|
// However finding the accurate offset requires backtracking, and we don't
|
||||||
// want to pay extra cost for the option that has lost its importance.
|
// want to pay extra cost for the option that has lost its importance.
|
||||||
return Result{j, maxScorePos + 1, int(maxScore)}, pos
|
return Result{minIdx + j, minIdx + maxScorePos + 1, int(maxScore)}, pos
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement the same sorting criteria as V2
|
// Implement the same sorting criteria as V2
|
||||||
func calculateScore(caseSensitive bool, normalize bool, text *util.Chars, pattern []rune, sidx int, eidx int, withPos bool) (int, *[]int) {
|
func calculateScore(caseSensitive bool, normalize bool, text *util.Chars, pattern []rune, sidx int, eidx int, withPos bool) (int, *[]int) {
|
||||||
pidx, score, inGap, consecutive, firstBonus := 0, 0, false, 0, int16(0)
|
pidx, score, inGap, consecutive, firstBonus := 0, 0, false, 0, int16(0)
|
||||||
pos := posArray(withPos, len(pattern))
|
pos := posArray(withPos, len(pattern))
|
||||||
prevClass := charNonWord
|
prevClass := initialCharClass
|
||||||
if sidx > 0 {
|
if sidx > 0 {
|
||||||
prevClass = charClassOf(text.Get(sidx - 1))
|
prevClass = charClassOf(text.Get(sidx - 1))
|
||||||
}
|
}
|
||||||
@@ -578,12 +676,12 @@ func calculateScore(caseSensitive bool, normalize bool, text *util.Chars, patter
|
|||||||
*pos = append(*pos, idx)
|
*pos = append(*pos, idx)
|
||||||
}
|
}
|
||||||
score += scoreMatch
|
score += scoreMatch
|
||||||
bonus := bonusFor(prevClass, class)
|
bonus := bonusMatrix[prevClass][class]
|
||||||
if consecutive == 0 {
|
if consecutive == 0 {
|
||||||
firstBonus = bonus
|
firstBonus = bonus
|
||||||
} else {
|
} else {
|
||||||
// Break consecutive chunk
|
// Break consecutive chunk
|
||||||
if bonus == bonusBoundary {
|
if bonus >= bonusBoundary && bonus > firstBonus {
|
||||||
firstBonus = bonus
|
firstBonus = bonus
|
||||||
}
|
}
|
||||||
bonus = util.Max16(util.Max16(bonus, firstBonus), bonusConsecutive)
|
bonus = util.Max16(util.Max16(bonus, firstBonus), bonusConsecutive)
|
||||||
@@ -598,7 +696,7 @@ func calculateScore(caseSensitive bool, normalize bool, text *util.Chars, patter
|
|||||||
pidx++
|
pidx++
|
||||||
} else {
|
} else {
|
||||||
if inGap {
|
if inGap {
|
||||||
score += scoreGapExtention
|
score += scoreGapExtension
|
||||||
} else {
|
} else {
|
||||||
score += scoreGapStart
|
score += scoreGapStart
|
||||||
}
|
}
|
||||||
@@ -616,7 +714,8 @@ func FuzzyMatchV1(caseSensitive bool, normalize bool, forward bool, text *util.C
|
|||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
return Result{0, 0, 0}, nil
|
return Result{0, 0, 0}, nil
|
||||||
}
|
}
|
||||||
if asciiFuzzyIndex(text, pattern, caseSensitive) < 0 {
|
idx, _ := asciiFuzzyIndex(text, pattern, caseSensitive)
|
||||||
|
if idx < 0 {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,6 +798,14 @@ func FuzzyMatchV1(caseSensitive bool, normalize bool, forward bool, text *util.C
|
|||||||
// The solution is much cheaper since there is only one possible alignment of
|
// The solution is much cheaper since there is only one possible alignment of
|
||||||
// the pattern.
|
// the pattern.
|
||||||
func ExactMatchNaive(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
func ExactMatchNaive(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
||||||
|
return exactMatchNaive(caseSensitive, normalize, forward, false, text, pattern, withPos, slab)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExactMatchBoundary(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
||||||
|
return exactMatchNaive(caseSensitive, normalize, forward, true, text, pattern, withPos, slab)
|
||||||
|
}
|
||||||
|
|
||||||
|
func exactMatchNaive(caseSensitive bool, normalize bool, forward bool, boundaryCheck bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
return Result{0, 0, 0}, nil
|
return Result{0, 0, 0}, nil
|
||||||
}
|
}
|
||||||
@@ -710,7 +817,8 @@ func ExactMatchNaive(caseSensitive bool, normalize bool, forward bool, text *uti
|
|||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if asciiFuzzyIndex(text, pattern, caseSensitive) < 0 {
|
idx, _ := asciiFuzzyIndex(text, pattern, caseSensitive)
|
||||||
|
if idx < 0 {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -732,16 +840,28 @@ func ExactMatchNaive(caseSensitive bool, normalize bool, forward bool, text *uti
|
|||||||
}
|
}
|
||||||
pidx_ := indexAt(pidx, lenPattern, forward)
|
pidx_ := indexAt(pidx, lenPattern, forward)
|
||||||
pchar := pattern[pidx_]
|
pchar := pattern[pidx_]
|
||||||
if pchar == char {
|
ok := pchar == char
|
||||||
|
if ok {
|
||||||
if pidx_ == 0 {
|
if pidx_ == 0 {
|
||||||
bonus = bonusAt(text, index_)
|
bonus = bonusAt(text, index_)
|
||||||
}
|
}
|
||||||
|
if boundaryCheck {
|
||||||
|
ok = bonus >= bonusBoundary
|
||||||
|
if ok && pidx_ == 0 {
|
||||||
|
ok = index_ == 0 || charClassOf(text.Get(index_-1)) <= charDelimiter
|
||||||
|
}
|
||||||
|
if ok && pidx_ == len(pattern)-1 {
|
||||||
|
ok = index_ == lenRunes-1 || charClassOf(text.Get(index_+1)) <= charDelimiter
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
pidx++
|
pidx++
|
||||||
if pidx == lenPattern {
|
if pidx == lenPattern {
|
||||||
if bonus > bestBonus {
|
if bonus > bestBonus {
|
||||||
bestPos, bestBonus = index, bonus
|
bestPos, bestBonus = index, bonus
|
||||||
}
|
}
|
||||||
if bonus == bonusBoundary {
|
if bonus >= bonusBoundary {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
index -= pidx - 1
|
index -= pidx - 1
|
||||||
@@ -761,7 +881,23 @@ func ExactMatchNaive(caseSensitive bool, normalize bool, forward bool, text *uti
|
|||||||
sidx = lenRunes - (bestPos + 1)
|
sidx = lenRunes - (bestPos + 1)
|
||||||
eidx = lenRunes - (bestPos - lenPattern + 1)
|
eidx = lenRunes - (bestPos - lenPattern + 1)
|
||||||
}
|
}
|
||||||
score, _ := calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false)
|
var score int
|
||||||
|
if boundaryCheck {
|
||||||
|
// Underscore boundaries should be ranked lower than the other types of boundaries
|
||||||
|
score = int(bonus)
|
||||||
|
deduct := int(bonus-bonusBoundary) + 1
|
||||||
|
if sidx > 0 && text.Get(sidx-1) == '_' {
|
||||||
|
score -= deduct + 1
|
||||||
|
deduct = 1
|
||||||
|
}
|
||||||
|
if eidx < lenRunes && text.Get(eidx) == '_' {
|
||||||
|
score -= deduct
|
||||||
|
}
|
||||||
|
// Add base score so that this can compete with other match types e.g. 'foo' | bar
|
||||||
|
score += scoreMatch*lenPattern + int(bonusBoundaryWhite)*(lenPattern+1)
|
||||||
|
} else {
|
||||||
|
score, _ = calculateScore(caseSensitive, normalize, text, pattern, sidx, eidx, false)
|
||||||
|
}
|
||||||
return Result{sidx, eidx, score}, nil
|
return Result{sidx, eidx, score}, nil
|
||||||
}
|
}
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
@@ -773,12 +909,17 @@ func PrefixMatch(caseSensitive bool, normalize bool, forward bool, text *util.Ch
|
|||||||
return Result{0, 0, 0}, nil
|
return Result{0, 0, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if text.Length() < len(pattern) {
|
trimmedLen := 0
|
||||||
|
if !unicode.IsSpace(pattern[0]) {
|
||||||
|
trimmedLen = text.LeadingWhitespaces()
|
||||||
|
}
|
||||||
|
|
||||||
|
if text.Length()-trimmedLen < len(pattern) {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, r := range pattern {
|
for index, r := range pattern {
|
||||||
char := text.Get(index)
|
char := text.Get(trimmedLen + index)
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
char = unicode.ToLower(char)
|
char = unicode.ToLower(char)
|
||||||
}
|
}
|
||||||
@@ -790,14 +931,17 @@ func PrefixMatch(caseSensitive bool, normalize bool, forward bool, text *util.Ch
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
lenPattern := len(pattern)
|
lenPattern := len(pattern)
|
||||||
score, _ := calculateScore(caseSensitive, normalize, text, pattern, 0, lenPattern, false)
|
score, _ := calculateScore(caseSensitive, normalize, text, pattern, trimmedLen, trimmedLen+lenPattern, false)
|
||||||
return Result{0, lenPattern, score}, nil
|
return Result{trimmedLen, trimmedLen + lenPattern, score}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuffixMatch performs suffix-match
|
// SuffixMatch performs suffix-match
|
||||||
func SuffixMatch(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
func SuffixMatch(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
||||||
lenRunes := text.Length()
|
lenRunes := text.Length()
|
||||||
trimmedLen := lenRunes - text.TrailingWhitespaces()
|
trimmedLen := lenRunes
|
||||||
|
if len(pattern) == 0 || !unicode.IsSpace(pattern[len(pattern)-1]) {
|
||||||
|
trimmedLen -= text.TrailingWhitespaces()
|
||||||
|
}
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
return Result{trimmedLen, trimmedLen, 0}, nil
|
return Result{trimmedLen, trimmedLen, 0}, nil
|
||||||
}
|
}
|
||||||
@@ -828,14 +972,30 @@ func SuffixMatch(caseSensitive bool, normalize bool, forward bool, text *util.Ch
|
|||||||
// EqualMatch performs equal-match
|
// EqualMatch performs equal-match
|
||||||
func EqualMatch(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
func EqualMatch(caseSensitive bool, normalize bool, forward bool, text *util.Chars, pattern []rune, withPos bool, slab *util.Slab) (Result, *[]int) {
|
||||||
lenPattern := len(pattern)
|
lenPattern := len(pattern)
|
||||||
if text.Length() != lenPattern {
|
if lenPattern == 0 {
|
||||||
|
return Result{-1, -1, 0}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip leading whitespaces
|
||||||
|
trimmedLen := 0
|
||||||
|
if !unicode.IsSpace(pattern[0]) {
|
||||||
|
trimmedLen = text.LeadingWhitespaces()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip trailing whitespaces
|
||||||
|
trimmedEndLen := 0
|
||||||
|
if !unicode.IsSpace(pattern[lenPattern-1]) {
|
||||||
|
trimmedEndLen = text.TrailingWhitespaces()
|
||||||
|
}
|
||||||
|
|
||||||
|
if text.Length()-trimmedLen-trimmedEndLen != lenPattern {
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
match := true
|
match := true
|
||||||
if normalize {
|
if normalize {
|
||||||
runes := text.ToRunes()
|
runes := text.ToRunes()
|
||||||
for idx, pchar := range pattern {
|
for idx, pchar := range pattern {
|
||||||
char := runes[idx]
|
char := runes[trimmedLen+idx]
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
char = unicode.To(unicode.LowerCase, char)
|
char = unicode.To(unicode.LowerCase, char)
|
||||||
}
|
}
|
||||||
@@ -845,15 +1005,16 @@ func EqualMatch(caseSensitive bool, normalize bool, forward bool, text *util.Cha
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
runesStr := text.ToString()
|
runes := text.ToRunes()
|
||||||
|
runesStr := string(runes[trimmedLen : len(runes)-trimmedEndLen])
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
runesStr = strings.ToLower(runesStr)
|
runesStr = strings.ToLower(runesStr)
|
||||||
}
|
}
|
||||||
match = runesStr == string(pattern)
|
match = runesStr == string(pattern)
|
||||||
}
|
}
|
||||||
if match {
|
if match {
|
||||||
return Result{0, lenPattern, (scoreMatch+bonusBoundary)*lenPattern +
|
return Result{trimmedLen, trimmedLen + lenPattern, (scoreMatch+int(bonusBoundaryWhite))*lenPattern +
|
||||||
(bonusFirstCharMultiplier-1)*bonusBoundary}, nil
|
(bonusFirstCharMultiplier-1)*int(bonusBoundaryWhite)}, nil
|
||||||
}
|
}
|
||||||
return Result{-1, -1, 0}, nil
|
return Result{-1, -1, 0}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import (
|
|||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
Init("default")
|
||||||
|
}
|
||||||
|
|
||||||
func assertMatch(t *testing.T, fun Algo, caseSensitive, forward bool, input, pattern string, sidx int, eidx int, score int) {
|
func assertMatch(t *testing.T, fun Algo, caseSensitive, forward bool, input, pattern string, sidx int, eidx int, score int) {
|
||||||
assertMatch2(t, fun, caseSensitive, false, forward, input, pattern, sidx, eidx, score)
|
assertMatch2(t, fun, caseSensitive, false, forward, input, pattern, sidx, eidx, score)
|
||||||
}
|
}
|
||||||
@@ -43,46 +47,46 @@ func TestFuzzyMatch(t *testing.T) {
|
|||||||
for _, fn := range []Algo{FuzzyMatchV1, FuzzyMatchV2} {
|
for _, fn := range []Algo{FuzzyMatchV1, FuzzyMatchV2} {
|
||||||
for _, forward := range []bool{true, false} {
|
for _, forward := range []bool{true, false} {
|
||||||
assertMatch(t, fn, false, forward, "fooBarbaz1", "oBZ", 2, 9,
|
assertMatch(t, fn, false, forward, "fooBarbaz1", "oBZ", 2, 9,
|
||||||
scoreMatch*3+bonusCamel123+scoreGapStart+scoreGapExtention*3)
|
scoreMatch*3+bonusCamel123+scoreGapStart+scoreGapExtension*3)
|
||||||
assertMatch(t, fn, false, forward, "foo bar baz", "fbb", 0, 9,
|
assertMatch(t, fn, false, forward, "foo bar baz", "fbb", 0, 9,
|
||||||
scoreMatch*3+bonusBoundary*bonusFirstCharMultiplier+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+
|
||||||
bonusBoundary*2+2*scoreGapStart+4*scoreGapExtention)
|
int(bonusBoundaryWhite)*2+2*scoreGapStart+4*scoreGapExtension)
|
||||||
assertMatch(t, fn, false, forward, "/AutomatorDocument.icns", "rdoc", 9, 13,
|
assertMatch(t, fn, false, forward, "/AutomatorDocument.icns", "rdoc", 9, 13,
|
||||||
scoreMatch*4+bonusCamel123+bonusConsecutive*2)
|
scoreMatch*4+bonusCamel123+bonusConsecutive*2)
|
||||||
assertMatch(t, fn, false, forward, "/man1/zshcompctl.1", "zshc", 6, 10,
|
assertMatch(t, fn, false, forward, "/man1/zshcompctl.1", "zshc", 6, 10,
|
||||||
scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*3)
|
scoreMatch*4+int(bonusBoundaryDelimiter)*bonusFirstCharMultiplier+int(bonusBoundaryDelimiter)*3)
|
||||||
assertMatch(t, fn, false, forward, "/.oh-my-zsh/cache", "zshc", 8, 13,
|
assertMatch(t, fn, false, forward, "/.oh-my-zsh/cache", "zshc", 8, 13,
|
||||||
scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*3+scoreGapStart)
|
scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*2+scoreGapStart+int(bonusBoundaryDelimiter))
|
||||||
assertMatch(t, fn, false, forward, "ab0123 456", "12356", 3, 10,
|
assertMatch(t, fn, false, forward, "ab0123 456", "12356", 3, 10,
|
||||||
scoreMatch*5+bonusConsecutive*3+scoreGapStart+scoreGapExtention)
|
scoreMatch*5+bonusConsecutive*3+scoreGapStart+scoreGapExtension)
|
||||||
assertMatch(t, fn, false, forward, "abc123 456", "12356", 3, 10,
|
assertMatch(t, fn, false, forward, "abc123 456", "12356", 3, 10,
|
||||||
scoreMatch*5+bonusCamel123*bonusFirstCharMultiplier+bonusCamel123*2+bonusConsecutive+scoreGapStart+scoreGapExtention)
|
scoreMatch*5+bonusCamel123*bonusFirstCharMultiplier+bonusCamel123*2+bonusConsecutive+scoreGapStart+scoreGapExtension)
|
||||||
assertMatch(t, fn, false, forward, "foo/bar/baz", "fbb", 0, 9,
|
assertMatch(t, fn, false, forward, "foo/bar/baz", "fbb", 0, 9,
|
||||||
scoreMatch*3+bonusBoundary*bonusFirstCharMultiplier+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+
|
||||||
bonusBoundary*2+2*scoreGapStart+4*scoreGapExtention)
|
int(bonusBoundaryDelimiter)*2+2*scoreGapStart+4*scoreGapExtension)
|
||||||
assertMatch(t, fn, false, forward, "fooBarBaz", "fbb", 0, 7,
|
assertMatch(t, fn, false, forward, "fooBarBaz", "fbb", 0, 7,
|
||||||
scoreMatch*3+bonusBoundary*bonusFirstCharMultiplier+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+
|
||||||
bonusCamel123*2+2*scoreGapStart+2*scoreGapExtention)
|
bonusCamel123*2+2*scoreGapStart+2*scoreGapExtension)
|
||||||
assertMatch(t, fn, false, forward, "foo barbaz", "fbb", 0, 8,
|
assertMatch(t, fn, false, forward, "foo barbaz", "fbb", 0, 8,
|
||||||
scoreMatch*3+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite)+
|
||||||
scoreGapStart*2+scoreGapExtention*3)
|
scoreGapStart*2+scoreGapExtension*3)
|
||||||
assertMatch(t, fn, false, forward, "fooBar Baz", "foob", 0, 4,
|
assertMatch(t, fn, false, forward, "fooBar Baz", "foob", 0, 4,
|
||||||
scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*3)
|
scoreMatch*4+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite)*3)
|
||||||
assertMatch(t, fn, false, forward, "xFoo-Bar Baz", "foo-b", 1, 6,
|
assertMatch(t, fn, false, forward, "xFoo-Bar Baz", "foo-b", 1, 6,
|
||||||
scoreMatch*5+bonusCamel123*bonusFirstCharMultiplier+bonusCamel123*2+
|
scoreMatch*5+bonusCamel123*bonusFirstCharMultiplier+bonusCamel123*2+
|
||||||
bonusNonWord+bonusBoundary)
|
bonusNonWord+bonusBoundary)
|
||||||
|
|
||||||
assertMatch(t, fn, true, forward, "fooBarbaz", "oBz", 2, 9,
|
assertMatch(t, fn, true, forward, "fooBarbaz", "oBz", 2, 9,
|
||||||
scoreMatch*3+bonusCamel123+scoreGapStart+scoreGapExtention*3)
|
scoreMatch*3+bonusCamel123+scoreGapStart+scoreGapExtension*3)
|
||||||
assertMatch(t, fn, true, forward, "Foo/Bar/Baz", "FBB", 0, 9,
|
assertMatch(t, fn, true, forward, "Foo/Bar/Baz", "FBB", 0, 9,
|
||||||
scoreMatch*3+bonusBoundary*(bonusFirstCharMultiplier+2)+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryDelimiter)*2+
|
||||||
scoreGapStart*2+scoreGapExtention*4)
|
scoreGapStart*2+scoreGapExtension*4)
|
||||||
assertMatch(t, fn, true, forward, "FooBarBaz", "FBB", 0, 7,
|
assertMatch(t, fn, true, forward, "FooBarBaz", "FBB", 0, 7,
|
||||||
scoreMatch*3+bonusBoundary*bonusFirstCharMultiplier+bonusCamel123*2+
|
scoreMatch*3+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+bonusCamel123*2+
|
||||||
scoreGapStart*2+scoreGapExtention*2)
|
scoreGapStart*2+scoreGapExtension*2)
|
||||||
assertMatch(t, fn, true, forward, "FooBar Baz", "FooB", 0, 4,
|
assertMatch(t, fn, true, forward, "FooBar Baz", "FooB", 0, 4,
|
||||||
scoreMatch*4+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary*2+
|
scoreMatch*4+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite)*2+
|
||||||
util.Max(bonusCamel123, bonusBoundary))
|
util.Max(bonusCamel123, int(bonusBoundaryWhite)))
|
||||||
|
|
||||||
// Consecutive bonus updated
|
// Consecutive bonus updated
|
||||||
assertMatch(t, fn, true, forward, "foo-bar", "o-ba", 2, 6,
|
assertMatch(t, fn, true, forward, "foo-bar", "o-ba", 2, 6,
|
||||||
@@ -98,10 +102,10 @@ func TestFuzzyMatch(t *testing.T) {
|
|||||||
|
|
||||||
func TestFuzzyMatchBackward(t *testing.T) {
|
func TestFuzzyMatchBackward(t *testing.T) {
|
||||||
assertMatch(t, FuzzyMatchV1, false, true, "foobar fb", "fb", 0, 4,
|
assertMatch(t, FuzzyMatchV1, false, true, "foobar fb", "fb", 0, 4,
|
||||||
scoreMatch*2+bonusBoundary*bonusFirstCharMultiplier+
|
scoreMatch*2+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+
|
||||||
scoreGapStart+scoreGapExtention)
|
scoreGapStart+scoreGapExtension)
|
||||||
assertMatch(t, FuzzyMatchV1, false, false, "foobar fb", "fb", 7, 9,
|
assertMatch(t, FuzzyMatchV1, false, false, "foobar fb", "fb", 7, 9,
|
||||||
scoreMatch*2+bonusBoundary*bonusFirstCharMultiplier+bonusBoundary)
|
scoreMatch*2+int(bonusBoundaryWhite)*bonusFirstCharMultiplier+int(bonusBoundaryWhite))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExactMatchNaive(t *testing.T) {
|
func TestExactMatchNaive(t *testing.T) {
|
||||||
@@ -114,9 +118,9 @@ func TestExactMatchNaive(t *testing.T) {
|
|||||||
assertMatch(t, ExactMatchNaive, false, dir, "/AutomatorDocument.icns", "rdoc", 9, 13,
|
assertMatch(t, ExactMatchNaive, false, dir, "/AutomatorDocument.icns", "rdoc", 9, 13,
|
||||||
scoreMatch*4+bonusCamel123+bonusConsecutive*2)
|
scoreMatch*4+bonusCamel123+bonusConsecutive*2)
|
||||||
assertMatch(t, ExactMatchNaive, false, dir, "/man1/zshcompctl.1", "zshc", 6, 10,
|
assertMatch(t, ExactMatchNaive, false, dir, "/man1/zshcompctl.1", "zshc", 6, 10,
|
||||||
scoreMatch*4+bonusBoundary*(bonusFirstCharMultiplier+3))
|
scoreMatch*4+int(bonusBoundaryDelimiter)*(bonusFirstCharMultiplier+3))
|
||||||
assertMatch(t, ExactMatchNaive, false, dir, "/.oh-my-zsh/cache", "zsh/c", 8, 13,
|
assertMatch(t, ExactMatchNaive, false, dir, "/.oh-my-zsh/cache", "zsh/c", 8, 13,
|
||||||
scoreMatch*5+bonusBoundary*(bonusFirstCharMultiplier+4))
|
scoreMatch*5+bonusBoundary*(bonusFirstCharMultiplier+3)+int(bonusBoundaryDelimiter))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,7 +132,7 @@ func TestExactMatchNaiveBackward(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPrefixMatch(t *testing.T) {
|
func TestPrefixMatch(t *testing.T) {
|
||||||
score := (scoreMatch+bonusBoundary)*3 + bonusBoundary*(bonusFirstCharMultiplier-1)
|
score := scoreMatch*3 + int(bonusBoundaryWhite)*bonusFirstCharMultiplier + int(bonusBoundaryWhite)*2
|
||||||
|
|
||||||
for _, dir := range []bool{true, false} {
|
for _, dir := range []bool{true, false} {
|
||||||
assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1, 0)
|
assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1, 0)
|
||||||
@@ -136,6 +140,10 @@ func TestPrefixMatch(t *testing.T) {
|
|||||||
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3, score)
|
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3, score)
|
||||||
assertMatch(t, PrefixMatch, false, dir, "foOBarBaZ", "foo", 0, 3, score)
|
assertMatch(t, PrefixMatch, false, dir, "foOBarBaZ", "foo", 0, 3, score)
|
||||||
assertMatch(t, PrefixMatch, false, dir, "f-oBarbaz", "f-o", 0, 3, score)
|
assertMatch(t, PrefixMatch, false, dir, "f-oBarbaz", "f-o", 0, 3, score)
|
||||||
|
|
||||||
|
assertMatch(t, PrefixMatch, false, dir, " fooBar", "foo", 1, 4, score)
|
||||||
|
assertMatch(t, PrefixMatch, false, dir, " fooBar", " fo", 0, 3, score)
|
||||||
|
assertMatch(t, PrefixMatch, false, dir, " fo", "foo", -1, -1, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +156,14 @@ func TestSuffixMatch(t *testing.T) {
|
|||||||
scoreMatch*3+bonusConsecutive*2)
|
scoreMatch*3+bonusConsecutive*2)
|
||||||
assertMatch(t, SuffixMatch, false, dir, "fooBarBaZ", "baz", 6, 9,
|
assertMatch(t, SuffixMatch, false, dir, "fooBarBaZ", "baz", 6, 9,
|
||||||
(scoreMatch+bonusCamel123)*3+bonusCamel123*(bonusFirstCharMultiplier-1))
|
(scoreMatch+bonusCamel123)*3+bonusCamel123*(bonusFirstCharMultiplier-1))
|
||||||
|
|
||||||
|
// Strip trailing white space from the string
|
||||||
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz ", "baz", 6, 9,
|
||||||
|
scoreMatch*3+bonusConsecutive*2)
|
||||||
|
|
||||||
|
// Only when the pattern doesn't end with a space
|
||||||
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz ", "baz ", 6, 10,
|
||||||
|
scoreMatch*4+bonusConsecutive*2+int(bonusBoundaryWhite))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,9 +187,9 @@ func TestNormalize(t *testing.T) {
|
|||||||
input, pattern, sidx, eidx, score)
|
input, pattern, sidx, eidx, score)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
test("Só Danço Samba", "So", 0, 2, 56, FuzzyMatchV1, FuzzyMatchV2, PrefixMatch, ExactMatchNaive)
|
test("Só Danço Samba", "So", 0, 2, 62, FuzzyMatchV1, FuzzyMatchV2, PrefixMatch, ExactMatchNaive)
|
||||||
test("Só Danço Samba", "sodc", 0, 7, 89, FuzzyMatchV1, FuzzyMatchV2)
|
test("Só Danço Samba", "sodc", 0, 7, 97, FuzzyMatchV1, FuzzyMatchV2)
|
||||||
test("Danço", "danco", 0, 5, 128, FuzzyMatchV1, FuzzyMatchV2, PrefixMatch, SuffixMatch, ExactMatchNaive, EqualMatch)
|
test("Danço", "danco", 0, 5, 140, FuzzyMatchV1, FuzzyMatchV2, PrefixMatch, SuffixMatch, ExactMatchNaive, EqualMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLongString(t *testing.T) {
|
func TestLongString(t *testing.T) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
package algo
|
package algo
|
||||||
|
|
||||||
var normalized map[rune]rune = map[rune]rune{
|
var normalized = map[rune]rune{
|
||||||
0x00E1: 'a', // WITH ACUTE, LATIN SMALL LETTER
|
0x00E1: 'a', // WITH ACUTE, LATIN SMALL LETTER
|
||||||
0x0103: 'a', // WITH BREVE, LATIN SMALL LETTER
|
0x0103: 'a', // WITH BREVE, LATIN SMALL LETTER
|
||||||
0x01CE: 'a', // WITH CARON, LATIN SMALL LETTER
|
0x01CE: 'a', // WITH CARON, LATIN SMALL LETTER
|
||||||
@@ -405,6 +405,74 @@ var normalized map[rune]rune = map[rune]rune{
|
|||||||
0x024E: 'Y', // WITH STROKE, LATIN CAPITAL LETTER
|
0x024E: 'Y', // WITH STROKE, LATIN CAPITAL LETTER
|
||||||
0x028F: 'Y', // , LATIN LETTER SMALL CAPITAL
|
0x028F: 'Y', // , LATIN LETTER SMALL CAPITAL
|
||||||
0x1D22: 'Z', // , LATIN LETTER SMALL CAPITAL
|
0x1D22: 'Z', // , LATIN LETTER SMALL CAPITAL
|
||||||
|
|
||||||
|
'Ắ': 'A',
|
||||||
|
'Ấ': 'A',
|
||||||
|
'Ằ': 'A',
|
||||||
|
'Ầ': 'A',
|
||||||
|
'Ẳ': 'A',
|
||||||
|
'Ẩ': 'A',
|
||||||
|
'Ẵ': 'A',
|
||||||
|
'Ẫ': 'A',
|
||||||
|
'Ặ': 'A',
|
||||||
|
'Ậ': 'A',
|
||||||
|
|
||||||
|
'ắ': 'a',
|
||||||
|
'ấ': 'a',
|
||||||
|
'ằ': 'a',
|
||||||
|
'ầ': 'a',
|
||||||
|
'ẳ': 'a',
|
||||||
|
'ẩ': 'a',
|
||||||
|
'ẵ': 'a',
|
||||||
|
'ẫ': 'a',
|
||||||
|
'ặ': 'a',
|
||||||
|
'ậ': 'a',
|
||||||
|
|
||||||
|
'Ế': 'E',
|
||||||
|
'Ề': 'E',
|
||||||
|
'Ể': 'E',
|
||||||
|
'Ễ': 'E',
|
||||||
|
'Ệ': 'E',
|
||||||
|
|
||||||
|
'ế': 'e',
|
||||||
|
'ề': 'e',
|
||||||
|
'ể': 'e',
|
||||||
|
'ễ': 'e',
|
||||||
|
'ệ': 'e',
|
||||||
|
|
||||||
|
'Ố': 'O',
|
||||||
|
'Ớ': 'O',
|
||||||
|
'Ồ': 'O',
|
||||||
|
'Ờ': 'O',
|
||||||
|
'Ổ': 'O',
|
||||||
|
'Ở': 'O',
|
||||||
|
'Ỗ': 'O',
|
||||||
|
'Ỡ': 'O',
|
||||||
|
'Ộ': 'O',
|
||||||
|
'Ợ': 'O',
|
||||||
|
|
||||||
|
'ố': 'o',
|
||||||
|
'ớ': 'o',
|
||||||
|
'ồ': 'o',
|
||||||
|
'ờ': 'o',
|
||||||
|
'ổ': 'o',
|
||||||
|
'ở': 'o',
|
||||||
|
'ỗ': 'o',
|
||||||
|
'ỡ': 'o',
|
||||||
|
'ộ': 'o',
|
||||||
|
'ợ': 'o',
|
||||||
|
|
||||||
|
'Ứ': 'U',
|
||||||
|
'Ừ': 'U',
|
||||||
|
'Ử': 'U',
|
||||||
|
'Ữ': 'U',
|
||||||
|
'Ự': 'U',
|
||||||
|
|
||||||
|
'ứ': 'u',
|
||||||
|
'ừ': 'u',
|
||||||
|
'ử': 'u',
|
||||||
|
'ữ': 'u',
|
||||||
|
'ự': 'u',
|
||||||
}
|
}
|
||||||
|
|
||||||
// NormalizeRunes normalizes latin script letters
|
// NormalizeRunes normalizes latin script letters
|
||||||
|
|||||||
379
src/ansi.go
379
src/ansi.go
@@ -1,8 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -15,89 +14,250 @@ type ansiOffset struct {
|
|||||||
color ansiState
|
color ansiState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type url struct {
|
||||||
|
uri string
|
||||||
|
params string
|
||||||
|
}
|
||||||
|
|
||||||
type ansiState struct {
|
type ansiState struct {
|
||||||
fg tui.Color
|
fg tui.Color
|
||||||
bg tui.Color
|
bg tui.Color
|
||||||
attr tui.Attr
|
attr tui.Attr
|
||||||
|
lbg tui.Color
|
||||||
|
url *url
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ansiState) colored() bool {
|
func (s *ansiState) colored() bool {
|
||||||
return s.fg != -1 || s.bg != -1 || s.attr > 0
|
return s.fg != -1 || s.bg != -1 || s.attr > 0 || s.lbg >= 0 || s.url != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ansiState) equals(t *ansiState) bool {
|
func (s *ansiState) equals(t *ansiState) bool {
|
||||||
if t == nil {
|
if t == nil {
|
||||||
return !s.colored()
|
return !s.colored()
|
||||||
}
|
}
|
||||||
return s.fg == t.fg && s.bg == t.bg && s.attr == t.attr
|
return s.fg == t.fg && s.bg == t.bg && s.attr == t.attr && s.lbg == t.lbg && s.url == t.url
|
||||||
}
|
}
|
||||||
|
|
||||||
var ansiRegex *regexp.Regexp
|
func (s *ansiState) ToString() string {
|
||||||
|
if !s.colored() {
|
||||||
func init() {
|
return ""
|
||||||
/*
|
|
||||||
References:
|
|
||||||
- https://github.com/gnachman/iTerm2
|
|
||||||
- http://ascii-table.com/ansi-escape-sequences.php
|
|
||||||
- http://ascii-table.com/ansi-escape-sequences-vt-100.php
|
|
||||||
- http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html
|
|
||||||
*/
|
|
||||||
// The following regular expression will include not all but most of the
|
|
||||||
// frequently used ANSI sequences
|
|
||||||
ansiRegex = regexp.MustCompile("(?:\x1b[\\[()][0-9;]*[a-zA-Z@]|\x1b.|[\x0e\x0f]|.\x08)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func findAnsiStart(str string) int {
|
ret := ""
|
||||||
idx := 0
|
if s.attr&tui.Bold > 0 {
|
||||||
for ; idx < len(str); idx++ {
|
ret += "1;"
|
||||||
b := str[idx]
|
|
||||||
if b == 0x1b || b == 0x0e || b == 0x0f {
|
|
||||||
return idx
|
|
||||||
}
|
}
|
||||||
if b == 0x08 && idx > 0 {
|
if s.attr&tui.Dim > 0 {
|
||||||
return idx - 1
|
ret += "2;"
|
||||||
|
}
|
||||||
|
if s.attr&tui.Italic > 0 {
|
||||||
|
ret += "3;"
|
||||||
|
}
|
||||||
|
if s.attr&tui.Underline > 0 {
|
||||||
|
ret += "4;"
|
||||||
|
}
|
||||||
|
if s.attr&tui.Blink > 0 {
|
||||||
|
ret += "5;"
|
||||||
|
}
|
||||||
|
if s.attr&tui.Reverse > 0 {
|
||||||
|
ret += "7;"
|
||||||
|
}
|
||||||
|
if s.attr&tui.StrikeThrough > 0 {
|
||||||
|
ret += "9;"
|
||||||
|
}
|
||||||
|
ret += toAnsiString(s.fg, 30) + toAnsiString(s.bg, 40)
|
||||||
|
|
||||||
|
ret = "\x1b[" + strings.TrimSuffix(ret, ";") + "m"
|
||||||
|
if s.url != nil {
|
||||||
|
ret = fmt.Sprintf("\x1b]8;%s;%s\x1b\\%s\x1b]8;;\x1b", s.url.params, s.url.uri, ret)
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func toAnsiString(color tui.Color, offset int) string {
|
||||||
|
col := int(color)
|
||||||
|
ret := ""
|
||||||
|
if col == -1 {
|
||||||
|
ret += strconv.Itoa(offset + 9)
|
||||||
|
} else if col < 8 {
|
||||||
|
ret += strconv.Itoa(offset + col)
|
||||||
|
} else if col < 16 {
|
||||||
|
ret += strconv.Itoa(offset - 30 + 90 + col - 8)
|
||||||
|
} else if col < 256 {
|
||||||
|
ret += strconv.Itoa(offset+8) + ";5;" + strconv.Itoa(col)
|
||||||
|
} else if col >= (1 << 24) {
|
||||||
|
r := strconv.Itoa((col >> 16) & 0xff)
|
||||||
|
g := strconv.Itoa((col >> 8) & 0xff)
|
||||||
|
b := strconv.Itoa(col & 0xff)
|
||||||
|
ret += strconv.Itoa(offset+8) + ";2;" + r + ";" + g + ";" + b
|
||||||
|
}
|
||||||
|
return ret + ";"
|
||||||
|
}
|
||||||
|
|
||||||
|
func isPrint(c uint8) bool {
|
||||||
|
return '\x20' <= c && c <= '\x7e'
|
||||||
|
}
|
||||||
|
|
||||||
|
func matchOperatingSystemCommand(s string) int {
|
||||||
|
// `\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)`
|
||||||
|
// ^ match starting here
|
||||||
|
//
|
||||||
|
i := 5 // prefix matched in nextAnsiEscapeSequence()
|
||||||
|
for ; i < len(s) && isPrint(s[i]); i++ {
|
||||||
|
}
|
||||||
|
if i < len(s) {
|
||||||
|
if s[i] == '\x07' {
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
// `\x1b]8;PARAMS;URI\x1b\\TITLE\x1b]8;;\x1b`
|
||||||
|
// ------
|
||||||
|
if s[i] == '\x1b' && i < len(s)-1 && s[i+1] == '\\' {
|
||||||
|
return i + 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return idx
|
|
||||||
|
// `\x1b]8;PARAMS;URI\x1b\\TITLE\x1b]8;;\x1b`
|
||||||
|
// ------------
|
||||||
|
if i < len(s) && s[:i+1] == "\x1b]8;;\x1b" {
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func matchControlSequence(s string) int {
|
||||||
|
// `\x1b[\\[()][0-9;:?]*[a-zA-Z@]`
|
||||||
|
// ^ match starting here
|
||||||
|
//
|
||||||
|
i := 2 // prefix matched in nextAnsiEscapeSequence()
|
||||||
|
for ; i < len(s); i++ {
|
||||||
|
c := s[i]
|
||||||
|
switch c {
|
||||||
|
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ';', ':', '?':
|
||||||
|
// ok
|
||||||
|
default:
|
||||||
|
if 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '@' {
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func isCtrlSeqStart(c uint8) bool {
|
||||||
|
switch c {
|
||||||
|
case '\\', '[', '(', ')':
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// nextAnsiEscapeSequence returns the ANSI escape sequence and is equivalent to
|
||||||
|
// calling FindStringIndex() on the below regex (which was originally used):
|
||||||
|
//
|
||||||
|
// "(?:\x1b[\\[()][0-9;:?]*[a-zA-Z@]|\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)"
|
||||||
|
func nextAnsiEscapeSequence(s string) (int, int) {
|
||||||
|
// fast check for ANSI escape sequences
|
||||||
|
i := 0
|
||||||
|
for ; i < len(s); i++ {
|
||||||
|
switch s[i] {
|
||||||
|
case '\x0e', '\x0f', '\x1b', '\x08':
|
||||||
|
// We ignore the fact that '\x08' cannot be the first char
|
||||||
|
// in the string and be an escape sequence for the sake of
|
||||||
|
// speed and simplicity.
|
||||||
|
goto Loop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1, -1
|
||||||
|
|
||||||
|
Loop:
|
||||||
|
for ; i < len(s); i++ {
|
||||||
|
switch s[i] {
|
||||||
|
case '\x08':
|
||||||
|
// backtrack to match: `.\x08`
|
||||||
|
if i > 0 && s[i-1] != '\n' {
|
||||||
|
if s[i-1] < utf8.RuneSelf {
|
||||||
|
return i - 1, i + 1
|
||||||
|
}
|
||||||
|
_, n := utf8.DecodeLastRuneInString(s[:i])
|
||||||
|
return i - n, i + 1
|
||||||
|
}
|
||||||
|
case '\x1b':
|
||||||
|
// match: `\x1b[\\[()][0-9;:?]*[a-zA-Z@]`
|
||||||
|
if i+2 < len(s) && isCtrlSeqStart(s[i+1]) {
|
||||||
|
if j := matchControlSequence(s[i:]); j != -1 {
|
||||||
|
return i, i + j
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// match: `\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)`
|
||||||
|
if i+5 < len(s) && s[i+1] == ']' && isNumeric(s[i+2]) &&
|
||||||
|
(s[i+3] == ';' || s[i+3] == ':') && isPrint(s[i+4]) {
|
||||||
|
|
||||||
|
if j := matchOperatingSystemCommand(s[i:]); j != -1 {
|
||||||
|
return i, i + j
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// match: `\x1b.`
|
||||||
|
if i+1 < len(s) && s[i+1] != '\n' {
|
||||||
|
if s[i+1] < utf8.RuneSelf {
|
||||||
|
return i, i + 2
|
||||||
|
}
|
||||||
|
_, n := utf8.DecodeRuneInString(s[i+1:])
|
||||||
|
return i, i + n + 1
|
||||||
|
}
|
||||||
|
case '\x0e', '\x0f':
|
||||||
|
// match: `[\x0e\x0f]`
|
||||||
|
return i, i + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1, -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractColor(str string, state *ansiState, proc func(string, *ansiState) bool) (string, *[]ansiOffset, *ansiState) {
|
func extractColor(str string, state *ansiState, proc func(string, *ansiState) bool) (string, *[]ansiOffset, *ansiState) {
|
||||||
var offsets []ansiOffset
|
// We append to a stack allocated variable that we'll
|
||||||
var output bytes.Buffer
|
// later copy and return, to save on allocations.
|
||||||
|
offsets := make([]ansiOffset, 0, 32)
|
||||||
|
|
||||||
if state != nil {
|
if state != nil {
|
||||||
offsets = append(offsets, ansiOffset{[2]int32{0, 0}, *state})
|
offsets = append(offsets, ansiOffset{[2]int32{0, 0}, *state})
|
||||||
}
|
}
|
||||||
|
|
||||||
prevIdx := 0
|
var (
|
||||||
runeCount := 0
|
pstate *ansiState // lazily allocated
|
||||||
|
output strings.Builder
|
||||||
|
prevIdx int
|
||||||
|
runeCount int
|
||||||
|
)
|
||||||
for idx := 0; idx < len(str); {
|
for idx := 0; idx < len(str); {
|
||||||
idx += findAnsiStart(str[idx:])
|
// Make sure that we found an ANSI code
|
||||||
if idx == len(str) {
|
start, end := nextAnsiEscapeSequence(str[idx:])
|
||||||
|
if start == -1 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
start += idx
|
||||||
// Make sure that we found an ANSI code
|
idx += end
|
||||||
offset := ansiRegex.FindStringIndex(str[idx:])
|
|
||||||
if len(offset) < 2 {
|
|
||||||
idx++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
offset[0] += idx
|
|
||||||
offset[1] += idx
|
|
||||||
idx = offset[1]
|
|
||||||
|
|
||||||
// Check if we should continue
|
// Check if we should continue
|
||||||
prev := str[prevIdx:offset[0]]
|
prev := str[prevIdx:start]
|
||||||
if proc != nil && !proc(prev, state) {
|
if proc != nil && !proc(prev, state) {
|
||||||
return "", nil, nil
|
return "", nil, nil
|
||||||
}
|
}
|
||||||
|
prevIdx = idx
|
||||||
|
|
||||||
prevIdx = offset[1]
|
if len(prev) != 0 {
|
||||||
runeCount += utf8.RuneCountInString(prev)
|
runeCount += utf8.RuneCountInString(prev)
|
||||||
|
// Grow the buffer size to the maximum possible length (string length
|
||||||
|
// containing ansi codes) to avoid repetitive allocation
|
||||||
|
if output.Cap() == 0 {
|
||||||
|
output.Grow(len(str))
|
||||||
|
}
|
||||||
output.WriteString(prev)
|
output.WriteString(prev)
|
||||||
|
}
|
||||||
|
|
||||||
newState := interpretCode(str[offset[0]:offset[1]], state)
|
newState := interpretCode(str[start:idx], state)
|
||||||
if !newState.equals(state) {
|
if !newState.equals(state) {
|
||||||
if state != nil {
|
if state != nil {
|
||||||
// Update last offset
|
// Update last offset
|
||||||
@@ -106,8 +266,15 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo
|
|||||||
|
|
||||||
if newState.colored() {
|
if newState.colored() {
|
||||||
// Append new offset
|
// Append new offset
|
||||||
state = newState
|
if pstate == nil {
|
||||||
offsets = append(offsets, ansiOffset{[2]int32{int32(runeCount), int32(runeCount)}, *state})
|
pstate = &ansiState{}
|
||||||
|
}
|
||||||
|
*pstate = newState
|
||||||
|
state = pstate
|
||||||
|
offsets = append(offsets, ansiOffset{
|
||||||
|
[2]int32{int32(runeCount), int32(runeCount)},
|
||||||
|
newState,
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// Discard state
|
// Discard state
|
||||||
state = nil
|
state = nil
|
||||||
@@ -117,7 +284,6 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo
|
|||||||
|
|
||||||
var rest string
|
var rest string
|
||||||
var trimmed string
|
var trimmed string
|
||||||
|
|
||||||
if prevIdx == 0 {
|
if prevIdx == 0 {
|
||||||
// No ANSI code found
|
// No ANSI code found
|
||||||
rest = str
|
rest = str
|
||||||
@@ -127,48 +293,97 @@ func extractColor(str string, state *ansiState, proc func(string, *ansiState) bo
|
|||||||
output.WriteString(rest)
|
output.WriteString(rest)
|
||||||
trimmed = output.String()
|
trimmed = output.String()
|
||||||
}
|
}
|
||||||
|
if proc != nil {
|
||||||
|
proc(rest, state)
|
||||||
|
}
|
||||||
|
if len(offsets) > 0 {
|
||||||
if len(rest) > 0 && state != nil {
|
if len(rest) > 0 && state != nil {
|
||||||
// Update last offset
|
// Update last offset
|
||||||
runeCount += utf8.RuneCountInString(rest)
|
runeCount += utf8.RuneCountInString(rest)
|
||||||
(&offsets[len(offsets)-1]).offset[1] = int32(runeCount)
|
(&offsets[len(offsets)-1]).offset[1] = int32(runeCount)
|
||||||
}
|
}
|
||||||
if proc != nil {
|
// Return a copy of the offsets slice
|
||||||
proc(rest, state)
|
a := make([]ansiOffset, len(offsets))
|
||||||
|
copy(a, offsets)
|
||||||
|
return trimmed, &a, state
|
||||||
}
|
}
|
||||||
if len(offsets) == 0 {
|
|
||||||
return trimmed, nil, state
|
return trimmed, nil, state
|
||||||
}
|
}
|
||||||
return trimmed, &offsets, state
|
|
||||||
|
func parseAnsiCode(s string, delimiter byte) (int, byte, string) {
|
||||||
|
var remaining string
|
||||||
|
var i int
|
||||||
|
if delimiter == 0 {
|
||||||
|
// Faster than strings.IndexAny(";:")
|
||||||
|
i = strings.IndexByte(s, ';')
|
||||||
|
if i < 0 {
|
||||||
|
i = strings.IndexByte(s, ':')
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i = strings.IndexByte(s, delimiter)
|
||||||
|
}
|
||||||
|
if i >= 0 {
|
||||||
|
delimiter = s[i]
|
||||||
|
remaining = s[i+1:]
|
||||||
|
s = s[:i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
|
if len(s) > 0 {
|
||||||
// State
|
// Inlined version of strconv.Atoi() that only handles positive
|
||||||
var state *ansiState
|
// integers and does not allocate on error.
|
||||||
|
code := 0
|
||||||
|
for _, ch := range stringBytes(s) {
|
||||||
|
ch -= '0'
|
||||||
|
if ch > 9 {
|
||||||
|
return -1, delimiter, remaining
|
||||||
|
}
|
||||||
|
code = code*10 + int(ch)
|
||||||
|
}
|
||||||
|
return code, delimiter, remaining
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1, delimiter, remaining
|
||||||
|
}
|
||||||
|
|
||||||
|
func interpretCode(ansiCode string, prevState *ansiState) ansiState {
|
||||||
|
var state ansiState
|
||||||
if prevState == nil {
|
if prevState == nil {
|
||||||
state = &ansiState{-1, -1, 0}
|
state = ansiState{-1, -1, 0, -1, nil}
|
||||||
} else {
|
} else {
|
||||||
state = &ansiState{prevState.fg, prevState.bg, prevState.attr}
|
state = ansiState{prevState.fg, prevState.bg, prevState.attr, prevState.lbg, prevState.url}
|
||||||
}
|
}
|
||||||
if ansiCode[0] != '\x1b' || ansiCode[1] != '[' || ansiCode[len(ansiCode)-1] != 'm' {
|
if ansiCode[0] != '\x1b' || ansiCode[1] != '[' || ansiCode[len(ansiCode)-1] != 'm' {
|
||||||
|
if prevState != nil && strings.HasSuffix(ansiCode, "0K") {
|
||||||
|
state.lbg = prevState.bg
|
||||||
|
} else if ansiCode == "\x1b]8;;\x1b\\" { // End of a hyperlink
|
||||||
|
state.url = nil
|
||||||
|
} else if strings.HasPrefix(ansiCode, "\x1b]8;") && strings.HasSuffix(ansiCode, "\x1b\\") {
|
||||||
|
if paramsEnd := strings.IndexRune(ansiCode[4:], ';'); paramsEnd >= 0 {
|
||||||
|
params := ansiCode[4 : 4+paramsEnd]
|
||||||
|
uri := ansiCode[5+paramsEnd : len(ansiCode)-2]
|
||||||
|
state.url = &url{uri: uri, params: params}
|
||||||
|
}
|
||||||
|
}
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr := &state.fg
|
if len(ansiCode) <= 3 {
|
||||||
state256 := 0
|
|
||||||
|
|
||||||
init := func() {
|
|
||||||
state.fg = -1
|
state.fg = -1
|
||||||
state.bg = -1
|
state.bg = -1
|
||||||
state.attr = 0
|
state.attr = 0
|
||||||
state256 = 0
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
ansiCode = ansiCode[2 : len(ansiCode)-1]
|
ansiCode = ansiCode[2 : len(ansiCode)-1]
|
||||||
if len(ansiCode) == 0 {
|
|
||||||
init()
|
state256 := 0
|
||||||
}
|
ptr := &state.fg
|
||||||
for _, code := range strings.Split(ansiCode, ";") {
|
|
||||||
if num, err := strconv.Atoi(code); err == nil {
|
var delimiter byte
|
||||||
|
count := 0
|
||||||
|
for len(ansiCode) != 0 {
|
||||||
|
var num int
|
||||||
|
if num, delimiter, ansiCode = parseAnsiCode(ansiCode, delimiter); num != -1 {
|
||||||
|
count++
|
||||||
switch state256 {
|
switch state256 {
|
||||||
case 0:
|
case 0:
|
||||||
switch num {
|
switch num {
|
||||||
@@ -194,8 +409,26 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
|
|||||||
state.attr = state.attr | tui.Blink
|
state.attr = state.attr | tui.Blink
|
||||||
case 7:
|
case 7:
|
||||||
state.attr = state.attr | tui.Reverse
|
state.attr = state.attr | tui.Reverse
|
||||||
|
case 9:
|
||||||
|
state.attr = state.attr | tui.StrikeThrough
|
||||||
|
case 22:
|
||||||
|
state.attr = state.attr &^ tui.Bold
|
||||||
|
state.attr = state.attr &^ tui.Dim
|
||||||
|
case 23: // tput rmso
|
||||||
|
state.attr = state.attr &^ tui.Italic
|
||||||
|
case 24: // tput rmul
|
||||||
|
state.attr = state.attr &^ tui.Underline
|
||||||
|
case 25:
|
||||||
|
state.attr = state.attr &^ tui.Blink
|
||||||
|
case 27:
|
||||||
|
state.attr = state.attr &^ tui.Reverse
|
||||||
|
case 29:
|
||||||
|
state.attr = state.attr &^ tui.StrikeThrough
|
||||||
case 0:
|
case 0:
|
||||||
init()
|
state.fg = -1
|
||||||
|
state.bg = -1
|
||||||
|
state.attr = 0
|
||||||
|
state256 = 0
|
||||||
default:
|
default:
|
||||||
if num >= 30 && num <= 37 {
|
if num >= 30 && num <= 37 {
|
||||||
state.fg = tui.Color(num - 30)
|
state.fg = tui.Color(num - 30)
|
||||||
@@ -231,6 +464,14 @@ func interpretCode(ansiCode string, prevState *ansiState) *ansiState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty sequence: reset
|
||||||
|
if count == 0 {
|
||||||
|
state.fg = -1
|
||||||
|
state.bg = -1
|
||||||
|
state.attr = 0
|
||||||
|
}
|
||||||
|
|
||||||
if state256 > 0 {
|
if state256 > 0 {
|
||||||
*ptr = -1
|
*ptr = -1
|
||||||
}
|
}
|
||||||
|
|||||||
279
src/ansi_test.go
279
src/ansi_test.go
@@ -1,12 +1,192 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"math/rand"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/tui"
|
"github.com/junegunn/fzf/src/tui"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// The following regular expression will include not all but most of the
|
||||||
|
// frequently used ANSI sequences. This regex is used as a reference for
|
||||||
|
// testing nextAnsiEscapeSequence().
|
||||||
|
//
|
||||||
|
// References:
|
||||||
|
// - https://github.com/gnachman/iTerm2
|
||||||
|
// - https://web.archive.org/web/20090204053813/http://ascii-table.com/ansi-escape-sequences.php
|
||||||
|
// (archived from http://ascii-table.com/ansi-escape-sequences.php)
|
||||||
|
// - https://web.archive.org/web/20090227051140/http://ascii-table.com/ansi-escape-sequences-vt-100.php
|
||||||
|
// (archived from http://ascii-table.com/ansi-escape-sequences-vt-100.php)
|
||||||
|
// - http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x405.html
|
||||||
|
// - https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
|
||||||
|
var ansiRegexReference = regexp.MustCompile("(?:\x1b[\\[()][0-9;:]*[a-zA-Z@]|\x1b][0-9][;:][[:print:]]+(?:\x1b\\\\|\x07)|\x1b.|[\x0e\x0f]|.\x08)")
|
||||||
|
|
||||||
|
func testParserReference(t testing.TB, str string) {
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
|
toSlice := func(start, end int) []int {
|
||||||
|
if start == -1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return []int{start, end}
|
||||||
|
}
|
||||||
|
|
||||||
|
s := str
|
||||||
|
for i := 0; ; i++ {
|
||||||
|
got := toSlice(nextAnsiEscapeSequence(s))
|
||||||
|
exp := ansiRegexReference.FindStringIndex(s)
|
||||||
|
|
||||||
|
equal := len(got) == len(exp)
|
||||||
|
if equal {
|
||||||
|
for i := 0; i < len(got); i++ {
|
||||||
|
if got[i] != exp[i] {
|
||||||
|
equal = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !equal {
|
||||||
|
var exps, gots []rune
|
||||||
|
if len(got) == 2 {
|
||||||
|
gots = []rune(s[got[0]:got[1]])
|
||||||
|
}
|
||||||
|
if len(exp) == 2 {
|
||||||
|
exps = []rune(s[exp[0]:exp[1]])
|
||||||
|
}
|
||||||
|
t.Errorf("%d: %q: got: %v (%q) want: %v (%q)", i, s, got, gots, exp, exps)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(exp) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s = s[exp[1]:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNextAnsiEscapeSequence(t *testing.T) {
|
||||||
|
testStrs := []string{
|
||||||
|
"\x1b[0mhello world",
|
||||||
|
"\x1b[1mhello world",
|
||||||
|
"椙\x1b[1m椙",
|
||||||
|
"椙\x1b[1椙m椙",
|
||||||
|
"\x1b[1mhello \x1b[mw\x1b7o\x1b8r\x1b(Bl\x1b[2@d",
|
||||||
|
"\x1b[1mhello \x1b[Kworld",
|
||||||
|
"hello \x1b[34;45;1mworld",
|
||||||
|
"hello \x1b[34;45;1mwor\x1b[34;45;1mld",
|
||||||
|
"hello \x1b[34;45;1mwor\x1b[0mld",
|
||||||
|
"hello \x1b[34;48;5;233;1mwo\x1b[38;5;161mr\x1b[0ml\x1b[38;5;161md",
|
||||||
|
"hello \x1b[38;5;38;48;5;48;1mwor\x1b[38;5;48;48;5;38ml\x1b[0md",
|
||||||
|
"hello \x1b[32;1mworld",
|
||||||
|
"hello world",
|
||||||
|
"hello \x1b[0;38;5;200;48;5;100mworld",
|
||||||
|
"\x1b椙",
|
||||||
|
"椙\x08",
|
||||||
|
"\n\x08",
|
||||||
|
"X\x08",
|
||||||
|
"",
|
||||||
|
"\x1b]4;3;rgb:aa/bb/cc\x07 ",
|
||||||
|
"\x1b]4;3;rgb:aa/bb/cc\x1b\\ ",
|
||||||
|
ansiBenchmarkString,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range testStrs {
|
||||||
|
testParserReference(t, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNextAnsiEscapeSequence_Fuzz_Modified(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("short test")
|
||||||
|
}
|
||||||
|
|
||||||
|
testStrs := []string{
|
||||||
|
"\x1b[0mhello world",
|
||||||
|
"\x1b[1mhello world",
|
||||||
|
"椙\x1b[1m椙",
|
||||||
|
"椙\x1b[1椙m椙",
|
||||||
|
"\x1b[1mhello \x1b[mw\x1b7o\x1b8r\x1b(Bl\x1b[2@d",
|
||||||
|
"\x1b[1mhello \x1b[Kworld",
|
||||||
|
"hello \x1b[34;45;1mworld",
|
||||||
|
"hello \x1b[34;45;1mwor\x1b[34;45;1mld",
|
||||||
|
"hello \x1b[34;45;1mwor\x1b[0mld",
|
||||||
|
"hello \x1b[34;48;5;233;1mwo\x1b[38;5;161mr\x1b[0ml\x1b[38;5;161md",
|
||||||
|
"hello \x1b[38;5;38;48;5;48;1mwor\x1b[38;5;48;48;5;38ml\x1b[0md",
|
||||||
|
"hello \x1b[32;1mworld",
|
||||||
|
"hello world",
|
||||||
|
"hello \x1b[0;38;5;200;48;5;100mworld",
|
||||||
|
ansiBenchmarkString,
|
||||||
|
}
|
||||||
|
|
||||||
|
replacementBytes := [...]rune{'\x0e', '\x0f', '\x1b', '\x08'}
|
||||||
|
|
||||||
|
modifyString := func(s string, rr *rand.Rand) string {
|
||||||
|
n := rr.Intn(len(s))
|
||||||
|
b := []rune(s)
|
||||||
|
for ; n >= 0 && len(b) != 0; n-- {
|
||||||
|
i := rr.Intn(len(b))
|
||||||
|
switch x := rr.Intn(4); x {
|
||||||
|
case 0:
|
||||||
|
b = append(b[:i], b[i+1:]...)
|
||||||
|
case 1:
|
||||||
|
j := rr.Intn(len(replacementBytes) - 1)
|
||||||
|
b[i] = replacementBytes[j]
|
||||||
|
case 2:
|
||||||
|
x := rune(rr.Intn(utf8.MaxRune))
|
||||||
|
for !utf8.ValidRune(x) {
|
||||||
|
x = rune(rr.Intn(utf8.MaxRune))
|
||||||
|
}
|
||||||
|
b[i] = x
|
||||||
|
case 3:
|
||||||
|
b[i] = rune(rr.Intn(utf8.MaxRune)) // potentially invalid
|
||||||
|
default:
|
||||||
|
t.Fatalf("unsupported value: %d", x)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
rr := rand.New(rand.NewSource(1))
|
||||||
|
for _, s := range testStrs {
|
||||||
|
for i := 1_000; i >= 0; i-- {
|
||||||
|
testParserReference(t, modifyString(s, rr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNextAnsiEscapeSequence_Fuzz_Random(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("short test")
|
||||||
|
}
|
||||||
|
|
||||||
|
randomString := func(rr *rand.Rand) string {
|
||||||
|
numChars := rand.Intn(50)
|
||||||
|
codePoints := make([]rune, numChars)
|
||||||
|
for i := 0; i < len(codePoints); i++ {
|
||||||
|
var r rune
|
||||||
|
for n := 0; n < 1000; n++ {
|
||||||
|
r = rune(rr.Intn(utf8.MaxRune))
|
||||||
|
// Allow 10% of runes to be invalid
|
||||||
|
if utf8.ValidRune(r) || rr.Float64() < 0.10 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
codePoints[i] = r
|
||||||
|
}
|
||||||
|
return string(codePoints)
|
||||||
|
}
|
||||||
|
|
||||||
|
rr := rand.New(rand.NewSource(1))
|
||||||
|
for i := 0; i < 100_000; i++ {
|
||||||
|
testParserReference(t, randomString(rr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExtractColor(t *testing.T) {
|
func TestExtractColor(t *testing.T) {
|
||||||
assert := func(offset ansiOffset, b int32, e int32, fg tui.Color, bg tui.Color, bold bool) {
|
assert := func(offset ansiOffset, b int32, e int32, fg tui.Color, bg tui.Color, bold bool) {
|
||||||
var attr tui.Attr
|
var attr tui.Attr
|
||||||
@@ -26,9 +206,9 @@ func TestExtractColor(t *testing.T) {
|
|||||||
output, ansiOffsets, newState := extractColor(src, state, nil)
|
output, ansiOffsets, newState := extractColor(src, state, nil)
|
||||||
state = newState
|
state = newState
|
||||||
if output != "hello world" {
|
if output != "hello world" {
|
||||||
t.Errorf("Invalid output: %s %s", output, []rune(output))
|
t.Errorf("Invalid output: %s %v", output, []rune(output))
|
||||||
}
|
}
|
||||||
fmt.Println(src, ansiOffsets, clean)
|
t.Log(src, ansiOffsets, clean)
|
||||||
assertion(ansiOffsets, state)
|
assertion(ansiOffsets, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,3 +336,96 @@ func TestExtractColor(t *testing.T) {
|
|||||||
assert((*offsets)[1], 6, 11, 200, 100, false)
|
assert((*offsets)[1], 6, 11, 200, 100, false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAnsiCodeStringConversion(t *testing.T) {
|
||||||
|
assert := func(code string, prevState *ansiState, expected string) {
|
||||||
|
state := interpretCode(code, prevState)
|
||||||
|
if expected != state.ToString() {
|
||||||
|
t.Errorf("expected: %s, actual: %s",
|
||||||
|
strings.ReplaceAll(expected, "\x1b[", "\\x1b["),
|
||||||
|
strings.ReplaceAll(state.ToString(), "\x1b[", "\\x1b["))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert("\x1b[m", nil, "")
|
||||||
|
assert("\x1b[m", &ansiState{attr: tui.Blink, lbg: -1}, "")
|
||||||
|
assert("\x1b[0m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
assert("\x1b[;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
assert("\x1b[;;m", &ansiState{fg: 4, bg: 4, lbg: -1}, "")
|
||||||
|
|
||||||
|
assert("\x1b[31m", nil, "\x1b[31;49m")
|
||||||
|
assert("\x1b[41m", nil, "\x1b[39;41m")
|
||||||
|
|
||||||
|
assert("\x1b[92m", nil, "\x1b[92;49m")
|
||||||
|
assert("\x1b[102m", nil, "\x1b[39;102m")
|
||||||
|
|
||||||
|
assert("\x1b[31m", &ansiState{fg: 4, bg: 4, lbg: -1}, "\x1b[31;44m")
|
||||||
|
assert("\x1b[1;2;31m", &ansiState{fg: 2, bg: -1, attr: tui.Reverse, lbg: -1}, "\x1b[1;2;7;31;49m")
|
||||||
|
assert("\x1b[38;5;100;48;5;200m", nil, "\x1b[38;5;100;48;5;200m")
|
||||||
|
assert("\x1b[38:5:100:48:5:200m", nil, "\x1b[38;5;100;48;5;200m")
|
||||||
|
assert("\x1b[48;5;100;38;5;200m", nil, "\x1b[38;5;200;48;5;100m")
|
||||||
|
assert("\x1b[48;5;100;38;2;10;20;30;1m", nil, "\x1b[1;38;2;10;20;30;48;5;100m")
|
||||||
|
assert("\x1b[48;5;100;38;2;10;20;30;7m",
|
||||||
|
&ansiState{attr: tui.Dim | tui.Italic, fg: 1, bg: 1},
|
||||||
|
"\x1b[2;3;7;38;2;10;20;30;48;5;100m")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseAnsiCode(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
In, Exp string
|
||||||
|
N int
|
||||||
|
}{
|
||||||
|
{"123", "", 123},
|
||||||
|
{"1a", "", -1},
|
||||||
|
{"1a;12", "12", -1},
|
||||||
|
{"12;a", "a", 12},
|
||||||
|
{"-2", "", -1},
|
||||||
|
}
|
||||||
|
for _, x := range tests {
|
||||||
|
n, _, s := parseAnsiCode(x.In, 0)
|
||||||
|
if n != x.N || s != x.Exp {
|
||||||
|
t.Fatalf("%q: got: (%d %q) want: (%d %q)", x.In, n, s, x.N, x.Exp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// kernel/bpf/preload/iterators/README
|
||||||
|
const ansiBenchmarkString = "\x1b[38;5;81m\x1b[01;31m\x1b[Kkernel/\x1b[0m\x1b[38:5:81mbpf/" +
|
||||||
|
"\x1b[0m\x1b[38:5:81mpreload/\x1b[0m\x1b[38;5;81miterators/" +
|
||||||
|
"\x1b[0m\x1b[38:5:149mMakefile\x1b[m\x1b[K\x1b[0m"
|
||||||
|
|
||||||
|
func BenchmarkNextAnsiEscapeSequence(b *testing.B) {
|
||||||
|
b.SetBytes(int64(len(ansiBenchmarkString)))
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
s := ansiBenchmarkString
|
||||||
|
for {
|
||||||
|
_, o := nextAnsiEscapeSequence(s)
|
||||||
|
if o == -1 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
s = s[o:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Baseline test to compare the speed of nextAnsiEscapeSequence() to the
|
||||||
|
// previously used regex based implementation.
|
||||||
|
func BenchmarkNextAnsiEscapeSequence_Regex(b *testing.B) {
|
||||||
|
b.SetBytes(int64(len(ansiBenchmarkString)))
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
s := ansiBenchmarkString
|
||||||
|
for {
|
||||||
|
a := ansiRegexReference.FindStringIndex(s)
|
||||||
|
if len(a) == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
s = s[a[1]:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkExtractColor(b *testing.B) {
|
||||||
|
b.SetBytes(int64(len(ansiBenchmarkString)))
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
extractColor(ansiBenchmarkString, nil, nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
18
src/cache.go
18
src/cache.go
@@ -12,8 +12,22 @@ type ChunkCache struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewChunkCache returns a new ChunkCache
|
// NewChunkCache returns a new ChunkCache
|
||||||
func NewChunkCache() ChunkCache {
|
func NewChunkCache() *ChunkCache {
|
||||||
return ChunkCache{sync.Mutex{}, make(map[*Chunk]*queryCache)}
|
return &ChunkCache{sync.Mutex{}, make(map[*Chunk]*queryCache)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *ChunkCache) Clear() {
|
||||||
|
cc.mutex.Lock()
|
||||||
|
cc.cache = make(map[*Chunk]*queryCache)
|
||||||
|
cc.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cc *ChunkCache) retire(chunk ...*Chunk) {
|
||||||
|
cc.mutex.Lock()
|
||||||
|
for _, c := range chunk {
|
||||||
|
delete(cc.cache, c)
|
||||||
|
}
|
||||||
|
cc.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the list to the cache
|
// Add adds the list to the cache
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ func TestChunkCache(t *testing.T) {
|
|||||||
cache := NewChunkCache()
|
cache := NewChunkCache()
|
||||||
chunk1p := &Chunk{}
|
chunk1p := &Chunk{}
|
||||||
chunk2p := &Chunk{count: chunkSize}
|
chunk2p := &Chunk{count: chunkSize}
|
||||||
items1 := []Result{Result{}}
|
items1 := []Result{{}}
|
||||||
items2 := []Result{Result{}, Result{}}
|
items2 := []Result{{}, {}}
|
||||||
cache.Add(chunk1p, "foo", items1)
|
cache.Add(chunk1p, "foo", items1)
|
||||||
cache.Add(chunk2p, "foo", items1)
|
cache.Add(chunk2p, "foo", items1)
|
||||||
cache.Add(chunk2p, "bar", items2)
|
cache.Add(chunk2p, "bar", items2)
|
||||||
|
|||||||
@@ -16,14 +16,16 @@ type ChunkList struct {
|
|||||||
chunks []*Chunk
|
chunks []*Chunk
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
trans ItemBuilder
|
trans ItemBuilder
|
||||||
|
cache *ChunkCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewChunkList returns a new ChunkList
|
// NewChunkList returns a new ChunkList
|
||||||
func NewChunkList(trans ItemBuilder) *ChunkList {
|
func NewChunkList(cache *ChunkCache, trans ItemBuilder) *ChunkList {
|
||||||
return &ChunkList{
|
return &ChunkList{
|
||||||
chunks: []*Chunk{},
|
chunks: []*Chunk{},
|
||||||
mutex: sync.Mutex{},
|
mutex: sync.Mutex{},
|
||||||
trans: trans}
|
trans: trans,
|
||||||
|
cache: cache}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Chunk) push(trans ItemBuilder, data []byte) bool {
|
func (c *Chunk) push(trans ItemBuilder, data []byte) bool {
|
||||||
@@ -48,7 +50,12 @@ func CountItems(cs []*Chunk) int {
|
|||||||
if len(cs) == 0 {
|
if len(cs) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return chunkSize*(len(cs)-1) + cs[len(cs)-1].count
|
if len(cs) == 1 {
|
||||||
|
return cs[0].count
|
||||||
|
}
|
||||||
|
|
||||||
|
// First chunk might not be full due to --tail=N
|
||||||
|
return cs[0].count + chunkSize*(len(cs)-2) + cs[len(cs)-1].count
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push adds the item to the list
|
// Push adds the item to the list
|
||||||
@@ -64,19 +71,64 @@ func (cl *ChunkList) Push(data []byte) bool {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
// Snapshot returns immutable snapshot of the ChunkList
|
// Clear clears the data
|
||||||
func (cl *ChunkList) Snapshot() ([]*Chunk, int) {
|
func (cl *ChunkList) Clear() {
|
||||||
cl.mutex.Lock()
|
cl.mutex.Lock()
|
||||||
|
cl.chunks = nil
|
||||||
|
cl.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Snapshot returns immutable snapshot of the ChunkList
|
||||||
|
func (cl *ChunkList) Snapshot(tail int) ([]*Chunk, int, bool) {
|
||||||
|
cl.mutex.Lock()
|
||||||
|
|
||||||
|
changed := false
|
||||||
|
if tail > 0 && CountItems(cl.chunks) > tail {
|
||||||
|
changed = true
|
||||||
|
// Find the number of chunks to keep
|
||||||
|
numChunks := 0
|
||||||
|
for left, i := tail, len(cl.chunks)-1; left > 0 && i >= 0; i-- {
|
||||||
|
numChunks++
|
||||||
|
left -= cl.chunks[i].count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy the chunks to keep
|
||||||
|
ret := make([]*Chunk, numChunks)
|
||||||
|
minIndex := len(cl.chunks) - numChunks
|
||||||
|
cl.cache.retire(cl.chunks[:minIndex]...)
|
||||||
|
copy(ret, cl.chunks[minIndex:])
|
||||||
|
|
||||||
|
for left, i := tail, len(ret)-1; i >= 0; i-- {
|
||||||
|
chunk := ret[i]
|
||||||
|
if chunk.count > left {
|
||||||
|
newChunk := *chunk
|
||||||
|
newChunk.count = left
|
||||||
|
oldCount := chunk.count
|
||||||
|
for i := 0; i < left; i++ {
|
||||||
|
newChunk.items[i] = chunk.items[oldCount-left+i]
|
||||||
|
}
|
||||||
|
ret[i] = &newChunk
|
||||||
|
cl.cache.retire(chunk)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
left -= chunk.count
|
||||||
|
}
|
||||||
|
cl.chunks = ret
|
||||||
|
}
|
||||||
|
|
||||||
ret := make([]*Chunk, len(cl.chunks))
|
ret := make([]*Chunk, len(cl.chunks))
|
||||||
copy(ret, cl.chunks)
|
copy(ret, cl.chunks)
|
||||||
|
|
||||||
// Duplicate the last chunk
|
// Duplicate the first and the last chunk
|
||||||
if cnt := len(ret); cnt > 0 {
|
if cnt := len(ret); cnt > 0 {
|
||||||
|
if tail > 0 && cnt > 1 {
|
||||||
|
newChunk := *ret[0]
|
||||||
|
ret[0] = &newChunk
|
||||||
|
}
|
||||||
newChunk := *ret[cnt-1]
|
newChunk := *ret[cnt-1]
|
||||||
ret[cnt-1] = &newChunk
|
ret[cnt-1] = &newChunk
|
||||||
}
|
}
|
||||||
|
|
||||||
cl.mutex.Unlock()
|
cl.mutex.Unlock()
|
||||||
return ret, CountItems(ret)
|
return ret, CountItems(ret), changed
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ func TestChunkList(t *testing.T) {
|
|||||||
// FIXME global
|
// FIXME global
|
||||||
sortCriteria = []criterion{byScore, byLength}
|
sortCriteria = []criterion{byScore, byLength}
|
||||||
|
|
||||||
cl := NewChunkList(func(item *Item, s []byte) bool {
|
cl := NewChunkList(NewChunkCache(), func(item *Item, s []byte) bool {
|
||||||
item.text = util.ToChars(s)
|
item.text = util.ToChars(s)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
// Snapshot
|
// Snapshot
|
||||||
snapshot, count := cl.Snapshot()
|
snapshot, count, _ := cl.Snapshot(0)
|
||||||
if len(snapshot) > 0 || count > 0 {
|
if len(snapshot) > 0 || count > 0 {
|
||||||
t.Error("Snapshot should be empty now")
|
t.Error("Snapshot should be empty now")
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func TestChunkList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// But the new snapshot should contain the added items
|
// But the new snapshot should contain the added items
|
||||||
snapshot, count = cl.Snapshot()
|
snapshot, count, _ = cl.Snapshot(0)
|
||||||
if len(snapshot) != 1 && count != 2 {
|
if len(snapshot) != 1 && count != 2 {
|
||||||
t.Error("Snapshot should not be empty now")
|
t.Error("Snapshot should not be empty now")
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ func TestChunkList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New snapshot
|
// New snapshot
|
||||||
snapshot, count = cl.Snapshot()
|
snapshot, count, _ = cl.Snapshot(0)
|
||||||
if len(snapshot) != 3 || !snapshot[0].IsFull() ||
|
if len(snapshot) != 3 || !snapshot[0].IsFull() ||
|
||||||
!snapshot[1].IsFull() || snapshot[2].IsFull() || count != chunkSize*2+2 {
|
!snapshot[1].IsFull() || snapshot[2].IsFull() || count != chunkSize*2+2 {
|
||||||
t.Error("Expected two full chunks and one more chunk")
|
t.Error("Expected two full chunks and one more chunk")
|
||||||
@@ -78,3 +78,39 @@ func TestChunkList(t *testing.T) {
|
|||||||
t.Error("Unexpected number of items:", lastChunkCount)
|
t.Error("Unexpected number of items:", lastChunkCount)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChunkListTail(t *testing.T) {
|
||||||
|
cl := NewChunkList(NewChunkCache(), func(item *Item, s []byte) bool {
|
||||||
|
item.text = util.ToChars(s)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
total := chunkSize*2 + chunkSize/2
|
||||||
|
for i := 0; i < total; i++ {
|
||||||
|
cl.Push([]byte(fmt.Sprintf("item %d", i)))
|
||||||
|
}
|
||||||
|
|
||||||
|
snapshot, count, changed := cl.Snapshot(0)
|
||||||
|
assertCount := func(expected int, shouldChange bool) {
|
||||||
|
if count != expected || CountItems(snapshot) != expected {
|
||||||
|
t.Errorf("Unexpected count: %d (expected: %d)", count, expected)
|
||||||
|
}
|
||||||
|
if changed != shouldChange {
|
||||||
|
t.Error("Unexpected change status")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertCount(total, false)
|
||||||
|
|
||||||
|
tail := chunkSize + chunkSize/2
|
||||||
|
snapshot, count, changed = cl.Snapshot(tail)
|
||||||
|
assertCount(tail, true)
|
||||||
|
|
||||||
|
snapshot, count, changed = cl.Snapshot(tail)
|
||||||
|
assertCount(tail, false)
|
||||||
|
|
||||||
|
snapshot, count, changed = cl.Snapshot(0)
|
||||||
|
assertCount(tail, false)
|
||||||
|
|
||||||
|
tail = chunkSize / 2
|
||||||
|
snapshot, count, changed = cl.Snapshot(tail)
|
||||||
|
assertCount(tail, true)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Current version
|
|
||||||
version = "0.17.1"
|
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||||
coordinatorDelayStep time.Duration = 10 * time.Millisecond
|
coordinatorDelayStep time.Duration = 10 * time.Millisecond
|
||||||
|
|
||||||
// Reader
|
// Reader
|
||||||
readerBufferSize = 64 * 1024
|
readerBufferSize = 64 * 1024
|
||||||
|
readerSlabSize = 128 * 1024
|
||||||
readerPollIntervalMin = 10 * time.Millisecond
|
readerPollIntervalMin = 10 * time.Millisecond
|
||||||
readerPollIntervalStep = 5 * time.Millisecond
|
readerPollIntervalStep = 5 * time.Millisecond
|
||||||
readerPollIntervalMax = 50 * time.Millisecond
|
readerPollIntervalMax = 50 * time.Millisecond
|
||||||
@@ -24,7 +22,12 @@ const (
|
|||||||
// Terminal
|
// Terminal
|
||||||
initialDelay = 20 * time.Millisecond
|
initialDelay = 20 * time.Millisecond
|
||||||
initialDelayTac = 100 * time.Millisecond
|
initialDelayTac = 100 * time.Millisecond
|
||||||
spinnerDuration = 200 * time.Millisecond
|
spinnerDuration = 100 * time.Millisecond
|
||||||
|
previewCancelWait = 500 * time.Millisecond
|
||||||
|
previewChunkDelay = 100 * time.Millisecond
|
||||||
|
previewDelayed = 500 * time.Millisecond
|
||||||
|
maxPatternLength = 300
|
||||||
|
maxMulti = math.MaxInt32
|
||||||
|
|
||||||
// Matcher
|
// Matcher
|
||||||
numPartitionsMultiplier = 8
|
numPartitionsMultiplier = 8
|
||||||
@@ -51,18 +54,6 @@ const (
|
|||||||
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
||||||
)
|
)
|
||||||
|
|
||||||
var defaultCommand string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
if !util.IsWindows() {
|
|
||||||
defaultCommand = `set -o pipefail; (command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print || command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print) 2> /dev/null | cut -b3-`
|
|
||||||
} else if os.Getenv("TERM") == "cygwin" {
|
|
||||||
defaultCommand = `sh -c "command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-"`
|
|
||||||
} else {
|
|
||||||
defaultCommand = `dir /s/b`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fzf events
|
// fzf events
|
||||||
const (
|
const (
|
||||||
EvtReadNew util.EventType = iota
|
EvtReadNew util.EventType = iota
|
||||||
@@ -72,11 +63,13 @@ const (
|
|||||||
EvtSearchFin
|
EvtSearchFin
|
||||||
EvtHeader
|
EvtHeader
|
||||||
EvtReady
|
EvtReady
|
||||||
|
EvtQuit
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
exitOk = 0
|
ExitOk = 0
|
||||||
exitNoMatch = 1
|
ExitNoMatch = 1
|
||||||
exitError = 2
|
ExitError = 2
|
||||||
exitInterrupt = 130
|
ExitBecome = 126
|
||||||
|
ExitInterrupt = 130
|
||||||
)
|
)
|
||||||
|
|||||||
355
src/core.go
355
src/core.go
@@ -1,33 +1,9 @@
|
|||||||
/*
|
// Package fzf implements fzf, a command-line fuzzy finder.
|
||||||
Package fzf implements fzf, a command-line fuzzy finder.
|
|
||||||
|
|
||||||
The MIT License (MIT)
|
|
||||||
|
|
||||||
Copyright (c) 2017 Junegunn Choi
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
@@ -42,20 +18,52 @@ Matcher -> EvtSearchFin -> Terminal (update list)
|
|||||||
Matcher -> EvtHeader -> Terminal (update header)
|
Matcher -> EvtHeader -> Terminal (update header)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
type revision struct {
|
||||||
|
major int
|
||||||
|
minor int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *revision) bumpMajor() {
|
||||||
|
r.major++
|
||||||
|
r.minor = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *revision) bumpMinor() {
|
||||||
|
r.minor++
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r revision) compatible(other revision) bool {
|
||||||
|
return r.major == other.major
|
||||||
|
}
|
||||||
|
|
||||||
// Run starts fzf
|
// Run starts fzf
|
||||||
func Run(opts *Options, revision string) {
|
func Run(opts *Options) (int, error) {
|
||||||
|
if opts.Filter == nil {
|
||||||
|
if opts.Tmux != nil && len(os.Getenv("TMUX")) > 0 && opts.Tmux.index >= opts.Height.index {
|
||||||
|
return runTmux(os.Args, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
if needWinpty(opts) {
|
||||||
|
return runWinpty(os.Args, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := postProcessOptions(opts); err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer util.RunAtExitFuncs()
|
||||||
|
|
||||||
|
// Output channel given
|
||||||
|
if opts.Output != nil {
|
||||||
|
opts.Printer = func(str string) {
|
||||||
|
opts.Output <- str
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sort := opts.Sort > 0
|
sort := opts.Sort > 0
|
||||||
sortCriteria = opts.Criteria
|
sortCriteria = opts.Criteria
|
||||||
|
|
||||||
if opts.Version {
|
|
||||||
if len(revision) > 0 {
|
|
||||||
fmt.Printf("%s (%s)\n", version, revision)
|
|
||||||
} else {
|
|
||||||
fmt.Println(version)
|
|
||||||
}
|
|
||||||
os.Exit(exitOk)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Event channel
|
// Event channel
|
||||||
eventBox := util.NewEventBox()
|
eventBox := util.NewEventBox()
|
||||||
|
|
||||||
@@ -63,32 +71,35 @@ func Run(opts *Options, revision string) {
|
|||||||
ansiProcessor := func(data []byte) (util.Chars, *[]ansiOffset) {
|
ansiProcessor := func(data []byte) (util.Chars, *[]ansiOffset) {
|
||||||
return util.ToChars(data), nil
|
return util.ToChars(data), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var lineAnsiState, prevLineAnsiState *ansiState
|
||||||
if opts.Ansi {
|
if opts.Ansi {
|
||||||
if opts.Theme != nil {
|
if opts.Theme.Colored {
|
||||||
var state *ansiState
|
|
||||||
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
||||||
trimmed, offsets, newState := extractColor(string(data), state, nil)
|
prevLineAnsiState = lineAnsiState
|
||||||
state = newState
|
trimmed, offsets, newState := extractColor(byteString(data), lineAnsiState, nil)
|
||||||
return util.ToChars([]byte(trimmed)), offsets
|
lineAnsiState = newState
|
||||||
|
return util.ToChars(stringBytes(trimmed)), offsets
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// When color is disabled but ansi option is given,
|
// When color is disabled but ansi option is given,
|
||||||
// we simply strip out ANSI codes from the input
|
// we simply strip out ANSI codes from the input
|
||||||
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
ansiProcessor = func(data []byte) (util.Chars, *[]ansiOffset) {
|
||||||
trimmed, _, _ := extractColor(string(data), nil, nil)
|
trimmed, _, _ := extractColor(byteString(data), nil, nil)
|
||||||
return util.ToChars([]byte(trimmed)), nil
|
return util.ToChars(stringBytes(trimmed)), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chunk list
|
// Chunk list
|
||||||
|
cache := NewChunkCache()
|
||||||
var chunkList *ChunkList
|
var chunkList *ChunkList
|
||||||
var itemIndex int32
|
var itemIndex int32
|
||||||
header := make([]string, 0, opts.HeaderLines)
|
header := make([]string, 0, opts.HeaderLines)
|
||||||
if len(opts.WithNth) == 0 {
|
if len(opts.WithNth) == 0 {
|
||||||
chunkList = NewChunkList(func(item *Item, data []byte) bool {
|
chunkList = NewChunkList(cache, func(item *Item, data []byte) bool {
|
||||||
if len(header) < opts.HeaderLines {
|
if len(header) < opts.HeaderLines {
|
||||||
header = append(header, string(data))
|
header = append(header, byteString(data))
|
||||||
eventBox.Set(EvtHeader, header)
|
eventBox.Set(EvtHeader, header)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@@ -98,8 +109,24 @@ func Run(opts *Options, revision string) {
|
|||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
chunkList = NewChunkList(func(item *Item, data []byte) bool {
|
chunkList = NewChunkList(cache, func(item *Item, data []byte) bool {
|
||||||
tokens := Tokenize(string(data), opts.Delimiter)
|
tokens := Tokenize(byteString(data), opts.Delimiter)
|
||||||
|
if opts.Ansi && opts.Theme.Colored && len(tokens) > 1 {
|
||||||
|
var ansiState *ansiState
|
||||||
|
if prevLineAnsiState != nil {
|
||||||
|
ansiStateDup := *prevLineAnsiState
|
||||||
|
ansiState = &ansiStateDup
|
||||||
|
}
|
||||||
|
for _, token := range tokens {
|
||||||
|
prevAnsiState := ansiState
|
||||||
|
_, _, ansiState = extractColor(token.text.ToString(), ansiState, nil)
|
||||||
|
if prevAnsiState != nil {
|
||||||
|
token.text.Prepend("\x1b[m" + prevAnsiState.ToString())
|
||||||
|
} else {
|
||||||
|
token.text.Prepend("\x1b[m")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
trans := Transform(tokens, opts.WithNth)
|
trans := Transform(tokens, opts.WithNth)
|
||||||
transformed := joinTokens(trans)
|
transformed := joinTokens(trans)
|
||||||
if len(header) < opts.HeaderLines {
|
if len(header) < opts.HeaderLines {
|
||||||
@@ -107,7 +134,8 @@ func Run(opts *Options, revision string) {
|
|||||||
eventBox.Set(EvtHeader, header)
|
eventBox.Set(EvtHeader, header)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
item.text, item.colors = ansiProcessor([]byte(transformed))
|
item.text, item.colors = ansiProcessor(stringBytes(transformed))
|
||||||
|
item.text.TrimTrailingWhitespaces()
|
||||||
item.text.Index = itemIndex
|
item.text.Index = itemIndex
|
||||||
item.origText = &data
|
item.origText = &data
|
||||||
itemIndex++
|
itemIndex++
|
||||||
@@ -115,32 +143,60 @@ func Run(opts *Options, revision string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process executor
|
||||||
|
executor := util.NewExecutor(opts.WithShell)
|
||||||
|
|
||||||
|
// Terminal I/O
|
||||||
|
var terminal *Terminal
|
||||||
|
var err error
|
||||||
|
var initialEnv []string
|
||||||
|
initialReload := opts.extractReloadOnStart()
|
||||||
|
if opts.Filter == nil {
|
||||||
|
terminal, err = NewTerminal(opts, eventBox, executor)
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
if len(initialReload) > 0 {
|
||||||
|
var temps []string
|
||||||
|
initialReload, temps = terminal.replacePlaceholderInInitialCommand(initialReload)
|
||||||
|
initialEnv = terminal.environ()
|
||||||
|
defer removeFiles(temps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reader
|
// Reader
|
||||||
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
|
streamingFilter := opts.Filter != nil && !sort && !opts.Tac && !opts.Sync
|
||||||
|
var reader *Reader
|
||||||
if !streamingFilter {
|
if !streamingFilter {
|
||||||
reader := NewReader(func(data []byte) bool {
|
reader = NewReader(func(data []byte) bool {
|
||||||
return chunkList.Push(data)
|
return chunkList.Push(data)
|
||||||
}, eventBox, opts.ReadZero)
|
}, eventBox, executor, opts.ReadZero, opts.Filter == nil)
|
||||||
go reader.ReadSource()
|
|
||||||
|
go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip, initialReload, initialEnv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matcher
|
// Matcher
|
||||||
forward := true
|
forward := true
|
||||||
for _, cri := range opts.Criteria[1:] {
|
withPos := false
|
||||||
if cri == byEnd {
|
for idx := len(opts.Criteria) - 1; idx > 0; idx-- {
|
||||||
|
switch opts.Criteria[idx] {
|
||||||
|
case byChunk:
|
||||||
|
withPos = true
|
||||||
|
case byEnd:
|
||||||
forward = false
|
forward = false
|
||||||
break
|
case byBegin:
|
||||||
}
|
forward = true
|
||||||
if cri == byBegin {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
patternCache := make(map[string]*Pattern)
|
||||||
patternBuilder := func(runes []rune) *Pattern {
|
patternBuilder := func(runes []rune) *Pattern {
|
||||||
return BuildPattern(
|
return BuildPattern(cache, patternCache,
|
||||||
opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward,
|
opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,
|
||||||
opts.Filter == nil, opts.Nth, opts.Delimiter, runes)
|
opts.Filter == nil, opts.Nth, opts.Delimiter, runes)
|
||||||
}
|
}
|
||||||
matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)
|
inputRevision := revision{}
|
||||||
|
snapshotRevision := revision{}
|
||||||
|
matcher := NewMatcher(cache, patternBuilder, sort, opts.Tac, eventBox, inputRevision)
|
||||||
|
|
||||||
// Filtering mode
|
// Filtering mode
|
||||||
if opts.Filter != nil {
|
if opts.Filter != nil {
|
||||||
@@ -149,27 +205,32 @@ func Run(opts *Options, revision string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pattern := patternBuilder([]rune(*opts.Filter))
|
pattern := patternBuilder([]rune(*opts.Filter))
|
||||||
|
matcher.sort = pattern.sortable
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
if streamingFilter {
|
if streamingFilter {
|
||||||
slab := util.MakeSlab(slab16Size, slab32Size)
|
slab := util.MakeSlab(slab16Size, slab32Size)
|
||||||
|
mutex := sync.Mutex{}
|
||||||
reader := NewReader(
|
reader := NewReader(
|
||||||
func(runes []byte) bool {
|
func(runes []byte) bool {
|
||||||
item := Item{}
|
item := Item{}
|
||||||
if chunkList.trans(&item, runes) {
|
if chunkList.trans(&item, runes) {
|
||||||
|
mutex.Lock()
|
||||||
if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil {
|
if result, _, _ := pattern.MatchItem(&item, false, slab); result != nil {
|
||||||
opts.Printer(item.text.ToString())
|
opts.Printer(item.text.ToString())
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
|
mutex.Unlock()
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}, eventBox, opts.ReadZero)
|
}, eventBox, executor, opts.ReadZero, false)
|
||||||
reader.ReadSource()
|
reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip, initialReload, initialEnv)
|
||||||
} else {
|
} else {
|
||||||
eventBox.Unwatch(EvtReadNew)
|
eventBox.Unwatch(EvtReadNew)
|
||||||
eventBox.WaitFor(EvtReadFin)
|
eventBox.WaitFor(EvtReadFin)
|
||||||
|
|
||||||
snapshot, _ := chunkList.Snapshot()
|
// NOTE: Streaming filter is inherently not compatible with --tail
|
||||||
|
snapshot, _, _ := chunkList.Snapshot(opts.Tail)
|
||||||
merger, _ := matcher.scan(MatchRequest{
|
merger, _ := matcher.scan(MatchRequest{
|
||||||
chunks: snapshot,
|
chunks: snapshot,
|
||||||
pattern: pattern})
|
pattern: pattern})
|
||||||
@@ -179,9 +240,9 @@ func Run(opts *Options, revision string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found {
|
if found {
|
||||||
os.Exit(exitOk)
|
return ExitOk, nil
|
||||||
}
|
}
|
||||||
os.Exit(exitNoMatch)
|
return ExitNoMatch, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronous search
|
// Synchronous search
|
||||||
@@ -192,45 +253,154 @@ func Run(opts *Options, revision string) {
|
|||||||
|
|
||||||
// Go interactive
|
// Go interactive
|
||||||
go matcher.Loop()
|
go matcher.Loop()
|
||||||
|
defer matcher.Stop()
|
||||||
|
|
||||||
// Terminal I/O
|
// Handling adaptive height
|
||||||
terminal := NewTerminal(opts, eventBox)
|
maxFit := 0 // Maximum number of items that can fit on screen
|
||||||
deferred := opts.Select1 || opts.Exit0
|
padHeight := 0
|
||||||
|
heightUnknown := opts.Height.auto
|
||||||
|
if heightUnknown {
|
||||||
|
maxFit, padHeight = terminal.MaxFitAndPad()
|
||||||
|
}
|
||||||
|
deferred := opts.Select1 || opts.Exit0 || opts.Sync
|
||||||
go terminal.Loop()
|
go terminal.Loop()
|
||||||
if !deferred {
|
if !deferred && !heightUnknown {
|
||||||
terminal.startChan <- true
|
// Start right away
|
||||||
|
terminal.startChan <- fitpad{-1, -1}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event coordination
|
// Event coordination
|
||||||
reading := true
|
reading := true
|
||||||
ticks := 0
|
ticks := 0
|
||||||
|
var nextCommand *commandSpec
|
||||||
|
var nextEnviron []string
|
||||||
eventBox.Watch(EvtReadNew)
|
eventBox.Watch(EvtReadNew)
|
||||||
|
total := 0
|
||||||
|
query := []rune{}
|
||||||
|
determine := func(final bool) {
|
||||||
|
if heightUnknown {
|
||||||
|
if total >= maxFit || final {
|
||||||
|
deferred = false
|
||||||
|
heightUnknown = false
|
||||||
|
terminal.startChan <- fitpad{util.Min(total, maxFit), padHeight}
|
||||||
|
}
|
||||||
|
} else if deferred {
|
||||||
|
deferred = false
|
||||||
|
terminal.startChan <- fitpad{-1, -1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
useSnapshot := false
|
||||||
|
var snapshot []*Chunk
|
||||||
|
var count int
|
||||||
|
restart := func(command commandSpec, environ []string) {
|
||||||
|
reading = true
|
||||||
|
chunkList.Clear()
|
||||||
|
itemIndex = 0
|
||||||
|
inputRevision.bumpMajor()
|
||||||
|
header = make([]string, 0, opts.HeaderLines)
|
||||||
|
go reader.restart(command, environ)
|
||||||
|
}
|
||||||
|
|
||||||
|
exitCode := ExitOk
|
||||||
|
stop := false
|
||||||
for {
|
for {
|
||||||
delay := true
|
delay := true
|
||||||
ticks++
|
ticks++
|
||||||
|
input := func() []rune {
|
||||||
|
paused, input := terminal.Input()
|
||||||
|
if !paused {
|
||||||
|
query = input
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
eventBox.Wait(func(events *util.Events) {
|
eventBox.Wait(func(events *util.Events) {
|
||||||
if _, fin := (*events)[EvtReadFin]; fin {
|
if _, fin := (*events)[EvtReadFin]; fin {
|
||||||
delete(*events, EvtReadNew)
|
delete(*events, EvtReadNew)
|
||||||
}
|
}
|
||||||
for evt, value := range *events {
|
for evt, value := range *events {
|
||||||
switch evt {
|
switch evt {
|
||||||
|
case EvtQuit:
|
||||||
case EvtReadNew, EvtReadFin:
|
if reading {
|
||||||
reading = reading && evt == EvtReadNew
|
reader.terminate()
|
||||||
snapshot, count := chunkList.Snapshot()
|
|
||||||
terminal.UpdateCount(count, !reading, value.(bool))
|
|
||||||
if opts.Sync {
|
|
||||||
terminal.UpdateList(PassMerger(&snapshot, opts.Tac))
|
|
||||||
}
|
}
|
||||||
matcher.Reset(snapshot, terminal.Input(), false, !reading, sort)
|
quitSignal := value.(quitSignal)
|
||||||
|
exitCode = quitSignal.code
|
||||||
|
err = quitSignal.err
|
||||||
|
stop = true
|
||||||
|
return
|
||||||
|
case EvtReadNew, EvtReadFin:
|
||||||
|
if evt == EvtReadFin && nextCommand != nil {
|
||||||
|
restart(*nextCommand, nextEnviron)
|
||||||
|
nextCommand = nil
|
||||||
|
nextEnviron = nil
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
reading = reading && evt == EvtReadNew
|
||||||
|
}
|
||||||
|
if useSnapshot && evt == EvtReadFin {
|
||||||
|
useSnapshot = false
|
||||||
|
}
|
||||||
|
if !useSnapshot {
|
||||||
|
if !snapshotRevision.compatible(inputRevision) {
|
||||||
|
query = []rune{}
|
||||||
|
}
|
||||||
|
var changed bool
|
||||||
|
snapshot, count, changed = chunkList.Snapshot(opts.Tail)
|
||||||
|
if changed {
|
||||||
|
inputRevision.bumpMinor()
|
||||||
|
}
|
||||||
|
snapshotRevision = inputRevision
|
||||||
|
}
|
||||||
|
total = count
|
||||||
|
terminal.UpdateCount(total, !reading, value.(*string))
|
||||||
|
if heightUnknown && !deferred {
|
||||||
|
determine(!reading)
|
||||||
|
}
|
||||||
|
matcher.Reset(snapshot, input(), false, !reading, sort, snapshotRevision)
|
||||||
|
|
||||||
case EvtSearchNew:
|
case EvtSearchNew:
|
||||||
|
var command *commandSpec
|
||||||
|
var environ []string
|
||||||
|
var changed bool
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
case bool:
|
case searchRequest:
|
||||||
sort = val
|
sort = val.sort
|
||||||
|
command = val.command
|
||||||
|
environ = val.environ
|
||||||
|
changed = val.changed
|
||||||
|
if command != nil {
|
||||||
|
useSnapshot = val.sync
|
||||||
}
|
}
|
||||||
snapshot, _ := chunkList.Snapshot()
|
}
|
||||||
matcher.Reset(snapshot, terminal.Input(), true, !reading, sort)
|
if command != nil {
|
||||||
|
if reading {
|
||||||
|
reader.terminate()
|
||||||
|
nextCommand = command
|
||||||
|
nextEnviron = environ
|
||||||
|
} else {
|
||||||
|
restart(*command, environ)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !changed {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if !useSnapshot {
|
||||||
|
newSnapshot, newCount, changed := chunkList.Snapshot(opts.Tail)
|
||||||
|
if changed {
|
||||||
|
inputRevision.bumpMinor()
|
||||||
|
}
|
||||||
|
// We want to avoid showing empty list when reload is triggered
|
||||||
|
// and the query string is changed at the same time i.e. command != nil && changed
|
||||||
|
if command == nil || newCount > 0 {
|
||||||
|
if snapshotRevision != inputRevision {
|
||||||
|
query = []rune{}
|
||||||
|
}
|
||||||
|
snapshot = newSnapshot
|
||||||
|
snapshotRevision = inputRevision
|
||||||
|
}
|
||||||
|
}
|
||||||
|
matcher.Reset(snapshot, input(), true, !reading, sort, snapshotRevision)
|
||||||
delay = false
|
delay = false
|
||||||
|
|
||||||
case EvtSearchProgress:
|
case EvtSearchProgress:
|
||||||
@@ -240,7 +410,9 @@ func Run(opts *Options, revision string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case EvtHeader:
|
case EvtHeader:
|
||||||
terminal.UpdateHeader(value.([]string))
|
headerPadded := make([]string, opts.HeaderLines)
|
||||||
|
copy(headerPadded, value.([]string))
|
||||||
|
terminal.UpdateHeader(headerPadded)
|
||||||
|
|
||||||
case EvtSearchFin:
|
case EvtSearchFin:
|
||||||
switch val := value.(type) {
|
switch val := value.(type) {
|
||||||
@@ -248,8 +420,7 @@ func Run(opts *Options, revision string) {
|
|||||||
if deferred {
|
if deferred {
|
||||||
count := val.Length()
|
count := val.Length()
|
||||||
if opts.Select1 && count > 1 || opts.Exit0 && !opts.Select1 && count > 0 {
|
if opts.Select1 && count > 1 || opts.Exit0 && !opts.Select1 && count > 0 {
|
||||||
deferred = false
|
determine(val.final)
|
||||||
terminal.startChan <- true
|
|
||||||
} else if val.final {
|
} else if val.final {
|
||||||
if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {
|
if opts.Exit0 && count == 0 || opts.Select1 && count == 1 {
|
||||||
if opts.PrintQuery {
|
if opts.PrintQuery {
|
||||||
@@ -261,13 +432,13 @@ func Run(opts *Options, revision string) {
|
|||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
opts.Printer(val.Get(i).item.AsString(opts.Ansi))
|
opts.Printer(val.Get(i).item.AsString(opts.Ansi))
|
||||||
}
|
}
|
||||||
if count > 0 {
|
if count == 0 {
|
||||||
os.Exit(exitOk)
|
exitCode = ExitNoMatch
|
||||||
}
|
}
|
||||||
os.Exit(exitNoMatch)
|
stop = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
deferred = false
|
determine(val.final)
|
||||||
terminal.startChan <- true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal.UpdateList(val)
|
terminal.UpdateList(val)
|
||||||
@@ -276,6 +447,9 @@ func Run(opts *Options, revision string) {
|
|||||||
}
|
}
|
||||||
events.Clear()
|
events.Clear()
|
||||||
})
|
})
|
||||||
|
if stop {
|
||||||
|
break
|
||||||
|
}
|
||||||
if delay && reading {
|
if delay && reading {
|
||||||
dur := util.DurWithin(
|
dur := util.DurWithin(
|
||||||
time.Duration(ticks)*coordinatorDelayStep,
|
time.Duration(ticks)*coordinatorDelayStep,
|
||||||
@@ -283,4 +457,5 @@ func Run(opts *Options, revision string) {
|
|||||||
time.Sleep(dur)
|
time.Sleep(dur)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return exitCode, err
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/functions.go
Normal file
35
src/functions.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func WriteTemporaryFile(data []string, printSep string) string {
|
||||||
|
f, err := os.CreateTemp("", "fzf-temp-*")
|
||||||
|
if err != nil {
|
||||||
|
// Unable to create temporary file
|
||||||
|
// FIXME: Should we terminate the program?
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
f.WriteString(strings.Join(data, printSep))
|
||||||
|
f.WriteString(printSep)
|
||||||
|
return f.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeFiles(files []string) {
|
||||||
|
for _, filename := range files {
|
||||||
|
os.Remove(filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func stringBytes(data string) []byte {
|
||||||
|
return unsafe.Slice(unsafe.StringData(data), len(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func byteString(data []byte) string {
|
||||||
|
return unsafe.String(unsafe.SliceData(data), len(data))
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ package fzf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -26,12 +25,12 @@ func NewHistory(path string, maxSize int) (*History, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read history file
|
// Read history file
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// If it doesn't exist, check if we can create a file with the name
|
// If it doesn't exist, check if we can create a file with the name
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
data = []byte{}
|
data = []byte{}
|
||||||
if err := ioutil.WriteFile(path, data, 0600); err != nil {
|
if err := os.WriteFile(path, data, 0600); err != nil {
|
||||||
return nil, fmtError(err)
|
return nil, fmtError(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -59,14 +58,14 @@ func (h *History) append(line string) error {
|
|||||||
|
|
||||||
lines := append(h.lines[:len(h.lines)-1], line)
|
lines := append(h.lines[:len(h.lines)-1], line)
|
||||||
if len(lines) > h.maxSize {
|
if len(lines) > h.maxSize {
|
||||||
lines = lines[len(lines)-h.maxSize : len(lines)]
|
lines = lines[len(lines)-h.maxSize:]
|
||||||
}
|
}
|
||||||
h.lines = append(lines, "")
|
h.lines = append(lines, "")
|
||||||
return ioutil.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600)
|
return os.WriteFile(h.path, []byte(strings.Join(h.lines, "\n")), 0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *History) override(str string) {
|
func (h *History) override(str string) {
|
||||||
// You can update the history but they're not written to the file
|
// You can update the history, but they're not written to the file
|
||||||
if h.cursor == len(h.lines)-1 {
|
if h.cursor == len(h.lines)-1 {
|
||||||
h.lines[h.cursor] = str
|
h.lines[h.cursor] = str
|
||||||
} else if h.cursor < len(h.lines)-1 {
|
} else if h.cursor < len(h.lines)-1 {
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -12,16 +10,12 @@ func TestHistory(t *testing.T) {
|
|||||||
maxHistory := 50
|
maxHistory := 50
|
||||||
|
|
||||||
// Invalid arguments
|
// Invalid arguments
|
||||||
user, _ := user.Current()
|
|
||||||
var paths []string
|
var paths []string
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
// GOPATH should exist, so we shouldn't be able to override it
|
// GOPATH should exist, so we shouldn't be able to override it
|
||||||
paths = []string{os.Getenv("GOPATH")}
|
paths = []string{os.Getenv("GOPATH")}
|
||||||
} else {
|
} else {
|
||||||
paths = []string{"/etc", "/proc"}
|
paths = []string{"/etc", "/proc"}
|
||||||
if user.Name != "root" {
|
|
||||||
paths = append(paths, "/etc/sudoers")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, path := range paths {
|
for _, path := range paths {
|
||||||
@@ -30,7 +24,7 @@ func TestHistory(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f, _ := ioutil.TempFile("", "fzf-history")
|
f, _ := os.CreateTemp("", "fzf-history")
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
{ // Append lines
|
{ // Append lines
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -17,7 +19,7 @@ func (item *Item) Index() int32 {
|
|||||||
return item.text.Index
|
return item.text.Index
|
||||||
}
|
}
|
||||||
|
|
||||||
var minItem = Item{text: util.Chars{Index: -1}}
|
var minItem = Item{text: util.Chars{Index: math.MinInt32}}
|
||||||
|
|
||||||
func (item *Item) TrimLength() uint16 {
|
func (item *Item) TrimLength() uint16 {
|
||||||
return item.text.TrimLength()
|
return item.text.TrimLength()
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ type MatchRequest struct {
|
|||||||
pattern *Pattern
|
pattern *Pattern
|
||||||
final bool
|
final bool
|
||||||
sort bool
|
sort bool
|
||||||
|
revision revision
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matcher is responsible for performing search
|
// Matcher is responsible for performing search
|
||||||
type Matcher struct {
|
type Matcher struct {
|
||||||
|
cache *ChunkCache
|
||||||
patternBuilder func([]rune) *Pattern
|
patternBuilder func([]rune) *Pattern
|
||||||
sort bool
|
sort bool
|
||||||
tac bool
|
tac bool
|
||||||
@@ -28,6 +30,7 @@ type Matcher struct {
|
|||||||
partitions int
|
partitions int
|
||||||
slab []*util.Slab
|
slab []*util.Slab
|
||||||
mergerCache map[string]*Merger
|
mergerCache map[string]*Merger
|
||||||
|
revision revision
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -36,10 +39,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewMatcher returns a new Matcher
|
// NewMatcher returns a new Matcher
|
||||||
func NewMatcher(patternBuilder func([]rune) *Pattern,
|
func NewMatcher(cache *ChunkCache, patternBuilder func([]rune) *Pattern,
|
||||||
sort bool, tac bool, eventBox *util.EventBox) *Matcher {
|
sort bool, tac bool, eventBox *util.EventBox, revision revision) *Matcher {
|
||||||
partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)
|
partitions := util.Min(numPartitionsMultiplier*runtime.NumCPU(), maxPartitions)
|
||||||
return &Matcher{
|
return &Matcher{
|
||||||
|
cache: cache,
|
||||||
patternBuilder: patternBuilder,
|
patternBuilder: patternBuilder,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
tac: tac,
|
tac: tac,
|
||||||
@@ -47,7 +51,8 @@ func NewMatcher(patternBuilder func([]rune) *Pattern,
|
|||||||
reqBox: util.NewEventBox(),
|
reqBox: util.NewEventBox(),
|
||||||
partitions: partitions,
|
partitions: partitions,
|
||||||
slab: make([]*util.Slab, partitions),
|
slab: make([]*util.Slab, partitions),
|
||||||
mergerCache: make(map[string]*Merger)}
|
mergerCache: make(map[string]*Merger),
|
||||||
|
revision: revision}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop puts Matcher in action
|
// Loop puts Matcher in action
|
||||||
@@ -57,8 +62,13 @@ func (m *Matcher) Loop() {
|
|||||||
for {
|
for {
|
||||||
var request MatchRequest
|
var request MatchRequest
|
||||||
|
|
||||||
|
stop := false
|
||||||
m.reqBox.Wait(func(events *util.Events) {
|
m.reqBox.Wait(func(events *util.Events) {
|
||||||
for _, val := range *events {
|
for t, val := range *events {
|
||||||
|
if t == reqQuit {
|
||||||
|
stop = true
|
||||||
|
return
|
||||||
|
}
|
||||||
switch val := val.(type) {
|
switch val := val.(type) {
|
||||||
case MatchRequest:
|
case MatchRequest:
|
||||||
request = val
|
request = val
|
||||||
@@ -68,11 +78,19 @@ func (m *Matcher) Loop() {
|
|||||||
}
|
}
|
||||||
events.Clear()
|
events.Clear()
|
||||||
})
|
})
|
||||||
|
if stop {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
if request.sort != m.sort {
|
cacheCleared := false
|
||||||
|
if request.sort != m.sort || request.revision != m.revision {
|
||||||
m.sort = request.sort
|
m.sort = request.sort
|
||||||
|
m.revision = request.revision
|
||||||
m.mergerCache = make(map[string]*Merger)
|
m.mergerCache = make(map[string]*Merger)
|
||||||
clearChunkCache()
|
if !request.revision.compatible(m.revision) {
|
||||||
|
m.cache.Clear()
|
||||||
|
}
|
||||||
|
cacheCleared = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restart search
|
// Restart search
|
||||||
@@ -81,11 +99,10 @@ func (m *Matcher) Loop() {
|
|||||||
cancelled := false
|
cancelled := false
|
||||||
count := CountItems(request.chunks)
|
count := CountItems(request.chunks)
|
||||||
|
|
||||||
foundCache := false
|
if !cacheCleared {
|
||||||
if count == prevCount {
|
if count == prevCount {
|
||||||
// Look up mergerCache
|
// Look up mergerCache
|
||||||
if cached, found := m.mergerCache[patternString]; found {
|
if cached, found := m.mergerCache[patternString]; found {
|
||||||
foundCache = true
|
|
||||||
merger = cached
|
merger = cached
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -93,8 +110,9 @@ func (m *Matcher) Loop() {
|
|||||||
prevCount = count
|
prevCount = count
|
||||||
m.mergerCache = make(map[string]*Merger)
|
m.mergerCache = make(map[string]*Merger)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !foundCache {
|
if merger == nil {
|
||||||
merger, cancelled = m.scan(request)
|
merger, cancelled = m.scan(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,13 +157,14 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|||||||
|
|
||||||
numChunks := len(request.chunks)
|
numChunks := len(request.chunks)
|
||||||
if numChunks == 0 {
|
if numChunks == 0 {
|
||||||
return EmptyMerger, false
|
return EmptyMerger(request.revision), false
|
||||||
}
|
}
|
||||||
pattern := request.pattern
|
pattern := request.pattern
|
||||||
if pattern.IsEmpty() {
|
if pattern.IsEmpty() {
|
||||||
return PassMerger(&request.chunks, m.tac), false
|
return PassMerger(&request.chunks, m.tac, request.revision), false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
minIndex := request.chunks[0].items[0].Index()
|
||||||
cancelled := util.NewAtomicBool(false)
|
cancelled := util.NewAtomicBool(false)
|
||||||
|
|
||||||
slices := m.sliceChunks(request.chunks)
|
slices := m.sliceChunks(request.chunks)
|
||||||
@@ -176,7 +195,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|||||||
for _, matches := range allMatches {
|
for _, matches := range allMatches {
|
||||||
sliceMatches = append(sliceMatches, matches...)
|
sliceMatches = append(sliceMatches, matches...)
|
||||||
}
|
}
|
||||||
if m.sort {
|
if m.sort && request.pattern.sortable {
|
||||||
if m.tac {
|
if m.tac {
|
||||||
sort.Sort(ByRelevanceTac(sliceMatches))
|
sort.Sort(ByRelevanceTac(sliceMatches))
|
||||||
} else {
|
} else {
|
||||||
@@ -207,21 +226,21 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|||||||
return nil, wait()
|
return nil, wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
if time.Now().Sub(startedAt) > progressMinDuration {
|
if time.Since(startedAt) > progressMinDuration {
|
||||||
m.eventBox.Set(EvtSearchProgress, float32(count)/float32(numChunks))
|
m.eventBox.Set(EvtSearchProgress, float32(count)/float32(numChunks))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
partialResults := make([][]Result, numSlices)
|
partialResults := make([][]Result, numSlices)
|
||||||
for _ = range slices {
|
for range slices {
|
||||||
partialResult := <-resultChan
|
partialResult := <-resultChan
|
||||||
partialResults[partialResult.index] = partialResult.matches
|
partialResults[partialResult.index] = partialResult.matches
|
||||||
}
|
}
|
||||||
return NewMerger(pattern, partialResults, m.sort, m.tac), false
|
return NewMerger(pattern, partialResults, m.sort && request.pattern.sortable, m.tac, request.revision, minIndex), false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset is called to interrupt/signal the ongoing search
|
// Reset is called to interrupt/signal the ongoing search
|
||||||
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool) {
|
func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final bool, sort bool, revision revision) {
|
||||||
pattern := m.patternBuilder(patternRunes)
|
pattern := m.patternBuilder(patternRunes)
|
||||||
|
|
||||||
var event util.EventType
|
var event util.EventType
|
||||||
@@ -230,5 +249,9 @@ func (m *Matcher) Reset(chunks []*Chunk, patternRunes []rune, cancel bool, final
|
|||||||
} else {
|
} else {
|
||||||
event = reqRetry
|
event = reqRetry
|
||||||
}
|
}
|
||||||
m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort})
|
m.reqBox.Set(event, MatchRequest{chunks, pattern, final, sort, revision})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Matcher) Stop() {
|
||||||
|
m.reqBox.Set(reqQuit, nil)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package fzf
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// EmptyMerger is a Merger with no data
|
// EmptyMerger is a Merger with no data
|
||||||
var EmptyMerger = NewMerger(nil, [][]Result{}, false, false)
|
func EmptyMerger(revision revision) *Merger {
|
||||||
|
return NewMerger(nil, [][]Result{}, false, false, revision, 0)
|
||||||
|
}
|
||||||
|
|
||||||
// Merger holds a set of locally sorted lists of items and provides the view of
|
// Merger holds a set of locally sorted lists of items and provides the view of
|
||||||
// a single, globally-sorted list
|
// a single, globally-sorted list
|
||||||
@@ -17,16 +19,26 @@ type Merger struct {
|
|||||||
tac bool
|
tac bool
|
||||||
final bool
|
final bool
|
||||||
count int
|
count int
|
||||||
|
pass bool
|
||||||
|
revision revision
|
||||||
|
minIndex int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// PassMerger returns a new Merger that simply returns the items in the
|
// PassMerger returns a new Merger that simply returns the items in the
|
||||||
// original order
|
// original order
|
||||||
func PassMerger(chunks *[]*Chunk, tac bool) *Merger {
|
func PassMerger(chunks *[]*Chunk, tac bool, revision revision) *Merger {
|
||||||
|
var minIndex int32
|
||||||
|
if len(*chunks) > 0 {
|
||||||
|
minIndex = (*chunks)[0].items[0].Index()
|
||||||
|
}
|
||||||
mg := Merger{
|
mg := Merger{
|
||||||
pattern: nil,
|
pattern: nil,
|
||||||
chunks: chunks,
|
chunks: chunks,
|
||||||
tac: tac,
|
tac: tac,
|
||||||
count: 0}
|
count: 0,
|
||||||
|
pass: true,
|
||||||
|
revision: revision,
|
||||||
|
minIndex: minIndex}
|
||||||
|
|
||||||
for _, chunk := range *mg.chunks {
|
for _, chunk := range *mg.chunks {
|
||||||
mg.count += chunk.count
|
mg.count += chunk.count
|
||||||
@@ -35,7 +47,7 @@ func PassMerger(chunks *[]*Chunk, tac bool) *Merger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewMerger returns a new Merger
|
// NewMerger returns a new Merger
|
||||||
func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool) *Merger {
|
func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool, revision revision, minIndex int32) *Merger {
|
||||||
mg := Merger{
|
mg := Merger{
|
||||||
pattern: pattern,
|
pattern: pattern,
|
||||||
lists: lists,
|
lists: lists,
|
||||||
@@ -45,7 +57,9 @@ func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool) *Merge
|
|||||||
sorted: sorted,
|
sorted: sorted,
|
||||||
tac: tac,
|
tac: tac,
|
||||||
final: false,
|
final: false,
|
||||||
count: 0}
|
count: 0,
|
||||||
|
revision: revision,
|
||||||
|
minIndex: minIndex}
|
||||||
|
|
||||||
for _, list := range mg.lists {
|
for _, list := range mg.lists {
|
||||||
mg.count += len(list)
|
mg.count += len(list)
|
||||||
@@ -53,17 +67,55 @@ func NewMerger(pattern *Pattern, lists [][]Result, sorted bool, tac bool) *Merge
|
|||||||
return &mg
|
return &mg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Revision returns revision number
|
||||||
|
func (mg *Merger) Revision() revision {
|
||||||
|
return mg.revision
|
||||||
|
}
|
||||||
|
|
||||||
// Length returns the number of items
|
// Length returns the number of items
|
||||||
func (mg *Merger) Length() int {
|
func (mg *Merger) Length() int {
|
||||||
return mg.count
|
return mg.count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (mg *Merger) First() Result {
|
||||||
|
if mg.tac && !mg.sorted {
|
||||||
|
return mg.Get(mg.count - 1)
|
||||||
|
}
|
||||||
|
return mg.Get(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FindIndex returns the index of the item with the given item index
|
||||||
|
func (mg *Merger) FindIndex(itemIndex int32) int {
|
||||||
|
index := -1
|
||||||
|
if mg.pass {
|
||||||
|
index = int(itemIndex - mg.minIndex)
|
||||||
|
if mg.tac {
|
||||||
|
index = mg.count - index - 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i := 0; i < mg.count; i++ {
|
||||||
|
if mg.Get(i).item.Index() == itemIndex {
|
||||||
|
index = i
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index
|
||||||
|
}
|
||||||
|
|
||||||
// Get returns the pointer to the Result object indexed by the given integer
|
// Get returns the pointer to the Result object indexed by the given integer
|
||||||
func (mg *Merger) Get(idx int) Result {
|
func (mg *Merger) Get(idx int) Result {
|
||||||
if mg.chunks != nil {
|
if mg.chunks != nil {
|
||||||
if mg.tac {
|
if mg.tac {
|
||||||
idx = mg.count - idx - 1
|
idx = mg.count - idx - 1
|
||||||
}
|
}
|
||||||
|
firstChunk := (*mg.chunks)[0]
|
||||||
|
if firstChunk.count < chunkSize && idx >= firstChunk.count {
|
||||||
|
idx -= firstChunk.count
|
||||||
|
|
||||||
|
chunk := (*mg.chunks)[idx/chunkSize+1]
|
||||||
|
return Result{item: &chunk.items[idx%chunkSize]}
|
||||||
|
}
|
||||||
chunk := (*mg.chunks)[idx/chunkSize]
|
chunk := (*mg.chunks)[idx/chunkSize]
|
||||||
return Result{item: &chunk.items[idx%chunkSize]}
|
return Result{item: &chunk.items[idx%chunkSize]}
|
||||||
}
|
}
|
||||||
@@ -106,7 +158,6 @@ func (mg *Merger) mergedGet(idx int) Result {
|
|||||||
minIdx = listIdx
|
minIdx = listIdx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mg.cursors[listIdx] = cursor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if minIdx >= 0 {
|
if minIdx >= 0 {
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ func randResult() Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyMerger(t *testing.T) {
|
func TestEmptyMerger(t *testing.T) {
|
||||||
assert(t, EmptyMerger.Length() == 0, "Not empty")
|
r := revision{}
|
||||||
assert(t, EmptyMerger.count == 0, "Invalid count")
|
assert(t, EmptyMerger(r).Length() == 0, "Not empty")
|
||||||
assert(t, len(EmptyMerger.lists) == 0, "Invalid lists")
|
assert(t, EmptyMerger(r).count == 0, "Invalid count")
|
||||||
assert(t, len(EmptyMerger.merged) == 0, "Invalid merged list")
|
assert(t, len(EmptyMerger(r).lists) == 0, "Invalid lists")
|
||||||
|
assert(t, len(EmptyMerger(r).merged) == 0, "Invalid merged list")
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildLists(partiallySorted bool) ([][]Result, []Result) {
|
func buildLists(partiallySorted bool) ([][]Result, []Result) {
|
||||||
@@ -57,7 +58,7 @@ func TestMergerUnsorted(t *testing.T) {
|
|||||||
cnt := len(items)
|
cnt := len(items)
|
||||||
|
|
||||||
// Not sorted: same order
|
// Not sorted: same order
|
||||||
mg := NewMerger(nil, lists, false, false)
|
mg := NewMerger(nil, lists, false, false, revision{}, 0)
|
||||||
assert(t, cnt == mg.Length(), "Invalid Length")
|
assert(t, cnt == mg.Length(), "Invalid Length")
|
||||||
for i := 0; i < cnt; i++ {
|
for i := 0; i < cnt; i++ {
|
||||||
assert(t, items[i] == mg.Get(i), "Invalid Get")
|
assert(t, items[i] == mg.Get(i), "Invalid Get")
|
||||||
@@ -69,7 +70,7 @@ func TestMergerSorted(t *testing.T) {
|
|||||||
cnt := len(items)
|
cnt := len(items)
|
||||||
|
|
||||||
// Sorted sorted order
|
// Sorted sorted order
|
||||||
mg := NewMerger(nil, lists, true, false)
|
mg := NewMerger(nil, lists, true, false, revision{}, 0)
|
||||||
assert(t, cnt == mg.Length(), "Invalid Length")
|
assert(t, cnt == mg.Length(), "Invalid Length")
|
||||||
sort.Sort(ByRelevance(items))
|
sort.Sort(ByRelevance(items))
|
||||||
for i := 0; i < cnt; i++ {
|
for i := 0; i < cnt; i++ {
|
||||||
@@ -79,7 +80,7 @@ func TestMergerSorted(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Inverse order
|
// Inverse order
|
||||||
mg2 := NewMerger(nil, lists, true, false)
|
mg2 := NewMerger(nil, lists, true, false, revision{}, 0)
|
||||||
for i := cnt - 1; i >= 0; i-- {
|
for i := cnt - 1; i >= 0; i-- {
|
||||||
if items[i] != mg2.Get(i) {
|
if items[i] != mg2.Get(i) {
|
||||||
t.Error("Not sorted", items[i], mg2.Get(i))
|
t.Error("Not sorted", items[i], mg2.Get(i))
|
||||||
|
|||||||
2641
src/options.go
2641
src/options.go
File diff suppressed because it is too large
Load Diff
13
src/options_no_pprof.go
Normal file
13
src/options_no_pprof.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
//go:build !pprof
|
||||||
|
// +build !pprof
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
func (o *Options) initProfiling() error {
|
||||||
|
if o.CPUProfile != "" || o.MEMProfile != "" || o.BlockProfile != "" || o.MutexProfile != "" {
|
||||||
|
return errors.New("error: profiling not supported: FZF must be built with '-tags=pprof' to enable profiling")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
73
src/options_pprof.go
Normal file
73
src/options_pprof.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
//go:build pprof
|
||||||
|
// +build pprof
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"runtime"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (o *Options) initProfiling() error {
|
||||||
|
if o.CPUProfile != "" {
|
||||||
|
f, err := os.Create(o.CPUProfile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create CPU profile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := pprof.StartCPUProfile(f); err != nil {
|
||||||
|
return fmt.Errorf("could not start CPU profile: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
util.AtExit(func() {
|
||||||
|
pprof.StopCPUProfile()
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
fmt.Fprintln(os.Stderr, "Error: closing cpu profile:", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
stopProfile := func(name string, f *os.File) {
|
||||||
|
if err := pprof.Lookup(name).WriteTo(f, 0); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: could not write %s profile: %v\n", name, err)
|
||||||
|
}
|
||||||
|
if err := f.Close(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Error: closing %s profile: %v\n", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.MEMProfile != "" {
|
||||||
|
f, err := os.Create(o.MEMProfile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create MEM profile: %w", err)
|
||||||
|
}
|
||||||
|
util.AtExit(func() {
|
||||||
|
runtime.GC()
|
||||||
|
stopProfile("allocs", f)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.BlockProfile != "" {
|
||||||
|
runtime.SetBlockProfileRate(1)
|
||||||
|
f, err := os.Create(o.BlockProfile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create BLOCK profile: %w", err)
|
||||||
|
}
|
||||||
|
util.AtExit(func() { stopProfile("block", f) })
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.MutexProfile != "" {
|
||||||
|
runtime.SetMutexProfileFraction(1)
|
||||||
|
f, err := os.Create(o.MutexProfile)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create MUTEX profile: %w", err)
|
||||||
|
}
|
||||||
|
util.AtExit(func() { stopProfile("mutex", f) })
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
89
src/options_pprof_test.go
Normal file
89
src/options_pprof_test.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
//go:build pprof
|
||||||
|
// +build pprof
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// runInitProfileTests is an internal flag used TestInitProfiling
|
||||||
|
var runInitProfileTests = flag.Bool("test-init-profile", false, "run init profile tests")
|
||||||
|
|
||||||
|
func TestInitProfiling(t *testing.T) {
|
||||||
|
if testing.Short() {
|
||||||
|
t.Skip("short test")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run this test in a separate process since it interferes with
|
||||||
|
// profiling and modifies the global atexit state. Without this
|
||||||
|
// running `go test -bench . -cpuprofile cpu.out` will fail.
|
||||||
|
if !*runInitProfileTests {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
// Make sure we are not the child process.
|
||||||
|
if os.Getenv("_FZF_CHILD_PROC") != "" {
|
||||||
|
t.Fatal("already running as child process!")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := exec.Command(os.Args[0],
|
||||||
|
"-test.timeout", "30s",
|
||||||
|
"-test.run", "^"+t.Name()+"$",
|
||||||
|
"-test-init-profile",
|
||||||
|
)
|
||||||
|
cmd.Env = append(os.Environ(), "_FZF_CHILD_PROC=1")
|
||||||
|
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
out = bytes.TrimSpace(out)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Child test process failed: %v:\n%s", err, out)
|
||||||
|
}
|
||||||
|
// Make sure the test actually ran
|
||||||
|
if bytes.Contains(out, []byte("no tests to run")) {
|
||||||
|
t.Fatalf("Failed to run test %q:\n%s", t.Name(), out)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Child process
|
||||||
|
|
||||||
|
tempdir := t.TempDir()
|
||||||
|
t.Cleanup(util.RunAtExitFuncs)
|
||||||
|
|
||||||
|
o := Options{
|
||||||
|
CPUProfile: filepath.Join(tempdir, "cpu.prof"),
|
||||||
|
MEMProfile: filepath.Join(tempdir, "mem.prof"),
|
||||||
|
BlockProfile: filepath.Join(tempdir, "block.prof"),
|
||||||
|
MutexProfile: filepath.Join(tempdir, "mutex.prof"),
|
||||||
|
}
|
||||||
|
if err := o.initProfiling(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
profiles := []string{
|
||||||
|
o.CPUProfile,
|
||||||
|
o.MEMProfile,
|
||||||
|
o.BlockProfile,
|
||||||
|
o.MutexProfile,
|
||||||
|
}
|
||||||
|
for _, name := range profiles {
|
||||||
|
if _, err := os.Stat(name); err != nil {
|
||||||
|
t.Errorf("Failed to create profile %s: %v", filepath.Base(name), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
util.RunAtExitFuncs()
|
||||||
|
|
||||||
|
for _, name := range profiles {
|
||||||
|
if _, err := os.Stat(name); err != nil {
|
||||||
|
t.Errorf("Failed to write profile %s: %v", filepath.Base(name), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package fzf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/tui"
|
"github.com/junegunn/fzf/src/tui"
|
||||||
@@ -50,7 +50,7 @@ func TestDelimiterRegexString(t *testing.T) {
|
|||||||
tokens[2].text.ToString() != "---*" ||
|
tokens[2].text.ToString() != "---*" ||
|
||||||
tokens[3].text.ToString() != "*" ||
|
tokens[3].text.ToString() != "*" ||
|
||||||
tokens[4].text.ToString() != "---" {
|
tokens[4].text.ToString() != "---" {
|
||||||
t.Errorf("%s %s %d", delim, tokens, len(tokens))
|
t.Errorf("%s %v %d", delim, tokens, len(tokens))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,17 +65,30 @@ func TestDelimiterRegexRegex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDelimiterRegexRegexCaret(t *testing.T) {
|
||||||
|
delim := delimiterRegexp(`(^\s*|\s+)`)
|
||||||
|
tokens := Tokenize("foo bar baz", delim)
|
||||||
|
if delim.str != nil ||
|
||||||
|
len(tokens) != 4 ||
|
||||||
|
tokens[0].text.ToString() != "" ||
|
||||||
|
tokens[1].text.ToString() != "foo " ||
|
||||||
|
tokens[2].text.ToString() != "bar " ||
|
||||||
|
tokens[3].text.ToString() != "baz" {
|
||||||
|
t.Errorf("%s %d", tokens, len(tokens))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSplitNth(t *testing.T) {
|
func TestSplitNth(t *testing.T) {
|
||||||
{
|
{
|
||||||
ranges := splitNth("..")
|
ranges, _ := splitNth("..")
|
||||||
if len(ranges) != 1 ||
|
if len(ranges) != 1 ||
|
||||||
ranges[0].begin != rangeEllipsis ||
|
ranges[0].begin != rangeEllipsis ||
|
||||||
ranges[0].end != rangeEllipsis {
|
ranges[0].end != rangeEllipsis {
|
||||||
t.Errorf("%s", ranges)
|
t.Errorf("%v", ranges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ranges := splitNth("..3,1..,2..3,4..-1,-3..-2,..,2,-2,2..-2,1..-1")
|
ranges, _ := splitNth("..3,1..,2..3,4..-1,-3..-2,..,2,-2,2..-2,1..-1")
|
||||||
if len(ranges) != 10 ||
|
if len(ranges) != 10 ||
|
||||||
ranges[0].begin != rangeEllipsis || ranges[0].end != 3 ||
|
ranges[0].begin != rangeEllipsis || ranges[0].end != 3 ||
|
||||||
ranges[1].begin != rangeEllipsis || ranges[1].end != rangeEllipsis ||
|
ranges[1].begin != rangeEllipsis || ranges[1].end != rangeEllipsis ||
|
||||||
@@ -87,95 +100,99 @@ func TestSplitNth(t *testing.T) {
|
|||||||
ranges[7].begin != -2 || ranges[7].end != -2 ||
|
ranges[7].begin != -2 || ranges[7].end != -2 ||
|
||||||
ranges[8].begin != 2 || ranges[8].end != -2 ||
|
ranges[8].begin != 2 || ranges[8].end != -2 ||
|
||||||
ranges[9].begin != rangeEllipsis || ranges[9].end != rangeEllipsis {
|
ranges[9].begin != rangeEllipsis || ranges[9].end != rangeEllipsis {
|
||||||
t.Errorf("%s", ranges)
|
t.Errorf("%v", ranges)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIrrelevantNth(t *testing.T) {
|
func TestIrrelevantNth(t *testing.T) {
|
||||||
|
index := 0
|
||||||
{
|
{
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
words := []string{"--nth", "..", "-x"}
|
words := []string{"--nth", "..", "-x"}
|
||||||
parseOptions(opts, words)
|
parseOptions(&index, opts, words)
|
||||||
postProcessOptions(opts)
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 0 {
|
if len(opts.Nth) != 0 {
|
||||||
t.Errorf("nth should be empty: %s", opts.Nth)
|
t.Errorf("nth should be empty: %v", opts.Nth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, words := range [][]string{[]string{"--nth", "..,3", "+x"}, []string{"--nth", "3,1..", "+x"}, []string{"--nth", "..-1,1", "+x"}} {
|
for _, words := range [][]string{{"--nth", "..,3", "+x"}, {"--nth", "3,1..", "+x"}, {"--nth", "..-1,1", "+x"}} {
|
||||||
{
|
{
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
parseOptions(opts, words)
|
parseOptions(&index, opts, words)
|
||||||
postProcessOptions(opts)
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 0 {
|
if len(opts.Nth) != 0 {
|
||||||
t.Errorf("nth should be empty: %s", opts.Nth)
|
t.Errorf("nth should be empty: %v", opts.Nth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
words = append(words, "-x")
|
words = append(words, "-x")
|
||||||
parseOptions(opts, words)
|
parseOptions(&index, opts, words)
|
||||||
postProcessOptions(opts)
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 2 {
|
if len(opts.Nth) != 2 {
|
||||||
t.Errorf("nth should not be empty: %s", opts.Nth)
|
t.Errorf("nth should not be empty: %v", opts.Nth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseKeys(t *testing.T) {
|
func TestParseKeys(t *testing.T) {
|
||||||
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ctrl-alt-a,ALT-enter,alt-SPACE", "")
|
pairs, _ := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ctrl-alt-a,ALT-enter,alt-SPACE", "")
|
||||||
check := func(i int, s string) {
|
checkEvent := func(e tui.Event, s string) {
|
||||||
if pairs[i] != s {
|
if pairs[e] != s {
|
||||||
t.Errorf("%s != %s", pairs[i], s)
|
t.Errorf("%s != %s", pairs[e], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
check := func(et tui.EventType, s string) {
|
||||||
|
checkEvent(et.AsEvent(), s)
|
||||||
|
}
|
||||||
if len(pairs) != 12 {
|
if len(pairs) != 12 {
|
||||||
t.Error(12)
|
t.Error(12)
|
||||||
}
|
}
|
||||||
check(tui.CtrlZ, "ctrl-z")
|
check(tui.CtrlZ, "ctrl-z")
|
||||||
check(tui.AltZ, "alt-z")
|
|
||||||
check(tui.F2, "f2")
|
check(tui.F2, "f2")
|
||||||
check(tui.AltZ+'@', "@")
|
check(tui.CtrlG, "ctrl-G")
|
||||||
check(tui.AltA, "Alt-a")
|
checkEvent(tui.AltKey('z'), "alt-z")
|
||||||
check(tui.AltZ+'!', "!")
|
checkEvent(tui.Key('@'), "@")
|
||||||
check(tui.CtrlA+'g'-'a', "ctrl-G")
|
checkEvent(tui.AltKey('a'), "Alt-a")
|
||||||
check(tui.AltZ+'J', "J")
|
checkEvent(tui.Key('!'), "!")
|
||||||
check(tui.AltZ+'g', "g")
|
checkEvent(tui.Key('J'), "J")
|
||||||
check(tui.CtrlAltA, "ctrl-alt-a")
|
checkEvent(tui.Key('g'), "g")
|
||||||
check(tui.CtrlAltM, "ALT-enter")
|
checkEvent(tui.CtrlAltKey('a'), "ctrl-alt-a")
|
||||||
check(tui.AltSpace, "alt-SPACE")
|
checkEvent(tui.CtrlAltKey('m'), "ALT-enter")
|
||||||
|
checkEvent(tui.AltKey(' '), "alt-SPACE")
|
||||||
|
|
||||||
// Synonyms
|
// Synonyms
|
||||||
pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")
|
pairs, _ = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")
|
||||||
if len(pairs) != 9 {
|
if len(pairs) != 9 {
|
||||||
t.Error(9)
|
t.Error(9)
|
||||||
}
|
}
|
||||||
check(tui.CtrlM, "Return")
|
check(tui.CtrlM, "Return")
|
||||||
check(tui.AltZ+' ', "space")
|
checkEvent(tui.Key(' '), "space")
|
||||||
check(tui.Tab, "tab")
|
check(tui.Tab, "tab")
|
||||||
check(tui.BTab, "btab")
|
check(tui.ShiftTab, "btab")
|
||||||
check(tui.ESC, "esc")
|
check(tui.Esc, "esc")
|
||||||
check(tui.Up, "up")
|
check(tui.Up, "up")
|
||||||
check(tui.Down, "down")
|
check(tui.Down, "down")
|
||||||
check(tui.Left, "left")
|
check(tui.Left, "left")
|
||||||
check(tui.Right, "right")
|
check(tui.Right, "right")
|
||||||
|
|
||||||
pairs = parseKeyChords("Tab,Ctrl-I,PgUp,page-up,pgdn,Page-Down,Home,End,Alt-BS,Alt-BSpace,shift-left,shift-right,btab,shift-tab,return,Enter,bspace", "")
|
pairs, _ = parseKeyChords("Tab,Ctrl-I,PgUp,page-up,pgdn,Page-Down,Home,End,Alt-BS,Alt-BSpace,shift-left,shift-right,btab,shift-tab,return,Enter,bspace", "")
|
||||||
if len(pairs) != 11 {
|
if len(pairs) != 11 {
|
||||||
t.Error(11)
|
t.Error(11)
|
||||||
}
|
}
|
||||||
check(tui.Tab, "Ctrl-I")
|
check(tui.Tab, "Ctrl-I")
|
||||||
check(tui.PgUp, "page-up")
|
check(tui.PageUp, "page-up")
|
||||||
check(tui.PgDn, "Page-Down")
|
check(tui.PageDown, "Page-Down")
|
||||||
check(tui.Home, "Home")
|
check(tui.Home, "Home")
|
||||||
check(tui.End, "End")
|
check(tui.End, "End")
|
||||||
check(tui.AltBS, "Alt-BSpace")
|
check(tui.AltBackspace, "Alt-BSpace")
|
||||||
check(tui.SLeft, "shift-left")
|
check(tui.ShiftLeft, "shift-left")
|
||||||
check(tui.SRight, "shift-right")
|
check(tui.ShiftRight, "shift-right")
|
||||||
check(tui.BTab, "shift-tab")
|
check(tui.ShiftTab, "shift-tab")
|
||||||
check(tui.CtrlM, "Enter")
|
check(tui.CtrlM, "Enter")
|
||||||
check(tui.BSpace, "bspace")
|
check(tui.Backspace, "bspace")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseKeysWithComma(t *testing.T) {
|
func TestParseKeysWithComma(t *testing.T) {
|
||||||
@@ -184,97 +201,103 @@ func TestParseKeysWithComma(t *testing.T) {
|
|||||||
t.Errorf("%d != %d", a, b)
|
t.Errorf("%d != %d", a, b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check := func(pairs map[int]string, i int, s string) {
|
check := func(pairs map[tui.Event]string, e tui.Event, s string) {
|
||||||
if pairs[i] != s {
|
if pairs[e] != s {
|
||||||
t.Errorf("%s != %s", pairs[i], s)
|
t.Errorf("%s != %s", pairs[e], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pairs := parseKeyChords(",", "")
|
pairs, _ := parseKeyChords(",", "")
|
||||||
checkN(len(pairs), 1)
|
checkN(len(pairs), 1)
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
pairs = parseKeyChords(",,a,b", "")
|
pairs, _ = parseKeyChords(",,a,b", "")
|
||||||
checkN(len(pairs), 3)
|
checkN(len(pairs), 3)
|
||||||
check(pairs, tui.AltZ+'a', "a")
|
check(pairs, tui.Key('a'), "a")
|
||||||
check(pairs, tui.AltZ+'b', "b")
|
check(pairs, tui.Key('b'), "b")
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
pairs = parseKeyChords("a,b,,", "")
|
pairs, _ = parseKeyChords("a,b,,", "")
|
||||||
checkN(len(pairs), 3)
|
checkN(len(pairs), 3)
|
||||||
check(pairs, tui.AltZ+'a', "a")
|
check(pairs, tui.Key('a'), "a")
|
||||||
check(pairs, tui.AltZ+'b', "b")
|
check(pairs, tui.Key('b'), "b")
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
pairs = parseKeyChords("a,,,b", "")
|
pairs, _ = parseKeyChords("a,,,b", "")
|
||||||
checkN(len(pairs), 3)
|
checkN(len(pairs), 3)
|
||||||
check(pairs, tui.AltZ+'a', "a")
|
check(pairs, tui.Key('a'), "a")
|
||||||
check(pairs, tui.AltZ+'b', "b")
|
check(pairs, tui.Key('b'), "b")
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
pairs = parseKeyChords("a,,,b,c", "")
|
pairs, _ = parseKeyChords("a,,,b,c", "")
|
||||||
checkN(len(pairs), 4)
|
checkN(len(pairs), 4)
|
||||||
check(pairs, tui.AltZ+'a', "a")
|
check(pairs, tui.Key('a'), "a")
|
||||||
check(pairs, tui.AltZ+'b', "b")
|
check(pairs, tui.Key('b'), "b")
|
||||||
check(pairs, tui.AltZ+'c', "c")
|
check(pairs, tui.Key('c'), "c")
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
pairs = parseKeyChords(",,,", "")
|
pairs, _ = parseKeyChords(",,,", "")
|
||||||
checkN(len(pairs), 1)
|
checkN(len(pairs), 1)
|
||||||
check(pairs, tui.AltZ+',', ",")
|
check(pairs, tui.Key(','), ",")
|
||||||
|
|
||||||
|
pairs, _ = parseKeyChords(",ALT-,,", "")
|
||||||
|
checkN(len(pairs), 1)
|
||||||
|
check(pairs, tui.AltKey(','), "ALT-,")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBind(t *testing.T) {
|
func TestBind(t *testing.T) {
|
||||||
keymap := defaultKeymap()
|
keymap := defaultKeymap()
|
||||||
check := func(keyName int, arg1 string, types ...actionType) {
|
check := func(event tui.Event, arg1 string, types ...actionType) {
|
||||||
if len(keymap[keyName]) != len(types) {
|
if len(keymap[event]) != len(types) {
|
||||||
t.Errorf("invalid number of actions (%d != %d)", len(types), len(keymap[keyName]))
|
t.Errorf("invalid number of actions for %v (%d != %d)",
|
||||||
|
event, len(types), len(keymap[event]))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for idx, action := range keymap[keyName] {
|
for idx, action := range keymap[event] {
|
||||||
if types[idx] != action.t {
|
if types[idx] != action.t {
|
||||||
t.Errorf("invalid action type (%d != %d)", types[idx], action.t)
|
t.Errorf("invalid action type (%d != %d)", types[idx], action.t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(arg1) > 0 && keymap[keyName][0].a != arg1 {
|
if len(arg1) > 0 && keymap[event][0].a != arg1 {
|
||||||
t.Errorf("invalid action argument: (%s != %s)", arg1, keymap[keyName][0].a)
|
t.Errorf("invalid action argument: (%s != %s)", arg1, keymap[event][0].a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
check(tui.CtrlA, "", actBeginningOfLine)
|
check(tui.CtrlA.AsEvent(), "", actBeginningOfLine)
|
||||||
parseKeymap(keymap,
|
parseKeymap(keymap,
|
||||||
"ctrl-a:kill-line,ctrl-b:toggle-sort+up+down,c:page-up,alt-z:page-down,"+
|
"ctrl-a:kill-line,ctrl-b:toggle-sort+up+down,c:page-up,alt-z:page-down,"+
|
||||||
"f1:execute(ls {})+abort,f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
|
"f1:execute(ls {+})+abort+execute(echo \n{+})+select-all,f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
|
||||||
"alt-a:execute-Multi@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};,"+
|
"alt-a:execute-Multi@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};,"+
|
||||||
"x:Execute(foo+bar),X:execute/bar+baz/"+
|
"x:Execute(foo+bar),X:execute/bar+baz/"+
|
||||||
|
",f1:+first,f1:+top"+
|
||||||
",,:abort,::accept,+:execute:++\nfoobar,Y:execute(baz)+up")
|
",,:abort,::accept,+:execute:++\nfoobar,Y:execute(baz)+up")
|
||||||
check(tui.CtrlA, "", actKillLine)
|
check(tui.CtrlA.AsEvent(), "", actKillLine)
|
||||||
check(tui.CtrlB, "", actToggleSort, actUp, actDown)
|
check(tui.CtrlB.AsEvent(), "", actToggleSort, actUp, actDown)
|
||||||
check(tui.AltZ+'c', "", actPageUp)
|
check(tui.Key('c'), "", actPageUp)
|
||||||
check(tui.AltZ+',', "", actAbort)
|
check(tui.Key(','), "", actAbort)
|
||||||
check(tui.AltZ+':', "", actAccept)
|
check(tui.Key(':'), "", actAccept)
|
||||||
check(tui.AltZ, "", actPageDown)
|
check(tui.AltKey('z'), "", actPageDown)
|
||||||
check(tui.F1, "ls {}", actExecute, actAbort)
|
check(tui.F1.AsEvent(), "ls {+}", actExecute, actAbort, actExecute, actSelectAll, actFirst, actFirst)
|
||||||
check(tui.F2, "echo {}, {}, {}", actExecute)
|
check(tui.F2.AsEvent(), "echo {}, {}, {}", actExecute)
|
||||||
check(tui.F3, "echo '({})'", actExecute)
|
check(tui.F3.AsEvent(), "echo '({})'", actExecute)
|
||||||
check(tui.F4, "less {}", actExecute)
|
check(tui.F4.AsEvent(), "less {}", actExecute)
|
||||||
check(tui.AltZ+'x', "foo+bar", actExecute)
|
check(tui.Key('x'), "foo+bar", actExecute)
|
||||||
check(tui.AltZ+'X', "bar+baz", actExecute)
|
check(tui.Key('X'), "bar+baz", actExecute)
|
||||||
check(tui.AltA, "echo (,),[,],/,:,;,%,{}", actExecuteMulti)
|
check(tui.AltKey('a'), "echo (,),[,],/,:,;,%,{}", actExecuteMulti)
|
||||||
check(tui.AltB, "echo (,),[,],/,:,@,%,{}", actExecute)
|
check(tui.AltKey('b'), "echo (,),[,],/,:,@,%,{}", actExecute)
|
||||||
check(tui.AltZ+'+', "++\nfoobar,Y:execute(baz)+up", actExecute)
|
check(tui.Key('+'), "++\nfoobar,Y:execute(baz)+up", actExecute)
|
||||||
|
|
||||||
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
|
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
|
||||||
parseKeymap(keymap, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
parseKeymap(keymap, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
||||||
check(tui.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0]), "foobar", actExecute)
|
check(tui.Key([]rune(fmt.Sprintf("%d", idx%10))[0]), "foobar", actExecute)
|
||||||
}
|
}
|
||||||
|
|
||||||
parseKeymap(keymap, "f1:abort")
|
parseKeymap(keymap, "f1:abort")
|
||||||
check(tui.F1, "", actAbort)
|
check(tui.F1.AsEvent(), "", actAbort)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestColorSpec(t *testing.T) {
|
func TestColorSpec(t *testing.T) {
|
||||||
theme := tui.Dark256
|
theme := tui.Dark256
|
||||||
dark := parseTheme(theme, "dark")
|
dark, _ := parseTheme(theme, "dark")
|
||||||
if *dark != *theme {
|
if *dark != *theme {
|
||||||
t.Errorf("colors should be equivalent")
|
t.Errorf("colors should be equivalent")
|
||||||
}
|
}
|
||||||
@@ -282,7 +305,7 @@ func TestColorSpec(t *testing.T) {
|
|||||||
t.Errorf("point should not be equivalent")
|
t.Errorf("point should not be equivalent")
|
||||||
}
|
}
|
||||||
|
|
||||||
light := parseTheme(theme, "dark,light")
|
light, _ := parseTheme(theme, "dark,light")
|
||||||
if *light == *theme {
|
if *light == *theme {
|
||||||
t.Errorf("should not be equivalent")
|
t.Errorf("should not be equivalent")
|
||||||
}
|
}
|
||||||
@@ -293,8 +316,8 @@ func TestColorSpec(t *testing.T) {
|
|||||||
t.Errorf("point should not be equivalent")
|
t.Errorf("point should not be equivalent")
|
||||||
}
|
}
|
||||||
|
|
||||||
customized := parseTheme(theme, "fg:231,bg:232")
|
customized, _ := parseTheme(theme, "fg:231,bg:232")
|
||||||
if customized.Fg != 231 || customized.Bg != 232 {
|
if customized.Fg.Color != 231 || customized.Bg.Color != 232 {
|
||||||
t.Errorf("color not customized")
|
t.Errorf("color not customized")
|
||||||
}
|
}
|
||||||
if *tui.Dark256 == *customized {
|
if *tui.Dark256 == *customized {
|
||||||
@@ -306,30 +329,20 @@ func TestColorSpec(t *testing.T) {
|
|||||||
t.Errorf("colors should now be equivalent: %v, %v", tui.Dark256, customized)
|
t.Errorf("colors should now be equivalent: %v, %v", tui.Dark256, customized)
|
||||||
}
|
}
|
||||||
|
|
||||||
customized = parseTheme(theme, "fg:231,dark,bg:232")
|
customized, _ = parseTheme(theme, "fg:231,dark,bg:232")
|
||||||
if customized.Fg != tui.Dark256.Fg || customized.Bg == tui.Dark256.Bg {
|
if customized.Fg != tui.Dark256.Fg || customized.Bg == tui.Dark256.Bg {
|
||||||
t.Errorf("color not customized")
|
t.Errorf("color not customized")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseNilTheme(t *testing.T) {
|
|
||||||
var theme *tui.ColorTheme
|
|
||||||
newTheme := parseTheme(theme, "prompt:12")
|
|
||||||
if newTheme != nil {
|
|
||||||
t.Errorf("color is disabled. keep it that way.")
|
|
||||||
}
|
|
||||||
newTheme = parseTheme(theme, "prompt:12,dark,prompt:13")
|
|
||||||
if newTheme.Prompt != 13 {
|
|
||||||
t.Errorf("color should now be enabled and customized")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDefaultCtrlNP(t *testing.T) {
|
func TestDefaultCtrlNP(t *testing.T) {
|
||||||
check := func(words []string, key int, expected actionType) {
|
index := 0
|
||||||
|
check := func(words []string, et tui.EventType, expected actionType) {
|
||||||
|
e := et.AsEvent()
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
parseOptions(opts, words)
|
parseOptions(&index, opts, words)
|
||||||
postProcessOptions(opts)
|
postProcessOptions(opts)
|
||||||
if opts.Keymap[key][0].t != expected {
|
if opts.Keymap[e][0].t != expected {
|
||||||
t.Error()
|
t.Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -339,22 +352,23 @@ func TestDefaultCtrlNP(t *testing.T) {
|
|||||||
check([]string{"--bind=ctrl-n:accept"}, tui.CtrlN, actAccept)
|
check([]string{"--bind=ctrl-n:accept"}, tui.CtrlN, actAccept)
|
||||||
check([]string{"--bind=ctrl-p:accept"}, tui.CtrlP, actAccept)
|
check([]string{"--bind=ctrl-p:accept"}, tui.CtrlP, actAccept)
|
||||||
|
|
||||||
f, _ := ioutil.TempFile("", "fzf-history")
|
f, _ := os.CreateTemp("", "fzf-history")
|
||||||
f.Close()
|
f.Close()
|
||||||
hist := "--history=" + f.Name()
|
hist := "--history=" + f.Name()
|
||||||
check([]string{hist}, tui.CtrlN, actNextHistory)
|
check([]string{hist}, tui.CtrlN, actNextHistory)
|
||||||
check([]string{hist}, tui.CtrlP, actPreviousHistory)
|
check([]string{hist}, tui.CtrlP, actPrevHistory)
|
||||||
|
|
||||||
check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlN, actAccept)
|
check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlN, actAccept)
|
||||||
check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlP, actPreviousHistory)
|
check([]string{hist, "--bind=ctrl-n:accept"}, tui.CtrlP, actPrevHistory)
|
||||||
|
|
||||||
check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlN, actNextHistory)
|
check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlN, actNextHistory)
|
||||||
check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlP, actAccept)
|
check([]string{hist, "--bind=ctrl-p:accept"}, tui.CtrlP, actAccept)
|
||||||
}
|
}
|
||||||
|
|
||||||
func optsFor(words ...string) *Options {
|
func optsFor(words ...string) *Options {
|
||||||
|
index := 0
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
parseOptions(opts, words)
|
parseOptions(&index, opts, words)
|
||||||
postProcessOptions(opts)
|
postProcessOptions(opts)
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
@@ -386,23 +400,26 @@ func TestPreviewOpts(t *testing.T) {
|
|||||||
opts.Preview.size.size == 50) {
|
opts.Preview.size.size == 50) {
|
||||||
t.Error()
|
t.Error()
|
||||||
}
|
}
|
||||||
opts = optsFor("--preview", "cat {}", "--preview-window=left:15:hidden:wrap")
|
opts = optsFor("--preview", "cat {}", "--preview-window=left:15,hidden,wrap:+{1}-/2")
|
||||||
if !(opts.Preview.command == "cat {}" &&
|
if !(opts.Preview.command == "cat {}" &&
|
||||||
opts.Preview.hidden == true &&
|
opts.Preview.hidden == true &&
|
||||||
opts.Preview.wrap == true &&
|
opts.Preview.wrap == true &&
|
||||||
opts.Preview.position == posLeft &&
|
opts.Preview.position == posLeft &&
|
||||||
|
opts.Preview.scroll == "+{1}-/2" &&
|
||||||
opts.Preview.size.percent == false &&
|
opts.Preview.size.percent == false &&
|
||||||
opts.Preview.size.size == 15+2+2) {
|
opts.Preview.size.size == 15) {
|
||||||
t.Error(opts.Preview)
|
t.Error(opts.Preview)
|
||||||
}
|
}
|
||||||
opts = optsFor("--preview-window=up:15:wrap:hidden", "--preview-window=down")
|
opts = optsFor("--preview-window=up,15,wrap,hidden,+{1}+3-1-2/2", "--preview-window=down", "--preview-window=cycle")
|
||||||
if !(opts.Preview.command == "" &&
|
if !(opts.Preview.command == "" &&
|
||||||
opts.Preview.hidden == false &&
|
opts.Preview.hidden == true &&
|
||||||
opts.Preview.wrap == false &&
|
opts.Preview.wrap == true &&
|
||||||
|
opts.Preview.cycle == true &&
|
||||||
opts.Preview.position == posDown &&
|
opts.Preview.position == posDown &&
|
||||||
opts.Preview.size.percent == true &&
|
opts.Preview.scroll == "+{1}+3-1-2/2" &&
|
||||||
opts.Preview.size.size == 50) {
|
opts.Preview.size.percent == false &&
|
||||||
t.Error(opts.Preview)
|
opts.Preview.size.size == 15) {
|
||||||
|
t.Error(opts.Preview.size.size)
|
||||||
}
|
}
|
||||||
opts = optsFor("--preview-window=up:15:wrap:hidden")
|
opts = optsFor("--preview-window=up:15:wrap:hidden")
|
||||||
if !(opts.Preview.command == "" &&
|
if !(opts.Preview.command == "" &&
|
||||||
@@ -410,7 +427,14 @@ func TestPreviewOpts(t *testing.T) {
|
|||||||
opts.Preview.wrap == true &&
|
opts.Preview.wrap == true &&
|
||||||
opts.Preview.position == posUp &&
|
opts.Preview.position == posUp &&
|
||||||
opts.Preview.size.percent == false &&
|
opts.Preview.size.percent == false &&
|
||||||
opts.Preview.size.size == 15+2) {
|
opts.Preview.size.size == 15) {
|
||||||
|
t.Error(opts.Preview)
|
||||||
|
}
|
||||||
|
opts = optsFor("--preview=foo", "--preview-window=up", "--preview-window=default:70%")
|
||||||
|
if !(opts.Preview.command == "foo" &&
|
||||||
|
opts.Preview.position == posRight &&
|
||||||
|
opts.Preview.size.percent == true &&
|
||||||
|
opts.Preview.size.size == 70) {
|
||||||
t.Error(opts.Preview)
|
t.Error(opts.Preview)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -421,3 +445,58 @@ func TestAdditiveExpect(t *testing.T) {
|
|||||||
t.Error(opts.Expect)
|
t.Error(opts.Expect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateSign(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
inputSign string
|
||||||
|
isValid bool
|
||||||
|
}{
|
||||||
|
{"> ", true},
|
||||||
|
{"아", true},
|
||||||
|
{"😀", true},
|
||||||
|
{">>>", false},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
err := validateSign(testCase.inputSign, "")
|
||||||
|
if testCase.isValid && err != nil {
|
||||||
|
t.Errorf("Input sign `%s` caused error", testCase.inputSign)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !testCase.isValid && err == nil {
|
||||||
|
t.Errorf("Input sign `%s` did not cause error", testCase.inputSign)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseSingleActionList(t *testing.T) {
|
||||||
|
actions, _ := parseSingleActionList("Execute@foo+bar,baz@+up+up+reload:down+down")
|
||||||
|
if len(actions) != 4 {
|
||||||
|
t.Errorf("Invalid number of actions parsed:%d", len(actions))
|
||||||
|
}
|
||||||
|
if actions[0].t != actExecute || actions[0].a != "foo+bar,baz" {
|
||||||
|
t.Errorf("Invalid action parsed: %v", actions[0])
|
||||||
|
}
|
||||||
|
if actions[1].t != actUp || actions[2].t != actUp {
|
||||||
|
t.Errorf("Invalid action parsed: %v / %v", actions[1], actions[2])
|
||||||
|
}
|
||||||
|
if actions[3].t != actReload || actions[3].a != "down+down" {
|
||||||
|
t.Errorf("Invalid action parsed: %v", actions[3])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseSingleActionListError(t *testing.T) {
|
||||||
|
_, err := parseSingleActionList("change-query(foobar)baz")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Failed to detect error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaskActionContents(t *testing.T) {
|
||||||
|
original := ":execute((f)(o)(o)(b)(a)(r))+change-query@qu@ry@+up,x:reload:hello:world"
|
||||||
|
expected := ":execute +change-query +up,x:reload "
|
||||||
|
masked := maskActionContents(original)
|
||||||
|
if masked != expected {
|
||||||
|
t.Errorf("Not masked: %s", masked)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -22,6 +23,7 @@ type termType int
|
|||||||
const (
|
const (
|
||||||
termFuzzy termType = iota
|
termFuzzy termType = iota
|
||||||
termExact
|
termExact
|
||||||
|
termExactBoundary
|
||||||
termPrefix
|
termPrefix
|
||||||
termSuffix
|
termSuffix
|
||||||
termEqual
|
termEqual
|
||||||
@@ -32,6 +34,12 @@ type term struct {
|
|||||||
inv bool
|
inv bool
|
||||||
text []rune
|
text []rune
|
||||||
caseSensitive bool
|
caseSensitive bool
|
||||||
|
normalize bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of a term.
|
||||||
|
func (t term) String() string {
|
||||||
|
return fmt.Sprintf("term{typ: %d, inv: %v, text: []rune(%q), caseSensitive: %v}", t.typ, t.inv, string(t.text), t.caseSensitive)
|
||||||
}
|
}
|
||||||
|
|
||||||
type termSet []term
|
type termSet []term
|
||||||
@@ -44,40 +52,27 @@ type Pattern struct {
|
|||||||
caseSensitive bool
|
caseSensitive bool
|
||||||
normalize bool
|
normalize bool
|
||||||
forward bool
|
forward bool
|
||||||
|
withPos bool
|
||||||
text []rune
|
text []rune
|
||||||
termSets []termSet
|
termSets []termSet
|
||||||
|
sortable bool
|
||||||
cacheable bool
|
cacheable bool
|
||||||
cacheKey string
|
cacheKey string
|
||||||
delimiter Delimiter
|
delimiter Delimiter
|
||||||
nth []Range
|
nth []Range
|
||||||
procFun map[termType]algo.Algo
|
procFun map[termType]algo.Algo
|
||||||
|
cache *ChunkCache
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var _splitRegex *regexp.Regexp
|
||||||
_patternCache map[string]*Pattern
|
|
||||||
_splitRegex *regexp.Regexp
|
|
||||||
_cache ChunkCache
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_splitRegex = regexp.MustCompile(" +")
|
_splitRegex = regexp.MustCompile(" +")
|
||||||
clearPatternCache()
|
|
||||||
clearChunkCache()
|
|
||||||
}
|
|
||||||
|
|
||||||
func clearPatternCache() {
|
|
||||||
// We can uniquely identify the pattern for a given string since
|
|
||||||
// search mode and caseMode do not change while the program is running
|
|
||||||
_patternCache = make(map[string]*Pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
func clearChunkCache() {
|
|
||||||
_cache = NewChunkCache()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildPattern builds Pattern object from the given arguments
|
// BuildPattern builds Pattern object from the given arguments
|
||||||
func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
|
func BuildPattern(cache *ChunkCache, patternCache map[string]*Pattern, fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
|
||||||
cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
|
withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
|
||||||
|
|
||||||
var asString string
|
var asString string
|
||||||
if extended {
|
if extended {
|
||||||
@@ -89,29 +84,42 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
|
|||||||
asString = string(runes)
|
asString = string(runes)
|
||||||
}
|
}
|
||||||
|
|
||||||
cached, found := _patternCache[asString]
|
// We can uniquely identify the pattern for a given string since
|
||||||
|
// search mode and caseMode do not change while the program is running
|
||||||
|
cached, found := patternCache[asString]
|
||||||
if found {
|
if found {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
caseSensitive := true
|
caseSensitive := true
|
||||||
|
sortable := true
|
||||||
termSets := []termSet{}
|
termSets := []termSet{}
|
||||||
|
|
||||||
if extended {
|
if extended {
|
||||||
termSets = parseTerms(fuzzy, caseMode, normalize, asString)
|
termSets = parseTerms(fuzzy, caseMode, normalize, asString)
|
||||||
|
// We should not sort the result if there are only inverse search terms
|
||||||
|
sortable = false
|
||||||
Loop:
|
Loop:
|
||||||
for _, termSet := range termSets {
|
for _, termSet := range termSets {
|
||||||
for idx, term := range termSet {
|
for idx, term := range termSet {
|
||||||
|
if !term.inv {
|
||||||
|
sortable = true
|
||||||
|
}
|
||||||
// If the query contains inverse search terms or OR operators,
|
// If the query contains inverse search terms or OR operators,
|
||||||
// we cannot cache the search scope
|
// we cannot cache the search scope
|
||||||
if !cacheable || idx > 0 || term.inv || fuzzy && term.typ != termFuzzy || !fuzzy && term.typ != termExact {
|
if !cacheable || idx > 0 || term.inv || fuzzy && term.typ != termFuzzy || !fuzzy && term.typ != termExact {
|
||||||
cacheable = false
|
cacheable = false
|
||||||
|
if sortable {
|
||||||
|
// Can't break until we see at least one non-inverse term
|
||||||
break Loop
|
break Loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
lowerString := strings.ToLower(asString)
|
lowerString := strings.ToLower(asString)
|
||||||
|
normalize = normalize &&
|
||||||
|
lowerString == string(algo.NormalizeRunes([]rune(lowerString)))
|
||||||
caseSensitive = caseMode == CaseRespect ||
|
caseSensitive = caseMode == CaseRespect ||
|
||||||
caseMode == CaseSmart && lowerString != asString
|
caseMode == CaseSmart && lowerString != asString
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
@@ -126,36 +134,42 @@ func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case,
|
|||||||
caseSensitive: caseSensitive,
|
caseSensitive: caseSensitive,
|
||||||
normalize: normalize,
|
normalize: normalize,
|
||||||
forward: forward,
|
forward: forward,
|
||||||
|
withPos: withPos,
|
||||||
text: []rune(asString),
|
text: []rune(asString),
|
||||||
termSets: termSets,
|
termSets: termSets,
|
||||||
|
sortable: sortable,
|
||||||
cacheable: cacheable,
|
cacheable: cacheable,
|
||||||
nth: nth,
|
nth: nth,
|
||||||
delimiter: delimiter,
|
delimiter: delimiter,
|
||||||
|
cache: cache,
|
||||||
procFun: make(map[termType]algo.Algo)}
|
procFun: make(map[termType]algo.Algo)}
|
||||||
|
|
||||||
ptr.cacheKey = ptr.buildCacheKey()
|
ptr.cacheKey = ptr.buildCacheKey()
|
||||||
ptr.procFun[termFuzzy] = fuzzyAlgo
|
ptr.procFun[termFuzzy] = fuzzyAlgo
|
||||||
ptr.procFun[termEqual] = algo.EqualMatch
|
ptr.procFun[termEqual] = algo.EqualMatch
|
||||||
ptr.procFun[termExact] = algo.ExactMatchNaive
|
ptr.procFun[termExact] = algo.ExactMatchNaive
|
||||||
|
ptr.procFun[termExactBoundary] = algo.ExactMatchBoundary
|
||||||
ptr.procFun[termPrefix] = algo.PrefixMatch
|
ptr.procFun[termPrefix] = algo.PrefixMatch
|
||||||
ptr.procFun[termSuffix] = algo.SuffixMatch
|
ptr.procFun[termSuffix] = algo.SuffixMatch
|
||||||
|
|
||||||
_patternCache[asString] = ptr
|
patternCache[asString] = ptr
|
||||||
return ptr
|
return ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet {
|
func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet {
|
||||||
str = strings.Replace(str, "\\ ", "\t", -1)
|
str = strings.ReplaceAll(str, "\\ ", "\t")
|
||||||
tokens := _splitRegex.Split(str, -1)
|
tokens := _splitRegex.Split(str, -1)
|
||||||
sets := []termSet{}
|
sets := []termSet{}
|
||||||
set := termSet{}
|
set := termSet{}
|
||||||
switchSet := false
|
switchSet := false
|
||||||
afterBar := false
|
afterBar := false
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
typ, inv, text := termFuzzy, false, strings.Replace(token, "\t", " ", -1)
|
typ, inv, text := termFuzzy, false, strings.ReplaceAll(token, "\t", " ")
|
||||||
lowerText := strings.ToLower(text)
|
lowerText := strings.ToLower(text)
|
||||||
caseSensitive := caseMode == CaseRespect ||
|
caseSensitive := caseMode == CaseRespect ||
|
||||||
caseMode == CaseSmart && text != lowerText
|
caseMode == CaseSmart && text != lowerText
|
||||||
|
normalizeTerm := normalize &&
|
||||||
|
lowerText == string(algo.NormalizeRunes([]rune(lowerText)))
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
text = lowerText
|
text = lowerText
|
||||||
}
|
}
|
||||||
@@ -181,15 +195,17 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet
|
|||||||
text = text[:len(text)-1]
|
text = text[:len(text)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(text, "'") {
|
if len(text) > 2 && strings.HasPrefix(text, "'") && strings.HasSuffix(text, "'") {
|
||||||
|
typ = termExactBoundary
|
||||||
|
text = text[1 : len(text)-1]
|
||||||
|
} else if strings.HasPrefix(text, "'") {
|
||||||
// Flip exactness
|
// Flip exactness
|
||||||
if fuzzy && !inv {
|
if fuzzy && !inv {
|
||||||
typ = termExact
|
typ = termExact
|
||||||
text = text[1:]
|
|
||||||
} else {
|
} else {
|
||||||
typ = termFuzzy
|
typ = termFuzzy
|
||||||
text = text[1:]
|
|
||||||
}
|
}
|
||||||
|
text = text[1:]
|
||||||
} else if strings.HasPrefix(text, "^") {
|
} else if strings.HasPrefix(text, "^") {
|
||||||
if typ == termSuffix {
|
if typ == termSuffix {
|
||||||
typ = termEqual
|
typ = termEqual
|
||||||
@@ -205,14 +221,15 @@ func parseTerms(fuzzy bool, caseMode Case, normalize bool, str string) []termSet
|
|||||||
set = termSet{}
|
set = termSet{}
|
||||||
}
|
}
|
||||||
textRunes := []rune(text)
|
textRunes := []rune(text)
|
||||||
if normalize {
|
if normalizeTerm {
|
||||||
textRunes = algo.NormalizeRunes(textRunes)
|
textRunes = algo.NormalizeRunes(textRunes)
|
||||||
}
|
}
|
||||||
set = append(set, term{
|
set = append(set, term{
|
||||||
typ: typ,
|
typ: typ,
|
||||||
inv: inv,
|
inv: inv,
|
||||||
text: textRunes,
|
text: textRunes,
|
||||||
caseSensitive: caseSensitive})
|
caseSensitive: caseSensitive,
|
||||||
|
normalize: normalizeTerm})
|
||||||
switchSet = true
|
switchSet = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,18 +275,18 @@ func (p *Pattern) Match(chunk *Chunk, slab *util.Slab) []Result {
|
|||||||
// ChunkCache: Exact match
|
// ChunkCache: Exact match
|
||||||
cacheKey := p.CacheKey()
|
cacheKey := p.CacheKey()
|
||||||
if p.cacheable {
|
if p.cacheable {
|
||||||
if cached := _cache.Lookup(chunk, cacheKey); cached != nil {
|
if cached := p.cache.Lookup(chunk, cacheKey); cached != nil {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prefix/suffix cache
|
// Prefix/suffix cache
|
||||||
space := _cache.Search(chunk, cacheKey)
|
space := p.cache.Search(chunk, cacheKey)
|
||||||
|
|
||||||
matches := p.matchChunk(chunk, space, slab)
|
matches := p.matchChunk(chunk, space, slab)
|
||||||
|
|
||||||
if p.cacheable {
|
if p.cacheable {
|
||||||
_cache.Add(chunk, cacheKey, matches)
|
p.cache.Add(chunk, cacheKey, matches)
|
||||||
}
|
}
|
||||||
return matches
|
return matches
|
||||||
}
|
}
|
||||||
@@ -279,13 +296,13 @@ func (p *Pattern) matchChunk(chunk *Chunk, space []Result, slab *util.Slab) []Re
|
|||||||
|
|
||||||
if space == nil {
|
if space == nil {
|
||||||
for idx := 0; idx < chunk.count; idx++ {
|
for idx := 0; idx < chunk.count; idx++ {
|
||||||
if match, _, _ := p.MatchItem(&chunk.items[idx], false, slab); match != nil {
|
if match, _, _ := p.MatchItem(&chunk.items[idx], p.withPos, slab); match != nil {
|
||||||
matches = append(matches, *match)
|
matches = append(matches, *match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, result := range space {
|
for _, result := range space {
|
||||||
if match, _, _ := p.MatchItem(result.item, false, slab); match != nil {
|
if match, _, _ := p.MatchItem(result.item, p.withPos, slab); match != nil {
|
||||||
matches = append(matches, *match)
|
matches = append(matches, *match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -314,7 +331,7 @@ func (p *Pattern) MatchItem(item *Item, withPos bool, slab *util.Slab) (*Result,
|
|||||||
func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, int, *[]int) {
|
func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset, int, *[]int) {
|
||||||
var input []Token
|
var input []Token
|
||||||
if len(p.nth) == 0 {
|
if len(p.nth) == 0 {
|
||||||
input = []Token{Token{text: &item.text, prefixLength: 0}}
|
input = []Token{{text: &item.text, prefixLength: 0}}
|
||||||
} else {
|
} else {
|
||||||
input = p.transformInput(item)
|
input = p.transformInput(item)
|
||||||
}
|
}
|
||||||
@@ -327,7 +344,7 @@ func (p *Pattern) basicMatch(item *Item, withPos bool, slab *util.Slab) (Offset,
|
|||||||
func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Offset, int, *[]int) {
|
func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Offset, int, *[]int) {
|
||||||
var input []Token
|
var input []Token
|
||||||
if len(p.nth) == 0 {
|
if len(p.nth) == 0 {
|
||||||
input = []Token{Token{text: &item.text, prefixLength: 0}}
|
input = []Token{{text: &item.text, prefixLength: 0}}
|
||||||
} else {
|
} else {
|
||||||
input = p.transformInput(item)
|
input = p.transformInput(item)
|
||||||
}
|
}
|
||||||
@@ -343,7 +360,7 @@ func (p *Pattern) extendedMatch(item *Item, withPos bool, slab *util.Slab) ([]Of
|
|||||||
matched := false
|
matched := false
|
||||||
for _, term := range termSet {
|
for _, term := range termSet {
|
||||||
pfun := p.procFun[term.typ]
|
pfun := p.procFun[term.typ]
|
||||||
off, score, pos := p.iter(pfun, input, term.caseSensitive, p.normalize, p.forward, term.text, withPos, slab)
|
off, score, pos := p.iter(pfun, input, term.caseSensitive, term.normalize, p.forward, term.text, withPos, slab)
|
||||||
if sidx := off[0]; sidx >= 0 {
|
if sidx := off[0]; sidx >= 0 {
|
||||||
if term.inv {
|
if term.inv {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ func TestParseTermsExtended(t *testing.T) {
|
|||||||
terms[8][1].typ != termExact || terms[8][1].inv ||
|
terms[8][1].typ != termExact || terms[8][1].inv ||
|
||||||
terms[8][2].typ != termSuffix || terms[8][2].inv ||
|
terms[8][2].typ != termSuffix || terms[8][2].inv ||
|
||||||
terms[8][3].typ != termExact || !terms[8][3].inv {
|
terms[8][3].typ != termExact || !terms[8][3].inv {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%v", terms)
|
||||||
}
|
}
|
||||||
for _, termSet := range terms[:8] {
|
for _, termSet := range terms[:8] {
|
||||||
term := termSet[0]
|
term := termSet[0]
|
||||||
if len(term.text) != 3 {
|
if len(term.text) != 3 {
|
||||||
t.Errorf("%s", term)
|
t.Errorf("%v", term)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -53,27 +53,32 @@ func TestParseTermsExtendedExact(t *testing.T) {
|
|||||||
terms[5][0].typ != termFuzzy || !terms[5][0].inv || len(terms[5][0].text) != 3 ||
|
terms[5][0].typ != termFuzzy || !terms[5][0].inv || len(terms[5][0].text) != 3 ||
|
||||||
terms[6][0].typ != termPrefix || !terms[6][0].inv || len(terms[6][0].text) != 3 ||
|
terms[6][0].typ != termPrefix || !terms[6][0].inv || len(terms[6][0].text) != 3 ||
|
||||||
terms[7][0].typ != termSuffix || !terms[7][0].inv || len(terms[7][0].text) != 3 {
|
terms[7][0].typ != termSuffix || !terms[7][0].inv || len(terms[7][0].text) != 3 {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%v", terms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseTermsEmpty(t *testing.T) {
|
func TestParseTermsEmpty(t *testing.T) {
|
||||||
terms := parseTerms(true, CaseSmart, false, "' ^ !' !^")
|
terms := parseTerms(true, CaseSmart, false, "' ^ !' !^")
|
||||||
if len(terms) != 0 {
|
if len(terms) != 0 {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%v", terms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,
|
||||||
|
withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {
|
||||||
|
return BuildPattern(NewChunkCache(), make(map[string]*Pattern),
|
||||||
|
fuzzy, fuzzyAlgo, extended, caseMode, normalize, forward,
|
||||||
|
withPos, cacheable, nth, delimiter, runes)
|
||||||
|
}
|
||||||
|
|
||||||
func TestExact(t *testing.T) {
|
func TestExact(t *testing.T) {
|
||||||
defer clearPatternCache()
|
pattern := buildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true,
|
||||||
clearPatternCache()
|
|
||||||
pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true,
|
|
||||||
[]Range{}, Delimiter{}, []rune("'abc"))
|
[]Range{}, Delimiter{}, []rune("'abc"))
|
||||||
chars := util.ToChars([]byte("aabbcc abc"))
|
chars := util.ToChars([]byte("aabbcc abc"))
|
||||||
res, pos := algo.ExactMatchNaive(
|
res, pos := algo.ExactMatchNaive(
|
||||||
pattern.caseSensitive, pattern.normalize, pattern.forward, &chars, pattern.termSets[0][0].text, true, nil)
|
pattern.caseSensitive, pattern.normalize, pattern.forward, &chars, pattern.termSets[0][0].text, true, nil)
|
||||||
if res.Start != 7 || res.End != 10 {
|
if res.Start != 7 || res.End != 10 {
|
||||||
t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)
|
t.Errorf("%v / %d / %d", pattern.termSets, res.Start, res.End)
|
||||||
}
|
}
|
||||||
if pos != nil {
|
if pos != nil {
|
||||||
t.Errorf("pos is expected to be nil")
|
t.Errorf("pos is expected to be nil")
|
||||||
@@ -81,16 +86,14 @@ func TestExact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEqual(t *testing.T) {
|
func TestEqual(t *testing.T) {
|
||||||
defer clearPatternCache()
|
pattern := buildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("^AbC$"))
|
||||||
clearPatternCache()
|
|
||||||
pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("^AbC$"))
|
|
||||||
|
|
||||||
match := func(str string, sidxExpected int, eidxExpected int) {
|
match := func(str string, sidxExpected int, eidxExpected int) {
|
||||||
chars := util.ToChars([]byte(str))
|
chars := util.ToChars([]byte(str))
|
||||||
res, pos := algo.EqualMatch(
|
res, pos := algo.EqualMatch(
|
||||||
pattern.caseSensitive, pattern.normalize, pattern.forward, &chars, pattern.termSets[0][0].text, true, nil)
|
pattern.caseSensitive, pattern.normalize, pattern.forward, &chars, pattern.termSets[0][0].text, true, nil)
|
||||||
if res.Start != sidxExpected || res.End != eidxExpected {
|
if res.Start != sidxExpected || res.End != eidxExpected {
|
||||||
t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)
|
t.Errorf("%v / %d / %d", pattern.termSets, res.Start, res.End)
|
||||||
}
|
}
|
||||||
if pos != nil {
|
if pos != nil {
|
||||||
t.Errorf("pos is expected to be nil")
|
t.Errorf("pos is expected to be nil")
|
||||||
@@ -98,22 +101,18 @@ func TestEqual(t *testing.T) {
|
|||||||
}
|
}
|
||||||
match("ABC", -1, -1)
|
match("ABC", -1, -1)
|
||||||
match("AbC", 0, 3)
|
match("AbC", 0, 3)
|
||||||
|
match("AbC ", 0, 3)
|
||||||
|
match(" AbC ", 1, 4)
|
||||||
|
match(" AbC", 2, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCaseSensitivity(t *testing.T) {
|
func TestCaseSensitivity(t *testing.T) {
|
||||||
defer clearPatternCache()
|
pat1 := buildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
pat2 := buildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
pat1 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
|
pat3 := buildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
pat4 := buildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
pat2 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
|
pat5 := buildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
pat6 := buildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
pat3 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
|
|
||||||
clearPatternCache()
|
|
||||||
pat4 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
|
|
||||||
clearPatternCache()
|
|
||||||
pat5 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("abc"))
|
|
||||||
clearPatternCache()
|
|
||||||
pat6 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))
|
|
||||||
|
|
||||||
if string(pat1.text) != "abc" || pat1.caseSensitive != false ||
|
if string(pat1.text) != "abc" || pat1.caseSensitive != false ||
|
||||||
string(pat2.text) != "Abc" || pat2.caseSensitive != true ||
|
string(pat2.text) != "Abc" || pat2.caseSensitive != true ||
|
||||||
@@ -126,9 +125,9 @@ func TestCaseSensitivity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestOrigTextAndTransformed(t *testing.T) {
|
func TestOrigTextAndTransformed(t *testing.T) {
|
||||||
pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("jg"))
|
pattern := buildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("jg"))
|
||||||
tokens := Tokenize("junegunn", Delimiter{})
|
tokens := Tokenize("junegunn", Delimiter{})
|
||||||
trans := Transform(tokens, []Range{Range{1, 1}})
|
trans := Transform(tokens, []Range{{1, 1}})
|
||||||
|
|
||||||
origBytes := []byte("junegunn.choi")
|
origBytes := []byte("junegunn.choi")
|
||||||
for _, extended := range []bool{false, true} {
|
for _, extended := range []bool{false, true} {
|
||||||
@@ -160,15 +159,13 @@ func TestOrigTextAndTransformed(t *testing.T) {
|
|||||||
|
|
||||||
func TestCacheKey(t *testing.T) {
|
func TestCacheKey(t *testing.T) {
|
||||||
test := func(extended bool, patStr string, expected string, cacheable bool) {
|
test := func(extended bool, patStr string, expected string, cacheable bool) {
|
||||||
clearPatternCache()
|
pat := buildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune(patStr))
|
||||||
pat := BuildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune(patStr))
|
|
||||||
if pat.CacheKey() != expected {
|
if pat.CacheKey() != expected {
|
||||||
t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
|
t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
|
||||||
}
|
}
|
||||||
if pat.cacheable != cacheable {
|
if pat.cacheable != cacheable {
|
||||||
t.Errorf("Expected: %t, actual: %t (%s)", cacheable, pat.cacheable, patStr)
|
t.Errorf("Expected: %t, actual: %t (%s)", cacheable, pat.cacheable, patStr)
|
||||||
}
|
}
|
||||||
clearPatternCache()
|
|
||||||
}
|
}
|
||||||
test(false, "foo !bar", "foo !bar", true)
|
test(false, "foo !bar", "foo !bar", true)
|
||||||
test(false, "foo | bar !baz", "foo | bar !baz", true)
|
test(false, "foo | bar !baz", "foo | bar !baz", true)
|
||||||
@@ -184,15 +181,13 @@ func TestCacheKey(t *testing.T) {
|
|||||||
|
|
||||||
func TestCacheable(t *testing.T) {
|
func TestCacheable(t *testing.T) {
|
||||||
test := func(fuzzy bool, str string, expected string, cacheable bool) {
|
test := func(fuzzy bool, str string, expected string, cacheable bool) {
|
||||||
clearPatternCache()
|
pat := buildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, false, true, []Range{}, Delimiter{}, []rune(str))
|
||||||
pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, true, []Range{}, Delimiter{}, []rune(str))
|
|
||||||
if pat.CacheKey() != expected {
|
if pat.CacheKey() != expected {
|
||||||
t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
|
t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
|
||||||
}
|
}
|
||||||
if cacheable != pat.cacheable {
|
if cacheable != pat.cacheable {
|
||||||
t.Errorf("Invalid Pattern.cacheable for \"%s\": %v (expected: %v)", str, pat.cacheable, cacheable)
|
t.Errorf("Invalid Pattern.cacheable for \"%s\": %v (expected: %v)", str, pat.cacheable, cacheable)
|
||||||
}
|
}
|
||||||
clearPatternCache()
|
|
||||||
}
|
}
|
||||||
test(true, "foo bar", "foo\tbar", true)
|
test(true, "foo bar", "foo\tbar", true)
|
||||||
test(true, "foo 'bar", "foo\tbar", false)
|
test(true, "foo 'bar", "foo\tbar", false)
|
||||||
|
|||||||
6
src/protector/protector.go
Normal file
6
src/protector/protector.go
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
//go:build !openbsd
|
||||||
|
|
||||||
|
package protector
|
||||||
|
|
||||||
|
// Protect calls OS specific protections like pledge on OpenBSD
|
||||||
|
func Protect() {}
|
||||||
10
src/protector/protector_openbsd.go
Normal file
10
src/protector/protector_openbsd.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
//go:build openbsd
|
||||||
|
|
||||||
|
package protector
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
// Protect calls OS specific protections like pledge on OpenBSD
|
||||||
|
func Protect() {
|
||||||
|
unix.PledgePromises("stdio dpath wpath rpath tty proc exec inet tmppath")
|
||||||
|
}
|
||||||
158
src/proxy.go
Normal file
158
src/proxy.go
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/tui"
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
const becomeSuffix = ".become"
|
||||||
|
|
||||||
|
func escapeSingleQuote(str string) string {
|
||||||
|
return "'" + strings.ReplaceAll(str, "'", "'\\''") + "'"
|
||||||
|
}
|
||||||
|
|
||||||
|
func fifo(name string) (string, error) {
|
||||||
|
ns := time.Now().UnixNano()
|
||||||
|
output := filepath.Join(os.TempDir(), fmt.Sprintf("fzf-%s-%d", name, ns))
|
||||||
|
output, err := mkfifo(output, 0600)
|
||||||
|
if err != nil {
|
||||||
|
return output, err
|
||||||
|
}
|
||||||
|
return output, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func runProxy(commandPrefix string, cmdBuilder func(temp string, needBash bool) (*exec.Cmd, error), opts *Options, withExports bool) (int, error) {
|
||||||
|
output, err := fifo("proxy-output")
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
defer os.Remove(output)
|
||||||
|
|
||||||
|
// Take the output
|
||||||
|
go func() {
|
||||||
|
withOutputPipe(output, func(outputFile io.ReadCloser) {
|
||||||
|
if opts.Output == nil {
|
||||||
|
io.Copy(os.Stdout, outputFile)
|
||||||
|
} else {
|
||||||
|
reader := bufio.NewReader(outputFile)
|
||||||
|
sep := opts.PrintSep[0]
|
||||||
|
for {
|
||||||
|
item, err := reader.ReadString(sep)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
opts.Output <- item
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
var command string
|
||||||
|
commandPrefix += ` --no-force-tty-in --proxy-script "$0"`
|
||||||
|
if opts.Input == nil && (opts.ForceTtyIn || util.IsTty(os.Stdin)) {
|
||||||
|
command = fmt.Sprintf(`%s > %q`, commandPrefix, output)
|
||||||
|
} else {
|
||||||
|
input, err := fifo("proxy-input")
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
defer os.Remove(input)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
withInputPipe(input, func(inputFile io.WriteCloser) {
|
||||||
|
if opts.Input == nil {
|
||||||
|
io.Copy(inputFile, os.Stdin)
|
||||||
|
} else {
|
||||||
|
for item := range opts.Input {
|
||||||
|
fmt.Fprint(inputFile, item+opts.PrintSep)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}()
|
||||||
|
|
||||||
|
if withExports {
|
||||||
|
command = fmt.Sprintf(`%s < %q > %q`, commandPrefix, input, output)
|
||||||
|
} else {
|
||||||
|
// For mintty: cannot directly read named pipe from Go code
|
||||||
|
command = fmt.Sprintf(`command cat %q | %s > %q`, input, commandPrefix, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// To ensure that the options are processed by a POSIX-compliant shell,
|
||||||
|
// we need to write the command to a temporary file and execute it with sh.
|
||||||
|
var exports []string
|
||||||
|
needBash := false
|
||||||
|
if withExports {
|
||||||
|
validIdentifier := regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)
|
||||||
|
for _, pairStr := range os.Environ() {
|
||||||
|
pair := strings.SplitN(pairStr, "=", 2)
|
||||||
|
if validIdentifier.MatchString(pair[0]) {
|
||||||
|
exports = append(exports, fmt.Sprintf("export %s=%s", pair[0], escapeSingleQuote(pair[1])))
|
||||||
|
} else if strings.HasPrefix(pair[0], "BASH_FUNC_") && strings.HasSuffix(pair[0], "%%") {
|
||||||
|
name := pair[0][10 : len(pair[0])-2]
|
||||||
|
exports = append(exports, name+pair[1])
|
||||||
|
exports = append(exports, "export -f "+name)
|
||||||
|
needBash = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
temp := WriteTemporaryFile(append(exports, command), "\n")
|
||||||
|
defer os.Remove(temp)
|
||||||
|
|
||||||
|
cmd, err := cmdBuilder(temp, needBash)
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
intChan := make(chan os.Signal, 1)
|
||||||
|
defer close(intChan)
|
||||||
|
go func() {
|
||||||
|
if sig, valid := <-intChan; valid {
|
||||||
|
cmd.Process.Signal(sig)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
signal.Notify(intChan, os.Interrupt)
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
code := exitError.ExitCode()
|
||||||
|
if code == ExitBecome {
|
||||||
|
becomeFile := temp + becomeSuffix
|
||||||
|
data, err := os.ReadFile(becomeFile)
|
||||||
|
os.Remove(becomeFile)
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
elems := strings.Split(string(data), "\x00")
|
||||||
|
if len(elems) < 1 {
|
||||||
|
return ExitError, errors.New("invalid become command")
|
||||||
|
}
|
||||||
|
command := elems[0]
|
||||||
|
env := []string{}
|
||||||
|
if len(elems) > 1 {
|
||||||
|
env = elems[1:]
|
||||||
|
}
|
||||||
|
executor := util.NewExecutor(opts.WithShell)
|
||||||
|
ttyin, err := tui.TtyIn()
|
||||||
|
if err != nil {
|
||||||
|
return ExitError, err
|
||||||
|
}
|
||||||
|
executor.Become(ttyin, env, command)
|
||||||
|
}
|
||||||
|
return code, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ExitOk, nil
|
||||||
|
}
|
||||||
41
src/proxy_unix.go
Normal file
41
src/proxy_unix.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
)
|
||||||
|
|
||||||
|
func sh(bash bool) (string, error) {
|
||||||
|
if bash {
|
||||||
|
return "bash", nil
|
||||||
|
}
|
||||||
|
return "sh", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mkfifo(path string, mode uint32) (string, error) {
|
||||||
|
return path, unix.Mkfifo(path, mode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func withOutputPipe(output string, task func(io.ReadCloser)) error {
|
||||||
|
outputFile, err := os.OpenFile(output, os.O_RDONLY, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
task(outputFile)
|
||||||
|
outputFile.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInputPipe(input string, task func(io.WriteCloser)) error {
|
||||||
|
inputFile, err := os.OpenFile(input, os.O_WRONLY, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
task(inputFile)
|
||||||
|
inputFile.Close()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
85
src/proxy_windows.go
Normal file
85
src/proxy_windows.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
|
var shPath atomic.Value
|
||||||
|
|
||||||
|
func sh(bash bool) (string, error) {
|
||||||
|
if cached := shPath.Load(); cached != nil {
|
||||||
|
return cached.(string), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
name := "sh"
|
||||||
|
if bash {
|
||||||
|
name = "bash"
|
||||||
|
}
|
||||||
|
cmd := exec.Command("cygpath", "-w", "/usr/bin/"+name)
|
||||||
|
bytes, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
sh := strings.TrimSpace(string(bytes))
|
||||||
|
shPath.Store(sh)
|
||||||
|
return sh, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mkfifo(path string, mode uint32) (string, error) {
|
||||||
|
m := strconv.FormatUint(uint64(mode), 8)
|
||||||
|
sh, err := sh(false)
|
||||||
|
if err != nil {
|
||||||
|
return path, err
|
||||||
|
}
|
||||||
|
cmd := exec.Command(sh, "-c", fmt.Sprintf(`command mkfifo -m %s %q`, m, path))
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return path, err
|
||||||
|
}
|
||||||
|
return path + ".lnk", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func withOutputPipe(output string, task func(io.ReadCloser)) error {
|
||||||
|
sh, err := sh(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := exec.Command(sh, "-c", fmt.Sprintf(`command cat %q`, output))
|
||||||
|
outputFile, err := cmd.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
task(outputFile)
|
||||||
|
cmd.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func withInputPipe(input string, task func(io.WriteCloser)) error {
|
||||||
|
sh, err := sh(false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd := exec.Command(sh, "-c", fmt.Sprintf(`command cat - > %q`, input))
|
||||||
|
inputFile, err := cmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := cmd.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
task(inputFile)
|
||||||
|
inputFile.Close()
|
||||||
|
cmd.Wait()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
275
src/reader.go
275
src/reader.go
@@ -1,26 +1,40 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bytes"
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/charlievieth/fastwalk"
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reader reads from command or standard input
|
// Reader reads from command or standard input
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
pusher func([]byte) bool
|
pusher func([]byte) bool
|
||||||
|
executor *util.Executor
|
||||||
eventBox *util.EventBox
|
eventBox *util.EventBox
|
||||||
delimNil bool
|
delimNil bool
|
||||||
event int32
|
event int32
|
||||||
|
finChan chan bool
|
||||||
|
mutex sync.Mutex
|
||||||
|
exec *exec.Cmd
|
||||||
|
execOut io.ReadCloser
|
||||||
|
command *string
|
||||||
|
killed bool
|
||||||
|
wait bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReader returns new Reader object
|
// NewReader returns new Reader object
|
||||||
func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, delimNil bool) *Reader {
|
func NewReader(pusher func([]byte) bool, eventBox *util.EventBox, executor *util.Executor, delimNil bool, wait bool) *Reader {
|
||||||
return &Reader{pusher, eventBox, delimNil, int32(EvtReady)}
|
return &Reader{pusher, executor, eventBox, delimNil, int32(EvtReady), make(chan bool, 1), sync.Mutex{}, nil, nil, nil, false, wait}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) startEventPoller() {
|
func (r *Reader) startEventPoller() {
|
||||||
@@ -29,9 +43,12 @@ func (r *Reader) startEventPoller() {
|
|||||||
pollInterval := readerPollIntervalMin
|
pollInterval := readerPollIntervalMin
|
||||||
for {
|
for {
|
||||||
if atomic.CompareAndSwapInt32(ptr, int32(EvtReadNew), int32(EvtReady)) {
|
if atomic.CompareAndSwapInt32(ptr, int32(EvtReadNew), int32(EvtReady)) {
|
||||||
r.eventBox.Set(EvtReadNew, true)
|
r.eventBox.Set(EvtReadNew, (*string)(nil))
|
||||||
pollInterval = readerPollIntervalMin
|
pollInterval = readerPollIntervalMin
|
||||||
} else if atomic.LoadInt32(ptr) == int32(EvtReadFin) {
|
} else if atomic.LoadInt32(ptr) == int32(EvtReadFin) {
|
||||||
|
if r.wait {
|
||||||
|
r.finChan <- true
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
pollInterval += readerPollIntervalStep
|
pollInterval += readerPollIntervalStep
|
||||||
@@ -46,20 +63,67 @@ func (r *Reader) startEventPoller() {
|
|||||||
|
|
||||||
func (r *Reader) fin(success bool) {
|
func (r *Reader) fin(success bool) {
|
||||||
atomic.StoreInt32(&r.event, int32(EvtReadFin))
|
atomic.StoreInt32(&r.event, int32(EvtReadFin))
|
||||||
r.eventBox.Set(EvtReadFin, success)
|
if r.wait {
|
||||||
|
<-r.finChan
|
||||||
|
}
|
||||||
|
|
||||||
|
r.mutex.Lock()
|
||||||
|
ret := r.command
|
||||||
|
if success || r.killed {
|
||||||
|
ret = nil
|
||||||
|
}
|
||||||
|
r.mutex.Unlock()
|
||||||
|
|
||||||
|
r.eventBox.Set(EvtReadFin, ret)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reader) terminate() {
|
||||||
|
r.mutex.Lock()
|
||||||
|
r.killed = true
|
||||||
|
if r.exec != nil && r.exec.Process != nil {
|
||||||
|
r.execOut.Close()
|
||||||
|
util.KillCommand(r.exec)
|
||||||
|
} else {
|
||||||
|
os.Stdin.Close()
|
||||||
|
}
|
||||||
|
r.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reader) restart(command commandSpec, environ []string) {
|
||||||
|
r.event = int32(EvtReady)
|
||||||
|
r.startEventPoller()
|
||||||
|
success := r.readFromCommand(command.command, environ)
|
||||||
|
r.fin(success)
|
||||||
|
removeFiles(command.tempFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reader) readChannel(inputChan chan string) bool {
|
||||||
|
for {
|
||||||
|
item, more := <-inputChan
|
||||||
|
if !more {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if r.pusher([]byte(item)) {
|
||||||
|
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadSource reads data from the default command or from standard input
|
// ReadSource reads data from the default command or from standard input
|
||||||
func (r *Reader) ReadSource() {
|
func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string, initCmd string, initEnv []string) {
|
||||||
r.startEventPoller()
|
r.startEventPoller()
|
||||||
var success bool
|
var success bool
|
||||||
if util.IsTty() {
|
if inputChan != nil {
|
||||||
|
success = r.readChannel(inputChan)
|
||||||
|
} else if len(initCmd) > 0 {
|
||||||
|
success = r.readFromCommand(initCmd, initEnv)
|
||||||
|
} else if util.IsTty(os.Stdin) {
|
||||||
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
|
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
|
||||||
if len(cmd) == 0 {
|
if len(cmd) == 0 {
|
||||||
// The default command for *nix requires bash
|
success = r.readFiles(root, opts, ignores)
|
||||||
success = r.readFromCommand("bash", defaultCommand)
|
|
||||||
} else {
|
} else {
|
||||||
success = r.readFromCommand("sh", cmd)
|
success = r.readFromCommand(cmd, initEnv)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
success = r.readFromStdin()
|
success = r.readFromStdin()
|
||||||
@@ -68,33 +132,91 @@ func (r *Reader) ReadSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) feed(src io.Reader) {
|
func (r *Reader) feed(src io.Reader) {
|
||||||
|
/*
|
||||||
|
readerSlabSize, ae := strconv.Atoi(os.Getenv("SLAB_KB"))
|
||||||
|
if ae != nil {
|
||||||
|
readerSlabSize = 128 * 1024
|
||||||
|
} else {
|
||||||
|
readerSlabSize *= 1024
|
||||||
|
}
|
||||||
|
readerBufferSize, be := strconv.Atoi(os.Getenv("BUF_KB"))
|
||||||
|
if be != nil {
|
||||||
|
readerBufferSize = 64 * 1024
|
||||||
|
} else {
|
||||||
|
readerBufferSize *= 1024
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
delim := byte('\n')
|
delim := byte('\n')
|
||||||
|
trimCR := util.IsWindows()
|
||||||
if r.delimNil {
|
if r.delimNil {
|
||||||
delim = '\000'
|
delim = '\000'
|
||||||
|
trimCR = false
|
||||||
}
|
}
|
||||||
reader := bufio.NewReaderSize(src, readerBufferSize)
|
|
||||||
|
slab := make([]byte, readerSlabSize)
|
||||||
|
leftover := []byte{}
|
||||||
|
var err error
|
||||||
for {
|
for {
|
||||||
// ReadBytes returns err != nil if and only if the returned data does not
|
n := 0
|
||||||
// end in delim.
|
scope := slab[:util.Min(len(slab), readerBufferSize)]
|
||||||
bytea, err := reader.ReadBytes(delim)
|
for i := 0; i < 100; i++ {
|
||||||
byteaLen := len(bytea)
|
n, err = src.Read(scope)
|
||||||
if byteaLen > 0 {
|
if n > 0 || err != nil {
|
||||||
if err == nil {
|
|
||||||
// get rid of carriage return if under Windows:
|
|
||||||
if util.IsWindows() && byteaLen >= 2 && bytea[byteaLen-2] == byte('\r') {
|
|
||||||
bytea = bytea[:byteaLen-2]
|
|
||||||
} else {
|
|
||||||
bytea = bytea[:byteaLen-1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.pusher(bytea) {
|
|
||||||
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We're not making any progress after 100 tries. Stop.
|
||||||
|
if n == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
buf := slab[:n]
|
||||||
|
slab = slab[n:]
|
||||||
|
|
||||||
|
for len(buf) > 0 {
|
||||||
|
if i := bytes.IndexByte(buf, delim); i >= 0 {
|
||||||
|
// Found the delimiter
|
||||||
|
slice := buf[:i+1]
|
||||||
|
buf = buf[i+1:]
|
||||||
|
if trimCR && len(slice) >= 2 && slice[len(slice)-2] == byte('\r') {
|
||||||
|
slice = slice[:len(slice)-2]
|
||||||
|
} else {
|
||||||
|
slice = slice[:len(slice)-1]
|
||||||
|
}
|
||||||
|
if len(leftover) > 0 {
|
||||||
|
slice = append(leftover, slice...)
|
||||||
|
leftover = []byte{}
|
||||||
|
}
|
||||||
|
if (err == nil || len(slice) > 0) && r.pusher(slice) {
|
||||||
|
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Could not find the delimiter in the buffer
|
||||||
|
// NOTE: We can further optimize this by keeping track of the cursor
|
||||||
|
// position in the slab so that a straddling item that doesn't go
|
||||||
|
// beyond the boundary of a slab doesn't need to be copied to
|
||||||
|
// another buffer. However, the performance gain is negligible in
|
||||||
|
// practice (< 0.1%) and is not
|
||||||
|
// worth the added complexity.
|
||||||
|
leftover = append(leftover, buf...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == io.EOF {
|
||||||
|
leftover = append(leftover, buf...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(slab) == 0 {
|
||||||
|
slab = make([]byte, readerSlabSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(leftover) > 0 && r.pusher(leftover) {
|
||||||
|
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) readFromStdin() bool {
|
func (r *Reader) readFromStdin() bool {
|
||||||
@@ -102,16 +224,95 @@ func (r *Reader) readFromStdin() bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) readFromCommand(shell string, cmd string) bool {
|
func isSymlinkToDir(path string, de os.DirEntry) bool {
|
||||||
listCommand := util.ExecCommandWith(shell, cmd)
|
if de.Type()&fs.ModeSymlink == 0 {
|
||||||
out, err := listCommand.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
err = listCommand.Start()
|
if s, err := os.Stat(path); err == nil {
|
||||||
if err != nil {
|
return s.IsDir()
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
r.feed(out)
|
|
||||||
return listCommand.Wait() == nil
|
func trimPath(path string) string {
|
||||||
|
bytes := stringBytes(path)
|
||||||
|
|
||||||
|
for len(bytes) > 1 && bytes[0] == '.' && (bytes[1] == '/' || bytes[1] == '\\') {
|
||||||
|
bytes = bytes[2:]
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bytes) == 0 {
|
||||||
|
return "."
|
||||||
|
}
|
||||||
|
|
||||||
|
return byteString(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool {
|
||||||
|
r.killed = false
|
||||||
|
conf := fastwalk.Config{
|
||||||
|
Follow: opts.follow,
|
||||||
|
// Use forward slashes when running a Windows binary under WSL or MSYS
|
||||||
|
ToSlash: fastwalk.DefaultToSlash(),
|
||||||
|
Sort: fastwalk.SortFilesFirst,
|
||||||
|
}
|
||||||
|
fn := func(path string, de os.DirEntry, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
path = trimPath(path)
|
||||||
|
if path != "." {
|
||||||
|
isDir := de.IsDir()
|
||||||
|
if isDir || opts.follow && isSymlinkToDir(path, de) {
|
||||||
|
base := filepath.Base(path)
|
||||||
|
if !opts.hidden && base[0] == '.' {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
for _, ignore := range ignores {
|
||||||
|
if ignore == base {
|
||||||
|
return filepath.SkipDir
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher(stringBytes(path)) {
|
||||||
|
atomic.StoreInt32(&r.event, int32(EvtReadNew))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.mutex.Lock()
|
||||||
|
defer r.mutex.Unlock()
|
||||||
|
if r.killed {
|
||||||
|
return context.Canceled
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fastwalk.Walk(&conf, root, fn) == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Reader) readFromCommand(command string, environ []string) bool {
|
||||||
|
r.mutex.Lock()
|
||||||
|
r.killed = false
|
||||||
|
r.command = &command
|
||||||
|
r.exec = r.executor.ExecCommand(command, true)
|
||||||
|
if environ != nil {
|
||||||
|
r.exec.Env = environ
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
r.execOut, err = r.exec.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
r.exec = nil
|
||||||
|
r.mutex.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
err = r.exec.Start()
|
||||||
|
if err != nil {
|
||||||
|
r.exec = nil
|
||||||
|
r.mutex.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
r.mutex.Unlock()
|
||||||
|
r.feed(r.execOut)
|
||||||
|
return r.exec.Wait() == nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import (
|
|||||||
func TestReadFromCommand(t *testing.T) {
|
func TestReadFromCommand(t *testing.T) {
|
||||||
strs := []string{}
|
strs := []string{}
|
||||||
eb := util.NewEventBox()
|
eb := util.NewEventBox()
|
||||||
reader := Reader{
|
exec := util.NewExecutor("")
|
||||||
pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },
|
reader := NewReader(
|
||||||
eventBox: eb,
|
func(s []byte) bool { strs = append(strs, string(s)); return true },
|
||||||
event: int32(EvtReady)}
|
eb, exec, false, true)
|
||||||
|
|
||||||
reader.startEventPoller()
|
reader.startEventPoller()
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ func TestReadFromCommand(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Normal command
|
// Normal command
|
||||||
reader.fin(reader.readFromCommand("sh", `echo abc && echo def`))
|
reader.fin(reader.readFromCommand(`echo abc&&echo def`, nil))
|
||||||
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
|
if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
|
||||||
t.Errorf("%s", strs)
|
t.Errorf("%s", strs)
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func TestReadFromCommand(t *testing.T) {
|
|||||||
reader.startEventPoller()
|
reader.startEventPoller()
|
||||||
|
|
||||||
// Failing command
|
// Failing command
|
||||||
reader.fin(reader.readFromCommand("sh", `no-such-command`))
|
reader.fin(reader.readFromCommand(`no-such-command`, nil))
|
||||||
strs = []string{}
|
strs = []string{}
|
||||||
if len(strs) > 0 {
|
if len(strs) > 0 {
|
||||||
t.Errorf("%s", strs)
|
t.Errorf("%s", strs)
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ type Offset [2]int32
|
|||||||
type colorOffset struct {
|
type colorOffset struct {
|
||||||
offset [2]int32
|
offset [2]int32
|
||||||
color tui.ColorPair
|
color tui.ColorPair
|
||||||
attr tui.Attr
|
match bool
|
||||||
index int32
|
url *url
|
||||||
}
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
@@ -51,6 +51,22 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
|
|||||||
case byScore:
|
case byScore:
|
||||||
// Higher is better
|
// Higher is better
|
||||||
val = math.MaxUint16 - util.AsUint16(score)
|
val = math.MaxUint16 - util.AsUint16(score)
|
||||||
|
case byChunk:
|
||||||
|
if validOffsetFound {
|
||||||
|
b := minBegin
|
||||||
|
e := maxEnd
|
||||||
|
for ; b >= 1; b-- {
|
||||||
|
if unicode.IsSpace(item.text.Get(b - 1)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for ; e < numChars; e++ {
|
||||||
|
if unicode.IsSpace(item.text.Get(e)) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val = util.AsUint16(e - b)
|
||||||
|
}
|
||||||
case byLength:
|
case byLength:
|
||||||
val = item.TrimLength()
|
val = item.TrimLength()
|
||||||
case byBegin, byEnd:
|
case byBegin, byEnd:
|
||||||
@@ -66,7 +82,7 @@ func buildResult(item *Item, offsets []Offset, score int) Result {
|
|||||||
if criterion == byBegin {
|
if criterion == byBegin {
|
||||||
val = util.AsUint16(minEnd - whitePrefixLen)
|
val = util.AsUint16(minEnd - whitePrefixLen)
|
||||||
} else {
|
} else {
|
||||||
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/int(item.TrimLength()))
|
val = util.AsUint16(math.MaxUint16 - math.MaxUint16*(maxEnd-whitePrefixLen)/(int(item.TrimLength())+1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,14 +104,14 @@ func minRank() Result {
|
|||||||
return Result{item: &minItem, points: [4]uint16{math.MaxUint16, 0, 0, 0}}
|
return Result{item: &minItem, points: [4]uint16{math.MaxUint16, 0, 0, 0}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme, color tui.ColorPair, attr tui.Attr, current bool) []colorOffset {
|
func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme, colBase tui.ColorPair, colMatch tui.ColorPair, current bool) []colorOffset {
|
||||||
itemColors := result.item.Colors()
|
itemColors := result.item.Colors()
|
||||||
|
|
||||||
// No ANSI code, or --color=no
|
// No ANSI codes
|
||||||
if len(itemColors) == 0 {
|
if len(itemColors) == 0 {
|
||||||
var offsets []colorOffset
|
var offsets []colorOffset
|
||||||
for _, off := range matchOffsets {
|
for _, off := range matchOffsets {
|
||||||
offsets = append(offsets, colorOffset{offset: [2]int32{off[0], off[1]}, color: color, attr: attr})
|
offsets = append(offsets, colorOffset{offset: [2]int32{off[0], off[1]}, color: colMatch, match: true})
|
||||||
}
|
}
|
||||||
return offsets
|
return offsets
|
||||||
}
|
}
|
||||||
@@ -112,17 +128,21 @@ func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme,
|
|||||||
maxCol = ansi.offset[1]
|
maxCol = ansi.offset[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cols := make([]int, maxCol)
|
|
||||||
|
|
||||||
|
cols := make([]int, maxCol)
|
||||||
for colorIndex, ansi := range itemColors {
|
for colorIndex, ansi := range itemColors {
|
||||||
for i := ansi.offset[0]; i < ansi.offset[1]; i++ {
|
for i := ansi.offset[0]; i < ansi.offset[1]; i++ {
|
||||||
cols[i] = colorIndex + 1 // XXX
|
cols[i] = colorIndex + 1 // 1-based index of itemColors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, off := range matchOffsets {
|
for _, off := range matchOffsets {
|
||||||
for i := off[0]; i < off[1]; i++ {
|
for i := off[0]; i < off[1]; i++ {
|
||||||
cols[i] = -1
|
// Negative of 1-based index of itemColors
|
||||||
|
// - The extra -1 means highlighted
|
||||||
|
if cols[i] >= 0 {
|
||||||
|
cols[i] = cols[i]*-1 - 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,36 +154,58 @@ func (result *Result) colorOffsets(matchOffsets []Offset, theme *tui.ColorTheme,
|
|||||||
// --++++++++-- --++++++++++---
|
// --++++++++-- --++++++++++---
|
||||||
curr := 0
|
curr := 0
|
||||||
start := 0
|
start := 0
|
||||||
var colors []colorOffset
|
ansiToColorPair := func(ansi ansiOffset, base tui.ColorPair) tui.ColorPair {
|
||||||
add := func(idx int) {
|
|
||||||
if curr != 0 && idx > start {
|
|
||||||
if curr == -1 {
|
|
||||||
colors = append(colors, colorOffset{
|
|
||||||
offset: [2]int32{int32(start), int32(idx)}, color: color, attr: attr})
|
|
||||||
} else {
|
|
||||||
ansi := itemColors[curr-1]
|
|
||||||
fg := ansi.color.fg
|
fg := ansi.color.fg
|
||||||
bg := ansi.color.bg
|
bg := ansi.color.bg
|
||||||
if theme != nil {
|
|
||||||
if fg == -1 {
|
if fg == -1 {
|
||||||
if current {
|
if current {
|
||||||
fg = theme.Current
|
fg = theme.Current.Color
|
||||||
} else {
|
} else {
|
||||||
fg = theme.Fg
|
fg = theme.Fg.Color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bg == -1 {
|
if bg == -1 {
|
||||||
if current {
|
if current {
|
||||||
bg = theme.DarkBg
|
bg = theme.DarkBg.Color
|
||||||
} else {
|
} else {
|
||||||
bg = theme.Bg
|
bg = theme.Bg.Color
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return tui.NewColorPair(fg, bg, ansi.color.attr).MergeAttr(base)
|
||||||
|
}
|
||||||
|
var colors []colorOffset
|
||||||
|
add := func(idx int) {
|
||||||
|
if curr != 0 && idx > start {
|
||||||
|
if curr < 0 {
|
||||||
|
color := colMatch
|
||||||
|
var url *url
|
||||||
|
if curr < -1 && theme.Colored {
|
||||||
|
ansi := itemColors[-curr-2]
|
||||||
|
url = ansi.color.url
|
||||||
|
origColor := ansiToColorPair(ansi, colMatch)
|
||||||
|
// hl or hl+ only sets the foreground color, so colMatch is the
|
||||||
|
// combination of either [hl and bg] or [hl+ and bg+].
|
||||||
|
//
|
||||||
|
// If the original text already has background color, and the
|
||||||
|
// foreground color of colMatch is -1, we shouldn't only apply the
|
||||||
|
// background color of colMatch.
|
||||||
|
// e.g. echo -e "\x1b[32;7mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline
|
||||||
|
// echo -e "\x1b[42mfoo\x1b[mbar" | fzf --ansi --color bg+:1,hl+:-1:underline
|
||||||
|
if color.Fg().IsDefault() && origColor.HasBg() {
|
||||||
|
color = origColor
|
||||||
|
} else {
|
||||||
|
color = origColor.MergeNonDefault(color)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
colors = append(colors, colorOffset{
|
||||||
|
offset: [2]int32{int32(start), int32(idx)}, color: color, match: true, url: url})
|
||||||
|
} else {
|
||||||
|
ansi := itemColors[curr-1]
|
||||||
colors = append(colors, colorOffset{
|
colors = append(colors, colorOffset{
|
||||||
offset: [2]int32{int32(start), int32(idx)},
|
offset: [2]int32{int32(start), int32(idx)},
|
||||||
color: tui.NewColorPair(fg, bg),
|
color: ansiToColorPair(ansi, colBase),
|
||||||
attr: ansi.color.attr.Merge(attr)})
|
match: false,
|
||||||
|
url: ansi.color.url})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !386,!amd64
|
//go:build !386 && !amd64
|
||||||
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// +build !tcell
|
|
||||||
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -18,8 +16,8 @@ func withIndex(i *Item, index int) *Item {
|
|||||||
|
|
||||||
func TestOffsetSort(t *testing.T) {
|
func TestOffsetSort(t *testing.T) {
|
||||||
offsets := []Offset{
|
offsets := []Offset{
|
||||||
Offset{3, 5}, Offset{2, 7},
|
{3, 5}, {2, 7},
|
||||||
Offset{1, 3}, Offset{2, 9}}
|
{1, 3}, {2, 9}}
|
||||||
sort.Sort(ByOrder(offsets))
|
sort.Sort(ByOrder(offsets))
|
||||||
|
|
||||||
if offsets[0][0] != 1 || offsets[0][1] != 3 ||
|
if offsets[0][0] != 1 || offsets[0][1] != 3 ||
|
||||||
@@ -56,9 +54,9 @@ func TestResultRank(t *testing.T) {
|
|||||||
// FIXME global
|
// FIXME global
|
||||||
sortCriteria = []criterion{byScore, byLength}
|
sortCriteria = []criterion{byScore, byLength}
|
||||||
|
|
||||||
strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")}
|
str := []rune("foo")
|
||||||
item1 := buildResult(
|
item1 := buildResult(
|
||||||
withIndex(&Item{text: util.RunesToChars(strs[0])}, 1), []Offset{}, 2)
|
withIndex(&Item{text: util.RunesToChars(str)}, 1), []Offset{}, 2)
|
||||||
if item1.points[3] != math.MaxUint16-2 || // Bonus
|
if item1.points[3] != math.MaxUint16-2 || // Bonus
|
||||||
item1.points[2] != 3 || // Length
|
item1.points[2] != 3 || // Length
|
||||||
item1.points[1] != 0 || // Unused
|
item1.points[1] != 0 || // Unused
|
||||||
@@ -67,7 +65,7 @@ func TestResultRank(t *testing.T) {
|
|||||||
t.Error(item1)
|
t.Error(item1)
|
||||||
}
|
}
|
||||||
// Only differ in index
|
// Only differ in index
|
||||||
item2 := buildResult(&Item{text: util.RunesToChars(strs[0])}, []Offset{}, 2)
|
item2 := buildResult(&Item{text: util.RunesToChars(str)}, []Offset{}, 2)
|
||||||
|
|
||||||
items := []Result{item1, item2}
|
items := []Result{item1, item2}
|
||||||
sort.Sort(ByRelevance(items))
|
sort.Sort(ByRelevance(items))
|
||||||
@@ -84,13 +82,13 @@ func TestResultRank(t *testing.T) {
|
|||||||
|
|
||||||
// Sort by relevance
|
// Sort by relevance
|
||||||
item3 := buildResult(
|
item3 := buildResult(
|
||||||
withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 3)
|
withIndex(&Item{}, 2), []Offset{{1, 3}, {5, 7}}, 3)
|
||||||
item4 := buildResult(
|
item4 := buildResult(
|
||||||
withIndex(&Item{}, 2), []Offset{Offset{1, 2}, Offset{6, 7}}, 4)
|
withIndex(&Item{}, 2), []Offset{{1, 2}, {6, 7}}, 4)
|
||||||
item5 := buildResult(
|
item5 := buildResult(
|
||||||
withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 5)
|
withIndex(&Item{}, 2), []Offset{{1, 3}, {5, 7}}, 5)
|
||||||
item6 := buildResult(
|
item6 := buildResult(
|
||||||
withIndex(&Item{}, 2), []Offset{Offset{1, 2}, Offset{6, 7}}, 6)
|
withIndex(&Item{}, 2), []Offset{{1, 2}, {6, 7}}, 6)
|
||||||
items = []Result{item1, item2, item3, item4, item5, item6}
|
items = []Result{item1, item2, item3, item4, item5, item6}
|
||||||
sort.Sort(ByRelevance(items))
|
sort.Sort(ByRelevance(items))
|
||||||
if !(items[0] == item6 && items[1] == item5 &&
|
if !(items[0] == item6 && items[1] == item5 &&
|
||||||
@@ -100,37 +98,77 @@ func TestResultRank(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestChunkTiebreak(t *testing.T) {
|
||||||
|
// FIXME global
|
||||||
|
sortCriteria = []criterion{byScore, byChunk}
|
||||||
|
|
||||||
|
score := 100
|
||||||
|
test := func(input string, offset Offset, chunk string) {
|
||||||
|
item := buildResult(withIndex(&Item{text: util.RunesToChars([]rune(input))}, 1), []Offset{offset}, score)
|
||||||
|
if !(item.points[3] == math.MaxUint16-uint16(score) && item.points[2] == uint16(len(chunk))) {
|
||||||
|
t.Error(item.points)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test("hello foobar goodbye", Offset{8, 9}, "foobar")
|
||||||
|
test("hello foobar goodbye", Offset{7, 18}, "foobar goodbye")
|
||||||
|
test("hello foobar goodbye", Offset{0, 1}, "hello")
|
||||||
|
test("hello foobar goodbye", Offset{5, 7}, "hello foobar") // TBD
|
||||||
|
}
|
||||||
|
|
||||||
func TestColorOffset(t *testing.T) {
|
func TestColorOffset(t *testing.T) {
|
||||||
// ------------ 20 ---- -- ----
|
// ------------ 20 ---- -- ----
|
||||||
// ++++++++ ++++++++++
|
// ++++++++ ++++++++++
|
||||||
// --++++++++-- --++++++++++---
|
// --++++++++-- --++++++++++---
|
||||||
|
|
||||||
offsets := []Offset{Offset{5, 15}, Offset{25, 35}}
|
offsets := []Offset{{5, 15}, {10, 12}, {25, 35}}
|
||||||
item := Result{
|
item := Result{
|
||||||
item: &Item{
|
item: &Item{
|
||||||
colors: &[]ansiOffset{
|
colors: &[]ansiOffset{
|
||||||
ansiOffset{[2]int32{0, 20}, ansiState{1, 5, 0}},
|
{[2]int32{0, 20}, ansiState{1, 5, 0, -1, nil}},
|
||||||
ansiOffset{[2]int32{22, 27}, ansiState{2, 6, tui.Bold}},
|
{[2]int32{22, 27}, ansiState{2, 6, tui.Bold, -1, nil}},
|
||||||
ansiOffset{[2]int32{30, 32}, ansiState{3, 7, 0}},
|
{[2]int32{30, 32}, ansiState{3, 7, 0, -1, nil}},
|
||||||
ansiOffset{[2]int32{33, 40}, ansiState{4, 8, tui.Bold}}}}}
|
{[2]int32{33, 40}, ansiState{4, 8, tui.Bold, -1, nil}}}}}
|
||||||
// [{[0 5] 9 false} {[5 15] 99 false} {[15 20] 9 false} {[22 25] 10 true} {[25 35] 99 false} {[35 40] 11 true}]
|
|
||||||
|
|
||||||
pair := tui.NewColorPair(99, 199)
|
colBase := tui.NewColorPair(89, 189, tui.AttrUndefined)
|
||||||
colors := item.colorOffsets(offsets, tui.Dark256, pair, tui.AttrRegular, true)
|
colMatch := tui.NewColorPair(99, 199, tui.AttrUndefined)
|
||||||
assert := func(idx int, b int32, e int32, c tui.ColorPair, bold bool) {
|
colors := item.colorOffsets(offsets, tui.Dark256, colBase, colMatch, true)
|
||||||
var attr tui.Attr
|
assert := func(idx int, b int32, e int32, c tui.ColorPair) {
|
||||||
if bold {
|
|
||||||
attr = tui.Bold
|
|
||||||
}
|
|
||||||
o := colors[idx]
|
o := colors[idx]
|
||||||
if o.offset[0] != b || o.offset[1] != e || o.color != c || o.attr != attr {
|
if o.offset[0] != b || o.offset[1] != e || o.color != c {
|
||||||
t.Error(o)
|
t.Error(o, b, e, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(0, 0, 5, tui.NewColorPair(1, 5), false)
|
// [{[0 5] {1 5 0}} {[5 15] {99 199 0}} {[15 20] {1 5 0}}
|
||||||
assert(1, 5, 15, pair, false)
|
// {[22 25] {2 6 1}} {[25 27] {99 199 1}} {[27 30] {99 199 0}}
|
||||||
assert(2, 15, 20, tui.NewColorPair(1, 5), false)
|
// {[30 32] {99 199 0}} {[32 33] {99 199 0}} {[33 35] {99 199 1}}
|
||||||
assert(3, 22, 25, tui.NewColorPair(2, 6), true)
|
// {[35 40] {4 8 1}}]
|
||||||
assert(4, 25, 35, pair, false)
|
assert(0, 0, 5, tui.NewColorPair(1, 5, tui.AttrUndefined))
|
||||||
assert(5, 35, 40, tui.NewColorPair(4, 8), true)
|
assert(1, 5, 15, colMatch)
|
||||||
|
assert(2, 15, 20, tui.NewColorPair(1, 5, tui.AttrUndefined))
|
||||||
|
assert(3, 22, 25, tui.NewColorPair(2, 6, tui.Bold))
|
||||||
|
assert(4, 25, 27, colMatch.WithAttr(tui.Bold))
|
||||||
|
assert(5, 27, 30, colMatch)
|
||||||
|
assert(6, 30, 32, colMatch)
|
||||||
|
assert(7, 32, 33, colMatch) // TODO: Should we merge consecutive blocks?
|
||||||
|
assert(8, 33, 35, colMatch.WithAttr(tui.Bold))
|
||||||
|
assert(9, 35, 40, tui.NewColorPair(4, 8, tui.Bold))
|
||||||
|
|
||||||
|
colRegular := tui.NewColorPair(-1, -1, tui.AttrUndefined)
|
||||||
|
colUnderline := tui.NewColorPair(-1, -1, tui.Underline)
|
||||||
|
colors = item.colorOffsets(offsets, tui.Dark256, colRegular, colUnderline, true)
|
||||||
|
|
||||||
|
// [{[0 5] {1 5 0}} {[5 15] {1 5 8}} {[15 20] {1 5 0}}
|
||||||
|
// {[22 25] {2 6 1}} {[25 27] {2 6 9}} {[27 30] {-1 -1 8}}
|
||||||
|
// {[30 32] {3 7 8}} {[32 33] {-1 -1 8}} {[33 35] {4 8 9}}
|
||||||
|
// {[35 40] {4 8 1}}]
|
||||||
|
assert(0, 0, 5, tui.NewColorPair(1, 5, tui.AttrUndefined))
|
||||||
|
assert(1, 5, 15, tui.NewColorPair(1, 5, tui.Underline))
|
||||||
|
assert(2, 15, 20, tui.NewColorPair(1, 5, tui.AttrUndefined))
|
||||||
|
assert(3, 22, 25, tui.NewColorPair(2, 6, tui.Bold))
|
||||||
|
assert(4, 25, 27, tui.NewColorPair(2, 6, tui.Bold|tui.Underline))
|
||||||
|
assert(5, 27, 30, colUnderline)
|
||||||
|
assert(6, 30, 32, tui.NewColorPair(3, 7, tui.Underline))
|
||||||
|
assert(7, 32, 33, colUnderline)
|
||||||
|
assert(8, 33, 35, tui.NewColorPair(4, 8, tui.Bold|tui.Underline))
|
||||||
|
assert(9, 35, 40, tui.NewColorPair(4, 8, tui.Bold))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build 386 amd64
|
//go:build 386 || amd64
|
||||||
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
|
|||||||
246
src/server.go
Normal file
246
src/server.go
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"bytes"
|
||||||
|
"crypto/subtle"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var getRegex *regexp.Regexp
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
getRegex = regexp.MustCompile(`^GET /(?:\?([a-z0-9=&]+))? HTTP`)
|
||||||
|
}
|
||||||
|
|
||||||
|
type getParams struct {
|
||||||
|
limit int
|
||||||
|
offset int
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
crlf = "\r\n"
|
||||||
|
httpOk = "HTTP/1.1 200 OK" + crlf
|
||||||
|
httpBadRequest = "HTTP/1.1 400 Bad Request" + crlf
|
||||||
|
httpUnauthorized = "HTTP/1.1 401 Unauthorized" + crlf
|
||||||
|
httpUnavailable = "HTTP/1.1 503 Service Unavailable" + crlf
|
||||||
|
httpReadTimeout = 10 * time.Second
|
||||||
|
channelTimeout = 2 * time.Second
|
||||||
|
jsonContentType = "Content-Type: application/json" + crlf
|
||||||
|
maxContentLength = 1024 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
|
type httpServer struct {
|
||||||
|
apiKey []byte
|
||||||
|
actionChannel chan []*action
|
||||||
|
getHandler func(getParams) string
|
||||||
|
}
|
||||||
|
|
||||||
|
type listenAddress struct {
|
||||||
|
host string
|
||||||
|
port int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (addr listenAddress) IsLocal() bool {
|
||||||
|
return addr.host == "localhost" || addr.host == "127.0.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultListenAddr = listenAddress{"localhost", 0}
|
||||||
|
|
||||||
|
func parseListenAddress(address string) (listenAddress, error) {
|
||||||
|
parts := strings.SplitN(address, ":", 3)
|
||||||
|
if len(parts) == 1 {
|
||||||
|
parts = []string{"localhost", parts[0]}
|
||||||
|
}
|
||||||
|
if len(parts) != 2 {
|
||||||
|
return defaultListenAddr, fmt.Errorf("invalid listen address: %s", address)
|
||||||
|
}
|
||||||
|
portStr := parts[len(parts)-1]
|
||||||
|
port, err := strconv.Atoi(portStr)
|
||||||
|
if err != nil || port < 0 || port > 65535 {
|
||||||
|
return defaultListenAddr, fmt.Errorf("invalid listen port: %s", portStr)
|
||||||
|
}
|
||||||
|
if len(parts[0]) == 0 {
|
||||||
|
parts[0] = "localhost"
|
||||||
|
}
|
||||||
|
return listenAddress{parts[0], port}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func startHttpServer(address listenAddress, actionChannel chan []*action, getHandler func(getParams) string) (net.Listener, int, error) {
|
||||||
|
host := address.host
|
||||||
|
port := address.port
|
||||||
|
apiKey := os.Getenv("FZF_API_KEY")
|
||||||
|
if !address.IsLocal() && len(apiKey) == 0 {
|
||||||
|
return nil, port, errors.New("FZF_API_KEY is required to allow remote access")
|
||||||
|
}
|
||||||
|
addrStr := fmt.Sprintf("%s:%d", host, port)
|
||||||
|
listener, err := net.Listen("tcp", addrStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, port, fmt.Errorf("failed to listen on %s", addrStr)
|
||||||
|
}
|
||||||
|
if port == 0 {
|
||||||
|
addr := listener.Addr().String()
|
||||||
|
parts := strings.Split(addr, ":")
|
||||||
|
if len(parts) < 2 {
|
||||||
|
return nil, port, fmt.Errorf("cannot extract port: %s", addr)
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
port, err = strconv.Atoi(parts[len(parts)-1])
|
||||||
|
if err != nil {
|
||||||
|
return nil, port, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
server := httpServer{
|
||||||
|
apiKey: []byte(apiKey),
|
||||||
|
actionChannel: actionChannel,
|
||||||
|
getHandler: getHandler,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
conn, err := listener.Accept()
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, net.ErrClosed) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
conn.Write([]byte(server.handleHttpRequest(conn)))
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return listener, port, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here we are writing a simplistic HTTP server without using net/http
|
||||||
|
// package to reduce the size of the binary.
|
||||||
|
//
|
||||||
|
// * No --listen: 2.8MB
|
||||||
|
// * --listen with net/http: 5.7MB
|
||||||
|
// * --listen w/o net/http: 3.3MB
|
||||||
|
func (server *httpServer) handleHttpRequest(conn net.Conn) string {
|
||||||
|
contentLength := 0
|
||||||
|
apiKey := ""
|
||||||
|
body := ""
|
||||||
|
answer := func(code string, message string) string {
|
||||||
|
message += "\n"
|
||||||
|
return code + fmt.Sprintf("Content-Length: %d%s", len(message), crlf+crlf+message)
|
||||||
|
}
|
||||||
|
unauthorized := func(message string) string {
|
||||||
|
return answer(httpUnauthorized, message)
|
||||||
|
}
|
||||||
|
bad := func(message string) string {
|
||||||
|
return answer(httpBadRequest, message)
|
||||||
|
}
|
||||||
|
good := func(message string) string {
|
||||||
|
return answer(httpOk+jsonContentType, message)
|
||||||
|
}
|
||||||
|
conn.SetReadDeadline(time.Now().Add(httpReadTimeout))
|
||||||
|
scanner := bufio.NewScanner(conn)
|
||||||
|
scanner.Split(func(data []byte, atEOF bool) (int, []byte, error) {
|
||||||
|
found := bytes.Index(data, []byte(crlf))
|
||||||
|
if found >= 0 {
|
||||||
|
token := data[:found+len(crlf)]
|
||||||
|
return len(token), token, nil
|
||||||
|
}
|
||||||
|
if atEOF || len(body)+len(data) >= contentLength {
|
||||||
|
return 0, data, bufio.ErrFinalToken
|
||||||
|
}
|
||||||
|
return 0, nil, nil
|
||||||
|
})
|
||||||
|
|
||||||
|
section := 0
|
||||||
|
for scanner.Scan() {
|
||||||
|
text := scanner.Text()
|
||||||
|
switch section {
|
||||||
|
case 0:
|
||||||
|
getMatch := getRegex.FindStringSubmatch(text)
|
||||||
|
if len(getMatch) > 0 {
|
||||||
|
response := server.getHandler(parseGetParams(getMatch[1]))
|
||||||
|
if len(response) > 0 {
|
||||||
|
return good(response)
|
||||||
|
}
|
||||||
|
return answer(httpUnavailable+jsonContentType, `{"error":"timeout"}`)
|
||||||
|
} else if !strings.HasPrefix(text, "POST / HTTP") {
|
||||||
|
return bad("invalid request method")
|
||||||
|
}
|
||||||
|
section++
|
||||||
|
case 1:
|
||||||
|
if text == crlf {
|
||||||
|
if contentLength == 0 {
|
||||||
|
return bad("content-length header missing")
|
||||||
|
}
|
||||||
|
section++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pair := strings.SplitN(text, ":", 2)
|
||||||
|
if len(pair) == 2 {
|
||||||
|
switch strings.ToLower(pair[0]) {
|
||||||
|
case "content-length":
|
||||||
|
length, err := strconv.Atoi(strings.TrimSpace(pair[1]))
|
||||||
|
if err != nil || length <= 0 || length > maxContentLength {
|
||||||
|
return bad("invalid content length")
|
||||||
|
}
|
||||||
|
contentLength = length
|
||||||
|
case "x-api-key":
|
||||||
|
apiKey = strings.TrimSpace(pair[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
body += text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(server.apiKey) != 0 && subtle.ConstantTimeCompare([]byte(apiKey), server.apiKey) != 1 {
|
||||||
|
return unauthorized("invalid api key")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(body) < contentLength {
|
||||||
|
return bad("incomplete request")
|
||||||
|
}
|
||||||
|
body = body[:contentLength]
|
||||||
|
|
||||||
|
actions, err := parseSingleActionList(strings.Trim(string(body), "\r\n"))
|
||||||
|
if err != nil {
|
||||||
|
return bad(err.Error())
|
||||||
|
}
|
||||||
|
if len(actions) == 0 {
|
||||||
|
return bad("no action specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
case server.actionChannel <- actions:
|
||||||
|
case <-time.After(channelTimeout):
|
||||||
|
return httpUnavailable + crlf
|
||||||
|
}
|
||||||
|
return httpOk + crlf
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseGetParams(query string) getParams {
|
||||||
|
params := getParams{limit: 100, offset: 0}
|
||||||
|
for _, pair := range strings.Split(query, "&") {
|
||||||
|
parts := strings.SplitN(pair, "=", 2)
|
||||||
|
if len(parts) == 2 {
|
||||||
|
switch parts[0] {
|
||||||
|
case "limit", "offset":
|
||||||
|
if val, err := strconv.Atoi(parts[1]); err == nil {
|
||||||
|
if parts[0] == "limit" {
|
||||||
|
params.limit = val
|
||||||
|
} else {
|
||||||
|
params.offset = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return params
|
||||||
|
}
|
||||||
4612
src/terminal.go
4612
src/terminal.go
File diff suppressed because it is too large
Load Diff
@@ -1,16 +1,31 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newItem(str string) *Item {
|
func replacePlaceholderTest(template string, stripAnsi bool, delimiter Delimiter, printsep string, forcePlus bool, query string, allItems []*Item) string {
|
||||||
bytes := []byte(str)
|
replaced, _ := replacePlaceholder(replacePlaceholderParams{
|
||||||
trimmed, _, _ := extractColor(str, nil, nil)
|
template: template,
|
||||||
return &Item{origText: &bytes, text: util.ToChars([]byte(trimmed))}
|
stripAnsi: stripAnsi,
|
||||||
|
delimiter: delimiter,
|
||||||
|
printsep: printsep,
|
||||||
|
forcePlus: forcePlus,
|
||||||
|
query: query,
|
||||||
|
allItems: allItems,
|
||||||
|
lastAction: actBackwardDeleteCharEof,
|
||||||
|
prompt: "prompt",
|
||||||
|
executor: util.NewExecutor(""),
|
||||||
|
})
|
||||||
|
return replaced
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReplacePlaceholder(t *testing.T) {
|
func TestReplacePlaceholder(t *testing.T) {
|
||||||
@@ -21,92 +36,624 @@ func TestReplacePlaceholder(t *testing.T) {
|
|||||||
newItem("foo'bar \x1b[31mbaz\x1b[m"),
|
newItem("foo'bar \x1b[31mbaz\x1b[m"),
|
||||||
newItem("FOO'BAR \x1b[31mBAZ\x1b[m")}
|
newItem("FOO'BAR \x1b[31mBAZ\x1b[m")}
|
||||||
|
|
||||||
|
delim := "'"
|
||||||
|
var regex *regexp.Regexp
|
||||||
|
|
||||||
var result string
|
var result string
|
||||||
check := func(expected string) {
|
check := func(expected string) {
|
||||||
if result != expected {
|
if result != expected {
|
||||||
t.Errorf("expected: %s, actual: %s", expected, result)
|
t.Errorf("expected: %s, actual: %s", expected, result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// helper function that converts template format into string and carries out the check()
|
||||||
|
checkFormat := func(format string) {
|
||||||
|
type quotes struct{ O, I, S string } // outer, inner quotes, print separator
|
||||||
|
unixStyle := quotes{`'`, `'\''`, "\n"}
|
||||||
|
windowsStyle := quotes{`^"`, `'`, "\n"}
|
||||||
|
var effectiveStyle quotes
|
||||||
|
|
||||||
|
if util.IsWindows() {
|
||||||
|
effectiveStyle = windowsStyle
|
||||||
|
} else {
|
||||||
|
effectiveStyle = unixStyle
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := templateToString(format, effectiveStyle)
|
||||||
|
check(expected)
|
||||||
|
}
|
||||||
|
printsep := "\n"
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test multiple placeholders and the function parameters.
|
||||||
|
*/
|
||||||
|
|
||||||
// {}, preserve ansi
|
// {}, preserve ansi
|
||||||
result = replacePlaceholder("echo {}", false, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {}", false, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo ' foo'\\''bar \x1b[31mbaz\x1b[m'")
|
checkFormat("echo {{.O}} foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
||||||
|
|
||||||
// {}, strip ansi
|
// {}, strip ansi
|
||||||
result = replacePlaceholder("echo {}", true, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo ' foo'\\''bar baz'")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {}, with multiple items
|
// {}, with multiple items
|
||||||
result = replacePlaceholder("echo {}", true, Delimiter{}, false, "query", items2)
|
result = replacePlaceholderTest("echo {}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
check("echo 'foo'\\''bar baz'")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {..}, strip leading whitespaces, preserve ansi
|
// {..}, strip leading whitespaces, preserve ansi
|
||||||
result = replacePlaceholder("echo {..}", false, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {..}", false, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo 'foo'\\''bar \x1b[31mbaz\x1b[m'")
|
checkFormat("echo {{.O}}foo{{.I}}bar \x1b[31mbaz\x1b[m{{.O}}")
|
||||||
|
|
||||||
// {..}, strip leading whitespaces, strip ansi
|
// {..}, strip leading whitespaces, strip ansi
|
||||||
result = replacePlaceholder("echo {..}", true, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {..}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo 'foo'\\''bar baz'")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// {q}
|
// {q}
|
||||||
result = replacePlaceholder("echo {} {q}", true, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {} {q}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo ' foo'\\''bar baz' 'query'")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}} {{.O}}query{{.O}}")
|
||||||
|
|
||||||
// {q}, multiple items
|
// {q}, multiple items
|
||||||
result = replacePlaceholder("echo {+}{q}{+}", true, Delimiter{}, false, "query 'string'", items2)
|
result = replacePlaceholderTest("echo {+}{q}{+}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
||||||
check("echo 'foo'\\''bar baz' 'FOO'\\''BAR BAZ''query '\\''string'\\''''foo'\\''bar baz' 'FOO'\\''BAR BAZ'")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {}{q}{}", true, Delimiter{}, false, "query 'string'", items2)
|
result = replacePlaceholderTest("echo {}{q}{}", true, Delimiter{}, printsep, false, "query 'string'", items2)
|
||||||
check("echo 'foo'\\''bar baz''query '\\''string'\\''''foo'\\''bar baz'")
|
checkFormat("echo {{.O}}foo{{.I}}bar baz{{.O}}{{.O}}query {{.I}}string{{.I}}{{.O}}{{.O}}foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {1}/{2}/{2,1}/{-1}/{-2}/{}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, false, "query", items1)
|
result = replacePlaceholderTest("echo {1}/{2}/{2,1}/{-1}/{-2}/{}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items1)
|
||||||
check("echo 'foo'\\''bar'/'baz'/'bazfoo'\\''bar'/'baz'/'foo'\\''bar'/' foo'\\''bar baz'/'foo'\\''bar baz'/{n.t}/{}/{1}/{q}/''")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}bazfoo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, false, "query", items2)
|
result = replacePlaceholderTest("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
check("echo 'foo'\\''bar'/'baz'/'baz'/'foo'\\''bar'/'foo'\\''bar baz'/{n.t}/{}/{1}/{q}/''")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}}/{{.O}}baz{{.O}}/{{.O}}baz{{.O}}/{{.O}}foo{{.I}}bar{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}}")
|
||||||
|
|
||||||
result = replacePlaceholder("echo {+1}/{+2}/{+-1}/{+-2}/{+..}/{n.t}/\\{}/\\{1}/\\{q}/{+3}", true, Delimiter{}, false, "query", items2)
|
result = replacePlaceholderTest("echo {+1}/{+2}/{+-1}/{+-2}/{+..}/{n.t}/\\{}/\\{1}/\\{q}/{+3}", true, Delimiter{}, printsep, false, "query", items2)
|
||||||
check("echo 'foo'\\''bar' 'FOO'\\''BAR'/'baz' 'BAZ'/'baz' 'BAZ'/'foo'\\''bar' 'FOO'\\''BAR'/'foo'\\''bar baz' 'FOO'\\''BAR BAZ'/{n.t}/{}/{1}/{q}/'' ''")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
||||||
|
|
||||||
// forcePlus
|
// forcePlus
|
||||||
result = replacePlaceholder("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, true, "query", items2)
|
result = replacePlaceholderTest("echo {1}/{2}/{-1}/{-2}/{..}/{n.t}/\\{}/\\{1}/\\{q}/{3}", true, Delimiter{}, printsep, true, "query", items2)
|
||||||
check("echo 'foo'\\''bar' 'FOO'\\''BAR'/'baz' 'BAZ'/'baz' 'BAZ'/'foo'\\''bar' 'FOO'\\''BAR'/'foo'\\''bar baz' 'FOO'\\''BAR BAZ'/{n.t}/{}/{1}/{q}/'' ''")
|
checkFormat("echo {{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}baz{{.O}} {{.O}}BAZ{{.O}}/{{.O}}foo{{.I}}bar{{.O}} {{.O}}FOO{{.I}}BAR{{.O}}/{{.O}}foo{{.I}}bar baz{{.O}} {{.O}}FOO{{.I}}BAR BAZ{{.O}}/{n.t}/{}/{1}/{q}/{{.O}}{{.O}} {{.O}}{{.O}}")
|
||||||
|
|
||||||
|
// Whitespace preserving flag with "'" delimiter
|
||||||
|
result = replacePlaceholderTest("echo {s1}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}} foo{{.O}}")
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}}bar baz{{.O}}")
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s..}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
|
// Whitespace preserving flag with regex delimiter
|
||||||
|
regex = regexp.MustCompile(`\w+`)
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s1}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}} {{.O}}")
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s2}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}}{{.I}}{{.O}}")
|
||||||
|
|
||||||
|
result = replacePlaceholderTest("echo {s3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
|
checkFormat("echo {{.O}} {{.O}}")
|
||||||
|
|
||||||
// No match
|
// No match
|
||||||
result = replacePlaceholder("echo {}/{+}", true, Delimiter{}, false, "query", []*Item{nil, nil})
|
result = replacePlaceholderTest("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, nil})
|
||||||
check("echo /")
|
check("echo /")
|
||||||
|
|
||||||
// No match, but with selections
|
// No match, but with selections
|
||||||
result = replacePlaceholder("echo {}/{+}", true, Delimiter{}, false, "query", []*Item{nil, item1})
|
result = replacePlaceholderTest("echo {}/{+}", true, Delimiter{}, printsep, false, "query", []*Item{nil, item1})
|
||||||
check("echo /' foo'\\''bar baz'")
|
checkFormat("echo /{{.O}} foo{{.I}}bar baz{{.O}}")
|
||||||
|
|
||||||
// String delimiter
|
// String delimiter
|
||||||
delim := "'"
|
result = replacePlaceholderTest("echo {}/{1}/{2}", true, Delimiter{str: &delim}, printsep, false, "query", items1)
|
||||||
result = replacePlaceholder("echo {}/{1}/{2}", true, Delimiter{str: &delim}, false, "query", items1)
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}foo{{.O}}/{{.O}}bar baz{{.O}}")
|
||||||
check("echo ' foo'\\''bar baz'/'foo'/'bar baz'")
|
|
||||||
|
|
||||||
// Regex delimiter
|
// Regex delimiter
|
||||||
regex := regexp.MustCompile("[oa]+")
|
regex = regexp.MustCompile("[oa]+")
|
||||||
// foo'bar baz
|
// foo'bar baz
|
||||||
result = replacePlaceholder("echo {}/{1}/{3}/{2..3}", true, Delimiter{regex: regex}, false, "query", items1)
|
result = replacePlaceholderTest("echo {}/{1}/{3}/{2..3}", true, Delimiter{regex: regex}, printsep, false, "query", items1)
|
||||||
check("echo ' foo'\\''bar baz'/'f'/'r b'/''\\''bar b'")
|
checkFormat("echo {{.O}} foo{{.I}}bar baz{{.O}}/{{.O}}f{{.O}}/{{.O}}r b{{.O}}/{{.O}}{{.I}}bar b{{.O}}")
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test single placeholders, but focus on the placeholders' parameters (e.g. flags).
|
||||||
|
see: TestParsePlaceholder
|
||||||
|
*/
|
||||||
|
items3 := []*Item{
|
||||||
|
// single line
|
||||||
|
newItem("1a 1b 1c 1d 1e 1f"),
|
||||||
|
// multi line
|
||||||
|
newItem("1a 1b 1c 1d 1e 1f"),
|
||||||
|
newItem("2a 2b 2c 2d 2e 2f"),
|
||||||
|
newItem("3a 3b 3c 3d 3e 3f"),
|
||||||
|
newItem("4a 4b 4c 4d 4e 4f"),
|
||||||
|
newItem("5a 5b 5c 5d 5e 5f"),
|
||||||
|
newItem("6a 6b 6c 6d 6e 6f"),
|
||||||
|
newItem("7a 7b 7c 7d 7e 7f"),
|
||||||
|
}
|
||||||
|
stripAnsi := false
|
||||||
|
forcePlus := false
|
||||||
|
query := "sample query"
|
||||||
|
|
||||||
|
templateToOutput := make(map[string]string)
|
||||||
|
templateToFile := make(map[string]string) // same as above, but the file contents will be matched
|
||||||
|
// I. item type placeholder
|
||||||
|
templateToOutput[`{}`] = `{{.O}}1a 1b 1c 1d 1e 1f{{.O}}`
|
||||||
|
templateToOutput[`{+}`] = `{{.O}}1a 1b 1c 1d 1e 1f{{.O}} {{.O}}2a 2b 2c 2d 2e 2f{{.O}} {{.O}}3a 3b 3c 3d 3e 3f{{.O}} {{.O}}4a 4b 4c 4d 4e 4f{{.O}} {{.O}}5a 5b 5c 5d 5e 5f{{.O}} {{.O}}6a 6b 6c 6d 6e 6f{{.O}} {{.O}}7a 7b 7c 7d 7e 7f{{.O}}`
|
||||||
|
templateToOutput[`{n}`] = `0`
|
||||||
|
templateToOutput[`{+n}`] = `0 0 0 0 0 0 0`
|
||||||
|
templateToFile[`{f}`] = `1a 1b 1c 1d 1e 1f{{.S}}`
|
||||||
|
templateToFile[`{+f}`] = `1a 1b 1c 1d 1e 1f{{.S}}2a 2b 2c 2d 2e 2f{{.S}}3a 3b 3c 3d 3e 3f{{.S}}4a 4b 4c 4d 4e 4f{{.S}}5a 5b 5c 5d 5e 5f{{.S}}6a 6b 6c 6d 6e 6f{{.S}}7a 7b 7c 7d 7e 7f{{.S}}`
|
||||||
|
templateToFile[`{nf}`] = `0{{.S}}`
|
||||||
|
templateToFile[`{+nf}`] = `0{{.S}}0{{.S}}0{{.S}}0{{.S}}0{{.S}}0{{.S}}0{{.S}}`
|
||||||
|
|
||||||
|
// II. token type placeholders
|
||||||
|
templateToOutput[`{..}`] = templateToOutput[`{}`]
|
||||||
|
templateToOutput[`{1..}`] = templateToOutput[`{}`]
|
||||||
|
templateToOutput[`{..2}`] = `{{.O}}1a 1b{{.O}}`
|
||||||
|
templateToOutput[`{1..2}`] = templateToOutput[`{..2}`]
|
||||||
|
templateToOutput[`{-2..-1}`] = `{{.O}}1e 1f{{.O}}`
|
||||||
|
// shorthand for x..x range
|
||||||
|
templateToOutput[`{1}`] = `{{.O}}1a{{.O}}`
|
||||||
|
templateToOutput[`{1..1}`] = templateToOutput[`{1}`]
|
||||||
|
templateToOutput[`{-6}`] = templateToOutput[`{1}`]
|
||||||
|
// multiple ranges
|
||||||
|
templateToOutput[`{1,2}`] = templateToOutput[`{1..2}`]
|
||||||
|
templateToOutput[`{1,2,4}`] = `{{.O}}1a 1b 1d{{.O}}`
|
||||||
|
templateToOutput[`{1,2..4}`] = `{{.O}}1a 1b 1c 1d{{.O}}`
|
||||||
|
templateToOutput[`{1..2,-4..-3}`] = `{{.O}}1a 1b 1c 1d{{.O}}`
|
||||||
|
// flags
|
||||||
|
templateToOutput[`{+1}`] = `{{.O}}1a{{.O}} {{.O}}2a{{.O}} {{.O}}3a{{.O}} {{.O}}4a{{.O}} {{.O}}5a{{.O}} {{.O}}6a{{.O}} {{.O}}7a{{.O}}`
|
||||||
|
templateToOutput[`{+-1}`] = `{{.O}}1f{{.O}} {{.O}}2f{{.O}} {{.O}}3f{{.O}} {{.O}}4f{{.O}} {{.O}}5f{{.O}} {{.O}}6f{{.O}} {{.O}}7f{{.O}}`
|
||||||
|
templateToOutput[`{s1}`] = `{{.O}}1a {{.O}}`
|
||||||
|
templateToFile[`{f1}`] = `1a{{.S}}`
|
||||||
|
templateToOutput[`{+s1..2}`] = `{{.O}}1a 1b {{.O}} {{.O}}2a 2b {{.O}} {{.O}}3a 3b {{.O}} {{.O}}4a 4b {{.O}} {{.O}}5a 5b {{.O}} {{.O}}6a 6b {{.O}} {{.O}}7a 7b {{.O}}`
|
||||||
|
templateToFile[`{+sf1..2}`] = `1a 1b {{.S}}2a 2b {{.S}}3a 3b {{.S}}4a 4b {{.S}}5a 5b {{.S}}6a 6b {{.S}}7a 7b {{.S}}`
|
||||||
|
|
||||||
|
// III. query type placeholder
|
||||||
|
// query flag is not removed after parsing, so it gets doubled
|
||||||
|
// while the double q is invalid, it is useful here for testing purposes
|
||||||
|
templateToOutput[`{q}`] = "{{.O}}" + query + "{{.O}}"
|
||||||
|
templateToOutput[`{fzf:query}`] = "{{.O}}" + query + "{{.O}}"
|
||||||
|
templateToOutput[`{fzf:action} {fzf:prompt}`] = "backward-delete-char-eof 'prompt'"
|
||||||
|
|
||||||
|
// IV. escaping placeholder
|
||||||
|
templateToOutput[`\{}`] = `{}`
|
||||||
|
templateToOutput[`\{q}`] = `{q}`
|
||||||
|
templateToOutput[`\{fzf:query}`] = `{fzf:query}`
|
||||||
|
templateToOutput[`\{fzf:action}`] = `{fzf:action}`
|
||||||
|
templateToOutput[`\{++}`] = `{++}`
|
||||||
|
templateToOutput[`{++}`] = templateToOutput[`{+}`]
|
||||||
|
|
||||||
|
for giveTemplate, wantOutput := range templateToOutput {
|
||||||
|
result = replacePlaceholderTest(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
||||||
|
checkFormat(wantOutput)
|
||||||
|
}
|
||||||
|
for giveTemplate, wantOutput := range templateToFile {
|
||||||
|
path := replacePlaceholderTest(giveTemplate, stripAnsi, Delimiter{}, printsep, forcePlus, query, items3)
|
||||||
|
|
||||||
|
data, err := readFile(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Cannot read the content of the temp file %s.", path)
|
||||||
|
}
|
||||||
|
result = string(data)
|
||||||
|
|
||||||
|
checkFormat(wantOutput)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQuoteEntry(t *testing.T) {
|
||||||
|
type quotes struct{ E, O, SQ, DQ, BS string } // standalone escape, outer, single and double quotes, backslash
|
||||||
|
unixStyle := quotes{``, `'`, `'\''`, `"`, `\`}
|
||||||
|
windowsStyle := quotes{`^`, `^"`, `'`, `\^"`, `\\`}
|
||||||
|
var effectiveStyle quotes
|
||||||
|
exec := util.NewExecutor("")
|
||||||
|
|
||||||
|
if util.IsWindows() {
|
||||||
|
effectiveStyle = windowsStyle
|
||||||
|
} else {
|
||||||
|
effectiveStyle = unixStyle
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQuoteEntryCmd(t *testing.T) {
|
|
||||||
tests := map[string]string{
|
tests := map[string]string{
|
||||||
`"`: `^"\^"^"`,
|
`'`: `{{.O}}{{.SQ}}{{.O}}`,
|
||||||
`\`: `^"\\^"`,
|
`"`: `{{.O}}{{.DQ}}{{.O}}`,
|
||||||
`\"`: `^"\\\^"^"`,
|
`\`: `{{.O}}{{.BS}}{{.O}}`,
|
||||||
`"\\\"`: `^"\^"\\\\\\\^"^"`,
|
`\"`: `{{.O}}{{.BS}}{{.DQ}}{{.O}}`,
|
||||||
`&|<>()@^%!`: `^"^&^|^<^>^(^)^@^^^%^!^"`,
|
`"\\\"`: `{{.O}}{{.DQ}}{{.BS}}{{.BS}}{{.BS}}{{.DQ}}{{.O}}`,
|
||||||
`%USERPROFILE%`: `^"^%USERPROFILE^%^"`,
|
|
||||||
`C:\Program Files (x86)\`: `^"C:\\Program Files ^(x86^)\\^"`,
|
`$`: `{{.O}}${{.O}}`,
|
||||||
|
`$HOME`: `{{.O}}$HOME{{.O}}`,
|
||||||
|
`'$HOME'`: `{{.O}}{{.SQ}}$HOME{{.SQ}}{{.O}}`,
|
||||||
|
|
||||||
|
`&`: `{{.O}}{{.E}}&{{.O}}`,
|
||||||
|
`|`: `{{.O}}{{.E}}|{{.O}}`,
|
||||||
|
`<`: `{{.O}}{{.E}}<{{.O}}`,
|
||||||
|
`>`: `{{.O}}{{.E}}>{{.O}}`,
|
||||||
|
`(`: `{{.O}}{{.E}}({{.O}}`,
|
||||||
|
`)`: `{{.O}}{{.E}}){{.O}}`,
|
||||||
|
`@`: `{{.O}}{{.E}}@{{.O}}`,
|
||||||
|
`^`: `{{.O}}{{.E}}^{{.O}}`,
|
||||||
|
`%`: `{{.O}}{{.E}}%{{.O}}`,
|
||||||
|
`!`: `{{.O}}{{.E}}!{{.O}}`,
|
||||||
|
`%USERPROFILE%`: `{{.O}}{{.E}}%USERPROFILE{{.E}}%{{.O}}`,
|
||||||
|
`C:\Program Files (x86)\`: `{{.O}}C:{{.BS}}Program Files {{.E}}(x86{{.E}}){{.BS}}{{.O}}`,
|
||||||
|
`"C:\Program Files"`: `{{.O}}{{.DQ}}C:{{.BS}}Program Files{{.DQ}}{{.O}}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
for input, expected := range tests {
|
for input, expected := range tests {
|
||||||
escaped := quoteEntryCmd(input)
|
escaped := exec.QuoteEntry(input)
|
||||||
|
expected = templateToString(expected, effectiveStyle)
|
||||||
if escaped != expected {
|
if escaped != expected {
|
||||||
t.Errorf("Input: %s, expected: %s, actual %s", input, expected, escaped)
|
t.Errorf("Input: %s, expected: %s, actual %s", input, expected, escaped)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// purpose of this test is to demonstrate some shortcomings of fzf's templating system on Unix
|
||||||
|
func TestUnixCommands(t *testing.T) {
|
||||||
|
if util.IsWindows() {
|
||||||
|
t.SkipNow()
|
||||||
|
}
|
||||||
|
tests := []testCase{
|
||||||
|
// reference: give{template, query, items}, want{output OR match}
|
||||||
|
|
||||||
|
// 1) working examples
|
||||||
|
|
||||||
|
// paths that does not have to evaluated will work fine, when quoted
|
||||||
|
{give{`grep foo {}`, ``, newItems(`test`)}, want{output: `grep foo 'test'`}},
|
||||||
|
{give{`grep foo {}`, ``, newItems(`/home/user/test`)}, want{output: `grep foo '/home/user/test'`}},
|
||||||
|
{give{`grep foo {}`, ``, newItems(`./test`)}, want{output: `grep foo './test'`}},
|
||||||
|
|
||||||
|
// only placeholders are escaped as data, this will lookup tilde character in a test file in your home directory
|
||||||
|
// quoting the tilde is required (to be treated as string)
|
||||||
|
{give{`grep {} ~/test`, ``, newItems(`~`)}, want{output: `grep '~' ~/test`}},
|
||||||
|
|
||||||
|
// 2) problematic examples
|
||||||
|
// (not necessarily unexpected)
|
||||||
|
|
||||||
|
// paths that need to expand some part of it won't work (special characters and variables)
|
||||||
|
{give{`cat {}`, ``, newItems(`~/test`)}, want{output: `cat '~/test'`}},
|
||||||
|
{give{`cat {}`, ``, newItems(`$HOME/test`)}, want{output: `cat '$HOME/test'`}},
|
||||||
|
}
|
||||||
|
testCommands(t, tests)
|
||||||
|
}
|
||||||
|
|
||||||
|
// purpose of this test is to demonstrate some shortcomings of fzf's templating system on Windows
|
||||||
|
func TestWindowsCommands(t *testing.T) {
|
||||||
|
// XXX Deprecated
|
||||||
|
t.SkipNow()
|
||||||
|
|
||||||
|
tests := []testCase{
|
||||||
|
// reference: give{template, query, items}, want{output OR match}
|
||||||
|
|
||||||
|
// 1) working examples
|
||||||
|
|
||||||
|
// example of redundantly escaped backslash in the output, besides looking bit ugly, it won't cause any issue
|
||||||
|
{give{`type {}`, ``, newItems(`C:\test.txt`)}, want{output: `type ^"C:\\test.txt^"`}},
|
||||||
|
{give{`rg -- "package" {}`, ``, newItems(`.\test.go`)}, want{output: `rg -- "package" ^".\\test.go^"`}},
|
||||||
|
// example of mandatorily escaped backslash in the output, otherwise `rg -- "C:\test.txt"` is matching for tabulator
|
||||||
|
{give{`rg -- {}`, ``, newItems(`C:\test.txt`)}, want{output: `rg -- ^"C:\\test.txt^"`}},
|
||||||
|
// example of mandatorily escaped double quote in the output, otherwise `rg -- ""C:\\test.txt""` is not matching for the double quotes around the path
|
||||||
|
{give{`rg -- {}`, ``, newItems(`"C:\test.txt"`)}, want{output: `rg -- ^"\^"C:\\test.txt\^"^"`}},
|
||||||
|
|
||||||
|
// 2) problematic examples
|
||||||
|
// (not necessarily unexpected)
|
||||||
|
|
||||||
|
// notepad++'s parser can't handle `-n"12"` generate by fzf, expects `-n12`
|
||||||
|
{give{`notepad++ -n{1} {2}`, ``, newItems(`12 C:\Work\Test Folder\File.txt`)}, want{output: `notepad++ -n^"12^" ^"C:\\Work\\Test Folder\\File.txt^"`}},
|
||||||
|
|
||||||
|
// cat is parsing `\"` as a part of the file path, double quote is illegal character for paths on Windows
|
||||||
|
// cat: "C:\\test.txt: Invalid argument
|
||||||
|
{give{`cat {}`, ``, newItems(`"C:\test.txt"`)}, want{output: `cat ^"\^"C:\\test.txt\^"^"`}},
|
||||||
|
// cat: "C:\\test.txt": Invalid argument
|
||||||
|
{give{`cmd /c {}`, ``, newItems(`cat "C:\test.txt"`)}, want{output: `cmd /c ^"cat \^"C:\\test.txt\^"^"`}},
|
||||||
|
|
||||||
|
// the "file" flag in the pattern won't create *.bat or *.cmd file so the command in the output tries to edit the file, instead of executing it
|
||||||
|
// the temp file contains: `cat "C:\test.txt"`
|
||||||
|
// TODO this should actually work
|
||||||
|
{give{`cmd /c {f}`, ``, newItems(`cat "C:\test.txt"`)}, want{match: `^cmd /c .*\fzf-preview-[0-9]{9}$`}},
|
||||||
|
}
|
||||||
|
testCommands(t, tests)
|
||||||
|
}
|
||||||
|
|
||||||
|
// purpose of this test is to demonstrate some shortcomings of fzf's templating system on Windows in Powershell
|
||||||
|
func TestPowershellCommands(t *testing.T) {
|
||||||
|
if !util.IsWindows() {
|
||||||
|
t.SkipNow()
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []testCase{
|
||||||
|
// reference: give{template, query, items}, want{output OR match}
|
||||||
|
|
||||||
|
/*
|
||||||
|
You can read each line in the following table as a pipeline that
|
||||||
|
consist of series of parsers that act upon your input (col. 1) and
|
||||||
|
each cell represents the output value.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
- exec.Command("program.exe", `\''`)
|
||||||
|
- goes to win32 api which will process it transparently as it contains no special characters, see [CommandLineToArgvW][].
|
||||||
|
- powershell command will receive it as is, that is two arguments: a literal backslash and empty string in single quotes
|
||||||
|
- native command run via/from powershell will receive only one argument: a literal backslash. Because extra parsing rules apply, see [NativeCallsFromPowershell][].
|
||||||
|
- some¹ apps have internal parser, that requires one more level of escaping (yes, this is completely application-specific, but see terminal_test.go#TestWindowsCommands)
|
||||||
|
|
||||||
|
Character⁰ CommandLineToArgvW Powershell commands Native commands from Powershell Apps requiring escapes¹ | Being tested below
|
||||||
|
---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------
|
||||||
|
" empty string² missing argument error ... ... |
|
||||||
|
\" literal " unbalanced quote error ... ... |
|
||||||
|
'\"' literal '"' literal " empty string empty string (match all) | yes
|
||||||
|
'\\\"' literal '\"' literal \" literal " literal " |
|
||||||
|
---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------
|
||||||
|
\ transparent transparent transparent regex error |
|
||||||
|
'\' transparent literal \ literal \ regex error | yes
|
||||||
|
\\ transparent transparent transparent literal \ |
|
||||||
|
'\\' transparent literal \\ literal \\ literal \ |
|
||||||
|
---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------
|
||||||
|
' transparent unbalanced quote error ... ... |
|
||||||
|
\' transparent literal \ and unb. quote error ... ... |
|
||||||
|
\'' transparent literal \ and empty string literal \ regex error | no, but given as example above
|
||||||
|
''' transparent unbalanced quote error ... ... |
|
||||||
|
'''' transparent literal ' literal ' literal ' | yes
|
||||||
|
---------- ------------------ ------------------------------ ------------------------------- -------------------------- | ------------------
|
||||||
|
|
||||||
|
⁰: charatecter or characters 'x' as an argument to a program in go's call: exec.Command("program.exe", `x`)
|
||||||
|
¹: native commands like grep, git grep, ripgrep
|
||||||
|
²: interpreted as a grouping quote, affects argument parser and gets removed from the result
|
||||||
|
|
||||||
|
[CommandLineToArgvW]: https://docs.microsoft.com/en-gb/windows/win32/api/shellapi/nf-shellapi-commandlinetoargvw#remarks
|
||||||
|
[NativeCallsFromPowershell]: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.1#passing-arguments-that-contain-quote-characters
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 1) working examples
|
||||||
|
|
||||||
|
{give{`Get-Content {}`, ``, newItems(`C:\test.txt`)}, want{output: `Get-Content 'C:\test.txt'`}},
|
||||||
|
{give{`rg -- "package" {}`, ``, newItems(`.\test.go`)}, want{output: `rg -- "package" '.\test.go'`}},
|
||||||
|
|
||||||
|
// example of escaping single quotes
|
||||||
|
{give{`rg -- {}`, ``, newItems(`'foobar'`)}, want{output: `rg -- '''foobar'''`}},
|
||||||
|
|
||||||
|
// chaining powershells
|
||||||
|
{give{`powershell -NoProfile -Command {}`, ``, newItems(`cat "C:\test.txt"`)}, want{output: `powershell -NoProfile -Command 'cat \"C:\test.txt\"'`}},
|
||||||
|
|
||||||
|
// 2) problematic examples
|
||||||
|
// (not necessarily unexpected)
|
||||||
|
|
||||||
|
// looking for a path string will only work with escaped backslashes
|
||||||
|
{give{`rg -- {}`, ``, newItems(`C:\test.txt`)}, want{output: `rg -- 'C:\test.txt'`}},
|
||||||
|
// looking for a literal double quote will only work with triple escaped double quotes
|
||||||
|
{give{`rg -- {}`, ``, newItems(`"C:\test.txt"`)}, want{output: `rg -- '\"C:\test.txt\"'`}},
|
||||||
|
|
||||||
|
// Get-Content (i.e. cat alias) is parsing `"` as a part of the file path, returns an error:
|
||||||
|
// Get-Content : Cannot find drive. A drive with the name '"C:' does not exist.
|
||||||
|
{give{`cat {}`, ``, newItems(`"C:\test.txt"`)}, want{output: `cat '\"C:\test.txt\"'`}},
|
||||||
|
|
||||||
|
// the "file" flag in the pattern won't create *.ps1 file so the powershell will offload this "unknown" filetype
|
||||||
|
// to explorer, which will prompt user to pick editing program for the fzf-preview file
|
||||||
|
// the temp file contains: `cat "C:\test.txt"`
|
||||||
|
// TODO this should actually work
|
||||||
|
{give{`powershell -NoProfile -Command {f}`, ``, newItems(`cat "C:\test.txt"`)}, want{match: `^powershell -NoProfile -Command .*\fzf-preview-[0-9]{9}$`}},
|
||||||
|
}
|
||||||
|
|
||||||
|
// to force powershell-style escaping we temporarily set environment variable that fzf honors
|
||||||
|
shellBackup := os.Getenv("SHELL")
|
||||||
|
os.Setenv("SHELL", "powershell")
|
||||||
|
testCommands(t, tests)
|
||||||
|
os.Setenv("SHELL", shellBackup)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test typical valid placeholders and parsing of them.
|
||||||
|
|
||||||
|
Also since the parser assumes the input is matched with `placeholder` regex,
|
||||||
|
the regex is tested here as well.
|
||||||
|
*/
|
||||||
|
func TestParsePlaceholder(t *testing.T) {
|
||||||
|
// give, want pairs
|
||||||
|
templates := map[string]string{
|
||||||
|
// I. item type placeholder
|
||||||
|
`{}`: `{}`,
|
||||||
|
`{+}`: `{+}`,
|
||||||
|
`{n}`: `{n}`,
|
||||||
|
`{+n}`: `{+n}`,
|
||||||
|
`{f}`: `{f}`,
|
||||||
|
`{+nf}`: `{+nf}`,
|
||||||
|
|
||||||
|
// II. token type placeholders
|
||||||
|
`{..}`: `{..}`,
|
||||||
|
`{1..}`: `{1..}`,
|
||||||
|
`{..2}`: `{..2}`,
|
||||||
|
`{1..2}`: `{1..2}`,
|
||||||
|
`{-2..-1}`: `{-2..-1}`,
|
||||||
|
// shorthand for x..x range
|
||||||
|
`{1}`: `{1}`,
|
||||||
|
`{1..1}`: `{1..1}`,
|
||||||
|
`{-6}`: `{-6}`,
|
||||||
|
// multiple ranges
|
||||||
|
`{1,2}`: `{1,2}`,
|
||||||
|
`{1,2,4}`: `{1,2,4}`,
|
||||||
|
`{1,2..4}`: `{1,2..4}`,
|
||||||
|
`{1..2,-4..-3}`: `{1..2,-4..-3}`,
|
||||||
|
// flags
|
||||||
|
`{+1}`: `{+1}`,
|
||||||
|
`{+-1}`: `{+-1}`,
|
||||||
|
`{s1}`: `{s1}`,
|
||||||
|
`{f1}`: `{f1}`,
|
||||||
|
`{+s1..2}`: `{+s1..2}`,
|
||||||
|
`{+sf1..2}`: `{+sf1..2}`,
|
||||||
|
|
||||||
|
// III. query type placeholder
|
||||||
|
// query flag is not removed after parsing, so it gets doubled
|
||||||
|
// while the double q is invalid, it is useful here for testing purposes
|
||||||
|
`{q}`: `{qq}`,
|
||||||
|
|
||||||
|
// IV. escaping placeholder
|
||||||
|
`\{}`: `{}`,
|
||||||
|
`\{++}`: `{++}`,
|
||||||
|
`{++}`: `{+}`,
|
||||||
|
}
|
||||||
|
|
||||||
|
for giveTemplate, wantTemplate := range templates {
|
||||||
|
if !placeholder.MatchString(giveTemplate) {
|
||||||
|
t.Errorf(`given placeholder %s does not match placeholder regex, so attempt to parse it is unexpected`, giveTemplate)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, placeholderWithoutFlags, flags := parsePlaceholder(giveTemplate)
|
||||||
|
gotTemplate := placeholderWithoutFlags[:1] + flags.encodePlaceholder() + placeholderWithoutFlags[1:]
|
||||||
|
|
||||||
|
if gotTemplate != wantTemplate {
|
||||||
|
t.Errorf(`parsed placeholder "%s" into "%s", but want "%s"`, giveTemplate, gotTemplate, wantTemplate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* utilities section */
|
||||||
|
|
||||||
|
// Item represents one line in fzf UI. Usually it is relative path to files and folders.
|
||||||
|
func newItem(str string) *Item {
|
||||||
|
bytes := []byte(str)
|
||||||
|
trimmed, _, _ := extractColor(str, nil, nil)
|
||||||
|
return &Item{origText: &bytes, text: util.ToChars([]byte(trimmed))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Functions tested in this file require array of items (allItems). The array needs
|
||||||
|
// to consist of at least two nils. This is helper function.
|
||||||
|
func newItems(str ...string) []*Item {
|
||||||
|
result := make([]*Item, util.Max(len(str), 2))
|
||||||
|
for i, s := range str {
|
||||||
|
result[i] = newItem(s)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// (for logging purposes)
|
||||||
|
func (item *Item) String() string {
|
||||||
|
return item.AsString(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper function to parse, execute and convert "text/template" to string. Panics on error.
|
||||||
|
func templateToString(format string, data interface{}) string {
|
||||||
|
bb := &bytes.Buffer{}
|
||||||
|
|
||||||
|
err := template.Must(template.New("").Parse(format)).Execute(bb, data)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return bb.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ad hoc types for test cases
|
||||||
|
type give struct {
|
||||||
|
template string
|
||||||
|
query string
|
||||||
|
allItems []*Item
|
||||||
|
}
|
||||||
|
type want struct {
|
||||||
|
/*
|
||||||
|
Unix:
|
||||||
|
The `want.output` string is supposed to be formatted for evaluation by
|
||||||
|
`sh -c command` system call.
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
The `want.output` string is supposed to be formatted for evaluation by
|
||||||
|
`cmd.exe /s /c "command"` system call. The `/s` switch enables so called old
|
||||||
|
behaviour, which is more favourable for nesting (possibly escaped)
|
||||||
|
special characters. This is the relevant section of `help cmd`:
|
||||||
|
|
||||||
|
...old behavior is to see if the first character is
|
||||||
|
a quote character and if so, strip the leading character and
|
||||||
|
remove the last quote character on the command line, preserving
|
||||||
|
any text after the last quote character.
|
||||||
|
*/
|
||||||
|
output string // literal output
|
||||||
|
match string // output is matched against this regex (when output is empty string)
|
||||||
|
}
|
||||||
|
type testCase struct {
|
||||||
|
give
|
||||||
|
want
|
||||||
|
}
|
||||||
|
|
||||||
|
func testCommands(t *testing.T, tests []testCase) {
|
||||||
|
// common test parameters
|
||||||
|
delim := "\t"
|
||||||
|
delimiter := Delimiter{str: &delim}
|
||||||
|
printsep := ""
|
||||||
|
stripAnsi := false
|
||||||
|
forcePlus := false
|
||||||
|
|
||||||
|
// evaluate the test cases
|
||||||
|
for idx, test := range tests {
|
||||||
|
gotOutput := replacePlaceholderTest(
|
||||||
|
test.give.template, stripAnsi, delimiter, printsep, forcePlus,
|
||||||
|
test.give.query,
|
||||||
|
test.give.allItems)
|
||||||
|
switch {
|
||||||
|
case test.want.output != "":
|
||||||
|
if gotOutput != test.want.output {
|
||||||
|
t.Errorf("tests[%v]:\ngave{\n\ttemplate: '%s',\n\tquery: '%s',\n\tallItems: %s}\nand got '%s',\nbut want '%s'",
|
||||||
|
idx,
|
||||||
|
test.give.template, test.give.query, test.give.allItems,
|
||||||
|
gotOutput, test.want.output)
|
||||||
|
}
|
||||||
|
case test.want.match != "":
|
||||||
|
wantMatch := strings.ReplaceAll(test.want.match, `\`, `\\`)
|
||||||
|
wantRegex := regexp.MustCompile(wantMatch)
|
||||||
|
if !wantRegex.MatchString(gotOutput) {
|
||||||
|
t.Errorf("tests[%v]:\ngave{\n\ttemplate: '%s',\n\tquery: '%s',\n\tallItems: %s}\nand got '%s',\nbut want '%s'",
|
||||||
|
idx,
|
||||||
|
test.give.template, test.give.query, test.give.allItems,
|
||||||
|
gotOutput, test.want.match)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
t.Errorf("tests[%v]: test case does not describe 'want' property", idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// naive encoder of placeholder flags
|
||||||
|
func (flags placeholderFlags) encodePlaceholder() string {
|
||||||
|
encoded := ""
|
||||||
|
if flags.plus {
|
||||||
|
encoded += "+"
|
||||||
|
}
|
||||||
|
if flags.preserveSpace {
|
||||||
|
encoded += "s"
|
||||||
|
}
|
||||||
|
if flags.number {
|
||||||
|
encoded += "n"
|
||||||
|
}
|
||||||
|
if flags.file {
|
||||||
|
encoded += "f"
|
||||||
|
}
|
||||||
|
if flags.forceUpdate { // FIXME
|
||||||
|
encoded += "q"
|
||||||
|
}
|
||||||
|
return encoded
|
||||||
|
}
|
||||||
|
|
||||||
|
// can be replaced with os.ReadFile() in go 1.16+
|
||||||
|
func readFile(path string) ([]byte, error) {
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
data := make([]byte, 0, 128)
|
||||||
|
for {
|
||||||
|
if len(data) >= cap(data) {
|
||||||
|
d := append(data[:cap(data)], 0)
|
||||||
|
data = d[:len(data)]
|
||||||
|
}
|
||||||
|
|
||||||
|
n, err := file.Read(data[len(data):cap(data)])
|
||||||
|
data = data[:len(data)+n]
|
||||||
|
if err != nil {
|
||||||
|
if err == io.EOF {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
|
return data, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build !windows
|
//go:build !windows
|
||||||
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
@@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func notifyOnResize(resizeChan chan<- os.Signal) {
|
func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||||
@@ -13,9 +15,10 @@ func notifyOnResize(resizeChan chan<- os.Signal) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func notifyStop(p *os.Process) {
|
func notifyStop(p *os.Process) {
|
||||||
p.Signal(syscall.SIGSTOP)
|
pid := p.Pid
|
||||||
|
pgid, err := unix.Getpgid(pid)
|
||||||
|
if err == nil {
|
||||||
|
pid = pgid * -1
|
||||||
}
|
}
|
||||||
|
unix.Kill(pid, syscall.SIGTSTP)
|
||||||
func notifyOnCont(resizeChan chan<- os.Signal) {
|
|
||||||
signal.Notify(resizeChan, syscall.SIGCONT)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// +build windows
|
//go:build windows
|
||||||
|
|
||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
@@ -13,7 +13,3 @@ func notifyOnResize(resizeChan chan<- os.Signal) {
|
|||||||
func notifyStop(p *os.Process) {
|
func notifyStop(p *os.Process) {
|
||||||
// NOOP
|
// NOOP
|
||||||
}
|
}
|
||||||
|
|
||||||
func notifyOnCont(resizeChan chan<- os.Signal) {
|
|
||||||
// NOOP
|
|
||||||
}
|
|
||||||
|
|||||||
60
src/tmux.go
Normal file
60
src/tmux.go
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
package fzf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/tui"
|
||||||
|
)
|
||||||
|
|
||||||
|
func runTmux(args []string, opts *Options) (int, error) {
|
||||||
|
// Prepare arguments
|
||||||
|
fzf := args[0]
|
||||||
|
args = append([]string{"--bind=ctrl-z:ignore"}, args[1:]...)
|
||||||
|
if opts.BorderShape == tui.BorderUndefined {
|
||||||
|
args = append(args, "--border")
|
||||||
|
}
|
||||||
|
argStr := escapeSingleQuote(fzf)
|
||||||
|
for _, arg := range args {
|
||||||
|
argStr += " " + escapeSingleQuote(arg)
|
||||||
|
}
|
||||||
|
argStr += ` --no-tmux --no-height`
|
||||||
|
|
||||||
|
// Get current directory
|
||||||
|
dir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
dir = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set tmux options for popup placement
|
||||||
|
// C Both The centre of the terminal
|
||||||
|
// R -x The right side of the terminal
|
||||||
|
// P Both The bottom left of the pane
|
||||||
|
// M Both The mouse position
|
||||||
|
// W Both The window position on the status line
|
||||||
|
// S -y The line above or below the status line
|
||||||
|
tmuxArgs := []string{"display-popup", "-E", "-B", "-d", dir}
|
||||||
|
switch opts.Tmux.position {
|
||||||
|
case posUp:
|
||||||
|
tmuxArgs = append(tmuxArgs, "-xC", "-y0")
|
||||||
|
case posDown:
|
||||||
|
tmuxArgs = append(tmuxArgs, "-xC", "-y9999")
|
||||||
|
case posLeft:
|
||||||
|
tmuxArgs = append(tmuxArgs, "-x0", "-yC")
|
||||||
|
case posRight:
|
||||||
|
tmuxArgs = append(tmuxArgs, "-xR", "-yC")
|
||||||
|
case posCenter:
|
||||||
|
tmuxArgs = append(tmuxArgs, "-xC", "-yC")
|
||||||
|
}
|
||||||
|
tmuxArgs = append(tmuxArgs, "-w"+opts.Tmux.width.String())
|
||||||
|
tmuxArgs = append(tmuxArgs, "-h"+opts.Tmux.height.String())
|
||||||
|
|
||||||
|
return runProxy(argStr, func(temp string, needBash bool) (*exec.Cmd, error) {
|
||||||
|
sh, err := sh(needBash)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
tmuxArgs = append(tmuxArgs, sh, temp)
|
||||||
|
return exec.Command("tmux", tmuxArgs...), nil
|
||||||
|
}, opts, true)
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package fzf
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -23,12 +24,22 @@ type Token struct {
|
|||||||
prefixLength int32
|
prefixLength int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of a Token.
|
||||||
|
func (t Token) String() string {
|
||||||
|
return fmt.Sprintf("Token{text: %s, prefixLength: %d}", t.text, t.prefixLength)
|
||||||
|
}
|
||||||
|
|
||||||
// Delimiter for tokenizing the input
|
// Delimiter for tokenizing the input
|
||||||
type Delimiter struct {
|
type Delimiter struct {
|
||||||
regex *regexp.Regexp
|
regex *regexp.Regexp
|
||||||
str *string
|
str *string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String returns the string representation of a Delimiter.
|
||||||
|
func (d Delimiter) String() string {
|
||||||
|
return fmt.Sprintf("Delimiter{regex: %v, str: &%q}", d.regex, *d.str)
|
||||||
|
}
|
||||||
|
|
||||||
func newRange(begin int, end int) Range {
|
func newRange(begin int, end int) Range {
|
||||||
if begin == 1 {
|
if begin == 1 {
|
||||||
begin = rangeEllipsis
|
begin = rangeEllipsis
|
||||||
@@ -80,7 +91,7 @@ func withPrefixLengths(tokens []string, begin int) []Token {
|
|||||||
|
|
||||||
prefixLength := begin
|
prefixLength := begin
|
||||||
for idx := range tokens {
|
for idx := range tokens {
|
||||||
chars := util.ToChars([]byte(tokens[idx]))
|
chars := util.ToChars(stringBytes(tokens[idx]))
|
||||||
ret[idx] = Token{&chars, int32(prefixLength)}
|
ret[idx] = Token{&chars, int32(prefixLength)}
|
||||||
prefixLength += chars.Length()
|
prefixLength += chars.Length()
|
||||||
}
|
}
|
||||||
@@ -145,14 +156,14 @@ func Tokenize(text string, delimiter Delimiter) []Token {
|
|||||||
// FIXME performance
|
// FIXME performance
|
||||||
var tokens []string
|
var tokens []string
|
||||||
if delimiter.regex != nil {
|
if delimiter.regex != nil {
|
||||||
for len(text) > 0 {
|
locs := delimiter.regex.FindAllStringIndex(text, -1)
|
||||||
loc := delimiter.regex.FindStringIndex(text)
|
begin := 0
|
||||||
if len(loc) < 2 {
|
for _, loc := range locs {
|
||||||
loc = []int{0, len(text)}
|
tokens = append(tokens, text[begin:loc[1]])
|
||||||
|
begin = loc[1]
|
||||||
}
|
}
|
||||||
last := util.Max(loc[1], 1)
|
if begin < len(text) {
|
||||||
tokens = append(tokens, text[:last])
|
tokens = append(tokens, text[begin:])
|
||||||
text = text[last:]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return withPrefixLengths(tokens, 0)
|
return withPrefixLengths(tokens, 0)
|
||||||
@@ -176,7 +187,7 @@ func Transform(tokens []Token, withNth []Range) []Token {
|
|||||||
if r.begin == r.end {
|
if r.begin == r.end {
|
||||||
idx := r.begin
|
idx := r.begin
|
||||||
if idx == rangeEllipsis {
|
if idx == rangeEllipsis {
|
||||||
chars := util.ToChars([]byte(joinTokens(tokens)))
|
chars := util.ToChars(stringBytes(joinTokens(tokens)))
|
||||||
parts = append(parts, &chars)
|
parts = append(parts, &chars)
|
||||||
} else {
|
} else {
|
||||||
if idx < 0 {
|
if idx < 0 {
|
||||||
@@ -227,7 +238,7 @@ func Transform(tokens []Token, withNth []Range) []Token {
|
|||||||
for _, part := range parts {
|
for _, part := range parts {
|
||||||
output.WriteString(part.ToString())
|
output.WriteString(part.ToString())
|
||||||
}
|
}
|
||||||
merged = util.ToChars([]byte(output.String()))
|
merged = util.ToChars(output.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
var prefixLength int32
|
var prefixLength int32
|
||||||
|
|||||||
@@ -9,35 +9,35 @@ func TestParseRange(t *testing.T) {
|
|||||||
i := ".."
|
i := ".."
|
||||||
r, _ := ParseRange(&i)
|
r, _ := ParseRange(&i)
|
||||||
if r.begin != rangeEllipsis || r.end != rangeEllipsis {
|
if r.begin != rangeEllipsis || r.end != rangeEllipsis {
|
||||||
t.Errorf("%s", r)
|
t.Errorf("%v", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
i := "3.."
|
i := "3.."
|
||||||
r, _ := ParseRange(&i)
|
r, _ := ParseRange(&i)
|
||||||
if r.begin != 3 || r.end != rangeEllipsis {
|
if r.begin != 3 || r.end != rangeEllipsis {
|
||||||
t.Errorf("%s", r)
|
t.Errorf("%v", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
i := "3..5"
|
i := "3..5"
|
||||||
r, _ := ParseRange(&i)
|
r, _ := ParseRange(&i)
|
||||||
if r.begin != 3 || r.end != 5 {
|
if r.begin != 3 || r.end != 5 {
|
||||||
t.Errorf("%s", r)
|
t.Errorf("%v", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
i := "-3..-5"
|
i := "-3..-5"
|
||||||
r, _ := ParseRange(&i)
|
r, _ := ParseRange(&i)
|
||||||
if r.begin != -3 || r.end != -5 {
|
if r.begin != -3 || r.end != -5 {
|
||||||
t.Errorf("%s", r)
|
t.Errorf("%v", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
i := "3"
|
i := "3"
|
||||||
r, _ := ParseRange(&i)
|
r, _ := ParseRange(&i)
|
||||||
if r.begin != 3 || r.end != 3 {
|
if r.begin != 3 || r.end != 3 {
|
||||||
t.Errorf("%s", r)
|
t.Errorf("%v", r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,14 +71,14 @@ func TestTransform(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tokens := Tokenize(input, Delimiter{})
|
tokens := Tokenize(input, Delimiter{})
|
||||||
{
|
{
|
||||||
ranges := splitNth("1,2,3")
|
ranges, _ := splitNth("1,2,3")
|
||||||
tx := Transform(tokens, ranges)
|
tx := Transform(tokens, ranges)
|
||||||
if string(joinTokens(tx)) != "abc: def: ghi: " {
|
if joinTokens(tx) != "abc: def: ghi: " {
|
||||||
t.Errorf("%s", tx)
|
t.Errorf("%s", tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
ranges := splitNth("1..2,3,2..,1")
|
ranges, _ := splitNth("1..2,3,2..,1")
|
||||||
tx := Transform(tokens, ranges)
|
tx := Transform(tokens, ranges)
|
||||||
if string(joinTokens(tx)) != "abc: def: ghi: def: ghi: jklabc: " ||
|
if string(joinTokens(tx)) != "abc: def: ghi: def: ghi: jklabc: " ||
|
||||||
len(tx) != 4 ||
|
len(tx) != 4 ||
|
||||||
@@ -93,9 +93,9 @@ func TestTransform(t *testing.T) {
|
|||||||
{
|
{
|
||||||
tokens := Tokenize(input, delimiterRegexp(":"))
|
tokens := Tokenize(input, delimiterRegexp(":"))
|
||||||
{
|
{
|
||||||
ranges := splitNth("1..2,3,2..,1")
|
ranges, _ := splitNth("1..2,3,2..,1")
|
||||||
tx := Transform(tokens, ranges)
|
tx := Transform(tokens, ranges)
|
||||||
if string(joinTokens(tx)) != " abc: def: ghi: def: ghi: jkl abc:" ||
|
if joinTokens(tx) != " abc: def: ghi: def: ghi: jkl abc:" ||
|
||||||
len(tx) != 4 ||
|
len(tx) != 4 ||
|
||||||
tx[0].text.ToString() != " abc: def:" || tx[0].prefixLength != 0 ||
|
tx[0].text.ToString() != " abc: def:" || tx[0].prefixLength != 0 ||
|
||||||
tx[1].text.ToString() != " ghi:" || tx[1].prefixLength != 12 ||
|
tx[1].text.ToString() != " ghi:" || tx[1].prefixLength != 12 ||
|
||||||
@@ -108,5 +108,6 @@ func TestTransform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTransformIndexOutOfBounds(t *testing.T) {
|
func TestTransformIndexOutOfBounds(t *testing.T) {
|
||||||
Transform([]Token{}, splitNth("1"))
|
s, _ := splitNth("1")
|
||||||
|
Transform([]Token{}, s)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
// +build !ncurses
|
//go:build !tcell && !windows
|
||||||
// +build !tcell
|
|
||||||
// +build !windows
|
|
||||||
|
|
||||||
package tui
|
package tui
|
||||||
|
|
||||||
type Attr int
|
type Attr int32
|
||||||
|
|
||||||
func HasFullscreenRenderer() bool {
|
func HasFullscreenRenderer() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var DefaultBorderShape = BorderRounded
|
||||||
|
|
||||||
func (a Attr) Merge(b Attr) Attr {
|
func (a Attr) Merge(b Attr) Attr {
|
||||||
return a | b
|
return a | b
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AttrRegular Attr = Attr(0)
|
AttrUndefined = Attr(0)
|
||||||
|
AttrRegular = Attr(1 << 8)
|
||||||
|
AttrClear = Attr(1 << 9)
|
||||||
|
|
||||||
Bold = Attr(1)
|
Bold = Attr(1)
|
||||||
Dim = Attr(1 << 1)
|
Dim = Attr(1 << 1)
|
||||||
Italic = Attr(1 << 2)
|
Italic = Attr(1 << 2)
|
||||||
@@ -23,22 +26,28 @@ const (
|
|||||||
Blink = Attr(1 << 4)
|
Blink = Attr(1 << 4)
|
||||||
Blink2 = Attr(1 << 5)
|
Blink2 = Attr(1 << 5)
|
||||||
Reverse = Attr(1 << 6)
|
Reverse = Attr(1 << 6)
|
||||||
|
StrikeThrough = Attr(1 << 7)
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Init() {}
|
func (r *FullscreenRenderer) Init() error { return nil }
|
||||||
|
func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}
|
||||||
func (r *FullscreenRenderer) Pause(bool) {}
|
func (r *FullscreenRenderer) Pause(bool) {}
|
||||||
func (r *FullscreenRenderer) Resume(bool) {}
|
func (r *FullscreenRenderer) Resume(bool, bool) {}
|
||||||
|
func (r *FullscreenRenderer) PassThrough(string) {}
|
||||||
func (r *FullscreenRenderer) Clear() {}
|
func (r *FullscreenRenderer) Clear() {}
|
||||||
|
func (r *FullscreenRenderer) NeedScrollbarRedraw() bool { return false }
|
||||||
|
func (r *FullscreenRenderer) ShouldEmitResizeEvent() bool { return false }
|
||||||
func (r *FullscreenRenderer) Refresh() {}
|
func (r *FullscreenRenderer) Refresh() {}
|
||||||
func (r *FullscreenRenderer) Close() {}
|
func (r *FullscreenRenderer) Close() {}
|
||||||
|
func (r *FullscreenRenderer) Size() TermSize { return TermSize{} }
|
||||||
|
|
||||||
func (r *FullscreenRenderer) DoesAutoWrap() bool { return false }
|
|
||||||
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
||||||
|
func (r *FullscreenRenderer) Top() int { return 0 }
|
||||||
func (r *FullscreenRenderer) MaxX() int { return 0 }
|
func (r *FullscreenRenderer) MaxX() int { return 0 }
|
||||||
func (r *FullscreenRenderer) MaxY() int { return 0 }
|
func (r *FullscreenRenderer) MaxY() int { return 0 }
|
||||||
|
|
||||||
func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}
|
func (r *FullscreenRenderer) RefreshWindows(windows []Window) {}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
|
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
122
src/tui/eventtype_string.go
Normal file
122
src/tui/eventtype_string.go
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
// Code generated by "stringer -type=EventType"; DO NOT EDIT.
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import "strconv"
|
||||||
|
|
||||||
|
func _() {
|
||||||
|
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||||
|
// Re-run the stringer command to generate them again.
|
||||||
|
var x [1]struct{}
|
||||||
|
_ = x[Rune-0]
|
||||||
|
_ = x[CtrlA-1]
|
||||||
|
_ = x[CtrlB-2]
|
||||||
|
_ = x[CtrlC-3]
|
||||||
|
_ = x[CtrlD-4]
|
||||||
|
_ = x[CtrlE-5]
|
||||||
|
_ = x[CtrlF-6]
|
||||||
|
_ = x[CtrlG-7]
|
||||||
|
_ = x[CtrlH-8]
|
||||||
|
_ = x[Tab-9]
|
||||||
|
_ = x[CtrlJ-10]
|
||||||
|
_ = x[CtrlK-11]
|
||||||
|
_ = x[CtrlL-12]
|
||||||
|
_ = x[CtrlM-13]
|
||||||
|
_ = x[CtrlN-14]
|
||||||
|
_ = x[CtrlO-15]
|
||||||
|
_ = x[CtrlP-16]
|
||||||
|
_ = x[CtrlQ-17]
|
||||||
|
_ = x[CtrlR-18]
|
||||||
|
_ = x[CtrlS-19]
|
||||||
|
_ = x[CtrlT-20]
|
||||||
|
_ = x[CtrlU-21]
|
||||||
|
_ = x[CtrlV-22]
|
||||||
|
_ = x[CtrlW-23]
|
||||||
|
_ = x[CtrlX-24]
|
||||||
|
_ = x[CtrlY-25]
|
||||||
|
_ = x[CtrlZ-26]
|
||||||
|
_ = x[Esc-27]
|
||||||
|
_ = x[CtrlSpace-28]
|
||||||
|
_ = x[CtrlDelete-29]
|
||||||
|
_ = x[CtrlBackSlash-30]
|
||||||
|
_ = x[CtrlRightBracket-31]
|
||||||
|
_ = x[CtrlCaret-32]
|
||||||
|
_ = x[CtrlSlash-33]
|
||||||
|
_ = x[ShiftTab-34]
|
||||||
|
_ = x[Backspace-35]
|
||||||
|
_ = x[Delete-36]
|
||||||
|
_ = x[PageUp-37]
|
||||||
|
_ = x[PageDown-38]
|
||||||
|
_ = x[Up-39]
|
||||||
|
_ = x[Down-40]
|
||||||
|
_ = x[Left-41]
|
||||||
|
_ = x[Right-42]
|
||||||
|
_ = x[Home-43]
|
||||||
|
_ = x[End-44]
|
||||||
|
_ = x[Insert-45]
|
||||||
|
_ = x[ShiftUp-46]
|
||||||
|
_ = x[ShiftDown-47]
|
||||||
|
_ = x[ShiftLeft-48]
|
||||||
|
_ = x[ShiftRight-49]
|
||||||
|
_ = x[ShiftDelete-50]
|
||||||
|
_ = x[F1-51]
|
||||||
|
_ = x[F2-52]
|
||||||
|
_ = x[F3-53]
|
||||||
|
_ = x[F4-54]
|
||||||
|
_ = x[F5-55]
|
||||||
|
_ = x[F6-56]
|
||||||
|
_ = x[F7-57]
|
||||||
|
_ = x[F8-58]
|
||||||
|
_ = x[F9-59]
|
||||||
|
_ = x[F10-60]
|
||||||
|
_ = x[F11-61]
|
||||||
|
_ = x[F12-62]
|
||||||
|
_ = x[AltBackspace-63]
|
||||||
|
_ = x[AltUp-64]
|
||||||
|
_ = x[AltDown-65]
|
||||||
|
_ = x[AltLeft-66]
|
||||||
|
_ = x[AltRight-67]
|
||||||
|
_ = x[AltShiftUp-68]
|
||||||
|
_ = x[AltShiftDown-69]
|
||||||
|
_ = x[AltShiftLeft-70]
|
||||||
|
_ = x[AltShiftRight-71]
|
||||||
|
_ = x[Alt-72]
|
||||||
|
_ = x[CtrlAlt-73]
|
||||||
|
_ = x[Invalid-74]
|
||||||
|
_ = x[Fatal-75]
|
||||||
|
_ = x[Mouse-76]
|
||||||
|
_ = x[DoubleClick-77]
|
||||||
|
_ = x[LeftClick-78]
|
||||||
|
_ = x[RightClick-79]
|
||||||
|
_ = x[SLeftClick-80]
|
||||||
|
_ = x[SRightClick-81]
|
||||||
|
_ = x[ScrollUp-82]
|
||||||
|
_ = x[ScrollDown-83]
|
||||||
|
_ = x[SScrollUp-84]
|
||||||
|
_ = x[SScrollDown-85]
|
||||||
|
_ = x[PreviewScrollUp-86]
|
||||||
|
_ = x[PreviewScrollDown-87]
|
||||||
|
_ = x[Resize-88]
|
||||||
|
_ = x[Change-89]
|
||||||
|
_ = x[BackwardEOF-90]
|
||||||
|
_ = x[Start-91]
|
||||||
|
_ = x[Load-92]
|
||||||
|
_ = x[Focus-93]
|
||||||
|
_ = x[One-94]
|
||||||
|
_ = x[Zero-95]
|
||||||
|
_ = x[Result-96]
|
||||||
|
_ = x[Jump-97]
|
||||||
|
_ = x[JumpCancel-98]
|
||||||
|
_ = x[ClickHeader-99]
|
||||||
|
}
|
||||||
|
|
||||||
|
const _EventType_name = "RuneCtrlACtrlBCtrlCCtrlDCtrlECtrlFCtrlGCtrlHTabCtrlJCtrlKCtrlLCtrlMCtrlNCtrlOCtrlPCtrlQCtrlRCtrlSCtrlTCtrlUCtrlVCtrlWCtrlXCtrlYCtrlZEscCtrlSpaceCtrlDeleteCtrlBackSlashCtrlRightBracketCtrlCaretCtrlSlashShiftTabBackspaceDeletePageUpPageDownUpDownLeftRightHomeEndInsertShiftUpShiftDownShiftLeftShiftRightShiftDeleteF1F2F3F4F5F6F7F8F9F10F11F12AltBackspaceAltUpAltDownAltLeftAltRightAltShiftUpAltShiftDownAltShiftLeftAltShiftRightAltCtrlAltInvalidFatalMouseDoubleClickLeftClickRightClickSLeftClickSRightClickScrollUpScrollDownSScrollUpSScrollDownPreviewScrollUpPreviewScrollDownResizeChangeBackwardEOFStartLoadFocusOneZeroResultJumpJumpCancelClickHeader"
|
||||||
|
|
||||||
|
var _EventType_index = [...]uint16{0, 4, 9, 14, 19, 24, 29, 34, 39, 44, 47, 52, 57, 62, 67, 72, 77, 82, 87, 92, 97, 102, 107, 112, 117, 122, 127, 132, 135, 144, 154, 167, 183, 192, 201, 209, 218, 224, 230, 238, 240, 244, 248, 253, 257, 260, 266, 273, 282, 291, 301, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 333, 336, 339, 351, 356, 363, 370, 378, 388, 400, 412, 425, 428, 435, 442, 447, 452, 463, 472, 482, 492, 503, 511, 521, 530, 541, 556, 573, 579, 585, 596, 601, 605, 610, 613, 617, 623, 627, 637, 648}
|
||||||
|
|
||||||
|
func (i EventType) String() string {
|
||||||
|
if i < 0 || i >= EventType(len(_EventType_index)-1) {
|
||||||
|
return "EventType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||||
|
}
|
||||||
|
return _EventType_name[_EventType_index[i]:_EventType_index[i+1]]
|
||||||
|
}
|
||||||
841
src/tui/light.go
841
src/tui/light.go
File diff suppressed because it is too large
Load Diff
125
src/tui/light_unix.go
Normal file
125
src/tui/light_unix.go
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
|
"golang.org/x/term"
|
||||||
|
)
|
||||||
|
|
||||||
|
func IsLightRendererSupported() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) defaultTheme() *ColorTheme {
|
||||||
|
if strings.Contains(os.Getenv("TERM"), "256") {
|
||||||
|
return Dark256
|
||||||
|
}
|
||||||
|
colors, err := exec.Command("tput", "colors").Output()
|
||||||
|
if err == nil && atoi(strings.TrimSpace(string(colors)), 16) > 16 {
|
||||||
|
return Dark256
|
||||||
|
}
|
||||||
|
return Default16
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) fd() int {
|
||||||
|
return int(r.ttyin.Fd())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) initPlatform() (err error) {
|
||||||
|
r.origState, err = term.MakeRaw(r.fd())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) closePlatform() {
|
||||||
|
r.ttyout.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
func openTty(mode int) (*os.File, error) {
|
||||||
|
in, err := os.OpenFile(consoleDevice, mode, 0)
|
||||||
|
if err != nil {
|
||||||
|
tty := ttyname()
|
||||||
|
if len(tty) > 0 {
|
||||||
|
if in, err := os.OpenFile(tty, mode, 0); err == nil {
|
||||||
|
return in, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, errors.New("failed to open " + consoleDevice)
|
||||||
|
}
|
||||||
|
return in, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openTtyIn() (*os.File, error) {
|
||||||
|
return openTty(syscall.O_RDONLY)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openTtyOut() (*os.File, error) {
|
||||||
|
return openTty(syscall.O_WRONLY)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) setupTerminal() {
|
||||||
|
term.MakeRaw(r.fd())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) restoreTerminal() {
|
||||||
|
term.Restore(r.fd(), r.origState)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) updateTerminalSize() {
|
||||||
|
width, height, err := term.GetSize(r.fd())
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
r.width = width
|
||||||
|
r.height = r.maxHeightFunc(height)
|
||||||
|
} else {
|
||||||
|
r.width = getEnv("COLUMNS", defaultWidth)
|
||||||
|
r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) findOffset() (row int, col int) {
|
||||||
|
r.csi("6n")
|
||||||
|
r.flush()
|
||||||
|
var err error
|
||||||
|
bytes := []byte{}
|
||||||
|
for tries := 0; tries < offsetPollTries; tries++ {
|
||||||
|
bytes, err = r.getBytesInternal(bytes, tries > 0)
|
||||||
|
if err != nil {
|
||||||
|
return -1, -1
|
||||||
|
}
|
||||||
|
|
||||||
|
offsets := offsetRegexp.FindSubmatch(bytes)
|
||||||
|
if len(offsets) > 3 {
|
||||||
|
// Add anything we skipped over to the input buffer
|
||||||
|
r.buffer = append(r.buffer, offsets[1]...)
|
||||||
|
return atoi(string(offsets[2]), 0) - 1, atoi(string(offsets[3]), 0) - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1, -1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) getch(nonblock bool) (int, bool) {
|
||||||
|
b := make([]byte, 1)
|
||||||
|
fd := r.fd()
|
||||||
|
util.SetNonblock(r.ttyin, nonblock)
|
||||||
|
_, err := util.Read(fd, b)
|
||||||
|
if err != nil {
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
return int(b[0]), true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) Size() TermSize {
|
||||||
|
ws, err := unix.IoctlGetWinsize(int(r.ttyin.Fd()), unix.TIOCGWINSZ)
|
||||||
|
if err != nil {
|
||||||
|
return TermSize{}
|
||||||
|
}
|
||||||
|
return TermSize{int(ws.Row), int(ws.Col), int(ws.Xpixel), int(ws.Ypixel)}
|
||||||
|
}
|
||||||
157
src/tui/light_windows.go
Normal file
157
src/tui/light_windows.go
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
timeoutInterval = 10
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
consoleFlagsInput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_EXTENDED_FLAGS)
|
||||||
|
consoleFlagsOutput = uint32(windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING | windows.ENABLE_PROCESSED_OUTPUT | windows.DISABLE_NEWLINE_AUTO_RETURN)
|
||||||
|
)
|
||||||
|
|
||||||
|
// IsLightRendererSupported checks to see if the Light renderer is supported
|
||||||
|
func IsLightRendererSupported() bool {
|
||||||
|
var oldState uint32
|
||||||
|
// enable vt100 emulation (https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences)
|
||||||
|
if windows.GetConsoleMode(windows.Stderr, &oldState) != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
// attempt to set mode to determine if we support VT 100 codes. This will work on newer Windows 10
|
||||||
|
// version:
|
||||||
|
canSetVt100 := windows.SetConsoleMode(windows.Stderr, oldState|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) == nil
|
||||||
|
var checkState uint32
|
||||||
|
if windows.GetConsoleMode(windows.Stderr, &checkState) != nil ||
|
||||||
|
(checkState&windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) != windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
windows.SetConsoleMode(windows.Stderr, oldState)
|
||||||
|
return canSetVt100
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) defaultTheme() *ColorTheme {
|
||||||
|
// the getenv check is borrowed from here: https://github.com/gdamore/tcell/commit/0c473b86d82f68226a142e96cc5a34c5a29b3690#diff-b008fcd5e6934bf31bc3d33bf49f47d8R178:
|
||||||
|
if !IsLightRendererSupported() || os.Getenv("ConEmuPID") != "" || os.Getenv("TCELL_TRUECOLOR") == "disable" {
|
||||||
|
return Default16
|
||||||
|
}
|
||||||
|
return Dark256
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) initPlatform() error {
|
||||||
|
//outHandle := windows.Stdout
|
||||||
|
outHandle, _ := syscall.Open("CONOUT$", syscall.O_RDWR, 0)
|
||||||
|
// enable vt100 emulation (https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences)
|
||||||
|
if err := windows.GetConsoleMode(windows.Handle(outHandle), &r.origStateOutput); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.outHandle = uintptr(outHandle)
|
||||||
|
inHandle, _ := syscall.Open("CONIN$", syscall.O_RDWR, 0)
|
||||||
|
if err := windows.GetConsoleMode(windows.Handle(inHandle), &r.origStateInput); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
r.inHandle = uintptr(inHandle)
|
||||||
|
|
||||||
|
r.setupTerminal()
|
||||||
|
|
||||||
|
// channel for non-blocking reads. Buffer to make sure
|
||||||
|
// we get the ESC sets:
|
||||||
|
r.ttyinChannel = make(chan byte, 1024)
|
||||||
|
|
||||||
|
// the following allows for non-blocking IO.
|
||||||
|
// syscall.SetNonblock() is a NOOP under Windows.
|
||||||
|
go func() {
|
||||||
|
fd := int(r.inHandle)
|
||||||
|
b := make([]byte, 1)
|
||||||
|
for !r.closed.Get() {
|
||||||
|
// HACK: if run from PSReadline, something resets ConsoleMode to remove ENABLE_VIRTUAL_TERMINAL_INPUT.
|
||||||
|
_ = windows.SetConsoleMode(windows.Handle(r.inHandle), consoleFlagsInput)
|
||||||
|
|
||||||
|
_, err := util.Read(fd, b)
|
||||||
|
if err == nil {
|
||||||
|
r.ttyinChannel <- b[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) closePlatform() {
|
||||||
|
windows.SetConsoleMode(windows.Handle(r.outHandle), r.origStateOutput)
|
||||||
|
windows.SetConsoleMode(windows.Handle(r.inHandle), r.origStateInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openTtyIn() (*os.File, error) {
|
||||||
|
// not used
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func openTtyOut() (*os.File, error) {
|
||||||
|
return os.Stderr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) setupTerminal() error {
|
||||||
|
if err := windows.SetConsoleMode(windows.Handle(r.outHandle), consoleFlagsOutput); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return windows.SetConsoleMode(windows.Handle(r.inHandle), consoleFlagsInput)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) restoreTerminal() error {
|
||||||
|
if err := windows.SetConsoleMode(windows.Handle(r.inHandle), r.origStateInput); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return windows.SetConsoleMode(windows.Handle(r.outHandle), r.origStateOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) Size() TermSize {
|
||||||
|
var w, h int
|
||||||
|
var bufferInfo windows.ConsoleScreenBufferInfo
|
||||||
|
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(r.outHandle), &bufferInfo); err != nil {
|
||||||
|
w = getEnv("COLUMNS", defaultWidth)
|
||||||
|
h = r.maxHeightFunc(getEnv("LINES", defaultHeight))
|
||||||
|
|
||||||
|
} else {
|
||||||
|
w = int(bufferInfo.Window.Right - bufferInfo.Window.Left)
|
||||||
|
h = r.maxHeightFunc(int(bufferInfo.Window.Bottom - bufferInfo.Window.Top))
|
||||||
|
}
|
||||||
|
return TermSize{h, w, 0, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) updateTerminalSize() {
|
||||||
|
size := r.Size()
|
||||||
|
r.width = size.Columns
|
||||||
|
r.height = size.Lines
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) findOffset() (row int, col int) {
|
||||||
|
var bufferInfo windows.ConsoleScreenBufferInfo
|
||||||
|
if err := windows.GetConsoleScreenBufferInfo(windows.Handle(r.outHandle), &bufferInfo); err != nil {
|
||||||
|
return -1, -1
|
||||||
|
}
|
||||||
|
return int(bufferInfo.CursorPosition.Y), int(bufferInfo.CursorPosition.X)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *LightRenderer) getch(nonblock bool) (int, bool) {
|
||||||
|
if nonblock {
|
||||||
|
select {
|
||||||
|
case bc := <-r.ttyinChannel:
|
||||||
|
return int(bc), true
|
||||||
|
case <-time.After(timeoutInterval * time.Millisecond):
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bc := <-r.ttyinChannel
|
||||||
|
return int(bc), true
|
||||||
|
}
|
||||||
|
}
|
||||||
615
src/tui/tcell.go
615
src/tui/tcell.go
@@ -1,41 +1,57 @@
|
|||||||
// +build tcell windows
|
//go:build tcell || windows
|
||||||
|
|
||||||
package tui
|
package tui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
|
||||||
|
|
||||||
"runtime"
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
|
||||||
"github.com/gdamore/tcell"
|
"github.com/rivo/uniseg"
|
||||||
"github.com/gdamore/tcell/encoding"
|
|
||||||
|
|
||||||
"github.com/mattn/go-runewidth"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func HasFullscreenRenderer() bool {
|
func HasFullscreenRenderer() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ColorPair) style() tcell.Style {
|
var DefaultBorderShape BorderShape = BorderSharp
|
||||||
style := tcell.StyleDefault
|
|
||||||
return style.Foreground(tcell.Color(p.Fg())).Background(tcell.Color(p.Bg()))
|
func asTcellColor(color Color) tcell.Color {
|
||||||
|
if color == colDefault {
|
||||||
|
return tcell.ColorDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
type Attr tcell.Style
|
value := uint64(tcell.ColorValid) + uint64(color)
|
||||||
|
if color.is24() {
|
||||||
|
value = value | uint64(tcell.ColorIsRGB)
|
||||||
|
}
|
||||||
|
return tcell.Color(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) style() tcell.Style {
|
||||||
|
style := tcell.StyleDefault
|
||||||
|
return style.Foreground(asTcellColor(p.Fg())).Background(asTcellColor(p.Bg()))
|
||||||
|
}
|
||||||
|
|
||||||
|
type Attr int32
|
||||||
|
|
||||||
type TcellWindow struct {
|
type TcellWindow struct {
|
||||||
color bool
|
color bool
|
||||||
|
preview bool
|
||||||
top int
|
top int
|
||||||
left int
|
left int
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
normal ColorPair
|
||||||
lastX int
|
lastX int
|
||||||
lastY int
|
lastY int
|
||||||
moveCursor bool
|
moveCursor bool
|
||||||
borderStyle BorderStyle
|
borderStyle BorderStyle
|
||||||
|
uri *string
|
||||||
|
params *string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Top() int {
|
func (w *TcellWindow) Top() int {
|
||||||
@@ -61,12 +77,6 @@ func (w *TcellWindow) Refresh() {
|
|||||||
}
|
}
|
||||||
w.lastX = 0
|
w.lastX = 0
|
||||||
w.lastY = 0
|
w.lastY = 0
|
||||||
switch w.borderStyle {
|
|
||||||
case BorderAround:
|
|
||||||
w.drawBorder(true)
|
|
||||||
case BorderHorizontal:
|
|
||||||
w.drawBorder(false)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) FinishFill() {
|
func (w *TcellWindow) FinishFill() {
|
||||||
@@ -79,13 +89,23 @@ const (
|
|||||||
Blink = Attr(tcell.AttrBlink)
|
Blink = Attr(tcell.AttrBlink)
|
||||||
Reverse = Attr(tcell.AttrReverse)
|
Reverse = Attr(tcell.AttrReverse)
|
||||||
Underline = Attr(tcell.AttrUnderline)
|
Underline = Attr(tcell.AttrUnderline)
|
||||||
Italic = Attr(tcell.AttrNone) // Not supported
|
StrikeThrough = Attr(tcell.AttrStrikeThrough)
|
||||||
|
Italic = Attr(tcell.AttrItalic)
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AttrRegular Attr = 0
|
AttrUndefined = Attr(0)
|
||||||
|
AttrRegular = Attr(1 << 7)
|
||||||
|
AttrClear = Attr(1 << 8)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) PassThrough(str string) {
|
||||||
|
// No-op
|
||||||
|
// https://github.com/gdamore/tcell/pull/650#issuecomment-1806442846
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) Resize(maxHeightFunc func(int) int) {}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) defaultTheme() *ColorTheme {
|
func (r *FullscreenRenderer) defaultTheme() *ColorTheme {
|
||||||
if _screen.Colors() >= 256 {
|
if _screen.Colors() >= 256 {
|
||||||
return Dark256
|
return Dark256
|
||||||
@@ -120,17 +140,21 @@ func (a Attr) Merge(b Attr) Attr {
|
|||||||
return a | b
|
return a | b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle the following as private members of FullscreenRenderer instance
|
||||||
|
// they are declared here to prevent introducing tcell library in non-windows builds
|
||||||
var (
|
var (
|
||||||
_screen tcell.Screen
|
_screen tcell.Screen
|
||||||
|
_prevMouseButton tcell.ButtonMask
|
||||||
|
_initialResize bool = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *FullscreenRenderer) initScreen() {
|
func (r *FullscreenRenderer) initScreen() error {
|
||||||
s, e := tcell.NewScreen()
|
s, e := tcell.NewScreen()
|
||||||
if e != nil {
|
if e != nil {
|
||||||
errorExit(e.Error())
|
return e
|
||||||
}
|
}
|
||||||
if e = s.Init(); e != nil {
|
if e = s.Init(); e != nil {
|
||||||
errorExit(e.Error())
|
return e
|
||||||
}
|
}
|
||||||
if r.mouse {
|
if r.mouse {
|
||||||
s.EnableMouse()
|
s.EnableMouse()
|
||||||
@@ -138,16 +162,25 @@ func (r *FullscreenRenderer) initScreen() {
|
|||||||
s.DisableMouse()
|
s.DisableMouse()
|
||||||
}
|
}
|
||||||
_screen = s
|
_screen = s
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Init() {
|
func (r *FullscreenRenderer) Init() error {
|
||||||
if os.Getenv("TERM") == "cygwin" {
|
if os.Getenv("TERM") == "cygwin" {
|
||||||
os.Setenv("TERM", "")
|
os.Setenv("TERM", "")
|
||||||
}
|
}
|
||||||
encoding.Register()
|
|
||||||
|
|
||||||
r.initScreen()
|
if err := r.initScreen(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
initTheme(r.theme, r.defaultTheme(), r.forceBlack)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) Top() int {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) MaxX() int {
|
func (r *FullscreenRenderer) MaxX() int {
|
||||||
@@ -168,152 +201,265 @@ func (w *TcellWindow) Y() int {
|
|||||||
return w.lastY
|
return w.lastY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) DoesAutoWrap() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Clear() {
|
func (r *FullscreenRenderer) Clear() {
|
||||||
_screen.Sync()
|
_screen.Sync()
|
||||||
_screen.Clear()
|
_screen.Clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) NeedScrollbarRedraw() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *FullscreenRenderer) ShouldEmitResizeEvent() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Refresh() {
|
func (r *FullscreenRenderer) Refresh() {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Pixel width and height not implemented
|
||||||
|
func (r *FullscreenRenderer) Size() TermSize {
|
||||||
|
cols, lines := _screen.Size()
|
||||||
|
return TermSize{lines, cols, 0, 0}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) GetChar() Event {
|
func (r *FullscreenRenderer) GetChar() Event {
|
||||||
ev := _screen.PollEvent()
|
ev := _screen.PollEvent()
|
||||||
switch ev := ev.(type) {
|
switch ev := ev.(type) {
|
||||||
case *tcell.EventResize:
|
case *tcell.EventResize:
|
||||||
|
// Ignore the first resize event
|
||||||
|
// https://github.com/gdamore/tcell/blob/v2.7.0/TUTORIAL.md?plain=1#L18
|
||||||
|
if _initialResize {
|
||||||
|
_initialResize = false
|
||||||
|
return Event{Invalid, 0, nil}
|
||||||
|
}
|
||||||
return Event{Resize, 0, nil}
|
return Event{Resize, 0, nil}
|
||||||
|
|
||||||
// process mouse events:
|
// process mouse events:
|
||||||
case *tcell.EventMouse:
|
case *tcell.EventMouse:
|
||||||
|
// mouse down events have zeroed buttons, so we can't use them
|
||||||
|
// mouse up event consists of two events, 1. (main) event with modifier and other metadata, 2. event with zeroed buttons
|
||||||
|
// so mouse click is three consecutive events, but the first and last are indistinguishable from movement events (with released buttons)
|
||||||
|
// dragging has same structure, it only repeats the middle (main) event appropriately
|
||||||
x, y := ev.Position()
|
x, y := ev.Position()
|
||||||
button := ev.Buttons()
|
|
||||||
mod := ev.Modifiers() != 0
|
mod := ev.Modifiers() != 0
|
||||||
if button&tcell.WheelDown != 0 {
|
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, mod}}
|
// since we dont have mouse down events (unlike LightRenderer), we need to track state in prevButton
|
||||||
} else if button&tcell.WheelUp != 0 {
|
prevButton, button := _prevMouseButton, ev.Buttons()
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, mod}}
|
_prevMouseButton = button
|
||||||
} else if runtime.GOOS != "windows" {
|
drag := prevButton == button
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case button&tcell.WheelDown != 0:
|
||||||
|
return Event{Mouse, 0, &MouseEvent{y, x, -1, false, false, false, mod}}
|
||||||
|
case button&tcell.WheelUp != 0:
|
||||||
|
return Event{Mouse, 0, &MouseEvent{y, x, +1, false, false, false, mod}}
|
||||||
|
case button&tcell.Button1 != 0:
|
||||||
|
double := false
|
||||||
|
if !drag {
|
||||||
|
// all potential double click events put their coordinates in the clicks array
|
||||||
|
// double click event has two conditions, temporal and spatial, the first is checked here
|
||||||
|
now := time.Now()
|
||||||
|
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
||||||
|
r.clicks = append(r.clicks, [2]int{x, y})
|
||||||
|
} else {
|
||||||
|
r.clicks = [][2]int{{x, y}}
|
||||||
|
}
|
||||||
|
r.prevDownTime = now
|
||||||
|
|
||||||
|
// detect double clicks (also check for spatial condition)
|
||||||
|
n := len(r.clicks)
|
||||||
|
double = n > 1 && r.clicks[n-2][0] == r.clicks[n-1][0] && r.clicks[n-2][1] == r.clicks[n-1][1]
|
||||||
|
if double {
|
||||||
|
// make sure two consecutive double clicks require four clicks
|
||||||
|
r.clicks = [][2]int{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// fire single or double click event
|
||||||
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, true, !double, double, mod}}
|
||||||
|
case button&tcell.Button2 != 0:
|
||||||
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, false, true, false, mod}}
|
||||||
|
default:
|
||||||
// double and single taps on Windows don't quite work due to
|
// double and single taps on Windows don't quite work due to
|
||||||
// the console acting on the events and not allowing us
|
// the console acting on the events and not allowing us
|
||||||
// to consume them.
|
// to consume them.
|
||||||
|
left := button&tcell.Button1 != 0
|
||||||
down := button&tcell.Button1 != 0 // left
|
down := left || button&tcell.Button3 != 0
|
||||||
double := false
|
double := false
|
||||||
if down {
|
|
||||||
now := time.Now()
|
|
||||||
if now.Sub(r.prevDownTime) < doubleClickDuration {
|
|
||||||
r.clickY = append(r.clickY, x)
|
|
||||||
} else {
|
|
||||||
r.clickY = []int{x}
|
|
||||||
r.prevDownTime = now
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if len(r.clickY) > 1 && r.clickY[0] == r.clickY[1] &&
|
|
||||||
time.Now().Sub(r.prevDownTime) < doubleClickDuration {
|
|
||||||
double = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Event{Mouse, 0, &MouseEvent{y, x, 0, down, double, mod}}
|
return Event{Mouse, 0, &MouseEvent{y, x, 0, left, down, double, mod}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// process keyboard:
|
// process keyboard:
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
alt := (ev.Modifiers() & tcell.ModAlt) > 0
|
mods := ev.Modifiers()
|
||||||
keyfn := func(r rune) int {
|
none := mods == tcell.ModNone
|
||||||
|
alt := (mods & tcell.ModAlt) > 0
|
||||||
|
ctrl := (mods & tcell.ModCtrl) > 0
|
||||||
|
shift := (mods & tcell.ModShift) > 0
|
||||||
|
ctrlAlt := ctrl && alt
|
||||||
|
altShift := alt && shift
|
||||||
|
|
||||||
|
keyfn := func(r rune) Event {
|
||||||
if alt {
|
if alt {
|
||||||
return CtrlAltA - 'a' + int(r)
|
return CtrlAltKey(r)
|
||||||
}
|
}
|
||||||
return CtrlA - 'a' + int(r)
|
return EventType(CtrlA.Int() - 'a' + int(r)).AsEvent()
|
||||||
}
|
}
|
||||||
switch ev.Key() {
|
switch ev.Key() {
|
||||||
|
// section 1: Ctrl+(Alt)+[a-z]
|
||||||
case tcell.KeyCtrlA:
|
case tcell.KeyCtrlA:
|
||||||
return Event{keyfn('a'), 0, nil}
|
return keyfn('a')
|
||||||
case tcell.KeyCtrlB:
|
case tcell.KeyCtrlB:
|
||||||
return Event{keyfn('b'), 0, nil}
|
return keyfn('b')
|
||||||
case tcell.KeyCtrlC:
|
case tcell.KeyCtrlC:
|
||||||
return Event{keyfn('c'), 0, nil}
|
return keyfn('c')
|
||||||
case tcell.KeyCtrlD:
|
case tcell.KeyCtrlD:
|
||||||
return Event{keyfn('d'), 0, nil}
|
return keyfn('d')
|
||||||
case tcell.KeyCtrlE:
|
case tcell.KeyCtrlE:
|
||||||
return Event{keyfn('e'), 0, nil}
|
return keyfn('e')
|
||||||
case tcell.KeyCtrlF:
|
case tcell.KeyCtrlF:
|
||||||
return Event{keyfn('f'), 0, nil}
|
return keyfn('f')
|
||||||
case tcell.KeyCtrlG:
|
case tcell.KeyCtrlG:
|
||||||
return Event{keyfn('g'), 0, nil}
|
return keyfn('g')
|
||||||
case tcell.KeyCtrlH:
|
case tcell.KeyCtrlH:
|
||||||
return Event{keyfn('h'), 0, nil}
|
switch ev.Rune() {
|
||||||
|
case 0:
|
||||||
|
if ctrl {
|
||||||
|
return Event{Backspace, 0, nil}
|
||||||
|
}
|
||||||
|
case rune(tcell.KeyCtrlH):
|
||||||
|
switch {
|
||||||
|
case ctrl:
|
||||||
|
return keyfn('h')
|
||||||
|
case alt:
|
||||||
|
return Event{AltBackspace, 0, nil}
|
||||||
|
case none, shift:
|
||||||
|
return Event{Backspace, 0, nil}
|
||||||
|
}
|
||||||
|
}
|
||||||
case tcell.KeyCtrlI:
|
case tcell.KeyCtrlI:
|
||||||
return Event{keyfn('i'), 0, nil}
|
return keyfn('i')
|
||||||
case tcell.KeyCtrlJ:
|
case tcell.KeyCtrlJ:
|
||||||
return Event{keyfn('j'), 0, nil}
|
return keyfn('j')
|
||||||
case tcell.KeyCtrlK:
|
case tcell.KeyCtrlK:
|
||||||
return Event{keyfn('k'), 0, nil}
|
return keyfn('k')
|
||||||
case tcell.KeyCtrlL:
|
case tcell.KeyCtrlL:
|
||||||
return Event{keyfn('l'), 0, nil}
|
return keyfn('l')
|
||||||
case tcell.KeyCtrlM:
|
case tcell.KeyCtrlM:
|
||||||
return Event{keyfn('m'), 0, nil}
|
return keyfn('m')
|
||||||
case tcell.KeyCtrlN:
|
case tcell.KeyCtrlN:
|
||||||
return Event{keyfn('n'), 0, nil}
|
return keyfn('n')
|
||||||
case tcell.KeyCtrlO:
|
case tcell.KeyCtrlO:
|
||||||
return Event{keyfn('o'), 0, nil}
|
return keyfn('o')
|
||||||
case tcell.KeyCtrlP:
|
case tcell.KeyCtrlP:
|
||||||
return Event{keyfn('p'), 0, nil}
|
return keyfn('p')
|
||||||
case tcell.KeyCtrlQ:
|
case tcell.KeyCtrlQ:
|
||||||
return Event{keyfn('q'), 0, nil}
|
return keyfn('q')
|
||||||
case tcell.KeyCtrlR:
|
case tcell.KeyCtrlR:
|
||||||
return Event{keyfn('r'), 0, nil}
|
return keyfn('r')
|
||||||
case tcell.KeyCtrlS:
|
case tcell.KeyCtrlS:
|
||||||
return Event{keyfn('s'), 0, nil}
|
return keyfn('s')
|
||||||
case tcell.KeyCtrlT:
|
case tcell.KeyCtrlT:
|
||||||
return Event{keyfn('t'), 0, nil}
|
return keyfn('t')
|
||||||
case tcell.KeyCtrlU:
|
case tcell.KeyCtrlU:
|
||||||
return Event{keyfn('u'), 0, nil}
|
return keyfn('u')
|
||||||
case tcell.KeyCtrlV:
|
case tcell.KeyCtrlV:
|
||||||
return Event{keyfn('v'), 0, nil}
|
return keyfn('v')
|
||||||
case tcell.KeyCtrlW:
|
case tcell.KeyCtrlW:
|
||||||
return Event{keyfn('w'), 0, nil}
|
return keyfn('w')
|
||||||
case tcell.KeyCtrlX:
|
case tcell.KeyCtrlX:
|
||||||
return Event{keyfn('x'), 0, nil}
|
return keyfn('x')
|
||||||
case tcell.KeyCtrlY:
|
case tcell.KeyCtrlY:
|
||||||
return Event{keyfn('y'), 0, nil}
|
return keyfn('y')
|
||||||
case tcell.KeyCtrlZ:
|
case tcell.KeyCtrlZ:
|
||||||
return Event{keyfn('z'), 0, nil}
|
return keyfn('z')
|
||||||
|
// section 2: Ctrl+[ \]_]
|
||||||
case tcell.KeyCtrlSpace:
|
case tcell.KeyCtrlSpace:
|
||||||
return Event{CtrlSpace, 0, nil}
|
return Event{CtrlSpace, 0, nil}
|
||||||
|
case tcell.KeyCtrlBackslash:
|
||||||
|
return Event{CtrlBackSlash, 0, nil}
|
||||||
|
case tcell.KeyCtrlRightSq:
|
||||||
|
return Event{CtrlRightBracket, 0, nil}
|
||||||
|
case tcell.KeyCtrlCarat:
|
||||||
|
return Event{CtrlCaret, 0, nil}
|
||||||
|
case tcell.KeyCtrlUnderscore:
|
||||||
|
return Event{CtrlSlash, 0, nil}
|
||||||
|
// section 3: (Alt)+Backspace2
|
||||||
case tcell.KeyBackspace2:
|
case tcell.KeyBackspace2:
|
||||||
if alt {
|
if alt {
|
||||||
return Event{AltBS, 0, nil}
|
return Event{AltBackspace, 0, nil}
|
||||||
}
|
}
|
||||||
return Event{BSpace, 0, nil}
|
return Event{Backspace, 0, nil}
|
||||||
|
|
||||||
|
// section 4: (Alt+Shift)+Key(Up|Down|Left|Right)
|
||||||
case tcell.KeyUp:
|
case tcell.KeyUp:
|
||||||
|
if altShift {
|
||||||
|
return Event{AltShiftUp, 0, nil}
|
||||||
|
}
|
||||||
|
if shift {
|
||||||
|
return Event{ShiftUp, 0, nil}
|
||||||
|
}
|
||||||
|
if alt {
|
||||||
|
return Event{AltUp, 0, nil}
|
||||||
|
}
|
||||||
return Event{Up, 0, nil}
|
return Event{Up, 0, nil}
|
||||||
case tcell.KeyDown:
|
case tcell.KeyDown:
|
||||||
|
if altShift {
|
||||||
|
return Event{AltShiftDown, 0, nil}
|
||||||
|
}
|
||||||
|
if shift {
|
||||||
|
return Event{ShiftDown, 0, nil}
|
||||||
|
}
|
||||||
|
if alt {
|
||||||
|
return Event{AltDown, 0, nil}
|
||||||
|
}
|
||||||
return Event{Down, 0, nil}
|
return Event{Down, 0, nil}
|
||||||
case tcell.KeyLeft:
|
case tcell.KeyLeft:
|
||||||
|
if altShift {
|
||||||
|
return Event{AltShiftLeft, 0, nil}
|
||||||
|
}
|
||||||
|
if shift {
|
||||||
|
return Event{ShiftLeft, 0, nil}
|
||||||
|
}
|
||||||
|
if alt {
|
||||||
|
return Event{AltLeft, 0, nil}
|
||||||
|
}
|
||||||
return Event{Left, 0, nil}
|
return Event{Left, 0, nil}
|
||||||
case tcell.KeyRight:
|
case tcell.KeyRight:
|
||||||
|
if altShift {
|
||||||
|
return Event{AltShiftRight, 0, nil}
|
||||||
|
}
|
||||||
|
if shift {
|
||||||
|
return Event{ShiftRight, 0, nil}
|
||||||
|
}
|
||||||
|
if alt {
|
||||||
|
return Event{AltRight, 0, nil}
|
||||||
|
}
|
||||||
return Event{Right, 0, nil}
|
return Event{Right, 0, nil}
|
||||||
|
|
||||||
|
// section 5: (Insert|Home|Delete|End|PgUp|PgDn|BackTab|F1-F12)
|
||||||
|
case tcell.KeyInsert:
|
||||||
|
return Event{Insert, 0, nil}
|
||||||
case tcell.KeyHome:
|
case tcell.KeyHome:
|
||||||
return Event{Home, 0, nil}
|
return Event{Home, 0, nil}
|
||||||
case tcell.KeyDelete:
|
case tcell.KeyDelete:
|
||||||
return Event{Del, 0, nil}
|
if ctrl {
|
||||||
|
return Event{CtrlDelete, 0, nil}
|
||||||
|
}
|
||||||
|
if shift {
|
||||||
|
return Event{ShiftDelete, 0, nil}
|
||||||
|
}
|
||||||
|
return Event{Delete, 0, nil}
|
||||||
case tcell.KeyEnd:
|
case tcell.KeyEnd:
|
||||||
return Event{End, 0, nil}
|
return Event{End, 0, nil}
|
||||||
case tcell.KeyPgUp:
|
case tcell.KeyPgUp:
|
||||||
return Event{PgUp, 0, nil}
|
return Event{PageUp, 0, nil}
|
||||||
case tcell.KeyPgDn:
|
case tcell.KeyPgDn:
|
||||||
return Event{PgDn, 0, nil}
|
return Event{PageDown, 0, nil}
|
||||||
|
|
||||||
case tcell.KeyBacktab:
|
case tcell.KeyBacktab:
|
||||||
return Event{BTab, 0, nil}
|
return Event{ShiftTab, 0, nil}
|
||||||
|
|
||||||
case tcell.KeyF1:
|
case tcell.KeyF1:
|
||||||
return Event{F1, 0, nil}
|
return Event{F1, 0, nil}
|
||||||
case tcell.KeyF2:
|
case tcell.KeyF2:
|
||||||
@@ -339,41 +485,45 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
case tcell.KeyF12:
|
case tcell.KeyF12:
|
||||||
return Event{F12, 0, nil}
|
return Event{F12, 0, nil}
|
||||||
|
|
||||||
// ev.Ch doesn't work for some reason for space:
|
// section 6: (Ctrl+Alt)+'rune'
|
||||||
case tcell.KeyRune:
|
case tcell.KeyRune:
|
||||||
r := ev.Rune()
|
r := ev.Rune()
|
||||||
if alt {
|
|
||||||
switch r {
|
switch {
|
||||||
case ' ':
|
// translate native key events to ascii control characters
|
||||||
return Event{AltSpace, 0, nil}
|
case r == ' ' && ctrl:
|
||||||
case '/':
|
return Event{CtrlSpace, 0, nil}
|
||||||
return Event{AltSlash, 0, nil}
|
// handle AltGr characters
|
||||||
}
|
case ctrlAlt:
|
||||||
if r >= 'a' && r <= 'z' {
|
return Event{Rune, r, nil} // dropping modifiers
|
||||||
return Event{AltA + int(r) - 'a', 0, nil}
|
// simple characters (possibly with modifier)
|
||||||
}
|
case alt:
|
||||||
if r >= '0' && r <= '9' {
|
return AltKey(r)
|
||||||
return Event{Alt0 + int(r) - '0', 0, nil}
|
default:
|
||||||
}
|
|
||||||
}
|
|
||||||
return Event{Rune, r, nil}
|
return Event{Rune, r, nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
// section 7: Esc
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
return Event{ESC, 0, nil}
|
return Event{Esc, 0, nil}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// section 8: Invalid
|
||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Pause(bool) {
|
func (r *FullscreenRenderer) Pause(clear bool) {
|
||||||
|
if clear {
|
||||||
_screen.Fini()
|
_screen.Fini()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Resume(bool) {
|
func (r *FullscreenRenderer) Resume(clear bool, sigcont bool) {
|
||||||
|
if clear {
|
||||||
r.initScreen()
|
r.initScreen()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Close() {
|
func (r *FullscreenRenderer) Close() {
|
||||||
_screen.Fini()
|
_screen.Fini()
|
||||||
@@ -387,31 +537,48 @@ func (r *FullscreenRenderer) RefreshWindows(windows []Window) {
|
|||||||
_screen.Show()
|
_screen.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window {
|
func (r *FullscreenRenderer) NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window {
|
||||||
// TODO
|
normal := ColNormal
|
||||||
return &TcellWindow{
|
if preview {
|
||||||
color: r.theme != nil,
|
normal = ColPreview
|
||||||
|
}
|
||||||
|
w := &TcellWindow{
|
||||||
|
color: r.theme.Colored,
|
||||||
|
preview: preview,
|
||||||
top: top,
|
top: top,
|
||||||
left: left,
|
left: left,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
|
normal: normal,
|
||||||
borderStyle: borderStyle}
|
borderStyle: borderStyle}
|
||||||
|
w.Erase()
|
||||||
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Close() {
|
func (w *TcellWindow) Close() {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
func fill(x, y, w, h int, r rune) {
|
func fill(x, y, w, h int, n ColorPair, r rune) {
|
||||||
for ly := 0; ly <= h; ly++ {
|
for ly := 0; ly <= h; ly++ {
|
||||||
for lx := 0; lx <= w; lx++ {
|
for lx := 0; lx <= w; lx++ {
|
||||||
_screen.SetContent(x+lx, y+ly, r, nil, ColNormal.style())
|
_screen.SetContent(x+lx, y+ly, r, nil, n.style())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Erase() {
|
func (w *TcellWindow) Erase() {
|
||||||
fill(w.left-1, w.top, w.width+1, w.height, ' ')
|
if w.borderStyle.shape.HasLeft() {
|
||||||
|
fill(w.left-1, w.top, w.width, w.height-1, w.normal, ' ')
|
||||||
|
} else {
|
||||||
|
fill(w.left, w.top, w.width-1, w.height-1, w.normal, ' ')
|
||||||
|
}
|
||||||
|
w.drawBorder(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) EraseMaybe() bool {
|
||||||
|
w.Erase()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Enclose(y int, x int) bool {
|
func (w *TcellWindow) Enclose(y int, x int) bool {
|
||||||
@@ -428,130 +595,176 @@ func (w *TcellWindow) Move(y int, x int) {
|
|||||||
func (w *TcellWindow) MoveAndClear(y int, x int) {
|
func (w *TcellWindow) MoveAndClear(y int, x int) {
|
||||||
w.Move(y, x)
|
w.Move(y, x)
|
||||||
for i := w.lastX; i < w.width; i++ {
|
for i := w.lastX; i < w.width; i++ {
|
||||||
_screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, ColNormal.style())
|
_screen.SetContent(i+w.left, w.lastY+w.top, rune(' '), nil, w.normal.style())
|
||||||
}
|
}
|
||||||
w.lastX = x
|
w.lastX = x
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Print(text string) {
|
func (w *TcellWindow) Print(text string) {
|
||||||
w.printString(text, ColNormal, 0)
|
w.printString(text, w.normal)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) printString(text string, pair ColorPair, a Attr) {
|
func (w *TcellWindow) withUrl(style tcell.Style) tcell.Style {
|
||||||
t := text
|
if w.uri != nil {
|
||||||
|
style = style.Url(*w.uri)
|
||||||
|
if md := regexp.MustCompile(`id=([^:]+)`).FindStringSubmatch(*w.params); len(md) > 1 {
|
||||||
|
style = style.UrlId(md[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return style
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) printString(text string, pair ColorPair) {
|
||||||
lx := 0
|
lx := 0
|
||||||
|
a := pair.Attr()
|
||||||
|
|
||||||
var style tcell.Style
|
style := pair.style()
|
||||||
if w.color {
|
if a&AttrClear == 0 {
|
||||||
style = pair.style().
|
|
||||||
Reverse(a&Attr(tcell.AttrReverse) != 0).
|
|
||||||
Underline(a&Attr(tcell.AttrUnderline) != 0)
|
|
||||||
} else {
|
|
||||||
style = ColNormal.style().
|
|
||||||
Reverse(a&Attr(tcell.AttrReverse) != 0 || pair == ColCurrent || pair == ColCurrentMatch).
|
|
||||||
Underline(a&Attr(tcell.AttrUnderline) != 0 || pair == ColMatch || pair == ColCurrentMatch)
|
|
||||||
}
|
|
||||||
style = style.
|
style = style.
|
||||||
|
Reverse(a&Attr(tcell.AttrReverse) != 0).
|
||||||
|
Underline(a&Attr(tcell.AttrUnderline) != 0).
|
||||||
|
StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).
|
||||||
|
Italic(a&Attr(tcell.AttrItalic) != 0).
|
||||||
Blink(a&Attr(tcell.AttrBlink) != 0).
|
Blink(a&Attr(tcell.AttrBlink) != 0).
|
||||||
Bold(a&Attr(tcell.AttrBold) != 0).
|
|
||||||
Dim(a&Attr(tcell.AttrDim) != 0)
|
Dim(a&Attr(tcell.AttrDim) != 0)
|
||||||
|
|
||||||
for {
|
|
||||||
if len(t) == 0 {
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
r, size := utf8.DecodeRuneInString(t)
|
style = w.withUrl(style)
|
||||||
t = t[size:]
|
|
||||||
|
|
||||||
if r < rune(' ') { // ignore control characters
|
gr := uniseg.NewGraphemes(text)
|
||||||
|
for gr.Next() {
|
||||||
|
st := style
|
||||||
|
rs := gr.Runes()
|
||||||
|
|
||||||
|
if len(rs) == 1 {
|
||||||
|
r := rs[0]
|
||||||
|
if r == '\r' {
|
||||||
|
st = style.Dim(true)
|
||||||
|
rs[0] = '␍'
|
||||||
|
} else if r == '\n' {
|
||||||
|
st = style.Dim(true)
|
||||||
|
rs[0] = '␊'
|
||||||
|
} else if r < rune(' ') { // ignore control characters
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if r == '\n' {
|
|
||||||
w.lastY++
|
|
||||||
lx = 0
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if r == '\u000D' { // skip carriage return
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var xPos = w.left + w.lastX + lx
|
var xPos = w.left + w.lastX + lx
|
||||||
var yPos = w.top + w.lastY
|
var yPos = w.top + w.lastY
|
||||||
if xPos < (w.left+w.width) && yPos < (w.top+w.height) {
|
if xPos < (w.left+w.width) && yPos < (w.top+w.height) {
|
||||||
_screen.SetContent(xPos, yPos, r, nil, style)
|
_screen.SetContent(xPos, yPos, rs[0], rs[1:], st)
|
||||||
}
|
|
||||||
lx += runewidth.RuneWidth(r)
|
|
||||||
}
|
}
|
||||||
|
lx += util.StringWidth(string(rs))
|
||||||
}
|
}
|
||||||
w.lastX += lx
|
w.lastX += lx
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) CPrint(pair ColorPair, attr Attr, text string) {
|
func (w *TcellWindow) CPrint(pair ColorPair, text string) {
|
||||||
w.printString(text, pair, attr)
|
w.printString(text, pair)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) fillString(text string, pair ColorPair, a Attr) FillReturn {
|
func (w *TcellWindow) fillString(text string, pair ColorPair) FillReturn {
|
||||||
lx := 0
|
lx := 0
|
||||||
|
a := pair.Attr()
|
||||||
|
|
||||||
var style tcell.Style
|
var style tcell.Style
|
||||||
if w.color {
|
if w.color {
|
||||||
style = pair.style()
|
style = pair.style()
|
||||||
} else {
|
} else {
|
||||||
style = ColNormal.style()
|
style = w.normal.style()
|
||||||
}
|
}
|
||||||
style = style.
|
style = style.
|
||||||
Blink(a&Attr(tcell.AttrBlink) != 0).
|
Blink(a&Attr(tcell.AttrBlink) != 0).
|
||||||
Bold(a&Attr(tcell.AttrBold) != 0).
|
Bold(a&Attr(tcell.AttrBold) != 0).
|
||||||
Dim(a&Attr(tcell.AttrDim) != 0).
|
Dim(a&Attr(tcell.AttrDim) != 0).
|
||||||
Reverse(a&Attr(tcell.AttrReverse) != 0).
|
Reverse(a&Attr(tcell.AttrReverse) != 0).
|
||||||
Underline(a&Attr(tcell.AttrUnderline) != 0)
|
Underline(a&Attr(tcell.AttrUnderline) != 0).
|
||||||
|
StrikeThrough(a&Attr(tcell.AttrStrikeThrough) != 0).
|
||||||
|
Italic(a&Attr(tcell.AttrItalic) != 0)
|
||||||
|
style = w.withUrl(style)
|
||||||
|
|
||||||
for _, r := range text {
|
gr := uniseg.NewGraphemes(text)
|
||||||
if r == '\n' {
|
Loop:
|
||||||
|
for gr.Next() {
|
||||||
|
st := style
|
||||||
|
rs := gr.Runes()
|
||||||
|
if len(rs) == 1 {
|
||||||
|
r := rs[0]
|
||||||
|
switch r {
|
||||||
|
case '\r':
|
||||||
|
st = style.Dim(true)
|
||||||
|
rs[0] = '␍'
|
||||||
|
case '\n':
|
||||||
w.lastY++
|
w.lastY++
|
||||||
w.lastX = 0
|
w.lastX = 0
|
||||||
lx = 0
|
lx = 0
|
||||||
} else {
|
continue Loop
|
||||||
var xPos = w.left + w.lastX + lx
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// word wrap:
|
// word wrap:
|
||||||
|
xPos := w.left + w.lastX + lx
|
||||||
if xPos >= (w.left + w.width) {
|
if xPos >= (w.left + w.width) {
|
||||||
w.lastY++
|
w.lastY++
|
||||||
w.lastX = 0
|
w.lastX = 0
|
||||||
lx = 0
|
lx = 0
|
||||||
xPos = w.left
|
xPos = w.left
|
||||||
}
|
}
|
||||||
var yPos = w.top + w.lastY
|
|
||||||
|
|
||||||
|
yPos := w.top + w.lastY
|
||||||
if yPos >= (w.top + w.height) {
|
if yPos >= (w.top + w.height) {
|
||||||
return FillSuspend
|
return FillSuspend
|
||||||
}
|
}
|
||||||
|
|
||||||
_screen.SetContent(xPos, yPos, r, nil, style)
|
_screen.SetContent(xPos, yPos, rs[0], rs[1:], st)
|
||||||
lx += runewidth.RuneWidth(r)
|
lx += util.StringWidth(string(rs))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
w.lastX += lx
|
w.lastX += lx
|
||||||
|
if w.lastX == w.width {
|
||||||
|
w.lastY++
|
||||||
|
w.lastX = 0
|
||||||
|
return FillNextLine
|
||||||
|
}
|
||||||
|
|
||||||
return FillContinue
|
return FillContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) Fill(str string) FillReturn {
|
func (w *TcellWindow) Fill(str string) FillReturn {
|
||||||
return w.fillString(str, ColNormal, 0)
|
return w.fillString(str, w.normal)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) LinkBegin(uri string, params string) {
|
||||||
|
w.uri = &uri
|
||||||
|
w.params = ¶ms
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) LinkEnd() {
|
||||||
|
w.uri = nil
|
||||||
|
w.params = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
|
func (w *TcellWindow) CFill(fg Color, bg Color, a Attr, str string) FillReturn {
|
||||||
if fg == colDefault {
|
if fg == colDefault {
|
||||||
fg = ColNormal.Fg()
|
fg = w.normal.Fg()
|
||||||
}
|
}
|
||||||
if bg == colDefault {
|
if bg == colDefault {
|
||||||
bg = ColNormal.Bg()
|
bg = w.normal.Bg()
|
||||||
}
|
}
|
||||||
return w.fillString(str, NewColorPair(fg, bg), a)
|
return w.fillString(str, NewColorPair(fg, bg, a))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) DrawBorder() {
|
||||||
|
w.drawBorder(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) DrawHBorder() {
|
||||||
|
w.drawBorder(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *TcellWindow) drawBorder(onlyHorizontal bool) {
|
||||||
|
shape := w.borderStyle.shape
|
||||||
|
if shape == BorderNone {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *TcellWindow) drawBorder(around bool) {
|
|
||||||
left := w.left
|
left := w.left
|
||||||
right := left + w.width
|
right := left + w.width
|
||||||
top := w.top
|
top := w.top
|
||||||
@@ -559,25 +772,61 @@ func (w *TcellWindow) drawBorder(around bool) {
|
|||||||
|
|
||||||
var style tcell.Style
|
var style tcell.Style
|
||||||
if w.color {
|
if w.color {
|
||||||
style = ColBorder.style()
|
if w.preview {
|
||||||
|
style = ColPreviewBorder.style()
|
||||||
} else {
|
} else {
|
||||||
style = ColNormal.style()
|
style = ColBorder.style()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
style = w.normal.style()
|
||||||
}
|
}
|
||||||
|
|
||||||
for x := left; x < right; x++ {
|
hw := runeWidth(w.borderStyle.top)
|
||||||
_screen.SetContent(x, top, tcell.RuneHLine, nil, style)
|
switch shape {
|
||||||
_screen.SetContent(x, bot-1, tcell.RuneHLine, nil, style)
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderTop:
|
||||||
|
max := right - 2*hw
|
||||||
|
if shape == BorderHorizontal || shape == BorderTop {
|
||||||
|
max = right - hw
|
||||||
}
|
}
|
||||||
|
// tcell has an issue displaying two overlapping wide runes
|
||||||
if around {
|
// e.g. SetContent( HH )
|
||||||
|
// SetContent( TR )
|
||||||
|
// ==================
|
||||||
|
// ( HH ) => TR is ignored
|
||||||
|
for x := left; x <= max; x += hw {
|
||||||
|
_screen.SetContent(x, top, w.borderStyle.top, nil, style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch shape {
|
||||||
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderHorizontal, BorderBottom:
|
||||||
|
max := right - 2*hw
|
||||||
|
if shape == BorderHorizontal || shape == BorderBottom {
|
||||||
|
max = right - hw
|
||||||
|
}
|
||||||
|
for x := left; x <= max; x += hw {
|
||||||
|
_screen.SetContent(x, bot-1, w.borderStyle.bottom, nil, style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !onlyHorizontal {
|
||||||
|
switch shape {
|
||||||
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderLeft:
|
||||||
for y := top; y < bot; y++ {
|
for y := top; y < bot; y++ {
|
||||||
_screen.SetContent(left, y, tcell.RuneVLine, nil, style)
|
_screen.SetContent(left, y, w.borderStyle.left, nil, style)
|
||||||
_screen.SetContent(right-1, y, tcell.RuneVLine, nil, style)
|
}
|
||||||
}
|
}
|
||||||
|
switch shape {
|
||||||
_screen.SetContent(left, top, tcell.RuneULCorner, nil, style)
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble, BorderVertical, BorderRight:
|
||||||
_screen.SetContent(right-1, top, tcell.RuneURCorner, nil, style)
|
vw := runeWidth(w.borderStyle.right)
|
||||||
_screen.SetContent(left, bot-1, tcell.RuneLLCorner, nil, style)
|
for y := top; y < bot; y++ {
|
||||||
_screen.SetContent(right-1, bot-1, tcell.RuneLRCorner, nil, style)
|
_screen.SetContent(right-vw, y, w.borderStyle.right, nil, style)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch shape {
|
||||||
|
case BorderRounded, BorderSharp, BorderBold, BorderBlock, BorderThinBlock, BorderDouble:
|
||||||
|
_screen.SetContent(left, top, w.borderStyle.topLeft, nil, style)
|
||||||
|
_screen.SetContent(right-runeWidth(w.borderStyle.topRight), top, w.borderStyle.topRight, nil, style)
|
||||||
|
_screen.SetContent(left, bot-1, w.borderStyle.bottomLeft, nil, style)
|
||||||
|
_screen.SetContent(right-runeWidth(w.borderStyle.bottomRight), bot-1, w.borderStyle.bottomRight, nil, style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
395
src/tui/tcell_test.go
Normal file
395
src/tui/tcell_test.go
Normal file
@@ -0,0 +1,395 @@
|
|||||||
|
//go:build tcell || windows
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func assert(t *testing.T, context string, got interface{}, want interface{}) bool {
|
||||||
|
if got == want {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
t.Errorf("%s = (%T)%v, want (%T)%v", context, got, got, want, want)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test the handling of the tcell keyboard events.
|
||||||
|
func TestGetCharEventKey(t *testing.T) {
|
||||||
|
if util.IsTty(os.Stdout) {
|
||||||
|
// This test is skipped when output goes to terminal, because it causes
|
||||||
|
// some glitches:
|
||||||
|
// - output lines may not start at the beginning of a row which makes
|
||||||
|
// the output unreadable
|
||||||
|
// - terminal may get cleared which prevents you from seeing results of
|
||||||
|
// previous tests
|
||||||
|
// Good ways to prevent the glitches are piping the output to a pager
|
||||||
|
// or redirecting to a file. I've found `less +G` to be trouble-free.
|
||||||
|
t.Skip("Skipped because this test misbehaves in terminal, pipe to a pager or redirect output to a file to run it safely.")
|
||||||
|
} else if testing.Verbose() {
|
||||||
|
// I have observed a behaviour when this test outputted more than 8192
|
||||||
|
// bytes (32*256) into the 'less' pager, both the go's test executable
|
||||||
|
// and the pager hanged. The go's executable was blocking on printing.
|
||||||
|
// I was able to create minimal working example of that behaviour, but
|
||||||
|
// that example hanged after 12256 bytes (32*(256+127)).
|
||||||
|
t.Log("If you are piping this test to a pager and it hangs, make the pager greedy for input, e.g. 'less +G'.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !HasFullscreenRenderer() {
|
||||||
|
t.Skip("Can't test FullscreenRenderer.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// construct test cases
|
||||||
|
type giveKey struct {
|
||||||
|
Type tcell.Key
|
||||||
|
Char rune
|
||||||
|
Mods tcell.ModMask
|
||||||
|
}
|
||||||
|
type wantKey = Event
|
||||||
|
type testCase struct {
|
||||||
|
giveKey
|
||||||
|
wantKey
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Some test cases are marked "fabricated". It means that giveKey value
|
||||||
|
is valid, but it is not what you get when you press the keys. For
|
||||||
|
example Ctrl+C will NOT give you tcell.KeyCtrlC, but tcell.KeyETX
|
||||||
|
(End-Of-Text character, causing SIGINT).
|
||||||
|
I was trying to accompany the fabricated test cases with real ones.
|
||||||
|
|
||||||
|
Some test cases are marked "unhandled". It means that giveKey.Type
|
||||||
|
is not present in tcell.go source code. It can still be handled via
|
||||||
|
implicit or explicit alias.
|
||||||
|
|
||||||
|
If not said otherwise, test cases are for US keyboard.
|
||||||
|
|
||||||
|
(tabstop=44)
|
||||||
|
*/
|
||||||
|
tests := []testCase{
|
||||||
|
|
||||||
|
// section 1: Ctrl+(Alt)+[a-z]
|
||||||
|
{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl}, wantKey{CtrlA, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyCtrlC, rune(tcell.KeyCtrlC), tcell.ModCtrl}, wantKey{CtrlC, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyETX, rune(tcell.KeyETX), tcell.ModCtrl}, wantKey{CtrlC, 0, nil}}, // this is SIGINT (Ctrl+C)
|
||||||
|
{giveKey{tcell.KeyCtrlZ, rune(tcell.KeyCtrlZ), tcell.ModCtrl}, wantKey{CtrlZ, 0, nil}}, // fabricated
|
||||||
|
// KeyTab is alias for KeyTAB
|
||||||
|
{giveKey{tcell.KeyCtrlI, rune(tcell.KeyCtrlI), tcell.ModCtrl}, wantKey{Tab, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyTab, rune(tcell.KeyTab), tcell.ModNone}, wantKey{Tab, 0, nil}}, // unhandled, actual "Tab" keystroke
|
||||||
|
{giveKey{tcell.KeyTAB, rune(tcell.KeyTAB), tcell.ModNone}, wantKey{Tab, 0, nil}}, // fabricated, unhandled
|
||||||
|
// KeyEnter is alias for KeyCR
|
||||||
|
{giveKey{tcell.KeyCtrlM, rune(tcell.KeyCtrlM), tcell.ModNone}, wantKey{CtrlM, 0, nil}}, // actual "Enter" keystroke
|
||||||
|
{giveKey{tcell.KeyCR, rune(tcell.KeyCR), tcell.ModNone}, wantKey{CtrlM, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyEnter, rune(tcell.KeyEnter), tcell.ModNone}, wantKey{CtrlM, 0, nil}}, // fabricated, unhandled
|
||||||
|
// Ctrl+Alt keys
|
||||||
|
{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAlt, 'a', nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyCtrlA, rune(tcell.KeyCtrlA), tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAlt, 'a', nil}}, // fabricated
|
||||||
|
|
||||||
|
// section 2: Ctrl+[ \]_]
|
||||||
|
{giveKey{tcell.KeyCtrlSpace, rune(tcell.KeyCtrlSpace), tcell.ModCtrl}, wantKey{CtrlSpace, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyNUL, rune(tcell.KeyNUL), tcell.ModNone}, wantKey{CtrlSpace, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyRune, ' ', tcell.ModCtrl}, wantKey{CtrlSpace, 0, nil}}, // actual Ctrl+' '
|
||||||
|
{giveKey{tcell.KeyCtrlBackslash, rune(tcell.KeyCtrlBackslash), tcell.ModCtrl}, wantKey{CtrlBackSlash, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyCtrlRightSq, rune(tcell.KeyCtrlRightSq), tcell.ModCtrl}, wantKey{CtrlRightBracket, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyCtrlCarat, rune(tcell.KeyCtrlCarat), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlCaret, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyRS, rune(tcell.KeyRS), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlCaret, 0, nil}}, // actual Ctrl+Shift+6 (i.e. Ctrl+^) keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlUnderscore, rune(tcell.KeyCtrlUnderscore), tcell.ModShift | tcell.ModCtrl}, wantKey{CtrlSlash, 0, nil}},
|
||||||
|
|
||||||
|
// section 3: (Alt)+Backspace2
|
||||||
|
// KeyBackspace2 is alias for KeyDEL = 0x7F (ASCII) (allegedly unused by Windows)
|
||||||
|
// KeyDelete = 0x2E (VK_DELETE constant in Windows)
|
||||||
|
// KeyBackspace is alias for KeyBS = 0x08 (ASCII) (implicit alias with KeyCtrlH)
|
||||||
|
{giveKey{tcell.KeyBackspace2, 0, tcell.ModNone}, wantKey{Backspace, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyBackspace2, 0, tcell.ModAlt}, wantKey{AltBackspace, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyDEL, 0, tcell.ModNone}, wantKey{Backspace, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyDelete, 0, tcell.ModNone}, wantKey{Delete, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyDelete, 0, tcell.ModAlt}, wantKey{Delete, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyBackspace, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyBS, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyCtrlH, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModNone}, wantKey{Backspace, 0, nil}}, // actual "Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModAlt}, wantKey{AltBackspace, 0, nil}}, // actual "Alt+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyDEL, rune(tcell.KeyDEL), tcell.ModCtrl}, wantKey{Backspace, 0, nil}}, // actual "Ctrl+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift}, wantKey{Backspace, 0, nil}}, // actual "Shift+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt}, wantKey{Backspace, 0, nil}}, // actual "Ctrl+Alt+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModShift}, wantKey{Backspace, 0, nil}}, // actual "Ctrl+Shift+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModShift | tcell.ModAlt}, wantKey{AltBackspace, 0, nil}}, // actual "Shift+Alt+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, 0, tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{Backspace, 0, nil}}, // actual "Ctrl+Shift+Alt+Backspace" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl}, wantKey{CtrlH, 0, nil}}, // actual "Ctrl+H" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModAlt}, wantKey{CtrlAlt, 'h', nil}}, // fabricated "Ctrl+Alt+H" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModShift}, wantKey{CtrlH, 0, nil}}, // actual "Ctrl+Shift+H" keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlH, rune(tcell.KeyCtrlH), tcell.ModCtrl | tcell.ModAlt | tcell.ModShift}, wantKey{CtrlAlt, 'h', nil}}, // fabricated "Ctrl+Shift+Alt+H" keystroke
|
||||||
|
|
||||||
|
// section 4: (Alt+Shift)+Key(Up|Down|Left|Right)
|
||||||
|
{giveKey{tcell.KeyUp, 0, tcell.ModNone}, wantKey{Up, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyDown, 0, tcell.ModAlt}, wantKey{AltDown, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyLeft, 0, tcell.ModShift}, wantKey{ShiftLeft, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyRight, 0, tcell.ModShift | tcell.ModAlt}, wantKey{AltShiftRight, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyUpLeft, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyUpRight, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyDownLeft, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyDownRight, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyCenter, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
// section 5: (Insert|Home|Delete|End|PgUp|PgDn|BackTab|F1-F12)
|
||||||
|
{giveKey{tcell.KeyInsert, 0, tcell.ModNone}, wantKey{Insert, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyF1, 0, tcell.ModNone}, wantKey{F1, 0, nil}},
|
||||||
|
// section 6: (Ctrl+Alt)+'rune'
|
||||||
|
{giveKey{tcell.KeyRune, 'a', tcell.ModNone}, wantKey{Rune, 'a', nil}},
|
||||||
|
{giveKey{tcell.KeyRune, 'a', tcell.ModCtrl}, wantKey{Rune, 'a', nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyRune, 'a', tcell.ModAlt}, wantKey{Alt, 'a', nil}},
|
||||||
|
{giveKey{tcell.KeyRune, 'A', tcell.ModAlt}, wantKey{Alt, 'A', nil}},
|
||||||
|
{giveKey{tcell.KeyRune, '`', tcell.ModAlt}, wantKey{Alt, '`', nil}},
|
||||||
|
/*
|
||||||
|
"Input method" in Windows Language options:
|
||||||
|
US: "US Keyboard" does not generate any characters (and thus any events) in Ctrl+Alt+[a-z] range
|
||||||
|
CS: "Czech keyboard"
|
||||||
|
DE: "German keyboard"
|
||||||
|
|
||||||
|
Note that right Alt is not just `tcell.ModAlt` on foreign language keyboards, but it is the AltGr `tcell.ModCtrl|tcell.ModAlt`.
|
||||||
|
*/
|
||||||
|
{giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // CS: Ctrl+Alt+b = "{" // Note that this does not interfere with CtrlB, since the "b" is replaced with "{" on OS level
|
||||||
|
{giveKey{tcell.KeyRune, '$', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '$', nil}}, // CS: Ctrl+Alt+ů = "$"
|
||||||
|
{giveKey{tcell.KeyRune, '~', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '~', nil}}, // CS: Ctrl+Alt++ = "~"
|
||||||
|
{giveKey{tcell.KeyRune, '`', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '`', nil}}, // CS: Ctrl+Alt+ý,Space = "`" // this is dead key, space is required to emit the char
|
||||||
|
|
||||||
|
{giveKey{tcell.KeyRune, '{', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '{', nil}}, // DE: Ctrl+Alt+7 = "{"
|
||||||
|
{giveKey{tcell.KeyRune, '@', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, '@', nil}}, // DE: Ctrl+Alt+q = "@"
|
||||||
|
{giveKey{tcell.KeyRune, 'µ', tcell.ModCtrl | tcell.ModAlt}, wantKey{Rune, 'µ', nil}}, // DE: Ctrl+Alt+m = "µ"
|
||||||
|
|
||||||
|
// section 7: Esc
|
||||||
|
// KeyEsc and KeyEscape are aliases for KeyESC
|
||||||
|
{giveKey{tcell.KeyEsc, rune(tcell.KeyEsc), tcell.ModNone}, wantKey{Esc, 0, nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyESC, rune(tcell.KeyESC), tcell.ModNone}, wantKey{Esc, 0, nil}}, // unhandled
|
||||||
|
{giveKey{tcell.KeyEscape, rune(tcell.KeyEscape), tcell.ModNone}, wantKey{Esc, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyESC, rune(tcell.KeyESC), tcell.ModCtrl}, wantKey{Esc, 0, nil}}, // actual Ctrl+[ keystroke
|
||||||
|
{giveKey{tcell.KeyCtrlLeftSq, rune(tcell.KeyCtrlLeftSq), tcell.ModCtrl}, wantKey{Esc, 0, nil}}, // fabricated, unhandled
|
||||||
|
|
||||||
|
// section 8: Invalid
|
||||||
|
{giveKey{tcell.KeyRune, 'a', tcell.ModMeta}, wantKey{Rune, 'a', nil}}, // fabricated
|
||||||
|
{giveKey{tcell.KeyF24, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}},
|
||||||
|
{giveKey{tcell.KeyHelp, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyExit, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyClear, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // unhandled, actual keystroke Numpad_5 with Numlock OFF
|
||||||
|
{giveKey{tcell.KeyCancel, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyPrint, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // fabricated, unhandled
|
||||||
|
{giveKey{tcell.KeyPause, 0, tcell.ModNone}, wantKey{Invalid, 0, nil}}, // unhandled
|
||||||
|
|
||||||
|
}
|
||||||
|
r := NewFullscreenRenderer(&ColorTheme{}, false, false)
|
||||||
|
r.Init()
|
||||||
|
|
||||||
|
// run and evaluate the tests
|
||||||
|
initialResizeAsInvalid := true
|
||||||
|
for _, test := range tests {
|
||||||
|
// generate key event
|
||||||
|
giveEvent := tcell.NewEventKey(test.giveKey.Type, test.giveKey.Char, test.giveKey.Mods)
|
||||||
|
_screen.PostEventWait(giveEvent)
|
||||||
|
t.Logf("giveEvent = %T{key: %v, ch: %q (%[3]v), mod: %#04b}\n", giveEvent, giveEvent.Key(), giveEvent.Rune(), giveEvent.Modifiers())
|
||||||
|
|
||||||
|
// process the event in fzf and evaluate the test
|
||||||
|
gotEvent := r.GetChar()
|
||||||
|
// skip Resize events, those are sometimes put in the buffer outside of this test
|
||||||
|
if initialResizeAsInvalid && gotEvent.Type == Invalid {
|
||||||
|
t.Logf("Resize as Invalid swallowed")
|
||||||
|
initialResizeAsInvalid = false
|
||||||
|
gotEvent = r.GetChar()
|
||||||
|
}
|
||||||
|
t.Logf("wantEvent = %T{Type: %v, Char: %q (%[3]v)}\n", test.wantKey, test.wantKey.Type, test.wantKey.Char)
|
||||||
|
t.Logf("gotEvent = %T{Type: %v, Char: %q (%[3]v)}\n", gotEvent, gotEvent.Type, gotEvent.Char)
|
||||||
|
|
||||||
|
assert(t, "r.GetChar().Type", gotEvent.Type, test.wantKey.Type)
|
||||||
|
assert(t, "r.GetChar().Char", gotEvent.Char, test.wantKey.Char)
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Quick reference
|
||||||
|
---------------
|
||||||
|
|
||||||
|
(tabstop=18)
|
||||||
|
(this is not mapping table, it merely puts multiple constants ranges in one table)
|
||||||
|
|
||||||
|
¹) the two columns are each other implicit alias
|
||||||
|
²) explicit aliases here
|
||||||
|
|
||||||
|
%v section # tcell ctrl key¹ tcell ctrl char¹ tcell alias² tui constants tcell named keys tcell mods
|
||||||
|
-- --------- -------------- --------------- ----------- ------------- ---------------- ----------
|
||||||
|
0 2 KeyCtrlSpace KeyNUL = ^@ Rune ModNone
|
||||||
|
1 1 KeyCtrlA KeySOH = ^A CtrlA ModShift
|
||||||
|
2 1 KeyCtrlB KeySTX = ^B CtrlB ModCtrl
|
||||||
|
3 1 KeyCtrlC KeyETX = ^C CtrlC
|
||||||
|
4 1 KeyCtrlD KeyEOT = ^D CtrlD ModAlt
|
||||||
|
5 1 KeyCtrlE KeyENQ = ^E CtrlE
|
||||||
|
6 1 KeyCtrlF KeyACK = ^F CtrlF
|
||||||
|
7 1 KeyCtrlG KeyBEL = ^G CtrlG
|
||||||
|
8 1 KeyCtrlH KeyBS = ^H KeyBackspace CtrlH ModMeta
|
||||||
|
9 1 KeyCtrlI KeyTAB = ^I KeyTab Tab
|
||||||
|
10 1 KeyCtrlJ KeyLF = ^J CtrlJ
|
||||||
|
11 1 KeyCtrlK KeyVT = ^K CtrlK
|
||||||
|
12 1 KeyCtrlL KeyFF = ^L CtrlL
|
||||||
|
13 1 KeyCtrlM KeyCR = ^M KeyEnter CtrlM
|
||||||
|
14 1 KeyCtrlN KeySO = ^N CtrlN
|
||||||
|
15 1 KeyCtrlO KeySI = ^O CtrlO
|
||||||
|
16 1 KeyCtrlP KeyDLE = ^P CtrlP
|
||||||
|
17 1 KeyCtrlQ KeyDC1 = ^Q CtrlQ
|
||||||
|
18 1 KeyCtrlR KeyDC2 = ^R CtrlR
|
||||||
|
19 1 KeyCtrlS KeyDC3 = ^S CtrlS
|
||||||
|
20 1 KeyCtrlT KeyDC4 = ^T CtrlT
|
||||||
|
21 1 KeyCtrlU KeyNAK = ^U CtrlU
|
||||||
|
22 1 KeyCtrlV KeySYN = ^V CtrlV
|
||||||
|
23 1 KeyCtrlW KeyETB = ^W CtrlW
|
||||||
|
24 1 KeyCtrlX KeyCAN = ^X CtrlX
|
||||||
|
25 1 KeyCtrlY KeyEM = ^Y CtrlY
|
||||||
|
26 1 KeyCtrlZ KeySUB = ^Z CtrlZ
|
||||||
|
27 7 KeyCtrlLeftSq KeyESC = ^[ KeyEsc, KeyEscape ESC
|
||||||
|
28 2 KeyCtrlBackslash KeyFS = ^\ CtrlSpace
|
||||||
|
29 2 KeyCtrlRightSq KeyGS = ^] CtrlBackSlash
|
||||||
|
30 2 KeyCtrlCarat KeyRS = ^^ CtrlRightBracket
|
||||||
|
31 2 KeyCtrlUnderscore KeyUS = ^_ CtrlCaret
|
||||||
|
32 CtrlSlash
|
||||||
|
33 Invalid
|
||||||
|
34 Resize
|
||||||
|
35 Mouse
|
||||||
|
36 DoubleClick
|
||||||
|
37 LeftClick
|
||||||
|
38 RightClick
|
||||||
|
39 BTab
|
||||||
|
40 Backspace
|
||||||
|
41 Del
|
||||||
|
42 PgUp
|
||||||
|
43 PgDn
|
||||||
|
44 Up
|
||||||
|
45 Down
|
||||||
|
46 Left
|
||||||
|
47 Right
|
||||||
|
48 Home
|
||||||
|
49 End
|
||||||
|
50 Insert
|
||||||
|
51 SUp
|
||||||
|
52 SDown
|
||||||
|
53 ShiftLeft
|
||||||
|
54 SRight
|
||||||
|
55 F1
|
||||||
|
56 F2
|
||||||
|
57 F3
|
||||||
|
58 F4
|
||||||
|
59 F5
|
||||||
|
60 F6
|
||||||
|
61 F7
|
||||||
|
62 F8
|
||||||
|
63 F9
|
||||||
|
64 F10
|
||||||
|
65 F11
|
||||||
|
66 F12
|
||||||
|
67 Change
|
||||||
|
68 BackwardEOF
|
||||||
|
69 AltBackspace
|
||||||
|
70 AltUp
|
||||||
|
71 AltDown
|
||||||
|
72 AltLeft
|
||||||
|
73 AltRight
|
||||||
|
74 AltSUp
|
||||||
|
75 AltSDown
|
||||||
|
76 AltShiftLeft
|
||||||
|
77 AltShiftRight
|
||||||
|
78 Alt
|
||||||
|
79 CtrlAlt
|
||||||
|
..
|
||||||
|
127 3 KeyDEL KeyBackspace2
|
||||||
|
..
|
||||||
|
256 6 KeyRune
|
||||||
|
257 4 KeyUp
|
||||||
|
258 4 KeyDown
|
||||||
|
259 4 KeyRight
|
||||||
|
260 4 KeyLeft
|
||||||
|
261 8 KeyUpLeft
|
||||||
|
262 8 KeyUpRight
|
||||||
|
263 8 KeyDownLeft
|
||||||
|
264 8 KeyDownRight
|
||||||
|
265 8 KeyCenter
|
||||||
|
266 5 KeyPgUp
|
||||||
|
267 5 KeyPgDn
|
||||||
|
268 5 KeyHome
|
||||||
|
269 5 KeyEnd
|
||||||
|
270 5 KeyInsert
|
||||||
|
271 5 KeyDelete
|
||||||
|
272 8 KeyHelp
|
||||||
|
273 8 KeyExit
|
||||||
|
274 8 KeyClear
|
||||||
|
275 8 KeyCancel
|
||||||
|
276 8 KeyPrint
|
||||||
|
277 8 KeyPause
|
||||||
|
278 5 KeyBacktab
|
||||||
|
279 5 KeyF1
|
||||||
|
280 5 KeyF2
|
||||||
|
281 5 KeyF3
|
||||||
|
282 5 KeyF4
|
||||||
|
283 5 KeyF5
|
||||||
|
284 5 KeyF6
|
||||||
|
285 5 KeyF7
|
||||||
|
286 5 KeyF8
|
||||||
|
287 5 KeyF9
|
||||||
|
288 5 KeyF10
|
||||||
|
289 5 KeyF11
|
||||||
|
290 5 KeyF12
|
||||||
|
291 8 KeyF13
|
||||||
|
292 8 KeyF14
|
||||||
|
293 8 KeyF15
|
||||||
|
294 8 KeyF16
|
||||||
|
295 8 KeyF17
|
||||||
|
296 8 KeyF18
|
||||||
|
297 8 KeyF19
|
||||||
|
298 8 KeyF20
|
||||||
|
299 8 KeyF21
|
||||||
|
300 8 KeyF22
|
||||||
|
301 8 KeyF23
|
||||||
|
302 8 KeyF24
|
||||||
|
303 8 KeyF25
|
||||||
|
304 8 KeyF26
|
||||||
|
305 8 KeyF27
|
||||||
|
306 8 KeyF28
|
||||||
|
307 8 KeyF29
|
||||||
|
308 8 KeyF30
|
||||||
|
309 8 KeyF31
|
||||||
|
310 8 KeyF32
|
||||||
|
311 8 KeyF33
|
||||||
|
312 8 KeyF34
|
||||||
|
313 8 KeyF35
|
||||||
|
314 8 KeyF36
|
||||||
|
315 8 KeyF37
|
||||||
|
316 8 KeyF38
|
||||||
|
317 8 KeyF39
|
||||||
|
318 8 KeyF40
|
||||||
|
319 8 KeyF41
|
||||||
|
320 8 KeyF42
|
||||||
|
321 8 KeyF43
|
||||||
|
322 8 KeyF44
|
||||||
|
323 8 KeyF45
|
||||||
|
324 8 KeyF46
|
||||||
|
325 8 KeyF47
|
||||||
|
326 8 KeyF48
|
||||||
|
327 8 KeyF49
|
||||||
|
328 8 KeyF50
|
||||||
|
329 8 KeyF51
|
||||||
|
330 8 KeyF52
|
||||||
|
331 8 KeyF53
|
||||||
|
332 8 KeyF54
|
||||||
|
333 8 KeyF55
|
||||||
|
334 8 KeyF56
|
||||||
|
335 8 KeyF57
|
||||||
|
336 8 KeyF58
|
||||||
|
337 8 KeyF59
|
||||||
|
338 8 KeyF60
|
||||||
|
339 8 KeyF61
|
||||||
|
340 8 KeyF62
|
||||||
|
341 8 KeyF63
|
||||||
|
342 8 KeyF64
|
||||||
|
-- --------- -------------- --------------- ----------- ------------- ---------------- ----------
|
||||||
|
%v section # tcell ctrl key tcell ctrl char tcell alias tui constants tcell named keys tcell mods
|
||||||
|
*/
|
||||||
54
src/tui/ttyname_unix.go
Normal file
54
src/tui/ttyname_unix.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"sync/atomic"
|
||||||
|
"syscall"
|
||||||
|
)
|
||||||
|
|
||||||
|
var devPrefixes = [...]string{"/dev/pts/", "/dev/"}
|
||||||
|
|
||||||
|
var tty atomic.Value
|
||||||
|
|
||||||
|
func ttyname() string {
|
||||||
|
if cached := tty.Load(); cached != nil {
|
||||||
|
return cached.(string)
|
||||||
|
}
|
||||||
|
|
||||||
|
var stderr syscall.Stat_t
|
||||||
|
if syscall.Fstat(2, &stderr) != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, prefix := range devPrefixes {
|
||||||
|
files, err := os.ReadDir(prefix)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, file := range files {
|
||||||
|
info, err := file.Info()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if stat, ok := info.Sys().(*syscall.Stat_t); ok && stat.Rdev == stderr.Rdev {
|
||||||
|
value := prefix + file.Name()
|
||||||
|
tty.Store(value)
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// TtyIn returns terminal device to read user input
|
||||||
|
func TtyIn() (*os.File, error) {
|
||||||
|
return openTtyIn()
|
||||||
|
}
|
||||||
|
|
||||||
|
// TtyIn returns terminal device to write to
|
||||||
|
func TtyOut() (*os.File, error) {
|
||||||
|
return openTtyOut()
|
||||||
|
}
|
||||||
21
src/tui/ttyname_windows.go
Normal file
21
src/tui/ttyname_windows.go
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package tui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ttyname() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// TtyIn on Windows returns os.Stdin
|
||||||
|
func TtyIn() (*os.File, error) {
|
||||||
|
return os.Stdin, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TtyIn on Windows returns nil
|
||||||
|
func TtyOut() (*os.File, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
782
src/tui/tui.go
782
src/tui/tui.go
@@ -1,15 +1,20 @@
|
|||||||
package tui
|
package tui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/junegunn/fzf/src/util"
|
||||||
|
"github.com/rivo/uniseg"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Types of user action
|
// Types of user action
|
||||||
|
//
|
||||||
|
//go:generate stringer -type=EventType
|
||||||
|
type EventType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Rune = iota
|
Rune EventType = iota
|
||||||
|
|
||||||
CtrlA
|
CtrlA
|
||||||
CtrlB
|
CtrlB
|
||||||
@@ -37,20 +42,22 @@ const (
|
|||||||
CtrlX
|
CtrlX
|
||||||
CtrlY
|
CtrlY
|
||||||
CtrlZ
|
CtrlZ
|
||||||
ESC
|
Esc
|
||||||
CtrlSpace
|
CtrlSpace
|
||||||
|
CtrlDelete
|
||||||
|
|
||||||
Invalid
|
// https://apple.stackexchange.com/questions/24261/how-do-i-send-c-that-is-control-slash-to-the-terminal
|
||||||
Resize
|
CtrlBackSlash
|
||||||
Mouse
|
CtrlRightBracket
|
||||||
DoubleClick
|
CtrlCaret
|
||||||
|
CtrlSlash
|
||||||
|
|
||||||
BTab
|
ShiftTab
|
||||||
BSpace
|
Backspace
|
||||||
|
|
||||||
Del
|
Delete
|
||||||
PgUp
|
PageUp
|
||||||
PgDn
|
PageDown
|
||||||
|
|
||||||
Up
|
Up
|
||||||
Down
|
Down
|
||||||
@@ -58,9 +65,13 @@ const (
|
|||||||
Right
|
Right
|
||||||
Home
|
Home
|
||||||
End
|
End
|
||||||
|
Insert
|
||||||
|
|
||||||
SLeft
|
ShiftUp
|
||||||
SRight
|
ShiftDown
|
||||||
|
ShiftLeft
|
||||||
|
ShiftRight
|
||||||
|
ShiftDelete
|
||||||
|
|
||||||
F1
|
F1
|
||||||
F2
|
F2
|
||||||
@@ -75,26 +86,105 @@ const (
|
|||||||
F11
|
F11
|
||||||
F12
|
F12
|
||||||
|
|
||||||
|
AltBackspace
|
||||||
|
|
||||||
|
AltUp
|
||||||
|
AltDown
|
||||||
|
AltLeft
|
||||||
|
AltRight
|
||||||
|
|
||||||
|
AltShiftUp
|
||||||
|
AltShiftDown
|
||||||
|
AltShiftLeft
|
||||||
|
AltShiftRight
|
||||||
|
|
||||||
|
Alt
|
||||||
|
CtrlAlt
|
||||||
|
|
||||||
|
Invalid
|
||||||
|
Fatal
|
||||||
|
|
||||||
|
Mouse
|
||||||
|
DoubleClick
|
||||||
|
LeftClick
|
||||||
|
RightClick
|
||||||
|
SLeftClick
|
||||||
|
SRightClick
|
||||||
|
ScrollUp
|
||||||
|
ScrollDown
|
||||||
|
SScrollUp
|
||||||
|
SScrollDown
|
||||||
|
PreviewScrollUp
|
||||||
|
PreviewScrollDown
|
||||||
|
|
||||||
|
// Events
|
||||||
|
Resize
|
||||||
Change
|
Change
|
||||||
|
BackwardEOF
|
||||||
AltSpace
|
Start
|
||||||
AltSlash
|
Load
|
||||||
AltBS
|
Focus
|
||||||
|
One
|
||||||
Alt0
|
Zero
|
||||||
|
Result
|
||||||
|
Jump
|
||||||
|
JumpCancel
|
||||||
|
ClickHeader
|
||||||
)
|
)
|
||||||
|
|
||||||
const ( // Reset iota
|
func (t EventType) AsEvent() Event {
|
||||||
AltA = Alt0 + 'a' - '0' + iota
|
return Event{t, 0, nil}
|
||||||
AltB
|
}
|
||||||
AltC
|
|
||||||
AltD
|
func (t EventType) Int() int {
|
||||||
AltE
|
return int(t)
|
||||||
AltF
|
}
|
||||||
AltZ = AltA + 'z' - 'a'
|
|
||||||
CtrlAltA = AltZ + 1
|
func (t EventType) Byte() byte {
|
||||||
CtrlAltM = CtrlAltA + 'm' - 'a'
|
return byte(t)
|
||||||
)
|
}
|
||||||
|
|
||||||
|
func (e Event) Comparable() Event {
|
||||||
|
// Ignore MouseEvent pointer
|
||||||
|
return Event{e.Type, e.Char, nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e Event) KeyName() string {
|
||||||
|
if e.Type >= Invalid {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
switch e.Type {
|
||||||
|
case Rune:
|
||||||
|
return string(e.Char)
|
||||||
|
case Alt:
|
||||||
|
return "alt-" + string(e.Char)
|
||||||
|
case CtrlAlt:
|
||||||
|
return "ctrl-alt-" + string(e.Char)
|
||||||
|
case CtrlBackSlash:
|
||||||
|
return "ctrl-\\"
|
||||||
|
case CtrlRightBracket:
|
||||||
|
return "ctrl-]"
|
||||||
|
case CtrlCaret:
|
||||||
|
return "ctrl-^"
|
||||||
|
case CtrlSlash:
|
||||||
|
return "ctrl-/"
|
||||||
|
}
|
||||||
|
|
||||||
|
return util.ToKebabCase(e.Type.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func Key(r rune) Event {
|
||||||
|
return Event{Rune, r, nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
func AltKey(r rune) Event {
|
||||||
|
return Event{Alt, r, nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CtrlAltKey(r rune) Event {
|
||||||
|
return Event{CtrlAlt, r, nil}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
doubleClickDuration = 500 * time.Millisecond
|
doubleClickDuration = 500 * time.Millisecond
|
||||||
@@ -102,13 +192,26 @@ const (
|
|||||||
|
|
||||||
type Color int32
|
type Color int32
|
||||||
|
|
||||||
|
func (c Color) IsDefault() bool {
|
||||||
|
return c == colDefault
|
||||||
|
}
|
||||||
|
|
||||||
func (c Color) is24() bool {
|
func (c Color) is24() bool {
|
||||||
return c > 0 && (c&(1<<24)) > 0
|
return c > 0 && (c&(1<<24)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ColorAttr struct {
|
||||||
|
Color Color
|
||||||
|
Attr Attr
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewColorAttr() ColorAttr {
|
||||||
|
return ColorAttr{Color: colUndefined, Attr: AttrUndefined}
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
colUndefined Color = -2
|
colUndefined Color = -2
|
||||||
colDefault = -1
|
colDefault Color = -1
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -133,7 +236,7 @@ const (
|
|||||||
type ColorPair struct {
|
type ColorPair struct {
|
||||||
fg Color
|
fg Color
|
||||||
bg Color
|
bg Color
|
||||||
id int
|
attr Attr
|
||||||
}
|
}
|
||||||
|
|
||||||
func HexToColor(rrggbb string) Color {
|
func HexToColor(rrggbb string) Color {
|
||||||
@@ -143,8 +246,8 @@ func HexToColor(rrggbb string) Color {
|
|||||||
return Color((1 << 24) + (r << 16) + (g << 8) + b)
|
return Color((1 << 24) + (r << 16) + (g << 8) + b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewColorPair(fg Color, bg Color) ColorPair {
|
func NewColorPair(fg Color, bg Color, attr Attr) ColorPair {
|
||||||
return ColorPair{fg, bg, -1}
|
return ColorPair{fg, bg, attr}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ColorPair) Fg() Color {
|
func (p ColorPair) Fg() Color {
|
||||||
@@ -155,28 +258,78 @@ func (p ColorPair) Bg() Color {
|
|||||||
return p.bg
|
return p.bg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p ColorPair) is24() bool {
|
func (p ColorPair) Attr() Attr {
|
||||||
return p.fg.is24() || p.bg.is24()
|
return p.attr
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) HasBg() bool {
|
||||||
|
return p.attr&Reverse == 0 && p.bg != colDefault ||
|
||||||
|
p.attr&Reverse > 0 && p.fg != colDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) merge(other ColorPair, except Color) ColorPair {
|
||||||
|
dup := p
|
||||||
|
dup.attr = dup.attr.Merge(other.attr)
|
||||||
|
if other.fg != except {
|
||||||
|
dup.fg = other.fg
|
||||||
|
}
|
||||||
|
if other.bg != except {
|
||||||
|
dup.bg = other.bg
|
||||||
|
}
|
||||||
|
return dup
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) WithAttr(attr Attr) ColorPair {
|
||||||
|
dup := p
|
||||||
|
dup.attr = dup.attr.Merge(attr)
|
||||||
|
return dup
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) MergeAttr(other ColorPair) ColorPair {
|
||||||
|
return p.WithAttr(other.attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) Merge(other ColorPair) ColorPair {
|
||||||
|
return p.merge(other, colUndefined)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ColorPair) MergeNonDefault(other ColorPair) ColorPair {
|
||||||
|
return p.merge(other, colDefault)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ColorTheme struct {
|
type ColorTheme struct {
|
||||||
Fg Color
|
Colored bool
|
||||||
Bg Color
|
Input ColorAttr
|
||||||
DarkBg Color
|
Disabled ColorAttr
|
||||||
Prompt Color
|
Fg ColorAttr
|
||||||
Match Color
|
Bg ColorAttr
|
||||||
Current Color
|
SelectedFg ColorAttr
|
||||||
CurrentMatch Color
|
SelectedBg ColorAttr
|
||||||
Spinner Color
|
SelectedMatch ColorAttr
|
||||||
Info Color
|
PreviewFg ColorAttr
|
||||||
Cursor Color
|
PreviewBg ColorAttr
|
||||||
Selected Color
|
DarkBg ColorAttr
|
||||||
Header Color
|
Gutter ColorAttr
|
||||||
Border Color
|
Prompt ColorAttr
|
||||||
|
Match ColorAttr
|
||||||
|
Current ColorAttr
|
||||||
|
CurrentMatch ColorAttr
|
||||||
|
Spinner ColorAttr
|
||||||
|
Info ColorAttr
|
||||||
|
Cursor ColorAttr
|
||||||
|
Marker ColorAttr
|
||||||
|
Header ColorAttr
|
||||||
|
Separator ColorAttr
|
||||||
|
Scrollbar ColorAttr
|
||||||
|
Border ColorAttr
|
||||||
|
PreviewBorder ColorAttr
|
||||||
|
PreviewScrollbar ColorAttr
|
||||||
|
BorderLabel ColorAttr
|
||||||
|
PreviewLabel ColorAttr
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Type int
|
Type EventType
|
||||||
Char rune
|
Char rune
|
||||||
MouseEvent *MouseEvent
|
MouseEvent *MouseEvent
|
||||||
}
|
}
|
||||||
@@ -185,35 +338,208 @@ type MouseEvent struct {
|
|||||||
Y int
|
Y int
|
||||||
X int
|
X int
|
||||||
S int
|
S int
|
||||||
|
Left bool
|
||||||
Down bool
|
Down bool
|
||||||
Double bool
|
Double bool
|
||||||
Mod bool
|
Mod bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type BorderStyle int
|
type BorderShape int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
BorderNone BorderStyle = iota
|
BorderUndefined BorderShape = iota
|
||||||
BorderAround
|
BorderNone
|
||||||
|
BorderRounded
|
||||||
|
BorderSharp
|
||||||
|
BorderBold
|
||||||
|
BorderBlock
|
||||||
|
BorderThinBlock
|
||||||
|
BorderDouble
|
||||||
BorderHorizontal
|
BorderHorizontal
|
||||||
|
BorderVertical
|
||||||
|
BorderTop
|
||||||
|
BorderBottom
|
||||||
|
BorderLeft
|
||||||
|
BorderRight
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s BorderShape) HasLeft() bool {
|
||||||
|
switch s {
|
||||||
|
case BorderNone, BorderRight, BorderTop, BorderBottom, BorderHorizontal: // No Left
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s BorderShape) HasRight() bool {
|
||||||
|
switch s {
|
||||||
|
case BorderNone, BorderLeft, BorderTop, BorderBottom, BorderHorizontal: // No right
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s BorderShape) HasTop() bool {
|
||||||
|
switch s {
|
||||||
|
case BorderNone, BorderLeft, BorderRight, BorderBottom, BorderVertical: // No top
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
type BorderStyle struct {
|
||||||
|
shape BorderShape
|
||||||
|
top rune
|
||||||
|
bottom rune
|
||||||
|
left rune
|
||||||
|
right rune
|
||||||
|
topLeft rune
|
||||||
|
topRight rune
|
||||||
|
bottomLeft rune
|
||||||
|
bottomRight rune
|
||||||
|
}
|
||||||
|
|
||||||
|
type BorderCharacter int
|
||||||
|
|
||||||
|
func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
|
||||||
|
if !unicode {
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '-',
|
||||||
|
bottom: '-',
|
||||||
|
left: '|',
|
||||||
|
right: '|',
|
||||||
|
topLeft: '+',
|
||||||
|
topRight: '+',
|
||||||
|
bottomLeft: '+',
|
||||||
|
bottomRight: '+',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch shape {
|
||||||
|
case BorderSharp:
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '─',
|
||||||
|
bottom: '─',
|
||||||
|
left: '│',
|
||||||
|
right: '│',
|
||||||
|
topLeft: '┌',
|
||||||
|
topRight: '┐',
|
||||||
|
bottomLeft: '└',
|
||||||
|
bottomRight: '┘',
|
||||||
|
}
|
||||||
|
case BorderBold:
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '━',
|
||||||
|
bottom: '━',
|
||||||
|
left: '┃',
|
||||||
|
right: '┃',
|
||||||
|
topLeft: '┏',
|
||||||
|
topRight: '┓',
|
||||||
|
bottomLeft: '┗',
|
||||||
|
bottomRight: '┛',
|
||||||
|
}
|
||||||
|
case BorderBlock:
|
||||||
|
// ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
|
||||||
|
// ▌ ▐
|
||||||
|
// ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '▀',
|
||||||
|
bottom: '▄',
|
||||||
|
left: '▌',
|
||||||
|
right: '▐',
|
||||||
|
topLeft: '▛',
|
||||||
|
topRight: '▜',
|
||||||
|
bottomLeft: '▙',
|
||||||
|
bottomRight: '▟',
|
||||||
|
}
|
||||||
|
|
||||||
|
case BorderThinBlock:
|
||||||
|
// 🭽▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔🭾
|
||||||
|
// ▏ ▕
|
||||||
|
// 🭼▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁🭿
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '▔',
|
||||||
|
bottom: '▁',
|
||||||
|
left: '▏',
|
||||||
|
right: '▕',
|
||||||
|
topLeft: '🭽',
|
||||||
|
topRight: '🭾',
|
||||||
|
bottomLeft: '🭼',
|
||||||
|
bottomRight: '🭿',
|
||||||
|
}
|
||||||
|
|
||||||
|
case BorderDouble:
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '═',
|
||||||
|
bottom: '═',
|
||||||
|
left: '║',
|
||||||
|
right: '║',
|
||||||
|
topLeft: '╔',
|
||||||
|
topRight: '╗',
|
||||||
|
bottomLeft: '╚',
|
||||||
|
bottomRight: '╝',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return BorderStyle{
|
||||||
|
shape: shape,
|
||||||
|
top: '─',
|
||||||
|
bottom: '─',
|
||||||
|
left: '│',
|
||||||
|
right: '│',
|
||||||
|
topLeft: '╭',
|
||||||
|
topRight: '╮',
|
||||||
|
bottomLeft: '╰',
|
||||||
|
bottomRight: '╯',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeTransparentBorder() BorderStyle {
|
||||||
|
return BorderStyle{
|
||||||
|
shape: BorderRounded,
|
||||||
|
top: ' ',
|
||||||
|
bottom: ' ',
|
||||||
|
left: ' ',
|
||||||
|
right: ' ',
|
||||||
|
topLeft: ' ',
|
||||||
|
topRight: ' ',
|
||||||
|
bottomLeft: ' ',
|
||||||
|
bottomRight: ' '}
|
||||||
|
}
|
||||||
|
|
||||||
|
type TermSize struct {
|
||||||
|
Lines int
|
||||||
|
Columns int
|
||||||
|
PxWidth int
|
||||||
|
PxHeight int
|
||||||
|
}
|
||||||
|
|
||||||
type Renderer interface {
|
type Renderer interface {
|
||||||
Init()
|
Init() error
|
||||||
|
Resize(maxHeightFunc func(int) int)
|
||||||
Pause(clear bool)
|
Pause(clear bool)
|
||||||
Resume(clear bool)
|
Resume(clear bool, sigcont bool)
|
||||||
Clear()
|
Clear()
|
||||||
RefreshWindows(windows []Window)
|
RefreshWindows(windows []Window)
|
||||||
Refresh()
|
Refresh()
|
||||||
Close()
|
Close()
|
||||||
|
PassThrough(string)
|
||||||
|
NeedScrollbarRedraw() bool
|
||||||
|
ShouldEmitResizeEvent() bool
|
||||||
|
|
||||||
GetChar() Event
|
GetChar() Event
|
||||||
|
|
||||||
|
Top() int
|
||||||
MaxX() int
|
MaxX() int
|
||||||
MaxY() int
|
MaxY() int
|
||||||
DoesAutoWrap() bool
|
|
||||||
|
|
||||||
NewWindow(top int, left int, width int, height int, borderStyle BorderStyle) Window
|
Size() TermSize
|
||||||
|
|
||||||
|
NewWindow(top int, left int, width int, height int, preview bool, borderStyle BorderStyle) Window
|
||||||
}
|
}
|
||||||
|
|
||||||
type Window interface {
|
type Window interface {
|
||||||
@@ -222,6 +548,8 @@ type Window interface {
|
|||||||
Width() int
|
Width() int
|
||||||
Height() int
|
Height() int
|
||||||
|
|
||||||
|
DrawBorder()
|
||||||
|
DrawHBorder()
|
||||||
Refresh()
|
Refresh()
|
||||||
FinishFill()
|
FinishFill()
|
||||||
Close()
|
Close()
|
||||||
@@ -233,10 +561,13 @@ type Window interface {
|
|||||||
Move(y int, x int)
|
Move(y int, x int)
|
||||||
MoveAndClear(y int, x int)
|
MoveAndClear(y int, x int)
|
||||||
Print(text string)
|
Print(text string)
|
||||||
CPrint(color ColorPair, attr Attr, text string)
|
CPrint(color ColorPair, text string)
|
||||||
Fill(text string) FillReturn
|
Fill(text string) FillReturn
|
||||||
CFill(fg Color, bg Color, attr Attr, text string) FillReturn
|
CFill(fg Color, bg Color, attr Attr, text string) FillReturn
|
||||||
|
LinkBegin(uri string, params string)
|
||||||
|
LinkEnd()
|
||||||
Erase()
|
Erase()
|
||||||
|
EraseMaybe() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type FullscreenRenderer struct {
|
type FullscreenRenderer struct {
|
||||||
@@ -244,7 +575,7 @@ type FullscreenRenderer struct {
|
|||||||
mouse bool
|
mouse bool
|
||||||
forceBlack bool
|
forceBlack bool
|
||||||
prevDownTime time.Time
|
prevDownTime time.Time
|
||||||
clickY []int
|
clicks [][2]int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
|
func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Renderer {
|
||||||
@@ -253,7 +584,7 @@ func NewFullscreenRenderer(theme *ColorTheme, forceBlack bool, mouse bool) Rende
|
|||||||
mouse: mouse,
|
mouse: mouse,
|
||||||
forceBlack: forceBlack,
|
forceBlack: forceBlack,
|
||||||
prevDownTime: time.Unix(0, 0),
|
prevDownTime: time.Unix(0, 0),
|
||||||
clickY: []int{}}
|
clicks: [][2]int{}}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,102 +593,211 @@ var (
|
|||||||
Dark256 *ColorTheme
|
Dark256 *ColorTheme
|
||||||
Light256 *ColorTheme
|
Light256 *ColorTheme
|
||||||
|
|
||||||
ColNormal ColorPair
|
|
||||||
ColPrompt ColorPair
|
ColPrompt ColorPair
|
||||||
|
ColNormal ColorPair
|
||||||
|
ColInput ColorPair
|
||||||
|
ColDisabled ColorPair
|
||||||
ColMatch ColorPair
|
ColMatch ColorPair
|
||||||
|
ColCursor ColorPair
|
||||||
|
ColCursorEmpty ColorPair
|
||||||
|
ColMarker ColorPair
|
||||||
|
ColSelected ColorPair
|
||||||
|
ColSelectedMatch ColorPair
|
||||||
ColCurrent ColorPair
|
ColCurrent ColorPair
|
||||||
ColCurrentMatch ColorPair
|
ColCurrentMatch ColorPair
|
||||||
|
ColCurrentCursor ColorPair
|
||||||
|
ColCurrentCursorEmpty ColorPair
|
||||||
|
ColCurrentMarker ColorPair
|
||||||
|
ColCurrentSelectedEmpty ColorPair
|
||||||
ColSpinner ColorPair
|
ColSpinner ColorPair
|
||||||
ColInfo ColorPair
|
ColInfo ColorPair
|
||||||
ColCursor ColorPair
|
|
||||||
ColSelected ColorPair
|
|
||||||
ColHeader ColorPair
|
ColHeader ColorPair
|
||||||
|
ColSeparator ColorPair
|
||||||
|
ColScrollbar ColorPair
|
||||||
ColBorder ColorPair
|
ColBorder ColorPair
|
||||||
|
ColPreview ColorPair
|
||||||
|
ColPreviewBorder ColorPair
|
||||||
|
ColBorderLabel ColorPair
|
||||||
|
ColPreviewLabel ColorPair
|
||||||
|
ColPreviewScrollbar ColorPair
|
||||||
|
ColPreviewSpinner ColorPair
|
||||||
)
|
)
|
||||||
|
|
||||||
func EmptyTheme() *ColorTheme {
|
func EmptyTheme() *ColorTheme {
|
||||||
return &ColorTheme{
|
return &ColorTheme{
|
||||||
Fg: colUndefined,
|
Colored: true,
|
||||||
Bg: colUndefined,
|
Input: ColorAttr{colUndefined, AttrUndefined},
|
||||||
DarkBg: colUndefined,
|
Fg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Prompt: colUndefined,
|
Bg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Match: colUndefined,
|
SelectedFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Current: colUndefined,
|
SelectedBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
CurrentMatch: colUndefined,
|
SelectedMatch: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Spinner: colUndefined,
|
DarkBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Info: colUndefined,
|
Prompt: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Cursor: colUndefined,
|
Match: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Selected: colUndefined,
|
Current: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Header: colUndefined,
|
CurrentMatch: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Border: colUndefined}
|
Spinner: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Info: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Cursor: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Marker: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Header: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Border: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
BorderLabel: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorExit(message string) {
|
func NoColorTheme() *ColorTheme {
|
||||||
fmt.Fprintln(os.Stderr, message)
|
return &ColorTheme{
|
||||||
os.Exit(2)
|
Colored: false,
|
||||||
|
Input: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
SelectedFg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
SelectedBg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
SelectedMatch: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
DarkBg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Prompt: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Match: ColorAttr{colDefault, Underline},
|
||||||
|
Current: ColorAttr{colDefault, Reverse},
|
||||||
|
CurrentMatch: ColorAttr{colDefault, Reverse | Underline},
|
||||||
|
Spinner: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Info: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Cursor: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Marker: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Header: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Border: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
BorderLabel: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Disabled: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
PreviewFg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
PreviewBg: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Gutter: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
PreviewBorder: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
PreviewScrollbar: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
PreviewLabel: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Separator: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
Scrollbar: ColorAttr{colDefault, AttrUndefined},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Default16 = &ColorTheme{
|
Default16 = &ColorTheme{
|
||||||
Fg: colDefault,
|
Colored: true,
|
||||||
Bg: colDefault,
|
Input: ColorAttr{colDefault, AttrUndefined},
|
||||||
DarkBg: colBlack,
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Prompt: colBlue,
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Match: colGreen,
|
SelectedFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Current: colYellow,
|
SelectedBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
CurrentMatch: colGreen,
|
SelectedMatch: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Spinner: colGreen,
|
DarkBg: ColorAttr{colBlack, AttrUndefined},
|
||||||
Info: colWhite,
|
Prompt: ColorAttr{colBlue, AttrUndefined},
|
||||||
Cursor: colRed,
|
Match: ColorAttr{colGreen, AttrUndefined},
|
||||||
Selected: colMagenta,
|
Current: ColorAttr{colYellow, AttrUndefined},
|
||||||
Header: colCyan,
|
CurrentMatch: ColorAttr{colGreen, AttrUndefined},
|
||||||
Border: colBlack}
|
Spinner: ColorAttr{colGreen, AttrUndefined},
|
||||||
|
Info: ColorAttr{colWhite, AttrUndefined},
|
||||||
|
Cursor: ColorAttr{colRed, AttrUndefined},
|
||||||
|
Marker: ColorAttr{colMagenta, AttrUndefined},
|
||||||
|
Header: ColorAttr{colCyan, AttrUndefined},
|
||||||
|
Border: ColorAttr{colBlack, AttrUndefined},
|
||||||
|
BorderLabel: ColorAttr{colWhite, AttrUndefined},
|
||||||
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
}
|
||||||
Dark256 = &ColorTheme{
|
Dark256 = &ColorTheme{
|
||||||
Fg: colDefault,
|
Colored: true,
|
||||||
Bg: colDefault,
|
Input: ColorAttr{colDefault, AttrUndefined},
|
||||||
DarkBg: 236,
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Prompt: 110,
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Match: 108,
|
SelectedFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Current: 254,
|
SelectedBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
CurrentMatch: 151,
|
SelectedMatch: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Spinner: 148,
|
DarkBg: ColorAttr{236, AttrUndefined},
|
||||||
Info: 144,
|
Prompt: ColorAttr{110, AttrUndefined},
|
||||||
Cursor: 161,
|
Match: ColorAttr{108, AttrUndefined},
|
||||||
Selected: 168,
|
Current: ColorAttr{254, AttrUndefined},
|
||||||
Header: 109,
|
CurrentMatch: ColorAttr{151, AttrUndefined},
|
||||||
Border: 59}
|
Spinner: ColorAttr{148, AttrUndefined},
|
||||||
|
Info: ColorAttr{144, AttrUndefined},
|
||||||
|
Cursor: ColorAttr{161, AttrUndefined},
|
||||||
|
Marker: ColorAttr{168, AttrUndefined},
|
||||||
|
Header: ColorAttr{109, AttrUndefined},
|
||||||
|
Border: ColorAttr{59, AttrUndefined},
|
||||||
|
BorderLabel: ColorAttr{145, AttrUndefined},
|
||||||
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
}
|
||||||
Light256 = &ColorTheme{
|
Light256 = &ColorTheme{
|
||||||
Fg: colDefault,
|
Colored: true,
|
||||||
Bg: colDefault,
|
Input: ColorAttr{colDefault, AttrUndefined},
|
||||||
DarkBg: 251,
|
Fg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Prompt: 25,
|
Bg: ColorAttr{colDefault, AttrUndefined},
|
||||||
Match: 66,
|
SelectedFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Current: 237,
|
SelectedBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
CurrentMatch: 23,
|
SelectedMatch: ColorAttr{colUndefined, AttrUndefined},
|
||||||
Spinner: 65,
|
DarkBg: ColorAttr{251, AttrUndefined},
|
||||||
Info: 101,
|
Prompt: ColorAttr{25, AttrUndefined},
|
||||||
Cursor: 161,
|
Match: ColorAttr{66, AttrUndefined},
|
||||||
Selected: 168,
|
Current: ColorAttr{237, AttrUndefined},
|
||||||
Header: 31,
|
CurrentMatch: ColorAttr{23, AttrUndefined},
|
||||||
Border: 145}
|
Spinner: ColorAttr{65, AttrUndefined},
|
||||||
|
Info: ColorAttr{101, AttrUndefined},
|
||||||
|
Cursor: ColorAttr{161, AttrUndefined},
|
||||||
|
Marker: ColorAttr{168, AttrUndefined},
|
||||||
|
Header: ColorAttr{31, AttrUndefined},
|
||||||
|
Border: ColorAttr{145, AttrUndefined},
|
||||||
|
BorderLabel: ColorAttr{59, AttrUndefined},
|
||||||
|
Disabled: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewFg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBg: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Gutter: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewBorder: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewScrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
PreviewLabel: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Separator: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
Scrollbar: ColorAttr{colUndefined, AttrUndefined},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
|
func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
|
||||||
if theme == nil {
|
|
||||||
initPalette(theme)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if forceBlack {
|
if forceBlack {
|
||||||
theme.Bg = colBlack
|
theme.Bg = ColorAttr{colBlack, AttrUndefined}
|
||||||
}
|
}
|
||||||
|
|
||||||
o := func(a Color, b Color) Color {
|
o := func(a ColorAttr, b ColorAttr) ColorAttr {
|
||||||
if b == colUndefined {
|
c := a
|
||||||
return a
|
if b.Color != colUndefined {
|
||||||
|
c.Color = b.Color
|
||||||
}
|
}
|
||||||
return b
|
if b.Attr != AttrUndefined {
|
||||||
|
c.Attr = b.Attr
|
||||||
}
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
theme.Input = o(baseTheme.Input, theme.Input)
|
||||||
theme.Fg = o(baseTheme.Fg, theme.Fg)
|
theme.Fg = o(baseTheme.Fg, theme.Fg)
|
||||||
theme.Bg = o(baseTheme.Bg, theme.Bg)
|
theme.Bg = o(baseTheme.Bg, theme.Bg)
|
||||||
theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg)
|
theme.DarkBg = o(baseTheme.DarkBg, theme.DarkBg)
|
||||||
@@ -368,54 +808,72 @@ func initTheme(theme *ColorTheme, baseTheme *ColorTheme, forceBlack bool) {
|
|||||||
theme.Spinner = o(baseTheme.Spinner, theme.Spinner)
|
theme.Spinner = o(baseTheme.Spinner, theme.Spinner)
|
||||||
theme.Info = o(baseTheme.Info, theme.Info)
|
theme.Info = o(baseTheme.Info, theme.Info)
|
||||||
theme.Cursor = o(baseTheme.Cursor, theme.Cursor)
|
theme.Cursor = o(baseTheme.Cursor, theme.Cursor)
|
||||||
theme.Selected = o(baseTheme.Selected, theme.Selected)
|
theme.Marker = o(baseTheme.Marker, theme.Marker)
|
||||||
theme.Header = o(baseTheme.Header, theme.Header)
|
theme.Header = o(baseTheme.Header, theme.Header)
|
||||||
theme.Border = o(baseTheme.Border, theme.Border)
|
theme.Border = o(baseTheme.Border, theme.Border)
|
||||||
|
theme.BorderLabel = o(baseTheme.BorderLabel, theme.BorderLabel)
|
||||||
|
|
||||||
|
// These colors are not defined in the base themes
|
||||||
|
theme.SelectedFg = o(theme.Fg, theme.SelectedFg)
|
||||||
|
theme.SelectedBg = o(theme.Bg, theme.SelectedBg)
|
||||||
|
theme.SelectedMatch = o(theme.Match, theme.SelectedMatch)
|
||||||
|
theme.Disabled = o(theme.Input, theme.Disabled)
|
||||||
|
theme.Gutter = o(theme.DarkBg, theme.Gutter)
|
||||||
|
theme.PreviewFg = o(theme.Fg, theme.PreviewFg)
|
||||||
|
theme.PreviewBg = o(theme.Bg, theme.PreviewBg)
|
||||||
|
theme.PreviewLabel = o(theme.BorderLabel, theme.PreviewLabel)
|
||||||
|
theme.PreviewBorder = o(theme.Border, theme.PreviewBorder)
|
||||||
|
theme.Separator = o(theme.Border, theme.Separator)
|
||||||
|
theme.Scrollbar = o(theme.Border, theme.Scrollbar)
|
||||||
|
theme.PreviewScrollbar = o(theme.PreviewBorder, theme.PreviewScrollbar)
|
||||||
|
|
||||||
initPalette(theme)
|
initPalette(theme)
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPalette(theme *ColorTheme) {
|
func initPalette(theme *ColorTheme) {
|
||||||
idx := 0
|
pair := func(fg, bg ColorAttr) ColorPair {
|
||||||
pair := func(fg, bg Color) ColorPair {
|
if fg.Color == colDefault && (fg.Attr&Reverse) > 0 {
|
||||||
idx++
|
bg.Color = colDefault
|
||||||
return ColorPair{fg, bg, idx}
|
|
||||||
}
|
}
|
||||||
if theme != nil {
|
return ColorPair{fg.Color, bg.Color, fg.Attr}
|
||||||
ColNormal = pair(theme.Fg, theme.Bg)
|
}
|
||||||
|
blank := theme.Fg
|
||||||
|
blank.Attr = AttrRegular
|
||||||
|
|
||||||
ColPrompt = pair(theme.Prompt, theme.Bg)
|
ColPrompt = pair(theme.Prompt, theme.Bg)
|
||||||
|
ColNormal = pair(theme.Fg, theme.Bg)
|
||||||
|
ColSelected = pair(theme.SelectedFg, theme.SelectedBg)
|
||||||
|
ColInput = pair(theme.Input, theme.Bg)
|
||||||
|
ColDisabled = pair(theme.Disabled, theme.Bg)
|
||||||
ColMatch = pair(theme.Match, theme.Bg)
|
ColMatch = pair(theme.Match, theme.Bg)
|
||||||
|
ColSelectedMatch = pair(theme.SelectedMatch, theme.SelectedBg)
|
||||||
|
ColCursor = pair(theme.Cursor, theme.Gutter)
|
||||||
|
ColCursorEmpty = pair(blank, theme.Gutter)
|
||||||
|
if theme.SelectedBg.Color != theme.Bg.Color {
|
||||||
|
ColMarker = pair(theme.Marker, theme.SelectedBg)
|
||||||
|
} else {
|
||||||
|
ColMarker = pair(theme.Marker, theme.Gutter)
|
||||||
|
}
|
||||||
ColCurrent = pair(theme.Current, theme.DarkBg)
|
ColCurrent = pair(theme.Current, theme.DarkBg)
|
||||||
ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)
|
ColCurrentMatch = pair(theme.CurrentMatch, theme.DarkBg)
|
||||||
|
ColCurrentCursor = pair(theme.Cursor, theme.DarkBg)
|
||||||
|
ColCurrentCursorEmpty = pair(blank, theme.DarkBg)
|
||||||
|
ColCurrentMarker = pair(theme.Marker, theme.DarkBg)
|
||||||
|
ColCurrentSelectedEmpty = pair(blank, theme.DarkBg)
|
||||||
ColSpinner = pair(theme.Spinner, theme.Bg)
|
ColSpinner = pair(theme.Spinner, theme.Bg)
|
||||||
ColInfo = pair(theme.Info, theme.Bg)
|
ColInfo = pair(theme.Info, theme.Bg)
|
||||||
ColCursor = pair(theme.Cursor, theme.DarkBg)
|
|
||||||
ColSelected = pair(theme.Selected, theme.DarkBg)
|
|
||||||
ColHeader = pair(theme.Header, theme.Bg)
|
ColHeader = pair(theme.Header, theme.Bg)
|
||||||
|
ColSeparator = pair(theme.Separator, theme.Bg)
|
||||||
|
ColScrollbar = pair(theme.Scrollbar, theme.Bg)
|
||||||
ColBorder = pair(theme.Border, theme.Bg)
|
ColBorder = pair(theme.Border, theme.Bg)
|
||||||
} else {
|
ColBorderLabel = pair(theme.BorderLabel, theme.Bg)
|
||||||
ColNormal = pair(colDefault, colDefault)
|
ColPreviewLabel = pair(theme.PreviewLabel, theme.PreviewBg)
|
||||||
ColPrompt = pair(colDefault, colDefault)
|
ColPreview = pair(theme.PreviewFg, theme.PreviewBg)
|
||||||
ColMatch = pair(colDefault, colDefault)
|
ColPreviewBorder = pair(theme.PreviewBorder, theme.PreviewBg)
|
||||||
ColCurrent = pair(colDefault, colDefault)
|
ColPreviewScrollbar = pair(theme.PreviewScrollbar, theme.PreviewBg)
|
||||||
ColCurrentMatch = pair(colDefault, colDefault)
|
ColPreviewSpinner = pair(theme.Spinner, theme.PreviewBg)
|
||||||
ColSpinner = pair(colDefault, colDefault)
|
|
||||||
ColInfo = pair(colDefault, colDefault)
|
|
||||||
ColCursor = pair(colDefault, colDefault)
|
|
||||||
ColSelected = pair(colDefault, colDefault)
|
|
||||||
ColHeader = pair(colDefault, colDefault)
|
|
||||||
ColBorder = pair(colDefault, colDefault)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func attrFor(color ColorPair, attr Attr) Attr {
|
func runeWidth(r rune) int {
|
||||||
switch color {
|
return uniseg.StringWidth(string(r))
|
||||||
case ColCurrent:
|
|
||||||
return attr | Reverse
|
|
||||||
case ColMatch:
|
|
||||||
return attr | Underline
|
|
||||||
case ColCurrentMatch:
|
|
||||||
return attr | Underline | Reverse
|
|
||||||
}
|
|
||||||
return attr
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
# http://www.rubydoc.info/github/rest-client/rest-client/RestClient
|
|
||||||
require 'rest_client'
|
|
||||||
require 'json'
|
|
||||||
|
|
||||||
if ARGV.length < 3
|
|
||||||
puts "usage: #$0 <token> <version> <files...>"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
token, version, *files = ARGV
|
|
||||||
base = "https://api.github.com/repos/junegunn/fzf-bin/releases"
|
|
||||||
|
|
||||||
# List releases
|
|
||||||
rels = JSON.parse(RestClient.get(base, :authorization => "token #{token}"))
|
|
||||||
rel = rels.find { |r| r['tag_name'] == version }
|
|
||||||
unless rel
|
|
||||||
puts "#{version} not found"
|
|
||||||
exit 1
|
|
||||||
end
|
|
||||||
|
|
||||||
# List assets
|
|
||||||
assets = Hash[rel['assets'].map { |a| a.values_at *%w[name id] }]
|
|
||||||
|
|
||||||
files.select { |f| File.exists? f }.map do |file|
|
|
||||||
Thread.new do
|
|
||||||
name = File.basename file
|
|
||||||
|
|
||||||
if asset_id = assets[name]
|
|
||||||
puts "#{name} found. Deleting asset id #{asset_id}."
|
|
||||||
RestClient.delete "#{base}/assets/#{asset_id}",
|
|
||||||
:authorization => "token #{token}"
|
|
||||||
else
|
|
||||||
puts "#{name} not found"
|
|
||||||
end
|
|
||||||
|
|
||||||
puts "Uploading #{name}"
|
|
||||||
RestClient.post(
|
|
||||||
"#{base.sub 'api', 'uploads'}/#{rel['id']}/assets?name=#{name}",
|
|
||||||
File.read(file),
|
|
||||||
:authorization => "token #{token}",
|
|
||||||
:content_type => "application/octet-stream")
|
|
||||||
end
|
|
||||||
end.each(&:join)
|
|
||||||
28
src/util/atexit.go
Normal file
28
src/util/atexit.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var atExitFuncs []func()
|
||||||
|
|
||||||
|
// AtExit registers the function fn to be called on program termination.
|
||||||
|
// The functions will be called in reverse order they were registered.
|
||||||
|
func AtExit(fn func()) {
|
||||||
|
if fn == nil {
|
||||||
|
panic("AtExit called with nil func")
|
||||||
|
}
|
||||||
|
once := &sync.Once{}
|
||||||
|
atExitFuncs = append(atExitFuncs, func() {
|
||||||
|
once.Do(fn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunAtExitFuncs runs any functions registered with AtExit().
|
||||||
|
func RunAtExitFuncs() {
|
||||||
|
fns := atExitFuncs
|
||||||
|
for i := len(fns) - 1; i >= 0; i-- {
|
||||||
|
fns[i]()
|
||||||
|
}
|
||||||
|
atExitFuncs = nil
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user