diff --git a/borgmatic/actions/browse/archive.py b/borgmatic/actions/browse/archive.py index d188915a..c31a8018 100644 --- a/borgmatic/actions/browse/archive.py +++ b/borgmatic/actions/browse/archive.py @@ -78,7 +78,7 @@ def get_archive_files(config, repository, archive_name, list_path=None): ) -READLINES_HINT_BYTES = 2000 +READLINES_HINT_BYTES = 100000 def get_archive_file_content(config, repository, archive_name, file_path): @@ -104,4 +104,8 @@ def get_archive_file_content(config, repository, archive_name, file_path): content = ''.join(line.decode() for line in lines) - return content if len(content) < READLINES_HINT_BYTES else f'{content}[...]' + return ( + content + if len(content) < READLINES_HINT_BYTES + else f'{content}[... truncated for display ...]' + ) diff --git a/borgmatic/actions/browse/loading.py b/borgmatic/actions/browse/loading.py index 60438553..44bb7b69 100644 --- a/borgmatic/actions/browse/loading.py +++ b/borgmatic/actions/browse/loading.py @@ -14,8 +14,11 @@ def update_inline_loading_indicator(widget): 'loading-indicator', (str(widget.get_option('loading-indicator').prompt) + '.').replace('....', ''), ) - elif isinstance(widget, textual.widgets.Static): - widget.update((str(widget.content) + '.').replace('....', '')) + elif isinstance(widget, textual.widgets.RichLog): + with contextlib.suppress(IndexError): + loading_message = str(widget.lines[0].text) + widget.clear() + widget.write((loading_message + '.').replace('....', '')) else: raise ValueError(f'Unsupported widget type: {type(widget)}') @@ -28,8 +31,8 @@ def add_inline_loading_indicator(widget): loading_option = textual.widgets.option_list.Option(loading_message, id='loading-indicator') widget.add_option(loading_option) widget.highlighted = None - elif isinstance(widget, textual.widgets.Static): - widget.update(loading_message) + elif isinstance(widget, textual.widgets.RichLog): + widget.write(loading_message) else: raise ValueError(f'Unsupported widget type: {type(widget)}') diff --git a/borgmatic/actions/browse/panels.py b/borgmatic/actions/browse/panels.py index d09ccf2b..aad66e5e 100644 --- a/borgmatic/actions/browse/panels.py +++ b/borgmatic/actions/browse/panels.py @@ -10,10 +10,10 @@ import borgmatic.actions.browse.workers OPTION_LIST_BINDINGS = ( *textual.widgets.OptionList.BINDINGS, textual.binding.Binding( - key='up,k', action='cursor_up', description='up', show=True, priority=True + key='up,k', action='cursor_up', description='scroll up', show=True, priority=True ), textual.binding.Binding( - key='down,j', action='cursor_down', description='down', show=True, priority=True + key='down,j', action='cursor_down', description='scroll down', show=True, priority=True ), textual.binding.Binding( key='enter', action='select', description='select', show=True, priority=True @@ -124,13 +124,28 @@ class Directory_list(textual.widgets.OptionList): self.highlighted_option_changed = True -class File_preview(textual.widgets.Static): +class File_preview(textual.widgets.RichLog): + BINDINGS = [ + *textual.widgets.RichLog.BINDINGS, + textual.binding.Binding( + key='up', action='scroll_up', description='scroll up', show=True, priority=True + ), + textual.binding.Binding( + key='down', action='scroll_down', description='scroll down', show=True, priority=True + ), + textual.binding.Binding( + key='pageup', action='page_up', description='page up', show=True, priority=True + ), + textual.binding.Binding( + key='pagedown', action='page_down', description='page down', show=True, priority=True + ), + ] + def __init__(self, config, repository, archive_name, file_path): self.config = config self.repository = repository self.archive_name = archive_name self.file_path = file_path - self.can_focus = True super().__init__(classes='panel') self.border_title = ' '.join( @@ -142,6 +157,7 @@ class File_preview(textual.widgets.Static): 'preview', ) ) + self.auto_scroll = False timer = borgmatic.actions.browse.loading.add_inline_loading_indicator(self) diff --git a/borgmatic/actions/browse/workers.py b/borgmatic/actions/browse/workers.py index 26267123..210009ff 100644 --- a/borgmatic/actions/browse/workers.py +++ b/borgmatic/actions/browse/workers.py @@ -89,4 +89,5 @@ def load_file_preview(browse_app, file_preview, config, repository, archive_name browse_app.call_from_thread(timer.stop) 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)) + browse_app.call_from_thread(file_preview.clear) + browse_app.call_from_thread(file_preview.write, rich.syntax.Syntax(file_content, syntax_lexer))