mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
Merge pull request #908 from jonathandturner/fix_907
Fix 907 and improve substring
This commit is contained in:
commit
05ff102e09
2 changed files with 73 additions and 24 deletions
|
@ -23,11 +23,20 @@ enum TableMode {
|
||||||
|
|
||||||
impl TableView {
|
impl TableView {
|
||||||
fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
||||||
let mut ret = vec![];
|
let mut ret: Vec<String> = vec![];
|
||||||
|
let value_column = "<value>".to_string();
|
||||||
for value in values {
|
for value in values {
|
||||||
for desc in value.data_descriptors() {
|
let descs = value.data_descriptors();
|
||||||
if !ret.contains(&desc) {
|
|
||||||
ret.push(desc);
|
if descs.len() == 0 {
|
||||||
|
if !ret.contains(&value_column) {
|
||||||
|
ret.push("<value>".to_string());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for desc in value.data_descriptors() {
|
||||||
|
if !ret.contains(&desc) {
|
||||||
|
ret.push(desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,23 +57,59 @@ impl TableView {
|
||||||
let mut entries = vec![];
|
let mut entries = vec![];
|
||||||
|
|
||||||
for (idx, value) in values.iter().enumerate() {
|
for (idx, value) in values.iter().enumerate() {
|
||||||
let mut row: Vec<(String, &'static str)> = match value {
|
// let mut row: Vec<(String, &'static str)> = match value {
|
||||||
Tagged {
|
// Tagged {
|
||||||
item: Value::Row(..),
|
// item: Value::Row(..),
|
||||||
..
|
// ..
|
||||||
} => headers
|
// } => headers
|
||||||
.iter()
|
// .iter()
|
||||||
.enumerate()
|
// .enumerate()
|
||||||
.map(|(i, d)| {
|
// .map(|(i, d)| {
|
||||||
let data = value.get_data(d);
|
// let data = value.get_data(d);
|
||||||
return (
|
// return (
|
||||||
data.borrow().format_leaf(Some(&headers[i])),
|
// data.borrow().format_leaf(Some(&headers[i])),
|
||||||
data.borrow().style_leaf(),
|
// data.borrow().style_leaf(),
|
||||||
);
|
// );
|
||||||
})
|
// })
|
||||||
.collect(),
|
// .collect(),
|
||||||
x => vec![(x.format_leaf(None), x.style_leaf())],
|
// x => vec![(x.format_leaf(None), x.style_leaf())],
|
||||||
};
|
// };
|
||||||
|
|
||||||
|
let mut row: Vec<(String, &'static str)> = headers
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(i, d)| {
|
||||||
|
if d == "<value>" {
|
||||||
|
match value {
|
||||||
|
Tagged {
|
||||||
|
item: Value::Row(..),
|
||||||
|
..
|
||||||
|
} => (
|
||||||
|
Value::nothing().format_leaf(None),
|
||||||
|
Value::nothing().style_leaf(),
|
||||||
|
),
|
||||||
|
_ => (value.format_leaf(None), value.style_leaf()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match value {
|
||||||
|
Tagged {
|
||||||
|
item: Value::Row(..),
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
let data = value.get_data(d);
|
||||||
|
(
|
||||||
|
data.borrow().format_leaf(Some(&headers[i])),
|
||||||
|
data.borrow().style_leaf(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
_ => (
|
||||||
|
Value::nothing().format_leaf(None),
|
||||||
|
Value::nothing().style_leaf(),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
if values.len() > 1 {
|
if values.len() > 1 {
|
||||||
// Indices are black, bold, right-aligned:
|
// Indices are black, bold, right-aligned:
|
||||||
|
|
|
@ -41,9 +41,13 @@ impl Str {
|
||||||
if start > input.len() - 1 {
|
if start > input.len() - 1 {
|
||||||
Value::string("")
|
Value::string("")
|
||||||
} else {
|
} else {
|
||||||
// Index operator isn't perfect:
|
Value::string(
|
||||||
// https://users.rust-lang.org/t/how-to-get-a-substring-of-a-string/1351
|
&input
|
||||||
Value::string(&input[start..end])
|
.chars()
|
||||||
|
.skip(start)
|
||||||
|
.take(end - start)
|
||||||
|
.collect::<String>(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(Action::ToInteger) => match input.trim() {
|
Some(Action::ToInteger) => match input.trim() {
|
||||||
|
|
Loading…
Reference in a new issue