diff options
| author | Kaushal Subedi | 2015-10-25 15:23:59 -0600 | 
|---|---|---|
| committer | Kaushal Subedi | 2015-10-25 15:23:59 -0600 | 
| commit | 80143b453d94c40ec74453754ce7f58a42278168 (patch) | |
| tree | 3653f270afa798650ce116c39ecdf4666e5a2194 | |
| parent | 3c26cf9dc98484a7b519db60a9a34e9969868d03 (diff) | |
| download | gomove-0.0.1-pre-release.tar.bz2 | |
added colors to console output0.0.1-pre-release
| -rw-r--r-- | main.go | 17 | 
1 files changed, 13 insertions, 4 deletions
| @@ -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)  		}  	}  } | 
