Repository navigation
Description
Summary
The pane viewer (ui://libtmux-mcp/pane-viewer.html, added in #149) draws the cursor in the wrong column on any row holding a character whose cell width differs from its length as a JavaScript string. snapshot_pane reports cursor_x in terminal cells, as tmux counts them; the page uses cursor_x as an index into the row's string. A CJK character fills two cells but is one string element, so on a row reading ab日本語 tmux reports cursor_x 8, the string has 5 elements, and the page draws the cursor 3 columns past the text. Zero-width combining marks shift it the other way.
Reproduction
- Start a pane whose cursor stays right after wide characters:
$ tmux -L cjkrepro -f /dev/null new-session -d -x 30 -y 4 "printf 'ab日本語'; sleep 30"- From a libtmux-mcp checkout, take a snapshot and compare
cursor_xwith the row's length in UTF-16 code units, the unit JavaScript strings index by:
$ uv run python -c "from libtmux_mcp.tools.pane_tools.meta import snapshot_pane; s = snapshot_pane(socket_name='cjkrepro'); row = s.content.split(chr(10))[s.cursor_y]; print(repr(row), s.cursor_x, len(row.encode('utf-16-le')) // 2)"- Repeat with
printf 'e\314\201x'(anefollowed by U+0301 COMBINING ACUTE ACCENT, thenx) andprintf '\342\234\214x'(U+270C VICTORY HAND, thenx).
Expected
The cursor on the cell after the last character: string index 5 for ab日本語, 3 for éx, and 2 for ✌x.
Actual
| Row | cursor_x (cells) |
String length | Where the page draws the cursor |
|---|---|---|---|
ab日本語 |
8 | 5 | 3 columns past the text |
e + U+0301 + x |
2 | 3 | on the x |
✌x |
3 | 2 | 1 column past the text |
The page pads the row to cursor_x + 1 elements and marks element cursor_x:
Environment
Versions
- tmux 3.8a
- libtmux-mcp
mainat d503159 - Linux
Proposal
Map cells to string positions with the widths tmux uses, and draw each wide character two cells wide (for example an inline-block span 2ch wide) so the columns after it line up. tmux 3.8 resolves a width in utf8_width: first from its override table, which holds built-in entries such as U+270C at width 2 (utf8_default_width_cache) plus the codepoint-widths server option, then from utf8proc_wcwidth or the system wcwidth. A width table in the page will disagree with tmux wherever those sources differ, so the map's source is a design choice for the fix.
References
- mcp(feat): Confirm kill_session, add pane viewer and icons #149 adds the viewer; Pane viewer: render tmux colours from
capture-pane -e#151 adds colour, whose renderer places the cursor the same way - tmux
utf8.cat 3.8
Activity