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
85ecf5b1
Commit
85ecf5b1
authored
Nov 19, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #80 from mruwek/colorblock-fix-truncate
Clear ANSI codes before output length calculations
parents
990173f8
1fe34e8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
4 deletions
+27
-4
test/test_list_format.py
test/test_list_format.py
+23
-0
topydo/lib/ListFormat.py
topydo/lib/ListFormat.py
+4
-4
No files found.
test/test_list_format.py
View file @
85ecf5b1
...
@@ -648,5 +648,28 @@ Z Z
...
@@ -648,5 +648,28 @@ Z Z
"""
"""
self.assertEqual(self.output, result)
self.assertEqual(self.output, result)
@mock.patch('
topydo
.
lib
.
ListFormat
.
get_terminal_size
')
def test_list_format43(self, mock_terminal_size):
""" Colorblocks should not affect truncating or right_alignment. """
self.maxDiff = None
mock_terminal_size.return_value = self.terminal_size(100, 25)
config(p_overrides={('
ls
', '
list_format
'): '
%
Z
|%
I
|
%
x
%
p
%
S
%
k
\\
t
%
{(}
h
{)}
'})
command1 = ListCommand(["-x"], self.todolist, self.out, self.error)
command1.execute()
config(p_overrides={('
ls
', '
list_format
'): '
%
z
|%
I
|
%
x
%
p
%
S
%
k
\\
t
%
{(}
h
{)}
'})
command2 = ListCommand(["-x"], self.todolist, self.out, self.error)
command2.execute()
result = u""" | 1| D Bar @Context1 +Project2 (due a month ago, started a month ago)
| 2| Z Lorem ipsum dolorem sit amet. Red @fox +jumpe... lazy:bar (due in 2 days, starts in a day)
| 3| C Foo @Context2 Not@Context +Project1 Not+Project
| 4| C Baz @Context1 +Project1 key:value
| 5| Drink beer @ home
| 6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result * 2)
if __name__ == '
__main__
':
if __name__ == '
__main__
':
unittest.main()
unittest.main()
topydo/lib/ListFormat.py
View file @
85ecf5b1
...
@@ -23,7 +23,7 @@ from six import u
...
@@ -23,7 +23,7 @@ from six import u
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
from
topydo.lib.Colorblock
import
color_block
from
topydo.lib.Colorblock
import
color_block
from
topydo.lib.Utils
import
get_terminal_size
from
topydo.lib.Utils
import
get_terminal_size
,
escape_ansi
MAIN_PATTERN
=
(
r'^({{(?P<before>.+?)}})?'
MAIN_PATTERN
=
(
r'^({{(?P<before>.+?)}})?'
r'(?P<placeholder>{ph}|\
[{ph}
\])'
r'(?P<placeholder>{ph}|\
[{ph}
\])'
...
@@ -110,7 +110,7 @@ def _truncate(p_str, p_repl):
...
@@ -110,7 +110,7 @@ def _truncate(p_str, p_repl):
Place of the truncation is calculated depending on p_max_width.
Place of the truncation is calculated depending on p_max_width.
"""
"""
# 4 is for '...' and an extra space at the end
# 4 is for '...' and an extra space at the end
text_lim
=
_columns
()
-
len
(
p_str
)
-
4
text_lim
=
_columns
()
-
len
(
escape_ansi
(
p_str
)
)
-
4
truncated_str
=
re
.
sub
(
re
.
escape
(
p_repl
),
p_repl
[:
text_lim
]
+
'...'
,
p_str
)
truncated_str
=
re
.
sub
(
re
.
escape
(
p_repl
),
p_repl
[:
text_lim
]
+
'...'
,
p_str
)
return
truncated_str
return
truncated_str
...
@@ -122,7 +122,7 @@ def _right_align(p_str):
...
@@ -122,7 +122,7 @@ def _right_align(p_str):
Right alignment is done using proper number of spaces calculated from
Right alignment is done using proper number of spaces calculated from
'line_width' attribute.
'line_width' attribute.
"""
"""
to_fill
=
_columns
()
-
len
(
p_str
)
to_fill
=
_columns
()
-
len
(
escape_ansi
(
p_str
)
)
if
to_fill
>
0
:
if
to_fill
>
0
:
p_str
=
re
.
sub
(
'
\
t
'
,
' '
*
to_fill
,
p_str
)
p_str
=
re
.
sub
(
'
\
t
'
,
' '
*
to_fill
,
p_str
)
...
@@ -272,7 +272,7 @@ class ListFormatParser(object):
...
@@ -272,7 +272,7 @@ class ListFormatParser(object):
parsed_str = _unescape_percent_sign(''.join(parsed_list))
parsed_str = _unescape_percent_sign(''.join(parsed_list))
parsed_str = _remove_redundant_spaces(parsed_str)
parsed_str = _remove_redundant_spaces(parsed_str)
if self.one_line and len(
parsed_str
) >= _columns():
if self.one_line and len(
escape_ansi(parsed_str)
) >= _columns():
parsed_str = _truncate(parsed_str, repl_trunc)
parsed_str = _truncate(parsed_str, repl_trunc)
if re.search('
.
*
\
t
', parsed_str):
if re.search('
.
*
\
t
', parsed_str):
...
...
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