Skip to content

Commit

Permalink
tabled/ Fix wrap emojie issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Feb 18, 2025
1 parent dd52238 commit a17fbd3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tabled/src/settings/width/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ fn split_keeping_words(text: &str, width: usize, prefix: &str, suffix: &str) ->
word_width = 0;
}
_ => {
word_width += get_char_width(c);
word_width += std::cmp::max(1, get_char_width(c));
word_chars += 1;
}
}
Expand Down Expand Up @@ -547,11 +547,11 @@ mod parsing {
}

pub(super) struct MultilineBuffer<'a> {
buf: String,
width_last: usize,
width: usize,
prefix: &'a str,
suffix: &'a str,
pub buf: String,
pub width_last: usize,
pub width: usize,
pub prefix: &'a str,
pub suffix: &'a str,
}

impl<'a> MultilineBuffer<'a> {
Expand Down Expand Up @@ -642,7 +642,7 @@ mod parsing {
count_chars += 1;
count_bytes += c.len_utf8();

let cwidth = get_char_width(c);
let cwidth = std::cmp::max(1, get_char_width(c));

let available_space = self.width - self.width_last;
if available_space == 0 {
Expand Down Expand Up @@ -690,7 +690,7 @@ mod parsing {
count_chars += 1;
count_bytes += c.len_utf8();

let cwidth = get_char_width(c);
let cwidth = std::cmp::max(1, get_char_width(c));
self.width_last += cwidth;

self.buf.push(c);
Expand Down
22 changes: 22 additions & 0 deletions tabled/tests/settings/width_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2542,6 +2542,28 @@ test_table!(
"+--+---+----------+----------+"
);

#[cfg(feature = "ansi")]
test_table!(
wrap_issue_0,
{
tabled::Table::new(vec![
("x xxx xx xxxxxxx xxxxxxxx xx xxxx xxxxxxx. xx xxxxxxxx xxx ❤️ xx xxxxx xx xxxxxxx x xx xxxxxx x xxxxxx xxxxxxxxxxxx xx xxxxxx xxx xxx xxxxxx xxxxxxx. xx xxxxxxxx xx xx xxxxxxxxxx"),
])
.with(Width::wrap(40).keep_words(true))
.to_string()
},
"+--------------------------------------+"
"| &str |"
"+--------------------------------------+"
"| x xxx xx xxxxxxx xxxxxxxx xx xxxx |"
"| xxxxxxx. xx xxxxxxxx xxx ❤️ xx xxxxx |"
"| xx xxxxxxx x xx xxxxxx x xxxxxx |"
"| xxxxxxxxxxxx xx xxxxxx xxx xxx |"
"| xxxxxx xxxxxxx. xx xxxxxxxx xx xx |"
"| xxxxxxxxxx |"
"+--------------------------------------+"
);

#[cfg(feature = "derive")]
mod derived {
use super::*;
Expand Down

0 comments on commit a17fbd3

Please sign in to comment.