Curses

Curses is a way to manipulate terminals mainly for text user interfaces in applications.

ncurses.h

The ncurses.h helper file in C includes a lot of other libraries, as well, which means you don't need to include them, as they may bloat your final compiled program[2]:

Example

This is an example of ncurses, the most common curses library, from Dan Gookin's book[2] in C.

goodbye.c

#include <ncurses.h> // Use the ncurses library

int main(void)
{
  initscr(); // allocates memory for present window which is called stdscr[4]
  addstr("Goodbye, cruel C programming!"); // add string to window
  refresh(); // flushes current window to the screen
  getch();   // waits for user input to exit

  endwin();  // call to end or exit our curses program[5]
  return 0;  // ended program without errors
}

Compiling

$ gcc -lncurses goodbye.c -o goodbye
# -lncurses : the curses linker

Running

$ ./goodbye

Functions

Cursor

Printing Text

Text Formatting

Styles

Attribute Effect
A_BOLD Bright text, bold text, thick text (depending on terminal type)
A_DIM Dimmed text (not as bright as regular text)
A_NORMAL Normal text
A_REVERSE Inverse text
A_STANDOUT Same as standout()
A_UNDERLINE Underline text

Colors

User Input

Display

References

  1. https://en.wikipedia.org/wiki/Curses_%28programming_library%29
  2. https://www.goodreads.com/book/show/4460597-programmer-s-guide-to-ncurses
  3. https://www.linuxhowtos.org/manpages/3x/ncurses.htm
  4. https://www.sbarjatiya.com/notes_wiki/index.php/Using_ncurses_library_with_C
  5. https://linux.die.net/man/3/endwin
  6. https://manpages.debian.org/testing/ncurses-doc/start_color.3ncurses.en.html
  7. https://stackoverflow.com/questions/5072881/how-to-clear-a-specific-line-with-ncurses
Incoming Links

Last modified: 202401040446