Repository: alacritty/alacritty (language: rust)

Issue:
Alacritty is likely sending repeat events for Enter, Tab, and Backspace
### System

OS: Linux (gentoo)
Version: alacritty 0.14.0
Linux/BSD: GNOME Wayland

### Logs

Crashes: NONE

Font/Terminal size:
```
>> alacritty -vv
Created log file at "/tmp/Alacritty-90736.log"
[0.000004981s] [INFO ] [alacritty] Welcome to Alacritty
[0.000046713s] [INFO ] [alacritty] Version 0.14.0
[0.000052931s] [INFO ] [alacritty] Running on X11
[0.000308695s] [INFO ] [alacritty] Configuration files loade
                                     "/home/bdas/.config/ala
[0.012889230s] [INFO ] [alacritty] Using GLX 1.4
[0.020940400s] [DEBUG] [alacritty] Picked GL Config:
                                     buffer_type: Some(Rgb {
                                     alpha_size: 8
                                     num_samples: 0
                                     hardware_accelerated: t
                                     supports_transparency:
                                     config_api: Api(OPENGL
                                     srgb_capable: false
[0.022652703s] [INFO ] [alacritty] Window scale factor: 1
[0.032052349s] [DEBUG] [alacritty] Loading "Source Code Pro"
[0.039537250s] [DEBUG] [crossfont] Loaded Face Face { ft_fac
[0.044446355s] [DEBUG] [crossfont] Loaded Face Face { ft_fac
[0.048278692s] [DEBUG] [crossfont] Loaded Face Face { ft_fac
[0.052028304s] [DEBUG] [crossfont] Loaded Face Face { ft_fac
[0.053652446s] [INFO ] [alacritty] Running on llvmpipe (LLVM
[0.053659559s] [INFO ] [alacritty] OpenGL version 4.5 (Core
[0.053662232s] [INFO ] [alacritty] Using OpenGL 3.3 renderer
[0.061422875s] [DEBUG] [alacritty] Enabled debug logging for
[0.061440245s] [DEBUG] [alacritty] Filling glyph cache with
[0.063433850s] [INFO ] [alacritty] Cell size: 10 x 23
[0.063442410s] [INFO ] [alacritty] Padding: 0 x 0
[0.063446090s] [INFO ] [alacritty] Width: 800, Height: 600
[0.064444006s] [INFO ] [alacritty] PTY dimensions: 26 x 80
[0.067551722s] [INFO ] [alacritty] Initialisation complete
```

Keyboard and bindings:
```
[41.392361260s] [INFO ] [alacritty_winit_event] About to wait
[41.470384238s] [INFO ] [alacritty_winit_event] About to wait
[41.473453397s] [INFO ] [alacritty_winit_event] KeyboardInput { device_id: DeviceId(X(DeviceId(3))), event: KeyEvent { physical_key: Code(Enter), logical_key: Named(Enter), text: Some("\r"), location: Standard, state: Released, repeat: false, platform_specific: KeyEventExtra { text_with_all_modifiers: Some("\r"), key_without_modifiers: Named(Enter) } }, is_synthetic: false }
[41.473511763s] [INFO ] [alacritty_winit_event] About to wait
[43.785675712s] [INFO ] [alacritty_winit_event] CursorMoved { device_id: DeviceId(X(DeviceId(2))), position: PhysicalPosition { x: 352.0, y: 561.0 } }
[43.785761442s] [INFO ] [alacritty_winit_event] AxisMotion { device_id: DeviceId(X(DeviceId(2))), axis: 0, value: 927.0 }
[43.785776078s] [INFO ] [alacritty_winit_event] AxisMotion { device_id: DeviceId(X(DeviceId(2))), axis: 1, value: 710.0 }
[43.785829918s] [INFO ] [alacritty_winit_event] About to wait
```

