Skip to main content

Crate promkit

Crate promkit 

Source
Expand description

§promkit

ci docs.rs

A toolkit for building your own interactive prompt in Rust.

§Getting Started

Put the package in your Cargo.toml.

[dependencies]
promkit = { version = "0.14.0", features = ["runtime", "texteditor"] }

§Features

  • Application-owned composition — Implement the Prompt lifecycle and combine only the widget states an application needs. Key bindings, focus, validation, background work, and other event policy remain in the application instead of framework-owned presets.
  • Optional runtime and terminal lifecycle — Use the asynchronous prompt runtime when useful, and independently manage raw mode, the alternate screen, cursor visibility, and mouse capture with TerminalSession.
  • Viewport-aware renderingpromkit-core handles wrapping or truncation, vertical pane allocation, cursor scrolling, clipping, resizing, and screen-to-widget hit testing.
  • Reusable widget statespromkit-widgets provides text editing and display, list and checkbox selection, prefix search, spinners and status output, trees, JSON and YAML documents, and CSV tables.
  • Efficient large-content projection — JSON, YAML, and table widgets can project only the visible terminal viewport instead of rebuilding all content on every redraw.
  • Feature-gated modules — No Cargo features are enabled by default. Choose the runtime, terminal session, capabilities, and individual widgets needed by the application.
  • Cross-platform terminal support — UNIX and Windows are supported through crossterm.

§Concept

See here.

§Projects using promkit

§Examples/Demos

promkit provides a runtime and reusable widgets for building interactive terminal applications. The examples own their event policies and demonstrate how applications can compose the widgets they need.

§Table of contents

ExampleDescription
ReadlineSingle-line editing with history and completion
ConfirmValidated yes-or-no input
PasswordMasked input with validation
FormMultiple editable fields in one prompt
ListboxKeyboard-driven single selection
QuerySelectorPrefix search over selectable candidates
CheckboxKeyboard-driven multiple selection
TreeNavigation and folding for hierarchical data
JSONLine-numbered navigation and folding for JSON
YAMLLine-numbered navigation and folding for YAML
CSVVertical and horizontal navigation for tabular data
TextScrollable styled text
Async Task with SpinnerBackground work with live input and progress feedback
Multiline REPLMultiline editing in an interactive loop

Each section includes a command, source link, and recorded demo.

§Readline

Command
cargo run --bin readline

Composition / Usage

§Confirm

Command
cargo run --bin confirm

Code

§Password

Command
cargo run --bin password

Code

§Form

Command
cargo run --bin form

Code

§Listbox

Command
cargo run --bin listbox

Code

§QuerySelector

Command
cargo run --bin query-selector

Code

§Checkbox

Command
cargo run --bin checkbox

Code

§Tree

Command
cargo run --bin tree

Code

§JSON

Command
cargo run --bin json ${PATH_TO_JSON_FILE}

Code

§YAML

Command
cargo run --bin yaml ${PATH_TO_YAML_FILE}

Code

§CSV

Command
cargo run --bin csv ${PATH_TO_CSV_FILE}

Code

§Text

Command
cargo run --bin text

Code

§Advanced Examples

These examples demonstrate how to compose widgets and rendering primitives for application-specific event loops and asynchronous workflows.

§Async Task with Spinner

Command
cargo run --bin async_task

Code

§Multiline REPL

Command
cargo run --bin repl

Code

§License

MIT License

Re-exports§

pub use anyhow;runtime
pub use async_trait;runtime
pub use promkit_core as core;core
pub use promkit_widgets as widgets;widgets

Modules§

validatevalidate

Structs§

TerminalModesterminal-session
Terminal modes managed by a TerminalSession.
TerminalSessionterminal-session
Owns configured terminal modes for the duration of an interactive session.

Enums§

Signalruntime
Indicates whether Prompt::run should continue reading terminal events.

Statics§

EVENT_STREAMruntime
The singleton terminal event stream used by Prompt::run.

Traits§

Promptruntime
Defines the lifecycle of a sequential, interactive prompt.