From 80143b453d94c40ec74453754ce7f58a42278168 Mon Sep 17 00:00:00 2001 From: Kaushal Subedi Date: Sun, 25 Oct 2015 15:23:59 -0600 Subject: added colors to console output --- main.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 785494b..93d86e2 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "strings" "github.com/codegangsta/cli" + "github.com/mgutz/ansi" "golang.org/x/tools/go/ast/astutil" ) @@ -69,6 +70,15 @@ func RunApp(dir string, from string, to string, c *cli.Context) { } func ProcessFile(filePath string, from string, to string) { + + //Colors to be used on the console + red := ansi.ColorCode("red+bh") + white := ansi.ColorCode("white+bh") + greenUnderline := ansi.ColorCode("green+buh") + blackOnWhite := ansi.ColorCode("black+b:white+h") + //Reset the color + reset := ansi.ColorCode("reset") + // If the file is a go file scan it if path.Ext(filePath) == ".go" { // New FileSet to parse the go file to @@ -100,7 +110,7 @@ func ProcessFile(filePath string, from string, to string) { // Join the path of the import package with the remainder from the old one after removing the old import package replacePackage := path.Join(to, strings.Replace(importString, from, "", -1)) - fmt.Println("Updating import " + importString + " from file " + filePath + " to " + replacePackage) + fmt.Println(red + "Updating import " + importString + " from file " + reset + white + filePath + reset + red + " to " + reset + white + replacePackage + reset) // Remove the old import and replace it with the replacement astutil.DeleteImport(fSet, file, importString) @@ -116,10 +126,9 @@ func ProcessFile(filePath string, from string, to string) { printer.Fprint(&outputBuffer, fSet, file) ioutil.WriteFile(filePath, outputBuffer.Bytes(), os.ModePerm) - - fmt.Printf("File "+filePath+" saved after %d changes.\n", numChanges) + fmt.Printf(blackOnWhite+"File "+filePath+" saved after %d changes."+reset+"\n", numChanges) } else { - fmt.Println("No changes needed on file " + filePath) + fmt.Println(greenUnderline + "No changes needed on file " + filePath + reset) } } } -- cgit v1.2.3