Skip to content

Commit 02e2dfe

Browse files
committed
Merge pull request #28 from dscho/tty-handles
Teach msys2-runtime to hand the tty through to Git
2 parents 59967c3 + d418372 commit 02e2dfe

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

@@ -2216,3 +2218,38 @@ void mingw_startup()
22162218
/* initialize Unicode console */
22172219
winansi_init();
22182220
}
2221+
2222+
int mingw_isatty(int fd) {
2223+
static DWORD id[] = {
2224+
STD_INPUT_HANDLE,
2225+
STD_OUTPUT_HANDLE,
2226+
STD_ERROR_HANDLE
2227+
};
2228+
static unsigned initialized;
2229+
static int is_tty[ARRAY_SIZE(id)];
2230+
2231+
if (fd < 0 || fd >= ARRAY_SIZE(is_tty))
2232+
return isatty(fd);
2233+
2234+
if (isatty(fd))
2235+
return 1;
2236+
2237+
if (!initialized) {
2238+
const char *env = getenv("MSYS_TTY_HANDLES");
2239+
2240+
if (env) {
2241+
int i;
2242+
char buffer[64];
2243+
2244+
for (i = 0; i < ARRAY_SIZE(is_tty); i++) {
2245+
sprintf(buffer, " %ld ", (unsigned long)
2246+
GetStdHandle(id[i]));
2247+
is_tty[i] = !!strstr(env, buffer);
2248+
}
2249+
}
2250+
2251+
initialized = 1;
2252+
}
2253+
2254+
return is_tty[fd];
2255+
}

compat/mingw.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ sig_handler_t mingw_signal(int sig, sig_handler_t handler);
351351
int mingw_raise(int sig);
352352
#define raise mingw_raise
353353

354+
int mingw_isatty(int fd);
355+
#define isatty mingw_isatty
356+
354357
/*
355358
* ANSI emulation wrappers
356359
*/

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)