From 3f0c099b80a792674a1d03e59ef0ff4489f77939 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Tue, 28 Aug 2012 22:08:59 +0100 Subject: add UI.apply_commandline that reads a cmdline string, possibly splits it in separate subcommand strings and fires the (sequence of) Command object(s). --- alot/ui.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'alot/ui.py') diff --git a/alot/ui.py b/alot/ui.py index 81d61556..e9413c81 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -9,7 +9,9 @@ from settings import settings from buffers import BufferlistBuffer from commands import commandfactory from alot.commands import CommandParseError +from alot.commands.globals import CommandSequenceCommand from alot.helper import string_decode +from alot.helper import split_commandline from alot.widgets.globals import CompleteEdit from alot.widgets.globals import ChoiceWidget @@ -141,6 +143,21 @@ class UI(object): # update statusbar self.update() + def apply_commandline(self, cmdline): + # split commandline if necessary + cmd = None + cmdlist = split_commandline(cmdline) + if len(cmdlist) == 1: + try: + # translate cmdstring into :class:`Command` + cmd = commandfactory(cmdlist[0], self.mode) + except CommandParseError, e: + self.notify(e.message, priority='error') + return + else: + cmd = CommandSequenceCommand(cmdlist) + self.apply_command(cmd) + def _unhandeled_input(self, key): """ Called by :class:`urwid.MainLoop` if a keypress was passed to the root -- cgit v1.2.3