Ejemplo n.º 1
0
    def test__buffer_hidden_cursor(self):
        """Ensure hidden cursor don't appear in the buffer return by _redraw_buffer
        Ensure that only one cursor is present in the buffer"""
        #   '\u001b[?25h' : display cursor
        #   '\u001b[?25l' : hide cursor
        escape_sequences = [
            '\u001b[?25ha',
            '\r\n\u001b[?25lb',
            '\r\n\u001b[?25hc',
        ]

        screen = pyte.Screen(80, 24)
        stream = pyte.Stream(screen)

        def hidden_cursor(x, y):
            c = pyte.screens.Cursor(x, y)
            c.hidden = True
            return c

        expected_cursors = [
            pyte.screens.Cursor(1, 0),
            hidden_cursor(1, 1),
            pyte.screens.Cursor(1, 2),
        ]
        z = itertools.zip_longest(expected_cursors, escape_sequences)
        cursor = None
        for count, (expected_cursor, escape_sequence) in enumerate(z):
            with self.subTest(case='Hidden cursor - item #{}'.format(count)):
Ejemplo n.º 2
0
    def __init__(self, size_x, size_y, display_q):
        super(DisplayThread, self).__init__()
        self.display_q = display_q
        self.bus = 0
        self.device = 0
        self.x_max = 128
        self.y_max = 296
        self.size_x = size_x
        self.size_y = size_y

        self.stoprequest = threading.Event()

        self.epd = epd2in9.EPD()
        self.epd.init(self.epd.lut_full_update)
        self.image = Image.new('1', (epd2in9.EPD_HEIGHT, epd2in9.EPD_WIDTH),
                               255)
        self.font = ImageFont.load('terminus_12.pil')
        self.line_height = 16
        #self.font = ImageFont.truetype('terminus.ttf', 12)
        self.draw = ImageDraw.Draw(self.image)
        self.clear_display()
        self.clear_display()
        self.epd.init(self.epd.lut_partial_update)

        self.screen = pyte.Screen(self.size_x, self.size_y)
        self.stream = pyte.Stream(self.screen)
        self.buffer = []
        self.cursor_enabled = False
Ejemplo n.º 3
0
def test_cursor_position():
    screen = pyte.Screen(10, 10)

    # a) testing that we expect 1-indexed values
    screen.cursor_position(5, 10)
    assert (screen.cursor.y, screen.cursor.x) == (4, 9)

    # b) but (0, 0) is also accepted and should be the same as (1, 1)
    screen.cursor_position(0, 10)
    assert (screen.cursor.y, screen.cursor.x) == (0, 9)

    # c) moving outside the margins constrains to within the screen
    #    bounds
    screen.cursor_position(100, 5)
    assert (screen.cursor.y, screen.cursor.x) == (9, 4)

    screen.cursor_position(5, 100)
    assert (screen.cursor.y, screen.cursor.x) == (4, 9)

    # d) DECOM on
    screen.set_margins(5, 9)
    screen.set_mode(mo.DECOM)
    screen.cursor_position()
    assert (screen.cursor.y, screen.cursor.x) == (4, 0)

    screen.cursor_position(2, 0)
    assert (screen.cursor.y, screen.cursor.x) == (5, 0)

    # Note that cursor position doesn't change.
    screen.cursor_position(10, 0)
    assert (screen.cursor.y, screen.cursor.x) == (5, 0)
Ejemplo n.º 4
0
 def __phase4(self, infile):
     logger.info('=== STARTING PHASE 4 SESSION EXECUTION ===')
     screen = pyte.Screen(80, 25)
     stream = pyte.Stream(screen)
     results = {}
     next_token = '[get-seed'
     with open(infile, 'r') as input_data:
         lines = input_data.readlines()
         seed_start_pos = 0
         current_junc = ''
         for idx, line in enumerate(lines):
             if next_token in line:
                 current_junc = line.split('-')[2].split(']')[0]
                 next_token = '[get-timings'
                 seed_start_pos = idx
                 break
         count = len(lines) - seed_start_pos
         for idx, line in enumerate(lines[seed_start_pos:]):
             if next_token in line:
                 next_token = self.__swap_seed_tokens(next_token)
                 current_screen = '\n'.join(screen.display)
                 if not current_junc in results:
                     results[current_junc] = self.__create_entry()
                 self.__extract_data_from_screen(current_screen, next_token, current_junc, results)
                 screen.reset()
                 current_junc = line.split('-')[2].split(']')[0]
                 logger.debug('[{:05.2f}%] We are at {}'.format(100 * idx / count, current_junc))
             stream.feed(line)
         current_screen = '\n'.join(screen.display)
         self.__extract_data_from_screen(current_screen, next_token, current_junc, results)
         screen.reset()
     logger.info('=== PHASE 4 SESSION DONE ===')
     return results
