94 lines
2.1 KiB
C++
94 lines
2.1 KiB
C++
|
#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);
|
||
|
std::string tty_name_str;
|
||
|
if (tty_name != nullptr)
|
||
|
{
|
||
|
tty_name_str = std::string(tty_name);
|
||
|
}
|
||
|
|
||
|
std::string fd_msg = "Hello tty: '" + tty_name_str + "'\n";
|
||
|
//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;
|
||
|
}
|
||
|
std::vector<char> buffer(100);
|
||
|
auto read_size = read(ttyfd, buffer.data(), buffer.size());
|
||
|
std::string out(buffer.begin(), buffer.begin()+read_size);
|
||
|
std::cout << "buf: " << out << std::endl;
|
||
|
}
|
||
|
std::cout << "loop break" << std::endl;
|
||
|
tcsetattr(ttyfd, TCSAFLUSH, &orig_tios);
|
||
|
*/
|
||
|
|
||
|
}
|
||
|
|
||
|
close(ttyfd);
|
||
|
}
|