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
2b7ac602
Commit
2b7ac602
authored
Jun 15, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a pretty printer for colors and todo numbers.
parent
44da5d4f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
3 deletions
+60
-3
Config.py
Config.py
+2
-0
Main.py
Main.py
+1
-1
PrettyPrinter.py
PrettyPrinter.py
+49
-0
TodoList.py
TodoList.py
+2
-1
View.py
View.py
+6
-1
No files found.
Config.py
View file @
2b7ac602
...
...
@@ -3,6 +3,8 @@ This module contains some definitions to configure the application.
"""
DEFAULT_ACTION
=
'ls'
COLORS
=
True
HIGHLIGHT_PROJECTS_CONTEXTS
=
True
FILENAME
=
'todo.txt'
COMPLETED_FILENAME
=
'done.txt'
...
...
Main.py
View file @
2b7ac602
...
...
@@ -94,7 +94,7 @@ class Application(object):
if
len
(
sys
.
argv
)
>
2
:
filters
.
append
(
Filter
.
GrepFilter
(
sys
.
argv
[
2
]))
print
self
.
todolist
.
view
(
sorter
,
filters
)
print
self
.
todolist
.
view
(
sorter
,
filters
)
.
pretty_print
()
def
run
(
self
):
""" Main entry function. """
...
...
PrettyPrinter.py
0 → 100644
View file @
2b7ac602
""" Provides a function to pretty print a list of todo items. """
import
re
import
Config
PRIORITY_COLORS
=
{
'A'
:
'
\
033
[36m'
,
# cyan
'B'
:
'
\
033
[33m'
,
# yellow
'C'
:
'
\
033
[34m'
# blue
}
def
add_colors
(
p_todo_str
,
p_todo
):
""" Adds colors to the todo string by inserting ANSI codes. """
color
=
'
\
033
[0m'
try
:
color
=
PRIORITY_COLORS
[
p_todo
.
priority
()]
except
KeyError
:
pass
p_todo_str
=
'%s%s%s'
%
(
color
,
p_todo_str
,
'
\
033
[0m'
)
if
Config
.
HIGHLIGHT_PROJECTS_CONTEXTS
:
p_todo_str
=
re
.
sub
(
r'\
B(
\+|@)\
S+
', r'
\
033
[
31
m
\
g
<
0
>
' + color,
\
p_todo_str)
return p_todo_str
def pretty_print(p_todos, p_show_numbers=False, p_color=False):
"""
Given a list of todo items, pretty print it and return a list of
formatted strings.
"""
result = []
for todo in p_todos:
todo_str = str(todo)
if p_show_numbers:
todo_str = "%3d %s" % (todo.number, todo_str)
if Config.COLORS and p_color:
todo_str = add_colors(todo_str, todo)
result.append(todo_str)
return result
TodoList.py
View file @
2b7ac602
...
...
@@ -4,6 +4,7 @@ A list of todo items.
import
re
from
PrettyPrinter
import
pretty_print
import
Todo
import
View
...
...
@@ -100,5 +101,5 @@ class TodoList(object):
return View.View(p_sorter, p_filters, self._todos)
def __str__(self):
return '
\
n
'.join(
[str(x) for x in self._todos]
)
return '
\
n
'.join(
pretty_print(self._todos)
)
View.py
View file @
2b7ac602
from
PrettyPrinter
import
pretty_print
class
View
:
def
__init__
(
self
,
p_sorter
,
p_filters
,
p_todos
):
self
.
_todos
=
p_todos
...
...
@@ -17,5 +19,8 @@ class View:
for
_filter
in
self
.
_filters
:
self
.
_viewdata
=
_filter
.
filter
(
self
.
_viewdata
)
def
pretty_print
(
self
):
return
'
\
n
'
.
join
(
pretty_print
(
self
.
_todos
,
True
,
True
))
def
__str__
(
self
):
return
'
\
n
'
.
join
(
[
str
(
x
)
for
x
in
self
.
_viewdata
]
)
return
'
\
n
'
.
join
(
pretty_print
(
self
.
_todos
)
)
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