1

当我在窗口、最大化和半屏(例如Win+ Left)之间切换 Powershell 时,我仍然受到控制台属性(布局下)中指定的“内部”尺寸的限制,它完成的只是显示/隐藏滚动条。

有没有办法让它自动重新调整缓冲区大小?如果它可以优雅地处理在 Vim 或 SSH 中,则可以加分,但我不会抱有希望的。

4

3 回答 3

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
        }
    }
}

编辑:请阅读评论以了解原始功能编码器

于 2012-05-08T05:37:16.930 回答
0

I am writing a system audit app using PowerShell, so I can easily dump to a non XML based html file, preformatted for reporting.

Part of it is using a tool set I have compiled, and part of THAT uses a custom menu (PS) that I am creating, to make it look nice and professional, I use a batch file to run the powershell and bypass the UAC and settings for running restricted ps1 files. But to make it look really pretty, I set the width, height and it's position, as well as the buffer size, and set all the menus to have it all fit perfectly in the window...

Below is the code I use for the settings of the window.

Hope it helps.

# 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
于 2013-01-13T11:50:23.273 回答
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
 }
于 2015-03-11T14:05:44.513 回答