summaryrefslogtreecommitdiff
path: root/alot/completion/commandname.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2019-08-17 10:00:30 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2019-08-17 11:10:37 +0100
commitd8d1429ec3daf8f2a67ffccbc2aa1d54eb3639c6 (patch)
tree3f13fd449bacd97432e18ba4fb0fb4b19ac0b5ed /alot/completion/commandname.py
parentb5e612c69b625271424b626da24d941ddbe39391 (diff)
refactor prompt completion
This just splits the file completion.py into several files, one for each Completer subclass.
Diffstat (limited to 'alot/completion/commandname.py')
-rw-r--r--alot/completion/commandname.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/alot/completion/commandname.py b/alot/completion/commandname.py
new file mode 100644
index 00000000..5c946eb6
--- /dev/null
+++ b/alot/completion/commandname.py
@@ -0,0 +1,26 @@
+# Copyright (C) 2011-2019 Patrick Totzke <patricktotzke@gmail.com>
+# This file is released under the GNU GPL, version 3 or a later revision.
+# For further details see the COPYING file
+
+import logging
+from alot import commands
+from .completer import Completer
+
+
+class CommandNameCompleter(Completer):
+ """Completes command names."""
+
+ def __init__(self, mode):
+ """
+ :param mode: mode identifier
+ :type mode: str
+ """
+ self.mode = mode
+
+ def complete(self, original, pos):
+ commandprefix = original[:pos]
+ logging.debug('original="%s" prefix="%s"', original, commandprefix)
+ cmdlist = commands.COMMANDS['global'].copy()
+ cmdlist.update(commands.COMMANDS[self.mode])
+ matching = [t for t in cmdlist if t.startswith(commandprefix)]
+ return [(t, len(t)) for t in matching]