types.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package query
  2. import (
  3. "fmt"
  4. "strconv"
  5. "github.com/Jguer/aur"
  6. "github.com/Jguer/go-alpm/v2"
  7. "github.com/leonelquinteros/gotext"
  8. "github.com/Jguer/yay/v12/pkg/db"
  9. "github.com/Jguer/yay/v12/pkg/text"
  10. )
  11. func getSearchBy(value string) aur.By {
  12. switch value {
  13. case "name":
  14. return aur.Name
  15. case "maintainer":
  16. return aur.Maintainer
  17. case "submitter":
  18. return aur.Submitter
  19. case "depends":
  20. return aur.Depends
  21. case "makedepends":
  22. return aur.MakeDepends
  23. case "optdepends":
  24. return aur.OptDepends
  25. case "checkdepends":
  26. return aur.CheckDepends
  27. case "provides":
  28. return aur.Provides
  29. case "conflicts":
  30. return aur.Conflicts
  31. case "replaces":
  32. return aur.Replaces
  33. case "groups":
  34. return aur.Groups
  35. case "keywords":
  36. return aur.Keywords
  37. case "comaintainers":
  38. return aur.CoMaintainers
  39. default:
  40. return aur.NameDesc
  41. }
  42. }
  43. func aurPkgSearchString(
  44. pkg *aur.Pkg,
  45. dbExecutor db.Executor,
  46. singleLineResults bool,
  47. ) string {
  48. toPrint := text.Bold(text.ColorHash("aur")) + "/" + text.Bold(pkg.Name) +
  49. " " + text.Cyan(pkg.Version) +
  50. text.Bold(" (+"+strconv.Itoa(pkg.NumVotes)) +
  51. " " + text.Bold(strconv.FormatFloat(pkg.Popularity, 'f', 2, 64)+") ")
  52. if pkg.Maintainer == "" {
  53. toPrint += text.Bold(text.Red(gotext.Get("(Orphaned)"))) + " "
  54. }
  55. if pkg.OutOfDate != 0 {
  56. toPrint += text.Bold(text.Red(gotext.Get("(Out-of-date: %s)", text.FormatTime(pkg.OutOfDate)))) + " "
  57. }
  58. if localPkg := dbExecutor.LocalPackage(pkg.Name); localPkg != nil {
  59. if localPkg.Version() != pkg.Version {
  60. toPrint += text.Bold(text.Green(gotext.Get("(Installed: %s)", localPkg.Version())))
  61. } else {
  62. toPrint += text.Bold(text.Green(gotext.Get("(Installed)")))
  63. }
  64. }
  65. if singleLineResults {
  66. toPrint += "\t"
  67. } else {
  68. toPrint += "\n "
  69. }
  70. toPrint += pkg.Description
  71. return toPrint
  72. }
  73. // PrintSearch receives a RepoSearch type and outputs pretty text.
  74. func syncPkgSearchString(pkg alpm.IPackage, dbExecutor db.Executor, singleLineResults bool) string {
  75. toPrint := text.Bold(text.ColorHash(pkg.DB().Name())) + "/" + text.Bold(pkg.Name()) +
  76. " " + text.Cyan(pkg.Version()) +
  77. text.Bold(" ("+text.Human(pkg.Size())+
  78. " "+text.Human(pkg.ISize())+") ")
  79. packageGroups := dbExecutor.PackageGroups(pkg)
  80. if len(packageGroups) != 0 {
  81. toPrint += fmt.Sprint(packageGroups, " ")
  82. }
  83. if localPkg := dbExecutor.LocalPackage(pkg.Name()); localPkg != nil {
  84. if localPkg.Version() != pkg.Version() {
  85. toPrint += text.Bold(text.Green(gotext.Get("(Installed: %s)", localPkg.Version())))
  86. } else {
  87. toPrint += text.Bold(text.Green(gotext.Get("(Installed)")))
  88. }
  89. }
  90. if singleLineResults {
  91. toPrint += "\t"
  92. } else {
  93. toPrint += "\n "
  94. }
  95. toPrint += pkg.Description()
  96. return toPrint
  97. }