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
The walk stopped after 200 commits: lines older than 3dfbcd9 point at it.
feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 1–20why, one step back1//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 {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 21why, one step back21 return fmt.Errorf("error making terminal raw: %w", err)feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 22–39why, one step back22 }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 {Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
line 40why, one step back40 return fmt.Errorf("error getting terminal state: %w", err)feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 41–47why, one step back41 }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 }47Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 48–50why, one step back48 if err := windows.SetConsoleMode(windows.Handle(p.ttyOutput.Fd()),49 mode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING|50 windows.DISABLE_NEWLINE_AUTO_RETURN); err != nil {feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 51–53why, one step back51 return fmt.Errorf("error setting console mode: %w", err)52 }53Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 54–56why, one step back54 //nolint:godox55 // TODO: check if we can optimize cursor movements on Windows.56 p.checkOptimizedMovements(p.previousOutputState)feat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
line 57why, one step back57 }Merge pull request #1118 from charmbracelet/v2-expAyman Bagabasbefore adoptiond1c8c97
lines 58–59why, one step back5859 return //nolint:nakedretfeat(render): skipping lines from previous frameKonstantin Antonovbefore adoption3dfbcd9
lines 60–64why, one step back60}6162const suspendSupported = false6364func suspendProcess() {}