-
-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(text): expose graphemes on Line
- add `Line::styled()` - add `Line::styled_graphemes()` - add `StyledGrapheme::new()`
- Loading branch information
Showing
3 changed files
with
114 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,31 @@ | ||
use crate::style::Style; | ||
use crate::style::{Style, Styled}; | ||
|
||
/// A grapheme associated to a style. | ||
/// Note that, although `StyledGrapheme` is the smallest divisible unit of text, | ||
/// it actually is not a member of the text type hierarchy (`Text` -> `Line` -> `Span`). | ||
/// It is a separate type used mostly for rendering purposes. A `Span` consists of components that | ||
/// can be split into `StyledGrapheme`s, but it does not contain a collection of `StyledGrapheme`s. | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct StyledGrapheme<'a> { | ||
pub symbol: &'a str, | ||
pub style: Style, | ||
} | ||
|
||
impl<'a> StyledGrapheme<'a> { | ||
pub fn new(symbol: &'a str, style: Style) -> StyledGrapheme<'a> { | ||
StyledGrapheme { symbol, style } | ||
} | ||
} | ||
|
||
impl<'a> Styled for StyledGrapheme<'a> { | ||
type Item = StyledGrapheme<'a>; | ||
|
||
fn style(&self) -> Style { | ||
self.style | ||
} | ||
|
||
fn set_style(mut self, style: Style) -> Self::Item { | ||
self.style = style; | ||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters