Preserve blanks lines and per line formatting in the ask kitten for the message with choices

This commit is contained in:
Kovid Goyal 2022-08-10 20:10:17 +05:30
parent ef1bee0f48
commit 7be6b28011
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 12 additions and 4 deletions

View File

@ -2,6 +2,7 @@
# License: GPL v3 Copyright: 2018, Kovid Goyal <kovid at kovidgoyal.net>
import os
import re
import sys
from contextlib import suppress
from typing import (
@ -16,11 +17,12 @@ from kitty.typing import BossType, KeyEventType, TypedDict
from kitty.utils import ScreenSize
from ..tui.handler import Handler, result_handler
from ..tui.loop import Loop, MouseEvent
from ..tui.loop import Loop, MouseEvent, debug
from ..tui.operations import MouseTracking, alternate_screen, styled
if TYPE_CHECKING:
import readline
debug
else:
readline = None
@ -198,6 +200,7 @@ class Choose(Handler):
mouse_tracking = MouseTracking.buttons_only
def __init__(self, cli_opts: AskCLIOptions) -> None:
self.prefix_style_pat = re.compile(r'(?:\x1b\[[^m]*?m)+')
self.cli_opts = cli_opts
self.choices: Dict[str, Choice] = {}
self.clickable_ranges: Dict[str, List[Range]] = {}
@ -228,12 +231,17 @@ class Choose(Handler):
self.cmd.set_cursor_visible(True)
def draw_long_text(self, text: str) -> int:
if not text:
self.print('')
return 1
y = 0
width = self.screen_size.cols - 2
m = self.prefix_style_pat.match(text)
prefix = m.group() if m else ''
while text:
t, text = truncate_at_space(text, width)
t = t.strip()
self.print(' ' * extra_for(wcswidth(t), width), styled(t, bold=True), sep='')
self.print(' ' * extra_for(wcswidth(t), width), styled(prefix + t, bold=True), sep='')
y += 1
return y

View File

@ -485,12 +485,12 @@ class Boss:
wid = 0 if window is None else window.id
overlay_window = self.choose(
_('A program wishes to control kitty.\n'
'Action: {1}\n' 'Password: {0}\n' '{2}'
'Action: {1}\n' 'Password: {0}\n\n' '{2}'
).format(
styled(pcmd['password'], fg='yellow'), styled(pcmd['cmd'], fg='magenta'),
'\x1b[m' + styled(_(
'Note that allowing the password will allow all future actions using the same password, in this kitty instance.'
), dim=True)),
), dim=True, italic=True)),
partial(self.remote_cmd_permission_received, pcmd, wid, peer_id),
'a;green:Allow request', 'p;yellow:Allow password', 'r;magenta:Deny request', 'd;red:Deny password',
window=window, default='a'