How can I change the width of a Windows console window?
Asked Answered
T

11

27

Is it possible to programmatically, or otherwise, increase the width of the Windows console window? Or do I need to create a wrapper program that looks and acts like the console somehow? Are there any programs around that do this already? I use Cygwin extensively in my development, and it seems a little ridiculous to me that all console windows in Windows are width limited.

If it matters at all, I'm running Windows XP.

Tittivate answered 10/10, 2008 at 8:42 Comment(0)
J
22

You can increase it manually by right-clicking the tray icon and entering the options dialog.

There are also third-party terminal emulators for Windows, such as Console:

Screenshot of Console

Jingo answered 10/10, 2008 at 8:46 Comment(3)
The last release was 2006, do you know if the 2.0b line is stable or not? Or should I go with 1.5 to test it out?Tittivate
Answering my own question, 2.0b is what is pictured. So I assume it is. Seems to be working at any rate :-)Tittivate
Console is really great, been using it wiht the windoes GNU tools and git.. almost makes my windoes box feel like a read os... almost ;-)Gauthier
O
57

Simply run "mode cols,lines" to change the size of the current console window:

mode 120,60

will resize the console window to 120 columns and 60 lines

Ordeal answered 8/3, 2009 at 15:32 Comment(2)
As I've discovered, thanks to this answer, running mode with no parameters will return all kinds of useful info, including columns and lines. Useful if you simply want to see what it is, rather than change it. You can parse it with cscript, too, if you need to size your command output to fit the user's settings.Lina
Unfortunately, this will also set the screen buffer size to these value (i.e. disable vertical scrolling).Poundage
J
22

You can increase it manually by right-clicking the tray icon and entering the options dialog.

There are also third-party terminal emulators for Windows, such as Console:

Screenshot of Console

Jingo answered 10/10, 2008 at 8:46 Comment(3)
The last release was 2006, do you know if the 2.0b line is stable or not? Or should I go with 1.5 to test it out?Tittivate
Answering my own question, 2.0b is what is pictured. So I assume it is. Seems to be working at any rate :-)Tittivate
Console is really great, been using it wiht the windoes GNU tools and git.. almost makes my windoes box feel like a read os... almost ;-)Gauthier
M
11
system("mode 45, 20");

This is a bad solution because it disables vertical scrolling.

This is better:

system("mode CON: COLS=120");
Mechanics answered 28/2, 2012 at 19:28 Comment(1)
is it part of the stdlib.h?Piccalilli
S
6

If you right click on the title bar of a command window and choose properties, you can change widths in the Layout tab

Shenitashenk answered 10/10, 2008 at 8:45 Comment(3)
Wow, much nicer. This is where I hang up my hat in shame. This allows you to set a default for individual links/programs, but is there a way to set a universal default?Tittivate
It allows you to set settings for the title window. If you open up cmd.exe then you can set it for that. It should work for most windows then on out.Cowpuncher
Yeah, I found that after I set it on cmd.exe it seemed to work on all the other things that I have used since. It didn't seem to have affected a console app that I build in .NET, so I changed the properties in the same way and it seems to have persisted even between buildsShenitashenk
L
5

If you're programming C# here's a method that worked for me (from the bottom of this page)

static void setConsoleSize()
   {
       System.Console.SetWindowPosition(0,0);   // sets window position to upper left
       System.Console.SetBufferSize(200,300);   // make sure buffer is bigger than window
       System.Console.SetWindowSize(122,54);   //set window size to almost full screen 
       //width - maxSet(127,57) (width, height)

       //System.Console.ResetColor(); //resets fore and background colors to default

   }  // End  setConsoleSize()

Quoted from the post: "My maximum console size that I could use was 127 columns and 57 rows because that's all that my screen resolution will allow. Reset your screen resolution and this will change.

This is just one of those things that you are going to have to play around with in order for you to get it to display as you like. "

