Skip to content

Commit 0d1b14a

Browse files
author
nalla
committed
Merge pull request #28 from dscho/tty-handles
Teach msys2-runtime to hand the tty through to Git
2 parents 57db7c6 + d12a2ce commit 0d1b14a

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

@@ -2267,3 +2269,38 @@ void mingw_startup()
22672269
/* initialize Unicode console */
22682270
winansi_init();
22692271
}
2272+
2273+
int mingw_isatty(int fd) {
2274+
static DWORD id[] = {
2275+
STD_INPUT_HANDLE,
2276+
STD_OUTPUT_HANDLE,
2277+
STD_ERROR_HANDLE
2278+
};
2279+
static unsigned initialized;
2280+
static int is_tty[ARRAY_SIZE(id)];
2281+
2282+
if (fd < 0 || fd >= ARRAY_SIZE(is_tty))
2283+
return isatty(fd);
2284+
2285+
if (isatty(fd))
2286+
return 1;
2287+
2288+
if (!initialized) {
2289+
const char *env = getenv("MSYS_TTY_HANDLES");
2290+
2291+
if (env) {
2292+
int i;
2293+
char buffer[64];
2294+
2295+
for (i = 0; i < ARRAY_SIZE(is_tty); i++) {
2296+
sprintf(buffer, " %ld ", (unsigned long)
2297+
GetStdHandle(id[i]));
2298+
is_tty[i] = !!strstr(env, buffer);
2299+
}
2300+
}
2301+
2302+
initialized = 1;
2303+
}
2304+
2305+
return is_tty[fd];
2306+
}

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)