Ejemplo n.º 5
0
 def send(self, text, silent=None):
     if hasattr(text, 'encode'):
         text = text.encode()
     text += b'\r'
     self.terminal.tx(text)
     # Wait for ok
     stream = pyte.ByteStream()
     width = 1000
     screen = pyte.Screen(width, 10)
     stream.attach(screen)
     incoming = io.BytesIO()
     if silent is None:
         silent = self.silent
     timeout = time.time() + 3
     while True:
         if time.time() > timeout:
             raise ValueError('Timeout')
         data = self.terminal.rx(silent=silent)
         if not data:
             continue
         stream.feed(data)
         incoming.write(data)
         incoming.seek(-4, io.SEEK_END)
         if incoming.read() == b'>>> ':
             output = io.StringIO()
             for line in screen.display:
                 line = line.strip()
                 output.write(line)
                 if len(line) < width:
                     output.write(u'\n')
             return output.getvalue().rstrip()[:-3]
Ejemplo n.º 6
0
 def __init_screen_stream(self):
     """
     初始化虚拟屏幕和字符流
     """
     self.stream = pyte.ByteStream()
     self.screen = pyte.Screen(80, 24)
     self.stream.attach(self.screen)
Ejemplo n.º 7
0
def test_remove_non_existant_attribute():
    screen = pyte.Screen(2, 2)
    assert tolist(screen) == [[screen.default_char, screen.default_char]] * 2

    screen.select_graphic_rendition(24)  # underline-off.
    assert tolist(screen) == [[screen.default_char, screen.default_char]] * 2
    assert not screen.cursor.attrs.underscore
Ejemplo n.º 8
0
def test_clear_tabstops():
    screen = pyte.Screen(10, 10)
    screen.clear_tab_stop(3)

    # a) clear a tabstop at current cusor location
    screen.cursor.x = 1
    screen.set_tab_stop()
    screen.cursor.x = 5
    screen.set_tab_stop()
    screen.clear_tab_stop()

    assert screen.tabstops == set([1])

    screen.set_tab_stop()
    screen.clear_tab_stop(0)

    assert screen.tabstops == set([1])

    # b) all tabstops
    screen.set_tab_stop()
    screen.cursor.x = 9
    screen.set_tab_stop()
    screen.clear_tab_stop(3)

    assert not screen.tabstops
Ejemplo n.º 9
0
def test_cursor_back_last_column():
    screen = pyte.Screen(13, 1)
    screen.draw("Hello, world!")
    assert screen.cursor.x == screen.columns

    screen.cursor_back(5)
    assert screen.cursor.x == (screen.columns - 1) - 5
Ejemplo n.º 10
0
def test_report_device_status():
    screen = pyte.Screen(10, 10)

    acc = []
    screen.write_process_input = acc.append

    # a) noop
    screen.report_device_status(42)
    assert not acc

    # b) terminal status
    screen.report_device_status(5)
    assert acc.pop() == ctrl.CSI + "0n"

    # c) cursor position, DECOM off
    screen.cursor_to_column(5)
    screen.report_device_status(6)
    assert acc.pop() == ctrl.CSI + "{0};{1}R".format(1, 5)

    # d) cursor position, DECOM on
    screen.cursor_position()
    screen.set_margins(5, 9)
    screen.set_mode(mo.DECOM)
    screen.cursor_to_line(5)
    screen.report_device_status(6)
    assert acc.pop() == ctrl.CSI + "{0};{1}R".format(5, 1)
