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

(cherry picked from commit 104934c095)
This commit is contained in:
Sam Doran 2017-10-26 12:05:08 -04:00 committed by Sam Doran
parent 88e7bb3e28
commit 4a8ffe56a9
2 changed files with 16 additions and 0 deletions

View file

@ -78,6 +78,8 @@ Ansible Changes By Release
(https://github.com/ansible/ansible/pull/29030)
* Fix elb_target_group module traceback when ports were specified inside of the targets parameter:
(https://github.com/ansible/ansible/pull/32202)
* Enable echo for `pause` module: (https://github.com/ansible/ansible/issues/14160)
<a id="2.4.1"></a>

View file

@ -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)