aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/example/demo_scankey.c2
-rw-r--r--toys/net/microcom.c30
-rw-r--r--toys/other/hexedit.c2
-rw-r--r--toys/posix/ps.c2
4 files changed, 6 insertions, 30 deletions
diff --git a/toys/example/demo_scankey.c b/toys/example/demo_scankey.c
index d21490c8..cc625092 100644
--- a/toys/example/demo_scankey.c
+++ b/toys/example/demo_scankey.c
@@ -33,7 +33,7 @@ void demo_scankey_main(void)
tty_esc("?25l"); // hide cursor
tty_esc("0m"); // reset color to default
tty_esc("2J"); // Clear screen
- xset_terminal(1, 1, 0); // Raw mode
+ xset_terminal(1, 1, 0, 0); // Raw mode
for (;;) {
tty_jump(x, y);
diff --git a/toys/net/microcom.c b/toys/net/microcom.c
index d34e1fee..62fe85e6 100644
--- a/toys/net/microcom.c
+++ b/toys/net/microcom.c
@@ -26,22 +26,7 @@ GLOBALS(
struct termios original_stdin_state, original_fd_state;
)
-// Puts `fd` into raw mode, setting the baud rate if `speed` != 0,
-// and saving the original terminal state.
-static void xraw(int fd, const char *name, speed_t speed,
- struct termios *original)
-{
- struct termios t;
-
- if (tcgetattr(fd, &t)) perror_exit("tcgetattr %s", name);
- *original = t;
-
- cfmakeraw(&t);
- if (speed) cfsetspeed(&t, speed);
-
- if (tcsetattr(fd, TCSAFLUSH, &t)) perror_exit("tcsetattr %s", name);
-}
-
+// TODO: tty_sigreset outputs ansi escape sequences, how to disable?
static void restore_states(int i)
{
tcsetattr(0, TCSAFLUSH, &TT.original_stdin_state);
@@ -50,29 +35,20 @@ static void restore_states(int i)
void microcom_main(void)
{
- int speeds[] = {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
- 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800,
- 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
- 2500000, 3000000, 3500000, 4000000};
struct pollfd fds[2];
int i, speed;
if (!TT.s) speed = 115200;
else speed = atoi(TT.s);
- // Find speed in table, adjust to constant
- for (i = 0; i < ARRAY_LEN(speeds); i++) if (speeds[i] == speed) break;
- if (i == ARRAY_LEN(speeds)) error_exit("unknown speed: %s", TT.s);
- speed = i+1+4081*(i>15);
-
// Open with O_NDELAY, but switch back to blocking for reads.
TT.fd = xopen(*toys.optargs, O_RDWR | O_NOCTTY | O_NDELAY);
if (-1==(i = fcntl(TT.fd, F_GETFL, 0)) || fcntl(TT.fd, F_SETFL, i&~O_NDELAY))
perror_exit_raw(*toys.optargs);
// Set both input and output to raw mode.
- xraw(TT.fd, "fd", speed, &TT.original_fd_state);
- xraw(0, "stdin", 0, &TT.original_stdin_state);
+ xset_terminal(TT.fd, 1, speed, &TT.original_fd_state);
+ set_terminal(0, 1, 0, &TT.original_stdin_state);
// ...and arrange to restore things, however we may exit.
sigatexit(restore_states);
diff --git a/toys/other/hexedit.c b/toys/other/hexedit.c
index 3c5ada3a..06a96a22 100644
--- a/toys/other/hexedit.c
+++ b/toys/other/hexedit.c
@@ -132,7 +132,7 @@ void hexedit_main(void)
tty_esc("0m");
tty_esc("?25l");
fflush(0);
- xset_terminal(1, 1, 0);
+ xset_terminal(1, 1, 0, 0);
if ((TT.len = fdlength(fd))<1) error_exit("bad length");
if (sizeof(long)==32 && TT.len>SIZE_MAX) TT.len = SIZE_MAX;
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 43c4ab1b..5133b69b 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1730,7 +1730,7 @@ static void top_setup(char *defo, char *defk)
// Grab starting time, make terminal raw, switch off cursor,
// set signal handler to put terminal/cursor back to normal at exit.
TT.time = millitime();
- set_terminal(0, 1, 0);
+ set_terminal(0, 1, 0, 0);
sigatexit(tty_sigreset);
xsignal(SIGWINCH, generic_signal);
printf("\033[?25l\033[0m");