Open joshka opened 2 hours ago
Omitting default values entirely, and collapsing spans that don't have non-default values to just a string:
Text {
lines: [
Line {
style: Style { fg: Green, },
spans: [
Span { ">" },
Span { " " },
Span { "Blockquote 1" },
],
},
Line {
style: Style { fg: Green },
spans: [
Span { ">" },
Span { ">" },
Span { " " },
Span { "Nested Blockquote" },
],
},
],
}
110 lines -> 21 lines
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: