wire: improve color output to term by using fatih/color (#186)
This commit is contained in:
@@ -31,6 +31,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
"github.com/google/subcommands"
|
"github.com/google/subcommands"
|
||||||
"github.com/google/wire/internal/wire"
|
"github.com/google/wire/internal/wire"
|
||||||
"github.com/pmezard/go-difflib/difflib"
|
"github.com/pmezard/go-difflib/difflib"
|
||||||
@@ -283,25 +284,18 @@ func (*showCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{
|
|||||||
}
|
}
|
||||||
return keys[i].ImportPath < keys[j].ImportPath
|
return keys[i].ImportPath < keys[j].ImportPath
|
||||||
})
|
})
|
||||||
// ANSI color codes.
|
boldRed := color.New(color.FgRed).Add(color.Bold)
|
||||||
// TODO(light): Possibly use github.com/fatih/color?
|
|
||||||
const (
|
|
||||||
reset = "\x1b[0m"
|
|
||||||
redBold = "\x1b[0;1;31m"
|
|
||||||
blue = "\x1b[0;34m"
|
|
||||||
green = "\x1b[0;32m"
|
|
||||||
)
|
|
||||||
for i, k := range keys {
|
for i, k := range keys {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
outGroups, imports := gather(info, k)
|
outGroups, imports := gather(info, k)
|
||||||
fmt.Printf("%s%s%s\n", redBold, k, reset)
|
boldRed.Println(k)
|
||||||
for _, imp := range sortSet(imports) {
|
for _, imp := range sortSet(imports) {
|
||||||
fmt.Printf("\t%s\n", imp)
|
fmt.Printf("\t%s\n", imp)
|
||||||
}
|
}
|
||||||
for i := range outGroups {
|
for i := range outGroups {
|
||||||
fmt.Printf("%sOutputs given %s:%s\n", blue, outGroups[i].name, reset)
|
color.Blue("Outputs given %s:", outGroups[i].name)
|
||||||
out := make(map[string]token.Pos, outGroups[i].outputs.Len())
|
out := make(map[string]token.Pos, outGroups[i].outputs.Len())
|
||||||
outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {
|
outGroups[i].outputs.Iterate(func(t types.Type, v interface{}) {
|
||||||
switch v := v.(type) {
|
switch v := v.(type) {
|
||||||
@@ -316,7 +310,7 @@ func (*showCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
for _, t := range sortSet(out) {
|
for _, t := range sortSet(out) {
|
||||||
fmt.Printf("\t%s%s%s\n", green, t, reset)
|
color.Green("\t%s", t)
|
||||||
fmt.Printf("\t\tat %v\n", info.Fset.Position(out[t]))
|
fmt.Printf("\t\tat %v\n", info.Fset.Position(out[t]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,7 +323,7 @@ func (*showCmd) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{
|
|||||||
}
|
}
|
||||||
return injectors[i].ImportPath < injectors[j].ImportPath
|
return injectors[i].ImportPath < injectors[j].ImportPath
|
||||||
})
|
})
|
||||||
fmt.Printf("%sInjectors:%s\n", redBold, reset)
|
boldRed.Println("Injectors:")
|
||||||
for _, in := range injectors {
|
for _, in := range injectors {
|
||||||
fmt.Printf("\t%v\n", in)
|
fmt.Printf("\t%v\n", in)
|
||||||
}
|
}
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,8 +1,10 @@
|
|||||||
module github.com/google/wire
|
module github.com/google/wire
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/fatih/color v1.7.0
|
||||||
github.com/google/go-cmp v0.2.0
|
github.com/google/go-cmp v0.2.0
|
||||||
github.com/google/subcommands v1.0.1
|
github.com/google/subcommands v1.0.1
|
||||||
|
github.com/mattn/go-colorable v0.1.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0
|
github.com/pmezard/go-difflib v1.0.0
|
||||||
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b
|
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b
|
||||||
)
|
)
|
||||||
|
|||||||
8
go.sum
8
go.sum
@@ -1,12 +1,20 @@
|
|||||||
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||||
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
|
github.com/google/subcommands v1.0.1 h1:/eqq+otEXm5vhfBrbREPCSVQbvofip6kIz+mX5TUH7k=
|
||||||
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
github.com/google/subcommands v1.0.1/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
|
||||||
|
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||||
|
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
|
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||||
|
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
||||||
|
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s=
|
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b h1:NVD8gBK33xpdqCaZVVtd6OFJp+3dxkXuz7+U7KaVN6s=
|
||||||
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
golang.org/x/tools v0.0.0-20190422233926-fe54fb35175b/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
github.com/fatih/color
|
||||||
github.com/google/subcommands
|
github.com/google/subcommands
|
||||||
github.com/google/wire
|
github.com/google/wire
|
||||||
|
github.com/mattn/go-colorable
|
||||||
|
github.com/mattn/go-isatty
|
||||||
github.com/pmezard/go-difflib
|
github.com/pmezard/go-difflib
|
||||||
|
golang.org/x/sys
|
||||||
golang.org/x/tools
|
golang.org/x/tools
|
||||||
|
|||||||
Reference in New Issue
Block a user