-
-
Notifications
You must be signed in to change notification settings - Fork 403
Debug formatting for Style, Span, Line, Text #1382
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
Labels
Type: Enhancement
New feature or request
Comments
Omitting default values entirely, and collapsing spans that don't have non-default values to just a string:
110 lines -> 21 lines |
+1 for this, sounds/looks reasonable to me. |
joshka
added a commit
that referenced
this issue
Sep 20, 2024
2 tasks
Discussion in https://discord.com/channels/1070692720437383208/1286506962783047764 Given: 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:
Alternate debug:
TODO
|
Span::from("foo") could be a reasonable other approach here. |
orhun
added a commit
that referenced
this issue
Sep 26, 2024
…#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: #1382 --------- Co-authored-by: Orhun Parmaksız <orhun@archlinux.org> Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
joshka
added a commit
to erak/ratatui
that referenced
this issue
Oct 14, 2024
…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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
When writing some widget level code (for tui-markdown) and debugging the output of the text in tests, I found that having all fields in
Style
listed when they're None seemed overly verbose, and made it more difficult to navigate through any assertion errors (e.g. when taking a TDD approach to building things).Additionally, the content field of the Span/Line/Text seems to dominate in size, as it's usually more complex than the other fields (style, alignment). This pushes them far below the start of the struct representation.
Solution
Debug
implementation ofStyle
with one that omits anyNone
valuesDebug
implementation)Some(...)
surrounding the valueAlternatives
Write a function that provides a more custom compact debugging view of these methods:
This doesn't work for assertions however, which use the Debug representation, so it seems like a non-starter.
Additional context
A real example from tui-markdown:
Which becomes after modification:
The text was updated successfully, but these errors were encountered: