From cebc2f3d62d3368f4ae7fba7049d335a4bdeb82a Mon Sep 17 00:00:00 2001 From: Julian Noble Date: Fri, 29 Aug 2025 02:15:16 +1000 Subject: [PATCH] getpunk windows SetConsoleMode --- getpunk.cmd | 43 +++++++++++++++++++++++++++++++++++++- src/scriptapps/getpunk.ps1 | 42 +++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/getpunk.cmd b/getpunk.cmd index 460b18ff..9a5b560a 100644 --- a/getpunk.cmd +++ b/getpunk.cmd @@ -1029,7 +1029,48 @@ git branch --set-upstream-to=origin/master master Set-Location $launchdir #restore original CWD - +Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +public class NativeMethods +{ + [DllImport("kernel32.dll", SetLastError=true)] + public static extern IntPtr GetStdHandle(int nStdHandle); + + [DllImport("kernel32.dll", SetLastError=true)] + public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int lpMode); + + [DllImport("kernel32.dll", SetLastError=true)] + public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode); + + // Constants for standard handles + public const int STD_INPUT_HANDLE = -10; + public const int STD_OUTPUT_HANDLE = -11; + public const int STD_ERROR_HANDLE = -12; + + // Console Input Modes + public const int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200; + + // Console Output Modes + public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; +} +"@ + +# Get the output handle +$hConsoleOutput = [NativeMethods]::GetStdHandle([NativeMethods]::STD_OUTPUT_HANDLE) + +# Get the current output mode +$currentMode = 0 +[NativeMethods]::GetConsoleMode($hConsoleOutput, [ref]$currentMode) | Out-Null + +# Enable Virtual Terminal Processing +$newMode = $currentMode -bor [NativeMethods]::ENABLE_VIRTUAL_TERMINAL_PROCESSING + +# Set the new console mode +[NativeMethods]::SetConsoleMode($hConsoleOutput, $newMode) | Out-Null + +write-host "`e[92m getpunk done `e[m" # # diff --git a/src/scriptapps/getpunk.ps1 b/src/scriptapps/getpunk.ps1 index 4fc4a0ae..3a19cbf0 100644 --- a/src/scriptapps/getpunk.ps1 +++ b/src/scriptapps/getpunk.ps1 @@ -120,3 +120,45 @@ git branch --set-upstream-to=origin/master master Set-Location $launchdir #restore original CWD +Add-Type -TypeDefinition @" +using System; +using System.Runtime.InteropServices; + +public class NativeMethods +{ + [DllImport("kernel32.dll", SetLastError=true)] + public static extern IntPtr GetStdHandle(int nStdHandle); + + [DllImport("kernel32.dll", SetLastError=true)] + public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out int lpMode); + + [DllImport("kernel32.dll", SetLastError=true)] + public static extern bool SetConsoleMode(IntPtr hConsoleHandle, int dwMode); + + // Constants for standard handles + public const int STD_INPUT_HANDLE = -10; + public const int STD_OUTPUT_HANDLE = -11; + public const int STD_ERROR_HANDLE = -12; + + // Console Input Modes + public const int ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200; + + // Console Output Modes + public const int ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004; +} +"@ + +# Get the output handle +$hConsoleOutput = [NativeMethods]::GetStdHandle([NativeMethods]::STD_OUTPUT_HANDLE) + +# Get the current output mode +$currentMode = 0 +[NativeMethods]::GetConsoleMode($hConsoleOutput, [ref]$currentMode) | Out-Null + +# Enable Virtual Terminal Processing +$newMode = $currentMode -bor [NativeMethods]::ENABLE_VIRTUAL_TERMINAL_PROCESSING + +# Set the new console mode +[NativeMethods]::SetConsoleMode($hConsoleOutput, $newMode) | Out-Null + +write-host "`e[92m getpunk done `e[m" \ No newline at end of file