From 680d0aff5499f08be867b5525d065d6dcf6b83ec Mon Sep 17 00:00:00 2001 From: Danilo Pantani Date: Sun, 9 Mar 2025 04:43:09 -0300 Subject: [PATCH] refactor: remove `github.com/gookit/color` (#4557) --- changelog.md | 1 + go.mod | 2 -- go.sum | 4 ---- ignite/cmd/account_create.go | 10 +++++++--- ignite/cmd/account_delete.go | 10 +++++++--- ignite/cmd/account_export.go | 10 ++++++---- ignite/cmd/account_import.go | 6 ++++-- ignite/cmd/cmd.go | 5 ++++- ignite/pkg/cliui/clispinner/simple.go | 7 ++++--- ignite/pkg/cliui/colors/colors.go | 6 ++++++ 10 files changed, 39 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index 65dec94d76..0c07c89cc8 100644 --- a/changelog.md +++ b/changelog.md @@ -58,6 +58,7 @@ - [#4463](https://github.com/ignite/cli/pull/4463) Run `chain simulation` with any simulation test case - [#4533](https://github.com/ignite/cli/pull/4533) Promote GitHub codespace instead of Gitpod - [#4549](https://github.com/ignite/cli/pull/4549) Remove unused placeholder vars +- [#4557](https://github.com/ignite/cli/pull/4557) Remove github.com/gookit/color ### Fixes diff --git a/go.mod b/go.mod index 7463e5adbd..5c1665d88d 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,6 @@ require ( github.com/goccy/go-yaml v1.15.23 github.com/google/go-github/v48 v48.2.0 github.com/google/go-querystring v1.1.0 - github.com/gookit/color v1.5.4 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-plugin v1.6.3 github.com/iancoleman/strcase v0.3.0 @@ -446,7 +445,6 @@ require ( github.com/vektra/mockery/v2 v2.46.0 // indirect github.com/xanzy/ssh-agent v0.3.3 // indirect github.com/xen0n/gosmopolitan v1.2.2 // indirect - github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect github.com/yagipy/maintidx v1.0.0 // indirect github.com/yeya24/promlinter v0.3.0 // indirect github.com/ykadowak/zerologlint v0.1.5 // indirect diff --git a/go.sum b/go.sum index fe72a66bbf..187ab2bdbc 100644 --- a/go.sum +++ b/go.sum @@ -968,8 +968,6 @@ github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqE github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gookit/color v1.5.4 h1:FZmqs7XOyGgCAxmWyPslpiok1k05wmY3SJTytgvYFs0= -github.com/gookit/color v1.5.4/go.mod h1:pZJOeOS8DM43rXbp4AZo1n9zCU2qjpcRko0b6/QJi9w= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gordonklaus/ineffassign v0.1.0 h1:y2Gd/9I7MdY1oEIt+n+rowjBNDcLQq3RsH5hwJd0f9s= github.com/gordonklaus/ineffassign v0.1.0/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0= @@ -1742,8 +1740,6 @@ github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU= github.com/xen0n/gosmopolitan v1.2.2/go.mod h1:7XX7Mj61uLYrj0qmeN0zi7XDon9JRAEhYQqAPLVNTeg= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8= -github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yagipy/maintidx v1.0.0 h1:h5NvIsCz+nRDapQ0exNv4aJ0yXSI0420omVANTv3GJM= github.com/yagipy/maintidx v1.0.0/go.mod h1:0qNf/I/CCZXSMhsRsrEPDZ+DkekpKLXAJfsTACwgXLk= diff --git a/ignite/cmd/account_create.go b/ignite/cmd/account_create.go index 51a2dc12e2..c3feee5fdd 100644 --- a/ignite/cmd/account_create.go +++ b/ignite/cmd/account_create.go @@ -3,6 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" + "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cosmosaccount" "github.com/ignite/cli/v29/ignite/pkg/errors" ) @@ -19,7 +20,11 @@ func NewAccountCreate() *cobra.Command { } func accountCreateHandler(cmd *cobra.Command, args []string) error { - name := args[0] + var ( + name = args[0] + session = cliui.New(cliui.StartSpinnerWithText(statusCreating)) + ) + defer session.End() ca, err := cosmosaccount.New( cosmosaccount.WithKeyringBackend(getKeyringBackend(cmd)), @@ -34,6 +39,5 @@ func accountCreateHandler(cmd *cobra.Command, args []string) error { return errors.Errorf("unable to create account: %w", err) } - cmd.Printf("Account %q created, keep your mnemonic in a secret place:\n\n%s\n", name, mnemonic) - return nil + return session.Printf("Account %q created, keep your mnemonic in a secret place:\n\n%s\n", name, mnemonic) } diff --git a/ignite/cmd/account_delete.go b/ignite/cmd/account_delete.go index 4819ada6eb..6bd3f5a53c 100644 --- a/ignite/cmd/account_delete.go +++ b/ignite/cmd/account_delete.go @@ -3,6 +3,7 @@ package ignitecmd import ( "github.com/spf13/cobra" + "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cosmosaccount" ) @@ -18,7 +19,11 @@ func NewAccountDelete() *cobra.Command { } func accountDeleteHandler(cmd *cobra.Command, args []string) error { - name := args[0] + var ( + name = args[0] + session = cliui.New(cliui.StartSpinnerWithText(statusDeleting)) + ) + defer session.End() ca, err := cosmosaccount.New( cosmosaccount.WithKeyringBackend(getKeyringBackend(cmd)), @@ -32,6 +37,5 @@ func accountDeleteHandler(cmd *cobra.Command, args []string) error { return err } - cmd.Printf("Account %s deleted.\n", name) - return nil + return session.Printf("Account %s deleted.\n", name) } diff --git a/ignite/cmd/account_export.go b/ignite/cmd/account_export.go index 3ced1b63d4..cb992eda8c 100644 --- a/ignite/cmd/account_export.go +++ b/ignite/cmd/account_export.go @@ -7,6 +7,7 @@ import ( "github.com/spf13/cobra" + "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cosmosaccount" "github.com/ignite/cli/v29/ignite/pkg/errors" ) @@ -27,9 +28,11 @@ func NewAccountExport() *cobra.Command { func accountExportHandler(cmd *cobra.Command, args []string) error { var ( - name = args[0] - path = flagGetPath(cmd) + name = args[0] + path = flagGetPath(cmd) + session = cliui.New(cliui.StartSpinnerWithText(statusExporting)) ) + defer session.End() passphrase, err := getPassphrase(cmd) if err != nil { @@ -65,6 +68,5 @@ func accountExportHandler(cmd *cobra.Command, args []string) error { return err } - cmd.Printf("Account %q exported to file: %s\n", name, path) - return nil + return session.Printf("Account %q exported to file: %s\n", name, path) } diff --git a/ignite/cmd/account_import.go b/ignite/cmd/account_import.go index 73b8af3b63..b97fe8fea3 100644 --- a/ignite/cmd/account_import.go +++ b/ignite/cmd/account_import.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/go-bip39" "github.com/spf13/cobra" + "github.com/ignite/cli/v29/ignite/pkg/cliui" "github.com/ignite/cli/v29/ignite/pkg/cliui/cliquiz" "github.com/ignite/cli/v29/ignite/pkg/cosmosaccount" "github.com/ignite/cli/v29/ignite/pkg/errors" @@ -31,7 +32,9 @@ func accountImportHandler(cmd *cobra.Command, args []string) error { var ( name = args[0] secret, _ = cmd.Flags().GetString(flagSecret) + session = cliui.New(cliui.StartSpinnerWithText(statusImporting)) ) + defer session.End() if secret == "" { if err := cliquiz.Ask( @@ -70,6 +73,5 @@ func accountImportHandler(cmd *cobra.Command, args []string) error { return err } - cmd.Printf("Account %q imported.\n", name) - return nil + return session.Printf("Account %q imported.\n", name) } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index a6630bc6d4..62543a2850 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -42,7 +42,10 @@ const ( cacheFileName = "ignite_cache.db" statusGenerating = "Generating..." - statusQuerying = "Querying..." + statusImporting = "Importing..." + statusExporting = "Exporting..." + statusCreating = "Creating..." + statusDeleting = "Deleting..." ) // List of CLI level one commands that should not load Ignite app instances. diff --git a/ignite/pkg/cliui/clispinner/simple.go b/ignite/pkg/cliui/clispinner/simple.go index bb36b70d5c..dc6a7e0355 100644 --- a/ignite/pkg/cliui/clispinner/simple.go +++ b/ignite/pkg/cliui/clispinner/simple.go @@ -8,13 +8,14 @@ import ( "time" "github.com/briandowns/spinner" - "github.com/gookit/color" + + "github.com/ignite/cli/v29/ignite/pkg/cliui/colors" ) var ( simpleCharset = spinner.CharSets[4] simpleRefreshRate = time.Millisecond * 300 - simpleColor = color.Blue + simpleColor = colors.Spinner ) type SimpleSpinner struct { @@ -115,7 +116,7 @@ func (s *SimpleSpinner) Start() Spinner { case <-ticker.C: // Update the spinner on each tick s.mu.Lock() frame := charset[index] - str := fmt.Sprintf("\r%s%s %s", prefix, simpleColor.Sprint(frame), text) + str := fmt.Sprintf("\r%s%s %s", prefix, simpleColor(frame), text) _, _ = fmt.Fprint(writer, str) // Update the spinner in the same line index++ if index >= len(charset) { diff --git a/ignite/pkg/cliui/colors/colors.go b/ignite/pkg/cliui/colors/colors.go index 6b53f41c9c..358de50830 100644 --- a/ignite/pkg/cliui/colors/colors.go +++ b/ignite/pkg/cliui/colors/colors.go @@ -14,6 +14,7 @@ const ( Cyan = "#34e2e2" White = "#FFFFFF" HiBlue = "#729FCF" + Blue = "#0a2fc4" ) var ( @@ -24,6 +25,7 @@ var ( modified = lipgloss.NewStyle().Foreground(lipgloss.Color(Magenta)) name = lipgloss.NewStyle().Bold(true) mnemonic = lipgloss.NewStyle().Foreground(lipgloss.Color(HiBlue)) + spinner = lipgloss.NewStyle().Foreground(lipgloss.Color(Blue)) faint = lipgloss.NewStyle().Faint(true) ) @@ -65,6 +67,10 @@ func Mnemonic(i ...interface{}) string { return mnemonic.Render(fmt.Sprint(i...)) } +func Spinner(i ...interface{}) string { + return spinner.Render(fmt.Sprint(i...)) +} + // Faint styles the text using a dimmer shade for the foreground color. func Faint(i ...interface{}) string { return faint.Render(fmt.Sprint(i...))