Esempio n. 1
0
 def test_screen_input_quit_enabled_none_default(self, get_input_mock):
     with self.assertRaises(UserQuit):
         Screen().input(prompt='This is my message',
                        validators=UrlValidator(),
                        default='https://www.google.com',
                        enable_quit=True,
                        quit_string='exit')
Esempio n. 2
0
    def test_screen_input_validators_with_default(self, get_input_mock):
        input_result = Screen().input(prompt='This is my message',
                                      validators=UrlValidator(),
                                      default='https://www.google.com')

        self.assertTrue(input_result.validation_result)
        self.assertEquals(input_result.input_string, 'https://www.google.com')
Esempio n. 3
0
 def test_screen_input_validation_regex_and_url_all_false(
         self, get_input_mock):
     input_result = Screen().input(
         prompt='This is my message',
         validators=[RegexValidator(pattern='notpresent'),
                     UrlValidator()])
     self.assertFalse(input_result.validation_result)
     self.assertEquals(input_result.input_string, 'https://www.google.com')
Esempio n. 4
0
    def setUp(self):
        self.mock_screen = Mock(spec=Screen())
        self.mock_screen.input.return_value = 4

        self.patcher = patch(target='consolemenu.console_menu.Screen',
                             new=self.mock_screen)
        self.patcher.start()
        self.addCleanup(self.patcher.stop)
Esempio n. 5
0
def get_input_words():
    prompt = 'To generate a poem, type some words separated by commas or spaces, and then press enter.\n\n'

    input_words = []
    while len(input_words) == 0:
        inp = Screen().input(prompt=prompt)
        input_words = [word for word in re.split(r'[\s,]', inp) if word]
    return input_words
 def test_format_with_item_borders(self):
     format = MenuFormatBuilder()
     item1 = MenuItem("This is Item 1")
     item2 = MenuItem("This is Item 2")
     item3 = MenuItem("This is Item 3")
     format.show_item_top_border(item2, True)
     format.show_item_bottom_border(item2, True)
     print("This should show both top and bottom borders on item 2...")
     Screen().printf(
         format.format(title="This is My Title",
                       subtitle="This is My Subtitle",
                       items=[item1, item2, item3]))
     # Now turn off the borders
     format.show_item_top_border(item2, False)
     format.show_item_bottom_border(item2, False)
     print("This should NOT show any borders on item 2...")
     Screen().printf(
         format.format(title="This is My Title",
                       subtitle="This is My Subtitle",
                       items=[item1, item2, item3]))
 def test_defaults(self):
     print_screen_edge()
     format = MenuFormatBuilder()
     items = [
         MenuItem("This is Item 1"),
         MenuItem("This is Item 2"),
         MenuItem("This is Item 3")
     ]
     Screen().printf(
         format.format(title="This is My Title",
                       subtitle="This is My Little Subtitle",
                       items=items))
Esempio n. 8
0
 def test_clear(self):
     # clear will raise error if TERM is not set
     if os.getenv('TERM') is None:
         os.environ['TERM'] = 'xterm'
     screen = Screen()
     screen.println('Clearing screen...')
     screen.clear()
 def test_format_with_prologue_with_top_border(self):
     format = MenuFormatBuilder().show_prologue_top_border(True)
     items = [
         MenuItem("This is Item 1"),
         MenuItem("This is Item 2"),
         MenuItem("This is Item 3")
     ]
     prologue_text = "This is my prologue. Follow these instructions."
     Screen().printf(
         format.format(title="This is My Title",
                       subtitle="This is My Subtitle",
                       items=items,
                       prologue_text=prologue_text))
    def test_format_with_prologue_no_border(self):
        format = MenuFormatBuilder()
        items = [
            MenuItem("This is Item 1"),
            MenuItem("This is Item 2"),
            MenuItem("This is Item 3")
        ]
        prologue_text = 'This a very long prologue, which can be used to explain how to use this menu, \
for people that might not understand it.'

        Screen().printf(
            format.format(title="This is My Title",
                          subtitle="This is My Subtitle",
                          items=items,
                          prologue_text=prologue_text))
    def test_format_with_long_prologue_with_both_borders(self):
        format = MenuFormatBuilder().show_prologue_top_border(
            True).show_prologue_bottom_border(True)
        items = [
            MenuItem("This is Item 1"),
            MenuItem("This is Item 2"),
            MenuItem("This is Item 3")
        ]
        prologue_text = 'This a very long prologue, which can be used to explain how to use this menu, \
for people that might not understand it. But if they read this description it can help them. Also, I have both \
my top and bottom borders enabled, so you should see them.'

        Screen().printf(
            format.format(title="This is My Title",
                          subtitle="This is My Subtitle",
                          items=items,
                          prologue_text=prologue_text))
    def __init__(self,
                 title=None,
                 subtitle=None,
                 screen=None,
                 formatter=None,
                 prologue_text=None,
                 epilogue_text=None,
                 show_exit_option=True,
                 exit_option_text='Exit'):
        if screen is None:
            screen = Screen()
        self.screen = screen

        if formatter is None:
            formatter = MenuFormatBuilder()
        self.formatter = formatter

        self.title = title
        self.subtitle = subtitle
        self.prologue_text = prologue_text
        self.epilogue_text = epilogue_text

        self.highlight = None
        self.normal = None

        self.show_exit_option = show_exit_option

        self.items = list()

        self.parent = None

        self.exit_item = ExitItem(menu=self, text=exit_option_text)

        self.current_option = 0
        self.selected_option = -1

        self.returned_value = None

        self.should_exit = False

        self.previous_active_menu = None

        self._main_thread = None

        self._running = threading.Event()
