Skip to content

Commit

Permalink
v1.0.0 - Release
Browse files Browse the repository at this point in the history
* Added request caching
* Fixed data-races
* Added "Provides" and "Conflicts" in package info dialog
* Reset focus to first package when search is performed (again)
  • Loading branch information
moson-mo committed Apr 5, 2022
1 parent bd2d17d commit e031316
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 372 deletions.
625 changes: 323 additions & 302 deletions coverage.out

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 h1:xe+mmCnDN82KhC010l3NfYlA8ZbOuzbXAzSYBa6wbMc=
Expand Down
4 changes: 4 additions & 0 deletions internal/pacseek/pacman.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ func infoPacman(h *alpm.Handle, pkg string) RpcResult {
deps := []string{}
makedeps := []string{}
odeps := []string{}
prov := []string{}
conf := []string{}
for _, d := range p.Depends().Slice() {
deps = append(deps, d.Name)
}
Expand All @@ -123,6 +125,8 @@ func infoPacman(h *alpm.Handle, pkg string) RpcResult {
i := InfoRecord{
Name: p.Name(),
Description: p.Description(),
Provides: prov,
Conflicts: conf,
Version: p.Version(),
License: p.Licenses().Slice(),
Maintainer: p.Packager(),
Expand Down
138 changes: 93 additions & 45 deletions internal/pacseek/pacseek.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import (
"github.com/Jguer/go-alpm/v2"
"github.com/gdamore/tcell/v2"
"github.com/moson-mo/pacseek/internal/config"
"github.com/patrickmn/go-cache"
"github.com/rivo/tview"
)

const (
colorHighlight = "[#1793d1]"
colorTitle = "[#00dfff]"

version = "0.2.7"
version = "1.0.0"
)

// UI is holding our application information and all tview components
Expand Down Expand Up @@ -52,6 +53,7 @@ type UI struct {
width int
selectedPackage *InfoRecord
settingsChanged bool
cache *cache.Cache
}

// New creates a UI object and makes sure everything is initialized
Expand All @@ -63,6 +65,7 @@ func New(config *config.Settings) (*UI, error) {
messageLocker: &sync.RWMutex{},
quitSpin: make(chan bool),
settingsChanged: false,
cache: cache.New(5*time.Minute, 1*time.Minute),
}

var err error
Expand Down Expand Up @@ -424,7 +427,8 @@ func (ps *UI) showPackageInfo(row, column int) {
source := ps.packages.GetCell(row, 1).Text

go func() {
if source == "AUR" {
infoCached, foundCached := ps.cache.Get(pkg)
if source == "AUR" && !foundCached {
time.Sleep(time.Duration(ps.conf.AurSearchDelay) * time.Millisecond)
}

Expand All @@ -436,15 +440,22 @@ func (ps *UI) showPackageInfo(row, column int) {
})

ps.locker.Lock()
ps.startSpin()
defer ps.stopSpin()
if !foundCached {
ps.startSpin()
defer ps.stopSpin()
}
defer ps.locker.Unlock()

var info RpcResult
if source == "AUR" {
info = infoAur(ps.conf.AurRpcUrl, pkg, ps.conf.AurTimeout)
if !foundCached {
if source == "AUR" {
info = infoAur(ps.conf.AurRpcUrl, pkg, ps.conf.AurTimeout)
} else {
info = infoPacman(ps.alpmHandle, pkg)
}
ps.cache.Set(pkg, info, cache.DefaultExpiration)
} else {
info = infoPacman(ps.alpmHandle, pkg)
info = infoCached.(RpcResult)
}

// draw results
Expand All @@ -458,7 +469,7 @@ func (ps *UI) showPackageInfo(row, column int) {
errorMsg = info.Error
}
ps.details.SetTitle(" [red]Error ")
ps.details.SetCellSimple(0, 0, fmt.Sprintf("[red]%s", errorMsg))
ps.details.SetCellSimple(0, 0, "[red]s"+errorMsg)
return
}
ps.selectedPackage = &info.Results[0]
Expand Down Expand Up @@ -505,39 +516,51 @@ func (ps *UI) showPackages(text string) {
go func() {
ps.locker.Lock()
defer ps.locker.Unlock()
defer ps.showPackageInfo(1, 0)
packages, err := searchRepos(ps.alpmHandle, text, ps.conf.SearchMode, ps.conf.SearchBy, ps.conf.MaxResults)
if err != nil {
ps.app.QueueUpdateDraw(func() {
ps.showMessage(err.Error(), true)
})
}
if !ps.conf.DisableAur {
aurPackages, err := searchAur(ps.conf.AurRpcUrl, text, ps.conf.AurTimeout, ps.conf.SearchMode, ps.conf.SearchBy, ps.conf.MaxResults)
defer ps.app.QueueUpdate(func() { ps.showPackageInfo(1, 0) })

var packages []Package
packagesCache, foundCache := ps.cache.Get("[search]" + text)

if !foundCache {
var err error
packages, err = searchRepos(ps.alpmHandle, text, ps.conf.SearchMode, ps.conf.SearchBy, ps.conf.MaxResults)
if err != nil {
ps.app.QueueUpdateDraw(func() {
ps.showMessage(err.Error(), true)
})
}
if !ps.conf.DisableAur {
aurPackages, err := searchAur(ps.conf.AurRpcUrl, text, ps.conf.AurTimeout, ps.conf.SearchMode, ps.conf.SearchBy, ps.conf.MaxResults)
if err != nil {
ps.app.QueueUpdateDraw(func() {
ps.showMessage(err.Error(), true)
})
}

for i := 0; i < len(aurPackages); i++ {
aurPackages[i].IsInstalled = isInstalled(ps.alpmHandle, aurPackages[i].Name)
for i := 0; i < len(aurPackages); i++ {
aurPackages[i].IsInstalled = isInstalled(ps.alpmHandle, aurPackages[i].Name)
}

packages = append(packages, aurPackages...)
}

packages = append(packages, aurPackages...)
}
sort.Slice(packages, func(i, j int) bool {
return packages[i].Name < packages[j].Name
})

sort.Slice(packages, func(i, j int) bool {
return packages[i].Name < packages[j].Name
})
if len(packages) == 0 {
ps.app.QueueUpdateDraw(func() {
ps.showMessage("No packages found for search-term: "+text, false)
})
}
if len(packages) > ps.conf.MaxResults {
packages = packages[:ps.conf.MaxResults]
}

if len(packages) == 0 {
ps.app.QueueUpdateDraw(func() {
ps.showMessage("No packages found for searh-term: "+text, false)
})
}
if len(packages) > ps.conf.MaxResults {
packages = packages[:ps.conf.MaxResults]
ps.cache.Set("[search]"+text, packages, cache.DefaultExpiration)

} else {
packages = packagesCache.([]Package)
}

// draw packages
Expand All @@ -546,6 +569,14 @@ func (ps *UI) showPackages(text string) {
return
}
ps.drawPackages(packages)
if ps.right.GetItem(0) == ps.settings {
ps.right.Clear()
ps.right.AddItem(ps.details, 0, 1, false)
}
r, _ := ps.packages.GetSelection()
if r > 1 {
ps.packages.Select(1, 0)
}
})
}()
}
Expand Down Expand Up @@ -791,8 +822,9 @@ func (ps *UI) runCommand(command string, args []string) {
cmd.Stderr = os.Stderr

// handle SIGINT and forward to the child process
cmd.Start()
quit := handleSigint(cmd)
cmd.Run()
cmd.Wait()
quit <- true
})
// we need to reinitialize the alpm handler to get the proper install state
Expand Down Expand Up @@ -851,6 +883,8 @@ func getDetailFields(i InfoRecord) (map[string]string, []string) {
order := []string{
"Description",
"Version",
"Provides",
"Conflicts",
"Licenses",
"Maintainer",
"Dependencies",
Expand All @@ -863,28 +897,43 @@ func getDetailFields(i InfoRecord) (map[string]string, []string) {
fields := map[string]string{}
fields[order[0]] = i.Description
fields[order[1]] = i.Version
fields[order[2]] = strings.Join(i.License, ", ")
fields[order[3]] = i.Maintainer
fields[order[2]] = strings.Join(i.Provides, ", ")
fields[order[3]] = strings.Join(i.Conflicts, ", ")
fields[order[4]] = strings.Join(i.License, ", ")
fields[order[5]] = i.Maintainer

fields[order[6]] = getDependenciesJoined(i)
fields[order[7]] = i.URL
if i.Source == "AUR" {
fields[order[8]] = fmt.Sprintf("%d", i.NumVotes)
fields[order[9]] = fmt.Sprintf("%f", i.Popularity)
}
fields[order[10]] = time.Unix(int64(i.LastModified), 0).UTC().Format("2006-01-02 - 15:04:05 (UTC)")

return fields, order
}

// join and format different dependencies as string
func getDependenciesJoined(i InfoRecord) string {
mdeps := strings.Join(i.MakeDepends, " (make), ")
if mdeps != "" {
mdeps = "\n" + mdeps
mdeps += " (make)"
}
odeps := strings.Join(i.OptDepends, " (opt), ")
if odeps != "" {
odeps = "\n" + odeps
odeps += " (opt)"
}
fields[order[4]] = strings.Join(i.Depends, ", ") + mdeps + odeps
fields[order[5]] = i.URL
if i.Source == "AUR" {
fields[order[6]] = fmt.Sprintf("%d", i.NumVotes)
fields[order[7]] = fmt.Sprintf("%f", i.Popularity)
}
fields[order[8]] = time.Unix(int64(i.LastModified), 0).UTC().Format("2006-01-02 - 15:04:05 (UTC)")

return fields, order
deps := strings.Join(i.Depends, ", ")
if deps != "" && mdeps != "" {
deps += "\n"
}
deps += mdeps
if deps != "" && odeps != "" {
deps += "\n"
}
deps += odeps
return deps
}

// handles SIGINT call and passes it to a cmd process
Expand All @@ -899,7 +948,6 @@ func handleSigint(cmd *exec.Cmd) chan bool {
cmd.Process.Signal(os.Interrupt)
}
case <-quit:
return
}
}()
return quit
Expand Down
51 changes: 26 additions & 25 deletions test_coverage.out
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@ github.com/moson-mo/pacseek/internal/pacseek/aur.go:77: infoAur 93.3%
github.com/moson-mo/pacseek/internal/pacseek/pacman.go:12: initPacmanDbs 90.9%
github.com/moson-mo/pacseek/internal/pacseek/pacman.go:33: searchRepos 87.5%
github.com/moson-mo/pacseek/internal/pacseek/pacman.go:78: isInstalled 87.5%
github.com/moson-mo/pacseek/internal/pacseek/pacman.go:93: infoPacman 90.9%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:58: New 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:83: Start 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:92: setupComponents 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:150: setupKeyBindings 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:270: setupSettingsForm 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:417: showPackageInfo 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:472: drawPackageInfo 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:504: showPackages 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:549: drawPackages 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:582: drawPackagesHeader 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:601: showMessage 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:621: showHelp 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:634: showAbout 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:657: saveSettings 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:724: startSpin 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:754: installPackage 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:779: runCommand 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:802: performSyncSysUpgrade 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:810: isSelected 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:827: stopSpin 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:832: reinitPacmanDbs 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:845: getDetailFields 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:886: handleSigint 0.0%
total: (statements) 18.7%
github.com/moson-mo/pacseek/internal/pacseek/pacman.go:93: infoPacman 91.7%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:60: New 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:86: Start 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:95: setupComponents 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:153: setupKeyBindings 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:273: setupSettingsForm 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:420: showPackageInfo 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:483: drawPackageInfo 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:515: showPackages 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:585: drawPackages 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:618: drawPackagesHeader 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:637: showMessage 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:657: showHelp 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:670: showAbout 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:693: saveSettings 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:760: startSpin 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:790: installPackage 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:815: runCommand 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:839: performSyncSysUpgrade 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:847: isSelected 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:864: stopSpin 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:869: reinitPacmanDbs 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:882: getDetailFields 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:917: getDependenciesJoined 0.0%
github.com/moson-mo/pacseek/internal/pacseek/pacseek.go:940: handleSigint 0.0%
total: (statements) 18.1%

0 comments on commit e031316

Please sign in to comment.