Skip to content
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

handle input editing #11

Open
GralfR opened this issue Mar 12, 2021 · 1 comment
Open

handle input editing #11

GralfR opened this issue Mar 12, 2021 · 1 comment

Comments

@GralfR
Copy link

GralfR commented Mar 12, 2021

With putty as client SerialCommands has problems matching commands when using backspace during input.

As an example with Debug-mode enabled enter:
1 2 3 4 [BACKSPACE] [ENTER]

The expexted input command should be "123" and SerialCommands does try to compare that. But it does not match to a command "123".
If You just enter

1 2 3 [ENTER]
without editing the input, the same command "123" is matched and the function for that command is executed.

There seams to be an additional non-printable char inside the string.

@GralfR
Copy link
Author

GralfR commented Mar 13, 2021

I think this problem only occurs when using an echo the way I did in issue #10.
So I've extended the code to enable a simple input-editing supporting:

  • [BACKSPACE] to delete the last typed character
  • [ESC] as a one-key-command anywhere while typing; could be used e.g. to cancel the input and start with an empty line with prompt written in your sketch.

Inside the SerialCommands.cpp in the ReadSerial() after
int ch = serial_->read();
I've added:

    if (isPrintable(ch)) {serial_->write(ch);} //ECHO
    switch (ch) { 
      case 8:   //Backspace
      case 127: //Backspace
        if (buffer_pos_>0) {serial_->write(ch);} //ECHO BACKSPACE
        buffer_[buffer_pos_]='\0';  //delete last char
        if (buffer_pos_-- < 0) {buffer_pos_=0;} //do not delete before start of line
        continue;
        break;
        
      case 27:  //ESC
        buffer_[0]='\e';
        if (CheckOneKeyCmd()) {return SERIAL_COMMANDS_SUCCESS;}
        break;
    }

I've also added a second buffer to store the last input in. So the last input can be recalled with the TAB-key. Because this is my second project with Arduino (I programmed AVR with assembler before) using this expansion makes it incompatible with other/public sources. So I do not like to make it public, yet, but if anybody is interested in writing a proper pull-request, please ask.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant