Commit d384173b authored by Bram Schoenmakers's avatar Bram Schoenmakers

Introduce completion of contexts and projects.

parent f8fd6ef3
...@@ -20,6 +20,7 @@ import sys ...@@ -20,6 +20,7 @@ import sys
from topydo.cli.CLIApplicationBase import CLIApplicationBase, error from topydo.cli.CLIApplicationBase import CLIApplicationBase, error
from prompt_toolkit.contrib.shortcuts import get_input from prompt_toolkit.contrib.shortcuts import get_input
from prompt_toolkit.contrib.completers import WordCompleter
from topydo.lib.Config import config, ConfigError from topydo.lib.Config import config, ConfigError
...@@ -46,6 +47,15 @@ class PromptApplication(CLIApplicationBase): ...@@ -46,6 +47,15 @@ class PromptApplication(CLIApplicationBase):
def __init__(self): def __init__(self):
super(PromptApplication, self).__init__() super(PromptApplication, self).__init__()
def completer(self):
""" Returns a completer instance with projects and contexts. """
projects = ["+" + project for project in self.todolist.projects()]
contexts = ["@" + context for context in self.todolist.contexts()]
complete_list = projects + contexts
return WordCompleter(complete_list)
def run(self): def run(self):
""" Main entry function. """ """ Main entry function. """
args = self._process_flags() args = self._process_flags()
...@@ -55,7 +65,7 @@ class PromptApplication(CLIApplicationBase): ...@@ -55,7 +65,7 @@ class PromptApplication(CLIApplicationBase):
while True: while True:
try: try:
user_input = get_input('topydo> ').split() user_input = get_input('topydo> ', completer=self.completer()).split()
except (EOFError, KeyboardInterrupt): except (EOFError, KeyboardInterrupt):
sys.exit(0) sys.exit(0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment