Commit cb403037 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add pretty printer filter for adding indent.

parent 6f8e873c
......@@ -8,6 +8,7 @@ colors = 1
highlight_projects_contexts = 1
[ls]
indent = 0
list_limit = -1
[tags]
......
......@@ -127,6 +127,16 @@ class ListCommandTest(CommandTest.CommandTest):
self.assertEquals(self.output, " 1 (C) Foo @Context2 Not@Context +Project1 Not+Project\n 3 (C) Baz @Context1 +Project1 key:value id:1\n 4 (C) Drink beer @ home\n 5 (C) 13 + 29 = 42\n")
self.assertEquals(self.errors, "")
def test_list14(self):
config("data/listcommand2.conf")
command = ListCommand.ListCommand([], self.todolist, self.out, self.error)
command.execute()
self.assertFalse(self.todolist.is_dirty())
self.assertEquals(self.output, " 1 (C) Foo @Context2 Not@Context +Project1 Not+Project\n 4 (C) Drink beer @ home\n 5 (C) 13 + 29 = 42\n 2 (D) Bar @Context1 +Project2 p:1\n")
self.assertEquals(self.errors, "")
def test_help(self):
command = ListCommand.ListCommand(["help"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -38,6 +38,7 @@ class _Config:
'archive_filename' : 'done.txt',
# ls
'indent': 0,
'list_limit': '-1',
# tags
......@@ -95,6 +96,12 @@ class _Config:
except ValueError:
return int(self.defaults['list_limit'])
def list_indent(self):
try:
return self.cp.getint('ls', 'indent')
except ValueError:
return int(self.defaults['indent'])
def sort_string(self):
return self.cp.get('sort', 'sort_string')
......
......@@ -17,6 +17,7 @@
import Command
from Config import config
import Filter
from PrettyPrinter import pp_indent
import Sorter
class ListCommand(Command.Command):
......@@ -40,7 +41,6 @@ class ListCommand(Command.Command):
self.args = args
def _filters(self):
filters = []
......@@ -74,7 +74,8 @@ class ListCommand(Command.Command):
sorter = Sorter.Sorter(self.sort_expression)
filters = self._filters()
self.out(self.todolist.view(sorter, filters).pretty_print())
pp_filters = [pp_indent(config().list_indent())]
self.out(self.todolist.view(sorter, filters).pretty_print(pp_filters))
def usage(self):
return """Synopsis: ls [-x] [-s <sort_expression>] [expression]"""
......
......@@ -53,6 +53,9 @@ def pp_color(p_todo_str, p_todo):
return p_todo_str
def pp_indent(p_indent=0):
return lambda s, t: ' ' * p_indent + s
def pretty_print(p_todo, p_filters=[]):
"""
Given a todo item, pretty print it and return a list of formatted strings.
......
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