# Path: src/rosrepo/util.py
# def isatty(fd):
#     return hasattr(fd, "isatty") and fd.isatty()
# 
# def get_terminal_size():
#     global _cached_terminal_size
#     if _cached_terminal_size is not None:
#         return _cached_terminal_size
#     try:
#         with open(os.ctermid(), "rb") as f:
#             cr = struct.unpack('hh', fcntl.ioctl(f.fileno(), termios.TIOCGWINSZ, '1234'))
#     except (IOError, struct.error):
#         raise OSError("Cannot determine terminal size")
#     _cached_terminal_size = int(cr[1]), int(cr[0])
#     return _cached_terminal_size
# 
# class UserError(RuntimeError):
#     pass
# 
# Path: src/rosrepo/terminal_color.py
# def fmt(msg, use_color=True, reset=True):
#     """Replaces color annotations with ansi escape sequences"""
#     global _ansi
#     msg = msg.replace('@!', '@{boldon}')
#     msg = msg.replace('@/', '@{italicson}')
#     msg = msg.replace('@_', '@{ulon}')
#     msg = msg.replace('@|', '@{reset}')
#     t = ColorTemplate(msg)
#     return t.safe_substitute(_ansi if use_color else _no_ansi) + (ansi('reset') if reset and use_color else '')


import sys
import re
from getpass import getpass
    from itertools import izip_longest as zip_longest
    from itertools import zip_longest
from .util import isatty, get_terminal_size, UserError
from .terminal_color import fmt as color_fmt
    from .terminal_color import ansi
        from .resolver import get_system_package_manager
    if width is None:
        return text
    if indent_first is None:
        indent_first = indent
    if indent_next is None:
        indent_next = indent
    result = []
    chunks = text.split("\n")
    sl = len(suffix)
    skip_blank = False
    for chunk in chunks:
        count = indent_first
        line = []
        empty_paragraph = True
        if indent_first > 0:
            line.append(" " * (indent_first - 1))
        for word in chunk.split(" "):
            L = len(remove_ansi(word))
            if L != 0 or not skip_blank:
                if L != 0:
                    skip_blank = False
                    empty_paragraph = False
                if count + L <= width - sl:
                    line.append(word)
                    count += L + 1
                else:
                    result.append(" ".join(line))
                    line = []
                    count = indent_next
                    if indent_next > 0:

# Path: src/rosrepo/util.py
# def isatty(fd):
#     return hasattr(fd, "isatty") and fd.isatty()
# 
# def get_terminal_size():
#     global _cached_terminal_size
#     if _cached_terminal_size is not None:
#         return _cached_terminal_size
#     try:
#         with open(os.ctermid(), "rb") as f:
#             cr = struct.unpack('hh', fcntl.ioctl(f.fileno(), termios.TIOCGWINSZ, '1234'))
#     except (IOError, struct.error):
#         raise OSError("Cannot determine terminal size")
#     _cached_terminal_size = int(cr[1]), int(cr[0])
#     return _cached_terminal_size
# 
# class UserError(RuntimeError):
#     pass
# 
# Path: src/rosrepo/terminal_color.py
# def fmt(msg, use_color=True, reset=True):
#     """Replaces color annotations with ansi escape sequences"""
#     global _ansi
#     msg = msg.replace('@!', '@{boldon}')
#     msg = msg.replace('@/', '@{italicson}')
#     msg = msg.replace('@_', '@{ulon}')
#     msg = msg.replace('@|', '@{reset}')
#     t = ColorTemplate(msg)
#     return t.safe_substitute(_ansi if use_color else _no_ansi) + (ansi('reset') if reset and use_color else '')


# Path: src/rosrepo/ui.py
import sys
import re
from getpass import getpass
    from itertools import izip_longest as zip_longest
    from itertools import zip_longest
from .util import isatty, get_terminal_size, UserError
from .terminal_color import fmt as color_fmt
    from .terminal_color import ansi
        from .resolver import get_system_package_manager

    if width is None:
        return text
    if indent_first is None:
        indent_first = indent
    if indent_next is None:
        indent_next = indent
    result = []
    chunks = text.split("\n")
    sl = len(suffix)
    skip_blank = False
    for chunk in chunks:
        count = indent_first
        line = []
        empty_paragraph = True
        if indent_first > 0:
            line.append(" " * (indent_first - 1))
        for word in chunk.split(" "):
            L = len(remove_ansi(word))
            if L != 0 or not skip_blank:
                if L != 0:
                    skip_blank = False
                    empty_paragraph = False
                if count + L <= width - sl:
                    line.append(word)
                    count += L + 1
                else:
                    result.append(" ".join(line))
                    line = []
                    count = indent_next
                    if indent_next > 0:

                        line.append(" " * (indent_next - 1))