Skip to content

Commit

Permalink
Merge pull request #385 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 12.76.0
  • Loading branch information
andyone authored Sep 14, 2023
2 parents 220e8ea + 4aa6afa commit a4d50a8
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 49 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
cache: false

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ${{env.SRC_DIR}}

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
cache: false

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ${{env.SRC_DIR}}

Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
cache: false

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: ${{env.SRC_DIR}}

Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Check spelling
continue-on-error: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 2

Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion ek.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// ////////////////////////////////////////////////////////////////////////////////// //

// VERSION is current ek package version
const VERSION = "12.75.1"
const VERSION = "12.76.0"

// ////////////////////////////////////////////////////////////////////////////////// //

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
14 changes: 10 additions & 4 deletions knf/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package knf

import (
"fmt"
"time"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions knf/knf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions knf/knf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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")
}

Expand Down
42 changes: 25 additions & 17 deletions spinner/spinner.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ 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,
55 * time.Millisecond,
75 * time.Millisecond,
75 * time.Millisecond,
75 * time.Millisecond,
75 * time.Millisecond,
95 * time.Millisecond,
}

var desc string
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion spinner/spinner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a4d50a8

Please sign in to comment.