diff --git a/Cargo.lock b/Cargo.lock index ac4b38ba..571993bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "aead" -version = "0.6.0-rc.10" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b657e772794c6b04730ea897b66a058ccd866c16d1967da05eeeecec39043fe" +checksum = "1973cfbc1a2daf9cf550e74e1f088c28e7f7d8c1e1418fb6c9dc5184b7e84c99" dependencies = [ "crypto-common 0.2.2", "inout", @@ -198,7 +198,7 @@ checksum = "0ae92a5119aa49cdbcf6b9f893fe4e1d98b04ccbf82ee0584ad948a44a734dea" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -435,9 +435,9 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" dependencies = [ "hybrid-array", "zeroize", @@ -464,9 +464,9 @@ dependencies = [ [[package]] name = "bon" -version = "3.9.2" +version = "3.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2f04f6fef12d70d42a77b1433c9e0f065238479a6cefc4f5bab105e9873a3c3" +checksum = "a602c73c7b0148ec6d12af6fd5cc7a46e2eacc8878271a999abac56eed12f561" dependencies = [ "bon-macros", "rustversion", @@ -474,9 +474,9 @@ dependencies = [ [[package]] name = "bon-macros" -version = "3.9.2" +version = "3.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d0bd4c2f75335ad98052a37efb54f428b492f64340257143b3429c8a508fa7b" +checksum = "6dee98b0db6a962de883bf5d20362dee4d7ca0d12fe39a7c6c73c844e1cd7c1f" dependencies = [ "darling", "ident_case", @@ -484,7 +484,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -541,7 +541,7 @@ checksum = "f9abbd1bc6865053c427f7198e6af43bfdedc55ab791faed4fbd361d789575ff" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -582,9 +582,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.63" +version = "1.2.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556e016178bb5662a08681bbe0f00f8e17631781a4dfc8c45e466e4b185ec27f" +checksum = "dad887fd958be91b5098c0248def011f4523ab786cd411be668777e55063501f" dependencies = [ "find-msvc-tools", "jobserver", @@ -637,7 +637,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf2a2c93cd704877c0858356ed03480ff301ee950b43f1cbe4573b088bfa6c" dependencies = [ - "block-buffer 0.12.0", + "block-buffer 0.12.1", "crypto-common 0.2.2", "inout", "zeroize", @@ -703,7 +703,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -922,13 +922,13 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "crypto-bigint" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a0d26b245348befa0c121944541476763dcc46ede886c88f9d12e1697d27c3" +checksum = "97bb4a855e3b10f84c4e7e895a7de01db7f9a7b7eb7f73ed9773fd52ac686451" dependencies = [ "cpubits", "ctutils", - "getrandom 0.4.2", + "getrandom 0.4.3", "hybrid-array", "num-traits", "rand_core 0.10.1", @@ -953,19 +953,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" dependencies = [ - "getrandom 0.4.2", + "getrandom 0.4.3", "hybrid-array", "rand_core 0.10.1", ] [[package]] name = "crypto-primes" -version = "0.7.0" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21f41f23de7d24cdbda7f0c4d9c0351f99a4ceb258ef30e5c1927af8987ffe5a" +checksum = "3633a51a39c69ebbaa4feaa694bd83d241e4093901c84a0963b19d9bb3f0cf8f" dependencies = [ "crypto-bigint", - "libm", "rand_core 0.10.1", ] @@ -1022,7 +1021,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1045,7 +1044,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1056,7 +1055,7 @@ checksum = "ac3984ec7bd6cfa798e62b4a642426a5be0e68f9401cfc2a01e3fa9ea2fcdb8d" dependencies = [ "darling_core", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1093,7 +1092,7 @@ checksum = "780eb241654bf097afb00fc5f054a09b687dad862e485fdcf8399bb056565370" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1119,7 +1118,6 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" dependencies = [ - "powerfmt", "serde_core", ] @@ -1142,7 +1140,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1170,7 +1168,7 @@ version = "0.11.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" dependencies = [ - "block-buffer 0.12.0", + "block-buffer 0.12.1", "const-oid", "crypto-common 0.2.2", "ctutils", @@ -1297,7 +1295,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1317,7 +1315,7 @@ checksum = "44f23cf4b44bfce11a86ace86f8a73ffdec849c9fd00a386a53d278bd9e81fb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1495,12 +1493,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - [[package]] name = "foldhash" version = "0.2.0" @@ -1578,7 +1570,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1656,17 +1648,15 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "js-sys", "libc", "r-efi 6.0.0", "rand_core 0.10.1", - "wasip2", - "wasip3", "wasm-bindgen", ] @@ -1736,15 +1726,6 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash 0.1.5", -] - [[package]] name = "hashbrown" version = "0.16.1" @@ -1753,7 +1734,7 @@ checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" dependencies = [ "allocator-api2", "equivalent", - "foldhash 0.2.0", + "foldhash", ] [[package]] @@ -1764,7 +1745,7 @@ checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" dependencies = [ "allocator-api2", "equivalent", - "foldhash 0.2.0", + "foldhash", "serde", "serde_core", ] @@ -1847,12 +1828,6 @@ dependencies = [ "cc", ] -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - [[package]] name = "ident_case" version = "1.0.1" @@ -1970,7 +1945,7 @@ dependencies = [ "indoc", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -1993,7 +1968,7 @@ checksum = "c34819042dc3d3971c46c2190835914dfbe0c3c13f61449b2997f4e9722dfa60" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -2038,13 +2013,12 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.99" +version = "0.3.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11" +checksum = "03d04c30968dffe80775bd4d7fb676131cd04a1fb46d2686dbffbaec2d9dfd31" dependencies = [ "cfg-if", "futures-util", - "once_cell", "wasm-bindgen", ] @@ -2111,12 +2085,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - [[package]] name = "lebe" version = "0.5.3" @@ -2378,7 +2346,7 @@ dependencies = [ "proc-macro2", "quote", "regex", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -2527,7 +2495,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -2771,7 +2739,7 @@ dependencies = [ "by_address", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -2879,7 +2847,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -2942,7 +2910,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -3080,14 +3048,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] name = "primefield" -version = "0.14.0-rc.10" +version = "0.14.0-rc.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f845ec3240cd5ed5e1e31cf3ff633a5bf47c698dc4092ba9e767415b3d393406" +checksum = "8675564771a62f69a0af716b03e89b917b963c7b173b5855575e84fd4f605ca0" dependencies = [ "crypto-bigint", "crypto-common 0.2.2", @@ -3125,7 +3093,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -3153,7 +3121,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4488a4a36b9a4ba6b9334a32a39971f77c1436ec82c38707bce707699cc3bbcb" dependencies = [ "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -3256,7 +3224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", - "getrandom 0.4.2", + "getrandom 0.4.3", "rand_core 0.10.1", ] @@ -3486,7 +3454,7 @@ checksum = "b7186006dcb21920990093f30e3dea63b7d6e977bf1256be20c3563a5db070da" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -3593,7 +3561,7 @@ dependencies = [ "enum_dispatch", "futures", "generic-array 1.4.3", - "getrandom 0.4.2", + "getrandom 0.4.3", "ghash", "hex-literal", "hmac", @@ -3848,7 +3816,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -3902,7 +3870,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4071,9 +4039,9 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "smallvec" -version = "1.15.1" +version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" +checksum = "8ed6a63f02c8539c91a8685a86f4099661ba3da017932f6ebbea6de3f0fa7c90" [[package]] name = "socket2" @@ -4192,7 +4160,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4220,9 +4188,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.117" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -4262,7 +4230,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.2", + "getrandom 0.4.3", "once_cell", "rustix 1.1.4", "windows-sys 0.61.2", @@ -4369,7 +4337,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4380,7 +4348,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4428,12 +4396,11 @@ dependencies = [ [[package]] name = "time" -version = "0.3.47" +version = "0.3.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" +checksum = "711a53c2d47bbd818258c498c8dbfe186a2526c631495cfe7e078567f86b8469" dependencies = [ "deranged", - "itoa", "libc", "num-conv", "num_threads", @@ -4445,15 +4412,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" [[package]] name = "time-macros" -version = "0.2.27" +version = "0.2.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" +checksum = "71c652a3727a9cbb9a02f707f530b618ce00d0ccd762009c8c23bd191df3c17d" dependencies = [ "num-conv", "time-core", @@ -4499,7 +4466,7 @@ checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4597,7 +4564,7 @@ checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -4730,12 +4697,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - [[package]] name = "universal-hash" version = "0.6.1" @@ -4766,12 +4727,12 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.23.2" +version = "1.23.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7" +checksum = "144d6b123cef80b301b8f72a9e2ca4370ddec21950d0a103dd22c437006d2db7" dependencies = [ "atomic", - "getrandom 0.4.2", + "getrandom 0.4.3", "js-sys", "serde_core", "wasm-bindgen", @@ -4876,27 +4837,18 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasip2" -version = "1.0.3+wasi-0.2.9" +version = "1.0.4+wasi-0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" dependencies = [ - "wit-bindgen 0.57.1", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen 0.51.0", + "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.122" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409" +checksum = "8ddb3f79143bced6de84270411622a2699cee572fc0875aeaf1e7867cf9fca1a" dependencies = [ "cfg-if", "once_cell", @@ -4907,9 +4859,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.72" +version = "0.4.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f" +checksum = "503b14d284f2c8dac03b819967e155ea753f573586193b2b2c95990cb5d69280" dependencies = [ "js-sys", "wasm-bindgen", @@ -4917,9 +4869,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.122" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6" +checksum = "4e21a184b13fb19e157296e2c46056aec9092264fab83e4ba59e68c61b323c3d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4927,60 +4879,26 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.122" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e" +checksum = "fecefd9c35bd935a20fc3fc344b5f29138961e4f47fb03297d88f2587afb5ebd" dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.122" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437" +checksum = "23939e44bb9a5d7576fa2b563dc2e136628f1224e88a8deed09e04858b77871f" dependencies = [ "unicode-ident", ] -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap 2.14.0", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags 2.13.0", - "hashbrown 0.15.5", - "indexmap 2.14.0", - "semver", -] - [[package]] name = "weezl" version = "0.1.12" @@ -5063,9 +4981,9 @@ dependencies = [ [[package]] name = "which" -version = "8.0.3" +version = "8.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c789537cf2f7f55be8e6192f92e464174ee55f91af622777f7f1ceb0dbccd03e" +checksum = "48d7cd18d4acb58fb3cdfe9ea54e6cd96a4e7d4cc45c56338b236e82dad47248" dependencies = [ "libc", ] @@ -5186,7 +5104,7 @@ checksum = "f6fc35f58ecd95a9b71c4f2329b911016e6bec66b3f2e6a4aad86bd2e99e2f9b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -5197,7 +5115,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -5208,7 +5126,7 @@ checksum = "08990546bf4edef8f431fa6326e032865f27138718c587dc21bc0265bbcb57cc" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -5219,7 +5137,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -5445,100 +5363,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - [[package]] name = "wit-bindgen" version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap 2.14.0", - "prettyplease", - "syn 2.0.117", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.117", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags 2.13.0", - "indexmap 2.14.0", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap 2.14.0", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - [[package]] name = "wyz" version = "0.5.1" @@ -5603,6 +5433,7 @@ dependencies = [ "anyhow", "base64", "image", + "inventory", "moxcms", "palette", "quantette", @@ -5616,8 +5447,8 @@ dependencies = [ "yazi-macro", "yazi-shared", "yazi-shim", - "yazi-term", "yazi-tty", + "yazi-widgets", ] [[package]] @@ -5628,31 +5459,22 @@ dependencies = [ "anyhow", "futures", "hashbrown 0.17.1", + "image", "inventory", "libc", "mlua", "ordered-float 5.3.0", - "parking_lot", - "paste", "ratatui", "serde", "serde_json", + "strum", "tokio", - "tokio-stream", "tracing", "unicode-width", "windows-sys 0.61.2", - "yazi-adapter", "yazi-codegen", - "yazi-config", - "yazi-fs", "yazi-macro", - "yazi-shared", "yazi-shim", - "yazi-term", - "yazi-tty", - "yazi-vfs", - "yazi-widgets", ] [[package]] @@ -5716,7 +5538,7 @@ version = "26.5.6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] @@ -5729,15 +5551,16 @@ dependencies = [ "globset", "hashbrown 0.17.1", "indexmap 2.14.0", + "inventory", "mlua", "ratatui", "regex", "serde", "serde_with", - "strum", "tokio", "toml", "tracing", + "yazi-binding", "yazi-codegen", "yazi-fs", "yazi-macro", @@ -5745,6 +5568,7 @@ dependencies = [ "yazi-shim", "yazi-term", "yazi-tty", + "yazi-widgets", ] [[package]] @@ -5779,6 +5603,7 @@ dependencies = [ "yazi-shared", "yazi-shim", "yazi-term", + "yazi-tty", "yazi-vfs", "yazi-watcher", "yazi-widgets", @@ -5849,7 +5674,6 @@ dependencies = [ "mlua", "paste", "ratatui", - "scopeguard", "signal-hook-tokio", "tikv-jemallocator", "tokio", @@ -5891,8 +5715,9 @@ dependencies = [ "core-foundation-sys", "dirs", "either", - "foldhash 0.2.0", + "foldhash", "hashbrown 0.17.1", + "inventory", "libc", "mlua", "objc2", @@ -5909,6 +5734,7 @@ dependencies = [ "typed-path", "uzers", "windows-sys 0.61.2", + "yazi-binding", "yazi-ffi", "yazi-macro", "yazi-shared", @@ -5946,6 +5772,7 @@ dependencies = [ "yazi-macro", "yazi-scheduler", "yazi-shared", + "yazi-shim", "yazi-term", "yazi-vfs", "yazi-widgets", @@ -5986,6 +5813,7 @@ dependencies = [ "yazi-shared", "yazi-shim", "yazi-term", + "yazi-tty", "yazi-vfs", "yazi-widgets", ] @@ -6040,7 +5868,7 @@ version = "26.5.6" dependencies = [ "anyhow", "async-priority-channel", - "foldhash 0.2.0", + "foldhash", "hashbrown 0.17.1", "libc", "lru", @@ -6058,6 +5886,7 @@ dependencies = [ "yazi-macro", "yazi-runner", "yazi-shared", + "yazi-shim", "yazi-term", "yazi-vfs", ] @@ -6080,7 +5909,7 @@ version = "26.5.6" dependencies = [ "anyhow", "dyn-clone", - "foldhash 0.2.0", + "foldhash", "futures", "hashbrown 0.17.1", "inventory", @@ -6099,6 +5928,7 @@ dependencies = [ "typed-path", "uzers", "windows-sys 0.61.2", + "yazi-codegen", "yazi-macro", "yazi-shim", "yazi-term", @@ -6108,6 +5938,7 @@ dependencies = [ name = "yazi-shim" version = "26.5.6" dependencies = [ + "anyhow", "arc-swap", "base64", "hashbrown 0.17.1", @@ -6131,8 +5962,8 @@ dependencies = [ "base64", "bitflags 2.13.0", "futures", + "mlua", "parking_lot", - "ratatui", "rustix 1.1.4", "serde", "signal-hook 0.4.4", @@ -6149,10 +5980,15 @@ dependencies = [ name = "yazi-tty" version = "26.5.9" dependencies = [ + "base64", + "bitflags 2.13.0", "libc", + "mlua", "parking_lot", + "ratatui", "tracing", "windows-sys 0.61.2", + "yazi-binding", "yazi-macro", "yazi-shim", ] @@ -6190,11 +6026,13 @@ dependencies = [ "either", "futures", "hashbrown 0.17.1", + "mlua", "parking_lot", "russh", "tokio", "tracing", "typed-path", + "yazi-binding", "yazi-config", "yazi-fs", "yazi-macro", @@ -6232,15 +6070,17 @@ dependencies = [ "clipboard-win", "dyn-clone", "futures", + "inventory", "mlua", "parking_lot", "ratatui", "serde", "strum", "tokio", + "tokio-stream", + "tracing", "unicode-width", - "yazi-adapter", - "yazi-config", + "yazi-binding", "yazi-macro", "yazi-shared", "yazi-shim", @@ -6250,29 +6090,29 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.50" +version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b065d4f0e55f82fae73202e189638116a87c55ab6b8e6c2721e13dd9d854ad1" +checksum = "ce1022995ff5ff5d841ad7d994facc23098cd40152f2c1d11cd607c6f530653f" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.50" +version = "0.8.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b631b19d36a892ab55420c92dbc83ccd79274f25be714855d3074aa71cab639" +checksum = "1ae7f38b72ec2a254e2b87ef277cf2cd4fb97cbebf944faa6f33354da0867930" dependencies = [ "proc-macro2", "quote", - "syn 2.0.117", + "syn 2.0.118", ] [[package]] name = "zeroize" -version = "1.8.2" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" [[package]] name = "zmij" diff --git a/Cargo.toml b/Cargo.toml index 451b5a5e..f107575a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,6 +50,7 @@ foldhash = "0.2.0" futures = "0.3.32" globset = "0.4.18" hashbrown = { version = "0.17.1", features = [ "serde" ] } +image = { version = "0.25.10", default-features = false, features = [ "avif", "bmp", "dds", "exr", "ff", "gif", "hdr", "ico", "jpeg", "png", "pnm", "qoi", "tga", "tiff", "webp" ] } indexmap = { version = "2.14.0", features = [ "serde" ] } inventory = "0.3.24" libc = "0.2.186" diff --git a/yazi-actor/src/app/dnd.rs b/yazi-actor/src/app/dnd.rs index 014aa552..576418d8 100644 --- a/yazi-actor/src/app/dnd.rs +++ b/yazi-actor/src/app/dnd.rs @@ -18,8 +18,6 @@ impl Actor for Dnd { const NAME: &str = "dnd"; fn act(cx: &mut Ctx, form: Self::Form) -> Result { - let event = yazi_binding::DndEvent::from(form.event); - let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() }; let area = yazi_binding::elements::Rect::from(size); @@ -27,10 +25,10 @@ impl Actor for Dnd { runtime_scope!(LUA, "root", { let root = LUA.globals().raw_get::("Root")?.call_method::
("new", area)?; - if event.is_drag() { - root.call_method::<()>("drag", event)?; + if form.event.is_drag() { + root.call_method::<()>("drag", form.event)?; } else { - root.call_method::<()>("drop", event)?; + root.call_method::<()>("drop", form.event)?; } Ok(()) diff --git a/yazi-actor/src/app/lua.rs b/yazi-actor/src/app/lua.rs index 73e4e181..fedf031e 100644 --- a/yazi-actor/src/app/lua.rs +++ b/yazi-actor/src/app/lua.rs @@ -1,9 +1,9 @@ use anyhow::Result; -use yazi_binding::{Sendable, runtime_scope}; +use yazi_binding::runtime_scope; use yazi_macro::succ; use yazi_parser::app::LuaForm; use yazi_plugin::LUA; -use yazi_shared::data::Data; +use yazi_shared::data::{Data, Sendable}; use crate::{Actor, Ctx, lives::Lives}; diff --git a/yazi-actor/src/app/mouse.rs b/yazi-actor/src/app/mouse.rs index 8ecdbf10..7eaecb61 100644 --- a/yazi-actor/src/app/mouse.rs +++ b/yazi-actor/src/app/mouse.rs @@ -19,8 +19,6 @@ impl Actor for Mouse { const NAME: &str = "mouse"; fn act(cx: &mut Ctx, form: Self::Form) -> Result { - let event = yazi_binding::MouseEvent::from(form.event); - let Some(size) = cx.term.as_ref().and_then(|t| t.size().ok()) else { succ!() }; let area = yazi_binding::elements::Rect::from(size); @@ -28,18 +26,18 @@ impl Actor for Mouse { runtime_scope!(LUA, "root", { let root = LUA.globals().raw_get::
("Root")?.call_method::
("new", area)?; - match event.kind { - MouseEventKind::Down(_) => root.call_method("click", (event, false))?, - MouseEventKind::Up(_) => root.call_method("click", (event, true))?, + match form.event.kind { + MouseEventKind::Down(_) => root.call_method("click", (form.event, false))?, + MouseEventKind::Up(_) => root.call_method("click", (form.event, true))?, - MouseEventKind::ScrollDown => root.call_method("scroll", (event, 1))?, - MouseEventKind::ScrollUp => root.call_method("scroll", (event, -1))?, + MouseEventKind::ScrollDown => root.call_method("scroll", (form.event, 1))?, + MouseEventKind::ScrollUp => root.call_method("scroll", (form.event, -1))?, - MouseEventKind::ScrollRight => root.call_method("touch", (event, 1))?, - MouseEventKind::ScrollLeft => root.call_method("touch", (event, -1))?, + MouseEventKind::ScrollRight => root.call_method("touch", (form.event, 1))?, + MouseEventKind::ScrollLeft => root.call_method("touch", (form.event, -1))?, - MouseEventKind::Moved => root.call_method("move", event)?, - MouseEventKind::Drag(_) => root.call_method("drag", event)?, + MouseEventKind::Moved => root.call_method("move", form.event)?, + MouseEventKind::Drag(_) => root.call_method("drag", form.event)?, } Ok(()) diff --git a/yazi-actor/src/app/title.rs b/yazi-actor/src/app/title.rs index e6011789..7b19d9e2 100644 --- a/yazi-actor/src/app/title.rs +++ b/yazi-actor/src/app/title.rs @@ -3,8 +3,7 @@ use yazi_actor::Ctx; use yazi_macro::{succ, writef}; use yazi_parser::{app::TitleForm, spark::SparkKind}; use yazi_shared::{Source, data::Data}; -use yazi_term::sequence::SetTitle; -use yazi_tty::TTY; +use yazi_tty::{TTY, sequence::SetTitle}; use yazi_tui::RatermState; use crate::Actor; diff --git a/yazi-actor/src/context.rs b/yazi-actor/src/context.rs index 1ad02d79..fbdc2863 100644 --- a/yazi-actor/src/context.rs +++ b/yazi-actor/src/context.rs @@ -2,8 +2,8 @@ use std::ops::{Deref, DerefMut}; use anyhow::{Result, anyhow}; use yazi_core::{Core, mgr::Tabs, tab::{Folder, Tab}}; -use yazi_fs::File; -use yazi_shared::{Id, Source, event::Action, url::UrlBuf}; +use yazi_fs::file::File; +use yazi_shared::{Source, event::Action, id::Id, url::UrlBuf}; use yazi_tui::Raterm; pub struct Ctx<'a> { diff --git a/yazi-actor/src/input/show.rs b/yazi-actor/src/input/show.rs index a9cb9a9c..00517668 100644 --- a/yazi-actor/src/input/show.rs +++ b/yazi-actor/src/input/show.rs @@ -1,28 +1,31 @@ use anyhow::Result; use ratatui::widgets::Padding; +use yazi_config::{THEME, YAZI}; use yazi_macro::{act, render, succ}; +use yazi_parser::input::ShowForm; use yazi_shared::data::Data; -use yazi_widgets::input::InputOpt; use crate::{Actor, Ctx}; pub struct Show; impl Actor for Show { - type Form = InputOpt; + type Form = ShowForm; const NAME: &str = "show"; - fn act(cx: &mut Ctx, mut form: Self::Form) -> Result { + fn act(cx: &mut Ctx, Self::Form { mut opt }: Self::Form) -> Result { act!(input:close, cx)?; let input = &mut cx.input; input.main_visible = true; - input.main_title = form.cfg.title.clone(); - input.main_position = form.cfg.position; + input.main_title = opt.title.clone(); + input.main_position = opt.position; - form.cfg.position = form.cfg.position.padding(Padding::uniform(1)); - input.main = yazi_widgets::input::Input::new(form)?; + opt.styles = (&THEME.input).into(); + opt.blinking = YAZI.input.cursor_blink; + opt.position = opt.position.padding(Padding::uniform(1)); + input.main = yazi_widgets::input::Input::new(opt)?; succ!(render!()); } diff --git a/yazi-actor/src/lives/core.rs b/yazi-actor/src/lives/core.rs index c3ea731f..666a219b 100644 --- a/yazi-actor/src/lives/core.rs +++ b/yazi-actor/src/lives/core.rs @@ -63,9 +63,7 @@ impl UserData for Core { b"yanked" => reuse!(yanked, super::Yanked::make(&me.mgr.yanked)), b"input" => reuse!(input, super::Input::make(&me.input)), b"which" => reuse!(which, super::Which::make(&me.which)), - b"layer" => { - reuse!(layer, Ok::<_, mlua::Error>(yazi_binding::Layer::from(me.layer()))) - } + b"layer" => reuse!(layer, Ok::<_, mlua::Error>(me.layer())), _ => Value::Nil, }) }); diff --git a/yazi-actor/src/lives/file.rs b/yazi-actor/src/lives/file.rs index bc802aa9..adca9c5f 100644 --- a/yazi-actor/src/lives/file.rs +++ b/yazi-actor/src/lives/file.rs @@ -1,7 +1,7 @@ use std::{ops::Deref, ptr}; use mlua::{AnyUserData, IntoLua, UserData, UserDataFields, UserDataMethods}; -use yazi_binding::{Range, Style}; +use yazi_binding::{Range, style::Style}; use yazi_config::THEME; use yazi_shared::{path::AsPath, url::UrlLike}; @@ -15,13 +15,13 @@ pub(super) struct File { } impl Deref for File { - type Target = yazi_fs::File; + type Target = yazi_fs::file::File; fn deref(&self) -> &Self::Target { &self.folder.files[self.idx] } } -impl AsRef for File { - fn as_ref(&self) -> &yazi_fs::File { self } +impl AsRef for File { + fn as_ref(&self) -> &yazi_fs::file::File { self } } impl File { @@ -49,7 +49,7 @@ impl File { impl UserData for File { fn add_fields>(fields: &mut F) { yazi_binding::impl_file_fields!(fields); - fields.add_cached_field("bare", |_, me| Ok(yazi_binding::File::new(&**me))); + fields.add_cached_field("bare", |_, me| Ok(yazi_fs::file::File::from(&**me))); fields.add_field_method_get("idx", |_, me| Ok(me.idx + 1)); fields.add_field_method_get("is_hovered", |_, me| Ok(me.is_hovered())); @@ -63,9 +63,8 @@ impl UserData for File { yazi_binding::impl_file_methods!(methods); methods.add_method("icon", |_, me, ()| { - use yazi_binding::Icon; // TODO: use a cache - Ok(yazi_config::THEME.icon.matches(me, me.is_hovered()).map(Icon::from)) + Ok(yazi_config::THEME.icon.matches(me, me.is_hovered())) }); methods.add_method("size", |_, me, ()| { Ok(if me.is_dir() { me.folder.files.sizes.get(&me.urn()).copied() } else { Some(me.len) }) diff --git a/yazi-actor/src/lives/folder.rs b/yazi-actor/src/lives/folder.rs index c6f59d6e..e7fa3e38 100644 --- a/yazi-actor/src/lives/folder.rs +++ b/yazi-actor/src/lives/folder.rs @@ -1,7 +1,6 @@ use std::ops::{Deref, Range}; use mlua::{AnyUserData, UserData, UserDataFields}; -use yazi_binding::{FolderStage, Url}; use yazi_config::LAYOUT; use yazi_shim::mlua::UserDataFieldsExt; @@ -39,9 +38,9 @@ impl Folder { impl UserData for Folder { fn add_fields>(fields: &mut F) { - fields.add_cached_field("cwd", |_, me| Ok(Url::new(&me.url))); + fields.add_cached_field("cwd", |_, me| Ok(me.url.clone())); fields.add_static_field("files", |_, me| Files::make(0..me.files.len(), me, &me.tab)); - fields.add_cached_field("stage", |_, me| Ok(FolderStage::new(me.stage.clone()))); + fields.add_cached_field("stage", |_, me| Ok(me.stage.clone())); fields.add_static_field("window", |_, me| Files::make(me.window.clone(), me, &me.tab)); fields.add_field_method_get("offset", |_, me| Ok(me.offset)); diff --git a/yazi-actor/src/lives/lives.rs b/yazi-actor/src/lives/lives.rs index 91db36c0..64b8046f 100644 --- a/yazi-actor/src/lives/lives.rs +++ b/yazi-actor/src/lives/lives.rs @@ -10,8 +10,9 @@ use super::{Core, PtrCell}; use crate::lives::MutCell; pub(super) static TO_DESTROY: MutCell> = MutCell::new(Vec::new()); -pub(super) static FILE_CACHE: MutCell, AnyUserData>>> = - MutCell::new(MaybeUninit::uninit()); +pub(super) static FILE_CACHE: MutCell< + MaybeUninit, AnyUserData>>, +> = MutCell::new(MaybeUninit::uninit()); pub struct Lives; diff --git a/yazi-actor/src/lives/selected.rs b/yazi-actor/src/lives/selected.rs index 2956dd37..68694257 100644 --- a/yazi-actor/src/lives/selected.rs +++ b/yazi-actor/src/lives/selected.rs @@ -1,4 +1,5 @@ use mlua::AnyUserData; +use yazi_shared::url::UrlBuf; use super::Lives; use crate::lives::PtrCell; @@ -11,7 +12,7 @@ impl Selected { let inner = PtrCell::from(inner); Lives::scoped_userdata(yazi_binding::Iter::new( - inner.as_static().values().map(yazi_binding::Url::new), + inner.as_static().values().map(UrlBuf::from), Some(inner.len()), )) } diff --git a/yazi-actor/src/lives/tab.rs b/yazi-actor/src/lives/tab.rs index 33571779..af7e8ba8 100644 --- a/yazi-actor/src/lives/tab.rs +++ b/yazi-actor/src/lives/tab.rs @@ -1,7 +1,7 @@ use std::{borrow::Cow, ops::Deref}; use mlua::{AnyUserData, UserData, UserDataFields, UserDataMethods}; -use yazi_binding::{Id, UrlRef}; +use yazi_shared::url::UrlRef; use yazi_shim::mlua::UserDataFieldsExt; use super::{Finder, Folder, Lives, Mode, Preference, Preview, PtrCell, Selected}; @@ -24,7 +24,7 @@ impl Tab { impl UserData for Tab { fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); + fields.add_field_method_get("id", |_, me| Ok(me.id)); fields.add_cached_field("name", |lua, me| match me.name() { Cow::Borrowed(s) => lua.create_string(s), Cow::Owned(s) => lua.create_external_string(s), diff --git a/yazi-actor/src/lives/task.rs b/yazi-actor/src/lives/task.rs index ca465a01..964a2f63 100644 --- a/yazi-actor/src/lives/task.rs +++ b/yazi-actor/src/lives/task.rs @@ -1,9 +1,8 @@ use std::ops::Deref; use mlua::{AnyUserData, LuaSerdeExt, UserData, UserDataFields}; -use yazi_binding::SER_OPT; use yazi_scheduler::Progress; -use yazi_shim::mlua::UserDataFieldsExt; +use yazi_shim::mlua::{SER_OPT, UserDataFieldsExt}; use super::{Lives, PtrCell}; diff --git a/yazi-actor/src/lives/tasks.rs b/yazi-actor/src/lives/tasks.rs index d6c31dce..b00cf715 100644 --- a/yazi-actor/src/lives/tasks.rs +++ b/yazi-actor/src/lives/tasks.rs @@ -1,8 +1,7 @@ use std::ops::Deref; use mlua::{AnyUserData, LuaSerdeExt, UserData, UserDataFields}; -use yazi_binding::SER_OPT; -use yazi_shim::mlua::UserDataFieldsExt; +use yazi_shim::mlua::{SER_OPT, UserDataFieldsExt}; use super::{Lives, PtrCell}; use crate::lives::{Behavior, TaskSnap}; diff --git a/yazi-actor/src/lives/which.rs b/yazi-actor/src/lives/which.rs index eaa90e43..3e80cb7f 100644 --- a/yazi-actor/src/lives/which.rs +++ b/yazi-actor/src/lives/which.rs @@ -26,7 +26,7 @@ impl UserData for Which { fields.add_cached_field("tx", |_, me| Ok(me.tx.clone().map(yazi_binding::MpscUnboundedTx))); fields.add_field_method_get("times", |_, me| Ok(me.inner.times)); fields.add_cached_field("cands", |lua, me| { - lua.create_sequence_from(me.inner.cands.iter().map(yazi_binding::keymap::Chord::from)) + lua.create_sequence_from(me.inner.cands.iter().cloned()) }); fields.add_field_method_get("active", |_, me| Ok(me.inner.active)); diff --git a/yazi-actor/src/lives/yanked.rs b/yazi-actor/src/lives/yanked.rs index d5b9ee92..1f30826c 100644 --- a/yazi-actor/src/lives/yanked.rs +++ b/yazi-actor/src/lives/yanked.rs @@ -1,7 +1,9 @@ use std::ops::Deref; use mlua::{AnyUserData, MetaMethod, MultiValue, ObjectLike, UserData, UserDataFields, UserDataMethods}; -use yazi_binding::{Iter, get_metatable}; +use yazi_binding::Iter; +use yazi_shared::url::UrlBuf; +use yazi_shim::mlua::get_metatable; use super::{Lives, PtrCell}; @@ -23,7 +25,7 @@ impl Yanked { Lives::scoped_userdata(Self { inner, iter: Lives::scoped_userdata(Iter::new( - inner.as_static().iter().map(yazi_binding::Url::new), + inner.as_static().iter().map(UrlBuf::from), Some(inner.len()), ))?, }) diff --git a/yazi-actor/src/mgr/bulk_create.rs b/yazi-actor/src/mgr/bulk_create.rs index 1b6defa0..e96f59c3 100644 --- a/yazi-actor/src/mgr/bulk_create.rs +++ b/yazi-actor/src/mgr/bulk_create.rs @@ -1,18 +1,18 @@ -use std::{fmt::{self, Display}, io::{self, Read, Write}, path::{MAIN_SEPARATOR, Path}, sync::Arc}; +use std::{fmt::{self, Display}, io::{self, Read, Write}, path::{MAIN_SEPARATOR, Path}}; use anyhow::{Result, anyhow}; use scopeguard::defer; use yazi_binding::Permit; -use yazi_config::{YAZI, opener::OpenerRule}; -use yazi_fs::{File, FilesOp, Splatter, provider::{Provider, local::Local}}; +use yazi_config::{YAZI, opener::OpenerRuleArc}; +use yazi_fs::{FilesOp, Splatter, file::File, provider::{Provider, local::Local}}; use yazi_macro::{succ, writef}; use yazi_parser::VoidForm; use yazi_proxy::TasksProxy; use yazi_scheduler::{AppProxy, NotifyProxy}; use yazi_shared::{data::Data, strand::Strand, url::{AsUrl, UrlBuf, UrlCow, UrlLike}}; use yazi_shim::path::CROSS_SEPARATOR; -use yazi_term::{YIELD_TO_SUBPROCESS, sequence::EraseScreen}; -use yazi_tty::TTY; +use yazi_term::YIELD_TO_SUBPROCESS; +use yazi_tty::{TTY, sequence::EraseScreen}; use yazi_vfs::{VfsFile, provider}; use yazi_watcher::WATCHER; @@ -106,7 +106,7 @@ impl BulkCreate { Ok(()) } - fn opener() -> Option> { + fn opener() -> Option { YAZI .open .match_dummy(Path::new("bulk-create.txt"), "text/plain") diff --git a/yazi-actor/src/mgr/bulk_rename.rs b/yazi-actor/src/mgr/bulk_rename.rs index b472aa44..0bd71e9b 100644 --- a/yazi-actor/src/mgr/bulk_rename.rs +++ b/yazi-actor/src/mgr/bulk_rename.rs @@ -1,20 +1,20 @@ -use std::{hash::Hash, io::{Read, Write}, ops::Deref, path::Path, sync::Arc}; +use std::{hash::Hash, io::{Read, Write}, ops::Deref, path::Path}; use anyhow::{Result, anyhow}; use hashbrown::HashMap; use scopeguard::defer; use tokio::io::AsyncWriteExt; use yazi_binding::Permit; -use yazi_config::{YAZI, opener::OpenerRule}; +use yazi_config::{YAZI, opener::OpenerRuleArc}; use yazi_dds::Pubsub; -use yazi_fs::{File, FilesOp, Splatter, max_common_root, path::skip_url, provider::{FileBuilder, Provider, local::{Gate, Local}}}; +use yazi_fs::{FilesOp, Splatter, file::File, max_common_root, path::skip_url, provider::{FileBuilder, Provider, local::{Gate, Local}}}; use yazi_macro::{err, succ, writef}; use yazi_parser::VoidForm; use yazi_proxy::TasksProxy; use yazi_scheduler::{AppProxy, NotifyProxy}; use yazi_shared::{data::Data, path::PathDyn, strand::{AsStrand, AsStrandJoin, Strand, StrandBuf, StrandLike}, url::{AsUrl, UrlBuf, UrlCow, UrlLike}}; -use yazi_term::{YIELD_TO_SUBPROCESS, sequence::EraseScreen}; -use yazi_tty::TTY; +use yazi_term::YIELD_TO_SUBPROCESS; +use yazi_tty::{TTY, sequence::EraseScreen}; use yazi_vfs::{VfsFile, maybe_exists, provider}; use yazi_watcher::WATCHER; @@ -152,7 +152,7 @@ impl BulkRename { Ok(()) } - fn opener() -> Option> { + fn opener() -> Option { YAZI .open .match_dummy(Path::new("bulk-rename.txt"), "text/plain") diff --git a/yazi-actor/src/mgr/cd.rs b/yazi-actor/src/mgr/cd.rs index 7192af9b..11da268d 100644 --- a/yazi-actor/src/mgr/cd.rs +++ b/yazi-actor/src/mgr/cd.rs @@ -3,10 +3,10 @@ use std::{mem, time::Duration}; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_core::mgr::CdSource; use yazi_dds::Pubsub; -use yazi_fs::{File, FilesOp, path::{clean_url, expand_url}}; +use yazi_fs::{FilesOp, file::File, path::{clean_url, expand_url}}; use yazi_macro::{act, err, input, render, succ}; use yazi_parser::mgr::CdForm; use yazi_proxy::{CmpProxy, MgrProxy}; @@ -63,7 +63,7 @@ impl Actor for Cd { impl Cd { fn cd_interactive(cx: &mut Ctx) -> Result { - let input = input!(cx, InputCfg::cd(cx.cwd().as_url()))?; + let input = input!(cx, YAZI.input.cd(cx.cwd().as_url()))?; tokio::spawn(async move { let rx = Debounce::new(UnboundedReceiverStream::new(input), Duration::from_millis(50)); diff --git a/yazi-actor/src/mgr/create.rs b/yazi-actor/src/mgr/create.rs index f1c7d2f1..08c6b027 100644 --- a/yazi-actor/src/mgr/create.rs +++ b/yazi-actor/src/mgr/create.rs @@ -1,6 +1,6 @@ use anyhow::{Result, bail}; -use yazi_config::popup::{ConfirmCfg, InputCfg}; -use yazi_fs::{File, FilesOp}; +use yazi_config::{YAZI, popup::ConfirmCfg}; +use yazi_fs::{FilesOp, file::File}; use yazi_macro::{input, ok_or_not_found, succ}; use yazi_parser::mgr::CreateForm; use yazi_proxy::{ConfirmProxy, MgrProxy}; @@ -20,7 +20,7 @@ impl Actor for Create { fn act(cx: &mut Ctx, form: Self::Form) -> Result { let cwd = cx.cwd().to_owned(); - let mut input = input!(cx, InputCfg::create(form.dir))?; + let mut input = input!(cx, YAZI.input.create(form.dir))?; tokio::spawn(async move { let Some(InputEvent::Submit(name)) = input.recv().await else { return }; diff --git a/yazi-actor/src/mgr/download.rs b/yazi-actor/src/mgr/download.rs index 8e9c174e..61b02d8a 100644 --- a/yazi-actor/src/mgr/download.rs +++ b/yazi-actor/src/mgr/download.rs @@ -4,7 +4,7 @@ use anyhow::Result; use futures::{StreamExt, stream::FuturesUnordered}; use hashbrown::HashSet; use yazi_core::mgr::OpenOpt; -use yazi_fs::{File, FsScheme, provider::{Provider, local::Local}}; +use yazi_fs::{FsScheme, file::File, provider::{Provider, local::Local}}; use yazi_macro::succ; use yazi_parser::mgr::DownloadForm; use yazi_proxy::MgrProxy; diff --git a/yazi-actor/src/mgr/filter.rs b/yazi-actor/src/mgr/filter.rs index dd070369..ade4752f 100644 --- a/yazi-actor/src/mgr/filter.rs +++ b/yazi-actor/src/mgr/filter.rs @@ -3,7 +3,7 @@ use std::time::Duration; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_core::mgr::FilterOpt; use yazi_macro::{input, succ}; use yazi_parser::mgr::FilterForm; @@ -21,7 +21,7 @@ impl Actor for Filter { const NAME: &str = "filter"; fn act(cx: &mut Ctx, Self::Form { opt }: Self::Form) -> Result { - let input = input!(cx, InputCfg::filter())?; + let input = input!(cx, YAZI.input.filter())?; tokio::spawn(async move { let rx = Debounce::new(UnboundedReceiverStream::new(input), Duration::from_millis(50)); diff --git a/yazi-actor/src/mgr/find.rs b/yazi-actor/src/mgr/find.rs index 8d1bcaf9..262df048 100644 --- a/yazi-actor/src/mgr/find.rs +++ b/yazi-actor/src/mgr/find.rs @@ -3,7 +3,7 @@ use std::time::Duration; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_core::mgr::FindDoOpt; use yazi_macro::{input, succ}; use yazi_parser::mgr::FindForm; @@ -21,7 +21,7 @@ impl Actor for Find { const NAME: &str = "find"; fn act(cx: &mut Ctx, form: Self::Form) -> Result { - let input = input!(cx, InputCfg::find(form.prev))?; + let input = input!(cx, YAZI.input.find(form.prev))?; tokio::spawn(async move { let rx = Debounce::new(UnboundedReceiverStream::new(input), Duration::from_millis(50)); diff --git a/yazi-actor/src/mgr/open.rs b/yazi-actor/src/mgr/open.rs index 4a39468c..2d789ed0 100644 --- a/yazi-actor/src/mgr/open.rs +++ b/yazi-actor/src/mgr/open.rs @@ -3,7 +3,7 @@ use futures::StreamExt; use hashbrown::HashSet; use yazi_boot::ARGS; use yazi_core::mgr::OpenDoOpt; -use yazi_fs::File; +use yazi_fs::file::File; use yazi_macro::{act, succ}; use yazi_parser::mgr::OpenForm; use yazi_proxy::MgrProxy; diff --git a/yazi-actor/src/mgr/open_do.rs b/yazi-actor/src/mgr/open_do.rs index defae85b..253151fb 100644 --- a/yazi-actor/src/mgr/open_do.rs +++ b/yazi-actor/src/mgr/open_do.rs @@ -1,7 +1,8 @@ use anyhow::Result; use hashbrown::HashMap; use indexmap::IndexSet; -use yazi_config::{YAZI, popup::PickCfg}; +use yazi_config::YAZI; +use yazi_fs::file::File; use yazi_macro::succ; use yazi_parser::mgr::OpenDoForm; use yazi_proxy::{PickProxy, TasksProxy}; @@ -40,7 +41,7 @@ impl Actor for OpenDo { succ!(); } - let pick = PickProxy::show(PickCfg::open(openers.iter().map(|o| o.desc()).collect())); + let pick = PickProxy::show(YAZI.pick.open(openers.iter().map(|o| o.desc()).collect())); let urls: Vec<_> = [UrlCow::default()] .into_iter() .chain(targets.into_iter().map(|(file, _)| file.url.into())) @@ -63,7 +64,7 @@ impl Actor for OpenDo { impl OpenDo { // TODO: remove - fn match_and_open(cx: &Ctx, cwd: UrlBuf, targets: Vec<(yazi_fs::File, &str)>) { + fn match_and_open(cx: &Ctx, cwd: UrlBuf, targets: Vec<(File, &str)>) { let mut openers = HashMap::new(); for (file, mime) in targets { if let Some(open) = YAZI.open.matches(&file, mime) diff --git a/yazi-actor/src/mgr/rename.rs b/yazi-actor/src/mgr/rename.rs index 1d956406..22d54467 100644 --- a/yazi-actor/src/mgr/rename.rs +++ b/yazi-actor/src/mgr/rename.rs @@ -1,11 +1,11 @@ use anyhow::Result; -use yazi_config::popup::{ConfirmCfg, InputCfg}; +use yazi_config::{YAZI, popup::ConfirmCfg}; use yazi_dds::Pubsub; -use yazi_fs::{File, FilesOp}; +use yazi_fs::{FilesOp, file::File}; use yazi_macro::{act, err, input, ok_or_not_found, succ}; use yazi_parser::mgr::RenameForm; use yazi_proxy::{ConfirmProxy, MgrProxy}; -use yazi_shared::{Id, data::Data, url::{UrlBuf, UrlLike}}; +use yazi_shared::{data::Data, id::Id, url::{UrlBuf, UrlLike}}; use yazi_vfs::{VfsFile, maybe_exists, provider}; use yazi_watcher::WATCHER; use yazi_widgets::input::InputEvent; @@ -42,7 +42,7 @@ impl Actor for Rename { }; let (tab, old) = (cx.tab().id, hovered.url_owned()); - let mut input = input!(cx, InputCfg::rename().with_value(name).with_cursor(cursor))?; + let mut input = input!(cx, YAZI.input.rename().with_value(name).with_cursor(cursor))?; tokio::spawn(async move { let Some(InputEvent::Submit(name)) = input.recv().await else { return }; diff --git a/yazi-actor/src/mgr/reveal.rs b/yazi-actor/src/mgr/reveal.rs index bc83fdfd..e7133d06 100644 --- a/yazi-actor/src/mgr/reveal.rs +++ b/yazi-actor/src/mgr/reveal.rs @@ -1,5 +1,5 @@ use anyhow::Result; -use yazi_fs::{File, FilesOp}; +use yazi_fs::{FilesOp, file::File}; use yazi_macro::{act, render, succ}; use yazi_parser::mgr::RevealForm; use yazi_shared::{data::Data, url::UrlLike}; diff --git a/yazi-actor/src/mgr/search.rs b/yazi-actor/src/mgr/search.rs index 9602490b..70b380a8 100644 --- a/yazi-actor/src/mgr/search.rs +++ b/yazi-actor/src/mgr/search.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, time::Duration}; use anyhow::Result; use tokio::pin; use tokio_stream::{StreamExt, wrappers::UnboundedReceiverStream}; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_core::mgr::{CdSource, SearchVia}; use yazi_fs::{FilesOp, cha::Cha}; use yazi_macro::{act, input, succ}; @@ -28,7 +28,7 @@ impl Actor for Search { handle.abort(); } - let mut input = input!(cx, InputCfg::search(opt.via.into()).with_value(&*opt.subject))?; + let mut input = input!(cx, YAZI.input.search(opt.via.into()).with_value(&*opt.subject))?; tokio::spawn(async move { if let Some(InputEvent::Submit(subject)) = input.recv().await { diff --git a/yazi-actor/src/mgr/shell.rs b/yazi-actor/src/mgr/shell.rs index f935b359..33fb79c3 100644 --- a/yazi-actor/src/mgr/shell.rs +++ b/yazi-actor/src/mgr/shell.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use anyhow::Result; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_macro::{act, input, succ}; use yazi_parser::mgr::ShellForm; use yazi_proxy::TasksProxy; @@ -25,7 +25,10 @@ impl Actor for Shell { let selected: Vec<_> = cx.tab().hovered_and_selected().cloned().map(Into::into).collect(); let input = if form.interactive { - Some(input!(cx, InputCfg::shell(form.block).with_value(&*form.run).with_cursor(form.cursor))?) + Some(input!( + cx, + YAZI.input.shell(form.block).with_value(&*form.run).with_cursor(form.cursor) + )?) } else { None }; diff --git a/yazi-actor/src/mgr/tab_rename.rs b/yazi-actor/src/mgr/tab_rename.rs index 238c5067..7a037129 100644 --- a/yazi-actor/src/mgr/tab_rename.rs +++ b/yazi-actor/src/mgr/tab_rename.rs @@ -1,7 +1,7 @@ use std::borrow::Cow; use anyhow::Result; -use yazi_config::popup::InputCfg; +use yazi_config::YAZI; use yazi_macro::{act, input, render, succ}; use yazi_parser::mgr::TabRenameForm; use yazi_proxy::MgrProxy; @@ -29,7 +29,7 @@ impl Actor for TabRename { let mut input = input!( cx, - InputCfg::tab_rename().with_value(form.name.unwrap_or(Cow::Borrowed(&pref.name))) + YAZI.input.tab_rename().with_value(form.name.unwrap_or(Cow::Borrowed(&pref.name))) )?; tokio::spawn(async move { diff --git a/yazi-actor/src/tasks/inspect.rs b/yazi-actor/src/tasks/inspect.rs index a7824471..e3606cd0 100644 --- a/yazi-actor/src/tasks/inspect.rs +++ b/yazi-actor/src/tasks/inspect.rs @@ -8,8 +8,8 @@ use yazi_macro::{succ, writef}; use yazi_parser::VoidForm; use yazi_scheduler::AppProxy; use yazi_shared::data::Data; -use yazi_term::{TERM, YIELD_TO_SUBPROCESS, sequence::EraseScreen}; -use yazi_tty::TTY; +use yazi_term::{TERM, YIELD_TO_SUBPROCESS}; +use yazi_tty::{TTY, sequence::EraseScreen}; use crate::{Actor, Ctx}; diff --git a/yazi-adapter/Cargo.toml b/yazi-adapter/Cargo.toml index f3acea37..db923d82 100644 --- a/yazi-adapter/Cargo.toml +++ b/yazi-adapter/Cargo.toml @@ -19,14 +19,15 @@ yazi-fs = { path = "../yazi-fs", version = "26.5.6" } yazi-macro = { path = "../yazi-macro", version = "26.5.6" } yazi-shared = { path = "../yazi-shared", version = "26.5.6" } yazi-shim = { path = "../yazi-shim", version = "26.5.6" } -yazi-term = { path = "../yazi-term", version = "26.5.6" } yazi-tty = { path = "../yazi-tty", version = "26.5.9" } +yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" } # External dependencies ansi-to-tui = { workspace = true } anyhow = { workspace = true } base64 = { workspace = true } -image = { version = "0.25.10", default-features = false, features = [ "avif", "bmp", "dds", "exr", "ff", "gif", "hdr", "ico", "jpeg", "png", "pnm", "qoi", "tga", "tiff", "webp" ] } +image = { workspace = true } +inventory = { workspace = true } moxcms = "0.8.1" palette = { version = "0.7.6", default-features = false } quantette = { version = "0.6.0", default-features = false } diff --git a/yazi-adapter/src/adapter.rs b/yazi-adapter/src/adapter.rs index f3fc75b2..72953de4 100644 --- a/yazi-adapter/src/adapter.rs +++ b/yazi-adapter/src/adapter.rs @@ -1,105 +1,56 @@ -use std::{env, path::PathBuf}; +use std::{fmt::{self, Debug}, ops::Deref}; use anyhow::Result; use ratatui::layout::Rect; -use strum::{Display, IntoStaticStr}; -use tracing::warn; -use yazi_emulator::{Emulator, TMUX}; -use yazi_shared::env_exists; +use yazi_emulator::EMULATOR; +use yazi_shim::cell::SyncCell; +use yazi_widgets::clear::ClearInventory; -use crate::{Adapters, SHOWN, drivers}; +use crate::{ADAPTOR, drivers::{Driver, Drivers}}; -#[derive(Clone, Copy, Debug, Display, Eq, IntoStaticStr, PartialEq)] -#[strum(serialize_all = "kebab-case")] -pub enum Adapter { - Kgp, - KgpOld, - Iip, - Sixel, +pub struct Adapter { + driver: Driver, + shown: SyncCell>, + pub collision: SyncCell, +} - // Supported by Überzug++ - X11, - Wayland, - Chafa, +impl Deref for Adapter { + type Target = Driver; + + fn deref(&self) -> &Self::Target { &self.driver } +} + +impl Debug for Adapter { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.driver.fmt(f) } } impl Adapter { - pub async fn image_show

(self, path: P, max: Rect) -> Result - where - P: Into, - { - if max.is_empty() { - return Ok(Rect::default()); - } - - let path = path.into(); - match self { - Self::Kgp => drivers::Kgp::image_show(path, max).await, - Self::KgpOld => drivers::KgpOld::image_show(path, max).await, - Self::Iip => drivers::Iip::image_show(path, max).await, - Self::Sixel => drivers::Sixel::image_show(path, max).await, - Self::X11 | Self::Wayland => drivers::Ueberzug::image_show(path, max).await, - Self::Chafa => drivers::Chafa::image_show(path, max).await, + pub(super) fn new() -> Self { + Self { + driver: Drivers::matches(&EMULATOR), + shown: SyncCell::new(None), + collision: SyncCell::new(false), } } - pub fn image_hide(self) -> Result<()> { - if let Some(area) = SHOWN.replace(None) { self.image_erase(area) } else { Ok(()) } + pub fn image_hide(&self) -> Result<()> { + if let Some(area) = self.shown.replace(None) { self.driver.image_erase(area) } else { Ok(()) } } - pub fn image_erase(self, area: Rect) -> Result<()> { - match self { - Self::Kgp => drivers::Kgp::image_erase(area), - Self::KgpOld => drivers::KgpOld::image_erase(area), - Self::Iip => drivers::Iip::image_erase(area), - Self::Sixel => drivers::Sixel::image_erase(area), - Self::X11 | Self::Wayland => drivers::Ueberzug::image_erase(area), - Self::Chafa => drivers::Chafa::image_erase(area), - } - } - - #[inline] - pub fn shown_load(self) -> Option { SHOWN.get() } - - #[inline] - pub(super) fn shown_store(area: Rect) { SHOWN.set(Some(area)); } - - pub(super) fn start(self) { drivers::Ueberzug::start(self); } - - #[inline] - pub(super) fn needs_ueberzug(self) -> bool { - !matches!(self, Self::Kgp | Self::KgpOld | Self::Iip | Self::Sixel) - } + pub(super) fn shown_store(&self, area: Rect) { self.shown.set(Some(area)); } } -impl Adapter { - pub fn matches(emulator: &Emulator) -> Self { - let mut adapters: Adapters = emulator.into(); - if env_exists("ZELLIJ_SESSION_NAME") { - adapters.retain(|p| *p == Self::Sixel); - } else if TMUX.get() { - adapters.retain(|p| *p != Self::KgpOld); - } - if let Some(p) = adapters.first() { - return *p; - } +inventory::submit! { + ClearInventory { + clear: |area| { + let overlap = area.intersection(ADAPTOR.shown.get()?); + if overlap.area() == 0 { + return None; + } - let supported_compositor = drivers::Ueberzug::supported_compositor(); - match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() { - "x11" => return Self::X11, - "wayland" if supported_compositor => return Self::Wayland, - "wayland" if !supported_compositor => return Self::Chafa, - _ => warn!("[Adapter] Could not identify XDG_SESSION_TYPE"), - } - if env_exists("WAYLAND_DISPLAY") { - return if supported_compositor { Self::Wayland } else { Self::Chafa }; - } - match env::var("DISPLAY").unwrap_or_default().as_str() { - s if !s.is_empty() && !s.contains("/org.xquartz") => return Self::X11, - _ => {} - } - - warn!("[Adapter] Falling back to chafa"); - Self::Chafa + ADAPTOR.driver.image_erase(overlap).ok(); + ADAPTOR.collision.set(true); + Some(overlap) + }, } } diff --git a/yazi-adapter/src/adapters.rs b/yazi-adapter/src/adapters.rs deleted file mode 100644 index 77912c41..00000000 --- a/yazi-adapter/src/adapters.rs +++ /dev/null @@ -1,62 +0,0 @@ -use std::ops::{Deref, DerefMut}; - -use crate::Adapter; - -pub(super) struct Adapters(Vec); - -impl Deref for Adapters { - type Target = Vec; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl DerefMut for Adapters { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } -} - -impl From<&yazi_emulator::Emulator> for Adapters { - fn from(value: &yazi_emulator::Emulator) -> Self { value.kind.either_into() } -} - -impl From for Adapters { - fn from(value: yazi_emulator::Brand) -> Self { - use yazi_emulator::Brand as B; - - use crate::Adapter as A; - - Self(match value { - B::Kitty => vec![A::Kgp], - B::Konsole => vec![A::KgpOld], - B::Iterm2 => vec![A::Iip, A::Sixel], - B::WezTerm => vec![A::Iip, A::Sixel], - B::Foot => vec![A::Sixel], - B::Ghostty => vec![A::Kgp], - B::Microsoft => vec![A::Sixel], - B::Warp => vec![A::Iip, A::KgpOld], - B::Rio => vec![A::Kgp], - B::BlackBox => vec![A::Sixel], - B::VSCode => vec![A::Iip, A::Sixel], - B::Tabby => vec![A::Iip, A::Sixel], - B::Hyper => vec![A::Iip, A::Sixel], - B::Mintty => vec![A::Iip], - B::Tmux => vec![], - B::VTerm => vec![], - B::Apple => vec![], - B::Urxvt => vec![], - B::Bobcat => vec![A::Iip, A::Sixel], - }) - } -} - -impl From for Adapters { - fn from(value: yazi_emulator::Unknown) -> Self { - use Adapter as A; - - Self(match (value.kgp, value.sixel) { - (true, true) => vec![A::Sixel, A::KgpOld], - (true, false) => vec![A::KgpOld], - (false, true) => vec![A::Sixel], - (false, false) => vec![], - }) - } -} diff --git a/yazi-adapter/src/drivers/chafa.rs b/yazi-adapter/src/drivers/chafa.rs index 9b13e96d..2bdbf445 100644 --- a/yazi-adapter/src/drivers/chafa.rs +++ b/yazi-adapter/src/drivers/chafa.rs @@ -6,14 +6,14 @@ use ratatui::layout::Rect; use tokio::process::Command; use yazi_config::THEME; use yazi_emulator::Emulator; -use yazi_term::sequence::{MoveTo, ResetAttrs, SetBg}; +use yazi_tty::sequence::{MoveTo, ResetAttrs, SetBg}; -use crate::Adapter; +use crate::ADAPTOR; -pub(crate) struct Chafa; +pub(super) struct Chafa; impl Chafa { - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let child = Command::new("chafa") .args([ "-f", @@ -58,8 +58,8 @@ impl Chafa { height: lines.len() as u16, }; - Adapter::Chafa.image_hide()?; - Adapter::shown_store(area); + ADAPTOR.image_hide()?; + ADAPTOR.shown_store(area); Emulator::move_lock((max.x, max.y), |w| { for (i, line) in lines.into_iter().enumerate() { w.write_all(line)?; @@ -69,7 +69,7 @@ impl Chafa { }) } - pub(crate) fn image_erase(area: Rect) -> Result<()> { + pub(super) fn image_erase(area: Rect) -> Result<()> { let s = " ".repeat(area.width as usize); Emulator::move_lock((0, 0), |w| { if let Some(c) = THEME.app.overall.get().bg { diff --git a/yazi-adapter/src/drivers/driver.rs b/yazi-adapter/src/drivers/driver.rs new file mode 100644 index 00000000..3764b1fb --- /dev/null +++ b/yazi-adapter/src/drivers/driver.rs @@ -0,0 +1,59 @@ +use std::path::PathBuf; + +use anyhow::Result; +use ratatui::layout::Rect; +use strum::{Display, IntoStaticStr}; + +use crate::drivers::{Chafa, Iip, Kgp, KgpOld, Sixel, Ueberzug}; + +#[derive(Clone, Copy, Debug, Display, Eq, IntoStaticStr, PartialEq)] +#[strum(serialize_all = "kebab-case")] +pub enum Driver { + Kgp, + KgpOld, + Iip, + Sixel, + + // Supported by Überzug++ + X11, + Wayland, + Chafa, +} + +impl Driver { + pub async fn image_show

(self, path: P, max: Rect) -> Result + where + P: Into, + { + if max.is_empty() { + return Ok(Rect::default()); + } + + let path = path.into(); + match self { + Self::Kgp => Kgp::image_show(path, max).await, + Self::KgpOld => KgpOld::image_show(path, max).await, + Self::Iip => Iip::image_show(path, max).await, + Self::Sixel => Sixel::image_show(path, max).await, + Self::X11 | Self::Wayland => Ueberzug::image_show(path, max).await, + Self::Chafa => Chafa::image_show(path, max).await, + } + } + + pub fn image_erase(self, area: Rect) -> Result<()> { + match self { + Self::Kgp => Kgp::image_erase(area), + Self::KgpOld => KgpOld::image_erase(area), + Self::Iip => Iip::image_erase(area), + Self::Sixel => Sixel::image_erase(area), + Self::X11 | Self::Wayland => Ueberzug::image_erase(area), + Self::Chafa => Chafa::image_erase(area), + } + } + + pub(crate) fn start(self) { Ueberzug::start(self); } + + pub(crate) fn needs_ueberzug(self) -> bool { + !matches!(self, Self::Kgp | Self::KgpOld | Self::Iip | Self::Sixel) + } +} diff --git a/yazi-adapter/src/drivers/drivers.rs b/yazi-adapter/src/drivers/drivers.rs new file mode 100644 index 00000000..ed442005 --- /dev/null +++ b/yazi-adapter/src/drivers/drivers.rs @@ -0,0 +1,94 @@ +use std::{env, ops::{Deref, DerefMut}}; + +use tracing::warn; +use yazi_emulator::{Emulator, TMUX}; +use yazi_shared::env_exists; + +use crate::drivers::{Driver as D, Ueberzug}; + +pub(crate) struct Drivers(Vec); + +impl Deref for Drivers { + type Target = Vec; + + fn deref(&self) -> &Self::Target { &self.0 } +} + +impl DerefMut for Drivers { + fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } +} + +impl From<&yazi_emulator::Emulator> for Drivers { + fn from(value: &yazi_emulator::Emulator) -> Self { value.kind.either_into() } +} + +impl From for Drivers { + fn from(value: yazi_emulator::Brand) -> Self { + use yazi_emulator::Brand as B; + + Self(match value { + B::Kitty => vec![D::Kgp], + B::Konsole => vec![D::KgpOld], + B::Iterm2 => vec![D::Iip, D::Sixel], + B::WezTerm => vec![D::Iip, D::Sixel], + B::Foot => vec![D::Sixel], + B::Ghostty => vec![D::Kgp], + B::Microsoft => vec![D::Sixel], + B::Warp => vec![D::Iip, D::KgpOld], + B::Rio => vec![D::Kgp], + B::BlackBox => vec![D::Sixel], + B::VSCode => vec![D::Iip, D::Sixel], + B::Tabby => vec![D::Iip, D::Sixel], + B::Hyper => vec![D::Iip, D::Sixel], + B::Mintty => vec![D::Iip], + B::Tmux => vec![], + B::VTerm => vec![], + B::Apple => vec![], + B::Urxvt => vec![], + B::Bobcat => vec![D::Iip, D::Sixel], + }) + } +} + +impl From for Drivers { + fn from(value: yazi_emulator::Unknown) -> Self { + Self(match (value.kgp, value.sixel) { + (true, true) => vec![D::Sixel, D::KgpOld], + (true, false) => vec![D::KgpOld], + (false, true) => vec![D::Sixel], + (false, false) => vec![], + }) + } +} + +impl Drivers { + pub fn matches(emulator: &Emulator) -> D { + let mut adapters: Self = emulator.into(); + if env_exists("ZELLIJ_SESSION_NAME") { + adapters.retain(|p| *p == D::Sixel); + } else if TMUX.get() { + adapters.retain(|p| *p != D::KgpOld); + } + if let Some(p) = adapters.first() { + return *p; + } + + let supported_compositor = Ueberzug::supported_compositor(); + match env::var("XDG_SESSION_TYPE").unwrap_or_default().as_str() { + "x11" => return D::X11, + "wayland" if supported_compositor => return D::Wayland, + "wayland" if !supported_compositor => return D::Chafa, + _ => warn!("[Adapter] Could not identify XDG_SESSION_TYPE"), + } + if env_exists("WAYLAND_DISPLAY") { + return if supported_compositor { D::Wayland } else { D::Chafa }; + } + match env::var("DISPLAY").unwrap_or_default().as_str() { + s if !s.is_empty() && !s.contains("/org.xquartz") => return D::X11, + _ => {} + } + + warn!("[Adapter] Falling back to chafa"); + D::Chafa + } +} diff --git a/yazi-adapter/src/drivers/iip.rs b/yazi-adapter/src/drivers/iip.rs index 33f99bd9..7968f4dd 100644 --- a/yazi-adapter/src/drivers/iip.rs +++ b/yazi-adapter/src/drivers/iip.rs @@ -6,27 +6,27 @@ use image::{DynamicImage, ExtendedColorType, ImageEncoder, codecs::{jpeg::JpegEn use ratatui::layout::Rect; use yazi_config::{THEME, YAZI}; use yazi_emulator::{CLOSE, Emulator, START}; -use yazi_term::sequence::{MoveTo, ResetAttrs, SetBg}; +use yazi_tty::sequence::{MoveTo, ResetAttrs, SetBg}; -use crate::{Image, adapter::Adapter}; +use crate::{ADAPTOR, Image}; -pub(crate) struct Iip; +pub(super) struct Iip; impl Iip { - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); let b = Self::encode(img).await?; - Adapter::Iip.image_hide()?; - Adapter::shown_store(area); + ADAPTOR.image_hide()?; + ADAPTOR.shown_store(area); Emulator::move_lock((max.x, max.y), |w| { w.write_all(&b)?; Ok(area) }) } - pub(crate) fn image_erase(area: Rect) -> Result<()> { + pub(super) fn image_erase(area: Rect) -> Result<()> { let s = " ".repeat(area.width as usize); Emulator::move_lock((0, 0), |w| { if let Some(c) = THEME.app.overall.get().bg { diff --git a/yazi-adapter/src/drivers/kgp.rs b/yazi-adapter/src/drivers/kgp.rs index e0391fbc..1a38d8d3 100644 --- a/yazi-adapter/src/drivers/kgp.rs +++ b/yazi-adapter/src/drivers/kgp.rs @@ -8,9 +8,9 @@ use ratatui::{layout::Rect, style::Color}; use yazi_config::THEME; use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; use yazi_shim::cell::SyncCell; -use yazi_term::sequence::{MoveTo, ResetAttrs, SetBg, SetFg}; +use yazi_tty::sequence::{MoveTo, ResetAttrs, SetBg, SetFg}; -use crate::{adapter::Adapter, image::Image}; +use crate::{ADAPTOR, image::Image}; static DIACRITICS: [char; 297] = [ '\u{0305}', @@ -312,18 +312,18 @@ static DIACRITICS: [char; 297] = [ '\u{1D244}', ]; -pub(crate) struct Kgp; +pub(super) struct Kgp; impl Kgp { - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); let b1 = Self::encode(img).await?; let b2 = Self::place(&area)?; - Adapter::Kgp.image_hide()?; - Adapter::shown_store(area); + ADAPTOR.image_hide()?; + ADAPTOR.shown_store(area); Emulator::move_lock((area.x, area.y), |w| { w.write_all(&b1)?; w.write_all(&b2)?; @@ -331,7 +331,7 @@ impl Kgp { }) } - pub(crate) fn image_erase(area: Rect) -> Result<()> { + pub(super) fn image_erase(area: Rect) -> Result<()> { let s = " ".repeat(area.width as usize); Emulator::move_lock((0, 0), |w| { if let Some(c) = THEME.app.overall.get().bg { diff --git a/yazi-adapter/src/drivers/kgp_old.rs b/yazi-adapter/src/drivers/kgp_old.rs index bb78103b..59842c10 100644 --- a/yazi-adapter/src/drivers/kgp_old.rs +++ b/yazi-adapter/src/drivers/kgp_old.rs @@ -8,25 +8,25 @@ use ratatui::layout::Rect; use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; use yazi_tty::TTY; -use crate::{Image, adapter::Adapter}; +use crate::{ADAPTOR, Image}; -pub(crate) struct KgpOld; +pub(super) struct KgpOld; impl KgpOld { - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); let b = Self::encode(img).await?; - Adapter::KgpOld.image_hide()?; - Adapter::shown_store(area); + ADAPTOR.image_hide()?; + ADAPTOR.shown_store(area); Emulator::move_lock((area.x, area.y), |w| { w.write_all(&b)?; Ok(area) }) } - pub(crate) fn image_erase(_: Rect) -> Result<()> { + pub(super) fn image_erase(_: Rect) -> Result<()> { let mut w = TTY.lockout(); write!(w, "{START}_Gq=2,a=d,d=A{ESCAPE}\\{CLOSE}")?; w.flush()?; diff --git a/yazi-adapter/src/drivers/mod.rs b/yazi-adapter/src/drivers/mod.rs index 57eeaf4f..20e82086 100644 --- a/yazi-adapter/src/drivers/mod.rs +++ b/yazi-adapter/src/drivers/mod.rs @@ -1 +1 @@ -yazi_macro::mod_flat!(chafa iip kgp kgp_old sixel ueberzug); +yazi_macro::mod_flat!(chafa driver drivers iip kgp kgp_old sixel ueberzug); diff --git a/yazi-adapter/src/drivers/sixel.rs b/yazi-adapter/src/drivers/sixel.rs index d774ae21..f06994ef 100644 --- a/yazi-adapter/src/drivers/sixel.rs +++ b/yazi-adapter/src/drivers/sixel.rs @@ -7,11 +7,11 @@ use quantette::{PaletteSize, color_map::IndexedColorMap, wu::{BinnerU8x3, WuU8x3 use ratatui::layout::Rect; use yazi_config::THEME; use yazi_emulator::{CLOSE, ESCAPE, Emulator, START}; -use yazi_term::sequence::{MoveTo, ResetAttrs, SetBg}; +use yazi_tty::sequence::{MoveTo, ResetAttrs, SetBg}; -use crate::{Image, adapter::Adapter}; +use crate::{ADAPTOR, Image}; -pub(crate) struct Sixel; +pub(super) struct Sixel; struct QuantizeOutput { indices: Vec, @@ -19,20 +19,20 @@ struct QuantizeOutput { } impl Sixel { - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let img = Image::downscale(path, max).await?; let area = Image::pixel_area((img.width(), img.height()), max); let b = Self::encode(img).await?; - Adapter::Sixel.image_hide()?; - Adapter::shown_store(area); + ADAPTOR.image_hide()?; + ADAPTOR.shown_store(area); Emulator::move_lock((area.x, area.y), |w| { w.write_all(&b)?; Ok(area) }) } - pub(crate) fn image_erase(area: Rect) -> Result<()> { + pub(super) fn image_erase(area: Rect) -> Result<()> { let s = " ".repeat(area.width as usize); Emulator::move_lock((0, 0), |w| { if let Some(c) = THEME.app.overall.get().bg { diff --git a/yazi-adapter/src/drivers/ueberzug.rs b/yazi-adapter/src/drivers/ueberzug.rs index 6ab4aabd..8e2dc9e0 100644 --- a/yazi-adapter/src/drivers/ueberzug.rs +++ b/yazi-adapter/src/drivers/ueberzug.rs @@ -10,21 +10,21 @@ use yazi_emulator::Dimension; use yazi_shared::{LOG_LEVEL, env_exists}; use yazi_shim::{cell::RoCell, strum::IntoStr}; -use crate::Adapter; +use crate::{ADAPTOR, drivers::Driver}; type Cmd = Option<(PathBuf, Rect)>; static DEMON: RoCell>> = RoCell::new(); -pub(crate) struct Ueberzug; +pub(super) struct Ueberzug; impl Ueberzug { - pub(crate) fn start(adapter: Adapter) { - if !adapter.needs_ueberzug() { + pub(super) fn start(driver: Driver) { + if !driver.needs_ueberzug() { return DEMON.init(None); } - let mut child = Self::create_demon(adapter).ok(); + let mut child = Self::create_demon(driver).ok(); let (tx, mut rx) = mpsc::unbounded_channel(); tokio::spawn(async move { @@ -34,17 +34,17 @@ impl Ueberzug { child = None; } if child.is_none() { - child = Self::create_demon(adapter).ok(); + child = Self::create_demon(driver).ok(); } if let Some(c) = &mut child { - Self::send_command(adapter, c, cmd).await.ok(); + Self::send_command(driver, c, cmd).await.ok(); } } }); DEMON.init(Some(tx)) } - pub(crate) async fn image_show(path: PathBuf, max: Rect) -> Result { + pub(super) async fn image_show(path: PathBuf, max: Rect) -> Result { let Some(tx) = &*DEMON else { bail!("uninitialized ueberzugpp"); }; @@ -64,11 +64,11 @@ impl Ueberzug { .unwrap_or(max); tx.send(Some((path, area)))?; - Adapter::shown_store(area); + ADAPTOR.shown_store(area); Ok(area) } - pub(crate) fn image_erase(_: Rect) -> Result<()> { + pub(super) fn image_erase(_: Rect) -> Result<()> { if let Some(tx) = &*DEMON { Ok(tx.send(None)?) } else { @@ -79,16 +79,16 @@ impl Ueberzug { // Currently Überzug++'s Wayland output only supports Niri, Sway, Hyprland and // Wayfire as it requires information from specific compositor socket directly. // These environment variables are from ueberzugpp src/canvas/wayland/config.cpp - pub(crate) fn supported_compositor() -> bool { + pub(super) fn supported_compositor() -> bool { env_exists("NIRI_SOCKET") || env_exists("SWAYSOCK") || env_exists("HYPRLAND_INSTANCE_SIGNATURE") || env_exists("WAYFIRE_SOCKET") } - fn create_demon(adapter: Adapter) -> Result { + fn create_demon(driver: Driver) -> Result { let result = Command::new("ueberzugpp") - .args(["layer", "-so", adapter.into_str()]) + .args(["layer", "-so", driver.into_str()]) .env("SPDLOG_LEVEL", if LOG_LEVEL.get().is_none() { "" } else { "debug" }) .kill_on_drop(true) .stdin(Stdio::piped()) @@ -113,7 +113,7 @@ impl Ueberzug { rect } - async fn send_command(adapter: Adapter, child: &mut Child, cmd: Cmd) -> Result<()> { + async fn send_command(driver: Driver, child: &mut Child, cmd: Cmd) -> Result<()> { let s = if let Some((path, rect)) = cmd { debug!("ueberzugpp rect before adjustment: {:?}", rect); let rect = Self::adjust_rect(rect); @@ -132,7 +132,7 @@ impl Ueberzug { format!(r#"{{"action":"remove","identifier":"yazi"}}{}"#, '\n') }; - debug!("`ueberzugpp layer -so {adapter}` command: {s}"); + debug!("`ueberzugpp layer -so {driver}` command: {s}"); child.stdin.as_mut().unwrap().write_all(s.as_bytes()).await?; Ok(()) diff --git a/yazi-adapter/src/icc.rs b/yazi-adapter/src/icc.rs index 6b3f0541..cf97bdb8 100644 --- a/yazi-adapter/src/icc.rs +++ b/yazi-adapter/src/icc.rs @@ -3,6 +3,7 @@ use image::{ColorType, DynamicImage, GrayAlphaImage, GrayImage, ImageDecoder, Rg use moxcms::{CicpColorPrimaries, ColorProfile, DataColorSpace, Layout, TransferCharacteristics, TransformOptions}; pub(super) struct Icc; + impl Icc { pub(super) fn transform(mut decoder: impl ImageDecoder) -> anyhow::Result { if let Some(layout) = Self::color_type_to_layout(decoder.color_type()) diff --git a/yazi-adapter/src/info.rs b/yazi-adapter/src/info.rs deleted file mode 100644 index 86d4052e..00000000 --- a/yazi-adapter/src/info.rs +++ /dev/null @@ -1,43 +0,0 @@ -use std::path::PathBuf; - -use image::{ImageDecoder, ImageError}; - -pub type ImageFormat = image::ImageFormat; -pub type ImageColor = image::ColorType; -pub type ImageOrientation = image::metadata::Orientation; - -#[derive(Clone, Copy)] -pub struct ImageInfo { - pub format: ImageFormat, - pub width: u32, - pub height: u32, - pub color: ImageColor, - pub orientation: Option, -} - -impl ImageInfo { - pub async fn new(path: PathBuf) -> image::ImageResult { - tokio::task::spawn_blocking(move || { - let reader = image::ImageReader::open(path)?.with_guessed_format()?; - - let Some(format) = reader.format() else { - return Err(ImageError::IoError(std::io::Error::new( - std::io::ErrorKind::InvalidData, - "unknown image format", - ))); - }; - - let mut decoder = reader.into_decoder()?; - let (width, height) = decoder.dimensions(); - Ok(Self { - format, - width, - height, - color: decoder.color_type(), - orientation: decoder.orientation().ok(), - }) - }) - .await - .map_err(|e| ImageError::IoError(e.into()))? - } -} diff --git a/yazi-adapter/src/lib.rs b/yazi-adapter/src/lib.rs index 01080816..347bd4e0 100644 --- a/yazi-adapter/src/lib.rs +++ b/yazi-adapter/src/lib.rs @@ -1,15 +1,12 @@ yazi_macro::mod_pub!(drivers); -yazi_macro::mod_flat!(adapter adapters icc image info); +yazi_macro::mod_flat!(adapter icc image); use yazi_emulator::{Brand, CLOSE, EMULATOR, ESCAPE, Emulator, Mux, START, TMUX}; use yazi_shared::in_wsl; -use yazi_shim::cell::SyncCell; +use yazi_shim::cell::{RoCell, SyncCell}; -pub static ADAPTOR: SyncCell = SyncCell::new(Adapter::Chafa); - -// Image state -static SHOWN: SyncCell> = SyncCell::new(None); +pub static ADAPTOR: RoCell = RoCell::new(); // WSL support pub static WSL: SyncCell = SyncCell::new(false); @@ -34,7 +31,7 @@ pub fn init() -> anyhow::Result<()> { EMULATOR.init(emulator); yazi_config::init_flavor(EMULATOR.light)?; - ADAPTOR.set(Adapter::matches(&EMULATOR)); - ADAPTOR.get().start(); + ADAPTOR.init(Adapter::new()); + ADAPTOR.start(); Ok(()) } diff --git a/yazi-binding/Cargo.toml b/yazi-binding/Cargo.toml index f5fdd02e..b21d4278 100644 --- a/yazi-binding/Cargo.toml +++ b/yazi-binding/Cargo.toml @@ -17,33 +17,24 @@ default = [ "vendored-lua" ] vendored-lua = [ "mlua/vendored" ] [dependencies] -yazi-adapter = { path = "../yazi-adapter", version = "26.5.6" } yazi-codegen = { path = "../yazi-codegen", version = "26.5.6" } -yazi-config = { path = "../yazi-config", version = "26.5.6" } -yazi-fs = { path = "../yazi-fs", version = "26.5.6" } yazi-macro = { path = "../yazi-macro", version = "26.5.6" } -yazi-shared = { path = "../yazi-shared", version = "26.5.6" } yazi-shim = { path = "../yazi-shim", version = "26.5.6" } -yazi-term = { path = "../yazi-term", version = "26.5.6" } -yazi-tty = { path = "../yazi-tty", version = "26.5.9" } -yazi-vfs = { path = "../yazi-vfs", version = "26.5.6" } -yazi-widgets = { path = "../yazi-widgets", version = "26.5.6" } # External dependencies ansi-to-tui = { workspace = true } anyhow = { workspace = true } futures = { workspace = true } hashbrown = { workspace = true } +image = { workspace = true } inventory = { workspace = true } mlua = { workspace = true } ordered-float = { workspace = true } -parking_lot = { workspace = true } -paste = { workspace = true } ratatui = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +strum = { workspace = true } tokio = { workspace = true } -tokio-stream = { workspace = true } tracing = { workspace = true } unicode-width = { workspace = true } diff --git a/yazi-binding/src/access.rs b/yazi-binding/src/access.rs deleted file mode 100644 index 1134d982..00000000 --- a/yazi-binding/src/access.rs +++ /dev/null @@ -1,42 +0,0 @@ -use mlua::{AnyUserData, IntoLuaMulti, UserData, UserDataMethods, Value}; -use yazi_fs::provider::FileBuilder; - -use crate::{Error, Fd, UrlRef}; - -#[derive(Default)] -pub struct Access(yazi_vfs::provider::Gate); - -impl UserData for Access { - fn add_methods>(methods: &mut M) { - methods.add_function("append", |_, (ud, append): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.append(append); - Ok(ud) - }); - methods.add_function("create", |_, (ud, create): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.create(create); - Ok(ud) - }); - methods.add_function("create_new", |_, (ud, create_new): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.create_new(create_new); - Ok(ud) - }); - methods.add_async_method("open", |lua, me, url: UrlRef| async move { - match me.0.open(&*url).await { - Ok(fd) => Fd(fd).into_lua_multi(&lua), - Err(e) => (Value::Nil, Error::Io(e)).into_lua_multi(&lua), - } - }); - methods.add_function("read", |_, (ud, read): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.read(read); - Ok(ud) - }); - methods.add_function("truncate", |_, (ud, truncate): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.truncate(truncate); - Ok(ud) - }); - methods.add_function("write", |_, (ud, write): (AnyUserData, bool)| { - ud.borrow_mut::()?.0.write(write); - Ok(ud) - }); - } -} diff --git a/yazi-binding/src/composer.rs b/yazi-binding/src/composer.rs index ebfc5bd2..e12d237f 100644 --- a/yazi-binding/src/composer.rs +++ b/yazi-binding/src/composer.rs @@ -5,10 +5,9 @@ pub type ComposerGet = fn(&Lua, &[u8]) -> mlua::Result; pub type ComposerSet = fn(&Lua, &[u8], Value) -> mlua::Result; pub struct Composer { - get: G, - set: S, - parent: Option<(G, S)>, - cache: HashMap, Value>, + get: G, + set: S, + cache: HashMap, Value>, } impl Composer @@ -16,13 +15,7 @@ where G: Fn(&Lua, &[u8]) -> mlua::Result + 'static, S: Fn(&Lua, &[u8], Value) -> mlua::Result + 'static, { - #[inline] - pub fn new(get: G, set: S) -> Self { Self { get, set, parent: None, cache: Default::default() } } - - #[inline] - pub fn with_parent(get: G, set: S, p_get: G, p_set: S) -> Self { - Self { get, set, parent: Some((p_get, p_set)), cache: Default::default() } - } + pub fn new(get: G, set: S) -> Self { Self { get, set, cache: Default::default() } } } impl UserData for Composer @@ -37,14 +30,9 @@ where return Ok(v.clone()); } - let mut value = (me.get)(lua, &key)?; - if value.is_nil() - && let Some((p_get, _)) = &me.parent - { - value = p_get(lua, &key)?; - } - + let value = (me.get)(lua, &key)?; me.cache.insert(key.to_owned(), value.clone()); + Ok(value) }); @@ -56,11 +44,6 @@ where if value.is_nil() { me.cache.remove(key.as_ref()); - } else if let Some((_, p_set)) = &me.parent { - match p_set(lua, key.as_ref(), value)? { - Value::Nil => me.cache.remove(key.as_ref()), - v => me.cache.insert(key.to_owned(), v), - }; } else { me.cache.insert(key.to_owned(), value); } diff --git a/yazi-binding/src/config/fetcher.rs b/yazi-binding/src/config/fetcher.rs deleted file mode 100644 index 68d76725..00000000 --- a/yazi-binding/src/config/fetcher.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, Value}; -use yazi_config::YAZI; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{FileRef, Id, Iter}; - -#[derive(Clone)] -pub struct Fetcher { - inner: Arc, -} - -impl Deref for Fetcher { - type Target = yazi_config::plugin::Fetcher; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl Fetcher { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl UserData for Fetcher { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - - fields.add_cached_field("name", |lua, me| lua.create_string(&*me.name)); - } -} - -// --- Matcher -pub struct FetcherMatcher(yazi_config::plugin::FetcherMatcher<'static>); - -impl FetcherMatcher { - pub fn new(inner: impl Into>) -> Self { - Self(inner.into()) - } -} - -impl TryFrom

for FetcherMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - let file: Option = value.raw_get("file")?; - let mime: Option = value.raw_get("mime")?; - - Ok(Self(yazi_config::plugin::FetcherMatcher { - fetchers: YAZI.plugin.fetchers.load_full(), - id: id.0, - file: file.map(|f| f.inner.clone().into()), - mime: mime.map(Into::into), - ..Default::default() - })) - } -} - -impl FromLua for FetcherMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of FetcherMatcher".into_lua_err()), - } - } -} - -impl IntoLua for FetcherMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(Fetcher::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/fetchers.rs b/yazi-binding/src/config/fetchers.rs deleted file mode 100644 index 66bc3fdb..00000000 --- a/yazi-binding/src/config/fetchers.rs +++ /dev/null @@ -1,17 +0,0 @@ -use mlua::{IntoLua, MetaMethod, UserData, UserDataMethods}; -use yazi_config::YAZI; - -use crate::config::FetcherMatcher; - -pub struct Fetchers; - -impl UserData for Fetchers { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, _, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => FetcherMatcher::new(&YAZI.plugin.fetchers).into_lua(lua), - }); - - methods.add_meta_method(MetaMethod::Len, |_, _, ()| Ok(YAZI.plugin.fetchers.load().len())); - } -} diff --git a/yazi-binding/src/config/mod.rs b/yazi-binding/src/config/mod.rs deleted file mode 100644 index 06de0823..00000000 --- a/yazi-binding/src/config/mod.rs +++ /dev/null @@ -1 +0,0 @@ -yazi_macro::mod_flat!(fetcher fetchers open_rule open_rules opener opener_rule opener_rules preloader preloaders previewer previewers spotter spotters); diff --git a/yazi-binding/src/config/open_rule.rs b/yazi-binding/src/config/open_rule.rs deleted file mode 100644 index 64fdc129..00000000 --- a/yazi-binding/src/config/open_rule.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, Table, UserData, UserDataFields, Value}; -use yazi_config::YAZI; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{FileRef, Id, Iter}; - -pub struct OpenRule { - inner: Arc, -} - -impl Deref for OpenRule { - type Target = Arc; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for Arc { - fn from(value: OpenRule) -> Self { value.inner } -} - -impl OpenRule { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl FromLua for OpenRule { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - Ok(Self::new(lua.from_value::(value)?)) - } -} - -impl UserData for OpenRule { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - fields.add_cached_field("use", |lua, me| { - lua.create_sequence_from(me.r#use.iter().map(|s| s.as_str())) - }); - } -} - -// --- Matcher -pub struct OpenRuleMatcher(pub(super) yazi_config::open::OpenRuleMatcher<'static>); - -impl OpenRuleMatcher { - pub fn new(inner: impl Into>) -> Self { - Self(inner.into()) - } -} - -impl TryFrom
for OpenRuleMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - let file: Option = value.raw_get("file")?; - let mime: Option = value.raw_get("mime")?; - - Ok(Self(yazi_config::open::OpenRuleMatcher { - rules: YAZI.open.load_full(), - id: id.0, - file: file.map(|f| f.inner.clone().into()), - mime: mime.map(Into::into), - ..Default::default() - })) - } -} - -impl FromLua for OpenRuleMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of OpenRuleMatcher".into_lua_err()), - } - } -} - -impl IntoLua for OpenRuleMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(OpenRule::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/open_rules.rs b/yazi-binding/src/config/open_rules.rs deleted file mode 100644 index 1f1f7689..00000000 --- a/yazi-binding/src/config/open_rules.rs +++ /dev/null @@ -1,39 +0,0 @@ -use mlua::{ExternalError, ExternalResult, IntoLua, MetaMethod, Table, UserData, UserDataMethods}; -use yazi_config::YAZI; -use yazi_shim::mlua::DeserializeOverLua; - -use crate::config::{OpenRule, OpenRuleMatcher}; - -pub struct OpenRules; - -impl UserData for OpenRules { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, _, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => OpenRuleMatcher::new(&*YAZI.open).into_lua(lua), - }); - - methods.add_method("insert", |_, _, (index, rule): (isize, OpenRule)| { - let index = match index { - 1.. => index - 1, - 0 => return Err("index must be 1-based or negative".into_lua_err()), - _ => index, - }; - - YAZI.open.insert(index, rule.clone()).into_lua_err()?; - Ok(rule) - }); - - methods.add_method("remove", |_, _, matcher: OpenRuleMatcher| { - YAZI.open.remove(matcher.0); - Ok(()) - }); - - methods.add_method("update", |_, _, (matcher, table): (OpenRuleMatcher, Table)| { - YAZI.open.update(matcher.0, |rule| rule.deserialize_over_lua(&table))?; - Ok(()) - }); - - methods.add_meta_method(MetaMethod::Len, |_, _, ()| Ok(YAZI.open.load().len())); - } -} diff --git a/yazi-binding/src/config/opener.rs b/yazi-binding/src/config/opener.rs deleted file mode 100644 index f3bbd76c..00000000 --- a/yazi-binding/src/config/opener.rs +++ /dev/null @@ -1,45 +0,0 @@ -use mlua::{ExternalError, FromLua, IntoLua, IntoLuaMulti, MetaMethod, UserData, UserDataMethods, Value}; -use yazi_config::{YAZI, opener::OpenerRulesMatcher}; - -use crate::config::OpenerRules; - -pub struct Opener; - -impl UserData for Opener { - fn add_methods>(methods: &mut M) { - methods.add_meta_method(MetaMethod::Index, |lua, _, key: mlua::String| { - let key = key.to_str()?; - match YAZI.opener.load().get(&*key) { - Some(rules) => OpenerRules::new(rules.clone()).into_lua(lua), - None => Ok(Value::Nil), - } - }); - - methods.add_meta_method(MetaMethod::NewIndex, |lua, _, (key, value): (mlua::String, Value)| { - let key = key.to_str()?; - match value { - t @ Value::Table(_) => { - YAZI.opener.insert(&key, &*OpenerRules::from_lua(t, lua)?); - } - Value::Nil => { - YAZI.opener.remove(&key); - } - _ => return Err("expected a table or nil".into_lua_err()), - } - Ok(()) - }); - - methods.add_meta_method(MetaMethod::Pairs, |lua, _, ()| { - let mut matcher = OpenerRulesMatcher::from(&YAZI.opener); - let iter = lua.create_function_mut(move |lua, ()| { - if let Some((name, rules)) = matcher.next() { - (name, OpenerRules::new(rules)).into_lua_multi(lua) - } else { - ().into_lua_multi(lua) - } - })?; - - Ok(iter) - }); - } -} diff --git a/yazi-binding/src/config/opener_rule.rs b/yazi-binding/src/config/opener_rule.rs deleted file mode 100644 index 3e1b03ef..00000000 --- a/yazi-binding/src/config/opener_rule.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, Table, UserData, UserDataFields, Value}; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{Id, Iter}; - -pub struct OpenerRule { - inner: Arc, -} - -impl Deref for OpenerRule { - type Target = Arc; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for Arc { - fn from(value: OpenerRule) -> Self { value.inner } -} - -impl OpenerRule { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl FromLua for OpenerRule { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - let mut inner: yazi_config::opener::OpenerRule = lua.from_value(value)?; - inner.fill(); - - Ok(Self::new(inner)) - } -} - -impl UserData for OpenerRule { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - fields.add_cached_field("run", |lua, me| lua.create_string(&*me.run)); - fields.add_field_method_get("block", |_, me| Ok(me.block)); - fields.add_field_method_get("orphan", |_, me| Ok(me.orphan)); - fields.add_cached_field("desc", |lua, me| lua.create_string(&*me.desc)); - } -} - -// --- Matcher -pub struct OpenerRuleMatcher(pub(super) yazi_config::opener::OpenerRuleMatcher); - -impl OpenerRuleMatcher { - pub fn new(inner: impl Into) -> Self { - Self(inner.into()) - } -} - -impl TryFrom
for OpenerRuleMatcher { - type Error = mlua::Error; - - fn try_from(t: Table) -> Result { - let id: Id = t.raw_get("id").unwrap_or_default(); - - Ok(Self(yazi_config::opener::OpenerRuleMatcher { id: id.0, ..Default::default() })) - } -} - -impl FromLua for OpenerRuleMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of OpenerRuleMatcher".into_lua_err()), - } - } -} - -impl IntoLua for OpenerRuleMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(OpenerRule::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/opener_rules.rs b/yazi-binding/src/config/opener_rules.rs deleted file mode 100644 index d694bdec..00000000 --- a/yazi-binding/src/config/opener_rules.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, ExternalResult, FromLua, IntoLua, Lua, LuaSerdeExt, MetaMethod, UserData, UserDataMethods, Value}; -use yazi_shim::toml::DeserializeOverHook; - -use crate::config::{OpenerRule, OpenerRuleMatcher}; - -pub struct OpenerRules { - inner: Arc, -} - -impl Deref for OpenerRules { - type Target = Arc; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl OpenerRules { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl FromLua for OpenerRules { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - let inner: yazi_config::opener::OpenerRules = lua.from_value(value)?; - - Ok(Self::new(inner.deserialize_over_hook().into_lua_err()?)) - } -} - -impl UserData for OpenerRules { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, me, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => OpenerRuleMatcher::new(&*me.inner).into_lua(lua), - }); - - methods.add_method("insert", |_, me, (index, rule): (isize, OpenerRule)| { - let index = match index { - 1.. => index - 1, - 0 => return Err("index must be 1-based or negative".into_lua_err()), - _ => index, - }; - - me.inner.insert(index, rule.clone()).into_lua_err()?; - Ok(rule) - }); - - methods.add_method("remove", |_, me, matcher: OpenerRuleMatcher| { - me.inner.remove(matcher.0); - Ok(()) - }); - - methods.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.inner.load().len())); - } -} diff --git a/yazi-binding/src/config/preloader.rs b/yazi-binding/src/config/preloader.rs deleted file mode 100644 index 3848ceda..00000000 --- a/yazi-binding/src/config/preloader.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, Value}; -use yazi_config::YAZI; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{FileRef, Id, Iter}; - -#[derive(Clone)] -pub struct Preloader { - inner: Arc, -} - -impl Deref for Preloader { - type Target = yazi_config::plugin::Preloader; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl Preloader { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl UserData for Preloader { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - - fields.add_cached_field("name", |lua, me| lua.create_string(&*me.name)); - } -} - -// --- Matcher -pub struct PreloaderMatcher(pub(super) yazi_config::plugin::PreloaderMatcher<'static>); - -impl PreloaderMatcher { - pub fn new(inner: impl Into>) -> Self { - Self(inner.into()) - } -} - -impl TryFrom
for PreloaderMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - let file: Option = value.raw_get("file")?; - let mime: Option = value.raw_get("mime")?; - - Ok(Self(yazi_config::plugin::PreloaderMatcher { - preloaders: YAZI.plugin.preloaders.load_full(), - id: id.0, - file: file.map(|f| f.inner.clone().into()), - mime: mime.map(Into::into), - ..Default::default() - })) - } -} - -impl FromLua for PreloaderMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of PreloaderMatcher".into_lua_err()), - } - } -} - -impl IntoLua for PreloaderMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(Preloader::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/preloaders.rs b/yazi-binding/src/config/preloaders.rs deleted file mode 100644 index f1c13769..00000000 --- a/yazi-binding/src/config/preloaders.rs +++ /dev/null @@ -1,17 +0,0 @@ -use mlua::{IntoLua, MetaMethod, UserData, UserDataMethods}; -use yazi_config::YAZI; - -use crate::config::PreloaderMatcher; - -pub struct Preloaders; - -impl UserData for Preloaders { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, _, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => PreloaderMatcher::new(&YAZI.plugin.preloaders).into_lua(lua), - }); - - methods.add_meta_method(MetaMethod::Len, |_, _, ()| Ok(YAZI.plugin.preloaders.load().len())); - } -} diff --git a/yazi-binding/src/config/previewer.rs b/yazi-binding/src/config/previewer.rs deleted file mode 100644 index b3c5e4eb..00000000 --- a/yazi-binding/src/config/previewer.rs +++ /dev/null @@ -1,84 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, Table, UserData, UserDataFields, Value}; -use yazi_config::YAZI; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{FileRef, Id, Iter}; - -#[derive(Clone)] -pub struct Previewer { - inner: Arc, -} - -impl Deref for Previewer { - type Target = yazi_config::plugin::Previewer; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for Arc { - fn from(value: Previewer) -> Self { value.inner } -} - -impl Previewer { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl FromLua for Previewer { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - Ok(Self::new(lua.from_value::(value)?)) - } -} - -impl UserData for Previewer { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - - fields.add_cached_field("name", |lua, me| lua.create_string(&*me.name)); - } -} - -// --- Matcher -pub struct PreviewerMatcher(pub(super) yazi_config::plugin::PreviewerMatcher<'static>); - -impl PreviewerMatcher { - pub fn new(inner: impl Into>) -> Self { - Self(inner.into()) - } -} - -impl TryFrom
for PreviewerMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - let file: Option = value.raw_get("file")?; - let mime: Option = value.raw_get("mime")?; - - Ok(Self(yazi_config::plugin::PreviewerMatcher { - previewers: YAZI.plugin.previewers.load_full(), - id: id.0, - file: file.map(|f| f.inner.clone().into()), - mime: mime.map(Into::into), - ..Default::default() - })) - } -} - -impl FromLua for PreviewerMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of PreviewerMatcher".into_lua_err()), - } - } -} - -impl IntoLua for PreviewerMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(Previewer::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/previewers.rs b/yazi-binding/src/config/previewers.rs deleted file mode 100644 index 66934839..00000000 --- a/yazi-binding/src/config/previewers.rs +++ /dev/null @@ -1,33 +0,0 @@ -use mlua::{ExternalError, ExternalResult, IntoLua, MetaMethod, UserData, UserDataMethods}; -use yazi_config::YAZI; - -use crate::config::{Previewer, PreviewerMatcher}; - -pub struct Previewers; - -impl UserData for Previewers { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, _, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => PreviewerMatcher::new(&YAZI.plugin.previewers).into_lua(lua), - }); - - methods.add_method("insert", |_, _, (index, previewer): (isize, Previewer)| { - let index = match index { - 1.. => index - 1, - 0 => return Err("index must be 1-based or negative".into_lua_err()), - _ => index, - }; - - YAZI.plugin.previewers.insert(index, previewer.clone().into()).into_lua_err()?; - Ok(previewer) - }); - - methods.add_method("remove", |_, _, matcher: PreviewerMatcher| { - YAZI.plugin.previewers.remove(matcher.0); - Ok(()) - }); - - methods.add_meta_method(MetaMethod::Len, |_, _, ()| Ok(YAZI.plugin.previewers.load().len())); - } -} diff --git a/yazi-binding/src/config/spotter.rs b/yazi-binding/src/config/spotter.rs deleted file mode 100644 index d116dde8..00000000 --- a/yazi-binding/src/config/spotter.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::{ops::Deref, sync::Arc}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, Value}; -use yazi_config::YAZI; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{FileRef, Id, Iter}; - -#[derive(Clone)] -pub struct Spotter { - inner: Arc, -} - -impl Deref for Spotter { - type Target = yazi_config::plugin::Spotter; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl Spotter { - pub fn new(inner: impl Into>) -> Self { - Self { inner: inner.into() } - } -} - -impl UserData for Spotter { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.id))); - - fields.add_cached_field("name", |lua, me| lua.create_string(&*me.name)); - } -} - -// --- Matcher -pub struct SpotterMatcher(pub(super) yazi_config::plugin::SpotterMatcher<'static>); - -impl SpotterMatcher { - pub fn new(inner: impl Into>) -> Self { - Self(inner.into()) - } -} - -impl TryFrom
for SpotterMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - let file: Option = value.raw_get("file")?; - let mime: Option = value.raw_get("mime")?; - - Ok(Self(yazi_config::plugin::SpotterMatcher { - spotters: YAZI.plugin.spotters.load_full(), - id: id.0, - file: file.map(|f| f.inner.clone().into()), - mime: mime.map(Into::into), - ..Default::default() - })) - } -} - -impl FromLua for SpotterMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of SpotterMatcher".into_lua_err()), - } - } -} - -impl IntoLua for SpotterMatcher { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(Spotter::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/config/spotters.rs b/yazi-binding/src/config/spotters.rs deleted file mode 100644 index 8afda780..00000000 --- a/yazi-binding/src/config/spotters.rs +++ /dev/null @@ -1,17 +0,0 @@ -use mlua::{IntoLua, MetaMethod, UserData, UserDataMethods}; -use yazi_config::YAZI; - -use crate::config::SpotterMatcher; - -pub struct Spotters; - -impl UserData for Spotters { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |lua, _, matcher: Option| match matcher { - Some(matcher) => matcher.into_lua(lua), - None => SpotterMatcher::new(&YAZI.plugin.spotters).into_lua(lua), - }); - - methods.add_meta_method(MetaMethod::Len, |_, _, ()| Ok(YAZI.plugin.spotters.load().len())); - } -} diff --git a/yazi-binding/src/dnd.rs b/yazi-binding/src/dnd.rs deleted file mode 100644 index b294e0f6..00000000 --- a/yazi-binding/src/dnd.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::{mem, ops::Deref}; - -use mlua::{IntoLua, UserData, UserDataFields, Value}; -use yazi_shim::{mlua::UserDataFieldsExt, strum::IntoStr}; -use yazi_term::event::{DndDropArrive, DndEvent as Inner}; - -pub struct DndEvent { - inner: Inner, -} - -impl Deref for DndEvent { - type Target = Inner; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for DndEvent { - fn from(inner: Inner) -> Self { Self { inner } } -} - -impl UserData for DndEvent { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("type", |_, me| Ok(me.inner.r#type())); - - fields.add_field_method_get("x", |_, me| Ok(me.inner.x())); - - fields.add_field_method_get("y", |_, me| Ok(me.inner.y())); - - fields.add_field_method_get("idx", |_, me| Ok(me.inner.idx())); - - fields.add_field_method_get("op", |_, me| Ok(me.inner.op().map(IntoStr::into_str))); - - fields.add_cached_field("mimes", |lua, me| { - if let Some(mimes) = me.inner.mimes() { - lua.create_sequence_from(mimes.iter())?.into_lua(lua) - } else { - Ok(Value::Nil) - } - }); - - fields.add_cached_field_mut("data", |lua, me| match &mut me.inner { - Inner::DropArrive(DndDropArrive { data, .. }) => { - lua.create_external_string(mem::take(data))?.into_lua(lua) - } - _ => Ok(Value::Nil), - }); - } -} diff --git a/yazi-binding/src/elements/area.rs b/yazi-binding/src/elements/area.rs index 5abb3991..1f3e8d4f 100644 --- a/yazi-binding/src/elements/area.rs +++ b/yazi-binding/src/elements/area.rs @@ -3,6 +3,7 @@ use std::fmt::Debug; use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, Value}; use super::{Pos, Rect}; +use crate::position::Position; const EXPECTED: &str = "expected a Pos or Rect"; @@ -45,7 +46,7 @@ impl Area { pub fn transform( self, - f: impl FnOnce(yazi_config::popup::Position) -> ratatui::layout::Rect, + f: impl FnOnce(Position) -> ratatui::layout::Rect, ) -> ratatui::layout::Rect { match self { Self::Rect(rect) => *rect, @@ -62,8 +63,8 @@ impl From for Area { fn from(rect: ratatui::layout::Rect) -> Self { Self::Rect(rect.into()) } } -impl From for Area { - fn from(pos: yazi_config::popup::Position) -> Self { Self::Pos(pos.into()) } +impl From for Area { + fn from(value: Position) -> Self { Self::Pos(value.into()) } } impl TryFrom<&AnyUserData> for Area { diff --git a/yazi-binding/src/elements/bar.rs b/yazi-binding/src/elements/bar.rs index 42d4a549..61ed138c 100644 --- a/yazi-binding/src/elements/bar.rs +++ b/yazi-binding/src/elements/bar.rs @@ -36,15 +36,6 @@ impl Spatial for Bar { fn set_area(&mut self, area: Area) { self.area = area; } } -impl Widget for Bar { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - (&self).render(rect, buf); - } -} - impl Widget for &Bar { fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) where diff --git a/yazi-binding/src/elements/elements.rs b/yazi-binding/src/elements/elements.rs deleted file mode 100644 index 6ef49bb4..00000000 --- a/yazi-binding/src/elements/elements.rs +++ /dev/null @@ -1,38 +0,0 @@ -use mlua::{IntoLua, Lua, Value}; - -use crate::{Composer, ComposerGet, ComposerSet}; - -pub fn compose(p_get: ComposerGet, p_set: ComposerSet) -> Composer { - fn get(lua: &Lua, key: &[u8]) -> mlua::Result { - match key { - b"Align" => super::Align::compose(lua)?, - b"Bar" => super::Bar::compose(lua)?, - b"Border" => super::Border::compose(lua)?, - b"Clear" => super::Clear::compose(lua)?, - b"Color" => super::Color::compose(lua)?, - b"Constraint" => super::Constraint::compose(lua)?, - b"Edge" => super::Edge::compose(lua)?, - b"Fill" => super::Fill::compose(lua)?, - b"Gauge" => super::Gauge::compose(lua)?, - b"Input" => super::Input::compose(lua)?, - b"Layout" => super::Layout::compose(lua)?, - b"Line" => super::Line::compose(lua)?, - b"List" => super::List::compose(lua)?, - b"Pad" => super::Pad::compose(lua)?, - b"Pos" => super::Pos::compose(lua)?, - b"Rect" => super::Rect::compose(lua)?, - b"Row" => super::Row::compose(lua)?, - b"Span" => super::Span::compose(lua)?, - b"Style" => crate::Style::compose(lua)?, - b"Table" => super::Table::compose(lua)?, - b"Text" => super::Text::compose(lua)?, - b"Wrap" => super::Wrap::compose(lua)?, - _ => return Ok(Value::Nil), - } - .into_lua(lua) - } - - fn set(_: &Lua, _: &[u8], value: Value) -> mlua::Result { Ok(value) } - - Composer::with_parent(get, set, p_get, p_set) -} diff --git a/yazi-binding/src/elements/fill.rs b/yazi-binding/src/elements/fill.rs index 6ca356b9..00881bdf 100644 --- a/yazi-binding/src/elements/fill.rs +++ b/yazi-binding/src/elements/fill.rs @@ -35,15 +35,6 @@ impl Spatial for Fill { fn set_area(&mut self, area: Area) { self.area = area; } } -impl Widget for Fill { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - (&self).render(rect, buf); - } -} - impl Widget for &Fill { fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) where diff --git a/yazi-binding/src/elements/gauge.rs b/yazi-binding/src/elements/gauge.rs index 4d9dd3d6..250317f7 100644 --- a/yazi-binding/src/elements/gauge.rs +++ b/yazi-binding/src/elements/gauge.rs @@ -2,7 +2,7 @@ use mlua::{AnyUserData, ExternalError, IntoLua, Lua, MetaMethod, Table, UserData use ratatui::widgets::Widget; use super::{Area, Span}; -use crate::{Style, elements::Spatial}; +use crate::{elements::Spatial, style::Style}; #[derive(Clone, Debug, Default)] pub struct Gauge { diff --git a/yazi-binding/src/elements/input.rs b/yazi-binding/src/elements/input.rs deleted file mode 100644 index 3095bbf9..00000000 --- a/yazi-binding/src/elements/input.rs +++ /dev/null @@ -1,117 +0,0 @@ -use std::sync::Arc; - -use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value}; -use parking_lot::Mutex; -use ratatui::widgets::Widget; - -use super::Area; -use crate::{elements::Spatial, impl_area_method}; - -const EXPECTED: &str = "expected a table or a Input"; - -#[derive(Clone, Debug, Default)] -pub struct Input { - pub focus: bool, - - inner: Arc>, -} - -impl Input { - pub fn compose(lua: &Lua) -> mlua::Result { - let new = lua.create_function(|_, (_, input): (Table, Self)| Ok(input))?; - - let input = lua.create_table()?; - input.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?; - input.into_lua(lua) - } -} - -impl From<&Input> for Arc> { - fn from(input: &Input) -> Self { input.inner.clone() } -} - -impl TryFrom<&AnyUserData> for Input { - type Error = mlua::Error; - - fn try_from(value: &AnyUserData) -> Result { - Ok(value.borrow::()?.clone()) - } -} - -impl TryFrom
for Input { - type Error = mlua::Error; - - fn try_from(tb: Table) -> Result { - let input = yazi_widgets::input::Input::new(yazi_widgets::input::InputOpt { - cfg: yazi_config::popup::InputCfg { - title: String::new(), - value: tb.raw_get("value")?, - cursor: None, - obscure: false, - position: Default::default(), - realtime: false, - completion: false, - }, - cb: None, - })?; - - Ok(Self { inner: Arc::new(Mutex::new(input)), ..Default::default() }) - } -} - -impl Spatial for Input { - fn area(&self) -> Area { self.inner.lock().pos.into() } - - fn set_area(&mut self, area: Area) { - self.inner.lock().repos(match area { - Area::Rect(rect) => yazi_config::popup::Position { - origin: yazi_config::popup::Origin::TopLeft, - offset: yazi_config::popup::Offset { - x: rect.x as i16, - y: rect.y as i16, - width: rect.width, - height: rect.height, - }, - }, - Area::Pos(pos) => pos.into(), - }); - } -} - -impl Widget for Input { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - (&self).render(rect, buf); - } -} - -impl Widget for &Input { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - self.inner.lock().render(rect, buf) - } -} - -impl FromLua for Input { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(tb) => Self::try_from(tb), - _ => Err(EXPECTED.into_lua_err()), - } - } -} - -impl UserData for Input { - fn add_methods>(methods: &mut M) { - impl_area_method!(methods); - - methods.add_function("focus", |lua, (ud, focus): (AnyUserData, bool)| { - ud.borrow_mut::()?.focus = focus; - ud.into_lua(lua) - }); - } -} diff --git a/yazi-binding/src/elements/line.rs b/yazi-binding/src/elements/line.rs index 31cb4f21..93180363 100644 --- a/yazi-binding/src/elements/line.rs +++ b/yazi-binding/src/elements/line.rs @@ -106,15 +106,6 @@ impl Spatial for Line { fn set_area(&mut self, area: Area) { self.area = area; } } -impl Widget for Line { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - (&self).render(rect, buf); - } -} - impl Widget for &Line { fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) where diff --git a/yazi-binding/src/elements/list.rs b/yazi-binding/src/elements/list.rs index 55c83972..5dba2f0d 100644 --- a/yazi-binding/src/elements/list.rs +++ b/yazi-binding/src/elements/list.rs @@ -37,15 +37,6 @@ impl Spatial for List { fn set_area(&mut self, area: Area) { self.area = area; } } -impl Widget for List { - fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) - where - Self: Sized, - { - (&self).render(rect, buf); - } -} - impl Widget for &List { fn render(self, rect: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) where diff --git a/yazi-binding/src/elements/mod.rs b/yazi-binding/src/elements/mod.rs index 2aad50fe..fa027fe9 100644 --- a/yazi-binding/src/elements/mod.rs +++ b/yazi-binding/src/elements/mod.rs @@ -1 +1 @@ -yazi_macro::mod_flat!(align area bar border cell clear color constraint edge elements fill gauge input layout line list pad pos rect renderable renderables row span spatial table text wrap); +yazi_macro::mod_flat!(align area bar border cell color constraint edge fill gauge layout line list pad pos rect row span spatial table text wrap); diff --git a/yazi-binding/src/elements/pos.rs b/yazi-binding/src/elements/pos.rs index 24a4a1e8..ac74de16 100644 --- a/yazi-binding/src/elements/pos.rs +++ b/yazi-binding/src/elements/pos.rs @@ -4,29 +4,28 @@ use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, Me use yazi_shim::strum::IntoStr; use super::Pad; +use crate::position::{Offset, Origin, Position}; const EXPECTED: &str = "expected a Pos"; #[derive(Clone, Copy, Default)] pub struct Pos { - inner: yazi_config::popup::Position, + inner: Position, pub(super) pad: Pad, } impl Deref for Pos { - type Target = yazi_config::popup::Position; + type Target = Position; fn deref(&self) -> &Self::Target { &self.inner } } -impl From for Pos { - fn from(value: yazi_config::popup::Position) -> Self { - Self { inner: value, ..Default::default() } - } +impl From for Pos { + fn from(value: Position) -> Self { Self { inner: value, ..Default::default() } } } -impl From for yazi_config::popup::Position { +impl From for Position { fn from(value: Pos) -> Self { value.inner } } @@ -42,8 +41,6 @@ impl TryFrom
for Pos { type Error = mlua::Error; fn try_from(t: Table) -> Result { - use yazi_config::popup::{Offset, Origin, Position}; - Ok(Self::from(Position { origin: Origin::from_str(&t.raw_get::(1)?.to_str()?).into_lua_err()?, offset: Offset { diff --git a/yazi-binding/src/elements/table.rs b/yazi-binding/src/elements/table.rs index d8077904..6be313c4 100644 --- a/yazi-binding/src/elements/table.rs +++ b/yazi-binding/src/elements/table.rs @@ -2,7 +2,7 @@ use mlua::{AnyUserData, IntoLua, Lua, MetaMethod, UserData, UserDataMethods, Val use ratatui::widgets::{StatefulWidget, Widget}; use super::{Area, Row}; -use crate::{Style, elements::{Constraint, Spatial}}; +use crate::{elements::{Constraint, Spatial}, style::Style}; // --- Table #[derive(Clone, Debug, Default)] diff --git a/yazi-binding/src/elements/text.rs b/yazi-binding/src/elements/text.rs index cf532308..8089cfbe 100644 --- a/yazi-binding/src/elements/text.rs +++ b/yazi-binding/src/elements/text.rs @@ -3,7 +3,7 @@ use std::{any::TypeId, mem}; use ansi_to_tui::IntoText; use mlua::{AnyUserData, ExternalError, ExternalResult, FromLua, IntoLua, Lua, MetaMethod, Table, UserData, UserDataMethods, Value}; use ratatui::widgets::Widget; -use yazi_shared::SStr; +use yazi_shim::SStr; use super::{Area, Line, Span, Wrap}; use crate::{Error, elements::{Align, Spatial}}; diff --git a/yazi-binding/src/elements/wrap.rs b/yazi-binding/src/elements/wrap.rs index 85f205f8..cce28cb1 100644 --- a/yazi-binding/src/elements/wrap.rs +++ b/yazi-binding/src/elements/wrap.rs @@ -1,10 +1,9 @@ use std::ops::Deref; use mlua::{FromLua, IntoLua, Lua, Value}; -use yazi_config::preview::PreviewWrap; #[derive(Clone, Copy, Debug, Default)] -pub struct Wrap(pub(super) Option); +pub struct Wrap(pub Option); impl Deref for Wrap { type Target = Option; @@ -26,15 +25,6 @@ impl From for Wrap { fn from(value: ratatui::widgets::Wrap) -> Self { Self(Some(value)) } } -impl From for Wrap { - fn from(value: PreviewWrap) -> Self { - Self(match value { - PreviewWrap::No => None, - PreviewWrap::Yes => Some(ratatui::widgets::Wrap { trim: false }), - }) - } -} - impl FromLua for Wrap { fn from_lua(value: Value, _: &Lua) -> mlua::Result { let Value::Integer(n) = value else { diff --git a/yazi-binding/src/error.rs b/yazi-binding/src/error.rs index ff075c4b..ddf5e52b 100644 --- a/yazi-binding/src/error.rs +++ b/yazi-binding/src/error.rs @@ -2,12 +2,12 @@ use std::{borrow::Cow, fmt::Display}; use mlua::{ExternalError, Lua, MetaMethod, UserData, UserDataFields, UserDataMethods, Value}; use yazi_codegen::FromLuaOwned; -use yazi_shared::SStr; +use yazi_shim::SStr; #[derive(FromLuaOwned)] pub enum Error { Io(std::io::Error), - Fs(yazi_fs::error::Error), + Fs(yazi_shim::fs::Error), Serde(serde_json::Error), Custom(SStr), } @@ -18,7 +18,7 @@ impl Error { let fs = lua.create_function(|_, value: Value| { Ok(Self::Fs(match value { - Value::Table(t) => yazi_fs::error::Error::custom( + Value::Table(t) => yazi_shim::fs::Error::custom( &t.raw_get::("kind")?.to_str()?, t.raw_get("code")?, &t.raw_get::("message")?.to_str()?, @@ -64,7 +64,7 @@ impl UserData for Error { }); fields.add_field_method_get("kind", |_, me| { Ok(match me { - Self::Io(e) => Some(yazi_fs::error::Error::from(e.kind()).kind_str()), + Self::Io(e) => Some(yazi_shim::fs::Error::from(e.kind()).kind_str()), Self::Fs(e) => Some(e.kind_str()), _ => None, }) diff --git a/yazi-binding/src/event/action.rs b/yazi-binding/src/event/action.rs deleted file mode 100644 index 984429c6..00000000 --- a/yazi-binding/src/event/action.rs +++ /dev/null @@ -1,52 +0,0 @@ -use std::ops::{Deref, DerefMut}; - -use mlua::{FromLua, Lua, UserData, UserDataFields, Value}; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::event::Cmd; - -pub struct Action { - inner: yazi_shared::event::Action, -} - -impl Deref for Action { - type Target = yazi_shared::event::Action; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl DerefMut for Action { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } -} - -impl From for yazi_shared::event::Action { - fn from(value: Action) -> Self { value.inner } -} - -impl From for yazi_shared::event::Actions { - fn from(value: Action) -> Self { Self::from(value.inner) } -} - -impl Action { - pub fn new(inner: impl Into) -> Self { Self { inner: inner.into() } } -} - -impl FromLua for Action { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - Ok(match value { - Value::String(s) => Self { inner: s.to_str()?.parse()? }, - Value::UserData(ud) => ud.take()?, - _ => Err(mlua::Error::FromLuaConversionError { - from: value.type_name(), - to: "Action".to_owned(), - message: Some("expected a string or an Action".to_string()), - })?, - }) - } -} - -impl UserData for Action { - fn add_fields>(fields: &mut F) { - fields.add_cached_field("cmd", |_, me| Ok(Cmd::new(me.cmd.clone()))); - } -} diff --git a/yazi-binding/src/event/actions.rs b/yazi-binding/src/event/actions.rs deleted file mode 100644 index 2cd1a942..00000000 --- a/yazi-binding/src/event/actions.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::ops::{Deref, DerefMut}; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, Value}; - -use crate::event::Action; - -#[derive(Clone)] -pub struct Actions { - inner: yazi_shared::event::Actions, -} - -impl Deref for Actions { - type Target = yazi_shared::event::Actions; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl DerefMut for Actions { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } -} - -impl From for yazi_shared::event::Actions { - fn from(value: Actions) -> Self { value.inner } -} - -impl Actions { - pub fn new(inner: yazi_shared::event::Actions) -> Self { Self { inner } } -} - -impl FromLua for Actions { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { - let inner = match value { - Value::Table(t) => t - .sequence_values::() - .map(|a| a.map(Into::into)) - .collect::>>()? - .into(), - v @ Value::String(_) => Action::from_lua(v, lua)?.into(), - _ => Err("expected a string or a table of actions".into_lua_err())?, - }; - - Ok(Self { inner }) - } -} - -impl IntoLua for Actions { - fn into_lua(self, lua: &Lua) -> mlua::Result { - lua.create_sequence_from(self.inner.into_iter().map(Action::new))?.into_lua(lua) - } -} diff --git a/yazi-binding/src/event/cmd.rs b/yazi-binding/src/event/cmd.rs deleted file mode 100644 index 5bd17115..00000000 --- a/yazi-binding/src/event/cmd.rs +++ /dev/null @@ -1,34 +0,0 @@ -use std::{mem, ops::{Deref, DerefMut}}; - -use mlua::{UserData, UserDataFields}; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::Sendable; - -pub struct Cmd { - inner: yazi_shared::event::Cmd, -} - -impl Deref for Cmd { - type Target = yazi_shared::event::Cmd; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl DerefMut for Cmd { - fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } -} - -impl Cmd { - pub fn new(inner: impl Into) -> Self { Self { inner: inner.into() } } -} - -impl UserData for Cmd { - fn add_fields>(fields: &mut F) { - fields.add_cached_field_mut("name", |_, me| Ok(mem::take(&mut me.name))); - - fields.add_cached_field_mut("args", |lua, me| { - Sendable::args_to_table(lua, mem::take(&mut me.args)) - }); - } -} diff --git a/yazi-binding/src/event/mod.rs b/yazi-binding/src/event/mod.rs deleted file mode 100644 index c0011e6d..00000000 --- a/yazi-binding/src/event/mod.rs +++ /dev/null @@ -1 +0,0 @@ -yazi_macro::mod_flat!(action actions cmd); diff --git a/yazi-binding/src/file.rs b/yazi-binding/src/file.rs deleted file mode 100644 index 0224fb91..00000000 --- a/yazi-binding/src/file.rs +++ /dev/null @@ -1,78 +0,0 @@ -use std::ops::Deref; - -use mlua::{AnyUserData, ExternalError, FromLua, Lua, ObjectLike, Table, UserData, UserDataFields, UserDataMethods, UserDataRef, Value}; - -use crate::{Cha, Url, impl_file_fields, impl_file_methods}; - -pub type FileRef = UserDataRef; - -const EXPECTED: &str = "expected a table, File, or fs::File"; - -#[derive(Clone)] -pub struct File { - pub(crate) inner: yazi_fs::File, -} - -impl Deref for File { - type Target = yazi_fs::File; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for yazi_fs::File { - fn from(value: File) -> Self { value.inner } -} - -impl File { - pub fn new(inner: impl Into) -> Self { Self { inner: inner.into() } } - - pub fn install(lua: &Lua) -> mlua::Result<()> { - lua.globals().raw_set("File", lua.create_function(|_, file: Self| Ok(file))?) - } -} - -impl TryFrom
for File { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - Ok(Self::new(yazi_fs::File { - url: value.raw_get::("url")?.into(), - cha: *value.raw_get::("cha")?, - ..Default::default() - })) - } -} - -impl TryFrom for File { - type Error = mlua::Error; - - fn try_from(value: AnyUserData) -> Result { - Ok(if let Ok(me) = value.take::() { me } else { value.get("bare")? }) - } -} - -impl FromLua for File { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(tbl) => Self::try_from(tbl), - Value::UserData(ud) => Self::try_from(ud), - _ => Err(EXPECTED.into_lua_err())?, - } - } -} - -impl UserData for File { - fn add_fields>(fields: &mut F) { - impl_file_fields!(fields); - } - - fn add_methods>(methods: &mut M) { - impl_file_methods!(methods); - - methods.add_method("icon", |_, me, ()| { - use crate::Icon; - // TODO: use a cache - Ok(yazi_config::THEME.icon.matches(me, false).map(Icon::from)) - }); - } -} diff --git a/yazi-binding/src/icon.rs b/yazi-binding/src/icon.rs deleted file mode 100644 index c0ddbb53..00000000 --- a/yazi-binding/src/icon.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::ops::Deref; - -use mlua::{IntoLua, Lua, Value}; - -use crate::Style; - -pub struct Icon { - inner: yazi_config::Icon, -} - -impl Deref for Icon { - type Target = yazi_config::Icon; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From for Icon { - fn from(inner: yazi_config::Icon) -> Self { Self { inner } } -} - -impl IntoLua for Icon { - fn into_lua(self, lua: &Lua) -> mlua::Result { - lua - .create_table_from([ - ("text", self.inner.text.into_lua(lua)?), - ("style", Style::from(self.inner.style).into_lua(lua)?), - ])? - .into_lua(lua) - } -} diff --git a/yazi-binding/src/image.rs b/yazi-binding/src/image.rs index 4a5bdfa9..24944ff7 100644 --- a/yazi-binding/src/image.rs +++ b/yazi-binding/src/image.rs @@ -1,17 +1,43 @@ -use std::ops::Deref; +use std::path::PathBuf; +use image::{ImageDecoder, ImageError}; use mlua::{MetaMethod, UserData, UserDataFields, UserDataMethods}; -pub struct ImageInfo(yazi_adapter::ImageInfo); - -impl Deref for ImageInfo { - type Target = yazi_adapter::ImageInfo; - - fn deref(&self) -> &Self::Target { &self.0 } +// --- ImageInfo +#[derive(Clone, Copy)] +pub struct ImageInfo { + pub format: image::ImageFormat, + pub width: u32, + pub height: u32, + pub color: image::ColorType, + pub orientation: Option, } -impl From for ImageInfo { - fn from(value: yazi_adapter::ImageInfo) -> Self { Self(value) } +impl ImageInfo { + pub async fn new(path: PathBuf) -> image::ImageResult { + tokio::task::spawn_blocking(move || { + let reader = image::ImageReader::open(path)?.with_guessed_format()?; + + let Some(format) = reader.format() else { + return Err(ImageError::IoError(std::io::Error::new( + std::io::ErrorKind::InvalidData, + "unknown image format", + ))); + }; + + let mut decoder = reader.into_decoder()?; + let (width, height) = decoder.dimensions(); + Ok(Self { + format, + width, + height, + color: decoder.color_type(), + orientation: decoder.orientation().ok(), + }) + }) + .await + .map_err(|e| ImageError::IoError(e.into()))? + } } impl UserData for ImageInfo { @@ -25,12 +51,12 @@ impl UserData for ImageInfo { } // --- ImageFormat -struct ImageFormat(yazi_adapter::ImageFormat); +struct ImageFormat(image::ImageFormat); impl UserData for ImageFormat { fn add_methods>(methods: &mut M) { methods.add_meta_method(MetaMethod::ToString, |_, me, ()| { - use yazi_adapter::ImageFormat as F; + use image::ImageFormat as F; Ok(match me.0 { F::Png => "PNG", @@ -55,12 +81,12 @@ impl UserData for ImageFormat { } // --- ImageColor -struct ImageColor(yazi_adapter::ImageColor); +struct ImageColor(image::ColorType); impl UserData for ImageColor { fn add_methods>(methods: &mut M) { methods.add_meta_method(MetaMethod::ToString, |_, me, ()| { - use yazi_adapter::ImageColor as C; + use image::ColorType as C; Ok(match me.0 { C::L8 => "L8", diff --git a/yazi-binding/src/keymap/chord.rs b/yazi-binding/src/keymap/chord.rs deleted file mode 100644 index 9c417349..00000000 --- a/yazi-binding/src/keymap/chord.rs +++ /dev/null @@ -1,108 +0,0 @@ -use std::ops::Deref; - -use mlua::{ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataFields, Value}; -use serde::Deserialize; -use yazi_codegen::FromLuaOwned; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::{Id, Iter, event::Actions, keymap::Key}; - -#[derive(FromLuaOwned)] -pub struct Chord { - inner: yazi_config::keymap::ChordArc, -} - -impl Deref for Chord { - type Target = yazi_config::keymap::ChordArc; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl From<&yazi_config::keymap::ChordArc> for Chord { - fn from(value: &yazi_config::keymap::ChordArc) -> Self { Self { inner: value.clone() } } -} - -impl From for yazi_config::keymap::ChordArc { - fn from(value: Chord) -> Self { value.inner } -} - -impl Chord { - pub fn new(inner: impl Into) -> Self { - Self { inner: inner.into() } - } -} - -impl TryFrom<(Value, yazi_shared::Layer)> for Chord { - type Error = mlua::Error; - - fn try_from((value, layer): (Value, yazi_shared::Layer)) -> Result { - use yazi_config::keymap::Chord as C; - use yazi_shared::Layer as L; - - let de = mlua::serde::Deserializer::new(value); - let inner = match layer { - L::Null => C::<{ L::Null as u8 }>::deserialize(de)?.into(), - L::App => C::<{ L::App as u8 }>::deserialize(de)?.into(), - L::Mgr => C::<{ L::Mgr as u8 }>::deserialize(de)?.into(), - L::Tasks => C::<{ L::Tasks as u8 }>::deserialize(de)?.into(), - L::Spot => C::<{ L::Spot as u8 }>::deserialize(de)?.into(), - L::Pick => C::<{ L::Pick as u8 }>::deserialize(de)?.into(), - L::Input => C::<{ L::Input as u8 }>::deserialize(de)?.into(), - L::Confirm => C::<{ L::Confirm as u8 }>::deserialize(de)?.into(), - L::Help => C::<{ L::Help as u8 }>::deserialize(de)?.into(), - L::Cmp => C::<{ L::Cmp as u8 }>::deserialize(de)?.into(), - L::Which => C::<{ L::Which as u8 }>::deserialize(de)?.into(), - L::Notify => C::<{ L::Notify as u8 }>::deserialize(de)?.into(), - }; - - Ok(Self { inner }) - } -} - -impl UserData for Chord { - fn add_fields>(fields: &mut F) { - fields.add_field_method_get("id", |_, me| Ok(Id(me.inner.id))); - - fields - .add_cached_field("on", |lua, me| lua.create_sequence_from(me.on.iter().copied().map(Key))); - - fields.add_cached_field("run", |_, me| Ok(Actions::new(me.run.clone()))); - - fields.add_cached_field("desc", |lua, me| lua.create_string(&me.desc)); - } -} - -// --- Matcher -pub struct ChordMatcher(pub(super) yazi_config::keymap::ChordMatcher); - -impl TryFrom
for ChordMatcher { - type Error = mlua::Error; - - fn try_from(value: Table) -> Result { - let id: Id = value.raw_get("id").unwrap_or_default(); - - Ok(Self(yazi_config::keymap::ChordMatcher { id: id.0, ..Default::default() })) - } -} - -impl FromLua for ChordMatcher { - fn from_lua(value: Value, _: &Lua) -> mlua::Result { - match value { - Value::Table(t) => t.try_into(), - _ => Err("expected a table of ChordMatcher".into_lua_err()), - } - } -} - -// --- ChordIter -pub struct ChordIter(pub(super) yazi_config::keymap::ChordIter); - -impl ChordIter { - pub fn new(inner: impl Into) -> Self { Self(inner.into()) } -} - -impl IntoLua for ChordIter { - fn into_lua(self, lua: &Lua) -> mlua::Result { - Iter::new(self.0.map(Chord::new), None).into_lua(lua) - } -} diff --git a/yazi-binding/src/keymap/chords.rs b/yazi-binding/src/keymap/chords.rs deleted file mode 100644 index 2b1a3f6a..00000000 --- a/yazi-binding/src/keymap/chords.rs +++ /dev/null @@ -1,69 +0,0 @@ -use std::ops::Deref; - -use mlua::{ExternalError, ExternalResult, MetaMethod, Table, UserData, UserDataMethods, Value}; -use yazi_shim::mlua::DeserializeOverLua; - -use super::{Chord, ChordMatcher}; -use crate::{event::Actions, keymap::ChordIter}; - -pub struct Chords { - pub(super) inner: &'static yazi_config::keymap::Chords, - pub(super) layer: yazi_shared::Layer, -} - -impl Deref for Chords { - type Target = yazi_config::keymap::Chords; - - fn deref(&self) -> &Self::Target { self.inner } -} - -impl UserData for Chords { - fn add_methods>(methods: &mut M) { - methods.add_method("match", |_, me, matcher: Option| { - Ok(match matcher { - Some(matcher) => ChordIter::new(yazi_config::keymap::ChordIter { - chords: me.as_erased(), - matcher: matcher.0, - ..Default::default() - }), - None => ChordIter::new(&*me.inner), - }) - }); - - methods.add_method("insert", |_, me, (index, value): (isize, Value)| { - let index = match index { - 1.. => index - 1, - 0 => return Err("index must be 1-based or negative".into_lua_err()), - _ => index, - }; - - let chord = Chord::try_from((value, me.layer))?; - me.insert(index, chord.clone()).into_lua_err()?; - - Ok(chord) - }); - - methods.add_method("remove", |_, me, matcher: ChordMatcher| { - me.remove(matcher.0); - Ok(()) - }); - - methods.add_method("update", |_, me, (matcher, table): (ChordMatcher, Table)| { - let mut run: Option = table.raw_get("run")?; - if let Some(run) = &mut run { - table.raw_remove("run")?; - run.set(me.layer, yazi_shared::Source::Key); - } - - me.update(matcher.0, |mut chord| { - chord = chord.deserialize_over_lua(&table)?; - if let Some(run) = &run { - chord.run = run.clone().into(); - } - Ok(chord) - }) - }); - - methods.add_meta_method(MetaMethod::Len, |_, me, ()| Ok(me.load().len())); - } -} diff --git a/yazi-binding/src/keymap/key.rs b/yazi-binding/src/keymap/key.rs deleted file mode 100644 index 2e35cad7..00000000 --- a/yazi-binding/src/keymap/key.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::ops::Deref; - -use mlua::{FromLua, IntoLua, Lua, LuaSerdeExt, Value}; - -use crate::SER_OPT; - -#[derive(Clone, Copy, Default, FromLua)] -pub struct Key(pub yazi_config::keymap::Key); - -impl Deref for Key { - type Target = yazi_config::keymap::Key; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl IntoLua for Key { - fn into_lua(self, lua: &Lua) -> mlua::Result { lua.to_value_with(&self.0, SER_OPT) } -} diff --git a/yazi-binding/src/keymap/mod.rs b/yazi-binding/src/keymap/mod.rs deleted file mode 100644 index b8f2ac0e..00000000 --- a/yazi-binding/src/keymap/mod.rs +++ /dev/null @@ -1 +0,0 @@ -yazi_macro::mod_flat!(chord chords key section); diff --git a/yazi-binding/src/keymap/section.rs b/yazi-binding/src/keymap/section.rs deleted file mode 100644 index 48fd44a9..00000000 --- a/yazi-binding/src/keymap/section.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::ops::Deref; - -use anyhow::bail; -use mlua::{UserData, UserDataFields}; -use yazi_config::KEYMAP; -use yazi_shim::mlua::UserDataFieldsExt; - -use crate::keymap::Chords; - -pub struct KeymapSection { - inner: &'static yazi_config::keymap::KeymapSection, - layer: yazi_shared::Layer, -} - -impl Deref for KeymapSection { - type Target = yazi_config::keymap::KeymapSection; - - fn deref(&self) -> &Self::Target { self.inner } -} - -impl TryFrom for KeymapSection { - type Error = anyhow::Error; - - fn try_from(layer: yazi_shared::Layer) -> Result { - use yazi_shared::Layer as L; - - let inner = match layer { - L::Null | L::App => bail!("invalid layer"), - L::Mgr => KEYMAP.mgr.as_erased(), - L::Tasks => KEYMAP.tasks.as_erased(), - L::Spot => KEYMAP.spot.as_erased(), - L::Pick => KEYMAP.pick.as_erased(), - L::Input => KEYMAP.input.as_erased(), - L::Confirm => KEYMAP.confirm.as_erased(), - L::Help => KEYMAP.help.as_erased(), - L::Cmp => KEYMAP.cmp.as_erased(), - L::Which => bail!("invalid layer"), - L::Notify => bail!("invalid layer"), - }; - - Ok(Self { inner, layer }) - } -} - -impl UserData for KeymapSection { - fn add_fields>(fields: &mut F) { - fields.add_cached_field("rules", |_, me| Ok(Chords { inner: me.inner, layer: me.layer })); - } -} diff --git a/yazi-binding/src/layer.rs b/yazi-binding/src/layer.rs deleted file mode 100644 index 1e85aa92..00000000 --- a/yazi-binding/src/layer.rs +++ /dev/null @@ -1,15 +0,0 @@ -use mlua::{MetaMethod, UserData, UserDataMethods}; -use yazi_shim::strum::IntoStr; - -#[derive(Clone, Copy)] -pub struct Layer(yazi_shared::Layer); - -impl From for Layer { - fn from(event: yazi_shared::Layer) -> Self { Self(event) } -} - -impl UserData for Layer { - fn add_methods>(methods: &mut M) { - methods.add_meta_method(MetaMethod::ToString, |_, me, ()| Ok(me.0.into_str())); - } -} diff --git a/yazi-binding/src/lib.rs b/yazi-binding/src/lib.rs index 8c52be9e..3e92c973 100644 --- a/yazi-binding/src/lib.rs +++ b/yazi-binding/src/lib.rs @@ -1,5 +1,5 @@ mod macros; -yazi_macro::mod_pub!(config elements event keymap process theme); +yazi_macro::mod_pub!(elements position process style); -yazi_macro::mod_flat!(access calculator cha chan composer dnd error fd file handle icon id image input iter layer mouse path permit range runtime scheme selector sendable stage style tty url utils); +yazi_macro::mod_flat!(chan composer error handle image iter permit range runtime); diff --git a/yazi-binding/src/macros.rs b/yazi-binding/src/macros.rs index bba655bf..272ebf87 100644 --- a/yazi-binding/src/macros.rs +++ b/yazi-binding/src/macros.rs @@ -50,8 +50,7 @@ macro_rules! impl_area_method { "area", |lua, (ud, area): (mlua::AnyUserData, Option)| { use mlua::IntoLua; - - use crate::elements::Spatial; + use $crate::elements::Spatial; if let Some(v) = area { ud.borrow_mut::()?.set_area((&v).try_into()?); @@ -67,7 +66,7 @@ macro_rules! impl_area_method { #[macro_export] macro_rules! impl_style_method { ($methods:ident, $($field:tt).+) => { - $methods.add_function("style", |_, (ud, style): (mlua::AnyUserData, $crate::Style)| { + $methods.add_function("style", |_, (ud, style): (mlua::AnyUserData, $crate::style::Style)| { ud.borrow_mut::()?.$($field).+ = style.0; Ok(ud) }); @@ -208,21 +207,22 @@ macro_rules! impl_file_fields { ($fields:ident) => { use yazi_shim::mlua::UserDataFieldsExt; - $fields.add_cached_field("cha", |_, me| Ok($crate::Cha(me.cha))); - $fields.add_cached_field("url", |_, me| Ok($crate::Url::new(me.url_owned()))); - $fields.add_cached_field("link_to", |_, me| Ok(me.link_to.as_ref().map($crate::Path::new))); + $fields.add_cached_field("cha", |_, me| Ok(me.cha)); + $fields.add_cached_field("url", |_, me| Ok(me.url_owned())); + $fields.add_cached_field("link_to", |_, me| Ok(me.link_to.clone())); $fields.add_cached_field("name", |lua, me| { me.name().map(|s| lua.create_string(s.encoded_bytes())).transpose() }); $fields.add_cached_field("path", |_, me| { use yazi_fs::FsUrl; - use yazi_shared::url::AsUrl; - Ok($crate::Path::new(me.url.as_url().unified_path())) + use yazi_shared::{path::PathBufDyn, url::AsUrl}; + Ok(PathBufDyn::from(me.url.as_url().unified_path())) }); $fields.add_cached_field("cache", |_, me| { use yazi_fs::FsUrl; - Ok(me.url.cache().map($crate::Path::new)) + use yazi_shared::path::PathBufDyn; + Ok(me.url.cache().map(PathBufDyn::from)) }); }; } diff --git a/yazi-binding/src/mouse.rs b/yazi-binding/src/mouse.rs deleted file mode 100644 index 8d837b7d..00000000 --- a/yazi-binding/src/mouse.rs +++ /dev/null @@ -1,37 +0,0 @@ -use std::ops::Deref; - -use mlua::{UserData, UserDataFields}; -use yazi_term::event::{MouseButton, MouseEventKind}; - -#[derive(Clone, Copy)] -pub struct MouseEvent(yazi_term::event::MouseEvent); - -impl Deref for MouseEvent { - type Target = yazi_term::event::MouseEvent; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl From for MouseEvent { - fn from(event: yazi_term::event::MouseEvent) -> Self { Self(event) } -} - -impl UserData for MouseEvent { - fn add_fields>(fields: &mut F) { - fields.add_field("type", "legacy"); - fields.add_field_method_get("x", |_, me| Ok(me.column)); - fields.add_field_method_get("y", |_, me| Ok(me.row)); - fields.add_field_method_get("is_left", |_, me| { - use MouseEventKind as K; - Ok(matches!(me.kind, K::Down(b) | K::Up(b) | K::Drag(b) if b == MouseButton::Left)) - }); - fields.add_field_method_get("is_right", |_, me| { - use MouseEventKind as K; - Ok(matches!(me.kind, K::Down(b) | K::Up(b) | K::Drag(b) if b == MouseButton::Right)) - }); - fields.add_field_method_get("is_middle", |_, me| { - use MouseEventKind as K; - Ok(matches!(me.kind, K::Down(b) | K::Up(b) | K::Drag(b) if b == MouseButton::Middle)) - }); - } -} diff --git a/yazi-binding/src/position/mod.rs b/yazi-binding/src/position/mod.rs new file mode 100644 index 00000000..eef64651 --- /dev/null +++ b/yazi-binding/src/position/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(offset origin position); diff --git a/yazi-config/src/popup/offset.rs b/yazi-binding/src/position/offset.rs similarity index 100% rename from yazi-config/src/popup/offset.rs rename to yazi-binding/src/position/offset.rs diff --git a/yazi-config/src/popup/origin.rs b/yazi-binding/src/position/origin.rs similarity index 100% rename from yazi-config/src/popup/origin.rs rename to yazi-binding/src/position/origin.rs diff --git a/yazi-config/src/popup/position.rs b/yazi-binding/src/position/position.rs similarity index 93% rename from yazi-config/src/popup/position.rs rename to yazi-binding/src/position/position.rs index fa48c69b..f370012e 100644 --- a/yazi-config/src/popup/position.rs +++ b/yazi-binding/src/position/position.rs @@ -1,7 +1,6 @@ use std::ops::{Deref, DerefMut}; use ratatui::{layout::Rect, widgets::Padding}; -use yazi_term::Dimension; use super::{Offset, Origin}; @@ -24,7 +23,7 @@ impl DerefMut for Position { impl Position { pub const fn new(origin: Origin, offset: Offset) -> Self { Self { origin, offset } } - pub fn rect(&self, Dimension { cols, rows, .. }: Dimension) -> Rect { + pub fn rect(&self, (cols, rows): (u16, u16)) -> Rect { use Origin::*; let Offset { x, y, width, height } = self.offset; @@ -54,7 +53,7 @@ impl Position { } } - pub fn sticky(Dimension { cols, rows, .. }: Dimension, base: Rect, offset: Offset) -> Rect { + pub fn sticky((cols, rows): (u16, u16), base: Rect, offset: Offset) -> Rect { let Offset { x, y, width, height } = offset; let above = diff --git a/yazi-binding/src/process/command.rs b/yazi-binding/src/process/command.rs index 519c6189..4949b266 100644 --- a/yazi-binding/src/process/command.rs +++ b/yazi-binding/src/process/command.rs @@ -2,7 +2,7 @@ use std::{any::TypeId, ffi::OsStr, io, process::Stdio}; use mlua::{AnyUserData, ExternalError, IntoLua, IntoLuaMulti, Lua, MetaMethod, Table, UserData, UserDataMethods, Value}; use tokio::process::{ChildStderr, ChildStdin, ChildStdout}; -use yazi_shared::wtf8::FromWtf8; +use yazi_shim::wtf8::FromWtf8; use super::{Child, output::Output}; use crate::{Error, process::Status}; diff --git a/yazi-binding/src/scheme.rs b/yazi-binding/src/scheme.rs deleted file mode 100644 index d4fe16a6..00000000 --- a/yazi-binding/src/scheme.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::ops::Deref; - -use mlua::{UserData, UserDataFields}; -use yazi_fs::FsScheme; -use yazi_shared::scheme::SchemeLike; -use yazi_shim::{mlua::UserDataFieldsExt, strum::IntoStr}; - -use crate::Path; - -pub struct Scheme { - inner: yazi_shared::scheme::Scheme, -} - -impl Deref for Scheme { - type Target = yazi_shared::scheme::Scheme; - - fn deref(&self) -> &Self::Target { &self.inner } -} - -impl Scheme { - pub fn new(scheme: impl Into) -> Self { - Self { inner: scheme.into() } - } -} - -impl UserData for Scheme { - fn add_fields>(fields: &mut F) { - fields.add_cached_field("kind", |_, me| Ok(me.kind().into_str())); - fields.add_cached_field("cache", |_, me| Ok(me.cache().map(Path::new))); - - fields.add_field_method_get("is_virtual", |_, me| Ok(me.is_virtual())); - } -} diff --git a/yazi-binding/src/selector.rs b/yazi-binding/src/selector.rs deleted file mode 100644 index d5d281ef..00000000 --- a/yazi-binding/src/selector.rs +++ /dev/null @@ -1,21 +0,0 @@ -use std::ops::Deref; - -use mlua::{FromLua, Lua, LuaSerdeExt, UserData, Value}; - -pub struct Selector(yazi_config::Selector); - -impl Deref for Selector { - type Target = yazi_config::Selector; - - fn deref(&self) -> &Self::Target { &self.0 } -} - -impl From for yazi_config::Selector { - fn from(value: Selector) -> Self { value.0 } -} - -impl FromLua for Selector { - fn from_lua(value: Value, lua: &Lua) -> mlua::Result { Ok(Self(lua.from_value(value)?)) } -} - -impl UserData for Selector {} diff --git a/yazi-binding/src/stage.rs b/yazi-binding/src/stage.rs deleted file mode 100644 index 9678175c..00000000 --- a/yazi-binding/src/stage.rs +++ /dev/null @@ -1,21 +0,0 @@ -use mlua::{IntoLuaMulti, MetaMethod, UserData, UserDataMethods}; - -pub struct FolderStage(yazi_fs::FolderStage); - -impl FolderStage { - pub fn new(inner: yazi_fs::FolderStage) -> Self { Self(inner) } -} - -impl UserData for FolderStage { - fn add_methods>(methods: &mut M) { - methods.add_meta_method(MetaMethod::Call, |lua, me, ()| { - use yazi_fs::FolderStage::*; - - match &me.0 { - Loading => false.into_lua_multi(lua), - Loaded => true.into_lua_multi(lua), - Failed(e) => (true, crate::Error::Fs(e.clone())).into_lua_multi(lua), - } - }); - } -} diff --git a/yazi-binding/src/style/mod.rs b/yazi-binding/src/style/mod.rs new file mode 100644 index 00000000..11ea7d99 --- /dev/null +++ b/yazi-binding/src/style/mod.rs @@ -0,0 +1 @@ +yazi_macro::mod_flat!(style style_flat); diff --git a/yazi-binding/src/style.rs b/yazi-binding/src/style/style.rs similarity index 89% rename from yazi-binding/src/style.rs rename to yazi-binding/src/style/style.rs index 45592ef2..29a19298 100644 --- a/yazi-binding/src/style.rs +++ b/yazi-binding/src/style/style.rs @@ -2,9 +2,9 @@ use std::ops::Deref; use mlua::{ExternalError, FromLua, IntoLua, Lua, LuaSerdeExt, MetaMethod, Table, UserData, UserDataMethods, Value}; use ratatui::style::Modifier; -use yazi_shim::cell::SyncCell; +use yazi_shim::{cell::SyncCell, mlua::SER_OPT}; -use crate::{SER_OPT, elements::Color}; +use crate::{elements::Color, style::StyleFlat}; #[derive(Clone, Copy, Default)] pub struct Style(pub ratatui::style::Style); @@ -15,18 +15,18 @@ impl Deref for Style { fn deref(&self) -> &Self::Target { &self.0 } } -impl From for Style { - fn from(value: yazi_config::Style) -> Self { Self(value.into()) } +impl From for Style { + fn from(value: StyleFlat) -> Self { Self(value.into()) } +} + +impl From<&SyncCell> for Style { + fn from(value: &SyncCell) -> Self { value.get().into() } } impl From