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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2018-02-23 02:50:03 +01:00
committed by Jameson Miller
parent f36a43d8bd
commit 0ef403a7a3

View File

@@ -77,17 +77,26 @@ static void restore_term(void)
hconin = INVALID_HANDLE_VALUE;
}
static int disable_echo(void)
static int set_echo(int echo)
{
hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
DWORD new_cmode;
if (hconin == INVALID_HANDLE_VALUE)
hconin = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hconin == INVALID_HANDLE_VALUE)
return -1;
GetConsoleMode(hconin, &cmode);
new_cmode = cmode | ENABLE_LINE_INPUT;
if (echo)
new_cmode |= ENABLE_ECHO_INPUT;
else
new_cmode &= ~ENABLE_ECHO_INPUT;
sigchain_push_common(restore_term_on_signal);
if (!SetConsoleMode(hconin, cmode & (~ENABLE_ECHO_INPUT))) {
if (!SetConsoleMode(hconin, new_cmode)) {
CloseHandle(hconin);
hconin = INVALID_HANDLE_VALUE;
return -1;
@@ -96,6 +105,11 @@ static int disable_echo(void)
return 0;
}
static int disable_echo(void)
{
return set_echo(0);
}
static char *shell_prompt(const char *prompt, int echo)
{
const char *read_input[] = {
@@ -169,6 +183,8 @@ char *git_terminal_prompt(const char *prompt, int echo)
if (result)
return result;
if (echo && set_echo(1))
return NULL;
#endif
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);