1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os,term.termios: add termios.set_state/2, state.disable_echo/0, use them in os.input_password, to fix v -os wasm32_emscripten examples/2048/

This commit is contained in:
Delyan Angelov
2023-07-31 10:28:45 +03:00
parent 37e7d5f5ae
commit 32114a679a
13 changed files with 161 additions and 40 deletions

View File

@@ -13,17 +13,15 @@ pub fn input_password(prompt string) !string {
if termios.tcgetattr(0, mut old_state) != 0 {
return last_error()
}
defer {
termios.tcsetattr(0, C.TCSANOW, mut old_state)
println('')
}
mut new_state := old_state
new_state.c_lflag &= termios.invert(C.ECHO) // Disable echoing of characters
termios.tcsetattr(0, C.TCSANOW, mut new_state)
new_state.disable_echo()
termios.set_state(0, new_state)
password := input_opt(prompt) or { return error('Failed to read password') }
termios.set_state(0, old_state)
println('')
return password
}