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

Make Style.with_reset more explicit as prefix_with_reset #50

Merged
merged 1 commit into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Style {
}

// Prefix everything with reset characters if needed
if self.with_reset {
if self.prefix_with_reset {
write!(f, "\x1B[0m")?
}

Expand Down
14 changes: 7 additions & 7 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub struct Style {
/// Whether this style is struckthrough.
pub is_strikethrough: bool,

/// Wether this style starts with reset code
pub with_reset: bool,
/// Wether this style is always displayed starting with a reset code to clear any remaining style artifacts
pub prefix_with_reset: bool,
}

impl Style {
Expand All @@ -64,7 +64,7 @@ impl Style {
Style::default()
}

/// Returns a `Style` with the reset_before_style property set.
/// Returns a [`Style`] with the `Style.prefix_with_reset` property set.
///
/// # Examples
///
Expand All @@ -76,7 +76,7 @@ impl Style {
/// ```
pub const fn reset_before_style(&self) -> Style {
Style {
with_reset: true,
prefix_with_reset: true,
..*self
}
}
Expand Down Expand Up @@ -289,7 +289,7 @@ impl Default for Style {
is_reverse: false,
is_hidden: false,
is_strikethrough: false,
with_reset: false,
prefix_with_reset: false,
}
}
}
Expand Down Expand Up @@ -577,7 +577,7 @@ impl Color {
pub fn reset_before_style(self) -> Style {
Style {
foreground: Some(self),
with_reset: true,
prefix_with_reset: true,
..Style::default()
}
}
Expand Down Expand Up @@ -659,6 +659,6 @@ mod serde_json_tests {
fn style_serialization() {
let style = Style::default();

assert_eq!(serde_json::to_string(&style).unwrap(), "{\"foreground\":null,\"background\":null,\"is_bold\":false,\"is_dimmed\":false,\"is_italic\":false,\"is_underline\":false,\"is_blink\":false,\"is_reverse\":false,\"is_hidden\":false,\"is_strikethrough\":false,\"with_reset\":false}".to_string());
assert_eq!(serde_json::to_string(&style).unwrap(), "{\"foreground\":null,\"background\":null,\"is_bold\":false,\"is_dimmed\":false,\"is_italic\":false,\"is_underline\":false,\"is_blink\":false,\"is_reverse\":false,\"is_hidden\":false,\"is_strikethrough\":false,\"prefix_with_reset\":false}".to_string());
}
}
2 changes: 1 addition & 1 deletion tests/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn manual_instance_style() {
is_reverse: false,
is_hidden: false,
is_strikethrough: false,
with_reset: false,
prefix_with_reset: false,
};
assert_eq!(Style::default(), s);
}