Skip to content

Commit 7f87192

Browse files
committed
Implement _nt._supports_virtual_terminal
1 parent e6c5370 commit 7f87192

7 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,15 @@ static long getPid(@Bind PythonContext context) {
611611
}
612612
}
613613

614+
@Builtin(name = "_supports_virtual_terminal", minNumOfPositionalArgs = 0, os = PythonOS.PLATFORM_WIN32)
615+
@GenerateNodeFactory
616+
abstract static class SupportsVirtualTerminalNode extends PythonBuiltinNode {
617+
@Specialization
618+
static boolean supportsVirtualTerminal(@Bind PythonContext context) {
619+
return context.getPosixSupport().supportsVirtualTerminal();
620+
}
621+
}
622+
614623
@Builtin(name = "_is_inputhook_installed", minNumOfPositionalArgs = 0)
615624
@GenerateNodeFactory
616625
abstract static class IsInputHookInstalledNode extends PythonBuiltinNode {

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/EmulatedPosixSupport.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,12 @@ public int msvcrtKbhit() throws UnsupportedPosixFeatureException {
611611
throw createUnsupportedFeature("msvcrt.kbhit");
612612
}
613613

614+
@Override
615+
@TruffleBoundary
616+
public boolean supportsVirtualTerminal() {
617+
return false;
618+
}
619+
614620
@Override
615621
@TruffleBoundary
616622
public int[] pipe() throws PosixException {

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/LoggingPosixSupport.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,13 @@ public final int msvcrtKbhit() throws PosixException {
311311
}
312312
}
313313

314+
@Override
315+
@TruffleBoundary
316+
public final boolean supportsVirtualTerminal() {
317+
logEnter("supportsVirtualTerminal", "");
318+
return logExit("supportsVirtualTerminal", "%s", delegate.supportsVirtualTerminal());
319+
}
320+
314321
@Override
315322
@TruffleBoundary
316323
public final int[] pipe() throws PosixException {

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/NativePosixSupport.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,9 @@ abstract static class PosixNativeFunctionInvoker {
236236
@DowncallSignature(returnType = SINT32, argumentTypes = {})
237237
abstract int call_msvcrt_kbhit();
238238

239+
@DowncallSignature(returnType = SINT32)
240+
abstract int supports_virtual_terminal();
241+
239242
@DowncallSignature(returnType = SINT32, argumentTypes = {POINTER})
240243
abstract int call_pipe2(long pipefd);
241244

@@ -902,6 +905,12 @@ public int msvcrtKbhit() throws PosixException {
902905
return result;
903906
}
904907

908+
@Override
909+
@TruffleBoundary
910+
public boolean supportsVirtualTerminal() {
911+
return posixNativeFunctionInvoker.supports_virtual_terminal() != 0;
912+
}
913+
905914
@Override
906915
@TruffleBoundary
907916
public int[] pipe() throws PosixException {

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixSupport.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,9 @@ public abstract int forkExec(Object[] executables, Object[] args, Object cwd, Ob
986986
@TruffleBoundary
987987
public abstract int msvcrtKbhit() throws PosixException;
988988

989+
@TruffleBoundary
990+
public abstract boolean supportsVirtualTerminal();
991+
989992
@TruffleBoundary
990993
public abstract int[] pipe() throws PosixException;
991994

‎graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PreInitPosixSupport.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ public final int msvcrtKbhit() throws PosixException {
279279
return nativePosixSupport.msvcrtKbhit();
280280
}
281281

282+
@Override
283+
@TruffleBoundary
284+
public final boolean supportsVirtualTerminal() {
285+
checkNotInPreInitialization();
286+
return nativePosixSupport.supportsVirtualTerminal();
287+
}
288+
282289
@Override
283290
@TruffleBoundary
284291
public final int[] pipe() throws PosixException {

‎graalpython/python-libposix/src/posix.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,12 @@ GP_EXPORT int32_t call_msvcrt_kbhit(void) {
13711371
return _kbhit();
13721372
}
13731373

1374+
GP_EXPORT int32_t supports_virtual_terminal(void) {
1375+
DWORD mode = 0;
1376+
HANDLE handle = GetStdHandle(STD_ERROR_HANDLE);
1377+
return GetConsoleMode(handle, &mode) && (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) != 0;
1378+
}
1379+
13741380
GP_EXPORT int32_t call_pipe2(int32_t *pipefd) {
13751381
int result = _pipe(pipefd, 8192, _O_BINARY | _O_NOINHERIT);
13761382
if (result < 0) {
@@ -2632,6 +2638,10 @@ int32_t call_msvcrt_locking(int32_t fd, int32_t mode, int64_t nbytes) {
26322638
return -1;
26332639
}
26342640

2641+
int32_t supports_virtual_terminal(void) {
2642+
return 0;
2643+
}
2644+
26352645
int32_t call_msvcrt_kbhit(void) {
26362646
errno = ENOSYS;
26372647
capture_errno();

0 commit comments

Comments
 (0)