Пример #1
0
def get_color_by_hex(
    hex_code: str,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by hexadecimal (web) code.

    The hexadecimal code must be specified without the hash (#) prefix
    and match the regular expression: ^(?:[0-9a-fA-F]{3}){1,2}$

    Usage examples:

        color hex FFFFFF
        color hex FFF
        color hex FFFFFF --shades --json --all --units

    :param hex_code: Hex color code without the hash (#) prefix.
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    hex_code = normalize_hex_code(hex_code)
    print_color(config, Color(*hex_to_rgb(hex_code)))
Пример #2
0
 def function(
     json: Optional[bool] = None,
     all: bool = False,
     units: Optional[bool] = None,
 ):
     config = load_config_file()
     config.set_flags(
         json=validate_boolean_flag(json),
         all=validate_boolean_flag(all),
         units=validate_boolean_flag(units),
     )
     print_colors(config, [Color(*rgb) for rgb in palette_to_rgbs(name)])
Пример #3
0
 def function(
     shades: int = 0,
     json: Optional[bool] = None,
     all: bool = False,
     units: Optional[bool] = None,
 ):
     config = load_config_file()
     config.set_flags(
         shades=validate_shades_count(shades),
         json=validate_boolean_flag(json),
         all=validate_boolean_flag(all),
         units=validate_boolean_flag(units),
     )
     print_color(config, Color(*name_to_rgb(name)))
Пример #4
0
def show_config(sort: bool = True, indent: int = 2):
    """Display Colorpedia configuration.

    Configuration file is located at ~/.config/colorpedia/config.json.

    :param sort: Sort JSON keys (default: True).
    :param indent: JSON indent width (default: 2).
    """
    if not CONFIG_FILE.exists():
        print('Configuration not initialized. Run "color config init".')
    else:
        config = load_config_file()
        validate_boolean_flag(sort)
        validate_indent_width(indent)
        print_config(config, sort=sort, indent=indent)
Пример #5
0
def get_color_by_cmyk(
    c: float,
    m: float,
    y: float,
    k: float,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by CMYK (Cyan Magenta Yellow Black) values.

    CMYK is a subtractive color model used in color printing. It refers
    to the four ink plates used in color printing: cyan, magenta, yellow,
    and key (black). Values must be between 0.0 and 100.0 inclusive.

    Usage examples:

        color cmyk 100 100 100 100
        color cmyk 0 0 0 0
        color cmyk 10 20 30 40 --shades --json --all --units

    :param c: Cyan % (0.0 to 100.0 inclusive).
    :param m: Magenta % (0.0 to 100.0 inclusive).
    :param y: Yellow % (0.0 to 100.0 inclusive).
    :param k: Black/Key % (0.0 to 100.0 inclusive).
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    c = normalize_percent_value(c)
    m = normalize_percent_value(m)
    y = normalize_percent_value(y)
    k = normalize_percent_value(k)
    print_color(config, Color(*cmyk_to_rgb(c, m, y, k)))
Пример #6
0
def get_color_by_hsv(
    h: float,
    s: float,
    v: float,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by HSV (Hue Saturation Brightness/Value) values.

    Hue is a point on the color wheel from 0 to 360 where 0 is red,
    120 is green, and 240 is blue. Saturation is a percentage value
    where 0% means faded, and 100% means full color. Brightness (or
    value) is a percentage value where 0% is black and 100% reveals
    the most color.

    Usage examples:

        color hsv 360 100 100
        color hsv 0 0 0
        color hsv 10 20 30 --shades --json --all --units

    :param h: Hue in degree angle (0.0 to 360.0 inclusive).
    :param s: Saturation % (0.0 to 100.0 inclusive).
    :param v: Brightness/Value % (0.0 to 100.0 inclusive).
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    h = normalize_degree_angle(h)
    s = normalize_percent_value(s)
    v = normalize_percent_value(v)
    print_color(config, Color(*hsv_to_rgb(h, s, v)))
Пример #7
0
def get_color_by_rgb(
    r: int,
    g: int,
    b: int,
    shades: int = 0,
    json: Optional[bool] = None,
    all: bool = False,
    units: Optional[bool] = None,
):
    """Look up colors by RGB (Red Green Blue) values.

    RGB is an additive color model where red, green, and blue lights are
    superimposed together to yield shades of colors. The RGB values must
    be integers between 0 to 255.

    Usage examples:

        color rgb 255 255 255
        color rgb 0 0 0
        color rgb 10 20 30 --shades --json --all --units

    :param r: Red (0 to 255 inclusive).
    :param g: Green (0 to 255 inclusive).
    :param b: Blue (0 to 255 inclusive).
    :param shades: Display different shades of the specified color.
    :param json: Display in JSON format.
    :param all: Bypass user configuration and display all keys.
    :param units: Bypass user configuration and display units.
    """
    config = load_config_file()
    config.set_flags(
        shades=validate_shades_count(shades),
        json=validate_boolean_flag(json),
        all=validate_boolean_flag(all),
        units=validate_boolean_flag(units),
    )
    r = validate_rgb_value(r)
    g = validate_rgb_value(g)
    b = validate_rgb_value(b)
    print_color(config, Color(r, g, b))