mirror of
https://github.com/nushell/nushell.git
synced 2025-08-14 02:28:35 +02:00
Add pretty errors to commands
This commit is contained in:
@ -55,36 +55,3 @@ impl RenderView for EntriesView {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EntriesListView {
|
||||
values: VecDeque<Value>,
|
||||
}
|
||||
|
||||
impl EntriesListView {
|
||||
crate async fn from_stream(values: InputStream) -> EntriesListView {
|
||||
EntriesListView {
|
||||
values: values.collect().await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderView for EntriesListView {
|
||||
fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> {
|
||||
if self.values.len() == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let last = self.values.len() - 1;
|
||||
|
||||
for (i, item) in self.values.iter().enumerate() {
|
||||
let view = EntriesView::from_value(item);
|
||||
view.render_view(host)?;
|
||||
|
||||
if i != last {
|
||||
host.stdout("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::format::{EntriesView, ListView, RenderView, TableView, TreeView};
|
||||
use crate::format::{EntriesView, RenderView, TableView};
|
||||
use crate::object::Value;
|
||||
use crate::prelude::*;
|
||||
use derive_new::new;
|
||||
|
@ -21,7 +21,9 @@ pub struct TreeView {
|
||||
impl TreeView {
|
||||
fn from_value_helper(value: &Value, mut builder: &mut TreeBuilder) {
|
||||
match value {
|
||||
Value::Primitive(p) => builder = builder.add_empty_child(p.format(None)),
|
||||
Value::Primitive(p) => {
|
||||
let _ = builder.add_empty_child(p.format(None));
|
||||
}
|
||||
Value::Object(o) => {
|
||||
for (k, v) in o.entries.iter() {
|
||||
builder = builder.begin_child(k.name.display().to_string());
|
||||
|
Reference in New Issue
Block a user