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
4352ece9
Commit
4352ece9
authored
Nov 20, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #81 from mruwek/colorblock-fix-pri-colors
Fix priority colors when using colorblocks.
parents
26371a66
c3f7e1b5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
101 deletions
+105
-101
test/test_colors.py
test/test_colors.py
+36
-36
topydo/lib/Colorblock.py
topydo/lib/Colorblock.py
+3
-2
topydo/lib/Colors.py
topydo/lib/Colors.py
+65
-56
topydo/lib/prettyprinters/Colors.py
topydo/lib/prettyprinters/Colors.py
+1
-7
No files found.
test/test_colors.py
View file @
4352ece9
...
...
@@ -122,49 +122,49 @@ class ColorsTest(TopydoTest):
def
test_priority_color1
(
self
):
config
(
"test/data/ColorsTest1.conf"
)
color
=
Colors
().
get_priority_c
olors
()
color
s
=
C
olors
()
self
.
assertEqual
(
color
[
'A'
]
,
'
\
033
[0;38;5;1m'
)
self
.
assertEqual
(
color
[
'B'
]
,
'
\
033
[0;38;5;2m'
)
self
.
assertEqual
(
color
[
'C'
]
,
'
\
033
[0;38;5;3m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'A'
)
,
'
\
033
[0;38;5;1m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'B'
)
,
'
\
033
[0;38;5;2m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'C'
)
,
'
\
033
[0;38;5;3m'
)
def
test_priority_color2
(
self
):
config
(
"test/data/ColorsTest2.conf"
)
color
=
Colors
().
get_priority_c
olors
()
color
s
=
C
olors
()
self
.
assertEqual
(
color
[
'A'
]
,
'
\
033
[0;35m'
)
self
.
assertEqual
(
color
[
'B'
]
,
'
\
033
[0;1;36m'
)
self
.
assertEqual
(
color
[
'C'
]
,
'
\
033
[0;37m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'A'
)
,
'
\
033
[0;35m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'B'
)
,
'
\
033
[0;1;36m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'C'
)
,
'
\
033
[0;37m'
)
def
test_priority_color3
(
self
):
config
(
"test/data/ColorsTest3.conf"
)
color
=
Colors
().
get_priority_c
olors
()
color
s
=
C
olors
()
self
.
assertEqual
(
color
[
'A'
]
,
'
\
033
[0;35m'
)
self
.
assertEqual
(
color
[
'B'
]
,
'
\
033
[0;1;36m'
)
self
.
assertEqual
(
color
[
'Z'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
[
'D'
]
,
'
\
033
[0;31m'
)
self
.
assertEqual
(
color
[
'C'
]
,
'
\
033
[0;38;5;7m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'A'
)
,
'
\
033
[0;35m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'B'
)
,
'
\
033
[0;1;36m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'Z'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'D'
)
,
'
\
033
[0;31m'
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'C'
)
,
'
\
033
[0;38;5;7m'
)
def
test_priority_color4
(
self
):
config
(
"test/data/ColorsTest4.conf"
)
color
=
Colors
().
get_priority_c
olors
()
color
s
=
C
olors
()
self
.
assertEqual
(
color
[
'A'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
[
'B'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
[
'C'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'A'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'B'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
color
s
.
get_priority_color
(
'C'
)
,
NEUTRAL_COLOR
)
def
test_empty_color_values
(
self
):
config
(
"test/data/ColorsTest5.conf"
)
pri_color
=
Colors
().
get_priority_c
olors
()
project_color
=
Colors
()
.
get_project_color
()
context_color
=
Colors
()
.
get_context_color
()
link_color
=
Colors
()
.
get_link_color
()
metadata_color
=
Colors
()
.
get_metadata_color
()
self
.
assertEqual
(
pri_color
[
'A'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
pri_color
[
'B'
]
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
pri_color
[
'C'
]
,
NEUTRAL_COLOR
)
colors
=
C
olors
()
project_color
=
colors
.
get_project_color
()
context_color
=
colors
.
get_context_color
()
link_color
=
colors
.
get_link_color
()
metadata_color
=
colors
.
get_metadata_color
()
self
.
assertEqual
(
colors
.
get_priority_color
(
'A'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
colors
.
get_priority_color
(
'B'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
colors
.
get_priority_color
(
'C'
)
,
NEUTRAL_COLOR
)
self
.
assertEqual
(
project_color
,
''
)
self
.
assertEqual
(
context_color
,
''
)
self
.
assertEqual
(
link_color
,
''
)
...
...
@@ -172,15 +172,15 @@ class ColorsTest(TopydoTest):
def
test_empty_colorscheme
(
self
):
config
(
"test/data/config1"
)
pri_color
=
Colors
().
get_priority_c
olors
()
project_color
=
Colors
()
.
get_project_color
()
context_color
=
Colors
()
.
get_context_color
()
link_color
=
Colors
()
.
get_link_color
()
metadata_color
=
Colors
()
.
get_metadata_color
()
self
.
assertEqual
(
pri_color
[
'A'
]
,
'
\
033
[0;36m'
)
self
.
assertEqual
(
pri_color
[
'B'
]
,
'
\
033
[0;33m'
)
self
.
assertEqual
(
pri_color
[
'C'
]
,
'
\
033
[0;34m'
)
colors
=
C
olors
()
project_color
=
colors
.
get_project_color
()
context_color
=
colors
.
get_context_color
()
link_color
=
colors
.
get_link_color
()
metadata_color
=
colors
.
get_metadata_color
()
self
.
assertEqual
(
colors
.
get_priority_color
(
'A'
)
,
'
\
033
[0;36m'
)
self
.
assertEqual
(
colors
.
get_priority_color
(
'B'
)
,
'
\
033
[0;33m'
)
self
.
assertEqual
(
colors
.
get_priority_color
(
'C'
)
,
'
\
033
[0;34m'
)
self
.
assertEqual
(
project_color
,
'
\
033
[1;31m'
)
self
.
assertEqual
(
context_color
,
'
\
033
[1;35m'
)
self
.
assertEqual
(
link_color
,
'
\
033
[4;36m'
)
...
...
topydo/lib/Colorblock.py
View file @
4352ece9
...
...
@@ -16,7 +16,7 @@
import
re
from
topydo.lib.Colors
import
int_to_ansi
,
NEUTRAL_COLOR
from
topydo.lib.Colors
import
int_to_ansi
,
Colors
from
topydo.lib.Recurrence
import
relative_date_to_date
COLOR16_RANGE
=
[
...
...
@@ -95,6 +95,7 @@ def progress_color_code(p_todo, p_safe=True):
def color_block(p_todo, p_safe=True):
color_code = progress_color_code(p_todo, p_safe)
ansi_code = int_to_ansi(color_code, p_safe=p_safe, p_background=color_code)
priority_color = Colors().get_priority_color(p_todo.priority())
return '
{}
{}
'.format(ansi_code,
NEUTRAL_COLOR
)
return '
{}
{}
'.format(ansi_code,
priority_color
)
topydo/lib/Colors.py
View file @
4352ece9
...
...
@@ -59,80 +59,89 @@ def int_to_ansi(p_int, p_decorator='normal', p_safe=True, p_background=''):
except
ValueError
:
return
None
def
_name_to_int
(
p_color_name
):
""" Returns xterm color id from color name. """
color_names_dict
=
{
'black'
:
0
,
'red'
:
1
,
'green'
:
2
,
'yellow'
:
3
,
'blue'
:
4
,
'magenta'
:
5
,
'cyan'
:
6
,
'gray'
:
7
,
'darkgray'
:
8
,
'light-red'
:
9
,
'light-green'
:
10
,
'light-yellow'
:
11
,
'light-blue'
:
12
,
'light-magenta'
:
13
,
'light-cyan'
:
14
,
'white'
:
15
,
}
class
Colors
(
object
):
def
__init__
(
self
):
self
.
priority_colors
=
config
().
priority_colors
()
self
.
project_color
=
config
().
project_color
()
self
.
context_color
=
config
().
context_color
()
self
.
metadata_color
=
config
().
metadata_color
()
self
.
link_color
=
config
().
link_color
()
try
:
return
color_names_dict
[
p_color_name
]
except
KeyError
:
return
404
def
_name_to_int
(
self
,
p_color_name
):
""" Returns xterm color id from color name. """
color_names_dict
=
{
'black'
:
0
,
'red'
:
1
,
'green'
:
2
,
'yellow'
:
3
,
'blue'
:
4
,
'magenta'
:
5
,
'cyan'
:
6
,
'gray'
:
7
,
'darkgray'
:
8
,
'light-red'
:
9
,
'light-green'
:
10
,
'light-yellow'
:
11
,
'light-blue'
:
12
,
'light-magenta'
:
13
,
'light-cyan'
:
14
,
'white'
:
15
,
}
def
_name_to_ansi
(
p_color_name
,
p_decorator
):
""" Returns ansi color code from color name. """
number
=
_name_to_int
(
p_color_name
)
try
:
return
color_names_dict
[
p_color_name
]
except
KeyError
:
return
404
return
int_to_ansi
(
number
,
p_decorator
)
def
_name_to_ansi
(
self
,
p_color_name
,
p_decorator
):
""" Returns ansi color code from color name. """
number
=
self
.
_name_to_int
(
p_color_name
)
def
_get_ansi
(
p_color
,
p_decorator
):
""" Returns ansi color code from color name or xterm color id. """
if
p_color
==
''
:
ansi
=
''
else
:
ansi
=
int_to_ansi
(
p_color
,
p_decorator
,
False
)
return
int_to_ansi
(
number
,
p_decorator
)
if
not
ansi
:
ansi
=
_name_to_ansi
(
p_color
,
p_decorator
)
def
_get_ansi
(
self
,
p_color
,
p_decorator
):
""" Returns ansi color code from color name or xterm color id. """
if
p_color
==
''
:
ansi
=
''
else
:
ansi
=
int_to_ansi
(
p_color
,
p_decorator
,
False
)
return
ansi
if
not
ansi
:
ansi
=
self
.
_name_to_ansi
(
p_color
,
p_decorator
)
def
_get_priority_colors
():
pri_ansi_colors
=
dict
()
pri_colors
=
config
().
priority_colors
()
return
ansi
for
pri
in
pri_colors
:
color
=
_get_ansi
(
pri_colors
[
pri
],
'normal'
)
def
get_priority_colors
(
self
)
:
pri_ansi_colors
=
dict
()
if
color
==
''
:
color
=
NEUTRAL_COLOR
for
pri
in
self
.
priority_colors
:
color
=
self
.
_get_ansi
(
self
.
priority_colors
[
pri
],
'normal'
)
pri_ansi_colors
[
pri
]
=
color
if
color
==
''
:
color
=
NEUTRAL_COLOR
return
pri_ansi_colors
pri_ansi_colors
[
pri
]
=
color
return
pri_ansi_colors
class
Colors
(
object
):
def
__init__
(
self
):
self
.
priority_colors
=
_get_priority_colors
()
self
.
project_color
=
config
().
project_color
()
self
.
context_color
=
config
().
context_color
()
self
.
metadata_color
=
config
().
metadata_color
()
self
.
link_color
=
config
().
link_color
()
def
get_project_color
(
self
):
return
self
.
_get_ansi
(
self
.
project_color
,
'bold'
)
return
_get_ansi
(
self
.
project_color
,
'bold'
)
def
get_context_color
(
self
):
return
self
.
_get_ansi
(
self
.
context_color
,
'bold'
)
return
_get_ansi
(
self
.
context_color
,
'bold'
)
def
get_metadata_color
(
self
):
return
self
.
_get_ansi
(
self
.
metadata_color
,
'bold'
)
return
_get_ansi
(
self
.
metadata_color
,
'bold'
)
def
get_link_color
(
self
):
return
self
.
_get_ansi
(
self
.
link_color
,
'underline'
)
return
_get_ansi
(
self
.
link_color
,
'underline'
)
def
get_priority_color
(
self
,
p_priority
):
try
:
priority_color
=
self
.
priority_colors
[
p_priority
]
except
KeyError
:
priority_color
=
NEUTRAL_COLOR
return
priority_color
topydo/lib/prettyprinters/Colors.py
View file @
4352ece9
...
...
@@ -34,18 +34,12 @@ class PrettyPrinterColorFilter(PrettyPrinterFilter):
""" Applies the colors. """
if
config
().
colors
():
colorscheme
=
Colors
()
priority_color
s
=
colorscheme
.
get_priority_colors
(
)
priority_color
=
colorscheme
.
get_priority_color
(
p_todo
.
priority
()
)
project_color
=
colorscheme
.
get_project_color
()
context_color
=
colorscheme
.
get_context_color
()
metadata_color
=
colorscheme
.
get_metadata_color
()
link_color
=
colorscheme
.
get_link_color
()
priority_color
=
NEUTRAL_COLOR
try
:
priority_color
=
priority_colors
[
p_todo
.
priority
()]
except
KeyError
:
pass
# color projects / contexts
p_todo_str
=
re
.
sub
(
r'\
B(
\+|@)(\
S*
\w)'
,
...
...
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