Avoid requesting key-release events in Ghostty (#36834)

## Why

Ghostty can leak release events for shortcuts that the terminal consumes.

## What changed

- Detect Ghostty when `TERM` is `xterm-ghostty`, including when `TERM_PROGRAM` is unavailable.
- Omit `REPORT_EVENT_TYPES` from keyboard enhancement flags for Ghostty while retaining alternate-key and escape-code disambiguation reporting.

## Testing

- Cover Ghostty detection through `TERM` and its keyboard enhancement flags.

GitOrigin-RevId: d865a6cdd1373aad4b78099e821d1ebaeb6cfdff
This commit is contained in:
Eric Traut
2026-08-04 03:44:23 +00:00
committed by copyberry
parent 8e3b5d3e87
commit db1a414569
3 changed files with 36 additions and 3 deletions

View File

@@ -150,6 +150,7 @@ impl TerminalInfo {
fn from_term(term: String, multiplexer: Option<Multiplexer>) -> Self {
let name = match term.as_str() {
"dumb" => TerminalName::Dumb,
"xterm-ghostty" => TerminalName::Ghostty,
"wezterm" | "wezterm-mux" => TerminalName::WezTerm,
_ => TerminalName::Unknown,
};
@@ -293,7 +294,7 @@ pub fn terminal_info() -> TerminalInfo {
/// - Otherwise, `TERM_PROGRAM` (plus `TERM_PROGRAM_VERSION`) drives the detected terminal name.
/// This means `TERM_PROGRAM` can mask later probes (for example `WT_SESSION`).
/// - Next, terminal-specific variables (WEZTERM, iTerm2, Apple Terminal, kitty, etc.) are checked.
/// - Finally, `TERM` is used as the capability fallback with `TerminalName::Unknown`.
/// - Finally, `TERM` is used as the capability fallback.
///
/// tmux client term info is only consulted when a tmux multiplexer is detected, and it is
/// derived from `tmux display-message` to surface the underlying terminal program instead of

View File

@@ -239,6 +239,25 @@ fn detects_ghostty() {
"Ghostty",
"ghostty_term_program_user_agent"
);
let env = FakeEnvironment::new().with_var("TERM", "xterm-ghostty");
let terminal = detect_terminal_info_from_env(&env);
assert_eq!(
terminal,
terminal_info(
TerminalName::Ghostty,
/*term_program*/ None,
/*version*/ None,
Some("xterm-ghostty"),
/*multiplexer*/ None
),
"ghostty_term_info"
);
assert_eq!(
terminal.user_agent_token(),
"xterm-ghostty",
"ghostty_term_user_agent"
);
}
#[test]