Use the ViewPort component
masterViewPort component allows you to create a viewport in your terminal to display data in a String view format.repository·master·Indexed 43 days ago
https://github.com/warpy-ai/rustubbleA 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.
ViewPort component allows you to create a viewport in your terminal to display data in a String view format.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.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...");Timer component is a simple component used for counting up.List and MenuList components are built using ratatui for terminal UI rendering.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);StopWatch component is a simple component used for counting down.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.ProgressBar component provides a dynamic visual loading animation for CLI applications to indicate progress during long-running operations.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,
};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
}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);