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
eb240558
Commit
eb240558
authored
Nov 17, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'split-filters'
parents
49f1e0a7
4e3ff64f
Changes
16
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
154 additions
and
95 deletions
+154
-95
topydo/commands/AddCommand.py
topydo/commands/AddCommand.py
+1
-1
topydo/commands/AppendCommand.py
topydo/commands/AppendCommand.py
+1
-1
topydo/commands/DepriCommand.py
topydo/commands/DepriCommand.py
+1
-1
topydo/commands/DoCommand.py
topydo/commands/DoCommand.py
+1
-1
topydo/commands/EditCommand.py
topydo/commands/EditCommand.py
+1
-1
topydo/commands/ListCommand.py
topydo/commands/ListCommand.py
+1
-2
topydo/commands/PostponeCommand.py
topydo/commands/PostponeCommand.py
+1
-1
topydo/commands/PriorityCommand.py
topydo/commands/PriorityCommand.py
+1
-1
topydo/commands/TagCommand.py
topydo/commands/TagCommand.py
+1
-1
topydo/lib/DCommand.py
topydo/lib/DCommand.py
+1
-1
topydo/lib/PrettyPrinter.py
topydo/lib/PrettyPrinter.py
+2
-2
topydo/lib/PrettyPrinterFilter.py
topydo/lib/PrettyPrinterFilter.py
+1
-82
topydo/lib/prettyprinters/Colors.py
topydo/lib/prettyprinters/Colors.py
+73
-0
topydo/lib/prettyprinters/Format.py
topydo/lib/prettyprinters/Format.py
+34
-0
topydo/lib/prettyprinters/Numbers.py
topydo/lib/prettyprinters/Numbers.py
+34
-0
topydo/lib/prettyprinters/__init__.py
topydo/lib/prettyprinters/__init__.py
+0
-0
No files found.
topydo/commands/AddCommand.py
View file @
eb240558
...
...
@@ -24,7 +24,7 @@ from sys import stdin
from
topydo.lib.Command
import
Command
from
topydo.lib.Config
import
config
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.RelativeDate
import
relative_date_to_date
from
topydo.lib.TodoListBase
import
InvalidTodoException
...
...
topydo/commands/AppendCommand.py
View file @
eb240558
...
...
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
topydo.lib.Command
import
Command
,
InvalidCommandArgument
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.TodoListBase
import
InvalidTodoException
...
...
topydo/commands/DepriCommand.py
View file @
eb240558
...
...
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
class
DepriCommand
(
MultiCommand
):
...
...
topydo/commands/DoCommand.py
View file @
eb240558
...
...
@@ -18,7 +18,7 @@ from datetime import date
from
topydo.lib.DCommand
import
DCommand
from
topydo.lib.PrettyPrinter
import
PrettyPrinter
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.Recurrence
import
NoRecurrenceException
,
advance_recurring_todo
from
topydo.lib.Utils
import
date_string_to_date
...
...
topydo/commands/EditCommand.py
View file @
eb240558
...
...
@@ -22,7 +22,7 @@ from six import u
from
topydo.lib.Config
import
config
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.Todo
import
Todo
from
topydo.lib.TodoList
import
TodoList
...
...
topydo/commands/ListCommand.py
View file @
eb240558
...
...
@@ -17,9 +17,8 @@
from
topydo.lib.Config
import
config
from
topydo.lib.ExpressionCommand
import
ExpressionCommand
from
topydo.lib.Filter
import
InstanceFilter
from
topydo.lib.ListFormat
import
ListFormatParser
from
topydo.lib.PrettyPrinter
import
pretty_printer_factory
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterFormatFilter
from
topydo.lib.
prettyprinters.Format
import
PrettyPrinterFormatFilter
from
topydo.lib.TodoListBase
import
InvalidTodoException
...
...
topydo/commands/PostponeCommand.py
View file @
eb240558
...
...
@@ -18,7 +18,7 @@ from datetime import date, timedelta
from
topydo.lib.Config
import
config
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.RelativeDate
import
relative_date_to_date
from
topydo.lib.Utils
import
date_string_to_date
...
...
topydo/commands/PriorityCommand.py
View file @
eb240558
...
...
@@ -17,7 +17,7 @@
import
re
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.Utils
import
is_valid_priority
...
...
topydo/commands/TagCommand.py
View file @
eb240558
...
...
@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
topydo.lib.Command
import
Command
,
InvalidCommandArgument
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
from
topydo.lib.TodoListBase
import
InvalidTodoException
...
...
topydo/lib/DCommand.py
View file @
eb240558
...
...
@@ -18,7 +18,7 @@ import re
from
topydo.lib.MultiCommand
import
MultiCommand
from
topydo.lib.PrettyPrinter
import
PrettyPrinter
from
topydo.lib.
PrettyPrinterFilter
import
PrettyPrinterNumbers
from
topydo.lib.
prettyprinters.Numbers
import
PrettyPrinterNumbers
class
DCommand
(
MultiCommand
):
...
...
topydo/lib/PrettyPrinter.py
View file @
eb240558
...
...
@@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
topydo.lib.
PrettyPrinterFilter
import
(
PrettyPrinterColorFilter
,
PrettyPrinterNumbers
)
from
topydo.lib.
prettyprinters.Colors
import
PrettyPrinterColorFilter
from
topydo.lib.prettyprinters.Numbers
import
PrettyPrinterNumbers
class
Printer
(
object
):
...
...
topydo/lib/PrettyPrinterFilter.py
View file @
eb240558
...
...
@@ -14,17 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
""" Provides filters used for pretty printing. """
import
re
from
collections
import
OrderedDict
from
six
import
u
from
topydo.lib.Colors
import
NEUTRAL_COLOR
,
Colors
from
topydo.lib.Config
import
config
from
topydo.lib.ListFormat
import
ListFormatParser
from
topydo.lib.Utils
import
get_terminal_size
""" Provides a base class for pretty printer filters. """
class
PrettyPrinterFilter
(
object
):
...
...
@@ -40,74 +30,3 @@ class PrettyPrinterFilter(object):
"""
raise
NotImplementedError
class
PrettyPrinterColorFilter
(
PrettyPrinterFilter
):
"""
Adds colors to the todo string by inserting ANSI codes.
Should be passed as a filter in the filter list of pretty_print()
"""
def
filter
(
self
,
p_todo_str
,
p_todo
):
""" Applies the colors. """
colorscheme
=
Colors
()
priority_colors
=
colorscheme
.
get_priority_colors
()
project_color
=
colorscheme
.
get_project_color
()
context_color
=
colorscheme
.
get_context_color
()
metadata_color
=
colorscheme
.
get_metadata_color
()
link_color
=
colorscheme
.
get_link_color
()
if
config
().
colors
():
color
=
NEUTRAL_COLOR
try
:
color
=
priority_colors
[
p_todo
.
priority
()]
except
KeyError
:
pass
# color projects / contexts
p_todo_str
=
re
.
sub
(
r'\
B(
\+|@)(\
S*
\w)'
,
lambda
m
:
(
context_color
if
m
.
group
(
0
)[
0
]
==
"@"
else
project_color
)
+
m
.
group
(
0
)
+
color
,
p_todo_str
)
# tags
p_todo_str
=
re
.
sub
(
r'\b\
S+:[^/
\s]\
S*
\b'
,
metadata_color
+
r'\
g<
0>'
+
color
,
p_todo_str
)
# add link_color to any valid URL specified outside of the tag.
p_todo_str
=
re
.
sub
(
r'(^|\
s)(
\w+:){1}(//\
S+)
',
r'
\
1
' + link_color + r'
\
2
\
3
' + color,
p_todo_str)
p_todo_str += NEUTRAL_COLOR
# color by priority
p_todo_str = color + p_todo_str
return p_todo_str
class PrettyPrinterNumbers(PrettyPrinterFilter):
""" Prepends the todo'
s
number
,
retrieved
from
the
todolist
.
"""
def __init__(self, p_todolist):
super(PrettyPrinterNumbers, self).__init__()
self.todolist = p_todolist
def filter(self, p_todo_str, p_todo):
"""
Prepends
the
number
to
the
todo
string
.
"""
return u("|{:>3}| {}").format(self.todolist.number(p_todo), p_todo_str)
class PrettyPrinterFormatFilter(PrettyPrinterFilter):
def __init__(self, p_todolist, p_format=None):
super(PrettyPrinterFormatFilter, self).__init__()
self.parser = ListFormatParser(p_todolist, p_format)
def filter(self, p_todo_str, p_todo):
p_todo_str = self.parser.parse(p_todo)
return p_todo_str
topydo/lib/prettyprinters/Colors.py
0 → 100644
View file @
eb240558
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 - 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/>.
""" Provides a pretty printer filter that colorizes todo items. """
import
re
from
topydo.lib.Colors
import
NEUTRAL_COLOR
,
Colors
from
topydo.lib.Config
import
config
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterFilter
class
PrettyPrinterColorFilter
(
PrettyPrinterFilter
):
"""
Adds colors to the todo string by inserting ANSI codes.
Should be passed as a filter in the filter list of pretty_print()
"""
def
filter
(
self
,
p_todo_str
,
p_todo
):
""" Applies the colors. """
colorscheme
=
Colors
()
priority_colors
=
colorscheme
.
get_priority_colors
()
project_color
=
colorscheme
.
get_project_color
()
context_color
=
colorscheme
.
get_context_color
()
metadata_color
=
colorscheme
.
get_metadata_color
()
link_color
=
colorscheme
.
get_link_color
()
if
config
().
colors
():
color
=
NEUTRAL_COLOR
try
:
color
=
priority_colors
[
p_todo
.
priority
()]
except
KeyError
:
pass
# color projects / contexts
p_todo_str
=
re
.
sub
(
r'\
B(
\+|@)(\
S*
\w)'
,
lambda
m
:
(
context_color
if
m
.
group
(
0
)[
0
]
==
"@"
else
project_color
)
+
m
.
group
(
0
)
+
color
,
p_todo_str
)
# tags
p_todo_str
=
re
.
sub
(
r'\b\
S+:[^/
\s]\
S*
\b'
,
metadata_color
+
r'\
g<
0>'
+
color
,
p_todo_str
)
# add link_color to any valid URL specified outside of the tag.
p_todo_str
=
re
.
sub
(
r'(^|\
s)(
\w+:){1}(//\
S+)
',
r'
\
1
' + link_color + r'
\
2
\
3
' + color,
p_todo_str)
p_todo_str += NEUTRAL_COLOR
# color by priority
p_todo_str = color + p_todo_str
return p_todo_str
topydo/lib/prettyprinters/Format.py
0 → 100644
View file @
eb240558
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 - 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/>.
"""
Provides a pretty printer filter that generates a todo string based on a format
string.
"""
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterFilter
from
topydo.lib.ListFormat
import
ListFormatParser
class
PrettyPrinterFormatFilter
(
PrettyPrinterFilter
):
def
__init__
(
self
,
p_todolist
,
p_format
=
None
):
super
(
PrettyPrinterFormatFilter
,
self
).
__init__
()
self
.
parser
=
ListFormatParser
(
p_todolist
,
p_format
)
def
filter
(
self
,
p_todo_str
,
p_todo
):
p_todo_str
=
self
.
parser
.
parse
(
p_todo
)
return
p_todo_str
topydo/lib/prettyprinters/Numbers.py
0 → 100644
View file @
eb240558
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 - 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/>.
""" Provides a pretty printer filter that inserts todo numbers. """
from
six
import
u
from
topydo.lib.PrettyPrinterFilter
import
PrettyPrinterFilter
class
PrettyPrinterNumbers
(
PrettyPrinterFilter
):
""" Prepends the todo's number, retrieved from the todolist. """
def
__init__
(
self
,
p_todolist
):
super
(
PrettyPrinterNumbers
,
self
).
__init__
()
self
.
todolist
=
p_todolist
def
filter
(
self
,
p_todo_str
,
p_todo
):
""" Prepends the number to the todo string. """
return
u
(
"|{:>3}| {}"
).
format
(
self
.
todolist
.
number
(
p_todo
),
p_todo_str
)
topydo/lib/prettyprinters/__init__.py
0 → 100644
View file @
eb240558
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