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
//! utils/clear_cli.rs
//!
//! Minimal console clear utilities using ANSI escape sequences only.
//! These functions assume an ANSI-capable terminali.
//! # Examples
//!
//! ```
//! use stdt::utils::clear_cli::*;
//!
//! // Clear screen + move cursor to top-left + attempt to clear scrollback.
//! clear().unwrap();
//!
//! // Or write to any `Write` target:
//! let mut buf = Vec::new();
//! write_clear(&mut buf).unwrap();
//! assert_eq!(buf, b"\x1b[H\x1b[2J\x1b[3J");
//! ```
use ;
/// ANSI sequence that:
/// - moves the cursor to the home position (`ESC[H`)
/// - clears the visible screen (`ESC[2J`)
/// - attempts to clear the scrollback buffer (`ESC[3J`)
///
/// This constant is private by design; use [`write_clear`] or [`clear`].
const CLEAR_SEQ: &str = "\x1b[H\x1b[2J\x1b[3J";
/// Writes the ANSI clear sequence to the given writer.
/// This does **not** flush automatically. No allocation.
///
/// # Errors
/// Returns any I/O error raised by the underlying writer.
///
/// # Examples
///
/// ```
/// use stdt::utils::clear_cli::write_clear;
/// let mut buf = Vec::new();
/// write_clear(&mut buf).unwrap();
/// assert_eq!(buf, b"\x1b[H\x1b[2J\x1b[3J");
/// ```
/// Writes the ANSI clear sequence to `stdout`.
/// This does **not** flush automatically. No allocation.
///
/// # Errors
/// Returns any I/O error raised when writing to `stdout`.
///
/// # Examples
///
/// ```
/// use stdt::utils::clear_cli::clear;
/// clear().unwrap();
/// ```