()
| 669 | /// Reads a line from stdin without echoing (for sensitive input like keys) |
| 670 | #[cfg(unix)] |
| 671 | fn read_password() -> io::Result<String> { |
| 672 | use nix::sys::termios::{self, LocalFlags, SetArg}; |
| 673 | use std::io::BufRead; |
| 674 | use std::os::fd::AsFd; |
| 675 | |
| 676 | let stdin = io::stdin(); |
| 677 | let fd = stdin.as_fd(); |
| 678 | |
| 679 | // Save original terminal settings |
| 680 | let original = termios::tcgetattr(fd)?; |
| 681 | |
| 682 | // Disable echo |
| 683 | let mut noecho = original.clone(); |
| 684 | noecho.local_flags.remove(LocalFlags::ECHO); |
| 685 | termios::tcsetattr(fd, SetArg::TCSANOW, &noecho)?; |
| 686 | |
| 687 | // Read the line |
| 688 | let mut input = String::new(); |
| 689 | let result = stdin.lock().read_line(&mut input); |
| 690 | |
| 691 | // Restore original settings |
| 692 | termios::tcsetattr(fd, SetArg::TCSANOW, &original)?; |
| 693 | |
| 694 | // Print newline since echo was disabled |
| 695 | println!(); |
| 696 | |
| 697 | result?; |
| 698 | Ok(input) |
| 699 | } |
| 700 | |
| 701 | /// Reads a line from stdin without echoing (for sensitive input like keys) |
| 702 | #[cfg(windows)] |
no outgoing calls
no test coverage detected