Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,26 @@
|
||||
module os
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
// input_password prompts the user for a password-like secret.
|
||||
// It disables the terminal echo during user input and resets it back to normal when done.
|
||||
pub fn input_password(prompt string) !string {
|
||||
if is_atty(1) <= 0 || getenv('TERM') == 'dumb' {
|
||||
return error('Could not obtain password discretely.')
|
||||
}
|
||||
|
||||
std_handle := C.GetStdHandle(C.STD_INPUT_HANDLE)
|
||||
mut mode := u32(0)
|
||||
|
||||
unsafe { C.GetConsoleMode(std_handle, voidptr(&mode)) }
|
||||
unsafe { C.SetConsoleMode(std_handle, mode & (~u32(C.ENABLE_ECHO_INPUT))) }
|
||||
|
||||
defer {
|
||||
unsafe { C.SetConsoleMode(std_handle, &mode) }
|
||||
println('')
|
||||
}
|
||||
|
||||
password := input_opt(prompt) or { return error('Failed to read password') }
|
||||
|
||||
return password
|
||||
}
|
||||
Reference in new issue
Block a user