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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! ANSI escape builders, byte-for-byte matching the `ansi-escapes` npm package
//! (`ink/node_modules/ansi-escapes/base.js`) for the small subset the
//! incremental line-diff transport uses.
//!
//! Provenance: every sequence below was captured from the oracle
//! (`node` against `ansi-escapes`) inside the ink repo, not written from
//! memory. `ESC` is `[` (CSI).
//!
//! Captured values:
//! - `cursorUp(0)` -> "[0A", `cursorUp(1)` -> "[1A", ...
//! - `cursorTo(0)` -> "[1G" (1-based column)
//! - `cursorNextLine` -> "[E"
//! - `eraseEndLine` -> "[K"
//! - `eraseLines(0)` -> "", `eraseLines(1)` -> "[2K[G",
//! `eraseLines(2)` -> "[2K[1A[2K[G", ...
/// CSI introducer: `ESC [`.
const ESC: &str = "\u{001B}[";
/// `ansiEscapes.cursorUp(count)` = `ESC + count + 'A'`.
/// `ansiEscapes.cursorDown(count)` = `ESC + count + 'B'`.
///
/// Used by the cursor transport's `buildReturnToBottom`
/// (`ink/src/cursor-helpers.ts:56-57`: `cursorDown(down)` when `down > 0`) to
/// walk the terminal cursor from a previously shown cursor position back down to
/// the bottom of the rendered frame before an erase or repaint. Oracle capture:
/// `cursorDown(1)` -> "[1B", `cursorDown(2)` -> "[2B".
/// `showCursorEscape` (`ink/src/cursor-helpers.ts:8`) = `ESC + '?25h'`.
/// Appended by `buildCursorSuffix` after repositioning a shown cursor.
pub const SHOW_CURSOR: &str = "\u{001B}[?25h";
/// `hideCursorEscape` (`ink/src/cursor-helpers.ts:9`) = `ESC + '?25l'`.
/// Emitted by `buildReturnToBottomPrefix`/`buildCursorOnlySequence` (hide-before-
/// move) and by `sync`'s `!activeCursor && cursorWasShown` clear branch.
pub const HIDE_CURSOR: &str = "\u{001B}[?25l";
/// `ansiEscapes.cursorTo(x)` for `y` omitted = `ESC + (x + 1) + 'G'`.
/// The transport only ever uses column 0.
/// `ansiEscapes.cursorNextLine` = `ESC + 'E'`.
/// `ansiEscapes.eraseEndLine` = `ESC + 'K'`.
/// `ansiEscapes.eraseLines(count)`: for each of `count` lines, emit
/// `eraseLine` (`ESC + '2K'`), and between lines (all but the last) a
/// `cursorUp()` (`ESC + '1A'`); after the loop, when `count > 0`, append
/// `cursorLeft` (`ESC + 'G'`). `count == 0` yields `""`.