mirror of
https://github.com/Jguer/yay
synced 2024-07-23 03:04:10 +00:00
Fixed a very subtle bug that hided the first result of every search in bottom up
This commit is contained in:
parent
bd2842841a
commit
a20646fa24
|
@ -72,7 +72,7 @@ func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
|
||||||
}
|
}
|
||||||
dir := config.YayConf.BuildDir + a.PackageBase + "/"
|
dir := config.YayConf.BuildDir + a.PackageBase + "/"
|
||||||
|
|
||||||
if _, err = os.Stat(dir); os.IsExist(err) {
|
if _, err = os.Stat(dir); !os.IsNotExist(err) {
|
||||||
if !config.ContinueTask("Directory exists. Clean Build?", "yY") {
|
if !config.ContinueTask("Directory exists. Clean Build?", "yY") {
|
||||||
_ = os.RemoveAll(config.YayConf.BuildDir + a.PackageBase)
|
_ = os.RemoveAll(config.YayConf.BuildDir + a.PackageBase)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,40 +9,23 @@ import (
|
||||||
"github.com/jguer/yay/config"
|
"github.com/jguer/yay/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Query describes a Repository search.
|
// Query holds the results of a repository search.
|
||||||
type Query []Result
|
type Query []alpm.Package
|
||||||
|
|
||||||
// Result describes a pkg.
|
|
||||||
type Result struct {
|
|
||||||
Name string
|
|
||||||
Repository string
|
|
||||||
Version string
|
|
||||||
Description string
|
|
||||||
Group string
|
|
||||||
Installed bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Search handles repo searches. Creates a RepoSearch struct.
|
// Search handles repo searches. Creates a RepoSearch struct.
|
||||||
func Search(pkgInputN []string) (s Query, n int, err error) {
|
func Search(pkgInputN []string) (s Query, n int, err error) {
|
||||||
localDb, err := config.AlpmHandle.LocalDb()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dbList, err := config.AlpmHandle.SyncDbs()
|
dbList, err := config.AlpmHandle.SyncDbs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var installed bool
|
|
||||||
dbS := dbList.Slice()
|
|
||||||
|
|
||||||
// BottomUp functions
|
// BottomUp functions
|
||||||
initL := func(len int) int {
|
initL := func(len int) int {
|
||||||
return len - 1
|
return len - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
compL := func(len int, i int) bool {
|
compL := func(len int, i int) bool {
|
||||||
return i > 0
|
return i > -1
|
||||||
}
|
}
|
||||||
|
|
||||||
finalL := func(i int) int {
|
finalL := func(i int) int {
|
||||||
|
@ -64,13 +47,12 @@ func Search(pkgInputN []string) (s Query, n int, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dbS := dbList.Slice()
|
||||||
lenDbs := len(dbS)
|
lenDbs := len(dbS)
|
||||||
for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
|
for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
|
||||||
pkgS := dbS[f].PkgCache().Slice()
|
pkgS := dbS[f].PkgCache().Slice()
|
||||||
lenPkgs := len(pkgS)
|
lenPkgs := len(pkgS)
|
||||||
|
|
||||||
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
|
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
|
||||||
|
|
||||||
match := true
|
match := true
|
||||||
for _, pkgN := range pkgInputN {
|
for _, pkgN := range pkgInputN {
|
||||||
if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
|
if !(strings.Contains(pkgS[i].Name(), pkgN) || strings.Contains(strings.ToLower(pkgS[i].Description()), pkgN)) {
|
||||||
|
@ -80,20 +62,8 @@ func Search(pkgInputN []string) (s Query, n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if match {
|
if match {
|
||||||
installed = false
|
|
||||||
if r, _ := localDb.PkgByName(pkgS[i].Name()); r != nil {
|
|
||||||
installed = true
|
|
||||||
}
|
|
||||||
n++
|
n++
|
||||||
|
s = append(s, pkgS[i])
|
||||||
s = append(s, Result{
|
|
||||||
Name: pkgS[i].Name(),
|
|
||||||
Description: pkgS[i].Description(),
|
|
||||||
Version: pkgS[i].Version(),
|
|
||||||
Repository: dbS[f].Name(),
|
|
||||||
Group: strings.Join(pkgS[i].Groups().Slice(), ","),
|
|
||||||
Installed: installed,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,21 +81,24 @@ func (s Query) PrintSearch() {
|
||||||
toprint += fmt.Sprintf("%d ", i)
|
toprint += fmt.Sprintf("%d ", i)
|
||||||
}
|
}
|
||||||
} else if config.YayConf.SearchMode == config.Minimal {
|
} else if config.YayConf.SearchMode == config.Minimal {
|
||||||
fmt.Println(res.Name)
|
fmt.Println(res.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m",
|
toprint += fmt.Sprintf("\x1b[1m%s/\x1b[33m%s \x1b[36m%s \x1b[0m",
|
||||||
res.Repository, res.Name, res.Version)
|
res.DB().Name(), res.Name(), res.Version())
|
||||||
|
|
||||||
if len(res.Group) != 0 {
|
if len(res.Groups().Slice()) != 0 {
|
||||||
toprint += fmt.Sprintf("(%s) ", res.Group)
|
toprint += fmt.Sprint(res.Groups().Slice(), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Installed {
|
localDb, err := config.AlpmHandle.LocalDb()
|
||||||
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
if err == nil {
|
||||||
|
if _, err = localDb.PkgByName(res.Name()); err == nil {
|
||||||
|
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toprint += "\n" + res.Description
|
toprint += "\n" + res.Description()
|
||||||
fmt.Println(toprint)
|
fmt.Println(toprint)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
yay.go
4
yay.go
|
@ -199,9 +199,9 @@ func numberMenu(pkgS []string, flags []string) (err error) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if config.YayConf.SortMode == config.BottomUp {
|
if config.YayConf.SortMode == config.BottomUp {
|
||||||
repoInstall = append(repoInstall, pq[numpq-num-1].Name)
|
repoInstall = append(repoInstall, pq[numpq-num-1].Name())
|
||||||
} else {
|
} else {
|
||||||
repoInstall = append(repoInstall, pq[num].Name)
|
repoInstall = append(repoInstall, pq[num].Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue