Пример #1
0
def helplist(dictionary, max_length=20, color="green"):
    # the dictionary to be converted into the list
    dict = dictionary

    # the actual string of the list
    string = "\n"
    for name in dict.keys():
        temp_string = ""
        # adding the name of the function as bold and colored as one of the rgb colors passed
        if color == "green":
            temp_string += colors.bold(colors.green(" "+name))
        elif color == "red":
            temp_string += colors.bold(colors.red(" "+name))
        elif color == "blue":
            temp_string += colors.bold(colors.blue(" "+name))
        # adding the amount of whitespaces missing until the max character count has been reached
        for i in range(0, max_length - len(name), 1):
            temp_string += " "
        # adding the separation
        temp_string += " - "
        # adding the content of the description to the string
        temp_string += dict[name]
        count = 0
        for character in temp_string:
            string += character
            if count == get_terminal_width() + 15:
                string += "\n" + (" " * (max_length+4))
                count = 0
            if len(str(character)) == 1:
                count += 1
        if string[-1] != "\n":
            string += "\n"
    return string
Пример #2
0
def run(process, std="nothing"):
    print(c.bold("a"))
    print(c.bold(c.green("a")))
    print(c.green("a"))
    print(c.bold(c.red("a")))
    print(c.red("a"))
    print(c.bold(c.blue("a")))
    print(c.blue("a"))
    print(c.bold(c.yellow("a")))
    print(c.yellow("a"))
    return "a"
Пример #3
0
    def run(self):
        """
        the main method of the shell running the infinite loop, continuesly prompting for a command, then attempting to
        execute the issued command
        :return: (void)
        """
        # opening the infinite loop inside of a try statement, so that the SystemExit Exception can be caught
        try:
            while True:
                # first fetching the user input
                print(colors.magenta(colors.bold(self.prompt)), end="")
                command = input()

                if command == "exit":
                    if self.supershell is None:
                        sys.exit()
                    else:
                        break
                # skipping the whole procedure in case the command prompt is empty
                if command != "" and command != " ":
                    # then converting the command into a token list via the parse method
                    tokenlist = self.parser.parse(command)
                    # checking for any potential errors
                    try:
                        self.analyzer.analyze(tokenlist, command)
                        # in case the analyzer didnt raise any errors attempting to execute the tokenlist
                        last_process = self.executer.execute(tokenlist)
                        while not(last_process.status == "terminated"):
                            pass
                        if last_process.is_foreground():
                            print(Message("result", last_process.output).message)
                    except error.SyntaxError as e:
                        print(e.message.message)
        except SystemExit as e:
            pass