Fix misaligned table headers (#3120)

This commit is contained in:
Daniel Girtler 2025-01-22 04:41:47 +11:00 committed by GitHub
parent 64f08cc890
commit 985775b143
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 6 deletions

View File

@ -849,7 +849,7 @@ class SelectMenu(AbstractCurses):
self._interrupt_warning = reset_warning_msg
self._header = header
header_offset = self._get_header_offset()
header_offset = self._get_header_offset(header)
self._headers = self.get_header_entries(header, offset=header_offset)
if self._interrupt_warning is None:
@ -875,11 +875,19 @@ class SelectMenu(AbstractCurses):
self._init_viewports(preview_size)
def _get_header_offset(self) -> int:
# any changes here will impact the list manager table view
offset = len(self._cursor_char) + 1
if self._multi:
offset += 3
def _get_header_offset(self, header: str | None) -> int:
# WARNING: any changes here will impact the list manager table view
if self._orientation == Orientation.HORIZONTAL:
return 0
lines = header.split('\n') if header else []
table_header = [line for line in lines if '|' in line]
longest_header = len(table_header[0]) if table_header else 0
longest_entry = self._item_group.max_width
delta = abs(longest_header - longest_entry)
offset = delta + 3 # 3 because it seems to align it...
return offset
def run(self) -> Result: