@@ -24,8 +24,49 @@ public DFFIConsole(Environment env, ClassEntity clazz) {
2424 super (env , clazz );
2525 }
2626
27+ private static Boolean isTerm = null ;
28+ private static Boolean isColorSupport = null ;
29+
2730 @ Signature
28- public boolean enableColors () {
31+ public static boolean isXTerm () {
32+ if (isTerm != null ) {
33+ return isTerm ;
34+ }
35+
36+ return isTerm = (System .getenv ("TERM" ).equalsIgnoreCase ("xterm" ));
37+ }
38+
39+ @ Signature
40+ public static boolean hasColorSupport () {
41+ if (isColorSupport != null ) {
42+ return isColorSupport ;
43+ }
44+
45+ if (isXTerm ()) {
46+ return isColorSupport = true ;
47+ }
48+
49+ String osName = System .getProperty ("os.name" );
50+ if (osName .equalsIgnoreCase ("windows" )) {
51+ try {
52+ float osVersion = Float .parseFloat (System .getProperty ("os.version" ));
53+ if (osVersion >= 10.0f ) {
54+ return isColorSupport = true ;
55+ }
56+ } catch (NumberFormatException e ) {
57+ return isColorSupport = false ;
58+ }
59+ }
60+
61+ return isColorSupport = false ;
62+ }
63+
64+ @ Signature
65+ public static boolean enableColors () {
66+ if (isXTerm ()) {
67+ return true ;
68+ }
69+
2970 String osName = System .getProperty ("os.name" );
3071
3172 if (osName .equalsIgnoreCase ("windows" )) {
@@ -36,16 +77,16 @@ public boolean enableColors() {
3677 return true ;
3778 }
3879
39- return false ;
80+ return isColorSupport = false ;
4081 } catch (NumberFormatException e ) {
41- return false ;
82+ return isColorSupport = false ;
4283 }
4384 }
4485
4586 return true ;
4687 }
4788
48- protected void enableColorsForWindows () {
89+ protected static void enableColorsForWindows () {
4990 // Set output mode to handle virtual terminal sequences
5091 Function GetStdHandleFunc = Function .getFunction ("kernel32" , "GetStdHandle" );
5192 WinDef .DWORD STD_OUTPUT_HANDLE = new WinDef .DWORD (-11 );
0 commit comments