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.
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.
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").
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.
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.
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.
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
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.
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.
+ 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
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.
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.