rustubble

repository·master·Indexed 43 days ago

https://github.com/warpy-ai/rustubble

A library of reusable UI components for terminal-based applications written in Rust. Version 0.1.4 provides components such as Spinner, ProgressBar, ViewPort, StopWatch, Timer, List, MenuList, TextInput, TextArea, and Table, utilizing ratatui and Crossterm for rendering and input handling.

Tokens
7.9K
Snippets
40
Records
48
Agent score
54%

What's inside rustubble

  1. Use the TextInput Component

    master
    The TextInput component is a customizable single-line input field for terminal applications. It supports Unicode, real-time input processing (including pasting and deletion), and cursor management. You can customize it using options such as padding, placeholder text, initial text, and helper text.
  2. Use and customize the Spinner Component

    master

    The Spinner component provides loading animations for CLI applications. It uses the Crossterm library to handle terminal output and allows you to control animation speed and attach real-time feedback messages.

    To create a spinner, use Spinner::new(style_name, message).

    Available styles include Dots, Dots2, Dots3, and others. Each style is defined by a unique key containing a sequence of animation frames and an interval timing in milliseconds.

    let spinner = Spinner::new("Dots2", "Loading resources...");
  3. Use and customize the Table Component

    master

    The Table component allows you to display data in a structured table format in the terminal.

    To initialize a table, use Table::new(headers, data, scroll_offset, visible_lines, padding).

    You can also control where the table is rendered on the view by specifying coordinates (x, y) when handling the table rendering.

    // Initialize a table with headers, data, scroll offset, visible lines, and padding
    let mut table = Table::new(headers, data, 0, 3, 7);
    
    // Render the table at a specific position (x, y)
    let (x, y) = (5, 5);
    handle_table(&mut table, x, y);
  4. Use the TextArea Component

    master
    The TextArea component is designed for multi-line text input, similar to an HTML <textarea />. It supports Unicode, pasting, and vertical scrolling when the content exceeds the element's width or height. It also offers various customization options for the input area.
  5. Customize the Spinner animation

    master

    You can customize the loading animation by providing a SpinnerData object. This allows you to define your own sequence of frames (strings) and the interval (milliseconds) between frame updates.

    While the library provides many built-in animations via string names, creating a custom SpinnerData gives you full control over the visual representation and timing of the loading state.

    // Conceptual usage of custom SpinnerData
    let custom_spinner = SpinnerData {
        frames: vec!["|", "/", "-", "\"],
        interval: 100,
    };
  6. Configure Spinner styles

    master

    Spinner styles are predefined and identified by unique string keys (e.g., Dots, Dots2, Dots3). Each style consists of an array of animation frames and an interval defined in milliseconds.

    // Example of internal style definition structure
    "Dots".into() => SpinnerData {
        frames: vec!["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
        interval: 80
    }
  7. Get styled text content with `return_color_text`

    master

    If you need to obtain a crossterm::style::StyledContent<String> instead of printing directly to stdout, use return_color_text. This is useful for integrating with other components that manage their own rendering lifecycle.

    use rustubble::colors::return_color_text;
    
    let styled = return_color_text("Styled Text", Color::Cyan);