From d8d1429ec3daf8f2a67ffccbc2aa1d54eb3639c6 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sat, 17 Aug 2019 10:00:30 +0100 Subject: refactor prompt completion This just splits the file completion.py into several files, one for each Completer subclass. --- alot/completion/commandname.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 alot/completion/commandname.py (limited to 'alot/completion/commandname.py') 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 +# 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] -- cgit v1.2.3