Skip to content
Myr

fix: restoreTerminalState resets mouse handling state

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- fixes mouse handling being enabled during sub commands - fixes shutdown order: restore mouse state before alt screen

authored by Christian Muehlhaeuser · committed by Christian Muehlhaeuser · parent 4aa9ce4 · Browse files · 3 files+18 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−17 removed

  • other:+18 added−17 removed

3 files+18 added−17 removed

modified:screen_test.go+8 added-8 removed
12 unmodified lines
13 }{14 {15 name: "clear_screen",16 cmds: []Cmd{ClearScreen},17 expected: "\x1b[?25l\x1b[2J\x1b[1;1H\x1b[1;1Hsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",17 expected: "\x1b[?25l\x1b[2J\x1b[1;1H\x1b[1;1Hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",18 },19 {20 name: "altscreen",21 cmds: []Cmd{EnterAltScreen, ExitAltScreen},22 expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1H\x1b[?1049lsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",22 expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1H\x1b[?1049lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",23 },24 {25 name: "altscreen_autoexit",26 cmds: []Cmd{EnterAltScreen},27 expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1Hsuccess\r\n\x1b[2;0H\x1b[2K\x1b[?1049l\x1b[?1002l\x1b[?1003l\x1b[?25h",27 expected: "\x1b[?25l\x1b[?1049h\x1b[2J\x1b[1;1H\x1b[1;1Hsuccess\r\n\x1b[2;0H\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l\x1b[?1049l",28 },29 {30 name: "mouse_cellmotion",31 cmds: []Cmd{EnableMouseCellMotion},32 expected: "\x1b[?25l\x1b[?1002hsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",32 expected: "\x1b[?25l\x1b[?1002hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",33 },34 {35 name: "mouse_allmotion",36 cmds: []Cmd{EnableMouseAllMotion},37 expected: "\x1b[?25l\x1b[?1003hsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",37 expected: "\x1b[?25l\x1b[?1003hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",38 },39 {40 name: "mouse_disable",41 cmds: []Cmd{EnableMouseAllMotion, DisableMouse},42 expected: "\x1b[?25l\x1b[?1003h\x1b[?1002l\x1b[?1003lsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",42 expected: "\x1b[?25l\x1b[?1003h\x1b[?1002l\x1b[?1003lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",43 },44 {45 name: "cursor_hide",46 cmds: []Cmd{HideCursor},47 expected: "\x1b[?25l\x1b[?25lsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",47 expected: "\x1b[?25l\x1b[?25lsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",48 },49 {50 name: "cursor_hideshow",51 cmds: []Cmd{HideCursor, ShowCursor},52 expected: "\x1b[?25l\x1b[?25l\x1b[?25hsuccess\r\n\x1b[0D\x1b[2K\x1b[?1002l\x1b[?1003l\x1b[?25h",52 expected: "\x1b[?25l\x1b[?25l\x1b[?25hsuccess\r\n\x1b[0D\x1b[2K\x1b[?25h\x1b[?1002l\x1b[?1003l",53 },54 }5556 for _, test := range tests {
20 unmodified lines
modified:tea.go+1 added-9 removed
16 unmodified lines
17 "os/signal"18 "runtime/debug"19 "sync"20 "syscall"21 "time"2122 "github.com/containerd/console"23 isatty "github.com/mattn/go-isatty"24 "github.com/muesli/cancelreader"
504 unmodified lines
529 } else {530 p.renderer.stop()531 }532 }534 p.ExitAltScreen()535 p.DisableMouseCellMotion()536 p.DisableMouseAllMotion()537 _ = p.restoreTerminalState()533534 _ = p.restoreTerminalState()535 if p.restoreOutput != nil {536 _ = p.restoreOutput()537 }538}
5 unmodified lines
544 p.cancelReader.Cancel()545 p.waitForReadLoop()546547 p.altScreenWasActive = p.renderer.altScreen()552 if p.renderer.altScreen() {553 p.ExitAltScreen()554 time.Sleep(time.Millisecond * 10) // give the terminal a moment to catch up555 }548 return p.restoreTerminalState()549}550551// RestoreTerminal reinitializes the Program's input reader, restores the
64 unmodified lines
modified:tty.go+9 added
28 unmodified lines
29// Bubble Tea program.30func (p *Program) restoreTerminalState() error {31 if p.renderer != nil {32 p.renderer.showCursor()33 p.renderer.disableMouseCellMotion()34 p.renderer.disableMouseAllMotion()3536 if p.renderer.altScreen() {37 p.renderer.exitAltScreen()3839 // give the terminal a moment to catch up40 time.Sleep(time.Millisecond * 10)41 }42 }4344 if p.console != nil {45 err := p.console.Reset()
55 unmodified lines