mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 14:37:59 +02:00
Cleanup and fixes
This commit is contained in:
@ -127,14 +127,12 @@ fn parse_filesize_unit(format: Spanned<String>) -> Result<FilesizeUnit, ShellErr
|
|||||||
fn format_value_impl(val: &Value, arg: &Arguments, span: Span) -> Value {
|
fn format_value_impl(val: &Value, arg: &Arguments, span: Span) -> Value {
|
||||||
let value_span = val.span();
|
let value_span = val.span();
|
||||||
match val {
|
match val {
|
||||||
Value::Filesize { val, .. } => Value::string(
|
Value::Filesize { val, .. } => FilesizeFormatter::new()
|
||||||
FilesizeFormatter::new()
|
.unit(arg.unit)
|
||||||
.unit(arg.unit)
|
.precision(None)
|
||||||
.precision(None)
|
.format(*val)
|
||||||
.format(*val)
|
.to_string()
|
||||||
.to_string(),
|
.into_value(span),
|
||||||
span,
|
|
||||||
),
|
|
||||||
Value::Error { .. } => val.clone(),
|
Value::Error { .. } => val.clone(),
|
||||||
_ => Value::error(
|
_ => Value::error(
|
||||||
ShellError::OnlySupportsThisInputType {
|
ShellError::OnlySupportsThisInputType {
|
||||||
|
@ -4,12 +4,7 @@ use nu_utils::get_system_locale;
|
|||||||
|
|
||||||
impl IntoValue for FilesizeUnitFormat {
|
impl IntoValue for FilesizeUnitFormat {
|
||||||
fn into_value(self, span: Span) -> Value {
|
fn into_value(self, span: Span) -> Value {
|
||||||
match self {
|
self.as_str().into_value(span)
|
||||||
FilesizeUnitFormat::Metric => "metric",
|
|
||||||
FilesizeUnitFormat::Binary => "binary",
|
|
||||||
FilesizeUnitFormat::Unit(unit) => unit.as_str(),
|
|
||||||
}
|
|
||||||
.into_value(span)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,12 +19,11 @@ impl FilesizeConfig {
|
|||||||
FilesizeFormatter::new()
|
FilesizeFormatter::new()
|
||||||
.unit(self.unit)
|
.unit(self.unit)
|
||||||
.precision(self.precision)
|
.precision(self.precision)
|
||||||
|
.locale(get_system_locale()) // TODO: cache this somewhere or pass in as argument
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(&self, filesize: Filesize) -> FormattedFilesize {
|
pub fn format(&self, filesize: Filesize) -> FormattedFilesize {
|
||||||
self.formatter()
|
self.formatter().format(filesize)
|
||||||
.locale(get_system_locale()) // TODO: cache this somewhere or pass in as argument
|
|
||||||
.format(filesize)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,7 +751,7 @@ impl FilesizeFormatter {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format a [`Filesize`] into [`FormattedFilesize`] which implements [`fmt::Display`].
|
/// Format a [`Filesize`] into a [`FormattedFilesize`] which implements [`fmt::Display`].
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
@ -801,7 +801,6 @@ impl fmt::Display for FormattedFilesize {
|
|||||||
let Filesize(filesize) = filesize;
|
let Filesize(filesize) = filesize;
|
||||||
let precision = f.precision().or(precision);
|
let precision = f.precision().or(precision);
|
||||||
|
|
||||||
// Format an exact, possibly fractional, string representation of `filesize`.
|
|
||||||
let bytes = unit.as_bytes() as i64;
|
let bytes = unit.as_bytes() as i64;
|
||||||
let whole = filesize / bytes;
|
let whole = filesize / bytes;
|
||||||
let fract = (filesize % bytes).unsigned_abs();
|
let fract = (filesize % bytes).unsigned_abs();
|
||||||
|
Reference in New Issue
Block a user