Sign in

    bobzhang/rich/color does not have a README file

    ColorParseError

    pub suberror ColorParseError {
    ColorParseError(String)
    } derive(
    Debug
    )

    Error raised when a color definition can not be parsed.

    Color

    pub(all) struct Color {
    name : String
    type_ : ColorType
    number : Int?
    triplet : ColorTriplet?
    } derive(Eq, Hash,
    Debug
    )

    Terminal color definition.
    impl Show for Color

    Color::default

    fn Color::default() -> Color

    A Color instance representing the default color.

    Color::downgrade

    fn Color::downgrade(self : Color, system : ColorSystem) -> Color

    Downgrade a color system to a system with fewer colors.

    Color::from_ansi

    fn Color::from_ansi(number : Int) -> Color

    Create a Color from its 8-bit ANSI number.

    Color::from_rgb

    fn Color::from_rgb(red : Double, green : Double, blue : Double) -> Color

    Create a truecolor from three color components in the range 0–255. Components are truncated towards zero like Python's int().

    Color::from_triplet

    fn Color::from_triplet(triplet : ColorTriplet) -> Color

    Create a truecolor RGB color from a triplet of values.

    Color::get_ansi_codes

    fn Color::get_ansi_codes(self : Color, foreground? : Bool) -> Array[String]

    Get the ANSI escape codes for this color.

    Color::get_truecolor

    fn Color::get_truecolor(self : Color, theme? : TerminalTheme, foreground? : Bool) -> ColorTriplet

    Get an equivalent color triplet for this color.

    Color::is_default

    fn Color::is_default(self : Color) -> Bool

    Check if the color is a default color.

    Color::is_system_defined

    fn Color::is_system_defined(self : Color) -> Bool

    Check if the color is ultimately defined by the system.

    Color::new

    fn Color::new(name : String, type_ : ColorType, number? : Int, triplet? : ColorTriplet) -> Color

    Color::parse

    fn Color::parse(color : String) -> Color raise ColorParseError

    Parse a color definition: a color name ("red", "bright_blue", "grey50"), "default", "#rrggbb", "color(N)" or "rgb(r,g,b)".

    Color::system

    fn Color::system(self : Color) -> ColorSystem

    The native color system for this color.

    ColorSystem

    pub(all) enum ColorSystem {
    Standard
    EightBit
    Truecolor
    Windows
    } derive(Compare, Eq, Hash,
    Debug
    )

    One of the color systems supported by terminals.
    impl Show for ColorSystem

    ColorSystem::to_int

    fn ColorSystem::to_int(self : ColorSystem) -> Int

    Upstream int(ColorSystem.X).

    ColorTriplet

    pub(all) struct ColorTriplet {
    red : Int
    green : Int
    blue : Int
    } derive(Compare, Eq, Hash,
    Debug
    )

    The red, green, and blue components of a color (0–255 each).

    ColorTriplet::hex

    fn ColorTriplet::hex(self : ColorTriplet) -> String

    The color in CSS style, e.g. "#ff0000".

    ColorTriplet::new

    fn ColorTriplet::new(red : Int, green : Int, blue : Int) -> ColorTriplet

    ColorTriplet::normalized

    fn ColorTriplet::normalized(self : ColorTriplet) -> (Double, Double, Double)

    Components as floats between 0 and 1.

    ColorTriplet::rgb

    fn ColorTriplet::rgb(self : ColorTriplet) -> String

    The color in RGB format, e.g. "rgb(100,23,255)".

    ColorType

    pub(all) enum ColorType {
    Default
    Standard
    EightBit
    Truecolor
    Windows
    } derive(Compare, Eq, Hash,
    Debug
    )

    Type of color stored in Color.
    impl Show for ColorType

    ColorType::name

    fn ColorType::name(self : ColorType) -> String

    Upstream ColorType.X.name, e.g. "EIGHT_BIT".

    ColorType::to_int

    fn ColorType::to_int(self : ColorType) -> Int

    Palette

    pub struct Palette {
    // private fields
    }

    A palette of available colors.

    Palette::at

    fn Palette::at(self : Palette, number : Int) -> ColorTriplet

    Palette::colors

    fn Palette::colors(self : Palette) -> Array[(Int, Int, Int)]

    Palette::length

    fn Palette::length(self : Palette) -> Int

    Palette::match_color

    fn Palette::match_color(self : Palette, color : ColorTriplet) -> Int

    Find a color from a palette that most closely matches a given color.

    Palette::new

    fn Palette::new(colors : Array[(Int, Int, Int)]) -> Palette

    TerminalTheme

    pub struct TerminalTheme {
    background_color : ColorTriplet
    foreground_color : ColorTriplet
    ansi_colors : Palette
    }

    A color theme used when exporting console content.

    TerminalTheme::new

    fn TerminalTheme::new(background : (Int, Int, Int), foreground : (Int, Int, Int), normal : Array[(Int, Int, Int)], bright? : Array[(Int, Int, Int)]) -> TerminalTheme

    normal holds 8 normal intensity colors; bright the 8 bright ones (or normal again when omitted).

    ansi_color_name_list

    fn ansi_color_name_list() -> Array[(String, Int)]

    All named colors (as accepted by Color::parse) and their numbers, in upstream order.

    blend_rgb

    fn blend_rgb(color1 : ColorTriplet, color2 : ColorTriplet, cross_fade? : Double) -> ColorTriplet

    Blend one RGB color in to another.

    default_terminal_theme

    let default_terminal_theme : TerminalTheme

    dimmed_monokai

    let dimmed_monokai : TerminalTheme

    eight_bit_palette

    let eight_bit_palette : Palette

    monokai

    let monokai : TerminalTheme

    night_owlish

    let night_owlish : TerminalTheme

    parse_rgb_hex

    fn parse_rgb_hex(hex_color : String) -> ColorTriplet

    Parse six hex characters in to an RGB triplet.

    Aborts on invalid hex digits (upstream raises ValueError).

    py_round

    fn py_round(x : Double) -> Int

    Python's round() (round half to even) for a non-negative double.

    rgb_to_hls

    fn rgb_to_hls(r : Double, g : Double, b : Double) -> (Double, Double, Double)

    Python's colorsys.rgb_to_hls.

    standard_palette

    let standard_palette : Palette

    svg_export_theme

    let svg_export_theme : TerminalTheme

    unicode_decimal_value

    fn unicode_decimal_value(c : Char) -> Int?

    The value of a Unicode decimal digit (category Nd), as accepted by Python's int(), e.g. '٣' → Some(3).

    windows_palette

    let windows_palette : Palette