Called when path changes.
(self, path: str | None)
| 63 | self.path = str(event.path) |
| 64 | |
| 65 | def watch_path(self, path: str | None) -> None: |
| 66 | """Called when path changes.""" |
| 67 | code_view = self.query_one("#code", Static) |
| 68 | if path is None: |
| 69 | code_view.update("") |
| 70 | return |
| 71 | try: |
| 72 | code = Path(path).read_text(encoding="utf-8") |
| 73 | syntax = highlight(code, path=path) |
| 74 | except Exception: |
| 75 | code_view.update(Traceback(theme="github-dark", width=None)) |
| 76 | self.sub_title = "ERROR" |
| 77 | else: |
| 78 | code_view.update(syntax) |
| 79 | self.query_one("#code-view").scroll_home(animate=False) |
| 80 | self.sub_title = path |
| 81 | |
| 82 | def action_toggle_files(self) -> None: |
| 83 | """Called in response to key binding.""" |
no test coverage detected