mirror of
https://github.com/nushell/nushell.git
synced 2025-05-21 10:20:46 +02:00
close? #8060 Quite a bit of refactoring took place. I believe a few improvements to collapse/expand were made. I've tried to track any performance regressions and seems like it is fine. I've noticed something different now with default configuration path or something in this regard? So I might missed something while testing because of this. Requires some oversight. --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use tabled::{
|
|
builder::Builder,
|
|
grid::util::string::string_width_multiline,
|
|
settings::{width::Truncate, Modify, Padding, Style, Width},
|
|
};
|
|
|
|
pub fn string_width(text: &str) -> usize {
|
|
string_width_multiline(text)
|
|
}
|
|
|
|
pub fn string_wrap(text: &str, width: usize, keep_words: bool) -> String {
|
|
// todo: change me...
|
|
//
|
|
// well... it's not efficient to build a table to wrap a string,
|
|
// but ... it's better than a copy paste (is it?)
|
|
|
|
if text.is_empty() {
|
|
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((0, 0)).with(wrap))
|
|
.to_string()
|
|
}
|
|
|
|
pub fn string_truncate(text: &str, width: usize) -> String {
|
|
// todo: change me...
|
|
|
|
let line = match text.lines().next() {
|
|
Some(first_line) => first_line,
|
|
None => return String::new(),
|
|
};
|
|
|
|
Truncate::truncate_text(line, width).into_owned()
|
|
}
|