def create_cli(self, connection, output, input=None): """ Create `CommandLineInterface` instance for this connection. """ def get_title(): return self.get_title(cli) def on_focus_changed(): """ When the focus changes to a read/write buffer, make sure to go to insert mode. This happens when the ViState was set to NAVIGATION in the copy buffer. """ vi_state = cli.vi_state if cli.current_buffer.read_only(): vi_state.input_mode = InputMode.NAVIGATION else: vi_state.input_mode = InputMode.INSERT application = Application( layout=self.layout_manager.layout, key_bindings_registry=self.key_bindings_manager.registry, buffers=_BufferMapping(self), mouse_support=Condition(lambda cli: self.enable_mouse_support), use_alternate_screen=True, style=self.style, get_title=get_title, on_invalidate=(lambda cli: self.invalidate())) cli = CommandLineInterface( application=application, output=output, input=input, eventloop=self.eventloop) # Synchronize the Vi state with the CLI object. # (This is stored in the current class, but expected to be in the # CommandLineInterface.) def sync_vi_state(_): client_state = self.get_client_state(cli) VI = EditingMode.VI EMACS = EditingMode.EMACS if (client_state.confirm_text or client_state.prompt_command or client_state.command_mode): cli.editing_mode = VI if self.status_keys_vi_mode else EMACS else: cli.editing_mode = VI if self.mode_keys_vi_mode else EMACS cli.input_processor.beforeKeyPress += sync_vi_state cli.input_processor.afterKeyPress += sync_vi_state # Set render postpone time. (.1 instead of 0). # This small change ensures that if for a split second a process # outputs a lot of information, we don't give the highest priority to # rendering output. (Nobody reads that fast in real-time.) cli.max_render_postpone_time = .1 # Second. # Hide message when a key has been pressed. def key_pressed(_): self.get_client_state(cli).message = None cli.input_processor.beforeKeyPress += key_pressed cli._is_running = True self.clis[connection] = cli # Redraw all CLIs. (Adding a new client could mean that the others # change size, so everything has to be redrawn.) self.invalidate() # Handle start-up comands. # (Does initial key bindings.) if not self._startup_done: self._startup_done = True # Execute default config. for cmd in STARTUP_COMMANDS.splitlines(): self.handle_command(cli, cmd) # Source the given file. if self.source_file: call_command_handler('source-file', self, cli, [self.source_file]) # Make sure that there is one window created. self.create_window(cli, command=self.startup_command) return cli
def create_cli(self, connection, output, input=None): """ Create `CommandLineInterface` instance for this connection. """ def get_title(): return self.get_title(cli) def on_focus_changed(): """ When the focus changes to a read/write buffer, make sure to go to insert mode. This happens when the ViState was set to NAVIGATION in the copy buffer. """ vi_state = self.key_bindings_manager.pt_key_bindings_manager.get_vi_state( cli) if cli.current_buffer.read_only(): vi_state.input_mode = InputMode.NAVIGATION else: vi_state.input_mode = InputMode.INSERT application = Application( layout=self.layout_manager.layout, key_bindings_registry=self.key_bindings_manager.registry, buffers=_BufferMapping(self), mouse_support=Condition(lambda cli: self.enable_mouse_support), use_alternate_screen=True, style=self.style, get_title=get_title) cli = CommandLineInterface(application=application, output=output, input=input, eventloop=self.eventloop) # Set render postpone time. (.1 instead of 0). # This small change ensures that if for a split second a process # outputs a lot of information, we don't give the highest priority to # rendering output. (Nobody reads that fast in real-time.) cli.max_render_postpone_time = .1 # Second. # Hide message when a key has been pressed. def key_pressed(): self.get_client_state(cli).message = None cli.input_processor.beforeKeyPress += key_pressed cli._is_running = True self.clis[connection] = cli # Redraw all CLIs. (Adding a new client could mean that the others # change size, so everything has to be redrawn.) self.invalidate() cli.on_invalidate += lambda: self.invalidate() # Handle start-up comands. # (Does initial key bindings.) if not self._startup_done: self._startup_done = True # Execute default config. for cmd in STARTUP_COMMANDS.splitlines(): self.handle_command(cli, cmd) # Source the given file. if self.source_file: call_command_handler('source-file', self, cli, [self.source_file]) # Make sure that there is one window created. self.create_window(cli, command=self.startup_command) return cli
def create_cli(self, connection, output, input=None): """ Create `CommandLineInterface` instance for this connection. """ def get_title(): return self.get_title(cli) def on_focus_changed(): """ When the focus changes to a read/write buffer, make sure to go to insert mode. This happens when the ViState was set to NAVIGATION in the copy buffer. """ vi_state = self.key_bindings_manager.pt_key_bindings_manager.get_vi_state(cli) if cli.current_buffer.read_only(): vi_state.input_mode = InputMode.NAVIGATION else: vi_state.input_mode = InputMode.INSERT application = Application( layout=self.layout_manager.layout, key_bindings_registry=self.key_bindings_manager.registry, buffers=_BufferMapping(self), mouse_support=Condition(lambda cli: self.enable_mouse_support), use_alternate_screen=True, style=self.style, get_title=get_title) cli = CommandLineInterface( application=application, output=output, input=input, eventloop=self.eventloop) # Hide message when a key has been pressed. def key_pressed(): self.get_client_state(cli).message = None cli.input_processor.beforeKeyPress += key_pressed cli._is_running = True self.clis[connection] = cli # Redraw all CLIs. (Adding a new client could mean that the others # change size, so everything has to be redrawn.) self.invalidate() cli.on_invalidate += lambda: self.invalidate() # Handle start-up comands. # (Does initial key bindings.) if not self._startup_done: self._startup_done = True # Execute default config. for cmd in STARTUP_COMMANDS.splitlines(): self.handle_command(cli, cmd) # Source the given file. if self.source_file: call_command_handler('source-file', self, cli, [self.source_file]) # Make sure that there is one window created. self.create_window(cli, command=self.startup_command) return cli