xterm.dart
xterm.dart copied to clipboard
Backspace not working
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.
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
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
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.
This seems to do it:
if (input.codeUnitAt(0) == 127) {
terminal.buffer.eraseCharacters(1);
terminal.buffer.backspace();
terminal.refresh();
return;
}
@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
This issue should be fixed now, right?