Skip to content

Commit

Permalink
Added windows color support
Browse files Browse the repository at this point in the history
  • Loading branch information
erdemkosk committed Jun 21, 2024
1 parent b699a1f commit 335bc50
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
29 changes: 19 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package cmd
import (
"fmt"
"os"
"runtime"

config "github.com/erdemkosk/envolve-go/internal"
"github.com/erdemkosk/envolve-go/internal/logic"
"github.com/mattn/go-colorable"
"github.com/mattn/go-isatty"
"github.com/spf13/cobra"
)

Expand All @@ -15,38 +18,39 @@ type Command interface {

var rootCmd = &cobra.Command{
Use: "envolve",
Version: "1.0.13",
Version: "1.0.16",
Short: "Envolve CLI is a tool for effortless .env file management.",
Long: `` + config.PASTEL_ORANGE + `Envolve ` + config.RESET + `is your solution for effortless .env file management. With ` + config.PASTEL_ORANGE + `Envolve ` + config.RESET + `,you can seamlessly gather, arrange, and fine-tune environment variables
Long: fmt.Sprintf(`%sEnvolve%s is your solution for effortless .env file management. With %sEnvolve%s, you can seamlessly gather, arrange, and fine-tune environment variables
across all your projects, ensuring that your configuration data is always at your fingertips without the risk of loss. `,
config.PASTEL_ORANGE, config.RESET, config.PASTEL_ORANGE, config.RESET),
// Use colorable for cross-platform ANSI color support
}

var customHelpTemplate = fmt.Sprintf(`{{with (or .Long .Short)}}{{. | trimTrailingWhitespaces}}{{end}}
Usage:
` + config.PASTEL_ORANGE + `{{.UseLine}}{{if .HasAvailableSubCommands}} ` + config.RESET + `
%s{{.UseLine}}{{if .HasAvailableSubCommands}} %s
` + config.PASTEL_RED + `Warning:
If you have not synchronized any of your projects, everything will be shown as an empty folder in show and edit commands. Edit and show work in already synced projects. ` + config.RESET + `
%sWarning:
If you have not synchronized any of your projects, everything will be shown as an empty folder in show and edit commands. Edit and show work in already synced projects. %s
` + config.PASTEL_CYAN + ` Info:
%s Info:
If you want to learn different ways to use a command, for example, just type envolve sync -h for sync.
In the description, you will find example information that you can give a path to a folder you want, not the current folder, with --path. ` + config.RESET + `
In the description, you will find example information that you can give a path to a folder you want, not the current folder, with --path. %s
Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
` + config.PASTEL_GRAY + `{{rpad .Name .NamePadding }}` + config.RESET + ` ` + config.PASTEL_BLUE + ` {{.Short}}{{end}}{{end}}{{end}} ` + config.RESET + `
%s{{rpad .Name .NamePadding }}%s %s{{.Short}}{{end}}{{end}}{{end}} %s
Flags:
{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}
Use "{{.CommandPath}} [command] --help" for more information about a command.
`)
`, config.PASTEL_ORANGE, config.RESET, config.PASTEL_RED, config.RESET, config.PASTEL_CYAN, config.RESET, config.PASTEL_GRAY, config.RESET, config.PASTEL_BLUE, config.RESET)

func Execute() {
envolvePath := logic.GetEnvolveHomePath()

err := logic.CreateFolderIfDoesNotExist(envolvePath)

if err != nil {
return
}
Expand All @@ -56,5 +60,10 @@ func Execute() {
}

func init() {
// Enable ANSI colors in Windows terminal if supported
if runtime.GOOS == "windows" && isatty.IsTerminal(os.Stdout.Fd()) {
rootCmd.SetOut(colorable.NewColorable(os.Stdout))
}

rootCmd.SetHelpTemplate(customHelpTemplate)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ require (
github.com/gdamore/encoding v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/tview v0.0.0-20240524063012-037df494fb76 h1:iqvDlgyjmqleATtFbA7c14djmPh2n4mCYUv7JlD/ruA=
Expand Down Expand Up @@ -38,7 +44,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Expand Down

0 comments on commit 335bc50

Please sign in to comment.