From: W. Trevor King Date: Thu, 14 Feb 2013 23:19:11 +0000 (-0500) Subject: ui.cli: Isolate ui.get_question() in QuestionCommandLine.get_question() X-Git-Tag: v0.2~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9e840075448d56f8dcef8e2f6d935d7a4b6c7de0;p=quizzer.git ui.cli: Isolate ui.get_question() in QuestionCommandLine.get_question() Ensure uniform handling across class methods by avoiding duplication. --- diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index 4a0fa49..a0f3652 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -45,9 +45,15 @@ class QuestionCommandLine (_cmd.Cmd): if self.ui.quiz.introduction: self.intro = '\n\n'.join([self.intro, self.ui.quiz.introduction]) - def preloop(self): + def get_question(self): self.question = self.ui.get_question() - self._reset() + if self.question: + self._reset() + else: + return True # out of questions + + def preloop(self): + self.get_question() def _reset(self): self.answers = [] @@ -89,10 +95,7 @@ class QuestionCommandLine (_cmd.Cmd): print(_colorize(self.ui.colors['correct'], 'correct\n')) else: print(_colorize(self.ui.colors['incorrect'], 'incorrect\n')) - self.question = self.ui.get_question() - if not self.question: - return True # out of questions - self._reset() + return self.get_question() def do_answer(self, arg): """Explicitly add a line to your answer @@ -112,10 +115,7 @@ class QuestionCommandLine (_cmd.Cmd): def do_skip(self, arg): "Skip the current question, and continue with the quiz" self.ui.stack.append(self.question) - self.question = self.ui.get_question() - if not self.question: - return True # out of questions - self._reset() + return self.get_question() def do_hint(self, arg): "Show a hint for the current question"