### Setup Terminal with TermionBackend, Raw Mode, and Alternate Screen Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Provides a comprehensive example of setting up a Ratatui terminal using the TermionBackend. It shows how to enable raw mode and switch to the alternate screen for a full-screen terminal application experience. This setup is crucial for most TUI applications. ```rust use std::io::{stderr, stdout}; use ratatui::Terminal; use ratatui::backend::TermionBackend; use ratatui::termion::raw::IntoRawMode; use ratatui::termion::screen::IntoAlternateScreen; // Example using stdout: // let writer = stdout().into_raw_mode()?.into_alternate_screen()?; // let mut backend = TermionBackend::new(writer); // Example using stderr: let writer = stderr().into_raw_mode()?.into_alternate_screen()?; let backend = TermionBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|frame| { // Application drawing logic here })?; // The writer will automatically restore the terminal state when dropped. // std::io::Result::Ok(()) ``` -------------------------------- ### TermionBackend Initialization and Usage Example Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs Demonstrates how to initialize TermionBackend with stdout or stderr, enabling raw mode and alternate screen for terminal applications. It shows basic usage within a Terminal instance for clearing and drawing content. Note: This example requires 'ignore' due to its interactive nature and external dependencies like Termion's raw mode and alternate screen. ```rust use std::io::{stderr, stdout}; use ratatui::Terminal; use ratatui::backend::TermionBackend; use ratatui::termion::raw::IntoRawMode; use ratatui::termion::screen::IntoAlternateScreen; let writer = stdout().into_raw_mode()?.into_alternate_screen()?; let mut backend = TermionBackend::new(writer); // or let writer = stderr().into_raw_mode()?.into_alternate_screen()?; let backend = TermionBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; # std::io::Result::Ok(()) ``` -------------------------------- ### Create TermionBackend Instance Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Provides a simple example of creating a new TermionBackend instance using standard output as the writer. This is a foundational step before integrating with the Terminal struct. ```rust use std::io::stdout; use ratatui::backend::TermionBackend; let backend = TermionBackend::new(stdout()); ``` -------------------------------- ### Show Cursor using TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend This code example illustrates how to show the terminal cursor using the `show_cursor` method, which is part of the `Backend` trait implementation for `TermionBackend`. ```rust let mut backend = TermionBackend::new(stdout()); backend.show_cursor()?; // This assumes backend is already initialized and writer is set up. ``` -------------------------------- ### Initialize Terminal with TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=std%3A%3Avec Shows the typical setup for initializing a Ratatui Terminal using TermionBackend. This involves putting the stdout into raw and alternate screen modes before creating the backend and terminal. ```rust use std::io::{stderr, stdout}; use ratatui::Terminal; use ratatui::backend::TermionBackend; use ratatui::termion::raw::IntoRawMode; use ratatui::termion::screen::IntoAlternateScreen; let writer = stdout().into_raw_mode()?.into_alternate_screen()?; let mut backend = TermionBackend::new(writer); let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; # std::io::Result::Ok(()) ``` -------------------------------- ### Initialize TermionBackend with Terminal Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Demonstrates how to initialize the TermionBackend with standard output or error, configure raw mode and alternate screen, and set up a ratatui Terminal for drawing. This is the typical setup for most terminal applications. ```rust use std::io::{stderr, stdout}; use ratatui::Terminal; use ratatui::backend::TermionBackend; use ratatui::termion::raw::IntoRawMode; use ratatui::termion::screen::IntoAlternateScreen; let writer = stdout().into_raw_mode()?.into_alternate_screen()?; let mut backend = TermionBackend::new(writer); // or let writer = stderr().into_raw_mode()?.into_alternate_screen()?; let backend = TermionBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; ``` -------------------------------- ### Initialize TermionBackend with stdout Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Demonstrates how to create a TermionBackend using standard output. It includes necessary imports and shows the basic instantiation of the backend, which is typically part of a larger terminal setup. ```rust use std::io::stdout; use ratatui::backend::TermionBackend; let backend = TermionBackend::new(stdout()); ``` -------------------------------- ### Implement Backend Trait for TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=std%3A%3Avec Details the implementations of the `Backend` trait for `TermionBackend`. This includes methods for clearing the screen, drawing content, cursor manipulation, and getting terminal size. ```Rust impl Backend for TermionBackend where W: Write, { type Error = Error; fn clear(&mut self) -> Result<()>; fn clear_region(&mut self, clear_type: ClearType) -> Result<()>; fn append_lines(&mut self, n: u16) -> Result<()>; fn hide_cursor(&mut self) -> Result<()>; fn show_cursor(&mut self) -> Result<()>; fn get_cursor_position(&mut self) -> Result; fn set_cursor_position>(&mut self, position: P) -> Result<()>; fn draw<'a, I>(&mut self, content: I) -> Result<()> where I: Iterator; fn size(&self) -> Result; fn window_size(&mut self) -> Result; fn flush(&mut self) -> Result<()>; } ``` -------------------------------- ### Get Terminal Size using TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend Demonstrates how to get the current dimensions (columns and rows) of the terminal screen using the `size` method, which is part of the `Backend` trait implementation for `TermionBackend`. ```rust use ratatui::backend::Backend; use ratatui::backend::Size; let backend = TermionBackend::new(stdout()); let terminal_size: Size = backend.size()?; // This assumes backend is already initialized. ``` -------------------------------- ### Flush Buffer using TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend This code example shows how to flush any buffered content to the terminal screen using the `flush` method. This ensures that all drawn content is immediately visible. ```rust let mut backend = TermionBackend::new(stdout()); backend.flush()?; // This assumes backend is already initialized and writer is set up. ``` -------------------------------- ### Initialize TermionBackend with stderr Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Illustrates the creation of a TermionBackend using standard error. This example is useful for applications that might need to redirect terminal output or have specific error handling requirements. ```rust use std::io::stderr; use ratatui::backend::TermionBackend; let backend = TermionBackend::new(stderr()); ``` -------------------------------- ### Get Window Size (Pixels Included) using Backend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Implements `window_size` for TermionBackend, providing both the character dimensions (columns/rows) and pixel dimensions of the terminal window. This is useful for more advanced layout calculations. ```rust fn window_size(&mut self) -> Result ``` -------------------------------- ### TermionBackend: Cursor Position Detection and Setting Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs Implements functions to get the current cursor position and set the cursor to a specific position on the terminal. It uses `termion::cursor::DetectCursorPos` for detection and `termion::cursor::Goto` for setting the position, adjusting coordinates for 0-based indexing. ```rust fn get_cursor_position(&mut self) -> io::Result { termion::cursor::DetectCursorPos::cursor_pos(&mut self.writer) .map(|(x, y)| Position { x: x - 1, y: y - 1 }) } fn set_cursor_position>(&mut self, position: P) -> io::Result<()> { let Position { x, y } = position.into(); write!(self.writer, "{}", termion::cursor::Goto(x + 1, y + 1))?; self.writer.flush() ``` -------------------------------- ### Cursor Manipulation with TermionBackend (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=std%3A%3Avec Provides methods to control the terminal cursor, including hiding, showing, getting its position, and setting it to a specific location. These operations utilize termion's cursor control sequences. ```rust fn hide_cursor(&mut self) -> io::Result<()> { write!(self.writer, "{}", termion::cursor::Hide)?; self.writer.flush() } fn show_cursor(&mut self) -> io::Result<()> { write!(self.writer, "{}", termion::cursor::Show)?; self.writer.flush() } fn get_cursor_position(&mut self) -> io::Result { termion::cursor::DetectCursorPos::cursor_pos(&mut self.writer) .map(|(x, y)| Position { x: x - 1, y: y - 1 }) } fn set_cursor_position>(&mut self, position: P) -> io::Result<()> { let Position { x, y } = position.into(); write!(self.writer, "{}", termion::cursor::Goto(x + 1, y + 1))?; self.writer.flush() } ``` -------------------------------- ### TermionBackend Cursor Position Detection and Setting (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Implements functionality to get the current cursor position and set the cursor to a specific position on the terminal using termion. Coordinates are 0-indexed internally. ```rust impl Backend for TermionBackend where W: Write, { // ... other methods ... fn get_cursor_position(&mut self) -> io::Result { termion::cursor::DetectCursorPos::cursor_pos(&mut self.writer) .map(|(x, y)| Position { x: x - 1, y: y - 1 }) } fn set_cursor_position>(&mut self, position: P) -> io::Result<()> { let Position { x, y } = position.into(); write!(self.writer, "{}", termion::cursor::Goto(x + 1, y + 1))?; self.writer.flush() } // ... other methods ... } ``` -------------------------------- ### TermionBackend Constructor and Getters (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Provides the constructor for TermionBackend and methods to get immutable or mutable references to the underlying writer. Note that direct mutable access to the writer might lead to incorrect output due to terminal buffer diffing. ```rust impl TermionBackend where W: Write, { pub const fn new(writer: W) -> Self { Self { writer } } /// Gets the writer. #[instability::unstable( feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991" )] pub const fn writer(&self) -> &W { &self.writer } /// Gets the writer as a mutable reference. /// Note: writing to the writer may cause incorrect output after the write. This is due to the /// way that the Terminal implements diffing Buffers. #[instability::unstable( feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991" )] pub const fn writer_mut(&mut self) -> &mut W { &mut self.writer } } ``` -------------------------------- ### ResetRegion Struct Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.ResetRegion_search= Documentation for the ResetRegion struct, used to reset the scrolling region. Includes its purpose and example usage. ```APIDOC ## Struct ResetRegion ### Description Reset scrolling region. ### Fields This struct does not contain any public fields. ``` -------------------------------- ### Get Terminal Cursor Position Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current cursor position on the terminal screen. This function is deprecated and 'get_cursor_position()' should be used instead, which returns a Result. ```rust fn get_cursor(&mut self) -> Result<(u16, u16), Self::Error> ``` -------------------------------- ### Initialize TermionBackend for Ratatui Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how to create a TermionBackend instance, typically wrapping stdout or stderr. It's common practice to put the writer into raw mode and alternate screen mode before creating the backend for interactive terminal applications. ```rust use std::io::{stderr, stdout}; use ratatui::Terminal; use ratatui::backend::TermionBackend; use ratatui::termion::raw::IntoRawMode; use ratatui::termion::screen::IntoAlternateScreen; // Using stdout: let writer = stdout().into_raw_mode()?.into_alternate_screen()?; let mut backend = TermionBackend::new(writer); // Or using stderr: let writer = stderr().into_raw_mode()?.into_alternate_screen()?; let backend = TermionBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; # std::io::Result::Ok(()) ``` ```rust use std::io::stdout; use ratatui::backend::TermionBackend; let backend = TermionBackend::new(stdout()); ``` -------------------------------- ### Hide Cursor using TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend This code example illustrates how to hide the terminal cursor using the `hide_cursor` method, which is part of the `Backend` trait implementation for `TermionBackend`. ```rust let mut backend = TermionBackend::new(stdout()); backend.hide_cursor()?; // This assumes backend is already initialized and writer is set up. ``` -------------------------------- ### TermionBackend Constructor Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Creates a new Termion backend instance. ```APIDOC ### pub const fn new(writer: W) -> Self Creates a new Termion backend with the given writer. Most applications will use either `stdout` or `stderr` as writer. See the FAQ to determine which one to use. #### Example ```rust use std::io::stdout; use ratatui::backend::TermionBackend; let backend = TermionBackend::new(stdout()); ``` ``` -------------------------------- ### Get Cursor Position using Backend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Implements `get_cursor_position` for TermionBackend, which retrieves the current X and Y coordinates of the terminal cursor. This is useful for precise cursor placement or tracking. ```rust fn get_cursor_position(&mut self) -> Result ``` -------------------------------- ### IntoAlternateScreen API Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=std%3A%3Avec API for switching the terminal to an alternate screen buffer. ```APIDOC ## fn into_alternate_screen(self) -> Result, Error> ### Description Switches the terminal controlled by this writer to use the alternate screen buffer. The terminal will automatically restore to the main screen when the returned `AlternateScreen` guard is dropped. ### Method `fn` ### Endpoint N/A (Method implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Assuming 'writer' implements Write and IntoAlternateScreen // let alternate_screen = writer.into_alternate_screen()?; // // ... perform operations on the alternate screen ... // // alternate_screen is dropped here, restoring the main screen ``` ### Response - **Ok(AlternateScreen)**: A guard object representing the alternate screen session. - **Err(Error)**: An error occurred during the switch. #### Success Response (200) ```json { "message": "Switched to alternate screen. Restore on drop." } ``` #### Response Example ```rust // Returns an AlternateScreen guard object ``` ``` -------------------------------- ### TermionBackend Get Terminal Size (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=u32+-%3E+bool Retrieves the current terminal dimensions (width and height) using termion's `terminal_size` function. Returns the size as a `Size` struct. ```rust fn size(&self) -> io::Result { let terminal = termion::terminal_size()?; Ok(Size::new(terminal.0, terminal.1)) } ``` -------------------------------- ### Get Mutable Reference Adapter for Write Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a mutable reference adapter for the `Write` trait. This allows methods that require `&mut self` to be called on a mutable reference to the writer. ```rust fn by_ref(&mut self) -> &mut Self where Self: Sized, ``` -------------------------------- ### TermionBackend Initialization Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs Provides methods for creating and accessing the writer associated with the TermionBackend. ```APIDOC ## TermionBackend Methods ### new Creates a new `TermionBackend` instance. #### Parameters - `writer` (W): The writer to use for terminal output. ### writer Gets an immutable reference to the writer. #### Returns - `&W`: An immutable reference to the writer. ### writer_mut Gets a mutable reference to the writer. #### Returns - `&mut W`: A mutable reference to the writer. ### clear Clears the entire terminal screen. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### clear_region Clears a specific region of the terminal screen. #### Parameters - `clear_type` (ClearType): The type of region to clear (e.g., All, AfterCursor, etc.). #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### append_lines Appends a specified number of new lines to the terminal output. #### Parameters - `n` (u16): The number of lines to append. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### hide_cursor Hides the terminal cursor. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### show_cursor Shows the terminal cursor. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### get_cursor_position Gets the current position of the terminal cursor. #### Returns - `io::Result`: The cursor's position (x, y). ### set_cursor_position Sets the position of the terminal cursor. #### Parameters - `position` (P: Into): The desired cursor position. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### draw Draws content to the terminal screen. #### Parameters - `content` (I: Iterator): An iterator yielding tuples of (x, y, cell) to draw. #### Returns - `io::Result<()>`: An empty result indicating success or failure. ### size Gets the current size of the terminal window. #### Returns - `io::Result`: The terminal size (width, height). ### window_size Gets the window size, including columns and rows. #### Returns - `io::Result`: The window size information. ``` -------------------------------- ### Get Cursor Position using TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend Demonstrates retrieving the current cursor's position on the terminal screen using the `get_cursor_position` method. This is part of the `Backend` trait implementation. ```rust use ratatui::backend::Backend; use ratatui::backend::Position; let mut backend = TermionBackend::new(stdout()); let cursor_pos: Position = backend.get_cursor_position()?; // This assumes backend is already initialized and writer is set up. ``` -------------------------------- ### TermionBackend Initialization and Writer Access (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=u32+-%3E+bool Provides methods to create a new TermionBackend instance and access its underlying writer. The `writer_mut` method allows mutable access, with a note about potential output issues due to terminal buffer diffing. ```rust pub const fn new(writer: W) -> Self { Self { writer } } /// Gets the writer. #[instability::unstable( feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991" )] pub const fn writer(&self) -> &W { &self.writer } /// Gets the writer as a mutable reference. /// Note: writing to the writer may cause incorrect output after the write. This is due to the /// way that the Terminal implements diffing Buffers. #[instability::unstable( feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991" )] pub const fn writer_mut(&mut self) -> &mut W { &mut self.writer } ``` -------------------------------- ### Clone Implementation Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Details the cloning behavior of the TermionBackend, allowing for duplicate instances to be created. ```APIDOC ## POST /clone ### Description Creates a duplicate (clone) of the `TermionBackend` instance. This operation requires the underlying writer `W` to also implement `Clone`. ### Method POST ### Endpoint /clone ### Response #### Success Response (200) - **cloned_backend** (object) - A new instance of `TermionBackend` that is a duplicate of the original. #### Response Example ```json { "cloned_backend": "" } ``` ``` -------------------------------- ### TermionBackend Get Window Size (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=u32+-%3E+bool Returns the terminal window size, specifically the number of columns and rows, using termion's `terminal_size`. The result is wrapped in a `WindowSize` struct. ```rust fn window_size(&mut self) -> io::Result { Ok(WindowSize { columns_rows: termion::terminal_size()?.into(), }) } ``` -------------------------------- ### Clone Implementation Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=std%3A%3Avec Provides functionality to create a duplicate of the `TermionBackend` instance. ```APIDOC ## POST /websites/rs_ratatui-termion_0_1_0/clone ### Description Returns a duplicate of the `TermionBackend` value. ### Method POST ### Endpoint /websites/rs_ratatui-termion_0_1_0/clone ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example (No request body for clone operation) ### Response #### Success Response (200) - **TermionBackend** (TermionBackend) - A cloned instance of the backend. #### Response Example (Returns a new instance of TermionBackend) ``` -------------------------------- ### clone_to_uninit Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=std%3A%3Avec Nightly-only experimental API to perform copy-assignment from self to a mutable pointer. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description This is a nightly-only experimental API. It performs copy-assignment from `self` to `dest`. ### Method `unsafe fn` ### Endpoint N/A (Method implementation) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust // Example usage (requires nightly Rust) // let mut data = [0u8; 10]; // unsafe { // original_data.clone_to_uninit(data.as_mut_ptr()); // } ``` ### Response None (modifies `dest` in place) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Get Terminal Size using Backend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Implements the `size` method for TermionBackend, returning the current dimensions of the terminal in columns and rows as a `Size` struct. This is crucial for responsive UI design. ```rust fn size(&self) -> Result ``` -------------------------------- ### Get Terminal Pixel Dimensions in Rust Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search=u32+-%3E+bool Retrieves the terminal's dimensions in pixels. This function relies on the `termion` crate and returns a `Result` which may contain an error if the terminal size cannot be determined. ```rust fn pixels(&mut self) -> io::Result { termion::terminal_size_pixels()?.into() } ``` -------------------------------- ### Implement Backend Trait for TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Shows the implementation of the `Backend` trait for `TermionBackend`. This includes methods for clearing the screen, drawing content, managing the cursor, and querying terminal size. ```rust impl Backend for TermionBackend where W: Write, { type Error = Error; fn clear(&mut self) -> Result<()>; fn clear_region(&mut self, clear_type: ClearType) -> Result<()>; fn append_lines(&mut self, n: u16) -> Result<()>; fn hide_cursor(&mut self) -> Result<()>; fn show_cursor(&mut self) -> Result<()>; fn get_cursor_position(&mut self) -> Result; fn set_cursor_position>(&mut self, position: P) -> Result<()>; fn draw<'a, I>(&mut self, content: I) -> Result<()> where I: Iterator fn size(&self) -> Result; fn window_size(&mut self) -> Result; fn flush(&mut self) -> Result<()>; } ``` -------------------------------- ### Write Trait Implementation Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Documenting the methods provided by the `Write` trait for `TermionBackend`, enabling buffered writing to the terminal. ```APIDOC ## POST /write ### Description Writes a buffer of bytes to the terminal, returning the number of bytes successfully written. This is part of the standard `Write` trait implementation. ### Method POST ### Endpoint /write ### Parameters #### Request Body - **buffer** (bytes) - Required - The byte slice to write to the terminal. ### Request Example ```json { "buffer": "SGVsbG8sIFdvcmxkIQ==" } ``` ### Response #### Success Response (200) - **bytes_written** (usize) - The number of bytes written to the terminal. #### Response Example ```json { "bytes_written": 12 } ``` ## POST /flush ### Description Ensures that all buffered output is written to the terminal destination. This is crucial for making visible any pending writes. ### Method POST ### Endpoint /flush ### Response #### Success Response (200) - **status** (string) - Indicates the success of the flush operation, e.g., "ok". #### Response Example ```json { "status": "ok" } ``` ``` -------------------------------- ### Trait Implementations Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend This section documents the implementations of various standard Rust traits for the `TermionBackend` struct, including Clone, Debug, Default, Hash, PartialEq, Eq, and Write. ```APIDOC ## Trait: Clone ### Description Provides the ability to create a duplicate of a `TermionBackend` instance. ### Methods #### `clone(&self) -> TermionBackend` Returns a duplicate of the value. #### `clone_from(&mut self, source: &Self)` Performs copy-assignment from `source`. ## Trait: Debug ### Description Enables debugging of `TermionBackend` instances. ### Methods #### `fmt(&self, f: &mut Formatter<'_>) -> Result` Formats the value using the given formatter. ## Trait: Default ### Description Provides a default value for `TermionBackend`. ### Methods #### `default() -> TermionBackend` Returns the "default value" for a type. ## Trait: Hash ### Description Allows `TermionBackend` instances to be hashed. ### Methods #### `hash<__H: Hasher>(&self, state: &mut __H)` Feeds this value into the given `Hasher`. #### `hash_slice(data: &[Self], state: &mut H)` Feeds a slice of this type into the given `Hasher`. ## Trait: PartialEq ### Description Enables equality comparison between `TermionBackend` instances. ### Methods #### `eq(&self, other: &TermionBackend) -> bool` Tests for `self` and `other` values to be equal. #### `ne(&self, other: &Rhs) -> bool` Tests for `!=`. ## Trait: Eq ### Description Marks `TermionBackend` as a type that supports total equality. ## Trait: Write ### Description Provides methods for writing data to the terminal backend. ### Methods #### `write(&mut self, buf: &[u8]) -> Result` Writes a buffer into this writer, returning how many bytes were written. #### `flush(&mut self) -> Result<()>` Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. #### `write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result` Writes from a slice of buffers. #### `is_write_vectored(&self) -> bool` Determines if this `Writer` has an efficient `write_vectored` implementation. #### `write_all(&mut self, buf: &[u8]) -> Result<(), Error>` Attempts to write an entire buffer into this writer. #### `write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>` Attempts to write multiple buffers into this writer. #### `write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>` Writes a formatted string into this writer. #### `by_ref(&mut self) -> &mut Self` Creates a “by reference” adapter for this instance of `Write`. ## Auto Trait Implementations ### `impl Freeze for TermionBackend where W: Freeze` ### `impl RefUnwindSafe for TermionBackend where W: RefUnwindSafe` ### `impl Send for TermionBackend where W: Send` ### `impl Sync for TermionBackend where W: Sync` ### `impl Unpin for TermionBackend where W: Unpin` ### `impl UnwindSafe for TermionBackend where W: UnwindSafe` ## Blanket Implementations ### `impl Any for T where T: 'static + ?Sized` #### `type_id(&self) -> TypeId` Gets the `TypeId` of `self`. ### `impl Borrow for T where T: ?Sized` #### `borrow(&self) -> &T` Immutably borrows from an owned value. ### `impl BorrowMut for T where T: ?Sized` #### `borrow_mut(&mut self) -> &mut T` Mutably borrows from an owned value. ### `impl CloneToUninit for T where T: Clone` ``` -------------------------------- ### Write Implementation Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=std%3A%3Avec Methods related to writing data to the terminal output, including buffer writing and flushing. ```APIDOC ## POST /websites/rs_ratatui-termion_0_1_0/write ### Description Writes a buffer of bytes to the terminal output, returning the number of bytes written. ### Method POST ### Endpoint /websites/rs_ratatui-termion_0_1_0/write ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **buf** (slice of u8) - Required - The byte buffer to write. ### Request Example ```json { "buf": [65, 66, 67] } ``` ### Response #### Success Response (200) - **bytes_written** (usize) - The number of bytes successfully written. #### Response Example ```json { "bytes_written": 3 } ``` ## POST /websites/rs_ratatui-termion_0_1_0/flush ### Description Flushes the output stream, ensuring all buffered contents are sent to their destination. ### Method POST ### Endpoint /websites/rs_ratatui-termion_0_1_0/flush ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example (No request body for flush operation) ### Response #### Success Response (200) - **Result** (Result<()>) - Indicates success or failure of the flush operation. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Style Conversions Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/trait.FromTermion_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Implementations of `FromTermion` for converting Termion foreground color types to Ratatui `Style`. ```APIDOC ## Style Conversions This section details the `FromTermion` trait implementations for converting Termion foreground color types into Ratatui's `Style`. ### `impl FromTermion> for Style` Converts `termion::color::Fg` to `ratatui::style::Style`. - **Method**: `from_termion` - **Parameters**: `_: Fg` ### `impl FromTermion> for Style` Converts `termion::color::Fg` to `ratatui::style::Style`. - **Method**: `from_termion` - **Parameters**: `_: Fg` ``` -------------------------------- ### Termion Backend Implementation using Termion Crate Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/index_search= This snippet showcases the TermionBackend implementation, which leverages the Termion crate for terminal interaction. It is part of the ratatui-termion module, designed for fine-grained control over dependencies and backend functionality. ```Rust pub struct TermionBackend { ... } ``` -------------------------------- ### Get Mutable Writer from TermionBackend (Unstable) Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Demonstrates obtaining a mutable reference to the underlying writer of a TermionBackend. This feature is unstable and requires the 'unstable-backend-writer' flag. Direct modifications to the writer can lead to unexpected rendering issues. ```rust pub const fn writer_mut(&mut self) -> &mut W where W: Write, { /* ... */ } ``` -------------------------------- ### PartialEq and Eq for TermionBackend Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Implements equality comparison traits (`PartialEq` and `Eq`) for `TermionBackend`. The `eq` method allows checking if two `TermionBackend` instances are equal, and `ne` provides the inequality check. These are fundamental for comparing terminal states. ```rust fn eq(&self, other: &TermionBackend) -> bool Tests for `self` and `other` values to be equal, and is used by `==`. 1.0.0 · Source§ ``` ```rust fn ne(&self, other: &Rhs) -> bool Tests for `!=`. The default implementation is almost always sufficient, and should not be overridden without very good reason. Source§ ``` -------------------------------- ### TermionBackend Size and Window Size Retrieval (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/src/ratatui_termion/lib.rs_search= Retrieves the terminal's size (columns and rows) using `termion::terminal_size()`. Also provides a method to get the window size, which is essentially the same as the terminal size in this implementation. ```rust impl Backend for TermionBackend where W: Write, { // ... other methods ... fn size(&self) -> io::Result { let terminal = termion::terminal_size()?; Ok(Size::new(terminal.0, terminal.1)) } fn window_size(&mut self) -> io::Result { Ok(WindowSize { columns_rows: termion::terminal_size()?.into(), }) } } ``` -------------------------------- ### Type Conversion APIs Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides various methods for type conversion, including cloning, into, and try_from/try_into operations. ```APIDOC ## fn clone_to_uninit(&self, dest: *mut u8) ### Description This is a nightly-only experimental API. Performs copy-assignment from `self` to `dest`. ### Method POST ### Endpoint /clone-to-uninit ### Parameters #### Path Parameters - **self** (Self) - Required - The source object to clone from. - **dest** (*mut u8) - Required - A mutable pointer to the destination buffer. ### Request Example (This is a low-level operation and a direct request example is not typically provided in this format.) ### Response #### Success Response (200) (This function operates in-place and does not typically return a value on success.) ``` ```APIDOC ## fn equivalent(&self, key: &K) -> bool ### Description Compare self to `key` and return `true` if they are equal. ### Method POST ### Endpoint /equivalent ### Parameters #### Query Parameters - **self** (Self) - Required - The object to compare. - **key** (K) - Required - The key to compare against. ### Response #### Success Response (200) - **is_equivalent** (bool) - True if the objects are equivalent, false otherwise. #### Response Example { "is_equivalent": true } ``` ```APIDOC ## fn from(t: T) -> T ### Description Returns the argument unchanged. ### Method POST ### Endpoint /from ### Parameters #### Query Parameters - **t** (T) - Required - The value to convert. ### Response #### Success Response (200) - **value** (T) - The unchanged argument. #### Response Example { "value": "" } ``` ```APIDOC ## fn into(self) -> U ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Method POST ### Endpoint /into ### Parameters #### Query Parameters - **self** (Self) - Required - The value to convert. ### Response #### Success Response (200) - **converted_value** (U) - The converted value. #### Response Example { "converted_value": "" } ``` ```APIDOC ## fn into_either(self, into_left: bool) -> Either ### Description Converts `self` into a `Left` variant of `Either` if `into_left` is `true`. Converts `self` into a `Right` variant of `Either` otherwise. ### Method POST ### Endpoint /into-either ### Parameters #### Query Parameters - **self** (Self) - Required - The value to convert. - **into_left** (bool) - Required - If true, convert to `Left`; otherwise, convert to `Right`. ### Response #### Success Response (200) - **either_value** (Either) - The resulting `Either` variant. #### Response Example { "either_value": { "Left": "" } } ``` ```APIDOC ## fn into_either_with(self, into_left: F) -> Either ### Description Converts `self` into a `Left` variant of `Either` if `into_left(&self)` returns `true`. Converts `self` into a `Right` variant of `Either` otherwise. ### Method POST ### Endpoint /into-either-with ### Parameters #### Query Parameters - **self** (Self) - Required - The value to convert. - **into_left** (F) - Required - A closure that returns true to convert to `Left`, false to convert to `Right`. ### Response #### Success Response (200) - **either_value** (Either) - The resulting `Either` variant. #### Response Example { "either_value": { "Right": "" } } ``` ```APIDOC ## fn to_owned(&self) -> T ### Description Creates owned data from borrowed data, usually by cloning. ### Method GET ### Endpoint /to-owned ### Parameters #### Query Parameters - **self** (Self) - Required - The borrowed data. ### Response #### Success Response (200) - **owned_data** (T) - The owned data. #### Response Example { "owned_data": "" } ``` ```APIDOC ## fn clone_into(&self, target: &mut T) ### Description Uses borrowed data to replace owned data, usually by cloning. ### Method POST ### Endpoint /clone-into ### Parameters #### Query Parameters - **self** (Self) - Required - The borrowed data to clone from. - **target** (&mut T) - Required - The mutable reference to the owned data to be replaced. ### Request Example (This function modifies data in-place and a direct request example is not typically provided in this format.) ### Response #### Success Response (200) (This function operates in-place and does not typically return a value on success.) ``` ```APIDOC ## fn try_from(value: U) -> Result>::Error> ### Description Performs the conversion. Returns `Ok(T)` on success or `Err(...)` on failure. ### Method POST ### Endpoint /try-from ### Parameters #### Query Parameters - **value** (U) - Required - The value to attempt conversion from. ### Response #### Success Response (200) - **converted_value** (T) - The successfully converted value. #### Error Response (400) - **error** (Error) - The error encountered during conversion. #### Response Example { "converted_value": "" } ``` ```APIDOC ## fn try_into(self) -> Result>::Error> ### Description Performs the conversion. Returns `Ok(U)` on success or `Err(...)` on failure. ### Method POST ### Endpoint /try-into ### Parameters #### Query Parameters - **self** (Self) - Required - The value to attempt conversion into. ### Response #### Success Response (200) - **converted_value** (U) - The successfully converted value. #### Error Response (400) - **error** (Error) - The error encountered during conversion. #### Response Example { "converted_value": "" } ``` -------------------------------- ### IntoAlternateScreen API Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search=u32+-%3E+bool Switches the terminal to use the alternate screen. The terminal will be restored when the returned `AlternateScreen` guard is dropped. ```APIDOC ## POST /websites/rs_ratatui-termion_0_1_0/into_alternate_screen ### Description Switch the terminal controlled by this writer to use the alternate screen. The terminal will be restored to the main screen when the `AlternateScreen` returned by this function is dropped. ### Method POST ### Endpoint /websites/rs_ratatui-termion_0_1_0/into_alternate_screen ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **alternate_screen_guard** (*AlternateScreen*) - A guard that manages the alternate screen session. #### Response Example ```json { "message": "Alternate screen activated. Restore on drop." } ``` ``` -------------------------------- ### Get Writer from TermionBackend (Unstable) Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/struct.TermionBackend_search= Shows how to access the underlying writer from a TermionBackend instance. This method is unstable and requires enabling the 'unstable-backend-writer' feature flag. Use with caution as direct writing might interfere with Terminal's buffer management. ```rust pub const fn writer(&self) -> &W where W: Write, { /* ... */ } ``` -------------------------------- ### Implement FromTermion for Termion Background Colors to Style Conversion (Rust) Source: https://docs.rs/ratatui-termion/0.1.0/ratatui_termion/trait.FromTermion_search= These implementations cover the conversion of various Termion background color types (e.g., `Bg`, `Bg`, `Bg`) into Ratatui `Style`. Each implementation maps a specific Termion background to its corresponding Ratatui style representation. ```rust impl FromTermion> for Style { fn from_termion(value: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(value: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } impl FromTermion> for Style { fn from_termion(_: Bg) -> Self; } ```