Add POSIX isatty() checks for stdin/stdout redirection detection - #267
Merged
Conversation
TerminalBuilder.isSystemTerminal(): add TtyDetect.isStdinTty() check. When stdin is not a TTY (redirected from file or piped), go directly to ExternalTerminal without trying (and failing at) system terminal providers. This follows standard POSIX convention where programs check isatty(STDIN_FILENO) to decide whether to run interactively. Previously, redirected stdin caused all SPI providers to be tried and fail (ExecPty forks 'tty' which returns 'not a tty', FfmPty calls isatty(0) which returns false), wasting ~8ms on subprocess calls before falling back to ExternalTerminal. Now the fallback is immediate. TerminalConnection: add TtyDetect.isStdoutTty() check for ANSI output suppression. When stdout is not a TTY (redirected to file or piped to another program), set ansi=false to prevent ANSI escape codes from being written to the redirected output. This follows standard POSIX convention where programs check isatty(STDOUT_FILENO) to decide whether to emit escape sequences (like ls --color=auto, grep --color=auto). TtyDetect.isTty(): reorder detection to try Console.isTerminal() (Java 22+) before FFM isatty(). Console.isTerminal() does not require loading LibC or creating FFM downcall handles, avoiding the JVM restricted method warning when --enable-native-access is not set. FFM isatty() is only tried as a secondary path when Console.isTerminal() is not available (pre-Java 22). Remove the now-unused fallbackIsTty() method. Fixes aeshell#266
stalep
force-pushed
the
posix-tty-detection
branch
from
September 1, 2026 09:52
1d3aece to
2027f30
Compare
Contributor
|
I have some tests I can add to this. I'll push a commit shortly |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TerminalBuilder.isSystemTerminal(): add TtyDetect.isStdinTty() check. When stdin is not a TTY (redirected from file or piped), go directly to ExternalTerminal without trying (and failing at) system terminal providers. This follows standard POSIX convention where programs check isatty(STDIN_FILENO) to decide whether to run interactively.
Previously, redirected stdin caused all SPI providers to be tried and fail (ExecPty forks 'tty' which returns 'not a tty', FfmPty calls isatty(0) which returns false), wasting ~8ms on subprocess calls before falling back to ExternalTerminal. Now the fallback is immediate.
TerminalConnection: add TtyDetect.isStdoutTty() check for ANSI output suppression. When stdout is not a TTY (redirected to file or piped to another program), set ansi=false to prevent ANSI escape codes from being written to the redirected output. This follows standard POSIX convention where programs check isatty(STDOUT_FILENO) to decide whether to emit escape sequences (like ls --color=auto, grep --color=auto).
This is independent of the stdin check — stdout can be redirected while stdin is still interactive (e.g., 'cmd | tee log.txt' where the user types interactively but output is also captured).
fixes #266