Shorthand HumanFloatCount and HumanCount#697
Shorthand HumanFloatCount and HumanCount#697ReagentX wants to merge 8 commits intoconsole-rs:mainfrom
HumanFloatCount and HumanCount#697Conversation
HumanCountHumanFloatCount and HumanCount
|
This includes changes from #696 but can be implemented without them if required. |
|
@chris-laplante I'm inclined to think that the Personally I think we should try to keep the number of significant digits constant, so that we get 123, 1.23 or 12.3 but not 12k (should be 12.0k) or 12.34M (should also be 12.3M). Also please rebase and squash into clean commits (potentially just one in this case). The assertion style with |
d0241dd to
e1ccd2b
Compare
That would break existing templates; this PR retains existing functionality and only adds new features. Old templates will behave the same as how they did before. If you have a specification in mind I am more than happy to implement it.
I agree; I just copied the design of what was already in the repo for both tests and code to maintain consistency. |
How would it break existing templates? Or do you mean it would change the output for existing templates? I'm saying that old templates behaving exactly the same as before isn't a very important goal to me.
Okay, let's leave it for now. |
|
I didn't want to change any existing behavior unless that was specifically requested. |
|
IMO this behavior should become the default for |
|
I can just flip the logic for when the alternative formatter is enabled, are there any other design details I should include? It sounds like |
Flipping the behavior sounds good to me. I don't see much of an issue with the |
2e21fce to
8b6cc84
Compare
(sorry for the radio silence - I was on vacation) I am also fine with flipping the behavior. |
|
I pushed the relevant changes. |
|
Please rebase on top of main. Here's what I'm looking for:
I don't see new formatting options ( |
|
I added logic to maintain 3 digits by default; I am not sure what the rest of your comment is referring to. |
There is quite a bit of documentation at https://github.com/console-rs/indicatif/blob/main/src/lib.rs#L136 about the template syntax. Please update this to describe the changes you've made. In my mind, this PR should not be adding new template keys (like the |
| } | ||
| } | ||
|
|
||
| const HUMAN_FLOAT_COUNT_THRESHOLDS: [(f64, &str); 5] = [ |
There was a problem hiding this comment.
I don't think we need both this and HUMAN_COUNT_TRESHOLDS, presumably we can drive the float value from the integer one?
There was a problem hiding this comment.
The types are different, so they have to be defined separately unless I want to cast them every time the formatter runs. I could do something like either of these:
macro_rules! define_thresholds {
($(($num:expr, $suffix:expr)),*) => {
const HUMAN_COUNT_THRESHOLDS: [(u64, &str); 5] = [
$(($num, $suffix),)*
];
const HUMAN_FLOAT_COUNT_THRESHOLDS: [(f64, &str); 5] = [
$(($num as f64, $suffix),)*
];
};
}
// Explicit type for 1T because Rust infers numeric literals to be i32 by default
define_thresholds!(
(1_000_000_000_000i64, "T"),
(1_000_000_000, "B"),
(1_000_000, "M"),
(1_000, "k"),
(0, "")
);or
const TRILLION: u64 = 1_000_000_000_000;
const BILLION: u64 = 1_000_000_000;
const MILLION: u64 = 1_000_000;
const THOUSAND: u64 = 1_000;
const ZERO: u64 = 0;
const HUMAN_COUNT_THRESHOLDS: [(u64, &str); 5] = [
(TRILLION, "T"),
(BILLION, "B"),
(MILLION, "M"),
(THOUSAND, "k"),
(ZERO, ""),
];
const HUMAN_FLOAT_COUNT_THRESHOLDS: [(f64, &str); 5] = [
(TRILLION as f64, "T"),
(BILLION as f64, "B"),
(MILLION as f64, "M"),
(THOUSAND as f64, "k"),
(ZERO as f64, ""),
];but they both feel a lot less maintainable than just having two arrays.
|
I updated the documentation in my PR: https://github.com/console-rs/indicatif/pull/697/files#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759 I didn't add the Lines 326 to 331 in 458e4dc The The tests call |
|
Do you need anything else from me? |
|
I don't remember. This is still on my list to review but it's not very high priority unless it can be funded, sorry. |
#to specify new alternative shorthand formatter forHumanFloatCountandHumanCountwidthto truncateHumanCountvaluesper_secrate #637human_pos_formatted,human_len_formatted, andper_sec_shortExamples:
"{spinner:.green} [{elapsed}] [{bar:.blue}] {human_pos}/{human_len} ({per_sec_formatted}, ETA: {eta})""{spinner:.green} [{elapsed}] [{bar:.blue}] {human_pos:3}/{human_len:3} ({per_sec_formatted}, ETA: {eta})""{spinner:.green} [{elapsed}] [{bar:.blue}] {human_pos:2}/{human_len:2} ({per_sec}, ETA: {eta})"