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
1,642 downloads per month
Used in 3 crates
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