Laniferous answered 18/6, 2015 at 15:7 Comment(1)
Except for SetWindowPosition() you can also use this in PowerShell.Poundage
S
2

the

mode 

and

system("mode... 

solutions did not work for me and I could not set the layout without getting a access error.

Fix was to close Cygwin, right click properties on the icon in the start menu and edit layout -> window -> height and then say yes to allowing administrator privileges to save settings. (not run as administrator).

now when running Cygwin always gives me a large window.

Windows 7 64bit.

Sherr answered 13/1, 2012 at 10:20 Comment(0)
M
1

To get all future console windows in a specific size you can create a shortcut to cmd.exe and then set size on the layout-tab of the shortcut properties.

Myrtismyrtle answered 10/10, 2008 at 9:7 Comment(0)
C
1

In console properties at the Layout tab you can configure the following:

Screen Buffer Size Width

Window Size Width

The Window Size Width is how many characters per line will be visible. The Screen Buffer Size is the size of the line. If you set for example the Window Size Width at 100 and the Screen Buffer Size Width at 200, you will need to use the scrollbar to view the whole contents of lines with sizes between 100 and 200. Lines longer than 200 characters will appear in more than one line. This is useful if you have long lines and you want to copy them in a text file.

The same things apply for Windows PowerShell

Crossbreed answered 10/10, 2008 at 9:9 Comment(0)
P
1

Hey have you guys here ever thought of the possibility of launching and running Cygwin from within the windows command prompt/console? This is what I always do. Then you can do anything you want to the look of the console to make it sexy.

trying to get su from within cygwin can be difficult at times, especially when you are attempting to do some heavy crunching with the tools provided. People have tried all sorts of things from sudo SU for windows to what ever...when it can be as simple as passing on the administrator credentials from you the "user" (if you are the admin?) even without weird UAC pop ups. You can do this via a simple batch script. Have a below this of a screen grab of what my Cygwin looks like and this is running from a portable version of Cygwin too! No registry entries and any of that rubbish!
The batch file passes the credentials to bash and then bash changes directory (notice the double quotes are needed to pass this variable to the Cygwin colsole in order for it to work)

@echo off
setlocal enabledelayedexpansion
REM Changing working folder back to current directory
%~d0
CD %~dp0
REM Folder changed
bash --login -i -c "cd {insert_directory_name_here} && exec ./execution-file-here"
cls
exit 1

Note: the brackets like so { } in the above example are NOT included in the batch script. also note that windows CMD window is passing off the string to cygwin to interpret as multiple conditions; cygwin doesn't read the quotes them selves but whats between them. the && is saying change directories and when you do execute the script ./execution-file-here when you get there.

It's a double whammy you can launch a Cygwin or linux like application from within a MS-Windows window and not even type a letter of code or open a console or anything.

I keep this batch file inside of the /Cygwin/bin directory and create a Windows shortcut link on the desktop. Within the shortcut I can stylise the cmd shell window. Even go as far as transparency ;-)

enter image description here

enter image description here

Portraiture answered 20/6, 2012 at 13:55 Comment(0)
P
0

Click on the icon on the top left of the console frame (the one that looks like "C:\"), then select Properties . This lets you customize all kinds of stuff. The "layout" tab has the width of the window.

Puckery answered 10/10, 2008 at 8:46 Comment(0)
T
0

Use SetConsoleScreenBufferSize(HANDLE hConsoleOutput, coord dwSize) from windows.h

Twink answered 29/8, 2023 at 12:11 Comment(1)
Thank you for your interest in contributing to the Stack Overflow community. This question already has quite a few answers—including one that has been extensively validated by the community. Are you certain your approach hasn’t been given previously? If so, it would be useful to explain how your approach is different, under what circumstances your approach might be preferred, and/or why you think the previous answers aren’t sufficient. Can you kindly edit your answer to offer an explanation?Irmairme

© 2022 - 2024 — McMap. All rights reserved.