### Full CrosstermBackend Example with Terminal Setup Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search= Demonstrates the complete setup for using CrosstermBackend with a Terminal, including enabling raw mode, entering alternate screen, drawing content, and cleaning up. ```rust use std::io::{stderr, stdout}; use crossterm::ExecutableCommand; use crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; let mut backend = CrosstermBackend::new(stdout()); // or let backend = CrosstermBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; enable_raw_mode()?; stdout().execute(EnterAlternateScreen)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; stdout().execute(LeaveAlternateScreen)?; disable_raw_mode()?; ``` -------------------------------- ### Full Terminal Setup with Crossterm Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search= Illustrates a complete setup for a Ratatui application using CrosstermBackend. It includes enabling raw mode, entering alternate screen, rendering, and then cleaning up by leaving alternate screen and disabling raw mode. ```rust use std::io::{stderr, stdout}; use crossterm::ExecutableCommand; use crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; let mut backend = CrosstermBackend::new(stdout()); // or // let backend = CrosstermBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; enable_raw_mode()?; stdout().execute(EnterAlternateScreen)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; stdout().execute(LeaveAlternateScreen)?; disable_raw_mode()?; # std::io::Result::Ok(()) ``` -------------------------------- ### CrosstermBackend Initialization and Usage Example Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search=std%3A%3Avec This example demonstrates how to initialize a CrosstermBackend with stdout, set up raw mode and alternate screen, clear the terminal, and draw content using a Terminal instance. It also shows how to clean up by leaving alternate screen and disabling raw mode. ```rust use std::io::{stderr, stdout}; use crossterm::ExecutableCommand; use crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; let mut backend = CrosstermBackend::new(stdout()); // or let backend = CrosstermBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; enable_raw_mode()?; stdout().execute(EnterAlternateScreen)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; stdout().execute(LeaveAlternateScreen)?; disable_raw_mode()?; ``` -------------------------------- ### Full CrosstermBackend Usage Example Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A comprehensive example illustrating the typical lifecycle of using CrosstermBackend with Ratatui. It includes enabling raw mode, entering alternate screen, rendering with a Terminal, and cleaning up by leaving the alternate screen and disabling raw mode. ```rust use std::io::{stderr, stdout}; use crossterm::ExecutableCommand; use crossterm::terminal::{ EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode, }; use ratatui::Terminal; use ratatui::backend::CrosstermBackend; let mut backend = CrosstermBackend::new(stdout()); // or let backend = CrosstermBackend::new(stderr()); let mut terminal = Terminal::new(backend)?; enable_raw_mode()?; stdout().execute(EnterAlternateScreen)?; terminal.clear()?; terminal.draw(|frame| { // -- snip -- })?; stdout().execute(LeaveAlternateScreen)?; disable_raw_mode()?; # std::io::Result::Ok(()) ``` -------------------------------- ### Crossterm Version Re-export Example Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html Demonstrates how enabling a feature flag for a specific Crossterm version (e.g., `crossterm_0_29`) makes that version available via `ratatui_crossterm::crossterm`. This ensures consistent use of Crossterm types and functions across the application. ```rust #![cfg_attr(feature = "crossterm_0_29", allow(unused_imports))] #[cfg(feature = "crossterm_0_29")] pub use crossterm_0_29 as crossterm; #[cfg(not(feature = "crossterm_0_29"))] #[cfg(feature = "crossterm_0_28")] pub use crossterm_0_28 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28")))] #[cfg(feature = "crossterm_0_27")] pub use crossterm_0_27 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27")))] #[cfg(feature = "crossterm_0_26")] pub use crossterm_0_26 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26")))] #[cfg(feature = "crossterm_0_25")] pub use crossterm_0_25 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25")))] #[cfg(feature = "crossterm_0_24")] pub use crossterm_0_24 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24")))] #[cfg(feature = "crossterm_0_23")] pub use crossterm_0_23 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23")))] #[cfg(feature = "crossterm_0_22")] pub use crossterm_0_22 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22")))] #[cfg(feature = "crossterm_0_21")] pub use crossterm_0_21 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21")))] #[cfg(feature = "crossterm_0_20")] pub use crossterm_0_20 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20")))] #[cfg(feature = "crossterm_0_19")] pub use crossterm_0_19 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19")))] #[cfg(feature = "crossterm_0_18")] pub use crossterm_0_18 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18")))] #[cfg(feature = "crossterm_0_17")] pub use crossterm_0_17 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17")))] #[cfg(feature = "crossterm_0_16")] pub use crossterm_0_16 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16")))] #[cfg(feature = "crossterm_0_15")] pub use crossterm_0_15 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15")))] #[cfg(feature = "crossterm_0_14")] pub use crossterm_0_14 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14")))] #[cfg(feature = "crossterm_0_13")] pub use crossterm_0_13 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13")))] #[cfg(feature = "crossterm_0_12")] pub use crossterm_0_12 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12")))] #[cfg(feature = "crossterm_0_11")] pub use crossterm_0_11 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11")))] #[cfg(feature = "crossterm_0_10")] pub use crossterm_0_10 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10")))] #[cfg(feature = "crossterm_0_9")] pub use crossterm_0_9 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9")))] #[cfg(feature = "crossterm_0_8")] pub use crossterm_0_8 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8")))] #[cfg(feature = "crossterm_0_7")] pub use crossterm_0_7 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7")))] #[cfg(feature = "crossterm_0_6")] pub use crossterm_0_6 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7", feature = "crossterm_0_6")))] #[cfg(feature = "crossterm_0_5")] pub use crossterm_0_5 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7", feature = "crossterm_0_6", feature = "crossterm_0_5")))] #[cfg(feature = "crossterm_0_4")] pub use crossterm_0_4 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7", feature = "crossterm_0_6", feature = "crossterm_0_5", feature = "crossterm_0_4")))] #[cfg(feature = "crossterm_0_3")] pub use crossterm_0_3 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7", feature = "crossterm_0_6", feature = "crossterm_0_5", feature = "crossterm_0_4", feature = "crossterm_0_3")))] #[cfg(feature = "crossterm_0_2")] pub use crossterm_0_2 as crossterm; #[cfg(not(any(feature = "crossterm_0_29", feature = "crossterm_0_28", feature = "crossterm_0_27", feature = "crossterm_0_26", feature = "crossterm_0_25", feature = "crossterm_0_24", feature = "crossterm_0_23", feature = "crossterm_0_22", feature = "crossterm_0_21", feature = "crossterm_0_20", feature = "crossterm_0_19", feature = "crossterm_0_18", feature = "crossterm_0_17", feature = "crossterm_0_16", feature = "crossterm_0_15", feature = "crossterm_0_14", feature = "crossterm_0_13", feature = "crossterm_0_12", feature = "crossterm_0_11", feature = "crossterm_0_10", feature = "crossterm_0_9", feature = "crossterm_0_8", feature = "crossterm_0_7", feature = "crossterm_0_6", feature = "crossterm_0_5", feature = "crossterm_0_4", feature = "crossterm_0_3", feature = "crossterm_0_2")))] #[cfg(feature = "crossterm_0_1")] pub use crossterm_0_1 as crossterm; ``` -------------------------------- ### CrosstermBackend Methods Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search=std%3A%3Avec Provides methods for interacting with the terminal backend, such as getting window size, flushing output, and managing the cursor. ```APIDOC ## `window_size()` ### Description Get the size of the terminal screen in columns/rows and pixels as a `WindowSize`. ### Method `fn` ### Endpoint N/A (Method call) ### Parameters None ### Response - `Result`: The size of the terminal window. ``` ```APIDOC ## `flush()` ### Description Flush any backend-buffered output to the terminal screen. ### Method `fn` ### Endpoint N/A (Method call) ### Parameters None ### Response - `Result<()>`: Indicates success or failure of the flush operation. ``` ```APIDOC ## `get_cursor()` ### Description Get the current cursor position on the terminal screen. This method is deprecated and `get_cursor_position()` should be used instead. ### Method `fn` ### Endpoint N/A (Method call) ### Parameters None ### Response - `Result<(u16, u16), Self::Error>`: The current cursor position (x, y). ``` ```APIDOC ## `set_cursor(x: u16, y: u16)` ### Description Set the cursor position on the terminal screen to the given x and y coordinates. This method is deprecated and `set_cursor_position()` should be used instead. ### Method `fn` ### Endpoint N/A (Method call) ### Parameters - **x** (u16) - The x-coordinate for the cursor. - **y** (u16) - The y-coordinate for the cursor. ### Response - `Result<(), Self::Error>`: Indicates success or failure of setting the cursor position. ``` -------------------------------- ### Get Window Size (Pixels and Rows/Columns) Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves detailed window size information, including both character-based dimensions (columns, rows) and pixel-based dimensions (width, height). ```rust fn window_size(&mut self) -> io::Result { let crossterm::terminal::WindowSize { columns, rows, width, height, } = terminal::window_size()?; Ok(WindowSize { columns_rows: Size { width: columns, height: rows, }, pixels: Size { width, height }, }) } ``` -------------------------------- ### type_id Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html Gets the `TypeId` of the `CrosstermBackend` instance. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `&self` ### Return Value - `TypeId`: The `TypeId` of the `CrosstermBackend`. ``` -------------------------------- ### default Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html Creates a new `CrosstermBackend` with default settings. ```APIDOC ## fn default() -> CrosstermBackend ### Description Returns the “default value” for a type. ### Method `()` (static method) ### Return Value - `CrosstermBackend`: A new `CrosstermBackend` instance with default values. ``` -------------------------------- ### Convert Default ContentStyle to Ratatui Style Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=u32+-%3E+bool Demonstrates the conversion of a default `ContentStyle` to a Ratatui `Style`. This is a basic case for initializing Ratatui styles from default content styles. ```rust #[case(ContentStyle::default(), Style::default())] ``` -------------------------------- ### Get Cursor Position Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html Retrieves the current position of the terminal cursor. ```APIDOC ## get_cursor_position ### Description Retrieves the current position of the terminal cursor. ### Method `get_cursor_position` ### Response - `io::Result`: Returns Ok(Position) with the cursor's x and y coordinates, or an io::Error on failure. ``` -------------------------------- ### Using Re-exported Crossterm Version Source: https://docs.rs/ratatui-crossterm/latest/index.html Demonstrates how to use the re-exported Crossterm crate to ensure compatibility with the version used by ratatui-crossterm. This is crucial for direct Crossterm operations. ```rust pub use crossterm_0_29 as crossterm; ``` -------------------------------- ### CrosstermBackend::writer Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets a reference to the underlying writer used by the CrosstermBackend. ```APIDOC ## `CrosstermBackend::writer` ### Description Gets a reference to the underlying writer used by the `CrosstermBackend`. ### Method `#[instability::unstable(feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991")] pub const fn writer(&self) -> &W` ### Returns A reference to the underlying writer (`&W`). ``` -------------------------------- ### Cursor Position Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search= Functions to get and set the terminal cursor's position. ```APIDOC ## fn get_cursor_position(&mut self) -> io::Result ### Description Retrieves the current position of the terminal cursor. ### Method `get_cursor_position` ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```rust // let mut ratatui_crossterm = RatatuiCrossterm::new(writer); // let position = ratatui_crossterm.get_cursor_position()?; ``` ### Response #### Success Response (io::Result) Returns the cursor's `Position` (x, y coordinates). #### Response Example ```json { "x": 10, "y": 5 } ``` ## fn set_cursor_position>(&mut self, position: P) -> io::Result<()> ### Description Sets the terminal cursor to a specified position. ### Method `set_cursor_position` ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **position** (P: Into) - Required - The target position to move the cursor to. ### Request Example ```rust // let mut ratatui_crossterm = RatatuiCrossterm::new(writer); // ratatui_crossterm.set_cursor_position((10, 5))?; ``` ### Response #### Success Response (io::Result<()>) Indicates successful execution. #### Response Example ```rust // Success is indicated by the absence of an error. ``` ``` -------------------------------- ### CrosstermBackend::writer_mut Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets a mutable reference to the underlying writer used by the CrosstermBackend. ```APIDOC ## `CrosstermBackend::writer_mut` ### Description Gets a mutable reference to the underlying writer used by the `CrosstermBackend`. Note: writing to the writer may cause incorrect output after the write. This is due to the way that the Terminal implements diffing Buffers. ### Method `#[instability::unstable(feature = "backend-writer", issue = "https://github.com/ratatui/ratatui/pull/991")] pub const fn writer_mut(&mut self) -> &mut W` ### Returns A mutable reference to the underlying writer (`&mut W`). ``` -------------------------------- ### Convert ContentStyle with Foreground Color to Ratatui Style Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search= Demonstrates how a `ContentStyle` with a specified foreground color (e.g., `CrosstermColor::DarkYellow`) is translated into the corresponding Ratatui `Style` with a foreground color (e.g., `Color::Yellow`). ```rust @case( ContentStyle { foreground_color: Some(CrosstermColor::DarkYellow), ..Default::default() }, Style::default().fg(Color::Yellow) ) ``` -------------------------------- ### type_id Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search=u32+-%3E+bool Gets the `TypeId` of the `CrosstermBackend` instance, used for runtime type identification. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Parameters None ### Returns - `TypeId`: The `TypeId` of the `CrosstermBackend` instance. ``` -------------------------------- ### Convert Default ContentStyle to Ratatui Style Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search= Illustrates the conversion of a default `ContentStyle` (with no specific colors set) to a default Ratatui `Style`. This shows the baseline mapping when no custom styling is applied. ```rust @case(ContentStyle::default(), Style::default()) ``` -------------------------------- ### Get Terminal Size Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html Retrieves the current size of the terminal in characters (columns and rows). ```APIDOC ## size ### Description Retrieves the current size of the terminal in characters (columns and rows). ### Method `size` ### Response - `io::Result`: Returns Ok(Size) with the terminal's width and height, or an io::Error on failure. ``` -------------------------------- ### Implement FromCrossterm for Style from ContentStyle Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/trait.FromCrossterm.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Implementation of FromCrossterm to convert Crossterm's ContentStyle to Ratatui's Style. ```rust fn from_crossterm(value: ContentStyle) -> Self; ``` -------------------------------- ### Get Window Size Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html Retrieves the current size of the terminal window in both characters (columns/rows) and pixels. ```APIDOC ## window_size ### Description Retrieves the current size of the terminal window in both characters (columns/rows) and pixels. ### Method `window_size` ### Response - `io::Result`: Returns Ok(WindowSize) containing character-based and pixel-based sizes, or an io::Error on failure. ``` -------------------------------- ### default Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search=u32+-%3E+bool Creates a new `CrosstermBackend` instance with its default values. ```APIDOC ## fn default() -> CrosstermBackend ### Description Returns the "default value" for a type. ### Method `default` ### Parameters None ### Returns - `CrosstermBackend`: A new `CrosstermBackend` instance initialized with default settings. ``` -------------------------------- ### Initialize CrosstermBackend with stdout Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search= Creates a new CrosstermBackend instance using standard output as the writer. ```rust use std::io::stdout; use ratatui::backend::CrosstermBackend; let backend = CrosstermBackend::new(stdout()); ``` -------------------------------- ### CrosstermBackend::writer_mut Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search= Gets the writer as a mutable reference. This API is unstable and requires the 'unstable-backend-writer' feature. ```APIDOC ## CrosstermBackend::writer_mut ### Description 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. ### Stability **This API is marked as unstable** and is only available when the `unstable-backend-writer` crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time. The tracking issue is: `https://github.com/ratatui/ratatui/pull/991`. ### Method `fn writer_mut(&mut self) -> &mut W` ### Returns A mutable reference to the underlying writer. ``` -------------------------------- ### Initialize CrosstermBackend with stderr Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Shows how to initialize a CrosstermBackend using standard error. The choice between stdout and stderr depends on the application's needs, as detailed in the Ratatui FAQ. ```rust use std::io::stderr; use ratatui::backend::CrosstermBackend; let backend = CrosstermBackend::new(stderr()); ``` -------------------------------- ### CrosstermBackend::writer Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search= Gets the writer as an immutable reference. This API is unstable and requires the 'unstable-backend-writer' feature. ```APIDOC ## CrosstermBackend::writer ### Description Gets the writer. ### Stability **This API is marked as unstable** and is only available when the `unstable-backend-writer` crate feature is enabled. This comes with no stability guarantees, and could be changed or removed at any time. The tracking issue is: `https://github.com/ratatui/ratatui/pull/991`. ### Method `fn writer(&self) -> &W` ### Returns A reference to the underlying writer. ``` -------------------------------- ### Get Cursor Position Source: https://docs.rs/ratatui-crossterm/latest/src/ratatui_crossterm/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the current position of the terminal cursor. Returns an io::Result containing a Position struct. ```rust fn get_cursor_position(&mut self) -> io::Result { crossterm::cursor::position() .map(|(x, y)| Position { x, y }) .map_err(io::Error::other) } ``` -------------------------------- ### by_ref Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html Creates a "by reference" adapter for the `CrosstermBackend` instance, allowing mutable borrowing. ```APIDOC ## fn by_ref(&mut self) -> &mut Self ### Description Creates a “by reference” adapter for this instance of `Write`. ### Method `&mut self` ### Return Value - `&mut Self`: A mutable reference to the `CrosstermBackend`. ``` -------------------------------- ### queue Source: https://docs.rs/ratatui-crossterm/latest/ratatui_crossterm/struct.CrosstermBackend.html?search= Queues the given command for further execution. Queued commands will be executed when `flush` is called or when the buffer is full. ```APIDOC ## fn queue(&mut self, command: impl Command) -> Result<&mut T, Error> ### Description Queues the given command for further execution. Queued commands will be executed when `flush` is called manually on the given type implementing `io::Write`, when the terminal automatically flushes the buffer, or each line is flushed in case of `stdout` because it is line buffered. ### Method `queue` ### Arguments * `command` - The command that you want to queue for later execution. ### Example ```rust use std::io::{self, Write}; use crossterm::{QueueableCommand, style::Print}; fn main() -> io::Result<()> { let mut stdout = io::stdout(); // `Print` will executed executed when `flush` is called. stdout .queue(Print("foo 1\n".to_string()))? .queue(Print("foo 2".to_string()))?; // some other code (no execution happening here) ... // when calling `flush` on `stdout`, all commands will be written to the stdout and therefore executed. stdout.flush()?; Ok(()) // ==== Output ==== // foo 1 // foo 2 } ``` ### Notes * In the case of UNIX and Windows 10, ANSI codes are written to the given ‘writer’. * In case of Windows versions lower than 10, a direct WinAPI call will be made. The reason for this is that Windows versions lower than 10 do not support ANSI codes, and can therefore not be written to the given `writer`. Therefore, there is no difference between execute and queue for those old Windows versions. ```