Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMD: Set buffer height independently of window height

Tags:

cmd

I've recently learned that I can control the size of the CMD window running my program with mode x,y. However I just as recently noticed that this sets the buffer size, and the window will adjust to match or max out at the screen size.

I would like to use mode 100,50 for the window size, but I also want to keep a arger buffer - for development at least I want mode 100,9999.

Is there any way to do this?

like image 254
Niet the Dark Absol Avatar asked Nov 09 '12 16:11

Niet the Dark Absol


1 Answers

I don't think there is a native batch command that gives independent control of buffer and window sizes. .NET can control both, but I don't think VBScript or JScript can access that functionality. But powershell can :-) See How Can I Expand the Width of the Windows PowerShell Console?

Thankfully, the new settings are preserved in the CMD window when PowerShell exits.

It is important that the window size is always less than or equal to the buffer size. To simplify things, I first use MODE to set both the window and buffer to the desired window size, and then I use powershell to set the buffer size.

Here is a simple conSize.bat hybrid batch/powershell script that takes the sizes as parameters:

@echo off
:conSize  winWidth  winHeight  bufWidth  bufHeight
mode con: cols=%1 lines=%2
powershell -command "&{$H=get-host;$W=$H.ui.rawui;$B=$W.buffersize;$B.width=%3;$B.height=%4;$W.buffersize=$B;}"

To get your desired size, you would simply use

call conSize 100 50 100 9999
like image 167
dbenham Avatar answered Nov 04 '22 10:11

dbenham