|
3 | 3 | //! |
4 | 4 | //! How the OSC 8 plumbing works: ratatui's `Buffer` stores per-cell symbol strings that the |
5 | 5 | //! crossterm backend prints verbatim. We collapse the whole linked row into the first cell's |
6 | | -//! symbol — `ESC ] 8 ; ; URL ESC \\ <text> ESC ] 8 ; ; ESC \\` — and mark the trailing cells with |
7 | | -//! `skip = true` so ratatui's diff doesn't try to redraw them. That keeps the OSC 8 sequence |
8 | | -//! atomic in the byte stream (no `MoveTo` interruption), and dodges `Buffer::diff`'s width |
9 | | -//! calculation, which would otherwise count the printable characters inside the escape sequence |
10 | | -//! as visible columns and incorrectly skip the cells immediately after the link. |
| 6 | +//! symbol — `ESC ] 8 ; ; URL ESC \\ <text> ESC ] 8 ; ; ESC \\` — pin its diff width to 1 via |
| 7 | +//! `CellDiffOption::ForcedWidth(1)`, and mark the trailing cells with `CellDiffOption::Skip` so |
| 8 | +//! ratatui's diff doesn't try to redraw them. The `ForcedWidth(1)` matters because ratatui 0.30's |
| 9 | +//! diff iterator advances by the cell's computed `cell_width` for non-skip cells; without the |
| 10 | +//! pin, the printable characters inside the escape sequence (URL, visible text) would be counted |
| 11 | +//! as visible columns and the iterator would jump far past the trailing cells — even spilling |
| 12 | +//! into the next row — so subsequent rows would never be diffed and would render blank. |
11 | 13 | //! |
12 | 14 | //! The `skip = true` trick only buys real-terminal correctness: `TestBackend` doesn't |
13 | 15 | //! simulate the terminal's char-rendering of the OSC 8 visible portion, so the skipped cells |
|
17 | 19 | //! capture, while the on-screen `CrosstermBackend` pass keeps the OSC 8 wrap. |
18 | 20 |
|
19 | 21 | use std::cell::Cell as StdCell; |
| 22 | +use std::num::NonZeroU16; |
20 | 23 |
|
21 | | -use ratatui::{Frame, buffer::Buffer, layout::Rect, style::Style}; |
| 24 | +use ratatui::{Frame, buffer::Buffer, buffer::CellDiffOption, layout::Rect, style::Style}; |
22 | 25 |
|
23 | 26 | use crate::options::OptionSchema; |
24 | 27 | use crate::payload::{Body, LinkedLine, LinkedTextBlockData}; |
@@ -156,25 +159,28 @@ fn osc8_suppressed() -> bool { |
156 | 159 | } |
157 | 160 |
|
158 | 161 | /// Re-export of the OSC 8 wrapping helper so sibling renderers (`list_cards`) can reuse the |
159 | | -/// `set_skip` plumbing without duplicating the escape-sequence dance. |
| 162 | +/// diff-option plumbing without duplicating the escape-sequence dance. |
160 | 163 | pub(crate) fn wrap_osc8(buf: &mut Buffer, x: u16, y: u16, end_x: u16, url: &str, style: Style) { |
161 | 164 | if osc8_suppressed() { |
162 | 165 | return; |
163 | 166 | } |
164 | 167 | wrap_link(buf, x, y, end_x, url, style); |
165 | 168 | } |
166 | 169 |
|
| 170 | +const FORCED_WIDTH_1: CellDiffOption = CellDiffOption::ForcedWidth(NonZeroU16::new(1).unwrap()); |
| 171 | + |
167 | 172 | fn wrap_link(buf: &mut Buffer, x: u16, y: u16, end_x: u16, url: &str, style: Style) { |
168 | 173 | let visible: String = (x..end_x) |
169 | 174 | .filter_map(|col| buf.cell((col, y)).map(|c| c.symbol().to_string())) |
170 | 175 | .collect(); |
171 | 176 | if let Some(cell) = buf.cell_mut((x, y)) { |
172 | 177 | cell.set_symbol(&format!("\x1b]8;;{url}\x1b\\{visible}\x1b]8;;\x1b\\")); |
173 | 178 | cell.set_style(style); |
| 179 | + cell.set_diff_option(FORCED_WIDTH_1); |
174 | 180 | } |
175 | 181 | for col in (x + 1)..end_x { |
176 | 182 | if let Some(cell) = buf.cell_mut((col, y)) { |
177 | | - cell.set_skip(true); |
| 183 | + cell.set_diff_option(CellDiffOption::Skip); |
178 | 184 | } |
179 | 185 | } |
180 | 186 | } |
|
0 commit comments