package displaywidth

Import Path
	github.com/clipperhouse/displaywidth (on go.dev)

Dependency Relation
	imports 3 packages, and imported by 2 packages


Package-Level Type Names (total 3, in which 2 are exported)
/* sort exporteds by: | */
Type Parameters: T: ~string | []byte Graphemes is an iterator over grapheme clusters. Iterate using the Next method, and get the width of the current grapheme using the Width method. Next advances the iterator to the next grapheme cluster. Value returns the current grapheme cluster. Width returns the display width of the current grapheme cluster. func BytesGraphemes(s []byte) Graphemes[[]byte] func StringGraphemes(s string) Graphemes[string] func Options.BytesGraphemes(s []byte) Graphemes[[]byte] func Options.StringGraphemes(s string) Graphemes[string]
Options allows you to specify the treatment of ambiguous East Asian characters and ANSI escape sequences. ControlSequences specifies whether to ignore 7-bit ECMA-48 escape sequences when calculating the display width. When false (default), ANSI escape sequences are treated as just a series of characters. When true, they are treated as a single zero-width unit. ControlSequences8Bit specifies whether to ignore 8-bit ECMA-48 escape sequences when calculating the display width. When false (default), these are treated as just a series of characters. When true, they are treated as a single zero-width unit. EastAsianWidth specifies whether to treat ambiguous East Asian characters as width 1 or 2. When false (default), ambiguous East Asian characters are treated as width 1. When true, they are width 2. Bytes calculates the display width of a []byte, for the given options, by iterating over grapheme clusters in the slice and summing their widths. BytesGraphemes returns an iterator over grapheme clusters for the given []byte, with the given options. Iterate using the Next method, and get the width of the current grapheme using the Width method. Rune calculates the display width of a rune, for the given options. You should almost certainly use [String] or [Bytes] for most purposes. The smallest unit of display width is a grapheme cluster, not a rune. Iterating over runes to measure width is incorrect in many cases. String calculates the display width of a string, for the given options, by iterating over grapheme clusters in the string and summing their widths. StringGraphemes returns an iterator over grapheme clusters for the given string, with the given options. Iterate using the Next method, and get the width of the current grapheme using the Width method. TruncateBytes truncates a []byte to the given maxWidth, and appends the given tail if the []byte is truncated. It ensures the visible width, including the width of the tail, is less than or equal to maxWidth. When [Options.ControlSequences] is true, 7-bit ANSI escape sequences that appear after the truncation point are preserved in the output. This ensures that escape sequences such as SGR resets are not lost, preventing color bleed in terminal output. [Options.ControlSequences8Bit] is ignored by truncation. 8-bit C1 byte values (0x80-0x9F) overlap with UTF-8 multi-byte encoding, so manipulating them during truncation can shift byte boundaries and form unintended visible characters. Use [Options.String] or [Options.Bytes] for 8-bit-aware width measurement. TruncateString truncates a string to the given maxWidth, and appends the given tail if the string is truncated. It ensures the visible width, including the width of the tail, is less than or equal to maxWidth. When [Options.ControlSequences] is true, 7-bit ANSI escape sequences that appear after the truncation point are preserved in the output. This ensures that escape sequences such as SGR resets are not lost, preventing color bleed in terminal output. [Options.ControlSequences8Bit] is ignored by truncation. 8-bit C1 byte values (0x80-0x9F) overlap with UTF-8 multi-byte encoding, so manipulating them during truncation can shift byte boundaries and form unintended visible characters. Use [Options.String] or [Options.Bytes] for 8-bit-aware width measurement. var DefaultOptions
Package-Level Functions (total 13, in which 7 are exported)
Bytes calculates the display width of a []byte, by iterating over grapheme clusters in the byte slice and summing their widths.
BytesGraphemes returns an iterator over grapheme clusters for the given []byte. Iterate using the Next method, and get the width of the current grapheme using the Width method.
Rune calculates the display width of a rune. You should almost certainly use [String] or [Bytes] for most purposes. The smallest unit of display width is a grapheme cluster, not a rune. Iterating over runes to measure width is incorrect in many cases.
String calculates the display width of a string, by iterating over grapheme clusters in the string and summing their widths.
StringGraphemes returns an iterator over grapheme clusters for the given string. Iterate using the Next method, and get the width of the current grapheme using the Width method.
TruncateBytes truncates a []byte to the given maxWidth, and appends the given tail if the []byte is truncated. It ensures the total width, including the width of the tail, is less than or equal to maxWidth.
TruncateString truncates a string to the given maxWidth, and appends the given tail if the string is truncated. It ensures the total width, including the width of the tail, is less than or equal to maxWidth.
Package-Level Variables (total 4, in which 1 is exported)
DefaultOptions is the default options for the display width calculation, which is EastAsianWidth false, ControlSequences false, and ControlSequences8Bit false.
Package-Level Constants (total 5, none are exported)