allows for nushell to have tables without the index column (#5380)

This commit is contained in:
Darren Schroeder 2022-04-30 09:07:46 -05:00 committed by GitHub
parent 1fc7abcc38
commit 5999506f87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View file

@ -304,9 +304,10 @@ fn convert_to_table(
let mut input = input.iter().peekable();
let color_hm = get_color_config(config);
let float_precision = config.float_precision as usize;
let disable_index = config.disable_table_indexes;
if input.peek().is_some() {
if !headers.is_empty() {
if !headers.is_empty() && !disable_index {
headers.insert(0, "#".into());
}
@ -323,16 +324,19 @@ fn convert_to_table(
return Err(error.clone());
}
// String1 = datatype, String2 = value as string
let mut row: Vec<(String, String)> =
vec![("string".to_string(), (row_num + row_offset).to_string())];
let mut row: Vec<(String, String)> = vec![];
if !disable_index {
row = vec![("string".to_string(), (row_num + row_offset).to_string())];
}
if headers.is_empty() {
row.push((
item.get_type().to_string(),
item.into_abbreviated_string(config),
))
));
} else {
for header in headers.iter().skip(1) {
let skip_num = if !disable_index { 1 } else { 0 };
for header in headers.iter().skip(skip_num) {
let result = match item {
Value::Record { .. } => {
item.clone().follow_cell_path(&[PathMember::String {
@ -373,7 +377,7 @@ fn convert_to_table(
x.into_iter()
.enumerate()
.map(|(col, y)| {
if col == 0 {
if col == 0 && !disable_index {
StyledString {
contents: y.1,
style: TextStyle {

View file

@ -47,6 +47,7 @@ pub struct Config {
pub menus: Vec<ParsedMenu>,
pub rm_always_trash: bool,
pub shell_integration: bool,
pub disable_table_indexes: bool,
}
impl Default for Config {
@ -73,6 +74,7 @@ impl Default for Config {
menus: Vec::new(),
rm_always_trash: false,
shell_integration: false,
disable_table_indexes: false,
}
}
}
@ -254,7 +256,13 @@ impl Value {
eprintln!("$config.shell_integration is not a bool")
}
}
"disable_table_indexes" => {
if let Ok(b) = value.as_bool() {
config.disable_table_indexes = b;
} else {
eprintln!("$config.disable_table_indexes is not a bool")
}
}
x => {
eprintln!("$config.{} is an unknown config setting", x)
}

View file

@ -196,6 +196,7 @@ let-env config = {
max_history_size: 10000 # Session has to be reloaded for this to take effect
sync_history_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file
shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue
disable_table_indexes: false # set to true to remove the index column from tables
menus: [
# Configuration for default nushell menus
# Note the lack of souce parameter