-
-
Notifications
You must be signed in to change notification settings - Fork 400
chore(backend): change From<T> impls to new backend specific IntoBackend and FromBackend traits #1464
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
Conversation
Follows up from #1460 (comment) |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1464 +/- ##
=======================================
- Coverage 93.5% 93.4% -0.1%
=======================================
Files 68 68
Lines 16888 16875 -13
=======================================
- Hits 15795 15778 -17
- Misses 1093 1097 +4 ☔ View full report in Codecov by Sentry. |
b5f6ba1
to
f7ad9cc
Compare
Followup |
…term Adds two new traits `IntoCrossterm` and `FromCrossterm` for converting between ratatui and crossterm types. This is necessary in order to avoid the orphan rule when implementing `From` for crossterm types once the crossterm types are moved to a separate crate. BREAKING CHANGE: The `From` impls for crossterm types are now replaced with `IntoCrossterm` and `FromCrossterm` traits. ```diff + use ratatui::backend::{FromCrossterm, IntoCrossterm}; let crossterm_color = crossterm::style::Color::Black; - let ratatui_color = crossterm_color.into(); - let ratatui_color = ratatui::style::Color::from(crossterm_color); + let ratatui_color = ratatui::style::Color::from_crossterm(crossterm_color); - let crossterm_color = ratatui_color.into(); - let crossterm_color = crossterm::style::Color::from(ratatui_color); + let crossterm_color = ratatui_color.into_crossterm(); let crossterm_attribute = crossterm::style::types::Attribute::Bold; - let ratatui_modifier = crossterm_attribute.into(); - let ratatui_modifier = ratatui::style::Modifier::from(crossterm_attribute); + let ratatui_modifier = ratatui::style::Modifier::from_crossterm(crossterm_attribute); - let crossterm_attribute = ratatui_modifier.into(); - let crossterm_attribute = crossterm::style::types::Attribute::from(ratatui_modifier); + let crossterm_attribute = ratatui_modifier.into_crossterm(); ``` Similar conversions for `ContentStyle` -> `Style` and `Attributes` -> `Modifier` exist.
f7ad9cc
to
76499dc
Compare
81d5adf
to
cd66b2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice trick, I'm wondering if there are any other libraries doing something similar? How did you get inspired? :D
Axum has:
This should mostly be unused as there's unlikely be a lot of crates that convert backend types to / from ratatui types, but for those that need it, it makes sense not to repeat the code. |
Adds two traits
IntoCrossterm
andFromCrossterm
for convertingbetween ratatui and crossterm types. This is necessary in order to avoid
the orphan rule when implementing
From
for crossterm types once thecrossterm types are moved to a separate crate.
Similarly Termwiz and Termwiz gain FromTermion, IntoTermion, FromTermwiz
and IntoTermwiz traits.
BREAKING CHANGE: The
From
andInto
impls for backend types are now replacedwith specific backend traits.
Similar conversions for
ContentStyle
->Style
andAttributes
->Modifier
exist for Crossterm,and all the Termion and Termwiz types.