Add --no-spinner option

This commit is contained in:
Daniele Rondina
2020-06-27 16:45:42 +02:00
parent 764a09ce0c
commit e2260b6956
2 changed files with 24 additions and 13 deletions

View File

@@ -88,8 +88,12 @@ func LoadConfig(c *config.LuetConfig) error {
return err return err
} }
noSpinner := c.Viper.GetBool("no_spinner")
InitAurora() InitAurora()
NewSpinner() if !noSpinner {
NewSpinner()
}
Debug("Using config file:", c.Viper.ConfigFileUsed()) Debug("Using config file:", c.Viper.ConfigFileUsed())
@@ -145,6 +149,7 @@ func init() {
pflags.BoolP("debug", "d", false, "verbose output") pflags.BoolP("debug", "d", false, "verbose output")
pflags.Bool("fatal", false, "Enables Warnings to exit") pflags.Bool("fatal", false, "Enables Warnings to exit")
pflags.Bool("enable-logfile", false, "Enable log to file") pflags.Bool("enable-logfile", false, "Enable log to file")
pflags.Bool("no-spinner", false, "Disable spinner.")
pflags.Bool("color", config.LuetCfg.GetLogging().Color, "Enable/Disable color.") pflags.Bool("color", config.LuetCfg.GetLogging().Color, "Enable/Disable color.")
pflags.Bool("emoji", config.LuetCfg.GetLogging().EnableEmoji, "Enable/Disable emoji.") pflags.Bool("emoji", config.LuetCfg.GetLogging().EnableEmoji, "Enable/Disable emoji.")
pflags.StringP("logfile", "l", config.LuetCfg.GetLogging().Path, pflags.StringP("logfile", "l", config.LuetCfg.GetLogging().Path,
@@ -168,6 +173,8 @@ func init() {
config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("debug")) config.LuetCfg.Viper.BindPFlag("general.debug", pflags.Lookup("debug"))
config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal")) config.LuetCfg.Viper.BindPFlag("general.fatal_warnings", pflags.Lookup("fatal"))
config.LuetCfg.Viper.BindPFlag("general.same_owner", pflags.Lookup("same-owner")) config.LuetCfg.Viper.BindPFlag("general.same_owner", pflags.Lookup("same-owner"))
// Currently I maintain this only from cli.
config.LuetCfg.Viper.BindPFlag("no_spinner", pflags.Lookup("no-spinner"))
// Extensions must be binary with the "luet-" prefix to be able to be shown in the help. // Extensions must be binary with the "luet-" prefix to be able to be shown in the help.
// we also accept extensions in the relative path where luet is being started, "extensions/" // we also accept extensions in the relative path where luet is being started, "extensions/"

View File

@@ -78,23 +78,25 @@ func Spinner(i int) {
i = 43 i = 43
} }
if !s.Active() { if s != nil && !s.Active() {
// s.UpdateCharSet(spinner.CharSets[i]) // s.UpdateCharSet(spinner.CharSets[i])
s.Start() // Start the spinner s.Start() // Start the spinner
} }
} }
func SpinnerText(suffix, prefix string) { func SpinnerText(suffix, prefix string) {
s.Lock() if s != nil {
defer s.Unlock() s.Lock()
if LuetCfg.GetGeneral().Debug { defer s.Unlock()
fmt.Println(fmt.Sprintf("%s %s", if LuetCfg.GetGeneral().Debug {
Bold(Cyan(prefix)).String(), fmt.Println(fmt.Sprintf("%s %s",
Bold(Magenta(suffix)).BgBlack().String(), Bold(Cyan(prefix)).String(),
)) Bold(Magenta(suffix)).BgBlack().String(),
} else { ))
s.Suffix = Bold(Magenta(suffix)).BgBlack().String() } else {
s.Prefix = Bold(Cyan(prefix)).String() s.Suffix = Bold(Magenta(suffix)).BgBlack().String()
s.Prefix = Bold(Cyan(prefix)).String()
}
} }
} }
@@ -108,7 +110,9 @@ func SpinnerStop() {
if 2 > confLevel { if 2 > confLevel {
return return
} }
s.Stop() if s != nil {
s.Stop()
}
} }
func level2Number(level string) int { func level2Number(level string) int {