Skip to content

Teach msys2-runtime to hand the tty through to Git #28

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 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions compat/mingw.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "../run-command.h"
#include "../cache.h"

#undef isatty

static const int delay[] = { 0, 1, 10, 20, 40 };
unsigned int _CRT_fmode = _O_BINARY;

Expand Down Expand Up @@ -2287,3 +2289,38 @@ void mingw_startup()
/* init length of current directory for handle_long_path */
current_directory_len = GetCurrentDirectoryW(0, NULL);
}

int mingw_isatty(int fd) {
static DWORD id[] = {
STD_INPUT_HANDLE,
STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE
};
static unsigned initialized;
static int is_tty[ARRAY_SIZE(id)];

if (fd < 0 || fd >= ARRAY_SIZE(is_tty))
return isatty(fd);

if (isatty(fd))
return 1;

if (!initialized) {
const char *env = getenv("MSYS_TTY_HANDLES");

if (env) {
int i;
char buffer[64];

for (i = 0; i < ARRAY_SIZE(is_tty); i++) {
sprintf(buffer, " %ld ", (unsigned long)
GetStdHandle(id[i]));
is_tty[i] = !!strstr(env, buffer);
}
}

initialized = 1;
}

return is_tty[fd];
}
3 changes: 3 additions & 0 deletions compat/mingw.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
int mingw_raise(int sig);
#define raise mingw_raise

int mingw_isatty(int fd);
#define isatty mingw_isatty

/*
* ANSI emulation wrappers
*/
Expand Down
2 changes: 2 additions & 0 deletions compat/winansi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <wingdi.h>
#include <winreg.h>

#undef isatty

/*
ANSI codes used by git: m, K

Expand Down