-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wincon)!: Make styled output stateless
To do this, we use cache the current colors on first check, rather than re-querying it on every check. This enables us to just have a simple `WinconStream::write_colored` function. This also fixes bugs with making sure that the stream is locked before doing our various operations on it, avoiding race conditions.
- Loading branch information
Showing
14 changed files
with
222 additions
and
491 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
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
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
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//! Low-level ANSI-styling | ||
/// Write ANSI colored text to the stream | ||
pub fn write_colored<S: std::io::Write>( | ||
stream: &mut S, | ||
fg: Option<anstyle::AnsiColor>, | ||
bg: Option<anstyle::AnsiColor>, | ||
data: &[u8], | ||
) -> std::io::Result<usize> { | ||
let non_default = fg.is_some() || bg.is_some(); | ||
|
||
if non_default { | ||
if let Some(fg) = fg { | ||
write!(stream, "{}", fg.render_fg())?; | ||
} | ||
if let Some(bg) = bg { | ||
write!(stream, "{}", bg.render_bg())?; | ||
} | ||
} | ||
let written = stream.write(data)?; | ||
if non_default { | ||
write!(stream, "{}", anstyle::Reset.render())?; | ||
} | ||
Ok(written) | ||
} |
Oops, something went wrong.