Skip to content

Commit

Permalink
mingw (git_terminal_prompt): turn on echo explictly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dscho committed Feb 23, 2018
1 parent 55a5bfb commit 80a18d4
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions compat/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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[] = {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 80a18d4

Please sign in to comment.