Skip to content

Commit

Permalink
fix: update of installed state after install/removal
Browse files Browse the repository at this point in the history
When a package is installed, the state of all shown package should be updated.
The list might contain other packages that got installed along the selected one.
Also, any cached data needs to be updated.
  • Loading branch information
moson-mo committed Apr 21, 2022
1 parent 65cd90b commit 1d292f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
6 changes: 1 addition & 5 deletions internal/pacseek/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ func (ps *UI) installPackage() {
ps.runCommand(ps.shell, args)

// update package install status
if isInstalled(ps.alpmHandle, pkg) {
ps.packages.SetCellSimple(row, 2, "Y")
} else {
ps.packages.SetCellSimple(row, 2, "-")
}
ps.updateInstalledState()
}

// issues "Update command"
Expand Down
28 changes: 28 additions & 0 deletions internal/pacseek/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,31 @@ func getDependenciesJoined(i InfoRecord) string {
deps += odeps
return deps
}

// updates the "install state" of all packages in cache and package list
func (ps *UI) updateInstalledState() {
// update cached packages
sterm := ps.search.GetText()
cpkg, exp, found := ps.searchCache.GetWithExpiration(sterm)
scpkg := cpkg.([]Package)
if found {
for i := 0; i < len(scpkg); i++ {
scpkg[i].IsInstalled = isInstalled(ps.alpmHandle, scpkg[i].Name)
}
ps.searchCache.Set(sterm, scpkg, exp.Sub(time.Now()))
}

// update currently shown packages
for i := 1; i < ps.packages.GetRowCount(); i++ {
newCell := &tview.TableCell{
Text: "-",
Expansion: 1000,
Color: tcell.ColorWhite,
BackgroundColor: tcell.ColorBlack,
}
if isInstalled(ps.alpmHandle, ps.packages.GetCell(i, 0).Text) {
newCell.Text = "Y"
}
ps.packages.SetCell(i, 2, newCell)
}
}

0 comments on commit 1d292f2

Please sign in to comment.