Esempio n. 13
0
    def test_screen_input_validators_None(self, get_input_mock):
        input_result = Screen().input(prompt='This is my message',
                                      validators=None)

        self.assertTrue(input_result.validation_result)
        self.assertEquals(input_result.input_string, 'https://asdasd')
Esempio n. 14
0
 def test_flush(self):
     screen = Screen()
     # standard printf will buffer, so output won't come until newline
     screen.println('The next line should print all at once...')
     for i in range(0, 40):
         screen.printf('.')
         time.sleep(0.5)
     screen.println()
     # now flush after each dot
     screen.println('The next line should print smoothly...')
     for i in range(0, 40):
         screen.printf('.')
         screen.flush()
         time.sleep(0.5)
     screen.println()
Esempio n. 15
0
 def test_input(self, get_input_mock):
     input_string = Screen().input(prompt='This is my message')
     self.assertEqual(input_string, 'This is my Cat')
 def test_empty(self):
     Screen().printf(MenuFormatBuilder().format())
Esempio n. 17
0
 def test_screen_size(self):
     screen = Screen()
     print('screen height:', screen.screen_height)
     print('screen width:', screen.screen_width)
     self.assertEqual(40, screen.screen_height)
     self.assertEqual(80, screen.screen_width)
Esempio n. 18
0
 def test_screen_input_validation_regex_false(self, get_input_mock):
     input_result = Screen().input(prompt='This is my message',
                                   validators=RegexValidator(pattern='Cat'))
     self.assertFalse(input_result.validation_result)
     self.assertEquals(input_result.input_string, 'This is my Cat')
Esempio n. 19
0
 def test_clear(self):
     screen = Screen()
     screen.println('Clearing screen...')
     screen.clear()
Esempio n. 20
0
 def test_screen_size(self):
     screen = Screen()
     print('screen height:', screen.screen_height)
     print('screen width:', screen.screen_width)
Esempio n. 21
0
 def test_println(self):
     screen = Screen()
     screen.println('single message.')
     screen.println('this a second line.')
     screen.println('this', 'is', 'a', 'list', 'message')
     screen.println(
         'same is a line with an explicit newline, which should cause an empty space below me.\n'
     )
     screen.println('this is a %s message.' % 'printf-style')
     screen.println('this is a {0} message.'.format('format-style'))
Esempio n. 22
0
 def test_screen_input_validation_invalid_validation(self, get_input_mock):
     with self.assertRaises(InvalidValidator):
         Screen().input(prompt='This is my message', validators=[None])
Esempio n. 23
0
    def __init__(self,
                 title=None,
                 subtitle=None,
                 show_exit_option=True,
                 screen=None,
                 formatter=None,
                 prologue_text=None,
                 epilogue_text=None):
        """
        :ivar str title: The title of the menu
        :ivar str subtitle: The subtitle of the menu
        :ivar bool show_exit_option: Whether this menu should show an exit item by default. Can be overridden \
        when the menu is started
        :ivar items: The list of MenuItems that the menu will display
        :vartype items: list[:class:`MenuItem<consolemenu.items.MenuItem>`]
        :ivar ConsoleMenu parent: The parent of this menu
        :ivar ConsoleMenu previous_active_menu: the previously active menu to be restored into the class's \
        currently active menu
        :ivar int current_option: The currently highlighted menu option
        :ivar MenuItem current_item: The item corresponding to the menu option that is currently highlighted
        :ivar int selected_option: The option that the user has most recently selected
        :ivar MenuItem selected_item: The item in :attr:`items` that the user most recently selected
        :ivar returned_value: The value returned by the most recently selected item
        :ivar screen: the screen object associated with this menu
        :ivar formatter: the MenuFormatBuilder instance used to format this menu.
        :ivar prologue_text: Text to include in the "prologue" section of the menu.
        :ivar epilogue_text: Text to include in the "epilogue" section of the menu.
        :ivar normal: the normal text color pair for this menu
        :ivar highlight: the highlight color pair associated with this window
        """

        if screen is None:
            screen = Screen()
        self.screen = screen

        if formatter is None:
            formatter = MenuFormatBuilder()
        self.formatter = formatter

        self.title = title
        self.subtitle = subtitle
        self.prologue_text = prologue_text
        self.epilogue_text = epilogue_text

        self.highlight = None
        self.normal = None

        self.show_exit_option = show_exit_option

        self.items = list()

        self.parent = None

        self.exit_item = ExitItem(menu=self)

        self.current_option = 0
        self.selected_option = -1

        self.returned_value = None

        self.should_exit = False

        self.previous_active_menu = None

        self._main_thread = None

        self._running = threading.Event()
Esempio n. 24
0
 def test_printf(self):
     screen = Screen()
     screen.printf('single message.')
     screen.printf(
         'this should be on ame line as above. explicit newline: \n')
     screen.printf('this', 'is', 'a', 'list', 'message')
     screen.printf('same line as list message', 'explicit newline: \n')
     screen.printf('this is a %s message.\n' % 'printf-style')
     screen.printf('this is a {0} message.\n'.format('format-style'))