[v2,1/4] git-p4: rewrite prompt to be Windows compatible
diff mbox series

Message ID 585bdd51b258acbf438efe5a84924977778aff71.1580507895.git.gitgitgadget@gmail.com
State New
Headers show
  • git-p4: add hook p4-pre-edit-changelist
Related show

Commit Message

Derrick Stolee via GitGitGadget Jan. 31, 2020, 9:58 p.m. UTC
From: Ben Keene <seraphire@gmail.com>

The existing function prompt(prompt_text) does not work correctly when
run on Windows 10 bash terminal when launched from the sourcetree
GUI application. The stdout is not flushed properly so the prompt text
is not displayed to the user until the next flush of stdout, which is
quite confusing.

Change this method by:
* Adding flush to stderr, stdout, and stdin
* Use readline from sys.stdin instead of raw_input.

The existing strip().lower() are retained.

Signed-off-by: Ben Keene <seraphire@gmail.com>
 git-p4.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff mbox series

diff --git a/git-p4.py b/git-p4.py
index 40d9e7c594..7d8a5ee788 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -175,7 +175,11 @@  def prompt(prompt_text):
     choices = set(m.group(1) for m in re.finditer(r"\[(.)\]", prompt_text))
     while True:
-        response = raw_input(prompt_text).strip().lower()
+        sys.stderr.flush()
+        sys.stdout.write(prompt_text)
+        sys.stdout.flush()
+        sys.stdin.flush()
+        response=sys.stdin.readline().strip().lower()
         if not response:
         response = response[0]