rich-theme-manager


Namerich-theme-manager JSON
Version 0.11.0 PyPI version JSON
download
home_pagehttps://github.com/RhetTbull/rich_theme_manager
SummaryManage rich themes for CLI applications
upload_time2022-05-01 15:09:30
maintainer
docs_urlNone
authorRhet Turnbull
requires_python>=3.8,<4.0.0
licenseMIT
keywords rich cli
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Rich Theme Manager

## Description

Implements a basic "theme manager" class for managing rich [Themes](https://rich.readthedocs.io/en/stable/style.html#style-themes) in your [rich](https://github.com/Textualize/rich) CLI application.

The rich package provides an easy way to define custom styles and themes for use with rich.  This package provides a simple way to manage the themes: e.g. to list, add, remove themes, for the user to preview themes, and to manage themes on disk.

## What problem does this solve?

Consider this scenario from the rich [documentation](https://rich.readthedocs.io/en/stable/style.html#style-themes):

If you re-use styles it can be a maintenance headache if you ever want to modify an attribute or color – you would have to change every line where the style is used. Rich provides a Theme class which you can use to define custom styles that you can refer to by name. That way you only need to update your styles in one place.

Style themes can make your code more semantic, for instance a style called "warning" better expresses intent that "italic magenta underline".

To use a style theme, construct a Theme instance and pass it to the Console constructor. Here’s an example:

```python
from rich.console import Console
from rich.theme import Theme
custom_theme = Theme({
    "info": "dim cyan",
    "warning": "magenta",
    "danger": "bold red"
})
console = Console(theme=custom_theme)
console.print("This is information", style="info")
console.print("[warning]The pod bay doors are locked[/warning]")
console.print("Something terrible happened!", style="danger")
```

I highly recommend the use of Themes in your rich application instead of hard-coding colors and styles. However, there's still a problem of managing themes.  For example, letting the user of your application change the default theme styles you've chosen.  What if they are color blind and can't distinguish the colors you've selected? What if they're using a light terminal background and you've selected colors best suited for a dark terminal?  

The rich `Theme` class provides everything you to manage these situations but doing so requires a fair amount of boiler plate code for each application. This package attempts to provide an easy solution for these scenarios with a minimal amount of code.  Instead of having to implement management of theme files and allowing the user to list or preview themes yourself, you can use the `ThemeManager` class to manage themes for you.

## Synopsis

Using `rich_theme_manager` is easy and takes just a few lines of code.  Import `Theme` from `rich_theme_manager` instead of from `rich.theme` (`rich_theme_manager.Theme` subclasses `rich.theme.Theme`) then use `ThemeManager` to manage themes.  `ThemeManager` can be created with or without a `theme_dir` argument. If you don't provide `theme_dir`, `ThemeManager` will not manage themes on disk.  This may still be useful for allowing the user to list and preview themes.  If you do provide `theme_dir`, any default themes passed to `ThemeManager` will be written to `theme_dir` and any theme config files found in `theme_dir` will be loaded.

```python
from rich.console import Console
from rich.style import Style
import pathlib

from rich_theme_manager import Theme, ThemeManager


THEMES = [
    Theme(
        name="dark",
        description="Dark mode theme",
        tags=["dark"],
        styles={
            "info": "dim cyan",
            "warning": "bold magenta",
            "danger": "bold red",
        },
    ),
    Theme(
        name="light",
        description="Light mode theme",
        styles={
            "info": Style(color="#22863a", bold=True),
            "warning": Style(color="#032f62", bold=True),
            "danger": Style(color="#b31d28", bold=True, underline=True, italic=True),
        },
    ),
    Theme(
        name="mono",
        description="Monochromatic theme",
        tags=["mono", "colorblind"],
        styles={
            "info": "italic",
            "warning": "bold",
            "danger": "reverse bold",
        },
    ),
]

if __name__ == "__main__":
    # you can specify a config directory to save/load themes to/from
    theme_dir = pathlib.Path("~/.rich_theme_manager/themes").expanduser()
    theme_dir.expanduser().mkdir(parents=True, exist_ok=True)

    theme_manager = ThemeManager(theme_dir=theme_dir, themes=THEMES)
    theme_manager.list_themes()
    print("\n")

    dark = theme_manager.get("dark")
    theme_manager.preview_theme(dark)
    console = Console(theme=dark)
    print("\n")

    console.print("This is information", style="info")
    console.print("[warning]The pod bay doors are locked[/warning]")
    console.print("Something terrible happened!", style="danger")
```

![Example output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/example1.png)

## Example app

A simple example app that demonstrates the ThemeManager class comes with rich_theme_manager in `__main__.py`:

`python -m rich_theme_manager`:

```text
usage: rich_theme_manager [-h] [--example [EXAMPLE]] [--list] [--preview THEME] [--config THEME]

Example CLI usage of rich_theme_manager

optional arguments:
  -h, --help           show this help message and exit
  --example [EXAMPLE]  Show example output for theme.
  --list               List themes.
  --preview THEME      Preview theme.
  --config THEME       Print configuration for theme THEME.
```

`python -m rich_theme_manager --list`:

![Example --list output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/list.png)

`python -m rich_theme_manager --preview dark`:

![Example --preview output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/preview_dark.png)

## Documentation

### Theme class

`rich_theme_manager.Theme` is a subclass of `rich.theme.Theme` and provides additional functionality for managing themes.

```python
    Theme(
          name: str,
          description: Optional[str] = None,
          styles: Optional[Mapping[str, StyleType]] = None,
          inherit: bool = True,
          tags: Optional[List[str]] = None,
          path: Optional[str] = None,
    )
```

Arguments

* `name`: The name of the theme; required
* `description`: An optional description of the theme.
* `styles`: An optional mapping of style names to styles.
* `inherit`: Whether the theme inherits from the default theme.
* `tags`: An optional list of tags for the theme; useful for allowing user to filter themes.
* `path`: The path to the theme file; in normal use this is not needed as `ThemeManager` will automatically create the theme file.

Properties

* `Theme().name`: The name of the theme
* `Theme().description`: Description of the theme
* `Theme().tags`: List of tags for the theme
* `Theme().inherit`: bool indicating whether the theme inherits from the default theme
* `Theme().style_names`: List of names for styles in the theme
* `Theme().path`: The path to the theme file; (getter/setter)
* `Theme().config`: Contents of a configuration file for the theme (same format as `rich.theme.Theme().config` but with an additional `[metadata]` section)

Methods

* `Theme().save()`: Save the theme to disk (to `Theme().path`)
* `Theme().load()`: Load the theme from disk (from `Theme().path`)
* `Theme().to_file(path: str)`: Save the theme to disk (to `path`)
* `Theme().update(other: Theme, overwrite_existing_styles: bool = True)`: Update the theme with the values from another theme, optionally overwriting existing styles.

Class Methods:

* `Theme.from_file(config_file: IO[str], source: Optional[str] = None, inherit: bool = True)` -> `Theme`: Load a theme from a text mode configuration file (in [configparser](https://docs.python.org/3/library/configparser.html) INI format).
* `Theme.read(path: str, inherit: bool = True) -> Theme`: Load a theme from disk (from `path`)

The `.theme` INI file format looks like this:

```ini
[metadata]
name = dark
description = Dark mode theme
tags = dark
inherit = True

[styles]
danger = bold red
info = dim cyan
warning = bold magenta
```

Here's an real world example of a theme INI file from one of my [apps](https://github.com/RhetTbull/osxphotos):

```INI
[metadata]
name = dark
description = Dark mode theme
tags = dark
inherit = True

[styles]
bar.back = rgb(68,71,90)
bar.complete = rgb(249,38,114)
bar.finished = rgb(80,250,123)
bar.pulse = rgb(98,114,164)
color = rgb(248,248,242)
count = rgb(139,233,253)
error = bold rgb(255,85,85)
filename = bold rgb(189,147,249)
filepath = bold rgb(80,250,123)
highlight = bold #000000 on #d73a49
num = bold rgb(139,233,253)
progress.elapsed = rgb(139,233,253)
progress.percentage = rgb(255,121,198)
progress.remaining = rgb(139,233,253)
time = bold rgb(139,233,253)
uuid = rgb(255,184,108)
warning = bold rgb(241,250,140)
```

`Theme` implements the [rich Console protocol](https://rich.readthedocs.io/en/stable/protocol.html) which means that you use `rich.print()` and `rich.console.Console().print()` to print a theme to the console.  Doing so results in a preview of the theme which visually shows the colors and styles used in the theme.

![Theme preview](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_preview_print.png)

The `Theme` preview will use default sample text for each style. You can change the sample text by setting the `rich_theme_manager.theme.SAMPLE_TEXT` global variable.

![Theme preview with sample text](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_preview_sample_text.png)

`Theme` implements the `__eq__` method so two `Theme` instances can be easily compared for equality. `Theme` instances are considered equal if all properties with exception of `path` are equal.

### ThemeManager class

```python
    ThemeManager(
        theme_dir: Optional[str] = None,
        themes: Optional[List[Theme]] = None,
        overwrite: bool = False,
        update: bool = False,
    )
```

Arguments:

* `theme_dir`: Optional directory to save/load themes to/from.
* `themes`: Optional list of Theme objects
* `overwrite`: overwrite existing theme files
* `update`: update existing theme files with *new* styles from themes but don't replace *existing* styles

If provided, `theme_dir` must exist.  If `theme_dir` is set (for example, using [click.get_app_dir](https://click.palletsprojects.com/en/8.0.x/api/?highlight=get_app_dir#click.get_app_dir)), upon initialization `ThemeManager` will save any default themes provided via `themes` to `theme_dir` and load any themes from `theme_dir`.  Theme files are standard INI files as created by [configparser](https://docs.python.org/3/library/configparser.html) and are named `<name>.theme` where `<name>` is the name of the Theme (see `Theme.name`).  If a theme file already exists, it will be loaded and `ThemeManager` will not overwrite it unless `overwrite=True`.  If `update=True`, any new styles defined in `themes` will be added to the theme file but existing styles will not be replaced. If tags and description of themes are different and `update=True`, those items will also be updated in the theme file.  This allows you to add new styles to an existing theme in future app updates without overriding changes made by the user to theme styles.

Properties:

* `ThemeManager().themes`: List of themes

Methods:

* `ThemeManager().add(theme: Theme, overwrite=False) -> None`: Add a theme to the list of managed themes.  If `overwrite` is True, the theme file will be overwritten if it already exists.
* `ThemeManager().remove(theme: Theme) -> None`: Remove a theme from the list of managed themes and delete the theme file if it exists.
* `ThemeManager().get(theme_name: str) -> Theme`: Get a theme by name. Raises 'ValueError` if no theme with the given name is found.
* `ThemeManager().load_themes(theme_dir=None) -> None`: Load themes from `theme_dir` (or `ThemeManager().theme_dir` if not provided).  Any `.theme` files found in `theme_dir` will be loaded and added to the list of managed themes.
* `ThemeManager().write_themes(overwrite=False) -> None`: Write themes to file (as specified in each `Theme().path` which will be set automatically by `ThemeManager`).  If `overwrite` is True, the theme file will be overwritten if it already exists.

* `ThemeManager().list_themes(show_path: bool = True, theme_names: Optional[List[str]] = None, console: Optional[Console] = None) -> None`: Print a list of themes to the console.  If `show_path` is True, the path to the theme file will be printed.  If `theme_names` is provided, only themes with names in the list will be printed. An optional `rich.console.Console()` instance may be provided to print to a specific console.

![ThemeManager list example](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_manager_list.png)

Class Methods:

* `ThemeManager.preview_theme(theme: Theme, sample_text: Optional[str] = None, show_path: bool = True, console: Optional[Console] = None) -> None`: Print a preview of the theme to the console showing the style of each style in the theme.  If `sample_text` is provided, it will be used as the sample text to preview otherwise a default string will be used.  If `show_path` is True, the path to the theme file will be printed.  An optional `rich.console.Console()` instance may be provided to print to a specific console.

![ThemeManager preview example](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_manager_preview.png)

## Test Coverage

100% coverage of all code with exception of the example CLI app.

```text
---------- coverage: platform darwin, python 3.8.12-final-0 ----------
Name                             Stmts   Miss  Cover
----------------------------------------------------
rich_theme_manager/__init__.py       5      0   100%
rich_theme_manager/manager.py       73      0   100%
rich_theme_manager/theme.py        155      0   100%
----------------------------------------------------
TOTAL                              233      0   100%
```

## License

MIT License

## Contributing

Contributions of all kinds are welcome!  Please submit pull requests, issues, and/or suggestions to the [github repo](https://github.com/RhetTbull/rich_theme_manager).

## Credits

Thank you to [Will McGugan](https://github.com/willmcgugan) for creating [rich](https://github.com/Textualize/rich) and helping to make our command line interfaces more beautiful!

## Projects Using Rich Theme Manager

* [osxphotos](https://github.com/RhetTbull/osxphotos): Python app to export pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RhetTbull/rich_theme_manager",
    "name": "rich-theme-manager",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0.0",
    "maintainer_email": "",
    "keywords": "rich,cli",
    "author": "Rhet Turnbull",
    "author_email": "rturnbull+git@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/33/27/8139d912017d8d885b44143235959ea7db679ad4bde8dd4e6d99b3e35517/rich-theme-manager-0.11.0.tar.gz",
    "platform": null,
    "description": "# Rich Theme Manager\n\n## Description\n\nImplements a basic \"theme manager\" class for managing rich [Themes](https://rich.readthedocs.io/en/stable/style.html#style-themes) in your [rich](https://github.com/Textualize/rich) CLI application.\n\nThe rich package provides an easy way to define custom styles and themes for use with rich.  This package provides a simple way to manage the themes: e.g. to list, add, remove themes, for the user to preview themes, and to manage themes on disk.\n\n## What problem does this solve?\n\nConsider this scenario from the rich [documentation](https://rich.readthedocs.io/en/stable/style.html#style-themes):\n\nIf you re-use styles it can be a maintenance headache if you ever want to modify an attribute or color \u2013 you would have to change every line where the style is used. Rich provides a Theme class which you can use to define custom styles that you can refer to by name. That way you only need to update your styles in one place.\n\nStyle themes can make your code more semantic, for instance a style called \"warning\" better expresses intent that \"italic magenta underline\".\n\nTo use a style theme, construct a Theme instance and pass it to the Console constructor. Here\u2019s an example:\n\n```python\nfrom rich.console import Console\nfrom rich.theme import Theme\ncustom_theme = Theme({\n    \"info\": \"dim cyan\",\n    \"warning\": \"magenta\",\n    \"danger\": \"bold red\"\n})\nconsole = Console(theme=custom_theme)\nconsole.print(\"This is information\", style=\"info\")\nconsole.print(\"[warning]The pod bay doors are locked[/warning]\")\nconsole.print(\"Something terrible happened!\", style=\"danger\")\n```\n\nI highly recommend the use of Themes in your rich application instead of hard-coding colors and styles. However, there's still a problem of managing themes.  For example, letting the user of your application change the default theme styles you've chosen.  What if they are color blind and can't distinguish the colors you've selected? What if they're using a light terminal background and you've selected colors best suited for a dark terminal?  \n\nThe rich `Theme` class provides everything you to manage these situations but doing so requires a fair amount of boiler plate code for each application. This package attempts to provide an easy solution for these scenarios with a minimal amount of code.  Instead of having to implement management of theme files and allowing the user to list or preview themes yourself, you can use the `ThemeManager` class to manage themes for you.\n\n## Synopsis\n\nUsing `rich_theme_manager` is easy and takes just a few lines of code.  Import `Theme` from `rich_theme_manager` instead of from `rich.theme` (`rich_theme_manager.Theme` subclasses `rich.theme.Theme`) then use `ThemeManager` to manage themes.  `ThemeManager` can be created with or without a `theme_dir` argument. If you don't provide `theme_dir`, `ThemeManager` will not manage themes on disk.  This may still be useful for allowing the user to list and preview themes.  If you do provide `theme_dir`, any default themes passed to `ThemeManager` will be written to `theme_dir` and any theme config files found in `theme_dir` will be loaded.\n\n```python\nfrom rich.console import Console\nfrom rich.style import Style\nimport pathlib\n\nfrom rich_theme_manager import Theme, ThemeManager\n\n\nTHEMES = [\n    Theme(\n        name=\"dark\",\n        description=\"Dark mode theme\",\n        tags=[\"dark\"],\n        styles={\n            \"info\": \"dim cyan\",\n            \"warning\": \"bold magenta\",\n            \"danger\": \"bold red\",\n        },\n    ),\n    Theme(\n        name=\"light\",\n        description=\"Light mode theme\",\n        styles={\n            \"info\": Style(color=\"#22863a\", bold=True),\n            \"warning\": Style(color=\"#032f62\", bold=True),\n            \"danger\": Style(color=\"#b31d28\", bold=True, underline=True, italic=True),\n        },\n    ),\n    Theme(\n        name=\"mono\",\n        description=\"Monochromatic theme\",\n        tags=[\"mono\", \"colorblind\"],\n        styles={\n            \"info\": \"italic\",\n            \"warning\": \"bold\",\n            \"danger\": \"reverse bold\",\n        },\n    ),\n]\n\nif __name__ == \"__main__\":\n    # you can specify a config directory to save/load themes to/from\n    theme_dir = pathlib.Path(\"~/.rich_theme_manager/themes\").expanduser()\n    theme_dir.expanduser().mkdir(parents=True, exist_ok=True)\n\n    theme_manager = ThemeManager(theme_dir=theme_dir, themes=THEMES)\n    theme_manager.list_themes()\n    print(\"\\n\")\n\n    dark = theme_manager.get(\"dark\")\n    theme_manager.preview_theme(dark)\n    console = Console(theme=dark)\n    print(\"\\n\")\n\n    console.print(\"This is information\", style=\"info\")\n    console.print(\"[warning]The pod bay doors are locked[/warning]\")\n    console.print(\"Something terrible happened!\", style=\"danger\")\n```\n\n![Example output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/example1.png)\n\n## Example app\n\nA simple example app that demonstrates the ThemeManager class comes with rich_theme_manager in `__main__.py`:\n\n`python -m rich_theme_manager`:\n\n```text\nusage: rich_theme_manager [-h] [--example [EXAMPLE]] [--list] [--preview THEME] [--config THEME]\n\nExample CLI usage of rich_theme_manager\n\noptional arguments:\n  -h, --help           show this help message and exit\n  --example [EXAMPLE]  Show example output for theme.\n  --list               List themes.\n  --preview THEME      Preview theme.\n  --config THEME       Print configuration for theme THEME.\n```\n\n`python -m rich_theme_manager --list`:\n\n![Example --list output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/list.png)\n\n`python -m rich_theme_manager --preview dark`:\n\n![Example --preview output](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/preview_dark.png)\n\n## Documentation\n\n### Theme class\n\n`rich_theme_manager.Theme` is a subclass of `rich.theme.Theme` and provides additional functionality for managing themes.\n\n```python\n    Theme(\n          name: str,\n          description: Optional[str] = None,\n          styles: Optional[Mapping[str, StyleType]] = None,\n          inherit: bool = True,\n          tags: Optional[List[str]] = None,\n          path: Optional[str] = None,\n    )\n```\n\nArguments\n\n* `name`: The name of the theme; required\n* `description`: An optional description of the theme.\n* `styles`: An optional mapping of style names to styles.\n* `inherit`: Whether the theme inherits from the default theme.\n* `tags`: An optional list of tags for the theme; useful for allowing user to filter themes.\n* `path`: The path to the theme file; in normal use this is not needed as `ThemeManager` will automatically create the theme file.\n\nProperties\n\n* `Theme().name`: The name of the theme\n* `Theme().description`: Description of the theme\n* `Theme().tags`: List of tags for the theme\n* `Theme().inherit`: bool indicating whether the theme inherits from the default theme\n* `Theme().style_names`: List of names for styles in the theme\n* `Theme().path`: The path to the theme file; (getter/setter)\n* `Theme().config`: Contents of a configuration file for the theme (same format as `rich.theme.Theme().config` but with an additional `[metadata]` section)\n\nMethods\n\n* `Theme().save()`: Save the theme to disk (to `Theme().path`)\n* `Theme().load()`: Load the theme from disk (from `Theme().path`)\n* `Theme().to_file(path: str)`: Save the theme to disk (to `path`)\n* `Theme().update(other: Theme, overwrite_existing_styles: bool = True)`: Update the theme with the values from another theme, optionally overwriting existing styles.\n\nClass Methods:\n\n* `Theme.from_file(config_file: IO[str], source: Optional[str] = None, inherit: bool = True)` -> `Theme`: Load a theme from a text mode configuration file (in [configparser](https://docs.python.org/3/library/configparser.html) INI format).\n* `Theme.read(path: str, inherit: bool = True) -> Theme`: Load a theme from disk (from `path`)\n\nThe `.theme` INI file format looks like this:\n\n```ini\n[metadata]\nname = dark\ndescription = Dark mode theme\ntags = dark\ninherit = True\n\n[styles]\ndanger = bold red\ninfo = dim cyan\nwarning = bold magenta\n```\n\nHere's an real world example of a theme INI file from one of my [apps](https://github.com/RhetTbull/osxphotos):\n\n```INI\n[metadata]\nname = dark\ndescription = Dark mode theme\ntags = dark\ninherit = True\n\n[styles]\nbar.back = rgb(68,71,90)\nbar.complete = rgb(249,38,114)\nbar.finished = rgb(80,250,123)\nbar.pulse = rgb(98,114,164)\ncolor = rgb(248,248,242)\ncount = rgb(139,233,253)\nerror = bold rgb(255,85,85)\nfilename = bold rgb(189,147,249)\nfilepath = bold rgb(80,250,123)\nhighlight = bold #000000 on #d73a49\nnum = bold rgb(139,233,253)\nprogress.elapsed = rgb(139,233,253)\nprogress.percentage = rgb(255,121,198)\nprogress.remaining = rgb(139,233,253)\ntime = bold rgb(139,233,253)\nuuid = rgb(255,184,108)\nwarning = bold rgb(241,250,140)\n```\n\n`Theme` implements the [rich Console protocol](https://rich.readthedocs.io/en/stable/protocol.html) which means that you use `rich.print()` and `rich.console.Console().print()` to print a theme to the console.  Doing so results in a preview of the theme which visually shows the colors and styles used in the theme.\n\n![Theme preview](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_preview_print.png)\n\nThe `Theme` preview will use default sample text for each style. You can change the sample text by setting the `rich_theme_manager.theme.SAMPLE_TEXT` global variable.\n\n![Theme preview with sample text](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_preview_sample_text.png)\n\n`Theme` implements the `__eq__` method so two `Theme` instances can be easily compared for equality. `Theme` instances are considered equal if all properties with exception of `path` are equal.\n\n### ThemeManager class\n\n```python\n    ThemeManager(\n        theme_dir: Optional[str] = None,\n        themes: Optional[List[Theme]] = None,\n        overwrite: bool = False,\n        update: bool = False,\n    )\n```\n\nArguments:\n\n* `theme_dir`: Optional directory to save/load themes to/from.\n* `themes`: Optional list of Theme objects\n* `overwrite`: overwrite existing theme files\n* `update`: update existing theme files with *new* styles from themes but don't replace *existing* styles\n\nIf provided, `theme_dir` must exist.  If `theme_dir` is set (for example, using [click.get_app_dir](https://click.palletsprojects.com/en/8.0.x/api/?highlight=get_app_dir#click.get_app_dir)), upon initialization `ThemeManager` will save any default themes provided via `themes` to `theme_dir` and load any themes from `theme_dir`.  Theme files are standard INI files as created by [configparser](https://docs.python.org/3/library/configparser.html) and are named `<name>.theme` where `<name>` is the name of the Theme (see `Theme.name`).  If a theme file already exists, it will be loaded and `ThemeManager` will not overwrite it unless `overwrite=True`.  If `update=True`, any new styles defined in `themes` will be added to the theme file but existing styles will not be replaced. If tags and description of themes are different and `update=True`, those items will also be updated in the theme file.  This allows you to add new styles to an existing theme in future app updates without overriding changes made by the user to theme styles.\n\nProperties:\n\n* `ThemeManager().themes`: List of themes\n\nMethods:\n\n* `ThemeManager().add(theme: Theme, overwrite=False) -> None`: Add a theme to the list of managed themes.  If `overwrite` is True, the theme file will be overwritten if it already exists.\n* `ThemeManager().remove(theme: Theme) -> None`: Remove a theme from the list of managed themes and delete the theme file if it exists.\n* `ThemeManager().get(theme_name: str) -> Theme`: Get a theme by name. Raises 'ValueError` if no theme with the given name is found.\n* `ThemeManager().load_themes(theme_dir=None) -> None`: Load themes from `theme_dir` (or `ThemeManager().theme_dir` if not provided).  Any `.theme` files found in `theme_dir` will be loaded and added to the list of managed themes.\n* `ThemeManager().write_themes(overwrite=False) -> None`: Write themes to file (as specified in each `Theme().path` which will be set automatically by `ThemeManager`).  If `overwrite` is True, the theme file will be overwritten if it already exists.\n\n* `ThemeManager().list_themes(show_path: bool = True, theme_names: Optional[List[str]] = None, console: Optional[Console] = None) -> None`: Print a list of themes to the console.  If `show_path` is True, the path to the theme file will be printed.  If `theme_names` is provided, only themes with names in the list will be printed. An optional `rich.console.Console()` instance may be provided to print to a specific console.\n\n![ThemeManager list example](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_manager_list.png)\n\nClass Methods:\n\n* `ThemeManager.preview_theme(theme: Theme, sample_text: Optional[str] = None, show_path: bool = True, console: Optional[Console] = None) -> None`: Print a preview of the theme to the console showing the style of each style in the theme.  If `sample_text` is provided, it will be used as the sample text to preview otherwise a default string will be used.  If `show_path` is True, the path to the theme file will be printed.  An optional `rich.console.Console()` instance may be provided to print to a specific console.\n\n![ThemeManager preview example](https://github.com/RhetTbull/rich_theme_manager/raw/main/images/theme_manager_preview.png)\n\n## Test Coverage\n\n100% coverage of all code with exception of the example CLI app.\n\n```text\n---------- coverage: platform darwin, python 3.8.12-final-0 ----------\nName                             Stmts   Miss  Cover\n----------------------------------------------------\nrich_theme_manager/__init__.py       5      0   100%\nrich_theme_manager/manager.py       73      0   100%\nrich_theme_manager/theme.py        155      0   100%\n----------------------------------------------------\nTOTAL                              233      0   100%\n```\n\n## License\n\nMIT License\n\n## Contributing\n\nContributions of all kinds are welcome!  Please submit pull requests, issues, and/or suggestions to the [github repo](https://github.com/RhetTbull/rich_theme_manager).\n\n## Credits\n\nThank you to [Will McGugan](https://github.com/willmcgugan) for creating [rich](https://github.com/Textualize/rich) and helping to make our command line interfaces more beautiful!\n\n## Projects Using Rich Theme Manager\n\n* [osxphotos](https://github.com/RhetTbull/osxphotos): Python app to export pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Manage rich themes for CLI applications",
    "version": "0.11.0",
    "project_urls": {
        "Homepage": "https://github.com/RhetTbull/rich_theme_manager",
        "Repository": "https://github.com/RhetTbull/rich_theme_manager"
    },
    "split_keywords": [
        "rich",
        "cli"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "68edbd13b916738781c860fe97fa7b0db73281d93f7989dd4f566c9f99846a93",
                "md5": "6ef0d6dd8e5484c27a31c23303dce5c9",
                "sha256": "b9155233076eb4f9fc888ef8cf7755a3cd8efa3bfa33cee5137fc00000117d8e"
            },
            "downloads": -1,
            "filename": "rich_theme_manager-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6ef0d6dd8e5484c27a31c23303dce5c9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0.0",
            "size": 14881,
            "upload_time": "2022-05-01T15:09:32",
            "upload_time_iso_8601": "2022-05-01T15:09:32.273734Z",
            "url": "https://files.pythonhosted.org/packages/68/ed/bd13b916738781c860fe97fa7b0db73281d93f7989dd4f566c9f99846a93/rich_theme_manager-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33278139d912017d8d885b44143235959ea7db679ad4bde8dd4e6d99b3e35517",
                "md5": "97c370b5bb4fada9a51e0e64454ba484",
                "sha256": "3bc1effa4b6c42f72994b73c8b3c391b1c6e803deccc2fc3932da31b00f1a112"
            },
            "downloads": -1,
            "filename": "rich-theme-manager-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "97c370b5bb4fada9a51e0e64454ba484",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0.0",
            "size": 17416,
            "upload_time": "2022-05-01T15:09:30",
            "upload_time_iso_8601": "2022-05-01T15:09:30.997703Z",
            "url": "https://files.pythonhosted.org/packages/33/27/8139d912017d8d885b44143235959ea7db679ad4bde8dd4e6d99b3e35517/rich-theme-manager-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-01 15:09:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RhetTbull",
    "github_project": "rich_theme_manager",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "rich-theme-manager"
}
        
Elapsed time: 0.22385s