Ejemplo n.º 1
0
def color_args_str(args, title=None, type='info'):
    s = cf.blue(f'\n{LINE}\n')
    if title:
        with cf.with_palette(PALETTE) as c:
            if type == 'error':
                s += f'{c.bold_error(title)}\n'
            elif type == 'success':
                s += f'{c.bold_success(title)}\n'
            else:
                s += f'{c.bold_info(title)}\n'
    for k in args:
        s += f'{cf.bold_violet(k)}: '
        s += f'{args[k]}\n'
    s += cf.blue(f'{LINE}\n')
    return s
def arguments_list_string(args, title=None, type='info'):
    s = f'\n{LONG_LINE}\n' if DISABLE_COLORS else cf.blue(f'\n{LONG_LINE}\n')
    if title:
        if DISABLE_COLORS:
            s += f'{title}\n'
        else:
            with cf.with_palette(PALETTE) as c:
                if type == 'error':
                    s += f'{c.bold_error(title)}\n'
                elif type == 'success':
                    s += f'{c.bold_success(title)}\n'
                else:
                    s += f'{c.bold_info(title)}\n'
    for k in args:
        s += f'{k}: ' if DISABLE_COLORS else f'{cf.bold_violet(k)}: '
        s += f'{args[k]}\n'
    s += f'{LONG_LINE}\n' if DISABLE_COLORS else cf.blue(f'{LONG_LINE}\n')
    return s
Ejemplo n.º 3
0
def test_change_color_palette():
    """
    Test changing the color palette in a with-block
    """
    NEW_COLOR_PALETTE = {
        'testColor': (0, 0, 0)
    }

    # updating existing color palette
    with colorful.with_updated_palette(NEW_COLOR_PALETTE) as c:
        # old and new colors should exist
        assert str(c.testColor) == '\033[30m'
        assert str(c.black) == '\033[30m'

    # set color palette and overwrite the old one
    with colorful.with_palette(NEW_COLOR_PALETTE) as c:
        assert str(c.testColor) == '\033[30m'

        with pytest.raises(ColorfulError) as exc:
            c.black('the color "black" was overwritten by the new palette')

        expected = ('the color "black" is unknown. '
                    'Use a color in your color palette (by default: X11 rgb.txt)')
        assert str(exc.value) == expected
Ejemplo n.º 4
0
print(cf.mint_on_snow('Wow, this is actually mint'))

# choose a predefined style
cf.use_style('solarized')
# print the official solarized colors
print(cf.yellow('yellow'), cf.orange('orange'),
    cf.red('red'), cf.magenta('magenta'),
    cf.violet('violet'), cf.blue('blue'),
    cf.cyan('cyan'), cf.green('green'))

# directly print with colors
cf.print('{c.bold_blue}Hello World{c.reset}')

# choose specific color mode for one block
with cf.with_8_ansi_colors() as c:
    print(c.bold_green('colorful is awesome!'))

# create and choose your own color palette
MY_COMPANY_PALETTE = {
    'companyOrange': '#f4b942',
    'companyBaige': '#e8dcc5'
}
with cf.with_palette(my_company_palette) as c:
    print(c.companyOrange_on_companyBaige('Thanks for choosing our product!'))

# use f-string (only Python >= 3.6)
print(f'{cf.bold}Hello World')

# support for chinese
print(cf.red('你好'))