import enum
import subprocess

from blessings import Terminal


TERM = Terminal()


class Color(enum.Enum):

    none = ""
    reset = TERM.normal
    black = TERM.black
    red = TERM.red
    green = TERM.green
    yellow = TERM.yellow
    blue = TERM.blue
    magenta = TERM.magenta
    cyan = TERM.cyan
    white = TERM.white

    def __str__(self):
        return self.value


class StreamOptions(enum.Enum):

    """Choices for stream handling."""

    capture = "capture"
    hide = "hide"
    none = "none"

    @property
    def option(self):
        return {
            "capture": subprocess.PIPE,
            "hide": subprocess.DEVNULL,
            "none": None,
        }[self.value]

import enum
import os
import subprocess
import sys

from blessings import Terminal

from .misc import isatty


if not (isatty(sys.stdout) and os.getenv("TERM")):

    class Terminal:
        def __getattr__(self, name):
            return ""


TERM = Terminal()


class Color(enum.Enum):

    none = ""
    reset = TERM.normal
    black = TERM.black
    red = TERM.red
    green = TERM.green
    yellow = TERM.yellow
    blue = TERM.blue
    magenta = TERM.magenta
    cyan = TERM.cyan
    white = TERM.white

    def __str__(self):
        return self.value


class StreamOptions(enum.Enum):

    """Choices for stream handling."""

    capture = "capture"
    hide = "hide"
    none = "none"

    @property
    def option(self):
        return {
            "capture": subprocess.PIPE,
            "hide": subprocess.DEVNULL,
            "none": None,
        }[self.value]

Check for TTY and TERM when setting up Color enum
Check for TTY and TERM when setting up Color enum

Amends 0d27649df30419a79ca063ee3e47073f2ba8330e

  import enum
+ import os
  import subprocess
+ import sys
  
  from blessings import Terminal
+ 
+ from .misc import isatty
+ 
+ 
+ if not (isatty(sys.stdout) and os.getenv("TERM")):
+ 
+     class Terminal:
+         def __getattr__(self, name):
+             return ""
  
  
  TERM = Terminal()
  
  
  class Color(enum.Enum):
  
      none = ""
      reset = TERM.normal
      black = TERM.black
      red = TERM.red
      green = TERM.green
      yellow = TERM.yellow
      blue = TERM.blue
      magenta = TERM.magenta
      cyan = TERM.cyan
      white = TERM.white
  
      def __str__(self):
          return self.value
  
  
  class StreamOptions(enum.Enum):
  
      """Choices for stream handling."""
  
      capture = "capture"
      hide = "hide"
      none = "none"
  
      @property
      def option(self):
          return {
              "capture": subprocess.PIPE,
              "hide": subprocess.DEVNULL,
              "none": None,
          }[self.value]
  
Check for TTY and TERM when setting up Color enum
## Code Before:
import enum
import subprocess

from blessings import Terminal


TERM = Terminal()


class Color(enum.Enum):

    none = ""
    reset = TERM.normal
    black = TERM.black
    red = TERM.red
    green = TERM.green
    yellow = TERM.yellow
    blue = TERM.blue
    magenta = TERM.magenta
    cyan = TERM.cyan
    white = TERM.white

    def __str__(self):
        return self.value


class StreamOptions(enum.Enum):

    """Choices for stream handling."""

    capture = "capture"
    hide = "hide"
    none = "none"

    @property
    def option(self):
        return {
            "capture": subprocess.PIPE,
            "hide": subprocess.DEVNULL,
            "none": None,
        }[self.value]

## Instruction:
Check for TTY and TERM when setting up Color enum
## Code After:
import enum
import os
import subprocess
import sys

from blessings import Terminal

from .misc import isatty


if not (isatty(sys.stdout) and os.getenv("TERM")):

    class Terminal:
        def __getattr__(self, name):
            return ""


TERM = Terminal()


class Color(enum.Enum):

    none = ""
    reset = TERM.normal
    black = TERM.black
    red = TERM.red
    green = TERM.green
    yellow = TERM.yellow
    blue = TERM.blue
    magenta = TERM.magenta
    cyan = TERM.cyan
    white = TERM.white

    def __str__(self):
        return self.value


class StreamOptions(enum.Enum):

    """Choices for stream handling."""

    capture = "capture"
    hide = "hide"
    none = "none"

    @property
    def option(self):
        return {
            "capture": subprocess.PIPE,
            "hide": subprocess.DEVNULL,
            "none": None,
        }[self.value]
