def max_width(*args, **kwargs):
    """Returns formatted text or context manager for textui:puts.

        >>> from clint.textui import puts, max_width
        >>> max_width('123 5678', 8)
        '123 5678'
        >>> max_width('123 5678', 7)
        '123 \n5678'
        >>> with max_width(7):
        ...     puts('123 5678')
        '123 \n5678'
    """
    args = list(args)

    if not args:
        args.append(kwargs.get('string'))
        args.append(kwargs.get('cols'))
        args.append(kwargs.get('separator'))
    elif len(args) == 1:
        args.append(kwargs.get('cols'))
        args.append(kwargs.get('separator'))
    elif len(args) == 2:
        args.append(kwargs.get('separator'))

    string, cols, separator = args
    if separator is None:
        separator = '\n'  # default value
    if cols is None:
        # cols should be specified vitally
        # because string can be specified at textui:puts function
        string, cols = cols, string

    if string is None:
        MAX_WIDTHS.append((cols, separator))
        return _max_width_context()
    else:
        return _max_width_formatter(string, cols, separator)
Returns formatted text or context manager for textui:puts.

        >>> from clint.textui import puts, max_width
        >>> max_width('123 5678', 8)
        '123 5678'
        >>> max_width('123 5678', 7)
        '123 \n5678'
        >>> with max_width(7):
        ...     puts('123 5678')
        '123 \n5678'