Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
721dab26
Commit
721dab26
authored
May 04, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add simple completer for subcommands, contexts and projects.
parent
8f7bb60d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
11 deletions
+48
-11
topydo/cli/Prompt.py
topydo/cli/Prompt.py
+4
-11
topydo/cli/TopydoCompleter.py
topydo/cli/TopydoCompleter.py
+44
-0
No files found.
topydo/cli/Prompt.py
View file @
721dab26
...
...
@@ -19,8 +19,8 @@
import
sys
from
topydo.cli.CLIApplicationBase
import
CLIApplicationBase
,
error
from
topydo.cli.TopydoCompleter
import
TopydoCompleter
from
prompt_toolkit.contrib.shortcuts
import
get_input
from
prompt_toolkit.contrib.completers
import
WordCompleter
from
topydo.lib.Config
import
config
,
ConfigError
...
...
@@ -47,15 +47,6 @@ class PromptApplication(CLIApplicationBase):
def
__init__
(
self
):
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
):
""" Main entry function. """
args
=
self
.
_process_flags
()
...
...
@@ -63,9 +54,11 @@ class PromptApplication(CLIApplicationBase):
self
.
todofile
=
TodoFile
.
TodoFile
(
self
.
path
)
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
completer
=
TopydoCompleter
(
self
.
todolist
)
while
True
:
try
:
user_input
=
get_input
(
'topydo> '
,
completer
=
self
.
completer
()
).
split
()
user_input
=
get_input
(
'topydo> '
,
completer
=
completer
).
split
()
except
(
EOFError
,
KeyboardInterrupt
):
sys
.
exit
(
0
)
...
...
topydo/cli/TopydoCompleter.py
0 → 100644
View file @
721dab26
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2015 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
re
from
prompt_toolkit.completion
import
Completer
,
Completion
from
topydo.Commands
import
_SUBCOMMAND_MAP
class
TopydoCompleter
(
Completer
):
def
__init__
(
self
,
p_todolist
):
self
.
todolist
=
p_todolist
def
get_completions
(
self
,
p_document
,
p_complete_event
):
# include all characters except whitespaces (for + and @)
word_before_cursor
=
p_document
.
get_word_before_cursor
(
True
)
is_first_word
=
not
re
.
match
(
r'\
s*
\S+\
s
', p_document.current_line_before_cursor)
if is_first_word:
subcommands = [sc for sc in sorted(_SUBCOMMAND_MAP.keys()) if sc.startswith(word_before_cursor)]
for command in subcommands:
yield Completion(command, -len(word_before_cursor))
elif word_before_cursor.startswith('
+
'):
projects = [p for p in self.todolist.projects() if p.startswith(word_before_cursor[1:])]
for project in projects:
yield Completion("+" + project, -len(word_before_cursor))
elif word_before_cursor.startswith('
@
'):
contexts = [c for c in self.todolist.contexts() if c.startswith(word_before_cursor[1:])]
for context in contexts:
yield Completion("@" + context, -len(word_before_cursor))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment