From c9df5ebf681cc08867e3cf6afcd14ebb0ad37d5d Mon Sep 17 00:00:00 2001 From: gerblesh <101901964+gerblesh@users.noreply.github.com> Date: Wed, 25 Dec 2024 17:21:19 -0800 Subject: [PATCH] fix: disable OSC incrementer --- cmd/update.go | 6 +++--- drv/distrobox/distrobox.go | 8 ++++---- drv/flatpak/flatpak.go | 8 ++++---- pkg/percent/incrementer.go | 1 + pkg/percent/progressmanager.go | 16 +++++++++------- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/cmd/update.go b/cmd/update.go index 1882aef..b822a15 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -117,7 +117,7 @@ func Update(cmd *cobra.Command, args []string) { } // -1 because 0 index - tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1} + tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1, OscEnabled: !disableOsc} flatpakUpdater.Tracker = tracker distroboxUpdater.Tracker = tracker @@ -144,7 +144,7 @@ func Update(cmd *cobra.Command, args []string) { if mainSystemDriverConfig.Enabled { slog.Debug(fmt.Sprintf("%s module", mainSystemDriverConfig.Title), slog.String("module_name", mainSystemDriverConfig.Title), slog.Any("module_configuration", mainSystemDriverConfig)) - percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: mainSystemDriverConfig.Title, Description: mainSystemDriverConfig.Description}) + tracker.ReportStatusChange(mainSystemDriverConfig.Title, mainSystemDriverConfig.Description) var out *[]drv.CommandOutput out, err = mainSystemDriver.Update() outputs = append(outputs, *out...) @@ -153,7 +153,7 @@ func Update(cmd *cobra.Command, args []string) { if brewUpdater.Config.Enabled { slog.Debug(fmt.Sprintf("%s module", brewUpdater.Config.Title), slog.String("module_name", brewUpdater.Config.Title), slog.Any("module_configuration", brewUpdater.Config)) - percent.ReportStatusChange(tracker, percent.TrackerMessage{Title: brewUpdater.Config.Title, Description: brewUpdater.Config.Description}) + tracker.ReportStatusChange(brewUpdater.Config.Title, brewUpdater.Config.Description) var out *[]drv.CommandOutput out, err = brewUpdater.Update() outputs = append(outputs, *out...) diff --git a/drv/distrobox/distrobox.go b/drv/distrobox/distrobox.go index 6ad670e..3b69b94 100644 --- a/drv/distrobox/distrobox.go +++ b/drv/distrobox/distrobox.go @@ -73,18 +73,18 @@ func (up DistroboxUpdater) Update() (*[]CommandOutput, error) { var finalOutput = []CommandOutput{} if up.Config.DryRun { - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + up.Tracker.ReportStatusChange(up.Config.Title, up.Config.Description) up.Tracker.IncrementSection(nil) var err error = nil for _, user := range up.users { up.Tracker.IncrementSection(err) - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + up.Tracker.ReportStatusChange(up.Config.Title, *up.Config.UserDescription+" "+user.Name) } return &finalOutput, nil } - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + up.Tracker.ReportStatusChange(up.Config.Title, up.Config.Description) cli := []string{up.binaryPath, "upgrade", "-a"} out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, 0, cli, nil) tmpout := CommandOutput{}.New(out, err) @@ -97,7 +97,7 @@ func (up DistroboxUpdater) Update() (*[]CommandOutput, error) { for _, user := range up.users { up.Tracker.IncrementSection(err) context := *up.Config.UserDescription + " " + user.Name - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + up.Tracker.ReportStatusChange(up.Config.Title, *up.Config.UserDescription+" "+user.Name) cli := []string{up.binaryPath, "upgrade", "-a"} out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, user.UID, cli, nil) tmpout = CommandOutput{}.New(out, err) diff --git a/drv/flatpak/flatpak.go b/drv/flatpak/flatpak.go index 7cbfd79..76ff670 100644 --- a/drv/flatpak/flatpak.go +++ b/drv/flatpak/flatpak.go @@ -62,18 +62,18 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) { var finalOutput = []CommandOutput{} if up.Config.DryRun { - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + up.Tracker.ReportStatusChange(up.Config.Title, up.Config.Description) up.Tracker.IncrementSection(nil) var err error = nil for _, user := range up.users { up.Tracker.IncrementSection(err) - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: *up.Config.UserDescription + " " + user.Name}) + up.Tracker.ReportStatusChange(up.Config.Title, *up.Config.UserDescription+" "+user.Name) } return &finalOutput, nil } - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: up.Config.Description}) + up.Tracker.ReportStatusChange(up.Config.Title, up.Config.Description) cli := []string{up.binaryPath, "update", "-y", "--noninteractive"} flatpakCmd := exec.Command(cli[0], cli[1:]...) out, err := session.RunLog(up.Config.Logger, slog.LevelDebug, flatpakCmd) @@ -87,7 +87,7 @@ func (up FlatpakUpdater) Update() (*[]CommandOutput, error) { for _, user := range up.users { up.Tracker.IncrementSection(err) context := *up.Config.UserDescription + " " + user.Name - percent.ReportStatusChange(up.Tracker, percent.TrackerMessage{Title: up.Config.Title, Description: context}) + up.Tracker.ReportStatusChange(up.Config.Title, context) cli := []string{up.binaryPath, "update", "-y"} out, err := session.RunUID(up.Config.Logger, slog.LevelDebug, user.UID, cli, nil) tmpout = CommandOutput{}.New(out, err) diff --git a/pkg/percent/incrementer.go b/pkg/percent/incrementer.go index 725c7d4..1086b77 100644 --- a/pkg/percent/incrementer.go +++ b/pkg/percent/incrementer.go @@ -3,6 +3,7 @@ package percent type Incrementer struct { DoneIncrements int MaxIncrements int + OscEnabled bool } func (it *Incrementer) IncrementSection(err error) { diff --git a/pkg/percent/progressmanager.go b/pkg/percent/progressmanager.go index a14f26a..3846886 100644 --- a/pkg/percent/progressmanager.go +++ b/pkg/percent/progressmanager.go @@ -1,18 +1,20 @@ package percent import ( + "fmt" "log/slog" + "math" ) -type TrackerMessage struct { - Title string - Description string -} +func (tracker Incrementer) ReportStatusChange(title string, description string) { + if tracker.OscEnabled { + percentage := math.Round((float64(tracker.CurrentStep()) / float64(tracker.MaxIncrements)) * 100) + fmt.Printf("\033]9;4;1;%d\a", int(percentage)) + } -func ReportStatusChange(tracker *Incrementer, message TrackerMessage) { slog.Info("Updating", - slog.String("title", message.Title), - slog.String("description", message.Description), + slog.String("title", title), + slog.String("description", description), slog.Int("progress", tracker.CurrentStep()), slog.Int("total", tracker.MaxIncrements), )