Skip to content

Commit

Permalink
fix: disable OSC when run noninteractively
Browse files Browse the repository at this point in the history
  • Loading branch information
gerblesh committed Dec 25, 2024
1 parent dd5c77c commit 11e22f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/spf13/cobra"
appLogging "github.com/ublue-os/uupd/pkg/logging"
"golang.org/x/term"
)

func assertRoot(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -111,7 +112,8 @@ func init() {
rootCmd.Flags().BoolP("dry-run", "n", false, "Do a dry run")
rootCmd.Flags().BoolP("verbose", "v", false, "Display command outputs after run")
rootCmd.Flags().Bool("ci", false, "Makes some modifications to behavior if is running in CI")

isTerminal := term.IsTerminal(int(os.Stdout.Fd()))
rootCmd.Flags().Bool("disable-osc-progress", !isTerminal, "Disable the GUI progress indicator")
rootCmd.PersistentFlags().BoolVar(&fLogJson, "json", false, "Print logs as json (used for testing)")
rootCmd.PersistentFlags().StringVar(&fLogFile, "log-file", "-", "File where user-facing logs will be written to")
rootCmd.PersistentFlags().StringVar(&fLogLevel, "log-level", "info", "Log level for user-facing logs")
Expand Down
11 changes: 7 additions & 4 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ func Update(cmd *cobra.Command, args []string) {
totalSteps += mainSystemDriver.Steps()
}

// FIXME: check if is interactive
percent.ResetOscProgress()
disableOsc, err := cmd.Flags().GetBool("disable-osc-progress")

Check failure on line 101 in cmd/update.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)

Check failure on line 101 in cmd/update.go

View workflow job for this annotation

GitHub Actions / lint

ineffectual assignment to err (ineffassign)
if !disableOsc {
percent.ResetOscProgress()
}

// -1 because 0 index
tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1}
Expand Down Expand Up @@ -161,8 +163,9 @@ func Update(cmd *cobra.Command, args []string) {
tracker.IncrementSection(err)
}

// FIXME: detect interactive session
percent.ResetOscProgress()
if !disableOsc {
percent.ResetOscProgress()
}
if verboseRun {
slog.Info("Verbose run requested")

Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0
github.com/shirou/gopsutil/v4 v4.24.10
github.com/spf13/cobra v1.8.1
golang.org/x/term v0.27.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -19,5 +20,5 @@ require (
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down

0 comments on commit 11e22f0

Please sign in to comment.