-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor terminal check into separate GUI class
- Loading branch information
Showing
3 changed files
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package convex.gui.utils; | ||
|
||
import java.io.Console; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
public class Terminal { | ||
|
||
public static boolean checkIfTerminal() { | ||
Console c=System.console(); | ||
// If null, we have no terminal (Java up to 21) | ||
if (c==null) return false; | ||
|
||
// We have a console, but in Java 22+ we need to check if it is actually a terminal | ||
try { | ||
Method m=c.getClass().getMethod("isTerminal"); | ||
return (Boolean)m.invoke(c); | ||
} catch (NoSuchMethodException e) { | ||
return true; | ||
} catch (SecurityException | IllegalAccessException | InvocationTargetException e) { | ||
// Shouldn't happen? | ||
return false; | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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