func installToolchains(langs []toolchainInstaller) error { var notInstalled []string for _, l := range langs { fmt.Println(brush.Cyan(l.name + " " + strings.Repeat("=", 78-len(l.name))).String()) if err := l.fn(); err != nil { if err2, ok := err.(skippedToolchain); ok { fmt.Printf("%s\n", brush.Yellow(err2.Error())) } else { fmt.Printf("%s\n", brush.Red(fmt.Sprintf("failed to install/upgrade %s toolchain: %s", l.name, err))) } notInstalled = append(notInstalled, l.name) // Continue here because we attempt to install // all the toolchains. continue } fmt.Println(brush.Green("OK! Installed/upgraded " + l.name + " toolchain").String()) fmt.Println(brush.Cyan(strings.Repeat("=", 80)).String()) fmt.Println() } if len(notInstalled) != 0 { return errors.New(brush.Red(fmt.Sprintf("The following toolchains were not installed:\n%s", strings.Join(notInstalled, "\n"))).String()) } return nil }
func main() { // Default Brush are available for your convenience. You can invoke // them directly fmt.Printf("This is %s\n", brush.Red("red")) // or you can create new ones! weird := color.NewBrush(color.PurplePaint, color.CyanPaint) fmt.Printf("This color is %s\n", weird("weird")) // Create a Style, which has convenience methods redBg := color.NewStyle(color.RedPaint, color.YellowPaint) // Style.WithForeground or WithBackground returns a new Style, with the applied // Paint. Styles are immutable so the original one is left unchanged greenFg := redBg.WithForeground(color.GreenPaint) // Style.Brush gives you a Brush that you can invoke directly to colorize strings. green := greenFg.Brush() fmt.Printf("This is %s but not really\n", green("kind of green")) // You can use it with all sorts of things sout := log.New(os.Stdout, "["+brush.Green("OK").String()+"]\t", log.LstdFlags) serr := log.New(os.Stderr, "["+brush.Red("OMG").String()+"]\t", log.LstdFlags) sout.Printf("Everything was going %s until...", brush.Cyan("fine")) serr.Printf("%s killed %s !!!", brush.Red("Locke"), brush.Blue("Jacob")) }
func Help(format string, args ...interface{}) { if PureMode { help(format, args...) } fmt.Printf("gopm %s %s\n", brush.Cyan("HELP"), fmt.Sprintf(format, args...)) os.Exit(2) }
func (c *ToolchainInstallStdCmd) Execute(args []string) error { fmt.Println(brush.Cyan("Installing/upgrading standard toolchains...")) fmt.Println() var is []toolchainInstaller OuterLoop: for name, installer := range stdToolchains { for _, skip := range c.Skip { if strings.EqualFold(name, skip) { fmt.Println(brush.Yellow(fmt.Sprintf("Skipping installation of %s", installer.name))) continue OuterLoop } } is = append(is, installer) } return installToolchains(is) }
"os" ) var stdout_std_logger *log.Logger var stderr_std_logger *log.Logger var prefixes = map[int]string{ DEBUG: "[debug] ", INFO: "[info] ", WARNING: "[warning] ", ERROR: "[error] ", FATAL: "[fatal] ", } var coloredPrefixes = map[int]string{ DEBUG: brush.Cyan("[debug] ").String(), INFO: brush.Green("[info] ").String(), WARNING: brush.Yellow("[warning] ").String(), ERROR: brush.Red("[error] ").String(), FATAL: brush.DarkRed("[fatal] ").String(), } type Stdout struct { MinLevel int Colored bool } func init() { stdout_std_logger = log.New(os.Stdout, "", log.Ldate|log.Ltime|log.Lshortfile) stderr_std_logger = log.New(os.Stderr, "", log.Ldate|log.Ltime|log.Lshortfile) }