Improve formatting

Ignorepkg also colours version differences like the upgrade menu
Tweaked formatting when asking for users to eneter number
This commit is contained in:
morganamilo 2018-02-19 17:01:19 +00:00
parent dab8f1b5d2
commit 716d775d5f
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E
2 changed files with 32 additions and 30 deletions

5
cmd.go
View file

@ -593,9 +593,8 @@ func numberMenu(pkgS []string, flags []string) (err error) {
aurQ.printSearch(numpq + 1) aurQ.printSearch(numpq + 1)
} }
fmt.Println(greenFg("Type the numbers or ranges (e.g. 1-10) you want to install. " + fmt.Println(boldGreenFg(arrow) + boldGreenFg(" Packages to not upgrade (eg: 1 2 3, 1-3 or ^4)"))
"Separate each one of them with a space.")) fmt.Print(boldGreenFg(arrow + " "))
fmt.Print("Numbers: ")
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
numberBuf, overflow, err := reader.ReadLine() numberBuf, overflow, err := reader.ReadLine()
if err != nil || overflow { if err != nil || overflow {

View file

@ -56,12 +56,34 @@ func (u upSlice) Less(i, j int) bool {
return false return false
} }
func getVersionDiff(oldVersion, newversion string) (left, right string) {
old, errOld := pkgb.NewCompleteVersion(oldVersion)
new, errNew := pkgb.NewCompleteVersion(newversion)
if errOld != nil {
left = redFg("Invalid Version")
}
if errNew != nil {
right = redFg("Invalid Version")
}
if errOld == nil && errNew == nil {
if old.Version == new.Version {
left = string(old.Version) + "-" + redFg(string(old.Pkgrel))
right = string(new.Version) + "-" + greenFg(string(new.Pkgrel))
} else {
left = redFg(string(old.Version)) + "-" + string(old.Pkgrel)
right = boldGreenFg(string(new.Version)) + "-" + string(new.Pkgrel)
}
}
return
}
// Print prints the details of the packages to upgrade. // Print prints the details of the packages to upgrade.
func (u upSlice) Print(start int) { func (u upSlice) Print(start int) {
for k, i := range u { for k, i := range u {
old, errOld := pkgb.NewCompleteVersion(i.LocalVersion) left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
new, errNew := pkgb.NewCompleteVersion(i.RemoteVersion)
var left, right string
f := func(name string) (output string) { f := func(name string) (output string) {
if alpmConf.Options&alpm.ConfColor == 0 { if alpmConf.Options&alpm.ConfColor == 0 {
@ -76,26 +98,6 @@ func (u upSlice) Print(start int) {
fmt.Print(yellowFg(fmt.Sprintf("%2d ", len(u)+start-k-1))) fmt.Print(yellowFg(fmt.Sprintf("%2d ", len(u)+start-k-1)))
fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name)) fmt.Print(f(i.Repository), "/", boldWhiteFg(i.Name))
if errOld != nil {
left = redFg("Invalid Version")
} else {
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 {
if old.Version == new.Version {
right = string(new.Version) + "-" + greenFg(string(new.Pkgrel))
} else {
right = boldGreenFg(string(new.Version)) + "-" + string(new.Pkgrel)
}
}
w := 70 - 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.Printf(fmt.Sprintf("%%%ds", w),
fmt.Sprintf("%s -> %s\n", left, right)) fmt.Sprintf("%s -> %s\n", left, right))
@ -167,7 +169,7 @@ func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) {
fmt.Print(yellowFg("Warning: ")) fmt.Print(yellowFg("Warning: "))
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), "git") fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), "git")
} else { } else {
packageC <- upgrade{e.Package, "devel", e.SHA[0:6], "git"} packageC <- upgrade{e.Package, "devel", pkg.Version() , "commit-" + e.SHA[0:6]}
} }
} else { } else {
removeVCSPackage([]string{e.Package}) removeVCSPackage([]string{e.Package})
@ -203,8 +205,9 @@ func upAUR(remote []alpm.Package, remoteNames []string, dt *depTree) (toUpgrade
if (config.TimeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) || if (config.TimeUpdate && (int64(aurPkg.LastModified) > pkg.BuildDate().Unix())) ||
(alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) { (alpm.VerCmp(pkg.Version(), aurPkg.Version) < 0) {
if pkg.ShouldIgnore() { if pkg.ShouldIgnore() {
left, right := getVersionDiff(pkg.Version(), aurPkg.Version)
fmt.Print(yellowFg("Warning: ")) fmt.Print(yellowFg("Warning: "))
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), pkg.Version(), aurPkg.Version) fmt.Printf("%s ignoring package upgrade (%s => %s)\n", pkg.Name(), left, right)
} else { } else {
packageC <- upgrade{aurPkg.Name, "aur", pkg.Version(), aurPkg.Version} packageC <- upgrade{aurPkg.Name, "aur", pkg.Version(), aurPkg.Version}
} }
@ -306,8 +309,8 @@ func upgradePkgs(dt *depTree) (stringSet, stringSet, error) {
aurUp.Print(1) aurUp.Print(1)
if !config.NoConfirm { if !config.NoConfirm {
fmt.Println(greenFg("Enter packages you don't want to upgrade.")) fmt.Println(boldGreenFg(arrow) + greenFg(" Packages to not upgrade (eg: 1 2 3, 1-3 or ^4)"))
fmt.Print("Numbers: ") fmt.Print(boldGreenFg(arrow + " "))
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
numberBuf, overflow, err := reader.ReadLine() numberBuf, overflow, err := reader.ReadLine()