mirror of
https://github.com/openai/codex.git
synced 2026-11-25 23:30:49 +00:00
Consolidate terminal capabilities in the TUI (#63789)
## What changed Group terminal probing and identity, keyboard modes, resize reflow, and tmux settings and clipboard forwarding under `terminal_capabilities`. Move pet image protocol detection and its tests into the same module tree. GitOrigin-RevId: 6d77b980982f6ea160b6d947760f04749352d94e
This commit is contained in:
@@ -21,7 +21,6 @@
|
||||
//! Image paste lives in `clipboard_paste`.
|
||||
|
||||
pub(crate) mod primary;
|
||||
mod tmux;
|
||||
pub(crate) mod worker;
|
||||
mod wsl;
|
||||
|
||||
@@ -29,10 +28,10 @@ use crate::terminal_capabilities::ClipboardCapabilities;
|
||||
use crate::terminal_capabilities::ClipboardCopyMode;
|
||||
pub(crate) use crate::terminal_capabilities::is_ssh_session;
|
||||
use crate::terminal_capabilities::is_tmux_session;
|
||||
use crate::terminal_capabilities::tmux_clipboard::copy as tmux_clipboard_copy;
|
||||
use base64::Engine;
|
||||
use std::io::Write;
|
||||
use std::sync::Arc;
|
||||
use tmux::copy as tmux_clipboard_copy;
|
||||
|
||||
/// Maximum raw bytes sent through tmux or directly encoded into OSC 52.
|
||||
/// Large payloads are rejected before encoding to avoid overwhelming the terminal.
|
||||
|
||||
@@ -207,7 +207,7 @@ mod pager_overlay;
|
||||
mod projectless;
|
||||
pub(crate) mod public_widgets;
|
||||
mod render;
|
||||
mod resize_reflow_cap;
|
||||
use terminal_capabilities::resize_reflow_cap;
|
||||
mod resume_permissions;
|
||||
mod resume_picker;
|
||||
mod screen_reader;
|
||||
@@ -246,7 +246,7 @@ mod temporary_structured_request;
|
||||
mod terminal_capabilities;
|
||||
mod terminal_hyperlinks;
|
||||
mod terminal_palette;
|
||||
mod terminal_probe;
|
||||
use terminal_capabilities::terminal_probe;
|
||||
mod terminal_size_telemetry;
|
||||
mod terminal_title;
|
||||
mod terminal_visualization_instructions;
|
||||
|
||||
@@ -10,10 +10,6 @@ use anyhow::Result;
|
||||
use anyhow::bail;
|
||||
use base64::Engine as _;
|
||||
use base64::engine::general_purpose;
|
||||
use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use crossterm::cursor::MoveTo;
|
||||
use crossterm::queue;
|
||||
use image::imageops::FilterType;
|
||||
@@ -25,66 +21,11 @@ const ESC: &str = "\x1b";
|
||||
const ST: &str = "\x1b\\";
|
||||
const KITTY_CHUNK_SIZE: usize = 4096;
|
||||
const SIXEL_CACHE_VERSION: &str = "v2";
|
||||
const ITERM2_KITTY_MIN_VERSION: (u64, u64, u64) = (3, 6, 0);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ImageProtocol {
|
||||
Kitty,
|
||||
KittyLocalFile,
|
||||
Sixel,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum PetImageSupport {
|
||||
Supported(ImageProtocol),
|
||||
Unsupported(PetImageUnsupportedReason),
|
||||
}
|
||||
|
||||
impl PetImageSupport {
|
||||
pub(crate) fn protocol(self) -> Option<ImageProtocol> {
|
||||
match self {
|
||||
Self::Supported(protocol) => Some(protocol),
|
||||
Self::Unsupported(PetImageUnsupportedReason::Tmux) => {
|
||||
crate::tui::tmux_fullscreen_image_base().map(|_| ImageProtocol::Kitty)
|
||||
}
|
||||
Self::Unsupported(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn unsupported_message(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::Supported(_) => None,
|
||||
Self::Unsupported(reason) => self.protocol().is_none().then(|| reason.message()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum PetImageUnsupportedReason {
|
||||
Tmux,
|
||||
Zellij,
|
||||
Iterm2TooOld,
|
||||
Terminal,
|
||||
}
|
||||
|
||||
impl PetImageUnsupportedReason {
|
||||
fn message(self) -> &'static str {
|
||||
match self {
|
||||
Self::Tmux => {
|
||||
"Pets are unavailable in this tmux pane. Use fullscreen Codex with allow-passthrough all, or run Codex outside tmux."
|
||||
}
|
||||
Self::Zellij => {
|
||||
"Pets are disabled in Zellij. Terminal images don’t stay reliably pane-local in Zellij. Run Codex outside Zellij to use pets."
|
||||
}
|
||||
Self::Iterm2TooOld => {
|
||||
"Pets require iTerm2 3.6 or newer. Upgrade iTerm2 to use terminal pets."
|
||||
}
|
||||
Self::Terminal => {
|
||||
"Pets aren’t available in this terminal. Terminal pets need image support, and this terminal environment doesn’t expose a supported image protocol. Try a terminal with Kitty graphics or Sixel support, or run Codex outside tmux."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub(crate) use crate::terminal_capabilities::images::ImageProtocol;
|
||||
pub(crate) use crate::terminal_capabilities::images::PetImageSupport;
|
||||
#[cfg(test)]
|
||||
pub(crate) use crate::terminal_capabilities::images::PetImageUnsupportedReason;
|
||||
pub(crate) use crate::terminal_capabilities::images::detect_pet_image_support;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ProtocolSelection {
|
||||
@@ -116,144 +57,6 @@ impl FromStr for ProtocolSelection {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn detect_pet_image_support() -> PetImageSupport {
|
||||
if env::var_os("TMUX").is_some() || env::var_os("TMUX_PANE").is_some() {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux);
|
||||
}
|
||||
|
||||
if env::var_os("ZELLIJ").is_some()
|
||||
|| env::var_os("ZELLIJ_SESSION_NAME").is_some()
|
||||
|| env::var_os("ZELLIJ_VERSION").is_some()
|
||||
{
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij);
|
||||
}
|
||||
|
||||
image_support_for_terminal_environment(&terminal_info())
|
||||
}
|
||||
|
||||
fn image_support_for_terminal_environment(info: &TerminalInfo) -> PetImageSupport {
|
||||
if info.name == TerminalName::Orca {
|
||||
return if supports_orca_kitty_graphics(
|
||||
info,
|
||||
env::var("ORCA_IMAGE_PROTOCOL").ok().as_deref(),
|
||||
env::var("TERM").ok().as_deref(),
|
||||
/*sty_present*/ env::var_os("STY").is_some(),
|
||||
) {
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
} else {
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
};
|
||||
}
|
||||
|
||||
if env::var_os("KITTY_WINDOW_ID").is_some() {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
if env::var_os("WEZTERM_EXECUTABLE").is_some() || env::var_os("WEZTERM_VERSION").is_some() {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
pet_image_support_for_terminal(info)
|
||||
}
|
||||
|
||||
fn supports_orca_kitty_graphics(
|
||||
info: &TerminalInfo,
|
||||
protocol: Option<&str>,
|
||||
term: Option<&str>,
|
||||
sty_present: bool,
|
||||
) -> bool {
|
||||
info.multiplexer.is_none()
|
||||
&& protocol == Some("kitty")
|
||||
&& !sty_present
|
||||
&& !term.is_some_and(|term| {
|
||||
term == "dumb" || term.starts_with("screen") || term.starts_with("tmux")
|
||||
})
|
||||
}
|
||||
|
||||
fn pet_image_support_for_terminal(info: &TerminalInfo) -> PetImageSupport {
|
||||
match info.multiplexer {
|
||||
Some(Multiplexer::Tmux { .. }) => {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux);
|
||||
}
|
||||
Some(Multiplexer::Zellij { .. }) => {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
if supports_iterm2_kitty_graphics(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::KittyLocalFile);
|
||||
}
|
||||
|
||||
if is_iterm2_terminal(info) {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld);
|
||||
}
|
||||
|
||||
if supports_kitty_graphics(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
if supports_sixel(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::Sixel);
|
||||
}
|
||||
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
}
|
||||
|
||||
fn supports_iterm2_kitty_graphics(info: &TerminalInfo) -> bool {
|
||||
is_iterm2_terminal(info)
|
||||
&& version_is_at_least(
|
||||
info.version.as_deref(),
|
||||
/*minimum*/ ITERM2_KITTY_MIN_VERSION,
|
||||
)
|
||||
}
|
||||
|
||||
fn is_iterm2_terminal(info: &TerminalInfo) -> bool {
|
||||
matches!(info.name, TerminalName::Iterm2)
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "iterm")
|
||||
}
|
||||
|
||||
fn supports_kitty_graphics(info: &TerminalInfo) -> bool {
|
||||
matches!(
|
||||
info.name,
|
||||
TerminalName::Ghostty | TerminalName::Kitty | TerminalName::Rex | TerminalName::WezTerm
|
||||
) || terminal_field_contains(info.term.as_deref(), "kitty")
|
||||
|| terminal_field_contains(info.term.as_deref(), "ghostty")
|
||||
|| terminal_field_contains(info.term.as_deref(), "wezterm")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "kitty")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "ghostty")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "wezterm")
|
||||
}
|
||||
|
||||
fn supports_sixel(info: &TerminalInfo) -> bool {
|
||||
matches!(info.name, TerminalName::WindowsTerminal)
|
||||
|| terminal_field_contains(info.term.as_deref(), "sixel")
|
||||
|| terminal_field_contains(info.term.as_deref(), "mlterm")
|
||||
|| terminal_field_contains(info.term.as_deref(), "foot")
|
||||
}
|
||||
|
||||
fn terminal_field_contains(value: Option<&str>, needle: &str) -> bool {
|
||||
value.is_some_and(|value| value.to_ascii_lowercase().contains(needle))
|
||||
}
|
||||
|
||||
fn version_is_at_least(version: Option<&str>, minimum: (u64, u64, u64)) -> bool {
|
||||
parse_dotted_version(version).is_some_and(|version| version >= minimum)
|
||||
}
|
||||
|
||||
fn parse_dotted_version(version: Option<&str>) -> Option<(u64, u64, u64)> {
|
||||
let version = version?;
|
||||
let mut parts = version.split('.');
|
||||
let major = parts.next()?.parse().ok()?;
|
||||
let minor = parts.next().unwrap_or("0").parse().ok()?;
|
||||
let patch = parts.next().unwrap_or("0").parse().ok()?;
|
||||
|
||||
if parts.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((major, minor, patch))
|
||||
}
|
||||
|
||||
pub fn kitty_delete_image(image_id: u32) -> String {
|
||||
wrap_for_tmux_if_needed(&format!("{ESC}_Ga=d,d=I,i={image_id},q=2;{ST}"))
|
||||
}
|
||||
@@ -395,30 +198,7 @@ mod tests {
|
||||
|
||||
use super::*;
|
||||
|
||||
struct EnvVarGuard {
|
||||
name: &'static str,
|
||||
previous: Option<std::ffi::OsString>,
|
||||
}
|
||||
|
||||
impl EnvVarGuard {
|
||||
fn new(name: &'static str, value: Option<&str>) -> Self {
|
||||
let previous = env::var_os(name);
|
||||
match value {
|
||||
Some(value) => unsafe { env::set_var(name, value) },
|
||||
None => unsafe { env::remove_var(name) },
|
||||
}
|
||||
Self { name, previous }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EnvVarGuard {
|
||||
fn drop(&mut self) {
|
||||
match self.previous.take() {
|
||||
Some(value) => unsafe { env::set_var(self.name, value) },
|
||||
None => unsafe { env::remove_var(self.name) },
|
||||
}
|
||||
}
|
||||
}
|
||||
use crate::terminal_capabilities::images::tests::EnvVarGuard;
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
@@ -493,302 +273,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_prefers_multiplexer_safety() {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Ghostty,
|
||||
Some(Multiplexer::Tmux { version: None }),
|
||||
Some("Ghostty"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux)
|
||||
);
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Kitty,
|
||||
Some(Multiplexer::Zellij { version: None }),
|
||||
Some("kitty"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_iterm2_kitty_file_graphics() {
|
||||
for info in [
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.6.10"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.6.10"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::KittyLocalFile)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_rejects_old_iterm2_versions() {
|
||||
for info in [
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.5.14"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
/*version*/ None,
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.5"),
|
||||
/*term*/ None,
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_old_iterm2_message_mentions_upgrade() {
|
||||
let message = PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld)
|
||||
.unsupported_message();
|
||||
|
||||
assert_eq!(
|
||||
message,
|
||||
Some("Pets require iTerm2 3.6 or newer. Upgrade iTerm2 to use terminal pets.")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_kitty_graphics_terminals() {
|
||||
for info in [
|
||||
terminal_info_for_test(
|
||||
TerminalName::Ghostty,
|
||||
/*multiplexer*/ None,
|
||||
Some("Ghostty"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Kitty,
|
||||
/*multiplexer*/ None,
|
||||
Some("kitty"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Rex,
|
||||
/*multiplexer*/ None,
|
||||
Some("rex"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::WezTerm,
|
||||
/*multiplexer*/ None,
|
||||
Some("WezTerm"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-kitty"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("wezterm"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("WezTerm"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orca_graphics_require_a_direct_terminal_and_advertised_protocol() {
|
||||
let mut info = terminal_info_for_test(
|
||||
TerminalName::Orca,
|
||||
/*multiplexer*/ None,
|
||||
Some("Orca"),
|
||||
/*term*/ None,
|
||||
);
|
||||
for (protocol, term, sty_present, expected) in [
|
||||
(Some("kitty"), Some("xterm-256color"), false, true),
|
||||
(None, Some("xterm-256color"), false, false),
|
||||
(Some("kitty"), Some("screen-256color"), false, false),
|
||||
(Some("kitty"), Some("tmux-256color"), false, false),
|
||||
(Some("kitty"), Some("dumb"), false, false),
|
||||
(Some("kitty"), Some("xterm-256color"), true, false),
|
||||
] {
|
||||
assert_eq!(
|
||||
supports_orca_kitty_graphics(&info, protocol, term, sty_present),
|
||||
expected
|
||||
);
|
||||
}
|
||||
info.multiplexer = Some(Multiplexer::Tmux { version: None });
|
||||
assert!(!supports_orca_kitty_graphics(
|
||||
&info,
|
||||
Some("kitty"),
|
||||
Some("xterm-256color"),
|
||||
/*sty_present*/ false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_sixel_terminals() {
|
||||
for info in [
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-sixel"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("foot"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("mlterm"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::WindowsTerminal,
|
||||
/*multiplexer*/ None,
|
||||
Some("WindowsTerminal"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::Sixel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn wezterm_env_uses_kitty_graphics_for_ambient_pets() {
|
||||
let _tmux = EnvVarGuard::new("TMUX", /*value*/ None);
|
||||
let _tmux_pane = EnvVarGuard::new("TMUX_PANE", /*value*/ None);
|
||||
let _zellij = EnvVarGuard::new("ZELLIJ", /*value*/ None);
|
||||
let _zellij_session = EnvVarGuard::new("ZELLIJ_SESSION_NAME", /*value*/ None);
|
||||
let _zellij_version = EnvVarGuard::new("ZELLIJ_VERSION", /*value*/ None);
|
||||
let _kitty = EnvVarGuard::new("KITTY_WINDOW_ID", /*value*/ None);
|
||||
let _wezterm = EnvVarGuard::new("WEZTERM_VERSION", Some("20240203"));
|
||||
let _wezterm_executable = EnvVarGuard::new("WEZTERM_EXECUTABLE", /*value*/ None);
|
||||
let _orca_protocol = EnvVarGuard::new("ORCA_IMAGE_PROTOCOL", /*value*/ None);
|
||||
|
||||
assert_eq!(
|
||||
image_support_for_terminal_environment(&terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
);
|
||||
assert_eq!(
|
||||
image_support_for_terminal_environment(&terminal_info_for_test(
|
||||
TerminalName::Orca,
|
||||
/*multiplexer*/ None,
|
||||
Some("Orca"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_rejects_unknown_terminals() {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-256color"),
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
);
|
||||
}
|
||||
|
||||
fn terminal_info_for_test(
|
||||
name: TerminalName,
|
||||
multiplexer: Option<Multiplexer>,
|
||||
term_program: Option<&str>,
|
||||
term: Option<&str>,
|
||||
) -> TerminalInfo {
|
||||
terminal_info_with_version_for_test(
|
||||
name,
|
||||
multiplexer,
|
||||
term_program,
|
||||
/*version*/ None,
|
||||
term,
|
||||
)
|
||||
}
|
||||
|
||||
fn terminal_info_with_version_for_test(
|
||||
name: TerminalName,
|
||||
multiplexer: Option<Multiplexer>,
|
||||
term_program: Option<&str>,
|
||||
version: Option<&str>,
|
||||
term: Option<&str>,
|
||||
) -> TerminalInfo {
|
||||
TerminalInfo {
|
||||
backend: None,
|
||||
name,
|
||||
term_program: term_program.map(str::to_string),
|
||||
version: version.map(str::to_string),
|
||||
term: term.map(str::to_string),
|
||||
multiplexer,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_dotted_version_requires_simple_numeric_components() {
|
||||
assert_eq!(parse_dotted_version(Some("3.6.10")), Some((3, 6, 10)));
|
||||
assert_eq!(parse_dotted_version(Some("3.6")), Some((3, 6, 0)));
|
||||
assert_eq!(parse_dotted_version(Some("3")), Some((3, 0, 0)));
|
||||
assert_eq!(parse_dotted_version(Some("3.6.10.1")), None);
|
||||
assert_eq!(parse_dotted_version(Some("3.6beta")), None);
|
||||
assert_eq!(parse_dotted_version(/*version*/ None), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sixel_frame_encodes_without_external_crate() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
//! Derives TUI capabilities from terminal identity and session environment.
|
||||
//! Keep environment-specific clipboard decisions here so delivery code only sees a strategy.
|
||||
|
||||
pub(crate) mod images;
|
||||
pub(crate) mod keyboard_modes;
|
||||
pub(crate) mod resize_reflow_cap;
|
||||
pub(crate) mod terminal_probe;
|
||||
pub(crate) mod tmux;
|
||||
pub(crate) mod tmux_clipboard;
|
||||
|
||||
use codex_terminal_detection::TerminalName;
|
||||
|
||||
/// How clipboard writes should reach the attached terminal.
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
//! Detects image protocols and placement support, including fullscreen-only virtual placements.
|
||||
use codex_terminal_detection::Multiplexer;
|
||||
use codex_terminal_detection::TerminalInfo;
|
||||
use codex_terminal_detection::TerminalName;
|
||||
use codex_terminal_detection::terminal_info;
|
||||
use std::env;
|
||||
|
||||
const ITERM2_KITTY_MIN_VERSION: (u64, u64, u64) = (3, 6, 0);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ImageProtocol {
|
||||
Kitty,
|
||||
KittyLocalFile,
|
||||
Sixel,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum PetImageSupport {
|
||||
Supported(ImageProtocol),
|
||||
Unsupported(PetImageUnsupportedReason),
|
||||
}
|
||||
|
||||
impl PetImageSupport {
|
||||
pub(crate) fn protocol(self) -> Option<ImageProtocol> {
|
||||
match self {
|
||||
Self::Supported(protocol) => Some(protocol),
|
||||
Self::Unsupported(PetImageUnsupportedReason::Tmux) => {
|
||||
crate::tui::tmux_fullscreen_image_base().map(|_| ImageProtocol::Kitty)
|
||||
}
|
||||
Self::Unsupported(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn unsupported_message(self) -> Option<&'static str> {
|
||||
match self {
|
||||
Self::Supported(_) => None,
|
||||
Self::Unsupported(reason) => self.protocol().is_none().then(|| reason.message()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(crate) enum PetImageUnsupportedReason {
|
||||
Tmux,
|
||||
Zellij,
|
||||
Iterm2TooOld,
|
||||
Terminal,
|
||||
}
|
||||
|
||||
impl PetImageUnsupportedReason {
|
||||
fn message(self) -> &'static str {
|
||||
match self {
|
||||
Self::Tmux => {
|
||||
"Pets are unavailable in this tmux pane. Use fullscreen Codex with allow-passthrough all, or run Codex outside tmux."
|
||||
}
|
||||
Self::Zellij => {
|
||||
"Pets are disabled in Zellij. Terminal images don’t stay reliably pane-local in Zellij. Run Codex outside Zellij to use pets."
|
||||
}
|
||||
Self::Iterm2TooOld => {
|
||||
"Pets require iTerm2 3.6 or newer. Upgrade iTerm2 to use terminal pets."
|
||||
}
|
||||
Self::Terminal => {
|
||||
"Pets aren’t available in this terminal. Terminal pets need image support, and this terminal environment doesn’t expose a supported image protocol. Try a terminal with Kitty graphics or Sixel support, or run Codex outside tmux."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn detect_pet_image_support() -> PetImageSupport {
|
||||
if env::var_os("TMUX").is_some() || env::var_os("TMUX_PANE").is_some() {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux);
|
||||
}
|
||||
|
||||
if env::var_os("ZELLIJ").is_some()
|
||||
|| env::var_os("ZELLIJ_SESSION_NAME").is_some()
|
||||
|| env::var_os("ZELLIJ_VERSION").is_some()
|
||||
{
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij);
|
||||
}
|
||||
|
||||
image_support_for_terminal_environment(&terminal_info())
|
||||
}
|
||||
|
||||
fn image_support_for_terminal_environment(info: &TerminalInfo) -> PetImageSupport {
|
||||
if info.name == TerminalName::Orca {
|
||||
return if supports_orca_kitty_graphics(
|
||||
info,
|
||||
env::var("ORCA_IMAGE_PROTOCOL").ok().as_deref(),
|
||||
env::var("TERM").ok().as_deref(),
|
||||
/*sty_present*/ env::var_os("STY").is_some(),
|
||||
) {
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
} else {
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
};
|
||||
}
|
||||
|
||||
if env::var_os("KITTY_WINDOW_ID").is_some() {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
if env::var_os("WEZTERM_EXECUTABLE").is_some() || env::var_os("WEZTERM_VERSION").is_some() {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
pet_image_support_for_terminal(info)
|
||||
}
|
||||
|
||||
fn supports_orca_kitty_graphics(
|
||||
info: &TerminalInfo,
|
||||
protocol: Option<&str>,
|
||||
term: Option<&str>,
|
||||
sty_present: bool,
|
||||
) -> bool {
|
||||
info.multiplexer.is_none()
|
||||
&& protocol == Some("kitty")
|
||||
&& !sty_present
|
||||
&& !term.is_some_and(|term| {
|
||||
term == "dumb" || term.starts_with("screen") || term.starts_with("tmux")
|
||||
})
|
||||
}
|
||||
|
||||
fn pet_image_support_for_terminal(info: &TerminalInfo) -> PetImageSupport {
|
||||
match info.multiplexer {
|
||||
Some(Multiplexer::Tmux { .. }) => {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux);
|
||||
}
|
||||
Some(Multiplexer::Zellij { .. }) => {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
if supports_iterm2_kitty_graphics(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::KittyLocalFile);
|
||||
}
|
||||
|
||||
if is_iterm2_terminal(info) {
|
||||
return PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld);
|
||||
}
|
||||
|
||||
if supports_kitty_graphics(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::Kitty);
|
||||
}
|
||||
|
||||
if supports_sixel(info) {
|
||||
return PetImageSupport::Supported(ImageProtocol::Sixel);
|
||||
}
|
||||
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
}
|
||||
|
||||
fn supports_iterm2_kitty_graphics(info: &TerminalInfo) -> bool {
|
||||
is_iterm2_terminal(info)
|
||||
&& version_is_at_least(
|
||||
info.version.as_deref(),
|
||||
/*minimum*/ ITERM2_KITTY_MIN_VERSION,
|
||||
)
|
||||
}
|
||||
|
||||
fn is_iterm2_terminal(info: &TerminalInfo) -> bool {
|
||||
matches!(info.name, TerminalName::Iterm2)
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "iterm")
|
||||
}
|
||||
|
||||
fn supports_kitty_graphics(info: &TerminalInfo) -> bool {
|
||||
matches!(
|
||||
info.name,
|
||||
TerminalName::Ghostty | TerminalName::Kitty | TerminalName::Rex | TerminalName::WezTerm
|
||||
) || terminal_field_contains(info.term.as_deref(), "kitty")
|
||||
|| terminal_field_contains(info.term.as_deref(), "ghostty")
|
||||
|| terminal_field_contains(info.term.as_deref(), "wezterm")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "kitty")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "ghostty")
|
||||
|| terminal_field_contains(info.term_program.as_deref(), "wezterm")
|
||||
}
|
||||
|
||||
fn supports_sixel(info: &TerminalInfo) -> bool {
|
||||
matches!(info.name, TerminalName::WindowsTerminal)
|
||||
|| terminal_field_contains(info.term.as_deref(), "sixel")
|
||||
|| terminal_field_contains(info.term.as_deref(), "mlterm")
|
||||
|| terminal_field_contains(info.term.as_deref(), "foot")
|
||||
}
|
||||
|
||||
fn terminal_field_contains(value: Option<&str>, needle: &str) -> bool {
|
||||
value.is_some_and(|value| value.to_ascii_lowercase().contains(needle))
|
||||
}
|
||||
|
||||
fn version_is_at_least(version: Option<&str>, minimum: (u64, u64, u64)) -> bool {
|
||||
parse_dotted_version(version).is_some_and(|version| version >= minimum)
|
||||
}
|
||||
|
||||
fn parse_dotted_version(version: Option<&str>) -> Option<(u64, u64, u64)> {
|
||||
let version = version?;
|
||||
let mut parts = version.split('.');
|
||||
let major = parts.next()?.parse().ok()?;
|
||||
let minor = parts.next().unwrap_or("0").parse().ok()?;
|
||||
let patch = parts.next().unwrap_or("0").parse().ok()?;
|
||||
|
||||
if parts.next().is_some() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some((major, minor, patch))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "images_tests.rs"]
|
||||
pub(crate) mod tests;
|
||||
@@ -0,0 +1,324 @@
|
||||
#![cfg(test)]
|
||||
use super::*;
|
||||
use serial_test::serial;
|
||||
|
||||
pub(crate) struct EnvVarGuard {
|
||||
name: &'static str,
|
||||
previous: Option<std::ffi::OsString>,
|
||||
}
|
||||
|
||||
impl EnvVarGuard {
|
||||
pub(crate) fn new(name: &'static str, value: Option<&str>) -> Self {
|
||||
let previous = env::var_os(name);
|
||||
match value {
|
||||
Some(value) => unsafe { env::set_var(name, value) },
|
||||
None => unsafe { env::remove_var(name) },
|
||||
}
|
||||
Self { name, previous }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for EnvVarGuard {
|
||||
fn drop(&mut self) {
|
||||
match self.previous.take() {
|
||||
Some(value) => unsafe { env::set_var(self.name, value) },
|
||||
None => unsafe { env::remove_var(self.name) },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_prefers_multiplexer_safety() {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Ghostty,
|
||||
Some(Multiplexer::Tmux { version: None }),
|
||||
Some("Ghostty"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Tmux)
|
||||
);
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Kitty,
|
||||
Some(Multiplexer::Zellij { version: None }),
|
||||
Some("kitty"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Zellij)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_iterm2_kitty_file_graphics() {
|
||||
for info in [
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.6.10"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.6.10"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::KittyLocalFile)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_rejects_old_iterm2_versions() {
|
||||
for info in [
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.5.14"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
/*version*/ None,
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
terminal_info_with_version_for_test(
|
||||
TerminalName::Iterm2,
|
||||
/*multiplexer*/ None,
|
||||
Some("iTerm.app"),
|
||||
Some("3.5"),
|
||||
/*term*/ None,
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_old_iterm2_message_mentions_upgrade() {
|
||||
let message =
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Iterm2TooOld).unsupported_message();
|
||||
|
||||
assert_eq!(
|
||||
message,
|
||||
Some("Pets require iTerm2 3.6 or newer. Upgrade iTerm2 to use terminal pets.")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_kitty_graphics_terminals() {
|
||||
for info in [
|
||||
terminal_info_for_test(
|
||||
TerminalName::Ghostty,
|
||||
/*multiplexer*/ None,
|
||||
Some("Ghostty"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Kitty,
|
||||
/*multiplexer*/ None,
|
||||
Some("kitty"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Rex,
|
||||
/*multiplexer*/ None,
|
||||
Some("rex"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::WezTerm,
|
||||
/*multiplexer*/ None,
|
||||
Some("WezTerm"),
|
||||
/*term*/ None,
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-kitty"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("wezterm"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
Some("WezTerm"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn orca_graphics_require_a_direct_terminal_and_advertised_protocol() {
|
||||
let mut info = terminal_info_for_test(
|
||||
TerminalName::Orca,
|
||||
/*multiplexer*/ None,
|
||||
Some("Orca"),
|
||||
/*term*/ None,
|
||||
);
|
||||
for (protocol, term, sty_present, expected) in [
|
||||
(Some("kitty"), Some("xterm-256color"), false, true),
|
||||
(None, Some("xterm-256color"), false, false),
|
||||
(Some("kitty"), Some("screen-256color"), false, false),
|
||||
(Some("kitty"), Some("tmux-256color"), false, false),
|
||||
(Some("kitty"), Some("dumb"), false, false),
|
||||
(Some("kitty"), Some("xterm-256color"), true, false),
|
||||
] {
|
||||
assert_eq!(
|
||||
supports_orca_kitty_graphics(&info, protocol, term, sty_present),
|
||||
expected
|
||||
);
|
||||
}
|
||||
info.multiplexer = Some(Multiplexer::Tmux { version: None });
|
||||
assert!(!supports_orca_kitty_graphics(
|
||||
&info,
|
||||
Some("kitty"),
|
||||
Some("xterm-256color"),
|
||||
/*sty_present*/ false
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_detects_sixel_terminals() {
|
||||
for info in [
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-sixel"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("foot"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("mlterm"),
|
||||
),
|
||||
terminal_info_for_test(
|
||||
TerminalName::WindowsTerminal,
|
||||
/*multiplexer*/ None,
|
||||
Some("WindowsTerminal"),
|
||||
Some("xterm-256color"),
|
||||
),
|
||||
] {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&info),
|
||||
PetImageSupport::Supported(ImageProtocol::Sixel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial]
|
||||
fn wezterm_env_uses_kitty_graphics_for_ambient_pets() {
|
||||
let _tmux = EnvVarGuard::new("TMUX", /*value*/ None);
|
||||
let _tmux_pane = EnvVarGuard::new("TMUX_PANE", /*value*/ None);
|
||||
let _zellij = EnvVarGuard::new("ZELLIJ", /*value*/ None);
|
||||
let _zellij_session = EnvVarGuard::new("ZELLIJ_SESSION_NAME", /*value*/ None);
|
||||
let _zellij_version = EnvVarGuard::new("ZELLIJ_VERSION", /*value*/ None);
|
||||
let _kitty = EnvVarGuard::new("KITTY_WINDOW_ID", /*value*/ None);
|
||||
let _wezterm = EnvVarGuard::new("WEZTERM_VERSION", Some("20240203"));
|
||||
let _wezterm_executable = EnvVarGuard::new("WEZTERM_EXECUTABLE", /*value*/ None);
|
||||
let _orca_protocol = EnvVarGuard::new("ORCA_IMAGE_PROTOCOL", /*value*/ None);
|
||||
|
||||
assert_eq!(
|
||||
image_support_for_terminal_environment(&terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Supported(ImageProtocol::Kitty)
|
||||
);
|
||||
assert_eq!(
|
||||
image_support_for_terminal_environment(&terminal_info_for_test(
|
||||
TerminalName::Orca,
|
||||
/*multiplexer*/ None,
|
||||
Some("Orca"),
|
||||
/*term*/ None,
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pet_image_support_rejects_unknown_terminals() {
|
||||
assert_eq!(
|
||||
pet_image_support_for_terminal(&terminal_info_for_test(
|
||||
TerminalName::Unknown,
|
||||
/*multiplexer*/ None,
|
||||
/*term_program*/ None,
|
||||
Some("xterm-256color"),
|
||||
)),
|
||||
PetImageSupport::Unsupported(PetImageUnsupportedReason::Terminal)
|
||||
);
|
||||
}
|
||||
|
||||
fn terminal_info_for_test(
|
||||
name: TerminalName,
|
||||
multiplexer: Option<Multiplexer>,
|
||||
term_program: Option<&str>,
|
||||
term: Option<&str>,
|
||||
) -> TerminalInfo {
|
||||
terminal_info_with_version_for_test(
|
||||
name,
|
||||
multiplexer,
|
||||
term_program,
|
||||
/*version*/ None,
|
||||
term,
|
||||
)
|
||||
}
|
||||
|
||||
fn terminal_info_with_version_for_test(
|
||||
name: TerminalName,
|
||||
multiplexer: Option<Multiplexer>,
|
||||
term_program: Option<&str>,
|
||||
version: Option<&str>,
|
||||
term: Option<&str>,
|
||||
) -> TerminalInfo {
|
||||
TerminalInfo {
|
||||
backend: None,
|
||||
name,
|
||||
term_program: term_program.map(str::to_string),
|
||||
version: version.map(str::to_string),
|
||||
term: term.map(str::to_string),
|
||||
multiplexer,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_dotted_version_requires_simple_numeric_components() {
|
||||
assert_eq!(parse_dotted_version(Some("3.6.10")), Some((3, 6, 10)));
|
||||
assert_eq!(parse_dotted_version(Some("3.6")), Some((3, 6, 0)));
|
||||
assert_eq!(parse_dotted_version(Some("3")), Some((3, 0, 0)));
|
||||
assert_eq!(parse_dotted_version(Some("3.6.10.1")), None);
|
||||
assert_eq!(parse_dotted_version(Some("3.6beta")), None);
|
||||
assert_eq!(parse_dotted_version(/*version*/ None), None);
|
||||
}
|
||||
+8
-8
@@ -29,7 +29,7 @@ pub(crate) enum VscodeDetection {
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub(super) fn keyboard_enhancement_disabled() -> bool {
|
||||
pub(crate) fn keyboard_enhancement_disabled() -> bool {
|
||||
let disable_env = std::env::var(DISABLE_KEYBOARD_ENHANCEMENT_ENV_VAR).ok();
|
||||
let is_wsl = running_in_wsl();
|
||||
let vscode_detection = if is_wsl {
|
||||
@@ -83,7 +83,7 @@ fn running_in_wsl() -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn running_in_vscode_terminal() -> bool {
|
||||
pub(crate) fn running_in_vscode_terminal() -> bool {
|
||||
detect_vscode_terminal() == VscodeDetection::VsCode
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ fn read_windows_vscode_detection_with_timeout(
|
||||
mod windows_term_program_tests;
|
||||
|
||||
/// Restore keyboard reporting and return the settings from the same tmux probe.
|
||||
pub(super) fn enable_keyboard_enhancement(writer: &mut impl Write) -> super::tmux::Options {
|
||||
pub(crate) fn enable_keyboard_enhancement(writer: &mut impl Write) -> super::tmux::Options {
|
||||
let tmux_options = super::tmux::options();
|
||||
if keyboard_enhancement_disabled() {
|
||||
set_reports_key_releases(/*reports*/ false);
|
||||
@@ -249,11 +249,11 @@ fn keyboard_enhancement_flags(
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reports_key_releases() -> bool {
|
||||
pub(crate) fn reports_key_releases() -> bool {
|
||||
REPORTS_KEY_RELEASES.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
pub(super) fn set_reports_key_releases(reports: bool) {
|
||||
pub(crate) fn set_reports_key_releases(reports: bool) {
|
||||
REPORTS_KEY_RELEASES.store(reports, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
@@ -278,13 +278,13 @@ fn tmux_should_enable_modify_other_keys_for(
|
||||
running_in_tmux_session && matches!(extended_keys_format, Some("csi-u"))
|
||||
}
|
||||
|
||||
pub(super) fn restore_keyboard_enhancement_stack(writer: &mut impl Write) {
|
||||
pub(crate) fn restore_keyboard_enhancement_stack(writer: &mut impl Write) {
|
||||
if execute!(writer, PopKeyboardEnhancementFlags, DisableModifyOtherKeys).is_ok() {
|
||||
set_reports_key_releases(/*reports*/ false);
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn reset_keyboard_reporting_after_exit(writer: &mut impl Write) {
|
||||
pub(crate) fn reset_keyboard_reporting_after_exit(writer: &mut impl Write) {
|
||||
if execute!(
|
||||
writer,
|
||||
PopKeyboardEnhancementFlags,
|
||||
@@ -342,7 +342,7 @@ impl Command for EnableModifyOtherKeys {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub(super) struct DisableModifyOtherKeys;
|
||||
pub(crate) struct DisableModifyOtherKeys;
|
||||
|
||||
impl Command for DisableModifyOtherKeys {
|
||||
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
---
|
||||
source: tui/src/clipboard_copy/tmux_tests.rs
|
||||
assertion_line: 58
|
||||
source: tui/src/terminal_capabilities/tmux_clipboard_tests.rs
|
||||
assertion_line: 60
|
||||
expression: "result.expect_err(\"no receiving client\")"
|
||||
---
|
||||
tmux clipboard forwarding is unavailable: no attached client
|
||||
+1
@@ -17,6 +17,7 @@ use std::time::Duration;
|
||||
mod startup_replay;
|
||||
|
||||
#[cfg(unix)]
|
||||
#[path = "terminal_identity.rs"]
|
||||
mod terminal_identity;
|
||||
|
||||
#[cfg(any(windows, test))]
|
||||
@@ -20,7 +20,7 @@ static PROBE_IN_FLIGHT: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
/// Capture policy for the current terminal setup, shared by fullscreen and overlays.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(super) enum MouseCapture {
|
||||
pub(crate) enum MouseCapture {
|
||||
#[default]
|
||||
Enabled,
|
||||
DisabledByTmux,
|
||||
@@ -62,7 +62,7 @@ fn target() -> Option<String> {
|
||||
}
|
||||
|
||||
/// A failed refresh must preserve the last confirmed policy, including mouse off.
|
||||
pub(super) fn sample_mouse(previous: MouseCapture) -> Option<MouseCapture> {
|
||||
pub(crate) fn sample_mouse(previous: MouseCapture) -> Option<MouseCapture> {
|
||||
let target = target()?;
|
||||
// tmux clears the socket's execute bits when its last client detaches.
|
||||
// Avoid spawning commands (and filling show-messages) on an idle server.
|
||||
@@ -90,13 +90,13 @@ pub(super) fn sample_mouse(previous: MouseCapture) -> Option<MouseCapture> {
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub(super) struct Options {
|
||||
pub(super) extended_keys_format: Option<String>,
|
||||
pub(super) mouse_capture: MouseCapture,
|
||||
pub(super) kitty_image_base: Option<u32>,
|
||||
pub(crate) struct Options {
|
||||
pub(crate) extended_keys_format: Option<String>,
|
||||
pub(crate) mouse_capture: MouseCapture,
|
||||
pub(crate) kitty_image_base: Option<u32>,
|
||||
}
|
||||
|
||||
pub(super) fn options() -> Options {
|
||||
pub(crate) fn options() -> Options {
|
||||
let pane = target();
|
||||
if std::env::var_os("TMUX").is_none() && pane.is_none() {
|
||||
return Options::default();
|
||||
+2
-2
@@ -12,7 +12,7 @@ use std::path::Path;
|
||||
/// `load-buffer -w -` lets tmux read the text from stdin, keep a matching tmux
|
||||
/// paste buffer, and forward the contents to the outer terminal clipboard when
|
||||
/// possible without relying on DCS passthrough.
|
||||
pub(super) fn copy(text: &str) -> Result<(), String> {
|
||||
pub(crate) fn copy(text: &str) -> Result<(), String> {
|
||||
let executable = codex_utils_path::system_executable("tmux")
|
||||
.ok_or_else(|| "tmux is unavailable in the system PATH".to_string())?;
|
||||
let path = codex_utils_path::system_path()
|
||||
@@ -145,5 +145,5 @@ fn command_output<const N: usize>(
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "tmux_tests.rs"]
|
||||
#[path = "tmux_clipboard_tests.rs"]
|
||||
mod tests;
|
||||
@@ -51,6 +51,8 @@ use crate::insert_history::HistoryLineWrapPolicy;
|
||||
use crate::insert_history::InsertHistoryMode;
|
||||
use crate::notifications::DesktopNotificationBackend;
|
||||
use crate::notifications::detect_backend;
|
||||
use crate::terminal_capabilities::keyboard_modes;
|
||||
use crate::terminal_capabilities::tmux;
|
||||
use crate::terminal_hyperlinks::HyperlinkLine;
|
||||
use crate::terminal_hyperlinks::plain_hyperlink_lines;
|
||||
use crate::tui::alternate_screen::ALTERNATE_SCREEN;
|
||||
@@ -71,7 +73,6 @@ mod history_tail;
|
||||
mod input_boundary;
|
||||
#[cfg(unix)]
|
||||
mod job_control;
|
||||
mod keyboard_modes;
|
||||
mod link_pointer;
|
||||
pub(crate) use link_pointer::PointerShape;
|
||||
#[cfg(test)]
|
||||
@@ -94,7 +95,6 @@ mod startup_tests;
|
||||
mod terminal_stderr;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod test_support;
|
||||
mod tmux;
|
||||
#[cfg(any(windows, test))]
|
||||
mod windows_console;
|
||||
#[cfg(any(windows, test))]
|
||||
|
||||
Reference in New Issue
Block a user