SVN / public / code / vorlesung-03 / NcursesDemo.cpp

Revision 1679
Date2026-05-05T16:08:54+02:00
Committerhb1003
Download
// Copyright 2026, University of Freiburg
// Chair of Algorithms and Data Structures
// Author: Hannah Bast <bast@cs.uni-freiburg.de>

#include "NcursesDemo.h"
#include <ncurses.h>

// _____________________________________________________________________________
int row;
int col;

// _____________________________________________________________________________
void startNcurses() {
  initscr();
  curs_set(false);
  noecho();
  nodelay(stdscr, true);
  keypad(stdscr, true);
  row = LINES / 2;
  col = COLS / 2;
  start_color();
  init_pair(1, COLOR_RED, COLOR_BLACK);
}

// ____________________________________________________________________________
void endNcurses() { endwin(); }

// ____________________________________________________________________________
void move(int keycode) {
  switch (keycode) {
  case KEY_LEFT:
    col -= 2;
    break;
  case KEY_RIGHT:
    col += 2;
    break;
  case KEY_UP:
    row -= 1;
    break;
  case KEY_DOWN:
    row += 1;
    break;
  }
}