Skip to content

Commit

Permalink
Convert \b to 0x7f to properly handle backspace in the terminal
Browse files Browse the repository at this point in the history
Includes a new system property `org.eclipse.tm.terminal.control.convertBackspace`
to allow us to disable this new behaviour in the field if it turns out that
some terminal/host combination does not like this conversion.

Fixes eclipse-cdt#392
  • Loading branch information
jonahgraham committed Nov 14, 2023
1 parent f5754e2 commit e063b40
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions NewAndNoteworthy/CDT-11.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ The managed build GNU linker tool description now provides an option for groupin

The new option is available within managed build configurations using a _Cross GCC_, _Cygwin GCC_, _Linux GCC_ or _MinGW GCC_ toolchain.

# Terminal

## Backspace now sends `0x7f` instead of `0x08` (`\b`, `^H`)

Introduced to [fix an incompatibility on Windows](https://github.com/eclipse-cdt/cdt/issues/392) the terminal converts `^H` to ascii `0x7f` to ensure a single character is deleted rather than a whole word.

The java property `org.eclipse.tm.terminal.control.convertBackspace` can be set to `false` to disable this behavior in case it interferes with the expected behavior of the terminal.

# API Changes, current and planned

## Changes to org.eclipse.tools.templates APIs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC

private PollingTextCanvasModel fPollingTextCanvasModel;

/**
* In some circumstances (e.g PowerShell on Windows) the backspace
* character received from the keypress needs modifying. This
* system property allows disabling this new feature in case there
* are users who are negatively affected by this conversion.
*
* \b is ^H which is interpreted by the console as Ctrl + Backspace
* which deletes a word. \b on its own should just delete a character
* so we send 0x7f to do that.
*/
private boolean convertBackspace = Boolean
.parseBoolean(System.getProperty("org.eclipse.tm.terminal.control.convertBackspace", "true")); //$NON-NLS-1$ //$NON-NLS-2$

/**
* Instantiate a Terminal widget.
* @param target Callback for notifying the owner of Terminal state changes.
Expand Down Expand Up @@ -1175,6 +1188,11 @@ public void keyPressed(KeyEvent event) {
}
}

// see javadoc on convertBackspace for details
if (convertBackspace && !ctrlKeyPressed && character == '\b') {
character = 0x7f;
}

//TODO: At this point, Ctrl+M sends the same as Ctrl+Shift+M .
//This is undesired. Fixing this here might make the special Ctrl+Shift+C
//handling unnecessary further up.
Expand Down

0 comments on commit e063b40

Please sign in to comment.