Skip to content

Commit 538ee51

Browse files
committed
Show error, when STDOUT is not a TTY, minor code cleanung.
1 parent 682ae9a commit 538ee51

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/host/common/ArduinoMain.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ bool user_exit = false;
4343
const char* host_interface = nullptr;
4444
size_t spiffs_kb = 1024;
4545
bool ignore_sigint = false;
46+
bool restore_tty = false;
4647

4748
#define STDIN STDIN_FILENO
4849

@@ -57,17 +58,23 @@ static int mock_start_uart(void)
5758
settings = initial_settings;
5859
settings.c_lflag &= ~(ignore_sigint ? ISIG : 0);
5960
settings.c_lflag &= ~(ECHO | ICANON);
60-
settings.c_iflag &= ~(ICRNL | INLCR | ISTRIP | IXON );
61+
settings.c_iflag &= ~(ICRNL | INLCR | ISTRIP | IXON);
6162
settings.c_oflag |= (ONLCR);
6263
settings.c_cc[VMIN] = 0;
6364
settings.c_cc[VTIME] = 0;
6465
if (tcsetattr(STDIN, TCSANOW, &settings) < 0) return -2;
66+
tty_restore = true;
6567
return 0;
6668
}
6769

6870
static int mock_stop_uart(void)
6971
{
70-
if (!isatty(STDIN)) return 0;
72+
if (!restore_tty) return 0;
73+
if (!isatty(STDIN)) {
74+
perror("isatty(STDIN)");
75+
//system("stty sane"); <- same error message "Inappropriate ioctl for device"
76+
return 0;
77+
}
7178
if (tcsetattr(STDIN, TCSANOW, &initial_settings) < 0) return -1;
7279
printf("\e[?25h"); // show cursor
7380
return (0);

0 commit comments

Comments
 (0)