tessl install tessl/pypi-textual@6.1.0Modern Text User Interface framework for building cross-platform terminal and web applications with Python
Agent Success
Agent success rate when using this tile
93%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.18x
Baseline
Agent success rate without this tile
79%
Build a custom Textual widget that displays formatted text with automatic wrapping, overflow handling, and alignment options.
Create a TextFormatter widget that:
Text Content Management:
Text Wrapping:
Alignment Options:
Overflow Handling:
Your widget should inherit from Widget and override the render() method to return the properly formatted content. The widget should accept these parameters during initialization:
text: The text content to display (string)alignment: Text alignment ("left", "center", or "right"), default "left"overflow: Overflow handling mode ("ellipsis" or "fold"), default "fold"markup: Whether the text contains markup (boolean), default TrueProvide a set_text(text: str) method to update the text content, and a set_alignment(alignment: str) method to change the alignment.
Modern Text User Interface framework for building terminal applications.
Create a file named test_text_formatter.py with the following test cases:
from textual.app import App
from text_formatter import TextFormatter
class TestApp(App):
def compose(self):
yield TextFormatter(
"Hello, World!",
alignment="left",
markup=False
)
app = TestApp()
# The widget should display "Hello, World!" aligned to the leftfrom textual.app import App
from text_formatter import TextFormatter
class TestApp(App):
def compose(self):
yield TextFormatter(
"[bold]Bold text[/bold] and [italic]italic text[/italic]",
alignment="center",
markup=True
)
app = TestApp()
# The widget should display styled text centeredfrom textual.app import App
from text_formatter import TextFormatter
class TestApp(App):
def compose(self):
widget = TextFormatter(
"This is a very long text that should be truncated with ellipsis when it exceeds the available width",
alignment="left",
overflow="ellipsis",
markup=False
)
widget.styles.width = 20 # Constrain width
yield widget
app = TestApp()
# The widget should show truncated text with "..." at the endfrom textual.app import App
from text_formatter import TextFormatter
class TestApp(App):
def compose(self):
self.formatter = TextFormatter("Initial text", markup=False)
yield self.formatter
def on_mount(self):
self.formatter.set_text("Updated text")
self.formatter.set_alignment("right")
app = TestApp()
# The widget should display "Updated text" aligned to the rightThe widget should: