This commit is contained in:
FreshOrangeXC 2025-03-10 05:19:50 -07:00 committed by GitHub
commit 81a8bd51a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 4 deletions

View File

@ -545,8 +545,13 @@ fn handle_record(input: CmdInput, mut record: Record) -> ShellResult<PipelineDat
let span = input.data.span().unwrap_or(input.call.head);
if record.is_empty() {
let value =
create_empty_placeholder("record", input.cfg.width, input.engine_state, input.stack);
let value = create_empty_placeholder(
"record",
input.cfg.width,
input.engine_state,
input.stack,
input.cfg.use_ansi_coloring,
);
let value = Value::string(value, span);
return Ok(value.into_pipeline_data());
};
@ -898,6 +903,7 @@ impl Iterator for PagingTableCreator {
self.table_config.width,
&self.engine_state,
&self.stack,
self.table_config.use_ansi_coloring,
);
let mut bytes = result.into_bytes();
// Add extra newline if show_empty is enabled
@ -1084,6 +1090,7 @@ fn create_empty_placeholder(
termwidth: usize,
engine_state: &EngineState,
stack: &Stack,
use_ansi_coloring: bool,
) -> String {
let config = stack.get_config(engine_state);
if !config.table.show_empty {
@ -1099,9 +1106,11 @@ 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(

View File

@ -3120,6 +3120,30 @@ 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");