### Set up and run the web example with Trunk Source: https://github.com/aschey/terminput/blob/main/examples/web/README.md Run these commands in a terminal to build and serve the web example. First add the wasm32-unknown-unknown target, then install Trunk, and finally start the Trunk development server with `trunk serve`. ```sh rustup target add wasm32-unknown-unknown cargo install trunk trunk serve ``` -------------------------------- ### Convert crossterm events to and from terminput Source: https://github.com/aschey/terminput/blob/main/README.md Shows how to convert between crossterm events and terminput's Event type using the terminput-crossterm integration crate. The conversion works in both directions: to_terminput converts a crossterm event to terminput, and to_crossterm converts back. Requires the crossterm and terminput-crossterm crates. ```rust use crossterm::event::read; use std::io; use terminput::Event; use terminput_crossterm::{to_crossterm, to_terminput}; fn main() -> io::Result<()> { let crossterm_event = read()?; let event: Result = to_terminput(crossterm_event); println!("{event:?}"); if let Ok(event) = event { // Conversions work both ways let event2: Result = to_crossterm(event); println!("{event2:?}"); } Ok(()) } ``` -------------------------------- ### Encode events with Event::encode Source: https://github.com/aschey/terminput/blob/main/README.md Encodes an Event into ANSI escape sequences using Event::encode. Shows both legacy (Encoding::Xterm) and Kitty (Encoding::Kitty with all flags) encodings. Useful for sending input to a child pty. ```rust use terminput::{Encoding, Event, KeyCode, KeyEvent, KittyFlags}; let event = Event::Key(KeyEvent::new(KeyCode::Char('a'))); let mut buf = [0; 16]; // Legacy encoding let written = event.encode(&mut buf, Encoding::Xterm); if let Ok(written) = written { println!("Encoded: {:?}", &buf[..written]); } // Kitty encoding let mut buf = [0; 16]; let written = event.encode(&mut buf, Encoding::Kitty(KittyFlags::all())); if let Ok(written) = written { println!("Encoded: {:?}", &buf[..written]); } ``` -------------------------------- ### Parse ANSI input with Event::parse_from Source: https://github.com/aschey/terminput/blob/main/README.md Parses an ANSI-encoded byte sequence into an Event using Event::parse_from. Useful for reading raw input from non-TTY sources like SSH. Returns Ok(None) when more input is required and Err on parse failure. ```rust use terminput::Event; fn read_input(input: &[u8]) { let event = Event::parse_from(input); match event { Ok(Some(event)) => { println!("Successfully parsed input: {event:?}"); } Ok(None) => { println!("More input required"); } Err(e) => { println!("Unable to parse input: {e:?}"); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.