From 2043855a4bd540e374f172778c37364a25f24d20 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 23 May 2024 11:20:18 -0500 Subject: [PATCH] Only set speed and flush buffer when -s option supplied. --- toys/net/microcom.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/toys/net/microcom.c b/toys/net/microcom.c index 49ccde0f..a294588d 100644 --- a/toys/net/microcom.c +++ b/toys/net/microcom.c @@ -2,7 +2,7 @@ * * Copyright 2017 The Android Open Source Project. -USE_MICROCOM(NEWTOY(microcom, "<1>1s#=115200X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF)) +USE_MICROCOM(NEWTOY(microcom, "<1>1s#X", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NOBUF)) config MICROCOM bool "microcom" @@ -12,7 +12,7 @@ config MICROCOM Simple serial console. Hit CTRL-] for menu. - -s Set baud rate to SPEED (default 115200) + -s Set baud rate to SPEED -X Ignore ^] menu escape */ @@ -29,10 +29,11 @@ GLOBALS( // TODO: tty_sigreset outputs ansi escape sequences, how to disable? static void restore_states(int i) { - if (TT.stok) tcsetattr(0, TCSAFLUSH, &TT.old_stdin); - tcsetattr(TT.fd, TCSAFLUSH, &TT.old_fd); + if (TT.stok) tcsetattr(0, TCSANOW, &TT.old_stdin); + tcsetattr(TT.fd, FLAG(s)*TCSAFLUSH, &TT.old_fd); } +// TODO bookmark, jump to bottom line (if !end), clear and return afterwards static void handle_esc(void) { char input; @@ -72,6 +73,7 @@ static void handle_esc(void) fputc('\r', stderr); return; } + // TODO xsendfile with progress indicator filename = xstrdup(toybuf); size = fdlength(fd); // The alternative would be to just feed this fd into the usual loop, @@ -106,8 +108,8 @@ void microcom_main(void) // Set both input and output to raw mode. memcpy(&tio, &TT.old_fd, sizeof(struct termios)); cfmakeraw(&tio); - xsetspeed(&tio, TT.s); - if (tcsetattr(TT.fd, TCSAFLUSH, &tio)) perror_exit("set speed"); + if (FLAG(s)) xsetspeed(&tio, TT.s); + if (tcsetattr(TT.fd, FLAG(s)*TCSAFLUSH, &tio)) perror_exit("set speed"); if (!set_terminal(0, 1, 0, &TT.old_stdin)) TT.stok++; // ...and arrange to restore things, however we may exit. sigatexit(restore_states); -- 2.39.2