8000 feat(crossterm): allow multiple crossterm versions by joshka · Pull Request #1841 · ratatui/ratatui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(crossterm): allow multiple crossterm versions #1841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

joshka
Copy link
Member
@joshka joshka commented May 10, 2025

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.

The available feature flags are crossterm_0_28 and crossterm_0_29.

@joshka joshka requested a review from a team as a code owner May 10, 2025 19:49
@joshka joshka force-pushed the jm/crossterm-multiple-versions branch 2 times, most recently from a5b5347 to 67d8a4a Compare May 10, 2025 21:05
joshka added 3 commits May 10, 2025 14:10
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.

The available feature flags are `crossterm_0_28` and `crossterm_0_29`.
@joshka joshka force-pushed the jm/crossterm-multiple-versions branch from 67d8a4a to f3d5e7c Compare May 10, 2025 21:12
Comment on lines +31 to +34
## Enables crossterm 0.28.x
crossterm_0_28 = ["dep:crossterm_0_28"]
## Enables crossterm 0.29.x
crossterm_0_29 = ["dep:crossterm_0_29"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might get a bit annoying to add a new feature flag for the each new version of crossterm, even the patches. Or are you thinking of only doing this for the minor versions?

Are we fine with that? If they decide to speed up their release cycle we might end up with so many feature flags. Maybe we can let the upstream know that we are doing this and hear what they think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's only necessary for semver incompatible versions (0.x -> 0.x+1). Patch version doesn't matter.
It's also fairly unlikely that crossterm will speed up development IMO. Either way, we can roll with it as needed.
Perhaps we support last 2 versions or something like that. The rationale here is to make it possible for downstream widget crates to support several versions as needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, supporting only the last 2-3 versions sound reasonable to me. We should then update these docs accordingly (we only support blah blah)

I still believe we should adjust this PR a bit to make it easier to add new versions (see my other comments)

//! version of Crossterm is compiled and used by the backend. Attempting to enable none or multiple
//! `crossterm_xx` features will result in a compile-time error.
//!
//! To promote interoperability within the [Ratatui] ecosystem, the selected Crossterm crate is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! To promote interoperability within the [Ratatui] ecosystem, the selected Crossterm crate is
//! To promote interoperability within the [Ratatui] ecosystem, the selected [Crossterm] crate is

//! `ratatui-crossterm` requires you to specify a version of the [Crossterm] library to be used.
//! This is managed via feature flags. You **must** enable one, and only one, of the available
//! `crossterm_xx` features (e.g., `crossterm_28`, `crossterm_29`). These features determine which
//! version of Crossterm is compiled and used by the backend. Attempting to enable none or multiple
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! version of Crossterm is compiled and used by the backend. Attempting to enable none or multiple
//! version of [Crossterm] is compiled and used by the backend. Attempting to enable none or multiple

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to link every time this is mentioned. It's enough to link it in the first paragraph I think. Sound good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd link every time due to OCD... but sure :D

//!
//! 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! libraries or any applications that need to perform direct Crossterm operations while ensuring
//! libraries or any applications that need to perform direct [Crossterm] operations while ensuring

//!
//! 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//! 0.29 version of Crossterm.
//! 0.29 version of [Crossterm].

Comment on lines +22 to +29
let common_features = [
"serde",
"underline-color",
"scrolling-regions",
"unstable",
"unstable-backend-writer",
]
.join(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think #1820 might help here maybe... Just as a reminder that we should do that :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this scenario quite fits into cargo-hack. I may be wrong though. The problem is that the crossterm features are mutually exclusive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... I guess we need to play around with cargo-hack a bit to see how that would work

.join(",");

// Run `cargo check` on `ratatui-crossterm` with specific crossterm versions
for crossterm_feature in ["crossterm_0_28", "crossterm_0_29"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would define a separate constant or variable for the available versions. It makes it easier to just update the array whenever a new crossterm version is out.

Or maybe export it from somewhere such as ratatui_crossterm::AVAILABLE_VERSIONS or something? I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly treating xtask as the place where this info is defined. Think of it as a makefile defined in rust. The available versions are not a runtime thing. It maybe makes sense to have a const in the xtask lib, but I think it's clear enough as-is on this. Put another way, you only have to look at this file to understand what the cargo xtask check command will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup... then maybe let's do a const there? I really don't like the idea of modifying loops directly whenever a new version is out.

let clippy_options = ["--", "-D", "warnings"];

// Run Clippy on `ratatui-crossterm` with `crossterm_0_28` and `crossterm_0_29`
for crossterm_feature in ["crossterm_0_28", "crossterm_0_29"] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

Copy link
Member Author
@joshka joshka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is still a WIP (getting CI to be happy with it)

//! `ratatui-crossterm` requires you to specify a version of the [Crossterm] library to be used.
//! This is managed via feature flags. You **must** enable one, and only one, of the available
//! `crossterm_xx` features (e.g., `crossterm_28`, `crossterm_29`). These features determine which
//! version of Crossterm is compiled and used by the backend. Attempting to enable none or multiple
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to link every time this is mentioned. It's enough to link it in the first paragraph I think. Sound good?

Comment on lines +22 to +29
let common_features = [
"serde",
"underline-color",
"scrolling-regions",
"unstable",
"unstable-backend-writer",
]
.join(",");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this scenario quite fits into cargo-hack. I may be wrong though. The problem is that the crossterm features are mutually exclusive.

.join(",");

// Run `cargo check` on `ratatui-crossterm` with specific crossterm versions
for crossterm_feature in ["crossterm_0_28", "crossterm_0_29"] {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly treating xtask as the place where this info is defined. Think of it as a makefile defined in rust. The available versions are not a runtime thing. It maybe makes sense to have a const in the xtask lib, but I think it's clear enough as-is on this. Put another way, you only have to look at this file to understand what the cargo xtask check command will do.

Comment on lines +39 to +40
// 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).
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas on this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never ran into it... But intuitively I'd guess that using those flags will use default features...

@joshka joshka marked this pull request as draft May 11, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0