Skip to content

Commit

Permalink
fix: ensure OSC is being printed on non-tty context
Browse files Browse the repository at this point in the history
  • Loading branch information
tulilirockz committed Dec 8, 2024
1 parent b8ee669 commit 575c827
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ func Update(cmd *cobra.Command, args []string) {
slog.Error("Failed releasing lock")
}
}()
// Disables the loading icon on the terminal
defer print("\033]9;4;0\a")
// Clears up any previous loading icon
print("\033]9;4;0\a")

hwCheck, err := cmd.Flags().GetBool("hw-check")
if err != nil {
Expand Down Expand Up @@ -106,6 +102,7 @@ func Update(cmd *cobra.Command, args []string) {

if progressEnabled {
go pw.Render()
lib.ResetOscProgress()
}

// -1 because 0 index
Expand Down Expand Up @@ -157,7 +154,10 @@ func Update(cmd *cobra.Command, args []string) {
tracker.IncrementSection(err)
}

pw.Stop()
if progressEnabled {
pw.Stop()
lib.ResetOscProgress()
}
if verboseRun {
slog.Info("Verbose run requested")

Expand Down
10 changes: 8 additions & 2 deletions lib/percentmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ type TrackerMessage struct {
}

func ChangeTrackerMessageFancy(writer progress.Writer, tracker *IncrementTracker, progress bool, message TrackerMessage) {
percentage := math.Round((float64(tracker.Tracker.Value()) / float64(tracker.Tracker.Total)) * 100)
fmt.Printf("\033]9;4;1;%d\a", int(percentage))
if !progress {
slog.Info("Updating",
slog.String("title", message.Title),
Expand All @@ -73,6 +71,8 @@ func ChangeTrackerMessageFancy(writer progress.Writer, tracker *IncrementTracker
)
return
}
percentage := math.Round((float64(tracker.Tracker.Value()) / float64(tracker.Tracker.Total)) * 100)
fmt.Printf("\033]9;4;1;%d\a", int(percentage))
finalMessage := fmt.Sprintf("Updating %s (%s)", message.Description, message.Title)
writer.SetMessageLength(len(finalMessage))
tracker.Tracker.UpdateMessage(finalMessage)
Expand All @@ -96,3 +96,9 @@ func (it *IncrementTracker) IncrementSection(err error) {
func (it *IncrementTracker) CurrentStep() int {
return it.incrementer.doneIncrements
}

func ResetOscProgress() {
// OSC escape sequence to reset all previous OSC progress hints to 0%.
// Documentation is on https://conemu.github.io/en/AnsiEscapeCodes.html#ConEmu_specific_OSC
print("\033]9;4;0\a")
}

0 comments on commit 575c827

Please sign in to comment.