From 104934c09565ddeb4c4d14bb9c283c5639988466 Mon Sep 17 00:00:00 2001 From: Sam Doran Date: Thu, 26 Oct 2017 12:05:08 -0400 Subject: [PATCH] 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 --- lib/ansible/plugins/action/pause.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/ansible/plugins/action/pause.py b/lib/ansible/plugins/action/pause.py index 29ea79fc7e7..abe7ee6ae16 100644 --- a/lib/ansible/plugins/action/pause.py +++ b/lib/ansible/plugins/action/pause.py @@ -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)