diff --git a/Cargo.toml b/Cargo.toml index 975dee8..2af7124 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rpassword" -version = "0.3.1" +version = "0.4.0" authors = ["Conrad Kleinespel "] description = "Read passwords in console applications." license = "Apache-2.0" diff --git a/README.md b/README.md index e7ecae2..2213fd6 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Add `rpassword` as a dependency in Cargo.toml: ```toml [dependencies] -rpassword = "0.3" +rpassword = "0.4" ``` Import the `rpassword` crate and use the `promt_password_stdout()` to show a message on `stdout` and read a password into a `String`: @@ -43,6 +43,17 @@ fn main() { } ``` +Finally, you can read strings with a single line, and without the terminating +newline that `read_line` would add: +```rust +extern crate rpassword; + +fn main() { + let response = rpassword::read_response().unwrap(); + println!("Your response is {}", response); +} +``` + Check [examples/example.rs](examples/example.rs) for a few more examples. ## Contributors @@ -55,3 +66,4 @@ Check [examples/example.rs](examples/example.rs) for a few more examples. * [@petevine](https://github.com/petevine) * [@psych0d0g](https://github.com/psych0d0g) * [@retep998](https://github.com/retep998) +* [@steveatinfincia](https://github.com/steveatinfincia) diff --git a/examples/example.rs b/examples/example.rs index 1933a18..8e2aa6e 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -10,9 +10,18 @@ fn main() { let pass = rpassword::read_password().unwrap(); println!("Your password is {}", pass); - let pass = rpassword::prompt_password_stdout("Password: ").unwrap(); + let pass = rpassword::prompt_password_stdout("Password with prompt on stdout: ").unwrap(); println!("Your password is {}", pass); - let pass = rpassword::prompt_password_stderr("Password: ").unwrap(); + let pass = rpassword::prompt_password_stderr("Password with prompt on stderr: ").unwrap(); println!("Your password is {}", pass); + + let response = rpassword::read_response().unwrap(); + println!("Your response is {}", response); + + let response = rpassword::prompt_response_stdout("Response with prompt on stdout: ").unwrap(); + println!("Your response is {}", response); + + let response = rpassword::prompt_response_stderr("Response with prompt on stderr: ").unwrap(); + println!("Your response is {}", response); } diff --git a/src/lib.rs b/src/lib.rs index 11658cb..265b39d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,7 @@ mod windows { } let new_mode_flags = match hide { true => winapi::ENABLE_LINE_INPUT | winapi::ENABLE_PROCESSED_INPUT, - false => winapi::ENABLE_LINE_INPUT | winapi::ENABLE_PROCESSED_INPUT| ENABLE_ECHO_INPUT, + false => winapi::ENABLE_LINE_INPUT | winapi::ENABLE_PROCESSED_INPUT | winapi::ENABLE_ECHO_INPUT, }; // We want to be able to read line by line, and we still want backspace to work