Commit graph

307 commits

Author SHA1 Message Date
yabu76
c74273ecaa Add option --no-tty-restore / -N that omits tty_restore() call #334
On exit, do not reset the tty device settings to the state they were in
before the program started.
This is effective when sending characters at a low baud rate and then
immediately exiting, to ensure that the last character is output
correctly.
2025-12-31 15:14:18 +09:00
yabu76
e73ff6d208 Fix tty_write to return error code (negative value) in error case 2025-12-30 21:04:29 +09:00
yabu76
5045ca1768 Fix issue that output-delay doen't work in non-interactive mode 2025-12-30 20:58:06 +09:00
yabu76
eab0f6245b Add write_poll to improve tty_write and tty_sync
Implement blockable write with poll + nonblock write.
2025-12-30 20:19:26 +09:00
yabu76
266338a926 Add Lua REPL mode and multiline edit function in the mode.
Typing "@repl" after Ctrl-t r, enter Lua REPL mode.
Typing "@exit" in REPL mode will return you to normal mode.

Note:
- the determination of continuation lines is not done automatically, and
  if the end of a line is \, it is determined to be a continuation
  instruction.
- In REPL mode, tio's main loop is blocked. (Ctrl-t q works.)

Example:
>> t = {1,2,3,4,5}
>> for _,v in ipairs(t) do\
>>     print(v,"\r")\
>> end

Implementation improvements:
- Add tty_init() and script_interp_init() in order to only once
  initialization.
- Fix script function to work without device_fd.
2025-12-30 11:41:39 +09:00
yabu76
a9f05a66f7 Change Ctrl-t r lua funtcion to start with the previous call state
When calling the Lua interpreter with Ctrl-t r, change to start with the
previous call state.

This allows you to use it like REPL:
(example)
  Ctrl-t r : my_library.lua
  Ctrl-t r : !result1 = my_func("test1"); result2 = my_func("test2")
  Ctrl-t r : !if (result1 == result2) then print("OK") else print("NG")
  Ctrl-t r : @new

When you enter strings using Ctrl-t r, the string is interpreted as
follows:
- If the string does not begin with either "!" or "@", the string is
assumed to be the file name of a script and is executed.
- If the string begins with "!", the string excluding the "!" is
interpreted as Lua commands.
- If the string begins with "@", Strings beginning with "@" are
considered instructions to the interpreter. Currently valid instructions
are:
@new: Clear the Lua state. (== reset the Lua interpreter.)
@doopt: Execute the Lua script action specified by the option that start
with clearing the Lua state.
@nuldo=opt: do @doopt action when an empty string is entered (default).
@nuldo=none: Do nothing when an empty string is entered.

And now, lua interpreter start with GC.
If you need to stop GC, do lua function collectgarbage("stop").
2025-11-29 18:03:30 +09:00
yabu76
0983ce6eeb Add history/line-edit function to Ctrl-t command string input
Ctrl-t r/R/x/y commands require string input. To reduce the hassle of
repeatedly entering this information, I apply readline functions
(line-editing and history) to the string input.

Now tio have two histories: one for the line input-mode and one for the
ctrl-t command's string input.

And the following changes are made to the line input:
- Add prompts.
  "> ": line input-mode, ">> " Ctrl-t string input.
- Omits duplicate lines from the history.

To implement the above functionality, we will modify the readline
functions to use the multi-instance style.
2025-11-29 16:41:04 +09:00
yabu76
e62a23f320 Add option '--output-line-delay-char cr|lf' 2025-10-05 15:25:47 +09:00
yabu76
6a590bd598 Fix output-delay and input-mode line combination bug 2025-09-20 22:09:16 +09:00
yabu76
3922ce3447 Fix output-line-delay behavior
If output-line-delay is non-zero and output-delay is any, line delay
time set output-line-delay.
If output-line-delay is zero and output-delay is non-zero, line delay
time set output-delay.

