2023-12-18 10:16:31 +00:00
|
|
|
#include "TestFramework.h"
|
|
|
|
#include "TestUtils.h"
|
|
|
|
|
|
|
|
#include "TermInfo.h"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
TEST_CASE(TestConsoleApp, "console")
|
|
|
|
{
|
|
|
|
//std::cout << "Hi from test console\n";
|
|
|
|
|
|
|
|
int ttyfd = open("/dev/tty", O_RDWR);
|
|
|
|
if (ttyfd > 0)
|
|
|
|
{
|
|
|
|
std::cout << "opened tty ok\n" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isatty(ttyfd))
|
|
|
|
{
|
|
|
|
auto tty_name = ttyname(ttyfd);
|
2023-12-21 09:18:44 +00:00
|
|
|
String tty_name_str;
|
2023-12-18 10:16:31 +00:00
|
|
|
if (tty_name != nullptr)
|
|
|
|
{
|
2023-12-21 09:18:44 +00:00
|
|
|
tty_name_str = String(tty_name);
|
2023-12-18 10:16:31 +00:00
|
|
|
}
|
|
|
|
|
2023-12-21 09:18:44 +00:00
|
|
|
String fd_msg = "Hello tty: '" + tty_name_str + "'\n";
|
2023-12-18 10:16:31 +00:00
|
|
|
//write(ttyfd, fd_msg.data(), fd_msg.size());
|
|
|
|
|
|
|
|
TermInfo term_info;
|
|
|
|
term_info.load();
|
|
|
|
/*
|
|
|
|
|
|
|
|
termios orig_tios;
|
|
|
|
tcgetattr(ttyfd, &orig_tios);
|
|
|
|
|
|
|
|
termios tios;
|
|
|
|
memcpy(&tios, &orig_tios, sizeof(tios));
|
|
|
|
|
|
|
|
cfmakeraw(&tios);
|
|
|
|
tios.c_cc[VMIN] = 1;
|
|
|
|
tios.c_cc[VTIME] = 0;
|
|
|
|
|
|
|
|
tcsetattr(ttyfd, TCSAFLUSH, &tios);
|
|
|
|
|
|
|
|
//int cap_enter_ca = 23;
|
|
|
|
//int cap_exit_ca = 24;
|
|
|
|
//int cap_hide_cursor = 26;
|
|
|
|
//int cap_clear_screen = 27;
|
|
|
|
|
|
|
|
|
|
|
|
fd_set fds;
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
|
|
|
|
int timeout = 2000;
|
|
|
|
timeval tv;
|
|
|
|
tv.tv_sec = timeout/1000;
|
|
|
|
tv.tv_usec = (timeout - (tv.tv_sec*1000))*1000;
|
|
|
|
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
|
|
|
|
int select_rv = select(1, &fds, nullptr, nullptr, &tv);
|
|
|
|
|
|
|
|
if (select_rv == 0)
|
|
|
|
{
|
|
|
|
std::cout << "timeout" << std::endl;
|
|
|
|
break;
|
|
|
|
}
|
2023-12-21 09:18:44 +00:00
|
|
|
Vector<char> buffer(100);
|
2023-12-18 10:16:31 +00:00
|
|
|
auto read_size = read(ttyfd, buffer.data(), buffer.size());
|
2023-12-21 09:18:44 +00:00
|
|
|
String out(buffer.begin(), buffer.begin()+read_size);
|
2023-12-18 10:16:31 +00:00
|
|
|
std::cout << "buf: " << out << std::endl;
|
|
|
|
}
|
|
|
|
std::cout << "loop break" << std::endl;
|
|
|
|
tcsetattr(ttyfd, TCSAFLUSH, &orig_tios);
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
close(ttyfd);
|
|
|
|
}
|