tty_windows.go
This file
Path
tty_windows.go
64 lines · 1.8 KiB · Go
Last changed by
Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
History of this fileTake it
1//go:build windows2// +build windows34package tea56import (7 "fmt"89 "github.com/charmbracelet/x/term"10 "golang.org/x/sys/windows"11)1213func (p *Program) initInput() (err error) {14 // Save stdin state and enable VT input15 // We also need to enable VT16 // input here.17 if f, ok := p.input.(term.File); ok && term.IsTerminal(f.Fd()) {18 p.ttyInput = f19 p.previousTtyInputState, err = term.MakeRaw(p.ttyInput.Fd())20 if err != nil {21 return fmt.Errorf("error making terminal raw: %w", err)22 }2324 // Enable VT input25 var mode uint3226 if err := windows.GetConsoleMode(windows.Handle(p.ttyInput.Fd()), &mode); err != nil {27 return fmt.Errorf("error getting console mode: %w", err)28 }2930 if err := windows.SetConsoleMode(windows.Handle(p.ttyInput.Fd()), mode|windows.ENABLE_VIRTUAL_TERMINAL_INPUT); err != nil {31 return fmt.Errorf("error setting console mode: %w", err)32 }33 }3435 // Save output screen buffer state and enable VT processing.36 if f, ok := p.output.(term.File); ok && term.IsTerminal(f.Fd()) {37 p.ttyOutput = f38 p.previousOutputState, err = term.GetState(f.Fd())39 if err != nil {40 return fmt.Errorf("error getting terminal state: %w", err)41 }4243 var mode uint3244 if err := windows.GetConsoleMode(windows.Handle(p.ttyOutput.Fd()), &mode); err != nil {45 return fmt.Errorf("error getting console mode: %w", err)46 }4748 if err := windows.SetConsoleMode(windows.Handle(p.ttyOutput.Fd()),49 mode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING|50 windows.DISABLE_NEWLINE_AUTO_RETURN); err != nil {51 return fmt.Errorf("error setting console mode: %w", err)52 }5354 //nolint:godox55 // TODO: check if we can optimize cursor movements on Windows.56 p.checkOptimizedMovements(p.previousOutputState)57 }5859 return //nolint:nakedret60}6162const suspendSupported = false6364func suspendProcess() {}