diff --git a/AUTHORS b/AUTHORS index 509ef50..722d779 100644 --- a/AUTHORS +++ b/AUTHORS @@ -29,5 +29,6 @@ Björn Stenberg Henner Zeller Henrik Brix Andersen Mariusz Midor +attila-v Thanks to everyone who has contributed to this project. diff --git a/README b/README deleted file mode 100644 index 6e1bf12..0000000 --- a/README +++ /dev/null @@ -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: - -b, --baudrate 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 Output delay (default: 0) - -n, --no-autoconnect Disable automatic connect - -l, --log Log to file - -m, --map 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 - - See the AUTHORS file for full list of authors. diff --git a/README.md b/README.md index 02eddf2..a75052b 100644 --- a/README.md +++ b/README.md @@ -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.

- +

## 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 [] @@ -32,6 +28,7 @@ The commandline interface is straightforward as reflected in the output from -o, --output-delay Output delay (default: 0) -n, --no-autoconnect Disable automatic connect -e, --local-echo Do local echo + -t, --timestamp Timestamp lines -l, --log Log to file -m, --map 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 \ -See the AUTHORS file for full list of authors. +See the AUTHORS file for full list of contributors. diff --git a/images/paypal.png b/images/paypal.png new file mode 100644 index 0000000..00bc3e2 Binary files /dev/null and b/images/paypal.png differ diff --git a/images/tio-demo.gif b/images/tio-demo.gif new file mode 100644 index 0000000..6809d29 Binary files /dev/null and b/images/tio-demo.gif differ diff --git a/man/tio.1 b/man/tio.1 index cdb0295..d1f1e2a 100644 --- a/man/tio.1 +++ b/man/tio.1 @@ -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 diff --git a/src/options.c b/src/options.c index c88582a..aace521 100644 --- a/src/options.c +++ b/src/options.c @@ -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 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 Log to file\n"); printf(" -m, --map Map special characters\n"); printf(" -v, --version Display version\n"); diff --git a/src/time.c b/src/time.c index 68f160c..de59624 100644 --- a/src/time.c +++ b/src/time.c @@ -22,27 +22,36 @@ #include "config.h" #include #include +#include #include +#include #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) diff --git a/src/tty.c b/src/tty.c index 52eafe4..8e1190a 100644 --- a/src/tty.c +++ b/src/tty.c @@ -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 */