Skip to content

Commit

Permalink
fix: disable OSC incrementer
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Dec 26, 2024
1 parent 1f3f3ac commit c9df5eb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
Expand All @@ -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...)
Expand Down
8 changes: 4 additions & 4 deletions drv/distrobox/distrobox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions drv/flatpak/flatpak.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/percent/incrementer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package percent
type Incrementer struct {
DoneIncrements int
MaxIncrements int
OscEnabled bool
}

func (it *Incrementer) IncrementSection(err error) {
Expand Down
16 changes: 9 additions & 7 deletions pkg/percent/progressmanager.go
Original file line number Diff line number Diff line change
@@ -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),
)
Expand Down

0 comments on commit c9df5eb

Please sign in to comment.