insch(3NCURSES)

πŸ’– insch β€” insert a curses character in a window πŸ’–

okay bestie, welcome to insch(3NCURSES), straight out of the Library calls section of the manual. this is the lil family of functions that shoves a character into your window and makes everybody else scooch over. it's giving polite queue energy. let's get into it ✨


✨ SYNOPSIS ✨

#include <curses.h>

int insch(chtype ch);
int winsch(WINDOW * win, chtype ch);
int mvinsch(int y, int x, chtype ch);
int mvwinsch(WINDOW * win, int y, int x, chtype ch);

four functions, one dream, no cap 🫢


🌸 DESCRIPTION 🌸

so winsch inserts the curses character ch at the cursor position in the window win. that's the whole vibe.

and the way it works? the character that was already sitting at the cursor, plus literally everything to its right, all move one cell to the right. the character that used to be the rightmost one on the line? bestie… it's discarded. gone. no forwarding address 😭

BUT β€” and this is the part people miss β€” unlike addch(3NCURSES), winsch does not advance the cursor. it inserts and then it just… stays put. main character behavior honestly πŸ’…

ncurses(3NCURSES) describes the variants of this function, so go read that if you wanna know how the family tree works 🧚


⭐ RETURN VALUE ⭐

these functions return OK on success and ERR on failure. simple as that πŸ’–

in ncurses, they return ERR if:

  • the curses screen has not been initialized, or
  • (for functions taking a WINDOW pointer argument) win is a null pointer.

and the ones with that mv prefix? they do cursor movement first, and they fail if the position (y, x) is outside the window boundaries. so if you're trying to move somewhere that doesn't exist, it's an ERR, periodt πŸ™ˆ


πŸŽ€ NOTES πŸŽ€

okay a couple of lil things you should know:

  • insch, mvinsch, and mvwinsch may be implemented as macros. so don't get cute with them, iykyk.
  • curses does not necessarily employ the terminal's insert_character (ich1) capability to achieve insertion. so like… don't assume the terminal is doing the work here. the library might be doing it all by itself. iconic of it honestly πŸ”₯

🌈 PORTABILITY 🌈

X/Open Curses Issue 4 describes these functions. it specifies no error conditions for them. wild, i know. we're just out here raw-dogging error handling bestie πŸ’€

SVr4 describes a successful return value only as β€œan integer value other than ERR”. so like, not even OK specifically. just… not ERR. the bar is on the floor fr fr 🫢


πŸ¦‹ HISTORY πŸ¦‹

SVr2 (1984) introduced these functions. so they've been around since before your parents were cool. vintage. antique. elder emoji πŸ‘‘


πŸ’œ SEE ALSO πŸ’œ

  • ins_wch(3NCURSES) β€” describes comparable functions in the wide-character curses configuration. so if you're doing wide chars, that's your girl 🌸
  • ncurses(3NCURSES)
  • terminfo(5)

quick reminder bestie: this is insch, not inch. one inserts a character, the other reads one. do not mix them up in front of company 😭

and that's the whole page!! this was ncurses 6.6, dated 2025-03-08, and yes the header really did say insch(3NCURSES) up top and Library calls as its section. slay, go insert some characters, you got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from