diff --git a/cmd/root.go b/cmd/root.go index 5a7fa43..fedc19e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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) { @@ -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") diff --git a/cmd/update.go b/cmd/update.go index 2f22aa7..eea07b2 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -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") + if !disableOsc { + percent.ResetOscProgress() + } // -1 because 0 index tracker := &percent.Incrementer{MaxIncrements: totalSteps - 1} @@ -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") diff --git a/go.mod b/go.mod index 0128381..91e2dc9 100644 --- a/go.mod +++ b/go.mod @@ -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 ) @@ -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 ) diff --git a/go.sum b/go.sum index a12d58d..2ed9f4a 100644 --- a/go.sum +++ b/go.sum @@ -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=