mirror of
https://github.com/Jguer/yay
synced 2024-10-05 23:59:13 +00:00
Make upgrade output as table
This commit is contained in:
parent
dc10c4b6dd
commit
58283a9799
29
print.go
29
print.go
|
@ -153,18 +153,33 @@ func formatPkgbase(pkg *rpc.Pkg, bases map[string][]*rpc.Pkg) string {
|
|||
return str
|
||||
}
|
||||
|
||||
func (u upgrade) StylizedNameWithRepository() string {
|
||||
return bold(colourHash(u.Repository)) + "/" + bold(u.Name)
|
||||
}
|
||||
|
||||
// Print prints the details of the packages to upgrade.
|
||||
func (u upSlice) Print(start int) {
|
||||
func (u upSlice) Print() {
|
||||
longestName, longestVersion := 0, 0
|
||||
for _, pack := range u {
|
||||
packNameLen := len(pack.StylizedNameWithRepository())
|
||||
version, _ := getVersionDiff(pack.LocalVersion, pack.RemoteVersion)
|
||||
packVersionLen := len(version)
|
||||
longestName = max(packNameLen, longestName)
|
||||
longestVersion = max(packVersionLen, longestVersion)
|
||||
}
|
||||
|
||||
namePadding := fmt.Sprintf("%%-%ds ", longestName)
|
||||
versionPadding := fmt.Sprintf("%%-%ds", longestVersion)
|
||||
numberPadding := fmt.Sprintf("%%%dd ", len(fmt.Sprintf("%v", len(u))))
|
||||
|
||||
for k, i := range u {
|
||||
left, right := getVersionDiff(i.LocalVersion, i.RemoteVersion)
|
||||
|
||||
fmt.Print(magenta(fmt.Sprintf("%3d ", len(u)+start-k-1)))
|
||||
fmt.Print(bold(colourHash(i.Repository)), "/", bold(i.Name))
|
||||
fmt.Print(magenta(fmt.Sprintf(numberPadding, len(u)-k)))
|
||||
|
||||
w := 70 - len(i.Repository) - len(i.Name)
|
||||
padding := fmt.Sprintf("%%%ds", w)
|
||||
fmt.Printf(padding, left)
|
||||
fmt.Printf(" -> %s\n", right)
|
||||
fmt.Printf(namePadding, i.StylizedNameWithRepository())
|
||||
|
||||
fmt.Printf("%s -> %s\n", fmt.Sprintf(versionPadding, left), right)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -305,15 +305,16 @@ func upgradePkgs(aurUp, repoUp upSlice) (stringSet, stringSet, error) {
|
|||
ignore := make(stringSet)
|
||||
aurNames := make(stringSet)
|
||||
|
||||
if len(aurUp)+len(repoUp) == 0 {
|
||||
allUpLen := len(repoUp) + len(aurUp)
|
||||
if allUpLen == 0 {
|
||||
return ignore, aurNames, nil
|
||||
}
|
||||
|
||||
sort.Sort(repoUp)
|
||||
sort.Sort(aurUp)
|
||||
fmt.Printf("%s"+bold(" %d ")+"%s\n", bold(cyan("::")), len(aurUp)+len(repoUp), bold("Packages to upgrade."))
|
||||
repoUp.Print(len(aurUp) + 1)
|
||||
aurUp.Print(1)
|
||||
allUp := append(repoUp, aurUp...)
|
||||
fmt.Printf("%s"+bold(" %d ")+"%s\n", bold(cyan("::")), allUpLen, bold("Packages to upgrade."))
|
||||
allUp.Print()
|
||||
|
||||
fmt.Println(bold(green(arrow + " Packages to not upgrade: (eg: 1 2 3, 1-3, ^4 or repo name)")))
|
||||
fmt.Print(bold(green(arrow + " ")))
|
||||
|
|
Loading…
Reference in a new issue