mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Cleaned up tio print mechanism
This commit is contained in:
parent
d25f90ec40
commit
7eb64748da
1 changed files with 17 additions and 20 deletions
37
src/tty.c
37
src/tty.c
|
|
@ -45,6 +45,12 @@ static bool connected = false;
|
||||||
static bool tainted = false;
|
static bool tainted = false;
|
||||||
static int fd;
|
static int fd;
|
||||||
|
|
||||||
|
#define tio_printf(format, args...) \
|
||||||
|
if (tainted) putchar('\n'); \
|
||||||
|
color_printf("[tio %s] " format, current_time(), ## args); \
|
||||||
|
tainted = false;
|
||||||
|
|
||||||
|
|
||||||
void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward)
|
void handle_command_sequence(char input_char, char previous_char, char *output_char, bool *forward)
|
||||||
{
|
{
|
||||||
char unused_char;
|
char unused_char;
|
||||||
|
|
@ -63,18 +69,15 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
switch (input_char)
|
switch (input_char)
|
||||||
{
|
{
|
||||||
case KEY_I:
|
case KEY_I:
|
||||||
if (tainted)
|
tio_printf("TTY device: %s", option.tty_device);
|
||||||
putchar('\n');
|
tio_printf("Baudrate: %d", option.baudrate);
|
||||||
color_printf("[tio %s] TTY device: %s", current_time(), option.tty_device);
|
tio_printf("Databits: %d", option.databits);
|
||||||
color_printf("[tio %s] Baudrate: %d", current_time(), option.baudrate);
|
tio_printf("Flow: %s", option.flow);
|
||||||
color_printf("[tio %s] Databits: %d", current_time(), option.databits);
|
tio_printf("Stopbits: %d", option.stopbits);
|
||||||
color_printf("[tio %s] Flow: %s", current_time(), option.flow);
|
tio_printf("Parity: %s", option.parity);
|
||||||
color_printf("[tio %s] Stopbits: %d", current_time(), option.stopbits);
|
tio_printf("Output delay: %d", option.output_delay);
|
||||||
color_printf("[tio %s] Parity: %s", current_time(), option.parity);
|
|
||||||
color_printf("[tio %s] Output delay: %d", current_time(), option.output_delay);
|
|
||||||
if (option.log)
|
if (option.log)
|
||||||
color_printf("[tio %s] Log file: %s", current_time(), option.log_filename);
|
color_printf("Log file: %s", option.log_filename);
|
||||||
tainted = false;
|
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
case KEY_Q:
|
case KEY_Q:
|
||||||
|
|
@ -86,10 +89,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
break;
|
break;
|
||||||
case KEY_S:
|
case KEY_S:
|
||||||
/* Show tx/rx statistics upon ctrl-t s sequence */
|
/* Show tx/rx statistics upon ctrl-t s sequence */
|
||||||
if (tainted)
|
tio_printf("Sent %ld bytes, received %ld bytes", tx_total, rx_total);
|
||||||
putchar('\n');
|
|
||||||
color_printf("[tio %s] Sent %ld bytes, received %ld bytes", current_time(), tx_total, rx_total);
|
|
||||||
tainted = false;
|
|
||||||
*forward = false;
|
*forward = false;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
@ -196,12 +196,9 @@ void restore_stdout(void)
|
||||||
|
|
||||||
void disconnect_tty(void)
|
void disconnect_tty(void)
|
||||||
{
|
{
|
||||||
if (tainted)
|
|
||||||
putchar('\n');
|
|
||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
color_printf("[tio %s] Disconnected", current_time());
|
tio_printf("Disconnected");
|
||||||
flock(fd, LOCK_UN);
|
flock(fd, LOCK_UN);
|
||||||
close(fd);
|
close(fd);
|
||||||
connected = false;
|
connected = false;
|
||||||
|
|
@ -253,7 +250,7 @@ int connect_tty(void)
|
||||||
tcflush(fd, TCIOFLUSH);
|
tcflush(fd, TCIOFLUSH);
|
||||||
|
|
||||||
/* Print connect status */
|
/* Print connect status */
|
||||||
color_printf("[tio %s] Connected", current_time());
|
tio_printf("Connected");
|
||||||
connected = true;
|
connected = true;
|
||||||
tainted = false;
|
tainted = false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue