Get/Set the available width of a Console Application


Currently working on a console app and I’ve been limiting my text output to 80 characters across (seems to be the historical default) so that the text doesn’t wrap onto the next line, however I note that (with Windows 10 at least) the default width seems to have increased and I could use some extra space for my output.

Is it possible to get and/or set the available width in code from within the console application? Xojo doesn’t appear to expose any methods or properties for doing this currently.

I should say I’ve had a look at the Windows API and it looks like this could be possible with some calls but ideally I’m after a cross platform solution in case I move the app to Mac/Linux in the future


On Mac and Linux there is a console app that will report this, but its name escapes me now. I’ve called that through Shell.

on macOS and Linux try:

stty size

the second number should be the number of columns.

To set the value, use:

stty cols N

Where N is the number of columns.

Thanks Greg
I don’t have a Mac to test it on currently but from other examples on the web it looks like that is an established way of handling it so I’m sure it will be fine.

For anyone else who finds this thread, I’ve found a similar shell function on Windows called MODE that seems to be working so far. I’ve produced the code below which will handle setting the dimensions depending on the build platform.

[code]#If TargetWindows Then
Dim sh as New Shell
sh.Execute(“MODE CON: cols=”+Str(cols)+" lines="+Str(rows))

#Else // Mac OSX and Linux use stty command
Dim sh as New Shell
sh.Execute("stty cols “+Str(cols)+” rows "+Str(rows))
'sh.Execute("stty rows "+Str(rows))