Ticket #3165 (new enhancement)

Opened 10 years ago

Last modified 10 years ago

Display human readable sizes in panels

Reported by: wentasah Owned by:
Priority: major Milestone: Future Releases
Component: mc-core Version: master
Keywords: Cc: gotar@…
Blocked By: Blocking:
Branch state: no branch Votes for changeset:

Description

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);
	// ...
}

Attachments

0001-Display-human-readable-sizes-in-panels.patch (14.3 KB) - added by wentasah 10 years ago.
Patch

Change History

Changed 10 years ago by wentasah

Patch

comment:1 Changed 10 years ago by gotar

  • Cc gotar@… added

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.

comment:2 Changed 10 years ago by wentasah

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?

Note: See TracTickets for help on using tickets.