diff --git a/native/src/io/github/alexarchambault/nativeterm/NativeTerminalFallbacks.java b/native/src/io/github/alexarchambault/nativeterm/TerminalScriptFallbacks.java similarity index 97% rename from native/src/io/github/alexarchambault/nativeterm/NativeTerminalFallbacks.java rename to native/src/io/github/alexarchambault/nativeterm/TerminalScriptFallbacks.java index 1e67625..bec675e 100644 --- a/native/src/io/github/alexarchambault/nativeterm/NativeTerminalFallbacks.java +++ b/native/src/io/github/alexarchambault/nativeterm/TerminalScriptFallbacks.java @@ -11,9 +11,9 @@ /** * Methods to query the terminal size and enable ANSI output in it like in {@link NativeTerminal} */ -public final class NativeTerminalFallbacks { +public final class TerminalScriptFallbacks { - private NativeTerminalFallbacks() {} + private TerminalScriptFallbacks() {} /** * Gets the terminal size diff --git a/native/src/io/github/alexarchambault/nativeterm/internal/ScriptRunner.java b/native/src/io/github/alexarchambault/nativeterm/internal/ScriptRunner.java index aaef2f0..42a04cc 100644 --- a/native/src/io/github/alexarchambault/nativeterm/internal/ScriptRunner.java +++ b/native/src/io/github/alexarchambault/nativeterm/internal/ScriptRunner.java @@ -34,7 +34,10 @@ public static String runPowerShellScript(String script) throws InterruptedExcept "-NoProfile", "-NonInteractive", "-EncodedCommand", encodedScript); - builder.inheritIO(); + builder + .redirectOutput(ProcessBuilder.Redirect.PIPE) + .redirectInput(ProcessBuilder.Redirect.INHERIT) + .redirectError(ProcessBuilder.Redirect.INHERIT); Process proc = builder.start(); diff --git a/native/src/io/github/alexarchambault/nativeterm/internal/WindowsTermScripts.java b/native/src/io/github/alexarchambault/nativeterm/internal/WindowsTermScripts.java index 295237b..d828464 100644 --- a/native/src/io/github/alexarchambault/nativeterm/internal/WindowsTermScripts.java +++ b/native/src/io/github/alexarchambault/nativeterm/internal/WindowsTermScripts.java @@ -32,7 +32,7 @@ private WindowsTermScripts() {} "public static extern uint SetConsoleMode(\n" + " IntPtr hConsoleHandle,\n" + " uint dwMode);\n" + - "public const int STD_OUTPUT_HANDLE = -11;\n" + + "public const int STD_ERROR_HANDLE = -12;\n" + "public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004;\n" + "'@\n" + "\n" + @@ -40,15 +40,18 @@ private WindowsTermScripts() {} " -Name WinAPI -Namespace ConinModeScript `\n" + " -PassThru\n" + "\n" + - "$handle = $WinAPI::GetStdHandle($WinAPI::STD_OUTPUT_HANDLE)\n" + + "$handle = $WinAPI::GetStdHandle($WinAPI::STD_ERROR_HANDLE)\n" + "$mode = 0\n" + "$ret = $WinAPI::GetConsoleMode($handle, [ref]$mode)\n" + "if ($ret -eq 0) {\n" + - " throw \"GetConsoleMode failed (is stdin a console?)\"\n" + - "}\n" + - "$ret = $WinAPI::SetConsoleMode($handle, $mode -bor $WinAPI::ENABLE_VIRTUAL_TERMINAL_PROCESSING)\n" + - "if ($ret -eq 0) {\n" + - " throw \"SetConsoleMode failed (is stdin a console?)\"\n" + + " Write-Host \"Error: GetConsoleMode failed (is stderr a console?)\"\n" + + "} else {\n" + + " $ret = $WinAPI::SetConsoleMode($handle, $mode -bor $WinAPI::ENABLE_VIRTUAL_TERMINAL_PROCESSING)\n" + + " if ($ret -eq 0) {\n" + + " Write-Host \"false\"\n" + + " } else {\n" + + " Write-Host \"true\"\n" + + " }\n" + "}\n"; /** @@ -68,7 +71,7 @@ private WindowsTermScripts() {} " [DllImport(\"kernel32.dll\", SetLastError = true)]\n" + " public static extern IntPtr GetStdHandle(int nStdHandle);\n" + "\n" + - " public const int STD_OUTPUT_HANDLE = -11;\n" + + " public const int STD_ERROR_HANDLE = -12;\n" + "\n" + " [StructLayout(LayoutKind.Sequential)]\n" + " public struct COORD\n" + @@ -100,14 +103,14 @@ private WindowsTermScripts() {} "\n" + "Add-Type -TypeDefinition $signature -Language CSharp\n" + "\n" + - "$outputHandle = [Kernel32]::GetStdHandle([Kernel32]::STD_OUTPUT_HANDLE)\n" + + "$outputHandle = [Kernel32]::GetStdHandle([Kernel32]::STD_ERROR_HANDLE)\n" + "\n" + "$info = New-Object Kernel32+CONSOLE_SCREEN_BUFFER_INFO\n" + "\n" + "if ([Kernel32]::GetConsoleScreenBufferInfo($outputHandle, [ref]$info)) {\n" + " Write-Host \"Size: $($info.srWindow.Right - $info.srWindow.Left + 1) $($info.srWindow.Bottom - $info.srWindow.Top + 1)\"\n" + "} else {\n" + - " Write-Host \"Error: \" + [System.Runtime.InteropServices.Marshal]::GetLastWin32Error()\n" + + " Write-Host \"Error: Win32 error $([System.Runtime.InteropServices.Marshal]::GetLastWin32Error())\"\n" + "}\n"; }