Skip to content

Commit

Permalink
Record and use previous TTY settings on exit
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Burton <mburton@quicinc.com>
  • Loading branch information
markfoodyburton committed Dec 12, 2024
1 parent 69dcfd7 commit 2259081
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class char_backend_stdio : public sc_core::sc_module

public:
gs::biflow_socket<char_backend_stdio> socket;
static struct termios oldtty;
static bool oldtty_valid;

#ifdef WIN32
#pragma message("CharBackendStdio not yet implemented for WIN32")
Expand All @@ -54,15 +56,15 @@ class char_backend_stdio : public sc_core::sc_module

static void tty_reset()
{
struct termios tty;

int fd = STDIN_FILENO; /* stdin */

tcgetattr(fd, &tty);

tty.c_lflag |= ECHO | ECHONL | ICANON | IEXTEN;

tcsetattr(fd, TCSANOW, &tty);
if (char_backend_stdio::oldtty_valid) {
tcsetattr(fd, TCSANOW, &char_backend_stdio::oldtty);
} else {
struct termios tty;
tcgetattr(fd, &tty);
tty.c_lflag |= ECHO | ECHONL | ICANON | IEXTEN;
tcsetattr(fd, TCSANOW, &tty);
}
}
// trim from end of string (right)
std::string& rtrim(std::string& s)
Expand Down Expand Up @@ -221,11 +223,15 @@ class char_backend_stdio : public sc_core::sc_module

void start_of_simulation()
{
struct termios tty;
int fd = STDIN_FILENO; /* stdin */
tcgetattr(fd, &tty);
tty.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
tcsetattr(fd, TCSANOW, &tty);
if (!char_backend_stdio::oldtty_valid) {
struct termios tty;
int fd = STDIN_FILENO; /* stdin */
tcgetattr(fd, &tty);
char_backend_stdio::oldtty = tty;
char_backend_stdio::oldtty_valid = true;
tty.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
tcsetattr(fd, TCSANOW, &tty);
}
}

void end_of_simulation() { tty_reset(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
#include <systemc>

#include "char_backend_stdio.h"
struct termios char_backend_stdio::oldtty;
bool char_backend_stdio::oldtty_valid = false;

void module_register() { GSC_MODULE_REGISTER_C(char_backend_stdio); }

0 comments on commit 2259081

Please sign in to comment.