# 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.package = package_name
        self.log_dir = log_dir
        self.color = color
        self.log_path = os.path.join(log_dir, self.package + '.log')
        if not os.path.exists(self.log_dir):
            os.makedirs(self.log_dir)
        self.file_handle = open(self.log_path, 'w')
        self.current_cmd = None
        self.last_command_line = None
        self.current_line = 0

    def start_command(self, cmd, msg):
        self.last_command_line = self.current_line
        self.current_cmd = cmd
        self.append(msg.rstrip('\n') + '\n')

    def append(self, msg):
        self.file_handle.write(msg)
        self.file_handle.flush()
        self.current_line += 1

    def finish_command(self, msg):
        self.current_cmd = None
        self.append(msg.rstrip('\n') + '\n')

    def close(self):
        self.file_handle.close()
        self.file_handle = None

    def print_last_command_log(self):

# 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.package = package_name
        self.log_dir = log_dir
        self.color = color
        self.log_path = os.path.join(log_dir, self.package + '.log')
        if not os.path.exists(self.log_dir):
            os.makedirs(self.log_dir)
        self.file_handle = open(self.log_path, 'w')
        self.current_cmd = None
        self.last_command_line = None
        self.current_line = 0

    def start_command(self, cmd, msg):
        self.last_command_line = self.current_line
        self.current_cmd = cmd
        self.append(msg.rstrip('\n') + '\n')

    def append(self, msg):
        self.file_handle.write(msg)
        self.file_handle.flush()
        self.current_line += 1

    def finish_command(self, msg):
        self.current_cmd = None
        self.append(msg.rstrip('\n') + '\n')

    def close(self):
        self.file_handle.close()
        self.file_handle = None

    def print_last_command_log(self):

        wide_log("")