From 9be16987624511eb48c99d2e4585761bb725872e Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Wed, 20 May 2026 21:00:16 -0700 Subject: [PATCH] Add syntax highlighting to previews. --- borgmatic/actions/browse/controller.py | 2 +- borgmatic/actions/browse/view.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/borgmatic/actions/browse/controller.py b/borgmatic/actions/browse/controller.py index 35273c5a..6716febe 100644 --- a/borgmatic/actions/browse/controller.py +++ b/borgmatic/actions/browse/controller.py @@ -70,7 +70,7 @@ def get_archive_files(config, repository, archive_name, list_path=None): ) -READLINES_HINT_BYTES = 1000 +READLINES_HINT_BYTES = 2000 def get_archive_file_content(config, repository, archive_name, file_path): diff --git a/borgmatic/actions/browse/view.py b/borgmatic/actions/browse/view.py index b665e84f..fe9fb722 100644 --- a/borgmatic/actions/browse/view.py +++ b/borgmatic/actions/browse/view.py @@ -6,6 +6,7 @@ import logging import borgmatic.actions.browse.controller +import rich.syntax import rich.text import textual._context import textual.app @@ -129,7 +130,8 @@ def load_file_preview(browse_app, file_preview, config, repository, archive_name file_content = borgmatic.actions.browse.controller.get_archive_file_content(config, repository, archive_name, file_path) browse_app.call_from_thread(timer.stop) - browse_app.call_from_thread(file_preview.update, file_content) + syntax_lexer = rich.syntax.Syntax.guess_lexer(file_path, file_content) + browse_app.call_from_thread(file_preview.update, rich.syntax.Syntax(file_content, syntax_lexer)) OPTION_LIST_BINDINGS = textual.widgets.OptionList.BINDINGS + [