Skip to content

Commit 8c01ab4

Browse files
committed
Merge pull request #28 from dscho/tty-handles
Teach msys2-runtime to hand the tty through to Git
2 parents 7354ebe + de0d35d commit 8c01ab4

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

compat/mingw.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "../run-command.h"
77
#include "../cache.h"
88

9+
#undef isatty
10+
911
static const int delay[] = { 0, 1, 10, 20, 40 };
1012
unsigned int _CRT_fmode = _O_BINARY;
1113

@@ -2287,3 +2289,38 @@ void mingw_startup()
22872289
/* init length of current directory for handle_long_path */
22882290
current_directory_len = GetCurrentDirectoryW(0, NULL);
22892291
}
2292+
2293+
int mingw_isatty(int fd) {
2294+
static DWORD id[] = {
2295+
STD_INPUT_HANDLE,
2296+
STD_OUTPUT_HANDLE,
2297+
STD_ERROR_HANDLE
2298+
};
2299+
static unsigned initialized;
2300+
static int is_tty[ARRAY_SIZE(id)];
2301+
2302+
if (fd < 0 || fd >= ARRAY_SIZE(is_tty))
2303+
return isatty(fd);
2304+
2305+
if (isatty(fd))
2306+
return 1;
2307+
2308+
if (!initialized) {
2309+
const char *env = getenv("MSYS_TTY_HANDLES");
2310+
2311+
if (env) {
2312+
int i;
2313+
char buffer[64];
2314+
2315+
for (i = 0; i < ARRAY_SIZE(is_tty); i++) {
2316+
sprintf(buffer, " %ld ", (unsigned long)
2317+
GetStdHandle(id[i]));
2318+
is_tty[i] = !!strstr(env, buffer);
2319+
}
2320+
}
2321+
2322+
initialized = 1;
2323+
}
2324+
2325+
return is_tty[fd];
2326+
}

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
367367
int mingw_raise(int sig);
368368
#define raise mingw_raise
369369

370+
int mingw_isatty(int fd);
371+
#define isatty mingw_isatty
372+
370373
/*
371374
* ANSI emulation wrappers
372375
*/

compat/winansi.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <wingdi.h>
88
#include <winreg.h>
99

10+
#undef isatty
11+
1012
/*
1113
ANSI codes used by git: m, K
1214

0 commit comments

Comments
 (0)