-
Notifications
You must be signed in to change notification settings - Fork 0
/
print.go
268 lines (229 loc) · 8.5 KB
/
print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/leonelquinteros/gotext"
rpc "github.com/mikkeloscar/aur"
"github.com/Jguer/yay/v10/pkg/db"
"github.com/Jguer/yay/v10/pkg/query"
"github.com/Jguer/yay/v10/pkg/settings"
"github.com/Jguer/yay/v10/pkg/stringset"
"github.com/Jguer/yay/v10/pkg/text"
)
// PrintSearch handles printing search results in a given format
func (q aurQuery) printSearch(start int, dbExecutor db.Executor) {
for i := range q {
var toprint string
if config.SearchMode == numberMenu {
switch config.SortMode {
case settings.TopDown:
toprint += text.Magenta(strconv.Itoa(start+i) + " ")
case settings.BottomUp:
toprint += text.Magenta(strconv.Itoa(len(q)+start-i-1) + " ")
default:
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
}
} else if config.SearchMode == minimal {
fmt.Println(q[i].Name)
continue
}
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 += text.Bold(text.Red(gotext.Get("(Orphaned)"))) + " "
}
if q[i].OutOfDate != 0 {
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 += text.Bold(text.Green(gotext.Get("(Installed: %s)", pkg.Version())))
} else {
toprint += text.Bold(text.Green(gotext.Get("(Installed)")))
}
}
toprint += "\n " + q[i].Description
fmt.Println(toprint)
}
}
// PrintSearch receives a RepoSearch type and outputs pretty text.
func (s repoQuery) printSearch(dbExecutor db.Executor) {
for i, res := range s {
var toprint string
if config.SearchMode == numberMenu {
switch config.SortMode {
case settings.TopDown:
toprint += text.Magenta(strconv.Itoa(i+1) + " ")
case settings.BottomUp:
toprint += text.Magenta(strconv.Itoa(len(s)-i) + " ")
default:
text.Warnln(gotext.Get("invalid sort mode. Fix with yay -Y --bottomup --save"))
}
} else if config.SearchMode == minimal {
fmt.Println(res.Name())
continue
}
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)
if len(packageGroups) != 0 {
toprint += fmt.Sprint(packageGroups, " ")
}
if pkg := dbExecutor.LocalPackage(res.Name()); pkg != nil {
if pkg.Version() != res.Version() {
toprint += text.Bold(text.Green(gotext.Get("(Installed: %s)", pkg.Version())))
} else {
toprint += text.Bold(text.Green(gotext.Get("(Installed)")))
}
}
toprint += "\n " + res.Description()
fmt.Println(toprint)
}
}
// Pretty print a set of packages from the same package base.
// PrintInfo prints package info like pacman -Si.
func PrintInfo(a *rpc.Pkg, extendedInfo bool) {
text.PrintInfoValue(gotext.Get("Repository"), "aur")
text.PrintInfoValue(gotext.Get("Name"), a.Name)
text.PrintInfoValue(gotext.Get("Keywords"), strings.Join(a.Keywords, " "))
text.PrintInfoValue(gotext.Get("Version"), a.Version)
text.PrintInfoValue(gotext.Get("Description"), a.Description)
text.PrintInfoValue(gotext.Get("URL"), a.URL)
text.PrintInfoValue(gotext.Get("AUR URL"), config.AURURL+"/packages/"+a.Name)
text.PrintInfoValue(gotext.Get("Groups"), strings.Join(a.Groups, " "))
text.PrintInfoValue(gotext.Get("Licenses"), strings.Join(a.License, " "))
text.PrintInfoValue(gotext.Get("Provides"), strings.Join(a.Provides, " "))
text.PrintInfoValue(gotext.Get("Depends On"), strings.Join(a.Depends, " "))
text.PrintInfoValue(gotext.Get("Make Deps"), strings.Join(a.MakeDepends, " "))
text.PrintInfoValue(gotext.Get("Check Deps"), strings.Join(a.CheckDepends, " "))
text.PrintInfoValue(gotext.Get("Optional Deps"), strings.Join(a.OptDepends, " "))
text.PrintInfoValue(gotext.Get("Conflicts With"), strings.Join(a.Conflicts, " "))
text.PrintInfoValue(gotext.Get("Maintainer"), a.Maintainer)
text.PrintInfoValue(gotext.Get("Votes"), fmt.Sprintf("%d", a.NumVotes))
text.PrintInfoValue(gotext.Get("Popularity"), fmt.Sprintf("%f", a.Popularity))
text.PrintInfoValue(gotext.Get("First Submitted"), text.FormatTimeQuery(a.FirstSubmitted))
text.PrintInfoValue(gotext.Get("Last Modified"), text.FormatTimeQuery(a.LastModified))
if a.OutOfDate != 0 {
text.PrintInfoValue(gotext.Get("Out-of-date"), text.FormatTimeQuery(a.OutOfDate))
} else {
text.PrintInfoValue(gotext.Get("Out-of-date"), "No")
}
if extendedInfo {
text.PrintInfoValue("ID", fmt.Sprintf("%d", a.ID))
text.PrintInfoValue(gotext.Get("Package Base ID"), fmt.Sprintf("%d", a.PackageBaseID))
text.PrintInfoValue(gotext.Get("Package Base"), a.PackageBase)
text.PrintInfoValue(gotext.Get("Snapshot URL"), config.AURURL+a.URLPath)
}
fmt.Println()
}
// BiggestPackages prints the name of the ten biggest packages in the system.
func biggestPackages(dbExecutor db.Executor) {
pkgS := dbExecutor.BiggestPackages()
if len(pkgS) < 10 {
return
}
for i := 0; i < 10; i++ {
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
}
// localStatistics prints installed packages statistics.
func localStatistics(dbExecutor db.Executor) error {
info := statistics(dbExecutor)
_, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}
text.Infoln(gotext.Get("Yay version v%s", yayVersion))
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(text.Bold(text.Cyan("===========================================")))
query.AURInfoPrint(remoteNames, config.RequestSplitN)
return nil
}
// TODO: Make it less hacky
func printNumberOfUpdates(dbExecutor db.Executor, enableDowngrade bool) error {
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err
}
fmt.Println(len(aurUp) + len(repoUp))
return nil
}
// TODO: Make it less hacky
func printUpdateList(cmdArgs *settings.Arguments, dbExecutor db.Executor, enableDowngrade bool) error {
targets := stringset.FromSlice(cmdArgs.Targets)
warnings := query.NewWarnings()
old := os.Stdout // keep backup of the real stdout
os.Stdout = nil
localNames, remoteNames, err := query.GetPackageNamesBySource(dbExecutor)
if err != nil {
return err
}
aurUp, repoUp, err := upList(warnings, dbExecutor, enableDowngrade)
os.Stdout = old // restoring the real stdout
if err != nil {
return err
}
noTargets := len(targets) == 0
if !cmdArgs.ExistsArg("m", "foreign") {
for _, pkg := range repoUp {
if noTargets || targets.Get(pkg.Name) {
if cmdArgs.ExistsArg("q", "quiet") {
fmt.Printf("%s\n", pkg.Name)
} else {
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
}
delete(targets, pkg.Name)
}
}
}
if !cmdArgs.ExistsArg("n", "native") {
for _, pkg := range aurUp {
if noTargets || targets.Get(pkg.Name) {
if cmdArgs.ExistsArg("q", "quiet") {
fmt.Printf("%s\n", pkg.Name)
} else {
fmt.Printf("%s %s -> %s\n", text.Bold(pkg.Name), text.Green(pkg.LocalVersion), text.Green(pkg.RemoteVersion))
}
delete(targets, pkg.Name)
}
}
}
missing := false
outer:
for pkg := range targets {
for _, name := range localNames {
if name == pkg {
continue outer
}
}
for _, name := range remoteNames {
if name == pkg {
continue outer
}
}
text.Errorln(gotext.Get("package '%s' was not found", pkg))
missing = true
}
if missing {
return fmt.Errorf("")
}
return nil
}