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
//! Terminal cell-width helpers.
//!
//! `chars().count()` counts code points, but terminal layout cares
//! about *cells*: a CJK glyph (e.g. `あ`) renders as two cells, ASCII
//! as one, and most control / zero-width chars contribute nothing
//! visible. Mixing these up makes the editor cursor drift past
//! fullwidth text and makes popup panels mis-size when their content
//! contains Japanese, emoji, or other wide characters.
//!
//! These helpers are the single source of truth for that math.
use ;
/// Cell width of `ch`. Wide East-Asian glyphs and most emoji count
/// as 2; zero-width / control chars are clamped up to 1 so a cursor
/// or per-char rendering loop always has at least one cell to place
/// the glyph in.
/// Total cell width of `s`. Tabs count as one cell here — callers
/// that expand tabs do so themselves; this helper is for content that
/// will never see tab expansion (status bar, popups, list items).
/// Visual column the character at `char_col` lands on within `line`,
/// once tabs are expanded to the next `tab_width`-aligned stop and
/// every other char contributes its terminal-cell width. Returns the
/// position *before* the char at `char_col` (i.e. the count of cells
/// consumed by the preceding prefix), so the result doubles as "x
/// offset to draw the cursor at".
///
/// Callers that work in App context use [`crate::app::App::char_col_visual`];
/// this is the underlying pure helper.
/// Take as many leading characters of `s` as fit within `max` cells.
/// Returns the byte length of that prefix so callers can slice the
/// original string (`&s[..len]`) without an allocation.