diff --git a/CHANGELOG.md b/CHANGELOG.md index de3a46f4d..81328e6c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Handle dereference (-L) with broken symlink from [r3dArch](https://github.com/r3dArch) - Avoid using Clap's deprecated structs and functions [sudame](https://github.com/sudame) - Icon theme with overrides from config [sudame](https://github.com/sudame) +- Incorrect colorizing with `--size=bytes` [bells307](https://github.com/bells307) ## [0.23.1] - 2022-09-13 diff --git a/src/meta/size.rs b/src/meta/size.rs index 9f39b993c..8b66c96e6 100644 --- a/src/meta/size.rs +++ b/src/meta/size.rs @@ -86,12 +86,15 @@ impl Size { ColoredString::new(Colors::default_style(), res) } - fn paint(&self, colors: &Colors, flags: &Flags, content: String) -> ColoredString { - let unit = self.get_unit(flags); - let elem = match unit { - Unit::Byte | Unit::Kilo => &Elem::FileSmall, - Unit::Mega => &Elem::FileMedium, - _ => &Elem::FileLarge, + fn paint(&self, colors: &Colors, content: String) -> ColoredString { + let bytes = self.get_bytes(); + + let elem = if bytes >= GB { + &Elem::FileLarge + } else if bytes >= MB { + &Elem::FileMedium + } else { + &Elem::FileSmall }; colors.colorize(content, elem) @@ -100,7 +103,7 @@ impl Size { pub fn render_value(&self, colors: &Colors, flags: &Flags) -> ColoredString { let content = self.value_string(flags); - self.paint(colors, flags, content) + self.paint(colors, content) } pub fn value_string(&self, flags: &Flags) -> String { @@ -118,7 +121,7 @@ impl Size { pub fn render_unit(&self, colors: &Colors, flags: &Flags) -> ColoredString { let content = self.unit_string(flags); - self.paint(colors, flags, content) + self.paint(colors, content) } pub fn unit_string(&self, flags: &Flags) -> String {