def hRun(c, inp): if (len(inp) == 2): temp = len(cmdHistory) - inp[1] else: temp = len(cmdHistory) - 2 main.scw(">> " + cmdHistory[temp]) i = input("? ") if (i.lower() == ""): main(cmdHistory[temp]) elif (i.lower() != "n"): error(2, inp[0])
def load(): # Slowly appending commands :) newCommA(True, "turn", turnValidate, turnRun, turnUsage, turnDesc) a = main.attribute(True) a2 = main.attribute(True) c = main.command("ch", [a, a2]) c.validate = main.MethodType(chValidate, c) c.usage = main.MethodType(chUsage, c) c.run = main.MethodType(chRun, c) c.description = main.MethodType(chDesc, c) main.commands.append(c) main.scw("commands loaded") main.scw(main.commands[0])
def helpDesc(c): main.scw( "I`m assuming you know what help does, since you just used it. Well it shows you all of the commands you can enter here :)" ) main.scw( "If you type 'help' <command> it will show you the commands description." ) main.scw( "If you just type 'help' it will show all of the commands with their usage." )
def turnDesc(c): main.scw( "This command makes you turn around. Could be useful for a text-based RPG maybe?" )
def chUsage(c): main.scw("ch + 'Name of a first file' 'Name of a second file'")
def turnUsage(c): main.scw("turn + 'left' / 'right' / 'backward' / 'forward' / ") main.scw(" 'North' / 'South' / 'East' / 'West'")
def chRun(c, inp): main.scw("You changed the name of " + inp[1] + " to " + inp[2] + ".")
def turnRun(c, inp): main.scw("You turned towards the", inp[1] + ".")
def helpRun(c, inp): main.scw("yee") main.scw("Type 'help' <command> for commands description.") main.scw() if (len(inp) > 1): count = 0 for i in commands: if (inp[1] == i.label): i.description() break else: for i in range(0, len(commands)): main.scw(str(i + 1) + ". " + commands[i].label, end="") if (len(commands[i].att) >= 1): main.scw(" - ", end="") commands[i].usage() else: main.scw()
def exitDesc(c): main.scw( "By typing 'exit', the shells main loop will end and the python script will terminate." )
def restartDesc(c): main.scw( "This command restarts this 'shell'. That means it clears the command-history and reloads all of the commands as well as the config file." )
def hUsage(c): main.scw("h (<1-max number>)")
def helpUsage(c): main.scw("help (<command>)")
def chDesc(c): main.scw( "'Ch' changes the name of a imaginary file. I doesn`t really do anything to be honest. It might at sometime though." )
def hDesc(c): main.scw( "This command lets you use a command you have recently typed already. It gives you acces to the command history." ) main.scw( "You can also type 'h' <number from 1-number of entered commands or maximum length>. This number increases he further back in he history you get." ) main.scw( "For the latest command you would type 'h' or 'h 1'. For the secodn latest 'h 2' and so on..." ) main.scw( "You will get a question mark. You either type enter to execute the command like shown above or type 'n' to abort the process." ) main.scw() main.scw("You can set the historys maxium length in the config.py file.")
def restartRun(c, inp): main.scw() main.scw("Restarting shell") main.scw() main.scw("-------------------------------------------------------") return "restart"
def exitRun(c, inp): main.scw("Goodbye") main.scw() sys.exit()