-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys/shell: ensure character is flushed when echoing. #10630
Conversation
64900f8
to
7f2b138
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and now the echo works, also erasing characters.
@@ -44,6 +44,12 @@ static void _putchar(int c) { | |||
#endif | |||
#endif | |||
|
|||
#ifdef MODULE_NEWLIB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not defining this in the _putchar function if it is only needed with newlib?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't need to flush after every character. I do think, however, that it would be better if stdio was in unbuffered mode: it fits better with the HW.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix was long overdue. thx!
Please remove the macro though.
7f2b138
to
b34dc3a
Compare
When using a serial terminal without local echo, the current line would not get updated as the user typed because the shell module's readline() was not flushing each character. This commit fixes that behavior. For additional clarity, fflush is turned into a macro (flush_if_needed) which expands to either a call to fflush() or empty, according to the standard library used. This also fixes the erase/line editing behavior (the delete characters were not being flushed either.)
I force pushed the fix (no point in a fixup commit) |
@kaspar030 Is it good to go? |
Let me do some tests |
Tested with pyterm on nucleo-l476rg and it seems good. |
|
I tested on nrf52dk using pyterm and picocom. I was curious if any tests might break when there's a possible double echo, but it seems fine. Let's also run the CI tests on samr21. |
maybe quickly add a change request, so noone gets trigger happy? |
At least on the samr21-xpro all tests succeeded. |
mmm, weird. In any case, it should not be affected by this change. Is it a thing with the terminal or with RIOT? To be sure the terminal is not messing things up, I always test with:
|
I used your miniterm setup
sorry 127 bytes, I guess it gets full, I can't delete or press enter. It doesn't crash... Ideally it would discard the last byte and evaluate the new one. I don't think it is part of this PR though. |
@MrKevinWeiss see #10639 . |
I am not sending at once, these are just typed characters (at the speed of me). |
Contribution description
When using a serial terminal without local echo, the current line would not get updated as the user typed because the shell module's readline() was not flushing each character.
This commit fixes that behavior. For additional clarity, fflush is turned into a macro (flush_if_needed) which expands to either a call to fflush() or empty, according to the standard library used.
This also fixes the erase/line editing behavior (the delete characters were not being flushed either.)
Testing procedure
Test that the shell is not broken by running
To test echo, I used miniterm.py (from pyserial) but any terminal with raw mode and no local echo should do:
Type a command. I used the 'test/shell' application.
Without this patch: you won't see anything on the screen until you type enter.
With this patch: you will see characters show up as you type. If you press backspace you will see the characters disappear too.
References
Mentioned by @neiljay in the mailing list some months ago: https://lists.riot-os.org/pipermail/devel/2018-July/005823.html