Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
Tweak style for new WithAnsi code
  • Loading branch information
djc committed Jun 28, 2025
commit ddf9426b7044296b7b8caabe2287bc4ec05da6ed
11 changes: 6 additions & 5 deletions src/ansi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,19 @@ pub fn strip_ansi_codes(s: &str) -> Cow<str> {
pub struct WithoutAnsi<'a> {
str: &'a str,
}

impl<'a> WithoutAnsi<'a> {
pub fn new(str: &'a str) -> Self {
Self { str }
}
}

impl Display for WithoutAnsi<'_> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
for str in
AnsiCodeIterator::new(self.str)
.filter_map(|(str, is_ansi)| if is_ansi { None } else { Some(str) })
{
f.write_str(str)?;
for (str, is_ansi) in AnsiCodeIterator::new(self.str) {
if !is_ansi {
f.write_str(str)?;
}
}
Ok(())
}
Expand Down
Loading