On Tue, 21 Feb 2017 23:17:57 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.da...@ens-lyon.org>
> # Date 1482372679 -3600
> #      Thu Dec 22 03:11:19 2016 +0100
> # Node ID 60a489f0531abbafc7f53a3dd4bad50f13b38015
> # Parent  e5363cb96233861fc99f7e9b85d7884d3121558c
> # EXP-Topic color
> color: move 'win32' declaration to the core module

The series looks good. Queued, thanks.

> +if pycompat.osname == 'nt':
> +    import ctypes
> +    import re
> +
> +    _kernel32 = ctypes.windll.kernel32
> +
> +    _WORD = ctypes.c_ushort
> +
> +    _INVALID_HANDLE_VALUE = -1
> +
> +    class _COORD(ctypes.Structure):
> +        _fields_ = [('X', ctypes.c_short),
> +                    ('Y', ctypes.c_short)]
> +
> +    class _SMALL_RECT(ctypes.Structure):
> +        _fields_ = [('Left', ctypes.c_short),
> +                    ('Top', ctypes.c_short),
> +                    ('Right', ctypes.c_short),
> +                    ('Bottom', ctypes.c_short)]
> +
> +    class _CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
> +        _fields_ = [('dwSize', _COORD),
> +                    ('dwCursorPosition', _COORD),
> +                    ('wAttributes', _WORD),
> +                    ('srWindow', _SMALL_RECT),
> +                    ('dwMaximumWindowSize', _COORD)]
> +
> +    _STD_OUTPUT_HANDLE = 0xfffffff5 # (DWORD)-11
> +    _STD_ERROR_HANDLE = 0xfffffff4  # (DWORD)-12

[...]

> +        try:
> +            while m:
> +                for sattr in m.group(1).split(';'):
> +                    if sattr:
> +                        attr = mapcolor(int(sattr), attr)
> +                _kernel32.SetConsoleTextAttribute(stdout, attr)
> +                orig(m.group(2), **opts)
> +                m = re.match(ansire, m.group(3))
> +        finally:
> +            # Explicitly reset original attributes
> +            _kernel32.SetConsoleTextAttribute(stdout, origattr)

I wonder if some parts of these Win32API stuff could be moved to win32.py, but
that wouldn't be simple.
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to