pad(3NCURSES)
π pad(3NCURSES) β the library calls that let you build enormous windows and peek at just a slice π
okay bestie, settle in, because this one's about pads β the glow-up of windows in ncurses (the library calls, that's the 3NCURSES part) β¨
πΈ SYNOPSIS πΈ
#include <curses.h>
WINDOW *newpad(int nlines, int ncols);
WINDOW *subpad(WINDOW *parent, int nlines, int ncols,
int begin_y, int begin_x);
int prefresh(WINDOW *pad, int pminrow, int pmincol,
int sminrow, int smincol, int smaxrow, int smaxcol);
int pnoutrefresh(WINDOW *pad, int pminrow, int pmincol,
int sminrow, int smincol, int smaxrow, int smaxcol);
int pechochar(WINDOW *pad, chtype ch);
int pecho_wchar(WINDOW *pad, const cchar_t *wch);
π¦ DESCRIPTION π¦
so a curses pad is literally just a window, except it said "no β" to the screen-size rules and it's not tied to any one part of the screen. it's giving main character energy that refuses to be contained π
use pads when you need a HUGE window but only a little piece of it should be visible on screen. and heads up: pads do not get auto-refreshed by scrolling or input-echoing operations. they mind their own business, fr fr.
π¨ also, you cannot refresh a pad withwrefresh(3NCURSES). useprefreshorpnoutrefreshinstead. do not try it. it will not slay.
β¨ newpad β¨
newpad creates a brand-new pad data structure and returns a pointer to it, with the number of lines you asked for (nlines) and columns you asked for (ncols). iconic. no notes.
π subpad π
subpad creates a subwindow inside a pad and returns a pointer to it, again with the lines (nlines) and columns (ncols) you want.
but here's the twist π β unlike subwin(3NCURSES), which uses screen coordinates, the new pad gets placed at position (begin_y, begin_x) relative to its parent. so they're likeβ¦ linked. changes made to one pad can affect both. it's giving shared custody π
and when you're operating on a subpad, you'll often have to call touchwin(3NCURSES) or touchline(3NCURSES) on the parent before you call prefresh. don't forget, bestie, or you'll be staring at a sad stale screen.
π prefresh, pnoutrefresh π
prefresh and pnoutrefresh are the pad-flavored twins of wrefresh(3NCURSES) and wnoutrefresh(3NCURSES) β same vibe, but they operate on pads instead of windows.
the catch? they need extra parameters to tell them which portions of the pad and the screen are involved, because how else would anything know π
pminrowandpmincolspecify the upper left-hand corner of a rectangular view of the pad.sminrow,smincol,smaxrow, andsmaxcolspecify the vertices of the rectangle to be displayed on the screen.
the lower right-hand corner of the rectangle to be displayed in the pad gets calculated from the screen coordinates, because the two rectangles have to be the same size β matching set, obviously π
both rectangles must be entirely contained within their respective structures. and if you pass negative values for any of these parameters, curses just treats them as zero. no drama, just zero.
π pechochar π
pechochar does exactly the same thing as calling waddch(3NCURSES) and then prefresh. literally the same.
but it whispers to the curses optimizer that only a single character is being output, and a considerable performance benefit may be thus enjoyed π₯ the location of the character ch written to the pad is what populates the arguments to prefresh. efficiency queen π
π pecho_wchar π
pecho_wchar is functionally equivalent to calling wadd_wch(3NCURSES) followed by prefresh. it hints to the curses optimizer that only a single wide character is being output, and again, considerable performance benefit may be thus enjoyed π₯π₯
the location of the character wch written to the pad populates the arguments to prefresh. same energy, wider characters π
π RETURN VALUE π
functions that return an int return ERR when things go wrong and OK when they go right. simple as.
functions that return pointers return a null pointer on failure. tragic but true.
and in this here implementation, specifically:
prefreshandpnoutrefreshβ returnERRif the window pointer is null, or if the window is not really a pad, or if the area to refresh extends off-screen, or if the minimum coordinates are greater than the maximum. four separate ways to fail, she contains multitudes πpechocharβ returnsERRif the window is not really a pad, and the associated call towechocharreturnsERR.pecho_wcharβ returnsERRif the window is not really a pad, and the associated call towecho_wcharreturnsERR.
π NOTES π
pechochar may be implemented as a macro. just so you know π«Ά
okay and here's some lore: curses documentation is traditionally averse to motivating the term "pad". the Apollo Aegis workstation operating system (circa 1981) supported a graphical pad feature. yes, we're going back in time, bestie π°οΈ
- these graphical pads could be much larger than the computer's display.
- the read-only output from a command could be scrolled back to inspect and select text from the pad.
the two uses may be related. we simply do not know. iykyk π€·
π§ PORTABILITY π§
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. bold of it.
SVr4 describes a successful return value only as "an integer value other than ERR". vague! mysterious! the minimalism π
the behavior of subpad if the parent window is not a pad is undocumented, and it is not checked by the vendor Unix implementations. so⦠undefined territory, tread carefully.
- SVr4 curses's
newpadsets a flag in theWINDOWstructure indicating that the window is a pad.- however, it uses this information only in
waddch(to decide if it should callwrefresh) andwscrl(to avoid scrolling a pad); itswrefreshdoes not check it to ensure that a pad is properly updated. so the flag is kind of just⦠vibing there unfollowed.
- however, it uses this information only in
- Solaris
xcurseschecks whether a window is a pad in itswnoutrefresh, returningERRin that case.- however, it sets the flag on subwindows only if the parent window is a pad. its
newpaddoes not set this information. consequently, the check never fails. incredible. iconic. useless π - it makes no comparable check in
pnoutrefreshβ though interestingly enough, a comment in the source code states that the lack of a check was an MKS extension.
- however, it sets the flag on subwindows only if the parent window is a pad. its
- NetBSD 7 curses sets a flag in the
WINDOWstructure fornewpadandsubpad, aiding itself to distinguish betweenwnoutrefreshandpnoutrefresh.- it does not check for the case where a subwindow is created in a pad using
subwinorderwin. - its
dupwinreturns a regular window when duplicating a pad. likewise, itsgetwinalways returns a window, even if the saved data was from a pad.
- it does not check for the case where a subwindow is created in a pad using
and then there's ncurses, which simply ate π :
- it sets a flag in the
WINDOWstructure fornewpadandsubpad, - it allows a
subwinorderwincall to succeed having a pad parent by forcing the subwindow to be a pad, - it checks in both
wnoutrefreshandpnoutrefreshto ensure that pads and windows are handled distinctly, and - it ensures that
dupwinandgetwintreat pads versus windows consistently.
no cap, that's the whole checklist, and she did all of it π
β HISTORY β
SVr2 (1984) introduced newpad, prefresh, and pnoutrefresh, documenting them in a single line each. stingy with the words, generous with the functions.
SVr3 (1987) added subpad and pechochar, and provided more extensive documentation. glow up unlocked.
The System V Interface Definition, Version 4 (1995), specified a function named pechowchar. this was a later addition to SVr4.x, and it does not appear in the first SVr4 (1989). it differs from X/Open's later pecho_wchar in that its wstr parameter was a chtype instead of a wchar_t, and was not const-qualified. history really said "close enough" π
π SEE ALSO π
ncurses(3NCURSES)addch(3NCURSES)refresh(3NCURSES)touch(3NCURSES)
and that's the whole page, bestie π«Ά this was ncurses 6.6, dated 2026-04-18 β go forth and refresh your pads responsibly πβ¨π
π¦ where this page comes from
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- Copyright 2018-2025,2026 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