From: W. Trevor King Date: Wed, 6 Feb 2013 17:59:39 +0000 (-0500) Subject: question: Add support for list-of-lines help X-Git-Tag: v0.1~23 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f13d065768d959442531d86d9202781996e1215a;p=quizzer.git 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. --- 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)