diff options
| author | Can Celik <ogulcancelik@gmail.com> | 2026-08-03 02:05:27 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-08-03 02:05:27 +0300 |
| commit | 10eb0bc744165ae91dfce9fd731fe170410b34ec (patch) | |
| tree | 8622d429d9453c2e8d06630322804a702973d94a /src/ghostty | |
| parent | cbc31d34a1fb3da64415737de57ad10fe6af5ba5 (diff) | |
fix: propagate host color scheme to pane apps (#2214)
refs #714
Diffstat (limited to 'src/ghostty')
| -rw-r--r-- | src/ghostty/mod.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs index c4541948..685c0735 100644 --- a/src/ghostty/mod.rs +++ b/src/ghostty/mod.rs @@ -119,6 +119,21 @@ impl FocusEvent { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ColorScheme { + Light, + Dark, +} + +impl ColorScheme { + fn as_raw(self) -> ffi::GhosttyColorScheme { + match self { + Self::Light => ffi::GhosttyColorScheme_GHOSTTY_COLOR_SCHEME_LIGHT, + Self::Dark => ffi::GhosttyColorScheme_GHOSTTY_COLOR_SCHEME_DARK, + } + } +} + pub const MOD_SHIFT: u16 = ffi::GHOSTTY_MODS_SHIFT as u16; pub const MOD_CTRL: u16 = ffi::GHOSTTY_MODS_CTRL as u16; pub const MOD_ALT: u16 = ffi::GHOSTTY_MODS_ALT as u16; @@ -163,6 +178,7 @@ 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; +pub const MODE_COLOR_SCHEME_REPORT: u16 = 2031; // 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; @@ -457,6 +473,25 @@ struct TerminalCallbackState { pwd_changes: Vec<Vec<u8>>, clipboard_writes: Vec<Vec<u8>>, size_report: ffi::GhosttySizeReportSize, + color_scheme: Option<ColorScheme>, +} + +unsafe extern "C" fn color_scheme_trampoline( + _terminal: ffi::GhosttyTerminal, + userdata: *mut c_void, + out_scheme: *mut ffi::GhosttyColorScheme, +) -> bool { + if userdata.is_null() || out_scheme.is_null() { + return false; + } + let state = unsafe { &*userdata.cast::<TerminalCallbackState>() }; + let Some(color_scheme) = state.color_scheme else { + return false; + }; + unsafe { + out_scheme.write(color_scheme.as_raw()); + } + true } unsafe extern "C" fn size_trampoline( @@ -793,6 +828,12 @@ impl Terminal { .into_result()?; ffi::ghostty_terminal_set( terminal.raw, + ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_COLOR_SCHEME, + (color_scheme_trampoline as *const ()).cast(), + ) + .into_result()?; + ffi::ghostty_terminal_set( + terminal.raw, ffi::GhosttyTerminalOption_GHOSTTY_TERMINAL_OPT_GLYPH_PROTOCOL, (&glyph_protocol as *const bool).cast(), ) @@ -913,6 +954,10 @@ impl Terminal { Ok(()) } + pub fn set_color_scheme(&mut self, color_scheme: Option<ColorScheme>) -> Option<ColorScheme> { + mem::replace(&mut self.callback_state.color_scheme, color_scheme) + } + pub fn take_pwd_changes(&mut self) -> Vec<Vec<u8>> { mem::take(&mut self.callback_state.pwd_changes) } |
