@@ -0,0 +1,2090 @@
+import sys, signal%0A%0Aprint %22==================%22%0Aprint %22welcome to %5Bchat-edit%5D%22%0Aprint %22to open a file try 'open %5Bpath to file%5D'%22%0Aprint %22==================%22%0A%0A# various vocabulary for editing files%0Aopenwords = %5B%22open%22, %22load%22%5D%0Asavewords = %5B%22save%22, %22write%22%5D%0Aquitwords = %5B%22quit%22, %22stop%22, %22exit%22, %22done%22%5D%0Ayeswords = %5B%22yes%22, %22y%22, %22ya%22, %22yeah%22, %22okay%22, %22sure%22, %22ok%22%5D%0A%0A# %5B and %5D denote a system message%0Adef msg(string):%0A    print %22%5B%22 + string + %22%5D%22%0A%0Adef confirm(string):%0A    msg(string)%0A    sys.stdout.write(%22%3E %22)%0A    response = raw_input()%0A    if response in yeswords:%0A        return True%0A    else:%0A        return False%0A%0Aclass ChatEdit:%0A    def __init__(self):%0A        self.changes = False%0A        self.file = %22none%22%0A        self.contents = %22%22%0A    %0A    # main interpret method that processes input%0A    def interpret(self, input):%0A        words = input.split(%22 %22)%0A        command = words%5B0%5D.lower()%0A        args = %22 %22.join(words%5B1:%5D)%0A        %0A        if command in openwords:%0A            self.file = open(args, %22w+%22)%0A            self.contents = self.file.read()%0A            self.changes = False%0A            msg(command + %22ed %22 + self.file.name + %22 into memory%22)%0A%0A        elif command in savewords:%0A            if self.file == %22none%22:%0A                msg(%22no file is loaded%22)%0A            else:%0A                self.file.write(self.contents)%0A                self.changes = False%0A                msg(str(len(self.contents)) + %22 characters written to %22 + self.file.name)%0A%0A        elif command in quitwords:%0A            if not self.changes:%0A                msg(%22now exiting%22)%0A                exit()%0A            else:%0A                if confirm(%22quit without saving?%22):%0A                    self.changes = False%0A                    interpret(input)%0A                else:%0A                    msg(%22quit cancelled%22)%0A%0A        else:%0A            msg(%22invalid command%22)%0A%0Amain = ChatEdit()%0A%0Adef signal_handler(signal, frame):%0A    print %22%22%0A    main.interpret(%22exit%22)%0A%0Asignal.signal(signal.SIGINT, signal_handler)%0A%0A# shell loop%0Awhile True:%0A    sys.stdout.write(%22%3E %22)%0A    input = raw_input()%0A    main.interpret(input)%0A

create main loop that understands basic commands