How to use the colored.ColoredString function in colored

To help you get started, we’ve selected a few colored 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 shrekwang / druid-monitor / druid_common.py View on Github external
for item in maxlens:
        headline = headline + "+" + ("-"*item) + "--"
    headline = headline+ "+" 

    formated_rows = []
    tail_split = False
    for rowindex,row in enumerate(rows):
        line = ""
        # if row is empty,than make a split line
        if (row == []) :
            formated_rows.append(headline)
            if rowindex == len(rows) - 1 :
                tail_split = True
        else :
            for index,field in enumerate(row):
                if isinstance(field,ColoredString) :
                    line = line+ "| " + field.ljust(maxlens[index] + 1)
                else :
                    field = str(field)
                    line = line+ "| " + field.ljust(maxlens[index] + 1)
            if rowindex == 1 : formated_rows.append(headline)
            formated_rows.append(line + "|")
    if not tail_split :
        formated_rows.append(headline)
    return formated_rows
github shrekwang / druid-monitor / druid_common.py View on Github external
def format_rows(rows):
    maxlens = [0] * len(rows[0])
    for row in rows:
        for index,field in enumerate(row) :
            if isinstance(field,ColoredString) :
                if (field.len()>maxlens[index]):
                    maxlens[index] = field.len()
            else :
                field = str(field)
                if (len(field)>maxlens[index]):
                    maxlens[index] = len(field)

    headline = ""
    for item in maxlens:
        headline = headline + "+" + ("-"*item) + "--"
    headline = headline+ "+" 

    formated_rows = []
    tail_split = False
    for rowindex,row in enumerate(rows):
        line = ""
github shrekwang / druid-monitor / druid_base.py View on Github external
def get_colored_value(color_info, value,name):
    color_conf = color_info.get(name)
    if color_conf == None :
        return value
    sorted_conf = sorted(color_conf.iteritems(),reverse=True)
    matched_color = None
    for limit,color in  sorted_conf :
        if value >= limit : 
            matched_color = color
            break
    if matched_color == None :
        return value
    return ColoredString(value,color)
github shrekwang / druid-monitor / druid_base.py View on Github external
str_value = ",".join([str(v) for v in value])
    color_conf = color_info.get(name)
    if color_conf == None :
        return str_value
    sorted_conf = sorted(color_conf.iteritems(),reverse=True)
    matched_color = None
    for i in range(len(value)-1,-1,-1):
        for limit,color in  sorted_conf :
            if i >= limit and value[i] > 0 :
                matched_color = color
                break
        if matched_color != None :
            break
    if matched_color == None :
        return str_value
    return ColoredString(str_value,color)