Merge branch 'tio:master' into colorfree

This commit is contained in:
William Alexander 2022-02-08 21:21:25 +00:00 committed by GitHub
commit e83b5e9f40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 77 additions and 163 deletions

View file

@ -29,5 +29,6 @@ Björn Stenberg <bjorn@haxx.se>
Henner Zeller <h.zeller@acm.org>
Henrik Brix Andersen <henrik@brixandersen.dk>
Mariusz Midor <dexlab@o2.pl>
attila-v <attila_v@index.hu>
Thanks to everyone who has contributed to this project.

109
README
View file

@ -1,109 +0,0 @@
=== tio - a simple TTY terminal I/O application ===
1. Introduction
tio is a simple TTY terminal application which features a straightforward
commandline interface to easily connect to TTY devices for basic
input/output.
It was created because the author needed a simple no-nonsense TTY terminal
application to easily connect to various terminal TTY devices.
2. Usage
The commandline interface is straightforward as reflected in the output
from 'tio --help':
Usage: tio [<options>] <tty device>
Options:
-b, --baudrate <bps> Baud rate (default: 115200)
-d, --databits 5|6|7|8 Data bits (default: 8)
-f, --flow hard|soft|none Flow control (default: none)
-s, --stopbits 1|2 Stop bits (default: 1)
-p, --parity even|odd|none Parity (default: none)
-o, --output-delay <ms> Output delay (default: 0)
-n, --no-autoconnect Disable automatic connect
-l, --log <filename> Log to file
-m, --map <flags> Map special characters
-v, --version Display version
-h, --help Display help
In session, press ctrl-t q to quit.
The only option which requires a bit of elaboration is perhaps the
--no-autoconnect option.
By default tio automatically connects to the provided device if present.
If the device is not present, it will wait for it to appear and then
connect. If the connection is lost (eg. device is unplugged), it will wait
for the device to reappear and then reconnect. However, if the
--no-autoconnect option is provided, tio will exit if the device is not
present or an established connection is lost.
Tio features full bash autocompletion support.
Tio also supports various key commands. Press ctrl-t ? to list the
available key commands.
See the tio man page for more details.
3. Installation
The latest release version is available at https://tio.github.io
3.1 Installation using release tarball
Install steps:
$ ./configure
$ make
$ make install
See INSTALL file for more installation details.
3.2 Installation using package
Tio comes prepackaged for various GNU/Linux distributions. Visit
https://tio.github.io for package installation details.
4. Contributing
Tio is open source. All contributions (bug fixes, doc, ideas, etc.) are
welcome. Visit the tio GitHub page to access latest source code, create
pull requests, add issues etc..
GitHub: https://github.com/tio/tio
Also, if you find this free open source software useful please consider
making a donation: https://www.paypal.me/lundmar
5. Support
Submit bug reports via GitHub: https://github.com/tio/tio/issues
6. Website
Visit https://tio.github.io
7. License
Tio is GPLv2+. See COPYING file for license details.
8. Authors
Created by Martin Lund <martin.lund@keep-it-simple.com>
See the AUTHORS file for full list of authors.

View file

