-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
47 lines (44 loc) · 1.19 KB
/
main.cpp
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
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <thread>
#include "libmterm.h"
int main(void)
{
int id = CreateMtermDefault();
std::thread readT([id] {
SetReadNonblockMterm(id);
char buf[4096];
int res;
while (true)
{
res = ReadMterm(id, buf, sizeof(buf));
if (res > 0)
write(1, buf, res);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
});
std::thread writeT([id] {
// stdin nonblock read
fcntl(0, F_SETFL, O_NONBLOCK | fcntl(0, F_GETFL));
// close echo and set canonical mode
struct termios oldSettings, newSettings;
tcgetattr(0, &oldSettings);
newSettings = oldSettings;
newSettings.c_lflag &= ~(ICANON | ECHO);
tcsetattr(0, TCSANOW, &newSettings);
char buf[4096];
int res;
while (true)
{
res = read(0, buf, sizeof(buf));
if (res > 0)
WriteMterm(id, buf, res);
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
});
readT.join();
writeT.join();
return 0;
}