Ncurses Notes from the series on the Casual Coder youtube channel.

Tutorial 0: init screen

#include <ncurses.h>
using namespace std;

main() {
  initscr();
  printw("Hello World!");
  refresh();
  int c = getch();
  printw("%d", c);
  getch();
  endwin();
  return 0;
}

Tutorial 1: move

  initscr();
  
  int x, y;
  x = y = 10;
  move(y,x); // note y first, x second

  int c = getch();
  move(0,0);
  printw("%d",c);

  mvprintw(2,3,"%d",c);
  refresh();

  getch();
  clear();

Tutorial 2: windows basics

  WINDOW *win;

  int height=10, width=40, start_y=5, start_x=5;
  win = newwin(height, width, start_y, start_x);
  refresh();
  
  box(win,0,0);
  mvwprintw(win,1,1,"this is my box");
  wrefresh(win);

Tutorial 3: Borders etc

  cbreak(); // ctrl+c exits
  raw();
  noecho();

  // opposites
  nocbreak();
  echo();
  noraw();

  // borders
  box(win,(int)'g',(int)'h');
  int left, right, top, bottom;
  int topleftcorner, toprightcorner, botleftcorner, botrightcorner;
  left = right = (int)'g';
  top = bottom = (int)'h';
  topleftcorner = toprightcorner = botleftcorner = botrightcorner = (int)'+'
  wborder(win,
    left,
    right,
    top,
    bottom,
    topleftcorner,
    toprightcorner,
    botleftcorner,
    botrightcorner);