instr(3NCURSES)
π instr β the manual page, but make it cute π
okay bestie, so this is a page from the ncurses manual (that's the Library calls section, iykyk) and it's literally all about grabbing a string out of a curses window. very demure, very mindful, very "get the text out of the box". 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 β¨
okay so winstr snatches a string out of a curses window called win. it starts right at the cursor π and keeps going until the end of the line, then it stashes the whole thing in str. and bestie, it terminates it with a null character β yes we love a clean ending β and it omits any attributes and the color pair identifier that curses associates with each character. so it's just the raw text, no glow-up attached π
winnstr does the exact same thing, but it copies at most n characters from win. and here's the tea: a negative n implies no limit β winnstr just chills and works like winstr in that case π¦
and ncurses(3NCURSES) describes the variants of these functions, if you want the full lore β¨
β¨ RETURN VALUE β¨
these functions hand you back the count of characters copied from win to str (and no, that count does not include the null terminator, she's not invited) β or ERR upon failure π
in ncurses, these functions fail if:
- 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 functions prefixed with mv first perform cursor movement, and they fail if the position (y, x) is outside the window boundaries. so like, know your bounds bestie π«Ά
β¨ NOTES β¨
all of these functions except winnstr may be implemented as macros. sneaky little things π
β οΈ reading a line that overflows the array pointed to bystrwithinstrand its variants causes undefined results. this is not the vibe. instead, use then-infixed functions with a positivenargument no larger than the size of the buffer backingstr. protect your buffers, protect your peace π§
β¨ EXTENSIONS β¨
innstr, winnstr, mvinnstr, and mvwinnstr's acceptance of negative n values is an ncurses extension π (not standard, just iconic)
β¨ PORTABILITY β¨
if your app is using ncurses extensions, bestie, you should condition their use on the visibility of the NCURSES_VERSION preprocessor macro. fr fr π
X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. no cap.
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.1andSVr4implementedwinstras 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) byX/Open, rather than an intentional change. π the drama of it allncursesretains compatibility withSystem Vcurses behavior. loyal to a fault π
SVr4 describes a successful return value only as "an integer value other than ERR". vague. mysterious. lowkey unhelpful β¨
and SVr4 does not document whether n counts the null terminator that these functions write to str. we simply do not know. the mystery remains π
β¨ HISTORY β¨
SVr3.1 (1987) introduced these functions. an oldie but a goodie π
β¨ SEE ALSO β¨
inwstr(3NCURSES) describes comparable functions of the ncurses library in its wide-character configuration (ncursesw). β¨
ncurses(3NCURSES), inch(3NCURSES), inchstr(3NCURSES) π
and that's the whole page bestie!! this lil' cutie came from ncurses 6.6, dated 2025-10-20, and the manual page itself goes by instr(3NCURSES) π¦ go forth and read your windows, but mind your buffer sizes okay?? 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,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