1
0
mirror of https://github.com/Jguer/yay synced 2024-07-09 12:56:32 +00:00

Fixed a very subtle bug that hided the first result of every search in bottom up

This commit is contained in:
Jguer 2017-05-07 03:29:01 +01:00
parent bd2842841a
commit a20646fa24
3 changed files with 18 additions and 45 deletions

View File

@ -72,7 +72,7 @@ func PkgInstall(a *rpc.Pkg, flags []string) (finalmdeps []string, err error) {
}
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") {
_ = os.RemoveAll(config.YayConf.BuildDir + a.PackageBase)
}

View File

@ -9,40 +9,23 @@ import (
"github.com/jguer/yay/config"
)
// Query describes a Repository search.
type Query []Result
// Result describes a pkg.
type Result struct {
Name string
Repository string
Version string
Description string
Group string
Installed bool
}
// Query holds the results of a repository search.
type Query []alpm.Package
// Search handles repo searches. Creates a RepoSearch struct.
func Search(pkgInputN []string) (s Query, n int, err error) {
localDb, err := config.AlpmHandle.LocalDb()
if err != nil {
return
}
dbList, err := config.AlpmHandle.SyncDbs()
if err != nil {
return
}
var installed bool
dbS := dbList.Slice()
// BottomUp functions
initL := func(len int) int {
return len - 1
}
compL := func(len int, i int) bool {
return i > 0
return i > -1
}
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)
for f := initL(lenDbs); compL(lenDbs, f); f = finalL(f) {
pkgS := dbS[f].PkgCache().Slice()
lenPkgs := len(pkgS)
for i := initL(lenPkgs); compL(lenPkgs, i); i = finalL(i) {
match := true
for _, pkgN := range pkgInputN {
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 {
installed = false
if r, _ := localDb.PkgByName(pkgS[i].Name()); r != nil {
installed = true
}
n++
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,
})
s = append(s, pkgS[i])
}
}
}
@ -111,21 +81,24 @@ func (s Query) PrintSearch() {
toprint += fmt.Sprintf("%d ", i)
}
} else if config.YayConf.SearchMode == config.Minimal {
fmt.Println(res.Name)
fmt.Println(res.Name())
continue
}
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 {
toprint += fmt.Sprintf("(%s) ", res.Group)
if len(res.Groups().Slice()) != 0 {
toprint += fmt.Sprint(res.Groups().Slice(), " ")
}
if res.Installed {
toprint += fmt.Sprintf("\x1b[32;40mInstalled\x1b[0m")
localDb, err := config.AlpmHandle.LocalDb()
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)
}
}

4
yay.go
View File

@ -199,9 +199,9 @@ func numberMenu(pkgS []string, flags []string) (err error) {
}
} else {
if config.YayConf.SortMode == config.BottomUp {
repoInstall = append(repoInstall, pq[numpq-num-1].Name)
repoInstall = append(repoInstall, pq[numpq-num-1].Name())
} else {
repoInstall = append(repoInstall, pq[num].Name)
repoInstall = append(repoInstall, pq[num].Name())
}
}
}