Skip to content

Commit

Permalink
refactor: use pterm.Fuzzy instead of Gray
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Mar 22, 2024
1 parent f001170 commit 7ec81b7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cmd/vale/command.go
Expand Up @@ -250,7 +250,7 @@ func printVars(_ []string, _ *core.CLIFlags) error {
if value, ok := os.LookupEnv(name); ok {
found = value
}
tableData = append(tableData, []string{pterm.Gray(name), info, found})
tableData = append(tableData, []string{toCodeStyle(name), info, found})
}

return pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
Expand Down Expand Up @@ -282,9 +282,9 @@ func printDirs(_ []string, _ *core.CLIFlags) error {

tableData := pterm.TableData{
{"Asset", "Default Location", "Found"},
{pterm.Gray("StylesPath"), styles, stylesFound},
{pterm.Gray(".vale.ini"), cfg, configFound},
{pterm.Gray("vale-native"), nativeExe, nativeFound},
{toCodeStyle("StylesPath"), styles, stylesFound},
{toCodeStyle(".vale.ini"), cfg, configFound},
{toCodeStyle("vale-native"), nativeExe, nativeFound},
}

return pterm.DefaultTable.WithHasHeader().WithData(tableData).Render()
Expand Down
9 changes: 4 additions & 5 deletions cmd/vale/flag.go
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"

"github.com/pterm/pterm"
"github.com/spf13/pflag"

"github.com/errata-ai/vale/v3/internal/core"
Expand All @@ -21,15 +20,15 @@ func init() {
pflag.StringVar(&Flags.Sources, "sources", "", "A config files to load")
pflag.StringVar(&Flags.Filter, "filter", "", "An expression to filter rules by.")
pflag.StringVar(&Flags.Glob, "glob", "*",
fmt.Sprintf(`A glob pattern (%s)`, pterm.Gray(`--glob='*.{md,txt}.'`)))
fmt.Sprintf(`A glob pattern (%s)`, toCodeStyle(`--glob='*.{md,txt}.'`)))
pflag.StringVar(&Flags.Path, "config", "",
fmt.Sprintf(`A file path (%s).`, pterm.Gray(`--config='some/file/path/.vale.ini'`)))
fmt.Sprintf(`A file path (%s).`, toCodeStyle(`--config='some/file/path/.vale.ini'`)))
pflag.StringVar(&Flags.Output, "output", "CLI", `An output style ("line", "JSON", or a template file).`)
pflag.StringVar(&Flags.InExt, "ext", ".txt",
fmt.Sprintf(`An extension to associate with stdin (%s).`, pterm.Gray(`--ext=.md`)))
fmt.Sprintf(`An extension to associate with stdin (%s).`, toCodeStyle(`--ext=.md`)))

pflag.StringVar(&Flags.AlertLevel, "minAlertLevel", "",
fmt.Sprintf(`The minimum level to display (%s).`, pterm.Gray(`--minAlertLevel=error`)))
fmt.Sprintf(`The minimum level to display (%s).`, toCodeStyle(`--minAlertLevel=error`)))

pflag.BoolVar(&Flags.Wrap, "no-wrap", false, "Don't wrap CLI output.")
pflag.BoolVar(&Flags.NoExit, "no-exit", false, "Don't return a nonzero exit code on errors.")
Expand Down
18 changes: 9 additions & 9 deletions cmd/vale/info.go
Expand Up @@ -34,21 +34,21 @@ To get started, you'll need a configuration file (%s):
See %s for more setup information.`,
pterm.Bold.Sprintf("Usage"),

pterm.Gray("vale [options] [input...]"),
pterm.Gray("vale myfile.md myfile1.md mydir1"),
pterm.Gray("vale --output=JSON [input...]"),
toCodeStyle("vale [options] [input...]"),
toCodeStyle("vale myfile.md myfile1.md mydir1"),
toCodeStyle("vale --output=JSON [input...]"),

pterm.Gray(".vale.ini"),
toCodeStyle(".vale.ini"),
pterm.Bold.Sprintf("Example"),
pterm.Gray(exampleConfig),
toCodeStyle(exampleConfig),

pterm.Underscore.Sprintf("https://vale.sh"))

var info = fmt.Sprintf(`%s
(Or use %s for a listing of all CLI options.)`,
intro,
pterm.Gray("vale --help"))
toCodeStyle("vale --help"))

var hidden = []string{
"mode-compat",
Expand Down Expand Up @@ -80,9 +80,9 @@ func PrintIntro() {

func toFlag(name string) string {
if code, ok := shortcodes[name]; ok {
return fmt.Sprintf("%s, %s", pterm.Gray("-"+code), pterm.Gray("--"+name))
return fmt.Sprintf("%s, %s", toCodeStyle("-"+code), toCodeStyle("--"+name))
}
return pterm.Gray("--" + name)
return toCodeStyle("--" + name)
}

func init() {
Expand All @@ -108,7 +108,7 @@ func init() {
fmt.Println(pterm.Bold.Sprintf("Commands:"))
for cmd, use := range commandInfo {
if !core.StringInSlice(cmd, hidden) {
table.Append([]string{pterm.Gray(cmd), use})
table.Append([]string{toCodeStyle(cmd), use})
}
}
table.Render()
Expand Down
4 changes: 4 additions & 0 deletions cmd/vale/util.go
Expand Up @@ -89,3 +89,7 @@ func platformAndArch() string {
func mkdir(dir string) error {
return os.MkdirAll(dir, os.ModeDir|0700)
}

func toCodeStyle(s string) string {
return pterm.Fuzzy.Sprint(s)
}
5 changes: 2 additions & 3 deletions internal/core/config.go
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/adrg/xdg"
"github.com/bmatcuk/doublestar/v4"
"github.com/errata-ai/ini"
"github.com/pterm/pterm"

"github.com/errata-ai/vale/v3/internal/glob"
)
Expand Down Expand Up @@ -48,8 +47,8 @@ var ConfigDirs = []string{VocabDir, DictDir, TmplDir, IgnoreDir, ActionDir, Scri

// ConfigVars is a list of all supported environment variables.
var ConfigVars = map[string]string{
"VALE_CONFIG_PATH": fmt.Sprintf("Override the default search process by specifying a %s file.", pterm.Gray(".vale.ini")),
"VALE_STYLES_PATH": fmt.Sprintf("Specify the location of the default %s.", pterm.Gray("StylesPath")),
"VALE_CONFIG_PATH": "Override the default search process by specifying a .vale.ini file.",
"VALE_STYLES_PATH": "Specify the location of the default StylesPath.",
}

// ConfigNames is a list of all possible configuration file names.
Expand Down
2 changes: 1 addition & 1 deletion internal/core/error.go
Expand Up @@ -77,7 +77,7 @@ func NewError(code, title, msg string) error {
pterm.BgRed.Sprintf(code),
title,
msg,
pterm.Gray(pterm.Italic.Sprintf("Execution stopped with code 1.")),
pterm.Fuzzy.Sprint(pterm.Italic.Sprintf("Execution stopped with code 1.")),
)
}

Expand Down

0 comments on commit 7ec81b7

Please sign in to comment.