# Path: pkg/win32/Python27/Lib/site-packages/clint/textui/formatters.py
# def max_width(string, cols, separator='\n'):
#     """Returns a freshly formatted """
# 
#     is_color = isinstance(string, ColoredString)
# 
#     if is_color:
#         offset = 10
#         string_copy = string._new('')
#     else:
#         offset = 0
#         
#     stack = tsplit(string, NEWLINES)
# 
#     for i, substring in enumerate(stack):
#         stack[i] = substring.split()
# 
#     _stack = []
#     
#     for row in stack:
#         _row = ['',]
#         _row_i = 0
# 
#         for word in row:
#             if (len(_row[_row_i]) + len(word)) < (cols + offset):
#                 _row[_row_i] += word
#                 _row[_row_i] += ' '
#                 
#             elif len(word) > (cols - offset):
# 
#                 # ensure empty row
#                 if len(_row[_row_i]):
#                     _row.append('')
#                     _row_i += 1
# 
#                 chunks = schunk(word, (cols + offset))
#                 for i, chunk in enumerate(chunks):
#                     if not (i + 1) == len(chunks):
#                         _row[_row_i] += chunk
#                         _row.append('')
#                         _row_i += 1
#                     else:
#                         _row[_row_i] += chunk
#                         _row[_row_i] += ' '
#             else:
#                 _row.append('')
#                 _row_i += 1
#                 _row[_row_i] += word
#                 _row[_row_i] += ' '
# 
#         _row = map(str, _row)
#         _stack.append(separator.join(_row))
# 
#     _s = '\n'.join(_stack)
#     if is_color:
#         _s = string_copy._new(_s)
#     return _s
# 
# def min_width(string, cols, padding=' '):
#     """Returns given string with right padding."""
# 
#     is_color = isinstance(string, ColoredString)
# 
#     stack = tsplit(str(string), NEWLINES)
# 
#     for i, substring in enumerate(stack):
#         _sub = clean(substring).ljust((cols + 0), padding)
#         if is_color:
#             _sub = (_sub.replace(clean(substring), substring))
#         stack[i] = _sub
#         
#     return '\n'.join(stack)
# 
# Path: pkg/win32/Python27/Lib/site-packages/clint/utils.py
# def tsplit(string, delimiters):
#     """Behaves str.split but supports tuples of delimiters."""
# 
#     delimiters = tuple(delimiters)
#     stack = [string,]
# 
#     for delimiter in delimiters:
#         for i, substring in enumerate(stack):
#             substack = substring.split(delimiter)
#             stack.pop(i)
#             for j, _substring in enumerate(substack):
#                 stack.insert(i+j, _substring)
# 
#     return stack


from .formatters import max_width, min_width
from ..utils import tsplit
    from ctypes import windll, create_string_buffer
import sys
    import termios, fcntl, struct, sys
        import struct
    if _width:
        console_width = _width
    else:
        if not console_width:
            console_width = 80

    return console_width



def columns(*cols, **kwargs):

    columns = list(cols)

    cwidth = console_width(kwargs)

    _big_col = None
    _total_cols = 0


    for i, (string, width) in enumerate(cols):

        if width is not None:
            _total_cols += (width + 1)
            cols[i][0] = max_width(string, width).split('\n')
        else:
            _big_col = i

    if _big_col:
        cols[_big_col][1] = (cwidth - _total_cols) - len(cols)

# Path: pkg/win32/Python27/Lib/site-packages/clint/textui/formatters.py
# def max_width(string, cols, separator='\n'):
#     """Returns a freshly formatted """
# 
#     is_color = isinstance(string, ColoredString)
# 
#     if is_color:
#         offset = 10
#         string_copy = string._new('')
#     else:
#         offset = 0
#         
#     stack = tsplit(string, NEWLINES)
# 
#     for i, substring in enumerate(stack):
#         stack[i] = substring.split()
# 
#     _stack = []
#     
#     for row in stack:
#         _row = ['',]
#         _row_i = 0
# 
#         for word in row:
#             if (len(_row[_row_i]) + len(word)) < (cols + offset):
#                 _row[_row_i] += word
#                 _row[_row_i] += ' '
#                 
#             elif len(word) > (cols - offset):
# 
#                 # ensure empty row
#                 if len(_row[_row_i]):
#                     _row.append('')
#                     _row_i += 1
# 
#                 chunks = schunk(word, (cols + offset))
#                 for i, chunk in enumerate(chunks):
#                     if not (i + 1) == len(chunks):
#                         _row[_row_i] += chunk
#                         _row.append('')
#                         _row_i += 1
#                     else:
#                         _row[_row_i] += chunk
#                         _row[_row_i] += ' '
#             else:
#                 _row.append('')
#                 _row_i += 1
#                 _row[_row_i] += word
#                 _row[_row_i] += ' '
# 
#         _row = map(str, _row)
#         _stack.append(separator.join(_row))
# 
#     _s = '\n'.join(_stack)
#     if is_color:
#         _s = string_copy._new(_s)
#     return _s
# 
# def min_width(string, cols, padding=' '):
#     """Returns given string with right padding."""
# 
#     is_color = isinstance(string, ColoredString)
# 
#     stack = tsplit(str(string), NEWLINES)
# 
#     for i, substring in enumerate(stack):
#         _sub = clean(substring).ljust((cols + 0), padding)
#         if is_color:
#             _sub = (_sub.replace(clean(substring), substring))
#         stack[i] = _sub
#         
#     return '\n'.join(stack)
# 
# Path: pkg/win32/Python27/Lib/site-packages/clint/utils.py
# def tsplit(string, delimiters):
#     """Behaves str.split but supports tuples of delimiters."""
# 
#     delimiters = tuple(delimiters)
#     stack = [string,]
# 
#     for delimiter in delimiters:
#         for i, substring in enumerate(stack):
#             substack = substring.split(delimiter)
#             stack.pop(i)
#             for j, _substring in enumerate(substack):
#                 stack.insert(i+j, _substring)
# 
#     return stack


# Path: pkg/win32/Python27/Lib/site-packages/clint/textui/cols.py
from .formatters import max_width, min_width
from ..utils import tsplit
    from ctypes import windll, create_string_buffer
import sys
    import termios, fcntl, struct, sys
        import struct

    if _width:
        console_width = _width
    else:
        if not console_width:
            console_width = 80

    return console_width



def columns(*cols, **kwargs):

    columns = list(cols)

    cwidth = console_width(kwargs)

    _big_col = None
    _total_cols = 0


    for i, (string, width) in enumerate(cols):

        if width is not None:
            _total_cols += (width + 1)
            cols[i][0] = max_width(string, width).split('\n')
        else:
            _big_col = i

    if _big_col:
        cols[_big_col][1] = (cwidth - _total_cols) - len(cols)

        cols[_big_col][0] = max_width(cols[_big_col][0], cols[_big_col][1]).split('\n')