From d5fe572a0ee5d55fa5c9e83647a8d4e0725d8fb8 Mon Sep 17 00:00:00 2001 From: Matt Wozniski Date: Fri, 2 Feb 2024 11:01:43 -0500 Subject: [PATCH] Use Textual's `TextArea.code_editor` if available Textual 0.48 introduces a breaking change for the `TextArea` widget: line wrapping is now enabled by default. Since we don't want line wrapping, we need to disable that. Fortunately, a new alternative constructor called `TextArea.code_editor` is introduced, and constructing the `TextArea` using it retains the old behavior. Unfortunately, that alternative constructor didn't exist prior to Textual 0.48, so we need to conditionally fall back to simply using the `TextArea` constructor when `TextArea.code_editor` doesn't exist. Signed-off-by: Matt Wozniski --- src/memray/reporters/tree.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/memray/reporters/tree.py b/src/memray/reporters/tree.py index ea999e7eef..d8b0603417 100644 --- a/src/memray/reporters/tree.py +++ b/src/memray/reporters/tree.py @@ -174,7 +174,9 @@ def compose(self) -> ComposeResult: else: lines = [] - text = TextArea( + # For Textual 0.48 and up, use the TextArea.code_editor() constructor. + # This used to be the default, so fall back to the main constructor. + text = getattr(TextArea, "code_editor", TextArea)( "\n".join(lines), language="python", theme="dracula", id="textarea" ) text.select_line(delta + 1)