diff options
Diffstat (limited to 'vendor/anstream')
-rw-r--r-- | vendor/anstream/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | vendor/anstream/Cargo.lock | 1094 | ||||
-rw-r--r-- | vendor/anstream/Cargo.toml | 144 | ||||
-rw-r--r-- | vendor/anstream/LICENSE-APACHE | 202 | ||||
-rw-r--r-- | vendor/anstream/LICENSE-MIT | 19 | ||||
-rw-r--r-- | vendor/anstream/README.md | 34 | ||||
-rw-r--r-- | vendor/anstream/benches/stream.rs | 81 | ||||
-rw-r--r-- | vendor/anstream/benches/strip.rs | 102 | ||||
-rw-r--r-- | vendor/anstream/benches/wincon.rs | 26 | ||||
-rw-r--r-- | vendor/anstream/examples/dump-stream.rs | 128 | ||||
-rw-r--r-- | vendor/anstream/examples/query-stream.rs | 20 | ||||
-rw-r--r-- | vendor/anstream/src/adapter/mod.rs | 15 | ||||
-rw-r--r-- | vendor/anstream/src/adapter/strip.rs | 513 | ||||
-rw-r--r-- | vendor/anstream/src/adapter/wincon.rs | 320 | ||||
-rw-r--r-- | vendor/anstream/src/auto.rs | 263 | ||||
-rw-r--r-- | vendor/anstream/src/buffer.rs | 68 | ||||
-rw-r--r-- | vendor/anstream/src/fmt.rs | 54 | ||||
-rw-r--r-- | vendor/anstream/src/lib.rs | 79 | ||||
-rw-r--r-- | vendor/anstream/src/macros.rs | 389 | ||||
-rw-r--r-- | vendor/anstream/src/stream.rs | 261 | ||||
-rw-r--r-- | vendor/anstream/src/strip.rs | 219 | ||||
-rw-r--r-- | vendor/anstream/src/wincon.rs | 210 |
22 files changed, 4242 insertions, 0 deletions
diff --git a/vendor/anstream/.cargo-checksum.json b/vendor/anstream/.cargo-checksum.json new file mode 100644 index 0000000..8c249ee --- /dev/null +++ b/vendor/anstream/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.lock":"e89078a9d7e89f125bea210c74fd30ef1167c208b9b240baa3fe76ec1170f6ec","Cargo.toml":"38deb1bfcca1eaef87c409274c63f9b25df94f6faaebc74061fa7ef1e4f078f1","LICENSE-APACHE":"c6596eb7be8581c18be736c846fb9173b69eccf6ef94c5135893ec56bd92ba08","LICENSE-MIT":"6efb0476a1cc085077ed49357026d8c173bf33017278ef440f222fb9cbcb66e6","README.md":"b230c2257d0c7a49b9bd97f2fa73abedcdc055757b5cedd2b0eb1a7a448ff461","benches/stream.rs":"7e666c4f4b79ddb5237361ed25264a966ee241192fbb2c1baea3006e3e0326b4","benches/strip.rs":"9603bd5ca1ae4661c2ccab50315dbfdec0c661ac2624262172bbd8f5d0bd87c9","benches/wincon.rs":"680e86933c008b242a3286c5149c33d3c086426eb99fe134b6e79f7578f96663","examples/dump-stream.rs":"54b2bce2409fc1a1f00dbdcab7abbbb6cde447fa20b5c829d1b17ce2e15eefd1","examples/query-stream.rs":"16f38843083174fbefa974a5aa38a5f3ffa51bd6e6db3dc1d91164462219399e","src/adapter/mod.rs":"baf4237ea0b18df63609e49d93572ca27c2202a4cbec0220adb5a7e815c7d8ed","src/adapter/strip.rs":"010972f96708c56da9bced98287f134ce43a4f6459c22c1697abdc4fd6f82d00","src/adapter/wincon.rs":"07d75878ca9edcef4f473a5ff6113b40aab681dcbcd1ae9de1ec895332f7cc2a","src/auto.rs":"71c249ab6b0af64c3946817ea9f1719d4b789128c244611a05075b1e13413007","src/buffer.rs":"83e7088b50dd3e2941c06a417d9eef75fda45311a2912ba94f480ec98d6f0183","src/fmt.rs":"cc11b005c4559843bd908a57958a13c8d0922fae6aff5261f3583c90e60da73c","src/lib.rs":"649b86b187835e0e33baaaf2242c5f331b7dff133fae8fc419c52b7add797c57","src/macros.rs":"a26ababe32a39732d0aade9674f6e5e267bd26c6ea06603ff9e61e80681195e0","src/stream.rs":"cbe8f61fba4c3c60934339c8bda5d1ff43320f57cdc4ed409aa173945a941b3d","src/strip.rs":"56e6516283b6c0dfa72a8e0e6679da8424295f50a3e56c44281e76de6aa0344b","src/wincon.rs":"fe5aff7bfd80b14c9a6b07143079d59b81831293ad766b845e46fad2e1459c9a"},"package":"d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6"}
\ No newline at end of file diff --git a/vendor/anstream/Cargo.lock b/vendor/anstream/Cargo.lock new file mode 100644 index 0000000..2915b67 --- /dev/null +++ b/vendor/anstream/Cargo.lock @@ -0,0 +1,1094 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + +[[package]] +name = "anstream" +version = "0.6.5" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "criterion", + "lexopt", + "owo-colors", + "proptest", + "strip-ansi-escapes", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "anstyle-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" +dependencies = [ + "anstyle", + "windows-sys 0.48.0", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + +[[package]] +name = "bumpalo" +version = "3.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" + +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ciborium" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c137568cc60b904a7724001b35ce2630fd00d5d84805fbb608ab89509d788f" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "346de753af073cc87b52b2083a506b38ac176a44cfb05497b622e27be899b369" + +[[package]] +name = "ciborium-ll" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213030a2b5a4e0c0892b6652260cf6ccac84827b83a85a534e178e3906c4cf1b" +dependencies = [ + "ciborium-io", + "half", +] + +[[package]] +name = "clap" +version = "4.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fffed7514f420abec6d183b1d3acfd9099c79c3a10a06ade4f8203f1411272" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63361bae7eef3771745f02d8d892bec2fee5f6e34af316ba556e7f97a7069ff1" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bd5f3f85273295a9d14aedfb86f6aadbff6d8f5295c4a9edb08e819dcf5695" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c063cd8cc95f5c377ed0d4b49a4b21f632396ff690e8470c29b3359b346984b" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[package]] +name = "errno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "getrandom" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + +[[package]] +name = "hermit-abi" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] + +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi 0.3.1", + "rustix 0.38.11", + "windows-sys 0.48.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "js-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "lexopt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401" + +[[package]] +name = "libc" +version = "0.2.147" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" + +[[package]] +name = "libm" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + +[[package]] +name = "plotters" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538b639e642295546c50fcd545198c9d64ee2a38620a628724a3b266d5fbf97" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193228616381fecdc1224c62e96946dfbc73ff4384fba576e052ff8c1bea8142" + +[[package]] +name = "plotters-svg" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9a81d2759aae1dae668f783c308bc5c8ebd191ff4184aaa1b37f65a6ae5a56f" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags 2.4.0", + "lazy_static", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax 0.8.2", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "rayon" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "regex" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +dependencies = [ + "regex-syntax 0.6.28", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rustix" +version = "0.36.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f43abb88211988493c1abb44a70efa56ff0ce98f233b7b276146f1f3f7ba9644" +dependencies = [ + "bitflags 1.3.2", + "errno 0.2.8", + "io-lifetimes", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + +[[package]] +name = "rustix" +version = "0.38.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0c3dde1fc030af041adc40e79c0e7fbcf431dd24870053d187d7c66e4b87453" +dependencies = [ + "bitflags 2.4.0", + "errno 0.3.3", + "libc", + "linux-raw-sys 0.4.5", + "windows-sys 0.48.0", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "strip-ansi-escapes" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55ff8ef943b384c414f54aefa961dd2bd853add74ec75e7ac74cf91dba62bcfa" +dependencies = [ + "vte", +] + +[[package]] +name = "syn" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix 0.36.8", + "windows-sys 0.42.0", +] + +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + +[[package]] +name = "vte" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5022b5fbf9407086c180e9557be968742d839e68346af7792b8592489732197" +dependencies = [ + "utf8parse", + "vte_generate_state_changes", +] + +[[package]] +name = "vte_generate_state_changes" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d257817081c7dffcdbab24b9e62d2def62e2ff7d00b1c20062551e6cccc145ff" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" + +[[package]] +name = "web-sys" +version = "0.3.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/vendor/anstream/Cargo.toml b/vendor/anstream/Cargo.toml new file mode 100644 index 0000000..a64ec8d --- /dev/null +++ b/vendor/anstream/Cargo.toml @@ -0,0 +1,144 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2021" +rust-version = "1.70.0" +name = "anstream" +version = "0.6.5" +include = [ + "build.rs", + "src/**/*", + "Cargo.toml", + "Cargo.lock", + "LICENSE*", + "README.md", + "benches/**/*", + "examples/**/*", +] +description = "A simple cross platform library for writing colored text to a terminal." +homepage = "https://github.com/rust-cli/anstyle" +readme = "README.md" +keywords = [ + "ansi", + "terminal", + "color", + "strip", + "wincon", +] +categories = ["command-line-interface"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/rust-cli/anstyle.git" + +[package.metadata.docs.rs] +cargo-args = [ + "-Zunstable-options", + "-Zrustdoc-scrape-examples", +] +rustdoc-args = [ + "--cfg", + "docsrs", +] + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +min = 1 +replace = "{{version}}" +search = "Unreleased" + +[[package.metadata.release.pre-release-replacements]] +exactly = 1 +file = "CHANGELOG.md" +replace = "...{{tag_name}}" +search = '\.\.\.HEAD' + +[[package.metadata.release.pre-release-replacements]] +file = "CHANGELOG.md" +min = 1 +replace = "{{date}}" +search = "ReleaseDate" + +[[package.metadata.release.pre-release-replacements]] +exactly = 1 +file = "CHANGELOG.md" +replace = """ +<!-- next-header --> +## [Unreleased] - ReleaseDate +""" +search = "<!-- next-header -->" + +[[package.metadata.release.pre-release-replacements]] +exactly = 1 +file = "CHANGELOG.md" +replace = """ +<!-- next-url --> +[Unreleased]: https://github.com/rust-cli/anstyle/compare/{{tag_name}}...HEAD""" +search = "<!-- next-url -->" + +[[bench]] +name = "strip" +harness = false + +[[bench]] +name = "wincon" +harness = false + +[[bench]] +name = "stream" +harness = false + +[dependencies.anstyle] +version = "1.0.0" + +[dependencies.anstyle-parse] +version = "0.2.0" + +[dependencies.anstyle-query] +version = "1.0.0" +optional = true + +[dependencies.colorchoice] +version = "1.0.0" +optional = true + +[dependencies.utf8parse] +version = "0.2.1" + +[dev-dependencies.criterion] +version = "0.5.1" + +[dev-dependencies.lexopt] +version = "0.3.0" + +[dev-dependencies.owo-colors] +version = "3.5.0" + +[dev-dependencies.proptest] +version = "1.4.0" + +[dev-dependencies.strip-ansi-escapes] +version = "0.2.0" + +[features] +auto = [ + "dep:anstyle-query", + "dep:colorchoice", +] +default = [ + "auto", + "wincon", +] +test = [] +wincon = ["dep:anstyle-wincon"] + +[target."cfg(windows)".dependencies.anstyle-wincon] +version = "3.0.1" +optional = true diff --git a/vendor/anstream/LICENSE-APACHE b/vendor/anstream/LICENSE-APACHE new file mode 100644 index 0000000..8f71f43 --- /dev/null +++ b/vendor/anstream/LICENSE-APACHE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/vendor/anstream/LICENSE-MIT b/vendor/anstream/LICENSE-MIT new file mode 100644 index 0000000..a2d0108 --- /dev/null +++ b/vendor/anstream/LICENSE-MIT @@ -0,0 +1,19 @@ +Copyright (c) Individual contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/anstream/README.md b/vendor/anstream/README.md new file mode 100644 index 0000000..c3d9266 --- /dev/null +++ b/vendor/anstream/README.md @@ -0,0 +1,34 @@ +# anstream + +> A simple cross platform library for writing colored text to a terminal. + +*A portmanteau of "ansi stream"* + +[![Documentation](https://img.shields.io/badge/docs-master-blue.svg)][Documentation] +![License](https://img.shields.io/crates/l/anstream.svg) +[![Crates Status](https://img.shields.io/crates/v/anstream.svg)](https://crates.io/crates/anstream) + +Specialized `stdout` and `stderr` that accept ANSI escape codes and adapt them +based on the terminal's capabilities. + +`anstream::adapter::strip_str` may also be of interest on its own for low +overhead stripping of ANSI escape codes. + +## License + +Licensed under either of + + * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally +submitted for inclusion in the work by you, as defined in the Apache-2.0 +license, shall be dual licensed as above, without any additional terms or +conditions. + +[Crates.io]: https://crates.io/crates/anstream +[Documentation]: https://docs.rs/anstream diff --git a/vendor/anstream/benches/stream.rs b/vendor/anstream/benches/stream.rs new file mode 100644 index 0000000..f89aacf --- /dev/null +++ b/vendor/anstream/benches/stream.rs @@ -0,0 +1,81 @@ +use std::io::Write as _; + +use criterion::{black_box, Criterion}; + +fn stream(c: &mut Criterion) { + for (name, content) in [ + ("demo.vte", &include_bytes!("../tests/demo.vte")[..]), + ("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]), + ("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]), + ( + "state_changes", + &b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..], + ), + ] { + let mut group = c.benchmark_group(name); + group.bench_function("nop", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = buffer; + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + group.bench_function("StripStream", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = anstream::StripStream::new(buffer); + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + #[cfg(all(windows, feature = "wincon"))] + group.bench_function("WinconStream", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = anstream::WinconStream::new(buffer); + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + group.bench_function("AutoStream::always_ansi", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = anstream::AutoStream::always_ansi(buffer); + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + group.bench_function("AutoStream::always", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = anstream::AutoStream::always(buffer); + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + group.bench_function("AutoStream::never", |b| { + b.iter(|| { + let buffer = Vec::with_capacity(content.len()); + let mut stream = anstream::AutoStream::never(buffer); + + stream.write_all(content).unwrap(); + + black_box(stream) + }) + }); + } +} + +criterion::criterion_group!(benches, stream); +criterion::criterion_main!(benches); diff --git a/vendor/anstream/benches/strip.rs b/vendor/anstream/benches/strip.rs new file mode 100644 index 0000000..9ed6178 --- /dev/null +++ b/vendor/anstream/benches/strip.rs @@ -0,0 +1,102 @@ +use criterion::{black_box, Criterion}; + +#[derive(Default)] +struct Strip(String); +impl Strip { + fn with_capacity(capacity: usize) -> Self { + Self(String::with_capacity(capacity)) + } +} +impl anstyle_parse::Perform for Strip { + fn print(&mut self, c: char) { + self.0.push(c); + } + + fn execute(&mut self, byte: u8) { + if byte.is_ascii_whitespace() { + self.0.push(byte as char); + } + } +} + +fn strip(c: &mut Criterion) { + for (name, content) in [ + ("demo.vte", &include_bytes!("../tests/demo.vte")[..]), + ("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]), + ("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]), + ( + "state_changes", + &b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..], + ), + ] { + // Make sure the comparison is fair + if let Ok(content) = std::str::from_utf8(content) { + let mut stripped = Strip::with_capacity(content.len()); + let mut parser = anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new(); + for byte in content.as_bytes() { + parser.advance(&mut stripped, *byte); + } + assert_eq!( + stripped.0, + anstream::adapter::strip_str(content).to_string() + ); + assert_eq!( + stripped.0, + String::from_utf8(anstream::adapter::strip_bytes(content.as_bytes()).into_vec()) + .unwrap() + ); + } + + let mut group = c.benchmark_group(name); + group.bench_function("advance_strip", |b| { + b.iter(|| { + let mut stripped = Strip::with_capacity(content.len()); + let mut parser = + anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new(); + + for byte in content { + parser.advance(&mut stripped, *byte); + } + + black_box(stripped.0) + }) + }); + group.bench_function("strip_ansi_escapes", |b| { + b.iter(|| { + let stripped = strip_ansi_escapes::strip(content); + + black_box(stripped) + }) + }); + if let Ok(content) = std::str::from_utf8(content) { + group.bench_function("strip_str", |b| { + b.iter(|| { + let stripped = anstream::adapter::strip_str(content).to_string(); + + black_box(stripped) + }) + }); + group.bench_function("StripStr", |b| { + b.iter(|| { + let mut stripped = String::with_capacity(content.len()); + let mut state = anstream::adapter::StripStr::new(); + for printable in state.strip_next(content) { + stripped.push_str(printable); + } + + black_box(stripped) + }) + }); + } + group.bench_function("strip_bytes", |b| { + b.iter(|| { + let stripped = anstream::adapter::strip_bytes(content).into_vec(); + + black_box(stripped) + }) + }); + } +} + +criterion::criterion_group!(benches, strip); +criterion::criterion_main!(benches); diff --git a/vendor/anstream/benches/wincon.rs b/vendor/anstream/benches/wincon.rs new file mode 100644 index 0000000..54e1f80 --- /dev/null +++ b/vendor/anstream/benches/wincon.rs @@ -0,0 +1,26 @@ +use criterion::{black_box, Criterion}; + +fn wincon(c: &mut Criterion) { + for (name, content) in [ + ("demo.vte", &include_bytes!("../tests/demo.vte")[..]), + ("rg_help.vte", &include_bytes!("../tests/rg_help.vte")[..]), + ("rg_linus.vte", &include_bytes!("../tests/rg_linus.vte")[..]), + ( + "state_changes", + &b"\x1b]2;X\x1b\\ \x1b[0m \x1bP0@\x1b\\"[..], + ), + ] { + let mut group = c.benchmark_group(name); + group.bench_function("wincon_bytes", |b| { + b.iter(|| { + let mut state = anstream::adapter::WinconBytes::new(); + let stripped = state.extract_next(content).collect::<Vec<_>>(); + + black_box(stripped) + }) + }); + } +} + +criterion::criterion_group!(benches, wincon); +criterion::criterion_main!(benches); diff --git a/vendor/anstream/examples/dump-stream.rs b/vendor/anstream/examples/dump-stream.rs new file mode 100644 index 0000000..86c768c --- /dev/null +++ b/vendor/anstream/examples/dump-stream.rs @@ -0,0 +1,128 @@ +use std::io::Write; + +fn main() -> Result<(), lexopt::Error> { + let args = Args::parse()?; + let stdout = anstream::stdout(); + let mut stdout = stdout.lock(); + + for fixed in 0..16 { + let style = style(fixed, args.layer, args.effects); + let _ = print_number(&mut stdout, fixed, style); + if fixed == 7 || fixed == 15 { + let _ = writeln!(&mut stdout); + } + } + + for r in 0..6 { + let _ = writeln!(stdout); + for g in 0..6 { + for b in 0..6 { + let fixed = r * 36 + g * 6 + b + 16; + let style = style(fixed, args.layer, args.effects); + let _ = print_number(&mut stdout, fixed, style); + } + let _ = writeln!(stdout); + } + } + + for c in 0..24 { + if 0 == c % 8 { + let _ = writeln!(stdout); + } + let fixed = 232 + c; + let style = style(fixed, args.layer, args.effects); + let _ = print_number(&mut stdout, fixed, style); + } + + Ok(()) +} + +fn style(fixed: u8, layer: Layer, effects: anstyle::Effects) -> anstyle::Style { + let color = anstyle::Ansi256Color(fixed).into(); + (match layer { + Layer::Fg => anstyle::Style::new().fg_color(Some(color)), + Layer::Bg => anstyle::Style::new().bg_color(Some(color)), + Layer::Underline => anstyle::Style::new().underline_color(Some(color)), + }) | effects +} + +fn print_number(stdout: &mut impl Write, fixed: u8, style: anstyle::Style) -> std::io::Result<()> { + write!( + stdout, + "{}{:>4}{}", + style.render(), + fixed, + anstyle::Reset.render() + ) +} + +#[derive(Default)] +struct Args { + effects: anstyle::Effects, + layer: Layer, +} + +#[derive(Copy, Clone, Default)] +enum Layer { + #[default] + Fg, + Bg, + Underline, +} + +impl Args { + fn parse() -> Result<Self, lexopt::Error> { + use lexopt::prelude::*; + + let mut res = Args::default(); + + let mut args = lexopt::Parser::from_env(); + while let Some(arg) = args.next()? { + match arg { + Long("layer") => { + res.layer = args.value()?.parse_with(|s| match s { + "fg" => Ok(Layer::Fg), + "bg" => Ok(Layer::Bg), + "underline" => Ok(Layer::Underline), + _ => Err("expected values fg, bg, underline"), + })?; + } + Long("effect") => { + const EFFECTS: [(&str, anstyle::Effects); 12] = [ + ("bold", anstyle::Effects::BOLD), + ("dimmed", anstyle::Effects::DIMMED), + ("italic", anstyle::Effects::ITALIC), + ("underline", anstyle::Effects::UNDERLINE), + ("double_underline", anstyle::Effects::DOUBLE_UNDERLINE), + ("curly_underline", anstyle::Effects::CURLY_UNDERLINE), + ("dotted_underline", anstyle::Effects::DOTTED_UNDERLINE), + ("dashed_underline", anstyle::Effects::DASHED_UNDERLINE), + ("blink", anstyle::Effects::BLINK), + ("invert", anstyle::Effects::INVERT), + ("hidden", anstyle::Effects::HIDDEN), + ("strikethrough", anstyle::Effects::STRIKETHROUGH), + ]; + let effect = args.value()?.parse_with(|s| { + EFFECTS + .into_iter() + .find(|(name, _)| *name == s) + .map(|(_, effect)| effect) + .ok_or_else(|| { + format!( + "expected one of {}", + EFFECTS + .into_iter() + .map(|(n, _)| n) + .collect::<Vec<_>>() + .join(", ") + ) + }) + })?; + res.effects = res.effects.insert(effect); + } + _ => return Err(arg.unexpected()), + } + } + Ok(res) + } +} diff --git a/vendor/anstream/examples/query-stream.rs b/vendor/anstream/examples/query-stream.rs new file mode 100644 index 0000000..fe0af95 --- /dev/null +++ b/vendor/anstream/examples/query-stream.rs @@ -0,0 +1,20 @@ +fn main() { + println!("stdout:"); + println!( + " choice: {:?}", + anstream::AutoStream::choice(&std::io::stdout()) + ); + println!( + " choice: {:?}", + anstream::AutoStream::auto(std::io::stdout()).current_choice() + ); + println!("stderr:"); + println!( + " choice: {:?}", + anstream::AutoStream::choice(&std::io::stderr()) + ); + println!( + " choice: {:?}", + anstream::AutoStream::auto(std::io::stderr()).current_choice() + ); +} diff --git a/vendor/anstream/src/adapter/mod.rs b/vendor/anstream/src/adapter/mod.rs new file mode 100644 index 0000000..f266b68 --- /dev/null +++ b/vendor/anstream/src/adapter/mod.rs @@ -0,0 +1,15 @@ +//! Gracefully degrade styled output + +mod strip; +mod wincon; + +pub use strip::strip_bytes; +pub use strip::strip_str; +pub use strip::StripBytes; +pub use strip::StripBytesIter; +pub use strip::StripStr; +pub use strip::StripStrIter; +pub use strip::StrippedBytes; +pub use strip::StrippedStr; +pub use wincon::WinconBytes; +pub use wincon::WinconBytesIter; diff --git a/vendor/anstream/src/adapter/strip.rs b/vendor/anstream/src/adapter/strip.rs new file mode 100644 index 0000000..5078c51 --- /dev/null +++ b/vendor/anstream/src/adapter/strip.rs @@ -0,0 +1,513 @@ +use anstyle_parse::state::state_change; +use anstyle_parse::state::Action; +use anstyle_parse::state::State; + +/// Strip ANSI escapes from a `&str`, returning the printable content +/// +/// This can be used to take output from a program that includes escape sequences and write it +/// somewhere that does not easily support them, such as a log file. +/// +/// For non-contiguous data, see [`StripStr`]. +/// +/// # Example +/// +/// ```rust +/// use std::io::Write as _; +/// +/// let styled_text = "\x1b[32mfoo\x1b[m bar"; +/// let plain_str = anstream::adapter::strip_str(&styled_text).to_string(); +/// assert_eq!(plain_str, "foo bar"); +/// ``` +#[inline] +pub fn strip_str(data: &str) -> StrippedStr<'_> { + StrippedStr::new(data) +} + +/// See [`strip_str`] +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct StrippedStr<'s> { + bytes: &'s [u8], + state: State, +} + +impl<'s> StrippedStr<'s> { + #[inline] + fn new(data: &'s str) -> Self { + Self { + bytes: data.as_bytes(), + state: State::Ground, + } + } + + /// Create a [`String`] of the printable content + #[inline] + #[allow(clippy::inherent_to_string_shadow_display)] // Single-allocation implementation + pub fn to_string(&self) -> String { + use std::fmt::Write as _; + let mut stripped = String::with_capacity(self.bytes.len()); + let _ = write!(&mut stripped, "{}", self); + stripped + } +} + +impl<'s> std::fmt::Display for StrippedStr<'s> { + /// **Note:** this does *not* exhaust the [`Iterator`] + #[inline] + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let iter = Self { + bytes: self.bytes, + state: self.state, + }; + for printable in iter { + printable.fmt(f)?; + } + Ok(()) + } +} + +impl<'s> Iterator for StrippedStr<'s> { + type Item = &'s str; + + #[inline] + fn next(&mut self) -> Option<Self::Item> { + next_str(&mut self.bytes, &mut self.state) + } +} + +/// Incrementally strip non-contiguous data +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct StripStr { + state: State, +} + +impl StripStr { + /// Initial state + pub fn new() -> Self { + Default::default() + } + + /// Strip the next segment of data + pub fn strip_next<'s>(&'s mut self, data: &'s str) -> StripStrIter<'s> { + StripStrIter { + bytes: data.as_bytes(), + state: &mut self.state, + } + } +} + +/// See [`StripStr`] +#[derive(Debug, PartialEq, Eq)] +pub struct StripStrIter<'s> { + bytes: &'s [u8], + state: &'s mut State, +} + +impl<'s> Iterator for StripStrIter<'s> { + type Item = &'s str; + + #[inline] + fn next(&mut self) -> Option<Self::Item> { + next_str(&mut self.bytes, self.state) + } +} + +#[inline] +fn next_str<'s>(bytes: &mut &'s [u8], state: &mut State) -> Option<&'s str> { + let offset = bytes.iter().copied().position(|b| { + let (next_state, action) = state_change(*state, b); + if next_state != State::Anywhere { + *state = next_state; + } + is_printable_str(action, b) + }); + let (_, next) = bytes.split_at(offset.unwrap_or(bytes.len())); + *bytes = next; + *state = State::Ground; + + let offset = bytes.iter().copied().position(|b| { + let (_next_state, action) = state_change(State::Ground, b); + !is_printable_str(action, b) + }); + let (printable, next) = bytes.split_at(offset.unwrap_or(bytes.len())); + *bytes = next; + if printable.is_empty() { + None + } else { + let printable = unsafe { + from_utf8_unchecked( + printable, + "`bytes` was validated as UTF-8, the parser preserves UTF-8 continuations", + ) + }; + Some(printable) + } +} + +#[inline] +unsafe fn from_utf8_unchecked<'b>(bytes: &'b [u8], safety_justification: &'static str) -> &'b str { + if cfg!(debug_assertions) { + // Catch problems more quickly when testing + std::str::from_utf8(bytes).expect(safety_justification) + } else { + std::str::from_utf8_unchecked(bytes) + } +} + +#[inline] +fn is_printable_str(action: Action, byte: u8) -> bool { + // VT320 considered 0x7f to be `Print`able but we expect to be working in UTF-8 systems and not + // ISO Latin-1, making it DEL and non-printable + const DEL: u8 = 0x7f; + (action == Action::Print && byte != DEL) + || action == Action::BeginUtf8 + // since we know the input is valid UTF-8, the only thing we can do with + // continuations is to print them + || is_utf8_continuation(byte) + || (action == Action::Execute && byte.is_ascii_whitespace()) +} + +#[inline] +fn is_utf8_continuation(b: u8) -> bool { + matches!(b, 0x80..=0xbf) +} + +/// Strip ANSI escapes from bytes, returning the printable content +/// +/// This can be used to take output from a program that includes escape sequences and write it +/// somewhere that does not easily support them, such as a log file. +/// +/// # Example +/// +/// ```rust +/// use std::io::Write as _; +/// +/// let styled_text = "\x1b[32mfoo\x1b[m bar"; +/// let plain_str = anstream::adapter::strip_bytes(styled_text.as_bytes()).into_vec(); +/// assert_eq!(plain_str.as_slice(), &b"foo bar"[..]); +/// ``` +#[inline] +pub fn strip_bytes(data: &[u8]) -> StrippedBytes<'_> { + StrippedBytes::new(data) +} + +/// See [`strip_bytes`] +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct StrippedBytes<'s> { + bytes: &'s [u8], + state: State, + utf8parser: Utf8Parser, +} + +impl<'s> StrippedBytes<'s> { + /// See [`strip_bytes`] + #[inline] + pub fn new(bytes: &'s [u8]) -> Self { + Self { + bytes, + state: State::Ground, + utf8parser: Default::default(), + } + } + + /// Strip the next slice of bytes + /// + /// Used when the content is in several non-contiguous slices + /// + /// # Panic + /// + /// May panic if it is not exhausted / empty + #[inline] + pub fn extend(&mut self, bytes: &'s [u8]) { + debug_assert!( + self.is_empty(), + "current bytes must be processed to ensure we end at the right state" + ); + self.bytes = bytes; + } + + /// Report the bytes has been exhausted + #[inline] + pub fn is_empty(&self) -> bool { + self.bytes.is_empty() + } + + /// Create a [`Vec`] of the printable content + #[inline] + pub fn into_vec(self) -> Vec<u8> { + let mut stripped = Vec::with_capacity(self.bytes.len()); + for printable in self { + stripped.extend(printable); + } + stripped + } +} + +impl<'s> Iterator for StrippedBytes<'s> { + type Item = &'s [u8]; + + #[inline] + fn next(&mut self) -> Option<Self::Item> { + next_bytes(&mut self.bytes, &mut self.state, &mut self.utf8parser) + } +} + +/// Incrementally strip non-contiguous data +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct StripBytes { + state: State, + utf8parser: Utf8Parser, +} + +impl StripBytes { + /// Initial state + pub fn new() -> Self { + Default::default() + } + + /// Strip the next segment of data + pub fn strip_next<'s>(&'s mut self, bytes: &'s [u8]) -> StripBytesIter<'s> { + StripBytesIter { + bytes, + state: &mut self.state, + utf8parser: &mut self.utf8parser, + } + } +} + +/// See [`StripBytes`] +#[derive(Debug, PartialEq, Eq)] +pub struct StripBytesIter<'s> { + bytes: &'s [u8], + state: &'s mut State, + utf8parser: &'s mut Utf8Parser, +} + +impl<'s> Iterator for StripBytesIter<'s> { + type Item = &'s [u8]; + + #[inline] + fn next(&mut self) -> Option<Self::Item> { + next_bytes(&mut self.bytes, self.state, self.utf8parser) + } +} + +#[inline] +fn next_bytes<'s>( + bytes: &mut &'s [u8], + state: &mut State, + utf8parser: &mut Utf8Parser, +) -> Option<&'s [u8]> { + let offset = bytes.iter().copied().position(|b| { + if *state == State::Utf8 { + true + } else { + let (next_state, action) = state_change(*state, b); + if next_state != State::Anywhere { + *state = next_state; + } + is_printable_bytes(action, b) + } + }); + let (_, next) = bytes.split_at(offset.unwrap_or(bytes.len())); + *bytes = next; + + let offset = bytes.iter().copied().position(|b| { + if *state == State::Utf8 { + if utf8parser.add(b) { + *state = State::Ground; + } + false + } else { + let (next_state, action) = state_change(State::Ground, b); + if next_state != State::Anywhere { + *state = next_state; + } + if *state == State::Utf8 { + utf8parser.add(b); + false + } else { + !is_printable_bytes(action, b) + } + } + }); + let (printable, next) = bytes.split_at(offset.unwrap_or(bytes.len())); + *bytes = next; + if printable.is_empty() { + None + } else { + Some(printable) + } +} + +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct Utf8Parser { + utf8_parser: utf8parse::Parser, +} + +impl Utf8Parser { + fn add(&mut self, byte: u8) -> bool { + let mut b = false; + let mut receiver = VtUtf8Receiver(&mut b); + self.utf8_parser.advance(&mut receiver, byte); + b + } +} + +struct VtUtf8Receiver<'a>(&'a mut bool); + +impl<'a> utf8parse::Receiver for VtUtf8Receiver<'a> { + fn codepoint(&mut self, _: char) { + *self.0 = true; + } + + fn invalid_sequence(&mut self) { + *self.0 = true; + } +} + +#[inline] +fn is_printable_bytes(action: Action, byte: u8) -> bool { + // VT320 considered 0x7f to be `Print`able but we expect to be working in UTF-8 systems and not + // ISO Latin-1, making it DEL and non-printable + const DEL: u8 = 0x7f; + + // Continuations aren't included as they may also be control codes, requiring more context + (action == Action::Print && byte != DEL) + || action == Action::BeginUtf8 + || (action == Action::Execute && byte.is_ascii_whitespace()) +} + +#[cfg(test)] +mod test { + use super::*; + use proptest::prelude::*; + + /// Model based off full parser + fn parser_strip(bytes: &[u8]) -> String { + #[derive(Default)] + struct Strip(String); + impl Strip { + fn with_capacity(capacity: usize) -> Self { + Self(String::with_capacity(capacity)) + } + } + impl anstyle_parse::Perform for Strip { + fn print(&mut self, c: char) { + self.0.push(c); + } + + fn execute(&mut self, byte: u8) { + if byte.is_ascii_whitespace() { + self.0.push(byte as char); + } + } + } + + let mut stripped = Strip::with_capacity(bytes.len()); + let mut parser = anstyle_parse::Parser::<anstyle_parse::DefaultCharAccumulator>::new(); + for byte in bytes { + parser.advance(&mut stripped, *byte); + } + stripped.0 + } + + /// Model verifying incremental parsing + fn strip_char(mut s: &str) -> String { + let mut result = String::new(); + let mut state = StripStr::new(); + while !s.is_empty() { + let mut indices = s.char_indices(); + indices.next(); // current + let offset = indices.next().map(|(i, _)| i).unwrap_or_else(|| s.len()); + let (current, remainder) = s.split_at(offset); + for printable in state.strip_next(current) { + result.push_str(printable); + } + s = remainder; + } + result + } + + /// Model verifying incremental parsing + fn strip_byte(s: &[u8]) -> Vec<u8> { + let mut result = Vec::new(); + let mut state = StripBytes::default(); + for start in 0..s.len() { + let current = &s[start..=start]; + for printable in state.strip_next(current) { + result.extend(printable); + } + } + result + } + + #[test] + fn test_strip_bytes_multibyte() { + let bytes = [240, 145, 141, 139]; + let expected = parser_strip(&bytes); + let actual = String::from_utf8(strip_bytes(&bytes).into_vec()).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_strip_byte_multibyte() { + let bytes = [240, 145, 141, 139]; + let expected = parser_strip(&bytes); + let actual = String::from_utf8(strip_byte(&bytes).to_vec()).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + fn test_strip_str_del() { + let input = std::str::from_utf8(&[0x7f]).unwrap(); + let expected = ""; + let actual = strip_str(input).to_string(); + assert_eq!(expected, actual); + } + + #[test] + fn test_strip_byte_del() { + let bytes = [0x7f]; + let expected = ""; + let actual = String::from_utf8(strip_byte(&bytes).to_vec()).unwrap(); + assert_eq!(expected, actual); + } + + proptest! { + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn strip_str_no_escapes(s in "\\PC*") { + let expected = parser_strip(s.as_bytes()); + let actual = strip_str(&s).to_string(); + assert_eq!(expected, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn strip_char_no_escapes(s in "\\PC*") { + let expected = parser_strip(s.as_bytes()); + let actual = strip_char(&s); + assert_eq!(expected, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn strip_bytes_no_escapes(s in "\\PC*") { + dbg!(&s); + dbg!(s.as_bytes()); + let expected = parser_strip(s.as_bytes()); + let actual = String::from_utf8(strip_bytes(s.as_bytes()).into_vec()).unwrap(); + assert_eq!(expected, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn strip_byte_no_escapes(s in "\\PC*") { + dbg!(&s); + dbg!(s.as_bytes()); + let expected = parser_strip(s.as_bytes()); + let actual = String::from_utf8(strip_byte(s.as_bytes()).to_vec()).unwrap(); + assert_eq!(expected, actual); + } + } +} diff --git a/vendor/anstream/src/adapter/wincon.rs b/vendor/anstream/src/adapter/wincon.rs new file mode 100644 index 0000000..de3da65 --- /dev/null +++ b/vendor/anstream/src/adapter/wincon.rs @@ -0,0 +1,320 @@ +/// Incrementally convert to wincon calls for non-contiguous data +#[derive(Default, Clone, Debug, PartialEq, Eq)] +pub struct WinconBytes { + parser: anstyle_parse::Parser, + capture: WinconCapture, +} + +impl WinconBytes { + /// Initial state + pub fn new() -> Self { + Default::default() + } + + /// Strip the next segment of data + pub fn extract_next<'s>(&'s mut self, bytes: &'s [u8]) -> WinconBytesIter<'s> { + self.capture.reset(); + self.capture.printable.reserve(bytes.len()); + WinconBytesIter { + bytes, + parser: &mut self.parser, + capture: &mut self.capture, + } + } +} + +/// See [`WinconBytes`] +#[derive(Debug, PartialEq, Eq)] +pub struct WinconBytesIter<'s> { + bytes: &'s [u8], + parser: &'s mut anstyle_parse::Parser, + capture: &'s mut WinconCapture, +} + +impl<'s> Iterator for WinconBytesIter<'s> { + type Item = (anstyle::Style, String); + + #[inline] + fn next(&mut self) -> Option<Self::Item> { + next_bytes(&mut self.bytes, self.parser, self.capture) + } +} + +#[inline] +fn next_bytes( + bytes: &mut &[u8], + parser: &mut anstyle_parse::Parser, + capture: &mut WinconCapture, +) -> Option<(anstyle::Style, String)> { + capture.reset(); + while capture.ready.is_none() { + let byte = if let Some((byte, remainder)) = (*bytes).split_first() { + *bytes = remainder; + *byte + } else { + break; + }; + parser.advance(capture, byte); + } + if capture.printable.is_empty() { + return None; + } + + let style = capture.ready.unwrap_or(capture.style); + Some((style, std::mem::take(&mut capture.printable))) +} + +#[derive(Default, Clone, Debug, PartialEq, Eq)] +struct WinconCapture { + style: anstyle::Style, + printable: String, + ready: Option<anstyle::Style>, +} + +impl WinconCapture { + fn reset(&mut self) { + self.ready = None; + } +} + +impl anstyle_parse::Perform for WinconCapture { + /// Draw a character to the screen and update states. + fn print(&mut self, c: char) { + self.printable.push(c); + } + + /// Execute a C0 or C1 control function. + fn execute(&mut self, byte: u8) { + if byte.is_ascii_whitespace() { + self.printable.push(byte as char); + } + } + + fn csi_dispatch( + &mut self, + params: &anstyle_parse::Params, + _intermediates: &[u8], + ignore: bool, + action: u8, + ) { + if ignore { + return; + } + if action != b'm' { + return; + } + + let mut style = self.style; + // param/value differences are dependent on the escape code + let mut state = State::Normal; + let mut r = None; + let mut g = None; + let mut is_bg = false; + for param in params { + for value in param { + match (state, *value) { + (State::Normal, 0) => { + style = anstyle::Style::default(); + break; + } + (State::Normal, 1) => { + style = style.bold(); + break; + } + (State::Normal, 4) => { + style = style.underline(); + break; + } + (State::Normal, 30..=37) => { + let color = to_ansi_color(value - 30).unwrap(); + style = style.fg_color(Some(color.into())); + break; + } + (State::Normal, 38) => { + is_bg = false; + state = State::PrepareCustomColor; + } + (State::Normal, 39) => { + style = style.fg_color(None); + break; + } + (State::Normal, 40..=47) => { + let color = to_ansi_color(value - 40).unwrap(); + style = style.bg_color(Some(color.into())); + break; + } + (State::Normal, 48) => { + is_bg = true; + state = State::PrepareCustomColor; + } + (State::Normal, 49) => { + style = style.bg_color(None); + break; + } + (State::Normal, 90..=97) => { + let color = to_ansi_color(value - 90).unwrap().bright(true); + style = style.fg_color(Some(color.into())); + break; + } + (State::Normal, 100..=107) => { + let color = to_ansi_color(value - 100).unwrap().bright(true); + style = style.bg_color(Some(color.into())); + break; + } + (State::PrepareCustomColor, 5) => { + state = State::Ansi256; + } + (State::PrepareCustomColor, 2) => { + state = State::Rgb; + r = None; + g = None; + } + (State::Ansi256, n) => { + let color = anstyle::Ansi256Color(n as u8); + if is_bg { + style = style.bg_color(Some(color.into())); + } else { + style = style.fg_color(Some(color.into())); + } + break; + } + (State::Rgb, b) => match (r, g) { + (None, _) => { + r = Some(b); + } + (Some(_), None) => { + g = Some(b); + } + (Some(r), Some(g)) => { + let color = anstyle::RgbColor(r as u8, g as u8, b as u8); + if is_bg { + style = style.bg_color(Some(color.into())); + } else { + style = style.fg_color(Some(color.into())); + } + break; + } + }, + _ => { + break; + } + } + } + } + + if style != self.style && !self.printable.is_empty() { + self.ready = Some(self.style); + } + self.style = style; + } +} + +#[derive(Copy, Clone, PartialEq, Eq, Debug)] +enum State { + Normal, + PrepareCustomColor, + Ansi256, + Rgb, +} + +fn to_ansi_color(digit: u16) -> Option<anstyle::AnsiColor> { + match digit { + 0 => Some(anstyle::AnsiColor::Black), + 1 => Some(anstyle::AnsiColor::Red), + 2 => Some(anstyle::AnsiColor::Green), + 3 => Some(anstyle::AnsiColor::Yellow), + 4 => Some(anstyle::AnsiColor::Blue), + 5 => Some(anstyle::AnsiColor::Magenta), + 6 => Some(anstyle::AnsiColor::Cyan), + 7 => Some(anstyle::AnsiColor::White), + _ => None, + } +} + +#[cfg(test)] +mod test { + use super::*; + use owo_colors::OwoColorize as _; + use proptest::prelude::*; + + #[track_caller] + fn verify(input: &str, expected: Vec<(anstyle::Style, &str)>) { + let expected = expected + .into_iter() + .map(|(style, value)| (style, value.to_owned())) + .collect::<Vec<_>>(); + let mut state = WinconBytes::new(); + let actual = state.extract_next(input.as_bytes()).collect::<Vec<_>>(); + assert_eq!(expected, actual, "{input:?}"); + } + + #[test] + fn start() { + let input = format!("{} world!", "Hello".green().on_red()); + let expected = vec![ + ( + anstyle::AnsiColor::Green.on(anstyle::AnsiColor::Red), + "Hello", + ), + (anstyle::Style::default(), " world!"), + ]; + verify(&input, expected); + } + + #[test] + fn middle() { + let input = format!("Hello {}!", "world".green().on_red()); + let expected = vec![ + (anstyle::Style::default(), "Hello "), + ( + anstyle::AnsiColor::Green.on(anstyle::AnsiColor::Red), + "world", + ), + (anstyle::Style::default(), "!"), + ]; + verify(&input, expected); + } + + #[test] + fn end() { + let input = format!("Hello {}", "world!".green().on_red()); + let expected = vec![ + (anstyle::Style::default(), "Hello "), + ( + anstyle::AnsiColor::Green.on(anstyle::AnsiColor::Red), + "world!", + ), + ]; + verify(&input, expected); + } + + #[test] + fn ansi256_colors() { + // termcolor only supports "brights" via these + let input = format!( + "Hello {}!", + "world".color(owo_colors::XtermColors::UserBrightYellow) + ); + let expected = vec![ + (anstyle::Style::default(), "Hello "), + (anstyle::Ansi256Color(11).on_default(), "world"), + (anstyle::Style::default(), "!"), + ]; + verify(&input, expected); + } + + proptest! { + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn wincon_no_escapes(s in "\\PC*") { + let expected = if s.is_empty() { + vec![] + } else { + vec![(anstyle::Style::default(), s.clone())] + }; + let mut state = WinconBytes::new(); + let actual = state.extract_next(s.as_bytes()).collect::<Vec<_>>(); + assert_eq!(expected, actual); + } + } +} diff --git a/vendor/anstream/src/auto.rs b/vendor/anstream/src/auto.rs new file mode 100644 index 0000000..7aaac6a --- /dev/null +++ b/vendor/anstream/src/auto.rs @@ -0,0 +1,263 @@ +use crate::stream::AsLockedWrite; +use crate::stream::RawStream; +#[cfg(feature = "auto")] +use crate::ColorChoice; +use crate::StripStream; +#[cfg(all(windows, feature = "wincon"))] +use crate::WinconStream; + +/// [`std::io::Write`] that adapts ANSI escape codes to the underlying `Write`s capabilities +#[derive(Debug)] +pub struct AutoStream<S: RawStream> { + inner: StreamInner<S>, +} + +#[derive(Debug)] +enum StreamInner<S: RawStream> { + PassThrough(S), + Strip(StripStream<S>), + #[cfg(all(windows, feature = "wincon"))] + Wincon(WinconStream<S>), +} + +impl<S> AutoStream<S> +where + S: RawStream, +{ + /// Runtime control over styling behavior + #[cfg(feature = "auto")] + #[inline] + pub fn new(raw: S, choice: ColorChoice) -> Self { + match choice { + ColorChoice::Auto => Self::auto(raw), + ColorChoice::AlwaysAnsi => Self::always_ansi(raw), + ColorChoice::Always => Self::always(raw), + ColorChoice::Never => Self::never(raw), + } + } + + /// Auto-adapt for the stream's capabilities + #[cfg(feature = "auto")] + #[inline] + pub fn auto(raw: S) -> Self { + let choice = Self::choice(&raw); + debug_assert_ne!(choice, ColorChoice::Auto); + Self::new(raw, choice) + } + + /// Report the desired choice for the given stream + #[cfg(feature = "auto")] + pub fn choice(raw: &S) -> ColorChoice { + choice(raw) + } + + /// Force ANSI escape codes to be passed through as-is, no matter what the inner `Write` + /// supports. + #[inline] + pub fn always_ansi(raw: S) -> Self { + #[cfg(feature = "auto")] + { + if raw.is_terminal() { + let _ = anstyle_query::windows::enable_ansi_colors(); + } + } + Self::always_ansi_(raw) + } + + #[inline] + fn always_ansi_(raw: S) -> Self { + let inner = StreamInner::PassThrough(raw); + AutoStream { inner } + } + + /// Force color, no matter what the inner `Write` supports. + #[inline] + pub fn always(raw: S) -> Self { + if cfg!(windows) { + #[cfg(feature = "auto")] + let use_wincon = raw.is_terminal() + && !anstyle_query::windows::enable_ansi_colors().unwrap_or(true) + && !anstyle_query::term_supports_ansi_color(); + #[cfg(not(feature = "auto"))] + let use_wincon = true; + if use_wincon { + Self::wincon(raw).unwrap_or_else(|raw| Self::always_ansi_(raw)) + } else { + Self::always_ansi_(raw) + } + } else { + Self::always_ansi(raw) + } + } + + /// Only pass printable data to the inner `Write`. + #[inline] + pub fn never(raw: S) -> Self { + let inner = StreamInner::Strip(StripStream::new(raw)); + AutoStream { inner } + } + + #[inline] + fn wincon(raw: S) -> Result<Self, S> { + #[cfg(all(windows, feature = "wincon"))] + { + Ok(Self { + inner: StreamInner::Wincon(WinconStream::new(raw)), + }) + } + #[cfg(not(all(windows, feature = "wincon")))] + { + Err(raw) + } + } + + /// Get the wrapped [`RawStream`] + #[inline] + pub fn into_inner(self) -> S { + match self.inner { + StreamInner::PassThrough(w) => w, + StreamInner::Strip(w) => w.into_inner(), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.into_inner(), + } + } + + #[inline] + pub fn is_terminal(&self) -> bool { + match &self.inner { + StreamInner::PassThrough(w) => w.is_terminal(), + StreamInner::Strip(w) => w.is_terminal(), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(_) => true, // its only ever a terminal + } + } + + /// Prefer [`AutoStream::choice`] + /// + /// This doesn't report what is requested but what is currently active. + #[inline] + #[cfg(feature = "auto")] + pub fn current_choice(&self) -> ColorChoice { + match &self.inner { + StreamInner::PassThrough(_) => ColorChoice::AlwaysAnsi, + StreamInner::Strip(_) => ColorChoice::Never, + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(_) => ColorChoice::Always, + } + } +} + +#[cfg(feature = "auto")] +fn choice(raw: &dyn RawStream) -> ColorChoice { + let choice = ColorChoice::global(); + match choice { + ColorChoice::Auto => { + let clicolor = anstyle_query::clicolor(); + let clicolor_enabled = clicolor.unwrap_or(false); + let clicolor_disabled = !clicolor.unwrap_or(true); + if raw.is_terminal() + && !anstyle_query::no_color() + && !clicolor_disabled + && (anstyle_query::term_supports_color() + || clicolor_enabled + || anstyle_query::is_ci()) + || anstyle_query::clicolor_force() + { + ColorChoice::Always + } else { + ColorChoice::Never + } + } + ColorChoice::AlwaysAnsi | ColorChoice::Always | ColorChoice::Never => choice, + } +} + +impl AutoStream<std::io::Stdout> { + /// Get exclusive access to the `AutoStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> AutoStream<std::io::StdoutLock<'static>> { + let inner = match self.inner { + StreamInner::PassThrough(w) => StreamInner::PassThrough(w.lock()), + StreamInner::Strip(w) => StreamInner::Strip(w.lock()), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => StreamInner::Wincon(w.lock()), + }; + AutoStream { inner } + } +} + +impl AutoStream<std::io::Stderr> { + /// Get exclusive access to the `AutoStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> AutoStream<std::io::StderrLock<'static>> { + let inner = match self.inner { + StreamInner::PassThrough(w) => StreamInner::PassThrough(w.lock()), + StreamInner::Strip(w) => StreamInner::Strip(w.lock()), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => StreamInner::Wincon(w.lock()), + }; + AutoStream { inner } + } +} + +impl<S> std::io::Write for AutoStream<S> +where + S: RawStream + AsLockedWrite, +{ + // Must forward all calls to ensure locking happens appropriately + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { + match &mut self.inner { + StreamInner::PassThrough(w) => w.as_locked_write().write(buf), + StreamInner::Strip(w) => w.write(buf), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.write(buf), + } + } + #[inline] + fn write_vectored(&mut self, bufs: &[std::io::IoSlice<'_>]) -> std::io::Result<usize> { + match &mut self.inner { + StreamInner::PassThrough(w) => w.as_locked_write().write_vectored(bufs), + StreamInner::Strip(w) => w.write_vectored(bufs), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.write_vectored(bufs), + } + } + // is_write_vectored: nightly only + #[inline] + fn flush(&mut self) -> std::io::Result<()> { + match &mut self.inner { + StreamInner::PassThrough(w) => w.as_locked_write().flush(), + StreamInner::Strip(w) => w.flush(), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.flush(), + } + } + #[inline] + fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> { + match &mut self.inner { + StreamInner::PassThrough(w) => w.as_locked_write().write_all(buf), + StreamInner::Strip(w) => w.write_all(buf), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.write_all(buf), + } + } + // write_all_vectored: nightly only + #[inline] + fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> { + match &mut self.inner { + StreamInner::PassThrough(w) => w.as_locked_write().write_fmt(args), + StreamInner::Strip(w) => w.write_fmt(args), + #[cfg(all(windows, feature = "wincon"))] + StreamInner::Wincon(w) => w.write_fmt(args), + } + } +} diff --git a/vendor/anstream/src/buffer.rs b/vendor/anstream/src/buffer.rs new file mode 100644 index 0000000..9846bb7 --- /dev/null +++ b/vendor/anstream/src/buffer.rs @@ -0,0 +1,68 @@ +#![allow(deprecated)] + +/// In-memory [`RawStream`][crate::stream::RawStream] +#[derive(Clone, Default, Debug, PartialEq, Eq)] +#[deprecated(since = "0.6.2", note = "Use Vec")] +#[doc(hidden)] +pub struct Buffer(Vec<u8>); + +impl Buffer { + #[inline] + pub fn new() -> Self { + Default::default() + } + + #[inline] + pub fn with_capacity(capacity: usize) -> Self { + Self(Vec::with_capacity(capacity)) + } + + #[inline] + pub fn as_bytes(&self) -> &[u8] { + &self.0 + } +} + +impl AsRef<[u8]> for Buffer { + #[inline] + fn as_ref(&self) -> &[u8] { + self.as_bytes() + } +} + +impl std::io::Write for Buffer { + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { + self.0.extend(buf); + Ok(buf.len()) + } + + #[inline] + fn flush(&mut self) -> std::io::Result<()> { + Ok(()) + } +} + +#[cfg(all(windows, feature = "wincon"))] +impl anstyle_wincon::WinconStream for Buffer { + fn write_colored( + &mut self, + fg: Option<anstyle::AnsiColor>, + bg: Option<anstyle::AnsiColor>, + data: &[u8], + ) -> std::io::Result<usize> { + self.0.write_colored(fg, bg, data) + } +} + +#[cfg(all(windows, feature = "wincon"))] +impl anstyle_wincon::WinconStream for &'_ mut Buffer { + fn write_colored( + &mut self, + fg: Option<anstyle::AnsiColor>, + bg: Option<anstyle::AnsiColor>, + data: &[u8], + ) -> std::io::Result<usize> { + (**self).write_colored(fg, bg, data) + } +} diff --git a/vendor/anstream/src/fmt.rs b/vendor/anstream/src/fmt.rs new file mode 100644 index 0000000..e673c26 --- /dev/null +++ b/vendor/anstream/src/fmt.rs @@ -0,0 +1,54 @@ +/// A shim which allows a [`std::io::Write`] to be implemented in terms of a [`std::fmt::Write`] +/// +/// This saves off I/O errors. instead of discarding them +pub(crate) struct Adapter<W> +where + W: FnMut(&[u8]) -> std::io::Result<()>, +{ + writer: W, + error: std::io::Result<()>, +} + +impl<W> Adapter<W> +where + W: FnMut(&[u8]) -> std::io::Result<()>, +{ + pub(crate) fn new(writer: W) -> Self { + Adapter { + writer, + error: Ok(()), + } + } + + pub(crate) fn write_fmt(mut self, fmt: std::fmt::Arguments<'_>) -> std::io::Result<()> { + match std::fmt::write(&mut self, fmt) { + Ok(()) => Ok(()), + Err(..) => { + // check if the error came from the underlying `Write` or not + if self.error.is_err() { + self.error + } else { + Err(std::io::Error::new( + std::io::ErrorKind::Other, + "formatter error", + )) + } + } + } + } +} + +impl<W> std::fmt::Write for Adapter<W> +where + W: FnMut(&[u8]) -> std::io::Result<()>, +{ + fn write_str(&mut self, s: &str) -> std::fmt::Result { + match (self.writer)(s.as_bytes()) { + Ok(()) => Ok(()), + Err(e) => { + self.error = Err(e); + Err(std::fmt::Error) + } + } + } +} diff --git a/vendor/anstream/src/lib.rs b/vendor/anstream/src/lib.rs new file mode 100644 index 0000000..9721139 --- /dev/null +++ b/vendor/anstream/src/lib.rs @@ -0,0 +1,79 @@ +//! **Auto-adapting [`stdout`] / [`stderr`] streams** +//! +//! *A portmanteau of "ansi stream"* +//! +//! [`AutoStream`] always accepts [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code), +//! adapting to the user's terminal's capabilities. +//! +//! Benefits +//! - Allows the caller to not be concerned with the terminal's capabilities +//! - Semver safe way of passing styled text between crates as ANSI escape codes offer more +//! compatibility than most crate APIs. +//! +//! Available styling crates: +//! - [anstyle](https://docs.rs/anstyle) for minimal runtime styling, designed to go in public APIs +//! (once it hits 1.0) +//! - [owo-colors](https://docs.rs/owo-colors) for feature-rich runtime styling +//! - [color-print](https://docs.rs/color-print) for feature-rich compile-time styling +//! +//! # Example +//! +//! ``` +//! # #[cfg(feature = "auto")] { +//! use anstream::println; +//! use owo_colors::OwoColorize as _; +//! +//! // Foreground colors +//! println!("My number is {:#x}!", 10.green()); +//! // Background colors +//! println!("My number is not {}!", 4.on_red()); +//! # } +//! ``` +//! +//! And this will correctly handle piping to a file, etc + +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + +pub mod adapter; +pub mod stream; + +mod buffer; +#[macro_use] +mod macros; +mod auto; +mod fmt; +mod strip; +#[cfg(all(windows, feature = "wincon"))] +mod wincon; + +pub use auto::AutoStream; +pub use strip::StripStream; +#[cfg(all(windows, feature = "wincon"))] +pub use wincon::WinconStream; + +#[allow(deprecated)] +pub use buffer::Buffer; + +/// Create an ANSI escape code compatible stdout +/// +/// **Note:** Call [`AutoStream::lock`] in loops to avoid the performance hit of acquiring/releasing +/// from the implicit locking in each [`std::io::Write`] call +#[cfg(feature = "auto")] +pub fn stdout() -> AutoStream<std::io::Stdout> { + let stdout = std::io::stdout(); + AutoStream::auto(stdout) +} + +/// Create an ANSI escape code compatible stderr +/// +/// **Note:** Call [`AutoStream::lock`] in loops to avoid the performance hit of acquiring/releasing +/// from the implicit locking in each [`std::io::Write`] call +#[cfg(feature = "auto")] +pub fn stderr() -> AutoStream<std::io::Stderr> { + let stderr = std::io::stderr(); + AutoStream::auto(stderr) +} + +/// Selection for overriding color output +#[cfg(feature = "auto")] +pub use colorchoice::ColorChoice; diff --git a/vendor/anstream/src/macros.rs b/vendor/anstream/src/macros.rs new file mode 100644 index 0000000..bd1accb --- /dev/null +++ b/vendor/anstream/src/macros.rs @@ -0,0 +1,389 @@ +/// Prints to [`stdout`][crate::stdout]. +/// +/// Equivalent to the [`println!`] macro except that a newline is not printed at +/// the end of the message. +/// +/// Note that stdout is frequently line-buffered by default so it may be +/// necessary to use [`std::io::Write::flush()`] to ensure the output is emitted +/// immediately. +/// +/// **NOTE:** The `print!` macro will lock the standard output on each call. If you call +/// `print!` within a hot loop, this behavior may be the bottleneck of the loop. +/// To avoid this, lock stdout with [`AutoStream::lock`][crate::AutoStream::lock]: +/// ``` +/// # #[cfg(feature = "auto")] { +/// use std::io::Write as _; +/// +/// let mut lock = anstream::stdout().lock(); +/// write!(lock, "hello world").unwrap(); +/// # } +/// ``` +/// +/// Use `print!` only for the primary output of your program. Use +/// [`eprint!`] instead to print error and progress messages. +/// +/// **NOTE:** Not all `print!` calls will be captured in tests like [`std::print!`] +/// - Capturing will automatically be activated in test binaries +/// - Otherwise, only when the `test` feature is enabled +/// +/// # Panics +/// +/// Panics if writing to `stdout` fails for any reason **except** broken pipe. +/// +/// Writing to non-blocking stdout can cause an error, which will lead +/// this macro to panic. +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "auto")] { +/// use std::io::Write as _; +/// use anstream::print; +/// use anstream::stdout; +/// +/// print!("this "); +/// print!("will "); +/// print!("be "); +/// print!("on "); +/// print!("the "); +/// print!("same "); +/// print!("line "); +/// +/// stdout().flush().unwrap(); +/// +/// print!("this string has a newline, why not choose println! instead?\n"); +/// +/// stdout().flush().unwrap(); +/// # } +/// ``` +#[cfg(feature = "auto")] +#[macro_export] +macro_rules! print { + ($($arg:tt)*) => {{ + if cfg!(any(feature = "test", test)) { + use std::io::Write as _; + + let stdio = std::io::stdout(); + let choice = $crate::AutoStream::choice(&stdio); + let buffer = Vec::new(); + let mut stream = $crate::AutoStream::new(buffer, choice); + // Ignore errors rather than panic + let _ = ::std::write!(&mut stream, $($arg)*); + let buffer = stream.into_inner(); + // Should be UTF-8 but not wanting to panic + let buffer = String::from_utf8_lossy(&buffer); + ::std::print!("{}", buffer) + } else { + use std::io::Write as _; + + let mut stream = $crate::stdout(); + match ::std::write!(&mut stream, $($arg)*) { + Err(e) if e.kind() != ::std::io::ErrorKind::BrokenPipe => { + ::std::panic!("failed printing to stdout: {e}"); + } + Err(_) | Ok(_) => {} + } + } + }}; +} + +/// Prints to [`stdout`][crate::stdout], with a newline. +/// +/// On all platforms, the newline is the LINE FEED character (`\n`/`U+000A`) alone +/// (no additional CARRIAGE RETURN (`\r`/`U+000D`)). +/// +/// This macro uses the same syntax as [`format!`], but writes to the standard output instead. +/// See [`std::fmt`] for more information. +/// +/// **NOTE:** The `println!` macro will lock the standard output on each call. If you call +/// `println!` within a hot loop, this behavior may be the bottleneck of the loop. +/// To avoid this, lock stdout with [`AutoStream::lock`][crate::AutoStream::lock]: +/// ``` +/// # #[cfg(feature = "auto")] { +/// use std::io::Write as _; +/// +/// let mut lock = anstream::stdout().lock(); +/// writeln!(lock, "hello world").unwrap(); +/// # } +/// ``` +/// +/// Use `println!` only for the primary output of your program. Use +/// [`eprintln!`] instead to print error and progress messages. +/// +/// **NOTE:** Not all `println!` calls will be captured in tests like [`std::println!`] +/// - Capturing will automatically be activated in test binaries +/// - Otherwise, only when the `test` feature is enabled +/// +/// # Panics +/// +/// Panics if writing to `stdout` fails for any reason **except** broken pipe. +/// +/// Writing to non-blocking stdout can cause an error, which will lead +/// this macro to panic. +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "auto")] { +/// use anstream::println; +/// +/// println!(); // prints just a newline +/// println!("hello there!"); +/// println!("format {} arguments", "some"); +/// let local_variable = "some"; +/// println!("format {local_variable} arguments"); +/// # } +/// ``` +#[cfg(feature = "auto")] +#[macro_export] +macro_rules! println { + () => { + $crate::print!("\n") + }; + ($($arg:tt)*) => {{ + if cfg!(any(feature = "test", test)) { + use std::io::Write as _; + + let stdio = std::io::stdout(); + let choice = $crate::AutoStream::choice(&stdio); + let buffer = Vec::new(); + let mut stream = $crate::AutoStream::new(buffer, choice); + // Ignore errors rather than panic + let _ = ::std::write!(&mut stream, $($arg)*); + let buffer = stream.into_inner(); + // Should be UTF-8 but not wanting to panic + let buffer = String::from_utf8_lossy(&buffer); + ::std::println!("{}", buffer) + } else { + use std::io::Write as _; + + let mut stream = $crate::stdout(); + match ::std::writeln!(&mut stream, $($arg)*) { + Err(e) if e.kind() != ::std::io::ErrorKind::BrokenPipe => { + ::std::panic!("failed printing to stdout: {e}"); + } + Err(_) | Ok(_) => {} + } + } + }}; +} + +/// Prints to [`stderr`][crate::stderr]. +/// +/// Equivalent to the [`print!`] macro, except that output goes to +/// `stderr` instead of `stdout`. See [`print!`] for +/// example usage. +/// +/// Use `eprint!` only for error and progress messages. Use `print!` +/// instead for the primary output of your program. +/// +/// **NOTE:** Not all `eprint!` calls will be captured in tests like [`std::eprint!`] +/// - Capturing will automatically be activated in test binaries +/// - Otherwise, only when the `test` feature is enabled +/// +/// # Panics +/// +/// Panics if writing to `stderr` fails for any reason **except** broken pipe. +/// +/// Writing to non-blocking stdout can cause an error, which will lead +/// this macro to panic. +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "auto")] { +/// use anstream::eprint; +/// +/// eprint!("Error: Could not complete task"); +/// # } +/// ``` +#[cfg(feature = "auto")] +#[macro_export] +macro_rules! eprint { + ($($arg:tt)*) => {{ + if cfg!(any(feature = "test", test)) { + use std::io::Write as _; + + let stdio = std::io::stderr(); + let choice = $crate::AutoStream::choice(&stdio); + let buffer = Vec::new(); + let mut stream = $crate::AutoStream::new(buffer, choice); + // Ignore errors rather than panic + let _ = ::std::write!(&mut stream, $($arg)*); + let buffer = stream.into_inner(); + // Should be UTF-8 but not wanting to panic + let buffer = String::from_utf8_lossy(&buffer); + ::std::eprint!("{}", buffer) + } else { + use std::io::Write as _; + + let mut stream = $crate::stderr(); + match ::std::write!(&mut stream, $($arg)*) { + Err(e) if e.kind() != ::std::io::ErrorKind::BrokenPipe => { + ::std::panic!("failed printing to stdout: {e}"); + } + Err(_) | Ok(_) => {} + } + } + }}; +} + +/// Prints to [`stderr`][crate::stderr], with a newline. +/// +/// Equivalent to the [`println!`] macro, except that output goes to +/// `stderr` instead of `stdout`. See [`println!`] for +/// example usage. +/// +/// Use `eprintln!` only for error and progress messages. Use `println!` +/// instead for the primary output of your program. +/// +/// **NOTE:** Not all `eprintln!` calls will be captured in tests like [`std::eprintln!`] +/// - Capturing will automatically be activated in test binaries +/// - Otherwise, only when the `test` feature is enabled +/// +/// # Panics +/// +/// Panics if writing to `stderr` fails for any reason **except** broken pipe. +/// +/// Writing to non-blocking stdout can cause an error, which will lead +/// this macro to panic. +/// +/// # Examples +/// +/// ``` +/// # #[cfg(feature = "auto")] { +/// use anstream::eprintln; +/// +/// eprintln!("Error: Could not complete task"); +/// # } +/// ``` +#[cfg(feature = "auto")] +#[macro_export] +macro_rules! eprintln { + () => { + $crate::eprint!("\n") + }; + ($($arg:tt)*) => {{ + if cfg!(any(feature = "test", test)) { + use std::io::Write as _; + + let stdio = std::io::stderr(); + let choice = $crate::AutoStream::choice(&stdio); + let buffer = Vec::new(); + let mut stream = $crate::AutoStream::new(buffer, choice); + // Ignore errors rather than panic + let _ = ::std::write!(&mut stream, $($arg)*); + let buffer = stream.into_inner(); + // Should be UTF-8 but not wanting to panic + let buffer = String::from_utf8_lossy(&buffer); + ::std::eprintln!("{}", buffer) + } else { + use std::io::Write as _; + + let mut stream = $crate::stderr(); + match ::std::writeln!(&mut stream, $($arg)*) { + Err(e) if e.kind() != ::std::io::ErrorKind::BrokenPipe => { + ::std::panic!("failed printing to stdout: {e}"); + } + Err(_) | Ok(_) => {} + } + } + }}; +} + +/// Panics the current thread. +/// +/// This allows a program to terminate immediately and provide feedback +/// to the caller of the program. +/// +/// This macro is the perfect way to assert conditions in example code and in +/// tests. `panic!` is closely tied with the `unwrap` method of both +/// [`Option`][ounwrap] and [`Result`][runwrap] enums. Both implementations call +/// `panic!` when they are set to [`None`] or [`Err`] variants. +/// +/// When using `panic!()` you can specify a string payload, that is built using +/// the [`format!`] syntax. That payload is used when injecting the panic into +/// the calling Rust thread, causing the thread to panic entirely. +/// +/// The behavior of the default `std` hook, i.e. the code that runs directly +/// after the panic is invoked, is to print the message payload to +/// `stderr` along with the file/line/column information of the `panic!()` +/// call. You can override the panic hook using [`std::panic::set_hook()`]. +/// Inside the hook a panic can be accessed as a `&dyn Any + Send`, +/// which contains either a `&str` or `String` for regular `panic!()` invocations. +/// To panic with a value of another other type, [`panic_any`] can be used. +/// +/// See also the macro [`compile_error!`], for raising errors during compilation. +/// +/// # When to use `panic!` vs `Result` +/// +/// The Rust language provides two complementary systems for constructing / +/// representing, reporting, propagating, reacting to, and discarding errors. These +/// responsibilities are collectively known as "error handling." `panic!` and +/// `Result` are similar in that they are each the primary interface of their +/// respective error handling systems; however, the meaning these interfaces attach +/// to their errors and the responsibilities they fulfill within their respective +/// error handling systems differ. +/// +/// The `panic!` macro is used to construct errors that represent a bug that has +/// been detected in your program. With `panic!` you provide a message that +/// describes the bug and the language then constructs an error with that message, +/// reports it, and propagates it for you. +/// +/// `Result` on the other hand is used to wrap other types that represent either +/// the successful result of some computation, `Ok(T)`, or error types that +/// represent an anticipated runtime failure mode of that computation, `Err(E)`. +/// `Result` is used alongside user defined types which represent the various +/// anticipated runtime failure modes that the associated computation could +/// encounter. `Result` must be propagated manually, often with the the help of the +/// `?` operator and `Try` trait, and they must be reported manually, often with +/// the help of the `Error` trait. +/// +/// For more detailed information about error handling check out the [book] or the +/// [`std::result`] module docs. +/// +/// [ounwrap]: Option::unwrap +/// [runwrap]: Result::unwrap +/// [`std::panic::set_hook()`]: ../std/panic/fn.set_hook.html +/// [`panic_any`]: ../std/panic/fn.panic_any.html +/// [`Box`]: ../std/boxed/struct.Box.html +/// [`Any`]: crate::any::Any +/// [`format!`]: ../std/macro.format.html +/// [book]: ../book/ch09-00-error-handling.html +/// [`std::result`]: ../std/result/index.html +/// +/// # Current implementation +/// +/// If the main thread panics it will terminate all your threads and end your +/// program with code `101`. +/// +/// # Examples +/// +/// ```should_panic +/// # #![allow(unreachable_code)] +/// use anstream::panic; +/// panic!(); +/// panic!("this is a terrible mistake!"); +/// panic!("this is a {} {message}", "fancy", message = "message"); +/// ``` +#[cfg(feature = "auto")] +#[macro_export] +macro_rules! panic { + () => { + ::std::panic!() + }; + ($($arg:tt)*) => {{ + use std::io::Write as _; + + let panic_stream = std::io::stderr(); + let choice = $crate::AutoStream::choice(&panic_stream); + let buffer = Vec::new(); + let mut stream = $crate::AutoStream::new(buffer, choice); + // Ignore errors rather than panic + let _ = ::std::write!(&mut stream, $($arg)*); + let buffer = stream.into_inner(); + // Should be UTF-8 but not wanting to panic + let buffer = String::from_utf8_lossy(&buffer).into_owned(); + ::std::panic!("{}", buffer) + }}; +} diff --git a/vendor/anstream/src/stream.rs b/vendor/anstream/src/stream.rs new file mode 100644 index 0000000..e2f7e68 --- /dev/null +++ b/vendor/anstream/src/stream.rs @@ -0,0 +1,261 @@ +//! Higher-level traits to describe writeable streams + +/// Required functionality for underlying [`std::io::Write`] for adaptation +#[cfg(not(all(windows, feature = "wincon")))] +pub trait RawStream: std::io::Write + IsTerminal + private::Sealed {} + +/// Required functionality for underlying [`std::io::Write`] for adaptation +#[cfg(all(windows, feature = "wincon"))] +pub trait RawStream: + std::io::Write + IsTerminal + anstyle_wincon::WinconStream + private::Sealed +{ +} + +impl RawStream for std::io::Stdout {} + +impl RawStream for std::io::StdoutLock<'_> {} + +impl RawStream for &'_ mut std::io::StdoutLock<'_> {} + +impl RawStream for std::io::Stderr {} + +impl RawStream for std::io::StderrLock<'_> {} + +impl RawStream for &'_ mut std::io::StderrLock<'_> {} + +impl RawStream for Box<dyn std::io::Write> {} + +impl RawStream for &'_ mut Box<dyn std::io::Write> {} + +impl RawStream for Vec<u8> {} + +impl RawStream for &'_ mut Vec<u8> {} + +impl RawStream for std::fs::File {} + +impl RawStream for &'_ mut std::fs::File {} + +#[allow(deprecated)] +impl RawStream for crate::Buffer {} + +#[allow(deprecated)] +impl RawStream for &'_ mut crate::Buffer {} + +pub trait IsTerminal: private::Sealed { + fn is_terminal(&self) -> bool; +} + +impl IsTerminal for std::io::Stdout { + #[inline] + fn is_terminal(&self) -> bool { + std::io::IsTerminal::is_terminal(self) + } +} + +impl IsTerminal for std::io::StdoutLock<'_> { + #[inline] + fn is_terminal(&self) -> bool { + std::io::IsTerminal::is_terminal(self) + } +} + +impl IsTerminal for &'_ mut std::io::StdoutLock<'_> { + #[inline] + fn is_terminal(&self) -> bool { + (**self).is_terminal() + } +} + +impl IsTerminal for std::io::Stderr { + #[inline] + fn is_terminal(&self) -> bool { + std::io::IsTerminal::is_terminal(self) + } +} + +impl IsTerminal for std::io::StderrLock<'_> { + #[inline] + fn is_terminal(&self) -> bool { + std::io::IsTerminal::is_terminal(self) + } +} + +impl IsTerminal for &'_ mut std::io::StderrLock<'_> { + #[inline] + fn is_terminal(&self) -> bool { + (**self).is_terminal() + } +} + +impl IsTerminal for Box<dyn std::io::Write> { + #[inline] + fn is_terminal(&self) -> bool { + false + } +} + +impl IsTerminal for &'_ mut Box<dyn std::io::Write> { + #[inline] + fn is_terminal(&self) -> bool { + false + } +} + +impl IsTerminal for Vec<u8> { + #[inline] + fn is_terminal(&self) -> bool { + false + } +} + +impl IsTerminal for &'_ mut Vec<u8> { + #[inline] + fn is_terminal(&self) -> bool { + false + } +} + +impl IsTerminal for std::fs::File { + #[inline] + fn is_terminal(&self) -> bool { + std::io::IsTerminal::is_terminal(self) + } +} + +impl IsTerminal for &'_ mut std::fs::File { + #[inline] + fn is_terminal(&self) -> bool { + (**self).is_terminal() + } +} + +#[allow(deprecated)] +impl IsTerminal for crate::Buffer { + #[inline] + fn is_terminal(&self) -> bool { + false + } +} + +#[allow(deprecated)] +impl IsTerminal for &'_ mut crate::Buffer { + #[inline] + fn is_terminal(&self) -> bool { + (**self).is_terminal() + } +} + +pub trait AsLockedWrite: private::Sealed { + type Write<'w>: RawStream + 'w + where + Self: 'w; + + fn as_locked_write(&mut self) -> Self::Write<'_>; +} + +impl AsLockedWrite for std::io::Stdout { + type Write<'w> = std::io::StdoutLock<'w>; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self.lock() + } +} + +impl AsLockedWrite for std::io::StdoutLock<'static> { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +impl AsLockedWrite for std::io::Stderr { + type Write<'w> = std::io::StderrLock<'w>; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self.lock() + } +} + +impl AsLockedWrite for std::io::StderrLock<'static> { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +impl AsLockedWrite for Box<dyn std::io::Write> { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +impl AsLockedWrite for Vec<u8> { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +impl AsLockedWrite for std::fs::File { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +#[allow(deprecated)] +impl AsLockedWrite for crate::Buffer { + type Write<'w> = &'w mut Self; + + #[inline] + fn as_locked_write(&mut self) -> Self::Write<'_> { + self + } +} + +mod private { + pub trait Sealed {} + + impl Sealed for std::io::Stdout {} + + impl Sealed for std::io::StdoutLock<'_> {} + + impl Sealed for &'_ mut std::io::StdoutLock<'_> {} + + impl Sealed for std::io::Stderr {} + + impl Sealed for std::io::StderrLock<'_> {} + + impl Sealed for &'_ mut std::io::StderrLock<'_> {} + + impl Sealed for Box<dyn std::io::Write> {} + + impl Sealed for &'_ mut Box<dyn std::io::Write> {} + + impl Sealed for Vec<u8> {} + + impl Sealed for &'_ mut Vec<u8> {} + + impl Sealed for std::fs::File {} + + impl Sealed for &'_ mut std::fs::File {} + + #[allow(deprecated)] + impl Sealed for crate::Buffer {} + + #[allow(deprecated)] + impl Sealed for &'_ mut crate::Buffer {} +} diff --git a/vendor/anstream/src/strip.rs b/vendor/anstream/src/strip.rs new file mode 100644 index 0000000..d7fda04 --- /dev/null +++ b/vendor/anstream/src/strip.rs @@ -0,0 +1,219 @@ +use crate::adapter::StripBytes; +use crate::stream::AsLockedWrite; +use crate::stream::RawStream; + +/// Only pass printable data to the inner `Write` +#[derive(Debug)] +pub struct StripStream<S> +where + S: RawStream, +{ + raw: S, + state: StripBytes, +} + +impl<S> StripStream<S> +where + S: RawStream, +{ + /// Only pass printable data to the inner `Write` + #[inline] + pub fn new(raw: S) -> Self { + Self { + raw, + state: Default::default(), + } + } + + /// Get the wrapped [`RawStream`] + #[inline] + pub fn into_inner(self) -> S { + self.raw + } + + #[inline] + pub fn is_terminal(&self) -> bool { + self.raw.is_terminal() + } +} + +impl StripStream<std::io::Stdout> { + /// Get exclusive access to the `StripStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> StripStream<std::io::StdoutLock<'static>> { + StripStream { + raw: self.raw.lock(), + state: self.state, + } + } +} + +impl StripStream<std::io::Stderr> { + /// Get exclusive access to the `StripStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> StripStream<std::io::StderrLock<'static>> { + StripStream { + raw: self.raw.lock(), + state: self.state, + } + } +} + +impl<S> std::io::Write for StripStream<S> +where + S: RawStream + AsLockedWrite, +{ + // Must forward all calls to ensure locking happens appropriately + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { + write(&mut self.raw.as_locked_write(), &mut self.state, buf) + } + #[inline] + fn write_vectored(&mut self, bufs: &[std::io::IoSlice<'_>]) -> std::io::Result<usize> { + let buf = bufs + .iter() + .find(|b| !b.is_empty()) + .map(|b| &**b) + .unwrap_or(&[][..]); + self.write(buf) + } + // is_write_vectored: nightly only + #[inline] + fn flush(&mut self) -> std::io::Result<()> { + self.raw.as_locked_write().flush() + } + #[inline] + fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> { + write_all(&mut self.raw.as_locked_write(), &mut self.state, buf) + } + // write_all_vectored: nightly only + #[inline] + fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> { + write_fmt(&mut self.raw.as_locked_write(), &mut self.state, args) + } +} + +fn write( + raw: &mut dyn std::io::Write, + state: &mut StripBytes, + buf: &[u8], +) -> std::io::Result<usize> { + let initial_state = state.clone(); + + for printable in state.strip_next(buf) { + let possible = printable.len(); + let written = raw.write(printable)?; + if possible != written { + let divergence = &printable[written..]; + let offset = offset_to(buf, divergence); + let consumed = &buf[offset..]; + *state = initial_state; + state.strip_next(consumed).last(); + return Ok(offset); + } + } + Ok(buf.len()) +} + +fn write_all( + raw: &mut dyn std::io::Write, + state: &mut StripBytes, + buf: &[u8], +) -> std::io::Result<()> { + for printable in state.strip_next(buf) { + raw.write_all(printable)?; + } + Ok(()) +} + +fn write_fmt( + raw: &mut dyn std::io::Write, + state: &mut StripBytes, + args: std::fmt::Arguments<'_>, +) -> std::io::Result<()> { + let write_all = |buf: &[u8]| write_all(raw, state, buf); + crate::fmt::Adapter::new(write_all).write_fmt(args) +} + +#[inline] +fn offset_to(total: &[u8], subslice: &[u8]) -> usize { + let total = total.as_ptr(); + let subslice = subslice.as_ptr(); + + debug_assert!( + total <= subslice, + "`Offset::offset_to` only accepts slices of `self`" + ); + subslice as usize - total as usize +} + +#[cfg(test)] +mod test { + use super::*; + use proptest::prelude::*; + use std::io::Write as _; + + proptest! { + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_all_no_escapes(s in "\\PC*") { + let buffer = Vec::new(); + let mut stream = StripStream::new(buffer); + stream.write_all(s.as_bytes()).unwrap(); + let buffer = stream.into_inner(); + let actual = std::str::from_utf8(buffer.as_ref()).unwrap(); + assert_eq!(s, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_byte_no_escapes(s in "\\PC*") { + let buffer = Vec::new(); + let mut stream = StripStream::new(buffer); + for byte in s.as_bytes() { + stream.write_all(&[*byte]).unwrap(); + } + let buffer = stream.into_inner(); + let actual = std::str::from_utf8(buffer.as_ref()).unwrap(); + assert_eq!(s, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_all_random(s in any::<Vec<u8>>()) { + let buffer = Vec::new(); + let mut stream = StripStream::new(buffer); + stream.write_all(s.as_slice()).unwrap(); + let buffer = stream.into_inner(); + if let Ok(actual) = std::str::from_utf8(buffer.as_ref()) { + for char in actual.chars() { + assert!(!char.is_ascii() || !char.is_control() || char.is_ascii_whitespace(), "{:?} -> {:?}: {:?}", String::from_utf8_lossy(&s), actual, char); + } + } + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_byte_random(s in any::<Vec<u8>>()) { + let buffer = Vec::new(); + let mut stream = StripStream::new(buffer); + for byte in s.as_slice() { + stream.write_all(&[*byte]).unwrap(); + } + let buffer = stream.into_inner(); + if let Ok(actual) = std::str::from_utf8(buffer.as_ref()) { + for char in actual.chars() { + assert!(!char.is_ascii() || !char.is_control() || char.is_ascii_whitespace(), "{:?} -> {:?}: {:?}", String::from_utf8_lossy(&s), actual, char); + } + } + } + } +} diff --git a/vendor/anstream/src/wincon.rs b/vendor/anstream/src/wincon.rs new file mode 100644 index 0000000..a5aa5e7 --- /dev/null +++ b/vendor/anstream/src/wincon.rs @@ -0,0 +1,210 @@ +use crate::adapter::WinconBytes; +use crate::stream::AsLockedWrite; +use crate::stream::RawStream; + +/// Only pass printable data to the inner `Write` +#[cfg(feature = "wincon")] // here mostly for documentation purposes +#[derive(Debug)] +pub struct WinconStream<S> +where + S: RawStream, +{ + raw: S, + // `WinconBytes` is especially large compared to other variants of `AutoStream`, so boxing it + // here so `AutoStream` doesn't have to discard one allocation and create another one when + // calling `AutoStream::lock` + state: Box<WinconBytes>, +} + +impl<S> WinconStream<S> +where + S: RawStream, +{ + /// Only pass printable data to the inner `Write` + #[inline] + pub fn new(raw: S) -> Self { + Self { + raw, + state: Default::default(), + } + } + + /// Get the wrapped [`RawStream`] + #[inline] + pub fn into_inner(self) -> S { + self.raw + } + + #[inline] + pub fn is_terminal(&self) -> bool { + self.raw.is_terminal() + } +} + +impl WinconStream<std::io::Stdout> { + /// Get exclusive access to the `WinconStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> WinconStream<std::io::StdoutLock<'static>> { + WinconStream { + raw: self.raw.lock(), + state: self.state, + } + } +} + +impl WinconStream<std::io::Stderr> { + /// Get exclusive access to the `WinconStream` + /// + /// Why? + /// - Faster performance when writing in a loop + /// - Avoid other threads interleaving output with the current thread + #[inline] + pub fn lock(self) -> WinconStream<std::io::StderrLock<'static>> { + WinconStream { + raw: self.raw.lock(), + state: self.state, + } + } +} + +impl<S> std::io::Write for WinconStream<S> +where + S: RawStream + AsLockedWrite, +{ + // Must forward all calls to ensure locking happens appropriately + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { + write(&mut self.raw.as_locked_write(), &mut self.state, buf) + } + #[inline] + fn write_vectored(&mut self, bufs: &[std::io::IoSlice<'_>]) -> std::io::Result<usize> { + let buf = bufs + .iter() + .find(|b| !b.is_empty()) + .map(|b| &**b) + .unwrap_or(&[][..]); + self.write(buf) + } + // is_write_vectored: nightly only + #[inline] + fn flush(&mut self) -> std::io::Result<()> { + self.raw.as_locked_write().flush() + } + #[inline] + fn write_all(&mut self, buf: &[u8]) -> std::io::Result<()> { + write_all(&mut self.raw.as_locked_write(), &mut self.state, buf) + } + // write_all_vectored: nightly only + #[inline] + fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::io::Result<()> { + write_fmt(&mut self.raw.as_locked_write(), &mut self.state, args) + } +} + +fn write(raw: &mut dyn RawStream, state: &mut WinconBytes, buf: &[u8]) -> std::io::Result<usize> { + for (style, printable) in state.extract_next(buf) { + let fg = style.get_fg_color().and_then(cap_wincon_color); + let bg = style.get_bg_color().and_then(cap_wincon_color); + let written = raw.write_colored(fg, bg, printable.as_bytes())?; + let possible = printable.len(); + if possible != written { + // HACK: Unsupported atm + break; + } + } + Ok(buf.len()) +} + +fn write_all(raw: &mut dyn RawStream, state: &mut WinconBytes, buf: &[u8]) -> std::io::Result<()> { + for (style, printable) in state.extract_next(buf) { + let mut buf = printable.as_bytes(); + let fg = style.get_fg_color().and_then(cap_wincon_color); + let bg = style.get_bg_color().and_then(cap_wincon_color); + while !buf.is_empty() { + match raw.write_colored(fg, bg, buf) { + Ok(0) => { + return Err(std::io::Error::new( + std::io::ErrorKind::WriteZero, + "failed to write whole buffer", + )); + } + Ok(n) => buf = &buf[n..], + Err(ref e) if e.kind() == std::io::ErrorKind::Interrupted => {} + Err(e) => return Err(e), + } + } + } + Ok(()) +} + +fn write_fmt( + raw: &mut dyn RawStream, + state: &mut WinconBytes, + args: std::fmt::Arguments<'_>, +) -> std::io::Result<()> { + let write_all = |buf: &[u8]| write_all(raw, state, buf); + crate::fmt::Adapter::new(write_all).write_fmt(args) +} + +fn cap_wincon_color(color: anstyle::Color) -> Option<anstyle::AnsiColor> { + match color { + anstyle::Color::Ansi(c) => Some(c), + anstyle::Color::Ansi256(c) => c.into_ansi(), + anstyle::Color::Rgb(_) => None, + } +} + +#[cfg(test)] +mod test { + use super::*; + use proptest::prelude::*; + use std::io::Write as _; + + proptest! { + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_all_no_escapes(s in "\\PC*") { + let buffer = Vec::new(); + let mut stream = WinconStream::new(buffer); + stream.write_all(s.as_bytes()).unwrap(); + let buffer = stream.into_inner(); + let actual = std::str::from_utf8(buffer.as_ref()).unwrap(); + assert_eq!(s, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_byte_no_escapes(s in "\\PC*") { + let buffer = Vec::new(); + let mut stream = WinconStream::new(buffer); + for byte in s.as_bytes() { + stream.write_all(&[*byte]).unwrap(); + } + let buffer = stream.into_inner(); + let actual = std::str::from_utf8(buffer.as_ref()).unwrap(); + assert_eq!(s, actual); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_all_random(s in any::<Vec<u8>>()) { + let buffer = Vec::new(); + let mut stream = WinconStream::new(buffer); + stream.write_all(s.as_slice()).unwrap(); + } + + #[test] + #[cfg_attr(miri, ignore)] // See https://github.com/AltSysrq/proptest/issues/253 + fn write_byte_random(s in any::<Vec<u8>>()) { + let buffer = Vec::new(); + let mut stream = WinconStream::new(buffer); + for byte in s.as_slice() { + stream.write_all(&[*byte]).unwrap(); + } + } + } +} |