Enable ECHO in prompt module (#32083)

* Enable ECHO in prompt module

Fixes #14160

* Set flags to make it possible to edit echoed input as well as hide control charcters

Only do this if a time limit is not set.

* Consolidate settings
pull/32212/head
Sam Doran 7 years ago committed by ansibot
parent c822292347
commit 104934c095

@ -140,6 +140,20 @@ class ActionModule(ActionBase):
old_settings = termios.tcgetattr(fd)
tty.setraw(fd)
# Enable a few things turned off by tty.setraw()
# ICANON -> Allows characters to be deleted and hides things like ^M.
# ICRNL -> Makes the return key work when ICANON is enabled, otherwise
# you get stuck at the prompt with no way to get out of it.
# ECHO -> Echos input back to stdout
#
# See man termios for details on these flags
if not seconds:
new_settings = termios.tcgetattr(fd)
new_settings[0] = new_settings[0] | termios.ICRNL
new_settings[3] = new_settings[3] | (termios.ICANON | termios.ECHO)
termios.tcsetattr(fd, termios.TCSANOW, new_settings)
termios.tcsetattr(fd, termios.TCSANOW, new_settings)
# flush the buffer to make sure no previous key presses
# are read in below
termios.tcflush(stdin, termios.TCIFLUSH)

Loading…
Cancel
Save