xterm.dart icon indicating copy to clipboard operation
xterm.dart copied to clipboard

Backspace not working

Open silverhairs opened this issue 3 years ago • 6 comments

OS: Linux (Manjaro) Flutter version: 1.26.0-1.0.pre Dart version: 2.10.5 xterm version: 1.1.1+1

I created a brand new app and reproduced the exact code that is in the example section. The app ran but every time I try to delete a character with the backspace key, it adds an empty space char.

silverhairs avatar Feb 13 '21 02:02 silverhairs

The same happens here on a Mac (macOS Big Sur), Flutter 2.0.1 Arrow Keys (Left, Right) also don't work for me.

Not sure if this is the same "root cause" but CTRL+C is printed as ^C but has no effect

devmil avatar Mar 05 '21 21:03 devmil

On a Mac: When I don't launch the app via flutter run or the App Bundle but by executing the executable inside the script then Backspace and the Arrow keys are working.

Also interesting: The keys get transferred correctly to the shell only the output is wrong: If I type ls bb, then two times <backspace>, then -al and <enter> then it outputs the list correctly but shows garbage on the prompt.

CTRL+C doesn't work even in that case

devmil avatar Mar 09 '21 21:03 devmil

The example definitely doesn't handle backspace. It looks like there's some attempt to have backspace support, but it doesn't seem to work like I'd expect. For example, changing the handler to this:

  void _onInput(String input) {
    if (input.isEmpty) {
      return;
    }
    if (input.codeUnitAt(0) == 127) {
      terminal.buffer.backspace();
      // terminal.writeChar(127); // Doesn't work.
      return;
    }
    if (input == '\r') {
      terminal.write('\r\n');
      terminal.write('\$ ');
    } else {
      terminal.write(input);
    }
  }

~~Kind of works on the first character but not on more. I've tried messing with the setCursorX a bit but that only seems to make things worse :)~~ It seems to erase in the buffer but not on screen. Still missing something.

dnfield avatar Apr 14 '21 05:04 dnfield

This seems to do it:

    if (input.codeUnitAt(0) == 127) {
      terminal.buffer.eraseCharacters(1);
      terminal.buffer.backspace();
      terminal.refresh();
      return;
    }

dnfield avatar Apr 14 '21 07:04 dnfield

@dnfield I think your problem is a specific problem of the provided sample that is not connected to any backend.

Normally handling the backspace is done by the backend (local shell or ssh) and this results in new update commands for the terminal to reflect the new state.

There was an issue in the way the local shell is started (missing terminal type) that also led to strange behavior regarding the backspace (and other keys) which should now be fixed (not here in the example but in the studio application that uses the pty package)

I think I mixed this up as the OP seems also to refer to the sample app without backend. So 👍 for your suggestion

devmil avatar Apr 14 '21 19:04 devmil

This issue should be fixed now, right?

devmil avatar Apr 16 '21 19:04 devmil