-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace owo-colors with anstream/anstyle
The anstream and anstyle crates look more promising and additionally allow to expose the on the API if needed, without restricting to a specific terminal coloring crate. Also, the owo-colors crate contained some unmaintained dependencies.
- Loading branch information
Showing
7 changed files
with
55 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,27 +1,36 @@ | ||
use std::fmt::Display; | ||
|
||
use owo_colors::OwoColorize; | ||
use anstream::ColorChoice; | ||
use anstyle::{AnsiColor, Color, Style}; | ||
|
||
pub fn sample(value: impl Display) -> String { | ||
if cfg!(feature = "debug") { | ||
format!("❬B❭{value}❬B❭") | ||
} else { | ||
value.bright_blue().to_string() | ||
} | ||
render(value, 'B', AnsiColor::BrightBlue) | ||
} | ||
|
||
pub fn value(value: impl Display) -> String { | ||
if cfg!(feature = "debug") { | ||
format!("❬Y❭{value}❬Y❭") | ||
} else { | ||
value.bright_yellow().to_string() | ||
} | ||
render(value, 'Y', AnsiColor::BrightYellow) | ||
} | ||
|
||
pub fn focus(value: impl Display) -> String { | ||
render(value, 'W', AnsiColor::BrightWhite) | ||
} | ||
|
||
#[inline] | ||
fn render(value: impl Display, debug_char: char, color: AnsiColor) -> String { | ||
if cfg!(feature = "debug") { | ||
format!("❬W❭{value}❬W❭") | ||
format!("❬{debug_char}❭{value}❬{debug_char}❭") | ||
} else if use_ansi() { | ||
let style = Style::new().fg_color(Some(Color::Ansi(color))); | ||
format!("{}{value}{}", style.render(), style.render_reset()) | ||
} else { | ||
value.bright_white().to_string() | ||
value.to_string() | ||
} | ||
} | ||
|
||
fn use_ansi() -> bool { | ||
match anstream::stderr().current_choice() { | ||
ColorChoice::Auto => anstream::stderr().is_terminal(), | ||
ColorChoice::AlwaysAnsi | ColorChoice::Always => true, | ||
ColorChoice::Never => false, | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
use std::fmt::Display; | ||
|
||
use owo_colors::{OwoColorize, Stream}; | ||
use anstream::ColorChoice; | ||
use anstyle::{AnsiColor, Color, Style}; | ||
|
||
pub fn sample(value: impl Display) -> String { | ||
if cfg!(feature = "debug") { | ||
format!("❬B❭{value}❬B❭") | ||
} else { | ||
value | ||
.if_supports_color(Stream::Stderr, OwoColorize::bright_blue) | ||
.to_string() | ||
} | ||
render(value, 'B', AnsiColor::BrightBlue) | ||
} | ||
|
||
pub fn value(value: impl Display) -> String { | ||
render(value, 'Y', AnsiColor::BrightYellow) | ||
} | ||
|
||
#[inline] | ||
fn render(value: impl Display, debug_char: char, color: AnsiColor) -> String { | ||
if cfg!(feature = "debug") { | ||
format!("❬Y❭{value}❬Y❭") | ||
format!("❬{debug_char}❭{value}❬{debug_char}❭") | ||
} else if use_ansi() { | ||
let style = Style::new().fg_color(Some(Color::Ansi(color))); | ||
format!("{}{value}{}", style.render(), style.render_reset()) | ||
} else { | ||
value | ||
.if_supports_color(Stream::Stderr, OwoColorize::bright_yellow) | ||
.to_string() | ||
value.to_string() | ||
} | ||
} | ||
|
||
fn use_ansi() -> bool { | ||
match anstream::stderr().current_choice() { | ||
ColorChoice::Auto => anstream::stderr().is_terminal(), | ||
ColorChoice::AlwaysAnsi | ColorChoice::Always => true, | ||
ColorChoice::Never => false, | ||
} | ||
} |
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