1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! How many cells text takes on a terminal, measured as Go's
//! `charmbracelet/x/ansi` v0.12.0 measures it: `WcWidth` (each code point
//! on its own, as `wcwidth` does) or `GraphemeWidth` (each grapheme
//! cluster as a whole).
//!
//! The tables are generated from the Go packages by
//! scripts/gen-width-tables.py, and tests/fixtures/width.tsv holds what Go
//! answers for a few thousand strings.
/// How text width is measured. Go's `ansi.Method`.
///
/// A program measures with [`WidthMethod::WcWidth`] until the terminal
/// reports that it supports grapheme clusters (mode 2027), as Bubble Tea
/// does; [`crate::style::width`] follows the running program's choice.
///
/// ```
/// use petitcarnets as tea;
/// use tea::style::WidthMethod;
///
/// // A thumbs up with a skin tone: two code points, one grapheme.
/// let thumb = "\u{1f44d}\u{1f3fd}";
/// assert_eq!(WidthMethod::WcWidth.string_width(thumb), 4);
/// assert_eq!(WidthMethod::GraphemeWidth.string_width(thumb), 2);
/// assert_eq!(
/// WidthMethod::GraphemeWidth.string_width("\x1b[1mok\x1b[0m"),
/// 2
/// );
/// ```
/// The first grapheme cluster of `s` and its width: Go's
/// `ansi.FirstGraphemeCluster`. An empty `s` gives an empty cluster.
pub