summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2011-10-01 22:45:51 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2011-10-01 22:45:51 +0100
commit2df5708976a2d6939d7300fad262cf37c9532cfe (patch)
treed789de07a3a09fde60470678f1dee5aa1c29a2b8
parent55b55165a7d3555abc91a92ee642259e119fff23 (diff)
add HelpCommand
-rw-r--r--alot/command.py61
-rw-r--r--alot/defaults/alot.rc1
-rw-r--r--alot/ui.py2
3 files changed, 63 insertions, 1 deletions
diff --git a/alot/command.py b/alot/command.py
index 5c689a55..721437c0 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -1063,6 +1063,64 @@ class TaglistSelectCommand(Command):
ui.apply_command(cmd)
+class HelpCommand(Command):
+ def __init__(self, commandline='', **kwargs):
+ Command.__init__(self, **kwargs)
+ self.commandline = commandline.strip()
+
+ def apply(self, ui):
+ if self.commandline:
+ cmd = self.commandline.split(' ', 1)[0]
+ # TODO: how to I access COMMANDS from below?
+ ui.notify('no help for \'%s\'' % cmd, priority='error')
+ titletext = 'help for %s' % cmd
+ body = urwid.Text('helpstring')
+ return
+ else:
+ # get mappings
+ modemaps = dict(settings.config.items('%s-maps' % ui.mode))
+ globalmaps = dict(settings.config.items('global-maps'))
+
+ # build table
+ maxkeylength = len(max((modemaps).keys() + globalmaps.keys(),
+ key=len))
+ keycolumnwidth = maxkeylength + 2
+
+ linewidgets = []
+ # mode specific maps
+ linewidgets.append(urwid.Text(('helptexth1',
+ '\n%s-mode specific maps' % ui.mode)))
+ for (k, v) in modemaps.items():
+ line = urwid.Columns([('fixed', keycolumnwidth, urwid.Text(k)),
+ urwid.Text(v)])
+ linewidgets.append(line)
+
+ # global maps
+ linewidgets.append(urwid.Text(('helptexth1',
+ '\nglobal maps')))
+ for (k, v) in globalmaps.items():
+ if k not in modemaps:
+ line = urwid.Columns(
+ [('fixed', keycolumnwidth, urwid.Text(k)),
+ urwid.Text(v)])
+ linewidgets.append(line)
+
+ body = urwid.ListBox(linewidgets)
+ urwidmaps = settings.config.items('urwid-maps')
+ ckey = [k for (k, v) in urwidmaps if v == 'cancel'][0] or 'esc'
+ titletext = 'Bindings Help (%s cancels)' % ckey
+
+ box = widgets.DialogBox(body, titletext,
+ bodyattr='helptext',
+ titleattr='helptitle')
+
+ # put promptwidget as overlay on main widget
+ overlay = urwid.Overlay(box, ui.mainframe, 'center',
+ ('relative', 70), 'middle',
+ ('relative', 70))
+ ui.show_as_root_until_keypress(overlay, 'cancel')
+
+
COMMANDS = {
'search': {
'refine': (RefineCommand, {}),
@@ -1113,6 +1171,7 @@ COMMANDS = {
'search': (SearchCommand, {}),
'shellescape': (ExternalCommand, {}),
'taglist': (TagListCommand, {}),
+ 'help': (HelpCommand, {}),
}
}
@@ -1174,6 +1233,8 @@ def interpret_commandline(cmdline, mode):
return commandfactory(cmd, mode=mode, headers=h)
elif cmd == 'attach':
return commandfactory(cmd, mode=mode, path=params)
+ elif cmd == 'help':
+ return commandfactory(cmd, mode=mode, commandline=params)
elif cmd == 'forward':
return commandfactory(cmd, mode=mode, inline=(params == '--inline'))
elif cmd == 'prompt':
diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc
index e72f28d5..bf732994 100644
--- a/alot/defaults/alot.rc
+++ b/alot/defaults/alot.rc
@@ -71,6 +71,7 @@ esc = cancel
[global-maps]
@ = refresh
+? = help
I = search tag:inbox AND NOT tag:killed
L = taglist
shift tab = bprevious
diff --git a/alot/ui.py b/alot/ui.py
index 9fd3b7ab..ddf88b04 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -82,7 +82,7 @@ class UI(object):
def keypress(self, key):
self.logger.debug('unhandeled input: %s' % key)
- def show_as_root_until_keypress_(self, w, key):
+ def show_as_root_until_keypress(self, w, key):
def oe():
self.mainloop.widget = self.mainframe # restore main screen
self.mainloop.widget = widgets.CatchKeyWidgetWrap(w, key,