Fixed file size colorizing with --size=bytes argument (#856)

<!--- PR Description --->

Fixed incorrect colorizing with `--size=bytes` described in issue #841 

---
#### TODO

- [x] Use `cargo fmt`
- [x] Add changelog entry

---------

Co-authored-by: Bells307 <sdikansky96@gmail.com>
This commit is contained in:
bells307 2023-06-21 21:20:05 +03:00 committed by GitHub
parent add930db6b
commit 8ea79c6817
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 8 deletions

View file

@ -28,6 +28,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

View file

@ -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 {