Skip to content

warpy-ai/rustubble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rustubble

Beautifull components for your terminal.

Rust

Motive

This project aims to provide a set of components that can be used in your terminal applications.

Components

TextInput Component

textInput

The TextInput component is a versatile and customizable input field designed for terminal-based applications using Rust. It supports Unicode, dynamic input handling, and comes with a variety of customization options to enhance user interaction.

Features

  • Unicode Support: Handles Unicode input seamlessly.
  • Dynamic Input Handling: Supports real-time input processing including pasting and deletion.
  • Customization: Allows setting up padding, placeholder, initial text, and helper text.
  • Cursor Management: Manages cursor positioning and ensures it is always placed correctly based on user interaction.

Usage

TextArea Component

textArea

A text area field, akin to an <textarea /> in HTML. Allows for input that spans multiple lines. Supports unicode, pasting, vertical scrolling when the value exceeds the width and height of the element, and many customization options.

Usage

Spinner Component

spinner

The Spinner Component provides an easy-to-use and customizable loading animation for CLI applications written in Rust, utilizing the Crossterm library to handle terminal output. This component allows for a dynamic visual display during long-running operations.

Features

  • Multiple Spinner Styles: Choose from a variety of predefined spinner styles including dots, lines, and more complex patterns.
  • Customizable Speed: Control the speed of the spinner animation.
  • Customizable Messages: Attach messages alongside the spinner to provide real-time feedback to users.
  • Easy Integration: Simple API for starting, updating, and stopping the spinner.

Usage

Customizing the Spinner

You can customize the spinner style and message at initialization. Here's how you can specify a different spinner style:

let spinner = Spinner::new("Dots2", "Loading resources...");

Available styles include Dots, Dots2, Dots3, etc. Refer to the spinner_data.rs file for a complete list of available styles and their configurations.

Spinner Styles

The spinner styles are predefined in a lazy_static block within the spinner_data.rs file. Each style is represented by a unique key and includes an array of frames and an interval timing in milliseconds.

Here’s an excerpt from the spinner styles definition:

lazy_static! {
    static ref SPINNERS: HashMap<String, SpinnerData> = {
        hashmap! {
            "Dots".into() => SpinnerData {
                frames: vec!["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
                interval: 80
            },
            // Additional spinner styles...
        }
    };
}

Table Component

The Table component allows you to create a table in your terminal application using Rust. The component provides a flexible and customizable way to display data in a table format.

table

Usage

Customizing the Table

You can set the padding, the number of visible lines and the scroll offset of the table. Here's an example of how you can customize the table:

let mut table = Table::new(headers, data, 0, 3, 7);

You can set the position of the table on the view when rendering:

 let (x, y) = (5, 5);
  handle_table(&mut table, x, y);

Progress bar Component

The ProgressBar component is a versatile and customizable loading animation for CLI applications written in Rust. This component allows for a dynamic visual display during long-running operations.

progress

Usage

ViewPort Component

The ViewPort component allows you to create a viewport in your terminal application. The component provides a flexible and customizable way to display data in a String view format

viewport

Usage

StopWatch Component

A simple component for counting down.

stopwatch

Usage

Timer Component

A simple component for counting up.

timer

Usage

List Component

list

A list component, build with ratatui.

Usage

MenuList Component

menulist

A menu list component, build with ratatui.

Usage

Contribution

Contributions are welcome! If you have suggestions for improving the spinner or adding new styles, please open an issue or pull request on our GitHub repository.

License

This project is licensed under the Apache License - see the LICENSE file for details.