bebraw
1/21/2010 - 4:37 PM

application.py

...

class KeyboardInput(KeyboardThread):
    def get_data(self):
        return raw_input('>>> ')

class Application:
 
    def run(self):
        plugin_loader = PluginLoader()
        plugin_directory = PluginDirectory()
        commands = plugin_loader.load(plugin_directory)
        self.interpreter = Interpreter(commands)
        poller = Poller(KeyboardInput, self.input_evaluator)

        poller.poll()

    def input_evaluator(self, user_input):
        result = self.interpreter.interpret(user_input)

        if result is not None:
            if isinstance(result, str):
                lines = result.split('\n')

                if len(lines) > 1:
                    for line in lines:
                        self.output(line)
                else:
                    self.output(result)
            else:
                self.output(result)

    # XXX
    def input(self):
        return raw_input('>>> ')

    def output(self, result):
        print result