1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Sam Doran 2017-10-26 12:05:08 -04:00 committed by ansibot
parent c822292347
commit 104934c095

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)