File tree Expand file tree Collapse file tree 3 files changed +187
-19
lines changed
__snapshots__/test_snapshots Expand file tree Collapse file tree 3 files changed +187
-19
lines changed Original file line number Diff line number Diff line change 66
77from rich .pretty import Pretty as PrettyRenderable
88
9- from textual .widget import Widget
9+ from textual .widgets import Static
1010
1111
12- class Pretty (Widget ):
12+ class Pretty (Static ):
1313 """A pretty-printing widget.
1414
1515 Used to pretty-print any object.
@@ -37,27 +37,13 @@ def __init__(
3737 id: The ID of the pretty in the DOM.
3838 classes: The CSS classes of the pretty.
3939 """
40- super ().__init__ (
41- name = name ,
42- id = id ,
43- classes = classes ,
44- )
45- self ._renderable = PrettyRenderable (object )
46-
47- def render (self ) -> PrettyRenderable :
48- """Render the pretty-printed object.
49-
50- Returns:
51- The rendered pretty-print.
52- """
53- return self ._renderable
40+ super ().__init__ (name = name , id = id , classes = classes )
41+ self .update (object )
5442
5543 def update (self , object : Any ) -> None :
5644 """Update the content of the pretty widget.
5745
5846 Args:
5947 object: The object to pretty-print.
6048 """
61- self ._renderable = PrettyRenderable (object )
62- self .clear_cached_dimensions ()
63- self .refresh (layout = True )
49+ super ().update (PrettyRenderable (object ))
Original file line number Diff line number Diff line change @@ -4538,3 +4538,35 @@ def compose(self) -> ComposeResult:
45384538 )
45394539
45404540 assert snap_compare (StreamApp ())
4541+
4542+
4543+ def test_pretty_auto (snap_compare ):
4544+ """Test that pretty works with auto dimensions.
4545+
4546+ You should see 'Hello World' including strings, 3 times in a purple box, top left.
4547+
4548+ """
4549+ from textual .widgets import Pretty
4550+
4551+ class Demo (App ):
4552+ CSS = """
4553+ Vertical {
4554+ background: blue 30%;
4555+ height: auto;
4556+ width: auto;
4557+ }
4558+
4559+ Pretty {
4560+ width: auto;
4561+ height: auto;
4562+ background: red 30%;
4563+ }
4564+ """
4565+
4566+ def compose (self ) -> ComposeResult :
4567+ with Vertical ():
4568+ yield Pretty ("hello world" )
4569+ yield Pretty ("hello world" )
4570+ yield Pretty ("hello world" )
4571+
4572+ assert snap_compare (Demo ())
You can’t perform that action at this time.
0 commit comments