Skip to content

Commit e9d728c

Browse files
committed
Add "hidden" command/config for switching on mouse wheel support
See (#206)
1 parent c16a146 commit e9d728c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
width uint
3737
showAllFiles bool
3838
localOnly bool
39+
mouse bool
3940

4041
rootCmd = &cobra.Command{
4142
Use: "glow SOURCE",
@@ -139,6 +140,7 @@ func validateOptions(cmd *cobra.Command) {
139140
style = viper.GetString("style")
140141
width = viper.GetUint("width")
141142
localOnly = viper.GetBool("local")
143+
mouse = viper.GetBool("mouse")
142144

143145
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd()))
144146
// We want to use a special no-TTY style, when stdout is not a terminal
@@ -287,11 +289,14 @@ func runTUI(stashedOnly bool) error {
287289
// Run Bubble Tea program
288290
p := ui.NewProgram(cfg)
289291
p.EnterAltScreen()
292+
defer p.ExitAltScreen()
293+
if mouse {
294+
p.EnableMouseCellMotion()
295+
defer p.DisableMouseCellMotion()
296+
}
290297
if err := p.Start(); err != nil {
291298
return err
292299
}
293-
p.ExitAltScreen()
294-
p.DisableMouseCellMotion()
295300

296301
// Exit message
297302
fmt.Printf("\n Thanks for using Glow!\n\n")
@@ -324,11 +329,14 @@ func init() {
324329
rootCmd.Flags().UintVarP(&width, "width", "w", 0, "word-wrap at width")
325330
rootCmd.Flags().BoolVarP(&showAllFiles, "all", "a", false, "show system files and directories (TUI-mode only)")
326331
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")
327334

328335
// Config bindings
329336
_ = viper.BindPFlag("style", rootCmd.Flags().Lookup("style"))
330337
_ = viper.BindPFlag("width", rootCmd.Flags().Lookup("width"))
331338
_ = viper.BindPFlag("local", rootCmd.Flags().Lookup("local"))
339+
_ = viper.BindPFlag("mouse", rootCmd.Flags().Lookup("mouse"))
332340
viper.SetDefault("style", "auto")
333341
viper.SetDefault("width", 0)
334342
viper.SetDefault("local", "false")

0 commit comments

Comments
 (0)