IsInteractive returns true when stdout is a TTY and the session is suitable for Bubble Tea TUI rendering. Commands use this to decide between interactive TUI and plain-text output paths.
()
| 19 | // is suitable for Bubble Tea TUI rendering. Commands use this to |
| 20 | // decide between interactive TUI and plain-text output paths. |
| 21 | func IsInteractive() bool { |
| 22 | if forceNonInteractive || !termx.IsTerminal(os.Stdout.Fd()) { |
| 23 | return false |
| 24 | } |
| 25 | if runtime.GOOS == "windows" { |
| 26 | // On Windows, Bubble Tea reads from CONIN$. If stdin isn't a console |
| 27 | // (redirected, piped, or spawned by a GUI launcher without a real |
| 28 | // conhost), the read fails with "No process is on the other end of |
| 29 | // the pipe." Checking stdin is a terminal avoids that. |
| 30 | return termx.IsTerminal(os.Stdin.Fd()) |
| 31 | } |
| 32 | // On Unix, Bubble Tea opens /dev/tty for input. Verify it's accessible |
| 33 | // to avoid "device not configured" errors in sandboxed environments |
| 34 | // where stdout is a PTY but no controlling terminal exists. |
| 35 | f, err := os.Open("/dev/tty") |
| 36 | if err != nil { |
| 37 | return false |
| 38 | } |
| 39 | f.Close() |
| 40 | return true |
| 41 | } |
no test coverage detected