mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:36:08 +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 {
|
||||
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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Reference in New Issue
Block a user