capsules: BUGFIX: backspace/delete would send an extra EOL char #3654
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request Overview
Whilst working on tockloader-rs/listen-prototype I've noticed a few peculiarities with the handling of backspace & delete. To cut a very long story short - every time backspace/delete/ANSI Delete is pressed in the process-console, an additional "null"/"end of line" byte is send. Python tockloader does not have an issue with this because its terminal emulator automatically converts it into a unicode character. The issue comes when developing for tockloader-rs where there isn't (or I haven't found) a fully-functional terminal emulator. As such, all bytes are treated as-is.
This also means null is a by out-of-place. Tock sends , which in effect should just delete the last byte. For the Unicode Null this works. For run-of-the-mill null, this doesn't work, and in fact it deletes the byte behind the . I don't know why this happens, but the same effect can be had by just sending .
Moreover, delete (ascii) was handled the same as backspace, which is confusing. ANSI Escape Sequence Delete is being handled properly (minus the null shenanigans). I've just made a logical short-circuit to make the code believe it is dealing with the escape sequence rather than a del byte.
Testing Strategy
I tested this using this branch of tockloader-rs, without the fixes implemented in the aforementioned pull request.
cargo run -- listen
Board: microbit v2
TODO or Help Wanted
The short-circuit condition to make a "DEL" char be treated the same as the escape sequence is a bit wonky. It works, but it I'd like a second opinion if we can leave it as-is or maybe extract the handling of "delete" (either) into a function or something else.
Documentation Updated
/docs
, or no updates are required.Formatting
make prepush
.