mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Centralize terminal capability checks in the TUI (#63802)
## What changed Use `terminal_capabilities` to select notification protocols, apply Ghostty's 255-byte notification limit, and provide the focused-window notice for notification tests. Reuse the shared tmux passthrough encoder for OSC notifications. Move program-status support checks and startup telemetry labels into the same module. ## Testing Extend the OSC 9 capability test to verify the notification body limit for each supported terminal. GitOrigin-RevId: ef3c9806dfafceba77cce3714073472224f1d173
This commit is contained in:
@@ -80,6 +80,7 @@ use crate::resume_picker::SessionSelection;
|
||||
use crate::resume_picker::SessionTarget;
|
||||
use crate::session_state::ThreadSessionState;
|
||||
use crate::startup_draft::StartupDraftPump;
|
||||
use crate::terminal_capabilities::user_agent;
|
||||
#[cfg(test)]
|
||||
use crate::test_support::PathBufExt;
|
||||
#[cfg(test)]
|
||||
@@ -159,7 +160,6 @@ use codex_protocol::openai_models::ModelPreset;
|
||||
use codex_protocol::openai_models::ModelUpgrade;
|
||||
use codex_protocol::openai_models::ReasoningEffort as ReasoningEffortConfig;
|
||||
use codex_rollout::StateDbHandle;
|
||||
use codex_terminal_detection::user_agent;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use codex_utils_approval_presets::builtin_permission_profile_for_active_permission_profile;
|
||||
use color_eyre::eyre::Result;
|
||||
|
||||
@@ -260,11 +260,11 @@ impl App {
|
||||
self.config_notification_test_pending = None;
|
||||
let notice = if !tui.notify_test("Codex notification test") {
|
||||
"Could not send test · check terminal connection"
|
||||
} else if codex_terminal_detection::terminal_info().name
|
||||
== codex_terminal_detection::TerminalName::Ghostty
|
||||
&& tui.is_terminal_focused()
|
||||
} else if tui.is_terminal_focused()
|
||||
&& let Some(notice) =
|
||||
crate::terminal_capabilities::NotificationCapabilities::detect().focused_notice
|
||||
{
|
||||
"Test sent · Ghostty hides banners while focused"
|
||||
notice
|
||||
} else {
|
||||
"Test sent · check terminal/system settings"
|
||||
};
|
||||
|
||||
@@ -1254,7 +1254,7 @@ impl ChatWidget {
|
||||
let status = self.desired_program_status();
|
||||
if let Err(err) = crate::terminal_program_status::set_terminal_program_status(
|
||||
status,
|
||||
self.iterm_session_detail(status),
|
||||
self.session_status_detail(status),
|
||||
) {
|
||||
tracing::debug!(error = %err, "failed to set terminal program status");
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn iterm_session_detail(&self, status: ProgramStatus) -> Option<&str> {
|
||||
pub(super) fn session_status_detail(&self, status: ProgramStatus) -> Option<&str> {
|
||||
(status == ProgramStatus::Working && self.bottom_pane.is_task_running())
|
||||
.then_some(self.status_state.current_status.header.as_str())
|
||||
.filter(|detail| *detail != "Working")
|
||||
|
||||
@@ -63,7 +63,7 @@ async fn session_status_follows_existing_lifecycle_state() {
|
||||
async fn session_status_detail_uses_only_foreground_activity() {
|
||||
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
|
||||
let detail =
|
||||
|chat: &ChatWidget, status| chat.iterm_session_detail(status).map(ToString::to_string);
|
||||
|chat: &ChatWidget, status| chat.session_status_detail(status).map(ToString::to_string);
|
||||
|
||||
chat.bottom_pane.set_task_running(/*running*/ true);
|
||||
let generic = detail(&chat, Working);
|
||||
|
||||
@@ -13,9 +13,9 @@ use super::ProgramStatus;
|
||||
use super::ProgramStatusKind;
|
||||
use super::SessionStatusState;
|
||||
use super::SetTerminalProgramStatus;
|
||||
use super::TerminalProgramStatusSupport;
|
||||
use super::sanitize_iterm_session_detail;
|
||||
use super::terminal_program_status_support;
|
||||
use crate::terminal_capabilities::TerminalProgramStatusSupport;
|
||||
use crate::terminal_capabilities::terminal_program_status_support;
|
||||
|
||||
#[test]
|
||||
fn encodes_iterm_session_status_fields() {
|
||||
|
||||
@@ -3,11 +3,9 @@ mod osc;
|
||||
|
||||
use std::io;
|
||||
|
||||
use crate::terminal_capabilities::NotificationCapabilities;
|
||||
use bel::BelBackend;
|
||||
use codex_config::types::NotificationMethod;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use osc::OscBackend;
|
||||
use osc::OscProtocol;
|
||||
|
||||
@@ -21,7 +19,7 @@ impl DesktopNotificationBackend {
|
||||
pub fn for_method(method: NotificationMethod) -> Self {
|
||||
match method {
|
||||
NotificationMethod::Auto => {
|
||||
if supports_osc9(&terminal_info()) {
|
||||
if NotificationCapabilities::detect().osc9 {
|
||||
Self::Osc(OscBackend::new(OscProtocol::Osc9))
|
||||
} else {
|
||||
Self::Bel(BelBackend)
|
||||
@@ -55,21 +53,10 @@ pub fn detect_backend(method: NotificationMethod) -> DesktopNotificationBackend
|
||||
DesktopNotificationBackend::for_method(method)
|
||||
}
|
||||
|
||||
fn supports_osc9(terminal: &TerminalInfo) -> bool {
|
||||
matches!(
|
||||
terminal.name,
|
||||
TerminalName::Ghostty
|
||||
| TerminalName::Iterm2
|
||||
| TerminalName::Kitty
|
||||
| TerminalName::WarpTerminal
|
||||
| TerminalName::WezTerm
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::detect_backend;
|
||||
use super::supports_osc9;
|
||||
use crate::terminal_capabilities::NotificationCapabilities;
|
||||
use codex_config::types::NotificationMethod;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
@@ -99,17 +86,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn supports_osc9_for_supported_terminals() {
|
||||
for name in [
|
||||
TerminalName::Ghostty,
|
||||
TerminalName::Iterm2,
|
||||
TerminalName::Kitty,
|
||||
TerminalName::WarpTerminal,
|
||||
TerminalName::WezTerm,
|
||||
for (name, limit) in [
|
||||
(TerminalName::Ghostty, 255),
|
||||
(TerminalName::Iterm2, usize::MAX),
|
||||
(TerminalName::Kitty, usize::MAX),
|
||||
(TerminalName::WarpTerminal, usize::MAX),
|
||||
(TerminalName::WezTerm, usize::MAX),
|
||||
] {
|
||||
assert!(
|
||||
supports_osc9(&test_terminal(name)),
|
||||
"{name:?} should support OSC 9"
|
||||
);
|
||||
let caps = NotificationCapabilities::for_terminal(&test_terminal(name));
|
||||
assert_eq!((caps.osc9, caps.max_body_bytes), (true, limit), "{name:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +112,7 @@ mod tests {
|
||||
TerminalName::WindowsTerminal,
|
||||
] {
|
||||
assert_eq!(
|
||||
supports_osc9(&test_terminal(name)),
|
||||
NotificationCapabilities::for_terminal(&test_terminal(name)).osc9,
|
||||
false,
|
||||
"{name:?} should not support OSC 9"
|
||||
);
|
||||
|
||||
@@ -4,15 +4,10 @@ use std::fmt;
|
||||
use std::io;
|
||||
use std::io::stdout;
|
||||
|
||||
use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use crate::terminal_capabilities::NotificationCapabilities;
|
||||
use crossterm::Command;
|
||||
use ratatui::crossterm::execute;
|
||||
|
||||
// Ghostty copies the parsed notification body into a 255-byte buffer.
|
||||
const GHOSTTY_BODY_BYTES: usize = 255;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) enum OscProtocol {
|
||||
Osc9,
|
||||
@@ -22,17 +17,17 @@ pub(super) enum OscProtocol {
|
||||
#[derive(Debug)]
|
||||
pub struct OscBackend {
|
||||
pub(super) protocol: OscProtocol,
|
||||
terminal_name: TerminalName,
|
||||
max_body_bytes: usize,
|
||||
dcs_passthrough: bool,
|
||||
}
|
||||
|
||||
impl OscBackend {
|
||||
pub(super) fn new(protocol: OscProtocol) -> Self {
|
||||
let terminal = terminal_info();
|
||||
let capabilities = NotificationCapabilities::detect();
|
||||
Self {
|
||||
protocol,
|
||||
terminal_name: terminal.name,
|
||||
dcs_passthrough: matches!(terminal.multiplexer, Some(Multiplexer::Tmux { .. })),
|
||||
max_body_bytes: capabilities.max_body_bytes,
|
||||
dcs_passthrough: capabilities.dcs_passthrough,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +37,7 @@ impl OscBackend {
|
||||
PostNotification {
|
||||
protocol: self.protocol,
|
||||
message,
|
||||
terminal_name: self.terminal_name,
|
||||
max_body_bytes: self.max_body_bytes,
|
||||
dcs_passthrough: self.dcs_passthrough,
|
||||
}
|
||||
)
|
||||
@@ -52,7 +47,7 @@ impl OscBackend {
|
||||
struct PostNotification<'a> {
|
||||
protocol: OscProtocol,
|
||||
message: &'a str,
|
||||
terminal_name: TerminalName,
|
||||
max_body_bytes: usize,
|
||||
dcs_passthrough: bool,
|
||||
}
|
||||
|
||||
@@ -68,8 +63,8 @@ impl Command for PostNotification<'_> {
|
||||
c => c,
|
||||
})
|
||||
.collect();
|
||||
if self.terminal_name == TerminalName::Ghostty && body.len() > GHOSTTY_BODY_BYTES {
|
||||
body.truncate(body.floor_char_boundary(GHOSTTY_BODY_BYTES - '…'.len_utf8()));
|
||||
if body.len() > self.max_body_bytes {
|
||||
body.truncate(body.floor_char_boundary(self.max_body_bytes - '…'.len_utf8()));
|
||||
body.push('…');
|
||||
}
|
||||
let sequence = match self.protocol {
|
||||
@@ -77,8 +72,7 @@ impl Command for PostNotification<'_> {
|
||||
OscProtocol::Osc777 => format!("\x1b]777;notify;Codex;{body}\x1b\\"),
|
||||
};
|
||||
if self.dcs_passthrough {
|
||||
let escaped = sequence.replace('\x1b', "\x1b\x1b");
|
||||
write!(f, "\x1bPtmux;{escaped}\x1b\\")
|
||||
f.write_str(&crate::terminal_capabilities::escaped_dcs(&sequence))
|
||||
} else {
|
||||
f.write_str(&sequence)
|
||||
}
|
||||
@@ -99,7 +93,6 @@ impl Command for PostNotification<'_> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use crossterm::Command;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
@@ -113,7 +106,7 @@ mod tests {
|
||||
let command = PostNotification {
|
||||
protocol: OscProtocol::Osc9,
|
||||
message: &message,
|
||||
terminal_name: TerminalName::Iterm2,
|
||||
max_body_bytes: usize::MAX,
|
||||
dcs_passthrough: false,
|
||||
};
|
||||
|
||||
@@ -140,7 +133,7 @@ mod tests {
|
||||
PostNotification {
|
||||
protocol,
|
||||
message: &message,
|
||||
terminal_name: TerminalName::Ghostty,
|
||||
max_body_bytes: 255,
|
||||
dcs_passthrough: false,
|
||||
}
|
||||
.write_ansi(&mut ansi)
|
||||
@@ -155,7 +148,7 @@ mod tests {
|
||||
let command = PostNotification {
|
||||
protocol: OscProtocol::Osc9,
|
||||
message: "done",
|
||||
terminal_name: TerminalName::Iterm2,
|
||||
max_body_bytes: usize::MAX,
|
||||
dcs_passthrough: true,
|
||||
};
|
||||
|
||||
@@ -172,7 +165,7 @@ mod tests {
|
||||
let command = PostNotification {
|
||||
protocol: OscProtocol::Osc9,
|
||||
message: "before\x07\x1bafter",
|
||||
terminal_name: TerminalName::Iterm2,
|
||||
max_body_bytes: usize::MAX,
|
||||
dcs_passthrough: true,
|
||||
};
|
||||
|
||||
@@ -193,7 +186,7 @@ mod tests {
|
||||
let command = PostNotification {
|
||||
protocol: OscProtocol::Osc777,
|
||||
message: "Approval requested: cargo test; git clean\x07\x1b\u{009c}-fd",
|
||||
terminal_name: TerminalName::WindowsTerminal,
|
||||
max_body_bytes: usize::MAX,
|
||||
dcs_passthrough,
|
||||
};
|
||||
let mut ansi = String::new();
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
//! configuration and app-server initialization remain responsive to safe local editing.
|
||||
|
||||
use super::*;
|
||||
use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
|
||||
pub(super) async fn run_main_inner(
|
||||
mut cli: Cli,
|
||||
@@ -782,31 +780,7 @@ pub(super) async fn run_main_inner(
|
||||
let Some(metrics) = metrics else {
|
||||
return Vec::new();
|
||||
};
|
||||
// Use a fixed category, not the versioned or user-provided terminal identifier.
|
||||
let terminal_info = codex_terminal_detection::terminal_info();
|
||||
let terminal_name = match terminal_info.name {
|
||||
TerminalName::AppleTerminal => "apple_terminal",
|
||||
TerminalName::Ghostty => "ghostty",
|
||||
TerminalName::Rex => "rex",
|
||||
TerminalName::Orca => "orca",
|
||||
TerminalName::Iterm2 => "iterm2",
|
||||
TerminalName::WarpTerminal => "warp",
|
||||
TerminalName::VsCode => "vscode",
|
||||
TerminalName::WezTerm => "wezterm",
|
||||
TerminalName::Kitty => "kitty",
|
||||
TerminalName::Alacritty => "alacritty",
|
||||
TerminalName::Konsole => "konsole",
|
||||
TerminalName::GnomeTerminal => "gnome_terminal",
|
||||
TerminalName::Vte => "vte",
|
||||
TerminalName::WindowsTerminal => "windows_terminal",
|
||||
TerminalName::Dumb => "dumb",
|
||||
TerminalName::Unknown => "unknown",
|
||||
};
|
||||
let multiplexer = match terminal_info.multiplexer {
|
||||
Some(Multiplexer::Tmux { .. }) => "tmux",
|
||||
Some(Multiplexer::Zellij { .. }) => "zellij",
|
||||
None => "none",
|
||||
};
|
||||
let (terminal_name, multiplexer) = crate::terminal_capabilities::telemetry_labels();
|
||||
launch_tags.extend([
|
||||
("app_server_mode", app_server_mode),
|
||||
("terminal_name", terminal_name),
|
||||
|
||||
@@ -12,6 +12,7 @@ mod tmux;
|
||||
mod tmux_clipboard;
|
||||
|
||||
use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalBackend;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
@@ -20,6 +21,7 @@ use std::io::IsTerminal;
|
||||
pub use codex_terminal_detection::StdoutColorLevel;
|
||||
pub use codex_terminal_detection::stdout_color_level;
|
||||
pub(crate) use codex_terminal_detection::terminal_color_level;
|
||||
pub(crate) use codex_terminal_detection::user_agent;
|
||||
pub(crate) use resize_reflow_cap::resize_reflow_max_rows;
|
||||
#[cfg(unix)]
|
||||
pub(crate) use terminal_identity::requires_inline_screen;
|
||||
@@ -314,6 +316,45 @@ pub(crate) fn detect_web_link_display() -> WebLinkDisplay {
|
||||
web_link_display(&terminal_info(), std::env::var("TERM").ok().as_deref())
|
||||
}
|
||||
|
||||
// VTE 0.54 introduced a parser that safely ignores unknown OSC sequences.
|
||||
const MIN_VTE_VERSION_WITH_SAFE_OSC: u32 = 5400;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(crate) struct TerminalProgramStatusSupport {
|
||||
pub(crate) osc_7501: bool,
|
||||
pub(crate) osc_21337: bool,
|
||||
}
|
||||
|
||||
pub(crate) fn detect_terminal_program_status_support() -> TerminalProgramStatusSupport {
|
||||
terminal_program_status_support(
|
||||
&terminal_info(),
|
||||
/*stdout_is_terminal*/ std::io::stdout().is_terminal(),
|
||||
/*screen_active*/ screen_active(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn terminal_program_status_support(
|
||||
terminal: &TerminalInfo,
|
||||
stdout_is_terminal: bool,
|
||||
screen_active: bool,
|
||||
) -> TerminalProgramStatusSupport {
|
||||
let osc_7501 = stdout_is_terminal
|
||||
&& match terminal.backend {
|
||||
Some(TerminalBackend::Vte { version }) => {
|
||||
version.is_none_or(|version| version >= MIN_VTE_VERSION_WITH_SAFE_OSC)
|
||||
}
|
||||
None => true,
|
||||
};
|
||||
let osc_21337 = osc_7501
|
||||
&& terminal.name == TerminalName::Iterm2
|
||||
&& terminal.multiplexer.is_none()
|
||||
&& !screen_active;
|
||||
TerminalProgramStatusSupport {
|
||||
osc_7501,
|
||||
osc_21337,
|
||||
}
|
||||
}
|
||||
|
||||
/// Why interactive screen control may be unavailable at launch.
|
||||
pub fn interactive_terminal_warning() -> Option<&'static str> {
|
||||
(terminal_info().name == TerminalName::Dumb).then_some("TERM is set to \"dumb\"")
|
||||
@@ -344,3 +385,63 @@ impl PointerReset {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn telemetry_labels() -> (&'static str, &'static str) {
|
||||
// Use a fixed category, not the versioned or user-provided terminal identifier.
|
||||
let terminal_info = terminal_info();
|
||||
let terminal_name = match terminal_info.name {
|
||||
TerminalName::AppleTerminal => "apple_terminal",
|
||||
TerminalName::Ghostty => "ghostty",
|
||||
TerminalName::Rex => "rex",
|
||||
TerminalName::Orca => "orca",
|
||||
TerminalName::Iterm2 => "iterm2",
|
||||
TerminalName::WarpTerminal => "warp",
|
||||
TerminalName::VsCode => "vscode",
|
||||
TerminalName::WezTerm => "wezterm",
|
||||
TerminalName::Kitty => "kitty",
|
||||
TerminalName::Alacritty => "alacritty",
|
||||
TerminalName::Konsole => "konsole",
|
||||
TerminalName::GnomeTerminal => "gnome_terminal",
|
||||
TerminalName::Vte => "vte",
|
||||
TerminalName::WindowsTerminal => "windows_terminal",
|
||||
TerminalName::Dumb => "dumb",
|
||||
TerminalName::Unknown => "unknown",
|
||||
};
|
||||
let multiplexer = match terminal_info.multiplexer {
|
||||
Some(Multiplexer::Tmux { .. }) => "tmux",
|
||||
Some(Multiplexer::Zellij { .. }) => "zellij",
|
||||
None => "none",
|
||||
};
|
||||
(terminal_name, multiplexer)
|
||||
}
|
||||
|
||||
pub(crate) struct NotificationCapabilities {
|
||||
pub(crate) osc9: bool,
|
||||
pub(crate) dcs_passthrough: bool,
|
||||
pub(crate) max_body_bytes: usize,
|
||||
pub(crate) focused_notice: Option<&'static str>,
|
||||
}
|
||||
|
||||
impl NotificationCapabilities {
|
||||
pub(crate) fn detect() -> Self {
|
||||
Self::for_terminal(&terminal_info())
|
||||
}
|
||||
|
||||
pub(crate) fn for_terminal(info: &TerminalInfo) -> Self {
|
||||
// Ghostty has a fixed notification buffer and suppresses focused banners.
|
||||
let ghostty = info.name == TerminalName::Ghostty;
|
||||
Self {
|
||||
osc9: matches!(
|
||||
info.name,
|
||||
TerminalName::Ghostty
|
||||
| TerminalName::Iterm2
|
||||
| TerminalName::Kitty
|
||||
| TerminalName::WarpTerminal
|
||||
| TerminalName::WezTerm
|
||||
),
|
||||
dcs_passthrough: matches!(info.multiplexer, Some(Multiplexer::Tmux { .. })),
|
||||
max_body_bytes: if ghostty { 255 } else { usize::MAX },
|
||||
focused_notice: ghostty.then_some("Test sent · Ghostty hides banners while focused"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,25 +5,22 @@
|
||||
//! activity text. The process-wide cache is used for exit, panic, and terminal
|
||||
//! handoff cleanup.
|
||||
|
||||
use crate::terminal_capabilities::TerminalProgramStatusSupport;
|
||||
use crate::terminal_capabilities::detect_terminal_program_status_support;
|
||||
use crossterm::Command;
|
||||
use ratatui::crossterm::execute;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::io::IsTerminal;
|
||||
use std::io::stdout;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use codex_terminal_detection::TerminalBackend;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use crossterm::Command;
|
||||
use ratatui::crossterm::execute;
|
||||
|
||||
static SESSION_STATUS_STATE: SessionStatusState = SessionStatusState::new();
|
||||
static TERMINAL_PROGRAM_STATUS_SUPPORT: OnceLock<TerminalProgramStatusSupport> = OnceLock::new();
|
||||
|
||||
// VTE 0.54 introduced a parser that safely ignores unknown OSC sequences.
|
||||
const MIN_VTE_VERSION_WITH_SAFE_OSC: u32 = 5400;
|
||||
fn current_terminal_program_status_support() -> TerminalProgramStatusSupport {
|
||||
*TERMINAL_PROGRAM_STATUS_SUPPORT.get_or_init(detect_terminal_program_status_support)
|
||||
}
|
||||
|
||||
struct SessionStatusState {
|
||||
last_emitted: Mutex<EmittedSessionStatus>,
|
||||
@@ -83,12 +80,6 @@ impl SessionStatusState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
struct TerminalProgramStatusSupport {
|
||||
osc_7501: bool,
|
||||
osc_21337: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub(crate) enum ProgramStatus {
|
||||
Idle,
|
||||
@@ -206,38 +197,6 @@ fn sanitize_iterm_session_detail(detail: &str) -> String {
|
||||
escaped
|
||||
}
|
||||
|
||||
fn current_terminal_program_status_support() -> TerminalProgramStatusSupport {
|
||||
*TERMINAL_PROGRAM_STATUS_SUPPORT.get_or_init(|| {
|
||||
terminal_program_status_support(
|
||||
&terminal_info(),
|
||||
/*stdout_is_terminal*/ stdout().is_terminal(),
|
||||
/*screen_active*/ std::env::var_os("STY").is_some(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn terminal_program_status_support(
|
||||
terminal: &TerminalInfo,
|
||||
stdout_is_terminal: bool,
|
||||
screen_active: bool,
|
||||
) -> TerminalProgramStatusSupport {
|
||||
let osc_7501 = stdout_is_terminal
|
||||
&& match terminal.backend {
|
||||
Some(TerminalBackend::Vte { version }) => {
|
||||
version.is_none_or(|version| version >= MIN_VTE_VERSION_WITH_SAFE_OSC)
|
||||
}
|
||||
None => true,
|
||||
};
|
||||
let osc_21337 = osc_7501
|
||||
&& terminal.name == TerminalName::Iterm2
|
||||
&& terminal.multiplexer.is_none()
|
||||
&& !screen_active;
|
||||
TerminalProgramStatusSupport {
|
||||
osc_7501,
|
||||
osc_21337,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct SetTerminalProgramStatus<'a> {
|
||||
status: ProgramStatus,
|
||||
|
||||
Reference in New Issue
Block a user