Skip to content

Commit ad6e3de

Browse files
authored
Merge pull request #1723 from willmcgugan/v10.15.0
10.15.0
2 parents a6d1d78 + 32eb546 commit ad6e3de

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [10.15.0] - Unreleased
8+
## [10.15.0] - 2021-11-28
99

1010
### Added
1111

1212
- Added dynamic_progress.py to examples
1313
- Added ConsoleOptions.update_height
14+
- Fixed Padding not respecting height
1415

1516
### Changed
1617

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "10.15.0-alpha3"
5+
version = "10.15.0"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <[email protected]>"]
88
license = "MIT"

rich/text.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ def from_ansi(
254254
end: str = "\n",
255255
tab_size: Optional[int] = 8,
256256
) -> "Text":
257-
"""Create a Text object from pre-formatted ANSI.
257+
"""Create a Text object from a string containing ANSI escape codes.
258258
259259
Args:
260-
text (str): A string containing ANSI color codes.
260+
text (str): A string containing escape codes.
261261
style (Union[str, Style], optional): Base style for text. Defaults to "".
262262
justify (str, optional): Justify method: "left", "center", "full", "right". Defaults to None.
263263
overflow (str, optional): Overflow method: "crop", "fold", "ellipsis". Defaults to None.
@@ -267,14 +267,18 @@ def from_ansi(
267267
"""
268268
from .ansi import AnsiDecoder
269269

270-
decoded_text = AnsiDecoder().decode_line(text)
271-
decoded_text.justify = justify
272-
decoded_text.overflow = overflow
273-
decoded_text.no_wrap = no_wrap
274-
decoded_text.end = end
275-
decoded_text.tab_size = tab_size
276-
decoded_text.stylize(style)
277-
return decoded_text
270+
joiner = Text(
271+
"\n",
272+
justify=justify,
273+
overflow=overflow,
274+
no_wrap=no_wrap,
275+
end=end,
276+
tab_size=tab_size,
277+
style=style,
278+
)
279+
decoder = AnsiDecoder()
280+
result = joiner.join(line for line in decoder.decode(text))
281+
return result
278282

279283
@classmethod
280284
def styled(

tests/test_pretty.py

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def test_small_width():
9797
assert result == expected
9898

9999

100+
@skip_py36
100101
def test_broken_repr():
101102
class BrokenRepr:
102103
def __repr__(self):
@@ -108,6 +109,7 @@ def __repr__(self):
108109
assert result == expected
109110

110111

112+
@skip_py36
111113
def test_broken_getattr():
112114
class BrokenAttr:
113115
def __getattr__(self, name):

tests/test_repr.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import pytest
2+
import sys
23
from typing import Optional
34

45
from rich.console import Console
56
import rich.repr
67

78

9+
skip_py36 = pytest.mark.skipif(
10+
sys.version_info.minor == 6 and sys.version_info.major == 3,
11+
reason="rendered differently on py3.6",
12+
)
13+
14+
skip_py37 = pytest.mark.skipif(
15+
sys.version_info.minor == 7 and sys.version_info.major == 3,
16+
reason="rendered differently on py3.7",
17+
)
18+
19+
820
@rich.repr.auto
921
class Foo:
1022
def __init__(self, foo: str, bar: Optional[int] = None, egg: int = 1):
@@ -59,13 +71,21 @@ def test_rich_repr() -> None:
5971
assert (repr(Foo("hello", bar=3))) == "Foo('hello', 'hello', bar=3, egg=1)"
6072

6173

74+
@skip_py36
75+
@skip_py37
6276
def test_rich_repr_positional_only() -> None:
63-
@rich.repr.auto
64-
class PosOnly:
65-
def __init__(self, foo, /):
66-
self.foo = 1
67-
68-
p = PosOnly(1)
77+
_locals = locals().copy()
78+
exec(
79+
"""\
80+
@rich.repr.auto
81+
class PosOnly:
82+
def __init__(self, foo, /):
83+
self.foo = 1
84+
""",
85+
globals(),
86+
_locals,
87+
)
88+
p = _locals["PosOnly"](1)
6989
assert repr(p) == "PosOnly(1)"
7090

7191

tests/test_text.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,12 @@ def test_from_markup():
9797

9898
def test_from_ansi():
9999
text = Text.from_ansi("Hello, \033[1mWorld!\033[0m")
100-
text2 = Text.from_ansi("Hello, \033[1mWorld!\033[0m", style="red")
101100
assert str(text) == "Hello, World!"
102101
assert text._spans == [Span(7, 13, Style(bold=True))]
103-
assert str(text2) == "Hello, World!"
104-
assert text2._spans == [Span(7, 13, Style(bold=True)), Span(0, 13, "red")]
102+
103+
text = Text.from_ansi("Hello, \033[1m\nWorld!\033[0m")
104+
assert str(text) == "Hello, \nWorld!"
105+
assert text._spans == [Span(8, 14, Style(bold=True))]
105106

106107

107108
def test_copy():

0 commit comments

Comments
 (0)