Last active
January 13, 2018 19:50
-
-
Save lidopaglia/9965434 to your computer and use it in GitHub Desktop.
Resize console window/buffer using arrow keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
This Gist was created by ISEGist | |
04/03/2014 20:11:13 | |
#> | |
# Resize the standard console window | |
function Resize-ConsoleWindow | |
{ | |
## | |
## Author : Roman Kuzmin | |
## Synopsis : Resize console window/buffer using arrow keys | |
## Link : http://stackoverflow.com/questions/153983/are-there-any-better-command-prompts-for-windows/188086#188086 | |
function Set-ConsoleSize($w, $h) | |
{ | |
New-Object System.Management.Automation.Host.Size($w, $h) | |
} | |
Write-Host '[Arrows] resize [Esc] exit ...' | |
$ErrorActionPreference = 'SilentlyContinue' | |
for($ui = $Host.UI.RawUI;;) | |
{ | |
$b = $ui.BufferSize | |
$w = $ui.WindowSize | |
switch($ui.ReadKey(6).VirtualKeyCode) | |
{ | |
37 { | |
$w = Set-ConsoleSize ($w.width - 1) $w.height | |
$ui.WindowSize = $w | |
$ui.BufferSize = Set-ConsoleSize $w.width $b.height | |
break | |
} | |
39 { | |
$w = Set-ConsoleSize ($w.width + 1) $w.height | |
$ui.BufferSize = Set-ConsoleSize $w.width $b.height | |
$ui.WindowSize = $w | |
break | |
} | |
38 { | |
$ui.WindowSize = Set-ConsoleSize $w.width ($w.height - 1) | |
break | |
} | |
40 { | |
$w = Set-ConsoleSize $w.width ($w.height + 1) | |
if ($w.height -gt $b.height) { | |
$ui.BufferSize = Set-ConsoleSize $b.width $w.height | |
} | |
$ui.WindowSize = $w | |
break | |
} | |
27 { | |
return | |
} | |
} | |
} | |
} | |
New-Alias -Name rcw -Value Resize-ConsoleWindow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment