diff --git a/HISTORY.rst b/HISTORY.rst index 4d8b127c..2ab9f183 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,9 @@ PlatformIO 2.0 and allowed to `change default upload reset method `_ for Espressif development platform (`issue #444 `_) +* Allowed to force to output color ANSI-codes even if the output is a ``pipe`` + (not a ``tty``) + (`issue #465 `_) * Set 1Mb SPIFFS for Espressif boards by default (`issue #458 `_) * Fixed builder for mbed framework and ST STM32 platform diff --git a/docs/envvars.rst b/docs/envvars.rst index d2d4f244..f9f037da 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -39,6 +39,11 @@ Currently, PlatformIO uses it to disable prompts. In other words, ``CI=true`` automatically setup :envvar:`PLATFORMIO_SETTING_ENABLE_PROMPTS=false `. +.. envvar:: PLATFORMIO_FORCE_COLOR + +Force to output color ANSI-codes even if the output is a ``pipe`` (not a ``tty``). +The possible values are ``true`` and ``false``. Default is ``PLATFORMIO_FORCE_COLOR=false``. + .. envvar:: PLATFORMIO_HOME_DIR Allows to override :ref:`projectconf` option :ref:`projectconf_pio_home_dir`. diff --git a/platformio/__init__.py b/platformio/__init__.py index dc5a8938..abb8deef 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -14,7 +14,7 @@ import sys -VERSION = (2, 7, "2.dev4") +VERSION = (2, 7, "2.dev5") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/__main__.py b/platformio/__main__.py index a5670711..8fe2359f 100644 --- a/platformio/__main__.py +++ b/platformio/__main__.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from os import listdir +from os import getenv, listdir from os.path import join from platform import system from sys import exit as sys_exit @@ -94,6 +94,14 @@ def main(): "Invalid installation of Python `requests` package`. See " "< https://github.com/platformio/platformio/issues/252 >") + # handle PLATFORMIO_FORCE_COLOR + if str(getenv("PLATFORMIO_FORCE_COLOR", "")).lower() == "true": + try: + # pylint: disable=protected-access + click._compat.isatty = lambda stream: True + except: # pylint: disable=bare-except + pass + cli(None, None, None) except Exception as e: # pylint: disable=W0703 if not isinstance(e, exception.ReturnErrorCode):