From d2487560a48ca447665c6f6b386a2e8c89d795c0 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Wed, 21 Aug 2024 16:31:30 -0400 Subject: [PATCH] feat(ansi): add mode 2027 This adds the necessary sequences to enable/disable/request mode 2027 (grapheme clustering). See https://mitchellh.com/writing/grapheme-clusters-in-terminals See https://github.com/contour-terminal/terminal-unicode-core --- ansi/mode.go | 12 ++++++++++++ ansi/parser_decode.go | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ansi/mode.go b/ansi/mode.go index a7bdda4..7d25ddc 100644 --- a/ansi/mode.go +++ b/ansi/mode.go @@ -130,6 +130,18 @@ const ( RequestSyncdOutput = "\x1b[?2026$p" ) +// Grapheme Clustering Mode is a mode that determines whether the terminal +// should look for grapheme clusters instead of single runes in the rendered +// text. This makes the terminal properly render combining characters such as +// emojis. +// +// See: https://github.com/contour-terminal/terminal-unicode-core +const ( + EnableGraphemeClustering = "\x1b[?2027h" + DisableGraphemeClustering = "\x1b[?2027l" + RequestGraphemeClustering = "\x1b[?2027$p" +) + // Win32Input is a mode that determines whether input is processed by the // Win32 console and Conpty. // diff --git a/ansi/parser_decode.go b/ansi/parser_decode.go index cfe915d..76688d0 100644 --- a/ansi/parser_decode.go +++ b/ansi/parser_decode.go @@ -30,7 +30,8 @@ const ( // The cell width will always be 0 for control and escape sequences, 1 for // ASCII printable characters, and the number of cells other Unicode characters // occupy. It uses the uniseg package to calculate the width of Unicode -// graphemes and characters. +// graphemes and characters. This means it will always do grapheme clustering +// (mode 2027). // // Passing a non-nil [*Parser] as the last argument will allow the decoder to // collect sequence parameters, data, and commands. The parser cmd will have