diff --git a/crates/nu-cli/src/data/base.rs b/crates/nu-cli/src/data/base.rs index c18d36b9a2..b00218ccb6 100644 --- a/crates/nu-cli/src/data/base.rs +++ b/crates/nu-cli/src/data/base.rs @@ -176,11 +176,15 @@ fn coerce_compare_primitive( (Decimal(left), Bytes(right)) => { CompareValues::Decimals(left.clone(), BigDecimal::from(*right)) } + (Bytes(left), Bytes(right)) => { + CompareValues::Ints(BigInt::from(*left), BigInt::from(*right)) + } (Bytes(left), Int(right)) => CompareValues::Ints(BigInt::from(*left), right.clone()), (Bytes(left), Decimal(right)) => { CompareValues::Decimals(BigDecimal::from(*left), right.clone()) } (Bytes(left), Nothing) => CompareValues::Ints(BigInt::from(*left), BigInt::from(0)), + (Nothing, Nothing) => CompareValues::Ints(BigInt::from(0), BigInt::from(0)), (Nothing, Bytes(right)) => CompareValues::Ints(BigInt::from(0), BigInt::from(*right)), (Int(left), Nothing) => CompareValues::Ints(left.clone(), BigInt::from(0)), (Nothing, Int(right)) => CompareValues::Ints(BigInt::from(0), right.clone()), diff --git a/crates/nu-cli/src/env/environment.rs b/crates/nu-cli/src/env/environment.rs index 74d4843f04..9b586eded2 100644 --- a/crates/nu-cli/src/env/environment.rs +++ b/crates/nu-cli/src/env/environment.rs @@ -275,7 +275,7 @@ mod tests { assert_eq!( actual.path(), Some( - UntaggedValue::table(&vec![ + UntaggedValue::table(&[ UntaggedValue::string("/Users/andresrobalino/.volta/bin") .into_untagged_value(), UntaggedValue::string("/users/mosqueteros/bin").into_untagged_value(), diff --git a/crates/nu-cli/src/format.rs b/crates/nu-cli/src/format.rs index bc464a0de6..6d7710a146 100644 --- a/crates/nu-cli/src/format.rs +++ b/crates/nu-cli/src/format.rs @@ -1,12 +1,8 @@ -pub(crate) mod entries; -pub(crate) mod generic; -pub(crate) mod list; pub(crate) mod table; use crate::prelude::*; use nu_errors::ShellError; -pub(crate) use entries::EntriesView; pub(crate) use table::TableView; pub(crate) trait RenderView { diff --git a/crates/nu-cli/src/format/entries.rs b/crates/nu-cli/src/format/entries.rs deleted file mode 100644 index 604256fc4d..0000000000 --- a/crates/nu-cli/src/format/entries.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::data::value; -use crate::format::RenderView; -use crate::prelude::*; -use nu_errors::ShellError; -use nu_protocol::Value; - -use derive_new::new; - -// An entries list is printed like this: -// -// name : ... -// name2 : ... -// another_name : ... -#[derive(new)] -pub struct EntriesView { - entries: Vec<(String, String)>, -} - -impl EntriesView { - pub(crate) fn from_value(value: &Value) -> EntriesView { - let descs = value.data_descriptors(); - let mut entries = vec![]; - - for desc in descs { - let value = value.get_data(&desc); - - let formatted_value = value::format_leaf(value.borrow()).plain_string(75); - - entries.push((desc.clone(), formatted_value)) - } - - EntriesView::new(entries) - } -} - -impl RenderView for EntriesView { - fn render_view(&self, _host: &mut dyn Host) -> Result<(), ShellError> { - if self.entries.is_empty() { - return Ok(()); - } - - if let Some(max_name_size) = self.entries.iter().map(|(n, _)| n.len()).max() { - for (name, value) in &self.entries { - outln!("{:width$} : {}", name, value, width = max_name_size) - } - } - - Ok(()) - } -} diff --git a/crates/nu-cli/src/format/generic.rs b/crates/nu-cli/src/format/generic.rs deleted file mode 100644 index 336b76e0e4..0000000000 --- a/crates/nu-cli/src/format/generic.rs +++ /dev/null @@ -1,48 +0,0 @@ -use crate::data::value::format_leaf; -use crate::format::{EntriesView, RenderView, TableView}; -use crate::prelude::*; -use derive_new::new; -use nu_errors::ShellError; -use nu_protocol::{format_primitive, UntaggedValue, Value}; - -// A list is printed one line at a time with an optional separator between groups -#[derive(new)] -pub struct GenericView<'value> { - value: &'value Value, -} - -impl RenderView for GenericView<'_> { - fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> { - let tag = &self.value.tag; - match &self.value.value { - UntaggedValue::Primitive(p) => { - host.stdout(&format_primitive(p, None)); - Ok(()) - } - UntaggedValue::Table(l) => { - let view = TableView::from_list(l, 0); - - if let Some(view) = view { - view.render_view(host)?; - } - - Ok(()) - } - - o @ UntaggedValue::Row(_) => { - let view = EntriesView::from_value(&o.clone().into_value(tag)); - view.render_view(host)?; - Ok(()) - } - - b @ UntaggedValue::Block(_) => { - let printed = format_leaf(b).plain_string(host.width()); - let view = EntriesView::from_value(&UntaggedValue::string(printed).into_value(tag)); - view.render_view(host)?; - Ok(()) - } - - UntaggedValue::Error(e) => Err(e.clone()), - } - } -} diff --git a/crates/nu-cli/src/format/list.rs b/crates/nu-cli/src/format/list.rs deleted file mode 100644 index 073940adff..0000000000 --- a/crates/nu-cli/src/format/list.rs +++ /dev/null @@ -1,23 +0,0 @@ -use crate::format::RenderView; -use crate::prelude::*; -use derive_new::new; -use nu_errors::ShellError; - -// A list is printed one line at a time with an optional separator between groups - -#[derive(new)] -pub struct ListView { - list: Vec>, - sep: String, -} - -impl RenderView for ListView { - fn render_view(&self, host: &mut dyn Host) -> Result<(), ShellError> { - for output in &self.list { - let string: String = output.iter().map(|l| format!("{}\n", l)).collect(); - host.stdout(&format!("{}{}", string, self.sep)); - } - - Ok(()) - } -} diff --git a/crates/nu-cli/src/format/table.rs b/crates/nu-cli/src/format/table.rs index 1b13974cac..795e8074b7 100644 --- a/crates/nu-cli/src/format/table.rs +++ b/crates/nu-cli/src/format/table.rs @@ -8,7 +8,6 @@ use textwrap::fill; use prettytable::format::{Alignment, FormatBuilder, LinePosition, LineSeparator}; use prettytable::{color, Attr, Cell, Row, Table}; -use term::color::Color; type Entries = Vec>; @@ -389,7 +388,7 @@ impl RenderView for TableView { } } -fn str_to_color(s: String) -> Option { +fn str_to_color(s: String) -> Option { match s.as_str() { "g" | "green" => Some(color::GREEN), "r" | "red" => Some(color::RED), diff --git a/crates/nu_plugin_str/src/nu/tests.rs b/crates/nu_plugin_str/src/nu/tests.rs index 205a2b30fe..e69c7990ee 100644 --- a/crates/nu_plugin_str/src/nu/tests.rs +++ b/crates/nu_plugin_str/src/nu/tests.rs @@ -34,7 +34,7 @@ mod integration { .unwrap(); match r { Primitive::Date(_) => (), - _ => assert!(false, "failed to convert string to date"), + _ => panic!("failed to convert string to date"), } } }