resizeterm(3NCURSES)
β¨ resizeterm(3NCURSES) β Library calls, but make it a group chat π
okay bestie, buckle up, this is the 3NCURSES manual for resizing your terminal dimensions, and it's so much cooler than it sounds. it's an extension to the curses library, it's giving main character energy, and it's literally here to save you when someone drags their xterm window bigger and everything falls apart. let's go π¦
πΈ NAME πΈ
is_term_resized, resize_term, resizeterm β manage the terminal dimensions understood by curses β¨
π SYNOPSIS π
#include <curses.h>
bool is_term_resized(int lines, int columns);
int resize_term(int lines, int columns);
int resizeterm(int lines, int columns);
π DESCRIPTION π
so this whole thing is an extension to the curses library. it hands callers a hook into the ncurses data so you can resize windows β primarily for programs running in an X Window terminal (like xterm, iykyk) when the user changes the terminal's screen size π
like, here's the vibe:
- curses windows cannot extend outside the screen. if the terminal gets shrunk, curses windows must be shrunk to fit. no negotiation.
- if the terminal gets stretched, rows and/or columns can be added to existing windows. and the added cells should match the current attributes of the windows. periodt.
now, if the application hasn't set up a handler for SIGWINCH when it initializes ncurses (by calling initscr(3NCURSES) or newterm(3NCURSES)), then ncurses establishes a SIGWINCH handler that notifies the library when a window-resizing event has occurred π«Ά
and the library checks for this notification:
- when reading input data,
- when implicitly resuming program mode (e.g., between
endwin(3NCURSES)andwrefresh(3NCURSES)), and - when explicitly resuming program mode in
restartterm(3NCURSES).
when the library has found that the terminal's window-size has changed, it calls resizeterm to update its data structures. that's the whole pipeline, bestie π
oh, and an application which establishes its own SIGWINCH handler can call resizeterm too β but in that case, the library will not see SIGWINCH, and proper layout will rely upon the application. so like, that's on you at that point π
π resizeterm π
resizeterm resizes the standard and current windows (i.e., stdscr and curscr) to the specified dimensions, and adjusts other bookkeeping data used by the ncurses library that record the window dimensions β such as the LINES and COLS variables. she keeps the receipts, fr fr π
π§ resize_term π§
most of the actual work for resizeterm is done by the inner function resize_term. the outer function resizeterm adds bookkeeping for the SIGWINCH handler, as well as repainting the soft-key area (see slk_touch(3NCURSES)). iconic division of labour honestly π
resize_term attempts to resize all windows. this helps with simple applications. however:
- it is not possible to automatically resize pads. nope. can't do it.
- applications which have complicated layouts should check for
KEY_RESIZEreturned fromwgetch, and adjust their layout β e.g., usingwresizeandmvwin, or by recreating the windows.
when resizing windows, resize_term recursively adjusts subwindows, keeping them within the updated parent window's limits πͺ so cute. and if a top-level window happens to extend to the screen's limits, then on resizing the window, resize_term will keep the window extending to the corresponding limit, regardless of whether the screen has shrunk or grown. loyal to the edge, always.
π is_term_resized π
a support function, is_term_resized, is provided so that applications can check if the resize_term function would modify the window structures. it returns TRUE if the windows would be modified, and FALSE otherwise. a little vibe check before you commit, love that for us β¨
β RETURN VALUE β
except as noted, these functions return the integer ERR upon failure and OK on success π
they will fail if either of the dimensions are less than or equal to zero, or if an error occurs while (re)allocating memory for the windows. so like, 0 lines? no ma'am. -1 columns? absolutely not.
π NOTES π
while these functions are intended to be used to support a signal handler (i.e., for SIGWINCH), care should be taken to avoid invoking them in a context where malloc or realloc may have been interrupted, since it uses those functions. this is a real caveat, bestie, don't skip it.
if ncurses is configured to supply its own SIGWINCH handler:
- on receipt of a
SIGWINCH, the handler sets a flag, - which is tested in
wgetch(3NCURSES),doupdate(3NCURSES)andrestartterm(3NCURSES), - in turn, calling the
resizetermfunction, - which
ungetch's aKEY_RESIZEwhich will be read on the next call towgetch.
the KEY_RESIZE alerts an application that the screen size has changed, and that it should repaint special features such as pads that cannot be done automatically.
calling resizeterm or resize_term directly from a signal handler is unsafe. this indirect method is used to provide a safe way to resize the ncurses data structures. π
if the environment variables LINES or COLUMNS are set, this overrides the library's use of the window size obtained from the operating system. thus, even if a SIGWINCH is received, no screen size change may be recorded. plot twist, the env vars ate π«
π PORTABILITY π
it is possible to resize the screen with SVr4 curses, by:
- exiting curses with
endwin(3NCURSES)and - resuming using
refresh(3NCURSES).
doing that clears the screen and is visually distracting π like, the whole screen flashes, it's giving chaos, not the vibe.
ncurses introduced this extension in mid-1995. NetBSD curses adopted it in 2001 and PDCurses in 2003. trendsetter behaviour, no cap β
π AUTHORS π
Thomas Dickey (from an equivalent function written in 1988 for BSD curses). 1988!! the longevity of it all ππ
π SEE ALSO π
getch(3NCURSES), curses_variables(3NCURSES), wresize(3NCURSES)
and that's the whole page, bestie π this one's from ncurses 6.6, dated 2025-07-05, and it's still serving resizeterm(3NCURSES) realness to this very day. resize responsibly, mwah πβ¨
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2015,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms