diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 94fe627d..36f5f8d3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,7 @@ jobs: cache: false - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{env.SRC_DIR}} @@ -91,7 +91,7 @@ jobs: cache: false - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{env.SRC_DIR}} @@ -142,7 +142,7 @@ jobs: cache: false - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: path: ${{env.SRC_DIR}} @@ -172,7 +172,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Check spelling continue-on-error: true diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2081d1c4..9195979f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ffa8d8..a181bf4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## Changelog +### 12.76.0 + +* `[knf]` Added modificator support for `GetD` +* `[spinner]` Added initial spinner animation + ### 12.75.1 * `[terminal]` Improved `AlwaysYes` flag handling diff --git a/ek.go b/ek.go index d172d046..05877dcf 100644 --- a/ek.go +++ b/ek.go @@ -20,7 +20,7 @@ import ( // ////////////////////////////////////////////////////////////////////////////////// // // VERSION is current ek package version -const VERSION = "12.75.1" +const VERSION = "12.76.0" // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/go.mod b/go.mod index 0dc556aa..e257c18a 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,8 @@ go 1.18 require ( github.com/essentialkaos/check v1.4.0 github.com/essentialkaos/go-linenoise/v3 v3.4.0 - golang.org/x/crypto v0.11.0 - golang.org/x/sys v0.10.0 + golang.org/x/crypto v0.13.0 + golang.org/x/sys v0.12.0 ) require ( diff --git a/go.sum b/go.sum index bb12c63d..0025c076 100644 --- a/go.sum +++ b/go.sum @@ -11,7 +11,7 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/knf/example_test.go b/knf/example_test.go index 8d5ab8b7..8cf77ace 100644 --- a/knf/example_test.go +++ b/knf/example_test.go @@ -9,6 +9,7 @@ package knf import ( "fmt" + "time" ) // ////////////////////////////////////////////////////////////////////////////////// // @@ -37,8 +38,11 @@ func ExampleGlobal() { // Read file mode value GetM("section:file-mode") - // Read duration in seconds - GetD("section:duration") + // Read duration as seconds + GetD("section:duration", time.Second) + + // Read duration as minutes + GetD("section:duration", time.Minute) // Check section if HasSection("section") { @@ -174,7 +178,8 @@ func ExampleGetD() { return } - fmt.Printf("Duration value from config: %v\n", GetD("section:duration")) + fmt.Printf("Duration value from config (as seconds): %v\n", GetD("section:duration", time.Second)) + fmt.Printf("Duration value from config (as minutes): %v\n", GetD("section:duration", time.Minute)) } func ExampleIs() { @@ -344,7 +349,8 @@ func ExampleConfig_GetD() { return } - fmt.Printf("Duration value from config: %v\n", cfg.GetD("section:duration")) + fmt.Printf("Duration value from config (as seconds): %v\n", cfg.GetD("section:duration", time.Second)) + fmt.Printf("Duration value from config (as minutes): %v\n", cfg.GetD("section:duration", time.Minute)) } func ExampleConfig_Is() { diff --git a/knf/knf.go b/knf/knf.go index 713e9887..8372a1ff 100644 --- a/knf/knf.go +++ b/knf/knf.go @@ -186,7 +186,7 @@ func GetM(name string, defvals ...os.FileMode) os.FileMode { } // GetD returns configuration values as duration -func GetD(name string, defvals ...time.Duration) time.Duration { +func GetD(name string, mod time.Duration, defvals ...time.Duration) time.Duration { if global == nil { if len(defvals) == 0 { return time.Duration(0) @@ -195,7 +195,7 @@ func GetD(name string, defvals ...time.Duration) time.Duration { return defvals[0] } - return global.GetD(name, defvals...) + return global.GetD(name, mod, defvals...) } // Is checks if given property contains given value @@ -476,7 +476,7 @@ func (c *Config) GetM(name string, defvals ...os.FileMode) os.FileMode { } // GetD returns configuration value as duration -func (c *Config) GetD(name string, defvals ...time.Duration) time.Duration { +func (c *Config) GetD(name string, mod time.Duration, defvals ...time.Duration) time.Duration { if c == nil || c.mx == nil { if len(defvals) == 0 { return time.Duration(0) @@ -497,7 +497,7 @@ func (c *Config) GetD(name string, defvals ...time.Duration) time.Duration { return defvals[0] } - return time.Duration(c.GetI64(name)) * time.Second + return time.Duration(c.GetI64(name)) * mod } // Is checks if given property contains given value @@ -524,7 +524,7 @@ func (c *Config) Is(name string, value any) bool { case os.FileMode: return c.GetM(name) == t case time.Duration: - return c.GetD(name) == t + return c.GetD(name, time.Second) == t } return false diff --git a/knf/knf_test.go b/knf/knf_test.go index a8880699..2954b336 100644 --- a/knf/knf_test.go +++ b/knf/knf_test.go @@ -184,7 +184,7 @@ func (s *KNFSuite) TestErrors(c *check.C) { c.Assert(GetF("test"), check.Equals, 0.0) c.Assert(GetB("test"), check.Equals, false) c.Assert(GetM("test"), check.Equals, os.FileMode(0)) - c.Assert(GetD("test"), check.Equals, time.Duration(0)) + c.Assert(GetD("test", time.Second), check.Equals, time.Duration(0)) c.Assert(Is("test", ""), check.Equals, false) c.Assert(HasSection("test"), check.Equals, false) c.Assert(HasProp("test"), check.Equals, false) @@ -199,7 +199,7 @@ func (s *KNFSuite) TestErrors(c *check.C) { c.Assert(config.GetF("test"), check.Equals, 0.0) c.Assert(config.GetB("test"), check.Equals, false) c.Assert(config.GetM("test"), check.Equals, os.FileMode(0)) - c.Assert(config.GetD("test"), check.Equals, time.Duration(0)) + c.Assert(config.GetD("test", time.Second), check.Equals, time.Duration(0)) c.Assert(config.Is("test", ""), check.Equals, true) c.Assert(config.HasSection("test"), check.Equals, false) c.Assert(config.HasProp("test"), check.Equals, false) @@ -369,10 +369,10 @@ func (s *KNFSuite) TestDuration(c *check.C) { c.Assert(global, check.NotNil) c.Assert(err, check.IsNil) - c.Assert(GetD("duration:test1"), check.Equals, time.Duration(0)) - c.Assert(GetD("duration:test2"), check.Equals, time.Minute) - c.Assert(GetD("duration:test3"), check.Equals, time.Duration(0)) - c.Assert(GetD("duration:test4"), check.Equals, time.Duration(0)) + c.Assert(GetD("duration:test1", time.Second), check.Equals, time.Duration(0)) + c.Assert(GetD("duration:test2", time.Second), check.Equals, time.Minute) + c.Assert(GetD("duration:test3", time.Second), check.Equals, time.Duration(0)) + c.Assert(GetD("duration:test4", time.Second), check.Equals, time.Duration(0)) } func (s *KNFSuite) TestIs(c *check.C) { @@ -429,7 +429,7 @@ func (s *KNFSuite) TestNil(c *check.C) { c.Assert(nilConf.GetF("formatting:test1"), check.Equals, 0.0) c.Assert(nilConf.GetB("formatting:test1"), check.Equals, false) c.Assert(nilConf.GetM("formatting:test1"), check.Equals, os.FileMode(0)) - c.Assert(nilConf.GetD("formatting:test1"), check.Equals, time.Duration(0)) + c.Assert(nilConf.GetD("formatting:test1", time.Second), check.Equals, time.Duration(0)) c.Assert(nilConf.Is("formatting:test1", ""), check.Equals, false) c.Assert(nilConf.HasSection("formatting"), check.Equals, false) c.Assert(nilConf.HasProp("formatting:test1"), check.Equals, false) @@ -459,7 +459,7 @@ func (s *KNFSuite) TestDefault(c *check.C) { c.Assert(GetU64("integer:test100", 9999), check.Equals, uint64(9999)) c.Assert(GetF("integer:test100", 123.45), check.Equals, 123.45) c.Assert(GetM("file-mode:test100", 0755), check.Equals, os.FileMode(0755)) - c.Assert(GetD("duration:test100", time.Minute), check.Equals, time.Minute) + c.Assert(GetD("duration:test100", time.Second, time.Minute), check.Equals, time.Minute) c.Assert(GetS("string:test6", "fail"), check.Equals, "fail") err := Global(s.ConfigPath) @@ -475,7 +475,7 @@ func (s *KNFSuite) TestDefault(c *check.C) { c.Assert(GetU64("integer:test100", 9999), check.Equals, uint64(9999)) c.Assert(GetF("integer:test100", 123.45), check.Equals, 123.45) c.Assert(GetM("file-mode:test100", 0755), check.Equals, os.FileMode(0755)) - c.Assert(GetD("duration:test100", time.Minute), check.Equals, time.Minute) + c.Assert(GetD("duration:test100", time.Second, time.Minute), check.Equals, time.Minute) c.Assert(GetS("string:test6", "fail"), check.Equals, "fail") var nc *Config @@ -488,7 +488,7 @@ func (s *KNFSuite) TestDefault(c *check.C) { c.Assert(nc.GetU64("integer:test100", 9999), check.Equals, uint64(9999)) c.Assert(nc.GetF("integer:test100", 123.45), check.Equals, 123.45) c.Assert(nc.GetM("file-mode:test100", 0755), check.Equals, os.FileMode(0755)) - c.Assert(nc.GetD("duration:test100", time.Minute), check.Equals, time.Minute) + c.Assert(nc.GetD("duration:test100", time.Second, time.Minute), check.Equals, time.Minute) c.Assert(nc.GetS("string:test6", "fail"), check.Equals, "fail") } diff --git a/spinner/spinner.go b/spinner/spinner.go index e6a22b77..3ad22ce1 100644 --- a/spinner/spinner.go +++ b/spinner/spinner.go @@ -58,9 +58,11 @@ var DisableAnimation = false // ////////////////////////////////////////////////////////////////////////////////// // -var spinnerFrames = []string{"⠸", "⠴", "⠤", "⠦", "⠇", "⠋", "⠉", "⠙"} +var spinnerFrames = []string{"⠒", "⠲", "⠴", "⠤", "⠦", "⠇", "⠋", "⠉", "⠙", "⠸"} var framesDelay = []time.Duration{ + 105 * time.Millisecond, + 95 * time.Millisecond, 75 * time.Millisecond, 55 * time.Millisecond, 35 * time.Millisecond, @@ -68,7 +70,7 @@ var framesDelay = []time.Duration{ 75 * time.Millisecond, 75 * time.Millisecond, 75 * time.Millisecond, - 75 * time.Millisecond, + 95 * time.Millisecond, } var desc string @@ -138,22 +140,28 @@ func Skip() { // ////////////////////////////////////////////////////////////////////////////////// // func showSpinner() { + var i int + for { - for i, frame := range spinnerFrames { - mu.RLock() - fmtc.Printf( - SpinnerColorTag+"%s {!}"+desc+"… "+TimeColorTag+"[%s]{!}", - frame, timeutil.ShortDuration(time.Since(start)), - ) - mu.RUnlock() - - time.Sleep(framesDelay[i]) - fmt.Print("\033[2K\r") - - if !isActive.Load() { - isHidden.Store(true) - return - } + mu.RLock() + fmtc.Printf( + SpinnerColorTag+"%s {!}"+desc+"… "+TimeColorTag+"[%s]{!}", + spinnerFrames[i], timeutil.ShortDuration(time.Since(start)), + ) + mu.RUnlock() + + i++ + + if i == 10 { + i = 2 + } + + time.Sleep(framesDelay[i]) + fmt.Print("\033[2K\r") + + if !isActive.Load() { + isHidden.Store(true) + return } } } diff --git a/spinner/spinner_test.go b/spinner/spinner_test.go index 903f9ba4..5ca0b35a 100644 --- a/spinner/spinner_test.go +++ b/spinner/spinner_test.go @@ -30,7 +30,7 @@ func (s *SpinnerSuite) TestSpinner(c *C) { Done(true) // skipped Show("ABCD") Show("ABCD") // skipped - time.Sleep(time.Millisecond * 100) + time.Sleep(time.Millisecond * 800) Update("ABCD") time.Sleep(time.Millisecond * 100) Done(true)