Skip to content

mingw: Proper git_terminal_prompt with xterm #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2015
Merged

mingw: Proper git_terminal_prompt with xterm #40

merged 1 commit into from
Mar 19, 2015

Conversation

nalla
Copy link

@nalla nalla commented Mar 19, 2015

The git_terminal_prompt calls with xterm, specially with mintty can
not rely on the WIN32 console. The MSYS_TTY_HANDLES should be used to
open the proper console input and output streams.

Signed-off-by: nalla [email protected]

@nalla
Copy link
Author

nalla commented Mar 19, 2015

@dscho I addressed your comments in a7e8c330fa70a70d24258ff9c02bc6f60035b5f8

@dscho
Copy link
Member

dscho commented Mar 19, 2015

Thanks! There was a mid-air collision, though (or maybe the opposite? Maybe a failed fueling maneuver?), as I suggested a more extensive commit message, too... (And it took me almost 10 minutes to write it...)

The `git_terminal_prompt()` function expects the terminal window to be
attached to a Win32 Console. However, this is not the case with terminal
windows other than `cmd.exe`'s, e.g. with MSys2's own `mintty`.

Non-cmd terminals such as `mintty` still have to have a Win32 Console
to be proper console programs, but have to hide the Win32 Console to
be able to provide more flexibility (such as being resizeable not only
vertically but also horizontally). By writing to that Win32 Console,
`git_terminal_prompt()` manages only to send the prompt to nowhere and
to wait for input from a Console to which the user has no access.

This commit introduces a function specifically to support `mintty` -- or
other terminals that are compatible with MSys2's `/dev/tty` emulation. We
use the `TERM` environment variable as an indicator for that: if the value
starts with "xterm" (such as `mintty`'s "xterm_256color"), we prefer to
let `xterm_prompt()` handle the user interaction.

To handle the case when standard input/output are redirected – as is the
case when pushing via HTTPS: `git-remote-https`' standard input and
output are pipes from/to the main Git executable – we make use of the
`MSYS_TTY_HANDLES` environment variable that was introduced to
fix another bug in MSys2-based Git: this environment variable contains
the Win32 `HANDLE`s of the standard input, output and error as originally
passed from MSys2 to the Git executable, enclosed within space
characters, skipping handles that do not refer to the terminal window
(e.g. when they were redirected). We will only use those handles when
that environment variable lists all three handles because then we can be
100% certain that we are running inside a terminal window, and that we
know exactly which Win32 handles to use to communicate with it.

Helped-by: Johannes Schindelin <[email protected]>
Signed-off-by: nalla <[email protected]>
dscho added a commit that referenced this pull request Mar 19, 2015
mingw: Proper `git_terminal_prompt` with `xterm`
@dscho dscho merged commit 1bd4e1e into git-for-windows:master Mar 19, 2015
@dscho
Copy link
Member

dscho commented Mar 19, 2015

Thank you very much!

@nalla nalla deleted the git-terminal-prompt branch March 19, 2015 16:18
dscho added a commit that referenced this pull request Mar 21, 2015
mingw: Proper `git_terminal_prompt` with `xterm`
dscho pushed a commit that referenced this pull request Mar 24, 2015
mingw: Proper `git_terminal_prompt` with `xterm`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants