Skip to content

Commit

Permalink
fix(color): remove duplicate colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Aug 16, 2020
1 parent 1ccfd3f commit c305e1c
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 100 deletions.
4 changes: 2 additions & 2 deletions clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?"))
Expand Down
10 changes: 5 additions & 5 deletions download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -271,23 +271,23 @@ 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
}

_, stderr, err := capture(exec.Command("cp", "-r", filepath.Join(config.ABSDir, pkg, "trunk"), filepath.Join(path, pkg)))
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()
}
Expand Down
30 changes: 15 additions & 15 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -548,20 +548,20 @@ 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 {
anyInstalled = anyInstalled || installed.Get(b.Name)
}

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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
}

Expand Down Expand Up @@ -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())))
}
}

Expand Down Expand Up @@ -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
}
}
Expand All @@ -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"}

Expand Down
97 changes: 27 additions & 70 deletions print.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand All @@ -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
Expand All @@ -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"))
}
Expand All @@ -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)
Expand All @@ -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)")))
}
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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)

Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Loading

0 comments on commit c305e1c

Please sign in to comment.