Exemplo n.º 1
0
def test_draw_wcwidth():
    # Example from https://github.com/selectel/pyte/issues/9
    screen = Screen(10, 1)
    for char in "コンニチハ":
        screen.draw(char)

    assert screen.cursor.x == screen.columns
Exemplo n.º 2
0
def test_report_device_attributes():
    screen = Screen(10, 10)

    acc = []
    screen.write_process_input = acc.append
    screen.report_device_attributes()
    assert acc.pop() == ctrl.CSI + "?6c"
Exemplo n.º 3
0
def test_erase_character():
    screen = update(Screen(3, 3), ["sam", "is ", "foo"], colored=[0])

    screen.erase_characters(2)
    assert (screen.cursor.y, screen.cursor.x) == (0, 0)
    assert screen.display == ["  m", "is ", "foo"]
    assert screen[0] == [
        screen.default_char,
        screen.default_char,
        Char("m", fg="red")
    ]

    screen.cursor.y, screen.cursor.x = 2, 2
    screen.erase_characters()
    assert (screen.cursor.y, screen.cursor.x) == (2, 2)
    assert screen.display == ["  m", "is ", "fo "]

    screen.cursor.y, screen.cursor.x = 1, 1
    screen.erase_characters(0)
    assert (screen.cursor.y, screen.cursor.x) == (1, 1)
    assert screen.display == ["  m", "i  ", "fo "]

    # ! extreme cases.
    screen = update(Screen(5, 1), ["12345"], colored=[0])
    screen.cursor.x = 1
    screen.erase_characters(3)
    assert (screen.cursor.y, screen.cursor.x) == (0, 1)
    assert screen.display == ["1   5"]
    assert screen[0] == [
        Char("1", fg="red"),
        screen.default_char,
        screen.default_char,
        screen.default_char,
        Char("5", "red")
    ]

    screen = update(Screen(5, 1), ["12345"], colored=[0])
    screen.cursor.x = 2
    screen.erase_characters(10)
    assert (screen.cursor.y, screen.cursor.x) == (0, 2)
    assert screen.display == ["12   "]
    assert screen[0] == [
        Char("1", fg="red"),
        Char("2", fg="red"),
        screen.default_char,
        screen.default_char,
        screen.default_char
    ]

    screen = update(Screen(5, 1), ["12345"], colored=[0])
    screen.erase_characters(4)
    assert (screen.cursor.y, screen.cursor.x) == (0, 0)
    assert screen.display == ["    5"]
    assert screen[0] == [
        screen.default_char,
        screen.default_char,
        screen.default_char,
        screen.default_char,
        Char("5", fg="red")
    ]
Exemplo n.º 4
0
def test_remove_non_existant_attribute():
    screen = Screen(2, 2)
    assert screen == [[screen.default_char, screen.default_char]] * 2

    screen.select_graphic_rendition(24)  # underline-off.
    assert screen == [[screen.default_char, screen.default_char]] * 2
    assert not screen.cursor.attrs.underscore
Exemplo n.º 5
0
def test_insert_characters():
    screen = update(Screen(3, 3), ["sam", "is ", "foo"], colored=[0])

    # a) normal case
    cursor = copy.copy(screen.cursor)
    screen.insert_characters(2)
    assert (screen.cursor.y, screen.cursor.x) == (cursor.y, cursor.x)
    assert screen[0] == [
        screen.default_char,
        screen.default_char,
        Char("s", fg="red")
    ]

    # b) now inserting from the middle of the line
    screen.cursor.y, screen.cursor.x = 2, 1
    screen.insert_characters(1)
    assert screen[2] == [Char("f"), screen.default_char, Char("o")]

    # c) inserting more than we have
    screen.insert_characters(10)
    assert screen[2] == [Char("f"), screen.default_char, screen.default_char]

    # d) 0 is 1
    screen = update(Screen(3, 3), ["sam", "is ", "foo"], colored=[0])

    screen.cursor_position()
    screen.insert_characters()
    assert screen[0] == [screen.default_char,
                         Char("s", fg="red"), Char("a", fg="red")]

    screen = update(Screen(3, 3), ["sam", "is ", "foo"], colored=[0])
    screen.cursor_position()
    screen.insert_characters(1)
    assert screen[0] == [screen.default_char,
                         Char("s", fg="red"), Char("a", fg="red")]
