Skip to content

Commit

Permalink
improve code redability
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Nov 11, 2024
1 parent 084095c commit 793acd1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cmd/oras/internal/display/status/progress/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,16 @@ func (s *status) String(width int) (string, string) {
// └─ digest(72)
var offset string
var percent float64
switch {
case s.done || total == 0: // 100%, show exact size
if s.done {
// 100%, show exact size
offset = fmt.Sprint(s.total.Size)
percent = 1
default: // 0% ~ 99%, show 2-digit precision
} else if total == 0 {
// 0 byte, show 100%
offset = "0"
percent = 1
} else {
// 0% ~ 99%, show 2-digit precision
if s.offset >= 0 {
// calculate percentage
percent = float64(s.offset) / float64(total)
Expand Down

0 comments on commit 793acd1

Please sign in to comment.