def main(): if isosx: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not isosx: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') try: locale.setlocale(locale.LC_ALL, '') except Exception: print('Failed to set locale with no LANG, ignoring', file=sys.stderr) if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1' and getattr(sys, 'frozen', True): os.chdir(os.path.expanduser('~')) if not os.path.isdir(os.getcwd()): os.chdir(os.path.expanduser('~')) args = option_parser().parse_args() if getattr(args, 'detach', False): detach() if args.cmd: exec(args.cmd) return if args.replay_commands: from kitty.client import main main(args.replay_commands) return config = args.config or (defconf, ) overrides = (a.replace('=', ' ', 1) for a in args.override or ()) opts = load_config(*config, overrides=overrides) change_wcwidth(not opts.use_system_wcwidth) glfw_set_error_callback(on_glfw_error) enable_automatic_opengl_error_checking(args.debug_gl) if GLFW_X11_WM_CLASS_CLASS is not None: glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, opts.cls) if not glfw_init(): raise SystemExit('GLFW initialization failed') try: if args.profile: tf = tempfile.NamedTemporaryFile(prefix='kitty-profiling-stats-') args.profile = tf.name import cProfile import pstats pr = cProfile.Profile() pr.enable() run_app(opts, args) pr.disable() pr.create_stats() s = pstats.Stats(pr) s.add(args.profile) tf.close() s.strip_dirs() s.sort_stats('time', 'name') s.print_stats(30) else: run_app(opts, args) finally: glfw_terminate()
def _main(): with suppress(AttributeError): # python compiled without threading sys.setswitchinterval(1000.0) # we have only a single python thread if is_macos: ensure_macos_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not is_macos: raise log_error('Failed to set locale with LANG:', os.environ.get('LANG')) os.environ.pop('LANG', None) try: locale.setlocale(locale.LC_ALL, '') except Exception: log_error('Failed to set locale with no LANG, ignoring') # Ensure kitty is in PATH rpath = os.path.dirname(kitty_exe()) items = frozenset(os.environ['PATH'].split(os.pathsep)) if rpath and rpath not in items: os.environ['PATH'] = rpath + os.pathsep + os.environ.get('PATH', '') 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('~')) args, rest = parse_args(args=args) args.args = rest if args.debug_config: create_opts(args, debug_config=True) return if getattr(args, 'detach', False): detach() if args.replay_commands: from kitty.client import main main(args.replay_commands) return if args.single_instance: is_first = single_instance(args.instance_group) if not is_first: talk_to_instance(args) return bad_lines = [] opts = create_opts(args, accumulate_bad_lines=bad_lines) init_glfw(opts, args.debug_keyboard) setup_environment(opts, args) try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies run_app(opts, args, bad_lines) finally: glfw_terminate()
def main(): try: sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading if is_macos: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not is_macos: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') try: locale.setlocale(locale.LC_ALL, '') except Exception: print('Failed to set locale with no LANG, ignoring', file=sys.stderr) if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1' and getattr(sys, 'frozen', True): os.chdir(os.path.expanduser('~')) if not os.path.isdir(os.getcwd()): os.chdir(os.path.expanduser('~')) args, rest = parse_args() args.args = rest if getattr(args, 'detach', False): detach() if args.cmd: exec(args.cmd) return if args.replay_commands: from kitty.client import main main(args.replay_commands) return if args.single_instance: is_first = single_instance(args.instance_group) if not is_first: import json data = { 'cmd': 'new_instance', 'args': tuple(sys.argv), 'startup_id': os.environ.get('DESKTOP_STARTUP_ID') } data = json.dumps(data, ensure_ascii=False).encode('utf-8') single_instance.socket.sendall(data) return opts = create_opts(args) change_wcwidth(not opts.use_system_wcwidth) init_graphics() try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies install_sigchld_handler() run_app(opts, args) signal.signal(signal.SIGCHLD, signal.SIG_DFL) finally: glfw_terminate()
def _main(): 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('~')) args, rest = parse_args(args=args) args.args = rest if args.debug_config: create_opts(args, debug_config=True) return if getattr(args, 'detach', False): detach() if args.replay_commands: from kitty.client import main main(args.replay_commands) return if args.single_instance: is_first = single_instance(args.instance_group) if not is_first: talk_to_instance(args) return bad_lines = [] opts = create_opts(args, accumulate_bad_lines=bad_lines) init_glfw(opts, args.debug_keyboard) setup_environment(opts, args) try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies run_app(opts, args, bad_lines) finally: glfw_terminate()
def main(): try: sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading if isosx: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not isosx: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') try: locale.setlocale(locale.LC_ALL, '') except Exception: print('Failed to set locale with no LANG, ignoring', file=sys.stderr) if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1' and getattr(sys, 'frozen', True): os.chdir(os.path.expanduser('~')) if not os.path.isdir(os.getcwd()): os.chdir(os.path.expanduser('~')) args = option_parser().parse_args() if getattr(args, 'detach', False): detach() if args.cmd: exec(args.cmd) return if args.replay_commands: from kitty.client import main main(args.replay_commands) return config = args.config or (defconf, ) overrides = (a.replace('=', ' ', 1) for a in args.override or ()) opts = load_config(*config, overrides=overrides) change_wcwidth(not opts.use_system_wcwidth) if GLFW_X11_WM_CLASS_CLASS is not None: glfw_init_hint_string(GLFW_X11_WM_CLASS_CLASS, args.cls) if not glfw_init(): raise SystemExit('GLFW initialization failed') try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies install_sigchld_handler() run_app(opts, args) signal.signal(signal.SIGCHLD, signal.SIG_DFL) finally: glfw_terminate()
def main(): if os.environ.pop('KITTY_LAUNCHED_BY_LAUNCH_SERVICES', None) == '1' and getattr(sys, 'frozen', True): os.chdir(os.path.expanduser('~')) args = option_parser().parse_args() if args.cmd: exec(args.cmd) return if args.replay_commands: from kitty.client import main main(args.replay_commands) return config = args.config or (defconf, ) overrides = (a.replace('=', ' ', 1) for a in args.override or ()) opts = load_config(*config, overrides=overrides) change_wcwidth(not opts.use_system_wcwidth) glfw_set_error_callback(on_glfw_error) enable_automatic_opengl_error_checking(args.debug_gl) if not glfw_init(): raise SystemExit('GLFW initialization failed') try: if args.profile: tf = tempfile.NamedTemporaryFile(prefix='kitty-profiling-stats-') args.profile = tf.name import cProfile import pstats pr = cProfile.Profile() pr.enable() run_app(opts, args) pr.disable() pr.create_stats() s = pstats.Stats(pr) s.add(args.profile) tf.close() s.strip_dirs() s.sort_stats('time', 'name') s.print_stats(30) else: run_app(opts, args) finally: glfw_terminate()
def main(): args = option_parser().parse_args() if args.cmd: exec(args.cmd) return if args.replay_commands: from kitty.client import main main(args.replay_commands) return opts = load_config(args.config) glfw_set_error_callback(on_glfw_error) enable_automatic_opengl_error_checking(False) if not glfw_init(): raise SystemExit('GLFW initialization failed') try: if args.profile: tf = tempfile.NamedTemporaryFile(prefix='kitty-profiling-stats-') args.profile = tf.name import cProfile import pstats pr = cProfile.Profile() pr.enable() run_app(opts, args) pr.disable() pr.create_stats() s = pstats.Stats(pr) s.add(args.profile) tf.close() s.strip_dirs() s.sort_stats('time', 'name') s.print_stats(30) else: run_app(opts, args) finally: glfw_terminate() os.closerange(3, 100)
def _main(): try: sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading if is_macos: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not is_macos: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') try: locale.setlocale(locale.LC_ALL, '') except Exception: print('Failed to set locale with no LANG, ignoring', file=sys.stderr) # Ensure kitty is in PATH rpath = os.path.dirname(kitty_exe()) items = frozenset(os.environ['PATH'].split(os.pathsep)) if rpath and rpath not in items: os.environ['PATH'] += os.pathsep + rpath 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() try: cwd_ok = os.path.isdir(os.getcwd()) except Exception: cwd_ok = False if not cwd_ok: os.chdir(os.path.expanduser('~')) args, rest = parse_args(args=args) args.args = rest if args.debug_config: init_glfw(args.debug_keyboard) # needed for parsing native keysyms create_opts(args, debug_config=True) return if getattr(args, 'detach', False): detach() if args.replay_commands: from kitty.client import main main(args.replay_commands) return if args.single_instance: is_first = single_instance(args.instance_group) if not is_first: talk_to_instance(args) return init_glfw(args.debug_keyboard) # needed for parsing native keysyms opts = create_opts(args) if opts.editor != '.': os.environ['EDITOR'] = opts.editor try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies run_app(opts, args) finally: glfw_terminate()
def _main(): try: sys.setswitchinterval(1000.0) # we have only a single python thread except AttributeError: pass # python compiled without threading if is_macos: ensure_osx_locale() try: locale.setlocale(locale.LC_ALL, '') except Exception: if not is_macos: raise print('Failed to set locale with LANG:', os.environ.get('LANG'), file=sys.stderr) os.environ.pop('LANG') try: locale.setlocale(locale.LC_ALL, '') except Exception: print('Failed to set locale with no LANG, ignoring', file=sys.stderr) # Ensure kitty is in PATH rpath = getattr(sys, 'bundle_exe_dir', None) items = frozenset(os.environ['PATH'].split(os.pathsep)) if not rpath: for candidate in items: if os.access(os.path.join(candidate, 'kitty'), os.X_OK): break else: rpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'launcher') if rpath and rpath not in items: os.environ['PATH'] += os.pathsep + rpath 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() try: cwd_ok = os.path.isdir(os.getcwd()) except Exception: cwd_ok = False if not cwd_ok: os.chdir(os.path.expanduser('~')) args, rest = parse_args(args=args) args.args = rest if args.debug_config: create_opts(args, debug_config=True) return if getattr(args, 'detach', False): detach() if args.replay_commands: from kitty.client import main main(args.replay_commands) return if args.single_instance: is_first = single_instance(args.instance_group) if not is_first: import json data = {'cmd': 'new_instance', 'args': tuple(sys.argv), 'startup_id': os.environ.get('DESKTOP_STARTUP_ID'), 'cwd': os.getcwd()} data = json.dumps(data, ensure_ascii=False).encode('utf-8') single_instance.socket.sendall(data) return opts = create_opts(args) init_graphics() try: with setup_profiling(args): # Avoid needing to launch threads to reap zombies run_app(opts, args) finally: glfw_terminate()