mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Provide local-echo option.
Can be switched on with -e on the command line. Can be toggled with Ctrl t e while program is running.
This commit is contained in:
parent
08fd18e803
commit
dabd2130a9
6 changed files with 38 additions and 1 deletions
|
|
@ -51,6 +51,11 @@ However, if the
|
||||||
.B \-\-no\-autoconnect
|
.B \-\-no\-autoconnect
|
||||||
option is provided, tio will exit if the device is not present or an established connection is lost.
|
option is provided, tio will exit if the device is not present or an established connection is lost.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR \-e ", " "\-\-local\-echo
|
||||||
|
|
||||||
|
Enable local echo.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
.BR \-l ", " "\-\-log " \fI<filename>
|
.BR \-l ", " "\-\-log " \fI<filename>
|
||||||
|
|
||||||
|
|
@ -100,6 +105,8 @@ List available key commands
|
||||||
Send serial break (triggers SysRq on Linux, etc.)
|
Send serial break (triggers SysRq on Linux, etc.)
|
||||||
.IP "\fBctrl-t c"
|
.IP "\fBctrl-t c"
|
||||||
Show configuration (baudrate, databits, etc.)
|
Show configuration (baudrate, databits, etc.)
|
||||||
|
.IP "\fBctrl-t e"
|
||||||
|
Toggle local echo mode
|
||||||
.IP "\fBctrl-t h"
|
.IP "\fBctrl-t h"
|
||||||
Toggle hexadecimal mode
|
Toggle hexadecimal mode
|
||||||
.IP "\fBctrl-t l"
|
.IP "\fBctrl-t l"
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,10 @@ _tio()
|
||||||
COMPREPLY=( $(compgen -W "5 6 7 8" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "5 6 7 8" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-h | --local-echo)
|
||||||
|
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
-f | --flow)
|
-f | --flow)
|
||||||
COMPREPLY=( $(compgen -W "hard soft none" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "hard soft none" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ struct option_t
|
||||||
int output_delay;
|
int output_delay;
|
||||||
bool no_autoconnect;
|
bool no_autoconnect;
|
||||||
bool log;
|
bool log;
|
||||||
|
bool local_echo;
|
||||||
const char *log_filename;
|
const char *log_filename;
|
||||||
const char *map;
|
const char *map;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#define KEY_QUESTION 0x3f
|
#define KEY_QUESTION 0x3f
|
||||||
#define KEY_B 0x62
|
#define KEY_B 0x62
|
||||||
#define KEY_C 0x63
|
#define KEY_C 0x63
|
||||||
|
#define KEY_E 0x65
|
||||||
#define KEY_H 0x68
|
#define KEY_H 0x68
|
||||||
#define KEY_L 0x6C
|
#define KEY_L 0x6C
|
||||||
#define KEY_Q 0x71
|
#define KEY_Q 0x71
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ struct option_t option =
|
||||||
0, // No output delay
|
0, // No output delay
|
||||||
false, // No autoconnect
|
false, // No autoconnect
|
||||||
false, // No log
|
false, // No log
|
||||||
|
false, // No local echo
|
||||||
"", // Log filename
|
"", // Log filename
|
||||||
"" // Map string
|
"" // Map string
|
||||||
};
|
};
|
||||||
|
|
@ -61,6 +62,7 @@ void print_help(char *argv[])
|
||||||
printf(" -p, --parity odd|even|none Parity (default: none)\n");
|
printf(" -p, --parity odd|even|none Parity (default: none)\n");
|
||||||
printf(" -o, --output-delay <ms> Output delay (default: 0)\n");
|
printf(" -o, --output-delay <ms> Output delay (default: 0)\n");
|
||||||
printf(" -n, --no-autoconnect Disable automatic connect\n");
|
printf(" -n, --no-autoconnect Disable automatic connect\n");
|
||||||
|
printf(" -e, --local-echo Do local echo\n");
|
||||||
printf(" -l, --log <filename> Log to file\n");
|
printf(" -l, --log <filename> Log to file\n");
|
||||||
printf(" -m, --map <flags> Map special characters\n");
|
printf(" -m, --map <flags> Map special characters\n");
|
||||||
printf(" -v, --version Display version\n");
|
printf(" -v, --version Display version\n");
|
||||||
|
|
@ -108,6 +110,7 @@ void parse_options(int argc, char *argv[])
|
||||||
{"stopbits", required_argument, 0, 's'},
|
{"stopbits", required_argument, 0, 's'},
|
||||||
{"parity", required_argument, 0, 'p'},
|
{"parity", required_argument, 0, 'p'},
|
||||||
{"output-delay", required_argument, 0, 'o'},
|
{"output-delay", required_argument, 0, 'o'},
|
||||||
|
{"local-echo", no_argument, 0, 'e'},
|
||||||
{"no-autoconnect", no_argument, 0, 'n'},
|
{"no-autoconnect", no_argument, 0, 'n'},
|
||||||
{"log", required_argument, 0, 'l'},
|
{"log", required_argument, 0, 'l'},
|
||||||
{"map", required_argument, 0, 'm'},
|
{"map", required_argument, 0, 'm'},
|
||||||
|
|
@ -120,7 +123,7 @@ void parse_options(int argc, char *argv[])
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
|
|
||||||
/* Parse argument using getopt_long */
|
/* Parse argument using getopt_long */
|
||||||
c = getopt_long(argc, argv, "b:d:f:s:p:o:nl:m:vh", long_options, &option_index);
|
c = getopt_long(argc, argv, "b:d:f:s:p:o:nl:m:vhe", long_options, &option_index);
|
||||||
|
|
||||||
/* Detect the end of the options */
|
/* Detect the end of the options */
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
|
|
@ -146,6 +149,10 @@ void parse_options(int argc, char *argv[])
|
||||||
option.databits = string_to_long(optarg);
|
option.databits = string_to_long(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
|
option.local_echo = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
option.flow = optarg;
|
option.flow = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
17
src/tty.c
17
src/tty.c
|
|
@ -100,6 +100,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
tio_printf(" ctrl-t ? List available key commands");
|
tio_printf(" ctrl-t ? List available key commands");
|
||||||
tio_printf(" ctrl-t b Send break");
|
tio_printf(" ctrl-t b Send break");
|
||||||
tio_printf(" ctrl-t c Show configuration");
|
tio_printf(" ctrl-t c Show configuration");
|
||||||
|
tio_printf(" ctrl-t e Toggle local echo mode");
|
||||||
tio_printf(" ctrl-t h Toggle hexadecimal mode");
|
tio_printf(" ctrl-t h Toggle hexadecimal mode");
|
||||||
tio_printf(" ctrl-t l Clear screen");
|
tio_printf(" ctrl-t l Clear screen");
|
||||||
tio_printf(" ctrl-t q Quit");
|
tio_printf(" ctrl-t q Quit");
|
||||||
|
|
@ -119,6 +120,7 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
tio_printf(" Flow: %s", option.flow);
|
tio_printf(" Flow: %s", option.flow);
|
||||||
tio_printf(" Stopbits: %d", option.stopbits);
|
tio_printf(" Stopbits: %d", option.stopbits);
|
||||||
tio_printf(" Parity: %s", option.parity);
|
tio_printf(" Parity: %s", option.parity);
|
||||||
|
tio_printf(" Local Echo: %s", option.local_echo ? "yes":"no");
|
||||||
tio_printf(" Output delay: %d", option.output_delay);
|
tio_printf(" Output delay: %d", option.output_delay);
|
||||||
if (option.map[0] != 0)
|
if (option.map[0] != 0)
|
||||||
tio_printf(" Map flags: %s", option.map);
|
tio_printf(" Map flags: %s", option.map);
|
||||||
|
|
@ -126,6 +128,10 @@ void handle_command_sequence(char input_char, char previous_char, char *output_c
|
||||||
tio_printf(" Log file: %s", option.log_filename);
|
tio_printf(" Log file: %s", option.log_filename);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case KEY_E:
|
||||||
|
option.local_echo = !option.local_echo;
|
||||||
|
break;
|
||||||
|
|
||||||
case KEY_H:
|
case KEY_H:
|
||||||
/* Toggle hexadecimal printing mode */
|
/* Toggle hexadecimal printing mode */
|
||||||
if (print_mode == NORMAL)
|
if (print_mode == NORMAL)
|
||||||
|
|
@ -511,6 +517,15 @@ void tty_restore(void)
|
||||||
tty_disconnect();
|
tty_disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void optional_local_echo(char c)
|
||||||
|
{
|
||||||
|
if (!option.local_echo)
|
||||||
|
return;
|
||||||
|
print(c);
|
||||||
|
if (option.log)
|
||||||
|
log_write(c);
|
||||||
|
}
|
||||||
|
|
||||||
int tty_connect(void)
|
int tty_connect(void)
|
||||||
{
|
{
|
||||||
fd_set rdfs; /* Read file descriptor set */
|
fd_set rdfs; /* Read file descriptor set */
|
||||||
|
|
@ -657,6 +672,7 @@ int tty_connect(void)
|
||||||
if ((output_char == '\n') && (map_onlcrnl)) {
|
if ((output_char == '\n') && (map_onlcrnl)) {
|
||||||
char r = '\r';
|
char r = '\r';
|
||||||
|
|
||||||
|
optional_local_echo(r);
|
||||||
status = write(fd, &r, 1);
|
status = write(fd, &r, 1);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
warning_printf("Could not write to tty device");
|
warning_printf("Could not write to tty device");
|
||||||
|
|
@ -666,6 +682,7 @@ int tty_connect(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send output to tty device */
|
/* Send output to tty device */
|
||||||
|
optional_local_echo(output_char);
|
||||||
status = write(fd, &output_char, 1);
|
status = write(fd, &output_char, 1);
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
warning_printf("Could not write to tty device");
|
warning_printf("Could not write to tty device");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue