From 85af72190de8f1efb857b99f68e94dd4ac5b1f82 Mon Sep 17 00:00:00 2001 From: Miguel Angel Garcia Date: Fri, 10 Aug 2018 05:59:34 +0200 Subject: [PATCH] #43 fix ascii issue for python 2 --- examples/located.py | 19 +++++++++++++++++++ inquirer/__init__.py | 2 +- inquirer/render/console/__init__.py | 2 ++ inquirer/render/console/_list.py | 1 - tests/unit/test_question.py | 9 +++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 examples/located.py diff --git a/examples/located.py b/examples/located.py new file mode 100644 index 00000000..f45ef8d0 --- /dev/null +++ b/examples/located.py @@ -0,0 +1,19 @@ +# encoding: utf-8 +import os +import sys +import re +sys.path.append(os.path.realpath('.')) +from pprint import pprint + +import inquirer + +LangQuestion = [ + inquirer.List('lang', + message="Select Language", + choices=['English', 'Français', 'Deutsche', 'Español'], + ), +] + +answers = inquirer.prompt(LangQuestion) + +pprint(answers) diff --git a/inquirer/__init__.py b/inquirer/__init__.py index cd4e3d0e..0503eded 100644 --- a/inquirer/__init__.py +++ b/inquirer/__init__.py @@ -1,6 +1,6 @@ from __future__ import print_function -__version__ = '2.2.0' +__version__ = '2.3.0' try: from .prompt import prompt diff --git a/inquirer/render/console/__init__.py b/inquirer/render/console/__init__.py index 993c421c..e46a28f9 100644 --- a/inquirer/render/console/__init__.py +++ b/inquirer/render/console/__init__.py @@ -68,6 +68,8 @@ def _print_status_bar(self, render): def _print_options(self, render): for message, symbol, color in render.get_options(): + if hasattr(message, 'decode'): # python 2 + message = message.decode('utf-8') self.print_line(' {color}{s} {m}{t.normal}', m=message, color=color, s=symbol) diff --git a/inquirer/render/console/_list.py b/inquirer/render/console/_list.py index ba46287f..a0510ace 100644 --- a/inquirer/render/console/_list.py +++ b/inquirer/render/console/_list.py @@ -45,7 +45,6 @@ def process_input(self, pressed): value = self.question.choices[self.current] raise errors.EndOfInput(getattr(value, 'value', value)) - raise errors.EndOfInput(self.question.choices[self.current]) if pressed == key.CTRL_C: raise KeyboardInterrupt() diff --git a/tests/unit/test_question.py b/tests/unit/test_question.py index fd58e995..3e00f089 100644 --- a/tests/unit/test_question.py +++ b/tests/unit/test_question.py @@ -1,3 +1,4 @@ +# encoding: utf-8 import unittest from inquirer import questions @@ -171,6 +172,14 @@ def test_factory_list_type(self): self.assertIsInstance(q, questions.List) self.assertEquals(name, q.name) + def test_factory_located_list_type(self): + name = 'ñçÑÇ' + q = questions.question_factory('list', name) + + self.assertEquals('list', q.kind) + self.assertIsInstance(q, questions.List) + self.assertEquals(name, q.name) + def test_factory_checkbox_type(self): name = 'foo' q = questions.question_factory('checkbox', name)