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
|
|
@ -63,6 +63,8 @@ Display help.
|
||||||
In session, the following key sequences are intercepted as tio commands:
|
In session, the following key sequences are intercepted as tio commands:
|
||||||
.IP "\fBctrl-t q"
|
.IP "\fBctrl-t q"
|
||||||
Quit
|
Quit
|
||||||
|
.IP "\fBctrl-t s"
|
||||||
|
Show session statistics (total number of bytes transmitted/received)
|
||||||
.IP "\fBctrl-t t"
|
.IP "\fBctrl-t t"
|
||||||
Send ctrl-t key code
|
Send ctrl-t key code
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,10 @@
|
||||||
#ifndef TTY_H
|
#ifndef TTY_H
|
||||||
#define TTY_H
|
#define TTY_H
|
||||||
|
|
||||||
#define KEY_CTRL_T 0x14
|
|
||||||
#define KEY_Q 0x71
|
#define KEY_Q 0x71
|
||||||
|
#define KEY_S 0x73
|
||||||
#define KEY_T 0x74
|
#define KEY_T 0x74
|
||||||
|
#define KEY_CTRL_T 0x14
|
||||||
|
|
||||||
void configure_stdout(void);
|
void configure_stdout(void);
|
||||||
void restore_stdout(void);
|
void restore_stdout(void);
|
||||||
|
|
|
||||||
13
src/tty.c
13
src/tty.c
|
|
@ -40,6 +40,7 @@
|
||||||
#include "tio/error.h"
|
#include "tio/error.h"
|
||||||
|
|
||||||
static struct termios new_stdout, old_stdout, old_tio;
|
static struct termios new_stdout, old_stdout, old_tio;
|
||||||
|
static long rx_total = 0, tx_total = 0;
|
||||||
static bool connected = false;
|
static bool connected = false;
|
||||||
static bool tainted = false;
|
static bool tainted = false;
|
||||||
static int fd;
|
static int fd;
|
||||||
|
|
@ -244,6 +245,9 @@ int connect_tty(void)
|
||||||
/* Input from tty device ready */
|
/* Input from tty device ready */
|
||||||
if (read(fd, &input_char, 1) > 0)
|
if (read(fd, &input_char, 1) > 0)
|
||||||
{
|
{
|
||||||
|
/* Update receive statistics */
|
||||||
|
rx_total++;
|
||||||
|
|
||||||
/* Print received tty character to stdout */
|
/* Print received tty character to stdout */
|
||||||
putchar(input_char);
|
putchar(input_char);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
@ -253,6 +257,7 @@ int connect_tty(void)
|
||||||
log_write(input_char);
|
log_write(input_char);
|
||||||
|
|
||||||
tainted = true;
|
tainted = true;
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
/* Error reading - device is likely unplugged */
|
/* Error reading - device is likely unplugged */
|
||||||
|
|
@ -289,6 +294,11 @@ int connect_tty(void)
|
||||||
/* Send ctrl-t key code upon ctrl-t t sequence */
|
/* Send ctrl-t key code upon ctrl-t t sequence */
|
||||||
output_char = KEY_CTRL_T;
|
output_char = KEY_CTRL_T;
|
||||||
break;
|
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:
|
default:
|
||||||
/* Ignore unknown ctrl-t escaped keys */
|
/* Ignore unknown ctrl-t escaped keys */
|
||||||
forward = false;
|
forward = false;
|
||||||
|
|
@ -306,6 +316,9 @@ int connect_tty(void)
|
||||||
/* Write to log */
|
/* Write to log */
|
||||||
if (option.log)
|
if (option.log)
|
||||||
log_write(output_char);
|
log_write(output_char);
|
||||||
|
|
||||||
|
/* Update transmit statistics */
|
||||||
|
tx_total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save previous key */
|
/* Save previous key */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue