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 10, 2022
1 parent 12759f0 commit f423f90
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 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
9 changes: 7 additions & 2 deletions src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,14 @@ impl<S: Span> Report<'_, S> {
self.config.unimportant_color()
};
let (c, width) = self.config.char_width(c, col);
for _ in 0..width {
if c.is_whitespace() {
for _ in 0..width {
write!(w, "{}", c.fg(color))?;
}
} else {
write!(w, "{}", c.fg(color))?;
}
};

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

0 comments on commit f423f90

Please sign in to comment.