1010from dataclasses import dataclass , field
1111
1212from libvt ._grid import WidthRole , _Row , raw_width_bits
13+ from libvt ._ucd import display_width
1314from libvt .config import (
1415 DEFAULT_LIMITS ,
1516 Limits ,
2728from libvt .parser import CsiParams , Parser , _parse_ascii_int , _parse_ascii_uint
2829from libvt .screen import CursorShape , Screen , ScrollRegion
2930from libvt .style import DEFAULT_STYLE
30- from libvt .terminal import Snapshot , Terminal
31+ from libvt .terminal import Snapshot , Terminal , strip
3132
3233#: Accepted input payload shapes for ``tmux capture-pane`` decoders.
3334type CaptureInput = str | bytes | bytearray | collections .abc .Sequence [str ]
@@ -456,8 +457,9 @@ class CaptureCompleteness:
456457 Attributes
457458 ----------
458459 exact_cells : bool
459- ``True`` when cell glyphs, styles, and tab expansions were decoded from
460- ``-e -p -N`` (or ``-e -p -N -T``) output.
460+ Whether the capture can certify cell positions and styles. A widening
461+ emoji presentation selector from a server older than 3.5 leaves its
462+ native columns unverified.
461463 exact_wraps : bool
462464 ``True`` when soft-wrap flags came from ``-F`` or an exact ``-J``
463465 companion capture.
@@ -737,6 +739,19 @@ def _row_trimmed_text_and_cols(row: _Row) -> tuple[str, int]:
737739 return row .slice_text (0 , t_end ), t_end
738740
739741
742+ def _has_widening_selector (lines : list [str ]) -> bool :
743+ """Test captured text using the producer's tmux width rules."""
744+ for line in lines :
745+ if "\ufe0f " in line :
746+ text = strip (line .encode ("utf-8" , errors = "surrogateescape" ))
747+ without_selector = text .replace ("\ufe0f " , "" )
748+ if display_width (text , profile = TMUX_PROFILE ) > display_width (
749+ without_selector , profile = TMUX_PROFILE
750+ ):
751+ return True
752+ return False
753+
754+
740755def _infer_wraps_from_joined (
741756 plain_rows : list [str ],
742757 joined_raw : CaptureInput ,
@@ -1156,6 +1171,7 @@ def decode_tmux_capture(
11561171 saved_primary_trim_trailing : bool | None = None ,
11571172 saved_primary_joined_capture : CaptureInput | None = None ,
11581173 post_metadata : TmuxPaneMetadata | str | None = None ,
1174+ tmux_version : tuple [int , int ] | str | None = None ,
11591175 profile : Profile = TMUX_PROFILE ,
11601176 policy : Policy = TMUX_CAPTURE_POLICY ,
11611177 limits : Limits = DEFAULT_LIMITS ,
@@ -1217,6 +1233,10 @@ def decode_tmux_capture(
12171233 post_metadata : TmuxPaneMetadata | str | None
12181234 Optional second metadata sample taken immediately after ``capture-pane``
12191235 to verify ``pane_output_generation`` stability.
1236+ tmux_version : tuple[int, int] | str | None
1237+ Release that produced the capture. Before tmux 3.5, a widening
1238+ emoji selector can shift the next captured cell. An unknown release
1239+ receives the same qualification in the completeness report.
12201240 profile : Profile
12211241 Compatibility profile for the reconstructed terminal.
12221242 policy : Policy
@@ -1252,6 +1272,7 @@ def decode_tmux_capture(
12521272 r0[0..5]: fg=green
12531273 """
12541274 eff_hist_req = _validate_history_lines (history_lines )
1275+ legacy_width = tmux_version is None or parse_tmux_version (tmux_version ) < (3 , 5 )
12551276 fallback_sb = 2_000 if scrollback is None else scrollback
12561277 if isinstance (metadata , str ):
12571278 meta = TmuxPaneMetadata .from_format_line (metadata )
@@ -1293,6 +1314,7 @@ def decode_tmux_capture(
12931314 term ._tabstops_from_list (term .screens .alternate , tabstops )
12941315
12951316 raw_lines = _split_capture_lines (captured )
1317+ unverified_width = legacy_width and _has_widening_selector (raw_lines )
12961318 stripped_trailing = 0
12971319 expected_hist = (
12981320 meta .history_size
@@ -1330,6 +1352,8 @@ def decode_tmux_capture(
13301352
13311353 if saved_primary_capture is not None :
13321354 prim_lines = _split_capture_lines (saved_primary_capture )
1355+ if legacy_width and not unverified_width :
1356+ unverified_width = _has_widening_selector (prim_lines )
13331357 prim_flagged = (
13341358 flagged if saved_primary_flagged is None else saved_primary_flagged
13351359 )
@@ -1546,6 +1570,8 @@ def decode_tmux_capture(
15461570 unexposed .discard ("cursor_shape" )
15471571 if uncalibrated_tabs :
15481572 unexposed .add ("pane_tabs" )
1573+ if unverified_width :
1574+ unexposed .add ("grapheme_widths" )
15491575 if not exact_wraps :
15501576 unexposed .add ("soft_wraps" )
15511577 if meta .alternate_on and saved_primary_capture is None :
@@ -1564,7 +1590,7 @@ def decode_tmux_capture(
15641590 == (meta .cols , meta .rows , meta .alternate_on , meta .history_size )
15651591 )
15661592 completeness = CaptureCompleteness (
1567- exact_cells = not uncalibrated_tabs ,
1593+ exact_cells = not ( uncalibrated_tabs or unverified_width ) ,
15681594 exact_wraps = exact_wraps ,
15691595 exact_generation_bracket = exact_gen ,
15701596 unexposed_fields = frozenset (unexposed ),
@@ -1760,6 +1786,7 @@ def parse(
17601786 saved_primary_flagged = self .flagged ,
17611787 saved_primary_trim_trailing = self .trim_trailing ,
17621788 saved_primary_joined_capture = saved_joined_lines ,
1789+ tmux_version = self .tmux_version ,
17631790 profile = tmux_profile (self .tmux_version ) if profile is None else profile ,
17641791 policy = policy ,
17651792 limits = limits ,
0 commit comments