From bc6c884a143b6627f004a0d66e58da2e088a1bb9 Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Mon, 19 Oct 2020 12:52:11 -0500 Subject: [PATCH] added num-format to allow bytes to be formatted with commas. (#2681) --- Cargo.lock | 1 + crates/nu-data/Cargo.toml | 1 + crates/nu-data/src/base/shape.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4f006235a3..2674dc5cb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3012,6 +3012,7 @@ dependencies = [ "nu-test-support", "nu-value-ext", "num-bigint 0.3.0", + "num-format", "num-traits 0.2.12", "parking_lot 0.11.0", "query_interface", diff --git a/crates/nu-data/Cargo.toml b/crates/nu-data/Cargo.toml index 1cff143fe7..1f0f7a9bd6 100644 --- a/crates/nu-data/Cargo.toml +++ b/crates/nu-data/Cargo.toml @@ -23,6 +23,7 @@ indexmap = {version = "1.6.0", features = ["serde-1"]} log = "0.4.11" num-bigint = {version = "0.3.0", features = ["serde"]} num-traits = "0.2.12" +num-format = "0.4.0" parking_lot = "0.11.0" query_interface = "0.3.5" serde = {version = "1.0.115", features = ["derive"]} diff --git a/crates/nu-data/src/base/shape.rs b/crates/nu-data/src/base/shape.rs index 670547dcfb..ae3f7b06c2 100644 --- a/crates/nu-data/src/base/shape.rs +++ b/crates/nu-data/src/base/shape.rs @@ -6,6 +6,7 @@ use nu_protocol::RangeInclusion; use nu_protocol::{format_primitive, ColumnPath, Dictionary, Primitive, UntaggedValue, Value}; use nu_source::{b, DebugDocBuilder, PrettyDebug, Tag}; use num_bigint::BigInt; +use num_format::{Locale, ToFormattedString}; use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::fmt::Debug; @@ -192,8 +193,8 @@ impl PrettyDebug for FormatInlineShape { match byte.get_unit() { byte_unit::ByteUnit::B => { - (b::primitive(format!("{}", byte.get_value())) + b::space() + b::kind("B")) - .group() + let locale_byte = byte.get_value() as u64; + (b::primitive(locale_byte.to_formatted_string(&Locale::en))).group() } _ => b::primitive(byte.format(1)), }