Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Smarter colorization and better support for native terminals on Windows #277

Merged
merged 2 commits into from Apr 10, 2019

Commits on Apr 10, 2019

  1. Introduce smarter coloring and --colorize option

    By default, do not colorize when stdout is not a tty. The --colorize option,
    with possible values 'auto', 'always', and 'never' -- defaults to 'auto' when
    not specified, and registers as 'always' when specified without a value -- is
    similar to the --color option found in many well known *nix tools, with
    coreutils ls(1) being a notable example. (Our option is named --colorize since
    we already have a --colors option.) The old -C, --nocolor option is now a
    shortcut for --colorize=never.
    
    Limitation: due to limitations of Python argparse, specifically not being able
    to make the equal sign between a long option and its value mandatory, one might
    expect the following to work:
    
        googler --colorize google
    
    but it does not, due to "google" being parsed as an argument to --colorize. One
    has to write
    
        googler --colorize -- google
    
    instead.
    zmwangx committed Apr 10, 2019
    Configuration menu
    Copy the full SHA
    c9eb8c8 View commit details
    Browse the repository at this point in the history
  2. Enable ANSI color in cmd and PowerShell on Windows 10

    VT100 control sequences are supported in cmd and PowerShell starting from
    Windows 10 Anniversary Update, but only if the
    ENABLE_VIRTUAL_TERMINAL_PROCESSING flag is set on the screen buffer handle
    using SetConsoleMode.
    
    Setting this flag does not seem to negatively affect third party terminal
    emulators with native ANSI support such as ConEmu, so hopefully there's no
    regression.
    
    References:
    https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
    https://docs.microsoft.com/en-us/windows/console/setconsolemode
    
    Credits:
    jarun#275
    tartley/colorama#139
    zmwangx committed Apr 10, 2019
    Configuration menu
    Copy the full SHA
    d2b579f View commit details
    Browse the repository at this point in the history