NCurses resizing terminal

I wanted to make the terminal screen bigger in my NCurses program.
Let's say if the defaults are 25 LINES and 80 COLS, I want to set them to 40 LINES and 120 COLS.

I've tried resizing all windows, but that did not work, because the actual terminal (console) was not resized.
Then I found functions resizeterm and newterm, but they did not work. As far as my understanding goes resizeterm only updates NCurses information with the current configuration, while the window itself is not actually modified.

NCurses man page wrote:
The function resizeterm resizes the standard and current windows to the specified dimensions


If I haven't made myself clear ( I sometimes make a mess of things... ), another example would be that I want my program to be fullscreen when I start it. Is this possible?
It should be, I found a fullscreen NCurses program once, but the code was too confusing for me to understand.

Having read about things like SIGWINCH, I assume you must define a method for resizing the terminal screen yourself, could anyone help out as I don't know where to start?
Last edited on
I don't think you can resize the terminal window with ncurses. It's the size that the user wants it to be. It's even possible that there is no window/GUI at all.
NCurses does not proffer the ability to resize the user's terminal. It is possible, though... The simplest way would be by resizing it using X.

Unfortunately, what you are trying to do is a Bad IdeaTM.


If you want your program to start fullscreen, you need to create a script that allocates a new xterm (or whatever terminal emulator you are using) and give it some appropriate -geometry.


Also, you must keep in mind one of the rules no one warns you about when writing programs that run in the terminal:

Your TUI program must be capable of operating no matter how the user sizes his terminal.

...even if that is just to quit with a complaint that the terminal is too small. (Or better yet, just suspend all functionality until the user resizes his term to something big enough.)

Make sure to pay attention to resize events in your NCurses program.


Sorry it doesn't work the way you wanted it... At least you can get pretty close.

Hope this helps.
Thank you.
I think I see how it is now.

I might as well try and re-write my program using a graphics library like SFML, I don't want to get into creating new xterm windows and so on as I want my source code to be portable between Linux and Windows.

So far NCurses has provided me with fairly good cross-platform solutions, but for the user, being able to resize the window size is almost necessary and the code solution for this would not be cross-platform at all as I see it.

I shall give up on the console, this wasn't a brilliant idea from the start. I just wanted to learn more of standard C++ and NCurses. Now it seems like it's time to move on.

Cheers!
Last edited on
Er, the user can resize his window however he wants...

Your NCurses/PDCurses solution should be listening for terminal resize events so that it can adjust appropriately.

Good luck!
I believe that you can resize the window as long as it runs in xterm or vt220 or just the standard terminal in linux (the second one does not support colour!), but when it comes to windows, there the console window is not resizeable.
Any ideas?
One of us is still confused.

The person using your program can resize his console window however he likes, even while your program is running. (And yes, he can do it in Windows too-- though it isn't as easy as on *nix.)

In contrast, your program cannot resize the console window however it likes. (Technically, it can, but it shouldn't.)

The point is that your user retains control over his GUI interface. If you try to take that control away, your users will hate you and stop using your program.

Hope this helps.
Hmmm...
How do you resize the console window in Windows?
In Linux you just drag one of the corners.

Now I'd like to discuss this idea:
Duoas wrote:
The point is that your user retains control over his GUI interface. If you try to take that control away, your users will hate you and stop using your program.

I believe that the control is taken away (not all of it) from the user from the moment the program opens!

What I was thinking is that since when the program opens a new window with default dimensions is opened, why would the user care if it used different dimensions? (of course I'm not considering making the window too large or too small)

I think the default dimensions are 24x80. If the program opened the window with the dimensions of 40x120, why would that make a difference?
why would the user care if it used different dimensions? (of course I'm not considering making the window too large or too small)

I think the default dimensions are 24x80. If the program opened the window with the dimensions of 40x120, why would that make a difference?


Lots of users care about the size of their windows because they have multiple windows open at once, allowing them to multitask. At this moment I have 4 windows visible on my desktop. (which is probably slightly below average for me)

If one of those windows was forcibly making itself larger than I wanted it and as a result was cutting off one of my other windows, it would be very irritating.
Last edited on
How do you resize the console window in Windows?


Click on the console icon on the top-left side of the title bar.
Click "Properties"
Click "Layout"
Mess around
Click "Ok"

I believe that the control is taken away (not all of it) from the user from the moment the program opens!


Believe what you want. You are still wrong.

Sorry.
Ok, thank you.
I suppose you may be right about this...
Although in programs with a GUI interface you can hard-code the exact dimensions of the window.
Also I don't think people would hate it if I made the window larger, in fact, I wanted to do it, because this was requested by my friends - for them, the window was too small.

But the original problem counts as solved, because you can adjust the layout of the program if the user decides to resize the window.
Ah.

Create a Link to your program.
In explorer, right-click the link and choose Properties.
Adjust the terminal size.

Now your friends can run the program from the link and the window will be larger when the program starts.

Hope this helps.
Topic archived. No new replies allowed.