Skip to content

Commit

Permalink
Merge pull request #25 from FollowTheProcess/feat/error-style-tweak
Browse files Browse the repository at this point in the history
Make the error default style nicer
  • Loading branch information
FollowTheProcess committed Jun 11, 2022
2 parents b33c5e6 + d079893 commit 823aeb3
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Set up Go 1.17
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.18

- name: Checkout Code
uses: actions/checkout@v3
Expand All @@ -30,10 +30,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.17
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.18

- name: Checkout Code
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
)

require (
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE=
github.com/matryer/is v1.4.0/go.mod h1:8I/i5uYgLzgsgEloJE1U6xx5HkBQpAZvepWuujKwMRU=
github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d h1:Zu/JngovGLVi6t2J3nmAf3AoTDwuzw85YZ3b9o4yU7s=
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
22 changes: 14 additions & 8 deletions msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,15 @@ func (p *Printer) Swarnf(format string, a ...interface{}) string {

// Fail prints an error message.
func (p *Printer) Fail(text string) {
fail := color.New(p.ColorFail)
failStyle := color.New(p.ColorFail).Add(color.Bold)
messageStyle := color.New(color.FgHiWhite, color.Bold)

if p.SymbolWarn != "" {
text = fmt.Sprintf("%s %s", p.SymbolFail, text)
text = fmt.Sprintf("%s: %s", failStyle.Sprint("Error"), messageStyle.Sprint(text))

if p.SymbolFail != "" {
text = fmt.Sprintf("%s %s", failStyle.Sprint(p.SymbolFail), text)
}
fail.Fprintln(p.Out, text)
fmt.Fprintln(p.Out, text)
}

// Failf prints a formatted error message.
Expand All @@ -154,12 +157,15 @@ func (p *Printer) Failf(format string, a ...interface{}) {

// Sfail is like Fail but returns a string rather than printing it.
func (p *Printer) Sfail(text string) string {
fail := color.New(p.ColorFail)
failStyle := color.New(p.ColorFail).Add(color.Bold)
messageStyle := color.New(color.FgHiWhite, color.Bold)

if p.SymbolWarn != "" {
text = fmt.Sprintf("%s %s", p.SymbolFail, text)
text = fmt.Sprintf("%s: %s", failStyle.Sprint("Error"), messageStyle.Sprint(text))

if p.SymbolFail != "" {
text = fmt.Sprintf("%s %s", failStyle.Sprint(p.SymbolFail), text)
}
return fail.Sprint(text)
return text
}

// Sfailf returns a formatted error string.
Expand Down
16 changes: 8 additions & 8 deletions msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestPrinter_Fail(t *testing.T) {
is := is.New(t)
rb, p := setup()

want := fmt.Sprintf("%s I'm a Failure\n", defaultFailSymbol)
want := fmt.Sprintf("%s Error: I'm a Failure\n", defaultFailSymbol)
p.Fail("I'm a Failure")
is.Equal(rb.String(), want)
}
Expand All @@ -196,7 +196,7 @@ func TestPrinter_FailSymbol(t *testing.T) {
// Change the symbol
p.SymbolFail = "🤬"

want := "🤬 I'm a Failure\n"
want := "🤬 Error: I'm a Failure\n"
p.Fail("I'm a Failure")
is.Equal(rb.String(), want)
}
Expand All @@ -205,7 +205,7 @@ func TestPrinter_Sfail(t *testing.T) {
is := is.New(t)
_, p := setup()

want := fmt.Sprintf("%s I'm a Sfail", defaultFailSymbol)
want := fmt.Sprintf("%s Error: I'm a Sfail", defaultFailSymbol)
got := p.Sfail("I'm a Sfail")
is.Equal(got, want)
}
Expand All @@ -217,7 +217,7 @@ func TestPrinter_SfailSymbol(t *testing.T) {
// Change the symbol
p.SymbolFail = "🤬"

want := "🤬 I'm a Sfail"
want := "🤬 Error: I'm a Sfail"
got := p.Sfail("I'm a Sfail")
is.Equal(got, want)
}
Expand All @@ -228,8 +228,8 @@ func TestPrinter_Sfailf(t *testing.T) {

about := "something"

want := fmt.Sprintf("%s Error about: %s", defaultFailSymbol, about)
got := p.Sfailf("Error about: %s", about)
want := fmt.Sprintf("%s Error: Something about: %s", defaultFailSymbol, about)
got := p.Sfailf("Something about: %s", about)
is.Equal(got, want)
}

Expand All @@ -239,8 +239,8 @@ func TestPrinter_Failf(t *testing.T) {

about := "something"

want := fmt.Sprintf("%s Error: %s\n", defaultFailSymbol, about)
p.Failf("Error: %s", about)
want := fmt.Sprintf("%s Error: Something: %s\n", defaultFailSymbol, about)
p.Failf("Something: %s", about)
is.Equal(rb.String(), want)
}

Expand Down

0 comments on commit 823aeb3

Please sign in to comment.