def test_ansi_terminal_parser_normalization(self): """ Check AnsiTerminalParser normalization works as expected. """ parser = AnsiTerminalParser() # SGR0 sets black and white normal text. parser.reset("\x1B[ma", None) self.assertEquals(parser.normalize(), "\x1B[38;5;7;2;48;5;0ma") # SGR1 sets bold and SGR7 reverse video. parser.reset("\x1B[1ma\x1B[7mb", None) self.assertEquals(parser.normalize(), "\x1B[1ma\x1B[7mb")
def test_ansi_terminal_parser_cursor(self): """ Check AnsiTerminalParser cursor movement work as expected. """ parser = AnsiTerminalParser() parser.reset("aa\x08b\rc\x1B[Cdd\x1B[De\r", None) tokens = parser.parse() # Carriage return and overwrite self.assertEquals(next(tokens), ("c", (None, None, None), 4)) # Backspace and overwrite. self.assertEquals(next(tokens), ("b", (None, None, None), 2)) # Move cursor forwards and append. self.assertEquals(next(tokens), ("d", (None, None, None), 6)) # Move cursor backwards and overwrite. self.assertEquals(next(tokens), ("e", (None, None, None), 11)) # Normalize returns correct linear form - complete with accurate cursor location. self.assertEqual(parser.normalize(), "cbde\x1B[4D")