Skip to content

Commit

Permalink
nu-table: Strip custom color in the header when used on border (nushe…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt authored Sep 13, 2023
1 parent ce4ea16 commit ffb5051
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/nu-table/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -285,13 +286,16 @@ 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)),
);
} else {
table.with(
Settings::default()
.with(wctrl)
.with(StripColorFromRow(0))
.with(HeaderMove((0, 0), true)),
);
}
Expand Down Expand Up @@ -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());
}
}
}

0 comments on commit ffb5051

Please sign in to comment.