Browse Source

fix(color): remove duplicate colors

jguer 4 years ago
parent
commit
c305e1c196
8 changed files with 57 additions and 100 deletions
  1. 2 2
      clean.go
  2. 2 2
      cmd.go
  3. 2 2
      config.go
  4. 5 5
      download.go
  5. 15 15
      install.go
  6. 27 70
      print.go
  7. 3 3
      upgrade.go
  8. 1 1
      vcs.go

+ 2 - 2
clean.go

@@ -216,7 +216,7 @@ func cleanAfter(bases []dep.Base) {
 			continue
 		}
 
-		text.OperationInfoln(gotext.Get("Cleaning (%d/%d): %s", i+1, len(bases), cyan(dir)))
+		text.OperationInfoln(gotext.Get("Cleaning (%d/%d): %s", i+1, len(bases), text.Cyan(dir)))
 
 		_, stderr, err := capture(passToGit(dir, "reset", "--hard", "HEAD"))
 		if err != nil {
@@ -232,7 +232,7 @@ func cleanAfter(bases []dep.Base) {
 func cleanBuilds(bases []dep.Base) {
 	for i, base := range bases {
 		dir := filepath.Join(config.BuildDir, base.Pkgbase())
-		text.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(bases), cyan(dir)))
+		text.OperationInfoln(gotext.Get("Deleting (%d/%d): %s", i+1, len(bases), text.Cyan(dir)))
 		if err := os.RemoveAll(dir); err != nil {
 			fmt.Fprintln(os.Stderr, err)
 		}

+ 2 - 2
cmd.go

@@ -433,10 +433,10 @@ func syncList(cmdArgs *settings.Arguments, dbExecutor db.Executor) error {
 			if cmdArgs.ExistsArg("q", "quiet") {
 				fmt.Println(name)
 			} else {
-				fmt.Printf("%s %s %s", magenta("aur"), bold(name), bold(green(gotext.Get("unknown-version"))))
+				fmt.Printf("%s %s %s", text.Magenta("aur"), text.Bold(name), text.Bold(text.Green(gotext.Get("unknown-version"))))
 
 				if dbExecutor.LocalPackage(name) != nil {
-					fmt.Print(bold(blue(gotext.Get(" [Installed]"))))
+					fmt.Print(text.Bold(text.Blue(gotext.Get(" [Installed]"))))
 				}
 
 				fmt.Println()

+ 2 - 2
config.go

@@ -63,8 +63,8 @@ func editor() (editor string, args []string) {
 		fallthrough
 	default:
 		fmt.Fprintln(os.Stderr)
-		text.Errorln(gotext.Get("%s is not set", bold(cyan("$EDITOR"))))
-		text.Warnln(gotext.Get("Add %s or %s to your environment variables", bold(cyan("$EDITOR")), bold(cyan("$VISUAL"))))
+		text.Errorln(gotext.Get("%s is not set", text.Bold(text.Cyan("$EDITOR"))))
+		text.Warnln(gotext.Get("Add %s or %s to your environment variables", text.Bold(text.Cyan("$EDITOR")), text.Bold(text.Cyan("$VISUAL"))))
 
 		for {
 			text.Infoln(gotext.Get("Edit PKGBUILD with?"))

+ 5 - 5
download.go

@@ -262,7 +262,7 @@ func getPkgbuildsfromABS(pkgs []string, path string, dbExecutor db.Executor, for
 				continue
 			}
 		default:
-			text.Warn(gotext.Get("%s already downloaded -- use -f to overwrite", cyan(name)))
+			text.Warn(gotext.Get("%s already downloaded -- use -f to overwrite", text.Cyan(name)))
 			continue
 		}
 
@@ -271,13 +271,13 @@ func getPkgbuildsfromABS(pkgs []string, path string, dbExecutor db.Executor, for
 
 	if len(missing) != 0 {
 		text.Warnln(gotext.Get("Missing ABS packages:"),
-			cyan(strings.Join(missing, ", ")))
+			text.Cyan(strings.Join(missing, ", ")))
 	}
 
 	download := func(pkg string, url string) {
 		defer wg.Done()
 		if _, err := gitDownloadABS(url, config.ABSDir, pkg); err != nil {
-			errs.Add(errors.New(gotext.Get("failed to get pkgbuild: %s: %s", cyan(pkg), err.Error())))
+			errs.Add(errors.New(gotext.Get("failed to get pkgbuild: %s: %s", text.Cyan(pkg), err.Error())))
 			return
 		}
 
@@ -285,9 +285,9 @@ func getPkgbuildsfromABS(pkgs []string, path string, dbExecutor db.Executor, for
 		mux.Lock()
 		downloaded++
 		if err != nil {
-			errs.Add(errors.New(gotext.Get("failed to link %s: %s", cyan(pkg), stderr)))
+			errs.Add(errors.New(gotext.Get("failed to link %s: %s", text.Cyan(pkg), stderr)))
 		} else {
-			fmt.Fprintln(os.Stdout, gotext.Get("(%d/%d) Downloaded PKGBUILD from ABS: %s", downloaded, len(names), cyan(pkg)))
+			fmt.Fprintln(os.Stdout, gotext.Get("(%d/%d) Downloaded PKGBUILD from ABS: %s", downloaded, len(names), text.Cyan(pkg)))
 		}
 		mux.Unlock()
 	}

+ 15 - 15
install.go

@@ -482,7 +482,7 @@ nextpkg:
 	if len(incompatible) > 0 {
 		text.Warnln(gotext.Get("The following packages are not compatible with your architecture:"))
 		for pkg := range incompatible {
-			fmt.Print("  " + cyan(basesMap[pkg].String()))
+			fmt.Print("  " + text.Cyan(basesMap[pkg].String()))
 		}
 
 		fmt.Println()
@@ -548,8 +548,8 @@ func pkgbuildNumberMenu(bases []dep.Base, installed stringset.StringSet) bool {
 		pkg := base.Pkgbase()
 		dir := filepath.Join(config.BuildDir, pkg)
 
-		toPrint += fmt.Sprintf(magenta("%3d")+" %-40s", len(bases)-n,
-			bold(base.String()))
+		toPrint += fmt.Sprintf(text.Magenta("%3d")+" %-40s", len(bases)-n,
+			text.Bold(base.String()))
 
 		anyInstalled := false
 		for _, b := range base {
@@ -557,11 +557,11 @@ func pkgbuildNumberMenu(bases []dep.Base, installed stringset.StringSet) bool {
 		}
 
 		if anyInstalled {
-			toPrint += bold(green(gotext.Get(" (Installed)")))
+			toPrint += text.Bold(text.Green(gotext.Get(" (Installed)")))
 		}
 
 		if _, err := os.Stat(dir); !os.IsNotExist(err) {
-			toPrint += bold(green(gotext.Get(" (Build Files Exist)")))
+			toPrint += text.Bold(text.Green(gotext.Get(" (Build Files Exist)")))
 			askClean = true
 		}
 
@@ -581,7 +581,7 @@ func cleanNumberMenu(bases []dep.Base, installed stringset.StringSet, hasClean b
 	}
 
 	text.Infoln(gotext.Get("Packages to cleanBuild?"))
-	text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", cyan(gotext.Get("[N]one"))))
+	text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
 	cleanInput, err := getInput(config.AnswerClean)
 	if err != nil {
 		return nil, err
@@ -656,14 +656,14 @@ func editDiffNumberMenu(bases []dep.Base, installed stringset.StringSet, diff bo
 
 	if diff {
 		text.Infoln(gotext.Get("Diffs to show?"))
-		text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", cyan(gotext.Get("[N]one"))))
+		text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
 		editInput, err = getInput(config.AnswerDiff)
 		if err != nil {
 			return nil, err
 		}
 	} else {
 		text.Infoln(gotext.Get("PKGBUILDs to edit?"))
-		text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", cyan(gotext.Get("[N]one"))))
+		text.Infoln(gotext.Get("%s [A]ll [Ab]ort [I]nstalled [No]tInstalled or (1 2 3, 1-3, ^4)", text.Cyan(gotext.Get("[N]one"))))
 		editInput, err = getInput(config.AnswerEdit)
 		if err != nil {
 			return nil, err
@@ -750,7 +750,7 @@ func showPkgbuildDiffs(bases []dep.Base, cloned stringset.StringSet) error {
 			}
 
 			if !hasDiff {
-				text.Warnln(gotext.Get("%s: No changes -- skipping", cyan(base.String())))
+				text.Warnln(gotext.Get("%s: No changes -- skipping", text.Cyan(base.String())))
 				continue
 			}
 		}
@@ -805,7 +805,7 @@ func parseSrcinfoFiles(bases []dep.Base, errIsFatal bool) (map[string]*gosrc.Src
 		pkg := base.Pkgbase()
 		dir := filepath.Join(config.BuildDir, pkg)
 
-		text.OperationInfoln(gotext.Get("(%d/%d) Parsing SRCINFO: %s", k+1, len(bases), cyan(base.String())))
+		text.OperationInfoln(gotext.Get("(%d/%d) Parsing SRCINFO: %s", k+1, len(bases), text.Cyan(base.String())))
 
 		pkgbuild, err := gosrc.ParseFile(filepath.Join(dir, ".SRCINFO"))
 		if err != nil {
@@ -875,7 +875,7 @@ func downloadPkgbuilds(bases []dep.Base, toSkip stringset.StringSet, buildDir st
 			downloaded++
 			text.OperationInfoln(
 				gotext.Get("PKGBUILD up to date, Skipping (%d/%d): %s",
-					downloaded, len(bases), cyan(base.String())))
+					downloaded, len(bases), text.Cyan(base.String())))
 			mux.Unlock()
 			return
 		}
@@ -893,7 +893,7 @@ func downloadPkgbuilds(bases []dep.Base, toSkip stringset.StringSet, buildDir st
 
 		mux.Lock()
 		downloaded++
-		text.OperationInfoln(gotext.Get("Downloaded PKGBUILD (%d/%d): %s", downloaded, len(bases), cyan(base.String())))
+		text.OperationInfoln(gotext.Get("Downloaded PKGBUILD (%d/%d): %s", downloaded, len(bases), text.Cyan(base.String())))
 		mux.Unlock()
 	}
 
@@ -924,7 +924,7 @@ func downloadPkgbuildsSources(bases []dep.Base, incompatible stringset.StringSet
 
 		err = show(passToMakepkg(dir, args...))
 		if err != nil {
-			return errors.New(gotext.Get("error downloading sources: %s", cyan(base.String())))
+			return errors.New(gotext.Get("error downloading sources: %s", text.Cyan(base.String())))
 		}
 	}
 
@@ -1075,7 +1075,7 @@ func buildInstallPkgbuilds(
 					return errors.New(gotext.Get("error making: %s", err))
 				}
 
-				fmt.Fprintln(os.Stdout, gotext.Get("%s is up to date -- skipping", cyan(pkg+"-"+pkgVersion)))
+				fmt.Fprintln(os.Stdout, gotext.Get("%s is up to date -- skipping", text.Cyan(pkg+"-"+pkgVersion)))
 				continue
 			}
 		}
@@ -1086,7 +1086,7 @@ func buildInstallPkgbuilds(
 				return errors.New(gotext.Get("error making: %s", err))
 			}
 
-			text.Warnln(gotext.Get("%s already made -- skipping build", cyan(pkg+"-"+pkgVersion)))
+			text.Warnln(gotext.Get("%s already made -- skipping build", text.Cyan(pkg+"-"+pkgVersion)))
 		} else {
 			args := []string{"-cf", "--noconfirm", "--noextract", "--noprepare", "--holdver"}
 

+ 27 - 70
print.go

@@ -23,9 +23,9 @@ func (q aurQuery) printSearch(start int, dbExecutor db.Executor) {
 		if config.SearchMode == numberMenu {
 			switch config.SortMode {
 			case settings.TopDown:
-				toprint += magenta(strconv.Itoa(start+i) + " ")
+				toprint += text.Magenta(strconv.Itoa(start+i) + " ")
 			case settings.BottomUp:
-				toprint += magenta(strconv.Itoa(len(q)+start-i-1) + " ")
+				toprint += text.Magenta(strconv.Itoa(len(q)+start-i-1) + " ")
 			default:
 				text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
 			}
@@ -34,24 +34,24 @@ func (q aurQuery) printSearch(start int, dbExecutor db.Executor) {
 			continue
 		}
 
-		toprint += bold(text.ColorHash("aur")) + "/" + bold(q[i].Name) +
-			" " + cyan(q[i].Version) +
-			bold(" (+"+strconv.Itoa(q[i].NumVotes)) +
-			" " + bold(strconv.FormatFloat(q[i].Popularity, 'f', 2, 64)+") ")
+		toprint += text.Bold(text.ColorHash("aur")) + "/" + text.Bold(q[i].Name) +
+			" " + text.Cyan(q[i].Version) +
+			text.Bold(" (+"+strconv.Itoa(q[i].NumVotes)) +
+			" " + text.Bold(strconv.FormatFloat(q[i].Popularity, 'f', 2, 64)+") ")
 
 		if q[i].Maintainer == "" {
-			toprint += bold(red(gotext.Get("(Orphaned)"))) + " "
+			toprint += text.Bold(text.Red(gotext.Get("(Orphaned)"))) + " "
 		}
 
 		if q[i].OutOfDate != 0 {
-			toprint += bold(red(gotext.Get("(Out-of-date: %s)", text.FormatTime(q[i].OutOfDate)))) + " "
+			toprint += text.Bold(text.Red(gotext.Get("(Out-of-date: %s)", text.FormatTime(q[i].OutOfDate)))) + " "
 		}
 
 		if pkg := dbExecutor.LocalPackage(q[i].Name); pkg != nil {
 			if pkg.Version() != q[i].Version {
-				toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
+				toprint += text.Bold(text.Green(gotext.Get("(Installed: %s)", pkg.Version())))
 			} else {
-				toprint += bold(green(gotext.Get("(Installed)")))
+				toprint += text.Bold(text.Green(gotext.Get("(Installed)")))
 			}
 		}
 		toprint += "\n    " + q[i].Description
@@ -66,9 +66,9 @@ func (s repoQuery) printSearch(dbExecutor db.Executor) {
 		if config.SearchMode == numberMenu {
 			switch config.SortMode {
 			case settings.TopDown:
-				toprint += magenta(strconv.Itoa(i+1) + " ")
+				toprint += text.Magenta(strconv.Itoa(i+1) + " ")
 			case settings.BottomUp:
-				toprint += magenta(strconv.Itoa(len(s)-i) + " ")
+				toprint += text.Magenta(strconv.Itoa(len(s)-i) + " ")
 			default:
 				text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
 			}
@@ -77,9 +77,9 @@ func (s repoQuery) printSearch(dbExecutor db.Executor) {
 			continue
 		}
 
-		toprint += bold(text.ColorHash(res.DB().Name())) + "/" + bold(res.Name()) +
-			" " + cyan(res.Version()) +
-			bold(" ("+text.Human(res.Size())+
+		toprint += text.Bold(text.ColorHash(res.DB().Name())) + "/" + text.Bold(res.Name()) +
+			" " + text.Cyan(res.Version()) +
+			text.Bold(" ("+text.Human(res.Size())+
 				" "+text.Human(res.ISize())+") ")
 
 		packageGroups := dbExecutor.PackageGroups(res)
@@ -89,9 +89,9 @@ func (s repoQuery) printSearch(dbExecutor db.Executor) {
 
 		if pkg := dbExecutor.LocalPackage(res.Name()); pkg != nil {
 			if pkg.Version() != res.Version() {
-				toprint += bold(green(gotext.Get("(Installed: %s)", pkg.Version())))
+				toprint += text.Bold(text.Green(gotext.Get("(Installed: %s)", pkg.Version())))
 			} else {
-				toprint += bold(green(gotext.Get("(Installed)")))
+				toprint += text.Bold(text.Green(gotext.Get("(Installed)")))
 			}
 		}
 
@@ -150,7 +150,7 @@ func biggestPackages(dbExecutor db.Executor) {
 	}
 
 	for i := 0; i < 10; i++ {
-		fmt.Printf("%s: %s\n", bold(pkgS[i].Name()), cyan(text.Human(pkgS[i].ISize())))
+		fmt.Printf("%s: %s\n", text.Bold(pkgS[i].Name()), text.Cyan(text.Human(pkgS[i].ISize())))
 	}
 	// Could implement size here as well, but we just want the general idea
 }
@@ -165,15 +165,15 @@ func localStatistics(dbExecutor db.Executor) error {
 	}
 
 	text.Infoln(gotext.Get("Yay version v%s", yayVersion))
-	fmt.Println(bold(cyan("===========================================")))
-	text.Infoln(gotext.Get("Total installed packages: %s", cyan(strconv.Itoa(info.Totaln))))
-	text.Infoln(gotext.Get("Total foreign installed packages: %s", cyan(strconv.Itoa(len(remoteNames)))))
-	text.Infoln(gotext.Get("Explicitly installed packages: %s", cyan(strconv.Itoa(info.Expln))))
-	text.Infoln(gotext.Get("Total Size occupied by packages: %s", cyan(text.Human(info.TotalSize))))
-	fmt.Println(bold(cyan("===========================================")))
+	fmt.Println(text.Bold(text.Cyan("===========================================")))
+	text.Infoln(gotext.Get("Total installed packages: %s", text.Cyan(strconv.Itoa(info.Totaln))))
+	text.Infoln(gotext.Get("Total foreign installed packages: %s", text.Cyan(strconv.Itoa(len(remoteNames)))))
+	text.Infoln(gotext.Get("Explicitly installed packages: %s", text.Cyan(strconv.Itoa(info.Expln))))
+	text.Infoln(gotext.Get("Total Size occupied by packages: %s", text.Cyan(text.Human(info.TotalSize))))
+	fmt.Println(text.Bold(text.Cyan("===========================================")))
 	text.Infoln(gotext.Get("Ten biggest packages:"))
 	biggestPackages(dbExecutor)
-	fmt.Println(bold(cyan("===========================================")))
+	fmt.Println(text.Bold(text.Cyan("===========================================")))
 
 	query.AURInfoPrint(remoteNames, config.RequestSplitN)
 
@@ -220,7 +220,7 @@ func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enable
 				if cmdArgs.ExistsArg("q", "quiet") {
 					fmt.Printf("%s\n", pkg.Name)
 				} else {
-					fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
+					fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
 				}
 				delete(targets, pkg.Name)
 			}
@@ -233,7 +233,7 @@ func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enable
 				if cmdArgs.ExistsArg("q", "quiet") {
 					fmt.Printf("%s\n", pkg.Name)
 				} else {
-					fmt.Printf("%s %s -> %s\n", bold(pkg.Name), green(pkg.LocalVersion), green(pkg.RemoteVersion))
+					fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
 				}
 				delete(targets, pkg.Name)
 			}
@@ -266,46 +266,3 @@ outer:
 
 	return nil
 }
-
-const (
-	redCode     = "\x1b[31m"
-	greenCode   = "\x1b[32m"
-	blueCode    = "\x1b[34m"
-	magentaCode = "\x1b[35m"
-	cyanCode    = "\x1b[36m"
-	boldCode    = "\x1b[1m"
-
-	resetCode = "\x1b[0m"
-)
-
-func stylize(startCode, in string) string {
-	if text.UseColor {
-		return startCode + in + resetCode
-	}
-
-	return in
-}
-
-func red(in string) string {
-	return stylize(redCode, in)
-}
-
-func green(in string) string {
-	return stylize(greenCode, in)
-}
-
-func blue(in string) string {
-	return stylize(blueCode, in)
-}
-
-func cyan(in string) string {
-	return stylize(cyanCode, in)
-}
-
-func magenta(in string) string {
-	return stylize(magentaCode, in)
-}
-
-func bold(in string) string {
-	return stylize(boldCode, in)
-}

+ 3 - 3
upgrade.go

@@ -156,7 +156,7 @@ func printIgnoringPackage(pkg db.RepoPackage, newPkgVersion string) {
 	left, right := upgrade.GetVersionDiff(pkg.Version(), newPkgVersion)
 
 	text.Warnln(gotext.Get("%s: ignoring package upgrade (%s => %s)",
-		cyan(pkg.Name()),
+		text.Cyan(pkg.Name()),
 		left, right,
 	))
 }
@@ -203,7 +203,7 @@ func printLocalNewerThanAUR(
 
 		if !isDevelPackage(pkg) && alpm.VerCmp(pkg.Version(), aurPkg.Version) > 0 {
 			text.Warnln(gotext.Get("%s: local (%s) is newer than AUR (%s)",
-				cyan(pkg.Name()),
+				text.Cyan(pkg.Name()),
 				left, right,
 			))
 		}
@@ -245,7 +245,7 @@ func upgradePkgs(aurUp, repoUp upgrade.UpSlice) (ignore, aurNames stringset.Stri
 	sort.Sort(repoUp)
 	sort.Sort(aurUp)
 	allUp := append(repoUp, aurUp...)
-	fmt.Printf("%s"+bold(" %d ")+"%s\n", bold(cyan("::")), allUpLen, bold(gotext.Get("Packages to upgrade.")))
+	fmt.Printf("%s"+text.Bold(" %d ")+"%s\n", text.Bold(text.Cyan("::")), allUpLen, text.Bold(gotext.Get("Packages to upgrade.")))
 	allUp.Print()
 
 	text.Infoln(gotext.Get("Packages to exclude: (eg: \"1 2 3\", \"1-3\", \"^4\" or repo name)"))

+ 1 - 1
vcs.go

@@ -148,7 +148,7 @@ func updateVCSData(vcsFilePath, pkgName string, sources []gosrc.ArchString, mux
 		}
 
 		savedInfo[pkgName] = info
-		text.Warnln(gotext.Get("Found git repo: %s", cyan(url)))
+		text.Warnln(gotext.Get("Found git repo: %s", text.Cyan(url)))
 		err := saveVCSInfo(vcsFilePath)
 		if err != nil {
 			fmt.Fprintln(os.Stderr, err)