Skip to content

Commit 11306ac

Browse files
committed
DFFIConsole new methods.
1 parent 6b561fa commit 11306ac

File tree

2 files changed

+60
-5
lines changed

2 files changed

+60
-5
lines changed

sdk/system/DFFIConsole.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ class DFFIConsole
1313
* Enable colors in console (for Windows)
1414
* @return bool
1515
*/
16-
public function enableColors(): bool
16+
public static function enableColors(): bool
17+
{
18+
}
19+
20+
/**
21+
* @return bool
22+
*/
23+
public static function isXTerm(): bool
24+
{
25+
}
26+
27+
/**
28+
* @return bool
29+
*/
30+
public static function hasColorSupport(): bool
1731
{
1832
}
1933
}

src-jvm/main/java/org/develnext/jphp/ext/system/classes/DFFIConsole.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)