@ -1,24 +1,20 @@
# tio - a simple TTY terminal I/O application
# tio - a simple TTY terminal I/O tool
[![Build Status](https://travis-ci.org/tio/tio.svg?branch=master)](https://travis-ci.org/tio/tio)
[![Snap Status](https://build.snapcraft.io/badge/tio/tio.snapcraft.svg)](https://build.snapcraft.io/user/tio/tio.snapcraft)
## 1. Introduction
tio is a simple TTY terminal application which features a straightforward
commandline interface to easily connect to TTY devices for basic input/output.
It was created because the author needed a simple no-nonsense TTY terminal
application to easily connect to various terminal TTY devices.
tio is a simple TTY terminal tool which features a straightforward command-line
interface to easily connect to TTY devices for basic I/O operations.
<p align="center">
<img src="https://tio.github.io/images/tio-demo.gif">
<img src="images/tio-demo.gif">
</p>
## 2. Usage
The commandline interface is straightforward as reflected in the output from
The command-line interface is straightforward as reflected in the output from
'tio --help':
```
Usage: tio [<options>] <tty-device>
@ -32,6 +28,7 @@ The commandline interface is straightforward as reflected in the output from
-o, --output-delay <ms> Output delay (default: 0)
-n, --no-autoconnect Disable automatic connect
-e, --local-echo Do local echo
-t, --timestamp Timestamp lines
-l, --log <filename> Log to file
-m, --map <flags> Map special characters
-v, --version Display version
@ -62,9 +59,23 @@ See the tio man page for more details.
## 3. Installation
The latest release version is available at https://tio.github.io
### 3.1 Installation using package manager
tio comes prepackaged for various GNU/Linux distributions. Please consult your package manager tool to find and install tio.
### 3.1 Installation using release tarball
### 3.2 Installation using snap
Install latest stable version:
```
$ snap install tio
```
Install bleeding edge:
```
$ snap install tio --edge
```
### 3.3 Installation from source
The latest source releases can be found [here](https://github.com/tio/tio/releases).
Install steps:
```
@ -74,11 +85,6 @@ Install steps:
```
See INSTALL file for more installation details.
### 3.2 Installation using package
Tio comes prepackaged for various GNU/Linux distributions. Visit
https://tio.github.io for package installation details.
## 4. Contributing
@ -89,9 +95,9 @@ requests, add issues etc..
GitHub: https://github.com/tio/tio
Also, if you find this free open source software useful please consider making
a donation:
a donation of your choice:
[![Donate](https://www.paypal.com/en_US/i/btn/x-click-but21.gif)](https://www.paypal.me/lundmar)
[![Donate](images/paypal.png)](https://www.paypal.me/lundmar)
## 5. Support
@ -101,7 +107,7 @@ Submit bug reports via GitHub: https://github.com/tio/tio/issues
## 6. Website
Visit https://tio.github.io
Visit [tio.github.io](https://tio.github.io)
## 7. License
@ -113,4 +119,4 @@ Tio is GPLv2+. See COPYING file for license details.
Created by Martin Lund \<martin.lund@keep-it-simple.com>
See the AUTHORS file for full list of authors.
See the AUTHORS file for full list of contributors.

BIN
images/paypal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
images/tio-demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 571 KiB

View file

@ -56,6 +56,11 @@ option is provided, tio will exit if the device is not present or an established
Enable local echo.
.TP
.BR \-t ", " \-\-timestamp
Timestamp lines.
.TP
.BR \-l ", " "\-\-log " \fI<filename>

View file

@ -36,19 +36,19 @@
/* Default options */
struct option_t option =
{
"", // Device name
115200, // Baudrate
8, // Databits
"none", // Flow
1, // Stopbits
"none", // Parity
0, // No output delay
false, // No autoconnect
false, // No log
false, // No local echo
false, // No timestamp
"", // Log filename
"" // Map string
.tty_device = "",
.baudrate = 115200,
.databits = 8,
.flow = "none",
.stopbits = 1,
.parity = "none",
.output_delay = 0,
.no_autoconnect = false,
.log = false,
.local_echo = false,
.timestamp = false,
.log_filename = "",
.map = ""
};
void print_help(char *argv[])
@ -64,7 +64,7 @@ void print_help(char *argv[])
printf(" -o, --output-delay <ms> Output delay (default: 0)\n");
printf(" -n, --no-autoconnect Disable automatic connect\n");
printf(" -e, --local-echo Do local echo\n");
printf(" -t, --timestamp Prefix each new line with a timestamp\n");
printf(" -t, --timestamp Timestamp lines\n");
printf(" -l, --log <filename> Log to file\n");
printf(" -m, --map <flags> Map special characters\n");
printf(" -v, --version Display version\n");

View file

@ -22,27 +22,36 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include "tio/error.h"
#include "tio/print.h"
// "YYYY-MM-DDThh:mm:ss.sss" (ISO-8601 format).
#define TIME_STRING_SIZE 24
char * current_time(void)
{
static char time_string[20];
time_t t;
static char time_string[TIME_STRING_SIZE];
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
struct timeval tv;
gettimeofday(&tv,NULL);
tmp = localtime(&tv.tv_sec);
if (tmp == NULL)
{
error_printf("Retrieving local time failed");
exit(EXIT_FAILURE);
}
strftime(time_string, sizeof(time_string), "%H:%M:%S", tmp);
size_t len = strftime(time_string, sizeof(time_string), "%Y-%m-%dT%H:%M:%S", tmp);
if (len) {
len = snprintf(time_string + len, TIME_STRING_SIZE - len, ".%03ld", (long)tv.tv_usec / 1000);
}
return time_string;
return (len >= 0) && (len < TIME_STRING_SIZE) ? time_string : NULL;
}
void delay(long ms)

View file

@ -619,7 +619,7 @@ int tty_connect(void)
static char previous_char = 0;
static bool first = true;
int status;
time_t next_timestamp = 0;
bool next_timestamp = false;
char* now = NULL;
/* Open tty device */
@ -658,7 +658,7 @@ int tty_connect(void)
tainted = false;
if (option.timestamp)
next_timestamp = time(NULL);
next_timestamp = true;
/* Save current port settings */
if (tcgetattr(fd, &tio_old) < 0)
@ -715,19 +715,21 @@ int tty_connect(void)
if (next_timestamp && input_char != '\n' && input_char != '\r')
{
now = current_time();
fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, now);
if (option.log)
{
log_write('[');
while (*now != '\0')
if (now) {
fprintf(stdout, ANSI_COLOR_GRAY "[%s] " ANSI_COLOR_RESET, now);
if (option.log)
{
log_write(*now);
++now;
log_write('[');
while (*now != '\0')
{
log_write(*now);
++now;
}
log_write(']');
log_write(' ');
}
log_write(']');
log_write(' ');
next_timestamp = false;
}
next_timestamp = 0;
}
/* Map input character */
@ -736,7 +738,7 @@ int tty_connect(void)
print('\r');
print('\n');
if (option.timestamp)
next_timestamp = time(NULL);
next_timestamp = true;
} else
{
/* Print received tty character to stdout */
@ -751,7 +753,7 @@ int tty_connect(void)
tainted = true;
if (input_char == '\n' && option.timestamp)
next_timestamp = time(NULL);
next_timestamp = true;
} else
{
/* Error reading - device is likely unplugged */