#include "main.h" #ifndef _TEMINAL_H_ #define _TEMINAL_H_ // This calls is used to initilaize ncurses terminal the correct way depending of the terminalk class Terminal { public: // Constuctor & Destructor Terminal(); ~Terminal(); //Functions int setup(); void tearDown(); int getKey(); int getXMax(); int getYMax(); void startDraw(); void endDraw(); bool isDone(); void quit(); void draw(int x, int y, const std::string& toDraw); private: int xMax, yMax, mouseX, mouseY = 0; bool m_done = false; }; Terminal::Terminal() { setup(); } Terminal::~Terminal() { tearDown(); } int Terminal::setup() { initscr(); // Inits ncurses screen in memory raw(); // raw input sor ctrl-c and ctrl-z wont work noecho(); // don't show the user inputs curs_set(0); // Cursor won't show up getmaxyx(stdscr, yMax, xMax); box(stdscr,0,0); if(!has_colors()) // If the terminal doesn't have colors { tearDown(); // Destroys the mains window printf("This menu is not supported by terminals without colors\n"); return -1; // Return an error. } getyx(stdscr, mouseY, mouseX); start_color(); // Otherwise init colors return 0; } void Terminal::tearDown() { endwin(); } int Terminal::getKey() { return getch(); } int Terminal::getXMax() { return xMax; } int Terminal::getYMax() { return yMax; } void Terminal::startDraw() { clear(); } void Terminal::endDraw() { refresh(); } bool Terminal::isDone() { return m_done; } void Terminal::quit() { m_done = true; } void Terminal::draw(int x, int y, const std::string& toDraw) { mvprintw(y,x,toDraw.c_str()); } #endif