Skip to content

Commit

Permalink
Made suggested changes from gofumpt
Browse files Browse the repository at this point in the history
  • Loading branch information
mjwhitta committed Jan 28, 2024
1 parent 551b433 commit 89a87ca
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 57 deletions.
3 changes: 1 addition & 2 deletions art/art.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ func NewFromJSON(b []byte) (*Art, error) {
return &a, nil
}

// String will convert the Art struct to a string for fmt's print
// functions.
// String will return a string representation of the Art.
func (a *Art) String() string {
var bottom string
var filler string
Expand Down
13 changes: 7 additions & 6 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type ArtCache struct {
// New will return a new ArtCache struct pointer with the specified
// version.
func New(version string) *ArtCache {
var c = &ArtCache{
var c *ArtCache = &ArtCache{
*jsoncfg.New(filepath.Join(cacheDir, cacheFile)),
version,
}
var vers = c.GetString("version")
var vers string = c.GetString("version")

// Initialize defaults
c.SetDefault(map[string]any{}, "art")
Expand All @@ -48,9 +48,9 @@ func New(version string) *ArtCache {
func (c *ArtCache) download() error {
var e error
var f *os.File
var json = "https://github.com/mjwhitta/artty_json"
var json string = "https://github.com/mjwhitta/artty_json"
var res *http.Response
var zipfile = "/archive/refs/heads/main.zip"
var zipfile string = "/archive/refs/heads/main.zip"

// Download zip
if res, e = http.Get(json + zipfile); e != nil {
Expand Down Expand Up @@ -206,15 +206,16 @@ func (c *ArtCache) organize() error {

// Refresh will read any found JSON files and update the art cache.
func (c *ArtCache) Refresh() error {
var arts = map[string]any{}
var addArt filepath.WalkFunc
var arts map[string]any = map[string]any{}
var e error

// Save with initial empty data
c.Set(arts, "art")
c.Set(c.version, "version")
c.Save()

var addArt = func(path string, info os.FileInfo, e error) error {
addArt = func(path string, info os.FileInfo, e error) error {
var a *art.Art

if e != nil {
Expand Down
8 changes: 5 additions & 3 deletions cache/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
)

// Cache related vars
var cacheDir string = pathname.ExpandPath("~/.cache/arTTY")
var cacheFile = "art.json"
var jsonDir = "json"
var (
cacheDir string = pathname.ExpandPath("~/.cache/arTTY")
cacheFile string = "art.json"
jsonDir string = "json"
)

// CustomJSONDir is the location where custom JSON files generated by
// the user are saved.
Expand Down
4 changes: 2 additions & 2 deletions cmd/arTTY/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var flags struct {
}

func ensureOnlyOne() {
var actions = []bool{
var actions []bool = []bool{
flags.cache,
flags.convert != "",
flags.demo,
Expand All @@ -60,7 +60,7 @@ func ensureOnlyOne() {
flags.show,
flags.update,
}
var onlyOne = 0
var onlyOne int = 0

// Ensure only 1 action was specified
for _, action := range actions {
Expand Down
26 changes: 13 additions & 13 deletions generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ func Convert(fn string) error {
// GenerateBash will generate a bash function from an image that can
// be ran to display in a terminal.
func GenerateBash(str string) string {
var bash = []string{
var bash []string = []string{
"function logo() {",
" echo",
}
var r = regexp.MustCompile(`(.{0,54})[^\\]`)
var r *regexp.Regexp = regexp.MustCompile(`(.{0,54})[^\\]`)

for _, l := range strings.Split(str, "\n") {
l = esc.ReplaceAllString(l, "\\e")
Expand All @@ -105,30 +105,30 @@ func GenerateBash(str string) string {
// GenerateGo will generate a go function from an image that can be
// ran to display in a terminal.
func GenerateGo(str string) string {
var rb = []string{
var golang []string = []string{
"func logo() {",
" fmt.Println()",
}
var r = regexp.MustCompile(`(.{0,50})[^\\]{1,3}`)
var r *regexp.Regexp = regexp.MustCompile(`(.{0,50})[^\\]{1,3}`)

for _, l := range strings.Split(str, "\n") {
l = esc.ReplaceAllString(l, "\\x1b")

if len(l) < 52 {
rb = append(rb, " fmt.Println(\""+l+"\")")
golang = append(golang, " fmt.Println(\""+l+"\")")
continue
}

for _, m := range r.FindAllString(l, -1) {
rb = append(rb, " fmt.Print(\""+m+"\")")
golang = append(golang, " fmt.Print(\""+m+"\")")
}

rb = append(rb, " fmt.Println()")
golang = append(golang, " fmt.Println()")
}

rb = append(rb, " fmt.Println()", "}")
golang = append(golang, " fmt.Println()", "}")

return strings.Join(rb, "\n")
return strings.Join(golang, "\n")
}

// GenerateJSON will generate JSON from an image that can be parsed by
Expand Down Expand Up @@ -164,11 +164,11 @@ func GenerateJSON(fn, name string) (string, string, error) {
// GeneratePython will generate a python3 function from an image that
// can be ran to display in a terminal.
func GeneratePython(str string) string {
var py = []string{
var py []string = []string{
"def logo():",
" print()",
}
var r = regexp.MustCompile(`(.{0,57})[^\\]{1,2}`)
var r *regexp.Regexp = regexp.MustCompile(`(.{0,57})[^\\]{1,2}`)

for _, l := range strings.Split(str, "\n") {
l = esc.ReplaceAllString(l, "\\33")
Expand All @@ -195,11 +195,11 @@ func GeneratePython(str string) string {
// GenerateRuby will generate a ruby function from an image that can
// be ran to display in a terminal.
func GenerateRuby(str string) string {
var rb = []string{
var rb []string = []string{
"def logo",
" puts",
}
var r = regexp.MustCompile(`(.{0,54})[^\\]`)
var r *regexp.Regexp = regexp.MustCompile(`(.{0,54})[^\\]`)

for _, l := range strings.Split(str, "\n") {
l = esc.ReplaceAllString(l, "\\e")
Expand Down
6 changes: 4 additions & 2 deletions generator/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package generator

import "regexp"

var esc = regexp.MustCompile(string(rune(0x1b)))
var keys []string
var (
esc = regexp.MustCompile(string(rune(0x1b)))
keys []string
)

func init() {
var key byte = '!'
Expand Down
10 changes: 6 additions & 4 deletions generator/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ func bootstrap(
var legend map[string]string
var pixels []string
var pixelClrs [][]string
var r = regexp.MustCompile(`([^/]+?)(_(\d+)x(\d+))?\.`)
var r *regexp.Regexp
var uniqClrs []string
var width int

r = regexp.MustCompile(`([^/]+?)(_(\d+)x(\d+))?\.`)

if img, e = decodeImage(fn); e != nil {
return "", nil, nil, e
}
Expand Down Expand Up @@ -106,9 +108,9 @@ func generateLegend(
pixelClrs [][]string,
uniqClrs []string,
) ([]string, map[string]string, error) {
var flipLegend = map[string]string{}
var flipLegend map[string]string = map[string]string{}
var idx int
var legend = map[string]string{}
var legend map[string]string = map[string]string{}
var pixels []string
var row string

Expand Down Expand Up @@ -147,7 +149,7 @@ func getPixelInfo(
var a uint32
var b uint32
var clr string
var colorSet = map[string]struct{}{}
var colorSet map[string]struct{} = map[string]struct{}{}
var g uint32
var hInc float64 = 1
var hMax int = img.Bounds().Max.Y
Expand Down
2 changes: 1 addition & 1 deletion globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ var Cache *cache.ArtCache = cache.New(Version)
var devRegex = regexp.MustCompile(`<a href.+>(.+)</a>`)

// Version is the package version
const Version = "1.4.5"
const Version = "1.4.6"
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ module github.com/mjwhitta/artty
go 1.19

require (
github.com/mjwhitta/cli v1.12.0
github.com/mjwhitta/cli v1.12.2
github.com/mjwhitta/errors v1.0.2
github.com/mjwhitta/hilighter v1.11.4
github.com/mjwhitta/jq v1.5.4
github.com/mjwhitta/jsoncfg v1.6.10
github.com/mjwhitta/log v1.6.5
github.com/mjwhitta/hilighter v1.11.7
github.com/mjwhitta/jq v1.5.5
github.com/mjwhitta/jsoncfg v1.6.12
github.com/mjwhitta/log v1.6.7
github.com/mjwhitta/pathname v1.2.5
github.com/mjwhitta/sysinfo v1.5.2
github.com/mjwhitta/where v1.2.9
github.com/mjwhitta/sysinfo v1.5.3
github.com/mjwhitta/where v1.2.10
github.com/stretchr/testify v1.8.4
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mjwhitta/safety v1.11.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/sys v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/mjwhitta/cli v1.12.0 h1:zqJP3qiEtWrDZ3wQodZ/xh+F8JDA3uHksvVCleZ7NM0=
github.com/mjwhitta/cli v1.12.0/go.mod h1:NnyhgKZy85L4PVuZBC+gi2b8bSty0lglc/0jyWAHdUw=
github.com/mjwhitta/cli v1.12.2 h1:yTgigpp3VklFhr/ASBTzdk+Yiq1Qsq9h2h9BGC49Oa8=
github.com/mjwhitta/cli v1.12.2/go.mod h1:NnyhgKZy85L4PVuZBC+gi2b8bSty0lglc/0jyWAHdUw=
github.com/mjwhitta/errors v1.0.2 h1:5QmN4kKfFwYiSsdASDmoi3ie7HesdU7pNDqlhXE9nuU=
github.com/mjwhitta/errors v1.0.2/go.mod h1:VxHM8bLMPVqkvHiYQq4Nq4sjNqPjUtKLhSF2I0wve5U=
github.com/mjwhitta/hilighter v1.11.4 h1:o+F3Zrfg+qeDe+iRl91C+9LyuCLl5bChhcozorltGQg=
github.com/mjwhitta/hilighter v1.11.4/go.mod h1:kZL6BcRWK87Ln/y84Ec5ftRYPyKG1daDi3pDP34o7T0=
github.com/mjwhitta/jq v1.5.4 h1:Qtz19TiwoGvuhswzIX4AK2BnJy+RXQppVSridNDBMqE=
github.com/mjwhitta/jq v1.5.4/go.mod h1:6JdcGqPfEqTmCJq0bEkpQq8JZp9MAxCBeNchR68UmoM=
github.com/mjwhitta/jsoncfg v1.6.10 h1:8SJkA6K6KHCH+MNwdl1os7Zs5xQZnsiI8CAEokL2Se4=
github.com/mjwhitta/jsoncfg v1.6.10/go.mod h1:ctPED06LIU7PZTrvdipoLEvmS+fFMW/lrMJal1R1Fxg=
github.com/mjwhitta/log v1.6.5 h1:Js7V1L2Y3OUAWnykng8NEfSW9lrKOdy1TedLJ2KBCXI=
github.com/mjwhitta/log v1.6.5/go.mod h1:fr5iTTV6OJIzn7fxvjyMbSp/Tq64hgt2K3yXvPjAqq8=
github.com/mjwhitta/hilighter v1.11.7 h1:p8BdAFQo1x4MpxLRb3pILN3Pjkq4ghBJcip8mSCWEUY=
github.com/mjwhitta/hilighter v1.11.7/go.mod h1:M60qv1MgwYoOWiHfKjjD0qSUqGuHhiwIZtbceGmu5p0=
github.com/mjwhitta/jq v1.5.5 h1:GHWCmesiCm69l2BZAtsoTK+YDAGrilL/yizhqpAIikI=
github.com/mjwhitta/jq v1.5.5/go.mod h1:6JdcGqPfEqTmCJq0bEkpQq8JZp9MAxCBeNchR68UmoM=
github.com/mjwhitta/jsoncfg v1.6.12 h1:VIMAdED0J1IzETGyDBpXBfQwlmjQJB1UDwwnOM7DOwI=
github.com/mjwhitta/jsoncfg v1.6.12/go.mod h1:oWik7JqstAnW3YFaUSEhNTRmco2+R0cjUKD3xSM47/I=
github.com/mjwhitta/log v1.6.7 h1:ukO2jBJO4sDSp2xCVNZyNgvDx7ceP1vZBJ4OfayxGdQ=
github.com/mjwhitta/log v1.6.7/go.mod h1:0LQLJQa6KYaAOjc8pkWlbCevM9WqrI4qgA4u54f65So=
github.com/mjwhitta/pathname v1.2.5 h1:wSUZGv+mCrmndNkX2uak8XMZhkXXbgjYG/dMclGKrUE=
github.com/mjwhitta/pathname v1.2.5/go.mod h1:t0k8GIucdXPKhiKyV4aAWtBA9LhLB7mV50DJlhrMpog=
github.com/mjwhitta/safety v1.11.3 h1:dpg6CIQrlrt8yf/cXEdhPI+vRV6g/cRw8uO/TmUK1Mg=
github.com/mjwhitta/safety v1.11.3/go.mod h1:K/LrHWgnJlD5vCe0c9tH4E2prhl4Xpl6nBelXAvuXo0=
github.com/mjwhitta/sysinfo v1.5.2 h1:FCo12LByEDpjzwuf02h54NwUVQ2Q3Joe0J/LetKMX1w=
github.com/mjwhitta/sysinfo v1.5.2/go.mod h1:0yhXYM+Xzrwex6Wk+JJmyFXf6XCO/kxp2cPcy2yCivs=
github.com/mjwhitta/where v1.2.9 h1:dewvKFWqVaXCYZFIPIFP0z23kefaWv9GcErd276Ncpo=
github.com/mjwhitta/where v1.2.9/go.mod h1:YlsPe6W7gdntj6l/oyv6M6/R5AKfkRp5vFDuQN9E07E=
github.com/mjwhitta/sysinfo v1.5.3 h1:lfiRKYCOKYA7wmX4o9NSKjeaPS1y5Uc41XC5M45UEqU=
github.com/mjwhitta/sysinfo v1.5.3/go.mod h1:IAapkvE4g+Hzr733PLyKh3JWkU4zcsKCWVMc2Ud1NnE=
github.com/mjwhitta/where v1.2.10 h1:vxHJh0IavPgQCd2a1060bOfUMklC2aMyhz0UrO074bQ=
github.com/mjwhitta/where v1.2.10/go.mod h1:RJPnB3KocU9KnulwPs6fjNfE4u6qtOoVmpqs4dy3ZYI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down

0 comments on commit 89a87ca

Please sign in to comment.