平衡点
2026/11/12
_ tmux での結合文字処理: VS15 編
はじめに
最近の tmux には
set -s variation-selector-always-wide on
という設定があります. これは「VS16 を含む emoji presentation は wideとして扱う」という処理を行なっています. 絵文字が綺麗に表示されて嬉しいですね.
コード自体は utf8-combined.c
/* Is this variation selector U+FE0F? */
int
utf8_is_vs(const struct utf8_data *ud)
{
if (ud->size != 3)
return (0);
return (memcmp(ud->data, "\357\270\217", 3) == 0);
}
と screen-write.c の
/* Combine a UTF-8 zero-width character onto the previous if necessary. */
static int
screen_write_combine(struct screen_write_ctx *ctx, const struct grid_cell *gc)
{
...
/*
* Is this character which makes no sense without being combined? If
* this is true then flag it here and discard the character (return 1)
* if we cannot combine it.
*/
if (utf8_is_zwj(ud))
zero_width = 1;
else if (utf8_is_vs(ud)) {
zero_width = 1;
if (options_get_number(oo, "variation-selector-always-wide"))
force_wide = 1;
} else if (ud->width == 0)
zero_width = 1;
...
/*
* Redraw the combined cell. If forcing the cell to width 2, reset the
* cached cursor position in the tty, since we don't really know
* whether the terminal thought the character was width 1 or width 2
* and what it is going to do now.
*/
screen_write_set_cursor(ctx, cx - n, cy);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.cell = &last;
if (force_wide)
ttyctx.flags |= TTY_CTX_CELL_INVALIDATE;
if (screen_write_should_draw_line(ctx, cy))
tty_write(tty_cmd_cell, &ttyctx);
screen_write_set_cursor(ctx, cx, cy);
return (1);
}
といった辺りかな.
処理としては どんな文字でも 0xFE0F が後置されていたら全角幅で表示する, でしょうか.
0xFE0F がつくのは主に絵文字なので, 処理としてはこれで良いかもしれません.
何がしたいの?
で, 本題.
VS15 というセレクタが付いた文字が weechat on tmux に入ってきて pane 罫線がブレブレになりました.
Variation Selector には
- VS16(
0xFE0F): emoji-style with color - VS15(
0xFE0E): text-style with monochrome
と二つがあって
- 文字 +
0xFE0F→ (色付き)絵文字, 全角幅 - 絵文字 +
0xFE0E→ 文字, 半角全角は East Asian ambiguous char Width の扱い次第
となるわけですね.
現在使っているターミナルは foot もしくは Ghostty なので, East Asian ambiguous char Width で N, A は半角幅にしています. なので VS15 が後置されている文字は強制的に文字幅を減らしたい, と考えます.
どうするの?: tmux の修正
こういうのはどうかな?
From: Youhei SASAKI <uwabami@gfd-dennou.org>
Date: Thu, 12 Nov 2026 10:19:32 +0900
Subject: Handling VS15 selector
Signed-off-by: Youhei SASAKI <uwabami@gfd-dennou.org>
---
screen-write.c | 22 ++++++++++++++++++----
utf8-combined.c | 6 +++++-
2 files changed, 23 insertions(+), 5 deletions(-)
--- a/screen-write.c
+++ b/screen-write.c
@@ -2859,6 +2859,7 @@
struct tty_ctx ttyctx;
int force_wide = 0, zero_width = 0;
int xoff = 0, yoff = 0;
+ int force_narrow = 0, vs;
struct visible_ranges *r;
/* Ignore U+3164 HANGUL_FILLER entirely. */
@@ -2872,10 +2873,14 @@
*/
if (utf8_is_zwj(ud))
zero_width = 1;
- else if (utf8_is_vs(ud)) {
+ else if ((vs = utf8_is_vs(ud)) != 0) {
zero_width = 1;
- if (options_get_number(oo, "variation-selector-always-wide"))
- force_wide = 1;
+ if (vs == 16) {
+ if (options_get_number(oo, "variation-selector-always-wide"))
+ force_wide = 1;
+ } else if (vs == 15) {
+ force_narrow = 1;
+ }
} else if (ud->width == 0)
zero_width = 1;
@@ -2942,6 +2947,15 @@
} else
force_wide = 0;
+ /* Force the width to 1 for variation selector 15 (U+FE0E). */
+ if (last.data.width == 2 && force_narrow) {
+ last.data.width = 1;
+ n = 1;
+ cx--;
+ grid_view_set_cell(gd, cx, cy, &grid_default_cell);
+ } else
+ force_narrow = 0;
+
/* Set the new cell. */
grid_view_set_cell(gd, cx - n, cy, &last);
if (force_wide)
@@ -2976,7 +2990,7 @@
screen_write_set_cursor(ctx, cx - n, cy);
screen_write_initctx(ctx, &ttyctx, 0, 0);
ttyctx.cell = &last;
- if (force_wide)
+ if (force_wide || force_narrow)
ttyctx.flags |= TTY_CTX_CELL_INVALIDATE;
if (screen_write_should_draw_line(ctx, cy))
tty_write(tty_cmd_cell, &ttyctx);
--- a/utf8-combined.c
+++ b/utf8-combined.c
@@ -70,7 +70,11 @@
{
if (ud->size != 3)
return (0);
- return (memcmp(ud->data, "\357\270\217", 3) == 0);
+ if (memcmp(ud->data, "\357\270\217", 3) == 0)
+ return (16);
+ if (memcmp(ud->data, "\357\270\216", 3) == 0)
+ return (15);
+ return (0);
}
/* Is this Hangul filler U+3164? */
オプションで処理を切り替えられた方が良いかも.
結論
とりあえず
printf "\r\u26aa\ufe0e\e[6n"; IFS=';' read -rs -d R _ col; echo " col=$col"
の結果が foot でも tmux でも
⚪︎ col=2
に揃う様になったのでヨシとする…?
いや, 多分 emoji-variation-sequences.txt を確認してちゃんと処理しないといけないんだろうけど.
また困ったら考えよう.
[ツッコミを入れる]