diff --git a/src/hosts/tui/import_export_modal.py b/src/hosts/tui/import_export_modal.py index 7f1b8a9..b3c792f 100644 --- a/src/hosts/tui/import_export_modal.py +++ b/src/hosts/tui/import_export_modal.py @@ -3,6 +3,7 @@ from dataclasses import dataclass from pathlib import Path +from rich.text import Text from textual.app import ComposeResult from textual.binding import Binding from textual.containers import Grid, Horizontal, Vertical @@ -258,6 +259,8 @@ class ImportModal(_FormatModal): class ParentDirectoryTree(DirectoryTree): """Directory tree with a conventional parent entry above its root.""" + PARENT_ICON = "↑ " + def _populate_node(self, node, content) -> None: super()._populate_node(node, content) if node is not self.root or node.data is None: @@ -272,6 +275,18 @@ class ParentDirectoryTree(DirectoryTree): before=0, ) + def render_label(self, node, base_style, style) -> Text: + """Render the parent entry as navigation rather than as a file.""" + if str(node.label) != "..": + return super().render_label(node, base_style, style) + + label = node.label.copy() + label.stylize(style) + label.stylize_before( + self.get_component_rich_style("directory-tree--folder", partial=True) + ) + return Text.assemble((self.PARENT_ICON, base_style), label) + class FileBrowserModal(ModalScreen[Path | None]): """A keyboard-accessible directory tree for file and folder selection.""" diff --git a/tests/test_import_export_workflow.py b/tests/test_import_export_workflow.py index e6e37a3..339d87f 100644 --- a/tests/test_import_export_workflow.py +++ b/tests/test_import_export_workflow.py @@ -3,6 +3,7 @@ from unittest.mock import Mock import pytest +from rich.style import Style from textual.containers import Vertical from textual.widgets import Button, DirectoryTree, Input, RadioButton, RadioSet, Static @@ -141,6 +142,9 @@ async def test_file_browser_presents_parent_directory_as_dot_dot(tmp_path): await pilot.pause() assert str(tree.root.children[0].label) == ".." + assert tree.render_label( + tree.root.children[0], Style(), Style() + ).plain.startswith("↑ ") assert len(browser.query("#up-button")) == 0 tree.focus()