prettui

Crates.ioprettui
lib.rsprettui
version0.3.3
created_at2025-07-24 12:32:30.290138+00
updated_at2025-08-07 17:34:05.195705+00
descriptionSimple high-level lib for pretty command-line ui
homepage
repositoryhttps://github.com/keepinfov/prettui
max_upload_size
id1765984
size57,417
Keepinfov (keepinfov)

documentation

https://docs.rs/prettui/

README

prettui

A terminal-based library to build beautiful and interactive command-line user interfaces in Rust.

Features

  • Configurable Lists: Customize items per row, rows per page, and cell width.
  • Arrow & Page Navigation: Navigate lists using arrow keys, PageUp/PageDown.
  • Numeric Input: Real-time, multi-digit numeric list input with live feedback.
  • Custom Colors: Easily style prefixes, prompts, and output text with configurable colors.
  • Input and Output Utilities: Flexible input prompts and styled, wrapped console output.

Installation

Add prettui to your Cargo.toml:

[dependencies]
prettui = "0.3.3"

Or using command:

cargo add prettui

Then import the prelude in your code:

use prettui::prelude::*;

Example

use prettui::prelude::*;

fn main() -> anyhow::Result<()> {
    // Prepare a list of 100 items
    let items: Vec<String> = (1..=100).map(|i| format!("Item {}", i)).collect();

    // Configure the list display
    let config = ListConfig::default()
        .items_per_row(1)
        .rows_per_page(10)
        .cell_width(30)
        .normal_fg(Color::DarkGrey)
        .highlight_fg(Color::Green);

    println!("Example of using prettui list chooser");
    println!(
        "Use arrows/PageUp/PageDown to navigate, type digits, Backspace to delete, Enter to confirm, Esc to cancel."
    );

    // Let the user choose an index or cancel
    if let Some(idx) = choose_from_list(&items, &config)? {
        println!("You chose: {}", items[idx]);
    } else {
        println!("Selection cancelled.");
    }

    // Prompt for user input
    let ic = InputConfig {
        input_text_color: Color::Blue,
        ..Default::default()
    };
    let name = read_input(&ic)?;

    // Print styled output without log level
    let oc = OutputConfig {
        log_level: None,
        ..Default::default()
    };
    write_output(&oc, &format!("Hello, {}!", name))?;

    // Print styled output with a log level tag
    let oc2 = OutputConfig {
        log_level: Some("DEBUG".into()),
        ..Default::default()
    };
    write_output(&oc2, "This is a debug message.")?;

    Ok(())
}

Modules

  • color: Defines the Color enum and conversions to terminal color types.
  • io::input: Utilities for reading user input, including configurable prompts and text wrapping.
  • io::output: Functions for printing styled and wrapped text, with optional log level tags.
  • list: Interactive list chooser with navigation and numeric input support.

Prelude

For convenience, prettui::prelude re-exports the most commonly used types and functions:

pub use crate::color::*;
pub use crate::io::*;
pub use crate::list::*;

License

This project is licensed under the MIT License. See the LICENSE file for details.

Commit count: 0

cargo fmt