From f13d065768d959442531d86d9202781996e1215a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 6 Feb 2013 12:59:39 -0500 Subject: [PATCH] question: Add support for list-of-lines help We use lists of lines for other question attributes (e.g. setup, teardown, answer, prompt). Be consistent with multi-line help. --- quizzer/question.py | 15 +++++++++++---- quizzer/ui/cli.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/quizzer/question.py b/quizzer/question.py index 8b2f6dc..da722df 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -74,10 +74,17 @@ class Question (object): def check(self, answer): return answer == self.answer - def format_prompt(self, newline='\n'): - if isinstance(self.prompt, str): - return self.prompt - return newline.join(self.prompt) + def _format_attribute(self, attribute, newline='\n'): + value = getattr(self, attribute) + if isinstance(value, str): + return value + return newline.join(value) + + def format_prompt(self, **kwargs): + return self._format_attribute(attribute='prompt', **kwargs) + + def format_help(self, **kwargs): + return self._format_attribute(attribute='help', **kwargs) class NormalizedStringQuestion (Question): diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index a9bb100..064f308 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -43,7 +43,7 @@ class CommandLineInterface (UserInterface): if a in ['?', 'help']: print() print(question.format_prompt()) - print(question.help) + print(question.format_help()) continue if question.multiline: answers.append(answer) -- 2.26.2