浏览代码

Refactor f() to a dedicated function colourHash()

Also enable colourHash() for yogurt mode.
morganamilo 7 年之前
父节点
当前提交
181663b7cb
共有 2 个文件被更改,包括 15 次插入14 次删除
  1. 14 3
      print.go
  2. 1 11
      upgrade.go

+ 14 - 3
print.go

@@ -41,7 +41,7 @@ func (q aurQuery) printSearch(start int) {
 			fmt.Println(res.Name)
 			continue
 		}
-		toprint += boldWhiteFg("aur/") + boldYellowFg(res.Name) +
+		toprint += colourHash("aur") + "/" + boldYellowFg(res.Name) +
 			" " + boldCyanFg(res.Version) +
 			" (" + strconv.Itoa(res.NumVotes) + ") "
 
@@ -75,7 +75,7 @@ func (s repoQuery) printSearch() {
 			fmt.Println(res.Name())
 			continue
 		}
-		toprint += boldWhiteFg(res.DB().Name()+"/") + boldYellowFg(res.Name()) +
+		toprint += colourHash(res.DB().Name()) + "/" + boldYellowFg(res.Name()) +
 			" " + boldCyanFg(res.Version()) + " "
 
 		if len(res.Groups().Slice()) != 0 {
@@ -85,7 +85,7 @@ func (s repoQuery) printSearch() {
 		localDb, err := alpmHandle.LocalDb()
 		if err == nil {
 			if _, err = localDb.PkgByName(res.Name()); err == nil {
-				toprint += greenFgBlackBg("Installed")
+				toprint += greenFgBlueBg("Installed")
 			}
 		}
 
@@ -417,3 +417,14 @@ func boldYellowFgBlackBg(in string) string {
 
 	return in
 }
+
+func colourHash(name string) (output string) {
+	if alpmConf.Options&alpm.ConfColor == 0 {
+		return name
+	}
+	var hash = 5381
+	for i := 0; i < len(name); i++ {
+		hash = int(name[i]) + ((hash << 5) + (hash))
+	}
+	return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name)
+}

+ 1 - 11
upgrade.go

@@ -85,18 +85,8 @@ func (u upSlice) Print(start int) {
 	for k, i := range u {
 		left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
 
-		f := func(name string) (output string) {
-			if alpmConf.Options&alpm.ConfColor == 0 {
-				return name
-			}
-			var hash = 5381
-			for i := 0; i < len(name); i++ {
-				hash = int(name[i]) + ((hash << 5) + (hash))
-			}
-			return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name)
-		}
 		fmt.Print(yellowFg(fmt.Sprintf("%2d ", len(u)+start-k-1)))
-		fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name))
+		fmt.Print(colourHash(i.Repository), "/", boldWhiteFg(i.Name))
 
 		w := 70 - len(i.Repository) - len(i.Name) + len(left)
 		fmt.Printf(fmt.Sprintf("%%%ds", w),