[PATCH v2 1/3] Cygwin: console: support 24 bit color
Corinna Vinschen
corinna-cygwin@cygwin.com
Sun Mar 31 14:37:00 GMT 2019
On Mar 31 22:47, Takashi Yano wrote:
> - Add 24 bit color support using xterm compatibility mode in
> Windows 10 1703 or later.
> - Add fake 24 bit color support for legacy console, which uses
> the nearest color from 16 system colors.
> ---
> winsup/cygwin/environ.cc | 7 +-
> winsup/cygwin/fhandler.h | 4 +
> winsup/cygwin/fhandler_console.cc | 229 +++++++++++++++++++++++++-----
> winsup/cygwin/select.cc | 8 ++
> winsup/cygwin/wincap.cc | 10 ++
> winsup/cygwin/wincap.h | 2 +
> 6 files changed, 227 insertions(+), 33 deletions(-)
>
> diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
> index 21f13734c..c27d10fe1 100644
> --- a/winsup/cygwin/environ.cc
> +++ b/winsup/cygwin/environ.cc
> @@ -869,10 +869,15 @@ win32env_to_cygenv (PWCHAR rawenv, bool posify)
> char *newp;
> int i;
> int sawTERM = 0;
> - static char NO_COPY cygterm[] = "TERM=cygwin";
> + static char NO_COPY cygterm[] = "TERM=xterm-256color";
> char *tmpbuf = tp.t_get ();
> PWCHAR w;
>
> + /* If console has 24 bit color capability, TERM=xterm-256color,
> + otherwise, TERM=cygwin */
> + if (!wincap.has_con_24bit_colors ())
> + strncpy (cygterm, "TERM=cygwin", sizeof (cygterm));
> +
This hunk is ok, but I wonder if the time hasn't come to simplify the
original code. The `static char NO_COPY' only makes marginal sense
since it's strdup'ed anyway.
What if we just define two const char's like this
const char cygterm[] = "TERM=cygwin";
const char xterm[] = "TERM=xterm-256color";
and then just strdup them conditionally:
if (!sawTERM)
envp[i++] = strdup (wincap.has_con_24bit_colors () ? xterm : cygterm);
What do you think?
> +#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
> +#define ENABLE_VIRTUAL_TERMINAL_PROCESSING 0x0004
> +#endif /* ENABLE_VIRTUAL_TERMINAL_PROCESSING */
> +#ifndef DISABLE_NEWLINE_AUTO_RETURN
> +#define DISABLE_NEWLINE_AUTO_RETURN 0x0008
> +#endif /* DISABLE_NEWLINE_AUTO_RETURN */
> +#ifndef ENABLE_VIRTUAL_TERMINAL_INPUT
> +#define ENABLE_VIRTUAL_TERMINAL_INPUT 0x0200
> +#endif /* ENABLE_VIRTUAL_TERMINAL_INPUT */
Sorry, didn't notice this before: Please prepend this block with
a comment along the lines of "/* Not yet defined in Mingw-w64 */"
> diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
> index 9b18e8f80..28adcf3e7 100644
> --- a/winsup/cygwin/select.cc
> +++ b/winsup/cygwin/select.cc
> @@ -1053,6 +1053,14 @@ peek_console (select_record *me, bool)
> else if (irec.Event.KeyEvent.uChar.UnicodeChar
> || fhandler_console::get_nonascii_key (irec, tmpbuf))
> return me->read_ready = true;
> + /* Allow Ctrl-Space for ^@ */
> + else if ( (irec.Event.KeyEvent.wVirtualKeyCode == VK_SPACE
> + || irec.Event.KeyEvent.wVirtualKeyCode == '2')
> + && (irec.Event.KeyEvent.dwControlKeyState &
> + (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
> + && !(irec.Event.KeyEvent.dwControlKeyState
> + & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) )
> + return me->read_ready = true;
> }
> /* Ignore key up events, except for Alt+Numpad events. */
> else if (is_alt_numpad_event (&irec))
Doesn't this belong into the select patch?
Thanks,
Corinna
--
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20190331/fd31c5cf/attachment.sig>
More information about the Cygwin-patches
mailing list