mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Added simple tx/rx statistics command (ctrl-t s)
To display the total number of bytes transmitted/received simply perform the 'ctrl-t s' command sequence. This feature can be useful when eg. trying to detect non-printable characters.
This commit is contained in:
parent
0687d7ff7b
commit
a8103b8983
3 changed files with 17 additions and 1 deletions
|
|
@ -22,9 +22,10 @@
|
|||
#ifndef TTY_H
|
||||
#define TTY_H
|
||||
|
||||
#define KEY_CTRL_T 0x14
|
||||
#define KEY_Q 0x71
|
||||
#define KEY_S 0x73
|
||||
#define KEY_T 0x74
|
||||
#define KEY_CTRL_T 0x14
|
||||
|
||||
void configure_stdout(void);
|
||||
void restore_stdout(void);
|
||||
|
|
|
|||
13
src/tty.c
13
src/tty.c
|
|
@ -40,6 +40,7 @@
|
|||
#include "tio/error.h"
|
||||
|
||||
static struct termios new_stdout, old_stdout, old_tio;
|
||||
static long rx_total = 0, tx_total = 0;
|
||||
static bool connected = false;
|
||||
static bool tainted = false;
|
||||
static int fd;
|
||||
|
|
@ -244,6 +245,9 @@ int connect_tty(void)
|
|||
/* Input from tty device ready */
|
||||
if (read(fd, &input_char, 1) > 0)
|
||||
{
|
||||
/* Update receive statistics */
|
||||
rx_total++;
|
||||
|
||||
/* Print received tty character to stdout */
|
||||
putchar(input_char);
|
||||
fflush(stdout);
|
||||
|
|
@ -253,6 +257,7 @@ int connect_tty(void)
|
|||
log_write(input_char);
|
||||
|
||||
tainted = true;
|
||||
|
||||
} else
|
||||
{
|
||||
/* Error reading - device is likely unplugged */
|
||||
|
|
@ -289,6 +294,11 @@ int connect_tty(void)
|
|||
/* Send ctrl-t key code upon ctrl-t t sequence */
|
||||
output_char = KEY_CTRL_T;
|
||||
break;
|
||||
case KEY_S:
|
||||
/* Show tx/rx statistics upon ctrl-t s sequence */
|
||||
color_printf("[tio %s] Sent %ld bytes, received %ld bytes", current_time(), tx_total, rx_total);
|
||||
forward = false;
|
||||
break;
|
||||
default:
|
||||
/* Ignore unknown ctrl-t escaped keys */
|
||||
forward = false;
|
||||
|
|
@ -306,6 +316,9 @@ int connect_tty(void)
|
|||
/* Write to log */
|
||||
if (option.log)
|
||||
log_write(output_char);
|
||||
|
||||
/* Update transmit statistics */
|
||||
tx_total++;
|
||||
}
|
||||
|
||||
/* Save previous key */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue