Skip to content

Commit d248756

Browse files
committed
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
1 parent 40aa88b commit d248756

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

ansi/mode.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ const (
130130
RequestSyncdOutput = "\x1b[?2026$p"
131131
)
132132

133+
// Grapheme Clustering Mode is a mode that determines whether the terminal
134+
// should look for grapheme clusters instead of single runes in the rendered
135+
// text. This makes the terminal properly render combining characters such as
136+
// emojis.
137+
//
138+
// See: https://github.com/contour-terminal/terminal-unicode-core
139+
const (
140+
EnableGraphemeClustering = "\x1b[?2027h"
141+
DisableGraphemeClustering = "\x1b[?2027l"
142+
RequestGraphemeClustering = "\x1b[?2027$p"
143+
)
144+
133145
// Win32Input is a mode that determines whether input is processed by the
134146
// Win32 console and Conpty.
135147
//

ansi/parser_decode.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ const (
3030
// The cell width will always be 0 for control and escape sequences, 1 for
3131
// ASCII printable characters, and the number of cells other Unicode characters
3232
// occupy. It uses the uniseg package to calculate the width of Unicode
33-
// graphemes and characters.
33+
// graphemes and characters. This means it will always do grapheme clustering
34+
// (mode 2027).
3435
//
3536
// Passing a non-nil [*Parser] as the last argument will allow the decoder to
3637
// collect sequence parameters, data, and commands. The parser cmd will have

0 commit comments

Comments
 (0)