From c644379e79262a7478a7fb9ea8001f315fdb6eaf Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 28 Mar 2024 16:18:36 -0400 Subject: Initial commit --- src/ui.cc | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/ui.cc (limited to 'src/ui.cc') diff --git a/src/ui.cc b/src/ui.cc new file mode 100644 index 0000000..37f8078 --- /dev/null +++ b/src/ui.cc @@ -0,0 +1,51 @@ +#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; + }); + } + +} -- cgit v1.2.3