More accurate TTY checking for IO - #9594
Draft
headius wants to merge 3 commits into
Draft
Conversation
The System.console() method is intended to indicate whether the JVM process is running with stdio connected to a TTY-like, but in JDK 22 through 24, it also returns non-null for non-TTY stdio due to the use of JLine as a pseudo-terminal. This behavior changed back to JDK 21 behavior in JDK 25, but we must continue double- checking Console.isTerminal() for situations where the JLine logic is live. Part of improvements for jruby#9590. See https://bugs.openjdk.org/browse/JDK-8361911 for an OpenJDK issue that details the changing behavior of System.console().
We have other reasons to know if JRuby was started as the JVM's main entry point, so rename this to reflect the actual state.
Member
Author
|
See also #8934 for previous attempts to deal with JDK 22 always returning non-null |
If JRuby is started through Main, then the stdio channels we set up are either native or come from the JVM's System.in/out/err. In the latter case, we can use the JVM's System.console() and Console.isTerminal() methods to indicate if the JRuby stdio is a TTY. This fixes previous logic that always assumed any non-native stdio was conneected to a TTY, leading to cases where embedded use might incorrectly assume that color console output or hard process exits were appropriate. Fixes jruby#9590
headius
force-pushed
the
better_console_checking
branch
from
August 17, 2026 20:34
3e3598f to
4a8dab5
Compare
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.
This introduces some cleanup and improvements in how we determine whether an IO is a TTY (
IO#tty?method):isatty, use that result.Main, use the JDK'sSystem.console()andConsole.isTerminal().This should address situations where JRuby has been embedded as part of a larger application with user-facing stdio streams connected to non-terminal channels, such as in #9590 (deployed in Tomcat using jruby-rack).
Draft until appropriate tests can be added.