Ejemplo n.º 11
0
def test_erase_in_line():
    screen = update(pyte.Screen(5, 5),
                    ["sam i", "s foo", "but a", "re yo", "u?   "],
                    colored=[0])
    screen.cursor_position(1, 3)

    # a) erase from cursor to the end of line
    screen.erase_in_line(0)
    assert (screen.cursor.y, screen.cursor.x) == (0, 2)
    assert screen.display == ["sa   ", "s foo", "but a", "re yo", "u?   "]
    assert tolist(screen)[0] == [
        Char("s", fg="red"),
        Char("a", fg="red"), screen.default_char, screen.default_char,
        screen.default_char
    ]

    # b) erase from the beginning of the line to the cursor
    screen = update(screen, ["sam i", "s foo", "but a", "re yo", "u?   "],
                    colored=[0])
    screen.erase_in_line(1)
    assert (screen.cursor.y, screen.cursor.x) == (0, 2)
    assert screen.display == ["    i", "s foo", "but a", "re yo", "u?   "]
    assert tolist(screen)[0] == [
        screen.default_char, screen.default_char, screen.default_char,
        Char(" ", fg="red"),
        Char("i", fg="red")
    ]

    # c) erase the entire line
    screen = update(screen, ["sam i", "s foo", "but a", "re yo", "u?   "],
                    colored=[0])
    screen.erase_in_line(2)
    assert (screen.cursor.y, screen.cursor.x) == (0, 2)
    assert screen.display == ["     ", "s foo", "but a", "re yo", "u?   "]
    assert tolist(screen)[0] == [screen.default_char] * 5
Ejemplo n.º 12
0
 def __init_screen_stream(self):
     """
     Initializing the virtual screen and the character stream
     """
     self._stream = pyte.ByteStream()
     self._screen = pyte.Screen(100, 35)
     self._stream.attach(self._screen)
Ejemplo n.º 13
0
def test_byte_stream_define_charset(charset, mapping):
    screen = pyte.Screen(3, 3)
    stream = pyte.ByteStream(screen)
    stream.select_other_charset("@")
    stream.feed((ctrl.ESC + "(" + charset).encode())
    assert screen.display[0] == " " * 3
    assert screen.g0_charset == mapping
Ejemplo n.º 14
0
def test_dollar_skip():
    screen = pyte.Screen(3, 3)
    handler = screen.draw = argcheck()
    stream = pyte.Stream(screen)
    stream.feed(ctrl.CSI + "12$p")
    assert handler.count == 0
    stream.feed(ctrl.CSI + "1;2;3;4$x")
    assert handler.count == 0
Ejemplo n.º 15
0
def test_non_utf8_shifts():
    screen = pyte.Screen(3, 3)
    handler = screen.shift_in = screen.shift_out = argcheck()
    stream = pyte.Stream(screen)
    stream.use_utf8 = False
    stream.feed(ctrl.SI)
    stream.feed(ctrl.SO)
    assert handler.count == 2
Ejemplo n.º 16
0
 def __init__(self, host=None):
     self.buf = ''
     self.cur_board = None
     self.screen = pyte.Screen(80, 24)
     self.stream = pyte.ByteStream(encodings = [("big5hkscs", "replace")])
     self.stream.attach(self.screen)
     self.tn = Telnet(host)
     self.state = "connected"
Ejemplo n.º 17
0
 def __init_screen_stream(self):
     """
     初始化虚拟屏幕和字符流
     """
     self.stream = pyte.ByteStream()
     self.screen = pyte.Screen(80, 24)
     #Adds a given screen to the listener queue
     self.stream.attach(self.screen)
Ejemplo n.º 18
0
    def test__buffer_simple_events(self):
        escape_sequences = ['{}\r\n'.format(i) for i in range(5)]

        screen = pyte.Screen(80, 24)
        stream = pyte.Stream(screen)
        for count, escape_sequence in enumerate(escape_sequences):
            with self.subTest(case='Simple events (record #{})'.format(count)):
                stream.feed(escape_sequence)
