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

Display human readable sizes in panels #3165

Open
mc-butler opened this issue Feb 3, 2014 · 5 comments
Open

Display human readable sizes in panels #3165

mc-butler opened this issue Feb 3, 2014 · 5 comments
Labels
area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress

Comments

@mc-butler
Copy link

Important

This issue was migrated from Trac:

Origin https://midnight-commander.org/ticket/3165
Reporter wentasah (michal.sojka@….cz)
Mentions gotar@….pl

When midnight commander displays the size of a file, it tries to
display as much digits as fits into the size column (7 characters
wide). The result is that for a 3 MB file it shows, for example, 3010050.
In many cases, it is not important to know the exact number
of bytes in a file, but only an approximate size (3 MB). Short numbers
are more "human friendly".

This patch adds a configuration option that enables displaying such
human readable sizes in panels. The "human readable" means that at
most three digits are displayed for each file size. This is
accomplished by modifying function size_trunc_len(). Since the comment
of this function says that floating point should be avoided by any
means, the implementation is not as trivial as it could be. It
displays floating point numbers by displaying integer and fractional
parts separately as integers.

The effect of this patch is shown in the following table. "si" and
"hr" denote the values use_si and human_readable parameters of the
size_trunc_len() function. The table shows the results of the function
for different sizes.

                 CURRENT        THIS PATCH
      size |  !si!hr   si!hr  !si hr   si hr
-----------|--------------------------------
       950 |     950     950     950     950
      1001 |    1001    1001   0.97K   1.00k
      1005 |    1005    1005   0.98K   1.01k
      1023 |    1023    1023   0.99K   1.02k
      1024 |    1024    1024   0.99K   1.02k
      9849 |    9849    9849   9.61K   9.85k
     12050 |   12050   12050   11.8K   12.1k
     99940 |   99940   99940   97.5K   99.9k
    100000 |  100000  100000   97.6K    100k
    102399 |  102399  102399    100K    102k
    102400 |  102400  102400    100K    102k
    210050 |  210050  210050    205K    210k
   3010050 | 3010050 3010050   2.87M   3.01m
  43010050 |  42002K  43010k   41.0M   43.0m
1072693248 |   1023M   1073m   0.99G   1.07g

Currently, the decimal separator (".") is hardcoded and independent of
user's locale.

If anyone wants to test the patch, the table was created with the code
below.

void print(uintmax_t size)
{
	char buffer[50];
	int units = 0;
	gboolean use_si = TRUE;
	gboolean human_readable = TRUE;
	int len = 7;

	printf("%10ld", size);
	size_trunc_len (buffer, len, size, units, !use_si, !human_readable);
	printf("%8s", buffer);
	size_trunc_len (buffer, len, size, units,  use_si, !human_readable);
	printf("%8s", buffer);
	size_trunc_len (buffer, len, size, units, !use_si,  human_readable);
	printf("%8s", buffer);
	size_trunc_len (buffer, len, size, units,  use_si,  human_readable);
	printf("%8s", buffer);
	printf("\n");
}

int main(int argc, char *argv[])
{
	print(950);
	print(1001);
	// ...
}

Note

Original attachments:

@mc-butler
Copy link
Author

Changed by wentasah (michal.sojka@….cz) on Feb 3, 2014 at 0:43 UTC

Patch

@mc-butler
Copy link
Author

Changed by gotar (gotar@….pl) on Apr 4, 2014 at 9:08 UTC (comment 1)

  • Cc set to gotar@….pl

As you've noticed there are cases that require byte-level count, but it's barely readable indeed, so I've got another idea - dimming non-significant digits.
By 'non-significant' I mean every trailing group of 3 digits, so that only 1-3 first digits are not dimmed.

@mc-butler
Copy link
Author

Changed by wentasah (michal.sojka@….cz) on Apr 4, 2014 at 18:39 UTC (comment 2)

Then you will have to train your brain to do the conversion of a unit + the number of dimmed digits to another unit. Dimming makes the conversion a bit easier, but it will be you doing it instead of the computer. The aim of my patch is to offload my brain :)

BTW, where are byte-level counts required?

@bgravato
Copy link

bgravato commented Mar 2, 2025

I'd love to see this feature in mc!

I've been using mc for decades and the one thing that really annoys me is the inability to display sizes in human readable format!

Setting size:4 is a common workaround, but not quite the same thing.

@zyv
Copy link
Member

zyv commented Mar 2, 2025

I've added this issue to the cluster of related issues. Maybe someone will come along to rebase, clean up and write tests for this patch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues not related to a specific subsystem prio: medium Has the potential to affect progress
Development

No branches or pull requests

3 participants