diff options
-rw-r--r-- | win32/winansi.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/win32/winansi.c b/win32/winansi.c index 15f443f4b..ef566684e 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -76,7 +76,10 @@ int skip_ansi_emulation(int reset) | |||
76 | static int skip = -1; | 76 | static int skip = -1; |
77 | 77 | ||
78 | if (skip < 0 || reset) { | 78 | if (skip < 0 || reset) { |
79 | HANDLE h; | ||
80 | DWORD oldmode, newmode; | ||
79 | const char *var = getenv(BB_SKIP_ANSI_EMULATION); | 81 | const char *var = getenv(BB_SKIP_ANSI_EMULATION); |
82 | |||
80 | if (var) { | 83 | if (var) { |
81 | skip = atoi(var); | 84 | skip = atoi(var); |
82 | if (skip < 0 || skip > 2) | 85 | if (skip < 0 || skip > 2) |
@@ -87,11 +90,10 @@ int skip_ansi_emulation(int reset) | |||
87 | } | 90 | } |
88 | 91 | ||
89 | if (is_console(STDOUT_FILENO)) { | 92 | if (is_console(STDOUT_FILENO)) { |
90 | HANDLE h = get_console(); | 93 | h = get_console(); |
91 | DWORD oldmode, newmode; | ||
92 | |||
93 | if (GetConsoleMode(h, &oldmode)) { | 94 | if (GetConsoleMode(h, &oldmode)) { |
94 | newmode = oldmode; | 95 | // Try to recover from mode 0 induced by SSH. |
96 | newmode = oldmode == 0 ? 3 : oldmode; | ||
95 | if (skip) | 97 | if (skip) |
96 | newmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | 98 | newmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
97 | else | 99 | else |
@@ -103,6 +105,14 @@ int skip_ansi_emulation(int reset) | |||
103 | } | 105 | } |
104 | } | 106 | } |
105 | } | 107 | } |
108 | |||
109 | // Try to recover from mode 0 induced by SSH. | ||
110 | if (reset && is_console_in(STDIN_FILENO)) { | ||
111 | h = GetStdHandle(STD_INPUT_HANDLE); | ||
112 | if (GetConsoleMode(h, &oldmode) && oldmode == 0) { | ||
113 | SetConsoleMode(h, 0x1f7); | ||
114 | } | ||
115 | } | ||
106 | } | 116 | } |
107 | 117 | ||
108 | return skip; | 118 | return skip; |