Skip to content

Commit

Permalink
[spinner] Added color tag validation
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Oct 19, 2023
1 parent 340e201 commit 91cbe72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* `[fmtutil/panel]` Added `DefaultOptions` variable to set default options for all panels
* `[strutil]` Added method `LenVisual`
* `[progress]` Added settings validation
* `[spinner]` Added color tag validation
* `[usage]` Added color tag validation
* `[fmtutil/panel]` Improved panel rendering when `BOTTOM_LINE` option is used
* `[fmtutil/panel]` Improved panel rendering when `label` is empty
Expand Down
18 changes: 14 additions & 4 deletions spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/essentialkaos/ek/v12/fmtc"
"github.com/essentialkaos/ek/v12/strutil"
"github.com/essentialkaos/ek/v12/timeutil"
)

Expand Down Expand Up @@ -142,10 +143,13 @@ func Skip() {
func showSpinner() {
var i int

spinnerColorTag := strutil.B(fmtc.IsTag(SpinnerColorTag), SpinnerColorTag, "{y}")
timeColorTag := strutil.B(fmtc.IsTag(TimeColorTag), TimeColorTag, "{s-}")

for {
mu.RLock()
fmtc.Printf(
SpinnerColorTag+"%s {!}"+desc+"… "+TimeColorTag+"[%s]{!}",
spinnerColorTag+"%s {!}"+desc+"… "+timeColorTag+"[%s]{!}",
spinnerFrames[i], timeutil.ShortDuration(time.Since(start)),
)
mu.RUnlock()
Expand Down Expand Up @@ -176,20 +180,26 @@ func stopSpinner(action uint8) {
}

mu.RLock()

timeColorTag := strutil.B(fmtc.IsTag(TimeColorTag), TimeColorTag, "{s-}")

switch action {
case _ACTION_ERROR:
errColorTag := strutil.B(fmtc.IsTag(ErrColorTag), ErrColorTag, "{r}")
fmtc.Printf(
ErrColorTag+ErrSymbol+" {!}"+desc+" "+TimeColorTag+"(%s){!}\n",
errColorTag+ErrSymbol+" {!}"+desc+" "+timeColorTag+"(%s){!}\n",
timeutil.ShortDuration(time.Since(start), true),
)
case _ACTION_SKIP:
skipColorTag := strutil.B(fmtc.IsTag(SkipColorTag), SkipColorTag, "{s-}")
fmtc.Printf(
SkipColorTag+SkipSymbol+" {!}"+desc+" "+TimeColorTag+"(%s){!}\n",
skipColorTag+SkipSymbol+" {!}"+desc+" "+timeColorTag+"(%s){!}\n",
timeutil.ShortDuration(time.Since(start), true),
)
default:
okColorTag := strutil.B(fmtc.IsTag(OkColorTag), OkColorTag, "{g}")
fmtc.Printf(
OkColorTag+OkSymbol+" {!}"+desc+" "+TimeColorTag+"(%s){!}\n",
okColorTag+OkSymbol+" {!}"+desc+" "+timeColorTag+"(%s){!}\n",
timeutil.ShortDuration(time.Since(start), true),
)
}
Expand Down

0 comments on commit 91cbe72

Please sign in to comment.