def _repl(templates: list[typer.FileText] = configurator.templates, macro: list[str] = configurator.macro, target: Optional[str] = configurator.to, repl_name: Optional[str] = typer.Option('', '--repl', help='Name of repl'), separator: Optional[str] = typer.Option( '', '--sep', help='Input prompt including spaces')): if not is_repl_install: raise Exception("requires pexpect, ptpython\n" "\trun 'python -m pip install kithon[repl]' to fix") prompt = PythonInput() transpiler = Transpiler() configurator.conf(transpiler, target, macro, templates) repl = pexpect.spawn(repl_name or transpiler.templates['meta']['repl']['name']) sep = separator or transpiler.templates['meta']['repl']['separator'] repl.expect(sep) code = '' while 1: src = prompt.app.run() if src.strip() == 'vars': pprint.pprint(transpiler.variables) continue if src.strip() == 'code': print(code) continue code = transpiler.generate(src, mode='block') repl.sendline(code) repl.expect(sep) print('\n'.join( repl.before.decode('utf-8').split('\n')[len(code.split('\n')):-1]))
def main(): locals_ = {} globals_ = globalenv eventloop = create_eventloop() try: python_input = PythonInput(get_globals=lambda: globals_, get_locals=lambda: locals_, history_filename=".sevalhist", _completer=BodgedPythonCompleter( lambda: locals_, lambda: globals_)) cli = PythonCommandLineInterface(eventloop=eventloop, python_input=python_input) while 1: python_code = cli.run() if python_code.text == "exit": break try: result, env = parse_string(locals_, python_code.text) for x in result: print(repr(x)) except Exception as e: _handle_exception(cli=cli, e=e, style=python_input._current_style) except EOFError: pass finally: eventloop.close()
def main(): prompt = PythonInput(vi_mode=True) while True: try: text = prompt.app.run() except KeyboardInterrupt: continue except EOFError: break else: is_statement = False try: code = compile(text, '<stdin>', 'eval') except SyntaxError: is_statement = True code = compile(text, '<stdin>', 'exec') if is_statement: send(text) else: send_prefix('/eval', text) print("goodbye")
def __init__(self): pdb.Pdb.__init__(self) # Cache for the grammar. self._grammar_cache = None # (current_pdb_commands, grammar) tuple. self.completer = None self.validator = None self.lexer = None self._source_code_window = Window(BufferControl( buffer_name='source_code', lexer=PygmentsLexer(PythonLexer), input_processors=[ HighlightSearchProcessor(preview_search=True), HighlightSelectionProcessor(), ], ), left_margins=[ SourceCodeMargin(self), NumberredMargin(), ], right_margins=[ScrollbarMargin()], scroll_offsets=ScrollOffsets( top=2, bottom=2), height=LayoutDimension(preferred=10)) # Callstack window. callstack = CallStack(weakref.ref(self)) self.callstack_focussed = False # When True, show cursor there, and allow navigation through it. self.callstack_selected_frame = 0 # Top frame. show_pdb_content_filter = ~IsDone() & Condition( lambda cli: not self.python_input.show_exit_confirmation) self.python_input = PythonInput( get_locals=lambda: self.curframe.f_locals, get_globals=lambda: self.curframe.f_globals, _completer=DynamicCompleter(lambda: self.completer), _validator=DynamicValidator(lambda: self.validator), _accept_action=self._create_accept_action(), _extra_buffers={'source_code': Buffer(read_only=True)}, _input_buffer_height=LayoutDimension(min=2, max=4), _lexer=PdbLexer(), _extra_buffer_processors=[ ConditionalProcessor(processor=CompletionHint(), filter=~IsDone()) ], _extra_layout_body=ConditionalContainer( HSplit([ VSplit([ HSplit([ SourceTitlebar(weakref.ref(self)), FloatContainer( content=self._source_code_window, floats=[ Float(right=0, bottom=0, content=BreakPointInfoToolbar( weakref.ref(self))) ]), ]), HSplit([ Window(width=LayoutDimension.exact(1), height=LayoutDimension.exact(1), content=FillControl( '\u252c', token=Token.Toolbar.Title)), Window(width=LayoutDimension.exact(1), content=FillControl('\u2502', token=Token.Separator)), ]), HSplit([ StackTitlebar(weakref.ref(self)), Window(callstack, scroll_offsets=ScrollOffsets(top=2, bottom=2), right_margins=[ScrollbarMargin()], height=LayoutDimension(preferred=10)), ]), ]), ]), filter=show_pdb_content_filter), _extra_toolbars=[ ConditionalContainer(PdbShortcutsToolbar(weakref.ref(self)), show_pdb_content_filter) ], history_filename=os.path.expanduser('~/.ptpdb_history'), ) # Override prompt style. self.python_input.all_prompt_styles['pdb'] = PdbPromptStyle( self._get_current_pdb_commands()) self.python_input.prompt_style = 'pdb' # Override exit message. self.python_input.exit_message = 'Do you want to quit BDB? This raises BdbQuit.' # Set UI styles. self.python_input.ui_styles = { 'ptpdb': get_ui_style(), } self.python_input.use_ui_colorscheme('ptpdb') # Set autocompletion style. (Multi-column works nicer.) self.python_input.completion_visualisation = CompletionVisualisation.MULTI_COLUMN # Load additional key bindings. load_custom_pdb_key_bindings(self, self.python_input.key_bindings_registry) self.cli = CommandLineInterface( eventloop=create_eventloop(), application=self.python_input.create_application())
def main(): prompt = PythonInput() text = prompt.app.run() print("You said: " + text)