Raw Display Attributes

class urwid.AttrSpec(fg: str, bg: str, colors: Literal[1, 16, 88, 256, 16777216] = 256)

Text attribute specification, encoding foreground and background colors and display settings.

Parameters:
  • fg –

    a string containing a comma-separated foreground color and settings

    Color values: ‘default’ (use the terminal’s default foreground), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’, ‘dark gray’, ‘light red’, ‘light green’, ‘yellow’, ‘light blue’, ‘light magenta’, ‘light cyan’, ‘white’

    High-color example values: ‘#009’ (0% red, 0% green, 60% red, like HTML colors) ‘#23facc’ (RRGGBB hex color code) ‘#fcc’ (100% red, 80% green, 80% blue) ‘g40’ (40% gray, decimal), ‘g#cc’ (80% gray, hex), ‘#000’, ‘g0’, ‘g#00’ (black), ‘#fff’, ‘g100’, ‘g#ff’ (white) ‘h8’ (color number 8), ‘h255’ (color number 255)

    Setting: ‘bold’, ‘italics’, ‘underline’, ‘blink’, ‘standout’, ‘strikethrough’, ‘faint’

    Some terminals use ‘bold’ for bright colors. Most terminals ignore the ‘blink’ setting. If the color is not given then ‘default’ will be assumed.

  • bg –

    a string containing the background color

    Color values: ‘default’ (use the terminal’s default background), ‘black’, ‘dark red’, ‘dark green’, ‘brown’, ‘dark blue’, ‘dark magenta’, ‘dark cyan’, ‘light gray’

    High-color exaples: see fg examples above

    An empty string will be treated the same as ‘default’.

  • colors – the maximum colors available for the specification

Raises:

AttrSpecError –

colors is not a supported palette size, or fg/bg need more colours than colors.

Valid values include: 1, 16, 88, 256, and 2**24. High-color values are only usable with 88, 256, or 2**24 colors. With 1 color only the foreground settings may be used.

>>> AttrSpec("dark red", "light gray", 16)
AttrSpec('dark red', 'light gray')
>>> AttrSpec("yellow, underline, bold", "dark blue")
AttrSpec('yellow,bold,underline', 'dark blue')
>>> AttrSpec("#ddb", "#004", 256)  # closest colors will be found
AttrSpec('#dda', '#006')
>>> AttrSpec("#ddb", "#004", 88)
AttrSpec('#ccc', '#000', colors=88)
property background: str

Return the background color.

property background_basic: bool

Return whether the background color is one of the 16 basic colors.

property background_high: bool

Return whether the background color is a 88- or 256-color palette entry.

property background_number: int

Return the encoded background color number.

property background_true: bool

Return whether the background color is a 24-bit true color.

Return whether the blink setting is enabled.

property bold: bool

Return whether the bold setting is enabled.

property colors: Literal[1, 16, 88, 256, 16777216]

Return the maximum colors required for this object.

Returns 16777216, 256, 88, 16 or 1.

copy_modified(fg: str | None = None, bg: str | None = None, colors: Literal[1, 16, 88, 256, 16777216] | None = None) → Self

Return a new AttrSpec, replacing fg, bg, and/or colors with the given values.

property faint: bool

Return whether the faint setting is enabled.

property foreground: str

Return the foreground color and settings as a comma-separated string.

property foreground_basic: bool

Return whether the foreground color is one of the 16 basic colors.

property foreground_high: bool

Return whether the foreground color is a 88- or 256-color palette entry.

property foreground_number: int

Return the encoded foreground color number.

property foreground_true: bool

Return whether the foreground color is a 24-bit true color.

get_rgb_values() → tuple[int | None, int | None, int | None, int | None, int | None, int | None]

Return (fg_red, fg_green, fg_blue, bg_red, bg_green, bg_blue) color components.

Each component is in the range 0-255. Values are taken from the XTerm defaults and may not exactly match the user’s terminal.

If the foreground or background is ‘default’ then all their compenents will be returned as None.

>>> AttrSpec("yellow", "#ccf", colors=88).get_rgb_values()
(255, 255, 0, 205, 205, 255)
>>> AttrSpec("default", "g92").get_rgb_values()
(None, None, None, 238, 238, 238)
Raises:

ValueError – this AttrSpec holds a colour number outside the 88-colour range.

property italics: bool

Return whether the italics setting is enabled.

property standout: bool

Return whether the standout setting is enabled.

property strikethrough: bool

Return whether the strikethrough setting is enabled.

property underline: bool

Return whether the underline setting is enabled.