Skip to content
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

Approximate istty() by checking System.console() != null #79

Closed
remkop opened this issue Apr 2, 2017 · 4 comments
Closed

Approximate istty() by checking System.console() != null #79

remkop opened this issue Apr 2, 2017 · 4 comments

Comments

@remkop
Copy link
Owner

remkop commented Apr 2, 2017

Use reflection to avoid introducing dependency on Java 6.

As indicated here, this is not entirely correct, but still better than no check at all...

@remkop remkop added this to the 0.4.0 user manual milestone Apr 2, 2017
@remkop remkop changed the title Approximate istty() by reflection on System.console() != null Approximate istty() by checking System.console() != null Apr 2, 2017
@remkop
Copy link
Owner Author

remkop commented Apr 3, 2017

            static final boolean ISATTY = calcTTY();
            static final boolean calcTTY() {
                try { return System.class.getDeclaredMethod("console").invoke(null) != null; }
                catch (Throwable reflectionFailed) {return true;}
            }

            private static boolean ansiPossible() { return ISATTY && (!isWindows || isXterm); }

@remkop remkop closed this as completed in c2def15 Apr 3, 2017
@bric3
Copy link

bric3 commented Jan 4, 2024

Hi,

It seems that in JDK 22, checking is System.console() returning null might not be enough. With JDK 22 there is now a Console::isTerminal as the new default console is based on JLine.

It still doesn't allow to be specific about which side is interactive or not though.

@remkop
Copy link
Owner Author

remkop commented Jan 4, 2024

Hi,

It seems that in JDK 22, checking is System.console() returning null might not be enough. With JDK 22 there is now a Console::isTerminal as the new default console is based on JLine.

It still doesn't allow to be specific about which side is interactive or not though.

@bric3 Please refer to #1104, #2083 and #2084 ; is there still an issue?

@bric3
Copy link

bric3 commented Jan 4, 2024

Oh thank you @remkop I wasn't looking for these keyword so I didn't find them.

No issue I was just exploring available options to detect if stdin or stdout were interactive (e.g. when piping). And I stumbled on this PR so I made the comment, but I'm way late as other work has been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants