diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 147555558e..c576fad7b3 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -545,8 +545,13 @@ fn handle_record(input: CmdInput, mut record: Record) -> ShellResult String { let config = stack.get_config(engine_state); if !config.table.show_empty { @@ -1099,9 +1106,10 @@ fn create_empty_placeholder( let style_computer = &StyleComputer::from_config(engine_state, stack); configure_table(&mut out, &config, style_computer, TableMode::default()); - out.table + let ret = out.table .draw(termwidth) - .expect("Could not create empty table placeholder") + .expect("Could not create empty table placeholder"); + maybe_strip_color(ret, use_ansi_coloring) } fn convert_table_to_output( diff --git a/crates/nu-command/tests/commands/table.rs b/crates/nu-command/tests/commands/table.rs index 41bd1ec531..bbfe0a3cd0 100644 --- a/crates/nu-command/tests/commands/table.rs +++ b/crates/nu-command/tests/commands/table.rs @@ -3120,6 +3120,45 @@ fn table_colors() { assert_eq!(actual.out, "╭───┬───╮│ a │ 1 ││ b │ 2 │╰───┴───╯"); } +#[test] +fn empty_table_colors() { + let actual = nu!(concat!( + "$env.config.use_ansi_coloring = true;", + "{}", + )); + assert_eq!( + actual.out, + "\u{1b}[37m╭──────────────╮\u{1b}[0m\u{1b}[37m│\u{1b}[0m \u{1b}[2mempty record\u{1b}[0m \u{1b}[37m│\u{1b}[0m\u{1b}[37m╰──────────────╯\u{1b}[0m" + ); + + let actual = nu!(concat!( + "$env.config.use_ansi_coloring = true;", + "[]", + )); + assert_eq!( + actual.out, + "\u{1b}[37m╭────────────╮\u{1b}[0m\u{1b}[37m│\u{1b}[0m \u{1b}[2mempty list\u{1b}[0m \u{1b}[37m│\u{1b}[0m\u{1b}[37m╰────────────╯\u{1b}[0m" + ); + + let actual = nu!(concat!( + "$env.config.use_ansi_coloring = false;", + "{}", + )); + assert_eq!( + actual.out, + "╭──────────────╮│ empty record │╰──────────────╯" + ); + + let actual = nu!(concat!( + "$env.config.use_ansi_coloring = false;", + "[]", + )); + assert_eq!( + actual.out, + "╭────────────╮│ empty list │╰────────────╯" + ); +} + #[test] fn table_index() { let actual = nu!("[[ index var ]; [ abc 1 ] [ def 2 ] [ ghi 3 ]] | table --width=80");