Ejemplo n.º 19
0
def test_restore_cursor_with_none_saved():
    screen = pyte.Screen(10, 10)
    screen.set_mode(mo.DECOM)
    screen.cursor.x, screen.cursor.y = 5, 5
    screen.restore_cursor()

    assert (screen.cursor.y, screen.cursor.x) == (0, 0)
    assert mo.DECOM not in screen.mode
Ejemplo n.º 20
0
def test_backspace():
    screen = pyte.Screen(2, 2)
    assert screen.cursor.x == 0
    screen.backspace()
    assert screen.cursor.x == 0
    screen.cursor.x = 1
    screen.backspace()
    assert screen.cursor.x == 0
 def __init__(self, MudData):
     self.screensize = (150, 80)
     self.screen = pyte.Screen(self.screensize[0], self.screensize[1])
     self.stream = pyte.ByteStream(self.screen)
     self.telnetConnection = telnetlib.Telnet()
     self.MudDataInner = MudData
     self.telnetConnection.set_option_negotiation_callback(
         self.handle_option_negotiations)
Ejemplo n.º 22
0
def test_draw_width0_irm():
    screen = pyte.Screen(10, 1)
    screen.set_mode(mo.IRM)

    # The following should not insert any blanks.
    screen.draw("\N{ZERO WIDTH SPACE}")
    screen.draw("\u0007")  # DELETE.
    assert screen.display == [" " * screen.columns]
Ejemplo n.º 23
0
def test_linefeed_margins():
    # See issue #63 on GitHub.
    screen = pyte.Screen(80, 24)
    screen.set_margins(3, 27)
    screen.cursor_position()
    assert (screen.cursor.y, screen.cursor.x) == (0, 0)
    screen.linefeed()
    assert (screen.cursor.y, screen.cursor.x) == (1, 0)
Ejemplo n.º 24
0
def test_reset_works_between_attributes():
    screen = pyte.Screen(2, 2)
    assert tolist(screen) == [[screen.default_char, screen.default_char]] * 2

    # Red fg, reset, red bg
    screen.select_graphic_rendition(31, 0, 41)
    assert screen.cursor.attrs.fg == "default"
    assert screen.cursor.attrs.bg == "red"
Ejemplo n.º 25
0
def test_multi_attribs():
    screen = pyte.Screen(2, 2)
    assert tolist(screen) == [[screen.default_char, screen.default_char]] * 2
    screen.select_graphic_rendition(1)
    screen.select_graphic_rendition(3)

    assert screen.cursor.attrs.bold
    assert screen.cursor.attrs.italics
Ejemplo n.º 26
0
def test_byte_stream_feed():
    screen = pyte.Screen(20, 1)
    screen.draw = handler = argcheck()

    stream = pyte.ByteStream(screen)
    stream.feed("Нерусский текст".encode("utf-8"))
    assert handler.count == 1
    assert handler.args == ("Нерусский текст", )
Ejemplo n.º 27
0
def test_screen_set_icon_name_title():
    screen = pyte.Screen(10, 1)

    text = "±"
    screen.set_icon_name(text)
    assert screen.icon_name == text

    screen.set_title(text)
    assert screen.title == text
Ejemplo n.º 28
0
def _get_output_lines(script, log_file):
    lines = log_file.readlines()[-const.LOG_SIZE:]
    grouped = list(_group_by_calls(lines))
    script_lines = _get_script_group_lines(grouped, script)

    screen = pyte.Screen(get_terminal_size().columns, len(script_lines))
    stream = pyte.Stream(screen)
    stream.feed(''.join(script_lines))
    return screen.display
Ejemplo n.º 29
0
def test_overflow():
    handler = argcheck()
    screen = pyte.Screen(80, 24)
    screen.cursor_position = handler

    stream = pyte.Stream(screen)
    stream.feed(ctrl.CSI + "999999999999999;99999999999999" + esc.HVP)
    assert handler.count == 1
    assert handler.args == (9999, 9999)
Ejemplo n.º 30
0
def test_missing_params():
    handler = argcheck()
    screen = pyte.Screen(80, 24)
    screen.cursor_position = handler

    stream = pyte.Stream(screen)
    stream.feed(ctrl.CSI + ";" + esc.HVP)
    assert handler.count == 1
    assert handler.args == (0, 0)