More sorting for upgrade menu

Sort accending instead of decending
Sort by package name as well as repo name
Sort AUR packages as well as repo packages
This commit is contained in:
morganamilo 2018-03-20 22:34:06 +00:00
parent b5c0cb7a11
commit 624851b80b
No known key found for this signature in database
GPG key ID: 6FE9E7996B0B082E

View file

@ -28,9 +28,18 @@ func (u upSlice) Len() int { return len(u) }
func (u upSlice) Swap(i, j int) { u[i], u[j] = u[j], u[i] }
func (u upSlice) Less(i, j int) bool {
if u[i].Repository != u[j].Repository {
iRunes := []rune(u[i].Repository)
jRunes := []rune(u[j].Repository)
return lessRunes(iRunes, jRunes)
} else {
iRunes := []rune(u[i].Name)
jRunes := []rune(u[j].Name)
return lessRunes(iRunes, jRunes)
}
}
func lessRunes(iRunes, jRunes []rune) bool {
max := len(iRunes)
if max > len(jRunes) {
max = len(jRunes)
@ -44,16 +53,16 @@ func (u upSlice) Less(i, j int) bool {
ljr := unicode.ToLower(jr)
if lir != ljr {
return lir > ljr
return lir < ljr
}
// the lowercase runes are the same, so compare the original
if ir != jr {
return ir > jr
return ir < jr
}
}
return false
return len(iRunes) < len(jRunes)
}
func getVersionDiff(oldVersion, newversion string) (left, right string) {
@ -272,6 +281,7 @@ func upgradePkgs(dt *depTree) (stringSet, stringSet, error) {
}
sort.Sort(repoUp)
sort.Sort(aurUp)
fmt.Println(bold(blue("::")), len(aurUp)+len(repoUp), bold("Packages to upgrade."))
repoUp.Print(len(aurUp) + 1)
aurUp.Print(1)