Skip to content

Commit

Permalink
feat(ansi): add mode 2027
Browse files Browse the repository at this point in the history
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
  • Loading branch information
aymanbagabas committed Aug 21, 2024
1 parent 40aa88b commit d248756
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ansi/mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
3 changes: 2 additions & 1 deletion ansi/parser_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d248756

Please sign in to comment.