Currently, when the prompt is read in `pyterm` the space after it is
ignored for the prompt and the output command just adds its own prompt.
This leads to the next output always having a leading space, see e.g.
this output from `tests/shell` using `RIOT_TERMINAL=pyterm`:
```
make: Entering directory '/home/mlenders/Repositories/RIOT-OS/RIOT2/tests/shell'
/home/mlenders/Repositories/RIOT-OS/RIOT2/dist/tools/pyterm/pyterm -p "/dev/ttyUSB1" -b "500000"
Twisted not available, please install it if you want to use pyterm's JSON capabilities
2021-02-09 14:47:15,071 # Connect to serial port /dev/ttyUSB1
Welcome to pyterm!
Type '/exit' to exit.
bufsize
2021-02-09 14:47:19,712 # bufsize
2021-02-09 14:47:19,712 # 128
> bufsize
2021-02-09 14:47:21,535 # bufsize
2021-02-09 14:47:21,536 # 128
>
```
While this isn't necessarily a problem in most cases, it becomes a
problem when the prompt is expected and the output of a command is
empty. In that case, the space is added to the empty output, making it
" ", so the prompt output command is never triggered and the prompt is
added to the next command in the log output. To demonstrate I added a
command `empty` to `tests/shell` that just does nothing and deactivated
the command echoing using `CFLAGS=-DCONFIG_SHELL_NO_ECHO=1`:
```
empty
> empty
empty
bufsize
2021-02-09 14:54:33,753 # > > 128
>
```
This fixes that problem by also reading the assumed space (we already
assume the prompt, so I don't see no harm in that) and if it is not a
space to skip the reading of the next char in the next iteration of the
reader loop.
The init_cmd feature is quite handy for automated pyterm runs but there
is no delay between the commands that are executed.
This adds a /sleep function that can be added between init_cmd commands
to prevent them from overflowing the RX buffer on the target.
Python3 has been the default in our scripts for some time now, but pyterm still
requested python which uses python2 on ubuntu stable.
This pushes toward only needing to install `python3` python
dependencies.
When installing the `serial` package (in contrast to `pyserial`)
the pyterm script will print a cryptic error message and fail.
This is because both packages, though unrelated, expose a `serial`
package (whereas pyserial should expose `pyserial`).
This change catches the error and might save some precious lifetime
of unsuspecting RIOT users, such as myself.
The default behaviour only appreciates the LF character (unix style).
The pyterm switch -nl/--newline can be used to specify the newline combination of CR/NL.
Possible values are CR, NL, CRNL and NLCR. Default is NL.
For the MSB-A2 the DTR and RTS pins have to be pulled down over the
serial interface in the beginning. (This is required because the Linux
usbserial driver pulls them up when initializing the device which set
the node into reset mode.) Since this is not necessary on most other
platforms and might even cause problems, it's better to make this an
optional behavior of pyterm.