12 stable releases

1.1.7 Jan 19, 2023
1.1.6 Jun 19, 2022
1.1.3 Feb 7, 2022
1.1.2 Jan 24, 2022
1.1.0 Dec 26, 2021

#151 in Command-line interface

Download history 3/week @ 2022-10-09 3/week @ 2022-10-16 50/week @ 2022-10-23 10/week @ 2022-10-30 6/week @ 2022-11-06 7/week @ 2022-11-13 14/week @ 2022-11-20 6/week @ 2022-11-27 64/week @ 2022-12-04 17/week @ 2022-12-11 16/week @ 2022-12-18 6/week @ 2022-12-25 5/week @ 2023-01-01 10/week @ 2023-01-08 191/week @ 2023-01-15 122/week @ 2023-01-22

328 downloads per month
Used in kestrel-cli

BSD-3-Clause

11KB
207 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 new, official windows crate instead of the older winapi crate.

Example: Get a password

use passterm::read_password;
use std::io::Write;

print!("New password: ");
std::io::stdout().flush()?;
let pass = read_password()?;
println!();

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

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 [read_password()] function to read a line from stdin with echo disabled.

Use the [isatty()] function to check if the given stream is a tty.

Dependencies

~0–43MB
~705K SLoC