From d8e43a34128449402d1a63c416185c3436ee44ff Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 30 Aug 2022 16:45:14 +0530 Subject: [PATCH] macOS: Fix regression in 0.26.0 that caused asking the user for a line of input such as for set_tab_title to not work Apparently libedit doesn't work in the forked process when the parent process is run via Launch Services. I cant be bothered to investigate why, given that libedit is closed source. macOS users will just have to live without history/completion in the ask kitten until I get around to writing a replacement for readline/libedit. And on a personal note, macOS >> Necrotizing fasciitis Fixes #5447 --- docs/changelog.rst | 2 ++ kittens/ask/main.py | 19 ++++++++++++++++--- kitty/main.py | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6752e8009..e831433a6 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -42,6 +42,8 @@ Detailed list of changes - Fix regression in 0.26.0 that caused launching kitty without working STDIO handles to result in high CPU usage and prewarming failing (:iss:`5444`) +- macOS: Fix regression in 0.26.0 that caused asking the user for a line of input such as for :ac:`set_tab_title` to not work (:iss:`5447`) + 0.26.1 [2022-08-30] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kittens/ask/main.py b/kittens/ask/main.py index 776af8d73..be87f19ea 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -158,14 +158,17 @@ def extra_for(width: int, screen_width: int) -> int: class Password(Handler): - def __init__(self, cli_opts: AskCLIOptions, prompt: str) -> None: + def __init__(self, cli_opts: AskCLIOptions, prompt: str, is_password: bool = True, initial_text: str = '') -> None: self.cli_opts = cli_opts self.prompt = prompt + self.initial_text = initial_text from kittens.tui.line_edit import LineEdit - self.line_edit = LineEdit(is_password=True) + self.line_edit = LineEdit(is_password=is_password) def initialize(self) -> None: self.cmd.set_cursor_shape('beam') + if self.initial_text: + self.line_edit.on_text(self.initial_text, True) self.draw_screen() @Handler.atomic_update @@ -205,7 +208,7 @@ class Password(Handler): return '' -class Choose(Handler): +class Choose(Handler): # {{{ mouse_tracking = MouseTracking.buttons_only def __init__(self, cli_opts: AskCLIOptions) -> None: @@ -441,6 +444,7 @@ class Choose(Handler): def on_interrupt(self) -> None: self.quit_loop(1) on_eot = on_interrupt +# }}} def main(args: List[str]) -> Response: @@ -472,6 +476,15 @@ def main(args: List[str]) -> Response: loop.loop(phandler) return {'items': items, 'response': phandler.response} + rd = getattr(sys, 'kitty_run_data') + if 'prewarmed' in rd and 'launched_by_launch_services' in rd: + # bloody libedit doesnt work in the prewarmed process run from launch + # services for reasons I really dont care enough to investigate + loop = Loop() + phandler = Password(cli_opts, prompt, is_password=False, initial_text=cli_opts.default or '') + loop.loop(phandler) + return {'items': items, 'response': phandler.response} + import readline as rl readline = rl from kitty.shell import init_readline diff --git a/kitty/main.py b/kitty/main.py index 4cc37217b..ad5d63820 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -379,6 +379,7 @@ def _main() -> None: if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1': os.chdir(os.path.expanduser('~')) args = macos_cmdline(args) + getattr(sys, 'kitty_run_data')['launched_by_launch_services'] = True try: cwd_ok = os.path.isdir(os.getcwd()) except Exception: