From 292a98a91e35662fd65993956278787ee0ca9840 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Thu, 25 Jun 2026 22:08:11 +0300 Subject: fix: answer osc 12 cursor color queries refs #806 --- src/ghostty/mod.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/ghostty') diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs index 2b45e3d8..3800ab49 100644 --- a/src/ghostty/mod.rs +++ b/src/ghostty/mod.rs @@ -162,6 +162,10 @@ pub const MODE_MOUSE_SGR_PIXELS: u16 = 1016; pub const MODE_BRACKETED_PASTE: u16 = 2004; pub const MODE_SYNCHRONIZED_OUTPUT: u16 = 2026; pub const MODE_GRAPHEME_CLUSTER: u16 = 2027; +// These are documented in vendor/libghostty-vt/include/ghostty/vt/terminal.h, +// but the generated bindings do not currently expose named constants for them. +const TERMINAL_DATA_COLOR_FOREGROUND: ffi::GhosttyTerminalData = 18; +const TERMINAL_DATA_COLOR_CURSOR: ffi::GhosttyTerminalData = 20; const KITTY_IMAGE_STORAGE_LIMIT_BYTES: u64 = 64 * 1024 * 1024; const APC_MAX_BYTES: usize = 16 * 1024 * 1024; @@ -1006,6 +1010,14 @@ impl Terminal { self.get_u16(ffi::GhosttyTerminalData_GHOSTTY_TERMINAL_DATA_ROWS) } + pub fn effective_foreground_color(&self) -> Result, Error> { + self.get_optional_rgb_color(TERMINAL_DATA_COLOR_FOREGROUND) + } + + pub fn effective_cursor_color(&self) -> Result, Error> { + self.get_optional_rgb_color(TERMINAL_DATA_COLOR_CURSOR) + } + fn width_px(&self) -> Result { self.get_u32(ffi::GhosttyTerminalData_GHOSTTY_TERMINAL_DATA_WIDTH_PX) } @@ -1052,6 +1064,25 @@ impl Terminal { Ok(out) } + fn get_optional_rgb_color( + &self, + data: ffi::GhosttyTerminalData, + ) -> Result, Error> { + let mut out = ffi::GhosttyColorRgb::default(); + let result = unsafe { + ffi::ghostty_terminal_get( + self.raw, + data, + (&mut out as *mut ffi::GhosttyColorRgb).cast(), + ) + }; + match result { + ffi::GhosttyResult_GHOSTTY_SUCCESS => Ok(Some(out.into())), + ffi::GhosttyResult_GHOSTTY_NO_VALUE => Ok(None), + other => Err(Error(other)), + } + } + pub fn kitty_image_placements(&self) -> Result, Error> { self.kitty_image_placements_with_data_filter(|_| true) } -- cgit v1.2.3