Skip to content

Commit

Permalink
Add support for unicode width
Browse files Browse the repository at this point in the history
  • Loading branch information
ratmice committed Sep 9, 2022
1 parent 12759f0 commit 7835860
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ exclude = [

[dependencies]
yansi = "0.5"
unicode-width = "0.1.9"
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use std::{
cmp::{PartialEq, Eq},
fmt,
};
use unicode_width::UnicodeWidthChar;

/// A trait implemented by spans within a character-based source.
pub trait Span {
Expand Down Expand Up @@ -369,7 +370,7 @@ impl Config {
(' ', tab_end - col)
},
c if c.is_whitespace() => (' ', 1),
_ => (c, 1),
_ => (c, c.width().unwrap_or(1)),
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,16 @@ impl<S: Span> Report<'_, S> {
} else {
self.config.unimportant_color()
};
let (c, width) = self.config.char_width(c, col);
for _ in 0..width {

if c.is_whitespace() {
let (_, width) = self.config.char_width(c, col);
for _ in 0..width {
write!(w, "{}", c.fg(color))?;
}
} else {
write!(w, "{}", c.fg(color))?;
}
};

}
}
write!(w, "\n")?;
Expand Down

0 comments on commit 7835860

Please sign in to comment.