18 stable releases

new 2.0.5 Dec 8, 2024
2.0.4 Oct 28, 2024
2.0.3 Dec 16, 2023
2.0.1 Jul 28, 2023
1.1.0 Dec 26, 2021

#127 in Command-line interface

Download history 238/week @ 2024-08-17 345/week @ 2024-08-24 383/week @ 2024-08-31 241/week @ 2024-09-07 153/week @ 2024-09-14 128/week @ 2024-09-21 228/week @ 2024-09-28 190/week @ 2024-10-05 387/week @ 2024-10-12 191/week @ 2024-10-19 455/week @ 2024-10-26 659/week @ 2024-11-02 564/week @ 2024-11-09 263/week @ 2024-11-16 352/week @ 2024-11-23 413/week @ 2024-11-30

1,642 downloads per month
Used in 3 crates

BSD-3-Clause

27KB
572 lines

Terminal Utilities

Provides a way to read passwords from a terminal. Terminal echo is disabled when reading the password.

Also provides the ability to check if a terminal is a tty or not.

This crate provides functionality similar to the python getpass and os.isatty functions.

Tested on Linux, macOS, and Windows.

Functions on windows use the windows api directly without relying on large crates like windows-sys or winapi.

Example: Get a password

use passterm::prompt_password_tty;

let pass = prompt_password_tty(Some("Password: ")).unwrap();

println!("Your password is: {}", &pass);

Example: Check if standard output has been redirected

use passterm::{isatty, Stream};

let is_tty = isatty(Stream::Stdout);
if is_tty {
    println!("We're in a terminal");
} else {
    println!("Not in a terminal. Output was redirected >.");
}

lib.rs:

Terminal utilities

Use the prompt_password_tty function to read a password from the tty.

Use the isatty function to check if the given stream is a tty.

Features

Enable the secure_zero feature to zero out data read from the tty.

Dependencies

~51KB