Page MenuHomePhabricator

Provide Arcanist option to disable ANSI colours / Disable ANSI colours on Windows
Closed, DuplicatePublic

Description

On Windows machines, we see the following output when running Arcanist under normal CMD or Powershell (not Git Bash):

←[1mNAME←[m
      ←[1marc←[m - arcanist, a code review and revision management utility

←[1mSYNOPSIS←[m
      ←[1marc←[m ←[4mcommand←[m [←[4moptions←[m] [←[4margs←[m]
      This help file provides a detailed command reference.

←[1mCOMMAND REFERENCE←[m

      ←[1malias←[m
      ←[1malias←[m ←[4mcommand←[m
      ←[1malias←[m ←[4mcommand←[m ←[4mtarget←[m -- [←[4moptions←[m]

      ←[1mamend←[m [--revision ←[4mrevision_id←[m] [--show]

      ←[1manoid←[m

      ←[1mbackout←[m

      ←[1mbookmark←[m [←[4moptions←[m]
      ←[1mbookmark←[m ←[4mname←[m [←[4mstart←[m]

      ←[1mbranch←[m [←[4moptions←[m]
      ←[1mbranch←[m ←[4mname←[m [←[4mstart←[m]

      ←[1mbrowse←[m [←[4moptions←[m] ←[4mpath←[m ...
      ←[1mbrowse←[m [←[4moptions←[m] ←[4mobject←[m ...

      ←[1mcall-conduit←[m ←[4mmethod←[m

      ←[1mclose←[m ←[4mtask_id←[m [←[4moptions←[m]

      ←[1mclose-revision←[m [←[4moptions←[m] ←[4mrevision←[m

      ←[1mcommit←[m [--revision ←[4mrevision_id←[m] [--show]

ANSI colours should just be disabled on Windows with something like:

if (phutil_is_windows()) {
  PhutilConsoleFormatter::disableANSI(true);
}

(the ANSI colours don't work in Git Bash either, but you don't get the ANSI symbols)

Event Timeline

waynea assigned this task to epriestley.
waynea raised the priority of this task from to Needs Triage.
waynea updated the task description. (Show Details)
waynea added projects: Arcanist, libphutil.
waynea added a subscriber: waynea.

Here's the code we currently use:

if (self::$disableANSI === null) {
  $term = phutil_utf8_strtolower(getenv('TERM'));
  // ansicon enables ANSI support on Windows
  if (!$term && getenv('ANSICON')) {
    $term = 'ansi';
  }

  if (phutil_is_windows() && $term !== 'cygwin' && $term !== 'ansi') {
    self::$disableANSI = true;
  } else if (function_exists('posix_isatty') && !posix_isatty(STDOUT)) {
    self::$disableANSI = true;
  } else {
    self::$disableANSI = false;
  }
}

Do you have ANSICON defined, or TERM defined and set to either cygwin or ansi?

This comes up often enough that we should probably just disable it unconditionally, but we do make an attempt to be smart about this, and hypothetically it seems like it's reasonable for us to interpret, e.g., TERM=ansi as "ANSI escape sequences are OK".

In my windows term ("git-bash", term=cygwin), I get the ←[1m when normally invoking arc, but piping through cat (Which I would expect to drop all ansi-ing) makes the colors work:

pasted_file (85×532 px, 19 KB)

I have given up trying to understand it, but aliased arc to go through cat instead.

I believe the check for TERM should be fine. However, for reference, the Symfony framework uses a slightly simpler check - and will probably behave saner in most of these cases to do go wrong.

I'd also very much welcome an option to turn off colors, since they don't work very well in the Emacs shell.