Exemplo n.º 1
0
def handle_regex_command(logria: 'Logria',
                         command: str) -> None:  # type: ignore
    """
    Handle a regex command
    """
    reset_regex_status(logria)
    regex_func = regex_test_generator(command)
    if regex_func is None:
        logria.write_to_command_line(f'Invalid regex pattern: {command}')
        return
    logria.func_handle = regex_test_generator(command)
    logria.highlight_match = True
    logria.regex_pattern = command

    # Tell the user what is happening since this is synchronous
    logria.current_status = f'Searching buffer for regex /{logria.regex_pattern}/'
    logria.write_to_command_line(logria.current_status)

    # Process any new matched messages to render
    process_matches(logria)

    # Tell the user we are now filtering
    logria.current_status = f'Regex with pattern /{logria.regex_pattern}/'
    logria.write_to_command_line(logria.current_status)

    # Render the text
    logria.render_text_in_output()
    curses.curs_set(0)
Exemplo n.º 2
0
    def test_can_render_matches(self):
        """
        Test we render properly when using matches
        """
        os.environ['TERM'] = 'dumb'
        app = Logria(None, False, False)

        # Fake window size: 10 x 100
        app.height = 10
        app.width = 100

        # Set fake previous render
        app.last_row = app.height - 3  # simulate the last row we can render to
        app.current_end = 80  # Simulate the last message rendered

        # Set fake messages
        app.messages = [f'{x}|{x}' for x in range(20)]

        # Set fake filter
        app.func_handle = regex_generator.regex_test_generator(r'\d\|\d')
        process_matches(app)

        # Set positional booleans
        app.manually_controlled_line = False
        app.stick_to_top = True
        app.stick_to_bottom = False

        start, end = determine_position(app, app.matched_rows)
        self.assertEqual(start, -1)
        self.assertEqual(end, 6)
        app.stop()
Exemplo n.º 3
0
    def handle_regex_command(self, command: str) -> None:
        """
        Handle a regex command
        """
        self.reset_regex_status()
        self.func_handle = regex_test_generator(command)
        self.highlight_match = True
        self.regex_pattern = command

        # Tell the user what is happening since this is synchronous
        self.current_status = f'Searching buffer for regex /{self.regex_pattern}/'
        self.write_to_command_line(self.current_status)

        # Process any new matched messages to render
        self.process_matches()

        # Tell the user we are now filtering
        self.current_status = f'Regex with pattern /{self.regex_pattern}/'
        self.write_to_command_line(self.current_status)

        # Render the text
        self.render_text_in_output()
        curses.curs_set(0)
Exemplo n.º 4
0
    def test_process_matches(self):
        """
        Test that we correctly process matches
        """
        os.environ['TERM'] = 'dumb'
        app = Logria(None, False, False)

        # Fake window size: 10 x 100
        app.height = 10
        app.width = 100

        # Set fake previous render
        app.last_row = app.height - 3  # simulate the last row we can render to
        app.current_end = 80  # Simulate the last message rendered

        # Set fake messages
        app.messages = [str(x) for x in range(20)]

        # Set regex function, process
        app.func_handle = regex_generator.regex_test_generator(r'\d')
        process_matches(app)

        self.assertEqual(app.messages, [str(x) for x in range(20)])
Exemplo n.º 5
0
 def test_generated_regex_func_with_color_code(self):
     """
     Test that we match properly against a string with escape codes
     """
     pattern = regex_generator.regex_test_generator(' - ')
     self.assertTrue(pattern(' \u001b[0m-\u001b[32m '))
Exemplo n.º 6
0
 def test_generated_regex_func(self):
     """
     Test that we properly generate a regex function
     """
     pattern = regex_generator.regex_test_generator('-')
     self.assertTrue(pattern('-'))
Exemplo n.º 7
0
 def test_validator(self):
     """
     Test that we correctly generate a pattern
     """
     self.assertTrue(callable(regex_generator.regex_test_generator('-')))
Exemplo n.º 8
0
 def test_generated_invalid_regex(self):
     """
     Test that we match properly against a string with escape codes
     """
     pattern = regex_generator.regex_test_generator('(')
     self.assertIsNone(pattern)