mirror of
https://github.com/nushell/nushell
synced 2025-01-14 22:24:54 +00:00
Approach fix differently
This commit is contained in:
parent
f589d3c795
commit
cd30fac050
2 changed files with 78 additions and 24 deletions
|
@ -10,6 +10,7 @@ pub struct Get;
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct GetArgs {
|
pub struct GetArgs {
|
||||||
member: ColumnPath,
|
member: ColumnPath,
|
||||||
|
rest: Vec<ColumnPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WholeStreamCommand for Get {
|
impl WholeStreamCommand for Get {
|
||||||
|
@ -117,10 +118,13 @@ pub fn get_column_path(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get(
|
pub fn get(
|
||||||
GetArgs { member }: GetArgs,
|
GetArgs {
|
||||||
|
member,
|
||||||
|
rest: fields,
|
||||||
|
}: GetArgs,
|
||||||
RunnableContext { input, .. }: RunnableContext,
|
RunnableContext { input, .. }: RunnableContext,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
trace!("get {:?}", member);
|
trace!("get {:?} {:?}", member, fields);
|
||||||
|
|
||||||
let stream = input
|
let stream = input
|
||||||
.values
|
.values
|
||||||
|
@ -129,7 +133,12 @@ pub fn get(
|
||||||
|
|
||||||
let member = vec![member.clone()];
|
let member = vec![member.clone()];
|
||||||
|
|
||||||
for path in member {
|
let column_paths = vec![&member, &fields]
|
||||||
|
.into_iter()
|
||||||
|
.flatten()
|
||||||
|
.collect::<Vec<&ColumnPath>>();
|
||||||
|
|
||||||
|
for path in column_paths {
|
||||||
let res = get_column_path(&path, &item);
|
let res = get_column_path(&path, &item);
|
||||||
|
|
||||||
match res {
|
match res {
|
||||||
|
|
|
@ -23,14 +23,23 @@ 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 {
|
||||||
|
let descs = value.data_descriptors();
|
||||||
|
|
||||||
|
if descs.len() == 0 {
|
||||||
|
if !ret.contains(&value_column) {
|
||||||
|
ret.push("<value>".to_string());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
for desc in value.data_descriptors() {
|
for desc in value.data_descriptors() {
|
||||||
if !ret.contains(&desc) {
|
if !ret.contains(&desc) {
|
||||||
ret.push(desc);
|
ret.push(desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()
|
||||||
|
// .enumerate()
|
||||||
|
// .map(|(i, d)| {
|
||||||
|
// let data = value.get_data(d);
|
||||||
|
// return (
|
||||||
|
// data.borrow().format_leaf(Some(&headers[i])),
|
||||||
|
// data.borrow().style_leaf(),
|
||||||
|
// );
|
||||||
|
// })
|
||||||
|
// .collect(),
|
||||||
|
// x => vec![(x.format_leaf(None), x.style_leaf())],
|
||||||
|
// };
|
||||||
|
|
||||||
|
let mut row: Vec<(String, &'static str)> = headers
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, d)| {
|
.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);
|
let data = value.get_data(d);
|
||||||
return (
|
(
|
||||||
data.borrow().format_leaf(Some(&headers[i])),
|
data.borrow().format_leaf(Some(&headers[i])),
|
||||||
data.borrow().style_leaf(),
|
data.borrow().style_leaf(),
|
||||||
);
|
)
|
||||||
|
}
|
||||||
|
_ => (
|
||||||
|
Value::nothing().format_leaf(None),
|
||||||
|
Value::nothing().style_leaf(),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect();
|
||||||
x => vec![(x.format_leaf(None), x.style_leaf())],
|
|
||||||
};
|
|
||||||
|
|
||||||
if values.len() > 1 {
|
if values.len() > 1 {
|
||||||
// Indices are black, bold, right-aligned:
|
// Indices are black, bold, right-aligned:
|
||||||
|
|
Loading…
Reference in a new issue