mirror of
https://github.com/nushell/nushell
synced 2025-01-15 14:44:14 +00:00
Add value abbreviations (#407)
This commit is contained in:
parent
687fefd791
commit
19766556f3
2 changed files with 31 additions and 3 deletions
|
@ -164,7 +164,7 @@ impl Command for Table {
|
||||||
style: TextStyle::default_field(),
|
style: TextStyle::default_field(),
|
||||||
},
|
},
|
||||||
StyledString {
|
StyledString {
|
||||||
contents: v.into_string(", ", &config),
|
contents: v.into_abbreviated_string(&config),
|
||||||
style: TextStyle::default(),
|
style: TextStyle::default(),
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
@ -225,7 +225,7 @@ fn convert_to_table(
|
||||||
|
|
||||||
if headers.is_empty() {
|
if headers.is_empty() {
|
||||||
// if header row is empty, this is probably a list so format it that way
|
// if header row is empty, this is probably a list so format it that way
|
||||||
row.push(("list".to_string(), item.into_string(", ", config)))
|
row.push(("list".to_string(), item.into_abbreviated_string(config)))
|
||||||
} else {
|
} else {
|
||||||
for header in headers.iter().skip(1) {
|
for header in headers.iter().skip(1) {
|
||||||
let result = match item {
|
let result = match item {
|
||||||
|
@ -241,7 +241,7 @@ fn convert_to_table(
|
||||||
match result {
|
match result {
|
||||||
Ok(value) => row.push((
|
Ok(value) => row.push((
|
||||||
(&value.get_type()).to_string(),
|
(&value.get_type()).to_string(),
|
||||||
value.into_string(", ", config),
|
value.into_abbreviated_string(config),
|
||||||
)),
|
)),
|
||||||
Err(_) => row.push(("empty".to_string(), String::new())),
|
Err(_) => row.push(("empty".to_string(), String::new())),
|
||||||
}
|
}
|
||||||
|
|
|
@ -328,6 +328,34 @@ impl Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert Value into string. Note that Streams will be consumed.
|
||||||
|
pub fn into_abbreviated_string(self, config: &Config) -> String {
|
||||||
|
match self {
|
||||||
|
Value::Bool { val, .. } => val.to_string(),
|
||||||
|
Value::Int { val, .. } => val.to_string(),
|
||||||
|
Value::Float { val, .. } => val.to_string(),
|
||||||
|
Value::Filesize { val, .. } => format_filesize(val, config),
|
||||||
|
Value::Duration { val, .. } => format_duration(val),
|
||||||
|
Value::Date { val, .. } => HumanTime::from(val).to_string(),
|
||||||
|
Value::Range { val, .. } => {
|
||||||
|
format!(
|
||||||
|
"{}..{}",
|
||||||
|
val.from.into_string(", ", config),
|
||||||
|
val.to.into_string(", ", config)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Value::String { val, .. } => val,
|
||||||
|
Value::List { vals: val, .. } => format!("[list {} items]", val.len()),
|
||||||
|
Value::Record { cols, .. } => format!("{{record {} fields}}", cols.len()),
|
||||||
|
Value::Block { val, .. } => format!("<Block {}>", val),
|
||||||
|
Value::Nothing { .. } => String::new(),
|
||||||
|
Value::Error { error } => format!("{:?}", error),
|
||||||
|
Value::Binary { val, .. } => format!("{:?}", val),
|
||||||
|
Value::CellPath { val, .. } => val.into_string(),
|
||||||
|
Value::CustomValue { val, .. } => val.value_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert Value into a debug string
|
/// Convert Value into a debug string
|
||||||
pub fn debug_value(self) -> String {
|
pub fn debug_value(self) -> String {
|
||||||
format!("{:#?}", self)
|
format!("{:#?}", self)
|
||||||
|
|
Loading…
Reference in a new issue