It was previously (output-line-delay + output-delay) in any case.
Also, since the buffer was flushed after the line delay, there was a
possibility that the delay would be reduced or not applied at all.
2025-09-20 22:08:25 +09:00
yabu76
9784d3c277 Fix compile error in MSYS2/Cygwin 2025-08-16 18:05:56 +09:00
yabu76
e458b02771 Add Xmodem-SUM support. 2025-08-16 10:52:31 +09:00
yabu76
4aa36e6e91 Adjust code style to comply with clang-format rules 2025-08-14 13:50:58 +09:00
yabu76
102657af58 Fix XMODEM reception start failure. 2025-08-14 09:03:58 +09:00
aiotter
3af4c5591e Fix redundant output on macOS 2025-08-07 17:18:29 +02:00
Keith Barratt
9d00cd3492 Fix device description-Linux
This commit only effects Linux.

The description field of the `device_list`, populated by
`tty_search_for_serial_devices()`, was either incorrect or less than ideal
for CDC ACM virtual com ports. For instance:
    (i) Some devices incorrectly have the description field populated by
    the 'product' property of USB hub they are connected via.
    (ii) Other devices have description fields populated with the interface,
    e.g. CDC, when there is a 'product' property available that would give a
    clearer description.

To solve these issues, we first prioritise searching for the 'product' property
of the device over the 'interface' property. We also look for the
'product' property in an additional directory.
2025-05-30 17:20:06 +02:00
Maximilian Seesslen
7e61a34df3 Added timestamp format "epoch-usec"
This timestamp format will print the seconds since epoch along with
subdivision in microseconds.

Example:
 [1748009585.087083] tio v3.9-8-g2fb788f-dirty
 [1748009585.087156] Press ctrl-t q to quit
 [1748009585.087683] Connected to /dev/ttyUSB0
2025-05-23 16:36:39 +02:00
Robert Lipe
5d915134a3 Fix --auto new and --auto latest on MacOS. (redo)
Git is being dumb about
67c071633d This PR is identical to that one and will supercede it.

Fix --auto new and --auto latest on MacOS.

'device_list' was both a global (eww!) and a local inside
tty_search_for_serial_devices(). The local got set and
returned, so it looked sane, but the caller used the global
instead of the return value of the function it had just
called, meaning (global) device_list was NULL while
(ignored, local) device_list held a perfectly lovely
linked list.

Tested:
tio --auto new waits for a new device to appare and connects
tio --latest will connect to the most recently attached device
  which, in most worlds, is the most recently enumerated USB
  device, conveniently skipping all the bluetooth nonsense.
  If the lone USB device is disconnected, it then connects to
  one of those, meaning you really do have to restart tio.
2025-04-29 17:05:24 +02:00
Robert Lipe
03ef931fb2 - Implemented getPropertyString(), getDeviceLocation(), tty_search_for_serial_devices()
for MacOS
- Added error handling and memory management
- Improved code readability and consistency
- Updated coding style to match project conventions

- Added robust error checking for CoreFoundation property retrieval
- Implemented more defensive memory allocation and type checking
- Switched to using callout device key for more reliable device discovery
- Added single-line block bracing consistent with project style
- Improved comments and code formatting

- Used `kIOCalloutDeviceKey` instead of `kIODialinDeviceKey` for device path retrieval
- Enhanced type checking for CoreFoundation objects
- Simplified memory management and error handling
- Added additional logging and error reporting

- Verified functionality on MacOS 10.11 and 10.15. Tested with ESP32-P4 and ESP32-BOX

Resolves potential device discovery and memory management issues in the MacOS serial device detection code.
2025-04-24 17:55:26 +02:00
David Ordnung
c736b1e353 Input ICRCRNL mapping to avoid using INLCRNL with ICRNL 2025-04-23 08:09:22 +02:00
V
7567e08227 Disable stdout buffering globally
This makes it possible to pipe output to other programs cleanly.
2025-03-11 20:46:14 +01:00
Martin Lund
b8135ea639 Rename git version to simply version 2024-11-30 11:37:27 +01:00
Keith Hill
afd82f7ac4 + Add system timestamps to lua read() and new lua read_line() per global options
+ Add missing timestamp-format epoch
+ Update send_ to use fsync and tcdrain like normal tty_sync does
+ Rework read_line to save partial line at timeout
+ Simplified read_line to reduce cyclomatic complexity

