Commit 82f17dc6 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Printer methods must always return a string.

There is no need for clients of printers to assume anything about the
format. In this case, the View class assumed that the printer would
return a list of strings, and then the view joined those entries. This
latter step is actually the responsibility of the printer, so move it
there.
parent bcf68647
......@@ -75,7 +75,7 @@ class DCommand(Command):
def _print_list(self, p_todos):
printer = PrettyPrinter()
printer.add_filter(PrettyPrinterNumbers(self.todolist))
self.out("\n".join(printer.print_list(p_todos)))
self.out(printer.print_list(p_todos))
def prompt_text(self):
return "Yes or no? [y/N] "
......
......@@ -29,7 +29,7 @@ class Printer(object):
Given a list of todo items, pretty print it and return a list of
formatted strings.
"""
return [self.print_todo(todo) for todo in p_todos]
return "\n".join([self.print_todo(todo) for todo in p_todos])
class PrettyPrinter(Printer):
"""
......
......@@ -257,5 +257,5 @@ class TodoListBase(object):
def __str__(self):
printer = PrettyPrinter()
return '\n'.join(printer.print_list(self._todos))
return printer.print_list(self._todos)
......@@ -64,7 +64,7 @@ class View(object):
for ppf in p_pp_filters:
printer.add_filter(ppf)
return '\n'.join(printer.print_list(self._viewdata))
return printer.print_list(self._viewdata)
def __str__(self):
return '\n'.join(self._printer.print_list(self._viewdata))
return self._printer.print_list(self._viewdata)
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