RestoreCookedMode is the exported entry-point that callers outside the coder package use to reset the controlling terminal to canonical (cooked, echo-on) mode. Used by the agent loop at the start of every ReAct run to recover from a prior go-prompt teardown that may have left the TTY in raw mode (no
()
| 38 | // (occasionally-broken-on-resume) behavior, which is what we are |
| 39 | // trying to improve. |
| 40 | func RestoreCookedMode() bool { |
| 41 | if runtime.GOOS == "windows" || sttyPath == "" { |
| 42 | return false |
| 43 | } |
| 44 | tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0) |
| 45 | if err != nil { |
| 46 | return false |
| 47 | } |
| 48 | defer func() { _ = tty.Close() }() |
| 49 | |
| 50 | cmd := exec.Command(sttyPath, "sane") |
| 51 | cmd.Stdin = tty |
| 52 | cmd.Stdout = tty |
| 53 | cmd.Stderr = tty |
| 54 | return cmd.Run() == nil |
| 55 | } |