Skip to content

ANSI Color support #101

@bitprophet

Description

@bitprophet

Description

  • Easy ability for both internal code and users to specify that (at least) full lines are a given ANSI color, if not words or arbitrary parts of output strings.
  • Global flag for disabling ANSI so that anyone who cares can turn it off (e.g. for someone scripting Fab itself, or whatever.)
  • Have various internal output calls make use of color so that e.g. "executing task X" lines are blue, running lines are...uh...yellow? green?, aborts/errors are red, and etc etc etc.

Be nice to leverage an external library for this instead of reinventing the wheel for the actual mechanics -- see what's out there.


ok, there is a handful of prior art:

General ideas:

  • Unary functions. print(red(blink("text") + "non blinking text")) etc. Seems easy enough to use, possibly some tricky spots in actual implementation -- check Term::ANSIColor (source) for ideas, maybe.
  • Dead simple mapping of the codes to constants/vars. (Possibly why nobody's done a lib for this -- it's dead simple.) E.g. print(RED + BLINK + "text" + CLEAR + RED + "non blinking text" + CLEAR).

ANSI code maps:

More notes:

  • there are apparently issues with this on Windows terminals, so may want/need an automatic if win32: env.disable_colors = True sort of thing.
  • have regular expressions that can trigger certain highlights, so that e.g. stdout/stderr matching "error messages" can be colored red or whatnot. I.e. "Permission denied" and the like. (see also: capistrano-colors)
  • if/when we do logging (Support full logging to file #57) it may make sense to turn colors off for the logs -- or make it an option in case anybody actually wants the ANSI codes in their log files.

Current status:

  • Implemented a barebones in-house lib as fabric.colors in Fabric 0.9.2
  • Not using it anywhere in Fabric core yet; only place I use it myself is in one seldom used task
  • May still be worth using a 3rd party lib if/when we get around to seriously leveraging color in Fabric itself
    • However, unless a bridge is provided to the current included colors module, doing so is likely to break backwards compatibility
    • So either write such a bridge, don't bother using a 3rd party lib, or wait to do so till 2.x

Originally submitted by Jeff Forcier (bitprophet) on 2009-11-11 at 05:46pm EST

Relations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions