How to use the lbuild.format.ColorWrapper.wrap function in lbuild

To help you get started, we’ve selected a few lbuild examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github modm-io / lbuild / lbuild / format.py View on Github external
def format_option_value(node, single_line=True):
    offset = -1
    if node.value is None:
        return (_cw("REQUIRED").wrap("error").wrap("bold"), offset, False)
    value = node.format_value()
    if single_line:
        value = value.replace("\n", " ")
    return (_cw(value).wrap("bold"), offset, True)
github modm-io / lbuild / lbuild / format.py View on Github external
def format_option_value(node, single_line=True):
    offset = -1
    if node.value is None:
        return (_cw("REQUIRED").wrap("error").wrap("bold"), offset, False)
    value = node.format_value()
    if single_line:
        value = value.replace("\n", " ")
    return (_cw(value).wrap("bold"), offset, True)
github modm-io / lbuild / lbuild / format.py View on Github external
def format_option_values(node, offset=0, single_line=True):
    values = node.format_values()
    if not single_line:
        if (offset + len(values)) > WIDTH:
            values = lbuild.filter.indent(lbuild.filter.wordwrap(values._string, WIDTH - offset),
                                          offset)
    return _cw(values).wrap("bold")
github modm-io / lbuild / lbuild / format.py View on Github external
def format_option_name(node, fullname=True):
    line = _cw(node.fullname if fullname else node.name).wrap(node).wrap("bold")
    if not node.is_default():
        line.wrap("underlined")
    return line
github modm-io / lbuild / lbuild / format.py View on Github external
def format_node(node, _, depth):
    class_name = _cw(node._type.name.capitalize())
    if node._type == node.Type.QUERY:
        class_name = class_name.wrap("underlined")

    name = _cw(node.name)
    if node._type == node.Type.REPOSITORY:
        name = _cw(node.name + " @ " + os.path.relpath(node._filepath))
    elif node._type == node.Type.OPTION:
        name = format_option_name(node, fullname=False)
    elif node._type in {node.Type.MODULE, node.Type.CONFIG}:
        name = _cw(node.fullname).wrap(node)
    elif node._type in {node.Type.QUERY, node.Type.COLLECTOR}:
        name = name.wrap("bold")
    if node._type in {node.Type.MODULE} and node._selected:
        name = name.wrap("underlined")

    descr = (class_name + _cw("(") + name + _cw(")")).wrap(node)

    offset = (node.depth - depth) * 4
    if node._type == node.Type.OPTION:
        descr += _cw(" = ")
        descr += format_option_value_description(node, offset=offset + len(descr), single_line=True)
    elif node._type == node.Type.COLLECTOR:
        descr += _cw(" in [")
        descr += format_option_values(node, offset=offset + len(descr), single_line=True)
        descr += _cw("]")
github modm-io / lbuild / lbuild / format.py View on Github external
def format_description(node, description):
    type_description = "  [{}]".format(node.class_name)
    output = [_cw(">> ") + _cw(node.description_name).wrap(node).wrap("bold") + _cw(type_description)]
    if description:
        description = description.strip()
        if len(description):
            output += [_cw(""), _cw(description)]

    if node.type == node.Type.OPTION:
        value = format_option_value(node, single_line=False)[0]
        values = format_option_values(node, offset=9, single_line=False)
        output += [_cw(""), _cw("Value: ") + value, _cw("Inputs: [") + values + _cw("]")]
    elif node.type == node.Type.COLLECTOR:
        values = format_option_values(node, offset=9, single_line=False)
        output += [_cw(""), _cw("Inputs: [") + values + _cw("]")]

    children = []
    # Print every node except the submodule, due to obvious recursion
    for ntype in (SHOW_NODES - {lbuild.node.BaseNode.Type.MODULE}):