Use containerd/console for raw mode to get arrow key support on Windows

This commit is contained in:
Christian Rocha
2020-10-13 14:41:35 -04:00
parent a85d22cf54
commit eb919b622f
3 changed files with 11 additions and 7 deletions

12
tty.go
View File

@@ -1,17 +1,15 @@
package tea
import (
"os"
"github.com/containerd/console"
"github.com/muesli/termenv"
"golang.org/x/crypto/ssh/terminal"
)
var origTTYState *terminal.State
var tty console.Console
func initTerminal() error {
var err error
origTTYState, err = terminal.MakeRaw(int(os.Stdin.Fd())) // enter raw mode
tty = console.Current()
err := tty.SetRaw()
if err != nil {
return err
}
@@ -23,5 +21,5 @@ func initTerminal() error {
func restoreTerminal() error {
termenv.ShowCursor()
return terminal.Restore(int(os.Stdin.Fd()), origTTYState) // exit raw mode
return tty.Reset()
}