Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ public static String getCode(int keyCode, int keyMode, boolean cursorApp, boolea
// This is back-tab when shifted:
return (keyMode & KEYMOD_SHIFT) == 0 ? "\011" : "\033[Z";
case KEYCODE_ENTER:
// Preserve the distinction between a plain Enter and modified
// physical Enter keys for terminal applications that use LF
// as an insertion/newline action.
if ((keyMode & (KEYMOD_SHIFT | KEYMOD_CTRL)) != 0) return "\n";
return ((keyMode & KEYMOD_ALT) == 0) ? "\r" : "\033\r";

case KEYCODE_NUMPAD_ENTER:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public void testKeyCodes() {
// Return sends carriage return (\r), which normally gets translated by the device driver to newline (\n) unless the ICRNL termios
// flag has been set.
assertKeysEquals("\r", KeyHandler.getCode(KeyEvent.KEYCODE_ENTER, 0, false, false));
assertKeysEquals("\033\r", KeyHandler.getCode(KeyEvent.KEYCODE_ENTER, KeyHandler.KEYMOD_ALT, false, false));
// Modified physical Enter keys use LF so terminal applications can
// distinguish them from a plain Enter submission.
assertKeysEquals("\n", KeyHandler.getCode(KeyEvent.KEYCODE_ENTER, KeyHandler.KEYMOD_SHIFT, false, false));
assertKeysEquals("\n", KeyHandler.getCode(KeyEvent.KEYCODE_ENTER, KeyHandler.KEYMOD_CTRL, false, false));
assertKeysEquals("\n", KeyHandler.getCode(KeyEvent.KEYCODE_ENTER, KeyHandler.KEYMOD_SHIFT | KeyHandler.KEYMOD_CTRL, false, false));

// Backspace.
assertKeysEquals("\u007f", KeyHandler.getCode(KeyEvent.KEYCODE_DEL, 0, false, false));
Expand Down