-
Notifications
You must be signed in to change notification settings - Fork 747
Implementing Escape State Machine for process console and command navigations #3414
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
Conversation
…wn Arrows) according to jettr's feedback
…field, working on it
…ant for most used ANSI characters
… modified insertion and deletion inside a command
Kind reminder to review this, thanks :) |
I think this needs some more testing/debugging. Try this:
|
I tried to recreate the behaviour, but could not get some errors. Are you sure that you have tested the As said above, I tried to recreate the error, but could not get any messages or panics, maybe if you could to check that you have tested the right branch and also if you could to write some more details about the error, because I could not recreate it, thanks for feedback. |
I am testing the better-process-console branch. I am testing on an imix board. What board are you using? |
A nrf52840dk board |
What sort of machine are you using? I think this is a \r\n problem. Under Linux, an enter is just a \n. This means that tock/capsules/core/src/process_console.rs Line 1252 in a06b0da
doesn't execute. |
I think you just want to check for a newline, and then see if a \r precedes it, and if so delete that too. You don't need the either \r\n or \n\r logic. |
I am using a MacOs system, let me try to check the error on a linux virtual machine and to see if the error happens. |
Regardless, the logic at tock/capsules/core/src/process_console.rs Line 1247 in a06b0da
is incorrect. Windows/Mac send \r\n, while Linux/BSD/UNIX send \n (terminals often emulate to \r\n). A \n\r is not a valid sequence and implies something is wrong. |
Checking the \r\n or \n\r was added 16 months ago as a functionality and it was not causing any problems. However, I tried to recreate the error on a linux machine on a |
Here is the merged pull request that discusses about the \r\n and \n\r #2894. |
So I have tested on MacOs and on Linux on following boards:
I could not reproduce the error presented above. Regarding to handling Tock's master for if read_buf[0] == ('\n' as u8) || read_buf[0] == ('\r' as u8) {
if (previous_byte == ('\n' as u8) || previous_byte == ('\r' as u8)) && previous_byte != read_buf[0] {
// Reset the sequence, when \r\n is received
self.previous_byte.set(0);
if COMMAND_HISTORY_LEN > 1 {
self.command_history_index.insert(None);
self.modified_in_history.set(false);
// Clear the unfinished command if the \r\n is received
self.command_history.map(|cmd_arr| {
cmd_arr[0].clear();
});
}
} else {
self.execute.set(true);
et _ = self.write_bytes(&['\r' as u8, '\n' as u8]);
}
} Now in the second if the previous byte is reseted to Now, by pressing up and down arrows, it does not echo a self.cursor.set(next_command_len); Talking about backspace the code is checked via: if cursor > 0 {
...
self.command_index.set(index - 1);
self.cursor.set(cursor - 1);
...
} Index and cursor are both decremented and user cannot delete any character if cursor is 0, so it cannot pass to When inserting a character the
EscKey::Left if cursor > 0
EscKey::Right if cursor < index
EscKey::Home if cursor > 0
EscKey::End if cursor < index
EscKey::Delete if cursor < index So I can't see a glitch in the code as I have tested on three different boards and also on two different Operating Systems, also I have used on Linux Perhaps could you try to test the code on a different board, if it is possible, and also to give me some more details about the error, because I do not know what to change, because I cannot reproduce the error. |
Update: |
Hi, I have moved the block code that was reseting the cursor and the history to the lower block, and tested it, and for me everything works perfectly, could you please try to reproduce the error, in order to see if everything is alright? |
It works for me now! But I would recommend creating a test case of different control sequences, \r, \n, etc., and running it through the console to make sure it executes correctly. |
Do you mean unit tests, or just to run a set of commands into the console? |
I don't think a lot of unit tests is necessary. But it's clear that individual consoles don't cover every input permutation. So it would be good to have a test string that exercises a lot of cases and make sure it passes. Something as simple as a shell script that pipes a defined input (with \r, \n, \r\n, \n\r, deletes, up, left, etc.) into the process console and checks that it doesn't crash. "Works for me" or "I typed in the console" pretty clearly isn't enough coverage. |
As there are no capsules (at least that I have seen) that implement unit testing, how do you see this implemented? I looked upon the mini tutorial on implementing kernel tests here(https://book.tockos.org/development/tests.html) I also though on creating a tests module and to instantiate a Are there any links or websites in order to lookup on implementing the test cases in order to match with the tock style, or the link from |
If you have a look at We also have an automated test runner which you could use, see https://github.com/tock/tock/tree/master/tools/board-runner |
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.
Just tried this, pretty awesome!
For this particular one, I think the test case could be a script you run from your PC. E.g., erase all apps, push some input to tockloader listen, and check that the output is as expected. This means it's not a test you can run through the build system, but the machinery to do that will be significant. |
I think all we need to merge this is a simple test in the tools/ directory which when executed sends some commands to the attached board over serial and verifies it receives the correct output. |
Hi, sorry for being so late about the test, I was a bit busy with university, I will send a test this week with the script. Sorry once again |
Hi, I made a small prototype of the test using python, that opened the tockloader and then tried to push some input to stdin, however everytime I get the error "(termios.error: (25, 'Inappropriate ioctl for device'))". I tried to open a serial port directly to the board and seemed to work properly. My question is: Is it necessary to send input via the tockloader or can I develop futher the test cases via a direct serial port? |
Hi, the test script is done, written in python It opens a serial port with the board and send some input and waits for some output, then the output is compared with a predefined string. The script tests everything we discussed in this thread and adds some more testing for left, right, delete, backspace and insert in any place of the command that is currently typed. |
I've added a licence header in the file, and run the |
The error message in the
Here's my guess, which I'm fairly confident is correct:
I recommend merging master into this PR's branch locally, which I expect will merge cleanly, then re-running |
Thanks for advice! |
bors r+ |
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page.
|
Thanks
Thanks to jettr for the escape state machine code snapshot and feedback
Pull Request Overview
This pull request implements the jettr's suggestion of implementing an escape state machine (#3381 (comment)).
Also this pull request implements new features over typing experience in the
ProcessConsole
, in order to make typing more dynamic.Added features
Left
andRight
arrows in order to navigate through a typing command.Home
andEnd
commands to move at the beginning or end of a command.Delete
key to remove the character under the cursor.Flash size for IMIX binary build:
new_code + history_size
Testing Strategy
This pull request was tested on a
nrf52840dk
boardChanged Files
capsules/core/src/process_console.rs
Documentation Updated
Updated the documentation in
doc/Process_Console.md
accordingly:TODO or Help Wanted
Feedback relating to optimize the new features and how to make a better
command_history
.Formatting
make prepush
.