Browse Source

colorful output

pull/103/head
Unknown 12 years ago
parent
commit
4868a429f5
  1. 4
      build.go
  2. 6
      check.go
  3. BIN
      gopm
  4. 2
      i18n/en-US/prompt.txt
  5. 2
      i18n/zh-CN/prompt.txt
  6. 10
      install.go
  7. 6
      remove.go
  8. 7
      utils/utils.go

4
build.go

@ -57,13 +57,13 @@ func runBuild(cmd *Command, args []string) {
if utils.IsExist(wd + "/" + proName) {
err := os.Remove(wd + "/" + proName)
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: %s\n", promptMsg["RemoveFile"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", promptMsg["RemoveFile"]), err))
return
}
}
err := os.Rename(v+"/bin/"+proName, wd+"/"+proName)
if err == nil {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["MovedFile"]), v, wd)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("<SUCCESS>$ %s\n", promptMsg["MovedFile"]), v, wd))
// Check if need to run program.
if cmdBuild.Flags["-r"] {
cmdArgs = make([]string, 0)

6
check.go

@ -52,7 +52,7 @@ func runCheck(cmd *Command, args []string) {
importPath := wd[len(gopath):]
imports, err := checkImportsByRoot(wd+"/", importPath)
if err != nil {
fmt.Printf(fmt.Sprintf("runCheck -> %s\n", promptMsg["CheckImports"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("runCheck -> %s\n", promptMsg["CheckImports"]), err))
return
}
@ -98,7 +98,7 @@ func runCheck(cmd *Command, args []string) {
}
installGOPATH = utils.GetBestMatchGOPATH(appPath)
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH))
// Generate temporary nodes.
nodes := make([]*doc.Node, len(uninstallList))
for i := range nodes {
@ -166,7 +166,7 @@ func checkIsExistWithVCS(path string) bool {
// Check if only has VCS folder.
dirs, err := utils.GetDirsInfo(path)
if err != nil {
fmt.Printf("checkIsExistWithVCS -> [ %s ]", err)
utils.ColorPrint(fmt.Sprintf("[ERROR] checkIsExistWithVCS -> [ %s ]", err))
return false
}

BIN
gopm

Binary file not shown.

2
i18n/en-US/prompt.txt

@ -13,7 +13,7 @@ ErrNoMatch=Unsupported project hosting.
PackageNotFound=Cannot find package: %s.
CheckImports=Fail to check dependencies[ %s ]
MovedFile=SUCCESS: Moved file from $GOPATH(%s) to current directory(%s).
MovedFile=Moved file from $GOPATH(%s) to current directory(%s).
PureDownload=You enabled download with version control.
DownloadOnly=You enabled download without installing.
DownloadExDeps=You enabled download dependencies in example.

2
i18n/zh-CN/prompt.txt

@ -13,7 +13,7 @@ ErrNoMatch=不被支持的源代码托管平台.
PackageNotFound=无法找到包: %s.
CheckImports=一百遍检查失败 [ %s ]
MovedFile=SUCCESS: 成功将文件从 $GOPATH(%s) 移动至当前目录 (%s).
MovedFile=成功将文件从 $GOPATH(%s) 移动至当前目录 (%s).
PureDownload=已激活版本控制下载模式.
DownloadOnly=已激活无安装模式.
DownloadExDeps=已激活下载示例代码依赖.

10
install.go

@ -120,7 +120,7 @@ func runInstall(cmd *Command, args []string) {
checkVCSTool()
installGOPATH = utils.GetBestMatchGOPATH(appPath)
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["DownloadPath"]), installGOPATH))
// Generate temporary nodes.
nodes := make([]*doc.Node, len(args))
@ -153,13 +153,13 @@ func runInstall(cmd *Command, args []string) {
// Save local nodes to file.
fw, err := os.Create(appPath + "data/nodes.json")
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["OpenFile"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", promptMsg["OpenFile"]), err))
return
}
defer fw.Close()
fbytes, err := json.MarshalIndent(&localNodes, "", "\t")
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: runInstall -> %s\n", promptMsg["ParseJSON"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runInstall -> %s\n", promptMsg["ParseJSON"]), err))
return
}
fw.Write(fbytes)
@ -204,7 +204,7 @@ func downloadPackages(nodes []*doc.Node) {
bnodes := checkLocalBundles(n.ImportPath[:l-2])
if len(bnodes) > 0 {
// Check with users if continue.
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2]))
for _, bn := range bnodes {
fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value)
}
@ -293,7 +293,7 @@ func downloadPackage(node *doc.Node) (*doc.Node, []string) {
imports, err := pureDownload(node)
if err != nil {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["DownloadError"]), node.ImportPath, err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] %s\n", promptMsg["DownloadError"]), node.ImportPath, err))
return nil, nil
}

6
remove.go

@ -48,13 +48,13 @@ func runRemove(cmd *Command, args []string) {
// Save local nodes to file.
fw, err := os.Create(appPath + "data/nodes.json")
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: runRemove -> %s\n", promptMsg["OpenFile"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", promptMsg["OpenFile"]), err))
return
}
defer fw.Close()
fbytes, err := json.MarshalIndent(&localNodes, "", "\t")
if err != nil {
fmt.Printf(fmt.Sprintf("ERROR: runRemove -> %s\n", promptMsg["ParseJSON"]), err)
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("[ERROR] runRemove -> %s\n", promptMsg["ParseJSON"]), err))
return
}
fw.Write(fbytes)
@ -72,7 +72,7 @@ func removePackages(nodes []*doc.Node) {
bnodes := checkLocalBundles(n.ImportPath[:l-2])
if len(bnodes) > 0 {
// Check with users if continue.
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2])
utils.ColorPrint(fmt.Sprintf(fmt.Sprintf("%s\n", promptMsg["BundleInfo"]), n.ImportPath[:l-2]))
for _, bn := range bnodes {
fmt.Printf("[%s] -> %s: %s.\n", bn.ImportPath, bn.Type, bn.Value)
}

7
utils/utils.go

@ -15,7 +15,6 @@ import (
const (
PureStartColor = "\033[%dm"
StartColor = "(\033[%dm"
Gray = uint8(90)
Red = uint8(91)
Green = uint8(92)
@ -31,10 +30,12 @@ const (
func ColorPrint(log string) {
// Make sure it's not windows.
if runtime.GOOS != "windows" {
log = strings.Replace(log, "[", fmt.Sprintf(StartColor, Red), -1)
log = strings.Replace(log, "[", fmt.Sprintf("[\033[%dm", Red), -1)
log = strings.Replace(log, "]", EndColor+"]", -1)
log = strings.Replace(log, "(", fmt.Sprintf(StartColor, Green), -1)
log = strings.Replace(log, "(", fmt.Sprintf("(\033[%dm", Yellow), -1)
log = strings.Replace(log, ")", EndColor+")", -1)
log = strings.Replace(log, "<", fmt.Sprintf("[\033[%dm", Green), -1)
log = strings.Replace(log, ">$", EndColor+"]", -1)
}
fmt.Print(log)
}

Loading…
Cancel
Save