当我在窗口化,最大化和半屏蔽(例如 Win + 左)之间切换Powershell时,我仍然受限于“内部”维度控制台属性(在布局下),它完成的只是显示/隐藏滚动条。
有没有办法以某种方式让它自动重新调整缓冲区大小?如果它可以优雅地处理Vim或SSH中的奖励积分,但我不会抱有希望。
答案 0 :(得分:2)
尝试将其保存为Console-sizing.ps1(我在原始的powershell控制台中使用它,在VIM或SSH或其他控制台中不知道它是否有效!)
function Size($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 = Size ($w.width - 1) $w.height
$ui.WindowSize = $w
$ui.BufferSize = Size $w.width $b.height
break
}
39 {
$w = Size ($w.width + 1) $w.height
$ui.BufferSize = Size $w.width $b.height
$ui.WindowSize = $w
break
}
38 {
$ui.WindowSize = Size $w.width ($w.height - 1)
break
}
40 {
$w = Size $w.width ($w.height + 1)
if ($w.height -gt $b.height) {
$ui.BufferSize = Size $b.width $w.height
}
$ui.WindowSize = $w
break
}
27 {
return
}
}
}
修改: 请阅读评论以了解original function coder
答案 1 :(得分:0)
我正在使用PowerShell编写系统审计应用程序,因此我可以轻松转储到非格式的html文件,预先格式化以进行报告。
部分原因是使用了我编译过的工具集,并且THAT的一部分使用了我正在创建的自定义菜单(PS),使其看起来很漂亮和专业,我使用批处理文件来运行powershell和绕过UAC和运行受限制的ps1文件的设置。但为了使它看起来非常漂亮,我设置宽度,高度和它的位置,以及缓冲区大小,并设置所有菜单以使它完全适合窗口...
以下是我用于设置窗口的代码。
希望它有所帮助。
# Use as short code for everything else.
$uisettings = (Get-Host).UI.RawUI
# Set the title of the window itself.
$uisettings.WindowTitle = "Something you want it to say."
# Sets the style of the cursor, 100 = full block (easier to see).
$uisettings.CursorSize = "100"
# Set the window size for the screen.
$b = $uisettings.WindowSize
$b.Width = 80
$b.Height = 60
$uisettings.WindowSize = $b
# Set the position on the screen for the window.
$x = $uisettings.WindowPosition
$x.x = 0
$x.y = 0
$uisettings.WindowPosition = $x
# Set the buffer size;
# use the below code to set the buffer to OTHER than the WindowSize above.
# OR, if you want to ensure it fits just right, remove lines 1, 2 and 3 below,
# and set $uisettings.BufferSize to $b instead.
$s = $uisettings.BufferSize
$s.Width = 80
$s.Height = 60
$uisettings.BufferSize = $s
答案 2 :(得分:0)
以下powershell函数模仿cmd 模式120 40
function mode ($1,$2){
$s = (get-host).ui.rawui
$b = $s.buffersize
$b.height = $2
$b.width = $1
$s.buffersize = $b
$w = $s.windowsize
$w.height = $2
$w.width = $1
$s.windowsize = $w
}