types.go 2.7 KB

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