Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ path = "src/main.rs"
name = "prettytable"

[dependencies]
unicode-width = "0.1"
unicode-width = "0.2"
term = "0.7"
lazy_static = "1.4"
is-terminal = "0.4"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1314,9 +1314,9 @@ mod tests {

table.add_row(Row::new(vec![Cell::new("\u{1b}[\u{1b}\u{0}\u{0}")]));

let out = "+--+
let out = "+-----+
| \u{1b}[\u{1b}\u{0}\u{0} |
+--+
+-----+
";

assert_eq!(table.to_string().replace("\r\n", "\n"), out);
Expand Down
8 changes: 6 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ pub fn display_width(text: &str) -> usize {
_ => state,
};

// We don't count escape characters as hidden as
// UnicodeWidthStr::width already considers them.
// We should count escape characters as hidden because
// UnicodeWidthStr::width treats escape characters as 1 column wide.
// However UnicodeWidthChar::width treats escape characters as `None`.
if state == State::EscapeChar {
hidden += 1;
}
if matches!(state, State::OpenBracket | State::AfterEscape) {
// but if we see an escape char *inside* the ANSI escape, we should ignore it.
if UnicodeWidthChar::width(c).unwrap_or(0) > 0 {
Expand Down