diff options
author | Your Name <you@example.com> | 2024-03-28 16:18:36 -0400 |
---|---|---|
committer | Your Name <you@example.com> | 2024-03-28 16:18:36 -0400 |
commit | c644379e79262a7478a7fb9ea8001f315fdb6eaf (patch) | |
tree | d71b15e396ebca28b76f0b5fd1971dd352877e4e /src/ui.cc | |
download | nerdhack-c644379e79262a7478a7fb9ea8001f315fdb6eaf.tar.gz nerdhack-c644379e79262a7478a7fb9ea8001f315fdb6eaf.tar.bz2 nerdhack-c644379e79262a7478a7fb9ea8001f315fdb6eaf.zip |
Diffstat (limited to 'src/ui.cc')
-rw-r--r-- | src/ui.cc | 51 |
1 files changed, 51 insertions, 0 deletions
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 <cstring> +#include <iostream> +#include <ctype.h> +#include <format> + +#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; + }); + } + +} |