Commit efb128c3 authored by Jacek Sowiński's avatar Jacek Sowiński

Add indentation to format string before parsing it

This way we can safely remove `PrettyPrinterIndentFilter` and output
length is still properly maintained by `ListFormatParser`.
parent 74a741d8
......@@ -628,6 +628,23 @@ Z Z
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
@mock.patch('topydo.lib.ListFormat.get_terminal_size')
def test_list_format42(self, mock_terminal_size):
mock_terminal_size.return_value = self.terminal_size(100, 25)
config('test/data/listformat.conf', p_overrides={('ls', 'indent'): '3'})
command = ListCommand(["-x"], self.todolist, self.out, self.error)
command.execute()
result = u""" | 1| (D) 2015-08-31 Bar @Context1 +Project2 due:2015-09-30 t:2015-09-29
| 2| (Z) 2015-11-06 Lorem ipsum dolorem sit amet. Red @... due:2015-11-08 lazy:bar t:2015-11-07
| 3| (C) 2015-07-12 Foo @Context2 Not@Context +Project1 Not+Project
| 4| (C) Baz @Context1 +Project1 key:value
| 5| Drink beer @ home ical:foobar id:1 p:2
| 6| x 2014-12-12 Completed but with date:2014-12-12
"""
self.assertEqual(self.output, result)
......
......@@ -18,8 +18,7 @@ from topydo.lib.Config import config
from topydo.lib.ExpressionCommand import ExpressionCommand
from topydo.lib.ListFormat import ListFormatParser
from topydo.lib.PrettyPrinter import pretty_printer_factory
from topydo.lib.PrettyPrinterFilter import (PrettyPrinterIndentFilter,
PrettyPrinterFormatFilter)
from topydo.lib.PrettyPrinterFilter import PrettyPrinterFormatFilter
class ListCommand(ExpressionCommand):
......@@ -87,11 +86,11 @@ class ListCommand(ExpressionCommand):
if self.printer is None:
# create a standard printer with some filters
indent = config().list_indent()
final_format = ' ' * indent + self.format
hidden_tags = config().hidden_tags()
filters = []
filters.append(PrettyPrinterFormatFilter(self.todolist, self.format))
filters.append(PrettyPrinterIndentFilter(indent))
filters.append(PrettyPrinterFormatFilter(self.todolist, final_format))
self.printer = pretty_printer_factory(self.todolist, filters)
......
......@@ -90,18 +90,6 @@ class PrettyPrinterColorFilter(PrettyPrinterFilter):
return p_todo_str
class PrettyPrinterIndentFilter(PrettyPrinterFilter):
""" Adds indentation to the todo item. """
def __init__(self, p_indent=0):
super(PrettyPrinterIndentFilter, self).__init__()
self.indent = p_indent
def filter(self, p_todo_str, _):
""" Applies the indentation. """
return ' ' * self.indent + p_todo_str
class PrettyPrinterNumbers(PrettyPrinterFilter):
""" Prepends the todo's number, retrieved from the todolist. """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment