Fix table expand wrap in case no header is there (#7605)

ref #7598

To be honest I was not able to obtain such results in basic mode as you
@rgwood.
But I've got it in `table -e`.

So this must fix the `table -e` wrapping.

Could you verify if it got fixed?

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt
2022-12-27 16:44:34 +03:00
committed by GitHub
parent 38fc42d352
commit 4f812a7f34
3 changed files with 96 additions and 46 deletions

View File

@ -4,7 +4,7 @@ pub fn string_width(text: &str) -> usize {
tabled::papergrid::util::string_width_multiline_tab(text, 4)
}
pub fn wrap_string(text: &str, width: usize) -> String {
pub fn string_wrap(text: &str, width: usize, keep_words: bool) -> String {
// todo: change me...
//
// well... it's not effitient to build a table to wrap a string,
@ -14,13 +14,17 @@ pub fn wrap_string(text: &str, width: usize) -> String {
return String::new();
}
let wrap = if keep_words {
Width::wrap(width).keep_words()
} else {
Width::wrap(width)
};
Builder::from_iter([[text]])
.build()
.with(Style::empty())
.with(Padding::zero())
.with(Modify::new(Cell(0, 0)).with(Width::wrap(width)))
.to_string()
.trim_end()
.with(Modify::new(Cell(0, 0)).with(wrap))
.to_string()
}
@ -39,18 +43,3 @@ pub fn string_truncate(text: &str, width: usize) -> String {
.with(Width::truncate(width))
.to_string()
}
pub fn string_wrap(text: &str, width: usize) -> String {
// todo: change me...
if text.is_empty() {
return String::new();
}
Builder::from_iter([[text]])
.build()
.with(Style::empty())
.with(Padding::zero())
.with(Width::wrap(width))
.to_string()
}