From cc482e388b93d324d3c3bf6b63d78e8d2d45ace3 Mon Sep 17 00:00:00 2001 From: Vito Castellano Date: Tue, 4 Feb 2025 00:31:58 +0100 Subject: [PATCH] update homebrew integration --- internal/services/app.go | 20 +++++++++++++++++++- internal/services/command.go | 6 ++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/services/app.go b/internal/services/app.go index f050468..2f458c5 100644 --- a/internal/services/app.go +++ b/internal/services/app.go @@ -231,7 +231,7 @@ func (s *AppService) BuildApp() { SetTextAlign(tview.AlignCenter) legend := tview.NewTextView(). - SetText(tview.Escape("[Up/Down] Navigate | [/] Search | [f] Filter Installed Only | [i] Install | [u] Update | [r] Remove | [Esc] Back to Table | [q] Quit")). + SetText(tview.Escape("[/] Search | [f] Filter Installed | [i] Install | [u] Update | [r] Remove | [Esc] Back to Table | [ctrl+u] Update Homebrew | [q] Quit")). SetDynamicColors(true). SetTextAlign(tview.AlignCenter) @@ -406,6 +406,24 @@ func (s *AppService) handleKeyEventInput(event *tcell.EventKey) *tcell.EventKey s.table.ScrollToBeginning() return nil } + case tcell.KeyCtrlU: + // Update homebrew + modal := s.createModal("Are you sure you want to update Homebrew?", func() { + s.outputView.Clear() + go func() { + err := s.CommandService.UpdateHomebrew(s.app, s.outputView) + if err != nil { + s.app.QueueUpdateDraw(func() { + errorModal := s.createModal(fmt.Sprintf("Failed to update Homebrew\nError: %v", err), nil) + s.app.SetRoot(errorModal, true).SetFocus(errorModal) + }) + } else { + s.updateTableView() + } + }() + }) + s.app.SetRoot(modal, true).SetFocus(modal) + return nil case tcell.KeyEsc: // Remove the modal if it is currently displayed if s.currentModal != nil { diff --git a/internal/services/command.go b/internal/services/command.go index 94c2b5e..f34175d 100644 --- a/internal/services/command.go +++ b/internal/services/command.go @@ -11,6 +11,7 @@ type CommandServiceInterface interface { UpdatePackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error RemovePackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error InstallPackage(info models.Formula, app *tview.Application, outputView *tview.TextView) error + UpdateHomebrew(app *tview.Application, outputView *tview.TextView) error } type CommandService struct{} @@ -34,6 +35,11 @@ func (s *CommandService) InstallPackage(info models.Formula, app *tview.Applicat return s.executeCommand(app, cmd, outputView) } +func (s *CommandService) UpdateHomebrew(app *tview.Application, outputView *tview.TextView) error { + cmd := exec.Command("brew", "update") + return s.executeCommand(app, cmd, outputView) +} + func (s *CommandService) executeCommand( app *tview.Application, cmd *exec.Cmd,