@@ -16,6 +16,7 @@ import (
16
16
"io"
17
17
"os"
18
18
"os/signal"
19
+ "runtime"
19
20
"runtime/debug"
20
21
"sync"
21
22
"sync/atomic"
@@ -183,6 +184,9 @@ type Program struct {
183
184
// fps is the frames per second we should set on the renderer, if
184
185
// applicable,
185
186
fps int
187
+
188
+ // mouseMode is true if the program should enable mouse mode on Windows.
189
+ mouseMode bool
186
190
}
187
191
188
192
// Quit is a special command that tells the Bubble Tea program to exit.
@@ -413,9 +417,25 @@ func (p *Program) eventLoop(model Model, cmds chan Cmd) (Model, error) {
413
417
// mouse mode (1006) is a no-op if the terminal doesn't support it.
414
418
p .renderer .enableMouseSGRMode ()
415
419
420
+ // XXX: This is used to enable mouse mode on Windows. We need
421
+ // to reinitialize the cancel reader to get the mouse events to
422
+ // work.
423
+ if runtime .GOOS == "windows" && ! p .mouseMode {
424
+ p .mouseMode = true
425
+ p .initCancelReader (true ) //nolint:errcheck
426
+ }
427
+
416
428
case disableMouseMsg :
417
429
p .disableMouse ()
418
430
431
+ // XXX: On Windows, mouse mode is enabled on the input reader
432
+ // level. We need to instruct the input reader to stop reading
433
+ // mouse events.
434
+ if runtime .GOOS == "windows" && p .mouseMode {
435
+ p .mouseMode = false
436
+ p .initCancelReader (true ) //nolint:errcheck
437
+ }
438
+
419
439
case showCursorMsg :
420
440
p .renderer .showCursor ()
421
441
@@ -579,6 +599,11 @@ func (p *Program) Run() (Model, error) {
579
599
p .renderer .enableMouseAllMotion ()
580
600
p .renderer .enableMouseSGRMode ()
581
601
}
602
+
603
+ // XXX: Should we enable mouse mode on Windows?
604
+ // This needs to happen before initializing the cancel and input reader.
605
+ p .mouseMode = p .startupOptions & withMouseCellMotion != 0 || p .startupOptions & withMouseAllMotion != 0
606
+
582
607
if p .startupOptions & withReportFocus != 0 {
583
608
p .renderer .enableReportFocus ()
584
609
}
@@ -607,7 +632,7 @@ func (p *Program) Run() (Model, error) {
607
632
608
633
// Subscribe to user input.
609
634
if p .input != nil {
610
- if err := p .initCancelReader (); err != nil {
635
+ if err := p .initCancelReader (false ); err != nil {
611
636
return model , err
612
637
}
613
638
}
@@ -763,7 +788,7 @@ func (p *Program) RestoreTerminal() error {
763
788
if err := p .initTerminal (); err != nil {
764
789
return err
765
790
}
766
- if err := p .initCancelReader (); err != nil {
791
+ if err := p .initCancelReader (false ); err != nil {
767
792
return err
768
793
}
769
794
if p .altScreenWasActive {
0 commit comments