# Path: catkin_tools/terminal_color.py
# def ansi(key):
#     """Returns the escape sequence for a given ansi color key"""
#     global _ansi
#     return _ansi[key]
# 
# Path: catkin_tools/common.py
# def remove_ansi_escape(string):
#     """Removes any ansi escape sequences from a string and returns it"""
#     global _ansi_escape
#     return _ansi_escape.sub('', string)
# 
# Path: catkin_tools/common.py
# def wide_log(msg, **kwargs):
#     """Prints a message to the screen, filling the remainder of the screen with spaces
# 
#     This is useful for printing lines which will completely overwrite previous
#     content printed with a carriage return at the end.
# 
#     If the message is wider than the terminal, then no filling is done.
# 
#     The wide logging can be disabled with :py:func:`disable_wide_log`, in order
#     to prevent queries to the terminal width, which is useful when output is
#     not to a terminal, like when being used with Continuous Integration.
# 
#     Truncating and right hand side messages are disabled when wide_log is
#     disabled as well.
# 
#     When a right hand side message is given, it implies truncate is True.
# 
#     :param msg: message to be printed
#     :type msg: str
#     :param rhs: message to print at the right hand side of the screen
#     :type rhs: str
#     :param truncate: If True, messages wider the then terminal will be truncated
#     :type truncate: bool
#     """
#     try:
#         global wide_log_fn
#         wide_log_fn(msg, **kwargs)
#     except IOError:
#         # This happens when someone ctrl-c's during a log message
#         pass


import os
from catkin_tools.terminal_color import ansi
from catkin_tools.common import remove_ansi_escape
from catkin_tools.common import wide_log
from .color import clr
        self.log_dir = log_dir
        self.quiet = quiet
        self.interleave = interleave_output
        self.color = color
        self.max_package_name_length = max_package_name_length
        self.prefix_output = prefix_output
        self.__command_log = {}

    def job_started(self, package):
        self.__command_log[package] = FileBackedLogCache(package, self.log_dir, self.color)
        wide_log(clr("Starting ==> {package}").format(**locals()))

    def command_started(self, package, cmd, location):
        if package not in self.__command_log:
            raise RuntimeError("Command started received for package '{0}' before package job started: '{1}' in '{2}'"
                               .format(package, cmd.pretty, location))
        msg = clr("[{package}] ==> '{cmd.cmd_str}' in '{location}'").format(**locals())
        self.__command_log[package].start_command(cmd, msg)
        if not self.quiet and self.interleave:
            wide_log(msg)

    def command_log(self, package, msg):
        if package not in self.__command_log:
            raise RuntimeError("Command log received for package '{0}' before package job started: '{1}'"
                               .format(package, msg))
        if self.__command_log[package].current_cmd is None:
            raise RuntimeError("Command log received for package '{0}' before command started: '{1}'"
                               .format(package, msg))
        self.__command_log[package].append(msg)
        if not self.color:

# Path: catkin_tools/terminal_color.py
# def ansi(key):
#     """Returns the escape sequence for a given ansi color key"""
#     global _ansi
#     return _ansi[key]
# 
# Path: catkin_tools/common.py
# def remove_ansi_escape(string):
#     """Removes any ansi escape sequences from a string and returns it"""
#     global _ansi_escape
#     return _ansi_escape.sub('', string)
# 
# Path: catkin_tools/common.py
# def wide_log(msg, **kwargs):
#     """Prints a message to the screen, filling the remainder of the screen with spaces
# 
#     This is useful for printing lines which will completely overwrite previous
#     content printed with a carriage return at the end.
# 
#     If the message is wider than the terminal, then no filling is done.
# 
#     The wide logging can be disabled with :py:func:`disable_wide_log`, in order
#     to prevent queries to the terminal width, which is useful when output is
#     not to a terminal, like when being used with Continuous Integration.
# 
#     Truncating and right hand side messages are disabled when wide_log is
#     disabled as well.
# 
#     When a right hand side message is given, it implies truncate is True.
# 
#     :param msg: message to be printed
#     :type msg: str
#     :param rhs: message to print at the right hand side of the screen
#     :type rhs: str
#     :param truncate: If True, messages wider the then terminal will be truncated
#     :type truncate: bool
#     """
#     try:
#         global wide_log_fn
#         wide_log_fn(msg, **kwargs)
#     except IOError:
#         # This happens when someone ctrl-c's during a log message
#         pass


# Path: catkin_tools/jobs/output.py
import os
from catkin_tools.terminal_color import ansi
from catkin_tools.common import remove_ansi_escape
from catkin_tools.common import wide_log
from .color import clr

        self.log_dir = log_dir
        self.quiet = quiet
        self.interleave = interleave_output
        self.color = color
        self.max_package_name_length = max_package_name_length
        self.prefix_output = prefix_output
        self.__command_log = {}

    def job_started(self, package):
        self.__command_log[package] = FileBackedLogCache(package, self.log_dir, self.color)
        wide_log(clr("Starting ==> {package}").format(**locals()))

    def command_started(self, package, cmd, location):
        if package not in self.__command_log:
            raise RuntimeError("Command started received for package '{0}' before package job started: '{1}' in '{2}'"
                               .format(package, cmd.pretty, location))
        msg = clr("[{package}] ==> '{cmd.cmd_str}' in '{location}'").format(**locals())
        self.__command_log[package].start_command(cmd, msg)
        if not self.quiet and self.interleave:
            wide_log(msg)

    def command_log(self, package, msg):
        if package not in self.__command_log:
            raise RuntimeError("Command log received for package '{0}' before package job started: '{1}'"
                               .format(package, msg))
        if self.__command_log[package].current_cmd is None:
            raise RuntimeError("Command log received for package '{0}' before command started: '{1}'"
                               .format(package, msg))
        self.__command_log[package].append(msg)
        if not self.color:

            msg = remove_ansi_escape(msg)