curs_pad(3X)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

✨ curs_pad(3X) ✨

okay bestie, pull up a chair πŸ’– this is the library calls page for curs_pad β€” aka the moment your terminal window realizes it doesn't have to fit on the screen anymore.


🌸 NAME 🌸

newpad, subpad, prefresh, pnoutrefresh, pechochar, pecho_wchar β€” create and display curses pads. that's the whole vibe, let's go πŸ’…


✨ 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 like a window, except it is not restricted by the screen size, and it's not necessarily associated with a particular part of the screen. it's giving main character energy in a world that's too small for it 🌈 pads are what you reach for when you need a huge window but only want part of it visible on screen. and lowkey important: pads are not automatically refreshed by scrolling or input-echoing operations. they don't do stuff behind your back, periodt.

pads cannot be refreshed with wrefresh(3X) β€” use prefresh or pnoutrefresh instead. that's the rule, no cap πŸ™…

πŸ¦‹ newpad

newpad creates and returns a pointer to a brand new pad data structure with the given number of lines, nlines, and columns, ncols. iconic, honestly.

πŸŽ€ subpad

subpad creates and returns a pointer to a subwindow within a pad with the given number of lines, nlines, and columns, ncols. and here's the plot twist β€” unlike subwin(3X), which uses screen coordinates, the new pad is placed at position (begin_y, begin_x) relative to its parent. so changes made to one pad can affect both πŸ‘€ they're linked, iykyk. when you're operating on a subpad, it's often necessary to call touchwin(3X) or touchline(3X) on parent before calling prefresh.

πŸ’– prefresh, pnoutrefresh

prefresh and pnoutrefresh are analogous to wrefresh(3X) and wnoutrefresh(3X) except that they operate on pads rather than windows. they need extra parameters to indicate what portions of the pad and the screen are involved:

  • pminrow and pmincol specify the upper left-hand corner of a rectangular view of the pad.
  • sminrow, smincol, smaxrow, and smaxcol specify 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 is calculated from the screen coordinates, since the rectangles must be the same size. both rectangles must be entirely contained within their respective structures. and curses treats negative values of any of these parameters as zero. zero, not negative, bestie 🫢

🌸 pechochar

pechochar is functionally equivalent to calling waddch(3X) followed by prefresh. it suggests to the curses optimizer that only a single character is being output β€” a considerable performance benefit may be thus enjoyed πŸ”₯ the location of the character ch written to the pad is used to populate the arguments to prefresh.

🌈 pecho_wchar

pecho_wchar is functionally equivalent to calling wadd_wch(3X) followed by prefresh. it suggests to the curses optimizer that only a single wide character is being output β€” a considerable performance benefit may be thus enjoyed πŸ”₯ the location of the character wch written to the pad is used to populate the arguments to prefresh.


πŸ‘‘ RETURN VALUE πŸ‘‘

functions that return an integer return ERR upon failure and OK upon successful completion. simple as that πŸ’…

functions that return pointers return a null pointer on failure, and set errno to ENOMEM.

in this implementation:

  • prefresh and pnoutrefresh β€” return ERR if 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.
  • pechochar β€” returns ERR if the window is not really a pad, and the associated call to wechochar returns ERR.
  • pecho_wchar β€” returns ERR if the window is not really a pad, and the associated call to wecho_wchar returns ERR.

πŸ“ NOTES πŸ“

pechochar may be implemented as a macro. πŸ™ˆ (not me finding out it might not even be a real function)

curses documentation is traditionally averse to motivating the term β€œpad”. the Apollo Aegis workstation operating system (circa 1981) supported a graphical pad feature.

  • 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. 🌟


πŸ’€ PORTABILITY πŸ’€

X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. πŸ’€

SVr4 describes a successful return value only as β€œan integer value other than ERR”.

the behavior of subpad if the parent window is not a pad is undocumented, and is not checked by the vendor Unix implementations. (so like... undefined behaviour territory, tread carefully bestie 🚨)

  • SVr4 curses's newpad sets a flag in the WINDOW structure indicating that the window is a pad.
    • however, it uses this information only in waddch (to decide if it should call wrefresh) and wscrl (to avoid scrolling a pad); its wrefresh does not check it to ensure that a pad is properly updated.
  • Solaris xcurses checks whether a window is a pad in its wnoutrefresh, returning ERR in that case.
    • however, it sets the flag on subwindows only if the parent window is a pad. its newpad does not set this information. consequently, the check never fails.
    • 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.
  • NetBSD 7 curses sets a flag in the WINDOW structure for newpad and subpad, aiding itself to distinguish between wnoutrefresh and pnoutrefresh.
    • it does not check for the case where a subwindow is created in a pad using subwin or derwin.
    • its dupwin returns a regular window when duplicating a pad. likewise, its getwin always returns a window, even if the saved data was from a pad.

ncurses:

  • sets a flag in the WINDOW structure for newpad and subpad,
  • allows a subwin or derwin call to succeed having a pad parent by forcing the subwindow to be a pad,
  • checks in both wnoutrefresh and pnoutrefresh to ensure that pads and windows are handled distinctly, and
  • ensures that dupwin and getwin treat pads versus windows consistently.

ncurses said "we do it right, everyone else can stay confused" ✨


πŸ“œ HISTORY πŸ“œ

SVr2 (1984) introduced newpad, prefresh, and pnoutrefresh, documenting them in a single line each. one line. for all three. iconic minimalism honestly 😭

SVr3 (1987) added subpad and pechochar, and provided more extensive documentation.

The System V Interface Definition, Version 4 (1995), specified a function named pechowchar. this was a later addition to SVr4.x, not appearing 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. the way the naming just... drifted πŸŒ€


🧚 SEE ALSO 🧚

curses(3X), curs_addch(3X), curs_refresh(3X), curs_touch(3X)


go forth and make enormous pads that don't fit on anybody's screen. that's your moment 🌟

and that's the page bestie!! brought to you by ncurses 6.6, dated 2025-08-23 β€” mwah, slay, bye πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from