aboutsummaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/winansi.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/win32/winansi.c b/win32/winansi.c
index 491285275..8ebe7b1af 100644
--- a/win32/winansi.c
+++ b/win32/winansi.c
@@ -16,6 +16,7 @@
16#undef fwrite 16#undef fwrite
17#undef puts 17#undef puts
18#undef write 18#undef write
19#undef read
19 20
20/* 21/*
21 ANSI codes used by git: m, K 22 ANSI codes used by git: m, K
@@ -25,6 +26,7 @@
25*/ 26*/
26 27
27static HANDLE console; 28static HANDLE console;
29static HANDLE console_in;
28static WORD plain_attr; 30static WORD plain_attr;
29static WORD attr; 31static WORD attr;
30static int negative; 32static int negative;
@@ -37,6 +39,10 @@ static void init(void)
37 if (initialized) 39 if (initialized)
38 return; 40 return;
39 41
42 console_in = GetStdHandle(STD_INPUT_HANDLE);
43 if (console_in == INVALID_HANDLE_VALUE)
44 console_in = NULL;
45
40 console = GetStdHandle(STD_OUTPUT_HANDLE); 46 console = GetStdHandle(STD_OUTPUT_HANDLE);
41 if (console == INVALID_HANDLE_VALUE) 47 if (console == INVALID_HANDLE_VALUE)
42 console = NULL; 48 console = NULL;
@@ -611,3 +617,23 @@ int winansi_write(int fd, const void *buf, size_t count)
611 617
612 return ansi_emulate_write(fd, buf, count); 618 return ansi_emulate_write(fd, buf, count);
613} 619}
620
621int winansi_read(int fd, void *buf, size_t count)
622{
623 int rv;
624
625 rv = read(fd, buf, count);
626 if (!isatty(fd))
627 return rv;
628
629 init();
630
631 if (!console_in)
632 return rv;
633
634 if ( rv > 0 ) {
635 OemToCharBuff(buf, buf, rv);
636 }
637
638 return rv;
639}