mirror of
https://github.com/nushell/nushell.git
synced 2025-03-13 06:58:47 +01:00
Merge 2c9b09af0d
into 95dcb2fd6c
This commit is contained in:
commit
81a8bd51a2
@ -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(
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user