def display_Menu(self): """ Displays the menu, waits for and processes commands """ menu_split = [' '] self._print_sequence(self.Command_Handler.menu_dictionary['display menu'](None), "") while(menu_split[0] != 'quit'): menu_code = input("Input your command: ") menu_split = menu_code.split(sep=" ") try: sequence = self.Command_Handler.process_command(menu_split) if(isinstance(sequence, int)): print(sequence) else: try: Validator.validate_int(get_index(sequence, 0), -10000, 10000) end_character = " " except IndexError: pass except ValueError: end_character = "" self._print_sequence(sequence, end_character) except TypeError as e: if(get_index(e.args[0].split(sep = " "), 1) == 'takes'): print('Invalid command') else: print(e.args[0]) except ValueError as e: print (e.args[0]) except IndexError as e: print (e.args[0])
def get_keywords(self, menu_split): """ Gets all the keystrings of a given command Example: - "replace subsequence 1 3 5 with 4 5" will return ["replace subsequence", "with"] - "delete index 1" will return ["delete index"] Input: -menu_split - The command string Returns: An array containing all identified keystrings """ key_list = [] key_string = '' for i in range(0, len(menu_split)): try: num = Validator.validate_int(get_index(menu_split,i), -10000, 10000) if(key_string != ''): key_string = key_string[:len(key_string) - 1] key_list.append(key_string) key_string = '' except ValueError as e: if(get_index(e.args, 0) == "Number is invalid"): key_string += get_index(menu_split,i) + ' ' if(key_string != ''): key_string = key_string[:len(key_string) - 1] key_list.append(key_string) return key_list
def get_numbers(self, menu_split, startIndex): """ Gets the first array of numbers encountered after a given index Input: -menu_split - The command string, split into an array of strings by the ' ' character -sequence - The base sequences Returns: The first array of numbers encountered """ num_array = [] for i in range(startIndex, len(menu_split)): try: num = Validator.validate_int(menu_split[i], -10000, 10000) except ValueError: break num_array.append(num) return num_array