Avoid flicker when starting kittens such as the hints kitten

Fixes #4674
This commit is contained in:
Kovid Goyal
2022-03-23 15:55:11 +05:30
parent 1837168b0b
commit 6dc1617429
14 changed files with 86 additions and 18 deletions

View File

@@ -159,6 +159,7 @@ class Hints(Handler):
def initialize(self) -> None:
self.init_terminal_state()
self.draw_screen()
self.cmd.overlay_ready()
def on_text(self, text: str, in_bracketed_paste: bool = False) -> None:
changed = False
@@ -752,7 +753,7 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i
}[action])(*cmd)
@result_handler(type_of_input='screen-ansi')
@result_handler(type_of_input='screen-ansi', has_ready_notification=True)
def handle_result(args: List[str], data: Dict[str, Any], target_window_id: int, boss: BossType) -> None:
if data['customize_processing']:
m = load_custom_processor(data['customize_processing'])

View File

@@ -69,6 +69,7 @@ def create_kitten_handler(kitten: str, orig_args: List[str]) -> Any:
ans = partial(m['end'], [kitten] + orig_args)
setattr(ans, 'type_of_input', getattr(m['end'], 'type_of_input', None))
setattr(ans, 'no_ui', getattr(m['end'], 'no_ui', False))
setattr(ans, 'has_ready_notification', getattr(m['end'], 'has_ready_notification', False))
return ans

View File

@@ -206,18 +206,23 @@ class HandleResult:
type_of_input: Optional[str] = None
no_ui: bool = False
def __init__(self, impl: Callable[..., Any], type_of_input: Optional[str], no_ui: bool):
def __init__(self, impl: Callable[..., Any], type_of_input: Optional[str], no_ui: bool, has_ready_notification: bool):
self.impl = impl
self.no_ui = no_ui
self.type_of_input = type_of_input
self.has_ready_notification = has_ready_notification
def __call__(self, args: Sequence[str], data: Any, target_window_id: int, boss: BossType) -> Any:
return self.impl(args, data, target_window_id, boss)
def result_handler(type_of_input: Optional[str] = None, no_ui: bool = False) -> Callable[[Callable[..., Any]], HandleResult]:
def result_handler(
type_of_input: Optional[str] = None,
no_ui: bool = False,
has_ready_notification: bool = False
) -> Callable[[Callable[..., Any]], HandleResult]:
def wrapper(impl: Callable[..., Any]) -> HandleResult:
return HandleResult(impl, type_of_input, no_ui)
return HandleResult(impl, type_of_input, no_ui, has_ready_notification)
return wrapper

View File

@@ -413,6 +413,11 @@ def restore_colors() -> str:
return '\x1b[#Q'
@cmd
def overlay_ready() -> str:
return '\x1bP@kitty-overlay-ready|\x1b\\'
@cmd
def write_to_clipboard(data: Union[str, bytes], use_primary: bool = False) -> str:
from base64 import standard_b64encode

View File

@@ -377,6 +377,7 @@ class UnicodeInput(Handler):
def initialize(self) -> None:
self.init_terminal_state()
self.draw_screen()
self.cmd.overlay_ready()
def draw_title_bar(self) -> None:
entries = []
@@ -585,7 +586,7 @@ def main(args: List[str]) -> Optional[str]:
return None
@result_handler()
@result_handler(has_ready_notification=True)
def handle_result(args: List[str], current_char: str, target_window_id: int, boss: BossType) -> None:
w = boss.window_id_map.get(target_window_id)
if w is not None: