Skip to content
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

feat(line): impl Styled for Line #968

Merged
merged 2 commits into from Feb 25, 2024
Merged

feat(line): impl Styled for Line #968

merged 2 commits into from Feb 25, 2024

Conversation

joshka
Copy link
Member

@joshka joshka commented Feb 25, 2024

This adds FromIterator impls for Line and Text that allow creating
Line and Text instances from iterators of Span and Line
instances, respectively.

let line = Line::from_iter(vec!["Hello".blue(), " world!".green()]);
let line: Line = iter::once("Hello".blue())
    .chain(iter::once(" world!".green()))
    .collect();
let text = Text::from_iter(vec!["The first line", "The second line"]);
let text: Text = iter::once("The first line")
    .chain(iter::once("The second line"))
    .collect();

This adds `FromIterator` impls for `Line` and `Text` that allow creating
`Line` and `Text` instances from iterators of `Span` and `Line`
instances, respectively.

```rust
let line = Line::from_iter(vec!["Hello".blue(), " world!".green()]);
let line: Line = iter::once("Hello".blue())
    .chain(iter::once(" world!".green()))
    .collect();
let text = Text::from_iter(vec!["The first line", "The second line"]);
let text: Text = iter::once("The first line")
    .chain(iter::once("The second line"))
    .collect();
```
This adds the `Stylize` methods to line, allowing for easy styling of
lines.

```rust
Line::raw("Hello, world!").green();
Line::raw("Hello, world!").on_green();
Line::raw("Hello, world!").italic();
```
@joshka
Copy link
Member Author

joshka commented Feb 25, 2024

Includes #967 - merge that first for separate changelog entries.

Copy link

codecov bot commented Feb 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.7%. Comparing base (943c043) to head (bf1ed9b).

Additional details and impacted files
@@          Coverage Diff          @@
##            main    #968   +/-   ##
=====================================
  Coverage   91.7%   91.7%           
=====================================
  Files         61      61           
  Lines      15742   15809   +67     
=====================================
+ Hits       14440   14507   +67     
  Misses      1302    1302           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@joshka joshka merged commit 1cff511 into main Feb 25, 2024
36 checks passed
@joshka joshka deleted the jm/line-styled branch February 25, 2024 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants