()
| 11 | ) |
| 12 | |
| 13 | func (p *Program) initInput() (err error) { |
| 14 | // Save stdin state and enable VT input |
| 15 | // We also need to enable VT |
| 16 | // input here. |
| 17 | if f, ok := p.input.(term.File); ok && term.IsTerminal(f.Fd()) { |
| 18 | p.ttyInput = f |
| 19 | p.previousTtyInputState, err = term.MakeRaw(p.ttyInput.Fd()) |
| 20 | if err != nil { |
| 21 | return fmt.Errorf("error making terminal raw: %w", err) |
| 22 | } |
| 23 | |
| 24 | // Enable VT input |
| 25 | var mode uint32 |
| 26 | if err := windows.GetConsoleMode(windows.Handle(p.ttyInput.Fd()), &mode); err != nil { |
| 27 | return fmt.Errorf("error getting console mode: %w", err) |
| 28 | } |
| 29 | |
| 30 | 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 | } |
| 34 | |
| 35 | // 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 = f |
| 38 | p.previousOutputState, err = term.GetState(f.Fd()) |
| 39 | if err != nil { |
| 40 | return fmt.Errorf("error getting terminal state: %w", err) |
| 41 | } |
| 42 | |
| 43 | var mode uint32 |
| 44 | if err := windows.GetConsoleMode(windows.Handle(p.ttyOutput.Fd()), &mode); err != nil { |
| 45 | return fmt.Errorf("error getting console mode: %w", err) |
| 46 | } |
| 47 | |
| 48 | 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 | } |
| 53 | |
| 54 | //nolint:godox |
| 55 | // TODO: check if we can optimize cursor movements on Windows. |
| 56 | p.checkOptimizedMovements(p.previousOutputState) |
| 57 | } |
| 58 | |
| 59 | return //nolint:nakedret |
| 60 | } |
| 61 | |
| 62 | const suspendSupported = false |
| 63 |
nothing calls this directly
no test coverage detected