[While using neovim (from master) I noticed that keys such ash Tab and backspace are being repeated.](https://github.com/neovim/neovim/issues/31806) I reported on neovim, but was asked to inform this to Alacritty developers and was guided to this https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-event-types. Can you please help.


Discussion / hints:
To clarify, Neovim recently enabled the [Report Event Types](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#report-event-types) mode of the kitty keyboard protocol. The specification indicates that unless the "Report all keys as escape codes" mode is also enabled (which it is not in this case), release events for Enter, Backspace, and Tab should not be sent. I haven't seen confirmation yet that is exactly what's happening here, but that seems to be the case.
Simple reproduction steps (from https://codeberg.org/dnkl/foot/issues/1892):

Run `printf '\x1b[>3u' && kitty +kitten show_key -m unchanged`, and press Enter, Backspace, and Tab.

In Alacritty 0.14.0 (22a44757) I get
```
$ printf '\x1b[>3u' && kitty +kitten show_key -m unchanged
Press any keys - Ctrl+D will terminate this program
UNIX		send_text
^M		\r    # this is the release event from hitting Enter to run the command
^M		\r
^M		\r
^?		\x7f
^?		\x7f
^I		\t
^I		\t
```

while in Kitty 0.38.1 I get
```
$ printf '\x1b[>3u' && kitty +kitten show_key -m unchanged
Press any keys - Ctrl+D will terminate this program
UNIX		send_text
^M		\r
^?		\x7f
^I		\t
```

Note: the above is with Num Lock off. I always have Num Lock on, in which case I get this in Alacritty:
```
$ printf '\x1b[>3u' && kitty +kitten show_key -m unchanged
Press any keys - Ctrl+D will terminate this program
UNIX		send_text
^M		\r    # this is the release event from hitting Enter to run the command
^M		\r
^M		\r
^?		\x7f
^?		\x7f
^I		\t
^I		\t
```

and in Kitty:
```
$ printf '\x1b[>3u' && kitty +kitten show_key -m unchanged
Press any keys - Ctrl+D will terminate this program
UNIX		send_text
^[[13;129:3u		\x1b[13;129:3u    # this is the release event from hitting Enter to run the command
^[[13;129u		\x1b[13;129u
^[[13;129:3u		\x1b[13;129:3u
^[[127;129u		\x1b[127;129u
^[[127;129:3u		\x1b[127;129:3u
^[[9;129u		\x1b[9;129u
^[[9;129:3u		\x1b[9;129:3u
```

The protocol docs are not clear on whether "lock" modifiers (Num Lock and Caps Lock) should stop Enter, Backspace and Tab from sending their legacy codes. But given that the reason for why those three keys are an exception in the first place is "to allow the user to type and execute commands in the shell such as reset after a program that sets this mode crashes without clearing it", I'd say Alacritty's behaviour of sending the legacy codes is more sensible. In Kitty, if an application crashes, I would have to disable Num Lock to be able to use the Backspace, Tab or Enter keys for recovery in the shell.
I am seeing the very same issue with `alacritty 0.15.0-dev`.
I remember asking about it, and got that that's how it should work, apparently not anymore...
I'd note to @gpanders if your request to some terminal results in this terminal changing spec, notifying other terminals might be not a bad idea, since I'm 99% sure that foot as well just copied behavior of kitty back in the day, the same as alacritty, since we even have a comment explaing that it's how it is, after even I tried to figure out why it was the case.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2a9efb5f735..f23f442fcce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ Notable changes to the `alacritty_terminal` crate are documented in its
 - `alacritty migrate` crashing with recursive toml imports
 - Migrating nonexistent toml import breaking the entire migration
 - First daemon mode window ignoring window options passed through CLI
+- Report of Enter/Tab/Backspace in kitty keyboard's report event types mode
 
 ## 0.14.0
 
diff --git a/alacritty/src/input/keyboard.rs b/alacritty/src/input/keyboard.rs
index 85734109db9..af9bfbb2507 100644
--- a/alacritty/src/input/keyboard.rs
+++ b/alacritty/src/input/keyboard.rs
@@ -218,20 +218,15 @@ impl<T: EventListener, A: ActionContext<T>> Processor<T, A> {
         let text = key.text_with_all_modifiers().unwrap_or_default();
         let mods = if self.alt_send_esc(&key, text) { mods } else { mods & !ModifiersState::ALT };
 
-        let bytes: Cow<'static, [u8]> = match key.logical_key.as_ref() {
-            // NOTE: Echo the key back on release to follow kitty/foot behavior. When
-            // KEYBOARD_REPORT_ALL_KEYS_AS_ESC is used, we build proper escapes for
-            // the keys below.
-            _ if mode.contains(TermMode::REPORT_ALL_KEYS_AS_ESC) => {
-                build_sequence(key, mods, mode).into()
+        let bytes = match key.logical_key.as_ref() {
+            Key::Named(NamedKey::Enter)
+            | Key::Named(NamedKey::Tab)
+            | Key::Named(NamedKey::Backspace)
+                if !mode.contains(TermMode::REPORT_ALL_KEYS_AS_ESC) =>
+            {
+                return
             },
-            // Winit uses different keys for `Backspace` so we explicitly specify the
-            // values, instead of using what was passed to us from it.
-            Key::Named(NamedKey::Tab) => [b'\t'].as_slice().into(),
-            Key::Named(NamedKey::Enter) => [b'\r'].as_slice().into(),
-            Key::Named(NamedKey::Backspace) => [b'\x7f'].as_slice().into(),
-            Key::Named(NamedKey::Escape) => [b'\x1b'].as_slice().into(),
-            _ => build_sequence(key, mods, mode).into(),
+            _ => build_sequence(key, mods, mode),
         };
 
         self.ctx.write_to_pty(bytes);


Test patch: