-
-
Notifications
You must be signed in to change notification settings - Fork 403 8000
chore(style): make Debug output for Text/Line/Span/Style more concise #1383
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
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.
I just gave this a try and it works well - however I'm a bit concerned about the complexity that this implementation might gain in the future. I see that the debug output is now as close as possible to the actual API and doing that might require more string work in the future. Also, there are some parts that can be extracted or can be simplified, e.g. Color
-> snake_case color name conversion.
I'm not too worried about the future concerns as we can handle those in the future when we need it. Keeping it simple as possible though makes sense. I wouldn't introduce a crate for case conversion unless it was also used in some other part of Ratatui, but I would extract color name conversion into a small function and consider making this public if it made sense. Mostly I wanted to get some general buy-in that this was useful. It certainly was for me when implementing some stuff for tui-markdown. It was easy to write a broken test asserting some output (which was a |
Yup, extracting that to a small function would be nice. Also, what else do you have in mind for going forward with this? I see some todos which I can take a look if you want. |
Go for it - I'm just catching up after a few days away, but this should be an easy one to complete quickly:
A guiding idea is that debug view should not be considered stable, so we can change this as needed. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1383 +/- ##
=======================================
- Coverage 94.0% 93.5% -0.5%
=======================================
Files 67 67
Lines 15750 15897 +147
=======================================
+ Hits 14809 14871 +62
- Misses 941 1026 +85 ☔ View full report in Codecov by Sentry. |
Addressed the comments, can you take a look? :) |
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.
LGTM, one small nit on naming.
LGTM. I can't approve this as the initial Author |
Improves #1383 The following now round trips when formatted for debug. This will make it easier to use insta when testing text related views of widgets. ```rust Text::from_iter([ Line::from("Hello, world!"), Line::from("How are you?").bold().left_aligned(), Line::from_iter([ Span::from("I'm "), Span::from("doing ").italic(), Span::from("great!").bold(), ]), ]).on_blue().italic().centered() ```
…ratatui#1383) Given: ```rust Text::from_iter([ Line::from("without line fields"), Line::from("with line fields").bold().centered(), Line::from_iter([ Span::from("without span fields"), Span::from("with span fields") .green() .on_black() .italic() .not_dim(), ]), ]) ``` Debug: ``` Text [Line [Span("without line fields")], Line { style: Style::new().add_modifier(Modifier::BOLD), alignment: Some(Center), spans: [Span("with line fields")] }, Line [Span("without span fields"), Span { style: Style::new().green().on_black().add_modifier(Modifier::ITALIC).remove_modifier(Modifier::DIM), content: "with span fields" }]] ``` Fixes: ratatui#1382 --------- Co-authored-by: Orhun Parmaksız <orhun@archlinux.org> Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
…tui#1410) Improves ratatui#1383 The following now round trips when formatted for debug. This will make it easier to use insta when testing text related views of widgets. ```rust Text::from_iter([ Line::from("Hello, world!"), Line::from("How are you?").bold().left_aligned(), Line::from_iter([ Span::from("I'm "), Span::from("doing ").italic(), Span::from("great!").bold(), ]), ]).on_blue().italic().centered() ```
Discussion in https://discord.com/channels/1070692720437383208/1286506962783047764
Given:
Debug:
Alternate debug:
Fixes: #1382
TODO