curs_instr(3X)
π curs_instr β Library calls π
okay bestie, we're diving into curs_instr(3X) from the ncurses fam, and honestly? it's giving "grab text off the screen" energy and i am obsessed. this whole page lives in the ncurses manual (yes, the library calls corner of it), and it's here to teach you how to yoink a string out of a curses window. no cap, it's useful. let's go π¦
β¨ NAME β¨
instr, winstr, mvinstr, mvwinstr, innstr, winnstr, mvinnstr, mvwinnstr β get a string from a curses window πΈ
β¨ SYNOPSIS β¨
#include <curses.h>
int instr(char * str);
int winstr(WINDOW * win, char * str);
int mvinstr(int y, int x, char * str);
int mvwinstr(WINDOW * win, int y, int x, char * str);
int innstr(char * str, int n);
int winnstr(WINDOW * win, char * str, int n);
int mvinnstr(int y, int x, char * str, int n);
int mvwinnstr(WINDOW * win, int y, int x, char * str, int n);
β¨ DESCRIPTION β¨
so winstr is the main character here π
it pulls a string out of a curses window called win, starting right at the cursor and going until it hits the end of the line. then it tucks that string into str, slaps a null character on the end to terminate it, and β super important β it leaves out any attributes and the color pair identifier that curses has attached to each character. clean string, no extra baggage, periodt.
winnstr does the exact same thing, except it copies at most n characters from win. and here's the cute part: a negative n means no limit at all, so winnstr just behaves like winstr. β¨
ncurses(3X) is where you go to read about the variants of these functions, iykyk.
β¨ RETURN VALUE β¨
these functions hand you back the count of characters copied from win to str β and no, the null terminator does not count, she's not included in the tally π β or they return ERR if something went wrong. π
in ncurses, these functions fail when:
- the curses screen has not been initialized,
- (for the functions that take a
WINDOWpointer argument)winis a null pointer, or stris a null pointer.
and the ones prefixed with βmvβ? they do cursor movement first, and they fail if the position (y, x) is outside the window boundaries. rude, but fair. π
β¨ NOTES β¨
- every single one of these functions except
winnstrmay be implemented as macros. so like, don't be weird about taking their address, bestie. π - reading a line that overflows the array pointed to by
strwith and its variants causes undefined results. yes, undefined. the void. we don't go there. π³οΈ
instead, use the n-infixed functions with a positivenargument that's no larger than the size of the buffer backingstr. that's the move. π«Ά
β¨ EXTENSIONS β¨
innstr, winnstr, mvinnstr, and mvwinnstr's acceptance of negative n values is an ncurses extension. like, that's our thing, ncurses invented it. π
β¨ PORTABILITY β¨
if your app is out here using ncurses extensions, you should gate that usage on whether the NCURSES_VERSION preprocessor macro is visible. be polite, check first. π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. wild, but okay.
X/Open Curses Issues 4 and 7 both state that instr, winstr, mvinstr, and mvwinstr return OK rather than a character count. this is likely an erratum. π¨
- SVr3.1 and SVr4 implemented
winstras a wrapper aroundwinnstr, returning the latter's return value. X/Open Curses's specification thus may have been an editorial solecism copied from System V's documentation (see below) by X/Open, rather than an intentional change. π - ncurses retains compatibility with System V curses behavior. π€
SVr4 describes a successful return value only as βan integer value other than ERRβ. so, vague. iconic of them.
SVr4 does not document whether n counts the null terminator that these functions write to str. the mystery continues. π΅οΈββοΈ
β¨ HISTORY β¨
SVr3.1 (1987) introduced these functions. a vintage moment. π
β¨ SEE ALSO β¨
curs_inwstr(3X) describes comparable functions of the ncurses library in its wide-character configuration (ncursesw). π¦
curses(3X), curs_inch(3X), curs_inchstr(3X)
and that's the whole page, bestie!! π«Ά this was brought to you by ncurses 6.6, dated 2025-10-20 β so you know it's fresh, you know it's iconic, and you know your girl read every single line so you didn't have to. go get that string. π β¨π
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2018-2024,2025 Thomas E. Dickey
- Copyright 1998-2010,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