def run_command(command, qtbot): runners.run(command, mode=api.modes.current()) # Wait for external command to complete if any was run external_runner = runners.external_runner._impl if external_runner is not None: def external_finished(): state = external_runner.state() assert state == QProcess.NotRunning, "external command timed out" qtbot.waitUntil(external_finished, timeout=30000)
def run_startup_commands(*commands: str) -> None: """Run commands given via --command at startup. Args: commands: All command strings given via individual --command arguments. """ total = len(commands) for i, command in enumerate(commands, start=1): _logger.debug("Startup commands: running %d/%d '%s'", i, total, command) if "quit" in command: # This does not work without a running app log.warning("Quitting forcefully as the app does not exist") app.Application.preexit(customtypes.Exit.success) sys.exit(customtypes.Exit.success) else: runners.run(command, mode=api.modes.current())
def _command_func(prefix, command, mode): """Return callable function for command depending on prefix.""" if prefix == ":": return lambda: runners.run(command, mode=mode) # No need to search again if incsearch is enabled if prefix in "/?" and not search.use_incremental(mode): return lambda: search.search(command, mode, reverse=prefix == "?") return lambda: None
def _process_event(self, sequence: SequenceT, mode: api.modes.Mode = None) -> bool: """Process event by name. Try to (partially) match the name with the current bindings. If a complete match is found, the corresponding command is run. Partial matches are displayed and the corresponding keys are stored. In case there is no match, reset and return False. Args: sequence: Event keys/buttons as meaningful string sequence. mode: Mode in which the event was received. None for current mode. Returns: True if processing was successful, False otherwise. """ mode = api.modes.current() if mode is None else mode name = "".join(sequence) _logger.debug("EventHandlerMixin: handling %s for mode %s", name, mode.name) bindings = api.keybindings.get(mode) stored_keys = self.partial_handler.keys.get_keys() match = bindings.match((*stored_keys, *sequence)) # Complete match => run command if match.is_full_match: _logger.debug("EventHandlerMixin: found command for event") count = self.partial_handler.count.get_text() command = cast(str, match.value) # Would not be a full match otherwise runners.run(command, count=count, mode=mode) self.partial_handler.clear_keys() return True # Partial match => store keys if match.is_partial_match: _logger.debug( "EventHandlerMixin: event matches bindings partially") self.partial_handler.keys.add_keys(*sequence) self.partial_handler.partial_matches.emit(name, match.partial) return True # Nothing => reset and return False _logger.debug("EventHandlerMixin: no matches for event") self.partial_handler.clear_keys() return False
def keyPressEvent(self, event): """Handle key press event for the widget. Args: event: QKeyEvent that activated the keyPressEvent. """ api.status.clear() mode = api.modes.current() keyname = keyevent_to_string(event) logging.debug("KeyPressEvent: handling %s for mode %s", keyname, mode.name) bindings = api.keybindings.get(mode) # Handle escape separately as it affects multiple widgets and must clear partial # matches instead of checking for them if keyname == "<escape>" and mode in api.modes.GLOBALS: logging.debug("KeyPressEvent: handling <escape> key specially") self.partial_handler.clear_keys() search.search.clear() return stored_keys = self.partial_handler.keys.get_text() keyname = stored_keys + keyname partial_matches = bindings.partial_matches(keyname) # Count if keyname and keyname in string.digits and mode != api.modes.COMMAND: logging.debug("KeyPressEvent: adding digits") self.partial_handler.count.add_text(keyname) # Complete match => run command elif keyname and keyname in bindings: logging.debug("KeyPressEvent: found command") count = self.partial_handler.count.get_text() cmd = bindings[keyname] runners.run(cmd, count=count, mode=mode) self.partial_handler.clear_keys() # Partial match => store keys elif partial_matches: self.partial_handler.keys.add_text(keyname) self.partial_handler.partial_matches.emit(keyname, partial_matches) # Nothing => run default Qt bindings of parent object else: # super() is the parent Qt widget super().keyPressEvent(event) # pylint: disable=no-member api.status.update() # Will not be called by command self.partial_handler.clear_keys()
def _on_return_pressed(self) -> None: """Run command and store history on return.""" prefix, command = self._split_prefix(self.text()) if not command: # Only prefix entered return self._history[self.mode].update(prefix + command) # Run commands in QTimer so the command line has been left when the # command runs if prefix == ":": QTimer.singleShot(0, lambda: runners.run(command, mode=self.mode)) elif not search.use_incremental(self.mode): QTimer.singleShot( 0, lambda: search.search( command, self.mode, reverse=prefix == "?"))
def run_command(command): runners.run(command, mode=api.modes.current())
def run_help(topic): runners.run(f"help {topic}", mode=api.modes.current())
def run_empty_command(): runners.run("", mode=api.modes.current())