Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
19 changes: 11 additions & 8 deletions src/meta/size.rs
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down