How to use the khal.terminal.colored function in khal

To help you get started, we’ve selected a few khal 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 pimutils / khal / khal / cli.py View on Github external
if format is None:
            format = ctx.obj['conf']['view']['event_format']
        try:
            collection = build_collection(
                ctx.obj['conf'],
                multi_calendar_select(ctx, include_calendar, exclude_calendar)
            )
            events = sorted(collection.search(search_string))
            event_column = list()
            term_width, _ = get_terminal_size()
            now = dt.datetime.now()
            env = {"calendars": ctx.obj['conf']['calendars']}
            for event in events:
                desc = textwrap.wrap(event.format(format, relative_to=now, env=env), term_width)
                event_column.extend(
                    [colored(d, event.color,
                             bold_for_light_color=ctx.obj['conf']['view']['bold_for_light_color'])
                     for d in desc]
                )
            click.echo('\n'.join(event_column))
        except FatalError as error:
            logger.debug(error, exc_info=True)
            logger.fatal(error)
            sys.exit(1)
github pimutils / khal / khal / calendar_display.py View on Github external
"""
    dstr = str(day.day).rjust(2)
    if color == '':
        dcolors = list(set(
            map(lambda x: get_calendar_color(x, default_color, collection), calendars)
        ))
        if len(dcolors) > 1:
            if multiple == '':
                if hmethod == "foreground" or hmethod == "fg":
                    return colored(dstr[:1], fg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
                else:
                    return colored(dstr[:1], bg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
            else:
                dcolor = multiple
        else:
            dcolor = dcolors[0] or default_color
    else:
        dcolor = color
    if dcolor != '':
        if hmethod == "foreground" or hmethod == "fg":
            return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
        else:
            return colored(dstr, bg=dcolor, bold_for_light_color=bold_for_light_color)
    return dstr
github pimutils / khal / khal / calendar_display.py View on Github external
colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
                else:
                    return colored(dstr[:1], bg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
            else:
                dcolor = multiple
        else:
            dcolor = dcolors[0] or default_color
    else:
        dcolor = color
    if dcolor != '':
        if hmethod == "foreground" or hmethod == "fg":
            return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
        else:
            return colored(dstr, bg=dcolor, bold_for_light_color=bold_for_light_color)
    return dstr
github pimutils / khal / khal / calendar_display.py View on Github external
def str_highlight_day(
        day, calendars, hmethod, default_color, multiple, color, bold_for_light_color, collection):
    """returns a string with day highlighted according to configuration
    """
    dstr = str(day.day).rjust(2)
    if color == '':
        dcolors = list(set(
            map(lambda x: get_calendar_color(x, default_color, collection), calendars)
        ))
        if len(dcolors) > 1:
            if multiple == '':
                if hmethod == "foreground" or hmethod == "fg":
                    return colored(dstr[:1], fg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
                else:
                    return colored(dstr[:1], bg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
            else:
                dcolor = multiple
        else:
            dcolor = dcolors[0] or default_color
    else:
        dcolor = color
    if dcolor != '':
        if hmethod == "foreground" or hmethod == "fg":
            return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
        else:
github pimutils / khal / khal / calendar_display.py View on Github external
def str_highlight_day(
        day, calendars, hmethod, default_color, multiple, color, bold_for_light_color, collection):
    """returns a string with day highlighted according to configuration
    """
    dstr = str(day.day).rjust(2)
    if color == '':
        dcolors = list(set(
            map(lambda x: get_calendar_color(x, default_color, collection), calendars)
        ))
        if len(dcolors) > 1:
            if multiple == '':
                if hmethod == "foreground" or hmethod == "fg":
                    return colored(dstr[:1], fg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
                else:
                    return colored(dstr[:1], bg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
            else:
                dcolor = multiple
        else:
            dcolor = dcolors[0] or default_color
    else:
        dcolor = color
    if dcolor != '':
        if hmethod == "foreground" or hmethod == "fg":
            return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
        else:
            return colored(dstr, bg=dcolor, bold_for_light_color=bold_for_light_color)
    return dstr
github pimutils / khal / khal / calendar_display.py View on Github external
day, calendars, hmethod, default_color, multiple, color, bold_for_light_color, collection):
    """returns a string with day highlighted according to configuration
    """
    dstr = str(day.day).rjust(2)
    if color == '':
        dcolors = list(set(
            map(lambda x: get_calendar_color(x, default_color, collection), calendars)
        ))
        if len(dcolors) > 1:
            if multiple == '':
                if hmethod == "foreground" or hmethod == "fg":
                    return colored(dstr[:1], fg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], fg=dcolors[1], bold_for_light_color=bold_for_light_color)
                else:
                    return colored(dstr[:1], bg=dcolors[0],
                                   bold_for_light_color=bold_for_light_color) + \
                        colored(dstr[1:], bg=dcolors[1], bold_for_light_color=bold_for_light_color)
            else:
                dcolor = multiple
        else:
            dcolor = dcolors[0] or default_color
    else:
        dcolor = color
    if dcolor != '':
        if hmethod == "foreground" or hmethod == "fg":
            return colored(dstr, fg=dcolor, bold_for_light_color=bold_for_light_color)
        else:
            return colored(dstr, bg=dcolor, bold_for_light_color=bold_for_light_color)
    return dstr