#include "ui.h" #include "ui_private.h" #include "ui_terminal.h" #include #include #include #include #define TERMLINES 24 #define TERMCOLS 80 namespace ui { UI::UI() : data(new uiImpl()) { initscr(); start_color(); data->terminal = newwin(TERMLINES, TERMCOLS, 1, COLS-TERMCOLS-1); data->termBorder = newwin(TERMLINES+2, TERMCOLS+2, 0, COLS-TERMCOLS-2); scrollok(data->terminal, TRUE); idlok(data->terminal, TRUE); noecho(); cbreak(); box(data->termBorder, 0, 0); mvwprintw(data->termBorder, 0, 1, "TERMINAL"); refresh(); wrefresh(data->termBorder); wrefresh(data->terminal); data->parser = CommandParser(getCommandCallbacks(this->data->terminal)); } UI::~UI() { endwin(); } void UI::registerCallbacks(vm::VM& vm) { vm.connect([this](const char *data, size_t nbytes) { for(size_t i = 0; i < nbytes; i++) { std::cerr << std::format("0x{:x}|", data[i]); this->data->parser.parse(data[i]); } wrefresh(this->data->terminal); return int(nbytes); }, [](char *data, size_t nbytes) { data[0] = getch(); return 1; }); } }