From 01ef6b0732f809bc55c2f69af7acc16b52d1fa70 Mon Sep 17 00:00:00 2001 From: Cristian Date: Mon, 20 Apr 2020 23:09:22 -0700 Subject: [PATCH] Add config to disable table index column (#1623) --- crates/nu-cli/src/format/table.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/nu-cli/src/format/table.rs b/crates/nu-cli/src/format/table.rs index 795e8074b..2169817ec 100644 --- a/crates/nu-cli/src/format/table.rs +++ b/crates/nu-cli/src/format/table.rs @@ -73,7 +73,19 @@ impl TableView { } } +fn are_table_indexes_disabled() -> bool { + let config = crate::data::config::config(Tag::unknown()); + match config { + Ok(config) => { + let disable_indexes = config.get("disable_table_indexes"); + disable_indexes.map_or(false, |x| x.as_bool().unwrap_or(false)) + } + _ => false, + } +} + fn values_to_entries(values: &[Value], headers: &mut Vec, starting_idx: usize) -> Entries { + let disable_indexes = are_table_indexes_disabled(); let mut entries = vec![]; if headers.is_empty() { @@ -117,12 +129,16 @@ fn values_to_entries(values: &[Value], headers: &mut Vec, starting_idx: .collect(); // Indices are green, bold, right-aligned: - row.insert(0, ((starting_idx + idx).to_string(), "Fgbr")); + if !disable_indexes { + row.insert(0, ((starting_idx + idx).to_string(), "Fgbr")); + } entries.push(row); } - headers.insert(0, "#".to_owned()); + if !disable_indexes { + headers.insert(0, "#".to_owned()); + } entries }