From 25f081da1dd71f25328daf554fd18c2d811bd429 Mon Sep 17 00:00:00 2001 From: dj-oyu <68707227+dj-oyu@users.noreply.github.com> Date: Fri, 20 Feb 2026 01:28:38 +0900 Subject: [PATCH] telegram: tune table width with emoji-aware display width --- pkg/channels/telegram.go | 9 +++++++++ pkg/channels/telegram_test.go | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index 23c1246af..d5863ec5a 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -771,6 +771,8 @@ func displayWidth(s string) int { continue case unicode.Is(unicode.Mn, r): continue + case isEmojiRune(r): + w += 3 case unicode.In(r, unicode.Han, unicode.Hiragana, @@ -787,6 +789,13 @@ func displayWidth(s string) int { return w } +func isEmojiRune(r rune) bool { + // Common emoji blocks + Dingbats/Stars used in rating tables. + return (r >= 0x1F300 && r <= 0x1FAFF) || // Misc emoji/pictographs/symbols + (r >= 0x2600 && r <= 0x27BF) || // Misc symbols + dingbats + r == 0x2B50 // WHITE MEDIUM STAR (⭐) +} + func wrapByDisplayWidth(s string, maxWidth int) []string { if maxWidth <= 0 { return []string{s} diff --git a/pkg/channels/telegram_test.go b/pkg/channels/telegram_test.go index ba0876721..6afcc1ff9 100644 --- a/pkg/channels/telegram_test.go +++ b/pkg/channels/telegram_test.go @@ -79,3 +79,10 @@ func TestMarkdownToTelegramHTML_TableWrapsLongCell(t *testing.T) { t.Fatalf("expected wrapped long cell content, got: %q", got) } } + +func TestDisplayWidth_EmojiIsThree(t *testing.T) { + got := displayWidth("⭐⭐⭐⭐⭐") + if got != 15 { + t.Fatalf("displayWidth(stars) = %d, want 15", got) + } +}