1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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;
});
}
}
|