mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-15 14:32:44 +00:00
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:
parent
add930db6b
commit
8ea79c6817
2 changed files with 12 additions and 8 deletions
|
@ -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)
|
- 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)
|
- Avoid using Clap's deprecated structs and functions [sudame](https://github.com/sudame)
|
||||||
- Icon theme with overrides from config [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
|
## [0.23.1] - 2022-09-13
|
||||||
|
|
||||||
|
|
|
@ -86,12 +86,15 @@ impl Size {
|
||||||
ColoredString::new(Colors::default_style(), res)
|
ColoredString::new(Colors::default_style(), res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint(&self, colors: &Colors, flags: &Flags, content: String) -> ColoredString {
|
fn paint(&self, colors: &Colors, content: String) -> ColoredString {
|
||||||
let unit = self.get_unit(flags);
|
let bytes = self.get_bytes();
|
||||||
let elem = match unit {
|
|
||||||
Unit::Byte | Unit::Kilo => &Elem::FileSmall,
|
let elem = if bytes >= GB {
|
||||||
Unit::Mega => &Elem::FileMedium,
|
&Elem::FileLarge
|
||||||
_ => &Elem::FileLarge,
|
} else if bytes >= MB {
|
||||||
|
&Elem::FileMedium
|
||||||
|
} else {
|
||||||
|
&Elem::FileSmall
|
||||||
};
|
};
|
||||||
|
|
||||||
colors.colorize(content, elem)
|
colors.colorize(content, elem)
|
||||||
|
@ -100,7 +103,7 @@ impl Size {
|
||||||
pub fn render_value(&self, colors: &Colors, flags: &Flags) -> ColoredString {
|
pub fn render_value(&self, colors: &Colors, flags: &Flags) -> ColoredString {
|
||||||
let content = self.value_string(flags);
|
let content = self.value_string(flags);
|
||||||
|
|
||||||
self.paint(colors, flags, content)
|
self.paint(colors, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn value_string(&self, flags: &Flags) -> String {
|
pub fn value_string(&self, flags: &Flags) -> String {
|
||||||
|
@ -118,7 +121,7 @@ impl Size {
|
||||||
pub fn render_unit(&self, colors: &Colors, flags: &Flags) -> ColoredString {
|
pub fn render_unit(&self, colors: &Colors, flags: &Flags) -> ColoredString {
|
||||||
let content = self.unit_string(flags);
|
let content = self.unit_string(flags);
|
||||||
|
|
||||||
self.paint(colors, flags, content)
|
self.paint(colors, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unit_string(&self, flags: &Flags) -> String {
|
pub fn unit_string(&self, flags: &Flags) -> String {
|
||||||
|
|
Loading…
Reference in a new issue