aboutsummaryrefslogtreecommitdiff
path: root/src/pane
diff options
context:
space:
mode:
authorakbash <akbash@herdr.dev>2026-07-24 01:28:35 +0300
committerGitHub <noreply@github.com>2026-07-24 01:28:35 +0300
commit503613c8ecbea752a234daf30cb0ad5a8bf93e4e (patch)
tree34b71e4c7055244ed191c043457c572e3ccfc935 /src/pane
parent58ad2c6438cf25cdf7e95528c7114d3bf12626d2 (diff)
fix: inherit host palette in pane queries (#1759)
refs #1752 Co-authored-by: Ogulcan Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/pane')
-rw-r--r--src/pane/osc.rs2
-rw-r--r--src/pane/terminal.rs128
2 files changed, 127 insertions, 3 deletions
diff --git a/src/pane/osc.rs b/src/pane/osc.rs
index 812c8edd..16ee8fee 100644
--- a/src/pane/osc.rs
+++ b/src/pane/osc.rs
@@ -891,6 +891,7 @@ mod tests {
g: colors.background.g,
b: colors.background.b,
}),
+ ..Default::default()
}
}
@@ -1486,6 +1487,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
pane.apply_host_terminal_theme(host_theme);
diff --git a/src/pane/terminal.rs b/src/pane/terminal.rs
index 261f7025..23dcffff 100644
--- a/src/pane/terminal.rs
+++ b/src/pane/terminal.rs
@@ -940,6 +940,21 @@ impl GhosttyPaneTerminal {
if foreground_unowned && background_unowned {
core.transient_default_color_owner_pgid = None;
}
+
+ let mut palette = crate::ghostty::default_palette();
+ for (index, color) in theme.palette.iter().enumerate() {
+ if let Some(color) = color {
+ palette[index] = crate::ghostty::RgbColor {
+ r: color.r,
+ g: color.g,
+ b: color.b,
+ };
+ }
+ }
+ if let Err(err) = core.terminal.set_default_palette(&palette) {
+ debug!(err = %err, "failed to apply host terminal palette");
+ }
+
write_host_terminal_theme_selective(
&mut core.terminal,
theme,
@@ -3559,6 +3574,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
}
let core = pane.core.lock().unwrap();
@@ -3585,6 +3601,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
}
let core = pane.core.lock().unwrap();
@@ -4837,6 +4854,7 @@ mod tests {
g: 0x2b,
b: 0x36,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1bP+q5463\x1b\\\x1b]11;?\x07", &tx);
@@ -4868,6 +4886,7 @@ mod tests {
g: 0xbb,
b: 0xcc,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]11;?\x07", &tx);
@@ -4893,6 +4912,7 @@ mod tests {
g: 0xbb,
b: 0xcc,
}),
+ ..Default::default()
});
pane.process_pty_bytes(pane_id, 0, b"\x1b]111\x07", &tx);
assert!(!pane.has_transient_default_color_override());
@@ -5049,6 +5069,7 @@ mod tests {
g: 0x2b,
b: 0x36,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]11;?\x07\x1b[c", &tx);
@@ -5063,23 +5084,110 @@ mod tests {
}
#[test]
- fn process_pty_bytes_returns_palette_color_query_response_without_queuing_input() {
+ fn process_pty_bytes_returns_host_palette_color_without_queuing_input() {
let (tx, mut rx) = mpsc::channel(4);
let terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
let pane = GhosttyPaneTerminal::new(terminal, tx.clone()).unwrap();
let pane_id = PaneId::from_raw(1);
- let color = current_palette_color(&pane, 0);
+ pane.apply_host_terminal_theme(
+ crate::terminal_theme::TerminalTheme::default().with_palette_color(
+ 0,
+ crate::terminal_theme::RgbColor {
+ r: 0x11,
+ g: 0x22,
+ b: 0x33,
+ },
+ ),
+ );
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]4;0;?\x07", &tx);
assert_eq!(
result.terminal_responses,
- vec![expected_osc_rgb_response("4;0", color)]
+ vec![Bytes::from_static(b"\x1b]4;0;rgb:1111/2222/3333\x1b\\")]
);
assert!(rx.try_recv().is_err());
}
#[test]
+ fn opentui_256_palette_query_burst_uses_host_snapshot() {
+ use std::fmt::Write as _;
+
+ let (tx, _rx) = mpsc::channel(4);
+ let terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
+ let pane = GhosttyPaneTerminal::new(terminal, tx.clone()).unwrap();
+ let pane_id = PaneId::from_raw(1);
+ let mut theme = crate::terminal_theme::TerminalTheme::default();
+ let mut queries = String::new();
+ for index in 0..=u8::MAX {
+ theme = theme.with_palette_color(
+ index,
+ crate::terminal_theme::RgbColor {
+ r: index,
+ g: 0x22,
+ b: 0x33,
+ },
+ );
+ let _ = write!(queries, "\x1b]4;{index};?\x07");
+ }
+ pane.apply_host_terminal_theme(theme);
+
+ let result = pane.process_pty_bytes(pane_id, 0, queries.as_bytes(), &tx);
+
+ assert_eq!(result.terminal_responses.len(), 256);
+ assert_eq!(
+ result.terminal_responses[0],
+ Bytes::from_static(b"\x1b]4;0;rgb:0000/2222/3333\x1b\\")
+ );
+ assert_eq!(
+ result.terminal_responses[255],
+ Bytes::from_static(b"\x1b]4;255;rgb:ffff/2222/3333\x1b\\")
+ );
+ }
+
+ #[test]
+ fn child_palette_override_survives_host_refresh_until_reset() {
+ let (tx, _rx) = mpsc::channel(4);
+ let terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
+ let pane = GhosttyPaneTerminal::new(terminal, tx.clone()).unwrap();
+ let pane_id = PaneId::from_raw(1);
+ pane.apply_host_terminal_theme(
+ crate::terminal_theme::TerminalTheme::default().with_palette_color(
+ 7,
+ crate::terminal_theme::RgbColor {
+ r: 0x11,
+ g: 0x22,
+ b: 0x33,
+ },
+ ),
+ );
+ pane.process_pty_bytes(pane_id, 0, b"\x1b]4;7;rgb:aa/bb/cc\x1b\\", &tx);
+
+ pane.apply_host_terminal_theme(
+ crate::terminal_theme::TerminalTheme::default().with_palette_color(
+ 7,
+ crate::terminal_theme::RgbColor {
+ r: 0x44,
+ g: 0x55,
+ b: 0x66,
+ },
+ ),
+ );
+ let overridden = pane.process_pty_bytes(pane_id, 0, b"\x1b]4;7;?\x1b\\", &tx);
+ assert_eq!(
+ overridden.terminal_responses,
+ vec![Bytes::from_static(b"\x1b]4;7;rgb:aaaa/bbbb/cccc\x1b\\")]
+ );
+
+ pane.process_pty_bytes(pane_id, 0, b"\x1b]104;7\x1b\\", &tx);
+ let reset = pane.process_pty_bytes(pane_id, 0, b"\x1b]4;7;?\x1b\\", &tx);
+ assert_eq!(
+ reset.terminal_responses,
+ vec![Bytes::from_static(b"\x1b]4;7;rgb:4444/5555/6666\x1b\\")]
+ );
+ }
+
+ #[test]
fn process_pty_bytes_returns_split_palette_color_query_response() {
let (tx, mut rx) = mpsc::channel(4);
let terminal = crate::ghostty::Terminal::new(20, 5, 0).unwrap();
@@ -5142,6 +5250,7 @@ mod tests {
g: 0x2b,
b: 0x36,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]4;0;?\x07\x1b]11;?\x07\x1b[c", &tx);
@@ -5172,6 +5281,7 @@ mod tests {
g: 0x2b,
b: 0x36,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]11;?\x07", &tx);
@@ -5200,6 +5310,7 @@ mod tests {
g: 0xf6,
b: 0xe3,
}),
+ ..Default::default()
});
let palette = pane.process_pty_bytes(pane_id, 0, b"\x1b]4;0;?;1;?\x1b\\", &tx);
@@ -5298,6 +5409,7 @@ mod tests {
b: 0x83,
}),
background: None,
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]12;?\x07", &tx);
@@ -5322,6 +5434,7 @@ mod tests {
b: 0x83,
}),
background: None,
+ ..Default::default()
});
pane.process_pty_bytes(pane_id, 0, b"\x1b]10;rgb:11/22/33\x07", &tx);
@@ -5347,6 +5460,7 @@ mod tests {
b: 0x83,
}),
background: None,
+ ..Default::default()
});
pane.process_pty_bytes(pane_id, 0, b"\x1b]12;rgb:11/22/33\x07", &tx);
@@ -5376,6 +5490,7 @@ mod tests {
g: 0xf6,
b: 0xe3,
}),
+ ..Default::default()
});
let result =
@@ -5405,6 +5520,7 @@ mod tests {
g: 0xf6,
b: 0xe3,
}),
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]11", &tx);
@@ -5435,6 +5551,7 @@ mod tests {
b: 0xe3,
}),
background: None,
+ ..Default::default()
});
let result = pane.process_pty_bytes(pane_id, 0, b"\x1b]12", &tx);
@@ -5465,6 +5582,7 @@ mod tests {
g: 0xf6,
b: 0xe3,
}),
+ ..Default::default()
});
let result =
@@ -5499,6 +5617,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
pane.apply_host_terminal_theme(host_theme);
{
@@ -5537,6 +5656,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
pane.apply_host_terminal_theme(host_theme);
{
@@ -5574,6 +5694,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
pane.apply_host_terminal_theme(host_theme);
{
@@ -5611,6 +5732,7 @@ mod tests {
g: 0x22,
b: 0x33,
}),
+ ..Default::default()
};
pane.apply_host_terminal_theme(host_theme);
{