Skip to content

Commit

Permalink
We don't need globals for just this
Browse files Browse the repository at this point in the history
  • Loading branch information
gdanko committed Aug 24, 2024
1 parent 766fb63 commit 4aaea42
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pkg/output/json-output.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"fmt"

"github.com/fatih/color"
"github.com/gdanko/enpass/globals"
"github.com/gdanko/enpass/pkg/enpass"
"github.com/hokaccha/go-prettyjson"
"github.com/sirupsen/logrus"
)

func doJsonOutput(logger *logrus.Logger, cards []enpass.Card, nocolorFlag bool) {
colorMap := globals.GetColorMap()
colorMap := colorMap
disabledColor := false
if nocolorFlag {
disabledColor = true
Expand Down
9 changes: 4 additions & 5 deletions pkg/output/list-output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

"github.com/fatih/color"
"github.com/gdanko/enpass/globals"
"github.com/gdanko/enpass/pkg/enpass"
)

Expand All @@ -30,10 +29,10 @@ func doListOutput(cards []enpass.Card, cmdType string, nocolorFlag bool) {
}
} else {
var (
boolColor = color.New(globals.GetColorMap()["BoolColor"]).SprintFunc()
keyColor = color.New(globals.GetColorMap()["KeyColor"]).SprintFunc()
numberColor = color.New(globals.GetColorMap()["NumberColor"]).SprintFunc()
stringColor = color.New(globals.GetColorMap()["StringColor"]).SprintFunc()
boolColor = color.New(colorMap["BoolColor"]).SprintFunc()
keyColor = color.New(colorMap["KeyColor"]).SprintFunc()
numberColor = color.New(colorMap["NumberColor"]).SprintFunc()
stringColor = color.New(colorMap["StringColor"]).SprintFunc()
)
fmt.Printf("%s = %s\n", keyColor(" uuid"), stringColor(cardItem.UUID))
fmt.Printf("%s = %s\n", keyColor(" created"), numberColor(cardItem.CreatedAt))
Expand Down
13 changes: 13 additions & 0 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ import (
"fmt"
"os"

"github.com/fatih/color"
"github.com/gdanko/enpass/pkg/enpass"
"github.com/sirupsen/logrus"
)

var (
colorMap = map[string]color.Attribute{
"AliasColor": color.FgHiYellow,
"AnchorColor": color.FgHiYellow,
"BoolColor": color.FgHiYellow,
"KeyColor": color.FgHiCyan,
"NullColor": color.FgHiBlack,
"NumberColor": color.FgHiMagenta,
"StringColor": color.FgHiGreen,
}
)

func GenerateOutput(logger *logrus.Logger, cmdType string, jsonFlag, listFlag, tableFlag, trashedFlag, yamlFlag, nocolorFlag bool, cards *[]enpass.Card) {
if len(*cards) <= 0 {
fmt.Println("No cards found matching the specified criteria")
Expand Down
13 changes: 6 additions & 7 deletions pkg/output/yaml-output.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/fatih/color"
"github.com/gdanko/enpass/globals"
"github.com/gdanko/enpass/pkg/enpass"
"github.com/goccy/go-yaml"
"github.com/goccy/go-yaml/lexer"
Expand Down Expand Up @@ -47,37 +46,37 @@ func doYamlOutput(logger *logrus.Logger, cards []enpass.Card, nocolorFlag bool)
}
p.Alias = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["AliasColor"]),
Prefix: format(colorMap["AliasColor"]),
Suffix: format(color.Reset),
}
}
p.Anchor = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["AnchorColor"]),
Prefix: format(colorMap["AnchorColor"]),
Suffix: format(color.Reset),
}
}
p.Bool = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["BoolColor"]),
Prefix: format(colorMap["BoolColor"]),
Suffix: format(color.Reset),
}
}
p.MapKey = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["KeyColor"]),
Prefix: format(colorMap["KeyColor"]),
Suffix: format(color.Reset),
}
}
p.Number = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["NumberColor"]),
Prefix: format(colorMap["NumberColor"]),
Suffix: format(color.Reset),
}
}
p.String = func() *printer.Property {
return &printer.Property{
Prefix: format(globals.GetColorMap()["StringColor"]),
Prefix: format(colorMap["StringColor"]),
Suffix: format(color.Reset),
}
}
Expand Down

0 comments on commit 4aaea42

Please sign in to comment.