Skip to main content

Module termui

Module termui 

Source
Expand description

Terminal UI utilities for click-rs.

This module provides terminal input/output functions for building interactive command-line applications. It includes styled output, user prompts, progress bars, and terminal utilities.

§Features

  • Output Functions: echo, secho, and style for formatted terminal output
  • Input Functions: prompt, confirm, getchar, and pause for user input
  • Progress Bars: Visual progress indication with ETA and percentage
  • Terminal Utilities: Screen clearing, size detection, TTY checks

§Example

use click::termui::{echo, secho, style, prompt, confirm, Color};

// Simple output
echo("Hello, world!", true, false, None);

// Styled output
secho("Success!", Some(Color::Green), None, true, false, false, false, false, false, false, true, true, false, None);

// Create a styled string
let styled = style("Error", Some(Color::Red), None, true, false, false, false, false, false, false, false);

// Prompt for input
let name = prompt("Enter your name", Some("World".to_string()), false, false, |s| Ok(s.to_string())).unwrap();

// Confirmation
if confirm("Continue?", Some(true), false).unwrap() {
    // proceed
}

Structs§

ProgressBar
A progress bar for displaying operation progress.
ProgressBarIter
An iterator wrapper that displays a progress bar.

Enums§

Color
Terminal colors for styled output.

Constants§

BLACK
BLUE
BRIGHT_BLACK
BRIGHT_BLUE
BRIGHT_CYAN
BRIGHT_GREEN
BRIGHT_MAGENTA
BRIGHT_RED
BRIGHT_WHITE
BRIGHT_YELLOW
CYAN
GREEN
MAGENTA
RED
RESET
WHITE
YELLOW

Functions§

clear
Clear the terminal screen.
confirm
Prompt for yes/no confirmation.
echo
Print a message to the terminal.
echo_via_pager
Display text via a pager.
edit_text
Open a text editor for the user to edit content.
get_terminal_size
Get the terminal size as (width, height).
getchar
Read a single character from the terminal.
isatty
Check if a file descriptor refers to a TTY.
launch
Open a URL or file path in the default application.
pause
Pause until the user presses any key.
progressbar
Wrap an iterator with a progress bar display.
prompt
Prompt the user for input with optional type conversion.
secho
Print a styled message to the terminal.
stderr_isatty
Check if stderr is connected to a TTY.
stdin_isatty
Check if stdin is connected to a TTY.
stdout_isatty
Check if stdout is connected to a TTY.
strip_ansi_codes
Strip ANSI escape codes from a string.
style
Style text with ANSI escape codes.