16 stable releases

2.0.3 Dec 16, 2023
2.0.2 Dec 15, 2023
2.0.1 Jul 28, 2023
1.1.7 Jan 19, 2023
1.1.0 Dec 26, 2021

#142 in Command-line interface

Download history 106/week @ 2023-12-21 303/week @ 2023-12-28 355/week @ 2024-01-04 623/week @ 2024-01-11 658/week @ 2024-01-18 487/week @ 2024-01-25 438/week @ 2024-02-01 404/week @ 2024-02-08 449/week @ 2024-02-15 451/week @ 2024-02-22 543/week @ 2024-02-29 337/week @ 2024-03-07 524/week @ 2024-03-14 323/week @ 2024-03-21 518/week @ 2024-03-28 303/week @ 2024-04-04

1,739 downloads per month
Used in 2 crates

BSD-3-Clause

28KB
619 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

~50KB