diff --git a/crates/nu-command/src/strings/format/filesize.rs b/crates/nu-command/src/strings/format/filesize.rs index 991553b9d1..09ec4e3c91 100644 --- a/crates/nu-command/src/strings/format/filesize.rs +++ b/crates/nu-command/src/strings/format/filesize.rs @@ -127,14 +127,12 @@ fn parse_filesize_unit(format: Spanned) -> Result Value { let value_span = val.span(); match val { - Value::Filesize { val, .. } => Value::string( - FilesizeFormatter::new() - .unit(arg.unit) - .precision(None) - .format(*val) - .to_string(), - span, - ), + Value::Filesize { val, .. } => FilesizeFormatter::new() + .unit(arg.unit) + .precision(None) + .format(*val) + .to_string() + .into_value(span), Value::Error { .. } => val.clone(), _ => Value::error( ShellError::OnlySupportsThisInputType { diff --git a/crates/nu-protocol/src/config/filesize.rs b/crates/nu-protocol/src/config/filesize.rs index 514af52d22..863f9d8293 100644 --- a/crates/nu-protocol/src/config/filesize.rs +++ b/crates/nu-protocol/src/config/filesize.rs @@ -4,12 +4,7 @@ use nu_utils::get_system_locale; impl IntoValue for FilesizeUnitFormat { fn into_value(self, span: Span) -> Value { - match self { - FilesizeUnitFormat::Metric => "metric", - FilesizeUnitFormat::Binary => "binary", - FilesizeUnitFormat::Unit(unit) => unit.as_str(), - } - .into_value(span) + self.as_str().into_value(span) } } @@ -24,12 +19,11 @@ impl FilesizeConfig { FilesizeFormatter::new() .unit(self.unit) .precision(self.precision) + .locale(get_system_locale()) // TODO: cache this somewhere or pass in as argument } pub fn format(&self, filesize: Filesize) -> FormattedFilesize { - self.formatter() - .locale(get_system_locale()) // TODO: cache this somewhere or pass in as argument - .format(filesize) + self.formatter().format(filesize) } } diff --git a/crates/nu-protocol/src/value/filesize.rs b/crates/nu-protocol/src/value/filesize.rs index 28eb5e5630..781b9755e5 100644 --- a/crates/nu-protocol/src/value/filesize.rs +++ b/crates/nu-protocol/src/value/filesize.rs @@ -751,7 +751,7 @@ impl FilesizeFormatter { self } - /// Format a [`Filesize`] into [`FormattedFilesize`] which implements [`fmt::Display`]. + /// Format a [`Filesize`] into a [`FormattedFilesize`] which implements [`fmt::Display`]. /// /// # Examples /// ``` @@ -801,7 +801,6 @@ impl fmt::Display for FormattedFilesize { let Filesize(filesize) = filesize; let precision = f.precision().or(precision); - // Format an exact, possibly fractional, string representation of `filesize`. let bytes = unit.as_bytes() as i64; let whole = filesize / bytes; let fract = (filesize % bytes).unsigned_abs();