Exemplo n.º 6
0
def test_multi_attribs():
    screen = Screen(2, 2)
    assert 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
Exemplo n.º 7
0
def test_draw_width0_decawm_off():
    screen = Screen(10, 1)
    screen.reset_mode(mo.DECAWM)
    screen.draw(" コンニチハ".encode("utf-8"))
    assert screen.cursor.x == screen.columns

    # The following should not advance the cursor.
    screen.draw("\N{ZERO WIDTH SPACE}".encode("utf-8"))
    screen.draw("\u0007".encode("utf-8"))  # DELETE.
    assert screen.cursor.x == screen.columns
Exemplo n.º 8
0
def test_private_report_device_attributes():
    # Some console apps (e.g. ADOM) might add ``?`` to the DA request,
    # even though the VT102/VT220 spec does not allow this.
    screen = Screen(10, 10)
    stream = Stream(screen)

    acc = []
    screen.write_process_input = acc.append
    stream.feed(ctrl.CSI + b"?0c")
    assert acc.pop() == ctrl.CSI + b"?6c"
Exemplo n.º 9
0
def test_private_report_device_attributes():
    # Some console apps (e.g. ADOM) might add ``?`` to the DA request,
    # even though the VT102/VT220 spec does not allow this.
    screen = Screen(10, 10)
    stream = Stream(screen)

    acc = []
    screen.write_process_input = acc.append
    stream.feed(ctrl.CSI + b"?0c")
    assert acc.pop() == ctrl.CSI + b"?6c"
Exemplo n.º 10
0
def test_colors():
    screen = Screen(2, 2)

    screen.select_graphic_rendition(30)
    screen.select_graphic_rendition(40)
    assert screen.cursor.attrs.fg == "black"
    assert screen.cursor.attrs.bg == "black"

    screen.select_graphic_rendition(31)
    assert screen.cursor.attrs.fg == "red"
    assert screen.cursor.attrs.bg == "black"
Exemplo n.º 11
0
def test_colors_aixterm():
    # See issue #57 on GitHub.
    screen = Screen(2, 2)

    # a) foreground color.
    screen.select_graphic_rendition(94)
    assert screen.cursor.attrs.fg == "blue"
    assert screen.cursor.attrs.bold

    # b) background color.
    screen.select_graphic_rendition(104)
    assert screen.cursor.attrs.bg == "blue"
    assert screen.cursor.attrs.bold
Exemplo n.º 12
0
def test_draw_width0_decawm_off():
    screen = Screen(10, 1)
    screen.reset_mode(mo.DECAWM)
    screen.draw(" コンニチハ".encode("utf-8"))
    assert screen.cursor.x == screen.columns

    # The following should not advance the cursor.
    screen.draw("\N{ZERO WIDTH SPACE}".encode("utf-8"))
    screen.draw("\u0007".encode("utf-8"))  # DELETE.
    assert screen.cursor.x == screen.columns
Exemplo n.º 13
0
def test_hide_cursor():
    screen = Screen(10, 10)

    # DECTCEM is set by default.
    assert mo.DECTCEM in screen.mode
    assert not screen.cursor.hidden

    # a) resetting DECTCEM hides the cursor.
    screen.reset_mode(mo.DECTCEM)
    assert screen.cursor.hidden

    # b) ... and it's back!
    screen.set_mode(mo.DECTCEM)
    assert not screen.cursor.hidden
Exemplo n.º 14
0
def test_attributes():
    screen = Screen(2, 2)
    assert screen == [[screen.default_char, screen.default_char]] * 2
    screen.select_graphic_rendition(1) # Bold

    # Still default, since we haven't written anything.
    assert screen == [[screen.default_char, screen.default_char]] * 2
    assert screen.cursor.attrs.bold

    screen.draw("f")
    assert screen == [
        [Char("f", "default", "default", bold=True), screen.default_char],
        [screen.default_char, screen.default_char]
    ]
