File: __init__.py

package info (click to toggle)
python-plumbum 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,300 kB
  • sloc: python: 10,016; makefile: 130; sh: 8
file content (46 lines) | stat: -rw-r--r-- 1,247 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""\
The ``ansicolor`` object provides ``bg`` and ``fg`` to access colors,
and attributes like bold and
underlined text. It also provides ``reset`` to recover the normal font.
"""

from __future__ import annotations

import sys

from .factories import StyleFactory
from .styles import ANSIStyle, ColorNotFound, HTMLStyle, Style

__all__ = (
    "ANSIStyle",
    "ColorNotFound",
    "HTMLStyle",
    "Style",
    "StyleFactory",
    "ansicolors",
    "htmlcolors",
    "load_ipython_extension",
    "main",
)

ansicolors = StyleFactory(ANSIStyle)
htmlcolors = StyleFactory(HTMLStyle)


def load_ipython_extension(ipython):  # pragma: no cover
    try:
        from ._ipython_ext import OutputMagics  # pylint:disable=import-outside-toplevel
    except ImportError:
        print("IPython required for the IPython extension to be loaded.")  # noqa: T201
        raise

    ipython.push({"colors": htmlcolors})
    ipython.register_magics(OutputMagics)


def main():  # pragma: no cover
    """Color changing script entry. Call using
    python3 -m plumbum.colors, will reset if no arguments given."""
    color = " ".join(sys.argv[1:]) if len(sys.argv) > 1 else ""
    ansicolors.use_color = True
    ansicolors.get_colors_from_string(color).now()