Ejemplo n.º 1
0
def _main() -> None:
    running_in_kitty(True)
    with suppress(AttributeError):  # python compiled without threading
        sys.setswitchinterval(1000.0)  # we have only a single python thread

    try:
        set_locale()
    except Exception:
        log_error('Failed to set locale, ignoring')

    # Ensure the correct kitty is in PATH
    rpath = sys._xoptions.get('bundle_exe_dir')
    if rpath:
        modify_path = is_macos or getattr(
            sys, 'frozen',
            False) or sys._xoptions.get('kitty_from_source') == '1'
        if modify_path or not shutil.which('kitty'):
            existing_paths = list(
                filter(None,
                       os.environ.get('PATH', '').split(os.pathsep)))
            existing_paths.insert(0, rpath)
            os.environ['PATH'] = os.pathsep.join(existing_paths)

    args = sys.argv[1:]
    if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES',
                                   None) == '1':
        os.chdir(os.path.expanduser('~'))
        args = macos_cmdline(args)
    try:
        cwd_ok = os.path.isdir(os.getcwd())
    except Exception:
        cwd_ok = False
    if not cwd_ok:
        os.chdir(os.path.expanduser('~'))
    cli_opts, rest = parse_args(args=args, result_class=CLIOptions)
    cli_opts.args = rest
    if cli_opts.debug_config:
        create_opts(cli_opts, debug_config=True)
        return
    if cli_opts.detach:
        detach()
    if cli_opts.replay_commands:
        from kitty.client import main as client_main
        client_main(cli_opts.replay_commands)
        return
    if cli_opts.single_instance:
        is_first = single_instance(cli_opts.instance_group)
        if not is_first:
            talk_to_instance(cli_opts)
            return
    bad_lines: List[BadLine] = []
    opts = create_opts(cli_opts, accumulate_bad_lines=bad_lines)
    init_glfw(opts, cli_opts.debug_keyboard)
    setup_environment(opts, cli_opts)
    try:
        with setup_profiling(cli_opts):
            # Avoid needing to launch threads to reap zombies
            run_app(opts, cli_opts, bad_lines)
    finally:
        glfw_terminate()
Ejemplo n.º 2
0
def _main() -> None:
    running_in_kitty(True)
    with suppress(AttributeError):  # python compiled without threading
        sys.setswitchinterval(1000.0)  # we have only a single python thread

    try:
        set_locale()
    except Exception:
        log_error('Failed to set locale, ignoring')

    args = sys.argv[1:]
    if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES',
                                   None) == '1':
        os.chdir(os.path.expanduser('~'))
        args = macos_cmdline(args)
    try:
        cwd_ok = os.path.isdir(os.getcwd())
    except Exception:
        cwd_ok = False
    if not cwd_ok:
        os.chdir(os.path.expanduser('~'))
    cli_opts, rest = parse_args(args=args, result_class=CLIOptions)
    cli_opts.args = rest
    if cli_opts.detach:
        if cli_opts.session == '-':
            from .session import PreReadSession
            cli_opts.session = PreReadSession(sys.stdin.read())
        detach()
    if cli_opts.replay_commands:
        from kitty.client import main as client_main
        client_main(cli_opts.replay_commands)
        return
    if cli_opts.single_instance:
        is_first = single_instance(cli_opts.instance_group)
        if not is_first:
            talk_to_instance(cli_opts)
            return
    bad_lines: List[BadLine] = []
    opts = create_opts(cli_opts, accumulate_bad_lines=bad_lines)
    init_glfw(opts, cli_opts.debug_keyboard, cli_opts.debug_rendering)
    setup_environment(opts, cli_opts)
    if cli_opts.watcher:
        from .window import global_watchers
        global_watchers.set_extra(cli_opts.watcher)
        log_error(
            'The --watcher command line option has been deprecated in favor of using the watcher option in kitty.conf'
        )
    try:
        with setup_profiling(cli_opts):
            # Avoid needing to launch threads to reap zombies
            run_app(opts, cli_opts, bad_lines)
    finally:
        glfw_terminate()
Ejemplo n.º 3
0
def _main() -> None:
    running_in_kitty(True)
    with suppress(AttributeError):  # python compiled without threading
        sys.setswitchinterval(1000.0)  # we have only a single python thread

    try:
        set_locale()
    except Exception:
        log_error('Failed to set locale, ignoring')

    args = sys.argv[1:]
    if is_macos and os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1':
        os.chdir(os.path.expanduser('~'))
        args = macos_cmdline(args)
    try:
        cwd_ok = os.path.isdir(os.getcwd())
    except Exception:
        cwd_ok = False
    if not cwd_ok:
        os.chdir(os.path.expanduser('~'))
    if getattr(sys, 'cmdline_args_for_open', False):
        usage: Optional[str] = 'file_or_url ...'
        appname: Optional[str] = 'kitty +open'
        msg: Optional[str] = (
            'Run kitty and open the specified files or URLs in it, using launch-actions.conf. For details'
            ' see https://sw.kovidgoyal.net/kitty/open_actions/#scripting-the-opening-of-files-with-kitty-on-macos'
            '\n\nAll the normal kitty options can be used.')
    else:
        usage = msg = appname = None
    cli_opts, rest = parse_args(args=args, result_class=CLIOptions, usage=usage, message=msg, appname=appname)
    if getattr(sys, 'cmdline_args_for_open', False):
        setattr(sys, 'cmdline_args_for_open', rest)
        cli_opts.args = []
    else:
        cli_opts.args = rest
    if cli_opts.detach:
        if cli_opts.session == '-':
            from .session import PreReadSession
            cli_opts.session = PreReadSession(sys.stdin.read())
        detach()
    if cli_opts.replay_commands:
        from kitty.client import main as client_main
        client_main(cli_opts.replay_commands)
        return
    if cli_opts.single_instance:
        is_first = single_instance(cli_opts.instance_group)
        if not is_first:
            talk_to_instance(cli_opts)
            return
    bad_lines: List[BadLine] = []
    opts = create_opts(cli_opts, accumulate_bad_lines=bad_lines)
    setup_environment(opts, cli_opts)
    prewarm = fork_prewarm_process(opts)
    if prewarm is None:
        raise SystemExit(1)
    init_glfw(opts, cli_opts.debug_keyboard, cli_opts.debug_rendering)
    if cli_opts.watcher:
        from .window import global_watchers
        global_watchers.set_extra(cli_opts.watcher)
        log_error('The --watcher command line option has been deprecated in favor of using the watcher option in kitty.conf')
    try:
        with setup_profiling():
            # Avoid needing to launch threads to reap zombies
            run_app(opts, cli_opts, prewarm, bad_lines)
    finally:
        glfw_terminate()
        cleanup_ssh_control_masters()