bytesize icon indicating copy to clipboard operation
bytesize copied to clipboard

sort -h friendly output mode

Open wookietreiber opened this issue 7 years ago • 8 comments

As of now an extremely ugly variant to get in #14. Works, though. Please review.

wookietreiber avatar Sep 05 '18 22:09 wookietreiber

@hyunsik The Travis failure is due to:

$ cargo fmt --all -- --write-mode=diff
Unrecognized option: 'write-mode'

wookietreiber avatar Sep 30 '18 07:09 wookietreiber

Hi @wookietreiber,

I'm sorry for a late response. I missed your issue and this PR from a lot of email deluge. I'll fix the travis issue and review your PR by tomorrow. Thank you for your contribution!

hyunsik avatar Sep 30 '18 19:09 hyunsik

I've also fixed the build error at https://github.com/hyunsik/bytesize/commit/9d8e13f05fe2fb2596a5534e86ef135af5bae6a3.

hyunsik avatar Oct 02 '18 04:10 hyunsik

Thanks for catching the println statements. Rebased.

wookietreiber avatar Oct 02 '18 15:10 wookietreiber

At the moment, I added a new function to_simple_string_as to ByteSize and a new argument to the to_string stand-alone function. Note that this can be done differently, e.g. adding the simple: bool argument to the to_string_as function on ByteSize and dropping the to_simple_string_as. Both of these variants, though, have implications regarding compatibility and would require a semver bump to the next major version.

It could also be done completely compatible by creating a new stand-alone to_string_simple function as well. But this wouldn't be as clean anymore.

I don't know which way you'd prefer. Please advise.

wookietreiber avatar Oct 02 '18 15:10 wookietreiber

Hi,

I'm sorry for a late response. The simple representation seems to lose a unit of measurement. I think that your approach is a good option.

I also have another suggestion that implement functions to result in float values in different unit of measurements. For example,

pub fn as_mb(&self) -> f64 {
      ...
    }

    pub fn as_mib(&self) -> f64 {
      ...
    }

    pub fn as_gb(&self) -> f64 {
      ...
    }

    pub fn as_gib(&self) -> f64 {
      ...
    }
...

Then, this approach will allows users to handle more various use-cases including your case. What do you think about that?

hyunsik avatar Oct 30 '18 20:10 hyunsik

I guess, I would prefer an even higher-level approach:

enum OutputFormat {
    SI,   // 1000, e.g. "32 KB"
    IEC,  // 1024, e.g. "32 KiB"
    Sort, // 1024, e.g. "32K"
}

fn to_string(b: ByteSize, fmt: OutputFormat) -> String {
    // ...
}

wookietreiber avatar Dec 08 '18 11:12 wookietreiber

@hyunsik I've finally gotten around to implementing my idea from my last comment.

wookietreiber avatar Jan 02 '19 13:01 wookietreiber