|
36 | 36 | width uint |
37 | 37 | showAllFiles bool |
38 | 38 | localOnly bool |
| 39 | + mouse bool |
39 | 40 |
|
40 | 41 | rootCmd = &cobra.Command{ |
41 | 42 | Use: "glow SOURCE", |
@@ -139,6 +140,7 @@ func validateOptions(cmd *cobra.Command) { |
139 | 140 | style = viper.GetString("style") |
140 | 141 | width = viper.GetUint("width") |
141 | 142 | localOnly = viper.GetBool("local") |
| 143 | + mouse = viper.GetBool("mouse") |
142 | 144 |
|
143 | 145 | isTerminal := terminal.IsTerminal(int(os.Stdout.Fd())) |
144 | 146 | // We want to use a special no-TTY style, when stdout is not a terminal |
@@ -287,11 +289,14 @@ func runTUI(stashedOnly bool) error { |
287 | 289 | // Run Bubble Tea program |
288 | 290 | p := ui.NewProgram(cfg) |
289 | 291 | p.EnterAltScreen() |
| 292 | + defer p.ExitAltScreen() |
| 293 | + if mouse { |
| 294 | + p.EnableMouseCellMotion() |
| 295 | + defer p.DisableMouseCellMotion() |
| 296 | + } |
290 | 297 | if err := p.Start(); err != nil { |
291 | 298 | return err |
292 | 299 | } |
293 | | - p.ExitAltScreen() |
294 | | - p.DisableMouseCellMotion() |
295 | 300 |
|
296 | 301 | // Exit message |
297 | 302 | fmt.Printf("\n Thanks for using Glow!\n\n") |
@@ -324,11 +329,14 @@ func init() { |
324 | 329 | rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width") |
325 | 330 | rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)") |
326 | 331 | rootCmd.Flags().BoolVarP(&localOnly, "local", "l", false, "show local files only; no network (TUI-mode only)") |
| 332 | + rootCmd.Flags().BoolVarP(&mouse, "mouse", "m", false, "enable mouse wheel (TUI-mode only)") |
| 333 | + rootCmd.Flags().MarkHidden("mouse") |
327 | 334 |
|
328 | 335 | // Config bindings |
329 | 336 | _ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style")) |
330 | 337 | _ = viper.BindPFlag("width", rootCmd.Flags().Lookup("width")) |
331 | 338 | _ = viper.BindPFlag("local", rootCmd.Flags().Lookup("local")) |
| 339 | + _ = viper.BindPFlag("mouse", rootCmd.Flags().Lookup("mouse")) |
332 | 340 | viper.SetDefault("style", "auto") |
333 | 341 | viper.SetDefault("width", 0) |
334 | 342 | viper.SetDefault("local", "false") |
|
0 commit comments