diff options
author | Ron Yorston <rmy@pobox.com> | 2023-03-07 12:49:25 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2023-03-07 12:49:25 +0000 |
commit | 6eeb5240974bb304830319e9fa5afbc4d6194fc0 (patch) | |
tree | 5ea53ff34648ff615c00f1f8596b82b645324a10 | |
parent | b50470de96320425adbed82129bdb7f7f5263ddb (diff) | |
download | busybox-w32-6eeb5240974bb304830319e9fa5afbc4d6194fc0.tar.gz busybox-w32-6eeb5240974bb304830319e9fa5afbc4d6194fc0.tar.bz2 busybox-w32-6eeb5240974bb304830319e9fa5afbc4d6194fc0.zip |
win32: more changes to console/terminal modes
Allowing virtual terminal input mode to be set if available proved
to be unhelpful: cmd.exe doesn't understand such newfangled stuff
(though PowerShell does).
The allowed values of BB_TERMINAL_MODE are changed to:
0 Force console mode.
1 Force virtual terminal mode for output.
2 Force virtual terminal mode for input.
3 Force virtual terminal mode for input and output.
4 Support virtual terminal input if enabled. Don't alter mode.
5 Support virtual terminal input if enabled. Set virtual terminal
mode for output, if possible.
The default is 5.
-rw-r--r-- | Config.in | 25 | ||||
-rw-r--r-- | win32/winansi.c | 38 |
2 files changed, 31 insertions, 32 deletions
@@ -458,24 +458,23 @@ config FEATURE_EURO | |||
458 | config TERMINAL_MODE | 458 | config TERMINAL_MODE |
459 | int "Default setting for terminal mode" | 459 | int "Default setting for terminal mode" |
460 | default 5 | 460 | default 5 |
461 | range 0 7 | 461 | range 0 5 |
462 | depends on PLATFORM_MINGW32 | 462 | depends on PLATFORM_MINGW32 |
463 | help | 463 | help |
464 | Control I/O mode of the Windows console/terminal. Possible | 464 | Set the default input/output modes of the Windows console/terminal. |
465 | values are: | 465 | Possible values are: |
466 | 466 | ||
467 | 0 Console mode. | 467 | 0 Force console mode. |
468 | 1 Force terminal mode output. | 468 | 1 Force virtual terminal mode for output. |
469 | 2 Force terminal mode input. | 469 | 2 Force virtual terminal mode for input. |
470 | 3 Force terminal mode input and output. | 470 | 3 Force virtual terminal mode for input and output. |
471 | 471 | ||
472 | 4 Console mode. | 472 | 4 Support virtual terminal input if enabled. Don't alter mode. |
473 | 5 Prefer terminal mode output, fall back to console mode. | 473 | 5 Support virtual terminal input if enabled. Set virtual terminal |
474 | 6 Prefer terminal mode input, fall back to console mode. | 474 | mode for output, if possible. |
475 | 7 Prefer terminal mode input and output, fall back to console. | ||
476 | 475 | ||
477 | Setting the environment variable BB_TERMINAL_MODE overrides this | 476 | Values 0-3 are for testing only. The default is 5. The environment |
478 | default. | 477 | variable BB_TERMINAL_MODE overrides this. |
479 | 478 | ||
480 | config FEATURE_IMPROVED_COLOUR_MAPPING | 479 | config FEATURE_IMPROVED_COLOUR_MAPPING |
481 | bool "More accurate colour mapping for ANSI emulation (0.6 kb)" | 480 | bool "More accurate colour mapping for ANSI emulation (0.6 kb)" |
diff --git a/win32/winansi.c b/win32/winansi.c index 11a9327e1..de6db08e2 100644 --- a/win32/winansi.c +++ b/win32/winansi.c | |||
@@ -76,7 +76,6 @@ int terminal_mode(int reset) | |||
76 | static int mode = -1; | 76 | static int mode = -1; |
77 | 77 | ||
78 | if (mode < 0 || reset) { | 78 | if (mode < 0 || reset) { |
79 | int prefer; | ||
80 | HANDLE h; | 79 | HANDLE h; |
81 | DWORD oldmode, newmode; | 80 | DWORD oldmode, newmode; |
82 | const char *term = getenv(BB_TERMINAL_MODE); | 81 | const char *term = getenv(BB_TERMINAL_MODE); |
@@ -95,30 +94,26 @@ int terminal_mode(int reset) | |||
95 | CONFIG_TERMINAL_MODE; | 94 | CONFIG_TERMINAL_MODE; |
96 | } | 95 | } |
97 | 96 | ||
98 | if (mode < 0 || mode > 7) { | 97 | if (mode < 0 || mode > 6) |
99 | prefer = mode = 0; | 98 | mode = CONFIG_TERMINAL_MODE; |
100 | } else if (mode > 3) { | ||
101 | // Try to get requested mode, fall back to console on failure. | ||
102 | prefer = mode = mode - 4; | ||
103 | } else { | ||
104 | // Force the requested mode, even if we can't get it. | ||
105 | prefer = 0; | ||
106 | } | ||
107 | 99 | ||
108 | if (is_console(STDOUT_FILENO)) { | 100 | if (is_console(STDOUT_FILENO)) { |
109 | h = get_console(); | 101 | h = get_console(); |
110 | if (GetConsoleMode(h, &oldmode)) { | 102 | if (GetConsoleMode(h, &oldmode)) { |
111 | // Try to recover from mode 0 induced by SSH. | 103 | // Try to recover from mode 0 induced by SSH. |
112 | newmode = oldmode == 0 ? 3 : oldmode; | 104 | newmode = oldmode == 0 ? 3 : oldmode; |
113 | if ((mode & VT_OUTPUT)) | 105 | |
106 | if ((mode & VT_OUTPUT)) { | ||
114 | newmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; | 107 | newmode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
115 | else | 108 | } else if (mode < 4) { |
116 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING; | 109 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
117 | newmode &= ~DISABLE_NEWLINE_AUTO_RETURN; | 110 | } else if ((oldmode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)) { |
111 | mode |= VT_OUTPUT; | ||
112 | } | ||
118 | 113 | ||
119 | if (newmode != oldmode) { | 114 | if (newmode != oldmode) { |
120 | if (!SetConsoleMode(h, newmode)) { | 115 | if (!SetConsoleMode(h, newmode)) { |
121 | if ((prefer & VT_OUTPUT)) | 116 | if (mode >= 4) |
122 | mode &= ~VT_OUTPUT; | 117 | mode &= ~VT_OUTPUT; |
123 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING; | 118 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_PROCESSING; |
124 | SetConsoleMode(h, newmode); | 119 | SetConsoleMode(h, newmode); |
@@ -132,14 +127,19 @@ int terminal_mode(int reset) | |||
132 | if (GetConsoleMode(h, &oldmode)) { | 127 | if (GetConsoleMode(h, &oldmode)) { |
133 | // Try to recover from mode 0 induced by SSH. | 128 | // Try to recover from mode 0 induced by SSH. |
134 | newmode = oldmode == 0 ? 0x1f7 : oldmode; | 129 | newmode = oldmode == 0 ? 0x1f7 : oldmode; |
135 | if ((mode & VT_INPUT)) | 130 | |
136 | newmode |= ENABLE_VIRTUAL_TERMINAL_INPUT; | 131 | if (mode < 4) { |
137 | else | 132 | if ((mode & VT_INPUT)) |
138 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_INPUT; | 133 | newmode |= ENABLE_VIRTUAL_TERMINAL_INPUT; |
134 | else | ||
135 | newmode &= ~ENABLE_VIRTUAL_TERMINAL_INPUT; | ||
136 | } else if ((oldmode & ENABLE_VIRTUAL_TERMINAL_INPUT)) { | ||
137 | mode |= VT_INPUT; | ||
138 | } | ||
139 | 139 | ||
140 | if (newmode != oldmode) { | 140 | if (newmode != oldmode) { |
141 | if (!SetConsoleMode(h, newmode)) { | 141 | if (!SetConsoleMode(h, newmode)) { |
142 | if ((prefer & VT_INPUT)) | 142 | if (mode >= 4) |
143 | mode &= ~VT_INPUT; | 143 | mode &= ~VT_INPUT; |
144 | // Failure to set the new mode seems to leave | 144 | // Failure to set the new mode seems to leave |
145 | // the flag set. Forcibly unset it. | 145 | // the flag set. Forcibly unset it. |