progress: fix ansimeter inconsistent time left formatting
The ansimeter currently uses FormatDuration() to render the time left on the progress bar in no more than 5 runes. This limitation forces the rendering to switch between whole and fractional values during the progress bar lifetime.
For example: 10.4m ... 6m55s
Add a new formatter FormatDurationGeneric() which supports more use-case specific rendering modes.
-
Inspired by the systemd format_timespan()
-
Supports the same units of time (y, d, h, m, s, ms, us, ns) as FormatDuration().
-
Supports ShowVerbose and ShowCompact mode. The compact mode limits the rendering width to 6 runes, by rendering only the first two most significant place values.
-
Supports space separated time unit rendering
-
Supports TimeLeft, TimePassed and TimeRounded modes to produce more accurate results for specific use-cases.
Add ProgressBarTimeLeft() and ProgressBarTimePassed() renderers based on FormatDurationGeneric(), specifically for use with progress bars either indicating time left or time elapse.
-
Optimised for use as visual user interface progress indicator
-
Duration range configured for rendering of seconds to hours
Change the ansimeter code to allow time duration to consume 6 runes, and use the ProgressBarTimeLeft() renderer.
For example: ages! ... 23h12m ... 11m22s ... 56s ... 1s ... 0s
Signed-off-by: Fred Lotter [email protected]
Thanks for helping us make a better snapd! Have you signed the license agreement and read the contribution guide?
Codecov Report
Merging #11054 (b6ae5c5) into master (8959914) will increase coverage by
0.01%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #11054 +/- ##
==========================================
+ Coverage 78.19% 78.21% +0.01%
==========================================
Files 913 915 +2
Lines 103354 103609 +255
==========================================
+ Hits 80821 81040 +219
- Misses 17465 17489 +24
- Partials 5068 5080 +12
| Flag | Coverage Δ | |
|---|---|---|
| unittests | 78.21% <100.00%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
| Impacted Files | Coverage Δ | |
|---|---|---|
| progress/ansimeter.go | 95.00% <100.00%> (-0.09%) |
:arrow_down: |
| strutil/quantity/quantity.go | 97.65% <100.00%> (+2.78%) |
:arrow_up: |
| osutil/synctree.go | 76.41% <0.00%> (-2.84%) |
:arrow_down: |
| daemon/api_validate.go | 79.56% <0.00%> (-2.49%) |
:arrow_down: |
| gadget/ondisk.go | 69.66% <0.00%> (-2.03%) |
:arrow_down: |
| store/cache.go | 69.23% <0.00%> (-1.93%) |
:arrow_down: |
| osutil/disks/mockdisk.go | 83.66% <0.00%> (-0.88%) |
:arrow_down: |
| osutil/disks/disks_linux.go | 72.22% <0.00%> (-0.82%) |
:arrow_down: |
| gadget/install/partition.go | 77.90% <0.00%> (-0.72%) |
:arrow_down: |
| daemon/api_connections.go | 93.04% <0.00%> (-0.54%) |
:arrow_down: |
| ... and 21 more |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing dataPowered by Codecov. Last update 8959914...b6ae5c5. Read the comment docs.
Hi @anonymouse64 , let me know if there is anything else you would like me to polish here. I have addressed all reported concerns from my perspective.
Hi @anonymouse64 . I ran golangci-lint on the sources and fixed the problem. Could you let me know if you are happy (i.e. approve), then I can request this to be merged. Thanks!
as there's been no forward motion and this is large I'm closing this with precious-but-later