From 5286f3858c9825a7dcb1d61f6bab80ed84864e52 Mon Sep 17 00:00:00 2001 From: Jguer Date: Fri, 26 Jan 2018 10:18:49 +0900 Subject: [PATCH 1/4] References #109. Begins to add escape codes and string constants --- install.go | 6 +- print.go | 227 ++++++++++++++++++++++++++++++++++------------------- query.go | 6 +- upgrade.go | 29 ++++--- 4 files changed, 172 insertions(+), 96 deletions(-) diff --git a/install.go b/install.go index d71d67c4..bcbcb136 100644 --- a/install.go +++ b/install.go @@ -58,13 +58,15 @@ func install(parser *arguments) error { for _, pkg := range dc.AurMake { if pkg.Maintainer == "" { - fmt.Printf("\x1b[1;31;40m==> Warning:\x1b[0;;40m %s is orphaned.\x1b[0m\n", pkg.Name+"-"+pkg.Version) + fmt.Println(boldRedFgBlackBg(arrow+"Warning:"), + blackBg(pkg.Name+"-"+pkg.Version+"is orphaned")) } } for _, pkg := range dc.Aur { if pkg.Maintainer == "" { - fmt.Printf("\x1b[1;31;40m==> Warning:\x1b[0;;40m %s is orphaned.\x1b[0m\n", pkg.Name+"-"+pkg.Version) + fmt.Println(boldRedFgBlackBg(arrow+"Warning:"), + blackBg(pkg.Name+"-"+pkg.Version+"is orphaned")) } } diff --git a/print.go b/print.go index c5be901a..e3569398 100644 --- a/print.go +++ b/print.go @@ -3,11 +3,16 @@ package main import ( "fmt" "os" + "strconv" "strings" + alpm "github.com/jguer/go-alpm" rpc "github.com/mikkeloscar/aur" ) +const warning = "\x1b[33mWarning:\x1b[0m " +const arrow = "==>" + // Human returns results in Human readable format. func human(size int64) string { floatsize := float32(size) @@ -29,25 +34,28 @@ func (q aurQuery) printSearch(start int) { var toprint string if config.SearchMode == NumberMenu { if config.SortMode == BottomUp { - toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", len(q)+start-i-1) + toprint += yellowFg(strconv.Itoa(len(q)+start-i-1) + " ") } else { - toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", start+i) + toprint += yellowFg(strconv.Itoa(start+i) + " ") } } else if config.SearchMode == Minimal { fmt.Println(res.Name) continue } - toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m(%d) ", "aur", res.Name, res.Version, res.NumVotes) + toprint += boldWhiteFg("aur/") + boldYellowFg(res.Name) + + " " + boldCyanFg(res.Version) + + " (" + strconv.Itoa(res.NumVotes) + ") " + if res.Maintainer == "" { - toprint += fmt.Sprintf("\x1b[31;40m(Orphaned)\x1b[0m ") + toprint += redFgBlackBg("(Orphaned)") + " " } if res.OutOfDate != 0 { - toprint += fmt.Sprintf("\x1b[31;40m(Out-of-date)\x1b[0m ") + toprint += redFgBlackBg("(Out-of-date)") + " " } if _, err := localDb.PkgByName(res.Name); err == nil { - toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m") + toprint += greenFgBlackBg("Installed") } toprint += "\n " + res.Description fmt.Println(toprint) @@ -60,16 +68,16 @@ func (s repoQuery) printSearch() { var toprint string if config.SearchMode == NumberMenu { if config.SortMode == BottomUp { - toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", len(s)-i) + toprint += yellowFg(strconv.Itoa(len(s)-i) + " ") } else { - toprint += fmt.Sprintf("\x1b[33m%d\x1b[0m ", i+1) + toprint += yellowFg(strconv.Itoa(i+1) + " ") } } else if config.SearchMode == Minimal { fmt.Println(res.Name()) continue } - toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m", - res.DB().Name(), res.Name(), res.Version()) + toprint += boldWhiteFg(res.DB().Name()+"/") + boldYellowFg(res.Name()) + + " " + boldCyanFg(res.Version()) + " " if len(res.Groups().Slice()) != 0 { toprint += fmt.Sprint(res.Groups().Slice(), " ") @@ -78,7 +86,7 @@ func (s repoQuery) printSearch() { localDb, err := alpmHandle.LocalDb() if err == nil { if _, err = localDb.PkgByName(res.Name()); err == nil { - toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m") + toprint += greenFgBlackBg("Installed") } } @@ -89,17 +97,17 @@ func (s repoQuery) printSearch() { func printDeps(repoDeps []string, aurDeps []string) { if len(repoDeps) != 0 { - fmt.Print("\x1b[1;32m==> Repository dependencies: \x1b[0m") + fmt.Print(boldGreenFg(arrow + " Repository dependencies: ")) for _, repoD := range repoDeps { - fmt.Print("\x1b[33m", repoD, " \x1b[0m") + fmt.Print(yellowFg(repoD) + " ") } fmt.Print("\n") } if len(aurDeps) != 0 { - fmt.Print("\x1b[1;32m==> AUR dependencies: \x1b[0m") + fmt.Print(boldGreenFg(arrow + " AUR dependencies: ")) for _, aurD := range aurDeps { - fmt.Print("\x1b[33m", aurD, " \x1b[0m") + fmt.Print(yellowFg(aurD) + " ") } fmt.Print("\n") } @@ -107,59 +115,21 @@ func printDeps(repoDeps []string, aurDeps []string) { // PrintInfo prints package info like pacman -Si. func PrintInfo(a *rpc.Pkg) { - fmt.Println("\x1b[1;37mRepository :\x1b[0m", "aur") - fmt.Println("\x1b[1;37mName :\x1b[0m", a.Name) - fmt.Println("\x1b[1;37mVersion :\x1b[0m", a.Version) - fmt.Println("\x1b[1;37mDescription :\x1b[0m", a.Description) - if a.URL != "" { - fmt.Println("\x1b[1;37mURL :\x1b[0m", a.URL) - } else { - fmt.Println("\x1b[1;37mURL :\x1b[0m", "None") - } - fmt.Println("\x1b[1;37mLicenses :\x1b[0m", strings.Join(a.License, " ")) - - // if len(a.Provides) != 0 { - // fmt.Println("\x1b[1;37mProvides :\x1b[0m", - // Strings.join(a.Provides, " ")) - // } else { - // fmt.Println("\x1b[1;37mProvides :\x1b[0m", "None") - // } - - if len(a.Depends) != 0 { - fmt.Println("\x1b[1;37mDepends On :\x1b[0m", strings.Join(a.Depends, " ")) - } else { - fmt.Println("\x1b[1;37mDepends On :\x1b[0m", "None") - } - - if len(a.MakeDepends) != 0 { - fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", strings.Join(a.MakeDepends, " ")) - } else { - fmt.Println("\x1b[1;37mMake depends On :\x1b[0m", "None") - } - - if len(a.OptDepends) != 0 { - fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", strings.Join(a.OptDepends, " ")) - } else { - fmt.Println("\x1b[1;37mOptional Deps :\x1b[0m", "None") - } - - if len(a.Conflicts) != 0 { - fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", strings.Join(a.Conflicts, " ")) - } else { - fmt.Println("\x1b[1;37mConflicts With :\x1b[0m", "None") - } - - if a.Maintainer != "" { - fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", a.Maintainer) - } else { - fmt.Println("\x1b[1;37mMaintainer :\x1b[0m", "None") - } - - fmt.Println("\x1b[1;37mVotes :\x1b[0m", a.NumVotes) - fmt.Println("\x1b[1;37mPopularity :\x1b[0m", a.Popularity) - + fmt.Println(boldWhiteFg("Repository :"), "aur") + fmt.Println(boldWhiteFg("Name :"), a.Name) + fmt.Println(boldWhiteFg("Version :"), a.Version) + fmt.Println(boldWhiteFg("Description :"), a.Description) + fmt.Println(boldWhiteFg("URL :"), a.URL) + fmt.Println(boldWhiteFg("Licenses :"), strings.Join(a.License, " ")) + fmt.Println(boldWhiteFg("Depends On :"), strings.Join(a.Depends, " ")) + fmt.Println(boldWhiteFg("Make Deps :"), strings.Join(a.MakeDepends, " ")) + fmt.Println(boldWhiteFg("Optional Deps :"), strings.Join(a.OptDepends, " ")) + fmt.Println(boldWhiteFg("Conflicts With :"), strings.Join(a.Conflicts, " ")) + fmt.Println(boldWhiteFg("Maintainer :"), a.Maintainer) + fmt.Println(boldWhiteFg("Votes :"), a.NumVotes) + fmt.Println(boldWhiteFg("Popularity :"), a.Popularity) if a.OutOfDate != 0 { - fmt.Println("\x1b[1;37mOut-of-date :\x1b[0m", "Yes") + fmt.Println(boldWhiteFg("Out-of-date :"), "Yes") } fmt.Println() @@ -180,7 +150,7 @@ func biggestPackages() { } for i := 0; i < 10; i++ { - fmt.Printf("%s: \x1B[0;33m%s\x1B[0m\n", pkgS[i].Name(), human(pkgS[i].ISize())) + fmt.Println(pkgS[i].Name() + ": " + yellowFg(human(pkgS[i].ISize()))) } // Could implement size here as well, but we just want the general idea } @@ -198,15 +168,15 @@ func localStatistics() error { } fmt.Printf("\n Yay version r%s\n", version) - fmt.Println("\x1B[1;34m===========================================\x1B[0m") - fmt.Printf("\x1B[1;32mTotal installed packages: \x1B[0;33m%d\x1B[0m\n", info.Totaln) - fmt.Printf("\x1B[1;32mTotal foreign installed packages: \x1B[0;33m%d\x1B[0m\n", len(remoteNames)) - fmt.Printf("\x1B[1;32mExplicitly installed packages: \x1B[0;33m%d\x1B[0m\n", info.Expln) - fmt.Printf("\x1B[1;32mTotal Size occupied by packages: \x1B[0;33m%s\x1B[0m\n", human(info.TotalSize)) - fmt.Println("\x1B[1;34m===========================================\x1B[0m") - fmt.Println("\x1B[1;32mTen biggest packages\x1B[0m") + fmt.Println(boldCyanFg("===========================================")) + fmt.Println(boldGreenFg("Total installed packages: ") + yellowFg(strconv.Itoa(info.Totaln))) + fmt.Println(boldGreenFg("Total foreign installed packages: ") + yellowFg(strconv.Itoa(len(remoteNames)))) + fmt.Println(boldGreenFg("Explicitly installed packages: ") + yellowFg(strconv.Itoa(info.Expln))) + fmt.Println(boldGreenFg("Total Size occupied by packages: ") + yellowFg(human(info.TotalSize))) + fmt.Println(boldCyanFg("===========================================")) + fmt.Println(boldGreenFg("Ten biggest packages")) biggestPackages() - fmt.Println("\x1B[1;34m===========================================\x1B[0m") + fmt.Println(boldCyanFg("===========================================")) var q aurQuery var j int @@ -242,15 +212,18 @@ func localStatistics() error { for _, res := range q { if res.Maintainer == "" { - fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is orphaned.\x1b[0m\n", res.Name) + fmt.Println(boldRedFgBlackBg(arrow+"Warning:"), + boldYellowFgBlackBg(res.Name), whiteFgBlackBg("is orphaned")) } if res.OutOfDate != 0 { - fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is out-of-date in AUR.\x1b[0m\n", res.Name) + fmt.Println(boldRedFgBlackBg(arrow+"Warning:"), + boldYellowFgBlackBg(res.Name), whiteFgBlackBg("is out-of-date in AUR")) } } for _, res := range outcast { - fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m%s\x1b[0;37;40m is not available in AUR.\x1b[0m\n", res) + fmt.Println(boldRedFgBlackBg(arrow+"Warning:"), + boldYellowFgBlackBg(res), whiteFgBlackBg("is not available in AUR")) } return nil @@ -297,3 +270,99 @@ func printUpdateList() error { return nil } + +func blackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[0;;40m" + in + "\x1b[0m" + } + + return in +} + +func redFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[0;31m" + in + "\x1b[0m" + } + + return in +} + +func yellowFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[0;33m" + in + "\x1b[0m" + } + + return in +} + +func boldGreenFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;32m" + in + "\x1b[0m" + } + + return in +} + +func boldYellowFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;33m" + in + "\x1b[0m" + } + + return in +} + +func boldCyanFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;36m" + in + "\x1b[0m" + } + + return in +} + +func boldWhiteFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;37m" + in + "\x1b[0m" + } + + return in +} + +func redFgBlackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[31;40m" + in + "\x1b[0m" + } + + return in +} + +func greenFgBlackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[32;40m" + in + "\x1b[0m" + } + + return in +} + +func whiteFgBlackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[0;37;40m" + in + "\x1b[0m" + } + + return in +} + +func boldRedFgBlackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;31;40m" + in + "\x1b[0m" + } + + return in +} + +func boldYellowFgBlackBg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;33;40m" + in + "\x1b[0m" + } + + return in +} diff --git a/query.go b/query.go index e3c3a664..e9ae6f94 100644 --- a/query.go +++ b/query.go @@ -81,7 +81,7 @@ func (q aurQuery) missingPackage(pkgS []string) { } if !found { - fmt.Println("\x1b[31mUnable to find", depName, "in AUR\x1b[0m") + fmt.Println(redFg("Unable to find" + depName + "in AUR")) } } } @@ -303,7 +303,7 @@ func hangingPackages() (hanging []string, err error) { requiredby := pkg.ComputeRequiredBy() if len(requiredby) == 0 { hanging = append(hanging, pkg.Name()) - fmt.Printf("%s: \x1B[0;33m%s\x1B[0m\n", pkg.Name(), human(pkg.ISize())) + fmt.Println(pkg.Name() + ": " + yellowFg(human(pkg.ISize()))) } return nil @@ -372,7 +372,7 @@ big: requiredby := pkg.ComputeRequiredBy() if len(requiredby) == 0 { hanging = append(hanging, pkgName) - fmt.Printf("%s: \x1B[0;33m%s\x1B[0m\n", pkg.Name(), human(pkg.ISize())) + fmt.Println(pkg.Name() + ": " + yellowFg(human(pkg.ISize()))) } } } diff --git a/upgrade.go b/upgrade.go index f74099d2..b3c27541 100644 --- a/upgrade.go +++ b/upgrade.go @@ -64,28 +64,30 @@ func (u upSlice) Print(start int) { new, errNew := pkgb.NewCompleteVersion(i.RemoteVersion) var left, right string - f := func(name string) (color int) { + f := func(name string) (output string) { var hash = 5381 for i := 0; i < len(name); i++ { hash = int(name[i]) + ((hash << 5) + (hash)) } - return hash%6 + 31 + return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name) } - fmt.Printf("\x1b[33m%-2d\x1b[0m ", len(u)+start-k-1) - fmt.Printf("\x1b[1;%dm%s\x1b[0m/\x1b[1;39m%-25s\t\t\x1b[0m", f(i.Repository), i.Repository, i.Name) + fmt.Printf("%2s ", yellowFg(strconv.Itoa(len(u)+start-k-1))) + fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name)) if errOld != nil { - left = fmt.Sprintf("\x1b[31m%20s\x1b[0m", "Invalid Version") + left = redFg("Invalid Version") } else { - left = fmt.Sprintf("\x1b[31m%18s\x1b[0m-%s", old.Version, old.Pkgrel) + left = redFg(string(old.Version)) + "-" + string(old.Pkgrel) } if errNew != nil { - right = fmt.Sprintf("\x1b[31m%s\x1b[0m", "Invalid Version") + right = redFg("Invalid Version") } else { - right = fmt.Sprintf("\x1b[31m%s\x1b[0m-%s", new.Version, new.Pkgrel) + right = redFg(string(new.Version)) + "-" + string(new.Pkgrel) } - fmt.Printf("%s -> %s\n", left, right) + w := 100 - len(i.Repository) - len(i.Name) - len(left) + fmt.Printf(fmt.Sprintf("%%%ds", w), + fmt.Sprintf("%s -> %s\n", left, right)) } } @@ -151,7 +153,8 @@ func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) { } if found { if pkg.ShouldIgnore() { - fmt.Printf("\x1b[33mwarning:\x1b[0m %s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), "git") + fmt.Print(warning) + fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), "git") } else { packageC <- upgrade{e.Package, "devel", e.SHA[0:6], "git"} } @@ -208,7 +211,8 @@ func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err if (config.TimeUpdate && (int64(qtemp[x].LastModified) > local[i].BuildDate().Unix())) || (alpm.VerCmp(local[i].Version(), qtemp[x].Version) < 0) { if local[i].ShouldIgnore() { - fmt.Printf("\x1b[33mwarning:\x1b[0m %s ignoring package upgrade (%s => %s)\n", local[i].Name(), local[i].Version(), qtemp[x].Version) + fmt.Print(warning) + fmt.Printf("%s ignoring package upgrade (%s => %s)\n", local[i].Name(), local[i].Version(), qtemp[x].Version) } else { packageC <- upgrade{qtemp[x].Name, "aur", local[i].Version(), qtemp[x].Version} } @@ -255,7 +259,8 @@ func upRepo(local []alpm.Package) (upSlice, error) { newPkg := pkg.NewVersion(dbList) if newPkg != nil { if pkg.ShouldIgnore() { - fmt.Printf("\x1b[33mwarning:\x1b[0m %s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), newPkg.Version()) + fmt.Print(warning) + fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), newPkg.Version()) } else { slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) } From f466fc74f5bb8d39d0cb3a50635a802a4407aaca Mon Sep 17 00:00:00 2001 From: Jguer Date: Fri, 26 Jan 2018 11:30:33 +0000 Subject: [PATCH 2/4] Ports more text to new colour format. --- cmd.go | 9 +++++---- print.go | 20 ++++++++++++++++++-- upgrade.go | 5 +++-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/cmd.go b/cmd.go index 5c643420..952f549a 100644 --- a/cmd.go +++ b/cmd.go @@ -561,9 +561,9 @@ func numberMenu(pkgS []string, flags []string) (err error) { aurQ.printSearch(numpq + 1) } - fmt.Printf("\x1b[32m%s %s\x1b[0m\nNumbers: ", - "Type the numbers or ranges (e.g. 1-10) you want to install.", - "Separate each one of them with a space.") + fmt.Println(greenFg("Type the numbers or ranges (e.g. 1-10) you want to install. " + + "Separate each one of them with a space.")) + fmt.Print("Numbers: ") reader := bufio.NewReader(os.Stdin) numberBuf, overflow, err := reader.ReadLine() if err != nil || overflow { @@ -673,7 +673,8 @@ func passToMakepkg(dir string, args ...string) (err error) { if err == nil { _ = saveVCSInfo() if config.CleanAfter { - fmt.Println("\x1b[1;32m==> CleanAfter enabled. Deleting source folder.\x1b[0m") + fmt.Println(boldGreenFg(arrow + + " CleanAfter enabled. Deleting source folder.")) os.RemoveAll(dir) } } diff --git a/print.go b/print.go index e3569398..d3773a05 100644 --- a/print.go +++ b/print.go @@ -287,6 +287,14 @@ func redFg(in string) string { return in } +func greenFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[0;32m" + in + "\x1b[0m" + } + + return in +} + func yellowFg(in string) string { if alpmConf.Options&alpm.ConfColor > 0 { return "\x1b[0;33m" + in + "\x1b[0m" @@ -311,6 +319,14 @@ func boldYellowFg(in string) string { return in } +func boldBlueFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1;34m" + in + "\x1b[0m" + } + + return in +} + func boldCyanFg(in string) string { if alpmConf.Options&alpm.ConfColor > 0 { return "\x1b[1;36m" + in + "\x1b[0m" @@ -329,7 +345,7 @@ func boldWhiteFg(in string) string { func redFgBlackBg(in string) string { if alpmConf.Options&alpm.ConfColor > 0 { - return "\x1b[31;40m" + in + "\x1b[0m" + return "\x1b[0;31;40m" + in + "\x1b[0m" } return in @@ -337,7 +353,7 @@ func redFgBlackBg(in string) string { func greenFgBlackBg(in string) string { if alpmConf.Options&alpm.ConfColor > 0 { - return "\x1b[32;40m" + in + "\x1b[0m" + return "\x1b[0;32;40m" + in + "\x1b[0m" } return in diff --git a/upgrade.go b/upgrade.go index b3c27541..c1251688 100644 --- a/upgrade.go +++ b/upgrade.go @@ -305,12 +305,13 @@ func upgradePkgs(flags []string) error { var repoNums []int var aurNums []int sort.Sort(repoUp) - fmt.Printf("\x1b[1;34;1m:: \x1b[0m\x1b[1m%d Packages to upgrade.\x1b[0m\n", len(aurUp)+len(repoUp)) + fmt.Println(boldBlueFg("::"), len(aurUp)+len(repoUp), boldWhiteFg("Packages to upgrade.")) repoUp.Print(len(aurUp) + 1) aurUp.Print(1) if !config.NoConfirm { - fmt.Print("\x1b[32mEnter packages you don't want to upgrade.\x1b[0m\nNumbers: ") + fmt.Println(greenFg("Enter packages you don't want to upgrade.")) + fmt.Print("Numbers: ") reader := bufio.NewReader(os.Stdin) numberBuf, overflow, err := reader.ReadLine() From ecc337c29fbab2c9ba260c432eb88c5ddb94c149 Mon Sep 17 00:00:00 2001 From: Jguer Date: Fri, 26 Jan 2018 15:04:10 +0000 Subject: [PATCH 3/4] Finishes porting text to new colour format. --- config.go | 8 +++++--- download.go | 4 ++-- print.go | 8 +++++++- upgrade.go | 12 ++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config.go b/config.go index 57d60996..2bc673c6 100644 --- a/config.go +++ b/config.go @@ -146,10 +146,12 @@ func editor() string { } fallthrough default: - fmt.Printf("\x1b[1;31;40mWarning: \x1B[1;33;40m$EDITOR\x1b[0;37;40m is not set.\x1b[0m\nPlease add $EDITOR or to your environment variables.\n") + fmt.Println(boldRedFgBlackBg("Warning:"), + boldYellowFgBlackBg("$EDITOR"), whiteFgBlackBg("is not set")) + fmt.Println("Please add $EDITOR or to your environment variables.") editorLoop: - fmt.Printf("\x1b[32m%s\x1b[0m ", "Edit PKGBUILD with:") + fmt.Print(greenFg("Edit PKGBUILD with:")) var editorInput string _, err := fmt.Scanln(&editorInput) if err != nil { @@ -181,7 +183,7 @@ func continueTask(s string, def string) (cont bool) { } var response string - fmt.Printf("\x1b[1;32m==> %s\x1b[1;37m %s\x1b[0m", s, postFix) + fmt.Println(boldGreenFg(arrow+" "+s), boldWhiteFg(postFix)) n, err := fmt.Scanln(&response) if err != nil || n == 0 { diff --git a/download.go b/download.go index 7ade9bc8..9cc8bf8a 100644 --- a/download.go +++ b/download.go @@ -97,7 +97,7 @@ func getPkgbuildfromABS(pkgN string, path string) (err error) { } else { return fmt.Errorf("Not in standard repositories") } - fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in ABS.\x1b[0m\n", pkgN) + fmt.Println(boldGreenFg(arrow), boldYellowFg(pkgN), boldGreenFg("found in ABS.")) errD := downloadAndUnpack(url, path, true) return errD } @@ -116,7 +116,7 @@ func getPkgbuildfromAUR(pkgN string, dir string) (err error) { return fmt.Errorf("no results") } - fmt.Printf("\x1b[1;32m==>\x1b[1;33m %s \x1b[1;32mfound in AUR.\x1b[0m\n", pkgN) + fmt.Println(boldGreenFg(arrow), boldYellowFg(pkgN), boldGreenFg("found in AUR.")) downloadAndUnpack(baseURL+aq[0].URLPath, dir, false) return } diff --git a/print.go b/print.go index d3773a05..ef1d5791 100644 --- a/print.go +++ b/print.go @@ -10,7 +10,6 @@ import ( rpc "github.com/mikkeloscar/aur" ) -const warning = "\x1b[33mWarning:\x1b[0m " const arrow = "==>" // Human returns results in Human readable format. @@ -303,6 +302,13 @@ func yellowFg(in string) string { return in } +func boldFg(in string) string { + if alpmConf.Options&alpm.ConfColor > 0 { + return "\x1b[1m" + in + "\x1b[0m" + } + + return in +} func boldGreenFg(in string) string { if alpmConf.Options&alpm.ConfColor > 0 { return "\x1b[1;32m" + in + "\x1b[0m" diff --git a/upgrade.go b/upgrade.go index c1251688..0c205b17 100644 --- a/upgrade.go +++ b/upgrade.go @@ -102,14 +102,14 @@ func upList() (aurUp upSlice, repoUp upSlice, err error) { aurC := make(chan upSlice) errC := make(chan error) - fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Searching databases for updates...\x1b[0m") + fmt.Println(boldCyanFg("::"), boldFg("Searching databases for updates...")) go func() { repoUpList, err := upRepo(local) errC <- err repoC <- repoUpList }() - fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Searching AUR for updates...\x1b[0m") + fmt.Println(boldCyanFg("::"), boldFg("Searching AUR for updates...")) go func() { aurUpList, err := upAUR(remote, remoteNames) errC <- err @@ -153,7 +153,7 @@ func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) { } if found { if pkg.ShouldIgnore() { - fmt.Print(warning) + fmt.Print(yellowFg("Warning: ")) fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), "git") } else { packageC <- upgrade{e.Package, "devel", e.SHA[0:6], "git"} @@ -179,7 +179,7 @@ func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err if config.Devel { routines++ go upDevel(remote, packageC, done) - fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Checking development packages...\x1b[0m") + fmt.Println(boldCyanFg("::"), boldFg("Checking development packages...")) } for i := len(remote); i != 0; i = j { @@ -211,7 +211,7 @@ func upAUR(remote []alpm.Package, remoteNames []string) (toUpgrade upSlice, err if (config.TimeUpdate && (int64(qtemp[x].LastModified) > local[i].BuildDate().Unix())) || (alpm.VerCmp(local[i].Version(), qtemp[x].Version) < 0) { if local[i].ShouldIgnore() { - fmt.Print(warning) + fmt.Print(yellowFg("Warning: ")) fmt.Printf("%s ignoring package upgrade (%s => %s)\n", local[i].Name(), local[i].Version(), qtemp[x].Version) } else { packageC <- upgrade{qtemp[x].Name, "aur", local[i].Version(), qtemp[x].Version} @@ -259,7 +259,7 @@ func upRepo(local []alpm.Package) (upSlice, error) { newPkg := pkg.NewVersion(dbList) if newPkg != nil { if pkg.ShouldIgnore() { - fmt.Print(warning) + fmt.Print(yellowFg("Warning: ")) fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), newPkg.Version()) } else { slice = append(slice, upgrade{pkg.Name(), newPkg.DB().Name(), pkg.Version(), newPkg.Version()}) From a25ed83b21557b7adfe26662679891a4d5886da1 Mon Sep 17 00:00:00 2001 From: Jguer Date: Fri, 26 Jan 2018 15:27:47 +0000 Subject: [PATCH 4/4] Fixes version colouring. Semi-fixes collumn allignment --- upgrade.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/upgrade.go b/upgrade.go index 0c205b17..24a095d9 100644 --- a/upgrade.go +++ b/upgrade.go @@ -71,21 +71,30 @@ func (u upSlice) Print(start int) { } return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", hash%6+31, name) } - fmt.Printf("%2s ", yellowFg(strconv.Itoa(len(u)+start-k-1))) + fmt.Print(yellowFg(fmt.Sprintf("%2d ", len(u)+start-k-1))) fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name)) if errOld != nil { left = redFg("Invalid Version") } else { - left = redFg(string(old.Version)) + "-" + string(old.Pkgrel) + if old.Version == new.Version { + left = string(old.Version) + "-" + redFg(string(old.Pkgrel)) + } else { + left = redFg(string(old.Version)) + "-" + string(old.Pkgrel) + } } if errNew != nil { right = redFg("Invalid Version") } else { - right = redFg(string(new.Version)) + "-" + string(new.Pkgrel) + if old.Version == new.Version { + right = string(new.Version) + "-" + greenFg(string(new.Pkgrel)) + } else { + right = boldGreenFg(string(new.Version)) + "-" + string(new.Pkgrel) + } } - w := 100 - len(i.Repository) - len(i.Name) - len(left) + + w := 70 - len(i.Repository) - len(i.Name) + len(left) fmt.Printf(fmt.Sprintf("%%%ds", w), fmt.Sprintf("%s -> %s\n", left, right)) }