Module input

Module input 

Source
Expand description

Input handling abstraction for different sources. Input handling system for the Bubble Tea TUI framework.

This module provides the core input processing functionality for bubbletea-rs. It is responsible for reading terminal events (keyboard, mouse, resize, focus, paste) and converting them into messages that can be processed by the application’s model following the Model-View-Update (MVU) pattern.

§Key Components

  • InputHandler - The main event processor that runs the input loop
  • InputSource - Enum defining different input sources (terminal or custom)

§Examples

Basic usage with terminal input:

use bubbletea_rs::input::{InputHandler, InputSource};
use tokio::sync::mpsc;

let (tx, rx) = mpsc::unbounded_channel();
let input_handler = InputHandler::new(tx);

// Start the input processing loop
tokio::spawn(async move {
    input_handler.run().await
});

Using a custom input source:

use bubbletea_rs::input::{InputHandler, InputSource};
use tokio::sync::mpsc;
use std::pin::Pin;

let (tx, rx) = mpsc::unbounded_channel();
let custom_reader = Box::pin(std::io::Cursor::new("hello\n"));
let input_source = InputSource::Custom(custom_reader);
let input_handler = InputHandler::with_source(tx, input_source);

// Process input from the custom source
input_handler.run().await?;

Structs§

InputHandler
InputHandler is responsible for processing terminal events and sending them as messages to the Program’s event loop.

Enums§

InputSource
Represents different input sources that the InputHandler can read from.