clear(3NCURSES)
β¨ clear β bestie, we're wiping the window β¨
okay so real talk, this is the clear page from ncurses (it lives in the Library calls section, hence the 3NCURSES β iykyk). it's the whole girlboss family of "make it blank" functions. and yes there's eight of them. stay with me π«Ά
πΈ NAME πΈ
erase, werase, clear, wclear, clrtobot, wclrtobot, clrtoeol, wclrtoeol β the squad that clears all of a curses window, or just part of it. your choice, main character π
β¨ SYNOPSIS β¨
#include <curses.h>
int erase(void);
int werase(WINDOW *win);
int clear(void);
int wclear(WINDOW *win);
int clrtobot(void);
int wclrtobot(WINDOW *win);
int clrtoeol(void);
int wclrtoeol(WINDOW *win);
like, so many twins. the w version is the one that takes a window, the one without w is the one that assumes stdscr. no cap.
π¦ DESCRIPTION π¦
erase, werase β the gentle wipe π¬οΈ
erase and werase literally copy blanks into every single position in the window. every one. the whole vibe, gone, replaced with spaces. screen = cleared.
and here's the cute detail bestie: those blanks aren't just naked spaces, they come with the current background rendition merged into them β the one you set with wbkgdset(3NCURSES). so they're wearing the outfit you picked. periodt.
clear, wclear β the dramatic wipe π
clear and wclear are exactly like erase and weraseβ¦ but they also call clearok(3NCURSES). and what does that do? it means the screen gets cleared completely on the next call to wrefresh for that window, and then repainted from scratch. not a touch-up. a full reset. it's giving rebirth. it's giving factory settings. π₯
clrtobot, wclrtobot β bottom half, gone π§Ή
clrtobot and wclrtobot erase from the cursor to the end of the screen. so like, every line below the cursor in the window? erased. and also the current line to the right of the cursor, inclusive, gets erased too. so the cursor's own spot is included. rude but fair.
clrtoeol, wclrtoeol β just this line, thanks π
clrtoeol and wclrtoeol erase the current line to the right of the cursor, inclusive, all the way to the end of the current line. that's it. one line. surgical. we love a specialist. β¨
π RETURN VALUE π
every single one of these returns the integer OK when it slays, and ERR when it doesn't. simple.
but in this implementation, there are two extra receipts:
- functions that use a window pointer parameter return
ERRif that pointer is null π wclrtoeolreturns an error if the cursor position is about to wrap
π NOTES π
erase, werase, clear, wclear, clrtobot, and clrtoeol may be implemented as macros. so don't be out here taking their address like a fool. (that's just how macros are, bestie, i don't make the rules)
π PORTABILITY π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. none. zero. they simply said "good luck".
SVr4 documentation says these functions return OK βor a non-negative integer if immedok() is setβ β and that's referring to the return value from wrefresh, which in SVr4 returns a count of characters written to the window if its immedok property is set. in ncurses, it does not. so like, don't count on that.
some historic curses implementations had, as an undocumented feature, the ability to do the equivalent of clearok(..., 1) by saying touchwin(stdscr) or clear(stdscr). > β οΈ this will not work under ncurses. sorry bestie, that trick is dead. π
this implementation β and others such as Solaris β sets the current position to 0,0 after erasing via werase and wclear. that fact is not documented in other implementations, and it may not be true of implementations that weren't derived from SVr4 source. so it's a vibe, not a guarantee.
and this one is not obvious from the description: most implementations clear the screen after wclear even for a subwindow or derived window. π« so if you do not want the screen cleared during the next wrefreshβ¦ use werase instead. that's the whole tip. that's the tea. π
π§ SEE ALSO π§
ncurses(3NCURSES)outopts(3NCURSES)refresh(3NCURSES)curses_variables(3NCURSES)
and that's the page bestie!! this was ncurses 6.6, dated 2025-01-18. go forth and clear your windows 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-2010,2016 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms