# theme

URL: /milo-cli/api/milo/theme/
Section: milo
Description: Theme system for styled CLI output.

Provides named styles that templates can reference via the ``style`` filter
or the ``theme`` global proxy::

    {{ message | style("primary") }}
    {{ theme.success }}Done!{{ theme.reset }}

CLI applications opt in by passing a theme dict to ``get_env()``::

    from milo.templates import get_env
    from milo.theme import DEFAULT_THEME, ThemeStyle

    env = get_env(theme={
        **DEFAULT_THEME,
        "brand": ThemeStyle(fg="magenta", bold=True),
    })

---

> For a complete page index, fetch /milo-cli/llms.txt.

Open LLM text
(/milo-cli/api/milo/theme/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Ftheme%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Ftheme%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Ftheme%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Ftheme%2Findex.txt)

Module

#
`theme`

Theme system for styled CLI output.

Provides named styles that templates can reference via the`style`filter
or the`theme`global proxy::

```
{{ message | style("primary") }}
{{ theme.success }}Done!{{ theme.reset }}
```

CLI applications opt in by passing a theme dict to`get_env()`::

```
from milo.templates import get_env
from milo.theme import DEFAULT_THEME, ThemeStyle

env = get_env(theme={
    **DEFAULT_THEME,
    "brand": ThemeStyle(fg="magenta", bold=True),
})
```

2Classes3Functions

## Classes

`ThemeStyle`

6

▼

A named style mapping to ANSI SGR attributes.

The ``fg`` and ``bg`` fields accept three formats:

…

A named style mapping to ANSI SGR attributes.

The`fg` and `bg`fields accept three formats:

- Named color (str):`"red"`, `"bright_cyan"`— basic 16-color ANSI.

- 256-color index (int):`33`— extended 256-color palette.

- Truecolor hex (str):`"#ff6600"`— 24-bit RGB color.

#### Attributes

Name
Type
Description

`fg`

`str | int | None`

—

`bg`

`str | int | None`

—

`bold`

`bool`

—

`dim`

`bool`

—

`italic`

`bool`

—

#### Methods

`sgr_prefix`

0

`str`

▼

Return the SGR escape prefix for this style (no reset).

`def sgr_prefix(self) -> str`

##### Returns

`str`

`ThemeProxy`

2

▼

Attribute-access proxy for use as a kida template global.

In templates::

{{ theme.primary }}H…

Attribute-access proxy for use as a kida template global.

In templates::

```
{{ theme.primary }}Hello{{ theme.reset }}
{{ theme.error }}Oops{{ theme.reset }}
```

When color is disabled, all attributes return empty strings.

#### Methods

Internal Methods
2

▼

`__init__`

2

▼

`def __init__(self, theme: dict[str, ThemeStyle], *, color: bool = True) -> None`

##### Parameters

Name
Type
Description

`theme`
`—`

`color`
`—`

Default:`True`

`__getattr__`

1

`str`

▼

`def __getattr__(self, name: str) -> str`

##### Parameters

Name
Type
Description

`name`
`—`

##### Returns

`str`

## Functions

`_parse_hex`

1

`tuple[int, int, int]`

▼

Parse ``#rrggbb`` into an (r, g, b) tuple.

`def _parse_hex(color: str) -> tuple[int, int, int]`

##### Parameters

Name
Type
Description

`color`
`str`

##### Returns

`tuple[int, int, int]`

`_color_codes`

2

`str`

▼

Return the SGR parameter string for a foreground or background color.

`def _color_codes(color: str | int, *, ground: str) -> str`

##### Parameters

Name
Type
Description

`color`
`str | int`

Named color, 256-color index (int), or`#rrggbb`hex string.

`ground`
`str`

`"fg"` or `"bg"`.

##### Returns

`str`

`make_style_filter`

2

`Any`

▼

Create a ``style`` filter closure bound to a theme.

Usage in templates::

…

`def make_style_filter(theme: dict[str, ThemeStyle], *, color: bool = True) -> Any`

Create a`style`filter closure bound to a theme.

Usage in templates::

```
{{ "Error!" | style("error") }}
{{ count | style("primary") }}
```

##### Parameters

Name
Type
Description

`theme`
`dict[str, ThemeStyle]`

`color`
`bool`

Default:`True`

##### Returns

`Any`
