mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #1710 from Textualize/line-api-docs
Documented the Line API
This commit is contained in:
@@ -83,6 +83,14 @@ def test_adjust_cell_length():
|
||||
)
|
||||
|
||||
|
||||
def test_extend_cell_length():
|
||||
strip = Strip([Segment("foo"), Segment("bar")])
|
||||
assert strip.extend_cell_length(3).text == "foobar"
|
||||
assert strip.extend_cell_length(6).text == "foobar"
|
||||
assert strip.extend_cell_length(7).text == "foobar "
|
||||
assert strip.extend_cell_length(9).text == "foobar "
|
||||
|
||||
|
||||
def test_simplify():
|
||||
assert Strip([Segment("foo"), Segment("bar")]).simplify() == Strip(
|
||||
[Segment("foobar")]
|
||||
|
||||
@@ -10,7 +10,7 @@ from textual.geometry import Region, Size
|
||||
from textual.strip import Strip
|
||||
|
||||
|
||||
def _extract_content(lines: list[list[Segment]]):
|
||||
def _extract_content(lines: list[Strip]) -> list[str]:
|
||||
"""Extract the text content from lines."""
|
||||
content = ["".join(segment.text for segment in line) for line in lines]
|
||||
return content
|
||||
@@ -28,9 +28,9 @@ def test_set_dirty():
|
||||
def test_no_styles():
|
||||
"""Test that empty style returns the content un-altered"""
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
cache = StylesCache()
|
||||
@@ -54,9 +54,9 @@ def test_no_styles():
|
||||
|
||||
def test_border():
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
styles.border = ("heavy", "white")
|
||||
@@ -85,9 +85,9 @@ def test_border():
|
||||
|
||||
def test_padding():
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
styles.padding = 1
|
||||
@@ -116,9 +116,9 @@ def test_padding():
|
||||
|
||||
def test_padding_border():
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
styles.padding = 1
|
||||
@@ -150,9 +150,9 @@ def test_padding_border():
|
||||
|
||||
def test_outline():
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
styles.outline = ("heavy", "white")
|
||||
@@ -177,9 +177,9 @@ def test_outline():
|
||||
|
||||
def test_crop():
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
styles = Styles()
|
||||
styles.padding = 1
|
||||
@@ -203,17 +203,17 @@ def test_crop():
|
||||
assert text_content == expected_text
|
||||
|
||||
|
||||
def test_dirty_cache():
|
||||
def test_dirty_cache() -> None:
|
||||
"""Check that we only render content once or if it has been marked as dirty."""
|
||||
|
||||
content = [
|
||||
[Segment("foo")],
|
||||
[Segment("bar")],
|
||||
[Segment("baz")],
|
||||
Strip([Segment("foo")]),
|
||||
Strip([Segment("bar")]),
|
||||
Strip([Segment("baz")]),
|
||||
]
|
||||
rendered_lines: list[int] = []
|
||||
|
||||
def get_content_line(y: int) -> list[Segment]:
|
||||
def get_content_line(y: int) -> Strip:
|
||||
rendered_lines.append(y)
|
||||
return content[y]
|
||||
|
||||
@@ -227,11 +227,13 @@ def test_dirty_cache():
|
||||
Color.parse("blue"),
|
||||
Color.parse("green"),
|
||||
get_content_line,
|
||||
Size(3, 3),
|
||||
)
|
||||
assert rendered_lines == [0, 1, 2]
|
||||
del rendered_lines[:]
|
||||
|
||||
text_content = _extract_content(lines)
|
||||
|
||||
expected_text = [
|
||||
"┏━━━━━┓",
|
||||
"┃ ┃",
|
||||
|
||||
Reference in New Issue
Block a user