nu-table: Strip custom color in the header when used on border (#10357)

ref: #10351
cc: @fdncred
This commit is contained in:
Maxim Zhiburt 2023-09-13 17:11:00 +00:00 committed by GitHub
parent ce4ea16c08
commit ffb5051f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@ use crate::table_theme::TableTheme;
use nu_ansi_term::Style;
use nu_color_config::TextStyle;
use nu_protocol::TrimStrategy;
use nu_utils::strip_ansi_unlikely;
use std::cmp::min;
use std::collections::HashMap;
use tabled::{
@ -285,6 +286,8 @@ fn set_border_head(table: &mut Table, with_footer: bool, wctrl: TableWidthCtrl)
table.with(
Settings::default()
.with(wctrl)
.with(StripColorFromRow(0))
.with(StripColorFromRow(count_rows - 1))
.with(HeaderMove((0, 0), true))
.with(HeaderMove((count_rows - 1 - 1, count_rows - 1), false)),
);
@ -292,6 +295,7 @@ fn set_border_head(table: &mut Table, with_footer: bool, wctrl: TableWidthCtrl)
table.with(
Settings::default()
.with(wctrl)
.with(StripColorFromRow(0))
.with(HeaderMove((0, 0), true)),
);
}
@ -968,3 +972,18 @@ fn colorize_lead_trail_space(
}
}
}
struct StripColorFromRow(usize);
impl TableOption<NuRecords, CompleteDimensionVecRecords<'_>, ColoredConfig> for StripColorFromRow {
fn change(
self,
recs: &mut NuRecords,
_: &mut ColoredConfig,
_: &mut CompleteDimensionVecRecords<'_>,
) {
for cell in &mut recs[self.0] {
*cell = CellInfo::new(strip_ansi_unlikely(cell.as_ref()).into_owned());
}
}
}