Skip to content

Commit

Permalink
Merge pull request #116 from alexarchambault/fix-fallbacks
Browse files Browse the repository at this point in the history
Fix Windows scripts after manual tests
  • Loading branch information
alexarchambault authored Jan 10, 2025
2 parents cb36805 + 794e59f commit efb30db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,26 @@ 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" +
"$WinAPI = Add-Type -MemberDefinition $signature `\n" +
" -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";

/**
Expand All @@ -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" +
Expand Down Expand Up @@ -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";

}

0 comments on commit efb30db

Please sign in to comment.