.cargo/
crates/
scripts/
src/
math/
readline/
cursor.rs
674 B
editor.rs
7.1 KiB
fmt.rs
2.3 KiB
lib.rs
1.1 KiB
math.rs
150 B
readline.rs
11.7 KiB
rng.rs
14.0 KiB
.gitignore
30 B
.gitsigners
198 B
AGENTS.md
1.9 KiB
CONTRIBUTING
1.7 KiB
Cargo.lock
5.4 KiB
Cargo.toml
1.9 KiB
LICENSE
1.1 KiB
README.md
245 B
STYLE
3.7 KiB
clippy.toml
213 B
src/readline/cursor.rs
raw
| 1 | //! ANSI escape sequences for cursor movement. |
| 2 | |
| 3 | /// Utilities for cursor movement in the terminal. |
| 4 | pub struct Cursor; |
| 5 | |
| 6 | impl Cursor { |
| 7 | /// Generates an ANSI escape sequence to move the cursor `n` positions to the left. |
| 8 | /// Returns an empty string if n is 0. |
| 9 | pub fn left(n: usize) -> String { |
| 10 | if n == 0 { |
| 11 | return String::new(); |
| 12 | } |
| 13 | format!("\x1b[{n}D") |
| 14 | } |
| 15 | |
| 16 | /// Generates an ANSI escape sequence to move the cursor `n` positions to the right. |
| 17 | /// Returns an empty string if n is 0. |
| 18 | pub fn right(n: usize) -> String { |
| 19 | if n == 0 { |
| 20 | return String::new(); |
| 21 | } |
| 22 | format!("\x1b[{n}C") |
| 23 | } |
| 24 | } |