diff options
author | Christian Rocha <christian@rocha.is> | 2020-11-20 15:13:43 -0500 |
---|---|---|
committer | Christian Rocha <meowgorithm@users.noreply.github.com> | 2020-11-20 15:28:36 -0500 |
commit | e9d728cd96ad3ba3a0986231afa70ff2c6162b64 (patch) | |
tree | dffddd8764e9b255f60e81732f2c2a19fd41820d | |
parent | c16a146c00340654e44ec2dcc061aa5ed6f4a1da (diff) |
Add "hidden" command/config for switching on mouse wheel supportv1.2.0
See (#206)
-rw-r--r-- | main.go | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -36,6 +36,7 @@ var ( width uint showAllFiles bool localOnly bool + mouse bool rootCmd = &cobra.Command{ Use: "glow SOURCE", @@ -139,6 +140,7 @@ func validateOptions(cmd *cobra.Command) { style = viper.GetString("style") width = viper.GetUint("width") localOnly = viper.GetBool("local") + mouse = viper.GetBool("mouse") isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) // We want to use a special no-TTY style, when stdout is not a terminal @@ -287,11 +289,14 @@ func runTUI(stashedOnly bool) error { // Run Bubble Tea program p := ui.NewProgram(cfg) p.EnterAltScreen() + defer p.ExitAltScreen() + if mouse { + p.EnableMouseCellMotion() + defer p.DisableMouseCellMotion() + } if err := p.Start(); err != nil { return err } - p.ExitAltScreen() - p.DisableMouseCellMotion() // Exit message fmt.Printf("\n Thanks for using Glow!\n\n") @@ -324,11 +329,14 @@ func init() { rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width") rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)") rootCmd.Flags().BoolVarP(&localOnly, "local", "l", false, "show local files only; no network (TUI-mode only)") + rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)") + rootCmd.Flags().MarkHidden("mouse") // Config bindings _ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style")) _ = viper.BindPFlag("width", rootCmd.Flags().Lookup("width")) _ = viper.BindPFlag("local", rootCmd.Flags().Lookup("local")) + _ = viper.BindPFlag("mouse", rootCmd.Flags().Lookup("mouse")) viper.SetDefault("style", "auto") viper.SetDefault("width", 0) viper.SetDefault("local", "false") |