### Run `editor` example for a simple text editor Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Demonstrates a simple text editor that can edit multiple files. The command runs the example with search features enabled and specifies a file. ```Shell cargo run --example editor --features search file.txt ``` -------------------------------- ### Run `tui-rs` versions of examples Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Commands to run `tui-rs` compatible versions of `minimal`, `editor`, and `termion` examples. These require specifying `tuirs-crossterm` or `tuirs-termion` features and disabling default features. ```Shell # tui-rs version of `minimal` example cargo run --example tuirs_minimal --no-default-features --features=tuirs-crossterm ``` ```Shell # tui-rs version of `editor` example cargo run --example tuirs_editor --no-default-features --features=tuirs-crossterm,search file.txt ``` ```Shell # tui-rs version of `termion` example cargo run --example tuirs_termion --no-default-features --features=tuirs-termion ``` -------------------------------- ### Run `split` example for multiple textareas Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Illustrates how to use multiple `textarea` instances by splitting the screen into two textareas and switching between them. ```Shell cargo run --example split ``` -------------------------------- ### Run `termion` example for minimal usage Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Illustrates minimal usage of `tui-textarea` with `termion` backend support. Requires disabling default features and enabling the `termion` feature. ```Shell cargo run --example termion --no-default-features --features=termion ``` -------------------------------- ### Run `termwiz` example for minimal usage Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Illustrates minimal usage of `tui-textarea` with `termwiz` backend support. Requires disabling default features and enabling the `termwiz` feature. ```Shell cargo run --example termwiz --no-default-features --features=termwiz ``` -------------------------------- ### Run `vim` example for Vim-like editor Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Provides a Vim-like modal text editor. The Vim emulation is implemented as a state machine. ```Shell cargo run --example vim ``` -------------------------------- ### Run `popup_placeholder` example for popup textarea Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Shows a popup textarea that includes a placeholder text. ```Shell cargo run --example popup_placeholder ``` -------------------------------- ### Managing Multiple TextArea Instances and Focus Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Provides an example of how to manage multiple `TextArea` instances on screen, rendering them and switching focus between them based on user input (e.g., Ctrl+S). ```Rust use tui_textarea::{TextArea, Input, Key}; use crossterm::event::{Event, read}; let editors = &mut [ TextArea::default(), TextArea::default(), ]; let mut focused = 0; loop { term.draw(|f| { let rects = ...; for (editor, rect) in editors.iter().zip(rects.into_iter()) { f.render_widget(editor, rect); } })?; match read()?.into() { // Switch focused textarea by Ctrl+S Input { key: Key::Char('s'), ctrl: true, .. } => focused = (focused + 1) % 2; // Handle input by the focused editor input => editors[focused].input(input), } } ``` -------------------------------- ### Install a pre-built binary with poof Source: https://docs.rs/arrayvec/latest/arrayvec/crate/poof/0.5 This command demonstrates how to use `poof` to download and install a specific pre-built binary from a GitHub repository. It simplifies the process of getting tools into your shell without manual downloads or system package managers. ```Shell poof install pirafrank/rust_exif_renamer ``` -------------------------------- ### Add `tui-textarea` to `Cargo.toml` dependencies Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Basic installation of `tui-textarea` crate by adding it to the `[dependencies]` section of `Cargo.toml`. This enables `crossterm` backend support by default. ```TOML [dependencies] ratatui = "*" tui-textarea = "*" ``` -------------------------------- ### Rust nostr-sdk Client Initialization and Event Publishing Source: https://docs.rs/arrayvec/latest/arrayvec/nostr-sdk/^0.37 This example demonstrates the full lifecycle of a `nostr-sdk` client. It covers generating and parsing keys, configuring proxy connections, adding and connecting to relays, updating user metadata, publishing standard and Proof-of-Work text notes, and performing various types of Lightning zap payments to profiles and events. ```Rust use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::str::FromStr; use nostr_sdk::prelude::*; #[tokio::main] async fn main() -> Result<()> { // Generate new random keys let keys = Keys::generate(); // Or use your already existing (from hex or bech32) let keys = Keys::parse("hex-or-bech32-secret-key")?; // Show bech32 public key let bech32_pubkey: String = keys.public_key().to_bech32()?; println!("Bech32 PubKey: {}", bech32_pubkey); // Configure client to use proxy for `.onion` relays let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050)); let connection: Connection = Connection::new() .proxy(addr) // Use `.embedded_tor()` instead to enable the embedded tor client (require `tor` feature) .target(ConnectionTarget::Onion); let opts = Options::new().connection(connection); // Create new client with custom options. // Use `Client::new(signer)` to construct the client with a custom signer and default options // or `Client::default()` to create one without signer and with default options. let client = Client::with_opts(keys.clone(), opts); // Add relays client.add_relay("wss://relay.damus.io").await?; client.add_relay("ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion").await?; // Add read relay client.add_read_relay("wss://relay.nostr.info").await?; // Connect to relays client.connect().await; let metadata = Metadata::new() .name("username") .display_name("My Username") .about("Description") .picture(Url::parse("https://example.com/avatar.png")?) .banner(Url::parse("https://example.com/banner.png")?) .nip05("username@example.com") .lud16("pay@yukikishimoto.com") .custom_field("custom_field", "my value"); // Update metadata client.set_metadata(&metadata).await?; // Publish a text note let builder = EventBuilder::text_note("My first text note from rust-nostr!"); client.send_event_builder(builder).await?; // Create a POW text note let builder = EventBuilder::text_note("POW text note from nostr-sdk").pow(20); client.send_event_builder(builder).await?; // Send to all relays // client.send_event_builder_to(["wss://relay.damus.io"], builder).await?; // Send to specific relay // --------- Zap! ------------- // Configure zapper let uri = NostrWalletConnectURI::from_str("nostr+walletconnect://...")?; let zapper = NWC::new(uri); // Use `WebLNZapper::new().await` for WebLN client.set_zapper(zapper).await; // Send SAT without zap event let public_key = PublicKey::from_bech32( "npub1drvpzev3syqt0kjrls50050uzf25gehpz9vgdw08hvex7e0vgfeq0eseet", )?; client.zap(public_key, 1000, None).await?; // Zap profile let details = ZapDetails::new(ZapType::Public).message("Test"); client.zap(public_key, 1000, Some(details)).await?; // Zap event let event = Nip19Event::from_bech32("nevent1qqsr0q447ylm3y3tvw07vt69w3kzk026vl6yn3dwm9fweay0dw0jttgpz3mhxue69uhhyetvv9ujumn0wd68ytnzvupzq6xcz9jerqgqkldy8lpg7lglcyj4g3nwzy2cs6u70wejdaj7csnjqvzqqqqqqygequ53")?; let details = ZapDetails::new(ZapType::Anonymous).message("Anonymous Zap!"); client.zap(event, 1000, Some(details)).await?; Ok(()) } ``` -------------------------------- ### Basic Actix Web Server Example Source: https://docs.rs/arrayvec/latest/arrayvec/actix-web/^3 This Rust example shows how to create a simple web server using Actix Web. It defines a GET route that extracts path parameters (id and name) and returns a formatted string. The `main` function initializes and runs the `HttpServer`. ```Rust use actix_web::{get, web, App, HttpServer, Responder}; #[get("/{id}/{name}/index.html")] async fn index(web::Path((id, name)): web::Path<(u32, String)>) -> impl Responder { format!("Hello {}! id:{}", name, id) } #[actix_web::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| App::new().service(index)) .bind("127.0.0.1:8080")? .run() .await } ``` -------------------------------- ### Run `variable` example for dynamic height textarea Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Demonstrates a simple textarea whose height dynamically adjusts based on the number of lines of text it contains. ```Shell cargo run --example variable ``` -------------------------------- ### Install poof using cargo binstall Source: https://docs.rs/arrayvec/latest/arrayvec/crate/poof/0.4 Installs the poof binary using cargo-binstall, which efficiently downloads pre-built binaries and skips the compilation step, providing a quick setup. ```shell cargo binstall poof ``` -------------------------------- ### Install a tool using poof Source: https://docs.rs/arrayvec/latest/arrayvec/crate/poof/0.4 Demonstrates the primary usage of the poof command to install a specific tool from GitHub. This example installs 'pirafrank/rust_exif_renamer' directly via its repository path. ```shell poof install pirafrank/rust_exif_renamer ``` -------------------------------- ### Rust Nostr SDK: Getting Started with Client Operations Source: https://docs.rs/arrayvec/latest/arrayvec/nostr-sdk/^0.32 This comprehensive Rust example demonstrates how to initialize the Nostr SDK client, generate or parse keys, connect to relays with various options (including proxy and write flags), update user metadata, publish text notes, and perform zap operations to profiles and events. It covers key functionalities for interacting with the Nostr network. ```Rust use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::str::FromStr; use nostr_sdk::prelude::*; #[tokio::main] async fn main() -> Result<()> { // Generate new random keys let my_keys = Keys::generate(); // Or use your already existing (from hex or bech32) let my_keys = Keys::parse("hex-or-bech32-secret-key")?; // Show bech32 public key let bech32_pubkey: String = my_keys.public_key().to_bech32()?; println!("Bech32 PubKey: {}", bech32_pubkey); // Create new client let client = Client::new(&my_keys); let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050))); // Add relays client.add_relay("wss://relay.damus.io").await?; client.add_relay_with_opts( "wss://relay.nostr.info", RelayOptions::new().proxy(proxy).write(false) ).await?; client.add_relay_with_opts( "ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion", RelayOptions::new().proxy(proxy), ).await?; // Connect to relays client.connect().await; let metadata = Metadata::new() .name("username") .display_name("My Username") .about("Description") .picture(Url::parse("https://example.com/avatar.png")?) .banner(Url::parse("https://example.com/banner.png")?) .nip05("username@example.com") .lud16("yuki@getalby.com") .custom_field("custom_field", "my value"); // Update metadata client.set_metadata(&metadata).await?; // Publish a text note client.publish_text_note("My first text note from rust-nostr!", []).await?; // Create a POW text note let event: Event = EventBuilder::text_note("POW text note from nostr-sdk", []).to_pow_event(&my_keys, 20)?; client.send_event(event).await?; // Send to all relays // client.send_event_to(["wss://relay.damus.io"], event).await?; // Send to specific relay // --------- Zap! ------------- // Configure zapper let uri = NostrWalletConnectURI::from_str("nostr+walletconnect://...")?; let zapper = NWC::new(uri); // Use `WebLNZapper::new().await` for WebLN client.set_zapper(zapper).await; // Send SAT without zap event let public_key = PublicKey::from_bech32( "npub1drvpzev3syqt0kjrls50050uzf25gehpz9vgdw08hvex7e0vgfeq0eseet", )?; client.zap(public_key, 1000, None).await?; // Zap profile let details = ZapDetails::new(ZapType::Public).message("Test"); client.zap(public_key, 1000, Some(details)).await?; // Zap event let event = Nip19Event::from_bech32("nevent1qqsr0q447ylm3y3tvw07vt69w3kzk026vl6yn3dwm9fweay0dw0jttgpz3mhxue69uhhyetvv9ujumn0wd68ytnzvupzq6xcz9jerqgqkldy8lpg7lglcyj4g3nwzy2cs6u70wejdaj7csnjqvzqqqqqqygequ53")?; let details = ZapDetails::new(ZapType::Anonymous).message("Anonymous Zap!"); client.zap(event, 1000, Some(details)).await?; Ok(()) } ``` -------------------------------- ### Serve a Simple Hello World Application with hyper-serve and Axum Source: https://docs.rs/arrayvec/latest/arrayvec/crate/hyper-serve/^0 This example demonstrates how to set up a basic 'Hello, world!' web server using `hyper-serve` with the `axum` web framework. It shows the necessary imports, router configuration, and how to bind and serve the application on a specified socket address. ```Rust use axum::{routing::get, Router}; use std::net::SocketAddr; #[tokio::main] async fn main() { let app = Router::new().route("/", get(|| async { "Hello, world!" })); let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); println!("listening on {}", addr); hyper_serve::bind(addr) .serve(app.into_make_service()) .await .unwrap(); } ``` -------------------------------- ### Initialize TextArea with Default Empty State Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet demonstrates how to create an empty `TextArea` instance using the `Default` trait. This is the simplest way to get a new editor with no initial text. ```Rust let mut textarea = TextArea::default(); ``` -------------------------------- ### Retrieve Text Content as Borrowed Slice Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet explains how to get a temporary reference to the text lines as `&[String]` using `TextArea::lines()`. This method allows you to read the content without taking ownership of the `TextArea` instance, and the example shows how to join them into a single `String`. ```Rust let text: String = textarea.lines().join("\n"); ``` -------------------------------- ### Basic Axum 'Hello, World!' Application Source: https://docs.rs/arrayvec/latest/arrayvec/axum/^0 This snippet demonstrates a minimal Axum web application that responds with 'Hello, World!' on the root path. It sets up a router with a single GET route and starts the server using `tokio::net::TcpListener` and `axum::serve`. ```Rust use axum::{ routing::get, Router, }; #[tokio::main] async fn main() { // build our application with a single route let app = Router::new().route("/", get(|| async { "Hello, World!" })); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } ``` -------------------------------- ### Shell: Steps to Test Clap Example Source: https://docs.rs/arrayvec/latest/arrayvec/clap/2.9 Instructions to clone, compile, and run a pre-built `clap` example from its GitHub repository, demonstrating how to test the CLI application and view its help output. ```Shell $ git clone https://github.com/kbknapp/clap-rs && cd clap-rs/clap-tests $ cargo build --release $ ./target/release/claptests --help ``` -------------------------------- ### Run `password` example for masked input Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Demonstrates a password input form where the text is masked with '●' characters. ```Shell cargo run --example password ``` -------------------------------- ### Basic Actix Web Server Example Source: https://docs.rs/arrayvec/latest/arrayvec/actix-web/^4 This Rust code snippet demonstrates how to set up a minimal Actix Web application. It defines a GET route `/hello/{name}` that responds with a greeting and initializes an `HttpServer` to run the application on `127.0.0.1:8080`. ```Rust use actix_web::{get, web, App, HttpServer, Responder}; #[get("/hello/{name}")] async fn greet(name: web::Path) -> impl Responder { format!("Hello {}!", name) } #[actix_web::main] // or #[tokio::main] async fn main() -> std::io::Result<()> { HttpServer::new(|| { App::new().service(greet) }) .bind(("127.0.0.1", 8080))? .run() .await } ``` -------------------------------- ### Run `single_line` example for single-line input Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Shows a single-line input form with built-in float number validation. ```Shell cargo run --example single_line ``` -------------------------------- ### Create a Basic Axum Web Application Source: https://docs.rs/arrayvec/latest/arrayvec/crate/axum/^0 This Rust code demonstrates how to set up a simple web server using the Axum framework. It includes routes for a root path (/) returning 'Hello, World!' and a user creation endpoint (/users) that accepts JSON input and returns a new user with a 201 Created status. It uses `tokio` for asynchronous operations and `serde` for JSON serialization/deserialization. ```Rust use axum::{ routing::{get, post}, http::StatusCode, Json, Router, }; use serde::{Deserialize, Serialize}; #[tokio::main] async fn main() { // initialize tracing tracing_subscriber::fmt::init(); // build our application with a route let app = Router::new() // `GET /` goes to `root` .route("/", get(root)) // `POST /users` goes to `create_user` .route("/users", post(create_user)); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap(); axum::serve(listener, app).await.unwrap(); } // basic handler that responds with a static string async fn root() -> &'static str { "Hello, World!" } async fn create_user( // this argument tells axum to parse the request body // as JSON into a `CreateUser` type Json(payload): Json, ) -> (StatusCode, Json) { // insert your application logic here let user = User { id: 1337, username: payload.username, }; // this will be converted into a JSON response // with a status code of `201 Created` (StatusCode::CREATED, Json(user)) } // the input to our `create_user` handler #[derive(Deserialize)] struct CreateUser { username: String, } // the output to our `create_user` handler #[derive(Serialize)] struct User { id: u64, username: String, } ``` -------------------------------- ### Basic Usage: Hello, world! with crossbeam-channel Source: https://docs.rs/arrayvec/latest/arrayvec/crossbeam-channel/^0 This snippet demonstrates the fundamental usage of `crossbeam-channel`. It illustrates how to create an unbounded channel, send a simple string message into it, and then receive that message, verifying the successful transmission. This is a basic example to get started with the library's core send/receive functionality. ```Rust use crossbeam_channel::unbounded; // Create a channel of unbounded capacity. let (s, r) = unbounded(); // Send a message into the channel. s.send("Hello, world!").unwrap(); // Receive the message from the channel. assert_eq!(r.recv(), Ok("Hello, world!")); ``` -------------------------------- ### Create a basic 'Hello World' terminal application with Ratatui Source: https://docs.rs/arrayvec/latest/arrayvec/ratatui/^0 This Rust example demonstrates how to initialize a Ratatui terminal, render a simple 'Hello World!' paragraph within a bordered block, and handle user input to exit the application when the 'q' key is pressed. It showcases the basic event loop and rendering process. ```Rust use ratatui::{ crossterm::event::{self, Event, KeyCode, KeyEventKind}, widgets::{Block, Paragraph}, }; fn main() -> std::io::Result<()> { let mut terminal = ratatui::init(); loop { terminal.draw(|frame| { frame.render_widget( Paragraph::new("Hello World!").block(Block::bordered().title("Greeting")), frame.area(), ); })?; if let Event::Key(key) = event::read()? { if key.kind == KeyEventKind::Press && key.code == KeyCode::Char('q') { break; } } } ratatui::restore(); Ok(()) } ``` -------------------------------- ### Minimal Usage of tui-textarea with Ratatui Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet demonstrates the basic setup for integrating `tui-textarea` into a `ratatui` application. It shows how to initialize a `TextArea` instance, render it within a terminal frame, handle keyboard events using `TextArea::input()`, and retrieve the final text content. ```Rust use tui_textarea::TextArea; use crossterm::event::{Event, read}; let mut term = ratatui::Terminal::new(...); // Create an empty `TextArea` instance which manages the editor state let mut textarea = TextArea::default(); // Event loop loop { term.draw(|f| { // Get `ratatui::layout::Rect` where the editor should be rendered let rect = ...; // Render the textarea in terminal screen f.render_widget(&textarea, rect); })?; if let Event::Key(key) = read()? { // Your own key mapping to break the event loop if key.code == KeyCode::Esc { break; } // `TextArea::input` can directly handle key events from backends and update the editor state textarea.input(key); } } // Get text lines as `&[String]` println!("Lines: {:?}", textarea.lines()); ``` -------------------------------- ### Getting Started with rust-nostr: Key Management and Event Creation Source: https://docs.rs/arrayvec/latest/arrayvec/nostr/^0.32 This Rust code snippet demonstrates how to generate and parse Nostr keys, create various types of Nostr events (metadata, text notes, Proof-of-Work notes), and serialize client messages to JSON using the `rust-nostr` library. It covers basic setup and common event building patterns. ```Rust use nostr::prelude::*; fn main() -> Result<()> { // Generate new random keys let my_keys = Keys::generate(); // Or use your already existing (from hex or bech32) let my_keys = Keys::parse("hex-or-bech32-secret-key")?; // Show bech32 public key let bech32_pubkey: String = my_keys.public_key().to_bech32()?; println!("Bech32 PubKey: {}", bech32_pubkey); let metadata = Metadata::new() .name("username") .display_name("My Username") .about("Description") .picture(Url::parse("https://example.com/avatar.png")?) .banner(Url::parse("https://example.com/banner.png")?) .nip05("username@example.com") .lud16("yuki@getalby.com") .custom_field("custom_field", "my value"); let event: Event = EventBuilder::metadata(&metadata).to_event(&my_keys)?; // New text note let event: Event = EventBuilder::text_note("Hello from rust-nostr", []).to_event(&my_keys)?; // New POW text note let event: Event = EventBuilder::text_note("My first POW text note from rust-nostr", []).to_pow_event(&my_keys, 20)?; // Convert client nessage to JSON let json = ClientMessage::event(event).as_json(); println!("{json}"); Ok(()) } ``` -------------------------------- ### APIDOC: tui_textarea::Scrolling Enum Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Specifies how to scroll the textarea in `tui_textarea`. ```APIDOC enum Scrolling description: Specify how to scroll the textarea. ``` -------------------------------- ### Install a tool using poof Source: https://docs.rs/arrayvec/latest/arrayvec/crate/poof/0.3 Demonstrates how to use `poof` to install a specific tool (e.g., `rust_exif_renamer`) from a GitHub repository. ```bash poof install pirafrank/rust_exif_renamer ``` -------------------------------- ### Install a Binary using poof Source: https://docs.rs/arrayvec/latest/arrayvec/crate/poof/0.2 This command demonstrates how to use 'poof' to install a pre-built binary from a GitHub repository. 'poof' will download the specified binary and place it in its managed bin directory, making it available in the system's PATH. ```Shell poof install pirafrank/rust_exif_renamer ``` -------------------------------- ### APIDOC: tui_textarea::Key Enum Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Backend-agnostic key input kind for `tui_textarea`. ```APIDOC enum Key description: Backend-agnostic key input kind. ``` -------------------------------- ### Ratatui Application Core Steps Source: https://docs.rs/arrayvec/latest/arrayvec/ratatui/^0 Outlines the fundamental steps required to build any application using the Ratatui library, including terminal initialization, a main loop for event handling and UI drawing, and terminal state restoration. ```APIDOC Every application built with `ratatui` needs to implement the following steps: - Initialize the terminal - A main loop to: - Handle input events - Draw the UI - Restore the terminal state ``` -------------------------------- ### APIDOC: tui_textarea::CursorMove Enum Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Specifies how to move the cursor within `tui_textarea`. ```APIDOC enum CursorMove description: Specify how to move the cursor. ``` -------------------------------- ### Minimal Clap App in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/clap/%7E2 This minimal Rust example demonstrates how to create a basic `clap` application with a name and version. It initializes an `App` and processes command-line arguments. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### APIDOC: tui_textarea::Input Struct Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Backend-agnostic key input type for `tui_textarea`. ```APIDOC struct Input description: Backend-agnostic key input type. ``` -------------------------------- ### Run Basic CSV Reading Example Source: https://docs.rs/arrayvec/latest/arrayvec/crate/csv/latest/target-redirect/x86_64-pc-windows-msvc/csv/index Instructions to clone the `rust-csv` repository and execute the basic CSV reading example from the command line, piping data from a sample CSV file. ```Shell $ git clone git://github.com/BurntSushi/rust-csv $ cd rust-csv $ cargo run --example cookbook-read-basic < examples/data/smallpop.csv ``` -------------------------------- ### Example TOML Configuration File Structure Source: https://docs.rs/arrayvec/latest/arrayvec/crate/toml/latest/target-redirect/x86_64-apple-darwin/toml/index A basic example of a TOML configuration file structure, showing a package section with name and dependencies. This demonstrates the simple and readable nature of the TOML format. ```TOML [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### APIDOC: tui_textarea::TextArea Struct Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 A type to manage the state of a textarea in `tui_textarea`, including important methods. ```APIDOC struct TextArea description: A type to manage state of textarea. notes: These are some important methods. ``` -------------------------------- ### Shell: Example CLI Help Output Source: https://docs.rs/arrayvec/latest/arrayvec/clap/2.9 Demonstrates the `--help` output for a `clap`-defined command-line interface, showing usage, flags, options, arguments, and subcommands as generated by the `clap` library. ```Shell $ myprog --help My Super Program 1.0 Kevin K. Does awesome things USAGE: MyApp [FLAGS] [OPTIONS] [SUBCOMMAND] FLAGS: -h, --help Prints this message -v Sets the level of verbosity -V, --version Prints version information OPTIONS: -c, --config Sets a custom config file ARGS: INPUT The input file to use SUBCOMMANDS: help Prints this message test Controls testing features ``` -------------------------------- ### Cargo.toml Dependency for Serde Support Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Adds `tui-textarea` as a dependency in `Cargo.toml`, enabling the `serde` feature for serialization/deserialization support. ```TOML [dependencies] tui-textarea = { version = "*", features = ["serde"] } ``` -------------------------------- ### Rust Example: Getting a Raw Pointer with `str::as_ptr` Source: https://docs.rs/arrayvec/latest/arrayvec/crate/arrayvec/latest/target-redirect/x86_64-unknown-linux-gnu/arrayvec/struct.ArrayString Demonstrates how to obtain an immutable raw pointer to the start of a string slice. ```Rust let s = "Hello"; let ptr = s.as_ptr(); ``` -------------------------------- ### Run Serde CSV Reading Example Source: https://docs.rs/arrayvec/latest/arrayvec/crate/csv/latest/target-redirect/x86_64-pc-windows-msvc/csv/index Instructions to clone the `rust-csv` repository and execute the Serde-enabled CSV reading example from the command line, piping data from a sample CSV file. ```Shell $ git clone git://github.com/BurntSushi/rust-csv $ cd rust-csv $ cargo run --example cookbook-read-serde < examples/data/smallpop.csv ``` -------------------------------- ### Basic Clap Application for Help/Version Source: https://docs.rs/arrayvec/latest/arrayvec/clap/2.9 This Rust code demonstrates a minimal `clap` application that initializes an `App` with a name and version. Running this program with `--help` or `--version` will display `clap`'s default auto-generated output. ```Rust extern crate clap; use clap::App; fn main() { App::new("fake").version("v1.0-beta").get_matches(); } ``` -------------------------------- ### Cargo.toml Dependency for tui-textarea Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Adds `tui-textarea` as a dependency in `Cargo.toml`, disabling default features and enabling `tuirs-no-backend` for `tui-rs` compatibility. ```TOML tui-textarea = { version = "*", default-features = false, features = ["tuirs-no-backend"] } ``` -------------------------------- ### Configure Cursor Line Style for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 By default, `TextArea` underlines the cursor line. This snippet shows how to change the style of the cursor line using `TextArea::set_cursor_line_style()`. The example styles the cursor line with bold text. ```Rust use ratatui::style::{Style, Modifier}; let style = Style::default().add_modifier(Modifier::BOLD); textarea.set_cursor_line_style(style); ``` -------------------------------- ### Core Actix Web API Entry Points Overview Source: https://docs.rs/arrayvec/latest/arrayvec/actix-web/^3 An overview of the primary structs and modules to begin navigating the Actix web API documentation, including application configuration, server instantiation, and request/response handling. ```APIDOC Struct App: Represents an Actix web application, used to configure routes and common application settings. Struct HttpServer: Represents an HTTP server instance, used to instantiate and configure servers. Module web: Provides essential types for route registration and common utilities for request handlers. Struct HttpRequest: Represents an HTTP request, exposing methods for creation, inspection, and utilization. Struct HttpResponse: Represents an HTTP response, exposing methods for creation, inspection, and utilization. ``` -------------------------------- ### Initialize TextArea from an Iterator of Strings Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet illustrates using `TextArea::from()` to create an instance from any iterator whose elements can be converted to `String`. Examples include creating from a slice of string literals (`[&str]`) or from the lines of an existing `String`. ```Rust // Create `TextArea` from from `[&str]` let mut textarea = TextArea::from([ "this is first line", "this is second line", "this is third line", ]); // Create `TextArea` from `String` let mut text: String = ...; let mut textarea = TextArea::from(text.lines()); ``` -------------------------------- ### Documentation Navigation Keyboard Shortcuts Source: https://docs.rs/arrayvec/latest/arrayvec/clap/2.9 Lists keyboard shortcuts for navigating and interacting with the documentation, including showing help, focusing search, moving through results, and expanding/collapsing sections. ```APIDOC ?: Show this help dialog S: Focus the search field ⇤: Move up in search results ⇥: Move down in search results ⏎: Go to active search result +: Collapse/expand all sections ``` -------------------------------- ### Disable Undo/Redo History for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet shows how to disable the undo/redo history in `TextArea` by setting the maximum history size to 0. ```Rust textarea.set_max_histories(0); ``` -------------------------------- ### Nostr SDK Rust Modules Source: https://docs.rs/arrayvec/latest/arrayvec/nostr-sdk/^0.37 Lists top-level modules available in the `nostr_sdk` crate, specifically the `client` module, which encapsulates client-related functionalities. ```APIDOC Module: client Full Path: mod nostr_sdk::client Description: Client ``` -------------------------------- ### Run and Test Clap CLI Application Source: https://docs.rs/arrayvec/latest/arrayvec/clap/* Demonstrates how to run the compiled `clap` application from the command line, showing the `--help` output and a basic execution with a name argument. Placeholders are used for version numbers and executable extensions. ```Shell $ demo --help A simple to use, efficient, and full-featured Command Line Argument Parser Usage: demo[EXE] [OPTIONS] --name Options: -n, --name Name of the person to greet -c, --count Number of times to greet [default: 1] -h, --help Print help -V, --version Print version $ demo --name Me Hello Me! ``` -------------------------------- ### Disable Cursor Line Style for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 This snippet demonstrates how to disable the cursor line style in `TextArea` by setting the default style. ```Rust use ratatui::style::{Style, Modifier}; textarea.set_cursor_line_style(Style::default()); ``` -------------------------------- ### Configure Max History Size for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 By default, `TextArea` stores 50 past modifications for undo/redo. This snippet demonstrates how to change the number of remembered edits using `TextArea::set_max_histories()`. The example sets the history size to 1000. ```Rust textarea.set_max_histories(1000); ``` -------------------------------- ### Nostr SDK Rust Client Example Source: https://docs.rs/arrayvec/latest/arrayvec/nostr-sdk/^0.19 This comprehensive Rust example demonstrates how to initialize a Nostr client, manage keys, connect to relays, update user metadata, publish various types of notes, and send custom events. It also includes handling incoming notifications from the Nostr network. ```Rust use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use nostr_sdk::prelude::*; #[tokio::main] async fn main() -> Result<()> { // Generate new keys let my_keys: Keys = Keys::generate(); // // or use your already existing // // From HEX or Bech32 // let my_keys = Keys::from_sk_str("hex-or-bech32-secret-key")?; // Show bech32 public key let bech32_pubkey: String = my_keys.public_key().to_bech32()?; println!("Bech32 PubKey: {}", bech32_pubkey); // Create new client let client = Client::new(&my_keys); let proxy = Some(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 9050))); // Add relays client.add_relay("wss://relay.damus.io", None).await?; client.add_relay("wss://relay.nostr.info", proxy).await?; client.add_relay( "ws://jgqaglhautb4k6e6i2g34jakxiemqp6z4wynlirltuukgkft2xuglmqd.onion", proxy, ).await?; // Connect to relays client.connect().await; let metadata = Metadata::new() .name("username") .display_name("My Username") .about("Description") .picture(Url::parse("https://example.com/avatar.png")?) .banner(Url::parse("https://example.com/banner.png")?) .nip05("username@example.com") .lud16("yuki@getalby.com"); // Update metadata client.set_metadata(metadata).await?; // Publish a text note client.publish_text_note("My first text note from Nostr SDK!", &[]).await?; // Publish a POW text note client.publish_pow_text_note("My first POW text note from Nostr SDK!", &[], 20).await?; // Send custom event let event_id = EventId::from_bech32("note1z3lwphdc7gdf6n0y4vaaa0x7ck778kg638lk0nqv2yd343qda78sf69t6r")?; let public_key = XOnlyPublicKey::from_bech32("npub14rnkcwkw0q5lnmjye7ffxvy7yxscyjl3u4mrr5qxsks76zctmz3qvuftjz")?; let event: Event = EventBuilder::new_reaction(event_id, public_key, "🧡").to_event(&my_keys)?; // Send custom event to all relays // client.send_event(event).await?; // Send custom event to a specific previously added relay client.send_event_to("wss://relay.damus.io", event).await?; // Handle notifications let mut notifications = client.notifications(); while let Ok(notification) = notifications.recv().await { println!("{notification:?}"); } Ok(()) } ``` -------------------------------- ### Deserializing tui-textarea Input from JSON Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Demonstrates how to deserialize a `tui_textarea::Input` instance from a JSON string using `serde_json`, showcasing the structure of the serialized input. ```Rust use tui_textarea::Input; let json = r#" { "key": { "Char": "a" }, "ctrl": true, "alt": false, "shift": true } "#; let input: Input = serde_json::from_str(json).unwrap(); println!("{input:?}"); // Input { // key: Key::Char('a'), // ctrl: true, // alt: false, // shift: true, // } ``` -------------------------------- ### Enable Line Numbers for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 By default, `TextArea` does not show line numbers. This snippet demonstrates how to enable them by setting a style for rendering line numbers using `TextArea::set_line_number_style()`. The example renders line numbers with a dark gray background. ```Rust use ratatui::style::{Style, Color}; let style = Style::default().bg(Color::DarkGray); textarea.set_line_number_style(style); ``` -------------------------------- ### Run and Test Clap CLI Application Source: https://docs.rs/arrayvec/latest/arrayvec/clap::Command Examples of running the compiled CLI application to demonstrate its functionality. This includes invoking the `--help` flag to display usage information and passing arguments like `--name` to see the program's output. ```Shell $ demo --help A simple to use, efficient, and full-featured Command Line Argument Parser Usage: demo[EXE] [OPTIONS] --name Options: -n, --name Name of the person to greet -c, --count Number of times to greet [default: 1] -h, --help Print help -V, --version Print version $ demo --name Me Hello Me! ``` -------------------------------- ### Configure Tab Width for TextArea in Rust Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 The default tab width in `TextArea` is 4. This snippet shows how to change it using `TextArea::set_tab_length()` method. The example sets the tab width to 2, meaning typing the tab key inserts 2 spaces. ```Rust textarea.set_tab_length(2); ``` -------------------------------- ### Basic TOML Configuration Example Source: https://docs.rs/arrayvec/latest/arrayvec/crate/toml/latest/target-redirect/i686-unknown-linux-gnu/toml/index Illustrates a typical TOML configuration file structure, specifically for a Rust `Cargo.toml`. It shows how to define package metadata and dependencies. ```TOML [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### Add `tui-textarea` with `search` feature Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Configuration for `Cargo.toml` to enable text search with regular expressions by adding the `search` feature to `tui-textarea`. This adds the `regex` crate as a dependency. ```TOML [dependencies] ratatui = "*" tui-textarea = { version = "*", features = ["search"] } ``` -------------------------------- ### Example TOML Configuration File Source: https://docs.rs/arrayvec/latest/arrayvec/crate/toml/latest/target-redirect/x86_64-unknown-linux-gnu/toml/index A basic example of a TOML configuration file, showing a package section with a name and dependencies, commonly used in Rust projects like Cargo. ```TOML [package] name = "toml" [dependencies] serde = "1.0" ``` -------------------------------- ### Add `tui-textarea` with `termion` backend Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 Configuration for `Cargo.toml` to use `termion` backend with `ratatui` and `tui-textarea`. Requires disabling default features and explicitly enabling the `termion` feature for both crates. ```TOML [dependencies] # For termion ratatui = { version = "*", default-features = false, features = ["termion"] } tui-textarea = { version = "*", default-features = false, features = ["termion"] } ``` -------------------------------- ### Run and Test Clap CLI Application Source: https://docs.rs/arrayvec/latest/arrayvec/clap Examples of running the compiled `demo` CLI application. It shows the `--help` output, detailing available options, and a basic execution with the `--name` argument. ```Shell $ demo --help A simple to use, efficient, and full-featured Command Line Argument Parser Usage: demo[EXE] [OPTIONS] --name Options: -n, --name Name of the person to greet -c, --count Number of times to greet [default: 1] -h, --help Print help -V, --version Print version $ demo --name Me Hello Me! ``` -------------------------------- ### Build nostr-sdk for WASM on macOS Source: https://docs.rs/arrayvec/latest/arrayvec/nostr-sdk/^0.37 Provides the necessary shell commands to install `llvm` and compile the `nostr-sdk` crate for the `wasm32-unknown-unknown` target on macOS, setting the appropriate environment variables for the `llvm` tools. ```Shell brew install llvm LLVM_PATH=$(brew --prefix llvm) AR="${LLVM_PATH}/bin/llvm-ar" CC="${LLVM_PATH}/bin/clang" cargo build --target wasm32-unknown-unknown ``` -------------------------------- ### Enable Search Feature for tui-textarea in Cargo.toml Source: https://docs.rs/arrayvec/latest/arrayvec/tui-textarea/^0 To use the text search functionality in `tui-textarea`, the `search` feature must be explicitly enabled in your `Cargo.toml` file. This avoids depending on the `regex` crate unnecessarily. ```TOML tui-textarea = { version = "*", features = ["search"] } ```