This addresses color issue; Yeees just got forgotten it :(
As far as I understand an acceptance test can't be created because ansi
got stripped in `nu!`. (for future regressions)

But wrapping I need to take a deeper look.
Maybe in an hour.

cc: @fdncred
This commit is contained in:
Maxim Zhiburt
2025-04-11 16:02:01 +03:00
committed by GitHub
parent 39edd7e080
commit d75aa7ed1b
6 changed files with 805 additions and 793 deletions

File diff suppressed because it is too large Load Diff

View File

@ -240,7 +240,7 @@ fn expand_list(input: &[Value], cfg: Cfg<'_>) -> TableResult {
}
let mut available = available_width - pad_space;
let mut column_width = string_width(&header);
let mut column_width = 0;
if !is_last_column {
// we need to make sure that we have a space for a next column if we use available width
@ -293,9 +293,18 @@ fn expand_list(input: &[Value], cfg: Cfg<'_>) -> TableResult {
column_rows = column_rows.saturating_add(cell.size);
}
let mut head_width = string_width(&header);
let mut header = header;
if head_width > available {
header = wrap_text(&header, available, cfg.opts.config);
head_width = available;
}
let head_cell = NuRecordsValue::new(header);
data[0].push(head_cell);
column_width = max(column_width, head_width);
if column_width > available {
// remove the column we just inserted
for row in &mut data {

View File

@ -31,6 +31,27 @@ pub fn string_wrap(text: &str, width: usize, keep_words: bool) -> String {
Wrap::wrap(text, width, keep_words)
}
pub fn string_expand(text: &str, width: usize) -> String {
use std::{borrow::Cow, iter::repeat};
use tabled::grid::util::string::{get_line_width, get_lines};
get_lines(text)
.map(|line| {
let length = get_line_width(&line);
if length < width {
let mut line = line.into_owned();
let remain = width - length;
line.extend(repeat(' ').take(remain));
Cow::Owned(line)
} else {
line
}
})
.collect::<Vec<_>>()
.join("\n")
}
pub fn string_truncate(text: &str, width: usize) -> String {
let line = match text.lines().next() {
Some(line) => line,