Skip to content

Commit 5d53268

Browse files
committed
mingw (git_terminal_prompt): turn on echo explictly
It turns out that when running in a Powershell window, we need to turn on ENABLE_ECHO_INPUT because the default would be *not* to echo anything. This also ensures that we use the input mode where all input is read until the user hits the Return key. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent ad62940 commit 5d53268

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

compat/terminal.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,26 @@ static void restore_term(void)
7777
hconin = INVALID_HANDLE_VALUE;
7878
}
7979

80-
static int disable_echo(void)
80+
static int set_echo(int echo)
8181
{
82-
hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
83-
FILE_SHARE_READ, NULL, OPEN_EXISTING,
84-
FILE_ATTRIBUTE_NORMAL, NULL);
82+
DWORD new_cmode;
83+
84+
if (hconin == INVALID_HANDLE_VALUE)
85+
hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
86+
FILE_SHARE_READ, NULL, OPEN_EXISTING,
87+
FILE_ATTRIBUTE_NORMAL, NULL);
8588
if (hconin == INVALID_HANDLE_VALUE)
8689
return -1;
8790

8891
GetConsoleMode(hconin, &cmode);
92+
new_cmode = cmode | ENABLE_LINE_INPUT;
93+
if (echo)
94+
new_cmode |= ENABLE_ECHO_INPUT;
95+
else
96+
new_cmode &= ~ENABLE_ECHO_INPUT;
97+
8998
sigchain_push_common(restore_term_on_signal);
90-
if (!SetConsoleMode(hconin, cmode & (~ENABLE_ECHO_INPUT))) {
99+
if (!SetConsoleMode(hconin, new_cmode)) {
91100
CloseHandle(hconin);
92101
hconin = INVALID_HANDLE_VALUE;
93102
return -1;
@@ -96,6 +105,11 @@ static int disable_echo(void)
96105
return 0;
97106
}
98107

108+
static int disable_echo(void)
109+
{
110+
return set_echo(0);
111+
}
112+
99113
static char *shell_prompt(const char *prompt, int echo)
100114
{
101115
const char *read_input[] = {
@@ -169,6 +183,8 @@ char *git_terminal_prompt(const char *prompt, int echo)
169183
if (result)
170184
return result;
171185

186+
if (echo && set_echo(1))
187+
return NULL;
172188
#endif
173189

174190
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);

0 commit comments

Comments
 (0)