add config "filesize_metric = true" for default formatting of filesize (#3045)

This commit is contained in:
Saeed Rasooli 2021-02-11 12:22:34 +03:30 committed by GitHub
parent aa564f5072
commit 041086d22a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 9 deletions

View file

@ -53,6 +53,19 @@ pub struct FormatInlineShape {
column: Option<Column>,
}
pub fn get_config_filesize_metric() -> bool {
let res = crate::config::config(Tag::unknown());
if res.is_err() {
return true;
}
let value = res
.unwrap_or_default()
.get("filesize_metric")
.map(|s| s.value.is_true())
.unwrap_or(true);
value
}
impl InlineShape {
pub fn from_primitive(primitive: &Primitive) -> InlineShape {
match primitive {
@ -165,16 +178,16 @@ impl InlineShape {
if let Some(value) = bytesize.to_u128() {
let byte = byte_unit::Byte::from_bytes(value);
let byte = if filesize_format.0 == byte_unit::ByteUnit::B && filesize_format.1 == "auto"
{
byte.get_appropriate_unit(false)
} else {
byte.get_adjusted_unit(filesize_format.0)
};
let adj_byte =
if filesize_format.0 == byte_unit::ByteUnit::B && filesize_format.1 == "auto" {
byte.get_appropriate_unit(!get_config_filesize_metric())
} else {
byte.get_adjusted_unit(filesize_format.0)
};
match byte.get_unit() {
match adj_byte.get_unit() {
byte_unit::ByteUnit::B => {
let locale_byte = byte.get_value() as u64;
let locale_byte = adj_byte.get_value() as u64;
let locale_byte_string = locale_byte.to_formatted_string(&Locale::en);
if filesize_format.1 == "auto" {
let doc = (DbgDocBldr::primitive(locale_byte_string)
@ -188,7 +201,7 @@ impl InlineShape {
}
}
_ => {
let doc = DbgDocBldr::primitive(byte.format(1));
let doc = DbgDocBldr::primitive(adj_byte.format(1));
(doc.clone(), InlineShape::render_doc(&doc))
}
}

View file

@ -1,4 +1,5 @@
filesize_format = "B" # can be b, kb, kib, mb, mib, gb, gib, etc
filesize_metric = true # true => (KB, MB, GB), false => (KiB, MiB, GiB)
skip_welcome_message = true
disable_table_indexes = false
nonzero_exit_errors = true