mirror of https://github.com/Textualize/rich.git
commit
ad6e3dea2d
|
@ -5,12 +5,13 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [10.15.0] - Unreleased
|
||||
## [10.15.0] - 2021-11-28
|
||||
|
||||
### Added
|
||||
|
||||
- Added dynamic_progress.py to examples
|
||||
- Added ConsoleOptions.update_height
|
||||
- Fixed Padding not respecting height
|
||||
|
||||
### Changed
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
name = "rich"
|
||||
homepage = "https://github.com/willmcgugan/rich"
|
||||
documentation = "https://rich.readthedocs.io/en/latest/"
|
||||
version = "10.15.0-alpha3"
|
||||
version = "10.15.0"
|
||||
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
|
||||
authors = ["Will McGugan <willmcgugan@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
|
24
rich/text.py
24
rich/text.py
|
@ -254,10 +254,10 @@ class Text(JupyterMixin):
|
|||
end: str = "\n",
|
||||
tab_size: Optional[int] = 8,
|
||||
) -> "Text":
|
||||
"""Create a Text object from pre-formatted ANSI.
|
||||
"""Create a Text object from a string containing ANSI escape codes.
|
||||
|
||||
Args:
|
||||
text (str): A string containing ANSI color codes.
|
||||
text (str): A string containing escape codes.
|
||||
style (Union[str, Style], optional): Base style for text. Defaults to "".
|
||||
justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
|
||||
overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
|
||||
|
@ -267,14 +267,18 @@ class Text(JupyterMixin):
|
|||
"""
|
||||
from .ansi import AnsiDecoder
|
||||
|
||||
decoded_text = AnsiDecoder().decode_line(text)
|
||||
decoded_text.justify = justify
|
||||
decoded_text.overflow = overflow
|
||||
decoded_text.no_wrap = no_wrap
|
||||
decoded_text.end = end
|
||||
decoded_text.tab_size = tab_size
|
||||
decoded_text.stylize(style)
|
||||
return decoded_text
|
||||
joiner = Text(
|
||||
"\n",
|
||||
justify=justify,
|
||||
overflow=overflow,
|
||||
no_wrap=no_wrap,
|
||||
end=end,
|
||||
tab_size=tab_size,
|
||||
style=style,
|
||||
)
|
||||
decoder = AnsiDecoder()
|
||||
result = joiner.join(line for line in decoder.decode(text))
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def styled(
|
||||
|
|
|
@ -97,6 +97,7 @@ def test_small_width():
|
|||
assert result == expected
|
||||
|
||||
|
||||
@skip_py36
|
||||
def test_broken_repr():
|
||||
class BrokenRepr:
|
||||
def __repr__(self):
|
||||
|
@ -108,6 +109,7 @@ def test_broken_repr():
|
|||
assert result == expected
|
||||
|
||||
|
||||
@skip_py36
|
||||
def test_broken_getattr():
|
||||
class BrokenAttr:
|
||||
def __getattr__(self, name):
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
import pytest
|
||||
import sys
|
||||
from typing import Optional
|
||||
|
||||
from rich.console import Console
|
||||
import rich.repr
|
||||
|
||||
|
||||
skip_py36 = pytest.mark.skipif(
|
||||
sys.version_info.minor == 6 and sys.version_info.major == 3,
|
||||
reason="rendered differently on py3.6",
|
||||
)
|
||||
|
||||
skip_py37 = pytest.mark.skipif(
|
||||
sys.version_info.minor == 7 and sys.version_info.major == 3,
|
||||
reason="rendered differently on py3.7",
|
||||
)
|
||||
|
||||
|
||||
@rich.repr.auto
|
||||
class Foo:
|
||||
def __init__(self, foo: str, bar: Optional[int] = None, egg: int = 1):
|
||||
|
@ -59,13 +71,21 @@ def test_rich_repr() -> None:
|
|||
assert (repr(Foo("hello", bar=3))) == "Foo('hello', 'hello', bar=3, egg=1)"
|
||||
|
||||
|
||||
@skip_py36
|
||||
@skip_py37
|
||||
def test_rich_repr_positional_only() -> None:
|
||||
@rich.repr.auto
|
||||
class PosOnly:
|
||||
def __init__(self, foo, /):
|
||||
self.foo = 1
|
||||
|
||||
p = PosOnly(1)
|
||||
_locals = locals().copy()
|
||||
exec(
|
||||
"""\
|
||||
@rich.repr.auto
|
||||
class PosOnly:
|
||||
def __init__(self, foo, /):
|
||||
self.foo = 1
|
||||
""",
|
||||
globals(),
|
||||
_locals,
|
||||
)
|
||||
p = _locals["PosOnly"](1)
|
||||
assert repr(p) == "PosOnly(1)"
|
||||
|
||||
|
||||
|
|
|
@ -97,11 +97,12 @@ def test_from_markup():
|
|||
|
||||
def test_from_ansi():
|
||||
text = Text.from_ansi("Hello, \033[1mWorld!\033[0m")
|
||||
text2 = Text.from_ansi("Hello, \033[1mWorld!\033[0m", style="red")
|
||||
assert str(text) == "Hello, World!"
|
||||
assert text._spans == [Span(7, 13, Style(bold=True))]
|
||||
assert str(text2) == "Hello, World!"
|
||||
assert text2._spans == [Span(7, 13, Style(bold=True)), Span(0, 13, "red")]
|
||||
|
||||
text = Text.from_ansi("Hello, \033[1m\nWorld!\033[0m")
|
||||
assert str(text) == "Hello, \nWorld!"
|
||||
assert text._spans == [Span(8, 14, Style(bold=True))]
|
||||
|
||||
|
||||
def test_copy():
|
||||
|
|
Loading…
Reference in New Issue