From 1d292f2a671170aaa9a350cd56279c69d720dd11 Mon Sep 17 00:00:00 2001 From: moson-mo Date: Thu, 21 Apr 2022 16:19:37 +0200 Subject: [PATCH] fix: update of installed state after install/removal 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. --- internal/pacseek/commands.go | 6 +----- internal/pacseek/draw.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/internal/pacseek/commands.go b/internal/pacseek/commands.go index 88807b9..9ab0080 100644 --- a/internal/pacseek/commands.go +++ b/internal/pacseek/commands.go @@ -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" diff --git a/internal/pacseek/draw.go b/internal/pacseek/draw.go index c1306af..022023c 100644 --- a/internal/pacseek/draw.go +++ b/internal/pacseek/draw.go @@ -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) + } +}