From 2d713d723d40a05fc09439f3d77fbca8cbbcc51a Mon Sep 17 00:00:00 2001 From: Josh McKinney Date: Sun, 17 Aug 2025 12:43:18 -0700 Subject: [PATCH] feat(crossterm): allow multiple crossterm versions (#1841) This commit introduces feature flags to make it possible for widget library authors to depend on a specific version of crossterm without causing version conflicts. This should make it easier for libraries and apps to update crossterm versions more easily. The available feature flags are `crossterm_0_28` and `crossterm_0_29`. By default, the latest version is enabled. If a multiple features are enabled we choose the latest version. We will in general support at least the last two major (0.x) versions of crossterm, and will only remove versions in a major version bump. --- .github/workflows/ci.yml | 9 + Cargo.lock | 309 ++++++++++++++++++-------------- ratatui-crossterm/Cargo.toml | 31 +++- ratatui-crossterm/README.md | 35 +++- ratatui-crossterm/src/lib.rs | 53 +++++- ratatui-termion/src/lib.rs | 4 +- ratatui-termwiz/Cargo.toml | 4 +- xtask/src/commands.rs | 37 +++- xtask/src/commands/check.rs | 32 +++- xtask/src/commands/clippy.rs | 62 +++++-- xtask/src/commands/coverage.rs | 23 ++- xtask/src/commands/test_docs.rs | 29 +++ xtask/src/main.rs | 16 ++ 13 files changed, 465 insertions(+), 179 deletions(-) create mode 100644 xtask/src/commands/test_docs.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9748179f..cb6ef123 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -158,6 +158,9 @@ jobs: - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # master with: toolchain: ${{ matrix.toolchain }} + - uses: taiki-e/install-action@f3a27926ea13d7be3ee2f4cbb925883cf9442b56 # v2 + with: + tool: cargo-hack - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2 - run: cargo xtask check --all-features @@ -232,6 +235,9 @@ jobs: - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # master with: toolchain: stable + - uses: taiki-e/install-action@f3a27926ea13d7be3ee2f4cbb925883cf9442b56 # v2 + with: + tool: cargo-hack - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2 - run: cargo xtask test-docs @@ -250,6 +256,9 @@ jobs: - uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # master with: toolchain: stable + - uses: taiki-e/install-action@f3a27926ea13d7be3ee2f4cbb925883cf9442b56 # v2 + with: + tool: cargo-hack - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2 - run: cargo xtask test-libs diff --git a/Cargo.lock b/Cargo.lock index e13c4940..caad0c49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,7 +22,7 @@ name = "advanced-widget-impl" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -64,9 +64,9 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.6.19" +version = "0.6.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +checksum = "3ae563653d1938f79b1ab1b5e668c87c76a9930414574a6583a7b7e11a8e6192" dependencies = [ "anstyle", "anstyle-parse", @@ -94,29 +94,29 @@ dependencies = [ [[package]] name = "anstyle-query" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anstyle-wincon" -version = "3.0.9" +version = "3.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" [[package]] name = "approx" @@ -138,7 +138,7 @@ name = "async-github" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "octocrab", "ratatui", "tokio", @@ -147,13 +147,13 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.88" +version = "0.1.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -224,9 +224,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" dependencies = [ "serde", ] @@ -254,9 +254,9 @@ checksum = "64fa3c856b712db6612c019f14756e64e4bcea13337a6b33b696333a9eaa2d06" [[package]] name = "bytemuck" -version = "1.23.1" +version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c76a5792e44e4abe34d3abf15636779261d45a7450612059293d1d2cfc63422" +checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" [[package]] name = "bytes" @@ -269,7 +269,7 @@ name = "calendar-explorer" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", "time", ] @@ -279,7 +279,7 @@ name = "canvas" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "itertools 0.14.0", "ratatui", ] @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.31" +version = "1.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2" +checksum = "3ee0f8803222ba5a7e2777dd72ca451868909b1ac410621b676adf07280e9b5f" dependencies = [ "shlex", ] @@ -325,7 +325,7 @@ name = "chart" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -373,9 +373,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.42" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -393,9 +393,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.42" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -405,14 +405,14 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -435,7 +435,7 @@ name = "color-explorer" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "itertools 0.14.0", "ratatui", ] @@ -478,7 +478,7 @@ name = "colors-rgb" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "palette", "ratatui", ] @@ -503,7 +503,7 @@ name = "constraint-explorer" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "itertools 0.14.0", "ratatui", "strum", @@ -514,7 +514,7 @@ name = "constraints" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", "strum", ] @@ -620,20 +620,37 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crossterm" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" +dependencies = [ + "bitflags 2.9.2", + "crossterm_winapi", + "mio", + "parking_lot", + "rustix 0.38.44", + "serde", + "signal-hook", + "signal-hook-mio", + "winapi", +] + [[package]] name = "crossterm" version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b9f2e4c67f833b660cdb0a3523065869fb35570177239812ed4c905aeff87b" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "crossterm_winapi", "derive_more", "document-features", "futures-core", "mio", "parking_lot", - "rustix", + "rustix 1.0.8", "serde", "signal-hook", "signal-hook-mio", @@ -680,7 +697,7 @@ name = "custom-widget" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -705,7 +722,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -716,7 +733,7 @@ checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" dependencies = [ "darling_core", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -730,7 +747,7 @@ name = "demo" version = "0.0.0" dependencies = [ "clap", - "crossterm", + "crossterm 0.29.0", "rand 0.9.2", "ratatui", "termion", @@ -742,7 +759,7 @@ name = "demo2" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "indoc", "itertools 0.14.0", "palette", @@ -781,7 +798,7 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -808,7 +825,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -935,7 +952,7 @@ name = "flex" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", "strum", ] @@ -1023,7 +1040,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1067,7 +1084,7 @@ name = "gauge" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -1114,9 +1131,9 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "glob" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "half" @@ -1130,9 +1147,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.4" +version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5971ac85611da7067dbfcabef3c70ebb5606018acd9e2a3903a0da507521e0d5" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ "allocator-api2", "equivalent", @@ -1150,7 +1167,7 @@ name = "hello-world" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -1276,7 +1293,7 @@ name = "hyperlink" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "itertools 0.14.0", "ratatui", ] @@ -1420,9 +1437,9 @@ dependencies = [ [[package]] name = "indenter" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +checksum = "964de6e86d545b246d84badc0fef527924ace5134f30641c203ef52ba83f58d5" [[package]] name = "indexmap" @@ -1445,7 +1462,7 @@ name = "inline" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "rand 0.9.2", "ratatui", ] @@ -1455,7 +1472,7 @@ name = "input-form" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", "serde", "serde_json", @@ -1471,7 +1488,7 @@ dependencies = [ "indoc", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1480,7 +1497,7 @@ version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d93587f37623a1a17d94ef2bc9ada592f5465fe7732084ab7beefabe5c77c0c4" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "cfg-if", "libc", ] @@ -1557,7 +1574,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96d9e0d6a8bf886abccc1cbcac7d74f9000ae5882aedc4a9042188bbc9cd4487" dependencies = [ "hashbrown", - "thiserror 2.0.12", + "thiserror 2.0.15", ] [[package]] @@ -1574,9 +1591,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libm" @@ -1599,7 +1616,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "libc", "redox_syscall", ] @@ -1610,7 +1627,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51a1679740111eb63b7b4cb3c97b1d5d9f82e142292a25edcfdb4120a48b3880" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", ] [[package]] @@ -1622,6 +1639,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" + [[package]] name = "linux-raw-sys" version = "0.9.4" @@ -1709,7 +1732,7 @@ dependencies = [ name = "minimal" version = "0.0.0" dependencies = [ - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -1745,7 +1768,7 @@ name = "modifiers" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "itertools 0.14.0", "ratatui", ] @@ -1755,7 +1778,7 @@ name = "mouse-drawing" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "line_drawing", "rand 0.9.2", "ratatui", @@ -1767,7 +1790,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "cfg-if", "cfg_aliases", "libc", @@ -1818,7 +1841,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1980,7 +2003,7 @@ dependencies = [ "by_address", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -1988,7 +2011,7 @@ name = "panic" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -2038,7 +2061,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323" dependencies = [ "memchr", - "thiserror 2.0.12", + "thiserror 2.0.15", "ucd-trie", ] @@ -2062,7 +2085,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2115,7 +2138,7 @@ dependencies = [ "phf_shared", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2144,7 +2167,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -2192,7 +2215,7 @@ name = "popup" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -2241,9 +2264,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] @@ -2442,7 +2465,7 @@ version = "0.30.0-beta.0" dependencies = [ "color-eyre", "criterion", - "crossterm", + "crossterm 0.29.0", "document-features", "fakeit", "futures", @@ -2473,7 +2496,7 @@ name = "ratatui-core" version = "0.1.0-beta.0" dependencies = [ "anstyle", - "bitflags 2.9.1", + "bitflags 2.9.2", "compact_str", "document-features", "hashbrown", @@ -2487,7 +2510,7 @@ dependencies = [ "serde", "serde_json", "strum", - "thiserror 2.0.12", + "thiserror 2.0.15", "unicode-segmentation", "unicode-truncate", "unicode-width", @@ -2497,10 +2520,11 @@ dependencies = [ name = "ratatui-crossterm" version = "0.1.0-beta.0" dependencies = [ - "crossterm", + "cfg-if", + "crossterm 0.28.1", + "crossterm 0.29.0", "document-features", "instability", - "ratatui", "ratatui-core", "rstest", ] @@ -2519,7 +2543,7 @@ name = "ratatui-state-examples" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -2549,9 +2573,9 @@ dependencies = [ name = "ratatui-widgets" version = "0.3.0-beta.0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "color-eyre", - "crossterm", + "crossterm 0.29.0", "document-features", "hashbrown", "indoc", @@ -2571,9 +2595,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" dependencies = [ "either", "rayon-core", @@ -2581,9 +2605,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -2604,7 +2628,7 @@ version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", ] [[package]] @@ -2710,7 +2734,7 @@ dependencies = [ "regex", "relative-path", "rustc_version", - "syn 2.0.104", + "syn 2.0.106", "unicode-ident", ] @@ -2729,16 +2753,29 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" +dependencies = [ + "bitflags 2.9.2", + "errno", + "libc", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + [[package]] name = "rustix" version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.9.4", "windows-sys 0.60.2", ] @@ -2791,9 +2828,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "ryu" @@ -2830,7 +2867,7 @@ name = "scrollbar" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -2845,11 +2882,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "3.2.0" +version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" +checksum = "80fb1d92c5028aa318b4b8bd7302a5bfcf48be96a37fc6fc790f806b0004ee0c" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "core-foundation", "core-foundation-sys", "libc", @@ -2889,7 +2926,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3027,7 +3064,7 @@ checksum = "297f631f50729c8c99b84667867963997ec0b50f32b2a7dbcab828ef0541e8bb" dependencies = [ "num-bigint", "num-traits", - "thiserror 2.0.12", + "thiserror 2.0.15", "time", ] @@ -3076,7 +3113,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3125,7 +3162,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3147,9 +3184,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -3170,7 +3207,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3178,7 +3215,7 @@ name = "table" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "fakeit", "itertools 0.14.0", "ratatui", @@ -3242,7 +3279,7 @@ checksum = "4676b37242ccbd1aabf56edb093a4827dc49086c0ffd764a5705899e0f35f8f7" dependencies = [ "anyhow", "base64", - "bitflags 2.9.1", + "bitflags 2.9.2", "fancy-regex", "filedescriptor", "finl_unicode", @@ -3288,11 +3325,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "80d76d3f064b981389ecb4b6b7f45a0bf9fdac1d5b9204c7bd6714fecc302850" dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl 2.0.15", ] [[package]] @@ -3303,18 +3340,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "44d29feb33e986b6ea906bd9c3559a856983f92371b3eaa5e83782a351623de0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3384,7 +3421,7 @@ name = "todo-list" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -3413,7 +3450,7 @@ checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3529,7 +3566,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "bytes", "futures-util", "http", @@ -3559,7 +3596,7 @@ name = "tracing" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", "tracing 0.1.41", "tracing-appender", @@ -3598,7 +3635,7 @@ checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -3736,7 +3773,7 @@ name = "user-input" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -3763,9 +3800,9 @@ dependencies = [ [[package]] name = "uuid" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cf4199d1e5d15ddd86a694e4d0dffa9c323ce759fea589f00fef9d81cc1931d" +checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be" dependencies = [ "atomic", "getrandom 0.3.3", @@ -3851,7 +3888,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-shared", ] @@ -3873,7 +3910,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3892,7 +3929,7 @@ name = "weather" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "rand 0.9.2", "ratatui", ] @@ -3939,7 +3976,7 @@ dependencies = [ "serde", "sha2", "thiserror 1.0.69", - "uuid 1.17.0", + "uuid 1.18.0", ] [[package]] @@ -3997,7 +4034,7 @@ name = "widget-ref-container" version = "0.0.0" dependencies = [ "color-eyre", - "crossterm", + "crossterm 0.29.0", "ratatui", ] @@ -4053,7 +4090,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -4064,7 +4101,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -4262,7 +4299,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", ] [[package]] @@ -4309,7 +4346,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure", ] @@ -4330,7 +4367,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] [[package]] @@ -4350,7 +4387,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", "synstructure", ] @@ -4390,5 +4427,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.106", ] diff --git a/ratatui-crossterm/Cargo.toml b/ratatui-crossterm/Cargo.toml index abd4437a..fedd3ab6 100644 --- a/ratatui-crossterm/Cargo.toml +++ b/ratatui-crossterm/Cargo.toml @@ -14,11 +14,31 @@ exclude.workspace = true edition.workspace = true rust-version.workspace = true +[package.metadata.docs.rs] +features = ["document-features"] +rustdoc-args = ["--cfg", "docsrs"] + [features] -default = ["underline-color"] +default = ["underline-color", "crossterm_0_29"] + +#! One of the following versions of crossterm must be enabled. By default, the latest version is +#! enabled. This will always default to the most recent version of crossterm, but you can override +#! this by specifying the version you want to use in your Cargo.toml file. The purpose of these +#! features is to allow widget libraries to depend on specific versions of crossterm in a way that +#! doesn't cause version conflicts. A compiler error will be raised if you don't enable at least one +#! of the following features. + +## Enables crossterm 0.28.x +crossterm_0_28 = ["dep:crossterm_0_28"] +## Enables crossterm 0.29.x +crossterm_0_29 = ["dep:crossterm_0_29"] + +#! The following features are optional and can be enabled to add additional functionality to the +#! library. These features are not required for the library to function, but they may be useful in +#! certain situations. ## Enables serde for crossterm dependency -serde = ["crossterm/serde"] +serde = ["crossterm_0_28?/serde", "crossterm_0_29?/serde"] ## enables the backend code that sets the underline color. ## Underline color is not supported on Windows 7. @@ -37,13 +57,14 @@ unstable-backend-writer = [] [dependencies] -crossterm.workspace = true +cfg-if = "1.0.1" +crossterm_0_28 = { version = "0.28", package = "crossterm", optional = true } +crossterm_0_29 = { version = "0.29", package = "crossterm", optional = true } document-features = { workspace = true, optional = true } instability.workspace = true -ratatui-core = { workspace = true } +ratatui-core.workspace = true [dev-dependencies] -ratatui = { path = "../ratatui", features = ["crossterm"] } rstest.workspace = true [lints] diff --git a/ratatui-crossterm/README.md b/ratatui-crossterm/README.md index c9b37cde..57147f3b 100644 --- a/ratatui-crossterm/README.md +++ b/ratatui-crossterm/README.md @@ -2,10 +2,41 @@ -This module provides the [`CrosstermBackend`] implementation for the [`Backend`] trait. It uses -the [Crossterm] crate to interact with the terminal. +This crate provides [`CrosstermBackend`], an implementation of the [`Backend`] trait for the +[Ratatui] library. It uses the [Crossterm] library for all terminal manipulation. +### Crossterm Version and Re-export + +`ratatui-crossterm` requires you to specify a version of the [Crossterm] library to be used. +This is managed via feature flags. The highest enabled feature flag of the available +`crossterm_0_xx` features (e.g., `crossterm_0_28`, `crossterm_0_29`) takes precedence. These +features determine which version of Crossterm is compiled and used by the backend. Feature +unification may mean that any crate in your dependency graph that chooses to depend on a +specific version of Crossterm may be affected by the feature flags you enable. + +Ratatui will support at least the two most recent versions of Crossterm (though we may increase +this if crossterm release cadence increases). We will remove support for older versions in major +(0.x) releases of `ratatui-crossterm`, and we may add support for newer versions in minor +(0.x.y) releases. + +To promote interoperability within the [Ratatui] ecosystem, the selected Crossterm crate is +re-exported as `ratatui_crossterm::crossterm`. This re-export is essential for authors of widget +libraries or any applications that need to perform direct Crossterm operations while ensuring +compatibility with the version used by `ratatui-crossterm`. By using +`ratatui_crossterm::crossterm` for such operations, developers can avoid version conflicts and +ensure that all parts of their application use a consistent set of Crossterm types and +functions. + +For example, if your application's `Cargo.toml` enables the `crossterm_0_29` feature for +`ratatui-crossterm`, then any code using `ratatui_crossterm::crossterm` will refer to the 0.29 +version of Crossterm. + +For more information on how to use the backend, see the documentation for the +[`CrosstermBackend`] struct. + +[Ratatui]: https://ratatui.rs [Crossterm]: https://crates.io/crates/crossterm +[`Backend`]: ratatui_core::backend::Backend ## Crate Organization diff --git a/ratatui-crossterm/src/lib.rs b/ratatui-crossterm/src/lib.rs index b94ff691..4aa59b27 100644 --- a/ratatui-crossterm/src/lib.rs +++ b/ratatui-crossterm/src/lib.rs @@ -6,10 +6,41 @@ html_favicon_url = "https://raw.githubusercontent.com/ratatui/ratatui/main/assets/favicon.ico" )] #![warn(missing_docs)] -//! This module provides the [`CrosstermBackend`] implementation for the [`Backend`] trait. It uses -//! the [Crossterm] crate to interact with the terminal. +//! This crate provides [`CrosstermBackend`], an implementation of the [`Backend`] trait for the +//! [Ratatui] library. It uses the [Crossterm] library for all terminal manipulation. //! +//! ## Crossterm Version and Re-export +//! +//! `ratatui-crossterm` requires you to specify a version of the [Crossterm] library to be used. +//! This is managed via feature flags. The highest enabled feature flag of the available +//! `crossterm_0_xx` features (e.g., `crossterm_0_28`, `crossterm_0_29`) takes precedence. These +//! features determine which version of Crossterm is compiled and used by the backend. Feature +//! unification may mean that any crate in your dependency graph that chooses to depend on a +//! specific version of Crossterm may be affected by the feature flags you enable. +//! +//! Ratatui will support at least the two most recent versions of Crossterm (though we may increase +//! this if crossterm release cadence increases). We will remove support for older versions in major +//! (0.x) releases of `ratatui-crossterm`, and we may add support for newer versions in minor +//! (0.x.y) releases. +//! +//! To promote interoperability within the [Ratatui] ecosystem, the selected Crossterm crate is +//! re-exported as `ratatui_crossterm::crossterm`. This re-export is essential for authors of widget +//! libraries or any applications that need to perform direct Crossterm operations while ensuring +//! compatibility with the version used by `ratatui-crossterm`. By using +//! `ratatui_crossterm::crossterm` for such operations, developers can avoid version conflicts and +//! ensure that all parts of their application use a consistent set of Crossterm types and +//! functions. +//! +//! For example, if your application's `Cargo.toml` enables the `crossterm_0_29` feature for +//! `ratatui-crossterm`, then any code using `ratatui_crossterm::crossterm` will refer to the 0.29 +//! version of Crossterm. +//! +//! For more information on how to use the backend, see the documentation for the +//! [`CrosstermBackend`] struct. +//! +//! [Ratatui]: https://ratatui.rs //! [Crossterm]: https://crates.io/crates/crossterm +//! [`Backend`]: ratatui_core::backend::Backend //! //! # Crate Organization //! @@ -36,7 +67,6 @@ use std::io::{self, Write}; -pub use crossterm; use crossterm::cursor::{Hide, MoveTo, Show}; #[cfg(feature = "underline-color")] use crossterm::style::SetUnderlineColor; @@ -47,6 +77,19 @@ use crossterm::style::{ }; use crossterm::terminal::{self, Clear}; use crossterm::{execute, queue}; +cfg_if::cfg_if! { + // Re-export the selected Crossterm crate making sure to choose the latest version. We do this + // to make it possible to easily enable all features when compiling `ratatui-crossterm`. + if #[cfg(feature = "crossterm_0_29")] { + pub use crossterm_0_29 as crossterm; + } else if #[cfg(feature = "crossterm_0_28")] { + pub use crossterm_0_28 as crossterm; + } else { + compile_error!( + "At least one crossterm feature must be enabled. See the crate docs for more information." + ); + } +} use ratatui_core::backend::{Backend, ClearType, WindowSize}; use ratatui_core::buffer::Cell; use ratatui_core::layout::{Position, Size}; @@ -70,7 +113,7 @@ use ratatui_core::style::{Color, Modifier, Style}; /// /// # Example /// -/// ```rust,no_run +/// ```rust,ignore /// use std::io::{stderr, stdout}; /// /// use crossterm::ExecutableCommand; @@ -126,7 +169,7 @@ where /// /// # Example /// - /// ```rust,no_run + /// ```rust,ignore /// use std::io::stdout; /// /// use ratatui::backend::CrosstermBackend; diff --git a/ratatui-termion/src/lib.rs b/ratatui-termion/src/lib.rs index a41d0119..ed056c67 100644 --- a/ratatui-termion/src/lib.rs +++ b/ratatui-termion/src/lib.rs @@ -66,7 +66,7 @@ use termion::{color as tcolor, style as tstyle}; /// /// # Example /// -/// ```rust,no_run +/// ```rust,ignore /// use std::io::{stderr, stdout}; /// /// use ratatui::Terminal; @@ -113,7 +113,7 @@ where /// /// # Example /// - /// ```rust,no_run + /// ```rust,ignore /// use std::io::stdout; /// /// use ratatui::backend::TermionBackend; diff --git a/ratatui-termwiz/Cargo.toml b/ratatui-termwiz/Cargo.toml index 64e12c98..11e2821c 100644 --- a/ratatui-termwiz/Cargo.toml +++ b/ratatui-termwiz/Cargo.toml @@ -27,7 +27,7 @@ serde = ["termwiz/use_serde"] ## Enables the backend code that sets the underline color. ## Underline color is not supported on Windows 7. -underline-color = [] +underline-color = ["ratatui-core/underline-color"] ## Use terminal scrolling regions to make Terminal::insert_before less prone to flickering. scrolling-regions = ["ratatui-core/scrolling-regions"] @@ -38,7 +38,7 @@ ratatui-core = { workspace = true } termwiz.workspace = true [dev-dependencies] -ratatui = { path = "../ratatui", features = ["termwiz"] } +ratatui = { path = "../ratatui", features = ["termwiz"], default-features = false } rstest.workspace = true [lints] diff --git a/xtask/src/commands.rs b/xtask/src/commands.rs index ba14756b..aca02cac 100644 --- a/xtask/src/commands.rs +++ b/xtask/src/commands.rs @@ -13,7 +13,7 @@ use self::clippy::Clippy; use self::docs::Docs; use self::format::Format; use self::typos::Typos; -use crate::{ExpressionExt, Run, run_cargo}; +use crate::{CROSSTERM_COMMON_FEATURES, ExpressionExt, Run, run_cargo}; mod backend; mod check; @@ -22,6 +22,7 @@ mod coverage; mod docs; mod format; mod rdme; +mod test_docs; mod typos; #[derive(Clone, Debug, Subcommand)] @@ -110,7 +111,7 @@ impl Run for Command { Command::LintMarkdown => lint_markdown(), Command::Test => test(), Command::TestBackend(command) => command.run(), - Command::TestDocs => test_docs(), + Command::TestDocs => test_docs::test_docs(), Command::TestLibs => test_libs(), Command::Hack => hack(), } @@ -154,18 +155,36 @@ fn test() -> Result<()> { for backend in [Backend::Crossterm, Backend::Termion, Backend::Termwiz] { TestBackend { backend }.run()?; } - test_docs()?; // run last because it's slow + test_docs::test_docs()?; // run last because it's slow Ok(()) } -/// Run doc tests for the workspace's default packages -fn test_docs() -> Result<()> { - run_cargo(vec!["test", "--doc", "--all-features"]) -} - /// Run lib tests for the workspace's default packages fn test_libs() -> Result<()> { - run_cargo(vec!["test", "--lib", "--all-targets", "--all-features"]) + run_cargo(vec![ + "hack", + "--ignore-private", // exclude packages that are libraries + "--exclude", + "ratatui-crossterm", + "test", + "--lib", + "--all-targets", + "--all-features", + ])?; + let crossterm_feature = CROSSTERM_COMMON_FEATURES.join(","); + for crossterm_version in crate::CROSSTERM_VERSION_FEATURES { + let features = format!("{crossterm_feature},{crossterm_version}"); + run_cargo(vec![ + "test", + "--package", + "ratatui-crossterm", + "--lib", + "--no-default-features", + "--features", + features.as_str(), + ])?; + } + Ok(()) } /// Run cargo hack to test each feature in isolation diff --git a/xtask/src/commands/check.rs b/xtask/src/commands/check.rs index 7ba82c96..b2c51dcb 100644 --- a/xtask/src/commands/check.rs +++ b/xtask/src/commands/check.rs @@ -1,6 +1,6 @@ use color_eyre::Result; -use crate::{Run, run_cargo}; +use crate::{CROSSTERM_COMMON_FEATURES, CROSSTERM_VERSION_FEATURES, Run, run_cargo}; /// Run cargo check #[derive(Clone, Debug, clap::Args)] @@ -13,7 +13,35 @@ pub struct Check { impl Run for Check { fn run(self) -> Result<()> { if self.all_features { - run_cargo(vec!["check", "--all-targets", "--all-features"]) + let common_features = CROSSTERM_COMMON_FEATURES.join(","); + + // Run `cargo check` on `ratatui-crossterm` with specific crossterm versions + for crossterm_feature in CROSSTERM_VERSION_FEATURES { + let features = format!("{common_features},{crossterm_feature}"); + let command = vec![ + "check", + "--all-targets", + "--package", + "ratatui-crossterm", + "--no-default-features", + "--features", + features.as_str(), + ]; + run_cargo(command)?; + } + + run_cargo(vec![ + "hack", + "--exclude", + "ratatui-crossterm", + #[cfg(windows)] + "--exclude", + #[cfg(windows)] + "ratatui-termion", + "check", + "--all-targets", + "--all-features", + ]) } else { run_cargo(vec!["check", "--all-targets"]) } diff --git a/xtask/src/commands/clippy.rs b/xtask/src/commands/clippy.rs index 552809f0..a4a1d509 100644 --- a/xtask/src/commands/clippy.rs +++ b/xtask/src/commands/clippy.rs @@ -1,6 +1,6 @@ use color_eyre::Result; -use crate::{Run, run_cargo}; +use crate::{CROSSTERM_VERSION_FEATURES, Run, run_cargo}; /// Run clippy on the project #[derive(Clone, Debug, clap::Args)] @@ -12,19 +12,57 @@ pub struct Clippy { impl Run for Clippy { fn run(self) -> Result<()> { - let mut args = vec![ - "clippy", - "--all-targets", + // Arguments that go before feature flags (e.g., "clippy", "--fix") + let mut clippy_command = vec!["clippy"]; + if self.fix { + clippy_command.push("--fix"); + } + + // Define common non-version-specific features for ratatui-crossterm. These will be enabled + // for both crossterm 0.28 and 0.29 runs. `underline-color`` is part of default, but with + // `--no-default-features``, we must add it. + let common_features = [ + "serde", + "underline-color", + "scrolling-regions", + "unstable", + "unstable-backend-writer", + ] + .join(","); + + let clippy_options = ["--", "-D", "warnings"]; + + // Run Clippy on `ratatui-crossterm` with `crossterm_0_28` and `crossterm_0_29` + for crossterm_feature in CROSSTERM_VERSION_FEATURES { + let mut command = clippy_command.clone(); + let features = format!("{common_features},{crossterm_feature}"); + // Note that adding --tests or --benches causes clippy to pick up the default features. + // I'm not sure why this is the case (JM 2025-05-10). + command.extend(vec![ + "--package", + "ratatui-crossterm", + "--no-default-features", + "--features", + features.as_str(), + ]); + command.extend(clippy_options); + run_cargo(command)?; + } + + // Run Clippy on all other workspace packages with --all-features + let mut command = clippy_command.clone(); + command.extend(vec![ "--all-features", + "--all-targets", "--tests", "--benches", - "--", - "-D", - "warnings", - ]; - if self.fix { - args.push("--fix"); - } - run_cargo(args) + "--workspace", + "--exclude", + "ratatui-crossterm", + ]); + command.extend(clippy_options); + run_cargo(command)?; + + Ok(()) } } diff --git a/xtask/src/commands/coverage.rs b/xtask/src/commands/coverage.rs index a0e82354..025f5f9f 100644 --- a/xtask/src/commands/coverage.rs +++ b/xtask/src/commands/coverage.rs @@ -14,14 +14,29 @@ impl Run for Coverage { fn run(self) -> Result<()> { let mut args = vec![ "llvm-cov", - "--lcov", - "--output-path", - "target/lcov.info", + "--workspace", + "--exclude", + "ratatui-crossterm", "--all-features", + "--no-report", ]; if self.lib { args.push("--lib"); } - run_cargo(args) + run_cargo(args)?; + + let mut args = vec!["llvm-cov", "--package", "ratatui-crossterm", "--no-report"]; + if self.lib { + args.push("--lib"); + } + run_cargo(args)?; + + run_cargo(vec![ + "llvm-cov", + "report", + "--lcov", + "--output-path", + "target/lcov.info", + ]) } } diff --git a/xtask/src/commands/test_docs.rs b/xtask/src/commands/test_docs.rs new file mode 100644 index 00000000..0de6661d --- /dev/null +++ b/xtask/src/commands/test_docs.rs @@ -0,0 +1,29 @@ +use crate::{CROSSTERM_COMMON_FEATURES, CROSSTERM_VERSION_FEATURES, Result, run_cargo}; + +/// Run doc tests for the workspace's default packages +pub fn test_docs() -> Result<()> { + run_cargo(vec![ + "hack", + "--workspace", + "--ignore-private", // exclude packages that are libraries + "--exclude", + "ratatui-crossterm", + "test", + "--doc", + "--all-features", + ])?; + let common_features = CROSSTERM_COMMON_FEATURES.join(","); + for crossterm_version in CROSSTERM_VERSION_FEATURES { + let features = format!("{common_features},{crossterm_version}"); + run_cargo(vec![ + "test", + "--package", + "ratatui-crossterm", + "--doc", + "--no-default-features", + "--features", + features.as_str(), + ])?; + } + Ok(()) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 1f4447ff..8dee08eb 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -16,6 +16,22 @@ use duct::cmd; mod commands; +/// The available feature flags for ratatui-crossterm. +/// +/// These will be enabled for both crossterm 0.28 and 0.29 runs. `underline-color` is part of +/// default features for ratatui-crossterm, but with `--no-default-features`, we must add it +/// explicitly if desired. +const CROSSTERM_COMMON_FEATURES: &[&str] = &[ + "serde", + "underline-color", + "scrolling-regions", + "unstable", + "unstable-backend-writer", +]; + +/// The available feature flags for crossterm versions. +const CROSSTERM_VERSION_FEATURES: [&str; 2] = ["crossterm_0_28", "crossterm_0_29"]; + pub trait Run { fn run(self) -> Result<()>; }