### Clone Memterm Repository Source: https://github.com/orhanbalci/memterm/blob/main/README.md To start development, clone the memterm repository from GitHub and navigate into the project directory. ```sh git clone https://github.com/orhanbalci/memterm.git cd memterm ``` -------------------------------- ### Example Usage: Terminal Screen Drawing and Mode Management Source: https://github.com/orhanbalci/memterm/blob/main/README.md This Rust test demonstrates drawing characters to the screen, managing terminal modes like DECAWM and IRM, and observing cursor behavior and screen updates. ```rust #[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()] ); } ``` -------------------------------- ### Create New Terminal Screen Source: https://context7.com/orhanbalci/memterm/llms.txt Initializes a new virtual terminal screen with specified dimensions. The screen starts with default settings like auto-wrap and a visible cursor. ```rust use memterm::screen::Screen; // Create a screen with 80 columns and 24 lines (standard terminal size) let mut screen = Screen::new(80, 24); // Access screen properties println!("Columns: {}, Lines: {}", screen.columns, screen.lines); println!("Cursor position: ({}, {})", screen.cursor.x, screen.cursor.y); // Screen is initialized with empty content assert_eq!(screen.display()[0], " ".repeat(80)); ``` -------------------------------- ### Screen::display - Get Screen Content as Strings Source: https://context7.com/orhanbalci/memterm/llms.txt Retrieves the entire screen buffer as a vector of strings, where each string represents a line of the terminal output. ```APIDOC ## Screen::display - Get Screen Content as Strings ### Description Returns the entire screen buffer as a vector of strings, one per line. This is the primary method for retrieving the rendered terminal output. Each line is rendered with proper handling of wide characters and combining marks. ### Method `display` ### Endpoint N/A (struct method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(5, 3); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); // Move to line 2 screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); // Move to line 3 screen.draw("Line3"); let display = screen.display(); assert_eq!(display, vec![ "Line1".to_string(), "Line2".to_string(), "Line3".to_string() ]); // Can iterate and process each line for (line_num, content) in display.iter().enumerate() { println!("Line {}: '{}'", line_num + 1, content); } ``` ### Response #### Success Response (200) - **display** (Vec) - A vector where each element is a string representing a line of the terminal output. #### Response Example ```json { "display": [ "Line1", "Line2", "Line3" ] } ``` ``` -------------------------------- ### Get Screen Content as Strings Source: https://context7.com/orhanbalci/memterm/llms.txt Retrieves the entire terminal screen buffer as a vector of strings, where each string represents a line. This method handles wide characters and combining marks for accurate rendering. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(5, 3); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); // Move to line 2 screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); // Move to line 3 screen.draw("Line3"); let display = screen.display(); assert_eq!(display, vec![ "Line1".to_string(), "Line2".to_string(), "Line3".to_string() ]); // Can iterate and process each line for (line_num, content) in display.iter().enumerate() { println!("Line {}: '{}'", line_num + 1, content); } ``` -------------------------------- ### Generate Local Documentation Source: https://github.com/orhanbalci/memterm/blob/main/README.md To generate and view the local documentation for the memterm crate, use the following cargo command. ```sh cargo doc --open ``` -------------------------------- ### Initialize and Access CharOpts Source: https://context7.com/orhanbalci/memterm/llms.txt Demonstrates how to create default character options and access attributes from the screen buffer after drawing text with specific renditions. Ensure necessary imports are included. ```rust use memterm::screen::{CharOpts, Screen}; use memterm::parser_listener::ParserListener; // Default character attributes let default = CharOpts::default(); assert_eq!(default.data, " "); assert_eq!(default.fg, "default"); assert_eq!(default.bg, "default"); assert!(!default.bold); assert!(!default.italics); assert!(!default.underscore); assert!(!default.strikethrough); assert!(!default.reverse); assert!(!default.blink); // Access character attributes from screen buffer let mut screen = Screen::new(10, 2); screen.select_graphic_rendition(&[1, 31]); // Bold + Red screen.draw("Test"); // Read attributes from buffer let char_opts = screen.buffer.get(&0).unwrap().get(&0).unwrap(); assert_eq!(char_opts.data, "T"); assert_eq!(char_opts.fg, "red"); assert!(char_opts.bold); ``` -------------------------------- ### Build and Test Memterm Crate Source: https://github.com/orhanbalci/memterm/blob/main/README.md After adding the dependency, you can build your project or run tests using cargo commands. ```sh cargo build ``` ```sh cargo test ``` -------------------------------- ### Initialize Terminal Parser with Parser::new Source: https://context7.com/orhanbalci/memterm/llms.txt Creates a parser instance that processes input and dispatches commands to a ParserListener implementation. ```rust use std::sync::{Arc, Mutex}; use memterm::parser::Parser; use memterm::screen::Screen; use memterm::parser_listener::ParserListener; // Create a screen as the parser listener let screen = Arc::new(Mutex::new(Screen::new(80, 24))); // Create parser with the screen let mut parser = Parser::new(screen.clone()); // Parser is ready to process input parser.feed("Hello, World!".to_string()); assert_eq!(screen.lock().unwrap().display()[0], "Hello, World!".to_string() + &" ".repeat(67)); ``` -------------------------------- ### Cursor Movement Methods in Memterm Source: https://context7.com/orhanbalci/memterm/llms.txt Illustrates various cursor movement methods including up, down, forward, back, to column, and to line. Movements are clamped to screen boundaries. Ensure Screen and ParserListener are imported. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(20, 10); screen.cursor_position(Some(5), Some(10)); // Start at row 5, col 10 // cursor_up - move up by count rows screen.cursor_up(Some(2)); assert_eq!(screen.cursor.y, 2); // 4 - 2 = 2 (0-indexed) // cursor_down - move down by count rows screen.cursor_down(Some(3)); assert_eq!(screen.cursor.y, 5); // cursor_forward - move right by count columns screen.cursor_forward(Some(5)); assert_eq!(screen.cursor.x, 14); // cursor_back - move left by count columns screen.cursor_back(Some(4)); assert_eq!(screen.cursor.x, 10); // Movements stop at boundaries screen.cursor_up(Some(100)); assert_eq!(screen.cursor.y, 0); // Clamped to top screen.cursor_down(Some(100)); assert_eq!(screen.cursor.y, 9); // Clamped to bottom // cursor_to_column - move to specific column screen.cursor_to_column(Some(5)); assert_eq!(screen.cursor.x, 4); // 1-indexed input // cursor_to_line - move to specific line screen.cursor_to_line(Some(3)); assert_eq!(screen.cursor.y, 2); ``` -------------------------------- ### Screen::new - Create a New Terminal Screen Source: https://context7.com/orhanbalci/memterm/llms.txt Initializes a new virtual terminal screen with specified dimensions. The screen includes a character buffer, cursor management, and terminal modes, defaulting to auto-wrap and visible cursor. ```APIDOC ## Screen::new - Create a New Terminal Screen ### Description Creates a new virtual terminal screen with specified dimensions. The screen maintains a character buffer, cursor position, and terminal modes. It initializes with default settings including auto-wrap mode (DECAWM) and visible cursor (DECTCEM). ### Method Associated function (constructor) ### Endpoint N/A (struct method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use memterm::screen::Screen; // Create a screen with 80 columns and 24 lines (standard terminal size) let mut screen = Screen::new(80, 24); // Access screen properties println!("Columns: {}, Lines: {}", screen.columns, screen.lines); println!("Cursor position: ({}, {})", screen.cursor.x, screen.cursor.y); // Screen is initialized with empty content assert_eq!(screen.display()[0], " ".repeat(80)); ``` ### Response #### Success Response (200) N/A (returns a Screen instance) #### Response Example N/A ``` -------------------------------- ### Line Insertion and Deletion Source: https://context7.com/orhanbalci/memterm/llms.txt Shows how to insert blank lines at the cursor position, pushing content down, and delete lines, pulling content up. Lines moved beyond margins are lost. Requires Screen and ParserListener imports. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(5, 5); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); screen.draw("Line3"); screen.cursor_position(Some(4), Some(1)); screen.draw("Line4"); screen.cursor_position(Some(5), Some(1)); screen.draw("Line5"); // insert_lines - insert blank lines at cursor, pushing content down screen.cursor_position(Some(2), Some(1)); screen.insert_lines(Some(2)); assert_eq!(screen.display(), vec![ "Line1", " ", " ", "Line2", "Line3" ]); // delete_lines - delete lines at cursor, pulling content up let mut screen = Screen::new(5, 5); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); screen.draw("Line3"); screen.cursor_position(Some(4), Some(1)); screen.draw("Line4"); screen.cursor_position(Some(5), Some(1)); screen.draw("Line5"); screen.cursor_position(Some(2), Some(1)); screen.delete_lines(Some(2)); assert_eq!(screen.display(), vec![ "Line1", "Line4", "Line5", " ", " " ]); ``` -------------------------------- ### Screen::resize Source: https://context7.com/orhanbalci/memterm/llms.txt Resizes the screen to new dimensions. Content is clipped when shrinking and filled with default characters when expanding. ```APIDOC ## Screen::resize ### Description Resizes the screen to new dimensions. When shrinking, content is clipped. When expanding, new space is filled with default characters. Scroll margins are reset. ### Parameters #### Path Parameters - **columns** (Option) - Required - The new number of columns. - **lines** (Option) - Required - The new number of lines. ``` -------------------------------- ### Cursor Movement Methods Source: https://context7.com/orhanbalci/memterm/llms.txt Provides methods for moving the cursor in all directions. Movements are bounded by screen margins and dimensions. Each method accepts an optional count parameter defaulting to 1. ```APIDOC ## Cursor Movement Methods Provides methods for moving the cursor in all directions. Movements are bounded by screen margins and dimensions. Each method accepts an optional count parameter defaulting to 1. ### Initializing and Positioning Cursor Sets the initial cursor position. ```rust use memterm::screen::Screen; let mut screen = Screen::new(20, 10); screen.cursor_position(Some(5), Some(10)); // Start at row 5, col 10 ``` ### Vertical Cursor Movement Methods for moving the cursor up and down. ```rust use memterm::screen::Screen; let mut screen = Screen::new(20, 10); screen.cursor_position(Some(5), Some(10)); // cursor_up - move up by count rows screen.cursor_up(Some(2)); assert_eq!(screen.cursor.y, 2); // 4 - 2 = 2 (0-indexed) // cursor_down - move down by count rows screen.cursor_down(Some(3)); assert_eq!(screen.cursor.y, 5); // Movements stop at boundaries screen.cursor_up(Some(100)); assert_eq!(screen.cursor.y, 0); // Clamped to top screen.cursor_down(Some(100)); assert_eq!(screen.cursor.y, 9); // Clamped to bottom ``` ### Horizontal Cursor Movement Methods for moving the cursor forward (right) and backward (left). ```rust use memterm::screen::Screen; let mut screen = Screen::new(20, 10); screen.cursor_position(Some(5), Some(10)); // cursor_forward - move right by count columns screen.cursor_forward(Some(5)); assert_eq!(screen.cursor.x, 14); // cursor_back - move left by count columns screen.cursor_back(Some(4)); assert_eq!(screen.cursor.x, 10); ``` ### Absolute Cursor Positioning Methods to move the cursor to a specific column or line. ```rust use memterm::screen::Screen; let mut screen = Screen::new(20, 10); // cursor_to_column - move to specific column screen.cursor_to_column(Some(5)); assert_eq!(screen.cursor.x, 4); // 1-indexed input // cursor_to_line - move to specific line screen.cursor_to_line(Some(3)); assert_eq!(screen.cursor.y, 2); ``` ``` -------------------------------- ### Define Scrolling Region with Screen::set_margins Source: https://context7.com/orhanbalci/memterm/llms.txt Sets top and bottom margins for the scrolling region. Margins are 1-indexed and setting them resets the cursor to the home position. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; use memterm::screen::Margins; let mut screen = Screen::new(10, 10); // Set scrolling region from line 2 to line 8 screen.set_margins(Some(2), Some(8)); assert_eq!(screen.margins, Some(Margins { top: 1, bottom: 7 })); // Cursor moves to home when margins change assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); // Reset margins to full screen screen.set_margins(None, None); assert!(screen.margins.is_none()); ``` -------------------------------- ### Manage Cursor State with save_cursor and restore_cursor Source: https://context7.com/orhanbalci/memterm/llms.txt Uses a stack to save and restore cursor position, attributes, and modes. Useful for temporary cursor movements. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(80, 24); // Position cursor and set attributes screen.cursor_position(Some(5), Some(10)); screen.select_graphic_rendition(&[1]); // Bold screen.save_cursor(); // Move and change attributes screen.cursor_position(Some(20), Some(40)); screen.select_graphic_rendition(&[0]); // Reset assert_eq!((screen.cursor.y, screen.cursor.x), (19, 39)); assert!(!screen.cursor.attr.bold); // Restore original position and attributes screen.restore_cursor(); assert_eq!((screen.cursor.y, screen.cursor.x), (4, 9)); assert!(screen.cursor.attr.bold); // Multiple saves create a stack screen.save_cursor(); screen.cursor_position(Some(1), Some(1)); screen.save_cursor(); screen.cursor_position(Some(10), Some(10)); screen.restore_cursor(); // Back to (1,1) assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); screen.restore_cursor(); // Back to (5,10) assert_eq!((screen.cursor.y, screen.cursor.x), (4, 9)); ``` -------------------------------- ### Add Memterm Dependency to Cargo.toml Source: https://github.com/orhanbalci/memterm/blob/main/README.md To include memterm in your project, add the following to your Cargo.toml file. ```toml [dependencies] memterm = "0.1" ``` -------------------------------- ### Resize Screen Dimensions in Rust Source: https://context7.com/orhanbalci/memterm/llms.txt Resizes the screen buffer. Shrinking clips content, while expanding fills new space with default characters. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(5, 3); screen.draw("Hello"); screen.cursor_position(Some(2), Some(1)); screen.draw("World"); assert_eq!(screen.display(), vec!["Hello", "World", " "]); // Resize larger - adds space screen.resize(Some(4), Some(7)); assert_eq!(screen.columns, 7); assert_eq!(screen.lines, 4); assert_eq!(screen.display()[0], "Hello "); // Resize smaller - clips content from right/top let mut screen = Screen::new(5, 3); screen.draw("Hello"); screen.cursor_position(Some(2), Some(1)); screen.draw("World"); screen.resize(Some(2), Some(3)); assert_eq!(screen.display(), vec!["Wor", " "]); ``` -------------------------------- ### Screen::draw - Display Characters on Screen Source: https://context7.com/orhanbalci/memterm/llms.txt Renders characters at the current cursor position and advances the cursor. It automatically handles single-width, double-width, and zero-width characters, with support for line wrapping. ```APIDOC ## Screen::draw - Display Characters on Screen ### Description Draws decoded characters at the current cursor position and advances the cursor. Handles single-width, double-width (CJK), and zero-width (combining) characters automatically. When auto-wrap mode (DECAWM) is enabled, text wraps to the next line at screen boundaries. ### Method `draw` ### Endpoint N/A (struct method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; use memterm::modes::LNM; let mut screen = Screen::new(10, 3); screen.set_mode(&[LNM], false); // Enable Line Feed/New Line mode // Draw simple ASCII text screen.draw("Hello"); assert_eq!(screen.display()[0], "Hello "); assert_eq!(screen.cursor.x, 5); // Draw double-width Japanese characters (each takes 2 columns) let mut screen = Screen::new(10, 1); screen.draw("コンニチハ"); assert_eq!(screen.display()[0], "コンニチハ"); assert_eq!(screen.cursor.x, 10); // 5 characters × 2 columns each // Draw with auto-wrap at line boundary let mut screen = Screen::new(5, 2); screen.set_mode(&[LNM], false); screen.draw("HelloWorld"); assert_eq!(screen.display(), vec!["Hello", "World"]); ``` ### Response #### Success Response (200) N/A (modifies the screen state) #### Response Example N/A ``` -------------------------------- ### Screen::reset - Reset Terminal to Initial State Source: https://context7.com/orhanbalci/memterm/llms.txt Resets the terminal to its initial state. Clears the screen, resets cursor to home position, restores default modes and character sets, and reinitializes tab stops every 8 columns. ```APIDOC ## Screen::reset - Reset Terminal to Initial State Resets the terminal to its initial state. Clears the screen, resets cursor to home position, restores default modes and character sets, and reinitializes tab stops every 8 columns. ### Modifying Screen State Before Reset Applies some changes to the screen before resetting. ```rust use memterm::screen::Screen; use memterm::modes::DECAWM; let mut screen = Screen::new(80, 24); // Modify screen state screen.draw("Some content"); screen.cursor_position(Some(10), Some(20)); screen.select_graphic_rendition(&[1, 31]); // Bold red screen.set_margins(Some(5), Some(20)); ``` ### Performing the Reset Calls the `reset` method to return the terminal to its default state. ```rust use memterm::screen::Screen; use memterm::modes::DECAWM; // Assuming screen is modified as above let mut screen = Screen::new(80, 24); screen.draw("Some content"); screen.cursor_position(Some(10), Some(20)); screen.select_graphic_rendition(&[1, 31]); // Bold red screen.set_margins(Some(5), Some(20)); screen.reset(); // Verify reset state assert_eq!(screen.display()[0], " ".repeat(80)); // Screen is cleared assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); // Cursor is at home assert_eq!(screen.cursor.attr.fg, "default"); // Attributes are reset assert!(!screen.cursor.attr.bold); assert!(screen.margins.is_none()); // Margins are cleared assert!(screen.mode.contains(&DECAWM)); // Default modes restored (DECAWM enabled) ``` ``` -------------------------------- ### Reset Terminal State with Screen::reset Source: https://context7.com/orhanbalci/memterm/llms.txt Resets the terminal to its initial state, clearing the screen, returning the cursor to home, and restoring default attributes and modes. Requires Screen, ParserListener, and DECAWM imports. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; use memterm::modes::DECAWM; let mut screen = Screen::new(80, 24); // Modify screen state screen.draw("Some content"); screen.cursor_position(Some(10), Some(20)); screen.select_graphic_rendition(&[1, 31]); // Bold red screen.set_margins(Some(5), Some(20)); // Reset everything screen.reset(); // Screen is cleared assert_eq!(screen.display()[0], " ".repeat(80)); // Cursor is at home assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); // Attributes are reset assert_eq!(screen.cursor.attr.fg, "default"); assert!(!screen.cursor.attr.bold); // Margins are cleared assert!(screen.margins.is_none()); // Default modes restored (DECAWM enabled) assert!(screen.mode.contains(&DECAWM)); ``` -------------------------------- ### Screen::select_graphic_rendition Source: https://context7.com/orhanbalci/memterm/llms.txt Sets display attributes for subsequently drawn characters using SGR codes, including styles, ANSI colors, and true color. ```APIDOC ## Screen::select_graphic_rendition ### Description Sets display attributes for subsequently drawn characters using SGR (Select Graphic Rendition) codes. ### Parameters #### Path Parameters - **codes** (&[u8]) - Required - A slice of SGR codes to apply. ``` -------------------------------- ### CharOpts - Character Attributes Structure Source: https://context7.com/orhanbalci/memterm/llms.txt Represents the display attributes for a single character cell including foreground/background colors and text styles. Each cell in the screen buffer stores a `CharOpts` describing how the character should be rendered. ```APIDOC ## CharOpts - Character Attributes Structure Represents the display attributes for a single character cell including foreground/background colors and text styles. Each cell in the screen buffer stores a `CharOpts` describing how the character should be rendered. ### Default Attributes Demonstrates the default values for `CharOpts`. ```rust use memterm::screen::CharOpts; let default = CharOpts::default(); assert_eq!(default.data, " "); assert_eq!(default.fg, "default"); assert_eq!(default.bg, "default"); assert!(!default.bold); assert!(!default.italics); assert!(!default.underscore); assert!(!default.strikethrough); assert!(!default.reverse); assert!(!default.blink); ``` ### Accessing Attributes from Screen Buffer Shows how to retrieve character attributes from the screen buffer after drawing content. ```rust use memterm::screen::{CharOpts, Screen}; let mut screen = Screen::new(10, 2); screen.select_graphic_rendition(&[1, 31]); // Bold + Red screen.draw("Test"); // Read attributes from buffer let char_opts = screen.buffer.get(&0).unwrap().get(&0).unwrap(); assert_eq!(char_opts.data, "T"); assert_eq!(char_opts.fg, "red"); assert!(char_opts.bold); ``` ``` -------------------------------- ### Draw Characters on Screen Source: https://context7.com/orhanbalci/memterm/llms.txt Renders characters at the current cursor position and advances the cursor. Supports various character widths and auto-wrapping. Ensure Line Feed/New Line mode (LNM) is set if needed for wrapping behavior. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; use memterm::modes::LNM; let mut screen = Screen::new(10, 3); screen.set_mode(&[LNM], false); // Enable Line Feed/New Line mode // Draw simple ASCII text screen.draw("Hello"); assert_eq!(screen.display()[0], "Hello "); assert_eq!(screen.cursor.x, 5); // Draw double-width Japanese characters (each takes 2 columns) let mut screen = Screen::new(10, 1); screen.draw("コンニチハ"); assert_eq!(screen.display()[0], "コンニチハ"); assert_eq!(screen.cursor.x, 10); // 5 characters × 2 columns each // Draw with auto-wrap at line boundary let mut screen = Screen::new(5, 2); screen.set_mode(&[LNM], false); screen.draw("HelloWorld"); assert_eq!(screen.display(), vec!["Hello", "World"]); ``` -------------------------------- ### Parser::new - Create Terminal Escape Sequence Parser Source: https://context7.com/orhanbalci/memterm/llms.txt Creates a new parser instance that processes terminal input and dispatches commands to a listener implementing `ParserListener`. The parser handles ANSI escape sequences, CSI commands, and operating system commands. ```APIDOC ## Parser::new - Create Terminal Escape Sequence Parser ### Description Creates a new parser instance that processes terminal input and dispatches commands to a listener implementing `ParserListener`. The parser handles ANSI escape sequences, CSI commands, and operating system commands. ### Method `Parser::new` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **listener** (Arc>) - Required - An implementation of the `ParserListener` trait, typically a `Screen` instance. ### Request Example ```rust use std::sync::{Arc, Mutex}; use memterm::parser::Parser; use memterm::screen::Screen; let screen = Arc::new(Mutex::new(Screen::new(80, 24))); let mut parser = Parser::new(screen.clone()); ``` ### Response #### Success Response (200) Returns a new `Parser` instance. #### Response Example ```rust // Parser instance is created and ready to use. ``` ``` -------------------------------- ### Set Text Attributes with SGR in Rust Source: https://context7.com/orhanbalci/memterm/llms.txt Applies display attributes like colors and styles using SGR codes. Supports ANSI, 256-color, and 24-bit true color modes. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(20, 5); // Set bold text (SGR code 1) screen.select_graphic_rendition(&[1]); assert!(screen.cursor.attr.bold); // Set foreground color to red (SGR code 31) screen.select_graphic_rendition(&[31]); assert_eq!(screen.cursor.attr.fg, "red"); // Set background color to blue (SGR code 44) screen.select_graphic_rendition(&[44]); assert_eq!(screen.cursor.attr.bg, "blue"); // Set 256-color foreground: code 38, mode 5, color index screen.select_graphic_rendition(&[38, 5, 0]); // Black from 256 palette assert_eq!(screen.cursor.attr.fg, "000000"); // Set 24-bit true color: code 38, mode 2, R, G, B screen.select_graphic_rendition(&[38, 2, 255, 128, 0]); // Orange assert_eq!(screen.cursor.attr.fg, "ff8000"); // Reset all attributes (SGR code 0) screen.select_graphic_rendition(&[0]); assert_eq!(screen.cursor.attr.fg, "default"); assert_eq!(screen.cursor.attr.bg, "default"); assert!(!screen.cursor.attr.bold); ``` -------------------------------- ### Screen::set_mode / reset_mode Source: https://context7.com/orhanbalci/memterm/llms.txt Enables or disables terminal operating modes such as auto-wrap, insert mode, and cursor visibility. ```APIDOC ## Screen::set_mode / reset_mode ### Description Enables or disables terminal operating modes. Supports standard ANSI modes and DEC private modes. ### Parameters #### Path Parameters - **modes** (&[u8]) - Required - The list of modes to modify. - **private** (bool) - Required - Whether the modes are DEC private modes. ``` -------------------------------- ### Control Terminal Modes in Rust Source: https://context7.com/orhanbalci/memterm/llms.txt Configures terminal operating modes such as auto-wrap, insert mode, and cursor visibility. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; use memterm::modes::{DECAWM, IRM, DECTCEM, LNM}; let mut screen = Screen::new(10, 5); // DECAWM (Auto Wrap Mode) - enabled by default assert!(screen.mode.contains(&DECAWM)); screen.reset_mode(&[DECAWM], false); // Disable auto-wrap assert!(!screen.mode.contains(&DECAWM)); // IRM (Insert/Replace Mode) - insert characters instead of overwriting screen.set_mode(&[IRM], false); screen.draw("abc"); screen.cursor_position(None, None); screen.draw("X"); // Inserts 'X', shifting 'abc' right assert_eq!(screen.display()[0], "Xabc "); // DECTCEM (Cursor Visibility) - hide/show cursor screen.reset_mode(&[DECTCEM], false); assert!(screen.cursor.hidden); screen.set_mode(&[DECTCEM], false); assert!(!screen.cursor.hidden); // LNM (Line Feed/New Line Mode) screen.set_mode(&[LNM], false); // Now LF moves cursor to start of next line (not just down) ``` -------------------------------- ### Screen::save_cursor / restore_cursor - Cursor State Stack Source: https://context7.com/orhanbalci/memterm/llms.txt Saves and restores cursor position, character attributes, character set, and certain modes to a stack. Multiple save operations push to the stack; restore pops from it. Used for temporary cursor movements. ```APIDOC ## Screen::save_cursor / restore_cursor - Cursor State Stack ### Description Saves and restores cursor position, character attributes, character set, and certain modes to a stack. Multiple save operations push to the stack; restore pops from it. Used for temporary cursor movements. ### Method `save_cursor`, `restore_cursor` ### Parameters None for these methods directly, they operate on internal state. ### Request Example ```rust use memterm::screen::Screen; let mut screen = Screen::new(80, 24); // Position cursor and set attributes screen.cursor_position(Some(5), Some(10)); screen.select_graphic_rendition(&[1]); // Bold screen.save_cursor(); // Restore original position and attributes screen.restore_cursor(); ``` ### Response #### Success Response (200) No explicit response body, modifies the screen state. #### Response Example None ``` -------------------------------- ### Screen::set_margins - Define Scrolling Region Source: https://context7.com/orhanbalci/memterm/llms.txt Sets the top and bottom margins for the scrolling region. Lines outside the margins are protected from scrolling operations. Margins are 1-indexed. Setting margins also moves the cursor to the home position. ```APIDOC ## Screen::set_margins - Define Scrolling Region ### Description Sets the top and bottom margins for the scrolling region. Lines outside the margins are protected from scrolling operations. Margins are 1-indexed. Setting margins also moves the cursor to home position. ### Method `set_margins` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **top** (Option) - Optional - The top margin (1-indexed). - **bottom** (Option) - Optional - The bottom margin (1-indexed). ### Request Example ```rust use memterm::screen::Screen; let mut screen = Screen::new(10, 10); // Set scrolling region from line 2 to line 8 screen.set_margins(Some(2), Some(8)); ``` ### Response #### Success Response (200) No explicit response body, modifies the screen state. #### Response Example None ``` -------------------------------- ### Move Cursor to Specific Location Source: https://context7.com/orhanbalci/memterm/llms.txt Repositions the cursor to a given row and column. Coordinates are 1-indexed and clamped to screen boundaries. When origin mode (DECOM) is active, positions are relative to the scrolling region. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(80, 24); // Move cursor to row 5, column 10 (1-indexed) screen.cursor_position(Some(5), Some(10)); assert_eq!(screen.cursor.y, 4); // 0-indexed internally assert_eq!(screen.cursor.x, 9); // Position (0,0) and (1,1) are equivalent (home position) screen.cursor_position(Some(0), Some(0)); assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); // Out-of-bounds positions are clamped screen.cursor_position(Some(100), Some(100)); assert_eq!(screen.cursor.y, 23); // Clamped to last row assert_eq!(screen.cursor.x, 79); // Clamped to last column // Move to home position (top-left) screen.cursor_position(None, None); assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); ``` -------------------------------- ### Line Editing Methods Source: https://context7.com/orhanbalci/memterm/llms.txt Provides methods for inserting and deleting lines within the scrolling region. Lines moved past margins are lost. These operations maintain line formatting and character attributes. ```APIDOC ## Line Editing Methods Provides methods for inserting and deleting lines within the scrolling region. Lines moved past margins are lost. These operations maintain line formatting and character attributes. ### Setting up the Screen Content Initializes a screen with multiple lines of text. ```rust use memterm::screen::Screen; let mut screen = Screen::new(5, 5); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); screen.draw("Line3"); screen.cursor_position(Some(4), Some(1)); screen.draw("Line4"); screen.cursor_position(Some(5), Some(1)); screen.draw("Line5"); ``` ### Inserting Lines Inserts blank lines at the cursor's position, shifting existing content downwards. ```rust use memterm::screen::Screen; // Assuming screen is set up as above let mut screen = Screen::new(5, 5); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); screen.draw("Line3"); screen.cursor_position(Some(4), Some(1)); screen.draw("Line4"); screen.cursor_position(Some(5), Some(1)); screen.draw("Line5"); screen.cursor_position(Some(2), Some(1)); screen.insert_lines(Some(2)); assert_eq!(screen.display(), vec!["Line1", " ", " ", "Line2", "Line3"]); ``` ### Deleting Lines Deletes lines starting from the cursor's position, pulling content upwards. ```rust use memterm::screen::Screen; // Assuming screen is set up as above let mut screen = Screen::new(5, 5); screen.draw("Line1"); screen.cursor_position(Some(2), Some(1)); screen.draw("Line2"); screen.cursor_position(Some(3), Some(1)); screen.draw("Line3"); screen.cursor_position(Some(4), Some(1)); screen.draw("Line4"); screen.cursor_position(Some(5), Some(1)); screen.draw("Line5"); screen.cursor_position(Some(2), Some(1)); screen.delete_lines(Some(2)); assert_eq!(screen.display(), vec!["Line1", "Line4", "Line5", " ", " "]); ``` ``` -------------------------------- ### Parser::feed - Process Terminal Input Source: https://context7.com/orhanbalci/memterm/llms.txt Feeds input data to the parser for processing. The parser handles both plain text (sent directly to the screen) and escape sequences (parsed and dispatched as commands). Supports all standard ANSI/VT100 escape sequences. ```APIDOC ## Parser::feed - Process Terminal Input ### Description Feeds input data to the parser for processing. The parser handles both plain text (sent directly to the screen) and escape sequences (parsed and dispatched as commands). Supports all standard ANSI/VT100 escape sequences. ### Method `feed` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **input** (String) - Required - The terminal input string to process. ### Request Example ```rust use std::sync::{Arc, Mutex}; use memterm::parser::Parser; use memterm::screen::Screen; let screen = Arc::new(Mutex::new(Screen::new(40, 10))); let mut parser = Parser::new(screen.clone()); // Draw text directly parser.feed("First line".to_string()); // Move cursor using escape sequence: ESC [ row ; col H parser.feed("\x1b[2;1H".to_string()); // Move to row 2, column 1 parser.feed("Second line".to_string()); // Set title using OSC: ESC ] 2 ; title BEL parser.feed("\x1b]2;My Terminal\x07".to_string()); ``` ### Response #### Success Response (200) No explicit response body, modifies the screen state based on the input processed. #### Response Example None ``` -------------------------------- ### Screen::cursor_position - Move Cursor to Specific Location Source: https://context7.com/orhanbalci/memterm/llms.txt Moves the terminal cursor to a specified row and column. Coordinates are 1-indexed and clamped to the screen boundaries. Supports relative positioning when origin mode is enabled. ```APIDOC ## Screen::cursor_position - Move Cursor to Specific Location ### Description Moves the cursor to a specific row and column position. Coordinates are 1-indexed (matching VT100 conventions). Values are clamped to screen boundaries. When origin mode (DECOM) is enabled, positions are relative to the scrolling region. ### Method `cursor_position` ### Endpoint N/A (struct method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(80, 24); // Move cursor to row 5, column 10 (1-indexed) screen.cursor_position(Some(5), Some(10)); assert_eq!(screen.cursor.y, 4); // 0-indexed internally assert_eq!(screen.cursor.x, 9); // Position (0,0) and (1,1) are equivalent (home position) screen.cursor_position(Some(0), Some(0)); assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); // Out-of-bounds positions are clamped screen.cursor_position(Some(100), Some(100)); assert_eq!(screen.cursor.y, 23); // Clamped to last row assert_eq!(screen.cursor.x, 79); // Clamped to last column // Move to home position (top-left) screen.cursor_position(None, None); assert_eq!((screen.cursor.y, screen.cursor.x), (0, 0)); ``` ### Response #### Success Response (200) N/A (modifies the screen state) #### Response Example N/A ``` -------------------------------- ### Screen::erase_in_display Source: https://context7.com/orhanbalci/memterm/llms.txt Erases portions of the screen based on the specified mode. ```APIDOC ## Screen::erase_in_display ### Description Erases portions of the screen based on the mode parameter. Mode 0 erases from cursor to end, mode 1 erases from start to cursor, and modes 2/3 erase the entire display. ### Parameters #### Path Parameters - **mode** (Option) - Required - The erase mode (0, 1, 2, or 3). - **private** (Option) - Optional - Whether to use private mode. ``` -------------------------------- ### Process Terminal Input with Parser::feed Source: https://context7.com/orhanbalci/memterm/llms.txt Feeds input data to the parser, supporting plain text and ANSI/VT100 escape sequences. ```rust use std::sync::{Arc, Mutex}; use memterm::parser::Parser; use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let screen = Arc::new(Mutex::new(Screen::new(40, 10))); let mut parser = Parser::new(screen.clone()); // Draw text directly parser.feed("First line".to_string()); // Move cursor using escape sequence: ESC [ row ; col H parser.feed("\x1b[2;1H".to_string()); // Move to row 2, column 1 parser.feed("Second line".to_string()); // Set text attributes: ESC [ 1 m (bold) parser.feed("\x1b[1m".to_string()); parser.feed("\x1b[3;1H".to_string()); parser.feed("Bold text".to_string()); // Clear screen: ESC [ 2 J parser.feed("\x1b[2J".to_string()); // Set title using OSC: ESC ] 2 ; title BEL parser.feed("\x1b]2;My Terminal\x07".to_string()); assert_eq!(screen.lock().unwrap().title, "My Terminal"); // Complex sequence: colored output let screen = Arc::new(Mutex::new(Screen::new(40, 5))); let mut parser = Parser::new(screen.clone()); parser.feed("\x1b[31mRed\x1b[0m Normal \x1b[1;32mBold Green\x1b[0m".to_string()); assert_eq!(screen.lock().unwrap().display()[0][..26], "Red Normal Bold Green ".to_string()[..26]); ``` -------------------------------- ### Clear Screen Regions in Rust Source: https://context7.com/orhanbalci/memterm/llms.txt Erases parts of the display based on the specified mode. Cursor position remains unchanged after the operation. ```rust use memterm::screen::Screen; use memterm::parser_listener::ParserListener; let mut screen = Screen::new(5, 3); screen.draw("AAAAA"); screen.cursor_position(Some(2), Some(1)); screen.draw("BBBBB"); screen.cursor_position(Some(3), Some(1)); screen.draw("CCCCC"); screen.cursor_position(Some(2), Some(3)); // Middle of screen // Erase from cursor to end (mode 0) screen.erase_in_display(Some(0), None); assert_eq!(screen.display(), vec!["AAAAA", "BB ", " "]); // Erase from beginning to cursor (mode 1) let mut screen = Screen::new(5, 3); screen.draw("AAAAA"); screen.cursor_position(Some(2), Some(1)); screen.draw("BBBBB"); screen.cursor_position(Some(3), Some(1)); screen.draw("CCCCC"); screen.cursor_position(Some(2), Some(3)); screen.erase_in_display(Some(1), None); assert_eq!(screen.display(), vec![" ", " BB", "CCCCC"]); // Erase entire display (mode 2) let mut screen = Screen::new(5, 3); screen.draw("AAAAA"); screen.erase_in_display(Some(2), None); assert_eq!(screen.display(), vec![" ", " ", " "]); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.