+ renamed example files read.lua and read_line.lua
+ moved #define READ_LINE_SIZE to top of file
+ renamed g_linebuf to linebuf, and moved it into read_line as a static variable
2024-11-07 21:45:06 +01:00
Martin Lund
ab678e6c88 Use version from git 2024-10-25 19:35:13 +02:00
Martin Lund
330e99381e Fix memory leak in base62_encode() 2024-10-25 18:26:59 +02:00
Steve Marple
f47467271f Add "epoch" timestamp option
Add an option that prints the timestamp as the number of seconds since
the Unix epoch.
2024-08-24 12:35:30 +02:00
Martin Lund
ef12ed62df Remove unnecessary sync in line input mode
This caused a problem for some highly timing sensitive modem read-eval-print
loops because the input line and line termination characters (cr/nl) would be
shifted out on the UART with too big delay inbetween because of two
syncs.
2024-08-06 20:48:43 +02:00
Martin Lund
e1fe232254 Fix shadow variable 2024-07-13 18:36:03 +02:00
Heinrich Schuchardt
68a64ac554 Print correct 'Done' timestamp for X- and Y-modem transfers
Closes: #268

Call tio_printf() after completing xymodem_send().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2024-07-13 15:10:39 +02:00
Martin Lund
c3654486c7 Fix hex output mode when using normal input mode
In this combination of modes the input character was not forwarded to
the tty device. This fix makes sure it is forwarded.
2024-07-10 13:11:28 +02:00
Robert Lipe
fc0c6f61d2 Recompute listing_device_name_length_max for MacOS case, too. 2024-07-10 01:46:32 +02:00
Martin Lund
da9f7a6540 Improve warning upon failing connect
Add device path to warning when connect fails.
2024-07-09 21:06:22 +02:00
Martin Lund
2a1dae6336 Fix crashy search_reset() on macOS 2024-07-09 16:44:10 +02:00
Martin Lund
ada2db0739 Clean up shadow variable 2024-07-02 19:20:59 +02:00
Martin Lund
2c700a90b0 Code cleanup 2024-07-02 19:11:40 +02:00
Martin Lund
da04c2c444 Improve listing of long device names 2024-07-02 17:41:49 +02:00
Martin Lund
5f70b75e90 Fix listing of serial devices on macOS 2024-07-01 23:11:58 +02:00
Martin Lund
d34fa1c1ad Rename mapping flag MSB2LSB to IMSB2LSB
This is the correct naming since we are changing the input bit order on
input from the serial device.
2024-06-29 12:14:34 +02:00
Martin Lund
4723cc3f4e Add OIGNCR mapping flag
Ignores CR on output to serial device.
2024-06-27 20:09:25 +02:00
Martin Lund
8c471105fe Fix line input mode ignoring characters ABCD 2024-06-27 18:54:19 +02:00
Jakob Haufe
c5afd86b9a Fix typos 2024-06-15 17:16:23 +02:00
Martin Lund
053ae53f19 Update configuration output 2024-06-15 16:00:58 +02:00
Martin Lund
8f77ad5830 Clean up script run interaction text 2024-06-15 15:58:08 +02:00
Martin Lund
6ec2ac19d0 Add history and editing feature to line input mode
Use up and down arrow keys to navigate history.

Use left and right arrow keys to move cursor back and forth.

We try mimic the behaviour of GNU readline which we can not use because
we also need to react to key commands.
2024-06-15 14:31:23 +02:00
Martin Lund
134038c1ce Fix line input mode
Fix so that ABCD are no longer ignored.
2024-06-09 13:03:59 +02:00
Martin Lund
003b2e37d4 Make sure ICRNL, IGNCR, INLCR take effect 2024-06-02 23:35:36 +02:00
Martin Lund
8014ef68c0 Cleanup parsing of mapping flags 2024-06-02 14:26:39 +02:00
Vyacheslav Patkov
563c4fa6ea Show current mappings in the configuration printout 2024-06-02 13:22:33 +02:00
Vyacheslav Patkov
d1d6b45e8e Use "ctrl-t m" to change mappings interactively 2024-06-02 13:22:33 +02:00
Vyacheslav Patkov
f148a1413c Prompt for Lua script or shell command in interactive session 2024-06-01 16:23:51 +02:00