def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] == 'uselistener' and position_util(cmd_line, 2, word_before_cursor): for listener in filtered_search_list(word_before_cursor, state.listener_types): yield Completion(listener, start_position=-len(word_before_cursor)) elif cmd_line[0] in ['set', 'unset'] and position_util(cmd_line, 2, word_before_cursor): # Todo need to refactor to not make api requests on every autocomplete. Look at usestager for option in filtered_search_list(word_before_cursor, state.get_listener_options(self.selected)['listeneroptions']): yield Completion(option, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] == 'usemodule' and position_util(cmd_line, 2, word_before_cursor): for module in filtered_search_list(word_before_cursor, state.modules.keys()): yield Completion(module, start_position=-len(word_before_cursor)) elif cmd_line[0] in ['set', 'unset'] and position_util(cmd_line, 2, word_before_cursor): for option in filtered_search_list(word_before_cursor, self.module_options): yield Completion(option, start_position=-len(word_before_cursor)) elif cmd_line[0] == 'set' and position_util(cmd_line, 3, word_before_cursor): if len(cmd_line) > 1 and cmd_line[1] == 'listener': for listener in filtered_search_list(word_before_cursor, state.listeners.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) if len(cmd_line) > 1 and cmd_line[1] == 'agent': for listener in filtered_search_list(word_before_cursor, state.agents.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): """ Adds autocomplete for the set and unset methods and defers to the base Menu when trying to invoke global commands (position 1 commands). """ if cmd_line[0] in ['set', 'unset'] and position_util(cmd_line, 2, word_before_cursor): for option in filtered_search_list(word_before_cursor, self.record_options): yield Completion(option, start_position=-len(word_before_cursor)) elif cmd_line[0] == 'set' and position_util(cmd_line, 3, word_before_cursor): if len(cmd_line) > 1 and cmd_line[1] == 'listener': for listener in filtered_search_list(word_before_cursor, state.listeners.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) if len(cmd_line) > 1 and cmd_line[1] == 'agent': for listener in filtered_search_list(word_before_cursor, state.agents.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): """ The default completion method. A menu should implement its own get_completion method for autocompleting its own commands and then use this as a fallback for autocompleting the globals. """ word_before_cursor = document.get_word_before_cursor() for word in filtered_search_list(word_before_cursor, self.autocomplete()): if word.startswith(word_before_cursor): yield Completion(word, start_position=-len(word_before_cursor))
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] in ['interact'] and position_util(cmd_line, 2, word_before_cursor): active_agents = list(map(lambda a: a['name'], filter(lambda a: a['stale'] is not True, state.agents.values()))) for agent in filtered_search_list(word_before_cursor, active_agents): yield Completion(agent, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor) elif cmd_line[0] in shortcut_handler.get_names(self.agent_language): position = len(cmd_line) shortcut = shortcut_handler.get(self.agent_language, cmd_line[0]) params = shortcut.get_dynamic_param_names() if position - 1 < len(params): if params[position - 1].lower() == 'listener': for listener in filtered_search_list(word_before_cursor, state.listeners.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) if params[position - 1].lower() == 'agent': for agent in filtered_search_list(word_before_cursor, state.agents.keys()): yield Completion(agent, start_position=-len(word_before_cursor))
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] == 'uselistener' and position_util( cmd_line, 2, word_before_cursor): for listener in filtered_search_list(word_before_cursor, state.listener_types): yield Completion(listener, start_position=-len(word_before_cursor)) else: yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] in ['kill', 'options'] and position_util( cmd_line, 2, word_before_cursor): for listener in filtered_search_list(word_before_cursor, state.listeners.keys()): yield Completion(listener, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] == 'usemodule' and position_util( cmd_line, 2, word_before_cursor): for module in filtered_search_list(word_before_cursor, state.modules.keys()): yield Completion(module, start_position=-len(word_before_cursor)) else: yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] == 'useplugin' and position_util( cmd_line, 2, word_before_cursor): for plugin in filtered_search_list(word_before_cursor, state.plugins.keys()): yield Completion(plugin, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if cmd_line[0] in ['kill', 'clear', 'rename'] and position_util( cmd_line, 2, word_before_cursor): for agent in filtered_search_list(word_before_cursor, state.agents.keys()): yield Completion(agent, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)
def get_completions(self, document, complete_event, cmd_line, word_before_cursor): if not state.connected: if cmd_line[0] == 'connect' and position_util( cmd_line, 2, word_before_cursor): yield Completion('-c', start_position=-len(word_before_cursor)) elif cmd_line[0] == 'connect' and len(cmd_line) > 1 and cmd_line[1] in ['-c', '--config'] \ and position_util(cmd_line, 3, word_before_cursor): for server in filtered_search_list( word_before_cursor, empire_config.yaml.get('servers', [])): yield Completion(server, start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): if 'connect'.startswith(word_before_cursor): yield Completion('connect', start_position=-len(word_before_cursor)) elif position_util(cmd_line, 1, word_before_cursor): yield from super().get_completions(document, complete_event, cmd_line, word_before_cursor)