Exemplo n.º 15
0
def test_draw_width0_irm():
    screen = Screen(10, 1)
    screen.set_mode(mo.IRM)

    # The following should not insert any blanks.
    screen.draw("\N{ZERO WIDTH SPACE}".encode("utf-8"))
    screen.draw("\u0007".encode("utf-8"))  # DELETE.
    assert screen.display == [" " * screen.columns]
Exemplo n.º 16
0
def test_erase_in_line():
    screen = update(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 screen.buffer[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 screen.buffer[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 screen.buffer[0] == [screen.default_char] * 5
Exemplo n.º 17
0
 def __init__(self, parent):
     Screen.__init__(self, 80, 24)
     QTextEdit.__init__(self, parent=None)
     QApplication.instance().setCursorFlashTime(0)
     self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
     self.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont))
     self.setFontPointSize(12)
     self._text_width = self.fontMetrics().maxWidth() + 1.5  # This could be cleaner
     self._text_height = self.fontMetrics().lineSpacing() + 2.3  # This could be cleaner too
     # self.setStyleSheet('background-color: black; color: white')
     self._parent = parent
     self._conn = None
     self._term_em = None
     self._timer = QTimer(self)
     self._angle_delta = 0
Exemplo n.º 18
0
def test_draw_cp437():
    screen = Screen(5, 1)
    assert screen.charset == 0

    screen.define_charset(b"U", b"(")
    screen.select_other_charset(b"@")
    screen.draw("α ± ε".encode("cp437"))

    assert screen.display == ["α ± ε"]
Exemplo n.º 19
0
def test_screen_set_icon_name_title():
    screen = Screen(10, 1)
    screen.select_other_charset(b"@")

    text = "±"
    screen.set_icon_name(text.encode("latin-1"))
    assert screen.icon_name == text

    screen.set_title(text.encode("latin-1"))
    assert screen.title == text
Exemplo n.º 20
0
def test_colors24bit():
    screen = Screen(2, 2)

    # a) OK-case
    screen.select_graphic_rendition(38, 2, 0, 0, 0)
    screen.select_graphic_rendition(48, 2, 255, 255, 255)
    assert screen.cursor.attrs.fg == "000000"
    assert screen.cursor.attrs.bg == "ffffff"

    # b) invalid color.
    screen.select_graphic_rendition(48, 2, 255)
Exemplo n.º 21
0
def test_colors256():
    screen = Screen(2, 2)

    # a) OK-case.
    screen.select_graphic_rendition(38, 5, 0)
    screen.select_graphic_rendition(48, 5, 15)
    assert screen.cursor.attrs.fg == "000000"
    assert screen.cursor.attrs.bg == "ffffff"

    # b) invalid color.
    screen.select_graphic_rendition(48, 5, 100500)
Exemplo n.º 22
0
def test_draw_width0_irm():
    screen = Screen(10, 1)
    screen.set_mode(mo.IRM)

    # The following should not insert any blanks.
    screen.draw("\N{ZERO WIDTH SPACE}".encode("utf-8"))
    screen.draw("\u0007".encode("utf-8"))  # DELETE.
    assert screen.display == [" " * screen.columns]
Exemplo n.º 23
0
def test_colors_ignore_invalid():
    screen = Screen(2, 2)
    default_attrs = screen.cursor.attrs

    screen.select_graphic_rendition(100500)
    assert screen.cursor.attrs == default_attrs

    screen.select_graphic_rendition(38, 100500)
    assert screen.cursor.attrs == default_attrs

    screen.select_graphic_rendition(48, 100500)
    assert screen.cursor.attrs == default_attrs
Exemplo n.º 24
0
def test_unicode():
    screen = Screen(4, 2)
    stream = Stream(screen)

    try:
        stream.feed("тест".encode("utf-8"))
    except UnicodeDecodeError:
        pytest.fail("Check your code -- we do accept unicode.")

    assert screen.display == ["тест", "    "]
Exemplo n.º 25
0
def test_draw_cp437():
    screen = Screen(5, 1)
    assert screen.charset == 0

    screen.define_charset(b"U", b"(")
    screen.select_other_charset(b"@")
    screen.draw("α ± ε".encode("cp437"))

    assert screen.display == ["α ± ε"]
Exemplo n.º 26
0
def test_screen_set_icon_name_title():
    screen = Screen(10, 1)
    screen.select_other_charset(b"@")

    text = "±"
    screen.set_icon_name(text.encode("latin-1"))
    assert screen.icon_name == text

    screen.set_title(text.encode("latin-1"))
    assert screen.title == text
Exemplo n.º 27
0
def test_colors24bit():
    screen = Screen(2, 2)

    # a) OK-case
    screen.select_graphic_rendition(38, 2, 0, 0, 0)
    screen.select_graphic_rendition(48, 2, 255, 255, 255)
    assert screen.cursor.attrs.fg == "000000"
    assert screen.cursor.attrs.bg == "ffffff"

    # b) invalid color.
    screen.select_graphic_rendition(48, 2, 255)
Exemplo n.º 28
0
def test_colors256():
    screen = Screen(2, 2)

    # a) OK-case.
    screen.select_graphic_rendition(38, 5, 0)
    screen.select_graphic_rendition(48, 5, 15)
    assert screen.cursor.attrs.fg == "000000"
    assert screen.cursor.attrs.bg == "ffffff"

    # b) invalid color.
    screen.select_graphic_rendition(48, 5, 100500)
Exemplo n.º 29
0
def test_backspace():
    screen = 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
Exemplo n.º 30
0
def test_select_other_charset():
    screen = Screen(3, 3)
    assert screen.use_utf8  # on by default.

    # a) disable utf-8
    screen.select_other_charset(b"@")
    assert not screen.use_utf8

    # b) unknown code -- noop
    screen.select_other_charset(b"X")
    assert not screen.use_utf8

    # c) enable utf-8
    screen.select_other_charset(b"G")
    assert screen.use_utf8
Exemplo n.º 31
0
def test_restore_cursor_with_none_saved():
    screen = 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
Exemplo n.º 32
0
def test_colors_ignore_invalid():
    screen = Screen(2, 2)
    default_attrs = screen.cursor.attrs

    screen.select_graphic_rendition(100500)
    assert screen.cursor.attrs == default_attrs

    screen.select_graphic_rendition(38, 100500)
    assert screen.cursor.attrs == default_attrs

    screen.select_graphic_rendition(48, 100500)
    assert screen.cursor.attrs == default_attrs
Exemplo n.º 33
0
def test_alignment_display():
    screen = Screen(5, 5)
    screen.draw("a")
    screen.linefeed()
    screen.linefeed()
    screen.draw("b")

    assert screen.display == ["a    ",
                              "     ",
                              "b    ",
                              "     ",
                              "     "]

    screen.alignment_display()

    assert screen.display == ["EEEEE",
                              "EEEEE",
                              "EEEEE",
                              "EEEEE",
                              "EEEEE"]
Exemplo n.º 34
0
def test_report_device_attributes():
    screen = Screen(10, 10)

    acc = []
    screen.write_process_input = acc.append

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

    # b) OK case
    screen.report_device_attributes()
    assert acc.pop() == ctrl.CSI + b"?6c"
Exemplo n.º 35
0
def test_cursor_up():
    screen = Screen(10, 10)

    # Moving the cursor up at the top doesn't do anything
    screen.cursor_up(1)
    assert screen.cursor.y == 0

    screen.cursor.y = 1

    # Moving the cursor past the top moves it to the top
    screen.cursor_up(10)
    assert screen.cursor.y == 0

    screen.cursor.y = 5
    # Can move the cursor more than one up.
    screen.cursor_up(3)
    assert screen.cursor.y == 2
Exemplo n.º 36
0
def test_linefeed():
    screen = update(Screen(2, 2), ["bo", "sh"], [None, None])
    screen.set_mode(mo.LNM)

    # a) LNM on by default (that's what `vttest` forces us to do).
    assert mo.LNM in screen.mode
    screen.cursor.x, screen.cursor.y = 1, 0
    screen.linefeed()
    assert (screen.cursor.y, screen.cursor.x) == (1, 0)

    # b) LNM off.
    screen.reset_mode(mo.LNM)
    screen.cursor.x, screen.cursor.y = 1, 0
    screen.linefeed()
    assert (screen.cursor.y, screen.cursor.x) == (1, 1)
Exemplo n.º 37
0
def test_cursor_forward():
    screen = Screen(10, 10)

    # Moving the cursor right at the margin doesn't do anything
    screen.cursor.x = 9
    screen.cursor_forward(1)
    assert screen.cursor.x == 9

    # Moving the cursor past the right margin moves it to the right margin
    screen.cursor.x = 8
    screen.cursor_forward(10)
    assert screen.cursor.x == 9

    # Can move the cursor more than one forward.
    screen.cursor.x = 5
    screen.cursor_forward(3)
    assert screen.cursor.x == 8
Exemplo n.º 38
0
def test_set_margins():
    screen = Screen(10, 10)

    assert screen.margins == (0, 9)

    # a) ok-case
    screen.set_margins(1, 5)
    assert screen.margins == (0, 4)

    # b) one of the margins is out of bounds
    screen.set_margins(100, 10)
    assert screen.margins != (99, 9)
    assert screen.margins == (0, 4)

    # c) no margins provided
    screen.set_margins()
    assert screen.margins == (0, screen.lines - 1)
Exemplo n.º 39
0
def test_cursor_down():
    screen = Screen(10, 10)

    # Moving the cursor down at the bottom doesn't do anything
    screen.cursor.y = 9
    screen.cursor_down(1)
    assert screen.cursor.y == 9

    screen.cursor.y = 8

    # Moving the cursor past the bottom moves it to the bottom
    screen.cursor_down(10)
    assert screen.cursor.y == 9

    screen.cursor.y = 5
    # Can move the cursor more than one down.
    screen.cursor_down(3)
    assert screen.cursor.y == 8
Exemplo n.º 40
0
def test_cursor_back():
    screen = Screen(10, 10)

    # Moving the cursor left at the margin doesn't do anything
    screen.cursor.x = 0
    screen.cursor_back(1)
    assert screen.cursor.x == 0

    screen.cursor.x = 3

    # Moving the cursor past the left margin moves it to the left margin
    screen.cursor_back(10)
    assert screen.cursor.x == 0

    screen.cursor.x = 5
    # Can move the cursor more than one back.
    screen.cursor_back(3)
    assert screen.cursor.x == 2
Exemplo n.º 41
0
def test_reset_resets_colors():
    screen = Screen(2, 2)
    assert screen == [[screen.default_char, screen.default_char]] * 2

    screen.select_graphic_rendition(30)
    screen.select_graphic_rendition(40)
    assert screen.cursor.attrs.fg == "black"
    assert screen.cursor.attrs.bg == "black"

    screen.select_graphic_rendition(0)
    assert screen.cursor.attrs == screen.default_char
Exemplo n.º 42
0
def test_colors():
    screen = Screen(2, 2)

    screen.select_graphic_rendition(30)
    screen.select_graphic_rendition(40)
    assert screen.cursor.attrs.fg == "black"
    assert screen.cursor.attrs.bg == "black"

    screen.select_graphic_rendition(31)
    assert screen.cursor.attrs.fg == "red"
    assert screen.cursor.attrs.bg == "black"
Exemplo n.º 43
0
def test_select_other_charset():
    screen = Screen(3, 3)
    assert screen.use_utf8  # on by default.

    # a) disable utf-8
    screen.select_other_charset(b"@")
    assert not screen.use_utf8

    # b) unknown code -- noop
    screen.select_other_charset(b"X")
    assert not screen.use_utf8

    # c) enable utf-8
    screen.select_other_charset(b"G")
    assert screen.use_utf8
Exemplo n.º 44
0
def test_colors():
    screen = Screen(2, 2)
    assert screen == [[screen.default_char, screen.default_char]] * 2

    screen.select_graphic_rendition(30) # black foreground
    screen.select_graphic_rendition(40) # black background
    assert screen.cursor.attrs.fg == "black"
    assert screen.cursor.attrs.bg == "black"

    screen.select_graphic_rendition(31) # red foreground
    assert screen.cursor.attrs.fg == "red"
    assert screen.cursor.attrs.bg == "black"
Exemplo n.º 45
0
def test_colors_aixterm():
    # See issue #57 on GitHub.
    screen = Screen(2, 2)

    # a) foreground color.
    screen.select_graphic_rendition(94)
    assert screen.cursor.attrs.fg == "blue"
    assert screen.cursor.attrs.bold

    # b) background color.
    screen.select_graphic_rendition(104)
    assert screen.cursor.attrs.bg == "blue"
    assert screen.cursor.attrs.bold
Exemplo n.º 46
0
def test_attributes():
    screen = Screen(2, 2)
    assert screen.buffer == [[screen.default_char, screen.default_char]] * 2
    screen.select_graphic_rendition(1)  # bold.

    # Still default, since we haven't written anything.
    assert screen.buffer == [[screen.default_char, screen.default_char]] * 2
    assert screen.cursor.attrs.bold

    screen.draw(b"f")
    assert screen.buffer == [[
        Char("f", "default", "default", bold=True), screen.default_char
    ], [screen.default_char, screen.default_char]]
Exemplo n.º 47
0
def test_report_device_attributes():
    screen = Screen(10, 10)

    acc = []
    screen.write_process_input = acc.append

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

    # b) OK case
    screen.report_device_attributes()
    assert acc.pop() == ctrl.CSI + "?6c"
Exemplo n.º 48
0
def test_set_margins():
    screen = Screen(10, 10)

    assert screen.margins == (0, 9)

    # a) ok-case
    screen.set_margins(1, 5)
    assert screen.margins == (0, 4)

    # b) one of the margins is out of bounds
    screen.set_margins(100, 10)
    assert screen.margins != (99, 9)
    assert screen.margins == (0, 4)

    # c) no margins provided
    screen.set_margins()
    assert screen.margins == (0, screen.lines - 1)
Exemplo n.º 49
0
def test_attributes_reset():
    screen = Screen(2, 2)
    screen.set_mode(mo.LNM)
    assert screen == [[screen.default_char, screen.default_char]] * 2
    screen.select_graphic_rendition(1)
    screen.draw("f")
    screen.draw("o")
    screen.draw("o")
    assert screen == [
        [Char("f", bold=True), Char("o", bold=True)],
        [Char("o", bold=True), screen.default_char  ],
    ]

    screen.cursor_position()
    screen.select_graphic_rendition(0) # Reset
    screen.draw("f")
    assert screen == [
        [Char("f"),            Char("o", bold=True)],
        [Char("o", bold=True), screen.default_char  ],
    ]
Exemplo n.º 50
0
def test_restore_cursor_out_of_bounds():
    screen = Screen(10, 10)

    # a) origin mode off.
    screen.cursor_position(5, 5)
    screen.save_cursor()
    screen.resize(3, 3)
    screen.reset()
    screen.restore_cursor()

    assert (screen.cursor.y, screen.cursor.x) == (2, 2)

    # b) origin mode is on.
    screen.resize(10, 10)
    screen.cursor_position(8, 8)
    screen.save_cursor()
    screen.resize(5, 5)
    screen.reset()
    screen.set_mode(mo.DECOM)
    screen.set_margins(2, 3)
    screen.restore_cursor()

    assert (screen.cursor.y, screen.cursor.x) == (2, 4)