Site Tools


wiki:h-curses

Table of Contents

<curses.h>

<curses.h> (typically <ncurses.h>) provides terminal control for building text-based user interfaces: window creation, cursor positioning, text attributes, and input handling. It translates portable abstractions into the right escape sequences for any terminal.

Use it to build full-screen TUI applications that work across different terminal types.

Example

This example initializes ncurses, draws text at a specific position, and waits for user input.

// compile: gcc -o cursesexample cursesexample.c -lncurses
// run: ./cursesexample
// description: draw positioned text and handle input
 
#include <ncurses.h>
#include <unistd.h>
 
int main() {
    initscr();
    int h, w;
    getmaxyx(stdscr, h, w);
 
    mvprintw(h/2, w/2 - 8, "Hello, ncurses!");
    mvprintw(h/2 + 1, w/2 - 10, "Terminal: %d x %d", w, h);
    refresh();
 
    sleep(2);
    endwin();
    return 0;
}
wiki/h-curses.md · Last modified: by 127.0.0.1