18 stable releases
| 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 |
#140 in Command-line interface
9,256 downloads per month
Used in 4 crates
(3 directly)
27KB
572 lines
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.
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 >.");
}
Dependencies
~49KB