Get it working even with 2 row windows assuming they are wide enough to fit the title on a single line

This commit is contained in:
Kovid Goyal 2022-01-21 21:46:27 +05:30
parent dd72deb546
commit 17e31565e2
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -174,8 +174,9 @@ class Choose(Handler):
self.print(end='\r\n'*y) self.print(end='\r\n'*y)
if self.cli_opts.message: if self.cli_opts.message:
y += self.draw_long_text(self.cli_opts.message) y += self.draw_long_text(self.cli_opts.message)
self.print() if self.screen_size.rows > 2:
y += 1 self.print()
y += 1
if self.cli_opts.type == 'yesno': if self.cli_opts.type == 'yesno':
self.draw_yesno(y) self.draw_yesno(y)
else: else:
@ -187,11 +188,11 @@ class Choose(Handler):
current_ranges: Dict[str, int] = {} current_ranges: Dict[str, int] = {}
width = self.screen_size.cols - 2 width = self.screen_size.cols - 2
def commit_line() -> None: def commit_line(end: str = '\r\n') -> None:
nonlocal current_line, y nonlocal current_line, y
extra = (width - wcswidth(current_line)) // 2 extra = (width - wcswidth(current_line)) // 2
x = extra + 1 x = extra + 1
self.print(' ' * x + current_line) self.print(' ' * x + current_line, end=end)
for letter, sz in current_ranges.items(): for letter, sz in current_ranges.items():
self.clickable_ranges[letter] = Range(x, x + sz - 3, y) self.clickable_ranges[letter] = Range(x, x + sz - 3, y)
x += sz x += sz
@ -210,7 +211,7 @@ class Choose(Handler):
current_line += text current_line += text
current_ranges[letter] = sz current_ranges[letter] = sz
if current_line: if current_line:
commit_line() commit_line(end='')
def draw_yesno(self, y: int) -> None: def draw_yesno(self, y: int) -> None:
sep = ' ' * 3 sep = ' ' * 3