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 width format #58

Open
gaborcsardi opened this issue May 28, 2020 · 6 comments
Open

Fixed width format #58

gaborcsardi opened this issue May 28, 2020 · 6 comments

Comments

@gaborcsardi
Copy link

For progress bars, it would be nice to have an output format that is always the same width. E.g. a possible six character wide format:

            1 -> 0.0 kB
           10 -> 0.0 kB
          100 -> 0.1 kB
         1000 -> 1.0 kB
        10000 ->  10 kB
       100000 -> 100 kB
      1000000 -> 1.0 MB
     10000000 ->  10 MB
    100000000 -> 100 MB
   1000000000 -> 1.0 GB
  10000000000 ->  10 GB
 100000000000 -> 100 GB
1000000000000 -> 1.0 TB
@vladshcherbin
Copy link

@gaborcsardi maybe padStart can help you 🤔

@gaborcsardi
Copy link
Author

Yeah, then I might just write another package, because it is not just a padStart() call, e.g. pretty-bytes returns 1 B for 1 byte, and ideally I would line up both the units and the numbers. This is why I was suggesting to avoid B in the example above.

@vladshcherbin
Copy link

@gaborcsardi oh, I see, this wasn't obvious from the example above :)

@vladshcherbin
Copy link

@gaborcsardi for your case, another option is to use filesize instead, you can set symbols there. A simple change of B to B and padStart should make your example possible.

I switched to it because I need precision #57 and it kinda works fine.

@Richienb
Copy link

Richienb commented Jan 9, 2021

@sindresorhus How do you want the fixed width to be achieved?

Spaces only make sense for terminals or when using fixed-width fonts since they would sometimes otherwise be too small.

@sindresorhus
Copy link
Owner

Maybe instead we could just make add a rightAlign option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants