Switch from a Static to a RichLog for file preview so we can get scrolling.

This commit is contained in:
Dan Helfman
2026-05-23 19:20:24 -07:00
parent c9ba0762f0
commit 94a2d68198
4 changed files with 35 additions and 11 deletions
+6 -2
View File
@@ -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 ...]'
)
+7 -4
View File
@@ -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)}')
+20 -4
View File
@@ -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)
+2 -1
View File
@@ -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))