Crates.io | memterm |
lib.rs | memterm |
version | 0.1.0 |
source | src |
created_at | 2025-01-06 11:37:22.013404+00 |
updated_at | 2025-01-06 11:37:22.013404+00 |
description | Inmemory terminal emulator |
homepage | https://github.com/orhanbalci |
repository | https://github.com/orhanbalci/memterm.git |
max_upload_size | |
id | 1505491 |
size | 406,261 |
memterm is a Rust virtual terminal emulator, offering a lightweight and efficient implementation for handling ANSI escape sequences and emulating terminal behavior. Inspired by the Python library pyte, it provides a robust and customizable terminal interface for your Rust applications.
Add memterm to your Cargo.toml
file:
[dependencies]
memterm = "0.1"
Then, run:
cargo build
#[test]
fn draw() {
// DECAWM on (default)
let mut screen = Screen::new(3, 3);
screen.set_mode(&[LNM], false);
assert!(screen.mode.contains(&DECAWM));
for ch in "abc".chars() {
screen.draw(&ch.to_string());
}
assert_eq!(
screen.display(),
vec!["abc".to_string(), " ".to_string(), " ".to_string()]
);
assert_eq!((screen.cursor.y, screen.cursor.x), (0, 3));
// One more character -- now we got a linefeed!
screen.draw("a");
assert_eq!((screen.cursor.y, screen.cursor.x), (1, 1));
// DECAWM is off
let mut screen = Screen::new(3, 3);
screen.reset_mode(&[DECAWM], false);
for ch in "abc".chars() {
screen.draw(&ch.to_string());
}
assert_eq!(
screen.display(),
vec!["abc".to_string(), " ".to_string(), " ".to_string()]
);
assert_eq!((screen.cursor.y, screen.cursor.x), (0, 3));
// No linefeed is issued on the end of the line ...
screen.draw("a");
assert_eq!(
screen.display(),
vec!["aba".to_string(), " ".to_string(), " ".to_string()]
);
assert_eq!((screen.cursor.y, screen.cursor.x), (0, 3));
// IRM mode is on, expecting new characters to move the old ones
// instead of replacing them
screen.set_mode(&[IRM], false);
screen.cursor_position(None, None);
screen.draw("x");
assert_eq!(
screen.display(),
vec!["xab".to_string(), " ".to_string(), " ".to_string()]
);
screen.cursor_position(None, None);
screen.draw("y");
assert_eq!(
screen.display(),
vec!["yxa".to_string(), " ".to_string(), " ".to_string()]
);
}
Escape Sequence Parsing Automatically interprets and applies ANSI escape sequences for text formatting, cursor movements, and more.
Screen Buffer Access Provides direct access to the virtual screen buffer for introspection or manipulation.
Terminal State Management Offers APIs to adjust dimensions and reset or inspect the terminal state.
Detailed documentation is available on docs.rs. To generate local documentation:
cargo doc --open
Contributions are encouraged! You can:
Clone the repository:
git clone https://github.com/orhanbalci/memterm.git
cd memterm
Build the crate:
cargo build
Run tests:
cargo test
memterm is licensed under the MIT License. See the LICENSE file for more information.
memterm draws inspiration from the Python library pyte and aims to bring similar functionality to the Rust ecosystem.