Merge pull request #28 from dscho/tty-handles

Teach msys2-runtime to hand the tty through to Git
This commit is contained in:
Johannes Schindelin
2015-03-20 15:04:27 +01:00
3 changed files with 42 additions and 0 deletions

View File

@@ -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;
@@ -2216,3 +2218,38 @@ void mingw_startup()
/* initialize Unicode console */
winansi_init();
}
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];
}

View File

@@ -351,6 +351,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
*/

View File

@@ -7,6 +7,8 @@
#include <wingdi.h>
#include <winreg.h>
#undef isatty
/*
ANSI codes used by git: m, K