-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AnsiConsole should always obey the terminal (fixes #1160) #1161
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
@@ -247,7 +247,10 @@ private static AnsiPrintStream ansiStream(boolean stdout) throws IOException { | |||
width = terminal::getWidth; | |||
type = terminal instanceof DumbTerminal ? AnsiType.Unsupported : AnsiType.Native; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
new FileInputStream(FileDescriptor.in), | ||
new FileOutputStream(systemStream == SystemStream.Error ? FileDescriptor.err : FileDescriptor.out), | ||
System.in, | ||
systemStream == SystemStream.Error ? System.err : System.out, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, undone this
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