def main(args: List[str]) -> Response: # For some reason importing readline in a key handler in the main kitty process # causes a crash of the python interpreter, probably because of some global # lock global readline msg = 'Ask the user for input' try: cli_opts, items = parse_args(args[1:], option_text, '', msg, 'kitty ask', result_class=AskCLIOptions) except SystemExit as e: if e.code != 0: print(e.args[0]) input('Press enter to quit...') raise SystemExit(e.code) if cli_opts.type in ('yesno', 'choices'): loop = Loop() handler = Choose(cli_opts) loop.loop(handler) return {'items': items, 'response': handler.response} import readline as rl readline = rl from kitty.shell import init_readline init_readline() response = None with alternate_screen(), HistoryCompleter(cli_opts.name): if cli_opts.message: print(styled(cli_opts.message, bold=True)) prompt = '> ' with suppress(KeyboardInterrupt, EOFError): response = input(prompt) return {'items': items, 'response': response}
def main(args): # For some reason importing readline in a key handler in the main kitty process # causes a crash of the python interpreter, probably because of some global # lock global readline import readline as rl readline = rl from kitty.shell import init_readline msg = 'Ask the user for input' try: args, items = parse_args(args[1:], option_text, '', msg, 'kitty ask', result_class=AskCLIOptions) except SystemExit as e: if e.code != 0: print(e.args[0]) input('Press enter to quit...') raise SystemExit(e.code) init_readline(readline) ans = {'items': items} with alternate_screen(), HistoryCompleter(args.name): if args.message: print(styled(args.message, bold=True)) prompt = '> ' with suppress(KeyboardInterrupt, EOFError): ans['response'] = input(prompt) return ans
def __enter__(self) -> 'ReadPath': self.matches: List[str] = [] import readline from kitty.shell import init_readline init_readline() readline.set_completer(self.complete) self.delims = readline.get_completer_delims() readline.set_completer_delims('\n\t') readline.clear_history() for x in history_list(): readline.add_history(x) return self
def main(args: List[str]) -> Response: # For some reason importing readline in a key handler in the main kitty process # causes a crash of the python interpreter, probably because of some global # lock global readline msg = 'Ask the user for input' try: cli_opts, items = parse_args(args[1:], option_text, '', msg, 'kitty ask', result_class=AskCLIOptions) except SystemExit as e: if e.code != 0: print(e.args[0]) input('Press Enter to quit') raise SystemExit(e.code) if cli_opts.type in ('yesno', 'choices'): loop = Loop() handler = Choose(cli_opts) loop.loop(handler) return {'items': items, 'response': handler.response} prompt = cli_opts.prompt if prompt[0] == prompt[-1] and prompt[0] in '\'"': prompt = prompt[1:-1] if cli_opts.type == 'password': loop = Loop() phandler = Password(cli_opts, prompt) loop.loop(phandler) return {'items': items, 'response': phandler.response} import readline as rl readline = rl from kitty.shell import init_readline init_readline() response = None with alternate_screen(), HistoryCompleter(cli_opts.name): if cli_opts.message: print(styled(cli_opts.message, bold=True)) with suppress(KeyboardInterrupt, EOFError): if cli_opts.default: def prefill_text() -> None: readline.insert_text(cli_opts.default or '') readline.redisplay() readline.set_pre_input_hook(prefill_text) response = input(prompt) readline.set_pre_input_hook() else: response = input(prompt) return {'items': items, 'response': response}
def main(args): if sys.stdin.isatty(): if '--help' not in args and '-h' not in args: print('You must pass the text to be hinted on STDIN', file=sys.stderr) input('Press Enter to quit') return global readline import readline as rl readline = rl from kitty.shell import init_readline init_readline(readline) sys.stdin = open(os.ctermid()) term = "" with alternate_screen(): with suppress(KeyboardInterrupt, EOFError): term = input("Enter search regex: ") if term == "": return fcntl.fcntl(sys.__stdin__.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) def replace_func(matchobj): return styled(matchobj.group(0), bold=True, fg="black", bg="green") try: while True: if select.select([sys.__stdin__], [], [], 0) == ([sys.__stdin__], [], []): text = sys.__stdin__.read() text = re.sub(term, replace_func, text, count=0) sys.stdout.write(text) except KeyboardInterrupt: sys.stderr.write("exiting\n") pass return