diff --git a/README.md b/README.md index fe1791b8c..1f9e2ebec 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,8 @@ These options are available when running with `--long` (`-l`): - **-b**, **--binary**: list file sizes with binary prefixes - **-B**, **--bytes**: list file sizes in bytes, without any prefixes -- **-g**, **--group**: list each file’s group +- **--hex**: list file sizes in hexadecimal (0x) +- **-g**, **--group**: list each file's group - **--smart-group**: only show group if it has a different name from owner - **-h**, **--header**: add a header row to each column - **-H**, **--links**: list each file’s number of hard links diff --git a/completions/fish/eza.fish b/completions/fish/eza.fish index e3488239f..3b336f4d4 100644 --- a/completions/fish/eza.fish +++ b/completions/fish/eza.fish @@ -89,6 +89,7 @@ complete -c eza -l no-symlinks -d "Do not show symbolic links" # Long view options complete -c eza -s b -l binary -d "List file sizes with binary prefixes" complete -c eza -s B -l bytes -d "List file sizes in bytes, without any prefixes" +complete -c eza -l hex -d "List file sizes in hexadecimal (0x)" complete -c eza -s g -l group -d "List each file's group" complete -c eza -s h -l header -d "Add a header row to each column" complete -c eza -s H -l links -d "List each file's number of hard links" diff --git a/completions/nush/eza.nu b/completions/nush/eza.nu index 3830fd9f1..c6568c088 100644 --- a/completions/nush/eza.nu +++ b/completions/nush/eza.nu @@ -36,6 +36,7 @@ export extern "eza" [ --no-symlinks # Do not show symbolic links --binary(-b) # List file sizes with binary prefixes --bytes(-B) # List file sizes in bytes, without any prefixes + --hex # List file sizes in hexadecimal (0x) --group(-g) # List each file's group --header(-h) # Add a header row to each column --links(-H) # List each file's number of hard links diff --git a/completions/pwsh/_eza.ps1 b/completions/pwsh/_eza.ps1 index e28d62c8b..71a749e07 100644 --- a/completions/pwsh/_eza.ps1 +++ b/completions/pwsh/_eza.ps1 @@ -86,7 +86,8 @@ Register-ArgumentCompleter -Native -CommandName 'eza' -ScriptBlock { # [CompletionResult]::new('-b' ,'binary' , [CompletionResultType]::ParameterName, 'list file sizes with binary prefixes') [CompletionResult]::new('--binary' ,'binary' , [CompletionResultType]::ParameterName, 'list file sizes with binary prefixes') # [CompletionResult]::new('-B' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes') - [CompletionResult]::new('--bytes' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes') + [CompletionResult]::new('--bytes' ,'bytes' , [CompletionResultType]::ParameterName, 'list file sizes in bytes, without any prefixes') + [CompletionResult]::new('--hex' ,'hex' , [CompletionResultType]::ParameterName, 'list file sizes in hexadecimal (0x)') # [CompletionResult]::new('-g' ,'group' , [CompletionResultType]::ParameterName, 'list each file''s group') [CompletionResult]::new('--smart-group' ,'smart-group' , [CompletionResultType]::ParameterName, 'only show group if it has a different name from owner') [CompletionResult]::new('--group' ,'group' , [CompletionResultType]::ParameterName, 'list each file''s group') diff --git a/completions/zsh/_eza b/completions/zsh/_eza index 9636fe254..dec45a194 100644 --- a/completions/zsh/_eza +++ b/completions/zsh/_eza @@ -45,6 +45,7 @@ __eza() { {-I,--ignore-glob}"[Ignore files that match these glob patterns]" \ {-b,--binary}"[List file sizes with binary prefixes]" \ {-B,--bytes}"[List file sizes in bytes, without any prefixes]" \ + --hex"[List file sizes in hexadecimal (0x)]" \ --changed"[Use the changed timestamp field]" \ {-g,--group}"[List each file's group]" \ {-h,--header}"[Add a header row to each column]" \ diff --git a/man/eza.1.md b/man/eza.1.md index 4daeac48b..0222a9f88 100644 --- a/man/eza.1.md +++ b/man/eza.1.md @@ -198,6 +198,9 @@ These options are available when running with `--long` (`-l`): `-B`, `--bytes` : List file sizes in bytes, without any prefixes. +`--hex` +: List file sizes in hexadecimal (0x). + `--changed` : Use the changed timestamp field. diff --git a/src/options/flags.rs b/src/options/flags.rs index 53eef54cb..e32b61f54 100644 --- a/src/options/flags.rs +++ b/src/options/flags.rs @@ -61,6 +61,7 @@ const SORTS: Values = &[ "name", "Name", "size", "extension", // display options pub static BINARY: Arg = Arg { short: Some(b'b'), long: "binary", takes_value: TakesValue::Forbidden }; pub static BYTES: Arg = Arg { short: Some(b'B'), long: "bytes", takes_value: TakesValue::Forbidden }; +pub static HEX: Arg = Arg { short: None, long: "hex", takes_value: TakesValue::Forbidden }; pub static GROUP: Arg = Arg { short: Some(b'g'), long: "group", takes_value: TakesValue::Forbidden }; pub static NUMERIC: Arg = Arg { short: Some(b'n'), long: "numeric", takes_value: TakesValue::Forbidden }; pub static HEADER: Arg = Arg { short: Some(b'h'), long: "header", takes_value: TakesValue::Forbidden }; @@ -108,7 +109,7 @@ pub static ALL_ARGS: Args = Args(&[ &ALL, &ALMOST_ALL, &TREAT_DIRS_AS_FILES, &LIST_DIRS, &LEVEL, &REVERSE, &SORT, &DIRS_FIRST, &DIRS_LAST, &IGNORE_GLOB, &GIT_IGNORE, &ONLY_DIRS, &ONLY_FILES, - &BINARY, &BYTES, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED, + &BINARY, &BYTES, &HEX, &GROUP, &NUMERIC, &HEADER, &ICONS, &INODE, &LINKS, &MODIFIED, &CHANGED, &BLOCKSIZE, &TOTAL_SIZE, &TIME, &ACCESSED, &CREATED, &TIME_STYLE, &HYPERLINK, &MOUNTS, &NO_PERMISSIONS, &NO_FILESIZE, &NO_USER, &NO_TIME, &SMART_GROUP, &NO_SYMLINKS, &SHOW_SYMLINKS, diff --git a/src/options/help.rs b/src/options/help.rs index 69070dbaf..9fb887268 100644 --- a/src/options/help.rs +++ b/src/options/help.rs @@ -64,6 +64,7 @@ static USAGE_PART2: &str = " \ LONG VIEW OPTIONS -b, --binary list file sizes with binary prefixes -B, --bytes list file sizes in bytes, without any prefixes + --hex list file sizes in hexadecimal (0x) -g, --group list each file's group --smart-group only show group if it has a different name from owner -h, --header add a header row to each column diff --git a/src/options/view.rs b/src/options/view.rs index 18aedaf8d..8df7a39fa 100644 --- a/src/options/view.rs +++ b/src/options/view.rs @@ -110,12 +110,13 @@ impl Mode { } fn strict_check_long_flags(matches: &MatchedFlags<'_>) -> Result<(), OptionsError> { - // If --long hasn’t been passed, then check if we need to warn the - // user about flags that won’t have any effect. + // If --long hasn't been passed, then check if we need to warn the + // user about flags that won't have any effect. if matches.is_strict() { for option in &[ &flags::BINARY, &flags::BYTES, + &flags::HEX, &flags::INODE, &flags::LINKS, &flags::HEADER, @@ -315,19 +316,22 @@ impl Columns { impl SizeFormat { /// Determine which file size to use in the file size column based on - /// the user’s options. + /// the user's options. /// /// The default mode is to use the decimal prefixes, as they are the - /// most commonly-understood, and don’t involve trying to parse large + /// most commonly-understood, and don't involve trying to parse large /// strings of digits in your head. Changing the format to anything else - /// involves the `--binary` or `--bytes` flags, and these conflict with + /// involves the `--binary`, `--bytes`, or `--hex` flags, and these conflict with /// each other. fn deduce(matches: &MatchedFlags<'_>) -> Result { - let flag = matches.has_where(|f| f.matches(&flags::BINARY) || f.matches(&flags::BYTES))?; + let flag = matches.has_where(|f| { + f.matches(&flags::BINARY) || f.matches(&flags::BYTES) || f.matches(&flags::HEX) + })?; Ok(match flag { Some(f) if f.matches(&flags::BINARY) => Self::BinaryBytes, Some(f) if f.matches(&flags::BYTES) => Self::JustBytes, + Some(f) if f.matches(&flags::HEX) => Self::HexBytes, _ => Self::DecimalBytes, }) } @@ -541,6 +545,7 @@ mod test { static TEST_ARGS: &[&Arg] = &[ &flags::BINARY, &flags::BYTES, + &flags::HEX, &flags::TIME_STYLE, &flags::TIME, &flags::MODIFIED, diff --git a/src/output/render/blocks.rs b/src/output/render/blocks.rs index 895566cd4..1a5d10113 100644 --- a/src/output/render/blocks.rs +++ b/src/output/render/blocks.rs @@ -39,6 +39,18 @@ impl f::Blocksize { // But format the number directly using the locale. let string = numerics.format_int(size); + return TextCell::paint(colours.blocksize(prefix), string); + } + SizeFormat::HexBytes => { + // Use the binary prefix to select a style. + let prefix = match NumberPrefix::binary(size as f64) { + NumberPrefix::Standalone(_) => None, + NumberPrefix::Prefixed(p, _) => Some(p), + }; + + // Format as hexadecimal with 0x prefix. + let string = format!("0x{size:x}"); + return TextCell::paint(colours.blocksize(prefix), string); } }; diff --git a/src/output/render/size.rs b/src/output/render/size.rs index 09a132ea0..788e9c941 100644 --- a/src/output/render/size.rs +++ b/src/output/render/size.rs @@ -46,6 +46,26 @@ impl f::Size { // But format the number directly using the locale. let string = numerics.format_int(size); + return if is_gradient_mode { + let csi = color_scale_info.unwrap(); + TextCell::paint( + csi.adjust_style(colours.size(prefix), size as f32, csi.size), + string, + ) + } else { + TextCell::paint(colours.size(prefix), string) + } + } + SizeFormat::HexBytes => { + // Use the binary prefix to select a style. + let prefix = match NumberPrefix::binary(size as f64) { + NumberPrefix::Standalone(_) => None, + NumberPrefix::Prefixed(p, _) => Some(p), + }; + + // Format as hexadecimal with 0x prefix. + let string = format!("0x{size:x}"); + return if is_gradient_mode { let csi = color_scale_info.unwrap(); TextCell::paint( diff --git a/src/output/table.rs b/src/output/table.rs index 3daa47257..5d1c0914d 100644 --- a/src/output/table.rs +++ b/src/output/table.rs @@ -241,17 +241,20 @@ impl Column { #[allow(clippy::enum_variant_names)] #[derive(PartialEq, Eq, Debug, Default, Copy, Clone)] pub enum SizeFormat { - /// Format the file size using **decimal** prefixes, such as “kilo”, - /// “mega”, or “giga”. + /// Format the file size using **decimal** prefixes, such as "kilo", + /// "mega", or "giga". #[default] DecimalBytes, - /// Format the file size using **binary** prefixes, such as “kibi”, - /// “mebi”, or “gibi”. + /// Format the file size using **binary** prefixes, such as "kibi", + /// "mebi", or "gibi". BinaryBytes, /// Do no formatting and just display the size as a number of bytes. JustBytes, + + /// Display the size as a hexadecimal number (0x prefix). + HexBytes, } /// Formatting options for user and group.