Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/_multiprocess/__init__.py +8 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/functorch/__init__.py +39 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/__init__.py +177 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/__main__.py +273 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_cell_widths.py +454 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_emoji_codes.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_emoji_replace.py +32 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_export_format.py +76 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_extension.py +10 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_inspect.py +268 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_log_render.py +94 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_loop.py +43 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_null_file.py +69 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_palettes.py +309 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_pick.py +17 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_ratio.py +159 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_spinners.py +482 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_stack.py +16 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_timer.py +19 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_win32_console.py +661 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_windows.py +71 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_windows_renderer.py +56 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_wrap.py +93 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/abc.py +33 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/align.py +312 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/ansi.py +241 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/bar.py +93 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/box.py +480 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/cells.py +174 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/color.py +621 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/color_triplet.py +38 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/columns.py +187 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/console.py +0 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/constrain.py +37 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/containers.py +167 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/control.py +225 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/default_styles.py +191 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/diagnose.py +37 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/emoji.py +96 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/errors.py +34 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/file_proxy.py +57 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/filesize.py +88 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/highlighter.py +232 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/json.py +139 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/jupyter.py +101 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/layout.py +442 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/live.py +375 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/live_render.py +112 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/logging.py +297 -0
- Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/markdown.py +784 -0
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/_multiprocess/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
#
|
| 3 |
+
# Author: Mike McKerns (mmckerns @caltech and @uqfoundation)
|
| 4 |
+
# Copyright (c) 2022-2024 The Uncertainty Quantification Foundation.
|
| 5 |
+
# License: 3-clause BSD. The full license text is available at:
|
| 6 |
+
# - https://github.com/uqfoundation/multiprocess/blob/master/LICENSE
|
| 7 |
+
|
| 8 |
+
from _multiprocessing import *
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/functorch/__init__.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright (c) Facebook, Inc. and its affiliates.
|
| 2 |
+
# All rights reserved.
|
| 3 |
+
#
|
| 4 |
+
# This source code is licensed under the BSD-style license found in the
|
| 5 |
+
# LICENSE file in the root directory of this source tree.
|
| 6 |
+
import torch
|
| 7 |
+
from torch._functorch.deprecated import (
|
| 8 |
+
combine_state_for_ensemble,
|
| 9 |
+
functionalize,
|
| 10 |
+
grad,
|
| 11 |
+
grad_and_value,
|
| 12 |
+
hessian,
|
| 13 |
+
jacfwd,
|
| 14 |
+
jacrev,
|
| 15 |
+
jvp,
|
| 16 |
+
make_functional,
|
| 17 |
+
make_functional_with_buffers,
|
| 18 |
+
vjp,
|
| 19 |
+
vmap,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# utilities. Maybe these should go in their own namespace in the future?
|
| 23 |
+
from torch._functorch.make_functional import (
|
| 24 |
+
FunctionalModule,
|
| 25 |
+
FunctionalModuleWithBuffers,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Was never documented
|
| 29 |
+
from torch._functorch.python_key import make_fx
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# Top-level APIs. Please think carefully before adding something to the
|
| 33 |
+
# top-level namespace:
|
| 34 |
+
# - private helper functions should go into torch._functorch
|
| 35 |
+
# - very experimental things should go into functorch.experimental
|
| 36 |
+
# - compilation related things should go into functorch.compile
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
__version__ = torch.__version__
|
Prism/LLaDA/LLaDA_Prism/.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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Rich text and beautiful formatting in the terminal."""
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from typing import IO, TYPE_CHECKING, Any, Callable, Optional, Union
|
| 5 |
+
|
| 6 |
+
from ._extension import load_ipython_extension # noqa: F401
|
| 7 |
+
|
| 8 |
+
__all__ = ["get_console", "reconfigure", "print", "inspect", "print_json"]
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from .console import Console
|
| 12 |
+
|
| 13 |
+
# Global console used by alternative print
|
| 14 |
+
_console: Optional["Console"] = None
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
_IMPORT_CWD = os.path.abspath(os.getcwd())
|
| 18 |
+
except FileNotFoundError:
|
| 19 |
+
# Can happen if the cwd has been deleted
|
| 20 |
+
_IMPORT_CWD = ""
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_console() -> "Console":
|
| 24 |
+
"""Get a global :class:`~rich.console.Console` instance. This function is used when Rich requires a Console,
|
| 25 |
+
and hasn't been explicitly given one.
|
| 26 |
+
|
| 27 |
+
Returns:
|
| 28 |
+
Console: A console instance.
|
| 29 |
+
"""
|
| 30 |
+
global _console
|
| 31 |
+
if _console is None:
|
| 32 |
+
from .console import Console
|
| 33 |
+
|
| 34 |
+
_console = Console()
|
| 35 |
+
|
| 36 |
+
return _console
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def reconfigure(*args: Any, **kwargs: Any) -> None:
|
| 40 |
+
"""Reconfigures the global console by replacing it with another.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
*args (Any): Positional arguments for the replacement :class:`~rich.console.Console`.
|
| 44 |
+
**kwargs (Any): Keyword arguments for the replacement :class:`~rich.console.Console`.
|
| 45 |
+
"""
|
| 46 |
+
from rich.console import Console
|
| 47 |
+
|
| 48 |
+
new_console = Console(*args, **kwargs)
|
| 49 |
+
_console = get_console()
|
| 50 |
+
_console.__dict__ = new_console.__dict__
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def print(
|
| 54 |
+
*objects: Any,
|
| 55 |
+
sep: str = " ",
|
| 56 |
+
end: str = "\n",
|
| 57 |
+
file: Optional[IO[str]] = None,
|
| 58 |
+
flush: bool = False,
|
| 59 |
+
) -> None:
|
| 60 |
+
r"""Print object(s) supplied via positional arguments.
|
| 61 |
+
This function has an identical signature to the built-in print.
|
| 62 |
+
For more advanced features, see the :class:`~rich.console.Console` class.
|
| 63 |
+
|
| 64 |
+
Args:
|
| 65 |
+
sep (str, optional): Separator between printed objects. Defaults to " ".
|
| 66 |
+
end (str, optional): Character to write at end of output. Defaults to "\\n".
|
| 67 |
+
file (IO[str], optional): File to write to, or None for stdout. Defaults to None.
|
| 68 |
+
flush (bool, optional): Has no effect as Rich always flushes output. Defaults to False.
|
| 69 |
+
|
| 70 |
+
"""
|
| 71 |
+
from .console import Console
|
| 72 |
+
|
| 73 |
+
write_console = get_console() if file is None else Console(file=file)
|
| 74 |
+
return write_console.print(*objects, sep=sep, end=end)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def print_json(
|
| 78 |
+
json: Optional[str] = None,
|
| 79 |
+
*,
|
| 80 |
+
data: Any = None,
|
| 81 |
+
indent: Union[None, int, str] = 2,
|
| 82 |
+
highlight: bool = True,
|
| 83 |
+
skip_keys: bool = False,
|
| 84 |
+
ensure_ascii: bool = False,
|
| 85 |
+
check_circular: bool = True,
|
| 86 |
+
allow_nan: bool = True,
|
| 87 |
+
default: Optional[Callable[[Any], Any]] = None,
|
| 88 |
+
sort_keys: bool = False,
|
| 89 |
+
) -> None:
|
| 90 |
+
"""Pretty prints JSON. Output will be valid JSON.
|
| 91 |
+
|
| 92 |
+
Args:
|
| 93 |
+
json (str): A string containing JSON.
|
| 94 |
+
data (Any): If json is not supplied, then encode this data.
|
| 95 |
+
indent (int, optional): Number of spaces to indent. Defaults to 2.
|
| 96 |
+
highlight (bool, optional): Enable highlighting of output: Defaults to True.
|
| 97 |
+
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
|
| 98 |
+
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
|
| 99 |
+
check_circular (bool, optional): Check for circular references. Defaults to True.
|
| 100 |
+
allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
|
| 101 |
+
default (Callable, optional): A callable that converts values that can not be encoded
|
| 102 |
+
in to something that can be JSON encoded. Defaults to None.
|
| 103 |
+
sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
|
| 104 |
+
"""
|
| 105 |
+
|
| 106 |
+
get_console().print_json(
|
| 107 |
+
json,
|
| 108 |
+
data=data,
|
| 109 |
+
indent=indent,
|
| 110 |
+
highlight=highlight,
|
| 111 |
+
skip_keys=skip_keys,
|
| 112 |
+
ensure_ascii=ensure_ascii,
|
| 113 |
+
check_circular=check_circular,
|
| 114 |
+
allow_nan=allow_nan,
|
| 115 |
+
default=default,
|
| 116 |
+
sort_keys=sort_keys,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def inspect(
|
| 121 |
+
obj: Any,
|
| 122 |
+
*,
|
| 123 |
+
console: Optional["Console"] = None,
|
| 124 |
+
title: Optional[str] = None,
|
| 125 |
+
help: bool = False,
|
| 126 |
+
methods: bool = False,
|
| 127 |
+
docs: bool = True,
|
| 128 |
+
private: bool = False,
|
| 129 |
+
dunder: bool = False,
|
| 130 |
+
sort: bool = True,
|
| 131 |
+
all: bool = False,
|
| 132 |
+
value: bool = True,
|
| 133 |
+
) -> None:
|
| 134 |
+
"""Inspect any Python object.
|
| 135 |
+
|
| 136 |
+
* inspect(<OBJECT>) to see summarized info.
|
| 137 |
+
* inspect(<OBJECT>, methods=True) to see methods.
|
| 138 |
+
* inspect(<OBJECT>, help=True) to see full (non-abbreviated) help.
|
| 139 |
+
* inspect(<OBJECT>, private=True) to see private attributes (single underscore).
|
| 140 |
+
* inspect(<OBJECT>, dunder=True) to see attributes beginning with double underscore.
|
| 141 |
+
* inspect(<OBJECT>, all=True) to see all attributes.
|
| 142 |
+
|
| 143 |
+
Args:
|
| 144 |
+
obj (Any): An object to inspect.
|
| 145 |
+
title (str, optional): Title to display over inspect result, or None use type. Defaults to None.
|
| 146 |
+
help (bool, optional): Show full help text rather than just first paragraph. Defaults to False.
|
| 147 |
+
methods (bool, optional): Enable inspection of callables. Defaults to False.
|
| 148 |
+
docs (bool, optional): Also render doc strings. Defaults to True.
|
| 149 |
+
private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
|
| 150 |
+
dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
|
| 151 |
+
sort (bool, optional): Sort attributes alphabetically. Defaults to True.
|
| 152 |
+
all (bool, optional): Show all attributes. Defaults to False.
|
| 153 |
+
value (bool, optional): Pretty print value. Defaults to True.
|
| 154 |
+
"""
|
| 155 |
+
_console = console or get_console()
|
| 156 |
+
from rich._inspect import Inspect
|
| 157 |
+
|
| 158 |
+
# Special case for inspect(inspect)
|
| 159 |
+
is_inspect = obj is inspect
|
| 160 |
+
|
| 161 |
+
_inspect = Inspect(
|
| 162 |
+
obj,
|
| 163 |
+
title=title,
|
| 164 |
+
help=is_inspect or help,
|
| 165 |
+
methods=is_inspect or methods,
|
| 166 |
+
docs=is_inspect or docs,
|
| 167 |
+
private=private,
|
| 168 |
+
dunder=dunder,
|
| 169 |
+
sort=sort,
|
| 170 |
+
all=all,
|
| 171 |
+
value=value,
|
| 172 |
+
)
|
| 173 |
+
_console.print(_inspect)
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
if __name__ == "__main__": # pragma: no cover
|
| 177 |
+
print("Hello, **World**")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/__main__.py
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import colorsys
|
| 2 |
+
import io
|
| 3 |
+
from time import process_time
|
| 4 |
+
|
| 5 |
+
from rich import box
|
| 6 |
+
from rich.color import Color
|
| 7 |
+
from rich.console import Console, ConsoleOptions, Group, RenderableType, RenderResult
|
| 8 |
+
from rich.markdown import Markdown
|
| 9 |
+
from rich.measure import Measurement
|
| 10 |
+
from rich.pretty import Pretty
|
| 11 |
+
from rich.segment import Segment
|
| 12 |
+
from rich.style import Style
|
| 13 |
+
from rich.syntax import Syntax
|
| 14 |
+
from rich.table import Table
|
| 15 |
+
from rich.text import Text
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class ColorBox:
|
| 19 |
+
def __rich_console__(
|
| 20 |
+
self, console: Console, options: ConsoleOptions
|
| 21 |
+
) -> RenderResult:
|
| 22 |
+
for y in range(0, 5):
|
| 23 |
+
for x in range(options.max_width):
|
| 24 |
+
h = x / options.max_width
|
| 25 |
+
l = 0.1 + ((y / 5) * 0.7)
|
| 26 |
+
r1, g1, b1 = colorsys.hls_to_rgb(h, l, 1.0)
|
| 27 |
+
r2, g2, b2 = colorsys.hls_to_rgb(h, l + 0.7 / 10, 1.0)
|
| 28 |
+
bgcolor = Color.from_rgb(r1 * 255, g1 * 255, b1 * 255)
|
| 29 |
+
color = Color.from_rgb(r2 * 255, g2 * 255, b2 * 255)
|
| 30 |
+
yield Segment("▄", Style(color=color, bgcolor=bgcolor))
|
| 31 |
+
yield Segment.line()
|
| 32 |
+
|
| 33 |
+
def __rich_measure__(
|
| 34 |
+
self, console: "Console", options: ConsoleOptions
|
| 35 |
+
) -> Measurement:
|
| 36 |
+
return Measurement(1, options.max_width)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def make_test_card() -> Table:
|
| 40 |
+
"""Get a renderable that demonstrates a number of features."""
|
| 41 |
+
table = Table.grid(padding=1, pad_edge=True)
|
| 42 |
+
table.title = "Rich features"
|
| 43 |
+
table.add_column("Feature", no_wrap=True, justify="center", style="bold red")
|
| 44 |
+
table.add_column("Demonstration")
|
| 45 |
+
|
| 46 |
+
color_table = Table(
|
| 47 |
+
box=None,
|
| 48 |
+
expand=False,
|
| 49 |
+
show_header=False,
|
| 50 |
+
show_edge=False,
|
| 51 |
+
pad_edge=False,
|
| 52 |
+
)
|
| 53 |
+
color_table.add_row(
|
| 54 |
+
(
|
| 55 |
+
"✓ [bold green]4-bit color[/]\n"
|
| 56 |
+
"✓ [bold blue]8-bit color[/]\n"
|
| 57 |
+
"✓ [bold magenta]Truecolor (16.7 million)[/]\n"
|
| 58 |
+
"✓ [bold yellow]Dumb terminals[/]\n"
|
| 59 |
+
"✓ [bold cyan]Automatic color conversion"
|
| 60 |
+
),
|
| 61 |
+
ColorBox(),
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
table.add_row("Colors", color_table)
|
| 65 |
+
|
| 66 |
+
table.add_row(
|
| 67 |
+
"Styles",
|
| 68 |
+
"All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/italic], [underline]underline[/], [strike]strikethrough[/], [reverse]reverse[/], and even [blink]blink[/].",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in metus sed sapien ultricies pretium a at justo. Maecenas luctus velit et auctor maximus."
|
| 72 |
+
lorem_table = Table.grid(padding=1, collapse_padding=True)
|
| 73 |
+
lorem_table.pad_edge = False
|
| 74 |
+
lorem_table.add_row(
|
| 75 |
+
Text(lorem, justify="left", style="green"),
|
| 76 |
+
Text(lorem, justify="center", style="yellow"),
|
| 77 |
+
Text(lorem, justify="right", style="blue"),
|
| 78 |
+
Text(lorem, justify="full", style="red"),
|
| 79 |
+
)
|
| 80 |
+
table.add_row(
|
| 81 |
+
"Text",
|
| 82 |
+
Group(
|
| 83 |
+
Text.from_markup(
|
| 84 |
+
"""Word wrap text. Justify [green]left[/], [yellow]center[/], [blue]right[/] or [red]full[/].\n"""
|
| 85 |
+
),
|
| 86 |
+
lorem_table,
|
| 87 |
+
),
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Table:
|
| 91 |
+
table = Table(show_header=False, pad_edge=False, box=None, expand=True)
|
| 92 |
+
table.add_column("1", ratio=1)
|
| 93 |
+
table.add_column("2", ratio=1)
|
| 94 |
+
table.add_row(renderable1, renderable2)
|
| 95 |
+
return table
|
| 96 |
+
|
| 97 |
+
table.add_row(
|
| 98 |
+
"Asian\nlanguage\nsupport",
|
| 99 |
+
":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다",
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
markup_example = (
|
| 103 |
+
"[bold magenta]Rich[/] supports a simple [i]bbcode[/i]-like [b]markup[/b] for [yellow]color[/], [underline]style[/], and emoji! "
|
| 104 |
+
":+1: :apple: :ant: :bear: :baguette_bread: :bus: "
|
| 105 |
+
)
|
| 106 |
+
table.add_row("Markup", markup_example)
|
| 107 |
+
|
| 108 |
+
example_table = Table(
|
| 109 |
+
show_edge=False,
|
| 110 |
+
show_header=True,
|
| 111 |
+
expand=False,
|
| 112 |
+
row_styles=["none", "dim"],
|
| 113 |
+
box=box.SIMPLE,
|
| 114 |
+
)
|
| 115 |
+
example_table.add_column("[green]Date", style="green", no_wrap=True)
|
| 116 |
+
example_table.add_column("[blue]Title", style="blue")
|
| 117 |
+
example_table.add_column(
|
| 118 |
+
"[cyan]Production Budget",
|
| 119 |
+
style="cyan",
|
| 120 |
+
justify="right",
|
| 121 |
+
no_wrap=True,
|
| 122 |
+
)
|
| 123 |
+
example_table.add_column(
|
| 124 |
+
"[magenta]Box Office",
|
| 125 |
+
style="magenta",
|
| 126 |
+
justify="right",
|
| 127 |
+
no_wrap=True,
|
| 128 |
+
)
|
| 129 |
+
example_table.add_row(
|
| 130 |
+
"Dec 20, 2019",
|
| 131 |
+
"Star Wars: The Rise of Skywalker",
|
| 132 |
+
"$275,000,000",
|
| 133 |
+
"$375,126,118",
|
| 134 |
+
)
|
| 135 |
+
example_table.add_row(
|
| 136 |
+
"May 25, 2018",
|
| 137 |
+
"[b]Solo[/]: A Star Wars Story",
|
| 138 |
+
"$275,000,000",
|
| 139 |
+
"$393,151,347",
|
| 140 |
+
)
|
| 141 |
+
example_table.add_row(
|
| 142 |
+
"Dec 15, 2017",
|
| 143 |
+
"Star Wars Ep. VIII: The Last Jedi",
|
| 144 |
+
"$262,000,000",
|
| 145 |
+
"[bold]$1,332,539,889[/bold]",
|
| 146 |
+
)
|
| 147 |
+
example_table.add_row(
|
| 148 |
+
"May 19, 1999",
|
| 149 |
+
"Star Wars Ep. [b]I[/b]: [i]The phantom Menace",
|
| 150 |
+
"$115,000,000",
|
| 151 |
+
"$1,027,044,677",
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
table.add_row("Tables", example_table)
|
| 155 |
+
|
| 156 |
+
code = '''\
|
| 157 |
+
def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
|
| 158 |
+
"""Iterate and generate a tuple with a flag for last value."""
|
| 159 |
+
iter_values = iter(values)
|
| 160 |
+
try:
|
| 161 |
+
previous_value = next(iter_values)
|
| 162 |
+
except StopIteration:
|
| 163 |
+
return
|
| 164 |
+
for value in iter_values:
|
| 165 |
+
yield False, previous_value
|
| 166 |
+
previous_value = value
|
| 167 |
+
yield True, previous_value'''
|
| 168 |
+
|
| 169 |
+
pretty_data = {
|
| 170 |
+
"foo": [
|
| 171 |
+
3.1427,
|
| 172 |
+
(
|
| 173 |
+
"Paul Atreides",
|
| 174 |
+
"Vladimir Harkonnen",
|
| 175 |
+
"Thufir Hawat",
|
| 176 |
+
),
|
| 177 |
+
],
|
| 178 |
+
"atomic": (False, True, None),
|
| 179 |
+
}
|
| 180 |
+
table.add_row(
|
| 181 |
+
"Syntax\nhighlighting\n&\npretty\nprinting",
|
| 182 |
+
comparison(
|
| 183 |
+
Syntax(code, "python3", line_numbers=True, indent_guides=True),
|
| 184 |
+
Pretty(pretty_data, indent_guides=True),
|
| 185 |
+
),
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
markdown_example = """\
|
| 189 |
+
# Markdown
|
| 190 |
+
|
| 191 |
+
Supports much of the *markdown* __syntax__!
|
| 192 |
+
|
| 193 |
+
- Headers
|
| 194 |
+
- Basic formatting: **bold**, *italic*, `code`
|
| 195 |
+
- Block quotes
|
| 196 |
+
- Lists, and more...
|
| 197 |
+
"""
|
| 198 |
+
table.add_row(
|
| 199 |
+
"Markdown", comparison("[cyan]" + markdown_example, Markdown(markdown_example))
|
| 200 |
+
)
|
| 201 |
+
|
| 202 |
+
table.add_row(
|
| 203 |
+
"+more!",
|
| 204 |
+
"""Progress bars, columns, styled logging handler, tracebacks, etc...""",
|
| 205 |
+
)
|
| 206 |
+
return table
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
if __name__ == "__main__": # pragma: no cover
|
| 210 |
+
console = Console(
|
| 211 |
+
file=io.StringIO(),
|
| 212 |
+
force_terminal=True,
|
| 213 |
+
)
|
| 214 |
+
test_card = make_test_card()
|
| 215 |
+
|
| 216 |
+
# Print once to warm cache
|
| 217 |
+
start = process_time()
|
| 218 |
+
console.print(test_card)
|
| 219 |
+
pre_cache_taken = round((process_time() - start) * 1000.0, 1)
|
| 220 |
+
|
| 221 |
+
console.file = io.StringIO()
|
| 222 |
+
|
| 223 |
+
start = process_time()
|
| 224 |
+
console.print(test_card)
|
| 225 |
+
taken = round((process_time() - start) * 1000.0, 1)
|
| 226 |
+
|
| 227 |
+
c = Console(record=True)
|
| 228 |
+
c.print(test_card)
|
| 229 |
+
|
| 230 |
+
print(f"rendered in {pre_cache_taken}ms (cold cache)")
|
| 231 |
+
print(f"rendered in {taken}ms (warm cache)")
|
| 232 |
+
|
| 233 |
+
from rich.panel import Panel
|
| 234 |
+
|
| 235 |
+
console = Console()
|
| 236 |
+
|
| 237 |
+
sponsor_message = Table.grid(padding=1)
|
| 238 |
+
sponsor_message.add_column(style="green", justify="right")
|
| 239 |
+
sponsor_message.add_column(no_wrap=True)
|
| 240 |
+
|
| 241 |
+
sponsor_message.add_row(
|
| 242 |
+
"Textualize",
|
| 243 |
+
"[u blue link=https://github.com/textualize]https://github.com/textualize",
|
| 244 |
+
)
|
| 245 |
+
sponsor_message.add_row(
|
| 246 |
+
"Twitter",
|
| 247 |
+
"[u blue link=https://twitter.com/willmcgugan]https://twitter.com/willmcgugan",
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
intro_message = Text.from_markup(
|
| 251 |
+
"""\
|
| 252 |
+
We hope you enjoy using Rich!
|
| 253 |
+
|
| 254 |
+
Rich is maintained with [red]:heart:[/] by [link=https://www.textualize.io]Textualize.io[/]
|
| 255 |
+
|
| 256 |
+
- Will McGugan"""
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
message = Table.grid(padding=2)
|
| 260 |
+
message.add_column()
|
| 261 |
+
message.add_column(no_wrap=True)
|
| 262 |
+
message.add_row(intro_message, sponsor_message)
|
| 263 |
+
|
| 264 |
+
console.print(
|
| 265 |
+
Panel.fit(
|
| 266 |
+
message,
|
| 267 |
+
box=box.ROUNDED,
|
| 268 |
+
padding=(1, 2),
|
| 269 |
+
title="[b red]Thanks for trying out Rich!",
|
| 270 |
+
border_style="bright_blue",
|
| 271 |
+
),
|
| 272 |
+
justify="center",
|
| 273 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_cell_widths.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Auto generated by make_terminal_widths.py
|
| 2 |
+
|
| 3 |
+
CELL_WIDTHS = [
|
| 4 |
+
(0, 0, 0),
|
| 5 |
+
(1, 31, -1),
|
| 6 |
+
(127, 159, -1),
|
| 7 |
+
(173, 173, 0),
|
| 8 |
+
(768, 879, 0),
|
| 9 |
+
(1155, 1161, 0),
|
| 10 |
+
(1425, 1469, 0),
|
| 11 |
+
(1471, 1471, 0),
|
| 12 |
+
(1473, 1474, 0),
|
| 13 |
+
(1476, 1477, 0),
|
| 14 |
+
(1479, 1479, 0),
|
| 15 |
+
(1536, 1541, 0),
|
| 16 |
+
(1552, 1562, 0),
|
| 17 |
+
(1564, 1564, 0),
|
| 18 |
+
(1611, 1631, 0),
|
| 19 |
+
(1648, 1648, 0),
|
| 20 |
+
(1750, 1757, 0),
|
| 21 |
+
(1759, 1764, 0),
|
| 22 |
+
(1767, 1768, 0),
|
| 23 |
+
(1770, 1773, 0),
|
| 24 |
+
(1807, 1807, 0),
|
| 25 |
+
(1809, 1809, 0),
|
| 26 |
+
(1840, 1866, 0),
|
| 27 |
+
(1958, 1968, 0),
|
| 28 |
+
(2027, 2035, 0),
|
| 29 |
+
(2045, 2045, 0),
|
| 30 |
+
(2070, 2073, 0),
|
| 31 |
+
(2075, 2083, 0),
|
| 32 |
+
(2085, 2087, 0),
|
| 33 |
+
(2089, 2093, 0),
|
| 34 |
+
(2137, 2139, 0),
|
| 35 |
+
(2192, 2193, 0),
|
| 36 |
+
(2200, 2207, 0),
|
| 37 |
+
(2250, 2307, 0),
|
| 38 |
+
(2362, 2364, 0),
|
| 39 |
+
(2366, 2383, 0),
|
| 40 |
+
(2385, 2391, 0),
|
| 41 |
+
(2402, 2403, 0),
|
| 42 |
+
(2433, 2435, 0),
|
| 43 |
+
(2492, 2492, 0),
|
| 44 |
+
(2494, 2500, 0),
|
| 45 |
+
(2503, 2504, 0),
|
| 46 |
+
(2507, 2509, 0),
|
| 47 |
+
(2519, 2519, 0),
|
| 48 |
+
(2530, 2531, 0),
|
| 49 |
+
(2558, 2558, 0),
|
| 50 |
+
(2561, 2563, 0),
|
| 51 |
+
(2620, 2620, 0),
|
| 52 |
+
(2622, 2626, 0),
|
| 53 |
+
(2631, 2632, 0),
|
| 54 |
+
(2635, 2637, 0),
|
| 55 |
+
(2641, 2641, 0),
|
| 56 |
+
(2672, 2673, 0),
|
| 57 |
+
(2677, 2677, 0),
|
| 58 |
+
(2689, 2691, 0),
|
| 59 |
+
(2748, 2748, 0),
|
| 60 |
+
(2750, 2757, 0),
|
| 61 |
+
(2759, 2761, 0),
|
| 62 |
+
(2763, 2765, 0),
|
| 63 |
+
(2786, 2787, 0),
|
| 64 |
+
(2810, 2815, 0),
|
| 65 |
+
(2817, 2819, 0),
|
| 66 |
+
(2876, 2876, 0),
|
| 67 |
+
(2878, 2884, 0),
|
| 68 |
+
(2887, 2888, 0),
|
| 69 |
+
(2891, 2893, 0),
|
| 70 |
+
(2901, 2903, 0),
|
| 71 |
+
(2914, 2915, 0),
|
| 72 |
+
(2946, 2946, 0),
|
| 73 |
+
(3006, 3010, 0),
|
| 74 |
+
(3014, 3016, 0),
|
| 75 |
+
(3018, 3021, 0),
|
| 76 |
+
(3031, 3031, 0),
|
| 77 |
+
(3072, 3076, 0),
|
| 78 |
+
(3132, 3132, 0),
|
| 79 |
+
(3134, 3140, 0),
|
| 80 |
+
(3142, 3144, 0),
|
| 81 |
+
(3146, 3149, 0),
|
| 82 |
+
(3157, 3158, 0),
|
| 83 |
+
(3170, 3171, 0),
|
| 84 |
+
(3201, 3203, 0),
|
| 85 |
+
(3260, 3260, 0),
|
| 86 |
+
(3262, 3268, 0),
|
| 87 |
+
(3270, 3272, 0),
|
| 88 |
+
(3274, 3277, 0),
|
| 89 |
+
(3285, 3286, 0),
|
| 90 |
+
(3298, 3299, 0),
|
| 91 |
+
(3315, 3315, 0),
|
| 92 |
+
(3328, 3331, 0),
|
| 93 |
+
(3387, 3388, 0),
|
| 94 |
+
(3390, 3396, 0),
|
| 95 |
+
(3398, 3400, 0),
|
| 96 |
+
(3402, 3405, 0),
|
| 97 |
+
(3415, 3415, 0),
|
| 98 |
+
(3426, 3427, 0),
|
| 99 |
+
(3457, 3459, 0),
|
| 100 |
+
(3530, 3530, 0),
|
| 101 |
+
(3535, 3540, 0),
|
| 102 |
+
(3542, 3542, 0),
|
| 103 |
+
(3544, 3551, 0),
|
| 104 |
+
(3570, 3571, 0),
|
| 105 |
+
(3633, 3633, 0),
|
| 106 |
+
(3636, 3642, 0),
|
| 107 |
+
(3655, 3662, 0),
|
| 108 |
+
(3761, 3761, 0),
|
| 109 |
+
(3764, 3772, 0),
|
| 110 |
+
(3784, 3790, 0),
|
| 111 |
+
(3864, 3865, 0),
|
| 112 |
+
(3893, 3893, 0),
|
| 113 |
+
(3895, 3895, 0),
|
| 114 |
+
(3897, 3897, 0),
|
| 115 |
+
(3902, 3903, 0),
|
| 116 |
+
(3953, 3972, 0),
|
| 117 |
+
(3974, 3975, 0),
|
| 118 |
+
(3981, 3991, 0),
|
| 119 |
+
(3993, 4028, 0),
|
| 120 |
+
(4038, 4038, 0),
|
| 121 |
+
(4139, 4158, 0),
|
| 122 |
+
(4182, 4185, 0),
|
| 123 |
+
(4190, 4192, 0),
|
| 124 |
+
(4194, 4196, 0),
|
| 125 |
+
(4199, 4205, 0),
|
| 126 |
+
(4209, 4212, 0),
|
| 127 |
+
(4226, 4237, 0),
|
| 128 |
+
(4239, 4239, 0),
|
| 129 |
+
(4250, 4253, 0),
|
| 130 |
+
(4352, 4447, 2),
|
| 131 |
+
(4448, 4607, 0),
|
| 132 |
+
(4957, 4959, 0),
|
| 133 |
+
(5906, 5909, 0),
|
| 134 |
+
(5938, 5940, 0),
|
| 135 |
+
(5970, 5971, 0),
|
| 136 |
+
(6002, 6003, 0),
|
| 137 |
+
(6068, 6099, 0),
|
| 138 |
+
(6109, 6109, 0),
|
| 139 |
+
(6155, 6159, 0),
|
| 140 |
+
(6277, 6278, 0),
|
| 141 |
+
(6313, 6313, 0),
|
| 142 |
+
(6432, 6443, 0),
|
| 143 |
+
(6448, 6459, 0),
|
| 144 |
+
(6679, 6683, 0),
|
| 145 |
+
(6741, 6750, 0),
|
| 146 |
+
(6752, 6780, 0),
|
| 147 |
+
(6783, 6783, 0),
|
| 148 |
+
(6832, 6862, 0),
|
| 149 |
+
(6912, 6916, 0),
|
| 150 |
+
(6964, 6980, 0),
|
| 151 |
+
(7019, 7027, 0),
|
| 152 |
+
(7040, 7042, 0),
|
| 153 |
+
(7073, 7085, 0),
|
| 154 |
+
(7142, 7155, 0),
|
| 155 |
+
(7204, 7223, 0),
|
| 156 |
+
(7376, 7378, 0),
|
| 157 |
+
(7380, 7400, 0),
|
| 158 |
+
(7405, 7405, 0),
|
| 159 |
+
(7412, 7412, 0),
|
| 160 |
+
(7415, 7417, 0),
|
| 161 |
+
(7616, 7679, 0),
|
| 162 |
+
(8203, 8207, 0),
|
| 163 |
+
(8232, 8238, 0),
|
| 164 |
+
(8288, 8292, 0),
|
| 165 |
+
(8294, 8303, 0),
|
| 166 |
+
(8400, 8432, 0),
|
| 167 |
+
(8986, 8987, 2),
|
| 168 |
+
(9001, 9002, 2),
|
| 169 |
+
(9193, 9196, 2),
|
| 170 |
+
(9200, 9200, 2),
|
| 171 |
+
(9203, 9203, 2),
|
| 172 |
+
(9725, 9726, 2),
|
| 173 |
+
(9748, 9749, 2),
|
| 174 |
+
(9800, 9811, 2),
|
| 175 |
+
(9855, 9855, 2),
|
| 176 |
+
(9875, 9875, 2),
|
| 177 |
+
(9889, 9889, 2),
|
| 178 |
+
(9898, 9899, 2),
|
| 179 |
+
(9917, 9918, 2),
|
| 180 |
+
(9924, 9925, 2),
|
| 181 |
+
(9934, 9934, 2),
|
| 182 |
+
(9940, 9940, 2),
|
| 183 |
+
(9962, 9962, 2),
|
| 184 |
+
(9970, 9971, 2),
|
| 185 |
+
(9973, 9973, 2),
|
| 186 |
+
(9978, 9978, 2),
|
| 187 |
+
(9981, 9981, 2),
|
| 188 |
+
(9989, 9989, 2),
|
| 189 |
+
(9994, 9995, 2),
|
| 190 |
+
(10024, 10024, 2),
|
| 191 |
+
(10060, 10060, 2),
|
| 192 |
+
(10062, 10062, 2),
|
| 193 |
+
(10067, 10069, 2),
|
| 194 |
+
(10071, 10071, 2),
|
| 195 |
+
(10133, 10135, 2),
|
| 196 |
+
(10160, 10160, 2),
|
| 197 |
+
(10175, 10175, 2),
|
| 198 |
+
(11035, 11036, 2),
|
| 199 |
+
(11088, 11088, 2),
|
| 200 |
+
(11093, 11093, 2),
|
| 201 |
+
(11503, 11505, 0),
|
| 202 |
+
(11647, 11647, 0),
|
| 203 |
+
(11744, 11775, 0),
|
| 204 |
+
(11904, 11929, 2),
|
| 205 |
+
(11931, 12019, 2),
|
| 206 |
+
(12032, 12245, 2),
|
| 207 |
+
(12272, 12329, 2),
|
| 208 |
+
(12330, 12335, 0),
|
| 209 |
+
(12336, 12350, 2),
|
| 210 |
+
(12353, 12438, 2),
|
| 211 |
+
(12441, 12442, 0),
|
| 212 |
+
(12443, 12543, 2),
|
| 213 |
+
(12549, 12591, 2),
|
| 214 |
+
(12593, 12686, 2),
|
| 215 |
+
(12688, 12771, 2),
|
| 216 |
+
(12783, 12830, 2),
|
| 217 |
+
(12832, 12871, 2),
|
| 218 |
+
(12880, 19903, 2),
|
| 219 |
+
(19968, 42124, 2),
|
| 220 |
+
(42128, 42182, 2),
|
| 221 |
+
(42607, 42610, 0),
|
| 222 |
+
(42612, 42621, 0),
|
| 223 |
+
(42654, 42655, 0),
|
| 224 |
+
(42736, 42737, 0),
|
| 225 |
+
(43010, 43010, 0),
|
| 226 |
+
(43014, 43014, 0),
|
| 227 |
+
(43019, 43019, 0),
|
| 228 |
+
(43043, 43047, 0),
|
| 229 |
+
(43052, 43052, 0),
|
| 230 |
+
(43136, 43137, 0),
|
| 231 |
+
(43188, 43205, 0),
|
| 232 |
+
(43232, 43249, 0),
|
| 233 |
+
(43263, 43263, 0),
|
| 234 |
+
(43302, 43309, 0),
|
| 235 |
+
(43335, 43347, 0),
|
| 236 |
+
(43360, 43388, 2),
|
| 237 |
+
(43392, 43395, 0),
|
| 238 |
+
(43443, 43456, 0),
|
| 239 |
+
(43493, 43493, 0),
|
| 240 |
+
(43561, 43574, 0),
|
| 241 |
+
(43587, 43587, 0),
|
| 242 |
+
(43596, 43597, 0),
|
| 243 |
+
(43643, 43645, 0),
|
| 244 |
+
(43696, 43696, 0),
|
| 245 |
+
(43698, 43700, 0),
|
| 246 |
+
(43703, 43704, 0),
|
| 247 |
+
(43710, 43711, 0),
|
| 248 |
+
(43713, 43713, 0),
|
| 249 |
+
(43755, 43759, 0),
|
| 250 |
+
(43765, 43766, 0),
|
| 251 |
+
(44003, 44010, 0),
|
| 252 |
+
(44012, 44013, 0),
|
| 253 |
+
(44032, 55203, 2),
|
| 254 |
+
(55216, 55295, 0),
|
| 255 |
+
(63744, 64255, 2),
|
| 256 |
+
(64286, 64286, 0),
|
| 257 |
+
(65024, 65039, 0),
|
| 258 |
+
(65040, 65049, 2),
|
| 259 |
+
(65056, 65071, 0),
|
| 260 |
+
(65072, 65106, 2),
|
| 261 |
+
(65108, 65126, 2),
|
| 262 |
+
(65128, 65131, 2),
|
| 263 |
+
(65279, 65279, 0),
|
| 264 |
+
(65281, 65376, 2),
|
| 265 |
+
(65504, 65510, 2),
|
| 266 |
+
(65529, 65531, 0),
|
| 267 |
+
(66045, 66045, 0),
|
| 268 |
+
(66272, 66272, 0),
|
| 269 |
+
(66422, 66426, 0),
|
| 270 |
+
(68097, 68099, 0),
|
| 271 |
+
(68101, 68102, 0),
|
| 272 |
+
(68108, 68111, 0),
|
| 273 |
+
(68152, 68154, 0),
|
| 274 |
+
(68159, 68159, 0),
|
| 275 |
+
(68325, 68326, 0),
|
| 276 |
+
(68900, 68903, 0),
|
| 277 |
+
(69291, 69292, 0),
|
| 278 |
+
(69373, 69375, 0),
|
| 279 |
+
(69446, 69456, 0),
|
| 280 |
+
(69506, 69509, 0),
|
| 281 |
+
(69632, 69634, 0),
|
| 282 |
+
(69688, 69702, 0),
|
| 283 |
+
(69744, 69744, 0),
|
| 284 |
+
(69747, 69748, 0),
|
| 285 |
+
(69759, 69762, 0),
|
| 286 |
+
(69808, 69818, 0),
|
| 287 |
+
(69821, 69821, 0),
|
| 288 |
+
(69826, 69826, 0),
|
| 289 |
+
(69837, 69837, 0),
|
| 290 |
+
(69888, 69890, 0),
|
| 291 |
+
(69927, 69940, 0),
|
| 292 |
+
(69957, 69958, 0),
|
| 293 |
+
(70003, 70003, 0),
|
| 294 |
+
(70016, 70018, 0),
|
| 295 |
+
(70067, 70080, 0),
|
| 296 |
+
(70089, 70092, 0),
|
| 297 |
+
(70094, 70095, 0),
|
| 298 |
+
(70188, 70199, 0),
|
| 299 |
+
(70206, 70206, 0),
|
| 300 |
+
(70209, 70209, 0),
|
| 301 |
+
(70367, 70378, 0),
|
| 302 |
+
(70400, 70403, 0),
|
| 303 |
+
(70459, 70460, 0),
|
| 304 |
+
(70462, 70468, 0),
|
| 305 |
+
(70471, 70472, 0),
|
| 306 |
+
(70475, 70477, 0),
|
| 307 |
+
(70487, 70487, 0),
|
| 308 |
+
(70498, 70499, 0),
|
| 309 |
+
(70502, 70508, 0),
|
| 310 |
+
(70512, 70516, 0),
|
| 311 |
+
(70709, 70726, 0),
|
| 312 |
+
(70750, 70750, 0),
|
| 313 |
+
(70832, 70851, 0),
|
| 314 |
+
(71087, 71093, 0),
|
| 315 |
+
(71096, 71104, 0),
|
| 316 |
+
(71132, 71133, 0),
|
| 317 |
+
(71216, 71232, 0),
|
| 318 |
+
(71339, 71351, 0),
|
| 319 |
+
(71453, 71467, 0),
|
| 320 |
+
(71724, 71738, 0),
|
| 321 |
+
(71984, 71989, 0),
|
| 322 |
+
(71991, 71992, 0),
|
| 323 |
+
(71995, 71998, 0),
|
| 324 |
+
(72000, 72000, 0),
|
| 325 |
+
(72002, 72003, 0),
|
| 326 |
+
(72145, 72151, 0),
|
| 327 |
+
(72154, 72160, 0),
|
| 328 |
+
(72164, 72164, 0),
|
| 329 |
+
(72193, 72202, 0),
|
| 330 |
+
(72243, 72249, 0),
|
| 331 |
+
(72251, 72254, 0),
|
| 332 |
+
(72263, 72263, 0),
|
| 333 |
+
(72273, 72283, 0),
|
| 334 |
+
(72330, 72345, 0),
|
| 335 |
+
(72751, 72758, 0),
|
| 336 |
+
(72760, 72767, 0),
|
| 337 |
+
(72850, 72871, 0),
|
| 338 |
+
(72873, 72886, 0),
|
| 339 |
+
(73009, 73014, 0),
|
| 340 |
+
(73018, 73018, 0),
|
| 341 |
+
(73020, 73021, 0),
|
| 342 |
+
(73023, 73029, 0),
|
| 343 |
+
(73031, 73031, 0),
|
| 344 |
+
(73098, 73102, 0),
|
| 345 |
+
(73104, 73105, 0),
|
| 346 |
+
(73107, 73111, 0),
|
| 347 |
+
(73459, 73462, 0),
|
| 348 |
+
(73472, 73473, 0),
|
| 349 |
+
(73475, 73475, 0),
|
| 350 |
+
(73524, 73530, 0),
|
| 351 |
+
(73534, 73538, 0),
|
| 352 |
+
(78896, 78912, 0),
|
| 353 |
+
(78919, 78933, 0),
|
| 354 |
+
(92912, 92916, 0),
|
| 355 |
+
(92976, 92982, 0),
|
| 356 |
+
(94031, 94031, 0),
|
| 357 |
+
(94033, 94087, 0),
|
| 358 |
+
(94095, 94098, 0),
|
| 359 |
+
(94176, 94179, 2),
|
| 360 |
+
(94180, 94180, 0),
|
| 361 |
+
(94192, 94193, 0),
|
| 362 |
+
(94208, 100343, 2),
|
| 363 |
+
(100352, 101589, 2),
|
| 364 |
+
(101632, 101640, 2),
|
| 365 |
+
(110576, 110579, 2),
|
| 366 |
+
(110581, 110587, 2),
|
| 367 |
+
(110589, 110590, 2),
|
| 368 |
+
(110592, 110882, 2),
|
| 369 |
+
(110898, 110898, 2),
|
| 370 |
+
(110928, 110930, 2),
|
| 371 |
+
(110933, 110933, 2),
|
| 372 |
+
(110948, 110951, 2),
|
| 373 |
+
(110960, 111355, 2),
|
| 374 |
+
(113821, 113822, 0),
|
| 375 |
+
(113824, 113827, 0),
|
| 376 |
+
(118528, 118573, 0),
|
| 377 |
+
(118576, 118598, 0),
|
| 378 |
+
(119141, 119145, 0),
|
| 379 |
+
(119149, 119170, 0),
|
| 380 |
+
(119173, 119179, 0),
|
| 381 |
+
(119210, 119213, 0),
|
| 382 |
+
(119362, 119364, 0),
|
| 383 |
+
(121344, 121398, 0),
|
| 384 |
+
(121403, 121452, 0),
|
| 385 |
+
(121461, 121461, 0),
|
| 386 |
+
(121476, 121476, 0),
|
| 387 |
+
(121499, 121503, 0),
|
| 388 |
+
(121505, 121519, 0),
|
| 389 |
+
(122880, 122886, 0),
|
| 390 |
+
(122888, 122904, 0),
|
| 391 |
+
(122907, 122913, 0),
|
| 392 |
+
(122915, 122916, 0),
|
| 393 |
+
(122918, 122922, 0),
|
| 394 |
+
(123023, 123023, 0),
|
| 395 |
+
(123184, 123190, 0),
|
| 396 |
+
(123566, 123566, 0),
|
| 397 |
+
(123628, 123631, 0),
|
| 398 |
+
(124140, 124143, 0),
|
| 399 |
+
(125136, 125142, 0),
|
| 400 |
+
(125252, 125258, 0),
|
| 401 |
+
(126980, 126980, 2),
|
| 402 |
+
(127183, 127183, 2),
|
| 403 |
+
(127374, 127374, 2),
|
| 404 |
+
(127377, 127386, 2),
|
| 405 |
+
(127488, 127490, 2),
|
| 406 |
+
(127504, 127547, 2),
|
| 407 |
+
(127552, 127560, 2),
|
| 408 |
+
(127568, 127569, 2),
|
| 409 |
+
(127584, 127589, 2),
|
| 410 |
+
(127744, 127776, 2),
|
| 411 |
+
(127789, 127797, 2),
|
| 412 |
+
(127799, 127868, 2),
|
| 413 |
+
(127870, 127891, 2),
|
| 414 |
+
(127904, 127946, 2),
|
| 415 |
+
(127951, 127955, 2),
|
| 416 |
+
(127968, 127984, 2),
|
| 417 |
+
(127988, 127988, 2),
|
| 418 |
+
(127992, 127994, 2),
|
| 419 |
+
(127995, 127999, 0),
|
| 420 |
+
(128000, 128062, 2),
|
| 421 |
+
(128064, 128064, 2),
|
| 422 |
+
(128066, 128252, 2),
|
| 423 |
+
(128255, 128317, 2),
|
| 424 |
+
(128331, 128334, 2),
|
| 425 |
+
(128336, 128359, 2),
|
| 426 |
+
(128378, 128378, 2),
|
| 427 |
+
(128405, 128406, 2),
|
| 428 |
+
(128420, 128420, 2),
|
| 429 |
+
(128507, 128591, 2),
|
| 430 |
+
(128640, 128709, 2),
|
| 431 |
+
(128716, 128716, 2),
|
| 432 |
+
(128720, 128722, 2),
|
| 433 |
+
(128725, 128727, 2),
|
| 434 |
+
(128732, 128735, 2),
|
| 435 |
+
(128747, 128748, 2),
|
| 436 |
+
(128756, 128764, 2),
|
| 437 |
+
(128992, 129003, 2),
|
| 438 |
+
(129008, 129008, 2),
|
| 439 |
+
(129292, 129338, 2),
|
| 440 |
+
(129340, 129349, 2),
|
| 441 |
+
(129351, 129535, 2),
|
| 442 |
+
(129648, 129660, 2),
|
| 443 |
+
(129664, 129672, 2),
|
| 444 |
+
(129680, 129725, 2),
|
| 445 |
+
(129727, 129733, 2),
|
| 446 |
+
(129742, 129755, 2),
|
| 447 |
+
(129760, 129768, 2),
|
| 448 |
+
(129776, 129784, 2),
|
| 449 |
+
(131072, 196605, 2),
|
| 450 |
+
(196608, 262141, 2),
|
| 451 |
+
(917505, 917505, 0),
|
| 452 |
+
(917536, 917631, 0),
|
| 453 |
+
(917760, 917999, 0),
|
| 454 |
+
]
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_emoji_codes.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_emoji_replace.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Callable, Match, Optional
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
from ._emoji_codes import EMOJI
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_ReStringMatch = Match[str] # regex match object
|
| 8 |
+
_ReSubCallable = Callable[[_ReStringMatch], str] # Callable invoked by re.sub
|
| 9 |
+
_EmojiSubMethod = Callable[[_ReSubCallable, str], str] # Sub method of a compiled re
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def _emoji_replace(
|
| 13 |
+
text: str,
|
| 14 |
+
default_variant: Optional[str] = None,
|
| 15 |
+
_emoji_sub: _EmojiSubMethod = re.compile(r"(:(\S*?)(?:(?:\-)(emoji|text))?:)").sub,
|
| 16 |
+
) -> str:
|
| 17 |
+
"""Replace emoji code in text."""
|
| 18 |
+
get_emoji = EMOJI.__getitem__
|
| 19 |
+
variants = {"text": "\uFE0E", "emoji": "\uFE0F"}
|
| 20 |
+
get_variant = variants.get
|
| 21 |
+
default_variant_code = variants.get(default_variant, "") if default_variant else ""
|
| 22 |
+
|
| 23 |
+
def do_replace(match: Match[str]) -> str:
|
| 24 |
+
emoji_code, emoji_name, variant = match.groups()
|
| 25 |
+
try:
|
| 26 |
+
return get_emoji(emoji_name.lower()) + get_variant(
|
| 27 |
+
variant, default_variant_code
|
| 28 |
+
)
|
| 29 |
+
except KeyError:
|
| 30 |
+
return emoji_code
|
| 31 |
+
|
| 32 |
+
return _emoji_sub(do_replace, text)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_export_format.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
CONSOLE_HTML_FORMAT = """\
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
+
<html>
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8">
|
| 6 |
+
<style>
|
| 7 |
+
{stylesheet}
|
| 8 |
+
body {{
|
| 9 |
+
color: {foreground};
|
| 10 |
+
background-color: {background};
|
| 11 |
+
}}
|
| 12 |
+
</style>
|
| 13 |
+
</head>
|
| 14 |
+
<body>
|
| 15 |
+
<pre style="font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace"><code style="font-family:inherit">{code}</code></pre>
|
| 16 |
+
</body>
|
| 17 |
+
</html>
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
CONSOLE_SVG_FORMAT = """\
|
| 21 |
+
<svg class="rich-terminal" viewBox="0 0 {width} {height}" xmlns="http://www.w3.org/2000/svg">
|
| 22 |
+
<!-- Generated with Rich https://www.textualize.io -->
|
| 23 |
+
<style>
|
| 24 |
+
|
| 25 |
+
@font-face {{
|
| 26 |
+
font-family: "Fira Code";
|
| 27 |
+
src: local("FiraCode-Regular"),
|
| 28 |
+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Regular.woff2") format("woff2"),
|
| 29 |
+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Regular.woff") format("woff");
|
| 30 |
+
font-style: normal;
|
| 31 |
+
font-weight: 400;
|
| 32 |
+
}}
|
| 33 |
+
@font-face {{
|
| 34 |
+
font-family: "Fira Code";
|
| 35 |
+
src: local("FiraCode-Bold"),
|
| 36 |
+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff2/FiraCode-Bold.woff2") format("woff2"),
|
| 37 |
+
url("https://cdnjs.cloudflare.com/ajax/libs/firacode/6.2.0/woff/FiraCode-Bold.woff") format("woff");
|
| 38 |
+
font-style: bold;
|
| 39 |
+
font-weight: 700;
|
| 40 |
+
}}
|
| 41 |
+
|
| 42 |
+
.{unique_id}-matrix {{
|
| 43 |
+
font-family: Fira Code, monospace;
|
| 44 |
+
font-size: {char_height}px;
|
| 45 |
+
line-height: {line_height}px;
|
| 46 |
+
font-variant-east-asian: full-width;
|
| 47 |
+
}}
|
| 48 |
+
|
| 49 |
+
.{unique_id}-title {{
|
| 50 |
+
font-size: 18px;
|
| 51 |
+
font-weight: bold;
|
| 52 |
+
font-family: arial;
|
| 53 |
+
}}
|
| 54 |
+
|
| 55 |
+
{styles}
|
| 56 |
+
</style>
|
| 57 |
+
|
| 58 |
+
<defs>
|
| 59 |
+
<clipPath id="{unique_id}-clip-terminal">
|
| 60 |
+
<rect x="0" y="0" width="{terminal_width}" height="{terminal_height}" />
|
| 61 |
+
</clipPath>
|
| 62 |
+
{lines}
|
| 63 |
+
</defs>
|
| 64 |
+
|
| 65 |
+
{chrome}
|
| 66 |
+
<g transform="translate({terminal_x}, {terminal_y})" clip-path="url(#{unique_id}-clip-terminal)">
|
| 67 |
+
{backgrounds}
|
| 68 |
+
<g class="{unique_id}-matrix">
|
| 69 |
+
{matrix}
|
| 70 |
+
</g>
|
| 71 |
+
</g>
|
| 72 |
+
</svg>
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
_SVG_FONT_FAMILY = "Rich Fira Code"
|
| 76 |
+
_SVG_CLASSES_PREFIX = "rich-svg"
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_extension.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def load_ipython_extension(ip: Any) -> None: # pragma: no cover
|
| 5 |
+
# prevent circular import
|
| 6 |
+
from rich.pretty import install
|
| 7 |
+
from rich.traceback import install as tr_install
|
| 8 |
+
|
| 9 |
+
install()
|
| 10 |
+
tr_install()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_inspect.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import inspect
|
| 2 |
+
from inspect import cleandoc, getdoc, getfile, isclass, ismodule, signature
|
| 3 |
+
from typing import Any, Collection, Iterable, Optional, Tuple, Type, Union
|
| 4 |
+
|
| 5 |
+
from .console import Group, RenderableType
|
| 6 |
+
from .control import escape_control_codes
|
| 7 |
+
from .highlighter import ReprHighlighter
|
| 8 |
+
from .jupyter import JupyterMixin
|
| 9 |
+
from .panel import Panel
|
| 10 |
+
from .pretty import Pretty
|
| 11 |
+
from .table import Table
|
| 12 |
+
from .text import Text, TextType
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _first_paragraph(doc: str) -> str:
|
| 16 |
+
"""Get the first paragraph from a docstring."""
|
| 17 |
+
paragraph, _, _ = doc.partition("\n\n")
|
| 18 |
+
return paragraph
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class Inspect(JupyterMixin):
|
| 22 |
+
"""A renderable to inspect any Python Object.
|
| 23 |
+
|
| 24 |
+
Args:
|
| 25 |
+
obj (Any): An object to inspect.
|
| 26 |
+
title (str, optional): Title to display over inspect result, or None use type. Defaults to None.
|
| 27 |
+
help (bool, optional): Show full help text rather than just first paragraph. Defaults to False.
|
| 28 |
+
methods (bool, optional): Enable inspection of callables. Defaults to False.
|
| 29 |
+
docs (bool, optional): Also render doc strings. Defaults to True.
|
| 30 |
+
private (bool, optional): Show private attributes (beginning with underscore). Defaults to False.
|
| 31 |
+
dunder (bool, optional): Show attributes starting with double underscore. Defaults to False.
|
| 32 |
+
sort (bool, optional): Sort attributes alphabetically. Defaults to True.
|
| 33 |
+
all (bool, optional): Show all attributes. Defaults to False.
|
| 34 |
+
value (bool, optional): Pretty print value of object. Defaults to True.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
def __init__(
|
| 38 |
+
self,
|
| 39 |
+
obj: Any,
|
| 40 |
+
*,
|
| 41 |
+
title: Optional[TextType] = None,
|
| 42 |
+
help: bool = False,
|
| 43 |
+
methods: bool = False,
|
| 44 |
+
docs: bool = True,
|
| 45 |
+
private: bool = False,
|
| 46 |
+
dunder: bool = False,
|
| 47 |
+
sort: bool = True,
|
| 48 |
+
all: bool = True,
|
| 49 |
+
value: bool = True,
|
| 50 |
+
) -> None:
|
| 51 |
+
self.highlighter = ReprHighlighter()
|
| 52 |
+
self.obj = obj
|
| 53 |
+
self.title = title or self._make_title(obj)
|
| 54 |
+
if all:
|
| 55 |
+
methods = private = dunder = True
|
| 56 |
+
self.help = help
|
| 57 |
+
self.methods = methods
|
| 58 |
+
self.docs = docs or help
|
| 59 |
+
self.private = private or dunder
|
| 60 |
+
self.dunder = dunder
|
| 61 |
+
self.sort = sort
|
| 62 |
+
self.value = value
|
| 63 |
+
|
| 64 |
+
def _make_title(self, obj: Any) -> Text:
|
| 65 |
+
"""Make a default title."""
|
| 66 |
+
title_str = (
|
| 67 |
+
str(obj)
|
| 68 |
+
if (isclass(obj) or callable(obj) or ismodule(obj))
|
| 69 |
+
else str(type(obj))
|
| 70 |
+
)
|
| 71 |
+
title_text = self.highlighter(title_str)
|
| 72 |
+
return title_text
|
| 73 |
+
|
| 74 |
+
def __rich__(self) -> Panel:
|
| 75 |
+
return Panel.fit(
|
| 76 |
+
Group(*self._render()),
|
| 77 |
+
title=self.title,
|
| 78 |
+
border_style="scope.border",
|
| 79 |
+
padding=(0, 1),
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
def _get_signature(self, name: str, obj: Any) -> Optional[Text]:
|
| 83 |
+
"""Get a signature for a callable."""
|
| 84 |
+
try:
|
| 85 |
+
_signature = str(signature(obj)) + ":"
|
| 86 |
+
except ValueError:
|
| 87 |
+
_signature = "(...)"
|
| 88 |
+
except TypeError:
|
| 89 |
+
return None
|
| 90 |
+
|
| 91 |
+
source_filename: Optional[str] = None
|
| 92 |
+
try:
|
| 93 |
+
source_filename = getfile(obj)
|
| 94 |
+
except (OSError, TypeError):
|
| 95 |
+
# OSError is raised if obj has no source file, e.g. when defined in REPL.
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
+
callable_name = Text(name, style="inspect.callable")
|
| 99 |
+
if source_filename:
|
| 100 |
+
callable_name.stylize(f"link file://{source_filename}")
|
| 101 |
+
signature_text = self.highlighter(_signature)
|
| 102 |
+
|
| 103 |
+
qualname = name or getattr(obj, "__qualname__", name)
|
| 104 |
+
|
| 105 |
+
# If obj is a module, there may be classes (which are callable) to display
|
| 106 |
+
if inspect.isclass(obj):
|
| 107 |
+
prefix = "class"
|
| 108 |
+
elif inspect.iscoroutinefunction(obj):
|
| 109 |
+
prefix = "async def"
|
| 110 |
+
else:
|
| 111 |
+
prefix = "def"
|
| 112 |
+
|
| 113 |
+
qual_signature = Text.assemble(
|
| 114 |
+
(f"{prefix} ", f"inspect.{prefix.replace(' ', '_')}"),
|
| 115 |
+
(qualname, "inspect.callable"),
|
| 116 |
+
signature_text,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
return qual_signature
|
| 120 |
+
|
| 121 |
+
def _render(self) -> Iterable[RenderableType]:
|
| 122 |
+
"""Render object."""
|
| 123 |
+
|
| 124 |
+
def sort_items(item: Tuple[str, Any]) -> Tuple[bool, str]:
|
| 125 |
+
key, (_error, value) = item
|
| 126 |
+
return (callable(value), key.strip("_").lower())
|
| 127 |
+
|
| 128 |
+
def safe_getattr(attr_name: str) -> Tuple[Any, Any]:
|
| 129 |
+
"""Get attribute or any exception."""
|
| 130 |
+
try:
|
| 131 |
+
return (None, getattr(obj, attr_name))
|
| 132 |
+
except Exception as error:
|
| 133 |
+
return (error, None)
|
| 134 |
+
|
| 135 |
+
obj = self.obj
|
| 136 |
+
keys = dir(obj)
|
| 137 |
+
total_items = len(keys)
|
| 138 |
+
if not self.dunder:
|
| 139 |
+
keys = [key for key in keys if not key.startswith("__")]
|
| 140 |
+
if not self.private:
|
| 141 |
+
keys = [key for key in keys if not key.startswith("_")]
|
| 142 |
+
not_shown_count = total_items - len(keys)
|
| 143 |
+
items = [(key, safe_getattr(key)) for key in keys]
|
| 144 |
+
if self.sort:
|
| 145 |
+
items.sort(key=sort_items)
|
| 146 |
+
|
| 147 |
+
items_table = Table.grid(padding=(0, 1), expand=False)
|
| 148 |
+
items_table.add_column(justify="right")
|
| 149 |
+
add_row = items_table.add_row
|
| 150 |
+
highlighter = self.highlighter
|
| 151 |
+
|
| 152 |
+
if callable(obj):
|
| 153 |
+
signature = self._get_signature("", obj)
|
| 154 |
+
if signature is not None:
|
| 155 |
+
yield signature
|
| 156 |
+
yield ""
|
| 157 |
+
|
| 158 |
+
if self.docs:
|
| 159 |
+
_doc = self._get_formatted_doc(obj)
|
| 160 |
+
if _doc is not None:
|
| 161 |
+
doc_text = Text(_doc, style="inspect.help")
|
| 162 |
+
doc_text = highlighter(doc_text)
|
| 163 |
+
yield doc_text
|
| 164 |
+
yield ""
|
| 165 |
+
|
| 166 |
+
if self.value and not (isclass(obj) or callable(obj) or ismodule(obj)):
|
| 167 |
+
yield Panel(
|
| 168 |
+
Pretty(obj, indent_guides=True, max_length=10, max_string=60),
|
| 169 |
+
border_style="inspect.value.border",
|
| 170 |
+
)
|
| 171 |
+
yield ""
|
| 172 |
+
|
| 173 |
+
for key, (error, value) in items:
|
| 174 |
+
key_text = Text.assemble(
|
| 175 |
+
(
|
| 176 |
+
key,
|
| 177 |
+
"inspect.attr.dunder" if key.startswith("__") else "inspect.attr",
|
| 178 |
+
),
|
| 179 |
+
(" =", "inspect.equals"),
|
| 180 |
+
)
|
| 181 |
+
if error is not None:
|
| 182 |
+
warning = key_text.copy()
|
| 183 |
+
warning.stylize("inspect.error")
|
| 184 |
+
add_row(warning, highlighter(repr(error)))
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
if callable(value):
|
| 188 |
+
if not self.methods:
|
| 189 |
+
continue
|
| 190 |
+
|
| 191 |
+
_signature_text = self._get_signature(key, value)
|
| 192 |
+
if _signature_text is None:
|
| 193 |
+
add_row(key_text, Pretty(value, highlighter=highlighter))
|
| 194 |
+
else:
|
| 195 |
+
if self.docs:
|
| 196 |
+
docs = self._get_formatted_doc(value)
|
| 197 |
+
if docs is not None:
|
| 198 |
+
_signature_text.append("\n" if "\n" in docs else " ")
|
| 199 |
+
doc = highlighter(docs)
|
| 200 |
+
doc.stylize("inspect.doc")
|
| 201 |
+
_signature_text.append(doc)
|
| 202 |
+
|
| 203 |
+
add_row(key_text, _signature_text)
|
| 204 |
+
else:
|
| 205 |
+
add_row(key_text, Pretty(value, highlighter=highlighter))
|
| 206 |
+
if items_table.row_count:
|
| 207 |
+
yield items_table
|
| 208 |
+
elif not_shown_count:
|
| 209 |
+
yield Text.from_markup(
|
| 210 |
+
f"[b cyan]{not_shown_count}[/][i] attribute(s) not shown.[/i] "
|
| 211 |
+
f"Run [b][magenta]inspect[/]([not b]inspect[/])[/b] for options."
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
def _get_formatted_doc(self, object_: Any) -> Optional[str]:
|
| 215 |
+
"""
|
| 216 |
+
Extract the docstring of an object, process it and returns it.
|
| 217 |
+
The processing consists in cleaning up the doctring's indentation,
|
| 218 |
+
taking only its 1st paragraph if `self.help` is not True,
|
| 219 |
+
and escape its control codes.
|
| 220 |
+
|
| 221 |
+
Args:
|
| 222 |
+
object_ (Any): the object to get the docstring from.
|
| 223 |
+
|
| 224 |
+
Returns:
|
| 225 |
+
Optional[str]: the processed docstring, or None if no docstring was found.
|
| 226 |
+
"""
|
| 227 |
+
docs = getdoc(object_)
|
| 228 |
+
if docs is None:
|
| 229 |
+
return None
|
| 230 |
+
docs = cleandoc(docs).strip()
|
| 231 |
+
if not self.help:
|
| 232 |
+
docs = _first_paragraph(docs)
|
| 233 |
+
return escape_control_codes(docs)
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def get_object_types_mro(obj: Union[object, Type[Any]]) -> Tuple[type, ...]:
|
| 237 |
+
"""Returns the MRO of an object's class, or of the object itself if it's a class."""
|
| 238 |
+
if not hasattr(obj, "__mro__"):
|
| 239 |
+
# N.B. we cannot use `if type(obj) is type` here because it doesn't work with
|
| 240 |
+
# some types of classes, such as the ones that use abc.ABCMeta.
|
| 241 |
+
obj = type(obj)
|
| 242 |
+
return getattr(obj, "__mro__", ())
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def get_object_types_mro_as_strings(obj: object) -> Collection[str]:
|
| 246 |
+
"""
|
| 247 |
+
Returns the MRO of an object's class as full qualified names, or of the object itself if it's a class.
|
| 248 |
+
|
| 249 |
+
Examples:
|
| 250 |
+
`object_types_mro_as_strings(JSONDecoder)` will return `['json.decoder.JSONDecoder', 'builtins.object']`
|
| 251 |
+
"""
|
| 252 |
+
return [
|
| 253 |
+
f'{getattr(type_, "__module__", "")}.{getattr(type_, "__qualname__", "")}'
|
| 254 |
+
for type_ in get_object_types_mro(obj)
|
| 255 |
+
]
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
def is_object_one_of_types(
|
| 259 |
+
obj: object, fully_qualified_types_names: Collection[str]
|
| 260 |
+
) -> bool:
|
| 261 |
+
"""
|
| 262 |
+
Returns `True` if the given object's class (or the object itself, if it's a class) has one of the
|
| 263 |
+
fully qualified names in its MRO.
|
| 264 |
+
"""
|
| 265 |
+
for type_name in get_object_types_mro_as_strings(obj):
|
| 266 |
+
if type_name in fully_qualified_types_names:
|
| 267 |
+
return True
|
| 268 |
+
return False
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_log_render.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
from typing import Iterable, List, Optional, TYPE_CHECKING, Union, Callable
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
from .text import Text, TextType
|
| 6 |
+
|
| 7 |
+
if TYPE_CHECKING:
|
| 8 |
+
from .console import Console, ConsoleRenderable, RenderableType
|
| 9 |
+
from .table import Table
|
| 10 |
+
|
| 11 |
+
FormatTimeCallable = Callable[[datetime], Text]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class LogRender:
|
| 15 |
+
def __init__(
|
| 16 |
+
self,
|
| 17 |
+
show_time: bool = True,
|
| 18 |
+
show_level: bool = False,
|
| 19 |
+
show_path: bool = True,
|
| 20 |
+
time_format: Union[str, FormatTimeCallable] = "[%x %X]",
|
| 21 |
+
omit_repeated_times: bool = True,
|
| 22 |
+
level_width: Optional[int] = 8,
|
| 23 |
+
) -> None:
|
| 24 |
+
self.show_time = show_time
|
| 25 |
+
self.show_level = show_level
|
| 26 |
+
self.show_path = show_path
|
| 27 |
+
self.time_format = time_format
|
| 28 |
+
self.omit_repeated_times = omit_repeated_times
|
| 29 |
+
self.level_width = level_width
|
| 30 |
+
self._last_time: Optional[Text] = None
|
| 31 |
+
|
| 32 |
+
def __call__(
|
| 33 |
+
self,
|
| 34 |
+
console: "Console",
|
| 35 |
+
renderables: Iterable["ConsoleRenderable"],
|
| 36 |
+
log_time: Optional[datetime] = None,
|
| 37 |
+
time_format: Optional[Union[str, FormatTimeCallable]] = None,
|
| 38 |
+
level: TextType = "",
|
| 39 |
+
path: Optional[str] = None,
|
| 40 |
+
line_no: Optional[int] = None,
|
| 41 |
+
link_path: Optional[str] = None,
|
| 42 |
+
) -> "Table":
|
| 43 |
+
from .containers import Renderables
|
| 44 |
+
from .table import Table
|
| 45 |
+
|
| 46 |
+
output = Table.grid(padding=(0, 1))
|
| 47 |
+
output.expand = True
|
| 48 |
+
if self.show_time:
|
| 49 |
+
output.add_column(style="log.time")
|
| 50 |
+
if self.show_level:
|
| 51 |
+
output.add_column(style="log.level", width=self.level_width)
|
| 52 |
+
output.add_column(ratio=1, style="log.message", overflow="fold")
|
| 53 |
+
if self.show_path and path:
|
| 54 |
+
output.add_column(style="log.path")
|
| 55 |
+
row: List["RenderableType"] = []
|
| 56 |
+
if self.show_time:
|
| 57 |
+
log_time = log_time or console.get_datetime()
|
| 58 |
+
time_format = time_format or self.time_format
|
| 59 |
+
if callable(time_format):
|
| 60 |
+
log_time_display = time_format(log_time)
|
| 61 |
+
else:
|
| 62 |
+
log_time_display = Text(log_time.strftime(time_format))
|
| 63 |
+
if log_time_display == self._last_time and self.omit_repeated_times:
|
| 64 |
+
row.append(Text(" " * len(log_time_display)))
|
| 65 |
+
else:
|
| 66 |
+
row.append(log_time_display)
|
| 67 |
+
self._last_time = log_time_display
|
| 68 |
+
if self.show_level:
|
| 69 |
+
row.append(level)
|
| 70 |
+
|
| 71 |
+
row.append(Renderables(renderables))
|
| 72 |
+
if self.show_path and path:
|
| 73 |
+
path_text = Text()
|
| 74 |
+
path_text.append(
|
| 75 |
+
path, style=f"link file://{link_path}" if link_path else ""
|
| 76 |
+
)
|
| 77 |
+
if line_no:
|
| 78 |
+
path_text.append(":")
|
| 79 |
+
path_text.append(
|
| 80 |
+
f"{line_no}",
|
| 81 |
+
style=f"link file://{link_path}#{line_no}" if link_path else "",
|
| 82 |
+
)
|
| 83 |
+
row.append(path_text)
|
| 84 |
+
|
| 85 |
+
output.add_row(*row)
|
| 86 |
+
return output
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__": # pragma: no cover
|
| 90 |
+
from rich.console import Console
|
| 91 |
+
|
| 92 |
+
c = Console()
|
| 93 |
+
c.print("[on blue]Hello", justify="right")
|
| 94 |
+
c.log("[on blue]hello", justify="right")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_loop.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Iterable, Tuple, TypeVar
|
| 2 |
+
|
| 3 |
+
T = TypeVar("T")
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def loop_first(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
|
| 7 |
+
"""Iterate and generate a tuple with a flag for first value."""
|
| 8 |
+
iter_values = iter(values)
|
| 9 |
+
try:
|
| 10 |
+
value = next(iter_values)
|
| 11 |
+
except StopIteration:
|
| 12 |
+
return
|
| 13 |
+
yield True, value
|
| 14 |
+
for value in iter_values:
|
| 15 |
+
yield False, value
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
|
| 19 |
+
"""Iterate and generate a tuple with a flag for last value."""
|
| 20 |
+
iter_values = iter(values)
|
| 21 |
+
try:
|
| 22 |
+
previous_value = next(iter_values)
|
| 23 |
+
except StopIteration:
|
| 24 |
+
return
|
| 25 |
+
for value in iter_values:
|
| 26 |
+
yield False, previous_value
|
| 27 |
+
previous_value = value
|
| 28 |
+
yield True, previous_value
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def loop_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]:
|
| 32 |
+
"""Iterate and generate a tuple with a flag for first and last value."""
|
| 33 |
+
iter_values = iter(values)
|
| 34 |
+
try:
|
| 35 |
+
previous_value = next(iter_values)
|
| 36 |
+
except StopIteration:
|
| 37 |
+
return
|
| 38 |
+
first = True
|
| 39 |
+
for value in iter_values:
|
| 40 |
+
yield first, False, previous_value
|
| 41 |
+
first = False
|
| 42 |
+
previous_value = value
|
| 43 |
+
yield first, True, previous_value
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_null_file.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from types import TracebackType
|
| 2 |
+
from typing import IO, Iterable, Iterator, List, Optional, Type
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class NullFile(IO[str]):
|
| 6 |
+
def close(self) -> None:
|
| 7 |
+
pass
|
| 8 |
+
|
| 9 |
+
def isatty(self) -> bool:
|
| 10 |
+
return False
|
| 11 |
+
|
| 12 |
+
def read(self, __n: int = 1) -> str:
|
| 13 |
+
return ""
|
| 14 |
+
|
| 15 |
+
def readable(self) -> bool:
|
| 16 |
+
return False
|
| 17 |
+
|
| 18 |
+
def readline(self, __limit: int = 1) -> str:
|
| 19 |
+
return ""
|
| 20 |
+
|
| 21 |
+
def readlines(self, __hint: int = 1) -> List[str]:
|
| 22 |
+
return []
|
| 23 |
+
|
| 24 |
+
def seek(self, __offset: int, __whence: int = 1) -> int:
|
| 25 |
+
return 0
|
| 26 |
+
|
| 27 |
+
def seekable(self) -> bool:
|
| 28 |
+
return False
|
| 29 |
+
|
| 30 |
+
def tell(self) -> int:
|
| 31 |
+
return 0
|
| 32 |
+
|
| 33 |
+
def truncate(self, __size: Optional[int] = 1) -> int:
|
| 34 |
+
return 0
|
| 35 |
+
|
| 36 |
+
def writable(self) -> bool:
|
| 37 |
+
return False
|
| 38 |
+
|
| 39 |
+
def writelines(self, __lines: Iterable[str]) -> None:
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
def __next__(self) -> str:
|
| 43 |
+
return ""
|
| 44 |
+
|
| 45 |
+
def __iter__(self) -> Iterator[str]:
|
| 46 |
+
return iter([""])
|
| 47 |
+
|
| 48 |
+
def __enter__(self) -> IO[str]:
|
| 49 |
+
return self
|
| 50 |
+
|
| 51 |
+
def __exit__(
|
| 52 |
+
self,
|
| 53 |
+
__t: Optional[Type[BaseException]],
|
| 54 |
+
__value: Optional[BaseException],
|
| 55 |
+
__traceback: Optional[TracebackType],
|
| 56 |
+
) -> None:
|
| 57 |
+
pass
|
| 58 |
+
|
| 59 |
+
def write(self, text: str) -> int:
|
| 60 |
+
return 0
|
| 61 |
+
|
| 62 |
+
def flush(self) -> None:
|
| 63 |
+
pass
|
| 64 |
+
|
| 65 |
+
def fileno(self) -> int:
|
| 66 |
+
return -1
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
NULL_FILE = NullFile()
|
Prism/LLaD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
[
|
| 7 |
+
(12, 12, 12),
|
| 8 |
+
(197, 15, 31),
|
| 9 |
+
(19, 161, 14),
|
| 10 |
+
(193, 156, 0),
|
| 11 |
+
(0, 55, 218),
|
| 12 |
+
(136, 23, 152),
|
| 13 |
+
(58, 150, 221),
|
| 14 |
+
(204, 204, 204),
|
| 15 |
+
(118, 118, 118),
|
| 16 |
+
(231, 72, 86),
|
| 17 |
+
(22, 198, 12),
|
| 18 |
+
(249, 241, 165),
|
| 19 |
+
(59, 120, 255),
|
| 20 |
+
(180, 0, 158),
|
| 21 |
+
(97, 214, 214),
|
| 22 |
+
(242, 242, 242),
|
| 23 |
+
]
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# # The standard ansi colors (including bright variants)
|
| 27 |
+
STANDARD_PALETTE = Palette(
|
| 28 |
+
[
|
| 29 |
+
(0, 0, 0),
|
| 30 |
+
(170, 0, 0),
|
| 31 |
+
(0, 170, 0),
|
| 32 |
+
(170, 85, 0),
|
| 33 |
+
(0, 0, 170),
|
| 34 |
+
(170, 0, 170),
|
| 35 |
+
(0, 170, 170),
|
| 36 |
+
(170, 170, 170),
|
| 37 |
+
(85, 85, 85),
|
| 38 |
+
(255, 85, 85),
|
| 39 |
+
(85, 255, 85),
|
| 40 |
+
(255, 255, 85),
|
| 41 |
+
(85, 85, 255),
|
| 42 |
+
(255, 85, 255),
|
| 43 |
+
(85, 255, 255),
|
| 44 |
+
(255, 255, 255),
|
| 45 |
+
]
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# The 256 color palette
|
| 50 |
+
EIGHT_BIT_PALETTE = Palette(
|
| 51 |
+
[
|
| 52 |
+
(0, 0, 0),
|
| 53 |
+
(128, 0, 0),
|
| 54 |
+
(0, 128, 0),
|
| 55 |
+
(128, 128, 0),
|
| 56 |
+
(0, 0, 128),
|
| 57 |
+
(128, 0, 128),
|
| 58 |
+
(0, 128, 128),
|
| 59 |
+
(192, 192, 192),
|
| 60 |
+
(128, 128, 128),
|
| 61 |
+
(255, 0, 0),
|
| 62 |
+
(0, 255, 0),
|
| 63 |
+
(255, 255, 0),
|
| 64 |
+
(0, 0, 255),
|
| 65 |
+
(255, 0, 255),
|
| 66 |
+
(0, 255, 255),
|
| 67 |
+
(255, 255, 255),
|
| 68 |
+
(0, 0, 0),
|
| 69 |
+
(0, 0, 95),
|
| 70 |
+
(0, 0, 135),
|
| 71 |
+
(0, 0, 175),
|
| 72 |
+
(0, 0, 215),
|
| 73 |
+
(0, 0, 255),
|
| 74 |
+
(0, 95, 0),
|
| 75 |
+
(0, 95, 95),
|
| 76 |
+
(0, 95, 135),
|
| 77 |
+
(0, 95, 175),
|
| 78 |
+
(0, 95, 215),
|
| 79 |
+
(0, 95, 255),
|
| 80 |
+
(0, 135, 0),
|
| 81 |
+
(0, 135, 95),
|
| 82 |
+
(0, 135, 135),
|
| 83 |
+
(0, 135, 175),
|
| 84 |
+
(0, 135, 215),
|
| 85 |
+
(0, 135, 255),
|
| 86 |
+
(0, 175, 0),
|
| 87 |
+
(0, 175, 95),
|
| 88 |
+
(0, 175, 135),
|
| 89 |
+
(0, 175, 175),
|
| 90 |
+
(0, 175, 215),
|
| 91 |
+
(0, 175, 255),
|
| 92 |
+
(0, 215, 0),
|
| 93 |
+
(0, 215, 95),
|
| 94 |
+
(0, 215, 135),
|
| 95 |
+
(0, 215, 175),
|
| 96 |
+
(0, 215, 215),
|
| 97 |
+
(0, 215, 255),
|
| 98 |
+
(0, 255, 0),
|
| 99 |
+
(0, 255, 95),
|
| 100 |
+
(0, 255, 135),
|
| 101 |
+
(0, 255, 175),
|
| 102 |
+
(0, 255, 215),
|
| 103 |
+
(0, 255, 255),
|
| 104 |
+
(95, 0, 0),
|
| 105 |
+
(95, 0, 95),
|
| 106 |
+
(95, 0, 135),
|
| 107 |
+
(95, 0, 175),
|
| 108 |
+
(95, 0, 215),
|
| 109 |
+
(95, 0, 255),
|
| 110 |
+
(95, 95, 0),
|
| 111 |
+
(95, 95, 95),
|
| 112 |
+
(95, 95, 135),
|
| 113 |
+
(95, 95, 175),
|
| 114 |
+
(95, 95, 215),
|
| 115 |
+
(95, 95, 255),
|
| 116 |
+
(95, 135, 0),
|
| 117 |
+
(95, 135, 95),
|
| 118 |
+
(95, 135, 135),
|
| 119 |
+
(95, 135, 175),
|
| 120 |
+
(95, 135, 215),
|
| 121 |
+
(95, 135, 255),
|
| 122 |
+
(95, 175, 0),
|
| 123 |
+
(95, 175, 95),
|
| 124 |
+
(95, 175, 135),
|
| 125 |
+
(95, 175, 175),
|
| 126 |
+
(95, 175, 215),
|
| 127 |
+
(95, 175, 255),
|
| 128 |
+
(95, 215, 0),
|
| 129 |
+
(95, 215, 95),
|
| 130 |
+
(95, 215, 135),
|
| 131 |
+
(95, 215, 175),
|
| 132 |
+
(95, 215, 215),
|
| 133 |
+
(95, 215, 255),
|
| 134 |
+
(95, 255, 0),
|
| 135 |
+
(95, 255, 95),
|
| 136 |
+
(95, 255, 135),
|
| 137 |
+
(95, 255, 175),
|
| 138 |
+
(95, 255, 215),
|
| 139 |
+
(95, 255, 255),
|
| 140 |
+
(135, 0, 0),
|
| 141 |
+
(135, 0, 95),
|
| 142 |
+
(135, 0, 135),
|
| 143 |
+
(135, 0, 175),
|
| 144 |
+
(135, 0, 215),
|
| 145 |
+
(135, 0, 255),
|
| 146 |
+
(135, 95, 0),
|
| 147 |
+
(135, 95, 95),
|
| 148 |
+
(135, 95, 135),
|
| 149 |
+
(135, 95, 175),
|
| 150 |
+
(135, 95, 215),
|
| 151 |
+
(135, 95, 255),
|
| 152 |
+
(135, 135, 0),
|
| 153 |
+
(135, 135, 95),
|
| 154 |
+
(135, 135, 135),
|
| 155 |
+
(135, 135, 175),
|
| 156 |
+
(135, 135, 215),
|
| 157 |
+
(135, 135, 255),
|
| 158 |
+
(135, 175, 0),
|
| 159 |
+
(135, 175, 95),
|
| 160 |
+
(135, 175, 135),
|
| 161 |
+
(135, 175, 175),
|
| 162 |
+
(135, 175, 215),
|
| 163 |
+
(135, 175, 255),
|
| 164 |
+
(135, 215, 0),
|
| 165 |
+
(135, 215, 95),
|
| 166 |
+
(135, 215, 135),
|
| 167 |
+
(135, 215, 175),
|
| 168 |
+
(135, 215, 215),
|
| 169 |
+
(135, 215, 255),
|
| 170 |
+
(135, 255, 0),
|
| 171 |
+
(135, 255, 95),
|
| 172 |
+
(135, 255, 135),
|
| 173 |
+
(135, 255, 175),
|
| 174 |
+
(135, 255, 215),
|
| 175 |
+
(135, 255, 255),
|
| 176 |
+
(175, 0, 0),
|
| 177 |
+
(175, 0, 95),
|
| 178 |
+
(175, 0, 135),
|
| 179 |
+
(175, 0, 175),
|
| 180 |
+
(175, 0, 215),
|
| 181 |
+
(175, 0, 255),
|
| 182 |
+
(175, 95, 0),
|
| 183 |
+
(175, 95, 95),
|
| 184 |
+
(175, 95, 135),
|
| 185 |
+
(175, 95, 175),
|
| 186 |
+
(175, 95, 215),
|
| 187 |
+
(175, 95, 255),
|
| 188 |
+
(175, 135, 0),
|
| 189 |
+
(175, 135, 95),
|
| 190 |
+
(175, 135, 135),
|
| 191 |
+
(175, 135, 175),
|
| 192 |
+
(175, 135, 215),
|
| 193 |
+
(175, 135, 255),
|
| 194 |
+
(175, 175, 0),
|
| 195 |
+
(175, 175, 95),
|
| 196 |
+
(175, 175, 135),
|
| 197 |
+
(175, 175, 175),
|
| 198 |
+
(175, 175, 215),
|
| 199 |
+
(175, 175, 255),
|
| 200 |
+
(175, 215, 0),
|
| 201 |
+
(175, 215, 95),
|
| 202 |
+
(175, 215, 135),
|
| 203 |
+
(175, 215, 175),
|
| 204 |
+
(175, 215, 215),
|
| 205 |
+
(175, 215, 255),
|
| 206 |
+
(175, 255, 0),
|
| 207 |
+
(175, 255, 95),
|
| 208 |
+
(175, 255, 135),
|
| 209 |
+
(175, 255, 175),
|
| 210 |
+
(175, 255, 215),
|
| 211 |
+
(175, 255, 255),
|
| 212 |
+
(215, 0, 0),
|
| 213 |
+
(215, 0, 95),
|
| 214 |
+
(215, 0, 135),
|
| 215 |
+
(215, 0, 175),
|
| 216 |
+
(215, 0, 215),
|
| 217 |
+
(215, 0, 255),
|
| 218 |
+
(215, 95, 0),
|
| 219 |
+
(215, 95, 95),
|
| 220 |
+
(215, 95, 135),
|
| 221 |
+
(215, 95, 175),
|
| 222 |
+
(215, 95, 215),
|
| 223 |
+
(215, 95, 255),
|
| 224 |
+
(215, 135, 0),
|
| 225 |
+
(215, 135, 95),
|
| 226 |
+
(215, 135, 135),
|
| 227 |
+
(215, 135, 175),
|
| 228 |
+
(215, 135, 215),
|
| 229 |
+
(215, 135, 255),
|
| 230 |
+
(215, 175, 0),
|
| 231 |
+
(215, 175, 95),
|
| 232 |
+
(215, 175, 135),
|
| 233 |
+
(215, 175, 175),
|
| 234 |
+
(215, 175, 215),
|
| 235 |
+
(215, 175, 255),
|
| 236 |
+
(215, 215, 0),
|
| 237 |
+
(215, 215, 95),
|
| 238 |
+
(215, 215, 135),
|
| 239 |
+
(215, 215, 175),
|
| 240 |
+
(215, 215, 215),
|
| 241 |
+
(215, 215, 255),
|
| 242 |
+
(215, 255, 0),
|
| 243 |
+
(215, 255, 95),
|
| 244 |
+
(215, 255, 135),
|
| 245 |
+
(215, 255, 175),
|
| 246 |
+
(215, 255, 215),
|
| 247 |
+
(215, 255, 255),
|
| 248 |
+
(255, 0, 0),
|
| 249 |
+
(255, 0, 95),
|
| 250 |
+
(255, 0, 135),
|
| 251 |
+
(255, 0, 175),
|
| 252 |
+
(255, 0, 215),
|
| 253 |
+
(255, 0, 255),
|
| 254 |
+
(255, 95, 0),
|
| 255 |
+
(255, 95, 95),
|
| 256 |
+
(255, 95, 135),
|
| 257 |
+
(255, 95, 175),
|
| 258 |
+
(255, 95, 215),
|
| 259 |
+
(255, 95, 255),
|
| 260 |
+
(255, 135, 0),
|
| 261 |
+
(255, 135, 95),
|
| 262 |
+
(255, 135, 135),
|
| 263 |
+
(255, 135, 175),
|
| 264 |
+
(255, 135, 215),
|
| 265 |
+
(255, 135, 255),
|
| 266 |
+
(255, 175, 0),
|
| 267 |
+
(255, 175, 95),
|
| 268 |
+
(255, 175, 135),
|
| 269 |
+
(255, 175, 175),
|
| 270 |
+
(255, 175, 215),
|
| 271 |
+
(255, 175, 255),
|
| 272 |
+
(255, 215, 0),
|
| 273 |
+
(255, 215, 95),
|
| 274 |
+
(255, 215, 135),
|
| 275 |
+
(255, 215, 175),
|
| 276 |
+
(255, 215, 215),
|
| 277 |
+
(255, 215, 255),
|
| 278 |
+
(255, 255, 0),
|
| 279 |
+
(255, 255, 95),
|
| 280 |
+
(255, 255, 135),
|
| 281 |
+
(255, 255, 175),
|
| 282 |
+
(255, 255, 215),
|
| 283 |
+
(255, 255, 255),
|
| 284 |
+
(8, 8, 8),
|
| 285 |
+
(18, 18, 18),
|
| 286 |
+
(28, 28, 28),
|
| 287 |
+
(38, 38, 38),
|
| 288 |
+
(48, 48, 48),
|
| 289 |
+
(58, 58, 58),
|
| 290 |
+
(68, 68, 68),
|
| 291 |
+
(78, 78, 78),
|
| 292 |
+
(88, 88, 88),
|
| 293 |
+
(98, 98, 98),
|
| 294 |
+
(108, 108, 108),
|
| 295 |
+
(118, 118, 118),
|
| 296 |
+
(128, 128, 128),
|
| 297 |
+
(138, 138, 138),
|
| 298 |
+
(148, 148, 148),
|
| 299 |
+
(158, 158, 158),
|
| 300 |
+
(168, 168, 168),
|
| 301 |
+
(178, 178, 178),
|
| 302 |
+
(188, 188, 188),
|
| 303 |
+
(198, 198, 198),
|
| 304 |
+
(208, 208, 208),
|
| 305 |
+
(218, 218, 218),
|
| 306 |
+
(228, 228, 228),
|
| 307 |
+
(238, 238, 238),
|
| 308 |
+
]
|
| 309 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_pick.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def pick_bool(*values: Optional[bool]) -> bool:
|
| 5 |
+
"""Pick the first non-none bool or return the last value.
|
| 6 |
+
|
| 7 |
+
Args:
|
| 8 |
+
*values (bool): Any number of boolean or None values.
|
| 9 |
+
|
| 10 |
+
Returns:
|
| 11 |
+
bool: First non-none boolean.
|
| 12 |
+
"""
|
| 13 |
+
assert values, "1 or more values required"
|
| 14 |
+
for value in values:
|
| 15 |
+
if value is not None:
|
| 16 |
+
return value
|
| 17 |
+
return bool(value)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_ratio.py
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from fractions import Fraction
|
| 3 |
+
from math import ceil
|
| 4 |
+
from typing import cast, List, Optional, Sequence
|
| 5 |
+
|
| 6 |
+
if sys.version_info >= (3, 8):
|
| 7 |
+
from typing import Protocol
|
| 8 |
+
else:
|
| 9 |
+
from typing_extensions import Protocol # pragma: no cover
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class Edge(Protocol):
|
| 13 |
+
"""Any object that defines an edge (such as Layout)."""
|
| 14 |
+
|
| 15 |
+
size: Optional[int] = None
|
| 16 |
+
ratio: int = 1
|
| 17 |
+
minimum_size: int = 1
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def ratio_resolve(total: int, edges: Sequence[Edge]) -> List[int]:
|
| 21 |
+
"""Divide total space to satisfy size, ratio, and minimum_size, constraints.
|
| 22 |
+
|
| 23 |
+
The returned list of integers should add up to total in most cases, unless it is
|
| 24 |
+
impossible to satisfy all the constraints. For instance, if there are two edges
|
| 25 |
+
with a minimum size of 20 each and `total` is 30 then the returned list will be
|
| 26 |
+
greater than total. In practice, this would mean that a Layout object would
|
| 27 |
+
clip the rows that would overflow the screen height.
|
| 28 |
+
|
| 29 |
+
Args:
|
| 30 |
+
total (int): Total number of characters.
|
| 31 |
+
edges (List[Edge]): Edges within total space.
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
List[int]: Number of characters for each edge.
|
| 35 |
+
"""
|
| 36 |
+
# Size of edge or None for yet to be determined
|
| 37 |
+
sizes = [(edge.size or None) for edge in edges]
|
| 38 |
+
|
| 39 |
+
_Fraction = Fraction
|
| 40 |
+
|
| 41 |
+
# While any edges haven't been calculated
|
| 42 |
+
while None in sizes:
|
| 43 |
+
# Get flexible edges and index to map these back on to sizes list
|
| 44 |
+
flexible_edges = [
|
| 45 |
+
(index, edge)
|
| 46 |
+
for index, (size, edge) in enumerate(zip(sizes, edges))
|
| 47 |
+
if size is None
|
| 48 |
+
]
|
| 49 |
+
# Remaining space in total
|
| 50 |
+
remaining = total - sum(size or 0 for size in sizes)
|
| 51 |
+
if remaining <= 0:
|
| 52 |
+
# No room for flexible edges
|
| 53 |
+
return [
|
| 54 |
+
((edge.minimum_size or 1) if size is None else size)
|
| 55 |
+
for size, edge in zip(sizes, edges)
|
| 56 |
+
]
|
| 57 |
+
# Calculate number of characters in a ratio portion
|
| 58 |
+
portion = _Fraction(
|
| 59 |
+
remaining, sum((edge.ratio or 1) for _, edge in flexible_edges)
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
# If any edges will be less than their minimum, replace size with the minimum
|
| 63 |
+
for index, edge in flexible_edges:
|
| 64 |
+
if portion * edge.ratio <= edge.minimum_size:
|
| 65 |
+
sizes[index] = edge.minimum_size
|
| 66 |
+
# New fixed size will invalidate calculations, so we need to repeat the process
|
| 67 |
+
break
|
| 68 |
+
else:
|
| 69 |
+
# Distribute flexible space and compensate for rounding error
|
| 70 |
+
# Since edge sizes can only be integers we need to add the remainder
|
| 71 |
+
# to the following line
|
| 72 |
+
remainder = _Fraction(0)
|
| 73 |
+
for index, edge in flexible_edges:
|
| 74 |
+
size, remainder = divmod(portion * edge.ratio + remainder, 1)
|
| 75 |
+
sizes[index] = size
|
| 76 |
+
break
|
| 77 |
+
# Sizes now contains integers only
|
| 78 |
+
return cast(List[int], sizes)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def ratio_reduce(
|
| 82 |
+
total: int, ratios: List[int], maximums: List[int], values: List[int]
|
| 83 |
+
) -> List[int]:
|
| 84 |
+
"""Divide an integer total in to parts based on ratios.
|
| 85 |
+
|
| 86 |
+
Args:
|
| 87 |
+
total (int): The total to divide.
|
| 88 |
+
ratios (List[int]): A list of integer ratios.
|
| 89 |
+
maximums (List[int]): List of maximums values for each slot.
|
| 90 |
+
values (List[int]): List of values
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
List[int]: A list of integers guaranteed to sum to total.
|
| 94 |
+
"""
|
| 95 |
+
ratios = [ratio if _max else 0 for ratio, _max in zip(ratios, maximums)]
|
| 96 |
+
total_ratio = sum(ratios)
|
| 97 |
+
if not total_ratio:
|
| 98 |
+
return values[:]
|
| 99 |
+
total_remaining = total
|
| 100 |
+
result: List[int] = []
|
| 101 |
+
append = result.append
|
| 102 |
+
for ratio, maximum, value in zip(ratios, maximums, values):
|
| 103 |
+
if ratio and total_ratio > 0:
|
| 104 |
+
distributed = min(maximum, round(ratio * total_remaining / total_ratio))
|
| 105 |
+
append(value - distributed)
|
| 106 |
+
total_remaining -= distributed
|
| 107 |
+
total_ratio -= ratio
|
| 108 |
+
else:
|
| 109 |
+
append(value)
|
| 110 |
+
return result
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def ratio_distribute(
|
| 114 |
+
total: int, ratios: List[int], minimums: Optional[List[int]] = None
|
| 115 |
+
) -> List[int]:
|
| 116 |
+
"""Distribute an integer total in to parts based on ratios.
|
| 117 |
+
|
| 118 |
+
Args:
|
| 119 |
+
total (int): The total to divide.
|
| 120 |
+
ratios (List[int]): A list of integer ratios.
|
| 121 |
+
minimums (List[int]): List of minimum values for each slot.
|
| 122 |
+
|
| 123 |
+
Returns:
|
| 124 |
+
List[int]: A list of integers guaranteed to sum to total.
|
| 125 |
+
"""
|
| 126 |
+
if minimums:
|
| 127 |
+
ratios = [ratio if _min else 0 for ratio, _min in zip(ratios, minimums)]
|
| 128 |
+
total_ratio = sum(ratios)
|
| 129 |
+
assert total_ratio > 0, "Sum of ratios must be > 0"
|
| 130 |
+
|
| 131 |
+
total_remaining = total
|
| 132 |
+
distributed_total: List[int] = []
|
| 133 |
+
append = distributed_total.append
|
| 134 |
+
if minimums is None:
|
| 135 |
+
_minimums = [0] * len(ratios)
|
| 136 |
+
else:
|
| 137 |
+
_minimums = minimums
|
| 138 |
+
for ratio, minimum in zip(ratios, _minimums):
|
| 139 |
+
if total_ratio > 0:
|
| 140 |
+
distributed = max(minimum, ceil(ratio * total_remaining / total_ratio))
|
| 141 |
+
else:
|
| 142 |
+
distributed = total_remaining
|
| 143 |
+
append(distributed)
|
| 144 |
+
total_ratio -= ratio
|
| 145 |
+
total_remaining -= distributed
|
| 146 |
+
return distributed_total
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
if __name__ == "__main__":
|
| 150 |
+
from dataclasses import dataclass
|
| 151 |
+
|
| 152 |
+
@dataclass
|
| 153 |
+
class E:
|
| 154 |
+
size: Optional[int] = None
|
| 155 |
+
ratio: int = 1
|
| 156 |
+
minimum_size: int = 1
|
| 157 |
+
|
| 158 |
+
resolved = ratio_resolve(110, [E(None, 1, 1), E(None, 1, 1), E(None, 1, 1)])
|
| 159 |
+
print(sum(resolved))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_spinners.py
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Spinners are from:
|
| 3 |
+
* cli-spinners:
|
| 4 |
+
MIT License
|
| 5 |
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights to
|
| 9 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 10 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 11 |
+
subject to the following conditions:
|
| 12 |
+
The above copyright notice and this permission notice shall be included
|
| 13 |
+
in all copies or substantial portions of the Software.
|
| 14 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
| 15 |
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
| 16 |
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
| 17 |
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
| 18 |
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
| 19 |
+
IN THE SOFTWARE.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
SPINNERS = {
|
| 23 |
+
"dots": {
|
| 24 |
+
"interval": 80,
|
| 25 |
+
"frames": "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏",
|
| 26 |
+
},
|
| 27 |
+
"dots2": {"interval": 80, "frames": "⣾⣽⣻⢿⡿⣟⣯⣷"},
|
| 28 |
+
"dots3": {
|
| 29 |
+
"interval": 80,
|
| 30 |
+
"frames": "⠋⠙⠚⠞⠖⠦⠴⠲⠳⠓",
|
| 31 |
+
},
|
| 32 |
+
"dots4": {
|
| 33 |
+
"interval": 80,
|
| 34 |
+
"frames": "⠄⠆⠇⠋⠙⠸⠰⠠⠰⠸⠙⠋⠇⠆",
|
| 35 |
+
},
|
| 36 |
+
"dots5": {
|
| 37 |
+
"interval": 80,
|
| 38 |
+
"frames": "⠋⠙⠚⠒⠂⠂⠒⠲⠴⠦⠖⠒⠐⠐⠒⠓⠋",
|
| 39 |
+
},
|
| 40 |
+
"dots6": {
|
| 41 |
+
"interval": 80,
|
| 42 |
+
"frames": "⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠴⠲⠒⠂⠂⠒⠚⠙⠉⠁",
|
| 43 |
+
},
|
| 44 |
+
"dots7": {
|
| 45 |
+
"interval": 80,
|
| 46 |
+
"frames": "⠈⠉⠋⠓⠒⠐⠐⠒⠖⠦⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈",
|
| 47 |
+
},
|
| 48 |
+
"dots8": {
|
| 49 |
+
"interval": 80,
|
| 50 |
+
"frames": "⠁⠁⠉⠙⠚⠒⠂⠂⠒⠲⠴⠤⠄⠄⠤⠠⠠⠤⠦⠖⠒⠐⠐⠒⠓⠋⠉⠈⠈",
|
| 51 |
+
},
|
| 52 |
+
"dots9": {"interval": 80, "frames": "⢹⢺⢼⣸⣇⡧⡗⡏"},
|
| 53 |
+
"dots10": {"interval": 80, "frames": "⢄⢂⢁⡁⡈⡐⡠"},
|
| 54 |
+
"dots11": {"interval": 100, "frames": "⠁⠂⠄⡀⢀⠠⠐⠈"},
|
| 55 |
+
"dots12": {
|
| 56 |
+
"interval": 80,
|
| 57 |
+
"frames": [
|
| 58 |
+
"⢀⠀",
|
| 59 |
+
"⡀⠀",
|
| 60 |
+
"⠄⠀",
|
| 61 |
+
"⢂⠀",
|
| 62 |
+
"⡂⠀",
|
| 63 |
+
"⠅⠀",
|
| 64 |
+
"⢃⠀",
|
| 65 |
+
"⡃⠀",
|
| 66 |
+
"⠍⠀",
|
| 67 |
+
"⢋⠀",
|
| 68 |
+
"⡋⠀",
|
| 69 |
+
"⠍⠁",
|
| 70 |
+
"⢋⠁",
|
| 71 |
+
"⡋⠁",
|
| 72 |
+
"⠍⠉",
|
| 73 |
+
"⠋⠉",
|
| 74 |
+
"⠋⠉",
|
| 75 |
+
"⠉⠙",
|
| 76 |
+
"⠉⠙",
|
| 77 |
+
"⠉⠩",
|
| 78 |
+
"⠈⢙",
|
| 79 |
+
"⠈⡙",
|
| 80 |
+
"⢈⠩",
|
| 81 |
+
"⡀⢙",
|
| 82 |
+
"⠄⡙",
|
| 83 |
+
"⢂⠩",
|
| 84 |
+
"⡂⢘",
|
| 85 |
+
"⠅⡘",
|
| 86 |
+
"⢃⠨",
|
| 87 |
+
"⡃⢐",
|
| 88 |
+
"⠍⡐",
|
| 89 |
+
"⢋⠠",
|
| 90 |
+
"⡋⢀",
|
| 91 |
+
"⠍⡁",
|
| 92 |
+
"⢋⠁",
|
| 93 |
+
"⡋⠁",
|
| 94 |
+
"⠍⠉",
|
| 95 |
+
"⠋⠉",
|
| 96 |
+
"⠋⠉",
|
| 97 |
+
"⠉⠙",
|
| 98 |
+
"⠉⠙",
|
| 99 |
+
"⠉⠩",
|
| 100 |
+
"⠈⢙",
|
| 101 |
+
"⠈⡙",
|
| 102 |
+
"⠈⠩",
|
| 103 |
+
"⠀⢙",
|
| 104 |
+
"⠀⡙",
|
| 105 |
+
"⠀⠩",
|
| 106 |
+
"⠀⢘",
|
| 107 |
+
"⠀⡘",
|
| 108 |
+
"⠀⠨",
|
| 109 |
+
"⠀⢐",
|
| 110 |
+
"⠀⡐",
|
| 111 |
+
"⠀⠠",
|
| 112 |
+
"⠀⢀",
|
| 113 |
+
"⠀⡀",
|
| 114 |
+
],
|
| 115 |
+
},
|
| 116 |
+
"dots8Bit": {
|
| 117 |
+
"interval": 80,
|
| 118 |
+
"frames": "⠀⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙"
|
| 119 |
+
"⡚⡛⡜⡝⡞⡟⠠⠡⠢⠣⠤⠥⠦⠧⡠⡡⡢⡣⡤⡥⡦⡧⠨⠩⠪⠫⠬⠭⠮⠯⡨⡩⡪⡫⡬⡭⡮⡯⠰⠱⠲⠳⠴⠵⠶⠷⡰⡱⡲⡳⡴⡵⡶⡷⠸⠹⠺⠻"
|
| 120 |
+
"⠼⠽⠾⠿⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⣀⣁⣂⣃⣄⣅⣆⣇⢈⢉⢊⢋⢌⢍⢎⢏⣈⣉⣊⣋⣌⣍⣎⣏⢐⢑⢒⢓⢔⢕⢖⢗⣐⣑⣒⣓⣔⣕"
|
| 121 |
+
"⣖⣗⢘⢙⢚⢛⢜⢝⢞⢟⣘⣙⣚⣛⣜⣝⣞⣟⢠⢡⢢⢣⢤⢥⢦⢧⣠⣡⣢⣣⣤⣥⣦⣧⢨⢩⢪⢫⢬⢭⢮⢯⣨⣩⣪⣫⣬⣭⣮⣯⢰⢱⢲⢳⢴⢵⢶⢷"
|
| 122 |
+
"⣰⣱⣲⣳⣴⣵⣶⣷⢸⢹⢺⢻⢼⢽⢾⢿⣸⣹⣺⣻⣼⣽⣾⣿",
|
| 123 |
+
},
|
| 124 |
+
"line": {"interval": 130, "frames": ["-", "\\", "|", "/"]},
|
| 125 |
+
"line2": {"interval": 100, "frames": "⠂-–—–-"},
|
| 126 |
+
"pipe": {"interval": 100, "frames": "┤┘┴└├┌┬┐"},
|
| 127 |
+
"simpleDots": {"interval": 400, "frames": [". ", ".. ", "...", " "]},
|
| 128 |
+
"simpleDotsScrolling": {
|
| 129 |
+
"interval": 200,
|
| 130 |
+
"frames": [". ", ".. ", "...", " ..", " .", " "],
|
| 131 |
+
},
|
| 132 |
+
"star": {"interval": 70, "frames": "✶✸✹✺✹✷"},
|
| 133 |
+
"star2": {"interval": 80, "frames": "+x*"},
|
| 134 |
+
"flip": {
|
| 135 |
+
"interval": 70,
|
| 136 |
+
"frames": "___-``'´-___",
|
| 137 |
+
},
|
| 138 |
+
"hamburger": {"interval": 100, "frames": "☱☲☴"},
|
| 139 |
+
"growVertical": {
|
| 140 |
+
"interval": 120,
|
| 141 |
+
"frames": "▁▃▄▅▆▇▆▅▄▃",
|
| 142 |
+
},
|
| 143 |
+
"growHorizontal": {
|
| 144 |
+
"interval": 120,
|
| 145 |
+
"frames": "▏▎▍▌▋▊▉▊▋▌▍▎",
|
| 146 |
+
},
|
| 147 |
+
"balloon": {"interval": 140, "frames": " .oO@* "},
|
| 148 |
+
"balloon2": {"interval": 120, "frames": ".oO°Oo."},
|
| 149 |
+
"noise": {"interval": 100, "frames": "▓▒░"},
|
| 150 |
+
"bounce": {"interval": 120, "frames": "⠁⠂⠄⠂"},
|
| 151 |
+
"boxBounce": {"interval": 120, "frames": "▖▘▝▗"},
|
| 152 |
+
"boxBounce2": {"interval": 100, "frames": "▌▀▐▄"},
|
| 153 |
+
"triangle": {"interval": 50, "frames": "◢◣◤◥"},
|
| 154 |
+
"arc": {"interval": 100, "frames": "◜◠◝◞◡◟"},
|
| 155 |
+
"circle": {"interval": 120, "frames": "◡⊙◠"},
|
| 156 |
+
"squareCorners": {"interval": 180, "frames": "◰◳◲◱"},
|
| 157 |
+
"circleQuarters": {"interval": 120, "frames": "◴◷◶◵"},
|
| 158 |
+
"circleHalves": {"interval": 50, "frames": "◐◓◑◒"},
|
| 159 |
+
"squish": {"interval": 100, "frames": "╫╪"},
|
| 160 |
+
"toggle": {"interval": 250, "frames": "⊶⊷"},
|
| 161 |
+
"toggle2": {"interval": 80, "frames": "▫▪"},
|
| 162 |
+
"toggle3": {"interval": 120, "frames": "□■"},
|
| 163 |
+
"toggle4": {"interval": 100, "frames": "■□▪▫"},
|
| 164 |
+
"toggle5": {"interval": 100, "frames": "▮▯"},
|
| 165 |
+
"toggle6": {"interval": 300, "frames": "ဝ၀"},
|
| 166 |
+
"toggle7": {"interval": 80, "frames": "⦾⦿"},
|
| 167 |
+
"toggle8": {"interval": 100, "frames": "◍◌"},
|
| 168 |
+
"toggle9": {"interval": 100, "frames": "◉◎"},
|
| 169 |
+
"toggle10": {"interval": 100, "frames": "㊂㊀㊁"},
|
| 170 |
+
"toggle11": {"interval": 50, "frames": "⧇⧆"},
|
| 171 |
+
"toggle12": {"interval": 120, "frames": "☗☖"},
|
| 172 |
+
"toggle13": {"interval": 80, "frames": "=*-"},
|
| 173 |
+
"arrow": {"interval": 100, "frames": "←↖↑↗→↘↓↙"},
|
| 174 |
+
"arrow2": {
|
| 175 |
+
"interval": 80,
|
| 176 |
+
"frames": ["⬆️ ", "↗️ ", "➡️ ", "↘️ ", "⬇️ ", "↙️ ", "⬅️ ", "↖️ "],
|
| 177 |
+
},
|
| 178 |
+
"arrow3": {
|
| 179 |
+
"interval": 120,
|
| 180 |
+
"frames": ["▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"],
|
| 181 |
+
},
|
| 182 |
+
"bouncingBar": {
|
| 183 |
+
"interval": 80,
|
| 184 |
+
"frames": [
|
| 185 |
+
"[ ]",
|
| 186 |
+
"[= ]",
|
| 187 |
+
"[== ]",
|
| 188 |
+
"[=== ]",
|
| 189 |
+
"[ ===]",
|
| 190 |
+
"[ ==]",
|
| 191 |
+
"[ =]",
|
| 192 |
+
"[ ]",
|
| 193 |
+
"[ =]",
|
| 194 |
+
"[ ==]",
|
| 195 |
+
"[ ===]",
|
| 196 |
+
"[====]",
|
| 197 |
+
"[=== ]",
|
| 198 |
+
"[== ]",
|
| 199 |
+
"[= ]",
|
| 200 |
+
],
|
| 201 |
+
},
|
| 202 |
+
"bouncingBall": {
|
| 203 |
+
"interval": 80,
|
| 204 |
+
"frames": [
|
| 205 |
+
"( ● )",
|
| 206 |
+
"( ● )",
|
| 207 |
+
"( ● )",
|
| 208 |
+
"( ● )",
|
| 209 |
+
"( ●)",
|
| 210 |
+
"( ● )",
|
| 211 |
+
"( ● )",
|
| 212 |
+
"( ● )",
|
| 213 |
+
"( ● )",
|
| 214 |
+
"(● )",
|
| 215 |
+
],
|
| 216 |
+
},
|
| 217 |
+
"smiley": {"interval": 200, "frames": ["😄 ", "😝 "]},
|
| 218 |
+
"monkey": {"interval": 300, "frames": ["🙈 ", "🙈 ", "🙉 ", "🙊 "]},
|
| 219 |
+
"hearts": {"interval": 100, "frames": ["💛 ", "💙 ", "💜 ", "💚 ", "❤️ "]},
|
| 220 |
+
"clock": {
|
| 221 |
+
"interval": 100,
|
| 222 |
+
"frames": [
|
| 223 |
+
"🕛 ",
|
| 224 |
+
"🕐 ",
|
| 225 |
+
"🕑 ",
|
| 226 |
+
"🕒 ",
|
| 227 |
+
"🕓 ",
|
| 228 |
+
"🕔 ",
|
| 229 |
+
"🕕 ",
|
| 230 |
+
"🕖 ",
|
| 231 |
+
"🕗 ",
|
| 232 |
+
"🕘 ",
|
| 233 |
+
"🕙 ",
|
| 234 |
+
"🕚 ",
|
| 235 |
+
],
|
| 236 |
+
},
|
| 237 |
+
"earth": {"interval": 180, "frames": ["🌍 ", "🌎 ", "🌏 "]},
|
| 238 |
+
"material": {
|
| 239 |
+
"interval": 17,
|
| 240 |
+
"frames": [
|
| 241 |
+
"█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 242 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 243 |
+
"███▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 244 |
+
"████▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 245 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 246 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 247 |
+
"███████▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 248 |
+
"████████▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 249 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 250 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 251 |
+
"██████████▁▁▁▁▁▁▁▁▁▁",
|
| 252 |
+
"███████████▁▁▁▁▁▁▁▁▁",
|
| 253 |
+
"█████████████▁▁▁▁▁▁▁",
|
| 254 |
+
"██████████████▁▁▁▁▁▁",
|
| 255 |
+
"██████████████▁▁▁▁▁▁",
|
| 256 |
+
"▁██████████████▁▁▁▁▁",
|
| 257 |
+
"▁██████████████▁▁▁▁▁",
|
| 258 |
+
"▁██████████████▁▁▁▁▁",
|
| 259 |
+
"▁▁██████████████▁▁▁▁",
|
| 260 |
+
"▁▁▁██████████████▁▁▁",
|
| 261 |
+
"▁▁▁▁█████████████▁▁▁",
|
| 262 |
+
"▁▁▁▁██████████████▁▁",
|
| 263 |
+
"▁▁▁▁██████████████▁▁",
|
| 264 |
+
"▁▁▁▁▁██████████████▁",
|
| 265 |
+
"▁▁▁▁▁██████████████▁",
|
| 266 |
+
"▁▁▁▁▁██████████████▁",
|
| 267 |
+
"▁▁▁▁▁▁██████████████",
|
| 268 |
+
"▁▁▁▁▁▁██████████████",
|
| 269 |
+
"▁▁▁▁▁▁▁█████████████",
|
| 270 |
+
"▁▁▁▁▁▁▁█████████████",
|
| 271 |
+
"▁▁▁▁▁▁▁▁████████████",
|
| 272 |
+
"▁▁▁▁▁▁▁▁████████████",
|
| 273 |
+
"▁▁▁▁▁▁▁▁▁███████████",
|
| 274 |
+
"▁▁▁▁▁▁▁▁▁███████████",
|
| 275 |
+
"▁▁▁▁▁▁▁▁▁▁██████████",
|
| 276 |
+
"▁▁▁▁▁▁▁▁▁▁██████████",
|
| 277 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁████████",
|
| 278 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
| 279 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁██████",
|
| 280 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
| 281 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
| 282 |
+
"█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
| 283 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
| 284 |
+
"██▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
| 285 |
+
"███▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
| 286 |
+
"████▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
| 287 |
+
"█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 288 |
+
"█████▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 289 |
+
"██████▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 290 |
+
"████████▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 291 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 292 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 293 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 294 |
+
"█████████▁▁▁▁▁▁▁▁▁▁▁",
|
| 295 |
+
"███████████▁▁▁▁▁▁▁▁▁",
|
| 296 |
+
"████████████▁▁▁▁▁▁▁▁",
|
| 297 |
+
"████████████▁▁▁▁▁▁▁▁",
|
| 298 |
+
"██████████████▁▁▁▁▁▁",
|
| 299 |
+
"██████████████▁▁▁▁▁▁",
|
| 300 |
+
"▁██████████████▁▁▁▁▁",
|
| 301 |
+
"▁██████████████▁▁▁▁▁",
|
| 302 |
+
"▁▁▁█████████████▁▁▁▁",
|
| 303 |
+
"▁▁▁▁▁████████████▁▁▁",
|
| 304 |
+
"▁▁▁▁▁████████████▁▁▁",
|
| 305 |
+
"▁▁▁▁▁▁███████████▁▁▁",
|
| 306 |
+
"▁▁▁▁▁▁▁▁█████████▁▁▁",
|
| 307 |
+
"▁▁▁▁▁▁▁▁█████████▁▁▁",
|
| 308 |
+
"▁▁▁▁▁▁▁▁▁█████████▁▁",
|
| 309 |
+
"▁▁▁▁▁▁▁▁▁█████████▁▁",
|
| 310 |
+
"▁▁▁▁▁▁▁▁▁▁█████████▁",
|
| 311 |
+
"▁▁▁▁▁▁▁▁▁▁▁████████▁",
|
| 312 |
+
"▁▁▁▁▁▁▁▁▁▁▁████████▁",
|
| 313 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
|
| 314 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁███████▁",
|
| 315 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
| 316 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁███████",
|
| 317 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█████",
|
| 318 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
| 319 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
| 320 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁████",
|
| 321 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
| 322 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███",
|
| 323 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
| 324 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
| 325 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁██",
|
| 326 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 327 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 328 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█",
|
| 329 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 330 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 331 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 332 |
+
"▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁",
|
| 333 |
+
],
|
| 334 |
+
},
|
| 335 |
+
"moon": {
|
| 336 |
+
"interval": 80,
|
| 337 |
+
"frames": ["🌑 ", "🌒 ", "🌓 ", "🌔 ", "🌕 ", "🌖 ", "🌗 ", "🌘 "],
|
| 338 |
+
},
|
| 339 |
+
"runner": {"interval": 140, "frames": ["🚶 ", "🏃 "]},
|
| 340 |
+
"pong": {
|
| 341 |
+
"interval": 80,
|
| 342 |
+
"frames": [
|
| 343 |
+
"▐⠂ ▌",
|
| 344 |
+
"▐⠈ ▌",
|
| 345 |
+
"▐ ⠂ ▌",
|
| 346 |
+
"▐ ⠠ ▌",
|
| 347 |
+
"▐ ⡀ ▌",
|
| 348 |
+
"▐ ⠠ ▌",
|
| 349 |
+
"▐ ⠂ ▌",
|
| 350 |
+
"▐ ⠈ ▌",
|
| 351 |
+
"▐ ⠂ ▌",
|
| 352 |
+
"▐ ⠠ ▌",
|
| 353 |
+
"▐ ⡀ ▌",
|
| 354 |
+
"▐ ⠠ ▌",
|
| 355 |
+
"▐ ⠂ ▌",
|
| 356 |
+
"▐ ⠈ ▌",
|
| 357 |
+
"▐ ⠂▌",
|
| 358 |
+
"▐ ⠠▌",
|
| 359 |
+
"▐ ⡀▌",
|
| 360 |
+
"▐ ⠠ ▌",
|
| 361 |
+
"▐ ⠂ ▌",
|
| 362 |
+
"▐ ⠈ ▌",
|
| 363 |
+
"▐ ⠂ ▌",
|
| 364 |
+
"▐ ⠠ ▌",
|
| 365 |
+
"▐ ⡀ ▌",
|
| 366 |
+
"▐ ⠠ ▌",
|
| 367 |
+
"▐ ⠂ ▌",
|
| 368 |
+
"▐ ⠈ ▌",
|
| 369 |
+
"▐ ⠂ ▌",
|
| 370 |
+
"▐ ⠠ ▌",
|
| 371 |
+
"▐ ⡀ ▌",
|
| 372 |
+
"▐⠠ ▌",
|
| 373 |
+
],
|
| 374 |
+
},
|
| 375 |
+
"shark": {
|
| 376 |
+
"interval": 120,
|
| 377 |
+
"frames": [
|
| 378 |
+
"▐|\\____________▌",
|
| 379 |
+
"▐_|\\___________▌",
|
| 380 |
+
"▐__|\\__________▌",
|
| 381 |
+
"▐___|\\_________▌",
|
| 382 |
+
"▐____|\\________▌",
|
| 383 |
+
"▐_____|\\_______▌",
|
| 384 |
+
"▐______|\\______▌",
|
| 385 |
+
"▐_______|\\_____▌",
|
| 386 |
+
"▐________|\\____▌",
|
| 387 |
+
"▐_________|\\___▌",
|
| 388 |
+
"▐__________|\\__▌",
|
| 389 |
+
"▐___________|\\_▌",
|
| 390 |
+
"▐____________|\\▌",
|
| 391 |
+
"▐____________/|▌",
|
| 392 |
+
"▐___________/|_▌",
|
| 393 |
+
"▐__________/|__▌",
|
| 394 |
+
"▐_________/|___▌",
|
| 395 |
+
"▐________/|____▌",
|
| 396 |
+
"▐_______/|_____▌",
|
| 397 |
+
"▐______/|______▌",
|
| 398 |
+
"▐_____/|_______▌",
|
| 399 |
+
"▐____/|________▌",
|
| 400 |
+
"▐___/|_________▌",
|
| 401 |
+
"▐__/|__________▌",
|
| 402 |
+
"▐_/|___________▌",
|
| 403 |
+
"▐/|____________▌",
|
| 404 |
+
],
|
| 405 |
+
},
|
| 406 |
+
"dqpb": {"interval": 100, "frames": "dqpb"},
|
| 407 |
+
"weather": {
|
| 408 |
+
"interval": 100,
|
| 409 |
+
"frames": [
|
| 410 |
+
"☀️ ",
|
| 411 |
+
"☀️ ",
|
| 412 |
+
"☀️ ",
|
| 413 |
+
"🌤 ",
|
| 414 |
+
"⛅️ ",
|
| 415 |
+
"🌥 ",
|
| 416 |
+
"☁️ ",
|
| 417 |
+
"🌧 ",
|
| 418 |
+
"🌨 ",
|
| 419 |
+
"🌧 ",
|
| 420 |
+
"🌨 ",
|
| 421 |
+
"🌧 ",
|
| 422 |
+
"🌨 ",
|
| 423 |
+
"⛈ ",
|
| 424 |
+
"🌨 ",
|
| 425 |
+
"🌧 ",
|
| 426 |
+
"🌨 ",
|
| 427 |
+
"☁️ ",
|
| 428 |
+
"🌥 ",
|
| 429 |
+
"⛅️ ",
|
| 430 |
+
"🌤 ",
|
| 431 |
+
"☀️ ",
|
| 432 |
+
"☀️ ",
|
| 433 |
+
],
|
| 434 |
+
},
|
| 435 |
+
"christmas": {"interval": 400, "frames": "🌲🎄"},
|
| 436 |
+
"grenade": {
|
| 437 |
+
"interval": 80,
|
| 438 |
+
"frames": [
|
| 439 |
+
"، ",
|
| 440 |
+
"′ ",
|
| 441 |
+
" ´ ",
|
| 442 |
+
" ‾ ",
|
| 443 |
+
" ⸌",
|
| 444 |
+
" ⸊",
|
| 445 |
+
" |",
|
| 446 |
+
" ⁎",
|
| 447 |
+
" ⁕",
|
| 448 |
+
" ෴ ",
|
| 449 |
+
" ⁓",
|
| 450 |
+
" ",
|
| 451 |
+
" ",
|
| 452 |
+
" ",
|
| 453 |
+
],
|
| 454 |
+
},
|
| 455 |
+
"point": {"interval": 125, "frames": ["∙∙∙", "●∙∙", "∙●∙", "∙∙●", "∙∙∙"]},
|
| 456 |
+
"layer": {"interval": 150, "frames": "-=≡"},
|
| 457 |
+
"betaWave": {
|
| 458 |
+
"interval": 80,
|
| 459 |
+
"frames": [
|
| 460 |
+
"ρββββββ",
|
| 461 |
+
"βρβββββ",
|
| 462 |
+
"ββρββββ",
|
| 463 |
+
"βββρβββ",
|
| 464 |
+
"ββββρββ",
|
| 465 |
+
"βββββρβ",
|
| 466 |
+
"ββββββρ",
|
| 467 |
+
],
|
| 468 |
+
},
|
| 469 |
+
"aesthetic": {
|
| 470 |
+
"interval": 80,
|
| 471 |
+
"frames": [
|
| 472 |
+
"▰▱▱▱▱▱▱",
|
| 473 |
+
"▰▰▱▱▱▱▱",
|
| 474 |
+
"▰▰▰▱▱▱▱",
|
| 475 |
+
"▰▰▰▰▱▱▱",
|
| 476 |
+
"▰▰▰▰▰▱▱",
|
| 477 |
+
"▰▰▰▰▰▰▱",
|
| 478 |
+
"▰▰▰▰▰▰▰",
|
| 479 |
+
"▰▱▱▱▱▱▱",
|
| 480 |
+
],
|
| 481 |
+
},
|
| 482 |
+
}
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_stack.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, TypeVar
|
| 2 |
+
|
| 3 |
+
T = TypeVar("T")
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Stack(List[T]):
|
| 7 |
+
"""A small shim over builtin list."""
|
| 8 |
+
|
| 9 |
+
@property
|
| 10 |
+
def top(self) -> T:
|
| 11 |
+
"""Get top of stack."""
|
| 12 |
+
return self[-1]
|
| 13 |
+
|
| 14 |
+
def push(self, item: T) -> None:
|
| 15 |
+
"""Push an item on to the stack (append in stack nomenclature)."""
|
| 16 |
+
self.append(item)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_timer.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Timer context manager, only used in debug.
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from time import time
|
| 7 |
+
|
| 8 |
+
import contextlib
|
| 9 |
+
from typing import Generator
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@contextlib.contextmanager
|
| 13 |
+
def timer(subject: str = "time") -> Generator[None, None, None]:
|
| 14 |
+
"""print the elapsed time. (only used in debugging)"""
|
| 15 |
+
start = time()
|
| 16 |
+
yield
|
| 17 |
+
elapsed = time() - start
|
| 18 |
+
elapsed_ms = elapsed * 1000
|
| 19 |
+
print(f"{subject} elapsed {elapsed_ms:.1f}ms")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_win32_console.py
ADDED
|
@@ -0,0 +1,661 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Light wrapper around the Win32 Console API - this module should only be imported on Windows
|
| 2 |
+
|
| 3 |
+
The API that this module wraps is documented at https://docs.microsoft.com/en-us/windows/console/console-functions
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import ctypes
|
| 7 |
+
import sys
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
windll: Any = None
|
| 11 |
+
if sys.platform == "win32":
|
| 12 |
+
windll = ctypes.LibraryLoader(ctypes.WinDLL)
|
| 13 |
+
else:
|
| 14 |
+
raise ImportError(f"{__name__} can only be imported on Windows")
|
| 15 |
+
|
| 16 |
+
import time
|
| 17 |
+
from ctypes import Structure, byref, wintypes
|
| 18 |
+
from typing import IO, NamedTuple, Type, cast
|
| 19 |
+
|
| 20 |
+
from rich.color import ColorSystem
|
| 21 |
+
from rich.style import Style
|
| 22 |
+
|
| 23 |
+
STDOUT = -11
|
| 24 |
+
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
|
| 25 |
+
|
| 26 |
+
COORD = wintypes._COORD
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class LegacyWindowsError(Exception):
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class WindowsCoordinates(NamedTuple):
|
| 34 |
+
"""Coordinates in the Windows Console API are (y, x), not (x, y).
|
| 35 |
+
This class is intended to prevent that confusion.
|
| 36 |
+
Rows and columns are indexed from 0.
|
| 37 |
+
This class can be used in place of wintypes._COORD in arguments and argtypes.
|
| 38 |
+
"""
|
| 39 |
+
|
| 40 |
+
row: int
|
| 41 |
+
col: int
|
| 42 |
+
|
| 43 |
+
@classmethod
|
| 44 |
+
def from_param(cls, value: "WindowsCoordinates") -> COORD:
|
| 45 |
+
"""Converts a WindowsCoordinates into a wintypes _COORD structure.
|
| 46 |
+
This classmethod is internally called by ctypes to perform the conversion.
|
| 47 |
+
|
| 48 |
+
Args:
|
| 49 |
+
value (WindowsCoordinates): The input coordinates to convert.
|
| 50 |
+
|
| 51 |
+
Returns:
|
| 52 |
+
wintypes._COORD: The converted coordinates struct.
|
| 53 |
+
"""
|
| 54 |
+
return COORD(value.col, value.row)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
|
| 58 |
+
_fields_ = [
|
| 59 |
+
("dwSize", COORD),
|
| 60 |
+
("dwCursorPosition", COORD),
|
| 61 |
+
("wAttributes", wintypes.WORD),
|
| 62 |
+
("srWindow", wintypes.SMALL_RECT),
|
| 63 |
+
("dwMaximumWindowSize", COORD),
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
class CONSOLE_CURSOR_INFO(ctypes.Structure):
|
| 68 |
+
_fields_ = [("dwSize", wintypes.DWORD), ("bVisible", wintypes.BOOL)]
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
_GetStdHandle = windll.kernel32.GetStdHandle
|
| 72 |
+
_GetStdHandle.argtypes = [
|
| 73 |
+
wintypes.DWORD,
|
| 74 |
+
]
|
| 75 |
+
_GetStdHandle.restype = wintypes.HANDLE
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def GetStdHandle(handle: int = STDOUT) -> wintypes.HANDLE:
|
| 79 |
+
"""Retrieves a handle to the specified standard device (standard input, standard output, or standard error).
|
| 80 |
+
|
| 81 |
+
Args:
|
| 82 |
+
handle (int): Integer identifier for the handle. Defaults to -11 (stdout).
|
| 83 |
+
|
| 84 |
+
Returns:
|
| 85 |
+
wintypes.HANDLE: The handle
|
| 86 |
+
"""
|
| 87 |
+
return cast(wintypes.HANDLE, _GetStdHandle(handle))
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
_GetConsoleMode = windll.kernel32.GetConsoleMode
|
| 91 |
+
_GetConsoleMode.argtypes = [wintypes.HANDLE, wintypes.LPDWORD]
|
| 92 |
+
_GetConsoleMode.restype = wintypes.BOOL
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def GetConsoleMode(std_handle: wintypes.HANDLE) -> int:
|
| 96 |
+
"""Retrieves the current input mode of a console's input buffer
|
| 97 |
+
or the current output mode of a console screen buffer.
|
| 98 |
+
|
| 99 |
+
Args:
|
| 100 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 101 |
+
|
| 102 |
+
Raises:
|
| 103 |
+
LegacyWindowsError: If any error occurs while calling the Windows console API.
|
| 104 |
+
|
| 105 |
+
Returns:
|
| 106 |
+
int: Value representing the current console mode as documented at
|
| 107 |
+
https://docs.microsoft.com/en-us/windows/console/getconsolemode#parameters
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
+
console_mode = wintypes.DWORD()
|
| 111 |
+
success = bool(_GetConsoleMode(std_handle, console_mode))
|
| 112 |
+
if not success:
|
| 113 |
+
raise LegacyWindowsError("Unable to get legacy Windows Console Mode")
|
| 114 |
+
return console_mode.value
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
_FillConsoleOutputCharacterW = windll.kernel32.FillConsoleOutputCharacterW
|
| 118 |
+
_FillConsoleOutputCharacterW.argtypes = [
|
| 119 |
+
wintypes.HANDLE,
|
| 120 |
+
ctypes.c_char,
|
| 121 |
+
wintypes.DWORD,
|
| 122 |
+
cast(Type[COORD], WindowsCoordinates),
|
| 123 |
+
ctypes.POINTER(wintypes.DWORD),
|
| 124 |
+
]
|
| 125 |
+
_FillConsoleOutputCharacterW.restype = wintypes.BOOL
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def FillConsoleOutputCharacter(
|
| 129 |
+
std_handle: wintypes.HANDLE,
|
| 130 |
+
char: str,
|
| 131 |
+
length: int,
|
| 132 |
+
start: WindowsCoordinates,
|
| 133 |
+
) -> int:
|
| 134 |
+
"""Writes a character to the console screen buffer a specified number of times, beginning at the specified coordinates.
|
| 135 |
+
|
| 136 |
+
Args:
|
| 137 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 138 |
+
char (str): The character to write. Must be a string of length 1.
|
| 139 |
+
length (int): The number of times to write the character.
|
| 140 |
+
start (WindowsCoordinates): The coordinates to start writing at.
|
| 141 |
+
|
| 142 |
+
Returns:
|
| 143 |
+
int: The number of characters written.
|
| 144 |
+
"""
|
| 145 |
+
character = ctypes.c_char(char.encode())
|
| 146 |
+
num_characters = wintypes.DWORD(length)
|
| 147 |
+
num_written = wintypes.DWORD(0)
|
| 148 |
+
_FillConsoleOutputCharacterW(
|
| 149 |
+
std_handle,
|
| 150 |
+
character,
|
| 151 |
+
num_characters,
|
| 152 |
+
start,
|
| 153 |
+
byref(num_written),
|
| 154 |
+
)
|
| 155 |
+
return num_written.value
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
_FillConsoleOutputAttribute = windll.kernel32.FillConsoleOutputAttribute
|
| 159 |
+
_FillConsoleOutputAttribute.argtypes = [
|
| 160 |
+
wintypes.HANDLE,
|
| 161 |
+
wintypes.WORD,
|
| 162 |
+
wintypes.DWORD,
|
| 163 |
+
cast(Type[COORD], WindowsCoordinates),
|
| 164 |
+
ctypes.POINTER(wintypes.DWORD),
|
| 165 |
+
]
|
| 166 |
+
_FillConsoleOutputAttribute.restype = wintypes.BOOL
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def FillConsoleOutputAttribute(
|
| 170 |
+
std_handle: wintypes.HANDLE,
|
| 171 |
+
attributes: int,
|
| 172 |
+
length: int,
|
| 173 |
+
start: WindowsCoordinates,
|
| 174 |
+
) -> int:
|
| 175 |
+
"""Sets the character attributes for a specified number of character cells,
|
| 176 |
+
beginning at the specified coordinates in a screen buffer.
|
| 177 |
+
|
| 178 |
+
Args:
|
| 179 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 180 |
+
attributes (int): Integer value representing the foreground and background colours of the cells.
|
| 181 |
+
length (int): The number of cells to set the output attribute of.
|
| 182 |
+
start (WindowsCoordinates): The coordinates of the first cell whose attributes are to be set.
|
| 183 |
+
|
| 184 |
+
Returns:
|
| 185 |
+
int: The number of cells whose attributes were actually set.
|
| 186 |
+
"""
|
| 187 |
+
num_cells = wintypes.DWORD(length)
|
| 188 |
+
style_attrs = wintypes.WORD(attributes)
|
| 189 |
+
num_written = wintypes.DWORD(0)
|
| 190 |
+
_FillConsoleOutputAttribute(
|
| 191 |
+
std_handle, style_attrs, num_cells, start, byref(num_written)
|
| 192 |
+
)
|
| 193 |
+
return num_written.value
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
_SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
|
| 197 |
+
_SetConsoleTextAttribute.argtypes = [
|
| 198 |
+
wintypes.HANDLE,
|
| 199 |
+
wintypes.WORD,
|
| 200 |
+
]
|
| 201 |
+
_SetConsoleTextAttribute.restype = wintypes.BOOL
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def SetConsoleTextAttribute(
|
| 205 |
+
std_handle: wintypes.HANDLE, attributes: wintypes.WORD
|
| 206 |
+
) -> bool:
|
| 207 |
+
"""Set the colour attributes for all text written after this function is called.
|
| 208 |
+
|
| 209 |
+
Args:
|
| 210 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 211 |
+
attributes (int): Integer value representing the foreground and background colours.
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
Returns:
|
| 215 |
+
bool: True if the attribute was set successfully, otherwise False.
|
| 216 |
+
"""
|
| 217 |
+
return bool(_SetConsoleTextAttribute(std_handle, attributes))
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
_GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
|
| 221 |
+
_GetConsoleScreenBufferInfo.argtypes = [
|
| 222 |
+
wintypes.HANDLE,
|
| 223 |
+
ctypes.POINTER(CONSOLE_SCREEN_BUFFER_INFO),
|
| 224 |
+
]
|
| 225 |
+
_GetConsoleScreenBufferInfo.restype = wintypes.BOOL
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def GetConsoleScreenBufferInfo(
|
| 229 |
+
std_handle: wintypes.HANDLE,
|
| 230 |
+
) -> CONSOLE_SCREEN_BUFFER_INFO:
|
| 231 |
+
"""Retrieves information about the specified console screen buffer.
|
| 232 |
+
|
| 233 |
+
Args:
|
| 234 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 235 |
+
|
| 236 |
+
Returns:
|
| 237 |
+
CONSOLE_SCREEN_BUFFER_INFO: A CONSOLE_SCREEN_BUFFER_INFO ctype struct contain information about
|
| 238 |
+
screen size, cursor position, colour attributes, and more."""
|
| 239 |
+
console_screen_buffer_info = CONSOLE_SCREEN_BUFFER_INFO()
|
| 240 |
+
_GetConsoleScreenBufferInfo(std_handle, byref(console_screen_buffer_info))
|
| 241 |
+
return console_screen_buffer_info
|
| 242 |
+
|
| 243 |
+
|
| 244 |
+
_SetConsoleCursorPosition = windll.kernel32.SetConsoleCursorPosition
|
| 245 |
+
_SetConsoleCursorPosition.argtypes = [
|
| 246 |
+
wintypes.HANDLE,
|
| 247 |
+
cast(Type[COORD], WindowsCoordinates),
|
| 248 |
+
]
|
| 249 |
+
_SetConsoleCursorPosition.restype = wintypes.BOOL
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def SetConsoleCursorPosition(
|
| 253 |
+
std_handle: wintypes.HANDLE, coords: WindowsCoordinates
|
| 254 |
+
) -> bool:
|
| 255 |
+
"""Set the position of the cursor in the console screen
|
| 256 |
+
|
| 257 |
+
Args:
|
| 258 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 259 |
+
coords (WindowsCoordinates): The coordinates to move the cursor to.
|
| 260 |
+
|
| 261 |
+
Returns:
|
| 262 |
+
bool: True if the function succeeds, otherwise False.
|
| 263 |
+
"""
|
| 264 |
+
return bool(_SetConsoleCursorPosition(std_handle, coords))
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
_GetConsoleCursorInfo = windll.kernel32.GetConsoleCursorInfo
|
| 268 |
+
_GetConsoleCursorInfo.argtypes = [
|
| 269 |
+
wintypes.HANDLE,
|
| 270 |
+
ctypes.POINTER(CONSOLE_CURSOR_INFO),
|
| 271 |
+
]
|
| 272 |
+
_GetConsoleCursorInfo.restype = wintypes.BOOL
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def GetConsoleCursorInfo(
|
| 276 |
+
std_handle: wintypes.HANDLE, cursor_info: CONSOLE_CURSOR_INFO
|
| 277 |
+
) -> bool:
|
| 278 |
+
"""Get the cursor info - used to get cursor visibility and width
|
| 279 |
+
|
| 280 |
+
Args:
|
| 281 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 282 |
+
cursor_info (CONSOLE_CURSOR_INFO): CONSOLE_CURSOR_INFO ctype struct that receives information
|
| 283 |
+
about the console's cursor.
|
| 284 |
+
|
| 285 |
+
Returns:
|
| 286 |
+
bool: True if the function succeeds, otherwise False.
|
| 287 |
+
"""
|
| 288 |
+
return bool(_GetConsoleCursorInfo(std_handle, byref(cursor_info)))
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
_SetConsoleCursorInfo = windll.kernel32.SetConsoleCursorInfo
|
| 292 |
+
_SetConsoleCursorInfo.argtypes = [
|
| 293 |
+
wintypes.HANDLE,
|
| 294 |
+
ctypes.POINTER(CONSOLE_CURSOR_INFO),
|
| 295 |
+
]
|
| 296 |
+
_SetConsoleCursorInfo.restype = wintypes.BOOL
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
def SetConsoleCursorInfo(
|
| 300 |
+
std_handle: wintypes.HANDLE, cursor_info: CONSOLE_CURSOR_INFO
|
| 301 |
+
) -> bool:
|
| 302 |
+
"""Set the cursor info - used for adjusting cursor visibility and width
|
| 303 |
+
|
| 304 |
+
Args:
|
| 305 |
+
std_handle (wintypes.HANDLE): A handle to the console input buffer or the console screen buffer.
|
| 306 |
+
cursor_info (CONSOLE_CURSOR_INFO): CONSOLE_CURSOR_INFO ctype struct containing the new cursor info.
|
| 307 |
+
|
| 308 |
+
Returns:
|
| 309 |
+
bool: True if the function succeeds, otherwise False.
|
| 310 |
+
"""
|
| 311 |
+
return bool(_SetConsoleCursorInfo(std_handle, byref(cursor_info)))
|
| 312 |
+
|
| 313 |
+
|
| 314 |
+
_SetConsoleTitle = windll.kernel32.SetConsoleTitleW
|
| 315 |
+
_SetConsoleTitle.argtypes = [wintypes.LPCWSTR]
|
| 316 |
+
_SetConsoleTitle.restype = wintypes.BOOL
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
def SetConsoleTitle(title: str) -> bool:
|
| 320 |
+
"""Sets the title of the current console window
|
| 321 |
+
|
| 322 |
+
Args:
|
| 323 |
+
title (str): The new title of the console window.
|
| 324 |
+
|
| 325 |
+
Returns:
|
| 326 |
+
bool: True if the function succeeds, otherwise False.
|
| 327 |
+
"""
|
| 328 |
+
return bool(_SetConsoleTitle(title))
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
class LegacyWindowsTerm:
|
| 332 |
+
"""This class allows interaction with the legacy Windows Console API. It should only be used in the context
|
| 333 |
+
of environments where virtual terminal processing is not available. However, if it is used in a Windows environment,
|
| 334 |
+
the entire API should work.
|
| 335 |
+
|
| 336 |
+
Args:
|
| 337 |
+
file (IO[str]): The file which the Windows Console API HANDLE is retrieved from, defaults to sys.stdout.
|
| 338 |
+
"""
|
| 339 |
+
|
| 340 |
+
BRIGHT_BIT = 8
|
| 341 |
+
|
| 342 |
+
# Indices are ANSI color numbers, values are the corresponding Windows Console API color numbers
|
| 343 |
+
ANSI_TO_WINDOWS = [
|
| 344 |
+
0, # black The Windows colours are defined in wincon.h as follows:
|
| 345 |
+
4, # red define FOREGROUND_BLUE 0x0001 -- 0000 0001
|
| 346 |
+
2, # green define FOREGROUND_GREEN 0x0002 -- 0000 0010
|
| 347 |
+
6, # yellow define FOREGROUND_RED 0x0004 -- 0000 0100
|
| 348 |
+
1, # blue define FOREGROUND_INTENSITY 0x0008 -- 0000 1000
|
| 349 |
+
5, # magenta define BACKGROUND_BLUE 0x0010 -- 0001 0000
|
| 350 |
+
3, # cyan define BACKGROUND_GREEN 0x0020 -- 0010 0000
|
| 351 |
+
7, # white define BACKGROUND_RED 0x0040 -- 0100 0000
|
| 352 |
+
8, # bright black (grey) define BACKGROUND_INTENSITY 0x0080 -- 1000 0000
|
| 353 |
+
12, # bright red
|
| 354 |
+
10, # bright green
|
| 355 |
+
14, # bright yellow
|
| 356 |
+
9, # bright blue
|
| 357 |
+
13, # bright magenta
|
| 358 |
+
11, # bright cyan
|
| 359 |
+
15, # bright white
|
| 360 |
+
]
|
| 361 |
+
|
| 362 |
+
def __init__(self, file: "IO[str]") -> None:
|
| 363 |
+
handle = GetStdHandle(STDOUT)
|
| 364 |
+
self._handle = handle
|
| 365 |
+
default_text = GetConsoleScreenBufferInfo(handle).wAttributes
|
| 366 |
+
self._default_text = default_text
|
| 367 |
+
|
| 368 |
+
self._default_fore = default_text & 7
|
| 369 |
+
self._default_back = (default_text >> 4) & 7
|
| 370 |
+
self._default_attrs = self._default_fore | (self._default_back << 4)
|
| 371 |
+
|
| 372 |
+
self._file = file
|
| 373 |
+
self.write = file.write
|
| 374 |
+
self.flush = file.flush
|
| 375 |
+
|
| 376 |
+
@property
|
| 377 |
+
def cursor_position(self) -> WindowsCoordinates:
|
| 378 |
+
"""Returns the current position of the cursor (0-based)
|
| 379 |
+
|
| 380 |
+
Returns:
|
| 381 |
+
WindowsCoordinates: The current cursor position.
|
| 382 |
+
"""
|
| 383 |
+
coord: COORD = GetConsoleScreenBufferInfo(self._handle).dwCursorPosition
|
| 384 |
+
return WindowsCoordinates(row=coord.Y, col=coord.X)
|
| 385 |
+
|
| 386 |
+
@property
|
| 387 |
+
def screen_size(self) -> WindowsCoordinates:
|
| 388 |
+
"""Returns the current size of the console screen buffer, in character columns and rows
|
| 389 |
+
|
| 390 |
+
Returns:
|
| 391 |
+
WindowsCoordinates: The width and height of the screen as WindowsCoordinates.
|
| 392 |
+
"""
|
| 393 |
+
screen_size: COORD = GetConsoleScreenBufferInfo(self._handle).dwSize
|
| 394 |
+
return WindowsCoordinates(row=screen_size.Y, col=screen_size.X)
|
| 395 |
+
|
| 396 |
+
def write_text(self, text: str) -> None:
|
| 397 |
+
"""Write text directly to the terminal without any modification of styles
|
| 398 |
+
|
| 399 |
+
Args:
|
| 400 |
+
text (str): The text to write to the console
|
| 401 |
+
"""
|
| 402 |
+
self.write(text)
|
| 403 |
+
self.flush()
|
| 404 |
+
|
| 405 |
+
def write_styled(self, text: str, style: Style) -> None:
|
| 406 |
+
"""Write styled text to the terminal.
|
| 407 |
+
|
| 408 |
+
Args:
|
| 409 |
+
text (str): The text to write
|
| 410 |
+
style (Style): The style of the text
|
| 411 |
+
"""
|
| 412 |
+
color = style.color
|
| 413 |
+
bgcolor = style.bgcolor
|
| 414 |
+
if style.reverse:
|
| 415 |
+
color, bgcolor = bgcolor, color
|
| 416 |
+
|
| 417 |
+
if color:
|
| 418 |
+
fore = color.downgrade(ColorSystem.WINDOWS).number
|
| 419 |
+
fore = fore if fore is not None else 7 # Default to ANSI 7: White
|
| 420 |
+
if style.bold:
|
| 421 |
+
fore = fore | self.BRIGHT_BIT
|
| 422 |
+
if style.dim:
|
| 423 |
+
fore = fore & ~self.BRIGHT_BIT
|
| 424 |
+
fore = self.ANSI_TO_WINDOWS[fore]
|
| 425 |
+
else:
|
| 426 |
+
fore = self._default_fore
|
| 427 |
+
|
| 428 |
+
if bgcolor:
|
| 429 |
+
back = bgcolor.downgrade(ColorSystem.WINDOWS).number
|
| 430 |
+
back = back if back is not None else 0 # Default to ANSI 0: Black
|
| 431 |
+
back = self.ANSI_TO_WINDOWS[back]
|
| 432 |
+
else:
|
| 433 |
+
back = self._default_back
|
| 434 |
+
|
| 435 |
+
assert fore is not None
|
| 436 |
+
assert back is not None
|
| 437 |
+
|
| 438 |
+
SetConsoleTextAttribute(
|
| 439 |
+
self._handle, attributes=ctypes.c_ushort(fore | (back << 4))
|
| 440 |
+
)
|
| 441 |
+
self.write_text(text)
|
| 442 |
+
SetConsoleTextAttribute(self._handle, attributes=self._default_text)
|
| 443 |
+
|
| 444 |
+
def move_cursor_to(self, new_position: WindowsCoordinates) -> None:
|
| 445 |
+
"""Set the position of the cursor
|
| 446 |
+
|
| 447 |
+
Args:
|
| 448 |
+
new_position (WindowsCoordinates): The WindowsCoordinates representing the new position of the cursor.
|
| 449 |
+
"""
|
| 450 |
+
if new_position.col < 0 or new_position.row < 0:
|
| 451 |
+
return
|
| 452 |
+
SetConsoleCursorPosition(self._handle, coords=new_position)
|
| 453 |
+
|
| 454 |
+
def erase_line(self) -> None:
|
| 455 |
+
"""Erase all content on the line the cursor is currently located at"""
|
| 456 |
+
screen_size = self.screen_size
|
| 457 |
+
cursor_position = self.cursor_position
|
| 458 |
+
cells_to_erase = screen_size.col
|
| 459 |
+
start_coordinates = WindowsCoordinates(row=cursor_position.row, col=0)
|
| 460 |
+
FillConsoleOutputCharacter(
|
| 461 |
+
self._handle, " ", length=cells_to_erase, start=start_coordinates
|
| 462 |
+
)
|
| 463 |
+
FillConsoleOutputAttribute(
|
| 464 |
+
self._handle,
|
| 465 |
+
self._default_attrs,
|
| 466 |
+
length=cells_to_erase,
|
| 467 |
+
start=start_coordinates,
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
def erase_end_of_line(self) -> None:
|
| 471 |
+
"""Erase all content from the cursor position to the end of that line"""
|
| 472 |
+
cursor_position = self.cursor_position
|
| 473 |
+
cells_to_erase = self.screen_size.col - cursor_position.col
|
| 474 |
+
FillConsoleOutputCharacter(
|
| 475 |
+
self._handle, " ", length=cells_to_erase, start=cursor_position
|
| 476 |
+
)
|
| 477 |
+
FillConsoleOutputAttribute(
|
| 478 |
+
self._handle,
|
| 479 |
+
self._default_attrs,
|
| 480 |
+
length=cells_to_erase,
|
| 481 |
+
start=cursor_position,
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
def erase_start_of_line(self) -> None:
|
| 485 |
+
"""Erase all content from the cursor position to the start of that line"""
|
| 486 |
+
row, col = self.cursor_position
|
| 487 |
+
start = WindowsCoordinates(row, 0)
|
| 488 |
+
FillConsoleOutputCharacter(self._handle, " ", length=col, start=start)
|
| 489 |
+
FillConsoleOutputAttribute(
|
| 490 |
+
self._handle, self._default_attrs, length=col, start=start
|
| 491 |
+
)
|
| 492 |
+
|
| 493 |
+
def move_cursor_up(self) -> None:
|
| 494 |
+
"""Move the cursor up a single cell"""
|
| 495 |
+
cursor_position = self.cursor_position
|
| 496 |
+
SetConsoleCursorPosition(
|
| 497 |
+
self._handle,
|
| 498 |
+
coords=WindowsCoordinates(
|
| 499 |
+
row=cursor_position.row - 1, col=cursor_position.col
|
| 500 |
+
),
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
def move_cursor_down(self) -> None:
|
| 504 |
+
"""Move the cursor down a single cell"""
|
| 505 |
+
cursor_position = self.cursor_position
|
| 506 |
+
SetConsoleCursorPosition(
|
| 507 |
+
self._handle,
|
| 508 |
+
coords=WindowsCoordinates(
|
| 509 |
+
row=cursor_position.row + 1,
|
| 510 |
+
col=cursor_position.col,
|
| 511 |
+
),
|
| 512 |
+
)
|
| 513 |
+
|
| 514 |
+
def move_cursor_forward(self) -> None:
|
| 515 |
+
"""Move the cursor forward a single cell. Wrap to the next line if required."""
|
| 516 |
+
row, col = self.cursor_position
|
| 517 |
+
if col == self.screen_size.col - 1:
|
| 518 |
+
row += 1
|
| 519 |
+
col = 0
|
| 520 |
+
else:
|
| 521 |
+
col += 1
|
| 522 |
+
SetConsoleCursorPosition(
|
| 523 |
+
self._handle, coords=WindowsCoordinates(row=row, col=col)
|
| 524 |
+
)
|
| 525 |
+
|
| 526 |
+
def move_cursor_to_column(self, column: int) -> None:
|
| 527 |
+
"""Move cursor to the column specified by the zero-based column index, staying on the same row
|
| 528 |
+
|
| 529 |
+
Args:
|
| 530 |
+
column (int): The zero-based column index to move the cursor to.
|
| 531 |
+
"""
|
| 532 |
+
row, _ = self.cursor_position
|
| 533 |
+
SetConsoleCursorPosition(self._handle, coords=WindowsCoordinates(row, column))
|
| 534 |
+
|
| 535 |
+
def move_cursor_backward(self) -> None:
|
| 536 |
+
"""Move the cursor backward a single cell. Wrap to the previous line if required."""
|
| 537 |
+
row, col = self.cursor_position
|
| 538 |
+
if col == 0:
|
| 539 |
+
row -= 1
|
| 540 |
+
col = self.screen_size.col - 1
|
| 541 |
+
else:
|
| 542 |
+
col -= 1
|
| 543 |
+
SetConsoleCursorPosition(
|
| 544 |
+
self._handle, coords=WindowsCoordinates(row=row, col=col)
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
def hide_cursor(self) -> None:
|
| 548 |
+
"""Hide the cursor"""
|
| 549 |
+
current_cursor_size = self._get_cursor_size()
|
| 550 |
+
invisible_cursor = CONSOLE_CURSOR_INFO(dwSize=current_cursor_size, bVisible=0)
|
| 551 |
+
SetConsoleCursorInfo(self._handle, cursor_info=invisible_cursor)
|
| 552 |
+
|
| 553 |
+
def show_cursor(self) -> None:
|
| 554 |
+
"""Show the cursor"""
|
| 555 |
+
current_cursor_size = self._get_cursor_size()
|
| 556 |
+
visible_cursor = CONSOLE_CURSOR_INFO(dwSize=current_cursor_size, bVisible=1)
|
| 557 |
+
SetConsoleCursorInfo(self._handle, cursor_info=visible_cursor)
|
| 558 |
+
|
| 559 |
+
def set_title(self, title: str) -> None:
|
| 560 |
+
"""Set the title of the terminal window
|
| 561 |
+
|
| 562 |
+
Args:
|
| 563 |
+
title (str): The new title of the console window
|
| 564 |
+
"""
|
| 565 |
+
assert len(title) < 255, "Console title must be less than 255 characters"
|
| 566 |
+
SetConsoleTitle(title)
|
| 567 |
+
|
| 568 |
+
def _get_cursor_size(self) -> int:
|
| 569 |
+
"""Get the percentage of the character cell that is filled by the cursor"""
|
| 570 |
+
cursor_info = CONSOLE_CURSOR_INFO()
|
| 571 |
+
GetConsoleCursorInfo(self._handle, cursor_info=cursor_info)
|
| 572 |
+
return int(cursor_info.dwSize)
|
| 573 |
+
|
| 574 |
+
|
| 575 |
+
if __name__ == "__main__":
|
| 576 |
+
handle = GetStdHandle()
|
| 577 |
+
|
| 578 |
+
from rich.console import Console
|
| 579 |
+
|
| 580 |
+
console = Console()
|
| 581 |
+
|
| 582 |
+
term = LegacyWindowsTerm(sys.stdout)
|
| 583 |
+
term.set_title("Win32 Console Examples")
|
| 584 |
+
|
| 585 |
+
style = Style(color="black", bgcolor="red")
|
| 586 |
+
|
| 587 |
+
heading = Style.parse("black on green")
|
| 588 |
+
|
| 589 |
+
# Check colour output
|
| 590 |
+
console.rule("Checking colour output")
|
| 591 |
+
console.print("[on red]on red!")
|
| 592 |
+
console.print("[blue]blue!")
|
| 593 |
+
console.print("[yellow]yellow!")
|
| 594 |
+
console.print("[bold yellow]bold yellow!")
|
| 595 |
+
console.print("[bright_yellow]bright_yellow!")
|
| 596 |
+
console.print("[dim bright_yellow]dim bright_yellow!")
|
| 597 |
+
console.print("[italic cyan]italic cyan!")
|
| 598 |
+
console.print("[bold white on blue]bold white on blue!")
|
| 599 |
+
console.print("[reverse bold white on blue]reverse bold white on blue!")
|
| 600 |
+
console.print("[bold black on cyan]bold black on cyan!")
|
| 601 |
+
console.print("[black on green]black on green!")
|
| 602 |
+
console.print("[blue on green]blue on green!")
|
| 603 |
+
console.print("[white on black]white on black!")
|
| 604 |
+
console.print("[black on white]black on white!")
|
| 605 |
+
console.print("[#1BB152 on #DA812D]#1BB152 on #DA812D!")
|
| 606 |
+
|
| 607 |
+
# Check cursor movement
|
| 608 |
+
console.rule("Checking cursor movement")
|
| 609 |
+
console.print()
|
| 610 |
+
term.move_cursor_backward()
|
| 611 |
+
term.move_cursor_backward()
|
| 612 |
+
term.write_text("went back and wrapped to prev line")
|
| 613 |
+
time.sleep(1)
|
| 614 |
+
term.move_cursor_up()
|
| 615 |
+
term.write_text("we go up")
|
| 616 |
+
time.sleep(1)
|
| 617 |
+
term.move_cursor_down()
|
| 618 |
+
term.write_text("and down")
|
| 619 |
+
time.sleep(1)
|
| 620 |
+
term.move_cursor_up()
|
| 621 |
+
term.move_cursor_backward()
|
| 622 |
+
term.move_cursor_backward()
|
| 623 |
+
term.write_text("we went up and back 2")
|
| 624 |
+
time.sleep(1)
|
| 625 |
+
term.move_cursor_down()
|
| 626 |
+
term.move_cursor_backward()
|
| 627 |
+
term.move_cursor_backward()
|
| 628 |
+
term.write_text("we went down and back 2")
|
| 629 |
+
time.sleep(1)
|
| 630 |
+
|
| 631 |
+
# Check erasing of lines
|
| 632 |
+
term.hide_cursor()
|
| 633 |
+
console.print()
|
| 634 |
+
console.rule("Checking line erasing")
|
| 635 |
+
console.print("\n...Deleting to the start of the line...")
|
| 636 |
+
term.write_text("The red arrow shows the cursor location, and direction of erase")
|
| 637 |
+
time.sleep(1)
|
| 638 |
+
term.move_cursor_to_column(16)
|
| 639 |
+
term.write_styled("<", Style.parse("black on red"))
|
| 640 |
+
term.move_cursor_backward()
|
| 641 |
+
time.sleep(1)
|
| 642 |
+
term.erase_start_of_line()
|
| 643 |
+
time.sleep(1)
|
| 644 |
+
|
| 645 |
+
console.print("\n\n...And to the end of the line...")
|
| 646 |
+
term.write_text("The red arrow shows the cursor location, and direction of erase")
|
| 647 |
+
time.sleep(1)
|
| 648 |
+
|
| 649 |
+
term.move_cursor_to_column(16)
|
| 650 |
+
term.write_styled(">", Style.parse("black on red"))
|
| 651 |
+
time.sleep(1)
|
| 652 |
+
term.erase_end_of_line()
|
| 653 |
+
time.sleep(1)
|
| 654 |
+
|
| 655 |
+
console.print("\n\n...Now the whole line will be erased...")
|
| 656 |
+
term.write_styled("I'm going to disappear!", style=Style.parse("black on cyan"))
|
| 657 |
+
time.sleep(1)
|
| 658 |
+
term.erase_line()
|
| 659 |
+
|
| 660 |
+
term.show_cursor()
|
| 661 |
+
print("\n")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_windows.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from dataclasses import dataclass
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
@dataclass
|
| 6 |
+
class WindowsConsoleFeatures:
|
| 7 |
+
"""Windows features available."""
|
| 8 |
+
|
| 9 |
+
vt: bool = False
|
| 10 |
+
"""The console supports VT codes."""
|
| 11 |
+
truecolor: bool = False
|
| 12 |
+
"""The console supports truecolor."""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
try:
|
| 16 |
+
import ctypes
|
| 17 |
+
from ctypes import LibraryLoader
|
| 18 |
+
|
| 19 |
+
if sys.platform == "win32":
|
| 20 |
+
windll = LibraryLoader(ctypes.WinDLL)
|
| 21 |
+
else:
|
| 22 |
+
windll = None
|
| 23 |
+
raise ImportError("Not windows")
|
| 24 |
+
|
| 25 |
+
from rich._win32_console import (
|
| 26 |
+
ENABLE_VIRTUAL_TERMINAL_PROCESSING,
|
| 27 |
+
GetConsoleMode,
|
| 28 |
+
GetStdHandle,
|
| 29 |
+
LegacyWindowsError,
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
except (AttributeError, ImportError, ValueError):
|
| 33 |
+
# Fallback if we can't load the Windows DLL
|
| 34 |
+
def get_windows_console_features() -> WindowsConsoleFeatures:
|
| 35 |
+
features = WindowsConsoleFeatures()
|
| 36 |
+
return features
|
| 37 |
+
|
| 38 |
+
else:
|
| 39 |
+
|
| 40 |
+
def get_windows_console_features() -> WindowsConsoleFeatures:
|
| 41 |
+
"""Get windows console features.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
WindowsConsoleFeatures: An instance of WindowsConsoleFeatures.
|
| 45 |
+
"""
|
| 46 |
+
handle = GetStdHandle()
|
| 47 |
+
try:
|
| 48 |
+
console_mode = GetConsoleMode(handle)
|
| 49 |
+
success = True
|
| 50 |
+
except LegacyWindowsError:
|
| 51 |
+
console_mode = 0
|
| 52 |
+
success = False
|
| 53 |
+
vt = bool(success and console_mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
| 54 |
+
truecolor = False
|
| 55 |
+
if vt:
|
| 56 |
+
win_version = sys.getwindowsversion()
|
| 57 |
+
truecolor = win_version.major > 10 or (
|
| 58 |
+
win_version.major == 10 and win_version.build >= 15063
|
| 59 |
+
)
|
| 60 |
+
features = WindowsConsoleFeatures(vt=vt, truecolor=truecolor)
|
| 61 |
+
return features
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
if __name__ == "__main__":
|
| 65 |
+
import platform
|
| 66 |
+
|
| 67 |
+
features = get_windows_console_features()
|
| 68 |
+
from rich import print
|
| 69 |
+
|
| 70 |
+
print(f'platform="{platform.system()}"')
|
| 71 |
+
print(repr(features))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_windows_renderer.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Iterable, Sequence, Tuple, cast
|
| 2 |
+
|
| 3 |
+
from rich._win32_console import LegacyWindowsTerm, WindowsCoordinates
|
| 4 |
+
from rich.segment import ControlCode, ControlType, Segment
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def legacy_windows_render(buffer: Iterable[Segment], term: LegacyWindowsTerm) -> None:
|
| 8 |
+
"""Makes appropriate Windows Console API calls based on the segments in the buffer.
|
| 9 |
+
|
| 10 |
+
Args:
|
| 11 |
+
buffer (Iterable[Segment]): Iterable of Segments to convert to Win32 API calls.
|
| 12 |
+
term (LegacyWindowsTerm): Used to call the Windows Console API.
|
| 13 |
+
"""
|
| 14 |
+
for text, style, control in buffer:
|
| 15 |
+
if not control:
|
| 16 |
+
if style:
|
| 17 |
+
term.write_styled(text, style)
|
| 18 |
+
else:
|
| 19 |
+
term.write_text(text)
|
| 20 |
+
else:
|
| 21 |
+
control_codes: Sequence[ControlCode] = control
|
| 22 |
+
for control_code in control_codes:
|
| 23 |
+
control_type = control_code[0]
|
| 24 |
+
if control_type == ControlType.CURSOR_MOVE_TO:
|
| 25 |
+
_, x, y = cast(Tuple[ControlType, int, int], control_code)
|
| 26 |
+
term.move_cursor_to(WindowsCoordinates(row=y - 1, col=x - 1))
|
| 27 |
+
elif control_type == ControlType.CARRIAGE_RETURN:
|
| 28 |
+
term.write_text("\r")
|
| 29 |
+
elif control_type == ControlType.HOME:
|
| 30 |
+
term.move_cursor_to(WindowsCoordinates(0, 0))
|
| 31 |
+
elif control_type == ControlType.CURSOR_UP:
|
| 32 |
+
term.move_cursor_up()
|
| 33 |
+
elif control_type == ControlType.CURSOR_DOWN:
|
| 34 |
+
term.move_cursor_down()
|
| 35 |
+
elif control_type == ControlType.CURSOR_FORWARD:
|
| 36 |
+
term.move_cursor_forward()
|
| 37 |
+
elif control_type == ControlType.CURSOR_BACKWARD:
|
| 38 |
+
term.move_cursor_backward()
|
| 39 |
+
elif control_type == ControlType.CURSOR_MOVE_TO_COLUMN:
|
| 40 |
+
_, column = cast(Tuple[ControlType, int], control_code)
|
| 41 |
+
term.move_cursor_to_column(column - 1)
|
| 42 |
+
elif control_type == ControlType.HIDE_CURSOR:
|
| 43 |
+
term.hide_cursor()
|
| 44 |
+
elif control_type == ControlType.SHOW_CURSOR:
|
| 45 |
+
term.show_cursor()
|
| 46 |
+
elif control_type == ControlType.ERASE_IN_LINE:
|
| 47 |
+
_, mode = cast(Tuple[ControlType, int], control_code)
|
| 48 |
+
if mode == 0:
|
| 49 |
+
term.erase_end_of_line()
|
| 50 |
+
elif mode == 1:
|
| 51 |
+
term.erase_start_of_line()
|
| 52 |
+
elif mode == 2:
|
| 53 |
+
term.erase_line()
|
| 54 |
+
elif control_type == ControlType.SET_WINDOW_TITLE:
|
| 55 |
+
_, title = cast(Tuple[ControlType, str], control_code)
|
| 56 |
+
term.set_title(title)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/_wrap.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import re
|
| 4 |
+
from typing import Iterable
|
| 5 |
+
|
| 6 |
+
from ._loop import loop_last
|
| 7 |
+
from .cells import cell_len, chop_cells
|
| 8 |
+
|
| 9 |
+
re_word = re.compile(r"\s*\S+\s*")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def words(text: str) -> Iterable[tuple[int, int, str]]:
|
| 13 |
+
"""Yields each word from the text as a tuple
|
| 14 |
+
containing (start_index, end_index, word). A "word" in this context may
|
| 15 |
+
include the actual word and any whitespace to the right.
|
| 16 |
+
"""
|
| 17 |
+
position = 0
|
| 18 |
+
word_match = re_word.match(text, position)
|
| 19 |
+
while word_match is not None:
|
| 20 |
+
start, end = word_match.span()
|
| 21 |
+
word = word_match.group(0)
|
| 22 |
+
yield start, end, word
|
| 23 |
+
word_match = re_word.match(text, end)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def divide_line(text: str, width: int, fold: bool = True) -> list[int]:
|
| 27 |
+
"""Given a string of text, and a width (measured in cells), return a list
|
| 28 |
+
of cell offsets which the string should be split at in order for it to fit
|
| 29 |
+
within the given width.
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
text: The text to examine.
|
| 33 |
+
width: The available cell width.
|
| 34 |
+
fold: If True, words longer than `width` will be folded onto a new line.
|
| 35 |
+
|
| 36 |
+
Returns:
|
| 37 |
+
A list of indices to break the line at.
|
| 38 |
+
"""
|
| 39 |
+
break_positions: list[int] = [] # offsets to insert the breaks at
|
| 40 |
+
append = break_positions.append
|
| 41 |
+
cell_offset = 0
|
| 42 |
+
_cell_len = cell_len
|
| 43 |
+
|
| 44 |
+
for start, _end, word in words(text):
|
| 45 |
+
word_length = _cell_len(word.rstrip())
|
| 46 |
+
remaining_space = width - cell_offset
|
| 47 |
+
word_fits_remaining_space = remaining_space >= word_length
|
| 48 |
+
|
| 49 |
+
if word_fits_remaining_space:
|
| 50 |
+
# Simplest case - the word fits within the remaining width for this line.
|
| 51 |
+
cell_offset += _cell_len(word)
|
| 52 |
+
else:
|
| 53 |
+
# Not enough space remaining for this word on the current line.
|
| 54 |
+
if word_length > width:
|
| 55 |
+
# The word doesn't fit on any line, so we can't simply
|
| 56 |
+
# place it on the next line...
|
| 57 |
+
if fold:
|
| 58 |
+
# Fold the word across multiple lines.
|
| 59 |
+
folded_word = chop_cells(word, width=width)
|
| 60 |
+
for last, line in loop_last(folded_word):
|
| 61 |
+
if start:
|
| 62 |
+
append(start)
|
| 63 |
+
if last:
|
| 64 |
+
cell_offset = _cell_len(line)
|
| 65 |
+
else:
|
| 66 |
+
start += len(line)
|
| 67 |
+
else:
|
| 68 |
+
# Folding isn't allowed, so crop the word.
|
| 69 |
+
if start:
|
| 70 |
+
append(start)
|
| 71 |
+
cell_offset = _cell_len(word)
|
| 72 |
+
elif cell_offset and start:
|
| 73 |
+
# The word doesn't fit within the remaining space on the current
|
| 74 |
+
# line, but it *can* fit on to the next (empty) line.
|
| 75 |
+
append(start)
|
| 76 |
+
cell_offset = _cell_len(word)
|
| 77 |
+
|
| 78 |
+
return break_positions
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__": # pragma: no cover
|
| 82 |
+
from .console import Console
|
| 83 |
+
|
| 84 |
+
console = Console(width=10)
|
| 85 |
+
console.print("12345 abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ 12345")
|
| 86 |
+
print(chop_cells("abcdefghijklmnopqrstuvwxyz", 10))
|
| 87 |
+
|
| 88 |
+
console = Console(width=20)
|
| 89 |
+
console.rule()
|
| 90 |
+
console.print("TextualはPythonの高速アプリケーション開発フレームワークです")
|
| 91 |
+
|
| 92 |
+
console.rule()
|
| 93 |
+
console.print("アプリケーションは1670万色を使用でき")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/abc.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class RichRenderable(ABC):
|
| 5 |
+
"""An abstract base class for Rich renderables.
|
| 6 |
+
|
| 7 |
+
Note that there is no need to extend this class, the intended use is to check if an
|
| 8 |
+
object supports the Rich renderable protocol. For example::
|
| 9 |
+
|
| 10 |
+
if isinstance(my_object, RichRenderable):
|
| 11 |
+
console.print(my_object)
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
@classmethod
|
| 16 |
+
def __subclasshook__(cls, other: type) -> bool:
|
| 17 |
+
"""Check if this class supports the rich render protocol."""
|
| 18 |
+
return hasattr(other, "__rich_console__") or hasattr(other, "__rich__")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__": # pragma: no cover
|
| 22 |
+
from rich.text import Text
|
| 23 |
+
|
| 24 |
+
t = Text()
|
| 25 |
+
print(isinstance(Text, RichRenderable))
|
| 26 |
+
print(isinstance(t, RichRenderable))
|
| 27 |
+
|
| 28 |
+
class Foo:
|
| 29 |
+
pass
|
| 30 |
+
|
| 31 |
+
f = Foo()
|
| 32 |
+
print(isinstance(f, RichRenderable))
|
| 33 |
+
print(isinstance("", RichRenderable))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/align.py
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from itertools import chain
|
| 3 |
+
from typing import TYPE_CHECKING, Iterable, Optional
|
| 4 |
+
|
| 5 |
+
if sys.version_info >= (3, 8):
|
| 6 |
+
from typing import Literal
|
| 7 |
+
else:
|
| 8 |
+
from typing_extensions import Literal # pragma: no cover
|
| 9 |
+
|
| 10 |
+
from .constrain import Constrain
|
| 11 |
+
from .jupyter import JupyterMixin
|
| 12 |
+
from .measure import Measurement
|
| 13 |
+
from .segment import Segment
|
| 14 |
+
from .style import StyleType
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
| 18 |
+
|
| 19 |
+
AlignMethod = Literal["left", "center", "right"]
|
| 20 |
+
VerticalAlignMethod = Literal["top", "middle", "bottom"]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class Align(JupyterMixin):
|
| 24 |
+
"""Align a renderable by adding spaces if necessary.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
renderable (RenderableType): A console renderable.
|
| 28 |
+
align (AlignMethod): One of "left", "center", or "right""
|
| 29 |
+
style (StyleType, optional): An optional style to apply to the background.
|
| 30 |
+
vertical (Optional[VerticalAlignMethod], optional): Optional vertical align, one of "top", "middle", or "bottom". Defaults to None.
|
| 31 |
+
pad (bool, optional): Pad the right with spaces. Defaults to True.
|
| 32 |
+
width (int, optional): Restrict contents to given width, or None to use default width. Defaults to None.
|
| 33 |
+
height (int, optional): Set height of align renderable, or None to fit to contents. Defaults to None.
|
| 34 |
+
|
| 35 |
+
Raises:
|
| 36 |
+
ValueError: if ``align`` is not one of the expected values.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
def __init__(
|
| 40 |
+
self,
|
| 41 |
+
renderable: "RenderableType",
|
| 42 |
+
align: AlignMethod = "left",
|
| 43 |
+
style: Optional[StyleType] = None,
|
| 44 |
+
*,
|
| 45 |
+
vertical: Optional[VerticalAlignMethod] = None,
|
| 46 |
+
pad: bool = True,
|
| 47 |
+
width: Optional[int] = None,
|
| 48 |
+
height: Optional[int] = None,
|
| 49 |
+
) -> None:
|
| 50 |
+
if align not in ("left", "center", "right"):
|
| 51 |
+
raise ValueError(
|
| 52 |
+
f'invalid value for align, expected "left", "center", or "right" (not {align!r})'
|
| 53 |
+
)
|
| 54 |
+
if vertical is not None and vertical not in ("top", "middle", "bottom"):
|
| 55 |
+
raise ValueError(
|
| 56 |
+
f'invalid value for vertical, expected "top", "middle", or "bottom" (not {vertical!r})'
|
| 57 |
+
)
|
| 58 |
+
self.renderable = renderable
|
| 59 |
+
self.align = align
|
| 60 |
+
self.style = style
|
| 61 |
+
self.vertical = vertical
|
| 62 |
+
self.pad = pad
|
| 63 |
+
self.width = width
|
| 64 |
+
self.height = height
|
| 65 |
+
|
| 66 |
+
def __repr__(self) -> str:
|
| 67 |
+
return f"Align({self.renderable!r}, {self.align!r})"
|
| 68 |
+
|
| 69 |
+
@classmethod
|
| 70 |
+
def left(
|
| 71 |
+
cls,
|
| 72 |
+
renderable: "RenderableType",
|
| 73 |
+
style: Optional[StyleType] = None,
|
| 74 |
+
*,
|
| 75 |
+
vertical: Optional[VerticalAlignMethod] = None,
|
| 76 |
+
pad: bool = True,
|
| 77 |
+
width: Optional[int] = None,
|
| 78 |
+
height: Optional[int] = None,
|
| 79 |
+
) -> "Align":
|
| 80 |
+
"""Align a renderable to the left."""
|
| 81 |
+
return cls(
|
| 82 |
+
renderable,
|
| 83 |
+
"left",
|
| 84 |
+
style=style,
|
| 85 |
+
vertical=vertical,
|
| 86 |
+
pad=pad,
|
| 87 |
+
width=width,
|
| 88 |
+
height=height,
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
@classmethod
|
| 92 |
+
def center(
|
| 93 |
+
cls,
|
| 94 |
+
renderable: "RenderableType",
|
| 95 |
+
style: Optional[StyleType] = None,
|
| 96 |
+
*,
|
| 97 |
+
vertical: Optional[VerticalAlignMethod] = None,
|
| 98 |
+
pad: bool = True,
|
| 99 |
+
width: Optional[int] = None,
|
| 100 |
+
height: Optional[int] = None,
|
| 101 |
+
) -> "Align":
|
| 102 |
+
"""Align a renderable to the center."""
|
| 103 |
+
return cls(
|
| 104 |
+
renderable,
|
| 105 |
+
"center",
|
| 106 |
+
style=style,
|
| 107 |
+
vertical=vertical,
|
| 108 |
+
pad=pad,
|
| 109 |
+
width=width,
|
| 110 |
+
height=height,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
@classmethod
|
| 114 |
+
def right(
|
| 115 |
+
cls,
|
| 116 |
+
renderable: "RenderableType",
|
| 117 |
+
style: Optional[StyleType] = None,
|
| 118 |
+
*,
|
| 119 |
+
vertical: Optional[VerticalAlignMethod] = None,
|
| 120 |
+
pad: bool = True,
|
| 121 |
+
width: Optional[int] = None,
|
| 122 |
+
height: Optional[int] = None,
|
| 123 |
+
) -> "Align":
|
| 124 |
+
"""Align a renderable to the right."""
|
| 125 |
+
return cls(
|
| 126 |
+
renderable,
|
| 127 |
+
"right",
|
| 128 |
+
style=style,
|
| 129 |
+
vertical=vertical,
|
| 130 |
+
pad=pad,
|
| 131 |
+
width=width,
|
| 132 |
+
height=height,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
def __rich_console__(
|
| 136 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 137 |
+
) -> "RenderResult":
|
| 138 |
+
align = self.align
|
| 139 |
+
width = console.measure(self.renderable, options=options).maximum
|
| 140 |
+
rendered = console.render(
|
| 141 |
+
Constrain(
|
| 142 |
+
self.renderable, width if self.width is None else min(width, self.width)
|
| 143 |
+
),
|
| 144 |
+
options.update(height=None),
|
| 145 |
+
)
|
| 146 |
+
lines = list(Segment.split_lines(rendered))
|
| 147 |
+
width, height = Segment.get_shape(lines)
|
| 148 |
+
lines = Segment.set_shape(lines, width, height)
|
| 149 |
+
new_line = Segment.line()
|
| 150 |
+
excess_space = options.max_width - width
|
| 151 |
+
style = console.get_style(self.style) if self.style is not None else None
|
| 152 |
+
|
| 153 |
+
def generate_segments() -> Iterable[Segment]:
|
| 154 |
+
if excess_space <= 0:
|
| 155 |
+
# Exact fit
|
| 156 |
+
for line in lines:
|
| 157 |
+
yield from line
|
| 158 |
+
yield new_line
|
| 159 |
+
|
| 160 |
+
elif align == "left":
|
| 161 |
+
# Pad on the right
|
| 162 |
+
pad = Segment(" " * excess_space, style) if self.pad else None
|
| 163 |
+
for line in lines:
|
| 164 |
+
yield from line
|
| 165 |
+
if pad:
|
| 166 |
+
yield pad
|
| 167 |
+
yield new_line
|
| 168 |
+
|
| 169 |
+
elif align == "center":
|
| 170 |
+
# Pad left and right
|
| 171 |
+
left = excess_space // 2
|
| 172 |
+
pad = Segment(" " * left, style)
|
| 173 |
+
pad_right = (
|
| 174 |
+
Segment(" " * (excess_space - left), style) if self.pad else None
|
| 175 |
+
)
|
| 176 |
+
for line in lines:
|
| 177 |
+
if left:
|
| 178 |
+
yield pad
|
| 179 |
+
yield from line
|
| 180 |
+
if pad_right:
|
| 181 |
+
yield pad_right
|
| 182 |
+
yield new_line
|
| 183 |
+
|
| 184 |
+
elif align == "right":
|
| 185 |
+
# Padding on left
|
| 186 |
+
pad = Segment(" " * excess_space, style)
|
| 187 |
+
for line in lines:
|
| 188 |
+
yield pad
|
| 189 |
+
yield from line
|
| 190 |
+
yield new_line
|
| 191 |
+
|
| 192 |
+
blank_line = (
|
| 193 |
+
Segment(f"{' ' * (self.width or options.max_width)}\n", style)
|
| 194 |
+
if self.pad
|
| 195 |
+
else Segment("\n")
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
def blank_lines(count: int) -> Iterable[Segment]:
|
| 199 |
+
if count > 0:
|
| 200 |
+
for _ in range(count):
|
| 201 |
+
yield blank_line
|
| 202 |
+
|
| 203 |
+
vertical_height = self.height or options.height
|
| 204 |
+
iter_segments: Iterable[Segment]
|
| 205 |
+
if self.vertical and vertical_height is not None:
|
| 206 |
+
if self.vertical == "top":
|
| 207 |
+
bottom_space = vertical_height - height
|
| 208 |
+
iter_segments = chain(generate_segments(), blank_lines(bottom_space))
|
| 209 |
+
elif self.vertical == "middle":
|
| 210 |
+
top_space = (vertical_height - height) // 2
|
| 211 |
+
bottom_space = vertical_height - top_space - height
|
| 212 |
+
iter_segments = chain(
|
| 213 |
+
blank_lines(top_space),
|
| 214 |
+
generate_segments(),
|
| 215 |
+
blank_lines(bottom_space),
|
| 216 |
+
)
|
| 217 |
+
else: # self.vertical == "bottom":
|
| 218 |
+
top_space = vertical_height - height
|
| 219 |
+
iter_segments = chain(blank_lines(top_space), generate_segments())
|
| 220 |
+
else:
|
| 221 |
+
iter_segments = generate_segments()
|
| 222 |
+
if self.style:
|
| 223 |
+
style = console.get_style(self.style)
|
| 224 |
+
iter_segments = Segment.apply_style(iter_segments, style)
|
| 225 |
+
yield from iter_segments
|
| 226 |
+
|
| 227 |
+
def __rich_measure__(
|
| 228 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 229 |
+
) -> Measurement:
|
| 230 |
+
measurement = Measurement.get(console, options, self.renderable)
|
| 231 |
+
return measurement
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
class VerticalCenter(JupyterMixin):
|
| 235 |
+
"""Vertically aligns a renderable.
|
| 236 |
+
|
| 237 |
+
Warn:
|
| 238 |
+
This class is deprecated and may be removed in a future version. Use Align class with
|
| 239 |
+
`vertical="middle"`.
|
| 240 |
+
|
| 241 |
+
Args:
|
| 242 |
+
renderable (RenderableType): A renderable object.
|
| 243 |
+
style (StyleType, optional): An optional style to apply to the background. Defaults to None.
|
| 244 |
+
"""
|
| 245 |
+
|
| 246 |
+
def __init__(
|
| 247 |
+
self,
|
| 248 |
+
renderable: "RenderableType",
|
| 249 |
+
style: Optional[StyleType] = None,
|
| 250 |
+
) -> None:
|
| 251 |
+
self.renderable = renderable
|
| 252 |
+
self.style = style
|
| 253 |
+
|
| 254 |
+
def __repr__(self) -> str:
|
| 255 |
+
return f"VerticalCenter({self.renderable!r})"
|
| 256 |
+
|
| 257 |
+
def __rich_console__(
|
| 258 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 259 |
+
) -> "RenderResult":
|
| 260 |
+
style = console.get_style(self.style) if self.style is not None else None
|
| 261 |
+
lines = console.render_lines(
|
| 262 |
+
self.renderable, options.update(height=None), pad=False
|
| 263 |
+
)
|
| 264 |
+
width, _height = Segment.get_shape(lines)
|
| 265 |
+
new_line = Segment.line()
|
| 266 |
+
height = options.height or options.size.height
|
| 267 |
+
top_space = (height - len(lines)) // 2
|
| 268 |
+
bottom_space = height - top_space - len(lines)
|
| 269 |
+
blank_line = Segment(f"{' ' * width}", style)
|
| 270 |
+
|
| 271 |
+
def blank_lines(count: int) -> Iterable[Segment]:
|
| 272 |
+
for _ in range(count):
|
| 273 |
+
yield blank_line
|
| 274 |
+
yield new_line
|
| 275 |
+
|
| 276 |
+
if top_space > 0:
|
| 277 |
+
yield from blank_lines(top_space)
|
| 278 |
+
for line in lines:
|
| 279 |
+
yield from line
|
| 280 |
+
yield new_line
|
| 281 |
+
if bottom_space > 0:
|
| 282 |
+
yield from blank_lines(bottom_space)
|
| 283 |
+
|
| 284 |
+
def __rich_measure__(
|
| 285 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 286 |
+
) -> Measurement:
|
| 287 |
+
measurement = Measurement.get(console, options, self.renderable)
|
| 288 |
+
return measurement
|
| 289 |
+
|
| 290 |
+
|
| 291 |
+
if __name__ == "__main__": # pragma: no cover
|
| 292 |
+
from rich.console import Console, Group
|
| 293 |
+
from rich.highlighter import ReprHighlighter
|
| 294 |
+
from rich.panel import Panel
|
| 295 |
+
|
| 296 |
+
highlighter = ReprHighlighter()
|
| 297 |
+
console = Console()
|
| 298 |
+
|
| 299 |
+
panel = Panel(
|
| 300 |
+
Group(
|
| 301 |
+
Align.left(highlighter("align='left'")),
|
| 302 |
+
Align.center(highlighter("align='center'")),
|
| 303 |
+
Align.right(highlighter("align='right'")),
|
| 304 |
+
),
|
| 305 |
+
width=60,
|
| 306 |
+
style="on dark_blue",
|
| 307 |
+
title="Align",
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
console.print(
|
| 311 |
+
Align.center(panel, vertical="middle", style="on red", height=console.height)
|
| 312 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/ansi.py
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import sys
|
| 3 |
+
from contextlib import suppress
|
| 4 |
+
from typing import Iterable, NamedTuple, Optional
|
| 5 |
+
|
| 6 |
+
from .color import Color
|
| 7 |
+
from .style import Style
|
| 8 |
+
from .text import Text
|
| 9 |
+
|
| 10 |
+
re_ansi = re.compile(
|
| 11 |
+
r"""
|
| 12 |
+
(?:\x1b[0-?])|
|
| 13 |
+
(?:\x1b\](.*?)\x1b\\)|
|
| 14 |
+
(?:\x1b([(@-Z\\-_]|\[[0-?]*[ -/]*[@-~]))
|
| 15 |
+
""",
|
| 16 |
+
re.VERBOSE,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class _AnsiToken(NamedTuple):
|
| 21 |
+
"""Result of ansi tokenized string."""
|
| 22 |
+
|
| 23 |
+
plain: str = ""
|
| 24 |
+
sgr: Optional[str] = ""
|
| 25 |
+
osc: Optional[str] = ""
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _ansi_tokenize(ansi_text: str) -> Iterable[_AnsiToken]:
|
| 29 |
+
"""Tokenize a string in to plain text and ANSI codes.
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
ansi_text (str): A String containing ANSI codes.
|
| 33 |
+
|
| 34 |
+
Yields:
|
| 35 |
+
AnsiToken: A named tuple of (plain, sgr, osc)
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
position = 0
|
| 39 |
+
sgr: Optional[str]
|
| 40 |
+
osc: Optional[str]
|
| 41 |
+
for match in re_ansi.finditer(ansi_text):
|
| 42 |
+
start, end = match.span(0)
|
| 43 |
+
osc, sgr = match.groups()
|
| 44 |
+
if start > position:
|
| 45 |
+
yield _AnsiToken(ansi_text[position:start])
|
| 46 |
+
if sgr:
|
| 47 |
+
if sgr == "(":
|
| 48 |
+
position = end + 1
|
| 49 |
+
continue
|
| 50 |
+
if sgr.endswith("m"):
|
| 51 |
+
yield _AnsiToken("", sgr[1:-1], osc)
|
| 52 |
+
else:
|
| 53 |
+
yield _AnsiToken("", sgr, osc)
|
| 54 |
+
position = end
|
| 55 |
+
if position < len(ansi_text):
|
| 56 |
+
yield _AnsiToken(ansi_text[position:])
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
SGR_STYLE_MAP = {
|
| 60 |
+
1: "bold",
|
| 61 |
+
2: "dim",
|
| 62 |
+
3: "italic",
|
| 63 |
+
4: "underline",
|
| 64 |
+
5: "blink",
|
| 65 |
+
6: "blink2",
|
| 66 |
+
7: "reverse",
|
| 67 |
+
8: "conceal",
|
| 68 |
+
9: "strike",
|
| 69 |
+
21: "underline2",
|
| 70 |
+
22: "not dim not bold",
|
| 71 |
+
23: "not italic",
|
| 72 |
+
24: "not underline",
|
| 73 |
+
25: "not blink",
|
| 74 |
+
26: "not blink2",
|
| 75 |
+
27: "not reverse",
|
| 76 |
+
28: "not conceal",
|
| 77 |
+
29: "not strike",
|
| 78 |
+
30: "color(0)",
|
| 79 |
+
31: "color(1)",
|
| 80 |
+
32: "color(2)",
|
| 81 |
+
33: "color(3)",
|
| 82 |
+
34: "color(4)",
|
| 83 |
+
35: "color(5)",
|
| 84 |
+
36: "color(6)",
|
| 85 |
+
37: "color(7)",
|
| 86 |
+
39: "default",
|
| 87 |
+
40: "on color(0)",
|
| 88 |
+
41: "on color(1)",
|
| 89 |
+
42: "on color(2)",
|
| 90 |
+
43: "on color(3)",
|
| 91 |
+
44: "on color(4)",
|
| 92 |
+
45: "on color(5)",
|
| 93 |
+
46: "on color(6)",
|
| 94 |
+
47: "on color(7)",
|
| 95 |
+
49: "on default",
|
| 96 |
+
51: "frame",
|
| 97 |
+
52: "encircle",
|
| 98 |
+
53: "overline",
|
| 99 |
+
54: "not frame not encircle",
|
| 100 |
+
55: "not overline",
|
| 101 |
+
90: "color(8)",
|
| 102 |
+
91: "color(9)",
|
| 103 |
+
92: "color(10)",
|
| 104 |
+
93: "color(11)",
|
| 105 |
+
94: "color(12)",
|
| 106 |
+
95: "color(13)",
|
| 107 |
+
96: "color(14)",
|
| 108 |
+
97: "color(15)",
|
| 109 |
+
100: "on color(8)",
|
| 110 |
+
101: "on color(9)",
|
| 111 |
+
102: "on color(10)",
|
| 112 |
+
103: "on color(11)",
|
| 113 |
+
104: "on color(12)",
|
| 114 |
+
105: "on color(13)",
|
| 115 |
+
106: "on color(14)",
|
| 116 |
+
107: "on color(15)",
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
class AnsiDecoder:
|
| 121 |
+
"""Translate ANSI code in to styled Text."""
|
| 122 |
+
|
| 123 |
+
def __init__(self) -> None:
|
| 124 |
+
self.style = Style.null()
|
| 125 |
+
|
| 126 |
+
def decode(self, terminal_text: str) -> Iterable[Text]:
|
| 127 |
+
"""Decode ANSI codes in an iterable of lines.
|
| 128 |
+
|
| 129 |
+
Args:
|
| 130 |
+
lines (Iterable[str]): An iterable of lines of terminal output.
|
| 131 |
+
|
| 132 |
+
Yields:
|
| 133 |
+
Text: Marked up Text.
|
| 134 |
+
"""
|
| 135 |
+
for line in terminal_text.splitlines():
|
| 136 |
+
yield self.decode_line(line)
|
| 137 |
+
|
| 138 |
+
def decode_line(self, line: str) -> Text:
|
| 139 |
+
"""Decode a line containing ansi codes.
|
| 140 |
+
|
| 141 |
+
Args:
|
| 142 |
+
line (str): A line of terminal output.
|
| 143 |
+
|
| 144 |
+
Returns:
|
| 145 |
+
Text: A Text instance marked up according to ansi codes.
|
| 146 |
+
"""
|
| 147 |
+
from_ansi = Color.from_ansi
|
| 148 |
+
from_rgb = Color.from_rgb
|
| 149 |
+
_Style = Style
|
| 150 |
+
text = Text()
|
| 151 |
+
append = text.append
|
| 152 |
+
line = line.rsplit("\r", 1)[-1]
|
| 153 |
+
for plain_text, sgr, osc in _ansi_tokenize(line):
|
| 154 |
+
if plain_text:
|
| 155 |
+
append(plain_text, self.style or None)
|
| 156 |
+
elif osc is not None:
|
| 157 |
+
if osc.startswith("8;"):
|
| 158 |
+
_params, semicolon, link = osc[2:].partition(";")
|
| 159 |
+
if semicolon:
|
| 160 |
+
self.style = self.style.update_link(link or None)
|
| 161 |
+
elif sgr is not None:
|
| 162 |
+
# Translate in to semi-colon separated codes
|
| 163 |
+
# Ignore invalid codes, because we want to be lenient
|
| 164 |
+
codes = [
|
| 165 |
+
min(255, int(_code) if _code else 0)
|
| 166 |
+
for _code in sgr.split(";")
|
| 167 |
+
if _code.isdigit() or _code == ""
|
| 168 |
+
]
|
| 169 |
+
iter_codes = iter(codes)
|
| 170 |
+
for code in iter_codes:
|
| 171 |
+
if code == 0:
|
| 172 |
+
# reset
|
| 173 |
+
self.style = _Style.null()
|
| 174 |
+
elif code in SGR_STYLE_MAP:
|
| 175 |
+
# styles
|
| 176 |
+
self.style += _Style.parse(SGR_STYLE_MAP[code])
|
| 177 |
+
elif code == 38:
|
| 178 |
+
# Foreground
|
| 179 |
+
with suppress(StopIteration):
|
| 180 |
+
color_type = next(iter_codes)
|
| 181 |
+
if color_type == 5:
|
| 182 |
+
self.style += _Style.from_color(
|
| 183 |
+
from_ansi(next(iter_codes))
|
| 184 |
+
)
|
| 185 |
+
elif color_type == 2:
|
| 186 |
+
self.style += _Style.from_color(
|
| 187 |
+
from_rgb(
|
| 188 |
+
next(iter_codes),
|
| 189 |
+
next(iter_codes),
|
| 190 |
+
next(iter_codes),
|
| 191 |
+
)
|
| 192 |
+
)
|
| 193 |
+
elif code == 48:
|
| 194 |
+
# Background
|
| 195 |
+
with suppress(StopIteration):
|
| 196 |
+
color_type = next(iter_codes)
|
| 197 |
+
if color_type == 5:
|
| 198 |
+
self.style += _Style.from_color(
|
| 199 |
+
None, from_ansi(next(iter_codes))
|
| 200 |
+
)
|
| 201 |
+
elif color_type == 2:
|
| 202 |
+
self.style += _Style.from_color(
|
| 203 |
+
None,
|
| 204 |
+
from_rgb(
|
| 205 |
+
next(iter_codes),
|
| 206 |
+
next(iter_codes),
|
| 207 |
+
next(iter_codes),
|
| 208 |
+
),
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
return text
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
if sys.platform != "win32" and __name__ == "__main__": # pragma: no cover
|
| 215 |
+
import io
|
| 216 |
+
import os
|
| 217 |
+
import pty
|
| 218 |
+
import sys
|
| 219 |
+
|
| 220 |
+
decoder = AnsiDecoder()
|
| 221 |
+
|
| 222 |
+
stdout = io.BytesIO()
|
| 223 |
+
|
| 224 |
+
def read(fd: int) -> bytes:
|
| 225 |
+
data = os.read(fd, 1024)
|
| 226 |
+
stdout.write(data)
|
| 227 |
+
return data
|
| 228 |
+
|
| 229 |
+
pty.spawn(sys.argv[1:], read)
|
| 230 |
+
|
| 231 |
+
from .console import Console
|
| 232 |
+
|
| 233 |
+
console = Console(record=True)
|
| 234 |
+
|
| 235 |
+
stdout_result = stdout.getvalue().decode("utf-8")
|
| 236 |
+
print(stdout_result)
|
| 237 |
+
|
| 238 |
+
for line in decoder.decode(stdout_result):
|
| 239 |
+
console.print(line)
|
| 240 |
+
|
| 241 |
+
console.save_html("stdout.html")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/bar.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional, Union
|
| 2 |
+
|
| 3 |
+
from .color import Color
|
| 4 |
+
from .console import Console, ConsoleOptions, RenderResult
|
| 5 |
+
from .jupyter import JupyterMixin
|
| 6 |
+
from .measure import Measurement
|
| 7 |
+
from .segment import Segment
|
| 8 |
+
from .style import Style
|
| 9 |
+
|
| 10 |
+
# There are left-aligned characters for 1/8 to 7/8, but
|
| 11 |
+
# the right-aligned characters exist only for 1/8 and 4/8.
|
| 12 |
+
BEGIN_BLOCK_ELEMENTS = ["█", "█", "█", "▐", "▐", "▐", "▕", "▕"]
|
| 13 |
+
END_BLOCK_ELEMENTS = [" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉"]
|
| 14 |
+
FULL_BLOCK = "█"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Bar(JupyterMixin):
|
| 18 |
+
"""Renders a solid block bar.
|
| 19 |
+
|
| 20 |
+
Args:
|
| 21 |
+
size (float): Value for the end of the bar.
|
| 22 |
+
begin (float): Begin point (between 0 and size, inclusive).
|
| 23 |
+
end (float): End point (between 0 and size, inclusive).
|
| 24 |
+
width (int, optional): Width of the bar, or ``None`` for maximum width. Defaults to None.
|
| 25 |
+
color (Union[Color, str], optional): Color of the bar. Defaults to "default".
|
| 26 |
+
bgcolor (Union[Color, str], optional): Color of bar background. Defaults to "default".
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
def __init__(
|
| 30 |
+
self,
|
| 31 |
+
size: float,
|
| 32 |
+
begin: float,
|
| 33 |
+
end: float,
|
| 34 |
+
*,
|
| 35 |
+
width: Optional[int] = None,
|
| 36 |
+
color: Union[Color, str] = "default",
|
| 37 |
+
bgcolor: Union[Color, str] = "default",
|
| 38 |
+
):
|
| 39 |
+
self.size = size
|
| 40 |
+
self.begin = max(begin, 0)
|
| 41 |
+
self.end = min(end, size)
|
| 42 |
+
self.width = width
|
| 43 |
+
self.style = Style(color=color, bgcolor=bgcolor)
|
| 44 |
+
|
| 45 |
+
def __repr__(self) -> str:
|
| 46 |
+
return f"Bar({self.size}, {self.begin}, {self.end})"
|
| 47 |
+
|
| 48 |
+
def __rich_console__(
|
| 49 |
+
self, console: Console, options: ConsoleOptions
|
| 50 |
+
) -> RenderResult:
|
| 51 |
+
width = min(
|
| 52 |
+
self.width if self.width is not None else options.max_width,
|
| 53 |
+
options.max_width,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
if self.begin >= self.end:
|
| 57 |
+
yield Segment(" " * width, self.style)
|
| 58 |
+
yield Segment.line()
|
| 59 |
+
return
|
| 60 |
+
|
| 61 |
+
prefix_complete_eights = int(width * 8 * self.begin / self.size)
|
| 62 |
+
prefix_bar_count = prefix_complete_eights // 8
|
| 63 |
+
prefix_eights_count = prefix_complete_eights % 8
|
| 64 |
+
|
| 65 |
+
body_complete_eights = int(width * 8 * self.end / self.size)
|
| 66 |
+
body_bar_count = body_complete_eights // 8
|
| 67 |
+
body_eights_count = body_complete_eights % 8
|
| 68 |
+
|
| 69 |
+
# When start and end fall into the same cell, we ideally should render
|
| 70 |
+
# a symbol that's "center-aligned", but there is no good symbol in Unicode.
|
| 71 |
+
# In this case, we fall back to right-aligned block symbol for simplicity.
|
| 72 |
+
|
| 73 |
+
prefix = " " * prefix_bar_count
|
| 74 |
+
if prefix_eights_count:
|
| 75 |
+
prefix += BEGIN_BLOCK_ELEMENTS[prefix_eights_count]
|
| 76 |
+
|
| 77 |
+
body = FULL_BLOCK * body_bar_count
|
| 78 |
+
if body_eights_count:
|
| 79 |
+
body += END_BLOCK_ELEMENTS[body_eights_count]
|
| 80 |
+
|
| 81 |
+
suffix = " " * (width - len(body))
|
| 82 |
+
|
| 83 |
+
yield Segment(prefix + body[len(prefix) :] + suffix, self.style)
|
| 84 |
+
yield Segment.line()
|
| 85 |
+
|
| 86 |
+
def __rich_measure__(
|
| 87 |
+
self, console: Console, options: ConsoleOptions
|
| 88 |
+
) -> Measurement:
|
| 89 |
+
return (
|
| 90 |
+
Measurement(self.width, self.width)
|
| 91 |
+
if self.width is not None
|
| 92 |
+
else Measurement(4, options.max_width)
|
| 93 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/box.py
ADDED
|
@@ -0,0 +1,480 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import TYPE_CHECKING, Iterable, List
|
| 3 |
+
|
| 4 |
+
if sys.version_info >= (3, 8):
|
| 5 |
+
from typing import Literal
|
| 6 |
+
else:
|
| 7 |
+
from typing_extensions import Literal # pragma: no cover
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
from ._loop import loop_last
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
from rich.console import ConsoleOptions
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class Box:
|
| 17 |
+
"""Defines characters to render boxes.
|
| 18 |
+
|
| 19 |
+
┌─┬┐ top
|
| 20 |
+
│ ││ head
|
| 21 |
+
├─┼┤ head_row
|
| 22 |
+
│ ││ mid
|
| 23 |
+
├─┼┤ row
|
| 24 |
+
├─┼┤ foot_row
|
| 25 |
+
│ ││ foot
|
| 26 |
+
└─┴┘ bottom
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
box (str): Characters making up box.
|
| 30 |
+
ascii (bool, optional): True if this box uses ascii characters only. Default is False.
|
| 31 |
+
"""
|
| 32 |
+
|
| 33 |
+
def __init__(self, box: str, *, ascii: bool = False) -> None:
|
| 34 |
+
self._box = box
|
| 35 |
+
self.ascii = ascii
|
| 36 |
+
line1, line2, line3, line4, line5, line6, line7, line8 = box.splitlines()
|
| 37 |
+
# top
|
| 38 |
+
self.top_left, self.top, self.top_divider, self.top_right = iter(line1)
|
| 39 |
+
# head
|
| 40 |
+
self.head_left, _, self.head_vertical, self.head_right = iter(line2)
|
| 41 |
+
# head_row
|
| 42 |
+
(
|
| 43 |
+
self.head_row_left,
|
| 44 |
+
self.head_row_horizontal,
|
| 45 |
+
self.head_row_cross,
|
| 46 |
+
self.head_row_right,
|
| 47 |
+
) = iter(line3)
|
| 48 |
+
|
| 49 |
+
# mid
|
| 50 |
+
self.mid_left, _, self.mid_vertical, self.mid_right = iter(line4)
|
| 51 |
+
# row
|
| 52 |
+
self.row_left, self.row_horizontal, self.row_cross, self.row_right = iter(line5)
|
| 53 |
+
# foot_row
|
| 54 |
+
(
|
| 55 |
+
self.foot_row_left,
|
| 56 |
+
self.foot_row_horizontal,
|
| 57 |
+
self.foot_row_cross,
|
| 58 |
+
self.foot_row_right,
|
| 59 |
+
) = iter(line6)
|
| 60 |
+
# foot
|
| 61 |
+
self.foot_left, _, self.foot_vertical, self.foot_right = iter(line7)
|
| 62 |
+
# bottom
|
| 63 |
+
self.bottom_left, self.bottom, self.bottom_divider, self.bottom_right = iter(
|
| 64 |
+
line8
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
def __repr__(self) -> str:
|
| 68 |
+
return "Box(...)"
|
| 69 |
+
|
| 70 |
+
def __str__(self) -> str:
|
| 71 |
+
return self._box
|
| 72 |
+
|
| 73 |
+
def substitute(self, options: "ConsoleOptions", safe: bool = True) -> "Box":
|
| 74 |
+
"""Substitute this box for another if it won't render due to platform issues.
|
| 75 |
+
|
| 76 |
+
Args:
|
| 77 |
+
options (ConsoleOptions): Console options used in rendering.
|
| 78 |
+
safe (bool, optional): Substitute this for another Box if there are known problems
|
| 79 |
+
displaying on the platform (currently only relevant on Windows). Default is True.
|
| 80 |
+
|
| 81 |
+
Returns:
|
| 82 |
+
Box: A different Box or the same Box.
|
| 83 |
+
"""
|
| 84 |
+
box = self
|
| 85 |
+
if options.legacy_windows and safe:
|
| 86 |
+
box = LEGACY_WINDOWS_SUBSTITUTIONS.get(box, box)
|
| 87 |
+
if options.ascii_only and not box.ascii:
|
| 88 |
+
box = ASCII
|
| 89 |
+
return box
|
| 90 |
+
|
| 91 |
+
def get_plain_headed_box(self) -> "Box":
|
| 92 |
+
"""If this box uses special characters for the borders of the header, then
|
| 93 |
+
return the equivalent box that does not.
|
| 94 |
+
|
| 95 |
+
Returns:
|
| 96 |
+
Box: The most similar Box that doesn't use header-specific box characters.
|
| 97 |
+
If the current Box already satisfies this criterion, then it's returned.
|
| 98 |
+
"""
|
| 99 |
+
return PLAIN_HEADED_SUBSTITUTIONS.get(self, self)
|
| 100 |
+
|
| 101 |
+
def get_top(self, widths: Iterable[int]) -> str:
|
| 102 |
+
"""Get the top of a simple box.
|
| 103 |
+
|
| 104 |
+
Args:
|
| 105 |
+
widths (List[int]): Widths of columns.
|
| 106 |
+
|
| 107 |
+
Returns:
|
| 108 |
+
str: A string of box characters.
|
| 109 |
+
"""
|
| 110 |
+
|
| 111 |
+
parts: List[str] = []
|
| 112 |
+
append = parts.append
|
| 113 |
+
append(self.top_left)
|
| 114 |
+
for last, width in loop_last(widths):
|
| 115 |
+
append(self.top * width)
|
| 116 |
+
if not last:
|
| 117 |
+
append(self.top_divider)
|
| 118 |
+
append(self.top_right)
|
| 119 |
+
return "".join(parts)
|
| 120 |
+
|
| 121 |
+
def get_row(
|
| 122 |
+
self,
|
| 123 |
+
widths: Iterable[int],
|
| 124 |
+
level: Literal["head", "row", "foot", "mid"] = "row",
|
| 125 |
+
edge: bool = True,
|
| 126 |
+
) -> str:
|
| 127 |
+
"""Get the top of a simple box.
|
| 128 |
+
|
| 129 |
+
Args:
|
| 130 |
+
width (List[int]): Widths of columns.
|
| 131 |
+
|
| 132 |
+
Returns:
|
| 133 |
+
str: A string of box characters.
|
| 134 |
+
"""
|
| 135 |
+
if level == "head":
|
| 136 |
+
left = self.head_row_left
|
| 137 |
+
horizontal = self.head_row_horizontal
|
| 138 |
+
cross = self.head_row_cross
|
| 139 |
+
right = self.head_row_right
|
| 140 |
+
elif level == "row":
|
| 141 |
+
left = self.row_left
|
| 142 |
+
horizontal = self.row_horizontal
|
| 143 |
+
cross = self.row_cross
|
| 144 |
+
right = self.row_right
|
| 145 |
+
elif level == "mid":
|
| 146 |
+
left = self.mid_left
|
| 147 |
+
horizontal = " "
|
| 148 |
+
cross = self.mid_vertical
|
| 149 |
+
right = self.mid_right
|
| 150 |
+
elif level == "foot":
|
| 151 |
+
left = self.foot_row_left
|
| 152 |
+
horizontal = self.foot_row_horizontal
|
| 153 |
+
cross = self.foot_row_cross
|
| 154 |
+
right = self.foot_row_right
|
| 155 |
+
else:
|
| 156 |
+
raise ValueError("level must be 'head', 'row' or 'foot'")
|
| 157 |
+
|
| 158 |
+
parts: List[str] = []
|
| 159 |
+
append = parts.append
|
| 160 |
+
if edge:
|
| 161 |
+
append(left)
|
| 162 |
+
for last, width in loop_last(widths):
|
| 163 |
+
append(horizontal * width)
|
| 164 |
+
if not last:
|
| 165 |
+
append(cross)
|
| 166 |
+
if edge:
|
| 167 |
+
append(right)
|
| 168 |
+
return "".join(parts)
|
| 169 |
+
|
| 170 |
+
def get_bottom(self, widths: Iterable[int]) -> str:
|
| 171 |
+
"""Get the bottom of a simple box.
|
| 172 |
+
|
| 173 |
+
Args:
|
| 174 |
+
widths (List[int]): Widths of columns.
|
| 175 |
+
|
| 176 |
+
Returns:
|
| 177 |
+
str: A string of box characters.
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
parts: List[str] = []
|
| 181 |
+
append = parts.append
|
| 182 |
+
append(self.bottom_left)
|
| 183 |
+
for last, width in loop_last(widths):
|
| 184 |
+
append(self.bottom * width)
|
| 185 |
+
if not last:
|
| 186 |
+
append(self.bottom_divider)
|
| 187 |
+
append(self.bottom_right)
|
| 188 |
+
return "".join(parts)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
# fmt: off
|
| 192 |
+
ASCII: Box = Box(
|
| 193 |
+
"+--+\n"
|
| 194 |
+
"| ||\n"
|
| 195 |
+
"|-+|\n"
|
| 196 |
+
"| ||\n"
|
| 197 |
+
"|-+|\n"
|
| 198 |
+
"|-+|\n"
|
| 199 |
+
"| ||\n"
|
| 200 |
+
"+--+\n",
|
| 201 |
+
ascii=True,
|
| 202 |
+
)
|
| 203 |
+
|
| 204 |
+
ASCII2: Box = Box(
|
| 205 |
+
"+-++\n"
|
| 206 |
+
"| ||\n"
|
| 207 |
+
"+-++\n"
|
| 208 |
+
"| ||\n"
|
| 209 |
+
"+-++\n"
|
| 210 |
+
"+-++\n"
|
| 211 |
+
"| ||\n"
|
| 212 |
+
"+-++\n",
|
| 213 |
+
ascii=True,
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
ASCII_DOUBLE_HEAD: Box = Box(
|
| 217 |
+
"+-++\n"
|
| 218 |
+
"| ||\n"
|
| 219 |
+
"+=++\n"
|
| 220 |
+
"| ||\n"
|
| 221 |
+
"+-++\n"
|
| 222 |
+
"+-++\n"
|
| 223 |
+
"| ||\n"
|
| 224 |
+
"+-++\n",
|
| 225 |
+
ascii=True,
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
SQUARE: Box = Box(
|
| 229 |
+
"┌─┬┐\n"
|
| 230 |
+
"│ ││\n"
|
| 231 |
+
"├─┼┤\n"
|
| 232 |
+
"│ ││\n"
|
| 233 |
+
"├─┼┤\n"
|
| 234 |
+
"├─┼┤\n"
|
| 235 |
+
"│ ││\n"
|
| 236 |
+
"└─┴┘\n"
|
| 237 |
+
)
|
| 238 |
+
|
| 239 |
+
SQUARE_DOUBLE_HEAD: Box = Box(
|
| 240 |
+
"┌─┬┐\n"
|
| 241 |
+
"│ ││\n"
|
| 242 |
+
"╞═╪╡\n"
|
| 243 |
+
"│ ││\n"
|
| 244 |
+
"├─┼┤\n"
|
| 245 |
+
"├─┼┤\n"
|
| 246 |
+
"│ ││\n"
|
| 247 |
+
"└─┴┘\n"
|
| 248 |
+
)
|
| 249 |
+
|
| 250 |
+
MINIMAL: Box = Box(
|
| 251 |
+
" ╷ \n"
|
| 252 |
+
" │ \n"
|
| 253 |
+
"╶─┼╴\n"
|
| 254 |
+
" │ \n"
|
| 255 |
+
"╶─┼╴\n"
|
| 256 |
+
"╶─┼╴\n"
|
| 257 |
+
" │ \n"
|
| 258 |
+
" ╵ \n"
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
MINIMAL_HEAVY_HEAD: Box = Box(
|
| 263 |
+
" ╷ \n"
|
| 264 |
+
" │ \n"
|
| 265 |
+
"╺━┿╸\n"
|
| 266 |
+
" │ \n"
|
| 267 |
+
"╶─┼╴\n"
|
| 268 |
+
"╶─┼╴\n"
|
| 269 |
+
" │ \n"
|
| 270 |
+
" ╵ \n"
|
| 271 |
+
)
|
| 272 |
+
|
| 273 |
+
MINIMAL_DOUBLE_HEAD: Box = Box(
|
| 274 |
+
" ╷ \n"
|
| 275 |
+
" │ \n"
|
| 276 |
+
" ═╪ \n"
|
| 277 |
+
" │ \n"
|
| 278 |
+
" ─┼ \n"
|
| 279 |
+
" ─┼ \n"
|
| 280 |
+
" │ \n"
|
| 281 |
+
" ╵ \n"
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
SIMPLE: Box = Box(
|
| 286 |
+
" \n"
|
| 287 |
+
" \n"
|
| 288 |
+
" ── \n"
|
| 289 |
+
" \n"
|
| 290 |
+
" \n"
|
| 291 |
+
" ── \n"
|
| 292 |
+
" \n"
|
| 293 |
+
" \n"
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
SIMPLE_HEAD: Box = Box(
|
| 297 |
+
" \n"
|
| 298 |
+
" \n"
|
| 299 |
+
" ── \n"
|
| 300 |
+
" \n"
|
| 301 |
+
" \n"
|
| 302 |
+
" \n"
|
| 303 |
+
" \n"
|
| 304 |
+
" \n"
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
SIMPLE_HEAVY: Box = Box(
|
| 309 |
+
" \n"
|
| 310 |
+
" \n"
|
| 311 |
+
" ━━ \n"
|
| 312 |
+
" \n"
|
| 313 |
+
" \n"
|
| 314 |
+
" ━━ \n"
|
| 315 |
+
" \n"
|
| 316 |
+
" \n"
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
HORIZONTALS: Box = Box(
|
| 321 |
+
" ── \n"
|
| 322 |
+
" \n"
|
| 323 |
+
" ── \n"
|
| 324 |
+
" \n"
|
| 325 |
+
" ── \n"
|
| 326 |
+
" ── \n"
|
| 327 |
+
" \n"
|
| 328 |
+
" ── \n"
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
ROUNDED: Box = Box(
|
| 332 |
+
"╭─┬╮\n"
|
| 333 |
+
"│ ││\n"
|
| 334 |
+
"├─┼┤\n"
|
| 335 |
+
"│ ││\n"
|
| 336 |
+
"├─┼┤\n"
|
| 337 |
+
"├─┼┤\n"
|
| 338 |
+
"│ ││\n"
|
| 339 |
+
"╰─┴╯\n"
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
HEAVY: Box = Box(
|
| 343 |
+
"┏━┳┓\n"
|
| 344 |
+
"┃ ┃┃\n"
|
| 345 |
+
"┣━╋┫\n"
|
| 346 |
+
"┃ ┃┃\n"
|
| 347 |
+
"┣━╋┫\n"
|
| 348 |
+
"┣━╋┫\n"
|
| 349 |
+
"┃ ┃┃\n"
|
| 350 |
+
"┗━┻┛\n"
|
| 351 |
+
)
|
| 352 |
+
|
| 353 |
+
HEAVY_EDGE: Box = Box(
|
| 354 |
+
"┏━┯┓\n"
|
| 355 |
+
"┃ │┃\n"
|
| 356 |
+
"┠─┼┨\n"
|
| 357 |
+
"┃ │┃\n"
|
| 358 |
+
"┠─┼┨\n"
|
| 359 |
+
"┠─┼┨\n"
|
| 360 |
+
"┃ │┃\n"
|
| 361 |
+
"┗━┷┛\n"
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
HEAVY_HEAD: Box = Box(
|
| 365 |
+
"┏━┳┓\n"
|
| 366 |
+
"┃ ┃┃\n"
|
| 367 |
+
"┡━╇┩\n"
|
| 368 |
+
"│ ││\n"
|
| 369 |
+
"├─┼┤\n"
|
| 370 |
+
"├─┼┤\n"
|
| 371 |
+
"│ ││\n"
|
| 372 |
+
"└─┴┘\n"
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
DOUBLE: Box = Box(
|
| 376 |
+
"╔═╦╗\n"
|
| 377 |
+
"║ ║║\n"
|
| 378 |
+
"╠═╬╣\n"
|
| 379 |
+
"║ ║║\n"
|
| 380 |
+
"╠═╬╣\n"
|
| 381 |
+
"╠═╬╣\n"
|
| 382 |
+
"║ ║║\n"
|
| 383 |
+
"╚═╩╝\n"
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
DOUBLE_EDGE: Box = Box(
|
| 387 |
+
"╔═╤╗\n"
|
| 388 |
+
"║ │║\n"
|
| 389 |
+
"╟─┼╢\n"
|
| 390 |
+
"║ │║\n"
|
| 391 |
+
"╟─┼╢\n"
|
| 392 |
+
"╟─┼╢\n"
|
| 393 |
+
"║ │║\n"
|
| 394 |
+
"╚═╧╝\n"
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
MARKDOWN: Box = Box(
|
| 398 |
+
" \n"
|
| 399 |
+
"| ||\n"
|
| 400 |
+
"|-||\n"
|
| 401 |
+
"| ||\n"
|
| 402 |
+
"|-||\n"
|
| 403 |
+
"|-||\n"
|
| 404 |
+
"| ||\n"
|
| 405 |
+
" \n",
|
| 406 |
+
ascii=True,
|
| 407 |
+
)
|
| 408 |
+
# fmt: on
|
| 409 |
+
|
| 410 |
+
# Map Boxes that don't render with raster fonts on to equivalent that do
|
| 411 |
+
LEGACY_WINDOWS_SUBSTITUTIONS = {
|
| 412 |
+
ROUNDED: SQUARE,
|
| 413 |
+
MINIMAL_HEAVY_HEAD: MINIMAL,
|
| 414 |
+
SIMPLE_HEAVY: SIMPLE,
|
| 415 |
+
HEAVY: SQUARE,
|
| 416 |
+
HEAVY_EDGE: SQUARE,
|
| 417 |
+
HEAVY_HEAD: SQUARE,
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
# Map headed boxes to their headerless equivalents
|
| 421 |
+
PLAIN_HEADED_SUBSTITUTIONS = {
|
| 422 |
+
HEAVY_HEAD: SQUARE,
|
| 423 |
+
SQUARE_DOUBLE_HEAD: SQUARE,
|
| 424 |
+
MINIMAL_DOUBLE_HEAD: MINIMAL,
|
| 425 |
+
MINIMAL_HEAVY_HEAD: MINIMAL,
|
| 426 |
+
ASCII_DOUBLE_HEAD: ASCII2,
|
| 427 |
+
}
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
if __name__ == "__main__": # pragma: no cover
|
| 431 |
+
from rich.columns import Columns
|
| 432 |
+
from rich.panel import Panel
|
| 433 |
+
|
| 434 |
+
from . import box as box
|
| 435 |
+
from .console import Console
|
| 436 |
+
from .table import Table
|
| 437 |
+
from .text import Text
|
| 438 |
+
|
| 439 |
+
console = Console(record=True)
|
| 440 |
+
|
| 441 |
+
BOXES = [
|
| 442 |
+
"ASCII",
|
| 443 |
+
"ASCII2",
|
| 444 |
+
"ASCII_DOUBLE_HEAD",
|
| 445 |
+
"SQUARE",
|
| 446 |
+
"SQUARE_DOUBLE_HEAD",
|
| 447 |
+
"MINIMAL",
|
| 448 |
+
"MINIMAL_HEAVY_HEAD",
|
| 449 |
+
"MINIMAL_DOUBLE_HEAD",
|
| 450 |
+
"SIMPLE",
|
| 451 |
+
"SIMPLE_HEAD",
|
| 452 |
+
"SIMPLE_HEAVY",
|
| 453 |
+
"HORIZONTALS",
|
| 454 |
+
"ROUNDED",
|
| 455 |
+
"HEAVY",
|
| 456 |
+
"HEAVY_EDGE",
|
| 457 |
+
"HEAVY_HEAD",
|
| 458 |
+
"DOUBLE",
|
| 459 |
+
"DOUBLE_EDGE",
|
| 460 |
+
"MARKDOWN",
|
| 461 |
+
]
|
| 462 |
+
|
| 463 |
+
console.print(Panel("[bold green]Box Constants", style="green"), justify="center")
|
| 464 |
+
console.print()
|
| 465 |
+
|
| 466 |
+
columns = Columns(expand=True, padding=2)
|
| 467 |
+
for box_name in sorted(BOXES):
|
| 468 |
+
table = Table(
|
| 469 |
+
show_footer=True, style="dim", border_style="not dim", expand=True
|
| 470 |
+
)
|
| 471 |
+
table.add_column("Header 1", "Footer 1")
|
| 472 |
+
table.add_column("Header 2", "Footer 2")
|
| 473 |
+
table.add_row("Cell", "Cell")
|
| 474 |
+
table.add_row("Cell", "Cell")
|
| 475 |
+
table.box = getattr(box, box_name)
|
| 476 |
+
table.title = Text(f"box.{box_name}", style="magenta")
|
| 477 |
+
columns.add_renderable(table)
|
| 478 |
+
console.print(columns)
|
| 479 |
+
|
| 480 |
+
# console.save_svg("box.svg")
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/cells.py
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from functools import lru_cache
|
| 4 |
+
from typing import Callable
|
| 5 |
+
|
| 6 |
+
from ._cell_widths import CELL_WIDTHS
|
| 7 |
+
|
| 8 |
+
# Ranges of unicode ordinals that produce a 1-cell wide character
|
| 9 |
+
# This is non-exhaustive, but covers most common Western characters
|
| 10 |
+
_SINGLE_CELL_UNICODE_RANGES: list[tuple[int, int]] = [
|
| 11 |
+
(0x20, 0x7E), # Latin (excluding non-printable)
|
| 12 |
+
(0xA0, 0xAC),
|
| 13 |
+
(0xAE, 0x002FF),
|
| 14 |
+
(0x00370, 0x00482), # Greek / Cyrillic
|
| 15 |
+
(0x02500, 0x025FC), # Box drawing, box elements, geometric shapes
|
| 16 |
+
(0x02800, 0x028FF), # Braille
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# A set of characters that are a single cell wide
|
| 20 |
+
_SINGLE_CELLS = frozenset(
|
| 21 |
+
[
|
| 22 |
+
character
|
| 23 |
+
for _start, _end in _SINGLE_CELL_UNICODE_RANGES
|
| 24 |
+
for character in map(chr, range(_start, _end + 1))
|
| 25 |
+
]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# When called with a string this will return True if all
|
| 29 |
+
# characters are single-cell, otherwise False
|
| 30 |
+
_is_single_cell_widths: Callable[[str], bool] = _SINGLE_CELLS.issuperset
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@lru_cache(4096)
|
| 34 |
+
def cached_cell_len(text: str) -> int:
|
| 35 |
+
"""Get the number of cells required to display text.
|
| 36 |
+
|
| 37 |
+
This method always caches, which may use up a lot of memory. It is recommended to use
|
| 38 |
+
`cell_len` over this method.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
text (str): Text to display.
|
| 42 |
+
|
| 43 |
+
Returns:
|
| 44 |
+
int: Get the number of cells required to display text.
|
| 45 |
+
"""
|
| 46 |
+
if _is_single_cell_widths(text):
|
| 47 |
+
return len(text)
|
| 48 |
+
return sum(map(get_character_cell_size, text))
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def cell_len(text: str, _cell_len: Callable[[str], int] = cached_cell_len) -> int:
|
| 52 |
+
"""Get the number of cells required to display text.
|
| 53 |
+
|
| 54 |
+
Args:
|
| 55 |
+
text (str): Text to display.
|
| 56 |
+
|
| 57 |
+
Returns:
|
| 58 |
+
int: Get the number of cells required to display text.
|
| 59 |
+
"""
|
| 60 |
+
if len(text) < 512:
|
| 61 |
+
return _cell_len(text)
|
| 62 |
+
if _is_single_cell_widths(text):
|
| 63 |
+
return len(text)
|
| 64 |
+
return sum(map(get_character_cell_size, text))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@lru_cache(maxsize=4096)
|
| 68 |
+
def get_character_cell_size(character: str) -> int:
|
| 69 |
+
"""Get the cell size of a character.
|
| 70 |
+
|
| 71 |
+
Args:
|
| 72 |
+
character (str): A single character.
|
| 73 |
+
|
| 74 |
+
Returns:
|
| 75 |
+
int: Number of cells (0, 1 or 2) occupied by that character.
|
| 76 |
+
"""
|
| 77 |
+
codepoint = ord(character)
|
| 78 |
+
_table = CELL_WIDTHS
|
| 79 |
+
lower_bound = 0
|
| 80 |
+
upper_bound = len(_table) - 1
|
| 81 |
+
index = (lower_bound + upper_bound) // 2
|
| 82 |
+
while True:
|
| 83 |
+
start, end, width = _table[index]
|
| 84 |
+
if codepoint < start:
|
| 85 |
+
upper_bound = index - 1
|
| 86 |
+
elif codepoint > end:
|
| 87 |
+
lower_bound = index + 1
|
| 88 |
+
else:
|
| 89 |
+
return 0 if width == -1 else width
|
| 90 |
+
if upper_bound < lower_bound:
|
| 91 |
+
break
|
| 92 |
+
index = (lower_bound + upper_bound) // 2
|
| 93 |
+
return 1
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def set_cell_size(text: str, total: int) -> str:
|
| 97 |
+
"""Set the length of a string to fit within given number of cells."""
|
| 98 |
+
|
| 99 |
+
if _is_single_cell_widths(text):
|
| 100 |
+
size = len(text)
|
| 101 |
+
if size < total:
|
| 102 |
+
return text + " " * (total - size)
|
| 103 |
+
return text[:total]
|
| 104 |
+
|
| 105 |
+
if total <= 0:
|
| 106 |
+
return ""
|
| 107 |
+
cell_size = cell_len(text)
|
| 108 |
+
if cell_size == total:
|
| 109 |
+
return text
|
| 110 |
+
if cell_size < total:
|
| 111 |
+
return text + " " * (total - cell_size)
|
| 112 |
+
|
| 113 |
+
start = 0
|
| 114 |
+
end = len(text)
|
| 115 |
+
|
| 116 |
+
# Binary search until we find the right size
|
| 117 |
+
while True:
|
| 118 |
+
pos = (start + end) // 2
|
| 119 |
+
before = text[: pos + 1]
|
| 120 |
+
before_len = cell_len(before)
|
| 121 |
+
if before_len == total + 1 and cell_len(before[-1]) == 2:
|
| 122 |
+
return before[:-1] + " "
|
| 123 |
+
if before_len == total:
|
| 124 |
+
return before
|
| 125 |
+
if before_len > total:
|
| 126 |
+
end = pos
|
| 127 |
+
else:
|
| 128 |
+
start = pos
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def chop_cells(
|
| 132 |
+
text: str,
|
| 133 |
+
width: int,
|
| 134 |
+
) -> list[str]:
|
| 135 |
+
"""Split text into lines such that each line fits within the available (cell) width.
|
| 136 |
+
|
| 137 |
+
Args:
|
| 138 |
+
text: The text to fold such that it fits in the given width.
|
| 139 |
+
width: The width available (number of cells).
|
| 140 |
+
|
| 141 |
+
Returns:
|
| 142 |
+
A list of strings such that each string in the list has cell width
|
| 143 |
+
less than or equal to the available width.
|
| 144 |
+
"""
|
| 145 |
+
_get_character_cell_size = get_character_cell_size
|
| 146 |
+
lines: list[list[str]] = [[]]
|
| 147 |
+
|
| 148 |
+
append_new_line = lines.append
|
| 149 |
+
append_to_last_line = lines[-1].append
|
| 150 |
+
|
| 151 |
+
total_width = 0
|
| 152 |
+
|
| 153 |
+
for character in text:
|
| 154 |
+
cell_width = _get_character_cell_size(character)
|
| 155 |
+
char_doesnt_fit = total_width + cell_width > width
|
| 156 |
+
|
| 157 |
+
if char_doesnt_fit:
|
| 158 |
+
append_new_line([character])
|
| 159 |
+
append_to_last_line = lines[-1].append
|
| 160 |
+
total_width = cell_width
|
| 161 |
+
else:
|
| 162 |
+
append_to_last_line(character)
|
| 163 |
+
total_width += cell_width
|
| 164 |
+
|
| 165 |
+
return ["".join(line) for line in lines]
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
if __name__ == "__main__": # pragma: no cover
|
| 169 |
+
print(get_character_cell_size("😽"))
|
| 170 |
+
for line in chop_cells("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", 8):
|
| 171 |
+
print(line)
|
| 172 |
+
for n in range(80, 1, -1):
|
| 173 |
+
print(set_cell_size("""这是对亚洲语言支持的测试。面对模棱两可的想法,拒绝猜测的诱惑。""", n) + "|")
|
| 174 |
+
print("x" * n)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/color.py
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import sys
|
| 3 |
+
from colorsys import rgb_to_hls
|
| 4 |
+
from enum import IntEnum
|
| 5 |
+
from functools import lru_cache
|
| 6 |
+
from typing import TYPE_CHECKING, NamedTuple, Optional, Tuple
|
| 7 |
+
|
| 8 |
+
from ._palettes import EIGHT_BIT_PALETTE, STANDARD_PALETTE, WINDOWS_PALETTE
|
| 9 |
+
from .color_triplet import ColorTriplet
|
| 10 |
+
from .repr import Result, rich_repr
|
| 11 |
+
from .terminal_theme import DEFAULT_TERMINAL_THEME
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING: # pragma: no cover
|
| 14 |
+
from .terminal_theme import TerminalTheme
|
| 15 |
+
from .text import Text
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
WINDOWS = sys.platform == "win32"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class ColorSystem(IntEnum):
|
| 22 |
+
"""One of the 3 color system supported by terminals."""
|
| 23 |
+
|
| 24 |
+
STANDARD = 1
|
| 25 |
+
EIGHT_BIT = 2
|
| 26 |
+
TRUECOLOR = 3
|
| 27 |
+
WINDOWS = 4
|
| 28 |
+
|
| 29 |
+
def __repr__(self) -> str:
|
| 30 |
+
return f"ColorSystem.{self.name}"
|
| 31 |
+
|
| 32 |
+
def __str__(self) -> str:
|
| 33 |
+
return repr(self)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class ColorType(IntEnum):
|
| 37 |
+
"""Type of color stored in Color class."""
|
| 38 |
+
|
| 39 |
+
DEFAULT = 0
|
| 40 |
+
STANDARD = 1
|
| 41 |
+
EIGHT_BIT = 2
|
| 42 |
+
TRUECOLOR = 3
|
| 43 |
+
WINDOWS = 4
|
| 44 |
+
|
| 45 |
+
def __repr__(self) -> str:
|
| 46 |
+
return f"ColorType.{self.name}"
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
ANSI_COLOR_NAMES = {
|
| 50 |
+
"black": 0,
|
| 51 |
+
"red": 1,
|
| 52 |
+
"green": 2,
|
| 53 |
+
"yellow": 3,
|
| 54 |
+
"blue": 4,
|
| 55 |
+
"magenta": 5,
|
| 56 |
+
"cyan": 6,
|
| 57 |
+
"white": 7,
|
| 58 |
+
"bright_black": 8,
|
| 59 |
+
"bright_red": 9,
|
| 60 |
+
"bright_green": 10,
|
| 61 |
+
"bright_yellow": 11,
|
| 62 |
+
"bright_blue": 12,
|
| 63 |
+
"bright_magenta": 13,
|
| 64 |
+
"bright_cyan": 14,
|
| 65 |
+
"bright_white": 15,
|
| 66 |
+
"grey0": 16,
|
| 67 |
+
"gray0": 16,
|
| 68 |
+
"navy_blue": 17,
|
| 69 |
+
"dark_blue": 18,
|
| 70 |
+
"blue3": 20,
|
| 71 |
+
"blue1": 21,
|
| 72 |
+
"dark_green": 22,
|
| 73 |
+
"deep_sky_blue4": 25,
|
| 74 |
+
"dodger_blue3": 26,
|
| 75 |
+
"dodger_blue2": 27,
|
| 76 |
+
"green4": 28,
|
| 77 |
+
"spring_green4": 29,
|
| 78 |
+
"turquoise4": 30,
|
| 79 |
+
"deep_sky_blue3": 32,
|
| 80 |
+
"dodger_blue1": 33,
|
| 81 |
+
"green3": 40,
|
| 82 |
+
"spring_green3": 41,
|
| 83 |
+
"dark_cyan": 36,
|
| 84 |
+
"light_sea_green": 37,
|
| 85 |
+
"deep_sky_blue2": 38,
|
| 86 |
+
"deep_sky_blue1": 39,
|
| 87 |
+
"spring_green2": 47,
|
| 88 |
+
"cyan3": 43,
|
| 89 |
+
"dark_turquoise": 44,
|
| 90 |
+
"turquoise2": 45,
|
| 91 |
+
"green1": 46,
|
| 92 |
+
"spring_green1": 48,
|
| 93 |
+
"medium_spring_green": 49,
|
| 94 |
+
"cyan2": 50,
|
| 95 |
+
"cyan1": 51,
|
| 96 |
+
"dark_red": 88,
|
| 97 |
+
"deep_pink4": 125,
|
| 98 |
+
"purple4": 55,
|
| 99 |
+
"purple3": 56,
|
| 100 |
+
"blue_violet": 57,
|
| 101 |
+
"orange4": 94,
|
| 102 |
+
"grey37": 59,
|
| 103 |
+
"gray37": 59,
|
| 104 |
+
"medium_purple4": 60,
|
| 105 |
+
"slate_blue3": 62,
|
| 106 |
+
"royal_blue1": 63,
|
| 107 |
+
"chartreuse4": 64,
|
| 108 |
+
"dark_sea_green4": 71,
|
| 109 |
+
"pale_turquoise4": 66,
|
| 110 |
+
"steel_blue": 67,
|
| 111 |
+
"steel_blue3": 68,
|
| 112 |
+
"cornflower_blue": 69,
|
| 113 |
+
"chartreuse3": 76,
|
| 114 |
+
"cadet_blue": 73,
|
| 115 |
+
"sky_blue3": 74,
|
| 116 |
+
"steel_blue1": 81,
|
| 117 |
+
"pale_green3": 114,
|
| 118 |
+
"sea_green3": 78,
|
| 119 |
+
"aquamarine3": 79,
|
| 120 |
+
"medium_turquoise": 80,
|
| 121 |
+
"chartreuse2": 112,
|
| 122 |
+
"sea_green2": 83,
|
| 123 |
+
"sea_green1": 85,
|
| 124 |
+
"aquamarine1": 122,
|
| 125 |
+
"dark_slate_gray2": 87,
|
| 126 |
+
"dark_magenta": 91,
|
| 127 |
+
"dark_violet": 128,
|
| 128 |
+
"purple": 129,
|
| 129 |
+
"light_pink4": 95,
|
| 130 |
+
"plum4": 96,
|
| 131 |
+
"medium_purple3": 98,
|
| 132 |
+
"slate_blue1": 99,
|
| 133 |
+
"yellow4": 106,
|
| 134 |
+
"wheat4": 101,
|
| 135 |
+
"grey53": 102,
|
| 136 |
+
"gray53": 102,
|
| 137 |
+
"light_slate_grey": 103,
|
| 138 |
+
"light_slate_gray": 103,
|
| 139 |
+
"medium_purple": 104,
|
| 140 |
+
"light_slate_blue": 105,
|
| 141 |
+
"dark_olive_green3": 149,
|
| 142 |
+
"dark_sea_green": 108,
|
| 143 |
+
"light_sky_blue3": 110,
|
| 144 |
+
"sky_blue2": 111,
|
| 145 |
+
"dark_sea_green3": 150,
|
| 146 |
+
"dark_slate_gray3": 116,
|
| 147 |
+
"sky_blue1": 117,
|
| 148 |
+
"chartreuse1": 118,
|
| 149 |
+
"light_green": 120,
|
| 150 |
+
"pale_green1": 156,
|
| 151 |
+
"dark_slate_gray1": 123,
|
| 152 |
+
"red3": 160,
|
| 153 |
+
"medium_violet_red": 126,
|
| 154 |
+
"magenta3": 164,
|
| 155 |
+
"dark_orange3": 166,
|
| 156 |
+
"indian_red": 167,
|
| 157 |
+
"hot_pink3": 168,
|
| 158 |
+
"medium_orchid3": 133,
|
| 159 |
+
"medium_orchid": 134,
|
| 160 |
+
"medium_purple2": 140,
|
| 161 |
+
"dark_goldenrod": 136,
|
| 162 |
+
"light_salmon3": 173,
|
| 163 |
+
"rosy_brown": 138,
|
| 164 |
+
"grey63": 139,
|
| 165 |
+
"gray63": 139,
|
| 166 |
+
"medium_purple1": 141,
|
| 167 |
+
"gold3": 178,
|
| 168 |
+
"dark_khaki": 143,
|
| 169 |
+
"navajo_white3": 144,
|
| 170 |
+
"grey69": 145,
|
| 171 |
+
"gray69": 145,
|
| 172 |
+
"light_steel_blue3": 146,
|
| 173 |
+
"light_steel_blue": 147,
|
| 174 |
+
"yellow3": 184,
|
| 175 |
+
"dark_sea_green2": 157,
|
| 176 |
+
"light_cyan3": 152,
|
| 177 |
+
"light_sky_blue1": 153,
|
| 178 |
+
"green_yellow": 154,
|
| 179 |
+
"dark_olive_green2": 155,
|
| 180 |
+
"dark_sea_green1": 193,
|
| 181 |
+
"pale_turquoise1": 159,
|
| 182 |
+
"deep_pink3": 162,
|
| 183 |
+
"magenta2": 200,
|
| 184 |
+
"hot_pink2": 169,
|
| 185 |
+
"orchid": 170,
|
| 186 |
+
"medium_orchid1": 207,
|
| 187 |
+
"orange3": 172,
|
| 188 |
+
"light_pink3": 174,
|
| 189 |
+
"pink3": 175,
|
| 190 |
+
"plum3": 176,
|
| 191 |
+
"violet": 177,
|
| 192 |
+
"light_goldenrod3": 179,
|
| 193 |
+
"tan": 180,
|
| 194 |
+
"misty_rose3": 181,
|
| 195 |
+
"thistle3": 182,
|
| 196 |
+
"plum2": 183,
|
| 197 |
+
"khaki3": 185,
|
| 198 |
+
"light_goldenrod2": 222,
|
| 199 |
+
"light_yellow3": 187,
|
| 200 |
+
"grey84": 188,
|
| 201 |
+
"gray84": 188,
|
| 202 |
+
"light_steel_blue1": 189,
|
| 203 |
+
"yellow2": 190,
|
| 204 |
+
"dark_olive_green1": 192,
|
| 205 |
+
"honeydew2": 194,
|
| 206 |
+
"light_cyan1": 195,
|
| 207 |
+
"red1": 196,
|
| 208 |
+
"deep_pink2": 197,
|
| 209 |
+
"deep_pink1": 199,
|
| 210 |
+
"magenta1": 201,
|
| 211 |
+
"orange_red1": 202,
|
| 212 |
+
"indian_red1": 204,
|
| 213 |
+
"hot_pink": 206,
|
| 214 |
+
"dark_orange": 208,
|
| 215 |
+
"salmon1": 209,
|
| 216 |
+
"light_coral": 210,
|
| 217 |
+
"pale_violet_red1": 211,
|
| 218 |
+
"orchid2": 212,
|
| 219 |
+
"orchid1": 213,
|
| 220 |
+
"orange1": 214,
|
| 221 |
+
"sandy_brown": 215,
|
| 222 |
+
"light_salmon1": 216,
|
| 223 |
+
"light_pink1": 217,
|
| 224 |
+
"pink1": 218,
|
| 225 |
+
"plum1": 219,
|
| 226 |
+
"gold1": 220,
|
| 227 |
+
"navajo_white1": 223,
|
| 228 |
+
"misty_rose1": 224,
|
| 229 |
+
"thistle1": 225,
|
| 230 |
+
"yellow1": 226,
|
| 231 |
+
"light_goldenrod1": 227,
|
| 232 |
+
"khaki1": 228,
|
| 233 |
+
"wheat1": 229,
|
| 234 |
+
"cornsilk1": 230,
|
| 235 |
+
"grey100": 231,
|
| 236 |
+
"gray100": 231,
|
| 237 |
+
"grey3": 232,
|
| 238 |
+
"gray3": 232,
|
| 239 |
+
"grey7": 233,
|
| 240 |
+
"gray7": 233,
|
| 241 |
+
"grey11": 234,
|
| 242 |
+
"gray11": 234,
|
| 243 |
+
"grey15": 235,
|
| 244 |
+
"gray15": 235,
|
| 245 |
+
"grey19": 236,
|
| 246 |
+
"gray19": 236,
|
| 247 |
+
"grey23": 237,
|
| 248 |
+
"gray23": 237,
|
| 249 |
+
"grey27": 238,
|
| 250 |
+
"gray27": 238,
|
| 251 |
+
"grey30": 239,
|
| 252 |
+
"gray30": 239,
|
| 253 |
+
"grey35": 240,
|
| 254 |
+
"gray35": 240,
|
| 255 |
+
"grey39": 241,
|
| 256 |
+
"gray39": 241,
|
| 257 |
+
"grey42": 242,
|
| 258 |
+
"gray42": 242,
|
| 259 |
+
"grey46": 243,
|
| 260 |
+
"gray46": 243,
|
| 261 |
+
"grey50": 244,
|
| 262 |
+
"gray50": 244,
|
| 263 |
+
"grey54": 245,
|
| 264 |
+
"gray54": 245,
|
| 265 |
+
"grey58": 246,
|
| 266 |
+
"gray58": 246,
|
| 267 |
+
"grey62": 247,
|
| 268 |
+
"gray62": 247,
|
| 269 |
+
"grey66": 248,
|
| 270 |
+
"gray66": 248,
|
| 271 |
+
"grey70": 249,
|
| 272 |
+
"gray70": 249,
|
| 273 |
+
"grey74": 250,
|
| 274 |
+
"gray74": 250,
|
| 275 |
+
"grey78": 251,
|
| 276 |
+
"gray78": 251,
|
| 277 |
+
"grey82": 252,
|
| 278 |
+
"gray82": 252,
|
| 279 |
+
"grey85": 253,
|
| 280 |
+
"gray85": 253,
|
| 281 |
+
"grey89": 254,
|
| 282 |
+
"gray89": 254,
|
| 283 |
+
"grey93": 255,
|
| 284 |
+
"gray93": 255,
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
class ColorParseError(Exception):
|
| 289 |
+
"""The color could not be parsed."""
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
RE_COLOR = re.compile(
|
| 293 |
+
r"""^
|
| 294 |
+
\#([0-9a-f]{6})$|
|
| 295 |
+
color\(([0-9]{1,3})\)$|
|
| 296 |
+
rgb\(([\d\s,]+)\)$
|
| 297 |
+
""",
|
| 298 |
+
re.VERBOSE,
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
@rich_repr
|
| 303 |
+
class Color(NamedTuple):
|
| 304 |
+
"""Terminal color definition."""
|
| 305 |
+
|
| 306 |
+
name: str
|
| 307 |
+
"""The name of the color (typically the input to Color.parse)."""
|
| 308 |
+
type: ColorType
|
| 309 |
+
"""The type of the color."""
|
| 310 |
+
number: Optional[int] = None
|
| 311 |
+
"""The color number, if a standard color, or None."""
|
| 312 |
+
triplet: Optional[ColorTriplet] = None
|
| 313 |
+
"""A triplet of color components, if an RGB color."""
|
| 314 |
+
|
| 315 |
+
def __rich__(self) -> "Text":
|
| 316 |
+
"""Displays the actual color if Rich printed."""
|
| 317 |
+
from .style import Style
|
| 318 |
+
from .text import Text
|
| 319 |
+
|
| 320 |
+
return Text.assemble(
|
| 321 |
+
f"<color {self.name!r} ({self.type.name.lower()})",
|
| 322 |
+
("⬤", Style(color=self)),
|
| 323 |
+
" >",
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
def __rich_repr__(self) -> Result:
|
| 327 |
+
yield self.name
|
| 328 |
+
yield self.type
|
| 329 |
+
yield "number", self.number, None
|
| 330 |
+
yield "triplet", self.triplet, None
|
| 331 |
+
|
| 332 |
+
@property
|
| 333 |
+
def system(self) -> ColorSystem:
|
| 334 |
+
"""Get the native color system for this color."""
|
| 335 |
+
if self.type == ColorType.DEFAULT:
|
| 336 |
+
return ColorSystem.STANDARD
|
| 337 |
+
return ColorSystem(int(self.type))
|
| 338 |
+
|
| 339 |
+
@property
|
| 340 |
+
def is_system_defined(self) -> bool:
|
| 341 |
+
"""Check if the color is ultimately defined by the system."""
|
| 342 |
+
return self.system not in (ColorSystem.EIGHT_BIT, ColorSystem.TRUECOLOR)
|
| 343 |
+
|
| 344 |
+
@property
|
| 345 |
+
def is_default(self) -> bool:
|
| 346 |
+
"""Check if the color is a default color."""
|
| 347 |
+
return self.type == ColorType.DEFAULT
|
| 348 |
+
|
| 349 |
+
def get_truecolor(
|
| 350 |
+
self, theme: Optional["TerminalTheme"] = None, foreground: bool = True
|
| 351 |
+
) -> ColorTriplet:
|
| 352 |
+
"""Get an equivalent color triplet for this color.
|
| 353 |
+
|
| 354 |
+
Args:
|
| 355 |
+
theme (TerminalTheme, optional): Optional terminal theme, or None to use default. Defaults to None.
|
| 356 |
+
foreground (bool, optional): True for a foreground color, or False for background. Defaults to True.
|
| 357 |
+
|
| 358 |
+
Returns:
|
| 359 |
+
ColorTriplet: A color triplet containing RGB components.
|
| 360 |
+
"""
|
| 361 |
+
|
| 362 |
+
if theme is None:
|
| 363 |
+
theme = DEFAULT_TERMINAL_THEME
|
| 364 |
+
if self.type == ColorType.TRUECOLOR:
|
| 365 |
+
assert self.triplet is not None
|
| 366 |
+
return self.triplet
|
| 367 |
+
elif self.type == ColorType.EIGHT_BIT:
|
| 368 |
+
assert self.number is not None
|
| 369 |
+
return EIGHT_BIT_PALETTE[self.number]
|
| 370 |
+
elif self.type == ColorType.STANDARD:
|
| 371 |
+
assert self.number is not None
|
| 372 |
+
return theme.ansi_colors[self.number]
|
| 373 |
+
elif self.type == ColorType.WINDOWS:
|
| 374 |
+
assert self.number is not None
|
| 375 |
+
return WINDOWS_PALETTE[self.number]
|
| 376 |
+
else: # self.type == ColorType.DEFAULT:
|
| 377 |
+
assert self.number is None
|
| 378 |
+
return theme.foreground_color if foreground else theme.background_color
|
| 379 |
+
|
| 380 |
+
@classmethod
|
| 381 |
+
def from_ansi(cls, number: int) -> "Color":
|
| 382 |
+
"""Create a Color number from it's 8-bit ansi number.
|
| 383 |
+
|
| 384 |
+
Args:
|
| 385 |
+
number (int): A number between 0-255 inclusive.
|
| 386 |
+
|
| 387 |
+
Returns:
|
| 388 |
+
Color: A new Color instance.
|
| 389 |
+
"""
|
| 390 |
+
return cls(
|
| 391 |
+
name=f"color({number})",
|
| 392 |
+
type=(ColorType.STANDARD if number < 16 else ColorType.EIGHT_BIT),
|
| 393 |
+
number=number,
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
@classmethod
|
| 397 |
+
def from_triplet(cls, triplet: "ColorTriplet") -> "Color":
|
| 398 |
+
"""Create a truecolor RGB color from a triplet of values.
|
| 399 |
+
|
| 400 |
+
Args:
|
| 401 |
+
triplet (ColorTriplet): A color triplet containing red, green and blue components.
|
| 402 |
+
|
| 403 |
+
Returns:
|
| 404 |
+
Color: A new color object.
|
| 405 |
+
"""
|
| 406 |
+
return cls(name=triplet.hex, type=ColorType.TRUECOLOR, triplet=triplet)
|
| 407 |
+
|
| 408 |
+
@classmethod
|
| 409 |
+
def from_rgb(cls, red: float, green: float, blue: float) -> "Color":
|
| 410 |
+
"""Create a truecolor from three color components in the range(0->255).
|
| 411 |
+
|
| 412 |
+
Args:
|
| 413 |
+
red (float): Red component in range 0-255.
|
| 414 |
+
green (float): Green component in range 0-255.
|
| 415 |
+
blue (float): Blue component in range 0-255.
|
| 416 |
+
|
| 417 |
+
Returns:
|
| 418 |
+
Color: A new color object.
|
| 419 |
+
"""
|
| 420 |
+
return cls.from_triplet(ColorTriplet(int(red), int(green), int(blue)))
|
| 421 |
+
|
| 422 |
+
@classmethod
|
| 423 |
+
def default(cls) -> "Color":
|
| 424 |
+
"""Get a Color instance representing the default color.
|
| 425 |
+
|
| 426 |
+
Returns:
|
| 427 |
+
Color: Default color.
|
| 428 |
+
"""
|
| 429 |
+
return cls(name="default", type=ColorType.DEFAULT)
|
| 430 |
+
|
| 431 |
+
@classmethod
|
| 432 |
+
@lru_cache(maxsize=1024)
|
| 433 |
+
def parse(cls, color: str) -> "Color":
|
| 434 |
+
"""Parse a color definition."""
|
| 435 |
+
original_color = color
|
| 436 |
+
color = color.lower().strip()
|
| 437 |
+
|
| 438 |
+
if color == "default":
|
| 439 |
+
return cls(color, type=ColorType.DEFAULT)
|
| 440 |
+
|
| 441 |
+
color_number = ANSI_COLOR_NAMES.get(color)
|
| 442 |
+
if color_number is not None:
|
| 443 |
+
return cls(
|
| 444 |
+
color,
|
| 445 |
+
type=(ColorType.STANDARD if color_number < 16 else ColorType.EIGHT_BIT),
|
| 446 |
+
number=color_number,
|
| 447 |
+
)
|
| 448 |
+
|
| 449 |
+
color_match = RE_COLOR.match(color)
|
| 450 |
+
if color_match is None:
|
| 451 |
+
raise ColorParseError(f"{original_color!r} is not a valid color")
|
| 452 |
+
|
| 453 |
+
color_24, color_8, color_rgb = color_match.groups()
|
| 454 |
+
if color_24:
|
| 455 |
+
triplet = ColorTriplet(
|
| 456 |
+
int(color_24[0:2], 16), int(color_24[2:4], 16), int(color_24[4:6], 16)
|
| 457 |
+
)
|
| 458 |
+
return cls(color, ColorType.TRUECOLOR, triplet=triplet)
|
| 459 |
+
|
| 460 |
+
elif color_8:
|
| 461 |
+
number = int(color_8)
|
| 462 |
+
if number > 255:
|
| 463 |
+
raise ColorParseError(f"color number must be <= 255 in {color!r}")
|
| 464 |
+
return cls(
|
| 465 |
+
color,
|
| 466 |
+
type=(ColorType.STANDARD if number < 16 else ColorType.EIGHT_BIT),
|
| 467 |
+
number=number,
|
| 468 |
+
)
|
| 469 |
+
|
| 470 |
+
else: # color_rgb:
|
| 471 |
+
components = color_rgb.split(",")
|
| 472 |
+
if len(components) != 3:
|
| 473 |
+
raise ColorParseError(
|
| 474 |
+
f"expected three components in {original_color!r}"
|
| 475 |
+
)
|
| 476 |
+
red, green, blue = components
|
| 477 |
+
triplet = ColorTriplet(int(red), int(green), int(blue))
|
| 478 |
+
if not all(component <= 255 for component in triplet):
|
| 479 |
+
raise ColorParseError(
|
| 480 |
+
f"color components must be <= 255 in {original_color!r}"
|
| 481 |
+
)
|
| 482 |
+
return cls(color, ColorType.TRUECOLOR, triplet=triplet)
|
| 483 |
+
|
| 484 |
+
@lru_cache(maxsize=1024)
|
| 485 |
+
def get_ansi_codes(self, foreground: bool = True) -> Tuple[str, ...]:
|
| 486 |
+
"""Get the ANSI escape codes for this color."""
|
| 487 |
+
_type = self.type
|
| 488 |
+
if _type == ColorType.DEFAULT:
|
| 489 |
+
return ("39" if foreground else "49",)
|
| 490 |
+
|
| 491 |
+
elif _type == ColorType.WINDOWS:
|
| 492 |
+
number = self.number
|
| 493 |
+
assert number is not None
|
| 494 |
+
fore, back = (30, 40) if number < 8 else (82, 92)
|
| 495 |
+
return (str(fore + number if foreground else back + number),)
|
| 496 |
+
|
| 497 |
+
elif _type == ColorType.STANDARD:
|
| 498 |
+
number = self.number
|
| 499 |
+
assert number is not None
|
| 500 |
+
fore, back = (30, 40) if number < 8 else (82, 92)
|
| 501 |
+
return (str(fore + number if foreground else back + number),)
|
| 502 |
+
|
| 503 |
+
elif _type == ColorType.EIGHT_BIT:
|
| 504 |
+
assert self.number is not None
|
| 505 |
+
return ("38" if foreground else "48", "5", str(self.number))
|
| 506 |
+
|
| 507 |
+
else: # self.standard == ColorStandard.TRUECOLOR:
|
| 508 |
+
assert self.triplet is not None
|
| 509 |
+
red, green, blue = self.triplet
|
| 510 |
+
return ("38" if foreground else "48", "2", str(red), str(green), str(blue))
|
| 511 |
+
|
| 512 |
+
@lru_cache(maxsize=1024)
|
| 513 |
+
def downgrade(self, system: ColorSystem) -> "Color":
|
| 514 |
+
"""Downgrade a color system to a system with fewer colors."""
|
| 515 |
+
|
| 516 |
+
if self.type in (ColorType.DEFAULT, system):
|
| 517 |
+
return self
|
| 518 |
+
# Convert to 8-bit color from truecolor color
|
| 519 |
+
if system == ColorSystem.EIGHT_BIT and self.system == ColorSystem.TRUECOLOR:
|
| 520 |
+
assert self.triplet is not None
|
| 521 |
+
_h, l, s = rgb_to_hls(*self.triplet.normalized)
|
| 522 |
+
# If saturation is under 15% assume it is grayscale
|
| 523 |
+
if s < 0.15:
|
| 524 |
+
gray = round(l * 25.0)
|
| 525 |
+
if gray == 0:
|
| 526 |
+
color_number = 16
|
| 527 |
+
elif gray == 25:
|
| 528 |
+
color_number = 231
|
| 529 |
+
else:
|
| 530 |
+
color_number = 231 + gray
|
| 531 |
+
return Color(self.name, ColorType.EIGHT_BIT, number=color_number)
|
| 532 |
+
|
| 533 |
+
red, green, blue = self.triplet
|
| 534 |
+
six_red = red / 95 if red < 95 else 1 + (red - 95) / 40
|
| 535 |
+
six_green = green / 95 if green < 95 else 1 + (green - 95) / 40
|
| 536 |
+
six_blue = blue / 95 if blue < 95 else 1 + (blue - 95) / 40
|
| 537 |
+
|
| 538 |
+
color_number = (
|
| 539 |
+
16 + 36 * round(six_red) + 6 * round(six_green) + round(six_blue)
|
| 540 |
+
)
|
| 541 |
+
return Color(self.name, ColorType.EIGHT_BIT, number=color_number)
|
| 542 |
+
|
| 543 |
+
# Convert to standard from truecolor or 8-bit
|
| 544 |
+
elif system == ColorSystem.STANDARD:
|
| 545 |
+
if self.system == ColorSystem.TRUECOLOR:
|
| 546 |
+
assert self.triplet is not None
|
| 547 |
+
triplet = self.triplet
|
| 548 |
+
else: # self.system == ColorSystem.EIGHT_BIT
|
| 549 |
+
assert self.number is not None
|
| 550 |
+
triplet = ColorTriplet(*EIGHT_BIT_PALETTE[self.number])
|
| 551 |
+
|
| 552 |
+
color_number = STANDARD_PALETTE.match(triplet)
|
| 553 |
+
return Color(self.name, ColorType.STANDARD, number=color_number)
|
| 554 |
+
|
| 555 |
+
elif system == ColorSystem.WINDOWS:
|
| 556 |
+
if self.system == ColorSystem.TRUECOLOR:
|
| 557 |
+
assert self.triplet is not None
|
| 558 |
+
triplet = self.triplet
|
| 559 |
+
else: # self.system == ColorSystem.EIGHT_BIT
|
| 560 |
+
assert self.number is not None
|
| 561 |
+
if self.number < 16:
|
| 562 |
+
return Color(self.name, ColorType.WINDOWS, number=self.number)
|
| 563 |
+
triplet = ColorTriplet(*EIGHT_BIT_PALETTE[self.number])
|
| 564 |
+
|
| 565 |
+
color_number = WINDOWS_PALETTE.match(triplet)
|
| 566 |
+
return Color(self.name, ColorType.WINDOWS, number=color_number)
|
| 567 |
+
|
| 568 |
+
return self
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def parse_rgb_hex(hex_color: str) -> ColorTriplet:
|
| 572 |
+
"""Parse six hex characters in to RGB triplet."""
|
| 573 |
+
assert len(hex_color) == 6, "must be 6 characters"
|
| 574 |
+
color = ColorTriplet(
|
| 575 |
+
int(hex_color[0:2], 16), int(hex_color[2:4], 16), int(hex_color[4:6], 16)
|
| 576 |
+
)
|
| 577 |
+
return color
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
def blend_rgb(
|
| 581 |
+
color1: ColorTriplet, color2: ColorTriplet, cross_fade: float = 0.5
|
| 582 |
+
) -> ColorTriplet:
|
| 583 |
+
"""Blend one RGB color in to another."""
|
| 584 |
+
r1, g1, b1 = color1
|
| 585 |
+
r2, g2, b2 = color2
|
| 586 |
+
new_color = ColorTriplet(
|
| 587 |
+
int(r1 + (r2 - r1) * cross_fade),
|
| 588 |
+
int(g1 + (g2 - g1) * cross_fade),
|
| 589 |
+
int(b1 + (b2 - b1) * cross_fade),
|
| 590 |
+
)
|
| 591 |
+
return new_color
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
if __name__ == "__main__": # pragma: no cover
|
| 595 |
+
from .console import Console
|
| 596 |
+
from .table import Table
|
| 597 |
+
from .text import Text
|
| 598 |
+
|
| 599 |
+
console = Console()
|
| 600 |
+
|
| 601 |
+
table = Table(show_footer=False, show_edge=True)
|
| 602 |
+
table.add_column("Color", width=10, overflow="ellipsis")
|
| 603 |
+
table.add_column("Number", justify="right", style="yellow")
|
| 604 |
+
table.add_column("Name", style="green")
|
| 605 |
+
table.add_column("Hex", style="blue")
|
| 606 |
+
table.add_column("RGB", style="magenta")
|
| 607 |
+
|
| 608 |
+
colors = sorted((v, k) for k, v in ANSI_COLOR_NAMES.items())
|
| 609 |
+
for color_number, name in colors:
|
| 610 |
+
if "grey" in name:
|
| 611 |
+
continue
|
| 612 |
+
color_cell = Text(" " * 10, style=f"on {name}")
|
| 613 |
+
if color_number < 16:
|
| 614 |
+
table.add_row(color_cell, f"{color_number}", Text(f'"{name}"'))
|
| 615 |
+
else:
|
| 616 |
+
color = EIGHT_BIT_PALETTE[color_number] # type: ignore[has-type]
|
| 617 |
+
table.add_row(
|
| 618 |
+
color_cell, str(color_number), Text(f'"{name}"'), color.hex, color.rgb
|
| 619 |
+
)
|
| 620 |
+
|
| 621 |
+
console.print(table)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/color_triplet.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import NamedTuple, Tuple
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class ColorTriplet(NamedTuple):
|
| 5 |
+
"""The red, green, and blue components of a color."""
|
| 6 |
+
|
| 7 |
+
red: int
|
| 8 |
+
"""Red component in 0 to 255 range."""
|
| 9 |
+
green: int
|
| 10 |
+
"""Green component in 0 to 255 range."""
|
| 11 |
+
blue: int
|
| 12 |
+
"""Blue component in 0 to 255 range."""
|
| 13 |
+
|
| 14 |
+
@property
|
| 15 |
+
def hex(self) -> str:
|
| 16 |
+
"""get the color triplet in CSS style."""
|
| 17 |
+
red, green, blue = self
|
| 18 |
+
return f"#{red:02x}{green:02x}{blue:02x}"
|
| 19 |
+
|
| 20 |
+
@property
|
| 21 |
+
def rgb(self) -> str:
|
| 22 |
+
"""The color in RGB format.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
str: An rgb color, e.g. ``"rgb(100,23,255)"``.
|
| 26 |
+
"""
|
| 27 |
+
red, green, blue = self
|
| 28 |
+
return f"rgb({red},{green},{blue})"
|
| 29 |
+
|
| 30 |
+
@property
|
| 31 |
+
def normalized(self) -> Tuple[float, float, float]:
|
| 32 |
+
"""Convert components into floats between 0 and 1.
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
Tuple[float, float, float]: A tuple of three normalized colour components.
|
| 36 |
+
"""
|
| 37 |
+
red, green, blue = self
|
| 38 |
+
return red / 255.0, green / 255.0, blue / 255.0
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/columns.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections import defaultdict
|
| 2 |
+
from itertools import chain
|
| 3 |
+
from operator import itemgetter
|
| 4 |
+
from typing import Dict, Iterable, List, Optional, Tuple
|
| 5 |
+
|
| 6 |
+
from .align import Align, AlignMethod
|
| 7 |
+
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
| 8 |
+
from .constrain import Constrain
|
| 9 |
+
from .measure import Measurement
|
| 10 |
+
from .padding import Padding, PaddingDimensions
|
| 11 |
+
from .table import Table
|
| 12 |
+
from .text import TextType
|
| 13 |
+
from .jupyter import JupyterMixin
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class Columns(JupyterMixin):
|
| 17 |
+
"""Display renderables in neat columns.
|
| 18 |
+
|
| 19 |
+
Args:
|
| 20 |
+
renderables (Iterable[RenderableType]): Any number of Rich renderables (including str).
|
| 21 |
+
width (int, optional): The desired width of the columns, or None to auto detect. Defaults to None.
|
| 22 |
+
padding (PaddingDimensions, optional): Optional padding around cells. Defaults to (0, 1).
|
| 23 |
+
expand (bool, optional): Expand columns to full width. Defaults to False.
|
| 24 |
+
equal (bool, optional): Arrange in to equal sized columns. Defaults to False.
|
| 25 |
+
column_first (bool, optional): Align items from top to bottom (rather than left to right). Defaults to False.
|
| 26 |
+
right_to_left (bool, optional): Start column from right hand side. Defaults to False.
|
| 27 |
+
align (str, optional): Align value ("left", "right", or "center") or None for default. Defaults to None.
|
| 28 |
+
title (TextType, optional): Optional title for Columns.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
def __init__(
|
| 32 |
+
self,
|
| 33 |
+
renderables: Optional[Iterable[RenderableType]] = None,
|
| 34 |
+
padding: PaddingDimensions = (0, 1),
|
| 35 |
+
*,
|
| 36 |
+
width: Optional[int] = None,
|
| 37 |
+
expand: bool = False,
|
| 38 |
+
equal: bool = False,
|
| 39 |
+
column_first: bool = False,
|
| 40 |
+
right_to_left: bool = False,
|
| 41 |
+
align: Optional[AlignMethod] = None,
|
| 42 |
+
title: Optional[TextType] = None,
|
| 43 |
+
) -> None:
|
| 44 |
+
self.renderables = list(renderables or [])
|
| 45 |
+
self.width = width
|
| 46 |
+
self.padding = padding
|
| 47 |
+
self.expand = expand
|
| 48 |
+
self.equal = equal
|
| 49 |
+
self.column_first = column_first
|
| 50 |
+
self.right_to_left = right_to_left
|
| 51 |
+
self.align: Optional[AlignMethod] = align
|
| 52 |
+
self.title = title
|
| 53 |
+
|
| 54 |
+
def add_renderable(self, renderable: RenderableType) -> None:
|
| 55 |
+
"""Add a renderable to the columns.
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
renderable (RenderableType): Any renderable object.
|
| 59 |
+
"""
|
| 60 |
+
self.renderables.append(renderable)
|
| 61 |
+
|
| 62 |
+
def __rich_console__(
|
| 63 |
+
self, console: Console, options: ConsoleOptions
|
| 64 |
+
) -> RenderResult:
|
| 65 |
+
render_str = console.render_str
|
| 66 |
+
renderables = [
|
| 67 |
+
render_str(renderable) if isinstance(renderable, str) else renderable
|
| 68 |
+
for renderable in self.renderables
|
| 69 |
+
]
|
| 70 |
+
if not renderables:
|
| 71 |
+
return
|
| 72 |
+
_top, right, _bottom, left = Padding.unpack(self.padding)
|
| 73 |
+
width_padding = max(left, right)
|
| 74 |
+
max_width = options.max_width
|
| 75 |
+
widths: Dict[int, int] = defaultdict(int)
|
| 76 |
+
column_count = len(renderables)
|
| 77 |
+
|
| 78 |
+
get_measurement = Measurement.get
|
| 79 |
+
renderable_widths = [
|
| 80 |
+
get_measurement(console, options, renderable).maximum
|
| 81 |
+
for renderable in renderables
|
| 82 |
+
]
|
| 83 |
+
if self.equal:
|
| 84 |
+
renderable_widths = [max(renderable_widths)] * len(renderable_widths)
|
| 85 |
+
|
| 86 |
+
def iter_renderables(
|
| 87 |
+
column_count: int,
|
| 88 |
+
) -> Iterable[Tuple[int, Optional[RenderableType]]]:
|
| 89 |
+
item_count = len(renderables)
|
| 90 |
+
if self.column_first:
|
| 91 |
+
width_renderables = list(zip(renderable_widths, renderables))
|
| 92 |
+
|
| 93 |
+
column_lengths: List[int] = [item_count // column_count] * column_count
|
| 94 |
+
for col_no in range(item_count % column_count):
|
| 95 |
+
column_lengths[col_no] += 1
|
| 96 |
+
|
| 97 |
+
row_count = (item_count + column_count - 1) // column_count
|
| 98 |
+
cells = [[-1] * column_count for _ in range(row_count)]
|
| 99 |
+
row = col = 0
|
| 100 |
+
for index in range(item_count):
|
| 101 |
+
cells[row][col] = index
|
| 102 |
+
column_lengths[col] -= 1
|
| 103 |
+
if column_lengths[col]:
|
| 104 |
+
row += 1
|
| 105 |
+
else:
|
| 106 |
+
col += 1
|
| 107 |
+
row = 0
|
| 108 |
+
for index in chain.from_iterable(cells):
|
| 109 |
+
if index == -1:
|
| 110 |
+
break
|
| 111 |
+
yield width_renderables[index]
|
| 112 |
+
else:
|
| 113 |
+
yield from zip(renderable_widths, renderables)
|
| 114 |
+
# Pad odd elements with spaces
|
| 115 |
+
if item_count % column_count:
|
| 116 |
+
for _ in range(column_count - (item_count % column_count)):
|
| 117 |
+
yield 0, None
|
| 118 |
+
|
| 119 |
+
table = Table.grid(padding=self.padding, collapse_padding=True, pad_edge=False)
|
| 120 |
+
table.expand = self.expand
|
| 121 |
+
table.title = self.title
|
| 122 |
+
|
| 123 |
+
if self.width is not None:
|
| 124 |
+
column_count = (max_width) // (self.width + width_padding)
|
| 125 |
+
for _ in range(column_count):
|
| 126 |
+
table.add_column(width=self.width)
|
| 127 |
+
else:
|
| 128 |
+
while column_count > 1:
|
| 129 |
+
widths.clear()
|
| 130 |
+
column_no = 0
|
| 131 |
+
for renderable_width, _ in iter_renderables(column_count):
|
| 132 |
+
widths[column_no] = max(widths[column_no], renderable_width)
|
| 133 |
+
total_width = sum(widths.values()) + width_padding * (
|
| 134 |
+
len(widths) - 1
|
| 135 |
+
)
|
| 136 |
+
if total_width > max_width:
|
| 137 |
+
column_count = len(widths) - 1
|
| 138 |
+
break
|
| 139 |
+
else:
|
| 140 |
+
column_no = (column_no + 1) % column_count
|
| 141 |
+
else:
|
| 142 |
+
break
|
| 143 |
+
|
| 144 |
+
get_renderable = itemgetter(1)
|
| 145 |
+
_renderables = [
|
| 146 |
+
get_renderable(_renderable)
|
| 147 |
+
for _renderable in iter_renderables(column_count)
|
| 148 |
+
]
|
| 149 |
+
if self.equal:
|
| 150 |
+
_renderables = [
|
| 151 |
+
None
|
| 152 |
+
if renderable is None
|
| 153 |
+
else Constrain(renderable, renderable_widths[0])
|
| 154 |
+
for renderable in _renderables
|
| 155 |
+
]
|
| 156 |
+
if self.align:
|
| 157 |
+
align = self.align
|
| 158 |
+
_Align = Align
|
| 159 |
+
_renderables = [
|
| 160 |
+
None if renderable is None else _Align(renderable, align)
|
| 161 |
+
for renderable in _renderables
|
| 162 |
+
]
|
| 163 |
+
|
| 164 |
+
right_to_left = self.right_to_left
|
| 165 |
+
add_row = table.add_row
|
| 166 |
+
for start in range(0, len(_renderables), column_count):
|
| 167 |
+
row = _renderables[start : start + column_count]
|
| 168 |
+
if right_to_left:
|
| 169 |
+
row = row[::-1]
|
| 170 |
+
add_row(*row)
|
| 171 |
+
yield table
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
if __name__ == "__main__": # pragma: no cover
|
| 175 |
+
import os
|
| 176 |
+
|
| 177 |
+
console = Console()
|
| 178 |
+
|
| 179 |
+
files = [f"{i} {s}" for i, s in enumerate(sorted(os.listdir()))]
|
| 180 |
+
columns = Columns(files, padding=(0, 1), expand=False, equal=False)
|
| 181 |
+
console.print(columns)
|
| 182 |
+
console.rule()
|
| 183 |
+
columns.column_first = True
|
| 184 |
+
console.print(columns)
|
| 185 |
+
columns.right_to_left = True
|
| 186 |
+
console.rule()
|
| 187 |
+
console.print(columns)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/console.py
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/constrain.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional, TYPE_CHECKING
|
| 2 |
+
|
| 3 |
+
from .jupyter import JupyterMixin
|
| 4 |
+
from .measure import Measurement
|
| 5 |
+
|
| 6 |
+
if TYPE_CHECKING:
|
| 7 |
+
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Constrain(JupyterMixin):
|
| 11 |
+
"""Constrain the width of a renderable to a given number of characters.
|
| 12 |
+
|
| 13 |
+
Args:
|
| 14 |
+
renderable (RenderableType): A renderable object.
|
| 15 |
+
width (int, optional): The maximum width (in characters) to render. Defaults to 80.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
def __init__(self, renderable: "RenderableType", width: Optional[int] = 80) -> None:
|
| 19 |
+
self.renderable = renderable
|
| 20 |
+
self.width = width
|
| 21 |
+
|
| 22 |
+
def __rich_console__(
|
| 23 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 24 |
+
) -> "RenderResult":
|
| 25 |
+
if self.width is None:
|
| 26 |
+
yield self.renderable
|
| 27 |
+
else:
|
| 28 |
+
child_options = options.update_width(min(self.width, options.max_width))
|
| 29 |
+
yield from console.render(self.renderable, child_options)
|
| 30 |
+
|
| 31 |
+
def __rich_measure__(
|
| 32 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 33 |
+
) -> "Measurement":
|
| 34 |
+
if self.width is not None:
|
| 35 |
+
options = options.update_width(self.width)
|
| 36 |
+
measurement = Measurement.get(console, options, self.renderable)
|
| 37 |
+
return measurement
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/containers.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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6 |
+
List,
|
| 7 |
+
Optional,
|
| 8 |
+
TypeVar,
|
| 9 |
+
Union,
|
| 10 |
+
overload,
|
| 11 |
+
)
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
from .console import (
|
| 15 |
+
Console,
|
| 16 |
+
ConsoleOptions,
|
| 17 |
+
JustifyMethod,
|
| 18 |
+
OverflowMethod,
|
| 19 |
+
RenderResult,
|
| 20 |
+
RenderableType,
|
| 21 |
+
)
|
| 22 |
+
from .text import Text
|
| 23 |
+
|
| 24 |
+
from .cells import cell_len
|
| 25 |
+
from .measure import Measurement
|
| 26 |
+
|
| 27 |
+
T = TypeVar("T")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class Renderables:
|
| 31 |
+
"""A list subclass which renders its contents to the console."""
|
| 32 |
+
|
| 33 |
+
def __init__(
|
| 34 |
+
self, renderables: Optional[Iterable["RenderableType"]] = None
|
| 35 |
+
) -> None:
|
| 36 |
+
self._renderables: List["RenderableType"] = (
|
| 37 |
+
list(renderables) if renderables is not None else []
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
def __rich_console__(
|
| 41 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 42 |
+
) -> "RenderResult":
|
| 43 |
+
"""Console render method to insert line-breaks."""
|
| 44 |
+
yield from self._renderables
|
| 45 |
+
|
| 46 |
+
def __rich_measure__(
|
| 47 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 48 |
+
) -> "Measurement":
|
| 49 |
+
dimensions = [
|
| 50 |
+
Measurement.get(console, options, renderable)
|
| 51 |
+
for renderable in self._renderables
|
| 52 |
+
]
|
| 53 |
+
if not dimensions:
|
| 54 |
+
return Measurement(1, 1)
|
| 55 |
+
_min = max(dimension.minimum for dimension in dimensions)
|
| 56 |
+
_max = max(dimension.maximum for dimension in dimensions)
|
| 57 |
+
return Measurement(_min, _max)
|
| 58 |
+
|
| 59 |
+
def append(self, renderable: "RenderableType") -> None:
|
| 60 |
+
self._renderables.append(renderable)
|
| 61 |
+
|
| 62 |
+
def __iter__(self) -> Iterable["RenderableType"]:
|
| 63 |
+
return iter(self._renderables)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class Lines:
|
| 67 |
+
"""A list subclass which can render to the console."""
|
| 68 |
+
|
| 69 |
+
def __init__(self, lines: Iterable["Text"] = ()) -> None:
|
| 70 |
+
self._lines: List["Text"] = list(lines)
|
| 71 |
+
|
| 72 |
+
def __repr__(self) -> str:
|
| 73 |
+
return f"Lines({self._lines!r})"
|
| 74 |
+
|
| 75 |
+
def __iter__(self) -> Iterator["Text"]:
|
| 76 |
+
return iter(self._lines)
|
| 77 |
+
|
| 78 |
+
@overload
|
| 79 |
+
def __getitem__(self, index: int) -> "Text":
|
| 80 |
+
...
|
| 81 |
+
|
| 82 |
+
@overload
|
| 83 |
+
def __getitem__(self, index: slice) -> List["Text"]:
|
| 84 |
+
...
|
| 85 |
+
|
| 86 |
+
def __getitem__(self, index: Union[slice, int]) -> Union["Text", List["Text"]]:
|
| 87 |
+
return self._lines[index]
|
| 88 |
+
|
| 89 |
+
def __setitem__(self, index: int, value: "Text") -> "Lines":
|
| 90 |
+
self._lines[index] = value
|
| 91 |
+
return self
|
| 92 |
+
|
| 93 |
+
def __len__(self) -> int:
|
| 94 |
+
return self._lines.__len__()
|
| 95 |
+
|
| 96 |
+
def __rich_console__(
|
| 97 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 98 |
+
) -> "RenderResult":
|
| 99 |
+
"""Console render method to insert line-breaks."""
|
| 100 |
+
yield from self._lines
|
| 101 |
+
|
| 102 |
+
def append(self, line: "Text") -> None:
|
| 103 |
+
self._lines.append(line)
|
| 104 |
+
|
| 105 |
+
def extend(self, lines: Iterable["Text"]) -> None:
|
| 106 |
+
self._lines.extend(lines)
|
| 107 |
+
|
| 108 |
+
def pop(self, index: int = -1) -> "Text":
|
| 109 |
+
return self._lines.pop(index)
|
| 110 |
+
|
| 111 |
+
def justify(
|
| 112 |
+
self,
|
| 113 |
+
console: "Console",
|
| 114 |
+
width: int,
|
| 115 |
+
justify: "JustifyMethod" = "left",
|
| 116 |
+
overflow: "OverflowMethod" = "fold",
|
| 117 |
+
) -> None:
|
| 118 |
+
"""Justify and overflow text to a given width.
|
| 119 |
+
|
| 120 |
+
Args:
|
| 121 |
+
console (Console): Console instance.
|
| 122 |
+
width (int): Number of cells available per line.
|
| 123 |
+
justify (str, optional): Default justify method for text: "left", "center", "full" or "right". Defaults to "left".
|
| 124 |
+
overflow (str, optional): Default overflow for text: "crop", "fold", or "ellipsis". Defaults to "fold".
|
| 125 |
+
|
| 126 |
+
"""
|
| 127 |
+
from .text import Text
|
| 128 |
+
|
| 129 |
+
if justify == "left":
|
| 130 |
+
for line in self._lines:
|
| 131 |
+
line.truncate(width, overflow=overflow, pad=True)
|
| 132 |
+
elif justify == "center":
|
| 133 |
+
for line in self._lines:
|
| 134 |
+
line.rstrip()
|
| 135 |
+
line.truncate(width, overflow=overflow)
|
| 136 |
+
line.pad_left((width - cell_len(line.plain)) // 2)
|
| 137 |
+
line.pad_right(width - cell_len(line.plain))
|
| 138 |
+
elif justify == "right":
|
| 139 |
+
for line in self._lines:
|
| 140 |
+
line.rstrip()
|
| 141 |
+
line.truncate(width, overflow=overflow)
|
| 142 |
+
line.pad_left(width - cell_len(line.plain))
|
| 143 |
+
elif justify == "full":
|
| 144 |
+
for line_index, line in enumerate(self._lines):
|
| 145 |
+
if line_index == len(self._lines) - 1:
|
| 146 |
+
break
|
| 147 |
+
words = line.split(" ")
|
| 148 |
+
words_size = sum(cell_len(word.plain) for word in words)
|
| 149 |
+
num_spaces = len(words) - 1
|
| 150 |
+
spaces = [1 for _ in range(num_spaces)]
|
| 151 |
+
index = 0
|
| 152 |
+
if spaces:
|
| 153 |
+
while words_size + num_spaces < width:
|
| 154 |
+
spaces[len(spaces) - index - 1] += 1
|
| 155 |
+
num_spaces += 1
|
| 156 |
+
index = (index + 1) % len(spaces)
|
| 157 |
+
tokens: List[Text] = []
|
| 158 |
+
for index, (word, next_word) in enumerate(
|
| 159 |
+
zip_longest(words, words[1:])
|
| 160 |
+
):
|
| 161 |
+
tokens.append(word)
|
| 162 |
+
if index < len(spaces):
|
| 163 |
+
style = word.get_style_at_offset(console, -1)
|
| 164 |
+
next_style = next_word.get_style_at_offset(console, 0)
|
| 165 |
+
space_style = style if style == next_style else line.style
|
| 166 |
+
tokens.append(Text(" " * spaces[index], style=space_style))
|
| 167 |
+
self[line_index] = Text("").join(tokens)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/control.py
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import time
|
| 3 |
+
from typing import TYPE_CHECKING, Callable, Dict, Iterable, List, Union
|
| 4 |
+
|
| 5 |
+
if sys.version_info >= (3, 8):
|
| 6 |
+
from typing import Final
|
| 7 |
+
else:
|
| 8 |
+
from typing_extensions import Final # pragma: no cover
|
| 9 |
+
|
| 10 |
+
from .segment import ControlCode, ControlType, Segment
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
from .console import Console, ConsoleOptions, RenderResult
|
| 14 |
+
|
| 15 |
+
STRIP_CONTROL_CODES: Final = [
|
| 16 |
+
7, # Bell
|
| 17 |
+
8, # Backspace
|
| 18 |
+
11, # Vertical tab
|
| 19 |
+
12, # Form feed
|
| 20 |
+
13, # Carriage return
|
| 21 |
+
]
|
| 22 |
+
_CONTROL_STRIP_TRANSLATE: Final = {
|
| 23 |
+
_codepoint: None for _codepoint in STRIP_CONTROL_CODES
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
CONTROL_ESCAPE: Final = {
|
| 27 |
+
7: "\\a",
|
| 28 |
+
8: "\\b",
|
| 29 |
+
11: "\\v",
|
| 30 |
+
12: "\\f",
|
| 31 |
+
13: "\\r",
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
CONTROL_CODES_FORMAT: Dict[int, Callable[..., str]] = {
|
| 35 |
+
ControlType.BELL: lambda: "\x07",
|
| 36 |
+
ControlType.CARRIAGE_RETURN: lambda: "\r",
|
| 37 |
+
ControlType.HOME: lambda: "\x1b[H",
|
| 38 |
+
ControlType.CLEAR: lambda: "\x1b[2J",
|
| 39 |
+
ControlType.ENABLE_ALT_SCREEN: lambda: "\x1b[?1049h",
|
| 40 |
+
ControlType.DISABLE_ALT_SCREEN: lambda: "\x1b[?1049l",
|
| 41 |
+
ControlType.SHOW_CURSOR: lambda: "\x1b[?25h",
|
| 42 |
+
ControlType.HIDE_CURSOR: lambda: "\x1b[?25l",
|
| 43 |
+
ControlType.CURSOR_UP: lambda param: f"\x1b[{param}A",
|
| 44 |
+
ControlType.CURSOR_DOWN: lambda param: f"\x1b[{param}B",
|
| 45 |
+
ControlType.CURSOR_FORWARD: lambda param: f"\x1b[{param}C",
|
| 46 |
+
ControlType.CURSOR_BACKWARD: lambda param: f"\x1b[{param}D",
|
| 47 |
+
ControlType.CURSOR_MOVE_TO_COLUMN: lambda param: f"\x1b[{param+1}G",
|
| 48 |
+
ControlType.ERASE_IN_LINE: lambda param: f"\x1b[{param}K",
|
| 49 |
+
ControlType.CURSOR_MOVE_TO: lambda x, y: f"\x1b[{y+1};{x+1}H",
|
| 50 |
+
ControlType.SET_WINDOW_TITLE: lambda title: f"\x1b]0;{title}\x07",
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class Control:
|
| 55 |
+
"""A renderable that inserts a control code (non printable but may move cursor).
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
*codes (str): Positional arguments are either a :class:`~rich.segment.ControlType` enum or a
|
| 59 |
+
tuple of ControlType and an integer parameter
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
__slots__ = ["segment"]
|
| 63 |
+
|
| 64 |
+
def __init__(self, *codes: Union[ControlType, ControlCode]) -> None:
|
| 65 |
+
control_codes: List[ControlCode] = [
|
| 66 |
+
(code,) if isinstance(code, ControlType) else code for code in codes
|
| 67 |
+
]
|
| 68 |
+
_format_map = CONTROL_CODES_FORMAT
|
| 69 |
+
rendered_codes = "".join(
|
| 70 |
+
_format_map[code](*parameters) for code, *parameters in control_codes
|
| 71 |
+
)
|
| 72 |
+
self.segment = Segment(rendered_codes, None, control_codes)
|
| 73 |
+
|
| 74 |
+
@classmethod
|
| 75 |
+
def bell(cls) -> "Control":
|
| 76 |
+
"""Ring the 'bell'."""
|
| 77 |
+
return cls(ControlType.BELL)
|
| 78 |
+
|
| 79 |
+
@classmethod
|
| 80 |
+
def home(cls) -> "Control":
|
| 81 |
+
"""Move cursor to 'home' position."""
|
| 82 |
+
return cls(ControlType.HOME)
|
| 83 |
+
|
| 84 |
+
@classmethod
|
| 85 |
+
def move(cls, x: int = 0, y: int = 0) -> "Control":
|
| 86 |
+
"""Move cursor relative to current position.
|
| 87 |
+
|
| 88 |
+
Args:
|
| 89 |
+
x (int): X offset.
|
| 90 |
+
y (int): Y offset.
|
| 91 |
+
|
| 92 |
+
Returns:
|
| 93 |
+
~Control: Control object.
|
| 94 |
+
|
| 95 |
+
"""
|
| 96 |
+
|
| 97 |
+
def get_codes() -> Iterable[ControlCode]:
|
| 98 |
+
control = ControlType
|
| 99 |
+
if x:
|
| 100 |
+
yield (
|
| 101 |
+
control.CURSOR_FORWARD if x > 0 else control.CURSOR_BACKWARD,
|
| 102 |
+
abs(x),
|
| 103 |
+
)
|
| 104 |
+
if y:
|
| 105 |
+
yield (
|
| 106 |
+
control.CURSOR_DOWN if y > 0 else control.CURSOR_UP,
|
| 107 |
+
abs(y),
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
control = cls(*get_codes())
|
| 111 |
+
return control
|
| 112 |
+
|
| 113 |
+
@classmethod
|
| 114 |
+
def move_to_column(cls, x: int, y: int = 0) -> "Control":
|
| 115 |
+
"""Move to the given column, optionally add offset to row.
|
| 116 |
+
|
| 117 |
+
Returns:
|
| 118 |
+
x (int): absolute x (column)
|
| 119 |
+
y (int): optional y offset (row)
|
| 120 |
+
|
| 121 |
+
Returns:
|
| 122 |
+
~Control: Control object.
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
return (
|
| 126 |
+
cls(
|
| 127 |
+
(ControlType.CURSOR_MOVE_TO_COLUMN, x),
|
| 128 |
+
(
|
| 129 |
+
ControlType.CURSOR_DOWN if y > 0 else ControlType.CURSOR_UP,
|
| 130 |
+
abs(y),
|
| 131 |
+
),
|
| 132 |
+
)
|
| 133 |
+
if y
|
| 134 |
+
else cls((ControlType.CURSOR_MOVE_TO_COLUMN, x))
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
@classmethod
|
| 138 |
+
def move_to(cls, x: int, y: int) -> "Control":
|
| 139 |
+
"""Move cursor to absolute position.
|
| 140 |
+
|
| 141 |
+
Args:
|
| 142 |
+
x (int): x offset (column)
|
| 143 |
+
y (int): y offset (row)
|
| 144 |
+
|
| 145 |
+
Returns:
|
| 146 |
+
~Control: Control object.
|
| 147 |
+
"""
|
| 148 |
+
return cls((ControlType.CURSOR_MOVE_TO, x, y))
|
| 149 |
+
|
| 150 |
+
@classmethod
|
| 151 |
+
def clear(cls) -> "Control":
|
| 152 |
+
"""Clear the screen."""
|
| 153 |
+
return cls(ControlType.CLEAR)
|
| 154 |
+
|
| 155 |
+
@classmethod
|
| 156 |
+
def show_cursor(cls, show: bool) -> "Control":
|
| 157 |
+
"""Show or hide the cursor."""
|
| 158 |
+
return cls(ControlType.SHOW_CURSOR if show else ControlType.HIDE_CURSOR)
|
| 159 |
+
|
| 160 |
+
@classmethod
|
| 161 |
+
def alt_screen(cls, enable: bool) -> "Control":
|
| 162 |
+
"""Enable or disable alt screen."""
|
| 163 |
+
if enable:
|
| 164 |
+
return cls(ControlType.ENABLE_ALT_SCREEN, ControlType.HOME)
|
| 165 |
+
else:
|
| 166 |
+
return cls(ControlType.DISABLE_ALT_SCREEN)
|
| 167 |
+
|
| 168 |
+
@classmethod
|
| 169 |
+
def title(cls, title: str) -> "Control":
|
| 170 |
+
"""Set the terminal window title
|
| 171 |
+
|
| 172 |
+
Args:
|
| 173 |
+
title (str): The new terminal window title
|
| 174 |
+
"""
|
| 175 |
+
return cls((ControlType.SET_WINDOW_TITLE, title))
|
| 176 |
+
|
| 177 |
+
def __str__(self) -> str:
|
| 178 |
+
return self.segment.text
|
| 179 |
+
|
| 180 |
+
def __rich_console__(
|
| 181 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 182 |
+
) -> "RenderResult":
|
| 183 |
+
if self.segment.text:
|
| 184 |
+
yield self.segment
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def strip_control_codes(
|
| 188 |
+
text: str, _translate_table: Dict[int, None] = _CONTROL_STRIP_TRANSLATE
|
| 189 |
+
) -> str:
|
| 190 |
+
"""Remove control codes from text.
|
| 191 |
+
|
| 192 |
+
Args:
|
| 193 |
+
text (str): A string possibly contain control codes.
|
| 194 |
+
|
| 195 |
+
Returns:
|
| 196 |
+
str: String with control codes removed.
|
| 197 |
+
"""
|
| 198 |
+
return text.translate(_translate_table)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def escape_control_codes(
|
| 202 |
+
text: str,
|
| 203 |
+
_translate_table: Dict[int, str] = CONTROL_ESCAPE,
|
| 204 |
+
) -> str:
|
| 205 |
+
"""Replace control codes with their "escaped" equivalent in the given text.
|
| 206 |
+
(e.g. "\b" becomes "\\b")
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
text (str): A string possibly containing control codes.
|
| 210 |
+
|
| 211 |
+
Returns:
|
| 212 |
+
str: String with control codes replaced with their escaped version.
|
| 213 |
+
"""
|
| 214 |
+
return text.translate(_translate_table)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__": # pragma: no cover
|
| 218 |
+
from rich.console import Console
|
| 219 |
+
|
| 220 |
+
console = Console()
|
| 221 |
+
console.print("Look at the title of your terminal window ^")
|
| 222 |
+
# console.print(Control((ControlType.SET_WINDOW_TITLE, "Hello, world!")))
|
| 223 |
+
for i in range(10):
|
| 224 |
+
console.set_window_title("🚀 Loading" + "." * i)
|
| 225 |
+
time.sleep(0.5)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/default_styles.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict
|
| 2 |
+
|
| 3 |
+
from .style import Style
|
| 4 |
+
|
| 5 |
+
DEFAULT_STYLES: Dict[str, Style] = {
|
| 6 |
+
"none": Style.null(),
|
| 7 |
+
"reset": Style(
|
| 8 |
+
color="default",
|
| 9 |
+
bgcolor="default",
|
| 10 |
+
dim=False,
|
| 11 |
+
bold=False,
|
| 12 |
+
italic=False,
|
| 13 |
+
underline=False,
|
| 14 |
+
blink=False,
|
| 15 |
+
blink2=False,
|
| 16 |
+
reverse=False,
|
| 17 |
+
conceal=False,
|
| 18 |
+
strike=False,
|
| 19 |
+
),
|
| 20 |
+
"dim": Style(dim=True),
|
| 21 |
+
"bright": Style(dim=False),
|
| 22 |
+
"bold": Style(bold=True),
|
| 23 |
+
"strong": Style(bold=True),
|
| 24 |
+
"code": Style(reverse=True, bold=True),
|
| 25 |
+
"italic": Style(italic=True),
|
| 26 |
+
"emphasize": Style(italic=True),
|
| 27 |
+
"underline": Style(underline=True),
|
| 28 |
+
"blink": Style(blink=True),
|
| 29 |
+
"blink2": Style(blink2=True),
|
| 30 |
+
"reverse": Style(reverse=True),
|
| 31 |
+
"strike": Style(strike=True),
|
| 32 |
+
"black": Style(color="black"),
|
| 33 |
+
"red": Style(color="red"),
|
| 34 |
+
"green": Style(color="green"),
|
| 35 |
+
"yellow": Style(color="yellow"),
|
| 36 |
+
"magenta": Style(color="magenta"),
|
| 37 |
+
"cyan": Style(color="cyan"),
|
| 38 |
+
"white": Style(color="white"),
|
| 39 |
+
"inspect.attr": Style(color="yellow", italic=True),
|
| 40 |
+
"inspect.attr.dunder": Style(color="yellow", italic=True, dim=True),
|
| 41 |
+
"inspect.callable": Style(bold=True, color="red"),
|
| 42 |
+
"inspect.async_def": Style(italic=True, color="bright_cyan"),
|
| 43 |
+
"inspect.def": Style(italic=True, color="bright_cyan"),
|
| 44 |
+
"inspect.class": Style(italic=True, color="bright_cyan"),
|
| 45 |
+
"inspect.error": Style(bold=True, color="red"),
|
| 46 |
+
"inspect.equals": Style(),
|
| 47 |
+
"inspect.help": Style(color="cyan"),
|
| 48 |
+
"inspect.doc": Style(dim=True),
|
| 49 |
+
"inspect.value.border": Style(color="green"),
|
| 50 |
+
"live.ellipsis": Style(bold=True, color="red"),
|
| 51 |
+
"layout.tree.row": Style(dim=False, color="red"),
|
| 52 |
+
"layout.tree.column": Style(dim=False, color="blue"),
|
| 53 |
+
"logging.keyword": Style(bold=True, color="yellow"),
|
| 54 |
+
"logging.level.notset": Style(dim=True),
|
| 55 |
+
"logging.level.debug": Style(color="green"),
|
| 56 |
+
"logging.level.info": Style(color="blue"),
|
| 57 |
+
"logging.level.warning": Style(color="yellow"),
|
| 58 |
+
"logging.level.error": Style(color="red", bold=True),
|
| 59 |
+
"logging.level.critical": Style(color="red", bold=True, reverse=True),
|
| 60 |
+
"log.level": Style.null(),
|
| 61 |
+
"log.time": Style(color="cyan", dim=True),
|
| 62 |
+
"log.message": Style.null(),
|
| 63 |
+
"log.path": Style(dim=True),
|
| 64 |
+
"repr.ellipsis": Style(color="yellow"),
|
| 65 |
+
"repr.indent": Style(color="green", dim=True),
|
| 66 |
+
"repr.error": Style(color="red", bold=True),
|
| 67 |
+
"repr.str": Style(color="green", italic=False, bold=False),
|
| 68 |
+
"repr.brace": Style(bold=True),
|
| 69 |
+
"repr.comma": Style(bold=True),
|
| 70 |
+
"repr.ipv4": Style(bold=True, color="bright_green"),
|
| 71 |
+
"repr.ipv6": Style(bold=True, color="bright_green"),
|
| 72 |
+
"repr.eui48": Style(bold=True, color="bright_green"),
|
| 73 |
+
"repr.eui64": Style(bold=True, color="bright_green"),
|
| 74 |
+
"repr.tag_start": Style(bold=True),
|
| 75 |
+
"repr.tag_name": Style(color="bright_magenta", bold=True),
|
| 76 |
+
"repr.tag_contents": Style(color="default"),
|
| 77 |
+
"repr.tag_end": Style(bold=True),
|
| 78 |
+
"repr.attrib_name": Style(color="yellow", italic=False),
|
| 79 |
+
"repr.attrib_equal": Style(bold=True),
|
| 80 |
+
"repr.attrib_value": Style(color="magenta", italic=False),
|
| 81 |
+
"repr.number": Style(color="cyan", bold=True, italic=False),
|
| 82 |
+
"repr.number_complex": Style(color="cyan", bold=True, italic=False), # same
|
| 83 |
+
"repr.bool_true": Style(color="bright_green", italic=True),
|
| 84 |
+
"repr.bool_false": Style(color="bright_red", italic=True),
|
| 85 |
+
"repr.none": Style(color="magenta", italic=True),
|
| 86 |
+
"repr.url": Style(underline=True, color="bright_blue", italic=False, bold=False),
|
| 87 |
+
"repr.uuid": Style(color="bright_yellow", bold=False),
|
| 88 |
+
"repr.call": Style(color="magenta", bold=True),
|
| 89 |
+
"repr.path": Style(color="magenta"),
|
| 90 |
+
"repr.filename": Style(color="bright_magenta"),
|
| 91 |
+
"rule.line": Style(color="bright_green"),
|
| 92 |
+
"rule.text": Style.null(),
|
| 93 |
+
"json.brace": Style(bold=True),
|
| 94 |
+
"json.bool_true": Style(color="bright_green", italic=True),
|
| 95 |
+
"json.bool_false": Style(color="bright_red", italic=True),
|
| 96 |
+
"json.null": Style(color="magenta", italic=True),
|
| 97 |
+
"json.number": Style(color="cyan", bold=True, italic=False),
|
| 98 |
+
"json.str": Style(color="green", italic=False, bold=False),
|
| 99 |
+
"json.key": Style(color="blue", bold=True),
|
| 100 |
+
"prompt": Style.null(),
|
| 101 |
+
"prompt.choices": Style(color="magenta", bold=True),
|
| 102 |
+
"prompt.default": Style(color="cyan", bold=True),
|
| 103 |
+
"prompt.invalid": Style(color="red"),
|
| 104 |
+
"prompt.invalid.choice": Style(color="red"),
|
| 105 |
+
"pretty": Style.null(),
|
| 106 |
+
"scope.border": Style(color="blue"),
|
| 107 |
+
"scope.key": Style(color="yellow", italic=True),
|
| 108 |
+
"scope.key.special": Style(color="yellow", italic=True, dim=True),
|
| 109 |
+
"scope.equals": Style(color="red"),
|
| 110 |
+
"table.header": Style(bold=True),
|
| 111 |
+
"table.footer": Style(bold=True),
|
| 112 |
+
"table.cell": Style.null(),
|
| 113 |
+
"table.title": Style(italic=True),
|
| 114 |
+
"table.caption": Style(italic=True, dim=True),
|
| 115 |
+
"traceback.error": Style(color="red", italic=True),
|
| 116 |
+
"traceback.border.syntax_error": Style(color="bright_red"),
|
| 117 |
+
"traceback.border": Style(color="red"),
|
| 118 |
+
"traceback.text": Style.null(),
|
| 119 |
+
"traceback.title": Style(color="red", bold=True),
|
| 120 |
+
"traceback.exc_type": Style(color="bright_red", bold=True),
|
| 121 |
+
"traceback.exc_value": Style.null(),
|
| 122 |
+
"traceback.offset": Style(color="bright_red", bold=True),
|
| 123 |
+
"traceback.error_range": Style(underline=True, bold=True, dim=False),
|
| 124 |
+
"bar.back": Style(color="grey23"),
|
| 125 |
+
"bar.complete": Style(color="rgb(249,38,114)"),
|
| 126 |
+
"bar.finished": Style(color="rgb(114,156,31)"),
|
| 127 |
+
"bar.pulse": Style(color="rgb(249,38,114)"),
|
| 128 |
+
"progress.description": Style.null(),
|
| 129 |
+
"progress.filesize": Style(color="green"),
|
| 130 |
+
"progress.filesize.total": Style(color="green"),
|
| 131 |
+
"progress.download": Style(color="green"),
|
| 132 |
+
"progress.elapsed": Style(color="yellow"),
|
| 133 |
+
"progress.percentage": Style(color="magenta"),
|
| 134 |
+
"progress.remaining": Style(color="cyan"),
|
| 135 |
+
"progress.data.speed": Style(color="red"),
|
| 136 |
+
"progress.spinner": Style(color="green"),
|
| 137 |
+
"status.spinner": Style(color="green"),
|
| 138 |
+
"tree": Style(),
|
| 139 |
+
"tree.line": Style(),
|
| 140 |
+
"markdown.paragraph": Style(),
|
| 141 |
+
"markdown.text": Style(),
|
| 142 |
+
"markdown.em": Style(italic=True),
|
| 143 |
+
"markdown.emph": Style(italic=True), # For commonmark backwards compatibility
|
| 144 |
+
"markdown.strong": Style(bold=True),
|
| 145 |
+
"markdown.code": Style(bold=True, color="cyan", bgcolor="black"),
|
| 146 |
+
"markdown.code_block": Style(color="cyan", bgcolor="black"),
|
| 147 |
+
"markdown.block_quote": Style(color="magenta"),
|
| 148 |
+
"markdown.list": Style(color="cyan"),
|
| 149 |
+
"markdown.item": Style(),
|
| 150 |
+
"markdown.item.bullet": Style(color="yellow", bold=True),
|
| 151 |
+
"markdown.item.number": Style(color="yellow", bold=True),
|
| 152 |
+
"markdown.hr": Style(color="yellow"),
|
| 153 |
+
"markdown.h1.border": Style(),
|
| 154 |
+
"markdown.h1": Style(bold=True),
|
| 155 |
+
"markdown.h2": Style(bold=True, underline=True),
|
| 156 |
+
"markdown.h3": Style(bold=True),
|
| 157 |
+
"markdown.h4": Style(bold=True, dim=True),
|
| 158 |
+
"markdown.h5": Style(underline=True),
|
| 159 |
+
"markdown.h6": Style(italic=True),
|
| 160 |
+
"markdown.h7": Style(italic=True, dim=True),
|
| 161 |
+
"markdown.link": Style(color="bright_blue"),
|
| 162 |
+
"markdown.link_url": Style(color="blue", underline=True),
|
| 163 |
+
"markdown.s": Style(strike=True),
|
| 164 |
+
"iso8601.date": Style(color="blue"),
|
| 165 |
+
"iso8601.time": Style(color="magenta"),
|
| 166 |
+
"iso8601.timezone": Style(color="yellow"),
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
if __name__ == "__main__": # pragma: no cover
|
| 171 |
+
import argparse
|
| 172 |
+
import io
|
| 173 |
+
|
| 174 |
+
from rich.console import Console
|
| 175 |
+
from rich.table import Table
|
| 176 |
+
from rich.text import Text
|
| 177 |
+
|
| 178 |
+
parser = argparse.ArgumentParser()
|
| 179 |
+
parser.add_argument("--html", action="store_true", help="Export as HTML table")
|
| 180 |
+
args = parser.parse_args()
|
| 181 |
+
html: bool = args.html
|
| 182 |
+
console = Console(record=True, width=70, file=io.StringIO()) if html else Console()
|
| 183 |
+
|
| 184 |
+
table = Table("Name", "Styling")
|
| 185 |
+
|
| 186 |
+
for style_name, style in DEFAULT_STYLES.items():
|
| 187 |
+
table.add_row(Text(style_name, style=style), str(style))
|
| 188 |
+
|
| 189 |
+
console.print(table)
|
| 190 |
+
if html:
|
| 191 |
+
print(console.export_html(inline_styles=True))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/diagnose.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import platform
|
| 3 |
+
|
| 4 |
+
from rich import inspect
|
| 5 |
+
from rich.console import Console, get_windows_console_features
|
| 6 |
+
from rich.panel import Panel
|
| 7 |
+
from rich.pretty import Pretty
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def report() -> None: # pragma: no cover
|
| 11 |
+
"""Print a report to the terminal with debugging information"""
|
| 12 |
+
console = Console()
|
| 13 |
+
inspect(console)
|
| 14 |
+
features = get_windows_console_features()
|
| 15 |
+
inspect(features)
|
| 16 |
+
|
| 17 |
+
env_names = (
|
| 18 |
+
"TERM",
|
| 19 |
+
"COLORTERM",
|
| 20 |
+
"CLICOLOR",
|
| 21 |
+
"NO_COLOR",
|
| 22 |
+
"TERM_PROGRAM",
|
| 23 |
+
"COLUMNS",
|
| 24 |
+
"LINES",
|
| 25 |
+
"JUPYTER_COLUMNS",
|
| 26 |
+
"JUPYTER_LINES",
|
| 27 |
+
"JPY_PARENT_PID",
|
| 28 |
+
"VSCODE_VERBOSE_LOGGING",
|
| 29 |
+
)
|
| 30 |
+
env = {name: os.getenv(name) for name in env_names}
|
| 31 |
+
console.print(Panel.fit((Pretty(env)), title="[b]Environment Variables"))
|
| 32 |
+
|
| 33 |
+
console.print(f'platform="{platform.system()}"')
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__": # pragma: no cover
|
| 37 |
+
report()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/emoji.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import TYPE_CHECKING, Optional, Union
|
| 3 |
+
|
| 4 |
+
from .jupyter import JupyterMixin
|
| 5 |
+
from .segment import Segment
|
| 6 |
+
from .style import Style
|
| 7 |
+
from ._emoji_codes import EMOJI
|
| 8 |
+
from ._emoji_replace import _emoji_replace
|
| 9 |
+
|
| 10 |
+
if sys.version_info >= (3, 8):
|
| 11 |
+
from typing import Literal
|
| 12 |
+
else:
|
| 13 |
+
from typing_extensions import Literal # pragma: no cover
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
if TYPE_CHECKING:
|
| 17 |
+
from .console import Console, ConsoleOptions, RenderResult
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
EmojiVariant = Literal["emoji", "text"]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class NoEmoji(Exception):
|
| 24 |
+
"""No emoji by that name."""
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class Emoji(JupyterMixin):
|
| 28 |
+
__slots__ = ["name", "style", "_char", "variant"]
|
| 29 |
+
|
| 30 |
+
VARIANTS = {"text": "\uFE0E", "emoji": "\uFE0F"}
|
| 31 |
+
|
| 32 |
+
def __init__(
|
| 33 |
+
self,
|
| 34 |
+
name: str,
|
| 35 |
+
style: Union[str, Style] = "none",
|
| 36 |
+
variant: Optional[EmojiVariant] = None,
|
| 37 |
+
) -> None:
|
| 38 |
+
"""A single emoji character.
|
| 39 |
+
|
| 40 |
+
Args:
|
| 41 |
+
name (str): Name of emoji.
|
| 42 |
+
style (Union[str, Style], optional): Optional style. Defaults to None.
|
| 43 |
+
|
| 44 |
+
Raises:
|
| 45 |
+
NoEmoji: If the emoji doesn't exist.
|
| 46 |
+
"""
|
| 47 |
+
self.name = name
|
| 48 |
+
self.style = style
|
| 49 |
+
self.variant = variant
|
| 50 |
+
try:
|
| 51 |
+
self._char = EMOJI[name]
|
| 52 |
+
except KeyError:
|
| 53 |
+
raise NoEmoji(f"No emoji called {name!r}")
|
| 54 |
+
if variant is not None:
|
| 55 |
+
self._char += self.VARIANTS.get(variant, "")
|
| 56 |
+
|
| 57 |
+
@classmethod
|
| 58 |
+
def replace(cls, text: str) -> str:
|
| 59 |
+
"""Replace emoji markup with corresponding unicode characters.
|
| 60 |
+
|
| 61 |
+
Args:
|
| 62 |
+
text (str): A string with emojis codes, e.g. "Hello :smiley:!"
|
| 63 |
+
|
| 64 |
+
Returns:
|
| 65 |
+
str: A string with emoji codes replaces with actual emoji.
|
| 66 |
+
"""
|
| 67 |
+
return _emoji_replace(text)
|
| 68 |
+
|
| 69 |
+
def __repr__(self) -> str:
|
| 70 |
+
return f"<emoji {self.name!r}>"
|
| 71 |
+
|
| 72 |
+
def __str__(self) -> str:
|
| 73 |
+
return self._char
|
| 74 |
+
|
| 75 |
+
def __rich_console__(
|
| 76 |
+
self, console: "Console", options: "ConsoleOptions"
|
| 77 |
+
) -> "RenderResult":
|
| 78 |
+
yield Segment(self._char, console.get_style(self.style))
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__": # pragma: no cover
|
| 82 |
+
import sys
|
| 83 |
+
|
| 84 |
+
from rich.columns import Columns
|
| 85 |
+
from rich.console import Console
|
| 86 |
+
|
| 87 |
+
console = Console(record=True)
|
| 88 |
+
|
| 89 |
+
columns = Columns(
|
| 90 |
+
(f":{name}: {name}" for name in sorted(EMOJI.keys()) if "\u200D" not in name),
|
| 91 |
+
column_first=True,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
console.print(columns)
|
| 95 |
+
if len(sys.argv) > 1:
|
| 96 |
+
console.save_html(sys.argv[1])
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/errors.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class ConsoleError(Exception):
|
| 2 |
+
"""An error in console operation."""
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class StyleError(Exception):
|
| 6 |
+
"""An error in styles."""
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class StyleSyntaxError(ConsoleError):
|
| 10 |
+
"""Style was badly formatted."""
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class MissingStyle(StyleError):
|
| 14 |
+
"""No such style."""
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class StyleStackError(ConsoleError):
|
| 18 |
+
"""Style stack is invalid."""
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class NotRenderableError(ConsoleError):
|
| 22 |
+
"""Object is not renderable."""
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class MarkupError(ConsoleError):
|
| 26 |
+
"""Markup was badly formatted."""
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class LiveError(ConsoleError):
|
| 30 |
+
"""Error related to Live display."""
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class NoAltScreen(ConsoleError):
|
| 34 |
+
"""Alt screen mode was required."""
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/file_proxy.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
from typing import IO, TYPE_CHECKING, Any, List
|
| 3 |
+
|
| 4 |
+
from .ansi import AnsiDecoder
|
| 5 |
+
from .text import Text
|
| 6 |
+
|
| 7 |
+
if TYPE_CHECKING:
|
| 8 |
+
from .console import Console
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class FileProxy(io.TextIOBase):
|
| 12 |
+
"""Wraps a file (e.g. sys.stdout) and redirects writes to a console."""
|
| 13 |
+
|
| 14 |
+
def __init__(self, console: "Console", file: IO[str]) -> None:
|
| 15 |
+
self.__console = console
|
| 16 |
+
self.__file = file
|
| 17 |
+
self.__buffer: List[str] = []
|
| 18 |
+
self.__ansi_decoder = AnsiDecoder()
|
| 19 |
+
|
| 20 |
+
@property
|
| 21 |
+
def rich_proxied_file(self) -> IO[str]:
|
| 22 |
+
"""Get proxied file."""
|
| 23 |
+
return self.__file
|
| 24 |
+
|
| 25 |
+
def __getattr__(self, name: str) -> Any:
|
| 26 |
+
return getattr(self.__file, name)
|
| 27 |
+
|
| 28 |
+
def write(self, text: str) -> int:
|
| 29 |
+
if not isinstance(text, str):
|
| 30 |
+
raise TypeError(f"write() argument must be str, not {type(text).__name__}")
|
| 31 |
+
buffer = self.__buffer
|
| 32 |
+
lines: List[str] = []
|
| 33 |
+
while text:
|
| 34 |
+
line, new_line, text = text.partition("\n")
|
| 35 |
+
if new_line:
|
| 36 |
+
lines.append("".join(buffer) + line)
|
| 37 |
+
buffer.clear()
|
| 38 |
+
else:
|
| 39 |
+
buffer.append(line)
|
| 40 |
+
break
|
| 41 |
+
if lines:
|
| 42 |
+
console = self.__console
|
| 43 |
+
with console:
|
| 44 |
+
output = Text("\n").join(
|
| 45 |
+
self.__ansi_decoder.decode_line(line) for line in lines
|
| 46 |
+
)
|
| 47 |
+
console.print(output)
|
| 48 |
+
return len(text)
|
| 49 |
+
|
| 50 |
+
def flush(self) -> None:
|
| 51 |
+
output = "".join(self.__buffer)
|
| 52 |
+
if output:
|
| 53 |
+
self.__console.print(output)
|
| 54 |
+
del self.__buffer[:]
|
| 55 |
+
|
| 56 |
+
def fileno(self) -> int:
|
| 57 |
+
return self.__file.fileno()
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/filesize.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Functions for reporting filesizes. Borrowed from https://github.com/PyFilesystem/pyfilesystem2
|
| 2 |
+
|
| 3 |
+
The functions declared in this module should cover the different
|
| 4 |
+
use cases needed to generate a string representation of a file size
|
| 5 |
+
using several different units. Since there are many standards regarding
|
| 6 |
+
file size units, three different functions have been implemented.
|
| 7 |
+
|
| 8 |
+
See Also:
|
| 9 |
+
* `Wikipedia: Binary prefix <https://en.wikipedia.org/wiki/Binary_prefix>`_
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
__all__ = ["decimal"]
|
| 14 |
+
|
| 15 |
+
from typing import Iterable, List, Optional, Tuple
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _to_str(
|
| 19 |
+
size: int,
|
| 20 |
+
suffixes: Iterable[str],
|
| 21 |
+
base: int,
|
| 22 |
+
*,
|
| 23 |
+
precision: Optional[int] = 1,
|
| 24 |
+
separator: Optional[str] = " ",
|
| 25 |
+
) -> str:
|
| 26 |
+
if size == 1:
|
| 27 |
+
return "1 byte"
|
| 28 |
+
elif size < base:
|
| 29 |
+
return f"{size:,} bytes"
|
| 30 |
+
|
| 31 |
+
for i, suffix in enumerate(suffixes, 2): # noqa: B007
|
| 32 |
+
unit = base**i
|
| 33 |
+
if size < unit:
|
| 34 |
+
break
|
| 35 |
+
return "{:,.{precision}f}{separator}{}".format(
|
| 36 |
+
(base * size / unit),
|
| 37 |
+
suffix,
|
| 38 |
+
precision=precision,
|
| 39 |
+
separator=separator,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def pick_unit_and_suffix(size: int, suffixes: List[str], base: int) -> Tuple[int, str]:
|
| 44 |
+
"""Pick a suffix and base for the given size."""
|
| 45 |
+
for i, suffix in enumerate(suffixes):
|
| 46 |
+
unit = base**i
|
| 47 |
+
if size < unit * base:
|
| 48 |
+
break
|
| 49 |
+
return unit, suffix
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def decimal(
|
| 53 |
+
size: int,
|
| 54 |
+
*,
|
| 55 |
+
precision: Optional[int] = 1,
|
| 56 |
+
separator: Optional[str] = " ",
|
| 57 |
+
) -> str:
|
| 58 |
+
"""Convert a filesize in to a string (powers of 1000, SI prefixes).
|
| 59 |
+
|
| 60 |
+
In this convention, ``1000 B = 1 kB``.
|
| 61 |
+
|
| 62 |
+
This is typically the format used to advertise the storage
|
| 63 |
+
capacity of USB flash drives and the like (*256 MB* meaning
|
| 64 |
+
actually a storage capacity of more than *256 000 000 B*),
|
| 65 |
+
or used by **Mac OS X** since v10.6 to report file sizes.
|
| 66 |
+
|
| 67 |
+
Arguments:
|
| 68 |
+
int (size): A file size.
|
| 69 |
+
int (precision): The number of decimal places to include (default = 1).
|
| 70 |
+
str (separator): The string to separate the value from the units (default = " ").
|
| 71 |
+
|
| 72 |
+
Returns:
|
| 73 |
+
`str`: A string containing a abbreviated file size and units.
|
| 74 |
+
|
| 75 |
+
Example:
|
| 76 |
+
>>> filesize.decimal(30000)
|
| 77 |
+
'30.0 kB'
|
| 78 |
+
>>> filesize.decimal(30000, precision=2, separator="")
|
| 79 |
+
'30.00kB'
|
| 80 |
+
|
| 81 |
+
"""
|
| 82 |
+
return _to_str(
|
| 83 |
+
size,
|
| 84 |
+
("kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"),
|
| 85 |
+
1000,
|
| 86 |
+
precision=precision,
|
| 87 |
+
separator=separator,
|
| 88 |
+
)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/highlighter.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
from abc import ABC, abstractmethod
|
| 3 |
+
from typing import List, Union
|
| 4 |
+
|
| 5 |
+
from .text import Span, Text
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _combine_regex(*regexes: str) -> str:
|
| 9 |
+
"""Combine a number of regexes in to a single regex.
|
| 10 |
+
|
| 11 |
+
Returns:
|
| 12 |
+
str: New regex with all regexes ORed together.
|
| 13 |
+
"""
|
| 14 |
+
return "|".join(regexes)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class Highlighter(ABC):
|
| 18 |
+
"""Abstract base class for highlighters."""
|
| 19 |
+
|
| 20 |
+
def __call__(self, text: Union[str, Text]) -> Text:
|
| 21 |
+
"""Highlight a str or Text instance.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
text (Union[str, ~Text]): Text to highlight.
|
| 25 |
+
|
| 26 |
+
Raises:
|
| 27 |
+
TypeError: If not called with text or str.
|
| 28 |
+
|
| 29 |
+
Returns:
|
| 30 |
+
Text: A test instance with highlighting applied.
|
| 31 |
+
"""
|
| 32 |
+
if isinstance(text, str):
|
| 33 |
+
highlight_text = Text(text)
|
| 34 |
+
elif isinstance(text, Text):
|
| 35 |
+
highlight_text = text.copy()
|
| 36 |
+
else:
|
| 37 |
+
raise TypeError(f"str or Text instance required, not {text!r}")
|
| 38 |
+
self.highlight(highlight_text)
|
| 39 |
+
return highlight_text
|
| 40 |
+
|
| 41 |
+
@abstractmethod
|
| 42 |
+
def highlight(self, text: Text) -> None:
|
| 43 |
+
"""Apply highlighting in place to text.
|
| 44 |
+
|
| 45 |
+
Args:
|
| 46 |
+
text (~Text): A text object highlight.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class NullHighlighter(Highlighter):
|
| 51 |
+
"""A highlighter object that doesn't highlight.
|
| 52 |
+
|
| 53 |
+
May be used to disable highlighting entirely.
|
| 54 |
+
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def highlight(self, text: Text) -> None:
|
| 58 |
+
"""Nothing to do"""
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class RegexHighlighter(Highlighter):
|
| 62 |
+
"""Applies highlighting from a list of regular expressions."""
|
| 63 |
+
|
| 64 |
+
highlights: List[str] = []
|
| 65 |
+
base_style: str = ""
|
| 66 |
+
|
| 67 |
+
def highlight(self, text: Text) -> None:
|
| 68 |
+
"""Highlight :class:`rich.text.Text` using regular expressions.
|
| 69 |
+
|
| 70 |
+
Args:
|
| 71 |
+
text (~Text): Text to highlighted.
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
|
| 75 |
+
highlight_regex = text.highlight_regex
|
| 76 |
+
for re_highlight in self.highlights:
|
| 77 |
+
highlight_regex(re_highlight, style_prefix=self.base_style)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class ReprHighlighter(RegexHighlighter):
|
| 81 |
+
"""Highlights the text typically produced from ``__repr__`` methods."""
|
| 82 |
+
|
| 83 |
+
base_style = "repr."
|
| 84 |
+
highlights = [
|
| 85 |
+
r"(?P<tag_start><)(?P<tag_name>[-\w.:|]*)(?P<tag_contents>[\w\W]*)(?P<tag_end>>)",
|
| 86 |
+
r'(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>"?[\w_]+"?)?',
|
| 87 |
+
r"(?P<brace>[][{}()])",
|
| 88 |
+
_combine_regex(
|
| 89 |
+
r"(?P<ipv4>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})",
|
| 90 |
+
r"(?P<ipv6>([A-Fa-f0-9]{1,4}::?){1,7}[A-Fa-f0-9]{1,4})",
|
| 91 |
+
r"(?P<eui64>(?:[0-9A-Fa-f]{1,2}-){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){7}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){3}[0-9A-Fa-f]{4})",
|
| 92 |
+
r"(?P<eui48>(?:[0-9A-Fa-f]{1,2}-){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{1,2}:){5}[0-9A-Fa-f]{1,2}|(?:[0-9A-Fa-f]{4}\.){2}[0-9A-Fa-f]{4})",
|
| 93 |
+
r"(?P<uuid>[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})",
|
| 94 |
+
r"(?P<call>[\w.]*?)\(",
|
| 95 |
+
r"\b(?P<bool_true>True)\b|\b(?P<bool_false>False)\b|\b(?P<none>None)\b",
|
| 96 |
+
r"(?P<ellipsis>\.\.\.)",
|
| 97 |
+
r"(?P<number_complex>(?<!\w)(?:\-?[0-9]+\.?[0-9]*(?:e[-+]?\d+?)?)(?:[-+](?:[0-9]+\.?[0-9]*(?:e[-+]?\d+)?))?j)",
|
| 98 |
+
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
|
| 99 |
+
r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
|
| 100 |
+
r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
|
| 101 |
+
r"(?P<url>(file|https|http|ws|wss)://[-0-9a-zA-Z$_+!`(),.?/;:&=%#~@]*)",
|
| 102 |
+
),
|
| 103 |
+
]
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class JSONHighlighter(RegexHighlighter):
|
| 107 |
+
"""Highlights JSON"""
|
| 108 |
+
|
| 109 |
+
# Captures the start and end of JSON strings, handling escaped quotes
|
| 110 |
+
JSON_STR = r"(?<![\\\w])(?P<str>b?\".*?(?<!\\)\")"
|
| 111 |
+
JSON_WHITESPACE = {" ", "\n", "\r", "\t"}
|
| 112 |
+
|
| 113 |
+
base_style = "json."
|
| 114 |
+
highlights = [
|
| 115 |
+
_combine_regex(
|
| 116 |
+
r"(?P<brace>[\{\[\(\)\]\}])",
|
| 117 |
+
r"\b(?P<bool_true>true)\b|\b(?P<bool_false>false)\b|\b(?P<null>null)\b",
|
| 118 |
+
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[\-\+]?\d+?)?\b|0x[0-9a-fA-F]*)",
|
| 119 |
+
JSON_STR,
|
| 120 |
+
),
|
| 121 |
+
]
|
| 122 |
+
|
| 123 |
+
def highlight(self, text: Text) -> None:
|
| 124 |
+
super().highlight(text)
|
| 125 |
+
|
| 126 |
+
# Additional work to handle highlighting JSON keys
|
| 127 |
+
plain = text.plain
|
| 128 |
+
append = text.spans.append
|
| 129 |
+
whitespace = self.JSON_WHITESPACE
|
| 130 |
+
for match in re.finditer(self.JSON_STR, plain):
|
| 131 |
+
start, end = match.span()
|
| 132 |
+
cursor = end
|
| 133 |
+
while cursor < len(plain):
|
| 134 |
+
char = plain[cursor]
|
| 135 |
+
cursor += 1
|
| 136 |
+
if char == ":":
|
| 137 |
+
append(Span(start, end, "json.key"))
|
| 138 |
+
elif char in whitespace:
|
| 139 |
+
continue
|
| 140 |
+
break
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
class ISO8601Highlighter(RegexHighlighter):
|
| 144 |
+
"""Highlights the ISO8601 date time strings.
|
| 145 |
+
Regex reference: https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html
|
| 146 |
+
"""
|
| 147 |
+
|
| 148 |
+
base_style = "iso8601."
|
| 149 |
+
highlights = [
|
| 150 |
+
#
|
| 151 |
+
# Dates
|
| 152 |
+
#
|
| 153 |
+
# Calendar month (e.g. 2008-08). The hyphen is required
|
| 154 |
+
r"^(?P<year>[0-9]{4})-(?P<month>1[0-2]|0[1-9])$",
|
| 155 |
+
# Calendar date w/o hyphens (e.g. 20080830)
|
| 156 |
+
r"^(?P<date>(?P<year>[0-9]{4})(?P<month>1[0-2]|0[1-9])(?P<day>3[01]|0[1-9]|[12][0-9]))$",
|
| 157 |
+
# Ordinal date (e.g. 2008-243). The hyphen is optional
|
| 158 |
+
r"^(?P<date>(?P<year>[0-9]{4})-?(?P<day>36[0-6]|3[0-5][0-9]|[12][0-9]{2}|0[1-9][0-9]|00[1-9]))$",
|
| 159 |
+
#
|
| 160 |
+
# Weeks
|
| 161 |
+
#
|
| 162 |
+
# Week of the year (e.g., 2008-W35). The hyphen is optional
|
| 163 |
+
r"^(?P<date>(?P<year>[0-9]{4})-?W(?P<week>5[0-3]|[1-4][0-9]|0[1-9]))$",
|
| 164 |
+
# Week date (e.g., 2008-W35-6). The hyphens are optional
|
| 165 |
+
r"^(?P<date>(?P<year>[0-9]{4})-?W(?P<week>5[0-3]|[1-4][0-9]|0[1-9])-?(?P<day>[1-7]))$",
|
| 166 |
+
#
|
| 167 |
+
# Times
|
| 168 |
+
#
|
| 169 |
+
# Hours and minutes (e.g., 17:21). The colon is optional
|
| 170 |
+
r"^(?P<time>(?P<hour>2[0-3]|[01][0-9]):?(?P<minute>[0-5][0-9]))$",
|
| 171 |
+
# Hours, minutes, and seconds w/o colons (e.g., 172159)
|
| 172 |
+
r"^(?P<time>(?P<hour>2[0-3]|[01][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9]))$",
|
| 173 |
+
# Time zone designator (e.g., Z, +07 or +07:00). The colons and the minutes are optional
|
| 174 |
+
r"^(?P<timezone>(Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?))$",
|
| 175 |
+
# Hours, minutes, and seconds with time zone designator (e.g., 17:21:59+07:00).
|
| 176 |
+
# All the colons are optional. The minutes in the time zone designator are also optional
|
| 177 |
+
r"^(?P<time>(?P<hour>2[0-3]|[01][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9]))(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?)$",
|
| 178 |
+
#
|
| 179 |
+
# Date and Time
|
| 180 |
+
#
|
| 181 |
+
# Calendar date with hours, minutes, and seconds (e.g., 2008-08-30 17:21:59 or 20080830 172159).
|
| 182 |
+
# A space is required between the date and the time. The hyphens and colons are optional.
|
| 183 |
+
# This regex matches dates and times that specify some hyphens or colons but omit others.
|
| 184 |
+
# This does not follow ISO 8601
|
| 185 |
+
r"^(?P<date>(?P<year>[0-9]{4})(?P<hyphen>-)?(?P<month>1[0-2]|0[1-9])(?(hyphen)-)(?P<day>3[01]|0[1-9]|[12][0-9])) (?P<time>(?P<hour>2[0-3]|[01][0-9])(?(hyphen):)(?P<minute>[0-5][0-9])(?(hyphen):)(?P<second>[0-5][0-9]))$",
|
| 186 |
+
#
|
| 187 |
+
# XML Schema dates and times
|
| 188 |
+
#
|
| 189 |
+
# Date, with optional time zone (e.g., 2008-08-30 or 2008-08-30+07:00).
|
| 190 |
+
# Hyphens are required. This is the XML Schema 'date' type
|
| 191 |
+
r"^(?P<date>(?P<year>-?(?:[1-9][0-9]*)?[0-9]{4})-(?P<month>1[0-2]|0[1-9])-(?P<day>3[01]|0[1-9]|[12][0-9]))(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
|
| 192 |
+
# Time, with optional fractional seconds and time zone (e.g., 01:45:36 or 01:45:36.123+07:00).
|
| 193 |
+
# There is no limit on the number of digits for the fractional seconds. This is the XML Schema 'time' type
|
| 194 |
+
r"^(?P<time>(?P<hour>2[0-3]|[01][0-9]):(?P<minute>[0-5][0-9]):(?P<second>[0-5][0-9])(?P<frac>\.[0-9]+)?)(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
|
| 195 |
+
# Date and time, with optional fractional seconds and time zone (e.g., 2008-08-30T01:45:36 or 2008-08-30T01:45:36.123Z).
|
| 196 |
+
# This is the XML Schema 'dateTime' type
|
| 197 |
+
r"^(?P<date>(?P<year>-?(?:[1-9][0-9]*)?[0-9]{4})-(?P<month>1[0-2]|0[1-9])-(?P<day>3[01]|0[1-9]|[12][0-9]))T(?P<time>(?P<hour>2[0-3]|[01][0-9]):(?P<minute>[0-5][0-9]):(?P<second>[0-5][0-9])(?P<ms>\.[0-9]+)?)(?P<timezone>Z|[+-](?:2[0-3]|[01][0-9]):[0-5][0-9])?$",
|
| 198 |
+
]
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if __name__ == "__main__": # pragma: no cover
|
| 202 |
+
from .console import Console
|
| 203 |
+
|
| 204 |
+
console = Console()
|
| 205 |
+
console.print("[bold green]hello world![/bold green]")
|
| 206 |
+
console.print("'[bold green]hello world![/bold green]'")
|
| 207 |
+
|
| 208 |
+
console.print(" /foo")
|
| 209 |
+
console.print("/foo/")
|
| 210 |
+
console.print("/foo/bar")
|
| 211 |
+
console.print("foo/bar/baz")
|
| 212 |
+
|
| 213 |
+
console.print("/foo/bar/baz?foo=bar+egg&egg=baz")
|
| 214 |
+
console.print("/foo/bar/baz/")
|
| 215 |
+
console.print("/foo/bar/baz/egg")
|
| 216 |
+
console.print("/foo/bar/baz/egg.py")
|
| 217 |
+
console.print("/foo/bar/baz/egg.py word")
|
| 218 |
+
console.print(" /foo/bar/baz/egg.py word")
|
| 219 |
+
console.print("foo /foo/bar/baz/egg.py word")
|
| 220 |
+
console.print("foo /foo/bar/ba._++z/egg+.py word")
|
| 221 |
+
console.print("https://example.org?foo=bar#header")
|
| 222 |
+
|
| 223 |
+
console.print(1234567.34)
|
| 224 |
+
console.print(1 / 2)
|
| 225 |
+
console.print(-1 / 123123123123)
|
| 226 |
+
|
| 227 |
+
console.print(
|
| 228 |
+
"127.0.1.1 bar 192.168.1.4 2001:0db8:85a3:0000:0000:8a2e:0370:7334 foo"
|
| 229 |
+
)
|
| 230 |
+
import json
|
| 231 |
+
|
| 232 |
+
console.print_json(json.dumps(obj={"name": "apple", "count": 1}), indent=None)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/json.py
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
from json import loads, dumps
|
| 3 |
+
from typing import Any, Callable, Optional, Union
|
| 4 |
+
|
| 5 |
+
from .text import Text
|
| 6 |
+
from .highlighter import JSONHighlighter, NullHighlighter
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
class JSON:
|
| 10 |
+
"""A renderable which pretty prints JSON.
|
| 11 |
+
|
| 12 |
+
Args:
|
| 13 |
+
json (str): JSON encoded data.
|
| 14 |
+
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
|
| 15 |
+
highlight (bool, optional): Enable highlighting. Defaults to True.
|
| 16 |
+
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
|
| 17 |
+
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
|
| 18 |
+
check_circular (bool, optional): Check for circular references. Defaults to True.
|
| 19 |
+
allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
|
| 20 |
+
default (Callable, optional): A callable that converts values that can not be encoded
|
| 21 |
+
in to something that can be JSON encoded. Defaults to None.
|
| 22 |
+
sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
|
| 23 |
+
"""
|
| 24 |
+
|
| 25 |
+
def __init__(
|
| 26 |
+
self,
|
| 27 |
+
json: str,
|
| 28 |
+
indent: Union[None, int, str] = 2,
|
| 29 |
+
highlight: bool = True,
|
| 30 |
+
skip_keys: bool = False,
|
| 31 |
+
ensure_ascii: bool = False,
|
| 32 |
+
check_circular: bool = True,
|
| 33 |
+
allow_nan: bool = True,
|
| 34 |
+
default: Optional[Callable[[Any], Any]] = None,
|
| 35 |
+
sort_keys: bool = False,
|
| 36 |
+
) -> None:
|
| 37 |
+
data = loads(json)
|
| 38 |
+
json = dumps(
|
| 39 |
+
data,
|
| 40 |
+
indent=indent,
|
| 41 |
+
skipkeys=skip_keys,
|
| 42 |
+
ensure_ascii=ensure_ascii,
|
| 43 |
+
check_circular=check_circular,
|
| 44 |
+
allow_nan=allow_nan,
|
| 45 |
+
default=default,
|
| 46 |
+
sort_keys=sort_keys,
|
| 47 |
+
)
|
| 48 |
+
highlighter = JSONHighlighter() if highlight else NullHighlighter()
|
| 49 |
+
self.text = highlighter(json)
|
| 50 |
+
self.text.no_wrap = True
|
| 51 |
+
self.text.overflow = None
|
| 52 |
+
|
| 53 |
+
@classmethod
|
| 54 |
+
def from_data(
|
| 55 |
+
cls,
|
| 56 |
+
data: Any,
|
| 57 |
+
indent: Union[None, int, str] = 2,
|
| 58 |
+
highlight: bool = True,
|
| 59 |
+
skip_keys: bool = False,
|
| 60 |
+
ensure_ascii: bool = False,
|
| 61 |
+
check_circular: bool = True,
|
| 62 |
+
allow_nan: bool = True,
|
| 63 |
+
default: Optional[Callable[[Any], Any]] = None,
|
| 64 |
+
sort_keys: bool = False,
|
| 65 |
+
) -> "JSON":
|
| 66 |
+
"""Encodes a JSON object from arbitrary data.
|
| 67 |
+
|
| 68 |
+
Args:
|
| 69 |
+
data (Any): An object that may be encoded in to JSON
|
| 70 |
+
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
|
| 71 |
+
highlight (bool, optional): Enable highlighting. Defaults to True.
|
| 72 |
+
default (Callable, optional): Optional callable which will be called for objects that cannot be serialized. Defaults to None.
|
| 73 |
+
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
|
| 74 |
+
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
|
| 75 |
+
check_circular (bool, optional): Check for circular references. Defaults to True.
|
| 76 |
+
allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
|
| 77 |
+
default (Callable, optional): A callable that converts values that can not be encoded
|
| 78 |
+
in to something that can be JSON encoded. Defaults to None.
|
| 79 |
+
sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
|
| 80 |
+
|
| 81 |
+
Returns:
|
| 82 |
+
JSON: New JSON object from the given data.
|
| 83 |
+
"""
|
| 84 |
+
json_instance: "JSON" = cls.__new__(cls)
|
| 85 |
+
json = dumps(
|
| 86 |
+
data,
|
| 87 |
+
indent=indent,
|
| 88 |
+
skipkeys=skip_keys,
|
| 89 |
+
ensure_ascii=ensure_ascii,
|
| 90 |
+
check_circular=check_circular,
|
| 91 |
+
allow_nan=allow_nan,
|
| 92 |
+
default=default,
|
| 93 |
+
sort_keys=sort_keys,
|
| 94 |
+
)
|
| 95 |
+
highlighter = JSONHighlighter() if highlight else NullHighlighter()
|
| 96 |
+
json_instance.text = highlighter(json)
|
| 97 |
+
json_instance.text.no_wrap = True
|
| 98 |
+
json_instance.text.overflow = None
|
| 99 |
+
return json_instance
|
| 100 |
+
|
| 101 |
+
def __rich__(self) -> Text:
|
| 102 |
+
return self.text
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
import argparse
|
| 107 |
+
import sys
|
| 108 |
+
|
| 109 |
+
parser = argparse.ArgumentParser(description="Pretty print json")
|
| 110 |
+
parser.add_argument(
|
| 111 |
+
"path",
|
| 112 |
+
metavar="PATH",
|
| 113 |
+
help="path to file, or - for stdin",
|
| 114 |
+
)
|
| 115 |
+
parser.add_argument(
|
| 116 |
+
"-i",
|
| 117 |
+
"--indent",
|
| 118 |
+
metavar="SPACES",
|
| 119 |
+
type=int,
|
| 120 |
+
help="Number of spaces in an indent",
|
| 121 |
+
default=2,
|
| 122 |
+
)
|
| 123 |
+
args = parser.parse_args()
|
| 124 |
+
|
| 125 |
+
from rich.console import Console
|
| 126 |
+
|
| 127 |
+
console = Console()
|
| 128 |
+
error_console = Console(stderr=True)
|
| 129 |
+
|
| 130 |
+
try:
|
| 131 |
+
if args.path == "-":
|
| 132 |
+
json_data = sys.stdin.read()
|
| 133 |
+
else:
|
| 134 |
+
json_data = Path(args.path).read_text()
|
| 135 |
+
except Exception as error:
|
| 136 |
+
error_console.print(f"Unable to read {args.path!r}; {error}")
|
| 137 |
+
sys.exit(-1)
|
| 138 |
+
|
| 139 |
+
console.print(JSON(json_data, indent=args.indent), soft_wrap=True)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/jupyter.py
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Sequence
|
| 2 |
+
|
| 3 |
+
if TYPE_CHECKING:
|
| 4 |
+
from rich.console import ConsoleRenderable
|
| 5 |
+
|
| 6 |
+
from . import get_console
|
| 7 |
+
from .segment import Segment
|
| 8 |
+
from .terminal_theme import DEFAULT_TERMINAL_THEME
|
| 9 |
+
|
| 10 |
+
if TYPE_CHECKING:
|
| 11 |
+
from rich.console import ConsoleRenderable
|
| 12 |
+
|
| 13 |
+
JUPYTER_HTML_FORMAT = """\
|
| 14 |
+
<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class JupyterRenderable:
|
| 19 |
+
"""A shim to write html to Jupyter notebook."""
|
| 20 |
+
|
| 21 |
+
def __init__(self, html: str, text: str) -> None:
|
| 22 |
+
self.html = html
|
| 23 |
+
self.text = text
|
| 24 |
+
|
| 25 |
+
def _repr_mimebundle_(
|
| 26 |
+
self, include: Sequence[str], exclude: Sequence[str], **kwargs: Any
|
| 27 |
+
) -> Dict[str, str]:
|
| 28 |
+
data = {"text/plain": self.text, "text/html": self.html}
|
| 29 |
+
if include:
|
| 30 |
+
data = {k: v for (k, v) in data.items() if k in include}
|
| 31 |
+
if exclude:
|
| 32 |
+
data = {k: v for (k, v) in data.items() if k not in exclude}
|
| 33 |
+
return data
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
class JupyterMixin:
|
| 37 |
+
"""Add to an Rich renderable to make it render in Jupyter notebook."""
|
| 38 |
+
|
| 39 |
+
__slots__ = ()
|
| 40 |
+
|
| 41 |
+
def _repr_mimebundle_(
|
| 42 |
+
self: "ConsoleRenderable",
|
| 43 |
+
include: Sequence[str],
|
| 44 |
+
exclude: Sequence[str],
|
| 45 |
+
**kwargs: Any,
|
| 46 |
+
) -> Dict[str, str]:
|
| 47 |
+
console = get_console()
|
| 48 |
+
segments = list(console.render(self, console.options))
|
| 49 |
+
html = _render_segments(segments)
|
| 50 |
+
text = console._render_buffer(segments)
|
| 51 |
+
data = {"text/plain": text, "text/html": html}
|
| 52 |
+
if include:
|
| 53 |
+
data = {k: v for (k, v) in data.items() if k in include}
|
| 54 |
+
if exclude:
|
| 55 |
+
data = {k: v for (k, v) in data.items() if k not in exclude}
|
| 56 |
+
return data
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _render_segments(segments: Iterable[Segment]) -> str:
|
| 60 |
+
def escape(text: str) -> str:
|
| 61 |
+
"""Escape html."""
|
| 62 |
+
return text.replace("&", "&").replace("<", "<").replace(">", ">")
|
| 63 |
+
|
| 64 |
+
fragments: List[str] = []
|
| 65 |
+
append_fragment = fragments.append
|
| 66 |
+
theme = DEFAULT_TERMINAL_THEME
|
| 67 |
+
for text, style, control in Segment.simplify(segments):
|
| 68 |
+
if control:
|
| 69 |
+
continue
|
| 70 |
+
text = escape(text)
|
| 71 |
+
if style:
|
| 72 |
+
rule = style.get_html_style(theme)
|
| 73 |
+
text = f'<span style="{rule}">{text}</span>' if rule else text
|
| 74 |
+
if style.link:
|
| 75 |
+
text = f'<a href="{style.link}" target="_blank">{text}</a>'
|
| 76 |
+
append_fragment(text)
|
| 77 |
+
|
| 78 |
+
code = "".join(fragments)
|
| 79 |
+
html = JUPYTER_HTML_FORMAT.format(code=code)
|
| 80 |
+
|
| 81 |
+
return html
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
def display(segments: Iterable[Segment], text: str) -> None:
|
| 85 |
+
"""Render segments to Jupyter."""
|
| 86 |
+
html = _render_segments(segments)
|
| 87 |
+
jupyter_renderable = JupyterRenderable(html, text)
|
| 88 |
+
try:
|
| 89 |
+
from IPython.display import display as ipython_display
|
| 90 |
+
|
| 91 |
+
ipython_display(jupyter_renderable)
|
| 92 |
+
except ModuleNotFoundError:
|
| 93 |
+
# Handle the case where the Console has force_jupyter=True,
|
| 94 |
+
# but IPython is not installed.
|
| 95 |
+
pass
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def print(*args: Any, **kwargs: Any) -> None:
|
| 99 |
+
"""Proxy for Console print."""
|
| 100 |
+
console = get_console()
|
| 101 |
+
return console.print(*args, **kwargs)
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/layout.py
ADDED
|
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from abc import ABC, abstractmethod
|
| 2 |
+
from itertools import islice
|
| 3 |
+
from operator import itemgetter
|
| 4 |
+
from threading import RLock
|
| 5 |
+
from typing import (
|
| 6 |
+
TYPE_CHECKING,
|
| 7 |
+
Dict,
|
| 8 |
+
Iterable,
|
| 9 |
+
List,
|
| 10 |
+
NamedTuple,
|
| 11 |
+
Optional,
|
| 12 |
+
Sequence,
|
| 13 |
+
Tuple,
|
| 14 |
+
Union,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
from ._ratio import ratio_resolve
|
| 18 |
+
from .align import Align
|
| 19 |
+
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
| 20 |
+
from .highlighter import ReprHighlighter
|
| 21 |
+
from .panel import Panel
|
| 22 |
+
from .pretty import Pretty
|
| 23 |
+
from .region import Region
|
| 24 |
+
from .repr import Result, rich_repr
|
| 25 |
+
from .segment import Segment
|
| 26 |
+
from .style import StyleType
|
| 27 |
+
|
| 28 |
+
if TYPE_CHECKING:
|
| 29 |
+
from rich.tree import Tree
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class LayoutRender(NamedTuple):
|
| 33 |
+
"""An individual layout render."""
|
| 34 |
+
|
| 35 |
+
region: Region
|
| 36 |
+
render: List[List[Segment]]
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
RegionMap = Dict["Layout", Region]
|
| 40 |
+
RenderMap = Dict["Layout", LayoutRender]
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class LayoutError(Exception):
|
| 44 |
+
"""Layout related error."""
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
class NoSplitter(LayoutError):
|
| 48 |
+
"""Requested splitter does not exist."""
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class _Placeholder:
|
| 52 |
+
"""An internal renderable used as a Layout placeholder."""
|
| 53 |
+
|
| 54 |
+
highlighter = ReprHighlighter()
|
| 55 |
+
|
| 56 |
+
def __init__(self, layout: "Layout", style: StyleType = "") -> None:
|
| 57 |
+
self.layout = layout
|
| 58 |
+
self.style = style
|
| 59 |
+
|
| 60 |
+
def __rich_console__(
|
| 61 |
+
self, console: Console, options: ConsoleOptions
|
| 62 |
+
) -> RenderResult:
|
| 63 |
+
width = options.max_width
|
| 64 |
+
height = options.height or options.size.height
|
| 65 |
+
layout = self.layout
|
| 66 |
+
title = (
|
| 67 |
+
f"{layout.name!r} ({width} x {height})"
|
| 68 |
+
if layout.name
|
| 69 |
+
else f"({width} x {height})"
|
| 70 |
+
)
|
| 71 |
+
yield Panel(
|
| 72 |
+
Align.center(Pretty(layout), vertical="middle"),
|
| 73 |
+
style=self.style,
|
| 74 |
+
title=self.highlighter(title),
|
| 75 |
+
border_style="blue",
|
| 76 |
+
height=height,
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class Splitter(ABC):
|
| 81 |
+
"""Base class for a splitter."""
|
| 82 |
+
|
| 83 |
+
name: str = ""
|
| 84 |
+
|
| 85 |
+
@abstractmethod
|
| 86 |
+
def get_tree_icon(self) -> str:
|
| 87 |
+
"""Get the icon (emoji) used in layout.tree"""
|
| 88 |
+
|
| 89 |
+
@abstractmethod
|
| 90 |
+
def divide(
|
| 91 |
+
self, children: Sequence["Layout"], region: Region
|
| 92 |
+
) -> Iterable[Tuple["Layout", Region]]:
|
| 93 |
+
"""Divide a region amongst several child layouts.
|
| 94 |
+
|
| 95 |
+
Args:
|
| 96 |
+
children (Sequence(Layout)): A number of child layouts.
|
| 97 |
+
region (Region): A rectangular region to divide.
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
class RowSplitter(Splitter):
|
| 102 |
+
"""Split a layout region in to rows."""
|
| 103 |
+
|
| 104 |
+
name = "row"
|
| 105 |
+
|
| 106 |
+
def get_tree_icon(self) -> str:
|
| 107 |
+
return "[layout.tree.row]⬌"
|
| 108 |
+
|
| 109 |
+
def divide(
|
| 110 |
+
self, children: Sequence["Layout"], region: Region
|
| 111 |
+
) -> Iterable[Tuple["Layout", Region]]:
|
| 112 |
+
x, y, width, height = region
|
| 113 |
+
render_widths = ratio_resolve(width, children)
|
| 114 |
+
offset = 0
|
| 115 |
+
_Region = Region
|
| 116 |
+
for child, child_width in zip(children, render_widths):
|
| 117 |
+
yield child, _Region(x + offset, y, child_width, height)
|
| 118 |
+
offset += child_width
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class ColumnSplitter(Splitter):
|
| 122 |
+
"""Split a layout region in to columns."""
|
| 123 |
+
|
| 124 |
+
name = "column"
|
| 125 |
+
|
| 126 |
+
def get_tree_icon(self) -> str:
|
| 127 |
+
return "[layout.tree.column]⬍"
|
| 128 |
+
|
| 129 |
+
def divide(
|
| 130 |
+
self, children: Sequence["Layout"], region: Region
|
| 131 |
+
) -> Iterable[Tuple["Layout", Region]]:
|
| 132 |
+
x, y, width, height = region
|
| 133 |
+
render_heights = ratio_resolve(height, children)
|
| 134 |
+
offset = 0
|
| 135 |
+
_Region = Region
|
| 136 |
+
for child, child_height in zip(children, render_heights):
|
| 137 |
+
yield child, _Region(x, y + offset, width, child_height)
|
| 138 |
+
offset += child_height
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
@rich_repr
|
| 142 |
+
class Layout:
|
| 143 |
+
"""A renderable to divide a fixed height in to rows or columns.
|
| 144 |
+
|
| 145 |
+
Args:
|
| 146 |
+
renderable (RenderableType, optional): Renderable content, or None for placeholder. Defaults to None.
|
| 147 |
+
name (str, optional): Optional identifier for Layout. Defaults to None.
|
| 148 |
+
size (int, optional): Optional fixed size of layout. Defaults to None.
|
| 149 |
+
minimum_size (int, optional): Minimum size of layout. Defaults to 1.
|
| 150 |
+
ratio (int, optional): Optional ratio for flexible layout. Defaults to 1.
|
| 151 |
+
visible (bool, optional): Visibility of layout. Defaults to True.
|
| 152 |
+
"""
|
| 153 |
+
|
| 154 |
+
splitters = {"row": RowSplitter, "column": ColumnSplitter}
|
| 155 |
+
|
| 156 |
+
def __init__(
|
| 157 |
+
self,
|
| 158 |
+
renderable: Optional[RenderableType] = None,
|
| 159 |
+
*,
|
| 160 |
+
name: Optional[str] = None,
|
| 161 |
+
size: Optional[int] = None,
|
| 162 |
+
minimum_size: int = 1,
|
| 163 |
+
ratio: int = 1,
|
| 164 |
+
visible: bool = True,
|
| 165 |
+
) -> None:
|
| 166 |
+
self._renderable = renderable or _Placeholder(self)
|
| 167 |
+
self.size = size
|
| 168 |
+
self.minimum_size = minimum_size
|
| 169 |
+
self.ratio = ratio
|
| 170 |
+
self.name = name
|
| 171 |
+
self.visible = visible
|
| 172 |
+
self.splitter: Splitter = self.splitters["column"]()
|
| 173 |
+
self._children: List[Layout] = []
|
| 174 |
+
self._render_map: RenderMap = {}
|
| 175 |
+
self._lock = RLock()
|
| 176 |
+
|
| 177 |
+
def __rich_repr__(self) -> Result:
|
| 178 |
+
yield "name", self.name, None
|
| 179 |
+
yield "size", self.size, None
|
| 180 |
+
yield "minimum_size", self.minimum_size, 1
|
| 181 |
+
yield "ratio", self.ratio, 1
|
| 182 |
+
|
| 183 |
+
@property
|
| 184 |
+
def renderable(self) -> RenderableType:
|
| 185 |
+
"""Layout renderable."""
|
| 186 |
+
return self if self._children else self._renderable
|
| 187 |
+
|
| 188 |
+
@property
|
| 189 |
+
def children(self) -> List["Layout"]:
|
| 190 |
+
"""Gets (visible) layout children."""
|
| 191 |
+
return [child for child in self._children if child.visible]
|
| 192 |
+
|
| 193 |
+
@property
|
| 194 |
+
def map(self) -> RenderMap:
|
| 195 |
+
"""Get a map of the last render."""
|
| 196 |
+
return self._render_map
|
| 197 |
+
|
| 198 |
+
def get(self, name: str) -> Optional["Layout"]:
|
| 199 |
+
"""Get a named layout, or None if it doesn't exist.
|
| 200 |
+
|
| 201 |
+
Args:
|
| 202 |
+
name (str): Name of layout.
|
| 203 |
+
|
| 204 |
+
Returns:
|
| 205 |
+
Optional[Layout]: Layout instance or None if no layout was found.
|
| 206 |
+
"""
|
| 207 |
+
if self.name == name:
|
| 208 |
+
return self
|
| 209 |
+
else:
|
| 210 |
+
for child in self._children:
|
| 211 |
+
named_layout = child.get(name)
|
| 212 |
+
if named_layout is not None:
|
| 213 |
+
return named_layout
|
| 214 |
+
return None
|
| 215 |
+
|
| 216 |
+
def __getitem__(self, name: str) -> "Layout":
|
| 217 |
+
layout = self.get(name)
|
| 218 |
+
if layout is None:
|
| 219 |
+
raise KeyError(f"No layout with name {name!r}")
|
| 220 |
+
return layout
|
| 221 |
+
|
| 222 |
+
@property
|
| 223 |
+
def tree(self) -> "Tree":
|
| 224 |
+
"""Get a tree renderable to show layout structure."""
|
| 225 |
+
from rich.styled import Styled
|
| 226 |
+
from rich.table import Table
|
| 227 |
+
from rich.tree import Tree
|
| 228 |
+
|
| 229 |
+
def summary(layout: "Layout") -> Table:
|
| 230 |
+
icon = layout.splitter.get_tree_icon()
|
| 231 |
+
|
| 232 |
+
table = Table.grid(padding=(0, 1, 0, 0))
|
| 233 |
+
|
| 234 |
+
text: RenderableType = (
|
| 235 |
+
Pretty(layout) if layout.visible else Styled(Pretty(layout), "dim")
|
| 236 |
+
)
|
| 237 |
+
table.add_row(icon, text)
|
| 238 |
+
_summary = table
|
| 239 |
+
return _summary
|
| 240 |
+
|
| 241 |
+
layout = self
|
| 242 |
+
tree = Tree(
|
| 243 |
+
summary(layout),
|
| 244 |
+
guide_style=f"layout.tree.{layout.splitter.name}",
|
| 245 |
+
highlight=True,
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
def recurse(tree: "Tree", layout: "Layout") -> None:
|
| 249 |
+
for child in layout._children:
|
| 250 |
+
recurse(
|
| 251 |
+
tree.add(
|
| 252 |
+
summary(child),
|
| 253 |
+
guide_style=f"layout.tree.{child.splitter.name}",
|
| 254 |
+
),
|
| 255 |
+
child,
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
recurse(tree, self)
|
| 259 |
+
return tree
|
| 260 |
+
|
| 261 |
+
def split(
|
| 262 |
+
self,
|
| 263 |
+
*layouts: Union["Layout", RenderableType],
|
| 264 |
+
splitter: Union[Splitter, str] = "column",
|
| 265 |
+
) -> None:
|
| 266 |
+
"""Split the layout in to multiple sub-layouts.
|
| 267 |
+
|
| 268 |
+
Args:
|
| 269 |
+
*layouts (Layout): Positional arguments should be (sub) Layout instances.
|
| 270 |
+
splitter (Union[Splitter, str]): Splitter instance or name of splitter.
|
| 271 |
+
"""
|
| 272 |
+
_layouts = [
|
| 273 |
+
layout if isinstance(layout, Layout) else Layout(layout)
|
| 274 |
+
for layout in layouts
|
| 275 |
+
]
|
| 276 |
+
try:
|
| 277 |
+
self.splitter = (
|
| 278 |
+
splitter
|
| 279 |
+
if isinstance(splitter, Splitter)
|
| 280 |
+
else self.splitters[splitter]()
|
| 281 |
+
)
|
| 282 |
+
except KeyError:
|
| 283 |
+
raise NoSplitter(f"No splitter called {splitter!r}")
|
| 284 |
+
self._children[:] = _layouts
|
| 285 |
+
|
| 286 |
+
def add_split(self, *layouts: Union["Layout", RenderableType]) -> None:
|
| 287 |
+
"""Add a new layout(s) to existing split.
|
| 288 |
+
|
| 289 |
+
Args:
|
| 290 |
+
*layouts (Union[Layout, RenderableType]): Positional arguments should be renderables or (sub) Layout instances.
|
| 291 |
+
|
| 292 |
+
"""
|
| 293 |
+
_layouts = (
|
| 294 |
+
layout if isinstance(layout, Layout) else Layout(layout)
|
| 295 |
+
for layout in layouts
|
| 296 |
+
)
|
| 297 |
+
self._children.extend(_layouts)
|
| 298 |
+
|
| 299 |
+
def split_row(self, *layouts: Union["Layout", RenderableType]) -> None:
|
| 300 |
+
"""Split the layout in to a row (layouts side by side).
|
| 301 |
+
|
| 302 |
+
Args:
|
| 303 |
+
*layouts (Layout): Positional arguments should be (sub) Layout instances.
|
| 304 |
+
"""
|
| 305 |
+
self.split(*layouts, splitter="row")
|
| 306 |
+
|
| 307 |
+
def split_column(self, *layouts: Union["Layout", RenderableType]) -> None:
|
| 308 |
+
"""Split the layout in to a column (layouts stacked on top of each other).
|
| 309 |
+
|
| 310 |
+
Args:
|
| 311 |
+
*layouts (Layout): Positional arguments should be (sub) Layout instances.
|
| 312 |
+
"""
|
| 313 |
+
self.split(*layouts, splitter="column")
|
| 314 |
+
|
| 315 |
+
def unsplit(self) -> None:
|
| 316 |
+
"""Reset splits to initial state."""
|
| 317 |
+
del self._children[:]
|
| 318 |
+
|
| 319 |
+
def update(self, renderable: RenderableType) -> None:
|
| 320 |
+
"""Update renderable.
|
| 321 |
+
|
| 322 |
+
Args:
|
| 323 |
+
renderable (RenderableType): New renderable object.
|
| 324 |
+
"""
|
| 325 |
+
with self._lock:
|
| 326 |
+
self._renderable = renderable
|
| 327 |
+
|
| 328 |
+
def refresh_screen(self, console: "Console", layout_name: str) -> None:
|
| 329 |
+
"""Refresh a sub-layout.
|
| 330 |
+
|
| 331 |
+
Args:
|
| 332 |
+
console (Console): Console instance where Layout is to be rendered.
|
| 333 |
+
layout_name (str): Name of layout.
|
| 334 |
+
"""
|
| 335 |
+
with self._lock:
|
| 336 |
+
layout = self[layout_name]
|
| 337 |
+
region, _lines = self._render_map[layout]
|
| 338 |
+
(x, y, width, height) = region
|
| 339 |
+
lines = console.render_lines(
|
| 340 |
+
layout, console.options.update_dimensions(width, height)
|
| 341 |
+
)
|
| 342 |
+
self._render_map[layout] = LayoutRender(region, lines)
|
| 343 |
+
console.update_screen_lines(lines, x, y)
|
| 344 |
+
|
| 345 |
+
def _make_region_map(self, width: int, height: int) -> RegionMap:
|
| 346 |
+
"""Create a dict that maps layout on to Region."""
|
| 347 |
+
stack: List[Tuple[Layout, Region]] = [(self, Region(0, 0, width, height))]
|
| 348 |
+
push = stack.append
|
| 349 |
+
pop = stack.pop
|
| 350 |
+
layout_regions: List[Tuple[Layout, Region]] = []
|
| 351 |
+
append_layout_region = layout_regions.append
|
| 352 |
+
while stack:
|
| 353 |
+
append_layout_region(pop())
|
| 354 |
+
layout, region = layout_regions[-1]
|
| 355 |
+
children = layout.children
|
| 356 |
+
if children:
|
| 357 |
+
for child_and_region in layout.splitter.divide(children, region):
|
| 358 |
+
push(child_and_region)
|
| 359 |
+
|
| 360 |
+
region_map = {
|
| 361 |
+
layout: region
|
| 362 |
+
for layout, region in sorted(layout_regions, key=itemgetter(1))
|
| 363 |
+
}
|
| 364 |
+
return region_map
|
| 365 |
+
|
| 366 |
+
def render(self, console: Console, options: ConsoleOptions) -> RenderMap:
|
| 367 |
+
"""Render the sub_layouts.
|
| 368 |
+
|
| 369 |
+
Args:
|
| 370 |
+
console (Console): Console instance.
|
| 371 |
+
options (ConsoleOptions): Console options.
|
| 372 |
+
|
| 373 |
+
Returns:
|
| 374 |
+
RenderMap: A dict that maps Layout on to a tuple of Region, lines
|
| 375 |
+
"""
|
| 376 |
+
render_width = options.max_width
|
| 377 |
+
render_height = options.height or console.height
|
| 378 |
+
region_map = self._make_region_map(render_width, render_height)
|
| 379 |
+
layout_regions = [
|
| 380 |
+
(layout, region)
|
| 381 |
+
for layout, region in region_map.items()
|
| 382 |
+
if not layout.children
|
| 383 |
+
]
|
| 384 |
+
render_map: Dict["Layout", "LayoutRender"] = {}
|
| 385 |
+
render_lines = console.render_lines
|
| 386 |
+
update_dimensions = options.update_dimensions
|
| 387 |
+
|
| 388 |
+
for layout, region in layout_regions:
|
| 389 |
+
lines = render_lines(
|
| 390 |
+
layout.renderable, update_dimensions(region.width, region.height)
|
| 391 |
+
)
|
| 392 |
+
render_map[layout] = LayoutRender(region, lines)
|
| 393 |
+
return render_map
|
| 394 |
+
|
| 395 |
+
def __rich_console__(
|
| 396 |
+
self, console: Console, options: ConsoleOptions
|
| 397 |
+
) -> RenderResult:
|
| 398 |
+
with self._lock:
|
| 399 |
+
width = options.max_width or console.width
|
| 400 |
+
height = options.height or console.height
|
| 401 |
+
render_map = self.render(console, options.update_dimensions(width, height))
|
| 402 |
+
self._render_map = render_map
|
| 403 |
+
layout_lines: List[List[Segment]] = [[] for _ in range(height)]
|
| 404 |
+
_islice = islice
|
| 405 |
+
for region, lines in render_map.values():
|
| 406 |
+
_x, y, _layout_width, layout_height = region
|
| 407 |
+
for row, line in zip(
|
| 408 |
+
_islice(layout_lines, y, y + layout_height), lines
|
| 409 |
+
):
|
| 410 |
+
row.extend(line)
|
| 411 |
+
|
| 412 |
+
new_line = Segment.line()
|
| 413 |
+
for layout_row in layout_lines:
|
| 414 |
+
yield from layout_row
|
| 415 |
+
yield new_line
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
if __name__ == "__main__":
|
| 419 |
+
from rich.console import Console
|
| 420 |
+
|
| 421 |
+
console = Console()
|
| 422 |
+
layout = Layout()
|
| 423 |
+
|
| 424 |
+
layout.split_column(
|
| 425 |
+
Layout(name="header", size=3),
|
| 426 |
+
Layout(ratio=1, name="main"),
|
| 427 |
+
Layout(size=10, name="footer"),
|
| 428 |
+
)
|
| 429 |
+
|
| 430 |
+
layout["main"].split_row(Layout(name="side"), Layout(name="body", ratio=2))
|
| 431 |
+
|
| 432 |
+
layout["body"].split_row(Layout(name="content", ratio=2), Layout(name="s2"))
|
| 433 |
+
|
| 434 |
+
layout["s2"].split_column(
|
| 435 |
+
Layout(name="top"), Layout(name="middle"), Layout(name="bottom")
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
layout["side"].split_column(Layout(layout.tree, name="left1"), Layout(name="left2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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from threading import Event, RLock, Thread
|
| 3 |
+
from types import TracebackType
|
| 4 |
+
from typing import IO, Any, Callable, List, Optional, TextIO, Type, cast
|
| 5 |
+
|
| 6 |
+
from . import get_console
|
| 7 |
+
from .console import Console, ConsoleRenderable, RenderableType, RenderHook
|
| 8 |
+
from .control import Control
|
| 9 |
+
from .file_proxy import FileProxy
|
| 10 |
+
from .jupyter import JupyterMixin
|
| 11 |
+
from .live_render import LiveRender, VerticalOverflowMethod
|
| 12 |
+
from .screen import Screen
|
| 13 |
+
from .text import Text
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class _RefreshThread(Thread):
|
| 17 |
+
"""A thread that calls refresh() at regular intervals."""
|
| 18 |
+
|
| 19 |
+
def __init__(self, live: "Live", refresh_per_second: float) -> None:
|
| 20 |
+
self.live = live
|
| 21 |
+
self.refresh_per_second = refresh_per_second
|
| 22 |
+
self.done = Event()
|
| 23 |
+
super().__init__(daemon=True)
|
| 24 |
+
|
| 25 |
+
def stop(self) -> None:
|
| 26 |
+
self.done.set()
|
| 27 |
+
|
| 28 |
+
def run(self) -> None:
|
| 29 |
+
while not self.done.wait(1 / self.refresh_per_second):
|
| 30 |
+
with self.live._lock:
|
| 31 |
+
if not self.done.is_set():
|
| 32 |
+
self.live.refresh()
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class Live(JupyterMixin, RenderHook):
|
| 36 |
+
"""Renders an auto-updating live display of any given renderable.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
renderable (RenderableType, optional): The renderable to live display. Defaults to displaying nothing.
|
| 40 |
+
console (Console, optional): Optional Console instance. Defaults to an internal Console instance writing to stdout.
|
| 41 |
+
screen (bool, optional): Enable alternate screen mode. Defaults to False.
|
| 42 |
+
auto_refresh (bool, optional): Enable auto refresh. If disabled, you will need to call `refresh()` or `update()` with refresh flag. Defaults to True
|
| 43 |
+
refresh_per_second (float, optional): Number of times per second to refresh the live display. Defaults to 4.
|
| 44 |
+
transient (bool, optional): Clear the renderable on exit (has no effect when screen=True). Defaults to False.
|
| 45 |
+
redirect_stdout (bool, optional): Enable redirection of stdout, so ``print`` may be used. Defaults to True.
|
| 46 |
+
redirect_stderr (bool, optional): Enable redirection of stderr. Defaults to True.
|
| 47 |
+
vertical_overflow (VerticalOverflowMethod, optional): How to handle renderable when it is too tall for the console. Defaults to "ellipsis".
|
| 48 |
+
get_renderable (Callable[[], RenderableType], optional): Optional callable to get renderable. Defaults to None.
|
| 49 |
+
"""
|
| 50 |
+
|
| 51 |
+
def __init__(
|
| 52 |
+
self,
|
| 53 |
+
renderable: Optional[RenderableType] = None,
|
| 54 |
+
*,
|
| 55 |
+
console: Optional[Console] = None,
|
| 56 |
+
screen: bool = False,
|
| 57 |
+
auto_refresh: bool = True,
|
| 58 |
+
refresh_per_second: float = 4,
|
| 59 |
+
transient: bool = False,
|
| 60 |
+
redirect_stdout: bool = True,
|
| 61 |
+
redirect_stderr: bool = True,
|
| 62 |
+
vertical_overflow: VerticalOverflowMethod = "ellipsis",
|
| 63 |
+
get_renderable: Optional[Callable[[], RenderableType]] = None,
|
| 64 |
+
) -> None:
|
| 65 |
+
assert refresh_per_second > 0, "refresh_per_second must be > 0"
|
| 66 |
+
self._renderable = renderable
|
| 67 |
+
self.console = console if console is not None else get_console()
|
| 68 |
+
self._screen = screen
|
| 69 |
+
self._alt_screen = False
|
| 70 |
+
|
| 71 |
+
self._redirect_stdout = redirect_stdout
|
| 72 |
+
self._redirect_stderr = redirect_stderr
|
| 73 |
+
self._restore_stdout: Optional[IO[str]] = None
|
| 74 |
+
self._restore_stderr: Optional[IO[str]] = None
|
| 75 |
+
|
| 76 |
+
self._lock = RLock()
|
| 77 |
+
self.ipy_widget: Optional[Any] = None
|
| 78 |
+
self.auto_refresh = auto_refresh
|
| 79 |
+
self._started: bool = False
|
| 80 |
+
self.transient = True if screen else transient
|
| 81 |
+
|
| 82 |
+
self._refresh_thread: Optional[_RefreshThread] = None
|
| 83 |
+
self.refresh_per_second = refresh_per_second
|
| 84 |
+
|
| 85 |
+
self.vertical_overflow = vertical_overflow
|
| 86 |
+
self._get_renderable = get_renderable
|
| 87 |
+
self._live_render = LiveRender(
|
| 88 |
+
self.get_renderable(), vertical_overflow=vertical_overflow
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
@property
|
| 92 |
+
def is_started(self) -> bool:
|
| 93 |
+
"""Check if live display has been started."""
|
| 94 |
+
return self._started
|
| 95 |
+
|
| 96 |
+
def get_renderable(self) -> RenderableType:
|
| 97 |
+
renderable = (
|
| 98 |
+
self._get_renderable()
|
| 99 |
+
if self._get_renderable is not None
|
| 100 |
+
else self._renderable
|
| 101 |
+
)
|
| 102 |
+
return renderable or ""
|
| 103 |
+
|
| 104 |
+
def start(self, refresh: bool = False) -> None:
|
| 105 |
+
"""Start live rendering display.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
refresh (bool, optional): Also refresh. Defaults to False.
|
| 109 |
+
"""
|
| 110 |
+
with self._lock:
|
| 111 |
+
if self._started:
|
| 112 |
+
return
|
| 113 |
+
self.console.set_live(self)
|
| 114 |
+
self._started = True
|
| 115 |
+
if self._screen:
|
| 116 |
+
self._alt_screen = self.console.set_alt_screen(True)
|
| 117 |
+
self.console.show_cursor(False)
|
| 118 |
+
self._enable_redirect_io()
|
| 119 |
+
self.console.push_render_hook(self)
|
| 120 |
+
if refresh:
|
| 121 |
+
try:
|
| 122 |
+
self.refresh()
|
| 123 |
+
except Exception:
|
| 124 |
+
# If refresh fails, we want to stop the redirection of sys.stderr,
|
| 125 |
+
# so the error stacktrace is properly displayed in the terminal.
|
| 126 |
+
# (or, if the code that calls Rich captures the exception and wants to display something,
|
| 127 |
+
# let this be displayed in the terminal).
|
| 128 |
+
self.stop()
|
| 129 |
+
raise
|
| 130 |
+
if self.auto_refresh:
|
| 131 |
+
self._refresh_thread = _RefreshThread(self, self.refresh_per_second)
|
| 132 |
+
self._refresh_thread.start()
|
| 133 |
+
|
| 134 |
+
def stop(self) -> None:
|
| 135 |
+
"""Stop live rendering display."""
|
| 136 |
+
with self._lock:
|
| 137 |
+
if not self._started:
|
| 138 |
+
return
|
| 139 |
+
self.console.clear_live()
|
| 140 |
+
self._started = False
|
| 141 |
+
|
| 142 |
+
if self.auto_refresh and self._refresh_thread is not None:
|
| 143 |
+
self._refresh_thread.stop()
|
| 144 |
+
self._refresh_thread = None
|
| 145 |
+
# allow it to fully render on the last even if overflow
|
| 146 |
+
self.vertical_overflow = "visible"
|
| 147 |
+
with self.console:
|
| 148 |
+
try:
|
| 149 |
+
if not self._alt_screen and not self.console.is_jupyter:
|
| 150 |
+
self.refresh()
|
| 151 |
+
finally:
|
| 152 |
+
self._disable_redirect_io()
|
| 153 |
+
self.console.pop_render_hook()
|
| 154 |
+
if not self._alt_screen and self.console.is_terminal:
|
| 155 |
+
self.console.line()
|
| 156 |
+
self.console.show_cursor(True)
|
| 157 |
+
if self._alt_screen:
|
| 158 |
+
self.console.set_alt_screen(False)
|
| 159 |
+
|
| 160 |
+
if self.transient and not self._alt_screen:
|
| 161 |
+
self.console.control(self._live_render.restore_cursor())
|
| 162 |
+
if self.ipy_widget is not None and self.transient:
|
| 163 |
+
self.ipy_widget.close() # pragma: no cover
|
| 164 |
+
|
| 165 |
+
def __enter__(self) -> "Live":
|
| 166 |
+
self.start(refresh=self._renderable is not None)
|
| 167 |
+
return self
|
| 168 |
+
|
| 169 |
+
def __exit__(
|
| 170 |
+
self,
|
| 171 |
+
exc_type: Optional[Type[BaseException]],
|
| 172 |
+
exc_val: Optional[BaseException],
|
| 173 |
+
exc_tb: Optional[TracebackType],
|
| 174 |
+
) -> None:
|
| 175 |
+
self.stop()
|
| 176 |
+
|
| 177 |
+
def _enable_redirect_io(self) -> None:
|
| 178 |
+
"""Enable redirecting of stdout / stderr."""
|
| 179 |
+
if self.console.is_terminal or self.console.is_jupyter:
|
| 180 |
+
if self._redirect_stdout and not isinstance(sys.stdout, FileProxy):
|
| 181 |
+
self._restore_stdout = sys.stdout
|
| 182 |
+
sys.stdout = cast("TextIO", FileProxy(self.console, sys.stdout))
|
| 183 |
+
if self._redirect_stderr and not isinstance(sys.stderr, FileProxy):
|
| 184 |
+
self._restore_stderr = sys.stderr
|
| 185 |
+
sys.stderr = cast("TextIO", FileProxy(self.console, sys.stderr))
|
| 186 |
+
|
| 187 |
+
def _disable_redirect_io(self) -> None:
|
| 188 |
+
"""Disable redirecting of stdout / stderr."""
|
| 189 |
+
if self._restore_stdout:
|
| 190 |
+
sys.stdout = cast("TextIO", self._restore_stdout)
|
| 191 |
+
self._restore_stdout = None
|
| 192 |
+
if self._restore_stderr:
|
| 193 |
+
sys.stderr = cast("TextIO", self._restore_stderr)
|
| 194 |
+
self._restore_stderr = None
|
| 195 |
+
|
| 196 |
+
@property
|
| 197 |
+
def renderable(self) -> RenderableType:
|
| 198 |
+
"""Get the renderable that is being displayed
|
| 199 |
+
|
| 200 |
+
Returns:
|
| 201 |
+
RenderableType: Displayed renderable.
|
| 202 |
+
"""
|
| 203 |
+
renderable = self.get_renderable()
|
| 204 |
+
return Screen(renderable) if self._alt_screen else renderable
|
| 205 |
+
|
| 206 |
+
def update(self, renderable: RenderableType, *, refresh: bool = False) -> None:
|
| 207 |
+
"""Update the renderable that is being displayed
|
| 208 |
+
|
| 209 |
+
Args:
|
| 210 |
+
renderable (RenderableType): New renderable to use.
|
| 211 |
+
refresh (bool, optional): Refresh the display. Defaults to False.
|
| 212 |
+
"""
|
| 213 |
+
if isinstance(renderable, str):
|
| 214 |
+
renderable = self.console.render_str(renderable)
|
| 215 |
+
with self._lock:
|
| 216 |
+
self._renderable = renderable
|
| 217 |
+
if refresh:
|
| 218 |
+
self.refresh()
|
| 219 |
+
|
| 220 |
+
def refresh(self) -> None:
|
| 221 |
+
"""Update the display of the Live Render."""
|
| 222 |
+
with self._lock:
|
| 223 |
+
self._live_render.set_renderable(self.renderable)
|
| 224 |
+
if self.console.is_jupyter: # pragma: no cover
|
| 225 |
+
try:
|
| 226 |
+
from IPython.display import display
|
| 227 |
+
from ipywidgets import Output
|
| 228 |
+
except ImportError:
|
| 229 |
+
import warnings
|
| 230 |
+
|
| 231 |
+
warnings.warn('install "ipywidgets" for Jupyter support')
|
| 232 |
+
else:
|
| 233 |
+
if self.ipy_widget is None:
|
| 234 |
+
self.ipy_widget = Output()
|
| 235 |
+
display(self.ipy_widget)
|
| 236 |
+
|
| 237 |
+
with self.ipy_widget:
|
| 238 |
+
self.ipy_widget.clear_output(wait=True)
|
| 239 |
+
self.console.print(self._live_render.renderable)
|
| 240 |
+
elif self.console.is_terminal and not self.console.is_dumb_terminal:
|
| 241 |
+
with self.console:
|
| 242 |
+
self.console.print(Control())
|
| 243 |
+
elif (
|
| 244 |
+
not self._started and not self.transient
|
| 245 |
+
): # if it is finished allow files or dumb-terminals to see final result
|
| 246 |
+
with self.console:
|
| 247 |
+
self.console.print(Control())
|
| 248 |
+
|
| 249 |
+
def process_renderables(
|
| 250 |
+
self, renderables: List[ConsoleRenderable]
|
| 251 |
+
) -> List[ConsoleRenderable]:
|
| 252 |
+
"""Process renderables to restore cursor and display progress."""
|
| 253 |
+
self._live_render.vertical_overflow = self.vertical_overflow
|
| 254 |
+
if self.console.is_interactive:
|
| 255 |
+
# lock needs acquiring as user can modify live_render renderable at any time unlike in Progress.
|
| 256 |
+
with self._lock:
|
| 257 |
+
reset = (
|
| 258 |
+
Control.home()
|
| 259 |
+
if self._alt_screen
|
| 260 |
+
else self._live_render.position_cursor()
|
| 261 |
+
)
|
| 262 |
+
renderables = [reset, *renderables, self._live_render]
|
| 263 |
+
elif (
|
| 264 |
+
not self._started and not self.transient
|
| 265 |
+
): # if it is finished render the final output for files or dumb_terminals
|
| 266 |
+
renderables = [*renderables, self._live_render]
|
| 267 |
+
|
| 268 |
+
return renderables
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
if __name__ == "__main__": # pragma: no cover
|
| 272 |
+
import random
|
| 273 |
+
import time
|
| 274 |
+
from itertools import cycle
|
| 275 |
+
from typing import Dict, List, Tuple
|
| 276 |
+
|
| 277 |
+
from .align import Align
|
| 278 |
+
from .console import Console
|
| 279 |
+
from .live import Live as Live
|
| 280 |
+
from .panel import Panel
|
| 281 |
+
from .rule import Rule
|
| 282 |
+
from .syntax import Syntax
|
| 283 |
+
from .table import Table
|
| 284 |
+
|
| 285 |
+
console = Console()
|
| 286 |
+
|
| 287 |
+
syntax = Syntax(
|
| 288 |
+
'''def loop_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
|
| 289 |
+
"""Iterate and generate a tuple with a flag for last value."""
|
| 290 |
+
iter_values = iter(values)
|
| 291 |
+
try:
|
| 292 |
+
previous_value = next(iter_values)
|
| 293 |
+
except StopIteration:
|
| 294 |
+
return
|
| 295 |
+
for value in iter_values:
|
| 296 |
+
yield False, previous_value
|
| 297 |
+
previous_value = value
|
| 298 |
+
yield True, previous_value''',
|
| 299 |
+
"python",
|
| 300 |
+
line_numbers=True,
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
table = Table("foo", "bar", "baz")
|
| 304 |
+
table.add_row("1", "2", "3")
|
| 305 |
+
|
| 306 |
+
progress_renderables = [
|
| 307 |
+
"You can make the terminal shorter and taller to see the live table hide"
|
| 308 |
+
"Text may be printed while the progress bars are rendering.",
|
| 309 |
+
Panel("In fact, [i]any[/i] renderable will work"),
|
| 310 |
+
"Such as [magenta]tables[/]...",
|
| 311 |
+
table,
|
| 312 |
+
"Pretty printed structures...",
|
| 313 |
+
{"type": "example", "text": "Pretty printed"},
|
| 314 |
+
"Syntax...",
|
| 315 |
+
syntax,
|
| 316 |
+
Rule("Give it a try!"),
|
| 317 |
+
]
|
| 318 |
+
|
| 319 |
+
examples = cycle(progress_renderables)
|
| 320 |
+
|
| 321 |
+
exchanges = [
|
| 322 |
+
"SGD",
|
| 323 |
+
"MYR",
|
| 324 |
+
"EUR",
|
| 325 |
+
"USD",
|
| 326 |
+
"AUD",
|
| 327 |
+
"JPY",
|
| 328 |
+
"CNH",
|
| 329 |
+
"HKD",
|
| 330 |
+
"CAD",
|
| 331 |
+
"INR",
|
| 332 |
+
"DKK",
|
| 333 |
+
"GBP",
|
| 334 |
+
"RUB",
|
| 335 |
+
"NZD",
|
| 336 |
+
"MXN",
|
| 337 |
+
"IDR",
|
| 338 |
+
"TWD",
|
| 339 |
+
"THB",
|
| 340 |
+
"VND",
|
| 341 |
+
]
|
| 342 |
+
with Live(console=console) as live_table:
|
| 343 |
+
exchange_rate_dict: Dict[Tuple[str, str], float] = {}
|
| 344 |
+
|
| 345 |
+
for index in range(100):
|
| 346 |
+
select_exchange = exchanges[index % len(exchanges)]
|
| 347 |
+
|
| 348 |
+
for exchange in exchanges:
|
| 349 |
+
if exchange == select_exchange:
|
| 350 |
+
continue
|
| 351 |
+
time.sleep(0.4)
|
| 352 |
+
if random.randint(0, 10) < 1:
|
| 353 |
+
console.log(next(examples))
|
| 354 |
+
exchange_rate_dict[(select_exchange, exchange)] = 200 / (
|
| 355 |
+
(random.random() * 320) + 1
|
| 356 |
+
)
|
| 357 |
+
if len(exchange_rate_dict) > len(exchanges) - 1:
|
| 358 |
+
exchange_rate_dict.pop(list(exchange_rate_dict.keys())[0])
|
| 359 |
+
table = Table(title="Exchange Rates")
|
| 360 |
+
|
| 361 |
+
table.add_column("Source Currency")
|
| 362 |
+
table.add_column("Destination Currency")
|
| 363 |
+
table.add_column("Exchange Rate")
|
| 364 |
+
|
| 365 |
+
for (source, dest), exchange_rate in exchange_rate_dict.items():
|
| 366 |
+
table.add_row(
|
| 367 |
+
source,
|
| 368 |
+
dest,
|
| 369 |
+
Text(
|
| 370 |
+
f"{exchange_rate:.4f}",
|
| 371 |
+
style="red" if exchange_rate < 1.0 else "green",
|
| 372 |
+
),
|
| 373 |
+
)
|
| 374 |
+
|
| 375 |
+
live_table.update(Align.center(table))
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/live_render.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from typing import Optional, Tuple
|
| 3 |
+
|
| 4 |
+
if sys.version_info >= (3, 8):
|
| 5 |
+
from typing import Literal
|
| 6 |
+
else:
|
| 7 |
+
from typing_extensions import Literal # pragma: no cover
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
from ._loop import loop_last
|
| 11 |
+
from .console import Console, ConsoleOptions, RenderableType, RenderResult
|
| 12 |
+
from .control import Control
|
| 13 |
+
from .segment import ControlType, Segment
|
| 14 |
+
from .style import StyleType
|
| 15 |
+
from .text import Text
|
| 16 |
+
|
| 17 |
+
VerticalOverflowMethod = Literal["crop", "ellipsis", "visible"]
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class LiveRender:
|
| 21 |
+
"""Creates a renderable that may be updated.
|
| 22 |
+
|
| 23 |
+
Args:
|
| 24 |
+
renderable (RenderableType): Any renderable object.
|
| 25 |
+
style (StyleType, optional): An optional style to apply to the renderable. Defaults to "".
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def __init__(
|
| 29 |
+
self,
|
| 30 |
+
renderable: RenderableType,
|
| 31 |
+
style: StyleType = "",
|
| 32 |
+
vertical_overflow: VerticalOverflowMethod = "ellipsis",
|
| 33 |
+
) -> None:
|
| 34 |
+
self.renderable = renderable
|
| 35 |
+
self.style = style
|
| 36 |
+
self.vertical_overflow = vertical_overflow
|
| 37 |
+
self._shape: Optional[Tuple[int, int]] = None
|
| 38 |
+
|
| 39 |
+
def set_renderable(self, renderable: RenderableType) -> None:
|
| 40 |
+
"""Set a new renderable.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
renderable (RenderableType): Any renderable object, including str.
|
| 44 |
+
"""
|
| 45 |
+
self.renderable = renderable
|
| 46 |
+
|
| 47 |
+
def position_cursor(self) -> Control:
|
| 48 |
+
"""Get control codes to move cursor to beginning of live render.
|
| 49 |
+
|
| 50 |
+
Returns:
|
| 51 |
+
Control: A control instance that may be printed.
|
| 52 |
+
"""
|
| 53 |
+
if self._shape is not None:
|
| 54 |
+
_, height = self._shape
|
| 55 |
+
return Control(
|
| 56 |
+
ControlType.CARRIAGE_RETURN,
|
| 57 |
+
(ControlType.ERASE_IN_LINE, 2),
|
| 58 |
+
*(
|
| 59 |
+
(
|
| 60 |
+
(ControlType.CURSOR_UP, 1),
|
| 61 |
+
(ControlType.ERASE_IN_LINE, 2),
|
| 62 |
+
)
|
| 63 |
+
* (height - 1)
|
| 64 |
+
)
|
| 65 |
+
)
|
| 66 |
+
return Control()
|
| 67 |
+
|
| 68 |
+
def restore_cursor(self) -> Control:
|
| 69 |
+
"""Get control codes to clear the render and restore the cursor to its previous position.
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
Control: A Control instance that may be printed.
|
| 73 |
+
"""
|
| 74 |
+
if self._shape is not None:
|
| 75 |
+
_, height = self._shape
|
| 76 |
+
return Control(
|
| 77 |
+
ControlType.CARRIAGE_RETURN,
|
| 78 |
+
*((ControlType.CURSOR_UP, 1), (ControlType.ERASE_IN_LINE, 2)) * height
|
| 79 |
+
)
|
| 80 |
+
return Control()
|
| 81 |
+
|
| 82 |
+
def __rich_console__(
|
| 83 |
+
self, console: Console, options: ConsoleOptions
|
| 84 |
+
) -> RenderResult:
|
| 85 |
+
renderable = self.renderable
|
| 86 |
+
style = console.get_style(self.style)
|
| 87 |
+
lines = console.render_lines(renderable, options, style=style, pad=False)
|
| 88 |
+
shape = Segment.get_shape(lines)
|
| 89 |
+
|
| 90 |
+
_, height = shape
|
| 91 |
+
if height > options.size.height:
|
| 92 |
+
if self.vertical_overflow == "crop":
|
| 93 |
+
lines = lines[: options.size.height]
|
| 94 |
+
shape = Segment.get_shape(lines)
|
| 95 |
+
elif self.vertical_overflow == "ellipsis":
|
| 96 |
+
lines = lines[: (options.size.height - 1)]
|
| 97 |
+
overflow_text = Text(
|
| 98 |
+
"...",
|
| 99 |
+
overflow="crop",
|
| 100 |
+
justify="center",
|
| 101 |
+
end="",
|
| 102 |
+
style="live.ellipsis",
|
| 103 |
+
)
|
| 104 |
+
lines.append(list(console.render(overflow_text)))
|
| 105 |
+
shape = Segment.get_shape(lines)
|
| 106 |
+
self._shape = shape
|
| 107 |
+
|
| 108 |
+
new_line = Segment.line()
|
| 109 |
+
for last, line in loop_last(lines):
|
| 110 |
+
yield from line
|
| 111 |
+
if not last:
|
| 112 |
+
yield new_line
|
Prism/LLaDA/LLaDA_Prism/.venv/lib/python3.12/site-packages/rich/logging.py
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 1 |
+
import logging
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
from logging import Handler, LogRecord
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
from typing import ClassVar, Iterable, List, Optional, Type, Union
|
| 7 |
+
|
| 8 |
+
from rich._null_file import NullFile
|
| 9 |
+
|
| 10 |
+
from . import get_console
|
| 11 |
+
from ._log_render import FormatTimeCallable, LogRender
|
| 12 |
+
from .console import Console, ConsoleRenderable
|
| 13 |
+
from .highlighter import Highlighter, ReprHighlighter
|
| 14 |
+
from .text import Text
|
| 15 |
+
from .traceback import Traceback
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class RichHandler(Handler):
|
| 19 |
+
"""A logging handler that renders output with Rich. The time / level / message and file are displayed in columns.
|
| 20 |
+
The level is color coded, and the message is syntax highlighted.
|
| 21 |
+
|
| 22 |
+
Note:
|
| 23 |
+
Be careful when enabling console markup in log messages if you have configured logging for libraries not
|
| 24 |
+
under your control. If a dependency writes messages containing square brackets, it may not produce the intended output.
|
| 25 |
+
|
| 26 |
+
Args:
|
| 27 |
+
level (Union[int, str], optional): Log level. Defaults to logging.NOTSET.
|
| 28 |
+
console (:class:`~rich.console.Console`, optional): Optional console instance to write logs.
|
| 29 |
+
Default will use a global console instance writing to stdout.
|
| 30 |
+
show_time (bool, optional): Show a column for the time. Defaults to True.
|
| 31 |
+
omit_repeated_times (bool, optional): Omit repetition of the same time. Defaults to True.
|
| 32 |
+
show_level (bool, optional): Show a column for the level. Defaults to True.
|
| 33 |
+
show_path (bool, optional): Show the path to the original log call. Defaults to True.
|
| 34 |
+
enable_link_path (bool, optional): Enable terminal link of path column to file. Defaults to True.
|
| 35 |
+
highlighter (Highlighter, optional): Highlighter to style log messages, or None to use ReprHighlighter. Defaults to None.
|
| 36 |
+
markup (bool, optional): Enable console markup in log messages. Defaults to False.
|
| 37 |
+
rich_tracebacks (bool, optional): Enable rich tracebacks with syntax highlighting and formatting. Defaults to False.
|
| 38 |
+
tracebacks_width (Optional[int], optional): Number of characters used to render tracebacks, or None for full width. Defaults to None.
|
| 39 |
+
tracebacks_code_width (int, optional): Number of code characters used to render tracebacks, or None for full width. Defaults to 88.
|
| 40 |
+
tracebacks_extra_lines (int, optional): Additional lines of code to render tracebacks, or None for full width. Defaults to None.
|
| 41 |
+
tracebacks_theme (str, optional): Override pygments theme used in traceback.
|
| 42 |
+
tracebacks_word_wrap (bool, optional): Enable word wrapping of long tracebacks lines. Defaults to True.
|
| 43 |
+
tracebacks_show_locals (bool, optional): Enable display of locals in tracebacks. Defaults to False.
|
| 44 |
+
tracebacks_suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
|
| 45 |
+
tracebacks_max_frames (int, optional): Optional maximum number of frames returned by traceback.
|
| 46 |
+
locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
|
| 47 |
+
Defaults to 10.
|
| 48 |
+
locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
|
| 49 |
+
log_time_format (Union[str, TimeFormatterCallable], optional): If ``log_time`` is enabled, either string for strftime or callable that formats the time. Defaults to "[%x %X] ".
|
| 50 |
+
keywords (List[str], optional): List of words to highlight instead of ``RichHandler.KEYWORDS``.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
KEYWORDS: ClassVar[Optional[List[str]]] = [
|
| 54 |
+
"GET",
|
| 55 |
+
"POST",
|
| 56 |
+
"HEAD",
|
| 57 |
+
"PUT",
|
| 58 |
+
"DELETE",
|
| 59 |
+
"OPTIONS",
|
| 60 |
+
"TRACE",
|
| 61 |
+
"PATCH",
|
| 62 |
+
]
|
| 63 |
+
HIGHLIGHTER_CLASS: ClassVar[Type[Highlighter]] = ReprHighlighter
|
| 64 |
+
|
| 65 |
+
def __init__(
|
| 66 |
+
self,
|
| 67 |
+
level: Union[int, str] = logging.NOTSET,
|
| 68 |
+
console: Optional[Console] = None,
|
| 69 |
+
*,
|
| 70 |
+
show_time: bool = True,
|
| 71 |
+
omit_repeated_times: bool = True,
|
| 72 |
+
show_level: bool = True,
|
| 73 |
+
show_path: bool = True,
|
| 74 |
+
enable_link_path: bool = True,
|
| 75 |
+
highlighter: Optional[Highlighter] = None,
|
| 76 |
+
markup: bool = False,
|
| 77 |
+
rich_tracebacks: bool = False,
|
| 78 |
+
tracebacks_width: Optional[int] = None,
|
| 79 |
+
tracebacks_code_width: int = 88,
|
| 80 |
+
tracebacks_extra_lines: int = 3,
|
| 81 |
+
tracebacks_theme: Optional[str] = None,
|
| 82 |
+
tracebacks_word_wrap: bool = True,
|
| 83 |
+
tracebacks_show_locals: bool = False,
|
| 84 |
+
tracebacks_suppress: Iterable[Union[str, ModuleType]] = (),
|
| 85 |
+
tracebacks_max_frames: int = 100,
|
| 86 |
+
locals_max_length: int = 10,
|
| 87 |
+
locals_max_string: int = 80,
|
| 88 |
+
log_time_format: Union[str, FormatTimeCallable] = "[%x %X]",
|
| 89 |
+
keywords: Optional[List[str]] = None,
|
| 90 |
+
) -> None:
|
| 91 |
+
super().__init__(level=level)
|
| 92 |
+
self.console = console or get_console()
|
| 93 |
+
self.highlighter = highlighter or self.HIGHLIGHTER_CLASS()
|
| 94 |
+
self._log_render = LogRender(
|
| 95 |
+
show_time=show_time,
|
| 96 |
+
show_level=show_level,
|
| 97 |
+
show_path=show_path,
|
| 98 |
+
time_format=log_time_format,
|
| 99 |
+
omit_repeated_times=omit_repeated_times,
|
| 100 |
+
level_width=None,
|
| 101 |
+
)
|
| 102 |
+
self.enable_link_path = enable_link_path
|
| 103 |
+
self.markup = markup
|
| 104 |
+
self.rich_tracebacks = rich_tracebacks
|
| 105 |
+
self.tracebacks_width = tracebacks_width
|
| 106 |
+
self.tracebacks_extra_lines = tracebacks_extra_lines
|
| 107 |
+
self.tracebacks_theme = tracebacks_theme
|
| 108 |
+
self.tracebacks_word_wrap = tracebacks_word_wrap
|
| 109 |
+
self.tracebacks_show_locals = tracebacks_show_locals
|
| 110 |
+
self.tracebacks_suppress = tracebacks_suppress
|
| 111 |
+
self.tracebacks_max_frames = tracebacks_max_frames
|
| 112 |
+
self.tracebacks_code_width = tracebacks_code_width
|
| 113 |
+
self.locals_max_length = locals_max_length
|
| 114 |
+
self.locals_max_string = locals_max_string
|
| 115 |
+
self.keywords = keywords
|
| 116 |
+
|
| 117 |
+
def get_level_text(self, record: LogRecord) -> Text:
|
| 118 |
+
"""Get the level name from the record.
|
| 119 |
+
|
| 120 |
+
Args:
|
| 121 |
+
record (LogRecord): LogRecord instance.
|
| 122 |
+
|
| 123 |
+
Returns:
|
| 124 |
+
Text: A tuple of the style and level name.
|
| 125 |
+
"""
|
| 126 |
+
level_name = record.levelname
|
| 127 |
+
level_text = Text.styled(
|
| 128 |
+
level_name.ljust(8), f"logging.level.{level_name.lower()}"
|
| 129 |
+
)
|
| 130 |
+
return level_text
|
| 131 |
+
|
| 132 |
+
def emit(self, record: LogRecord) -> None:
|
| 133 |
+
"""Invoked by logging."""
|
| 134 |
+
message = self.format(record)
|
| 135 |
+
traceback = None
|
| 136 |
+
if (
|
| 137 |
+
self.rich_tracebacks
|
| 138 |
+
and record.exc_info
|
| 139 |
+
and record.exc_info != (None, None, None)
|
| 140 |
+
):
|
| 141 |
+
exc_type, exc_value, exc_traceback = record.exc_info
|
| 142 |
+
assert exc_type is not None
|
| 143 |
+
assert exc_value is not None
|
| 144 |
+
traceback = Traceback.from_exception(
|
| 145 |
+
exc_type,
|
| 146 |
+
exc_value,
|
| 147 |
+
exc_traceback,
|
| 148 |
+
width=self.tracebacks_width,
|
| 149 |
+
code_width=self.tracebacks_code_width,
|
| 150 |
+
extra_lines=self.tracebacks_extra_lines,
|
| 151 |
+
theme=self.tracebacks_theme,
|
| 152 |
+
word_wrap=self.tracebacks_word_wrap,
|
| 153 |
+
show_locals=self.tracebacks_show_locals,
|
| 154 |
+
locals_max_length=self.locals_max_length,
|
| 155 |
+
locals_max_string=self.locals_max_string,
|
| 156 |
+
suppress=self.tracebacks_suppress,
|
| 157 |
+
max_frames=self.tracebacks_max_frames,
|
| 158 |
+
)
|
| 159 |
+
message = record.getMessage()
|
| 160 |
+
if self.formatter:
|
| 161 |
+
record.message = record.getMessage()
|
| 162 |
+
formatter = self.formatter
|
| 163 |
+
if hasattr(formatter, "usesTime") and formatter.usesTime():
|
| 164 |
+
record.asctime = formatter.formatTime(record, formatter.datefmt)
|
| 165 |
+
message = formatter.formatMessage(record)
|
| 166 |
+
|
| 167 |
+
message_renderable = self.render_message(record, message)
|
| 168 |
+
log_renderable = self.render(
|
| 169 |
+
record=record, traceback=traceback, message_renderable=message_renderable
|
| 170 |
+
)
|
| 171 |
+
if isinstance(self.console.file, NullFile):
|
| 172 |
+
# Handles pythonw, where stdout/stderr are null, and we return NullFile
|
| 173 |
+
# instance from Console.file. In this case, we still want to make a log record
|
| 174 |
+
# even though we won't be writing anything to a file.
|
| 175 |
+
self.handleError(record)
|
| 176 |
+
else:
|
| 177 |
+
try:
|
| 178 |
+
self.console.print(log_renderable)
|
| 179 |
+
except Exception:
|
| 180 |
+
self.handleError(record)
|
| 181 |
+
|
| 182 |
+
def render_message(self, record: LogRecord, message: str) -> "ConsoleRenderable":
|
| 183 |
+
"""Render message text in to Text.
|
| 184 |
+
|
| 185 |
+
Args:
|
| 186 |
+
record (LogRecord): logging Record.
|
| 187 |
+
message (str): String containing log message.
|
| 188 |
+
|
| 189 |
+
Returns:
|
| 190 |
+
ConsoleRenderable: Renderable to display log message.
|
| 191 |
+
"""
|
| 192 |
+
use_markup = getattr(record, "markup", self.markup)
|
| 193 |
+
message_text = Text.from_markup(message) if use_markup else Text(message)
|
| 194 |
+
|
| 195 |
+
highlighter = getattr(record, "highlighter", self.highlighter)
|
| 196 |
+
if highlighter:
|
| 197 |
+
message_text = highlighter(message_text)
|
| 198 |
+
|
| 199 |
+
if self.keywords is None:
|
| 200 |
+
self.keywords = self.KEYWORDS
|
| 201 |
+
|
| 202 |
+
if self.keywords:
|
| 203 |
+
message_text.highlight_words(self.keywords, "logging.keyword")
|
| 204 |
+
|
| 205 |
+
return message_text
|
| 206 |
+
|
| 207 |
+
def render(
|
| 208 |
+
self,
|
| 209 |
+
*,
|
| 210 |
+
record: LogRecord,
|
| 211 |
+
traceback: Optional[Traceback],
|
| 212 |
+
message_renderable: "ConsoleRenderable",
|
| 213 |
+
) -> "ConsoleRenderable":
|
| 214 |
+
"""Render log for display.
|
| 215 |
+
|
| 216 |
+
Args:
|
| 217 |
+
record (LogRecord): logging Record.
|
| 218 |
+
traceback (Optional[Traceback]): Traceback instance or None for no Traceback.
|
| 219 |
+
message_renderable (ConsoleRenderable): Renderable (typically Text) containing log message contents.
|
| 220 |
+
|
| 221 |
+
Returns:
|
| 222 |
+
ConsoleRenderable: Renderable to display log.
|
| 223 |
+
"""
|
| 224 |
+
path = Path(record.pathname).name
|
| 225 |
+
level = self.get_level_text(record)
|
| 226 |
+
time_format = None if self.formatter is None else self.formatter.datefmt
|
| 227 |
+
log_time = datetime.fromtimestamp(record.created)
|
| 228 |
+
|
| 229 |
+
log_renderable = self._log_render(
|
| 230 |
+
self.console,
|
| 231 |
+
[message_renderable] if not traceback else [message_renderable, traceback],
|
| 232 |
+
log_time=log_time,
|
| 233 |
+
time_format=time_format,
|
| 234 |
+
level=level,
|
| 235 |
+
path=path,
|
| 236 |
+
line_no=record.lineno,
|
| 237 |
+
link_path=record.pathname if self.enable_link_path else None,
|
| 238 |
+
)
|
| 239 |
+
return log_renderable
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
if __name__ == "__main__": # pragma: no cover
|
| 243 |
+
from time import sleep
|
| 244 |
+
|
| 245 |
+
FORMAT = "%(message)s"
|
| 246 |
+
# FORMAT = "%(asctime)-15s - %(levelname)s - %(message)s"
|
| 247 |
+
logging.basicConfig(
|
| 248 |
+
level="NOTSET",
|
| 249 |
+
format=FORMAT,
|
| 250 |
+
datefmt="[%X]",
|
| 251 |
+
handlers=[RichHandler(rich_tracebacks=True, tracebacks_show_locals=True)],
|
| 252 |
+
)
|
| 253 |
+
log = logging.getLogger("rich")
|
| 254 |
+
|
| 255 |
+
log.info("Server starting...")
|
| 256 |
+
log.info("Listening on http://127.0.0.1:8080")
|
| 257 |
+
sleep(1)
|
| 258 |
+
|
| 259 |
+
log.info("GET /index.html 200 1298")
|
| 260 |
+
log.info("GET /imgs/backgrounds/back1.jpg 200 54386")
|
| 261 |
+
log.info("GET /css/styles.css 200 54386")
|
| 262 |
+
log.warning("GET /favicon.ico 404 242")
|
| 263 |
+
sleep(1)
|
| 264 |
+
|
| 265 |
+
log.debug(
|
| 266 |
+
"JSONRPC request\n--> %r\n<-- %r",
|
| 267 |
+
{
|
| 268 |
+
"version": "1.1",
|
| 269 |
+
"method": "confirmFruitPurchase",
|
| 270 |
+
"params": [["apple", "orange", "mangoes", "pomelo"], 1.123],
|
| 271 |
+
"id": "194521489",
|
| 272 |
+
},
|
| 273 |
+
{"version": "1.1", "result": True, "error": None, "id": "194521489"},
|
| 274 |
+
)
|
| 275 |
+
log.debug(
|
| 276 |
+
"Loading configuration file /adasd/asdasd/qeqwe/qwrqwrqwr/sdgsdgsdg/werwerwer/dfgerert/ertertert/ertetert/werwerwer"
|
| 277 |
+
)
|
| 278 |
+
log.error("Unable to find 'pomelo' in database!")
|
| 279 |
+
log.info("POST /jsonrpc/ 200 65532")
|
| 280 |
+
log.info("POST /admin/ 401 42234")
|
| 281 |
+
log.warning("password was rejected for admin site.")
|
| 282 |
+
|
| 283 |
+
def divide() -> None:
|
| 284 |
+
number = 1
|
| 285 |
+
divisor = 0
|
| 286 |
+
foos = ["foo"] * 100
|
| 287 |
+
log.debug("in divide")
|
| 288 |
+
try:
|
| 289 |
+
number / divisor
|
| 290 |
+
except:
|
| 291 |
+
log.exception("An error of some kind occurred!")
|
| 292 |
+
|
| 293 |
+
divide()
|
| 294 |
+
sleep(1)
|
| 295 |
+
log.critical("Out of memory!")
|
| 296 |
+
log.info("Server exited with code=-1")
|
| 297 |
+
log.info("[bold]EXITING...[/bold]", extra=dict(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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import sys
|
| 4 |
+
from typing import ClassVar, Iterable
|
| 5 |
+
|
| 6 |
+
from markdown_it import MarkdownIt
|
| 7 |
+
from markdown_it.token import Token
|
| 8 |
+
|
| 9 |
+
if sys.version_info >= (3, 8):
|
| 10 |
+
from typing import get_args
|
| 11 |
+
else:
|
| 12 |
+
from typing_extensions import get_args # pragma: no cover
|
| 13 |
+
|
| 14 |
+
from rich.table import Table
|
| 15 |
+
|
| 16 |
+
from . import box
|
| 17 |
+
from ._loop import loop_first
|
| 18 |
+
from ._stack import Stack
|
| 19 |
+
from .console import Console, ConsoleOptions, JustifyMethod, RenderResult
|
| 20 |
+
from .containers import Renderables
|
| 21 |
+
from .jupyter import JupyterMixin
|
| 22 |
+
from .panel import Panel
|
| 23 |
+
from .rule import Rule
|
| 24 |
+
from .segment import Segment
|
| 25 |
+
from .style import Style, StyleStack
|
| 26 |
+
from .syntax import Syntax
|
| 27 |
+
from .text import Text, TextType
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class MarkdownElement:
|
| 31 |
+
new_line: ClassVar[bool] = True
|
| 32 |
+
|
| 33 |
+
@classmethod
|
| 34 |
+
def create(cls, markdown: Markdown, token: Token) -> MarkdownElement:
|
| 35 |
+
"""Factory to create markdown element,
|
| 36 |
+
|
| 37 |
+
Args:
|
| 38 |
+
markdown (Markdown): The parent Markdown object.
|
| 39 |
+
token (Token): A node from markdown-it.
|
| 40 |
+
|
| 41 |
+
Returns:
|
| 42 |
+
MarkdownElement: A new markdown element
|
| 43 |
+
"""
|
| 44 |
+
return cls()
|
| 45 |
+
|
| 46 |
+
def on_enter(self, context: MarkdownContext) -> None:
|
| 47 |
+
"""Called when the node is entered.
|
| 48 |
+
|
| 49 |
+
Args:
|
| 50 |
+
context (MarkdownContext): The markdown context.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def on_text(self, context: MarkdownContext, text: TextType) -> None:
|
| 54 |
+
"""Called when text is parsed.
|
| 55 |
+
|
| 56 |
+
Args:
|
| 57 |
+
context (MarkdownContext): The markdown context.
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
def on_leave(self, context: MarkdownContext) -> None:
|
| 61 |
+
"""Called when the parser leaves the element.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
context (MarkdownContext): [description]
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 68 |
+
"""Called when a child element is closed.
|
| 69 |
+
|
| 70 |
+
This method allows a parent element to take over rendering of its children.
|
| 71 |
+
|
| 72 |
+
Args:
|
| 73 |
+
context (MarkdownContext): The markdown context.
|
| 74 |
+
child (MarkdownElement): The child markdown element.
|
| 75 |
+
|
| 76 |
+
Returns:
|
| 77 |
+
bool: Return True to render the element, or False to not render the element.
|
| 78 |
+
"""
|
| 79 |
+
return True
|
| 80 |
+
|
| 81 |
+
def __rich_console__(
|
| 82 |
+
self, console: Console, options: ConsoleOptions
|
| 83 |
+
) -> RenderResult:
|
| 84 |
+
return ()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
class UnknownElement(MarkdownElement):
|
| 88 |
+
"""An unknown element.
|
| 89 |
+
|
| 90 |
+
Hopefully there will be no unknown elements, and we will have a MarkdownElement for
|
| 91 |
+
everything in the document.
|
| 92 |
+
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class TextElement(MarkdownElement):
|
| 97 |
+
"""Base class for elements that render text."""
|
| 98 |
+
|
| 99 |
+
style_name = "none"
|
| 100 |
+
|
| 101 |
+
def on_enter(self, context: MarkdownContext) -> None:
|
| 102 |
+
self.style = context.enter_style(self.style_name)
|
| 103 |
+
self.text = Text(justify="left")
|
| 104 |
+
|
| 105 |
+
def on_text(self, context: MarkdownContext, text: TextType) -> None:
|
| 106 |
+
self.text.append(text, context.current_style if isinstance(text, str) else None)
|
| 107 |
+
|
| 108 |
+
def on_leave(self, context: MarkdownContext) -> None:
|
| 109 |
+
context.leave_style()
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
class Paragraph(TextElement):
|
| 113 |
+
"""A Paragraph."""
|
| 114 |
+
|
| 115 |
+
style_name = "markdown.paragraph"
|
| 116 |
+
justify: JustifyMethod
|
| 117 |
+
|
| 118 |
+
@classmethod
|
| 119 |
+
def create(cls, markdown: Markdown, token: Token) -> Paragraph:
|
| 120 |
+
return cls(justify=markdown.justify or "left")
|
| 121 |
+
|
| 122 |
+
def __init__(self, justify: JustifyMethod) -> None:
|
| 123 |
+
self.justify = justify
|
| 124 |
+
|
| 125 |
+
def __rich_console__(
|
| 126 |
+
self, console: Console, options: ConsoleOptions
|
| 127 |
+
) -> RenderResult:
|
| 128 |
+
self.text.justify = self.justify
|
| 129 |
+
yield self.text
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
class Heading(TextElement):
|
| 133 |
+
"""A heading."""
|
| 134 |
+
|
| 135 |
+
@classmethod
|
| 136 |
+
def create(cls, markdown: Markdown, token: Token) -> Heading:
|
| 137 |
+
return cls(token.tag)
|
| 138 |
+
|
| 139 |
+
def on_enter(self, context: MarkdownContext) -> None:
|
| 140 |
+
self.text = Text()
|
| 141 |
+
context.enter_style(self.style_name)
|
| 142 |
+
|
| 143 |
+
def __init__(self, tag: str) -> None:
|
| 144 |
+
self.tag = tag
|
| 145 |
+
self.style_name = f"markdown.{tag}"
|
| 146 |
+
super().__init__()
|
| 147 |
+
|
| 148 |
+
def __rich_console__(
|
| 149 |
+
self, console: Console, options: ConsoleOptions
|
| 150 |
+
) -> RenderResult:
|
| 151 |
+
text = self.text
|
| 152 |
+
text.justify = "center"
|
| 153 |
+
if self.tag == "h1":
|
| 154 |
+
# Draw a border around h1s
|
| 155 |
+
yield Panel(
|
| 156 |
+
text,
|
| 157 |
+
box=box.HEAVY,
|
| 158 |
+
style="markdown.h1.border",
|
| 159 |
+
)
|
| 160 |
+
else:
|
| 161 |
+
# Styled text for h2 and beyond
|
| 162 |
+
if self.tag == "h2":
|
| 163 |
+
yield Text("")
|
| 164 |
+
yield text
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
class CodeBlock(TextElement):
|
| 168 |
+
"""A code block with syntax highlighting."""
|
| 169 |
+
|
| 170 |
+
style_name = "markdown.code_block"
|
| 171 |
+
|
| 172 |
+
@classmethod
|
| 173 |
+
def create(cls, markdown: Markdown, token: Token) -> CodeBlock:
|
| 174 |
+
node_info = token.info or ""
|
| 175 |
+
lexer_name = node_info.partition(" ")[0]
|
| 176 |
+
return cls(lexer_name or "text", markdown.code_theme)
|
| 177 |
+
|
| 178 |
+
def __init__(self, lexer_name: str, theme: str) -> None:
|
| 179 |
+
self.lexer_name = lexer_name
|
| 180 |
+
self.theme = theme
|
| 181 |
+
|
| 182 |
+
def __rich_console__(
|
| 183 |
+
self, console: Console, options: ConsoleOptions
|
| 184 |
+
) -> RenderResult:
|
| 185 |
+
code = str(self.text).rstrip()
|
| 186 |
+
syntax = Syntax(
|
| 187 |
+
code, self.lexer_name, theme=self.theme, word_wrap=True, padding=1
|
| 188 |
+
)
|
| 189 |
+
yield syntax
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
class BlockQuote(TextElement):
|
| 193 |
+
"""A block quote."""
|
| 194 |
+
|
| 195 |
+
style_name = "markdown.block_quote"
|
| 196 |
+
|
| 197 |
+
def __init__(self) -> None:
|
| 198 |
+
self.elements: Renderables = Renderables()
|
| 199 |
+
|
| 200 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 201 |
+
self.elements.append(child)
|
| 202 |
+
return False
|
| 203 |
+
|
| 204 |
+
def __rich_console__(
|
| 205 |
+
self, console: Console, options: ConsoleOptions
|
| 206 |
+
) -> RenderResult:
|
| 207 |
+
render_options = options.update(width=options.max_width - 4)
|
| 208 |
+
lines = console.render_lines(self.elements, render_options, style=self.style)
|
| 209 |
+
style = self.style
|
| 210 |
+
new_line = Segment("\n")
|
| 211 |
+
padding = Segment("▌ ", style)
|
| 212 |
+
for line in lines:
|
| 213 |
+
yield padding
|
| 214 |
+
yield from line
|
| 215 |
+
yield new_line
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
class HorizontalRule(MarkdownElement):
|
| 219 |
+
"""A horizontal rule to divide sections."""
|
| 220 |
+
|
| 221 |
+
new_line = False
|
| 222 |
+
|
| 223 |
+
def __rich_console__(
|
| 224 |
+
self, console: Console, options: ConsoleOptions
|
| 225 |
+
) -> RenderResult:
|
| 226 |
+
style = console.get_style("markdown.hr", default="none")
|
| 227 |
+
yield Rule(style=style)
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
class TableElement(MarkdownElement):
|
| 231 |
+
"""MarkdownElement corresponding to `table_open`."""
|
| 232 |
+
|
| 233 |
+
def __init__(self) -> None:
|
| 234 |
+
self.header: TableHeaderElement | None = None
|
| 235 |
+
self.body: TableBodyElement | None = None
|
| 236 |
+
|
| 237 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 238 |
+
if isinstance(child, TableHeaderElement):
|
| 239 |
+
self.header = child
|
| 240 |
+
elif isinstance(child, TableBodyElement):
|
| 241 |
+
self.body = child
|
| 242 |
+
else:
|
| 243 |
+
raise RuntimeError("Couldn't process markdown table.")
|
| 244 |
+
return False
|
| 245 |
+
|
| 246 |
+
def __rich_console__(
|
| 247 |
+
self, console: Console, options: ConsoleOptions
|
| 248 |
+
) -> RenderResult:
|
| 249 |
+
table = Table(box=box.SIMPLE_HEAVY)
|
| 250 |
+
|
| 251 |
+
if self.header is not None and self.header.row is not None:
|
| 252 |
+
for column in self.header.row.cells:
|
| 253 |
+
table.add_column(column.content)
|
| 254 |
+
|
| 255 |
+
if self.body is not None:
|
| 256 |
+
for row in self.body.rows:
|
| 257 |
+
row_content = [element.content for element in row.cells]
|
| 258 |
+
table.add_row(*row_content)
|
| 259 |
+
|
| 260 |
+
yield table
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
class TableHeaderElement(MarkdownElement):
|
| 264 |
+
"""MarkdownElement corresponding to `thead_open` and `thead_close`."""
|
| 265 |
+
|
| 266 |
+
def __init__(self) -> None:
|
| 267 |
+
self.row: TableRowElement | None = None
|
| 268 |
+
|
| 269 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 270 |
+
assert isinstance(child, TableRowElement)
|
| 271 |
+
self.row = child
|
| 272 |
+
return False
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
class TableBodyElement(MarkdownElement):
|
| 276 |
+
"""MarkdownElement corresponding to `tbody_open` and `tbody_close`."""
|
| 277 |
+
|
| 278 |
+
def __init__(self) -> None:
|
| 279 |
+
self.rows: list[TableRowElement] = []
|
| 280 |
+
|
| 281 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 282 |
+
assert isinstance(child, TableRowElement)
|
| 283 |
+
self.rows.append(child)
|
| 284 |
+
return False
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
class TableRowElement(MarkdownElement):
|
| 288 |
+
"""MarkdownElement corresponding to `tr_open` and `tr_close`."""
|
| 289 |
+
|
| 290 |
+
def __init__(self) -> None:
|
| 291 |
+
self.cells: list[TableDataElement] = []
|
| 292 |
+
|
| 293 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 294 |
+
assert isinstance(child, TableDataElement)
|
| 295 |
+
self.cells.append(child)
|
| 296 |
+
return False
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
class TableDataElement(MarkdownElement):
|
| 300 |
+
"""MarkdownElement corresponding to `td_open` and `td_close`
|
| 301 |
+
and `th_open` and `th_close`."""
|
| 302 |
+
|
| 303 |
+
@classmethod
|
| 304 |
+
def create(cls, markdown: Markdown, token: Token) -> MarkdownElement:
|
| 305 |
+
style = str(token.attrs.get("style")) or ""
|
| 306 |
+
|
| 307 |
+
justify: JustifyMethod
|
| 308 |
+
if "text-align:right" in style:
|
| 309 |
+
justify = "right"
|
| 310 |
+
elif "text-align:center" in style:
|
| 311 |
+
justify = "center"
|
| 312 |
+
elif "text-align:left" in style:
|
| 313 |
+
justify = "left"
|
| 314 |
+
else:
|
| 315 |
+
justify = "default"
|
| 316 |
+
|
| 317 |
+
assert justify in get_args(JustifyMethod)
|
| 318 |
+
return cls(justify=justify)
|
| 319 |
+
|
| 320 |
+
def __init__(self, justify: JustifyMethod) -> None:
|
| 321 |
+
self.content: Text = Text("", justify=justify)
|
| 322 |
+
self.justify = justify
|
| 323 |
+
|
| 324 |
+
def on_text(self, context: MarkdownContext, text: TextType) -> None:
|
| 325 |
+
text = Text(text) if isinstance(text, str) else text
|
| 326 |
+
text.stylize(context.current_style)
|
| 327 |
+
self.content.append_text(text)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class ListElement(MarkdownElement):
|
| 331 |
+
"""A list element."""
|
| 332 |
+
|
| 333 |
+
@classmethod
|
| 334 |
+
def create(cls, markdown: Markdown, token: Token) -> ListElement:
|
| 335 |
+
return cls(token.type, int(token.attrs.get("start", 1)))
|
| 336 |
+
|
| 337 |
+
def __init__(self, list_type: str, list_start: int | None) -> None:
|
| 338 |
+
self.items: list[ListItem] = []
|
| 339 |
+
self.list_type = list_type
|
| 340 |
+
self.list_start = list_start
|
| 341 |
+
|
| 342 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 343 |
+
assert isinstance(child, ListItem)
|
| 344 |
+
self.items.append(child)
|
| 345 |
+
return False
|
| 346 |
+
|
| 347 |
+
def __rich_console__(
|
| 348 |
+
self, console: Console, options: ConsoleOptions
|
| 349 |
+
) -> RenderResult:
|
| 350 |
+
if self.list_type == "bullet_list_open":
|
| 351 |
+
for item in self.items:
|
| 352 |
+
yield from item.render_bullet(console, options)
|
| 353 |
+
else:
|
| 354 |
+
number = 1 if self.list_start is None else self.list_start
|
| 355 |
+
last_number = number + len(self.items)
|
| 356 |
+
for index, item in enumerate(self.items):
|
| 357 |
+
yield from item.render_number(
|
| 358 |
+
console, options, number + index, last_number
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
class ListItem(TextElement):
|
| 363 |
+
"""An item in a list."""
|
| 364 |
+
|
| 365 |
+
style_name = "markdown.item"
|
| 366 |
+
|
| 367 |
+
def __init__(self) -> None:
|
| 368 |
+
self.elements: Renderables = Renderables()
|
| 369 |
+
|
| 370 |
+
def on_child_close(self, context: MarkdownContext, child: MarkdownElement) -> bool:
|
| 371 |
+
self.elements.append(child)
|
| 372 |
+
return False
|
| 373 |
+
|
| 374 |
+
def render_bullet(self, console: Console, options: ConsoleOptions) -> RenderResult:
|
| 375 |
+
render_options = options.update(width=options.max_width - 3)
|
| 376 |
+
lines = console.render_lines(self.elements, render_options, style=self.style)
|
| 377 |
+
bullet_style = console.get_style("markdown.item.bullet", default="none")
|
| 378 |
+
|
| 379 |
+
bullet = Segment(" • ", bullet_style)
|
| 380 |
+
padding = Segment(" " * 3, bullet_style)
|
| 381 |
+
new_line = Segment("\n")
|
| 382 |
+
for first, line in loop_first(lines):
|
| 383 |
+
yield bullet if first else padding
|
| 384 |
+
yield from line
|
| 385 |
+
yield new_line
|
| 386 |
+
|
| 387 |
+
def render_number(
|
| 388 |
+
self, console: Console, options: ConsoleOptions, number: int, last_number: int
|
| 389 |
+
) -> RenderResult:
|
| 390 |
+
number_width = len(str(last_number)) + 2
|
| 391 |
+
render_options = options.update(width=options.max_width - number_width)
|
| 392 |
+
lines = console.render_lines(self.elements, render_options, style=self.style)
|
| 393 |
+
number_style = console.get_style("markdown.item.number", default="none")
|
| 394 |
+
|
| 395 |
+
new_line = Segment("\n")
|
| 396 |
+
padding = Segment(" " * number_width, number_style)
|
| 397 |
+
numeral = Segment(f"{number}".rjust(number_width - 1) + " ", number_style)
|
| 398 |
+
for first, line in loop_first(lines):
|
| 399 |
+
yield numeral if first else padding
|
| 400 |
+
yield from line
|
| 401 |
+
yield new_line
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
class Link(TextElement):
|
| 405 |
+
@classmethod
|
| 406 |
+
def create(cls, markdown: Markdown, token: Token) -> MarkdownElement:
|
| 407 |
+
url = token.attrs.get("href", "#")
|
| 408 |
+
return cls(token.content, str(url))
|
| 409 |
+
|
| 410 |
+
def __init__(self, text: str, href: str):
|
| 411 |
+
self.text = Text(text)
|
| 412 |
+
self.href = href
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
class ImageItem(TextElement):
|
| 416 |
+
"""Renders a placeholder for an image."""
|
| 417 |
+
|
| 418 |
+
new_line = False
|
| 419 |
+
|
| 420 |
+
@classmethod
|
| 421 |
+
def create(cls, markdown: Markdown, token: Token) -> MarkdownElement:
|
| 422 |
+
"""Factory to create markdown element,
|
| 423 |
+
|
| 424 |
+
Args:
|
| 425 |
+
markdown (Markdown): The parent Markdown object.
|
| 426 |
+
token (Any): A token from markdown-it.
|
| 427 |
+
|
| 428 |
+
Returns:
|
| 429 |
+
MarkdownElement: A new markdown element
|
| 430 |
+
"""
|
| 431 |
+
return cls(str(token.attrs.get("src", "")), markdown.hyperlinks)
|
| 432 |
+
|
| 433 |
+
def __init__(self, destination: str, hyperlinks: bool) -> None:
|
| 434 |
+
self.destination = destination
|
| 435 |
+
self.hyperlinks = hyperlinks
|
| 436 |
+
self.link: str | None = None
|
| 437 |
+
super().__init__()
|
| 438 |
+
|
| 439 |
+
def on_enter(self, context: MarkdownContext) -> None:
|
| 440 |
+
self.link = context.current_style.link
|
| 441 |
+
self.text = Text(justify="left")
|
| 442 |
+
super().on_enter(context)
|
| 443 |
+
|
| 444 |
+
def __rich_console__(
|
| 445 |
+
self, console: Console, options: ConsoleOptions
|
| 446 |
+
) -> RenderResult:
|
| 447 |
+
link_style = Style(link=self.link or self.destination or None)
|
| 448 |
+
title = self.text or Text(self.destination.strip("/").rsplit("/", 1)[-1])
|
| 449 |
+
if self.hyperlinks:
|
| 450 |
+
title.stylize(link_style)
|
| 451 |
+
text = Text.assemble("🌆 ", title, " ", end="")
|
| 452 |
+
yield text
|
| 453 |
+
|
| 454 |
+
|
| 455 |
+
class MarkdownContext:
|
| 456 |
+
"""Manages the console render state."""
|
| 457 |
+
|
| 458 |
+
def __init__(
|
| 459 |
+
self,
|
| 460 |
+
console: Console,
|
| 461 |
+
options: ConsoleOptions,
|
| 462 |
+
style: Style,
|
| 463 |
+
inline_code_lexer: str | None = None,
|
| 464 |
+
inline_code_theme: str = "monokai",
|
| 465 |
+
) -> None:
|
| 466 |
+
self.console = console
|
| 467 |
+
self.options = options
|
| 468 |
+
self.style_stack: StyleStack = StyleStack(style)
|
| 469 |
+
self.stack: Stack[MarkdownElement] = Stack()
|
| 470 |
+
|
| 471 |
+
self._syntax: Syntax | None = None
|
| 472 |
+
if inline_code_lexer is not None:
|
| 473 |
+
self._syntax = Syntax("", inline_code_lexer, theme=inline_code_theme)
|
| 474 |
+
|
| 475 |
+
@property
|
| 476 |
+
def current_style(self) -> Style:
|
| 477 |
+
"""Current style which is the product of all styles on the stack."""
|
| 478 |
+
return self.style_stack.current
|
| 479 |
+
|
| 480 |
+
def on_text(self, text: str, node_type: str) -> None:
|
| 481 |
+
"""Called when the parser visits text."""
|
| 482 |
+
if node_type in {"fence", "code_inline"} and self._syntax is not None:
|
| 483 |
+
highlight_text = self._syntax.highlight(text)
|
| 484 |
+
highlight_text.rstrip()
|
| 485 |
+
self.stack.top.on_text(
|
| 486 |
+
self, Text.assemble(highlight_text, style=self.style_stack.current)
|
| 487 |
+
)
|
| 488 |
+
else:
|
| 489 |
+
self.stack.top.on_text(self, text)
|
| 490 |
+
|
| 491 |
+
def enter_style(self, style_name: str | Style) -> Style:
|
| 492 |
+
"""Enter a style context."""
|
| 493 |
+
style = self.console.get_style(style_name, default="none")
|
| 494 |
+
self.style_stack.push(style)
|
| 495 |
+
return self.current_style
|
| 496 |
+
|
| 497 |
+
def leave_style(self) -> Style:
|
| 498 |
+
"""Leave a style context."""
|
| 499 |
+
style = self.style_stack.pop()
|
| 500 |
+
return style
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
class Markdown(JupyterMixin):
|
| 504 |
+
"""A Markdown renderable.
|
| 505 |
+
|
| 506 |
+
Args:
|
| 507 |
+
markup (str): A string containing markdown.
|
| 508 |
+
code_theme (str, optional): Pygments theme for code blocks. Defaults to "monokai". See https://pygments.org/styles/ for code themes.
|
| 509 |
+
justify (JustifyMethod, optional): Justify value for paragraphs. Defaults to None.
|
| 510 |
+
style (Union[str, Style], optional): Optional style to apply to markdown.
|
| 511 |
+
hyperlinks (bool, optional): Enable hyperlinks. Defaults to ``True``.
|
| 512 |
+
inline_code_lexer: (str, optional): Lexer to use if inline code highlighting is
|
| 513 |
+
enabled. Defaults to None.
|
| 514 |
+
inline_code_theme: (Optional[str], optional): Pygments theme for inline code
|
| 515 |
+
highlighting, or None for no highlighting. Defaults to None.
|
| 516 |
+
"""
|
| 517 |
+
|
| 518 |
+
elements: ClassVar[dict[str, type[MarkdownElement]]] = {
|
| 519 |
+
"paragraph_open": Paragraph,
|
| 520 |
+
"heading_open": Heading,
|
| 521 |
+
"fence": CodeBlock,
|
| 522 |
+
"code_block": CodeBlock,
|
| 523 |
+
"blockquote_open": BlockQuote,
|
| 524 |
+
"hr": HorizontalRule,
|
| 525 |
+
"bullet_list_open": ListElement,
|
| 526 |
+
"ordered_list_open": ListElement,
|
| 527 |
+
"list_item_open": ListItem,
|
| 528 |
+
"image": ImageItem,
|
| 529 |
+
"table_open": TableElement,
|
| 530 |
+
"tbody_open": TableBodyElement,
|
| 531 |
+
"thead_open": TableHeaderElement,
|
| 532 |
+
"tr_open": TableRowElement,
|
| 533 |
+
"td_open": TableDataElement,
|
| 534 |
+
"th_open": TableDataElement,
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
inlines = {"em", "strong", "code", "s"}
|
| 538 |
+
|
| 539 |
+
def __init__(
|
| 540 |
+
self,
|
| 541 |
+
markup: str,
|
| 542 |
+
code_theme: str = "monokai",
|
| 543 |
+
justify: JustifyMethod | None = None,
|
| 544 |
+
style: str | Style = "none",
|
| 545 |
+
hyperlinks: bool = True,
|
| 546 |
+
inline_code_lexer: str | None = None,
|
| 547 |
+
inline_code_theme: str | None = None,
|
| 548 |
+
) -> None:
|
| 549 |
+
parser = MarkdownIt().enable("strikethrough").enable("table")
|
| 550 |
+
self.markup = markup
|
| 551 |
+
self.parsed = parser.parse(markup)
|
| 552 |
+
self.code_theme = code_theme
|
| 553 |
+
self.justify: JustifyMethod | None = justify
|
| 554 |
+
self.style = style
|
| 555 |
+
self.hyperlinks = hyperlinks
|
| 556 |
+
self.inline_code_lexer = inline_code_lexer
|
| 557 |
+
self.inline_code_theme = inline_code_theme or code_theme
|
| 558 |
+
|
| 559 |
+
def _flatten_tokens(self, tokens: Iterable[Token]) -> Iterable[Token]:
|
| 560 |
+
"""Flattens the token stream."""
|
| 561 |
+
for token in tokens:
|
| 562 |
+
is_fence = token.type == "fence"
|
| 563 |
+
is_image = token.tag == "img"
|
| 564 |
+
if token.children and not (is_image or is_fence):
|
| 565 |
+
yield from self._flatten_tokens(token.children)
|
| 566 |
+
else:
|
| 567 |
+
yield token
|
| 568 |
+
|
| 569 |
+
def __rich_console__(
|
| 570 |
+
self, console: Console, options: ConsoleOptions
|
| 571 |
+
) -> RenderResult:
|
| 572 |
+
"""Render markdown to the console."""
|
| 573 |
+
style = console.get_style(self.style, default="none")
|
| 574 |
+
options = options.update(height=None)
|
| 575 |
+
context = MarkdownContext(
|
| 576 |
+
console,
|
| 577 |
+
options,
|
| 578 |
+
style,
|
| 579 |
+
inline_code_lexer=self.inline_code_lexer,
|
| 580 |
+
inline_code_theme=self.inline_code_theme,
|
| 581 |
+
)
|
| 582 |
+
tokens = self.parsed
|
| 583 |
+
inline_style_tags = self.inlines
|
| 584 |
+
new_line = False
|
| 585 |
+
_new_line_segment = Segment.line()
|
| 586 |
+
|
| 587 |
+
for token in self._flatten_tokens(tokens):
|
| 588 |
+
node_type = token.type
|
| 589 |
+
tag = token.tag
|
| 590 |
+
|
| 591 |
+
entering = token.nesting == 1
|
| 592 |
+
exiting = token.nesting == -1
|
| 593 |
+
self_closing = token.nesting == 0
|
| 594 |
+
|
| 595 |
+
if node_type == "text":
|
| 596 |
+
context.on_text(token.content, node_type)
|
| 597 |
+
elif node_type == "hardbreak":
|
| 598 |
+
context.on_text("\n", node_type)
|
| 599 |
+
elif node_type == "softbreak":
|
| 600 |
+
context.on_text(" ", node_type)
|
| 601 |
+
elif node_type == "link_open":
|
| 602 |
+
href = str(token.attrs.get("href", ""))
|
| 603 |
+
if self.hyperlinks:
|
| 604 |
+
link_style = console.get_style("markdown.link_url", default="none")
|
| 605 |
+
link_style += Style(link=href)
|
| 606 |
+
context.enter_style(link_style)
|
| 607 |
+
else:
|
| 608 |
+
context.stack.push(Link.create(self, token))
|
| 609 |
+
elif node_type == "link_close":
|
| 610 |
+
if self.hyperlinks:
|
| 611 |
+
context.leave_style()
|
| 612 |
+
else:
|
| 613 |
+
element = context.stack.pop()
|
| 614 |
+
assert isinstance(element, Link)
|
| 615 |
+
link_style = console.get_style("markdown.link", default="none")
|
| 616 |
+
context.enter_style(link_style)
|
| 617 |
+
context.on_text(element.text.plain, node_type)
|
| 618 |
+
context.leave_style()
|
| 619 |
+
context.on_text(" (", node_type)
|
| 620 |
+
link_url_style = console.get_style(
|
| 621 |
+
"markdown.link_url", default="none"
|
| 622 |
+
)
|
| 623 |
+
context.enter_style(link_url_style)
|
| 624 |
+
context.on_text(element.href, node_type)
|
| 625 |
+
context.leave_style()
|
| 626 |
+
context.on_text(")", node_type)
|
| 627 |
+
elif (
|
| 628 |
+
tag in inline_style_tags
|
| 629 |
+
and node_type != "fence"
|
| 630 |
+
and node_type != "code_block"
|
| 631 |
+
):
|
| 632 |
+
if entering:
|
| 633 |
+
# If it's an opening inline token e.g. strong, em, etc.
|
| 634 |
+
# Then we move into a style context i.e. push to stack.
|
| 635 |
+
context.enter_style(f"markdown.{tag}")
|
| 636 |
+
elif exiting:
|
| 637 |
+
# If it's a closing inline style, then we pop the style
|
| 638 |
+
# off of the stack, to move out of the context of it...
|
| 639 |
+
context.leave_style()
|
| 640 |
+
else:
|
| 641 |
+
# If it's a self-closing inline style e.g. `code_inline`
|
| 642 |
+
context.enter_style(f"markdown.{tag}")
|
| 643 |
+
if token.content:
|
| 644 |
+
context.on_text(token.content, node_type)
|
| 645 |
+
context.leave_style()
|
| 646 |
+
else:
|
| 647 |
+
# Map the markdown tag -> MarkdownElement renderable
|
| 648 |
+
element_class = self.elements.get(token.type) or UnknownElement
|
| 649 |
+
element = element_class.create(self, token)
|
| 650 |
+
|
| 651 |
+
if entering or self_closing:
|
| 652 |
+
context.stack.push(element)
|
| 653 |
+
element.on_enter(context)
|
| 654 |
+
|
| 655 |
+
if exiting: # CLOSING tag
|
| 656 |
+
element = context.stack.pop()
|
| 657 |
+
|
| 658 |
+
should_render = not context.stack or (
|
| 659 |
+
context.stack
|
| 660 |
+
and context.stack.top.on_child_close(context, element)
|
| 661 |
+
)
|
| 662 |
+
|
| 663 |
+
if should_render:
|
| 664 |
+
if new_line:
|
| 665 |
+
yield _new_line_segment
|
| 666 |
+
|
| 667 |
+
yield from console.render(element, context.options)
|
| 668 |
+
elif self_closing: # SELF-CLOSING tags (e.g. text, code, image)
|
| 669 |
+
context.stack.pop()
|
| 670 |
+
text = token.content
|
| 671 |
+
if text is not None:
|
| 672 |
+
element.on_text(context, text)
|
| 673 |
+
|
| 674 |
+
should_render = (
|
| 675 |
+
not context.stack
|
| 676 |
+
or context.stack
|
| 677 |
+
and context.stack.top.on_child_close(context, element)
|
| 678 |
+
)
|
| 679 |
+
if should_render:
|
| 680 |
+
if new_line and node_type != "inline":
|
| 681 |
+
yield _new_line_segment
|
| 682 |
+
yield from console.render(element, context.options)
|
| 683 |
+
|
| 684 |
+
if exiting or self_closing:
|
| 685 |
+
element.on_leave(context)
|
| 686 |
+
new_line = element.new_line
|
| 687 |
+
|
| 688 |
+
|
| 689 |
+
if __name__ == "__main__": # pragma: no cover
|
| 690 |
+
import argparse
|
| 691 |
+
import sys
|
| 692 |
+
|
| 693 |
+
parser = argparse.ArgumentParser(
|
| 694 |
+
description="Render Markdown to the console with Rich"
|
| 695 |
+
)
|
| 696 |
+
parser.add_argument(
|
| 697 |
+
"path",
|
| 698 |
+
metavar="PATH",
|
| 699 |
+
help="path to markdown file, or - for stdin",
|
| 700 |
+
)
|
| 701 |
+
parser.add_argument(
|
| 702 |
+
"-c",
|
| 703 |
+
"--force-color",
|
| 704 |
+
dest="force_color",
|
| 705 |
+
action="store_true",
|
| 706 |
+
default=None,
|
| 707 |
+
help="force color for non-terminals",
|
| 708 |
+
)
|
| 709 |
+
parser.add_argument(
|
| 710 |
+
"-t",
|
| 711 |
+
"--code-theme",
|
| 712 |
+
dest="code_theme",
|
| 713 |
+
default="monokai",
|
| 714 |
+
help="pygments code theme",
|
| 715 |
+
)
|
| 716 |
+
parser.add_argument(
|
| 717 |
+
"-i",
|
| 718 |
+
"--inline-code-lexer",
|
| 719 |
+
dest="inline_code_lexer",
|
| 720 |
+
default=None,
|
| 721 |
+
help="inline_code_lexer",
|
| 722 |
+
)
|
| 723 |
+
parser.add_argument(
|
| 724 |
+
"-y",
|
| 725 |
+
"--hyperlinks",
|
| 726 |
+
dest="hyperlinks",
|
| 727 |
+
action="store_true",
|
| 728 |
+
help="enable hyperlinks",
|
| 729 |
+
)
|
| 730 |
+
parser.add_argument(
|
| 731 |
+
"-w",
|
| 732 |
+
"--width",
|
| 733 |
+
type=int,
|
| 734 |
+
dest="width",
|
| 735 |
+
default=None,
|
| 736 |
+
help="width of output (default will auto-detect)",
|
| 737 |
+
)
|
| 738 |
+
parser.add_argument(
|
| 739 |
+
"-j",
|
| 740 |
+
"--justify",
|
| 741 |
+
dest="justify",
|
| 742 |
+
action="store_true",
|
| 743 |
+
help="enable full text justify",
|
| 744 |
+
)
|
| 745 |
+
parser.add_argument(
|
| 746 |
+
"-p",
|
| 747 |
+
"--page",
|
| 748 |
+
dest="page",
|
| 749 |
+
action="store_true",
|
| 750 |
+
help="use pager to scroll output",
|
| 751 |
+
)
|
| 752 |
+
args = parser.parse_args()
|
| 753 |
+
|
| 754 |
+
from rich.console import Console
|
| 755 |
+
|
| 756 |
+
if args.path == "-":
|
| 757 |
+
markdown_body = sys.stdin.read()
|
| 758 |
+
else:
|
| 759 |
+
with open(args.path, encoding="utf-8") as markdown_file:
|
| 760 |
+
markdown_body = markdown_file.read()
|
| 761 |
+
|
| 762 |
+
markdown = Markdown(
|
| 763 |
+
markdown_body,
|
| 764 |
+
justify="full" if args.justify else "left",
|
| 765 |
+
code_theme=args.code_theme,
|
| 766 |
+
hyperlinks=args.hyperlinks,
|
| 767 |
+
inline_code_lexer=args.inline_code_lexer,
|
| 768 |
+
)
|
| 769 |
+
if args.page:
|
| 770 |
+
import io
|
| 771 |
+
import pydoc
|
| 772 |
+
|
| 773 |
+
fileio = io.StringIO()
|
| 774 |
+
console = Console(
|
| 775 |
+
file=fileio, force_terminal=args.force_color, width=args.width
|
| 776 |
+
)
|
| 777 |
+
console.print(markdown)
|
| 778 |
+
pydoc.pager(fileio.getvalue())
|
| 779 |
+
|
| 780 |
+
else:
|
| 781 |
+
console = Console(
|
| 782 |
+
force_terminal=args.force_color, width=args.width, record=True
|
| 783 |
+
)
|
| 784 |
+
console.print(markdown)
|