AnsiConsole should always obey the terminal (fixes #1160) - #1161
Merged
Conversation
Currently, if terminal is set, but is not "tty" (ie. is dumb), AnsiConsole will grab the process stdout/stderr instead to obey the set terminal output. Fixes jline#1160
gnodet
reviewed
Jan 23, 2025
| @@ -247,7 +247,10 @@ private static AnsiPrintStream ansiStream(boolean stdout) throws IOException { | |||
| width = terminal::getWidth; | |||
| type = terminal instanceof DumbTerminal ? AnsiType.Unsupported : AnsiType.Native; | |||
Member
There was a problem hiding this comment.
That line is also problematic I think, as DumbTerminalProvider always return false for isSystemStream.
So I'm tempted to rather somehow change the isatty computation, or maybe just remove it.
What about replacing:
final TerminalProvider provider = ((TerminalExt) terminal).getProvider();
final boolean isatty =
provider != null && provider.isSystemStream(stdout ? SystemStream.Output : SystemStream.Error);
if (isatty) {
out = terminal.output();
width = terminal::getWidth;
type = terminal instanceof DumbTerminal ? AnsiType.Unsupported : AnsiType.Native;
} else {
out = new FastBufferedOutputStream(new FileOutputStream(stdout ? FileDescriptor.out : FileDescriptor.err));
width = new AnsiOutputStream.ZeroWidthSupplier();
type = ((TerminalExt) terminal).getSystemStream() != null ? AnsiType.Redirected : AnsiType.Unsupported;
}with
out = terminal.output();
width = terminal::getWidth;
type = terminal instanceof DumbTerminal
? AnsiType.Unsupported
: ((TerminalExt) terminal).getSystemStream() != null ? AnsiType.Redirected : AnsiType.Native;as terminal cannot be null.
gnodet
reviewed
Jan 23, 2025
| new FileInputStream(FileDescriptor.in), | ||
| new FileOutputStream(systemStream == SystemStream.Error ? FileDescriptor.err : FileDescriptor.out), | ||
| System.in, | ||
| systemStream == SystemStream.Error ? System.err : System.out, |
Member
There was a problem hiding this comment.
I'm not sure about those lines.
The provider is required to create a system terminal, which is supposed to be backed by the real terminal emulator where the JVM is running. If someone changes System.out or System.err, there's no guarantee about the behavior. If the goal is to be able to run tests, you need to initialize a terminal and set it on the AnsiConsole before calling systemInstall.
gnodet
approved these changes
Jan 24, 2025
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.
Currently, if terminal is set, but is not "tty" (ie. is dumb), AnsiConsole will grab the process stdout/stderr instead to obey the set terminal output.
Fixes #1160