mirror of
https://github.com/nushell/nushell.git
synced 2024-11-25 01:43:47 +01:00
some minor improvements and removing dead code (#1563)
This commit is contained in:
parent
2c513d1883
commit
c86cf31aac
@ -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()),
|
||||
|
2
crates/nu-cli/src/env/environment.rs
vendored
2
crates/nu-cli/src/env/environment.rs
vendored
@ -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(),
|
||||
|
@ -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 {
|
||||
|
@ -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(())
|
||||
}
|
||||
}
|
@ -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()),
|
||||
}
|
||||
}
|
||||
}
|
@ -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<Vec<String>>,
|
||||
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(())
|
||||
}
|
||||
}
|
@ -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<Vec<(String, &'static str)>>;
|
||||
|
||||
@ -389,7 +388,7 @@ impl RenderView for TableView {
|
||||
}
|
||||
}
|
||||
|
||||
fn str_to_color(s: String) -> Option<Color> {
|
||||
fn str_to_color(s: String) -> Option<color::Color> {
|
||||
match s.as_str() {
|
||||
"g" | "green" => Some(color::GREEN),
|
||||
"r" | "red" => Some(color::RED),
|
||||
|
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user