refactoring: settings/colors.go -> style/style.go

This commit is contained in:
Kyoichiro Yamada 2017-04-13 22:49:51 +09:00
parent a54593d7f3
commit 9bc92338ca
10 changed files with 152 additions and 211 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/tockins/interact" "github.com/tockins/interact"
"github.com/tockins/realize/server" "github.com/tockins/realize/server"
"github.com/tockins/realize/settings" "github.com/tockins/realize/settings"
"github.com/tockins/realize/style"
"github.com/tockins/realize/watcher" "github.com/tockins/realize/watcher"
cli "gopkg.in/urfave/cli.v2" cli "gopkg.in/urfave/cli.v2"
) )
@ -96,7 +97,7 @@ func before() error {
// Handle errors // Handle errors
func handle(err error) error { func handle(err error) error {
if err != nil { if err != nil {
fmt.Println(r.Red.Bold(err.Error())) fmt.Println(style.Red.Bold(err.Error()))
os.Exit(1) os.Exit(1)
} }
return nil return nil
@ -178,7 +179,7 @@ func main() {
fmt.Println(p.String("path")) fmt.Println(p.String("path"))
handle(r.Blueprint.Add(p)) handle(r.Blueprint.Add(p))
handle(r.Record(r)) handle(r.Record(r))
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Your project was successfully added.")) fmt.Println(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), style.Green.Bold("Your project was successfully added."))
return nil return nil
}, },
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {
@ -193,8 +194,8 @@ func main() {
Action: func(p *cli.Context) (actErr error) { Action: func(p *cli.Context) (actErr error) {
interact.Run(&interact.Interact{ interact.Run(&interact.Interact{
Before: func(context interact.Context) error { Before: func(context interact.Context) error {
context.SetErr(r.Red.Bold("INVALID INPUT")) context.SetErr(style.Red.Bold("INVALID INPUT"))
context.SetPrfx(color.Output, r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]")) context.SetPrfx(color.Output, style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"))
return nil return nil
}, },
Questions: []*interact.Question{ Questions: []*interact.Question{
@ -203,12 +204,12 @@ func main() {
if _, err := os.Stat(".realize/" + config); err != nil { if _, err := os.Stat(".realize/" + config); err != nil {
d.Skip() d.Skip()
} }
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Would you want to overwrite the existing " + r.Colors.Magenta.Bold("Realize") + " config?", Msg: "Would you want to overwrite the existing " + style.Magenta.Bold("Realize") + " config?",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
val, err := d.Ans().Bool() val, err := d.Ans().Bool()
@ -239,12 +240,12 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Would you want to customize the " + r.Colors.Magenta.Bold("settings") + "?", Msg: "Would you want to customize the " + ("settings") + "?",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
return val return val
@ -253,11 +254,11 @@ func main() {
Subs: []*interact.Question{ Subs: []*interact.Question{
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(0, r.Green.Regular("(os default)")) d.SetDef(0, style.Green.Regular("(os default)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[int]"), Options: style.Yellow.Regular("[int]"),
Msg: "Max number of open files (root required)", Msg: "Max number of open files (root required)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -271,11 +272,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable legacy watch by polling", Msg: "Enable legacy watch by polling",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -285,11 +286,11 @@ func main() {
Subs: []*interact.Question{ Subs: []*interact.Question{
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(1, r.Green.Regular("(1s)")) d.SetDef(1, style.Green.Regular("(1s)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[seconds]"), Options: style.Yellow.Regular("[seconds]"),
Msg: "Set polling interval in seconds", Msg: "Set polling interval in seconds",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -313,11 +314,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable web server", Msg: "Enable web server",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -327,11 +328,11 @@ func main() {
Subs: []*interact.Question{ Subs: []*interact.Question{
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(5001, r.Green.Regular("(5001)")) d.SetDef(5001, style.Green.Regular("(5001)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[int]"), Options: style.Yellow.Regular("[int]"),
Msg: "Server port", Msg: "Server port",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -345,11 +346,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef("localhost", r.Green.Regular("(localhost)")) d.SetDef("localhost", style.Green.Regular("(localhost)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Server host", Msg: "Server host",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -363,11 +364,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Open in the current browser", Msg: "Open in the current browser",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -400,13 +401,13 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(true, r.Green.Regular("(y)")) d.SetDef(true, style.Green.Regular("(y)"))
d.SetEnd("!") d.SetEnd("!")
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Would you want to " + r.Colors.Magenta.Regular("add a new project") + "? (insert '!' to stop)", Msg: "Would you want to " + style.Magenta.Regular("add a new project") + "? (insert '!' to stop)",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
if val { if val {
@ -418,11 +419,11 @@ func main() {
Subs: []*interact.Question{ Subs: []*interact.Question{
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(r.Settings.Wdir(), r.Green.Regular("("+r.Settings.Wdir()+")")) d.SetDef(r.Settings.Wdir(), style.Green.Regular("("+r.Settings.Wdir()+")"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Project name", Msg: "Project name",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -437,11 +438,11 @@ func main() {
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
dir, _ := os.Getwd() dir, _ := os.Getwd()
d.SetDef(dir, r.Green.Regular("("+dir+")")) d.SetDef(dir, style.Green.Regular("("+dir+")"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Project path", Msg: "Project path",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -455,11 +456,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(true, r.Green.Regular("(y)")) d.SetDef(true, style.Green.Regular("(y)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go fmt", Msg: "Enable go fmt",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -473,11 +474,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go test", Msg: "Enable go test",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -491,11 +492,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go generate", Msg: "Enable go generate",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -509,11 +510,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(true, r.Green.Regular("(y)")) d.SetDef(true, style.Green.Regular("(y)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go install", Msg: "Enable go install",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -527,11 +528,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go build", Msg: "Enable go build",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -545,11 +546,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(true, r.Green.Regular("(y)")) d.SetDef(true, style.Green.Regular("(y)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable go run", Msg: "Enable go run",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -563,11 +564,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Customize the watched paths", Msg: "Customize the watched paths",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -584,7 +585,7 @@ func main() {
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Insert a path to watch (insert '!' to stop)", Msg: "Insert a path to watch (insert '!' to stop)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -608,11 +609,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Customize the ignored paths", Msg: "Customize the ignored paths",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -629,7 +630,7 @@ func main() {
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Insert a path to ignore (insert '!' to stop)", Msg: "Insert a path to ignore (insert '!' to stop)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -653,11 +654,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Add additionals arguments", Msg: "Add additionals arguments",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -671,7 +672,7 @@ func main() {
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Insert an argument (insert '!' to stop)", Msg: "Insert an argument (insert '!' to stop)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -695,11 +696,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Add 'before' custom commands", Msg: "Add 'before' custom commands",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -713,7 +714,7 @@ func main() {
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Insert a command (insert '!' to stop)", Msg: "Insert a command (insert '!' to stop)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -737,11 +738,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Add 'after' custom commands", Msg: "Add 'after' custom commands",
Resolve: func(d interact.Context) bool { Resolve: func(d interact.Context) bool {
val, _ := d.Ans().Bool() val, _ := d.Ans().Bool()
@ -755,7 +756,7 @@ func main() {
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[string]"), Options: style.Yellow.Regular("[string]"),
Msg: "Insert a command (insert '!' to stop)", Msg: "Insert a command (insert '!' to stop)",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -779,11 +780,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable watcher files preview", Msg: "Enable watcher files preview",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -797,11 +798,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable file output history", Msg: "Enable file output history",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -815,11 +816,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable file logs history", Msg: "Enable file logs history",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -833,11 +834,11 @@ func main() {
}, },
{ {
Before: func(d interact.Context) error { Before: func(d interact.Context) error {
d.SetDef(false, r.Green.Regular("(n)")) d.SetDef(false, style.Green.Regular("(n)"))
return nil return nil
}, },
Quest: interact.Quest{ Quest: interact.Quest{
Options: r.Yellow.Regular("[y/n]"), Options: style.Yellow.Regular("[y/n]"),
Msg: "Enable file errors history", Msg: "Enable file errors history",
}, },
Action: func(d interact.Context) interface{} { Action: func(d interact.Context) interface{} {
@ -871,7 +872,7 @@ func main() {
}, },
}) })
handle(r.Record(r)) handle(r.Record(r))
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Your configuration was successful.")) fmt.Println(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), style.Green.Bold("Your configuration was successful."))
return nil return nil
}, },
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {
@ -889,7 +890,7 @@ func main() {
Action: func(p *cli.Context) error { Action: func(p *cli.Context) error {
handle(r.Blueprint.Remove(p)) handle(r.Blueprint.Remove(p))
handle(r.Record(r)) handle(r.Record(r))
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Your project was successfully removed.")) fmt.Println(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), style.Green.Bold("Your project was successfully removed."))
return nil return nil
}, },
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {
@ -915,7 +916,7 @@ func main() {
Usage: "Remove realize folder.", Usage: "Remove realize folder.",
Action: func(p *cli.Context) error { Action: func(p *cli.Context) error {
handle(r.Settings.Remove()) handle(r.Settings.Remove())
fmt.Println(r.Yellow.Bold("[")+"REALIZE"+r.Yellow.Bold("]"), r.Green.Bold("Realize folder successfully removed.")) fmt.Println(style.Yellow.Bold("[")+"REALIZE"+style.Yellow.Bold("]"), style.Green.Bold("Realize folder successfully removed."))
return nil return nil
}, },
Before: func(c *cli.Context) error { Before: func(c *cli.Context) error {

View File

@ -1,89 +0,0 @@
package settings
import (
"github.com/fatih/color"
)
// Colors allowed
type Colors struct {
Red
Blue
Yellow
Magenta
Green
}
// Red color
type Red struct{}
// Blue color
type Blue struct{}
// Yellow color
type Yellow struct{}
// Magenta color
type Magenta struct{}
// Green color
type Green struct{}
// Regular font in red
func (c Red) Regular(t ...interface{}) string {
r := color.New(color.FgRed).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Red) Bold(t ...interface{}) string {
r := color.New(color.FgRed, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in blue
func (c Blue) Regular(t ...interface{}) string {
r := color.New(color.FgBlue).SprintFunc()
return r(t...)
}
// Bold font in blue
func (c Blue) Bold(t ...interface{}) string {
r := color.New(color.FgBlue, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in yellow
func (c Yellow) Regular(t ...interface{}) string {
r := color.New(color.FgYellow).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Yellow) Bold(t ...interface{}) string {
r := color.New(color.FgYellow, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in magenta
func (c Magenta) Regular(t ...interface{}) string {
r := color.New(color.FgMagenta).SprintFunc()
return r(t...)
}
// Bold font in magenta
func (c Magenta) Bold(t ...interface{}) string {
r := color.New(color.FgMagenta, color.Bold).SprintFunc()
return r(t...)
}
// Regular font in green
func (c Green) Regular(t ...interface{}) string {
r := color.New(color.FgGreen).SprintFunc()
return r(t...)
}
// Bold font in red
func (c Green) Bold(t ...interface{}) string {
r := color.New(color.FgGreen, color.Bold).SprintFunc()
return r(t...)
}

View File

@ -9,7 +9,6 @@ import (
// Settings defines a group of general settings // Settings defines a group of general settings
type Settings struct { type Settings struct {
Colors `yaml:"-"`
Config `yaml:",inline" json:"config"` Config `yaml:",inline" json:"config"`
Resources `yaml:"resources" json:"resources"` Resources `yaml:"resources" json:"resources"`
Server `yaml:"server,omitempty" json:"server,omitempty"` Server `yaml:"server,omitempty" json:"server,omitempty"`

View File

@ -5,6 +5,8 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/tockins/realize/style"
) )
// Wdir return the current working directory // Wdir return the current working directory
@ -25,7 +27,7 @@ func (s Settings) Validate(err error) error {
// Fatal prints a fatal error with its additional messages // Fatal prints a fatal error with its additional messages
func (s Settings) Fatal(err error, msg ...interface{}) { func (s Settings) Fatal(err error, msg ...interface{}) {
if len(msg) > 0 && err != nil { if len(msg) > 0 && err != nil {
log.Fatalln(s.Red.Regular(msg...), err.Error()) log.Fatalln(style.Red.Regular(msg...), err.Error())
} else if err != nil { } else if err != nil {
log.Fatalln(err.Error()) log.Fatalln(err.Error())
} }

24
style/style.go Normal file
View File

@ -0,0 +1,24 @@
package style
import (
"github.com/fatih/color"
)
type colorBase color.Attribute
func (s colorBase) Regular(a ...interface{}) string {
return color.New(color.Attribute(s)).Sprint(a...)
}
func (s colorBase) Bold(a ...interface{}) string {
return color.New(color.Attribute(s), color.Bold).Sprint(a...)
}
// allowed colors
var (
Red = colorBase(color.FgRed)
Blue = colorBase(color.FgBlue)
Yellow = colorBase(color.FgYellow)
Magenta = colorBase(color.FgMagenta)
Green = colorBase(color.FgGreen)
)

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2" cli "gopkg.in/urfave/cli.v2"
) )
@ -89,49 +90,49 @@ func (h *Blueprint) List() error {
err := h.check() err := h.check()
if err == nil { if err == nil {
for _, val := range h.Projects { for _, val := range h.Projects {
fmt.Println(h.Blue.Bold("[") + strings.ToUpper(val.Name) + h.Blue.Bold("]")) fmt.Println(style.Blue.Bold("[") + strings.ToUpper(val.Name) + style.Blue.Bold("]"))
name := h.Magenta.Bold("[") + strings.ToUpper(val.Name) + h.Magenta.Bold("]") name := style.Magenta.Bold("[") + strings.ToUpper(val.Name) + style.Magenta.Bold("]")
fmt.Println(name, h.Yellow.Regular("Base Path"), ":", h.Magenta.Regular(val.Path)) fmt.Println(name, style.Yellow.Regular("Base Path"), ":", style.Magenta.Regular(val.Path))
fmt.Println(name, h.Yellow.Regular("Fmt"), ":", h.Magenta.Regular(val.Fmt)) fmt.Println(name, style.Yellow.Regular("Fmt"), ":", style.Magenta.Regular(val.Fmt))
fmt.Println(name, h.Yellow.Regular("Generate"), ":", h.Magenta.Regular(val.Generate)) fmt.Println(name, style.Yellow.Regular("Generate"), ":", style.Magenta.Regular(val.Generate))
fmt.Println(name, h.Yellow.Regular("Test"), ":", h.Magenta.Regular(val.Test)) fmt.Println(name, style.Yellow.Regular("Test"), ":", style.Magenta.Regular(val.Test))
fmt.Println(name, h.Yellow.Regular("Install"), ":", h.Magenta.Regular(val.Bin)) fmt.Println(name, style.Yellow.Regular("Install"), ":", style.Magenta.Regular(val.Bin))
fmt.Println(name, h.Yellow.Regular("Build"), ":", h.Magenta.Regular(val.Build)) fmt.Println(name, style.Yellow.Regular("Build"), ":", style.Magenta.Regular(val.Build))
fmt.Println(name, h.Yellow.Regular("Run"), ":", h.Magenta.Regular(val.Run)) fmt.Println(name, style.Yellow.Regular("Run"), ":", style.Magenta.Regular(val.Run))
if len(val.Params) > 0 { if len(val.Params) > 0 {
fmt.Println(name, h.Yellow.Regular("Params"), ":", h.Magenta.Regular(val.Params)) fmt.Println(name, style.Yellow.Regular("Params"), ":", style.Magenta.Regular(val.Params))
} }
fmt.Println(name, h.Yellow.Regular("Watcher"), ":") fmt.Println(name, style.Yellow.Regular("Watcher"), ":")
fmt.Println(name, "\t", h.Yellow.Regular("Preview"), ":", h.Magenta.Regular(val.Watcher.Preview)) fmt.Println(name, "\t", style.Yellow.Regular("Preview"), ":", style.Magenta.Regular(val.Watcher.Preview))
if len(val.Watcher.Exts) > 0 { if len(val.Watcher.Exts) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Extensions"), ":", h.Magenta.Regular(val.Watcher.Exts)) fmt.Println(name, "\t", style.Yellow.Regular("Extensions"), ":", style.Magenta.Regular(val.Watcher.Exts))
} }
if len(val.Watcher.Paths) > 0 { if len(val.Watcher.Paths) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Paths"), ":", h.Magenta.Regular(val.Watcher.Paths)) fmt.Println(name, "\t", style.Yellow.Regular("Paths"), ":", style.Magenta.Regular(val.Watcher.Paths))
} }
if len(val.Watcher.Ignore) > 0 { if len(val.Watcher.Ignore) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Ignored paths"), ":", h.Magenta.Regular(val.Watcher.Ignore)) fmt.Println(name, "\t", style.Yellow.Regular("Ignored paths"), ":", style.Magenta.Regular(val.Watcher.Ignore))
} }
if len(val.Watcher.Scripts) > 0 { if len(val.Watcher.Scripts) > 0 {
fmt.Println(name, "\t", h.Yellow.Regular("Scripts"), ":") fmt.Println(name, "\t", style.Yellow.Regular("Scripts"), ":")
for _, v := range val.Watcher.Scripts { for _, v := range val.Watcher.Scripts {
if v.Command != "" { if v.Command != "" {
fmt.Println(name, "\t\t", h.Magenta.Regular("-"), h.Yellow.Regular("Command"), ":", h.Magenta.Regular(v.Command)) fmt.Println(name, "\t\t", style.Magenta.Regular("-"), style.Yellow.Regular("Command"), ":", style.Magenta.Regular(v.Command))
if v.Path != "" { if v.Path != "" {
fmt.Println(name, "\t\t", h.Yellow.Regular("Path"), ":", h.Magenta.Regular(v.Path)) fmt.Println(name, "\t\t", style.Yellow.Regular("Path"), ":", style.Magenta.Regular(v.Path))
} }
if v.Type != "" { if v.Type != "" {
fmt.Println(name, "\t\t", h.Yellow.Regular("Type"), ":", h.Magenta.Regular(v.Type)) fmt.Println(name, "\t\t", style.Yellow.Regular("Type"), ":", style.Magenta.Regular(v.Type))
} }
} }
} }
} }
fmt.Println(name, h.Yellow.Regular("Streams"), ":") fmt.Println(name, style.Yellow.Regular("Streams"), ":")
fmt.Println(name, "\t", h.Yellow.Regular("Cli Out"), ":", h.Magenta.Regular(val.Streams.CliOut)) fmt.Println(name, "\t", style.Yellow.Regular("Cli Out"), ":", style.Magenta.Regular(val.Streams.CliOut))
fmt.Println(name, "\t", h.Yellow.Regular("File Out"), ":", h.Magenta.Regular(val.Streams.FileOut)) fmt.Println(name, "\t", style.Yellow.Regular("File Out"), ":", style.Magenta.Regular(val.Streams.FileOut))
fmt.Println(name, "\t", h.Yellow.Regular("File Log"), ":", h.Magenta.Regular(val.Streams.FileLog)) fmt.Println(name, "\t", style.Yellow.Regular("File Log"), ":", style.Magenta.Regular(val.Streams.FileLog))
fmt.Println(name, "\t", h.Yellow.Regular("File Err"), ":", h.Magenta.Regular(val.Streams.FileErr)) fmt.Println(name, "\t", style.Yellow.Regular("File Err"), ":", style.Magenta.Regular(val.Streams.FileErr))
} }
return nil return nil
} }

View File

@ -11,6 +11,8 @@ import (
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/tockins/realize/style"
) )
// GoRun is an implementation of the bin execution // GoRun is an implementation of the bin execution
@ -46,7 +48,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()}) p.Buffer.StdLog = append(p.Buffer.StdLog, BufferOut{Time: time.Now(), Text: "Failed to stop: " + err.Error()})
p.Fatal(err, "Failed to stop", ":") p.Fatal(err, "Failed to stop", ":")
} }
msg := fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular("Ended")) msg := fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular("Ended"))
out := BufferOut{Time: time.Now(), Text: "Ended", Type: "Go Run"} out := BufferOut{Time: time.Now(), Text: "Ended", Type: "Go Run"}
p.print("log", out, msg, "") p.print("log", out, msg, "")
wr.Done() wr.Done()
@ -55,11 +57,11 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
stdout, err := build.StdoutPipe() stdout, err := build.StdoutPipe()
stderr, err := build.StderrPipe() stderr, err := build.StderrPipe()
if err != nil { if err != nil {
log.Println(p.Red.Bold(err.Error())) log.Println(style.Red.Bold(err.Error()))
return err return err
} }
if err := build.Start(); err != nil { if err := build.Start(); err != nil {
log.Println(p.Red.Bold(err.Error())) log.Println(style.Red.Bold(err.Error()))
return err return err
} }
close(runner) close(runner)
@ -70,7 +72,7 @@ func (p *Project) goRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
for output.Scan() { for output.Scan() {
select { select {
default: default:
msg := fmt.Sprintln(p.pname(p.Name, 3), ":", p.Blue.Regular(output.Text())) msg := fmt.Sprintln(p.pname(p.Name, 3), ":", style.Blue.Regular(output.Text()))
if isError { if isError {
out := BufferOut{Time: time.Now(), Text: output.Text(), Type: "Go Run"} out := BufferOut{Time: time.Now(), Text: output.Text(), Type: "Go Run"}
p.print("error", out, msg, "") p.print("error", out, msg, "")

View File

@ -22,7 +22,6 @@ type pollWatcher struct {
// Log struct // Log struct
type logWriter struct { type logWriter struct {
settings.Colors
} }
// Blueprint struct contains a projects list // Blueprint struct contains a projects list

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/tockins/realize/style"
cli "gopkg.in/urfave/cli.v2" cli "gopkg.in/urfave/cli.v2"
) )
@ -43,5 +44,5 @@ func inArray(str string, list []string) bool {
// Rewrite the layout of the log timestamp // Rewrite the layout of the log timestamp
func (w logWriter) Write(bytes []byte) (int, error) { func (w logWriter) Write(bytes []byte) (int, error) {
return fmt.Print(w.Yellow.Regular("[") + time.Now().Format("15:04:05") + w.Yellow.Regular("]") + string(bytes)) return fmt.Print(style.Yellow.Regular("[") + time.Now().Format("15:04:05") + style.Yellow.Regular("]") + string(bytes))
} }

View File

@ -15,6 +15,7 @@ import (
"time" "time"
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/tockins/realize/style"
) )
var msg string var msg string
@ -72,7 +73,7 @@ func (p *Project) watchByPolling() {
} }
p.LastChangedOn = time.Now().Truncate(time.Second) p.LastChangedOn = time.Now().Truncate(time.Second)
// repeat the initial cycle // repeat the initial cycle
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file)) msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file))
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file} out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
p.print("log", out, msg, "") p.print("log", out, msg, "")
@ -89,7 +90,7 @@ func (p *Project) watchByPolling() {
base := filepath.Join(p.base, dir) base := filepath.Join(p.base, dir)
if _, err := os.Stat(base); err == nil { if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, walk); err != nil { if err := filepath.Walk(base, walk); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular(err.Error())) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error()} out = BufferOut{Time: time.Now(), Text: err.Error()}
p.print("error", out, msg, "") p.print("error", out, msg, "")
} }
@ -148,7 +149,7 @@ func (p *Project) watchByNotify() {
} }
p.LastChangedOn = time.Now().Truncate(time.Second) p.LastChangedOn = time.Now().Truncate(time.Second)
// repeat the initial cycle // repeat the initial cycle
msg = fmt.Sprintln(p.pname(p.Name, 4), ":", p.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), p.Magenta.Bold(file)) msg = fmt.Sprintln(p.pname(p.Name, 4), ":", style.Magenta.Bold(strings.ToUpper(ext[1:])+" changed"), style.Magenta.Bold(file))
out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file} out = BufferOut{Time: time.Now(), Text: strings.ToUpper(ext[1:]) + " changed " + file}
p.print("log", out, msg, "") p.print("log", out, msg, "")
@ -161,7 +162,7 @@ func (p *Project) watchByNotify() {
} }
} }
case err := <-watcher.Errors: case err := <-watcher.Errors:
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Regular(err.Error())) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error()} out = BufferOut{Time: time.Now(), Text: err.Error()}
p.print("error", out, msg, "") p.print("error", out, msg, "")
case <-exit: case <-exit:
@ -207,13 +208,13 @@ func (p *Project) watch(watcher watcher) error {
base := filepath.Join(p.base, dir) base := filepath.Join(p.base, dir)
if _, err := os.Stat(base); err == nil { if _, err := os.Stat(base); err == nil {
if err := filepath.Walk(base, walk); err != nil { if err := filepath.Walk(base, walk); err != nil {
log.Println(p.Red.Bold(err.Error())) log.Println(style.Red.Bold(err.Error()))
} }
} else { } else {
return errors.New(base + " path doesn't exist") return errors.New(base + " path doesn't exist")
} }
} }
msg = fmt.Sprintln(p.pname(p.Name, 1), ":", p.Blue.Bold("Watching"), p.Magenta.Bold(files), "file/s", p.Magenta.Bold(folders), "folder/s") msg = fmt.Sprintln(p.pname(p.Name, 1), ":", style.Blue.Bold("Watching"), style.Magenta.Bold(files), "file/s", style.Magenta.Bold(folders), "folder/s")
out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(files, 10) + " files/s " + strconv.FormatInt(folders, 10) + " folder/s"} out = BufferOut{Time: time.Now(), Text: "Watching " + strconv.FormatInt(files, 10) + " files/s " + strconv.FormatInt(folders, 10) + " folder/s"}
p.print("log", out, msg, "") p.print("log", out, msg, "")
return nil return nil
@ -226,11 +227,11 @@ func (p *Project) install() error {
log.Println(p.pname(p.Name, 1), ":", "Installing..") log.Println(p.pname(p.Name, 1), ":", "Installing..")
stream, err := p.goInstall() stream, err := p.goInstall()
if err != nil { if err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Install"), p.Red.Regular(err.Error())) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Install"), style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream} out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Install", Stream: stream}
p.print("error", out, msg, stream) p.print("error", out, msg, stream)
} else { } else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Installed")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Installed")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Installed after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"} out = BufferOut{Time: time.Now(), Text: "Installed after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, stream) p.print("log", out, msg, stream)
} }
@ -249,7 +250,7 @@ func (p *Project) run(channel chan bool, wr *sync.WaitGroup) {
for { for {
select { select {
case <-runner: case <-runner:
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Has been run")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Has been run")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Has been run after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"} out = BufferOut{Time: time.Now(), Text: "Has been run after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, "") p.print("log", out, msg, "")
return return
@ -265,11 +266,11 @@ func (p *Project) build() error {
log.Println(p.pname(p.Name, 1), ":", "Building..") log.Println(p.pname(p.Name, 1), ":", "Building..")
stream, err := p.goBuild() stream, err := p.goBuild()
if err != nil { if err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Build"), p.Red.Regular(err.Error())) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Build"), style.Red.Regular(err.Error()))
out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream} out = BufferOut{Time: time.Now(), Text: err.Error(), Type: "Go Build", Stream: stream}
p.print("error", out, msg, stream) p.print("error", out, msg, stream)
} else { } else {
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Regular("Builded")+" after", p.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Regular("Builded")+" after", style.Magenta.Regular(big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3), " s"))
out = BufferOut{Time: time.Now(), Text: "Builded after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"} out = BufferOut{Time: time.Now(), Text: "Builded after " + big.NewFloat(float64(time.Since(start).Seconds())).Text('f', 3) + " s"}
p.print("log", out, msg, stream) p.print("log", out, msg, stream)
} }
@ -282,7 +283,7 @@ func (p *Project) build() error {
func (p *Project) fmt(path string) error { func (p *Project) fmt(path string) error {
if p.Fmt && strings.HasSuffix(path, ".go") { if p.Fmt && strings.HasSuffix(path, ".go") {
if stream, err := p.goTools(p.base, "gofmt", "-s", "-w", "-e", path); err != nil { if stream, err := p.goTools(p.base, "gofmt", "-s", "-w", "-e", path); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Fmt"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path)) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Fmt"), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Fmt", Stream: stream} out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Fmt", Stream: stream}
p.print("error", out, msg, stream) p.print("error", out, msg, stream)
return err return err
@ -295,7 +296,7 @@ func (p *Project) fmt(path string) error {
func (p *Project) generate(path string) error { func (p *Project) generate(path string) error {
if p.Generate { if p.Generate {
if stream, err := p.goTools(path, "go", "generate"); err != nil { if stream, err := p.goTools(path, "go", "generate"); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Generate"), p.Red.Regular("there are some errors in"), ":", p.Magenta.Bold(path)) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Generate"), style.Red.Regular("there are some errors in"), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Generate", Stream: stream} out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Generate", Stream: stream}
p.print("error", out, msg, stream) p.print("error", out, msg, stream)
return err return err
@ -308,7 +309,7 @@ func (p *Project) generate(path string) error {
func (p *Project) test(path string) error { func (p *Project) test(path string) error {
if p.Test { if p.Test {
if stream, err := p.goTools(path, "go", "test"); err != nil { if stream, err := p.goTools(path, "go", "test"); err != nil {
msg = fmt.Sprintln(p.pname(p.Name, 2), ":", p.Red.Bold("Go Test"), p.Red.Regular("there are some errors in "), ":", p.Magenta.Bold(path)) msg = fmt.Sprintln(p.pname(p.Name, 2), ":", style.Red.Bold("Go Test"), style.Red.Regular("there are some errors in "), ":", style.Magenta.Bold(path))
out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Test", Stream: stream} out = BufferOut{Time: time.Now(), Text: "there are some errors in", Path: path, Type: "Go Test", Stream: stream}
p.print("error", out, msg, stream) p.print("error", out, msg, stream)
return err return err
@ -322,7 +323,7 @@ func (p *Project) cmd(flag string) {
for _, cmd := range p.Watcher.Scripts { for _, cmd := range p.Watcher.Scripts {
if strings.ToLower(cmd.Type) == flag { if strings.ToLower(cmd.Type) == flag {
errors, logs := p.command(cmd) errors, logs := p.command(cmd)
msg = fmt.Sprintln(p.pname(p.Name, 5), ":", p.Green.Bold("Command"), p.Green.Bold("\"")+cmd.Command+p.Green.Bold("\"")) msg = fmt.Sprintln(p.pname(p.Name, 5), ":", style.Green.Bold("Command"), style.Green.Bold("\"")+cmd.Command+style.Green.Bold("\""))
out = BufferOut{Time: time.Now(), Text: cmd.Command, Type: flag} out = BufferOut{Time: time.Now(), Text: cmd.Command, Type: flag}
if logs != "" { if logs != "" {
p.print("log", out, msg, "") p.print("log", out, msg, "")
@ -336,7 +337,7 @@ func (p *Project) cmd(flag string) {
p.print("log", out, "", msg) p.print("log", out, "", msg)
} }
if errors != "" { if errors != "" {
msg = fmt.Sprintln(p.Red.Regular(errors)) msg = fmt.Sprintln(style.Red.Regular(errors))
out = BufferOut{Time: time.Now(), Text: errors, Type: flag} out = BufferOut{Time: time.Now(), Text: errors, Type: flag}
p.print("error", out, "", msg) p.print("error", out, "", msg)
} }
@ -369,19 +370,19 @@ func (p *Project) routines(channel chan bool, wr *sync.WaitGroup) {
func (p *Project) pname(name string, color int) string { func (p *Project) pname(name string, color int) string {
switch color { switch color {
case 1: case 1:
name = p.Yellow.Regular("[") + strings.ToUpper(name) + p.Yellow.Regular("]") name = style.Yellow.Regular("[") + strings.ToUpper(name) + style.Yellow.Regular("]")
break break
case 2: case 2:
name = p.Yellow.Regular("[") + p.Red.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]") name = style.Yellow.Regular("[") + style.Red.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break break
case 3: case 3:
name = p.Yellow.Regular("[") + p.Blue.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]") name = style.Yellow.Regular("[") + style.Blue.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break break
case 4: case 4:
name = p.Yellow.Regular("[") + p.Magenta.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]") name = style.Yellow.Regular("[") + style.Magenta.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break break
case 5: case 5:
name = p.Yellow.Regular("[") + p.Green.Bold(strings.ToUpper(name)) + p.Yellow.Regular("]") name = style.Yellow.Regular("[") + style.Green.Bold(strings.ToUpper(name)) + style.Yellow.Regular("]")
break break
} }
return name return name