Expand description
§promkit
A toolkit for building your own interactive prompt in Rust.
§Getting Started
Put the package in your Cargo.toml.
[dependencies]
promkit = "0.4.4"
§Features
- Support cross-platform both UNIX and Windows owing to crossterm
- Various building methods
- Preset; Support for quickly setting up a UI by providing simple parameters.
- Combining various UI components.
- They are provided with the same interface, allowing users to choose and assemble them according to their preferences.
- (Upcoming) Stronger support to display yor own data structures.
- Versatile customization capabilities
- Theme for designing the appearance of the prompt.
- e.g. cursor, text
- Validation for user input and error message construction.
- Theme for designing the appearance of the prompt.
- Mouse support (partially)
- Allows scrolling through lists with the mouse wheel
§Examples/Demos
See here
§Why promkit?
Related libraries in this category include the following:
promkit offers several advantages over these libraries:
§Unified interface approach for UI components
promkit takes a unified approach by having all of its components inherit the
same Renderer trait. This design choice enables users to seamlessly support
their custom data structures for display, similar to the relationships seen in
TUI projects like ratatui-org/ratatui
and
EdJoPaTo/tui-rs-tree-widget.
In other words, it’s straightforward for anyone to display their own data
structures using widgets within promkit.
In contrast, other libraries tend to treat each prompt as a mostly independent
entity. If you want to display a new data structure, you often have to build the
UI from scratch, which can be a time-consuming and less flexible process.
pub trait Renderer: AsAny + Finalizer {
/// Creates a collection of panes based on the specified width.
///
/// This method is responsible for generating the layout of the UI components
/// that will be displayed in the prompt. The width parameter allows the layout
/// to adapt to the current terminal width.
///
/// # Parameters
///
/// * `width`: The width of the terminal in characters.
///
/// # Returns
///
/// Returns a vector of `Pane` objects that represent the layout of the UI components.
fn create_panes(&self, width: u16) -> Vec<Pane>;
/// Evaluates an event and determines the next action for the prompt.
///
/// This method is called whenever an event occurs (e.g., user input). It allows
/// the renderer to react to the event and decide whether the prompt should continue
/// running or quit.
///
/// # Parameters
///
/// * `event`: A reference to the event that occurred.
///
/// # Returns
///
/// Returns a `Result` containing a `PromptSignal`. `PromptSignal::Continue` indicates
/// that the prompt should continue running, while `PromptSignal::Quit` indicates that
/// the prompt should terminate its execution.
fn evaluate(&mut self, event: &Event) -> anyhow::Result<PromptSignal>;
}§Variety of Pre-built UI Preset Components
One of the compelling reasons to choose promkit is its extensive range of pre-built UI preset components. These presets allow developers to quickly implement various interactive prompts without the need to design and build each component from scratch. The availability of these presets not only speeds up the development process but also ensures consistency and reliability across different applications. Here are some of the preset components available, see Examples
§Resilience to terminal resizing
Performing operations that involve executing a command in one pane while
simultaneously opening a new pane is a common occurrence. During such operations,
if UI corruption is caused by resizing the terminal size, it may adversely affect
the user experience.
Other libraries can struggle when the terminal is resized, making typing and
interaction difficult or impossible. For example:
promkit introduces a step to align data with the screen size before rendering. This approach ensures consistency in UI elements even when the terminal size changes, providing a smoother user experience.
Re-exports§
pub use crossterm;pub use serde_json;
Modules§
Structs§
- A generic cursor structure for navigating and manipulating collections. It maintains a position within the collection and provides methods to move forward, backward, to the head, and to the tail of the collection. It requires the collection to implement the
Lentrait. Thecyclicparameter allows the cursor to cycle through the collection. - Represents a customizable prompt that can handle user input and produce a result.
Enums§
- Represents the signal to control the flow of a prompt.
Traits§
- A trait for rendering components within a prompt.