Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Wish <[email protected]>
  • Loading branch information
breezewish committed Dec 19, 2023
1 parent 8a879fd commit 64b8586
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pkg/exec/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ func PrepareCommand(p *PrepareCommandParams) (*exec.Cmd, error) {

func cmdCheckUpdate(component string, version utils.Version) {
const (
slowTimeoutSec = 1 * time.Second // Timeout to display checking message
cancelTimeoutSec = 2 * time.Second // Timeout to cancel the check
slowTimeout = 1 * time.Second // Timeout to display checking message
cancelTimeout = 2 * time.Second // Timeout to cancel the check
)

// This mutex is used for protecting flag as well as stdout
Expand All @@ -193,7 +193,7 @@ func cmdCheckUpdate(component string, version utils.Version) {
result := make(chan string, 1)

go func() {
time.Sleep(slowTimeoutSec)
time.Sleep(slowTimeout)
mu.Lock()
defer mu.Unlock()
if !isCheckFinished {
Expand All @@ -202,8 +202,8 @@ func cmdCheckUpdate(component string, version utils.Version) {
}()

go func() {
time.Sleep(cancelTimeoutSec)
result <- colorstr.Sprintf("[yellow]Timedout (after %s)", cancelTimeoutSec)
time.Sleep(cancelTimeout)
result <- colorstr.Sprintf("[yellow]Timedout (after %s)", cancelTimeout)
}()

go func() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/tui/colorstr/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ type colorTokens struct {

// Printf is a convenience wrapper for fmt.Printf with support for color codes.
// Only color codes in the format param will be respected.
func (c colorTokens) Printf(format string, a ...interface{}) (n int, err error) {
func (c colorTokens) Printf(format string, a ...any) (n int, err error) {
return fmt.Printf(c.Color(format), a...)
}

// Fprintf is a convenience wrapper for fmt.Fprintf with support for color codes.
// Only color codes in the format param will be respected.
func (c colorTokens) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
func (c colorTokens) Fprintf(w io.Writer, format string, a ...any) (n int, err error) {
return fmt.Fprintf(w, c.Color(format), a...)
}

// Sprintf is a convenience wrapper for fmt.Sprintf with support for color codes.
// Only color codes in the format param will be respected.
func (c colorTokens) Sprintf(format string, a ...interface{}) string {
func (c colorTokens) Sprintf(format string, a ...any) string {
return fmt.Sprintf(c.Color(format), a...)
}

Expand All @@ -74,18 +74,18 @@ var DefaultTokens = (func() colorTokens {

// Printf is a convenience wrapper for fmt.Printf with support for color codes.
// Only color codes in the format param will be respected.
func Printf(format string, a ...interface{}) (n int, err error) {
func Printf(format string, a ...any) (n int, err error) {
return DefaultTokens.Printf(format, a...)
}

// Fprintf is a convenience wrapper for fmt.Fprintf with support for color codes.
// Only color codes in the format param will be respected.
func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
func Fprintf(w io.Writer, format string, a ...any) (n int, err error) {
return DefaultTokens.Fprintf(w, format, a...)
}

// Sprintf is a convenience wrapper for fmt.Sprintf with support for color codes.
// Only color codes in the format param will be respected.
func Sprintf(format string, a ...interface{}) string {
func Sprintf(format string, a ...any) string {
return DefaultTokens.Sprintf(format, a...)
}
2 changes: 2 additions & 0 deletions pkg/tui/colorstr/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
"github.com/stretchr/testify/require"
)

// RequireEqualColorToken compares whether the actual string is equal to the expected string after color processing.
func RequireEqualColorToken(t *testing.T, expectColorTokens string, actualString string) {
require.Equal(t, DefaultTokens.Color(expectColorTokens), actualString)
}

// RequireNotEqualColorToken compares whether the actual string is not equal to the expected string after color processing.
func RequireNotEqualColorToken(t *testing.T, expectColorTokens string, actualString string) {
require.NotEqual(t, DefaultTokens.Color(expectColorTokens), actualString)
}

0 comments on commit 64b8586

Please sign in to comment.