diff --git a/src/main.c b/src/main.c index f387292..519e8d9 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,11 @@ int main(int argc, char *argv[]) { stdin_configure(); } + else + { + // Enter non interactive mode + interactive_mode = false; + } /* Configure output terminal */ if (isatty(fileno(stdout))) @@ -85,7 +90,10 @@ int main(int argc, char *argv[]) /* Print launch hints */ tio_printf("tio v%s", VERSION); - tio_printf("Press ctrl-t q to quit"); + if (interactive_mode) + { + tio_printf("Press ctrl-t q to quit"); + } /* Open socket */ if (option.socket) @@ -94,7 +102,7 @@ int main(int argc, char *argv[]) } /* Connect to tty device */ - if (option.no_autoconnect) + if ((option.no_autoconnect) || (!interactive_mode)) { status = tty_connect(); } diff --git a/src/tty.c b/src/tty.c index 760f263..e24da9c 100644 --- a/src/tty.c +++ b/src/tty.c @@ -63,6 +63,8 @@ extern int iossiospeed(int fd, int baudrate); #define PATH_SERIAL_DEVICES "/dev/serial/by-id/" #endif +bool interactive_mode = true; + static struct termios tio, tio_old, stdout_new, stdout_old, stdin_new, stdin_old; static unsigned long rx_total = 0, tx_total = 0; static bool connected = false; @@ -855,17 +857,21 @@ int tty_connect(void) goto error_read; } - /* Forward input to output except ctrl-t key */ + /* Forward input to output */ output_char = input_char; - if (input_char == KEY_CTRL_T) - forward = false; - /* Handle commands */ - handle_command_sequence(input_char, previous_char, &output_char, &forward); + if (interactive_mode) + { + /* Do not forward ctrl-t key */ + if (input_char == KEY_CTRL_T) + forward = false; - /* Save previous key */ - previous_char = input_char; + /* Handle commands */ + handle_command_sequence(input_char, previous_char, &output_char, &forward); + /* Save previous key */ + previous_char = input_char; + } } else { diff --git a/src/tty.h b/src/tty.h index df5e824..081ba47 100644 --- a/src/tty.h +++ b/src/tty.h @@ -21,6 +21,8 @@ #pragma once +#include + #define KEY_QUESTION 0x3f #define KEY_B 0x62 #define KEY_C 0x63 @@ -48,3 +50,5 @@ void tty_configure(void); int tty_connect(void); void tty_wait_for_device(void); void list_serial_devices(void); + +extern bool interactive_mode;