mirror of
https://github.com/tio/tio.git
synced 2026-05-01 23:07:58 +02:00
Merge branch 'master' into bug/92-fflush
This commit is contained in:
commit
50e33a1a5b
3 changed files with 80 additions and 1 deletions
|
|
@ -117,6 +117,12 @@ Quit
|
||||||
Show TX/RX statistics
|
Show TX/RX statistics
|
||||||
.IP "\fBctrl-t t"
|
.IP "\fBctrl-t t"
|
||||||
Send ctrl-t key code
|
Send ctrl-t key code
|
||||||
|
.IP "\fBctrl-t L"
|
||||||
|
Show lines state (DTR, RTS, CTS, DSR, DCD, RI)
|
||||||
|
.IP "\fBctrl-t d"
|
||||||
|
Toggle DTR
|
||||||
|
.IP "\fBctrl-t r"
|
||||||
|
Toggle RTS
|
||||||
.IP "\fBctrl-t v"
|
.IP "\fBctrl-t v"
|
||||||
Show version
|
Show version
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@
|
||||||
#define KEY_SHIFT_T 0x54
|
#define KEY_SHIFT_T 0x54
|
||||||
#define KEY_CTRL_T 0x14
|
#define KEY_CTRL_T 0x14
|
||||||
#define KEY_V 0x76
|
#define KEY_V 0x76
|
||||||
|
#define KEY_D 0x64
|
||||||
|
#define KEY_R 0x72
|
||||||
|
#define KEY_SHIFT_L 0x4C
|
||||||
|
|
||||||
#define NORMAL 0
|
#define NORMAL 0
|
||||||
#define HEX 1
|
#define HEX 1
|
||||||
|
|
|
||||||
72
src/tty.c
72
src/tty.c
|
|
@ -30,6 +30,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/file.h>
|
#include <sys/file.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
@ -79,10 +80,36 @@ static void print_normal(char c)
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void toggle_line(const char *line_name, int mask)
|
||||||
|
{
|
||||||
|
int state;
|
||||||
|
|
||||||
|
if (ioctl(fd, TIOCMGET, &state) < 0)
|
||||||
|
{
|
||||||
|
error_printf("Could not get line state: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (state & mask)
|
||||||
|
{
|
||||||
|
state &= ~mask;
|
||||||
|
tio_printf("set %s to LOW", line_name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
state |= mask;
|
||||||
|
tio_printf("set %s to HIGH", line_name);
|
||||||
|
}
|
||||||
|
if (ioctl(fd, TIOCMSET, &state) < 0)
|
||||||
|
error_printf("Could not set line state: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
bool unused_bool;
|
bool unused_bool;
|
||||||
|
int state;
|
||||||
|
|
||||||
/* Ignore unused arguments */
|
/* Ignore unused arguments */
|
||||||
if (output_char == NULL)
|
if (output_char == NULL)
|
||||||
|
|
@ -111,9 +138,34 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
tio_printf(" ctrl-t s Show statistics");
|
tio_printf(" ctrl-t s Show statistics");
|
||||||
tio_printf(" ctrl-t t Send ctrl-t key code");
|
tio_printf(" ctrl-t t Send ctrl-t key code");
|
||||||
tio_printf(" ctrl-t T Toggle timestamps");
|
tio_printf(" ctrl-t T Toggle timestamps");
|
||||||
|
tio_printf(" ctrl-t L Show lines");
|
||||||
|
tio_printf(" ctrl-t d Toggle DTR");
|
||||||
|
tio_printf(" ctrl-t r Toggle RTS");
|
||||||
tio_printf(" ctrl-t v Show version");
|
tio_printf(" ctrl-t v Show version");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEY_SHIFT_L:
|
||||||
|
if (ioctl(fd, TIOCMGET, &state) < 0)
|
||||||
|
{
|
||||||
|
error_printf("Could not get line state: %s", strerror(errno));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
tio_printf("Lines state:");
|
||||||
|
tio_printf(" DTR: %s", (state & TIOCM_DTR) ? "HIGH" : "LOW");
|
||||||
|
tio_printf(" RTS: %s", (state & TIOCM_RTS) ? "HIGH" : "LOW");
|
||||||
|
tio_printf(" CTS: %s", (state & TIOCM_CTS) ? "HIGH" : "LOW");
|
||||||
|
tio_printf(" DSR: %s", (state & TIOCM_DSR) ? "HIGH" : "LOW");
|
||||||
|
tio_printf(" DCD: %s", (state & TIOCM_CD) ? "HIGH" : "LOW");
|
||||||
|
tio_printf(" RI : %s", (state & TIOCM_RI) ? "HIGH" : "LOW");
|
||||||
|
break;
|
||||||
|
case KEY_D:
|
||||||
|
toggle_line("DTR", TIOCM_DTR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case KEY_R:
|
||||||
|
toggle_line("RTS", TIOCM_RTS);
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_B:
|
case KEY_B:
|
||||||
tcsendbreak(fd, 0);
|
tcsendbreak(fd, 0);
|
||||||
break;
|
break;
|
||||||
|
|
@ -236,6 +288,10 @@ void stdout_configure(void)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
|
/* Disable line buffering in stdout. This is necessary if we
|
||||||
|
* want things like local echo to work correctly. */
|
||||||
|
setbuf(stdout, NULL);
|
||||||
|
|
||||||
/* Save current stdout settings */
|
/* Save current stdout settings */
|
||||||
if (tcgetattr(STDOUT_FILENO, &stdout_old) < 0)
|
if (tcgetattr(STDOUT_FILENO, &stdout_old) < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -537,6 +593,7 @@ static void optional_local_echo(char c)
|
||||||
if (!option.local_echo)
|
if (!option.local_echo)
|
||||||
return;
|
return;
|
||||||
print(c);
|
print(c);
|
||||||
|
fflush(stdout);
|
||||||
if (option.log)
|
if (option.log)
|
||||||
log_write(c);
|
log_write(c);
|
||||||
}
|
}
|
||||||
|
|
@ -550,6 +607,7 @@ int tty_connect(void)
|
||||||
static bool first = true;
|
static bool first = true;
|
||||||
int status;
|
int status;
|
||||||
time_t next_timestamp = 0;
|
time_t next_timestamp = 0;
|
||||||
|
char* now = NULL;
|
||||||
|
|
||||||
/* Open tty device */
|
/* Open tty device */
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
|
|
@ -643,7 +701,19 @@ int tty_connect(void)
|
||||||
/* Print timestamp on new line, if desired. */
|
/* Print timestamp on new line, if desired. */
|
||||||
if (next_timestamp && input_char != '\n' && input_char != '\r')
|
if (next_timestamp && input_char != '\n' && input_char != '\r')
|
||||||
{
|
{
|
||||||
fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, current_time());
|
now = current_time();
|
||||||
|
fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, now);
|
||||||
|
if (option.log)
|
||||||
|
{
|
||||||
|
log_write('[');
|
||||||
|
while (*now != '\0')
|
||||||
|
{
|
||||||
|
log_write(*now);
|
||||||
|
++now;
|
||||||
|
}
|
||||||
|
log_write(']');
|
||||||
|
log_write(' ');
|
||||||
|
}
|
||||||
next_timestamp = 0;
|
next_timestamp = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue