Skip to content

armgit / herdr

Public Imported from GitHub
0

the runtime your coding agents live on

fix: enable grapheme clusters in panes

Ogulcan Celikacfbb7c85a44
diff --git a/docs/next/CHANGELOG.md b/docs/next/CHANGELOG.md
index fb4e4cb2f..f0aeda9de 100644
--- a/docs/next/CHANGELOG.md
+++ b/docs/next/CHANGELOG.md
@@ -3,6 +3,7 @@
## Unreleased
### Fixed
+- Pane output now renders flag emoji and other multi-codepoint grapheme clusters as complete symbols instead of blank cells. (#243)
- Starting Herdr with no restored workspaces, or closing the last workspace, now opens a default workspace instead of leaving the client on an empty screen where direct keybindings such as `cmd+n` were shown but ignored. (#366)
- Resizing restored panes no longer aborts the server when libghostty-vt reflows a terminal whose pre-resize cursor row is past the new height. (#465)
- Full-screen TUIs such as Neovim now receive resize-generated terminal responses after Herdr internal pane resizes, so grown panes redraw without waiting for extra input. (#471)
diff --git a/src/ghostty/mod.rs b/src/ghostty/mod.rs
index a64fece1b..08d0e1175 100644
--- a/src/ghostty/mod.rs
+++ b/src/ghostty/mod.rs
@@ -161,6 +161,7 @@ pub const MODE_MOUSE_ALTERNATE_SCROLL: u16 = 1007;
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;
const KITTY_IMAGE_STORAGE_LIMIT_BYTES: u64 = 64 * 1024 * 1024;
const APC_MAX_BYTES: usize = 16 * 1024 * 1024;
@@ -678,6 +679,10 @@ impl Terminal {
unsafe { ffi::ghostty_terminal_mode_set(self.raw, mode, value).into_result() }
}
+ pub fn enable_grapheme_cluster_mode(&mut self) -> Result<(), Error> {
+ self.mode_set(MODE_GRAPHEME_CLUSTER, true)
+ }
+
pub fn kitty_keyboard_flags(&self) -> Result<u8, Error> {
let mut out = 0u8;
unsafe {
@@ -2961,6 +2966,43 @@ mod tests {
}
}
+ #[test]
+ fn grapheme_cluster_mode_keeps_issue_453_payload_safe() {
+ let mut terminal = Terminal::new(80, 3, 100).unwrap();
+ terminal.enable_grapheme_cluster_mode().unwrap();
+ terminal.write("README πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ πŸ§‘β€πŸ’» βœ… ⚑ ζΌ’ε­— cafΓ© é πŸ³οΈβ€πŸŒˆ πŸš€\r\n".as_bytes());
+
+ let mut render_state = RenderState::new().unwrap();
+ render_state.update(&terminal).unwrap();
+
+ let mut row_iterator = RowIterator::new().unwrap();
+ let mut rows = render_state
+ .populate_row_iterator(&mut row_iterator)
+ .unwrap();
+ let mut row_cells = RowCells::new().unwrap();
+ let mut codepoints = Vec::new();
+ let mut text = String::new();
+
+ while rows.next() {
+ let mut cells = rows.populate_cells(&mut row_cells).unwrap();
+ while cells.next() {
+ cells
+ .grapheme_text_into(&mut codepoints, &mut text)
+ .unwrap();
+ }
+ }
+ }
+
+ #[test]
+ fn grapheme_cluster_mode_is_default_and_survives_full_reset() {
+ let mut terminal = Terminal::new(80, 3, 100).unwrap();
+ assert!(terminal.mode_get(MODE_GRAPHEME_CLUSTER).unwrap());
+
+ terminal.write(b"\x1bc");
+
+ assert!(terminal.mode_get(MODE_GRAPHEME_CLUSTER).unwrap());
+ }
+
#[test]
fn render_state_row_dirty_can_be_cleared_independently() {
let mut terminal = Terminal::new(8, 3, 100).unwrap();
diff --git a/src/pane.rs b/src/pane.rs
index 19556ffee..214eeef2f 100644
--- a/src/pane.rs
+++ b/src/pane.rs
@@ -1284,6 +1284,9 @@ impl PaneRuntime {
let (response_tx, _response_rx) = mpsc::channel::<Bytes>(1);
let mut terminal = crate::ghostty::Terminal::new(cols, rows, scrollback_limit_bytes)
.map_err(|e| std::io::Error::other(e.to_string()))?;
+ terminal
+ .enable_grapheme_cluster_mode()
+ .map_err(|e| std::io::Error::other(e.to_string()))?;
if crate::kitty_graphics::is_enabled() {
terminal
.enable_kitty_graphics()
@@ -1395,6 +1398,9 @@ impl PaneRuntime {
let (response_tx, _response_rx) = mpsc::channel::<Bytes>(1);
let mut terminal = crate::ghostty::Terminal::new(cols, rows, scrollback_limit_bytes)
.map_err(|e| std::io::Error::other(e.to_string()))?;
+ terminal
+ .enable_grapheme_cluster_mode()
+ .map_err(|e| std::io::Error::other(e.to_string()))?;
if crate::kitty_graphics::is_enabled() {
terminal
.enable_kitty_graphics()
diff --git a/src/pane/terminal.rs b/src/pane/terminal.rs
index f2fceaa81..cf8506bad 100644
--- a/src/pane/terminal.rs
+++ b/src/pane/terminal.rs
@@ -2432,6 +2432,8 @@ mod tests {
#[test]
fn ghostty_normalize_buffer_symbol_prefers_grapheme_width_when_metadata_disagrees() {
const WIDE_GRAPHEME: &str = "πŸ™‚";
+ const FLAG_GRAPHEME: &str = "πŸ‡§πŸ‡·";
+ const FAMILY_GRAPHEME: &str = "πŸ‘¨β€πŸ‘©β€πŸ‘§";
const VS16_GRAPHEME: &str = "⚠️";
const EMOJI_GRAPHEME: &str = "πŸ’³";
@@ -2443,6 +2445,14 @@ mod tests {
ghostty_normalize_buffer_symbol("a", crate::ghostty::CellWide::Wide),
" "
);
+ assert_eq!(
+ ghostty_normalize_buffer_symbol(FLAG_GRAPHEME, crate::ghostty::CellWide::Wide),
+ FLAG_GRAPHEME
+ );
+ assert_eq!(
+ ghostty_normalize_buffer_symbol(FAMILY_GRAPHEME, crate::ghostty::CellWide::Wide),
+ FAMILY_GRAPHEME
+ );
assert_eq!(
ghostty_normalize_buffer_symbol("⌨️", crate::ghostty::CellWide::Narrow),
"⌨️"
@@ -2465,6 +2475,74 @@ mod tests {
);
}
+ fn render_cells_to_symbols(
+ terminal: &mut crate::ghostty::Terminal,
+ ) -> Vec<(crate::ghostty::CellWide, String)> {
+ let mut render_state = crate::ghostty::RenderState::new().unwrap();
+ render_state.update(terminal).unwrap();
+
+ let mut row_iterator = crate::ghostty::RowIterator::new().unwrap();
+ let mut rows = render_state
+ .populate_row_iterator(&mut row_iterator)
+ .unwrap();
+ let mut row_cells = crate::ghostty::RowCells::new().unwrap();
+ let mut grapheme_codepoints = Vec::new();
+ let mut symbol_scratch = String::new();
+ let mut out = Vec::new();
+
+ if rows.next() {
+ let mut cells = rows.populate_cells(&mut row_cells).unwrap();
+ while cells.next() {
+ let wide = cells.wide().unwrap_or(crate::ghostty::CellWide::Narrow);
+ let symbol = ghostty_buffer_symbol_into(
+ &cells,
+ wide,
+ false,
+ &mut grapheme_codepoints,
+ &mut symbol_scratch,
+ )
+ .unwrap()
+ .to_string();
+ out.push((wide, symbol));
+ }
+ }
+
+ out
+ }
+
+ #[test]
+ fn grapheme_cluster_mode_renders_flag_emoji_in_single_wide_cell() {
+ let mut terminal = crate::ghostty::Terminal::new(40, 1, 0).unwrap();
+ terminal.enable_grapheme_cluster_mode().unwrap();
+ terminal.write("πŸ‡§πŸ‡·".as_bytes());
+
+ let cells = render_cells_to_symbols(&mut terminal);
+
+ assert!(
+ cells
+ .iter()
+ .any(|(wide, symbol)| *wide == crate::ghostty::CellWide::Wide && symbol == "πŸ‡§πŸ‡·"),
+ "expected a wide cell containing the full flag grapheme, got {cells:?}"
+ );
+ }
+
+ #[test]
+ fn grapheme_cluster_mode_renders_zwj_family_in_single_wide_cell() {
+ let mut terminal = crate::ghostty::Terminal::new(40, 1, 0).unwrap();
+ terminal.enable_grapheme_cluster_mode().unwrap();
+ terminal.write("πŸ‘¨\u{200d}πŸ‘©\u{200d}πŸ‘§".as_bytes());
+
+ let cells = render_cells_to_symbols(&mut terminal);
+
+ assert!(
+ cells
+ .iter()
+ .any(|(wide, symbol)| *wide == crate::ghostty::CellWide::Wide
+ && symbol == "πŸ‘¨\u{200d}πŸ‘©\u{200d}πŸ‘§"),
+ "expected a wide cell containing the full ZWJ grapheme, got {cells:?}"
+ );
+ }
+
#[test]
fn pane_scrollback_controls_reach_top_without_ui_interference() {
let (tx, _rx) = mpsc::channel(4);
diff --git a/vendor/libghostty-vt/src/terminal/c/terminal.zig b/vendor/libghostty-vt/src/terminal/c/terminal.zig
index 39959f83b..a7ad35a60 100644
--- a/vendor/libghostty-vt/src/terminal/c/terminal.zig
+++ b/vendor/libghostty-vt/src/terminal/c/terminal.zig
@@ -263,6 +263,7 @@ fn new_(
.cols = opts.cols,
.rows = opts.rows,
.max_scrollback = opts.max_scrollback,
+ .default_modes = .{ .grapheme_cluster = true },
});
errdefer t.deinit(alloc);