-
-
Notifications
You must be signed in to change notification settings - Fork 346
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
refactor(text): replace Spans
with Line
#178
Conversation
`Line` is a significantly better name over `Spans` as the plural causes confusion and the type really is a representation of a line of text made up of spans. This is a backwards compatible version of the approach from ratatui#175 There is a significant amount of code that uses the Spans type and methods, so instead of just renaming it, we add a new type and replace parameters that accepts a `Spans` with a parameter that accepts `Into<Line>`. Note that the examples have been intentionally left using `Spans` in this commit to demonstrate the compiler warnings that will be emitted in existing code. Implementation notes: - moves the Spans code to text::spans and publicly reexports on the text module. This makes the test in that module only relevant to the Spans type. - adds a line module with a copy of the code and tests from Spans with a single addition: `impl<'a> From<Spans<'a>> for Line<'a>` - adds tests for `Spans` (created and checked before refactoring) - adds the same tests for `Line` - updates all widget methods that accept and store Spans to instead store `Line` and accept `Into<Line>`
Re-exports the Masked type at text::Masked
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.
Thanks for the PR rework, LGTM.
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 like where this ended up! LGTM
Lookg good 👍 |
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
Great work and great idea to begin with!
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 🦀
Spans
with Line
Line
is a significantly better name overSpans
as the plural causesconfusion and the type really is a representation of a line of text made
up of spans.
This is a backwards compatible version of the approach from
#175
There is a significant amount of code that uses the Spans type and
methods, so instead of just renaming it, we add a new type and replace
parameters that accepts a
Spans
with a parameter that acceptsInto<Line>
.Note that the examples have been intentionally left using
Spans
inthis commit to demonstrate the compiler warnings that will be emitted in
existing code.
Implementation notes:
module. This makes the test in that module only relevant to the Spans
type.
single addition:
impl<'a> From<Spans<'a>> for Line<'a>
Spans
(created and checked before refactoring)Line
store
Line
and acceptInto<Line>
There is a second related commit on this PR to move text::Masked -> text::masked::Masked, with no changes.
Tagging @Eyesonjune18 and @TimerErTim for their input
This will likely require changes to be made on the changes in #149 (hopefully, just in
Text
andLine
?)I also updated the examples in a third commit. I wanted to make sure that backwards compatibility was maintained in a way that made sense first though so I intentionally kept the two commits separate. E.g.:
I think the only breaking change on this is any code that specifically calls
Text::into_iter()
and then stores that in a variable or field of type IntoIter<Spans<'a>> rather than just letting type inference do its thing. This seems unlikely enough that it's probably not even worth noting.