feat: v0.2.0 API

This commit is contained in:
sxyazi 2023-12-30 23:41:41 +08:00
parent 32aa1909cf
commit ccb98ac21f
No known key found for this signature in database
37 changed files with 319 additions and 305 deletions

215
Cargo.lock generated
View file

@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "ahash"
version = "0.8.6"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
dependencies = [
"cfg-if",
"once_cell",
@ -120,9 +120,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.75"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
checksum = "c9d19de80eff169429ac1e9f48fffb163916b448a44e8e046186232046d9e1f9"
[[package]]
name = "arc-swap"
@ -214,9 +214,9 @@ dependencies = [
[[package]]
name = "bstr"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "542f33a8835a0884b006a0c3df3dadd99c0c3f296ed26c2fdc8028e01ad6230c"
checksum = "c48f0051a4b4c5e0b6d365cd04af53aeaa209e3cc15ec2cdb69e73cc87fbd0dc"
dependencies = [
"memchr",
"serde",
@ -281,9 +281,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.4.11"
version = "4.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfaff671f6b22ca62406885ece523383b9b64022e341e53e009a62ebc47a45f2"
checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d"
dependencies = [
"clap_builder",
"clap_derive",
@ -291,9 +291,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.4.11"
version = "4.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a216b506622bb1d316cd51328dce24e07bdff4a6128a47c7e7fad11878d5adbb"
checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9"
dependencies = [
"anstream",
"anstyle",
@ -303,9 +303,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.4.4"
version = "4.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bffe91f06a11b4b9420f62103854e90867812cd5d01557f853c5ee8e791b12ae"
checksum = "a51919c5608a32e34ea1d6be321ad070065e17613e168c5b6977024290f2630b"
dependencies = [
"clap",
]
@ -339,7 +339,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -400,9 +400,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.8"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200"
checksum = "82a9b73a36529d9c47029b9fb3a6f0ea3cc916a261195352ba19e770fc1748b2"
dependencies = [
"cfg-if",
"crossbeam-utils",
@ -410,9 +410,9 @@ dependencies = [
[[package]]
name = "crossbeam-deque"
version = "0.8.3"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef"
checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751"
dependencies = [
"cfg-if",
"crossbeam-epoch",
@ -421,22 +421,20 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.15"
version = "0.9.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7"
checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d"
dependencies = [
"autocfg",
"cfg-if",
"crossbeam-utils",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.16"
version = "0.8.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294"
checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c"
dependencies = [
"cfg-if",
]
@ -594,9 +592,9 @@ dependencies = [
[[package]]
name = "fdeflate"
version = "0.3.1"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64d6dafc854908ff5da46ff3f8f473c6984119a2876a383a860246dd7841a868"
checksum = "209098dd6dfc4445aa6111f0e98653ac323eaa4dfd212c9ca3931bf9955c31bd"
dependencies = [
"simd-adler32",
]
@ -668,9 +666,9 @@ dependencies = [
[[package]]
name = "futures"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335"
checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0"
dependencies = [
"futures-channel",
"futures-core",
@ -683,9 +681,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb"
checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78"
dependencies = [
"futures-core",
"futures-sink",
@ -693,15 +691,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c"
checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d"
[[package]]
name = "futures-executor"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc"
checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d"
dependencies = [
"futures-core",
"futures-task",
@ -710,38 +708,38 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa"
checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1"
[[package]]
name = "futures-macro"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb"
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
name = "futures-sink"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5"
[[package]]
name = "futures-task"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2"
checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004"
[[package]]
name = "futures-util"
version = "0.3.29"
version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104"
checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48"
dependencies = [
"futures-channel",
"futures-core",
@ -831,11 +829,11 @@ checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
[[package]]
name = "home"
version = "0.5.5"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5444c27eef6923071f7ebcc33e3444508466a76f7a2b93da00ed6e19f30c1ddb"
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
dependencies = [
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@ -957,6 +955,15 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.10"
@ -1072,18 +1079,18 @@ dependencies = [
[[package]]
name = "lua-src"
version = "546.0.1"
version = "546.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c26d4af78361e025a3d03a2b964cd1592aff7495f4d4f7947218c084c6fdca8"
checksum = "2da0daa7eee611a4c30c8f5ee31af55266e26e573971ba9336d2993e2da129b2"
dependencies = [
"cc",
]
[[package]]
name = "luajit-src"
version = "210.5.2+113a168"
version = "210.5.3+29b0b28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "823ec7bedb1819b11633bd583ae981b0082db08492b0c3396412b85dd329ffee"
checksum = "0c2bb89013916ce5c949f01a1fbd6d435a58e1d980767a791d755911211d792d"
dependencies = [
"cc",
"which",
@ -1110,18 +1117,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.6.4"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167"
[[package]]
name = "memoffset"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c"
dependencies = [
"autocfg",
]
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "minimal-lexical"
@ -1188,13 +1186,13 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f359220f24e6452dd82a3f50d7242d4aab822b5594798048e953d7a9e0314c6"
dependencies = [
"itertools",
"itertools 0.11.0",
"once_cell",
"proc-macro-error",
"proc-macro2",
"quote",
"regex",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -1295,9 +1293,9 @@ dependencies = [
[[package]]
name = "object"
version = "0.32.1"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
@ -1400,9 +1398,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "pkg-config"
version = "0.3.27"
version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a"
[[package]]
name = "plist"
@ -1463,9 +1461,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.70"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b"
checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8"
dependencies = [
"unicode-ident",
]
@ -1499,17 +1497,18 @@ dependencies = [
[[package]]
name = "ratatui"
version = "0.24.0"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ebc917cfb527a566c37ecb94c7e3fd098353516fb4eb6bea17015ade0182425"
checksum = "a5659e52e4ba6e07b2dad9f1158f578ef84a73762625ddb51536019f34d180eb"
dependencies = [
"bitflags 2.4.1",
"cassowary",
"crossterm",
"indoc",
"itertools",
"itertools 0.12.0",
"lru",
"paste",
"stability",
"strum",
"unicode-segmentation",
"unicode-width",
@ -1675,7 +1674,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -1691,9 +1690,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.4"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
dependencies = [
"serde",
]
@ -1795,6 +1794,16 @@ dependencies = [
"lock_api",
]
[[package]]
name = "stability"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebd1b177894da2a2d9120208c3386066af06a488255caabc5de8ddca22dbc3ce"
dependencies = [
"quote",
"syn 1.0.109",
]
[[package]]
name = "str-buf"
version = "1.0.6"
@ -1826,7 +1835,7 @@ dependencies = [
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -1842,9 +1851,9 @@ dependencies = [
[[package]]
name = "syn"
version = "2.0.40"
version = "2.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13fa70a4ee923979ffb522cacce59d34421ebdea5625e1073c4326ef9d2dd42e"
checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53"
dependencies = [
"proc-macro2",
"quote",
@ -1873,22 +1882,22 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.50"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
checksum = "83a48fd946b02c0a526b2e9481c8e2a17755e47039164a86c4070446e3a4614d"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.50"
version = "1.0.52"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -1914,9 +1923,9 @@ dependencies = [
[[package]]
name = "time"
version = "0.3.30"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
checksum = "f657ba42c3f86e7680e53c8cd3af8abbe56b5491790b46e22e19c0d57463583e"
dependencies = [
"deranged",
"itoa",
@ -1936,9 +1945,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
[[package]]
name = "time-macros"
version = "0.2.15"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
checksum = "26197e33420244aeb70c3e8c78376ca46571bc4e701e4791c2cd9f57dcb3a43f"
dependencies = [
"time-core",
]
@ -1960,9 +1969,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.35.0"
version = "1.35.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "841d45b238a16291a4e1584e61820b8ae57d696cc5015c459c229ccc6990cc1c"
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
dependencies = [
"backtrace",
"bytes",
@ -1985,7 +1994,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -2078,7 +2087,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]
@ -2290,7 +2299,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
"wasm-bindgen-shared",
]
@ -2312,7 +2321,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -2591,9 +2600,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.5.27"
version = "0.5.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb877ca3232bec99a6472ed63f7241de2a250165260908b2d24c09d867907a85"
checksum = "97a4882e6b134d6c28953a387571f1acdd3496830d5e36c5e3a1075580ea641c"
dependencies = [
"memchr",
]
@ -2725,9 +2734,9 @@ dependencies = [
[[package]]
name = "yazi-prebuild"
version = "0.1.1"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "394457709d77af570fcb3c0ef878336213b4e9c8f298eccde728aecd602aa7e0"
checksum = "f4b6c8e12e39ac0f79fa96f36e5b88e0da8d230691abd729eec709b43c74f632"
[[package]]
name = "yazi-scheduler"
@ -2769,22 +2778,22 @@ dependencies = [
[[package]]
name = "zerocopy"
version = "0.7.30"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7"
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.7.30"
version = "0.7.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba"
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.40",
"syn 2.0.43",
]
[[package]]

View file

@ -1,7 +1,7 @@
use std::{env, path::Path, sync::Arc};
use anyhow::{anyhow, Result};
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use tracing::warn;
use yazi_shared::{env_exists, term::Term};

View file

@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::{codecs::jpeg::JpegEncoder, DynamicImage};
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;
use super::image::Image;

View file

@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;
use super::image::Image;

View file

@ -3,7 +3,7 @@ use std::{io::{stdout, Write}, path::Path};
use anyhow::Result;
use base64::{engine::general_purpose, Engine};
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;
use super::image::Image;

View file

@ -3,7 +3,7 @@ use std::{io::{stdout, BufWriter, Write}, path::Path};
use anyhow::{bail, Result};
use color_quant::NeuQuant;
use image::DynamicImage;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_shared::term::Term;
use crate::{adaptor::Adaptor, Image, CLOSE, ESCAPE, START};

View file

@ -2,7 +2,7 @@ use std::{path::{Path, PathBuf}, process::Stdio};
use anyhow::{bail, Result};
use imagesize::ImageSize;
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use tokio::{io::AsyncWriteExt, process::{Child, Command}, sync::mpsc::{self, UnboundedSender}};
use tracing::debug;
use yazi_config::PREVIEW;

View file

@ -99,18 +99,18 @@ keymap = [
{ on = [ "N" ], exec = "find_arrow --previous", desc = "Go to previous found file" },
# Sorting
{ on = [ ",", "m" ], exec = "sort modified --dir_first", desc = "Sort by modified time" },
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir_first", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], exec = "sort created --dir_first", desc = "Sort by created time" },
{ on = [ ",", "C" ], exec = "sort created --reverse --dir_first", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], exec = "sort extension --dir_first", desc = "Sort by extension" },
{ on = [ ",", "E" ], exec = "sort extension --reverse --dir_first", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], exec = "sort alphabetical --dir_first", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir_first", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], exec = "sort natural --dir_first", desc = "Sort naturally" },
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir_first", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], exec = "sort size --dir_first", desc = "Sort by size" },
{ on = [ ",", "S" ], exec = "sort size --reverse --dir_first", desc = "Sort by size (reverse)" },
{ on = [ ",", "m" ], exec = "sort modified --dir-first", desc = "Sort by modified time" },
{ on = [ ",", "M" ], exec = "sort modified --reverse --dir-first", desc = "Sort by modified time (reverse)" },
{ on = [ ",", "c" ], exec = "sort created --dir-first", desc = "Sort by created time" },
{ on = [ ",", "C" ], exec = "sort created --reverse --dir-first", desc = "Sort by created time (reverse)" },
{ on = [ ",", "e" ], exec = "sort extension --dir-first", desc = "Sort by extension" },
{ on = [ ",", "E" ], exec = "sort extension --reverse --dir-first", desc = "Sort by extension (reverse)" },
{ on = [ ",", "a" ], exec = "sort alphabetical --dir-first", desc = "Sort alphabetically" },
{ on = [ ",", "A" ], exec = "sort alphabetical --reverse --dir-first", desc = "Sort alphabetically (reverse)" },
{ on = [ ",", "n" ], exec = "sort natural --dir-first", desc = "Sort naturally" },
{ on = [ ",", "N" ], exec = "sort natural --reverse --dir-first", desc = "Sort naturally (reverse)" },
{ on = [ ",", "s" ], exec = "sort size --dir-first", desc = "Sort by size" },
{ on = [ ",", "S" ], exec = "sort size --reverse --dir-first", desc = "Sort by size (reverse)" },
# Tabs
{ on = [ "t" ], exec = "tab_create --current", desc = "Create a new tab using the current path" },

View file

@ -1,5 +1,5 @@
[manager]
layout = [ 1, 4, 3 ]
ratio = [ 1, 4, 3 ]
sort_by = "modified"
sort_sensitive = true
sort_reverse = true

View file

@ -6,8 +6,7 @@ use crate::{validation::check_validation, MERGED_YAZI};
#[derive(Debug, Deserialize, Serialize, Validate)]
pub struct Manager {
// FIXME: rename this to "ratio"
pub layout: ManagerRatio,
pub ratio: ManagerRatio,
// Sorting
pub sort_by: SortBy,

View file

@ -12,7 +12,7 @@ impl Tab {
}
self.conf.sort_sensitive = e.named.contains_key("sensitive");
self.conf.sort_reverse = e.named.contains_key("reverse");
self.conf.sort_dir_first = e.named.contains_key("dir_first");
self.conf.sort_dir_first = e.named.contains_key("dir-first");
self.apply_files_attrs(false)
}

View file

@ -6,7 +6,7 @@ use yazi_plugin::{bindings::Cast, elements::{render_widgets, Rect}, LUA};
pub(crate) struct Status;
impl Widget for Status {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::prelude::Buffer) {
fn render(self, area: ratatui::layout::Rect, buf: &mut ratatui::buffer::Buffer) {
let mut f = || {
let area = Rect::cast(&LUA, area)?;
let comp: Table = LUA.globals().get("Status")?;

View file

@ -1,4 +1,4 @@
use ratatui::prelude::Rect;
use ratatui::layout::Rect;
use yazi_config::popup::{Origin, Position};
use yazi_core::{completion::Completion, help::Help, input::Input, manager::Manager, select::Select, tasks::Tasks, which::Which};

View file

@ -36,10 +36,12 @@ impl Widget for Bindings<'_> {
.map(|c| ListItem::new(c.desc.as_deref().unwrap_or("-")).style(THEME.help.desc.into()))
.collect::<Vec<_>>();
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([Constraint::Ratio(2, 10), Constraint::Ratio(3, 10), Constraint::Ratio(5, 10)])
.split(area);
let chunks = layout::Layout::new(Direction::Horizontal, [
Constraint::Ratio(2, 10),
Constraint::Ratio(3, 10),
Constraint::Ratio(5, 10),
])
.split(area);
let cursor = self.cx.help.rel_cursor() as u16;
buf.set_style(

View file

@ -14,10 +14,9 @@ impl<'a> Layout<'a> {
impl<'a> Widget for Layout<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = layout::Layout::new()
.direction(Direction::Vertical)
.constraints([Constraint::Min(0), Constraint::Length(1)])
.split(area);
let chunks =
layout::Layout::new(Direction::Vertical, [Constraint::Min(0), Constraint::Length(1)])
.split(area);
widgets::Clear.render(area, buf);

View file

@ -13,10 +13,12 @@ impl<'a> Root<'a> {
impl<'a> Widget for Root<'a> {
fn render(self, area: Rect, buf: &mut Buffer) {
let chunks = Layout::new()
.direction(Direction::Vertical)
.constraints([Constraint::Length(1), Constraint::Min(0), Constraint::Length(1)])
.split(area);
let chunks = Layout::new(Direction::Vertical, [
Constraint::Length(1),
Constraint::Min(0),
Constraint::Length(1),
])
.split(area);
components::Header.render(chunks[0], buf);
components::Manager.render(chunks[1], buf);

View file

@ -12,23 +12,19 @@ impl<'a> Layout<'a> {
pub(crate) fn new(cx: &'a Ctx) -> Self { Self { cx } }
pub(super) fn area(area: Rect) -> Rect {
let chunk = layout::Layout::new()
.direction(Direction::Vertical)
.constraints([
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(area)[1];
let chunk = layout::Layout::new(Direction::Vertical, [
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(area)[1];
layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(chunk)[1]
layout::Layout::new(Direction::Horizontal, [
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
Constraint::Percentage(TASKS_PERCENT),
Constraint::Percentage((100 - TASKS_PERCENT) / 2),
])
.split(chunk)[1]
}
}

View file

@ -33,10 +33,12 @@ impl Widget for Which<'_> {
height,
};
let chunks = layout::Layout::new()
.direction(Direction::Horizontal)
.constraints([Constraint::Ratio(1, 3), Constraint::Ratio(1, 3), Constraint::Ratio(1, 3)])
.split(area);
let chunks = layout::Layout::new(Direction::Horizontal, [
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
Constraint::Ratio(1, 3),
])
.split(area);
widgets::Clear.render(area, buf);
Block::new().style(THEME.which.mask.into()).render(area, buf);

View file

@ -66,7 +66,7 @@ function Folder:linemode(area)
spans[#spans + 1] = ui.Span(" ")
lines[#lines + 1] = ui.Line(spans)
end
return ui.Paragraph(area, lines):align(ui.Alignment.RIGHT)
return ui.Paragraph(area, lines):align(ui.Paragraph.RIGHT)
end
function Folder:markers(area, markers)
@ -84,7 +84,7 @@ function Folder:markers(area, markers)
w = 1,
h = 1 + math.min(last[2] - last[1], area.h - y),
},
ui.Position.LEFT
ui.Bar.LEFT
)
if last[3] == 1 then

View file

@ -34,7 +34,7 @@ function Header:render(area)
self.area = area
local chunks = ui.Layout()
:direction(ui.Direction.HORIZONTAL)
:direction(ui.Layout.HORIZONTAL)
:constraints({ ui.Constraint.Percentage(50), ui.Constraint.Percentage(50) })
:split(area)
@ -42,6 +42,6 @@ function Header:render(area)
local right = ui.Line { self:tabs() }
return {
ui.Paragraph(chunks[1], { left }),
ui.Paragraph(chunks[2], { right }):align(ui.Alignment.RIGHT),
ui.Paragraph(chunks[2], { right }):align(ui.Paragraph.RIGHT),
}
end

View file

@ -6,18 +6,18 @@ function Manager:render(area)
self.area = area
local chunks = ui.Layout()
:direction(ui.Direction.HORIZONTAL)
:direction(ui.Layout.HORIZONTAL)
:constraints({
ui.Constraint.Ratio(MANAGER.layout.parent, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.layout.current, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.layout.preview, MANAGER.layout.all),
ui.Constraint.Ratio(MANAGER.ratio.parent, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.current, MANAGER.ratio.all),
ui.Constraint.Ratio(MANAGER.ratio.preview, MANAGER.ratio.all),
})
:split(area)
return ya.flat {
-- Borders
ui.Bar(chunks[1], ui.Position.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[3], ui.Position.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[1], ui.Bar.RIGHT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
ui.Bar(chunks[3], ui.Bar.LEFT):symbol(THEME.manager.border_symbol):style(THEME.manager.border_style),
-- Parent
Parent:render(chunks[1]:padding(ui.Padding.x(1))),

View file

@ -148,7 +148,7 @@ function Status:render(area)
local progress = self:progress(area, right:width())
return {
ui.Paragraph(area, { left }),
ui.Paragraph(area, { right }):align(ui.Alignment.RIGHT),
ui.Paragraph(area, { right }):align(ui.Paragraph.RIGHT),
table.unpack(progress),
}
end

View file

@ -2,7 +2,7 @@ local M = {}
function M:peek()
local limit = self.area.h
local child = Command.new("jq")
local child = Command("jq")
:args({
"-C",
"--tab",

View file

@ -1,7 +1,7 @@
local M = {}
function M:preload()
local command = Command.new("file"):arg("--mime-type"):stdout(Command.PIPED):stderr(Command.PIPED)
local command = Command("file"):arg("--mime-type"):stdout(Command.PIPED):stderr(Command.PIPED)
if ya.target_family() == "windows" then
command:arg("-b")
else

View file

@ -23,7 +23,7 @@ function M:preload()
return 1
end
local output = Command.new("pdftoppm")
local output = Command("pdftoppm")
:args({ "-singlefile", "-jpeg", "-jpegopt", "quality=75", "-f", tostring(self.skip + 1), tostring(self.file.url) })
:stdout(Command.PIPED)
:stderr(Command.PIPED)

View file

@ -31,7 +31,7 @@ function M:preload()
return 1
end
local status = Command.new("ffmpegthumbnailer")
local status = Command("ffmpegthumbnailer")
:args({
"-q",
"6",

View file

@ -1,23 +1,4 @@
ui = {
-- FIXME: merge those three into their own modules
Alignment = {
LEFT = 0,
CENTER = 1,
RIGHT = 2,
},
Direction = {
HORIZONTAL = false,
VERTICAL = true,
},
Position = {
NONE = 0,
TOP = 1,
RIGHT = 2,
BOTTOM = 4,
LEFT = 8,
ALL = 15,
},
}
ui = {}
function ui.highlight_ranges(s, ranges)
if ranges == nil or #ranges == 0 then

View file

@ -1,4 +1,5 @@
use mlua::{AnyUserData, ExternalError, Lua, Table, UserData, Value};
use mlua::{AnyUserData, ExternalError, IntoLua, Lua, Table, UserData, Value};
use ratatui::widgets::Borders;
use super::{RectRef, Renderable, Style};
@ -13,24 +14,28 @@ pub struct Bar {
impl Bar {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
ui.set(
"Bar",
lua.create_function(|_, (area, direction): (RectRef, u8)| {
Ok(Self {
area: *area,
let new = lua.create_function(|_, (_, area, direction): (Table, RectRef, u8)| {
Ok(Self {
area: *area,
position: match direction {
1 => ratatui::widgets::Borders::TOP,
2 => ratatui::widgets::Borders::RIGHT,
4 => ratatui::widgets::Borders::BOTTOM,
8 => ratatui::widgets::Borders::LEFT,
_ => ratatui::widgets::Borders::NONE,
},
symbol: Default::default(),
style: Default::default(),
})
})?,
)
position: Borders::from_bits_truncate(direction),
symbol: Default::default(),
style: Default::default(),
})
})?;
let bar = lua.create_table_from([
("NONE", Borders::NONE.bits().into_lua(lua)?),
("TOP", Borders::TOP.bits().into_lua(lua)?),
("RIGHT", Borders::RIGHT.bits().into_lua(lua)?),
("BOTTOM", Borders::BOTTOM.bits().into_lua(lua)?),
("LEFT", Borders::LEFT.bits().into_lua(lua)?),
("ALL", Borders::ALL.bits().into_lua(lua)?),
])?;
bar.set_metatable(Some(lua.create_table_from([("__call", new)])?));
ui.set("Bar", bar)
}
}
@ -57,7 +62,6 @@ impl UserData for Bar {
impl Renderable for Bar {
fn render(self: Box<Self>, buf: &mut ratatui::buffer::Buffer) {
use ratatui::widgets::Borders;
if self.area.area() == 0 {
return;
}

View file

@ -21,22 +21,15 @@ pub struct Border {
impl Border {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
#[inline]
fn new(area: RectRef, position: u8) -> mlua::Result<Border> {
let new = lua.create_function(|_, (_, area, position): (Table, RectRef, u8)| {
Ok(Border {
area: *area,
position: ratatui::widgets::Borders::from_bits_truncate(position),
..Default::default()
})
}
})?;
let border = lua.create_table_from([
(
"new",
lua
.create_function(|_, (area, position): (RectRef, u8)| new(area, position))?
.into_lua(lua)?,
),
// Border type
("PLAIN", PLAIN.into_lua(lua)?),
("ROUNDED", ROUNDED.into_lua(lua)?),
@ -46,10 +39,7 @@ impl Border {
("QUADRANT_OUTSIDE", QUADRANT_OUTSIDE.into_lua(lua)?),
])?;
border.set_metatable(Some(lua.create_table_from([(
"__call",
lua.create_function(|_, (_, area, position): (Table, RectRef, u8)| new(area, position))?,
)])?));
border.set_metatable(Some(lua.create_table_from([("__call", new)])?));
ui.set("Border", border)
}

View file

@ -34,7 +34,7 @@ pub trait Renderable {
fn clone_render(&self, buf: &mut ratatui::buffer::Buffer);
}
pub fn render_widgets(widgets: Vec<AnyUserData>, buf: &mut ratatui::prelude::Buffer) {
pub fn render_widgets(widgets: Vec<AnyUserData>, buf: &mut ratatui::buffer::Buffer) {
for widget in widgets {
if let Some(w) = cast_to_renderable(widget) {
w.render(buf);

View file

@ -1,8 +1,11 @@
use mlua::{AnyUserData, Lua, Table, UserData, UserDataMethods};
use mlua::{AnyUserData, IntoLua, Lua, Table, UserData, UserDataMethods};
use super::{Constraint, Rect, RectRef};
use crate::bindings::Cast;
const HORIZONTAL: bool = true;
const VERTICAL: bool = false;
#[derive(Clone, Default)]
pub struct Layout {
direction: bool,
@ -12,7 +15,16 @@ pub struct Layout {
impl Layout {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
ui.set("Layout", lua.create_function(|_, ()| Ok(Self::default()))?)
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
let layout = lua.create_table_from([
("HORIZONTAL", HORIZONTAL.into_lua(lua)?),
("VERTICAL", VERTICAL.into_lua(lua)?),
])?;
layout.set_metatable(Some(lua.create_table_from([("__call", new)])?));
ui.set("Layout", layout)
}
}
@ -55,13 +67,14 @@ impl UserData for Layout {
methods.add_function("split", |lua, (ud, value): (AnyUserData, RectRef)| {
let me = ud.borrow::<Self>()?;
let mut layout = ratatui::layout::Layout::new()
.direction(if me.direction {
let mut layout = ratatui::layout::Layout::new(
if me.direction == VERTICAL {
ratatui::layout::Direction::Vertical
} else {
ratatui::layout::Direction::Horizontal
})
.constraints(me.constraints.as_slice());
},
&me.constraints,
);
if let Some(margin) = me.margin {
layout = layout.horizontal_margin(margin.horizontal);

View file

@ -1,35 +1,58 @@
use mlua::{AnyUserData, ExternalError, FromLua, Lua, Table, UserData, UserDataMethods, Value};
use mlua::{AnyUserData, ExternalError, FromLua, IntoLua, Lua, Table, UserData, UserDataMethods, Value};
use super::{Span, Style};
const LEFT: u8 = 0;
const CENTER: u8 = 1;
const RIGHT: u8 = 2;
#[derive(Clone, FromLua)]
pub struct Line(pub(super) ratatui::text::Line<'static>);
impl<'a> TryFrom<Table<'a>> for Line {
type Error = mlua::Error;
fn try_from(tbl: Table) -> Result<Self, Self::Error> {
let seq: Vec<_> = tbl.sequence_values().filter_map(|v| v.ok()).collect();
let mut spans = Vec::with_capacity(seq.len());
for value in seq {
if let Value::UserData(ud) = value {
if let Ok(span) = ud.take::<Span>() {
spans.push(span.0);
} else if let Ok(line) = ud.take::<Line>() {
spans.extend(line.0.spans.into_iter().collect::<Vec<_>>());
} else {
return Err("expected a table of Spans or Lines".into_lua_err());
}
}
}
Ok(Self(ratatui::text::Line::from(spans)))
}
}
impl Line {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
ui.set(
"Line",
lua.create_function(|_, value: Value| {
if let Value::Table(tbl) = value {
let seq: Vec<_> = tbl.sequence_values().filter_map(|v| v.ok()).collect();
let mut spans = Vec::with_capacity(seq.len());
for value in seq {
if let Value::UserData(ud) = value {
if let Ok(span) = ud.take::<Span>() {
spans.push(span.0);
} else if let Ok(line) = ud.take::<Line>() {
spans.extend(line.0.spans.into_iter().collect::<Vec<_>>());
} else {
return Err("expected a table of Spans or Lines".into_lua_err());
}
}
}
return Ok(Self(ratatui::text::Line::from(spans)));
}
#[inline]
fn new(value: Value) -> mlua::Result<Line> {
if let Value::Table(tbl) = value {
return Line::try_from(tbl);
}
Err("expected a table of Spans or Lines".into_lua_err())
}
Err("expected a table of Spans or Lines".into_lua_err())
})?,
)
let line = lua.create_table_from([
// Alignment
("LEFT", LEFT.into_lua(lua)?),
("CENTER", CENTER.into_lua(lua)?),
("RIGHT", RIGHT.into_lua(lua)?),
])?;
line.set_metatable(Some(lua.create_table_from([(
"__call",
lua.create_function(|_, (_, value): (Table, Value)| new(value))?,
)])?));
ui.set("Line", line)
}
}
@ -50,9 +73,9 @@ impl UserData for Line {
});
methods.add_function("align", |_, (ud, align): (AnyUserData, u8)| {
ud.borrow_mut::<Self>()?.0.alignment = Some(match align {
1 => ratatui::prelude::Alignment::Center,
2 => ratatui::prelude::Alignment::Right,
_ => ratatui::prelude::Alignment::Left,
CENTER => ratatui::layout::Alignment::Center,
RIGHT => ratatui::layout::Alignment::Right,
_ => ratatui::layout::Alignment::Left,
});
Ok(ud)
});

View file

@ -16,7 +16,6 @@ impl List {
ui.set(
"List",
lua.create_function(|_, (area, items): (RectRef, Vec<ListItem>)| {
let items: Vec<_> = items.into_iter().map(|x| x.into()).collect();
Ok(Self { area: *area, inner: ratatui::widgets::List::new(items) })
})?,
)

View file

@ -8,13 +8,11 @@ pub struct Padding;
impl Padding {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
let new = lua.create_function(|lua, args: (Table, u16, u16, u16, u16)| {
Self::cast(lua, ratatui::widgets::Padding::new(args.1, args.2, args.3, args.4))
})?;
let padding = lua.create_table_from([
(
"new",
lua.create_function(|lua, args: (u16, u16, u16, u16)| {
Self::cast(lua, ratatui::widgets::Padding::new(args.0, args.1, args.2, args.3))
})?,
),
(
"left",
lua.create_function(|lua, left: u16| {
@ -59,12 +57,7 @@ impl Padding {
),
])?;
padding.set_metatable(Some(lua.create_table_from([(
"__call",
lua.create_function(|lua, args: (Table, u16, u16, u16, u16)| {
Self::cast(lua, ratatui::widgets::Padding::new(args.1, args.2, args.3, args.4))
})?,
)])?));
padding.set_metatable(Some(lua.create_table_from([("__call", new)])?));
ui.set("Padding", padding)
}

View file

@ -1,43 +1,45 @@
use ansi_to_tui::IntoText;
use mlua::{AnyUserData, ExternalError, ExternalResult, Lua, Table, UserData, Value};
use mlua::{AnyUserData, ExternalError, ExternalResult, IntoLua, Lua, Table, UserData, Value};
use ratatui::widgets::Widget;
use super::{Line, RectRef, Renderable, Style};
const LEFT: u8 = 0;
const CENTER: u8 = 1;
const RIGHT: u8 = 2;
#[derive(Clone, Debug, Default)]
pub struct Paragraph {
pub area: ratatui::layout::Rect,
pub text: ratatui::text::Text<'static>,
pub style: Option<ratatui::style::Style>,
pub alignment: ratatui::prelude::Alignment,
pub alignment: ratatui::layout::Alignment,
}
impl Paragraph {
pub fn install(lua: &Lua, ui: &Table) -> mlua::Result<()> {
#[inline]
fn new(area: RectRef, lines: Vec<Line>) -> mlua::Result<Paragraph> {
let new = lua.create_function(|_, (_, area, lines): (Table, RectRef, Vec<Line>)| {
Ok(Paragraph {
area: *area,
text: lines.into_iter().map(|s| s.0).collect::<Vec<_>>().into(),
..Default::default()
})
}
})?;
#[inline]
fn parse(area: RectRef, code: mlua::String) -> mlua::Result<Paragraph> {
let parse = lua.create_function(|_, (area, code): (RectRef, mlua::String)| {
Ok(Paragraph { area: *area, text: code.into_text().into_lua_err()?, ..Default::default() })
}
})?;
let paragraph = lua.create_table_from([
("new", lua.create_function(|_, (area, lines): (RectRef, Vec<Line>)| new(area, lines))?),
("parse", lua.create_function(|_, (area, code): (RectRef, mlua::String)| parse(area, code))?),
("parse", parse.into_lua(lua)?),
// Alignment
("LEFT", LEFT.into_lua(lua)?),
("CENTER", CENTER.into_lua(lua)?),
("RIGHT", RIGHT.into_lua(lua)?),
])?;
paragraph.set_metatable(Some(lua.create_table_from([(
"__call",
lua.create_function(|_, (_, area, lines): (Table, RectRef, Vec<Line>)| new(area, lines))?,
)])?));
paragraph.set_metatable(Some(lua.create_table_from([("__call", new)])?));
ui.set("Paragraph", paragraph)
}
@ -59,9 +61,9 @@ impl UserData for Paragraph {
});
methods.add_function("align", |_, (ud, align): (AnyUserData, u8)| {
ud.borrow_mut::<Self>()?.alignment = match align {
1 => ratatui::prelude::Alignment::Center,
2 => ratatui::prelude::Alignment::Right,
_ => ratatui::prelude::Alignment::Left,
CENTER => ratatui::layout::Alignment::Center,
RIGHT => ratatui::layout::Alignment::Right,
_ => ratatui::layout::Alignment::Left,
};
Ok(ud)
});

View file

@ -19,10 +19,10 @@ impl Rect {
})
}
let rect = lua.create_table_from([
("new", lua.create_function(new)?.into_lua(lua)?),
("default", Rect::cast(lua, ratatui::layout::Rect::default())?.into_lua(lua)?),
])?;
let rect = lua.create_table_from([(
"default",
Rect::cast(lua, ratatui::layout::Rect::default())?.into_lua(lua)?,
)])?;
rect.set_metatable(Some(lua.create_table_from([(
"__call",

View file

@ -1,6 +1,6 @@
use std::process::Stdio;
use mlua::{prelude::LuaUserDataMethods, AnyUserData, IntoLua, Lua, UserData};
use mlua::{prelude::LuaUserDataMethods, AnyUserData, IntoLua, Lua, Table, UserData};
use super::{output::Output, Child};
@ -14,23 +14,23 @@ const INHERIT: u8 = 2;
impl Command {
pub fn install(lua: &Lua) -> mlua::Result<()> {
let new = lua.create_function(|_, program: String| {
let new = lua.create_function(|_, (_, program): (Table, String)| {
let mut inner = tokio::process::Command::new(program);
inner.kill_on_drop(true).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());
Ok(Self { inner })
})?;
lua.globals().set(
"Command",
lua.create_table_from([
("new", new.into_lua(lua)?),
// Stdio
("NULL", NULL.into_lua(lua)?),
("PIPED", PIPED.into_lua(lua)?),
("INHERIT", INHERIT.into_lua(lua)?),
])?,
)
let command = lua.create_table_from([
// Stdio
("NULL", NULL.into_lua(lua)?),
("PIPED", PIPED.into_lua(lua)?),
("INHERIT", INHERIT.into_lua(lua)?),
])?;
command.set_metatable(Some(lua.create_table_from([("__call", new)])?));
lua.globals().set("Command", command)
}
}