From 91cbe72b636b555b43aed1d029b3adafdae1cdf9 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Thu, 19 Oct 2023 17:30:04 +0300 Subject: [PATCH] [spinner] Added color tag validation --- CHANGELOG.md | 1 + spinner/spinner.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15f99843..4df8049c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/spinner/spinner.go b/spinner/spinner.go index 3ad22ce1..9c193246 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -16,6 +16,7 @@ import ( "time" "github.com/essentialkaos/ek/v12/fmtc" + "github.com/essentialkaos/ek/v12/strutil" "github.com/essentialkaos/ek/v12/timeutil" ) @@ -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() @@ -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), ) }