def test_DECSCL_RISOnChange(self): """DECSCL should do an RIS. RIS does a lot, so we'll just test a few things. This may not be true for VT220's, though, to quote the xterm code: VT300, VT420, VT520 manuals claim that DECSCL does a hard reset (RIS). VT220 manual states that it is a soft reset. Perhaps both are right (unlikely). Kermit says it's soft. So that's why this test is for vt level 3 and up.""" escio.Write("x") # Set saved cursor position esccmd.CUP(Point(5, 6)) esccmd.DECSC() # Turn on insert mode esccmd.SM(esccmd.IRM) esccmd.DECSCL(61) AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), [ NUL ]) # Ensure saved cursor position is the origin esccmd.DECRC() AssertEQ(GetCursorPosition(), Point(1, 1)) # Ensure replace mode is on esccmd.CUP(Point(1, 1)) escio.Write("a") esccmd.CUP(Point(1, 1)) escio.Write("b") AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), [ "b" ])
def test_SOS_Basic(self): esccmd.SOS() escio.Write("xyz") escio.Write(ST) escio.Write("A") AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), ["A" + NUL * 2])
def test_SM_IRM(self): """Turn on insert mode.""" escio.Write("abc") esccmd.CUP(Point(1, 1)) esccmd.SM(esccmd.IRM) escio.Write("X") AssertScreenCharsInRectEqual(Rect(1, 1, 4, 1), ["Xabc"])
def test_VPR_IgnoresOriginMode(self): """VPR continues to work in origin mode.""" # Set a scroll region. esccmd.DECSTBM(6, 11) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Enter origin mode esccmd.DECSET(esccmd.DECOM) # Move to center of region esccmd.CUP(Point(2, 2)) escio.Write('X') # Move down by 2 esccmd.VPR(2) escio.Write('Y') # Exit origin mode esccmd.DECRESET(esccmd.DECOM) # Reset margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTBM() # See what happened AssertScreenCharsInRectEqual(Rect(6, 7, 7, 9), ['X' + NUL, NUL * 2, NUL + 'Y'])
def test_LF_MovesDoesNotScrollOutsideLeftRight(self): """Cursor moves down but won't scroll when outside left-right region.""" esccmd.DECSTBM(2, 5) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 5) esccmd.CUP(Point(3, 5)) escio.Write("x") # Move past bottom margin but to the right of the left-right region esccmd.CUP(Point(6, 5)) escio.Write(LF) # Cursor won't pass bottom or scroll. AssertEQ(GetCursorPosition(), Point(6, 5)) AssertScreenCharsInRectEqual(Rect(3, 5, 3, 5), ["x"]) # Try to move past the bottom of the screen but to the right of the left-right region height = GetScreenSize().height() esccmd.CUP(Point(6, height)) escio.Write(LF) AssertEQ(GetCursorPosition(), Point(6, height)) AssertScreenCharsInRectEqual(Rect(3, 5, 3, 5), ["x"]) # Move past bottom margin but to the left of the left-right region esccmd.CUP(Point(1, 5)) escio.Write(LF) AssertEQ(GetCursorPosition(), Point(1, 5)) AssertScreenCharsInRectEqual(Rect(3, 5, 3, 5), ["x"]) # Try to move past the bottom of the screen but to the left of the left-right region height = GetScreenSize().height() esccmd.CUP(Point(1, height)) escio.Write(LF) AssertEQ(GetCursorPosition(), Point(1, height)) AssertScreenCharsInRectEqual(Rect(3, 5, 3, 5), ["x"])
def test_HPR_IgnoresOriginMode(self): """HPR continues to work in origin mode.""" # Set a scroll region. esccmd.DECSTBM(6, 11) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Enter origin mode esccmd.DECSET(esccmd.DECOM) # Move to center of region esccmd.CUP(Point(2, 2)) escio.Write('X') # Move right by 2 esccmd.HPR(2) escio.Write('Y') # Exit origin mode esccmd.DECRESET(esccmd.DECOM) # Reset margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTBM() # See what happened AssertScreenCharsInRectEqual(Rect(5, 7, 9, 7), [empty() + "X" + empty() * 2 + "Y"])
def test_TBC_Default(self): """No param clears the tab stop at the cursor.""" escio.Write(TAB) AssertEQ(GetCursorPosition().x(), 9) esccmd.TBC() esccmd.CUP(Point(1, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition().x(), 17)
def test_TBC_0(object): """0 param clears the tab stop at the cursor.""" escio.Write(TAB) AssertEQ(GetCursorPosition().x(), 9) esccmd.TBC(0) esccmd.CUP(Point(1, 1)) escio.Write(TAB) AssertEQ(GetCursorPosition().x(), 17)
def test_PM_Basic(self): esccmd.PM() escio.Write("xyz") escio.Write(ST) escio.Write("A") AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), ["A" + empty() * 2])
def test_DECSEL_doesNotRespectISOProtect(self): """DECSEL does not respect ISO protection.""" escio.Write("a") esccmd.SPA() escio.Write("b") esccmd.EPA() esccmd.DECSEL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 2, 1), [blank() * 2])
def test_DECSTBM_NewlineBelowRegion(self): """A newline below the region has no effect on the region.""" esccmd.DECSTBM(2, 3) esccmd.CUP(Point(1, 2)) escio.Write("1" + CR + LF) escio.Write("2") esccmd.CUP(Point(1, 4)) escio.Write(CR + LF) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), ["1", "2"])
def test_S8C1T_DCS(self): esccmd.DECSTBM(5, 6) escio.use8BitControls = True escio.Write(S8C1T) esccmd.DECRQSS("r") result = escio.ReadDCS() escio.Write(S7C1T) escio.use8BitControls = False AssertEQ(result, "1$r5;6r")
def test_DECSET_DECAWM_TabDoesNotWrapAround(self): """In auto-wrap mode, tabs to not wrap to the next line.""" esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() for _ in xrange(size.width() / 8 + 2): escio.Write(TAB) AssertEQ(GetCursorPosition().x(), size.width()) AssertEQ(GetCursorPosition().y(), 1) escio.Write("X")
def test_BS_CursorStartsInDoWrapPosition(self): """Cursor is right of right edge of screen.""" size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("ab") escio.Write(esc.BS) escio.Write("X") AssertScreenCharsInRectEqual( Rect(size.width() - 1, 1, size.width(), 1), ["Xb"])
def test_DECSET_ResetReverseWraparoundDisablesIt(self): """DECRESET of reverse wraparound prevents it from happening.""" # iTerm2 turns reverse wraparound on by default, while xterm does not. esccmd.DECRESET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUP(Point(GetScreenSize().width() - 1, 1)) escio.Write("abc") escio.Write(BS * 5) AssertEQ(GetCursorPosition().x(), 1)
def test_DECSET_ReverseWraparound_RequiresDECAWM(self): """Reverse wraparound only works if DECAWM is set.""" # iTerm2 turns reverse wraparound on by default, while xterm does not. esccmd.CUP(Point(GetScreenSize().width() - 1, 1)) escio.Write("abc") esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECRESET(esccmd.DECAWM) escio.Write(BS * 5) AssertEQ(GetCursorPosition().x(), 1)
def test_DECSTBM_TopOfZeroIsTopOfScreen(self): """A zero value for the top arg gives the top of the screen.""" esccmd.DECSTBM(0, 3) esccmd.CUP(Point(1, 2)) escio.Write("1" + CR + LF) escio.Write("2" + CR + LF) escio.Write("3" + CR + LF) escio.Write("4") AssertScreenCharsInRectEqual(Rect(1, 1, 1, 3), ["2", "3", "4"])
def test_ECH_doesNotRespectDECPRotection(self): """ECH should not respect DECSCA.""" escio.Write("a") escio.Write("b") esccmd.DECSCA(1) escio.Write("c") esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) esccmd.ECH(3) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 3])
def test_EL_respectsISOProtection(self): """EL respects SPA/EPA.""" escio.Write("a") escio.Write("b") esccmd.SPA() escio.Write("c") esccmd.EPA() esccmd.CUP(Point(1, 1)) esccmd.EL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [blank() * 2 + "c"])
def test_EL_doesNotRespectDECProtection(self): """EL respects DECSCA.""" escio.Write("a") escio.Write("b") esccmd.DECSCA(1) escio.Write("c") esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) esccmd.EL(2) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [empty() * 3])
def test_ED_doesNotRespectDECProtection(self): """ED should not respect DECSCA""" escio.Write("a") escio.Write("b") esccmd.DECSCA(1) escio.Write("c") esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) esccmd.ED(0) AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), [empty() * 3])
def test_DECSTBM_ScrollsOnNewline(self): """Define a top-bottom margin, put text in it, and have newline scroll it.""" esccmd.DECSTBM(2, 3) esccmd.CUP(Point(1, 2)) escio.Write("1" + CR + LF) escio.Write("2") AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), ["1", "2"]) escio.Write(CR + LF) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), ["2", NUL]) AssertEQ(GetCursorPosition().y(), 3)
def doLinefeedModeTest(self, code): esccmd.RM(esccmd.LNM) esccmd.CUP(Point(5, 1)) escio.Write(code) AssertEQ(GetCursorPosition(), Point(5, 2)) esccmd.SM(esccmd.LNM) esccmd.CUP(Point(5, 1)) escio.Write(code) AssertEQ(GetCursorPosition(), Point(1, 2))
def test_DECID_8bit(self): escio.use8BitControls = True escio.Write(S8C1T) esccmd.DECID() params = escio.ReadCSI("c", expected_prefix="?") AssertTrue(len(params) > 0) escio.Write(S7C1T) escio.use8BitControls = False
def doAltBuftest(self, code, altGetsClearedBeforeToMain, cursorSaved, movesCursorOnEnter=False): """|code| is the code to test with, either 47 or 1047.""" # Scribble in main screen escio.Write("abc" + CR + LF + "abc") # Switch from main to alt. Cursor should not move. If |cursorSaved| is set, # record the position first to verify that it's restored after DECRESET. if cursorSaved: mainCursorPosition = GetCursorPosition() before = GetCursorPosition() esccmd.DECSET(code) after = GetCursorPosition() if not movesCursorOnEnter: # 1049 moves the cursor on enter AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) # Scribble in alt screen, clearing it first since who knows what might have # been there. esccmd.ED(2) esccmd.CUP(Point(1, 2)) escio.Write("def" + CR +LF + "def") # Make sure abc is gone AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [empty() * 3, "def", "def"]) # Switch to main. Cursor should not move. before = GetCursorPosition() esccmd.DECRESET(code) after = GetCursorPosition() if cursorSaved: AssertEQ(mainCursorPosition.x(), after.x()) AssertEQ(mainCursorPosition.y(), after.y()) else: AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) # def should be gone, abc should be back. AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), ["abc", "abc", empty() * 3]) # Switch to alt before = GetCursorPosition() esccmd.DECSET(code) after = GetCursorPosition() if not movesCursorOnEnter: # 1049 moves the cursor on enter AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) if altGetsClearedBeforeToMain: AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [empty() * 3, empty() * 3, empty() * 3]) else: AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [empty() * 3, "def", "def"])
def test_SGR_Bold(self): """Tests bold.""" escio.Write("x") esccmd.SGR(esccmd.SGR_BOLD) escio.Write("y") AssertCharHasSGR(Point(1, 1), [esccmd.SGR_FG_DEFAULT, esccmd.SGR_BG_DEFAULT], [esccmd.SGR_BOLD]) AssertCharHasSGR( Point(2, 1), [esccmd.SGR_FG_DEFAULT, esccmd.SGR_BG_DEFAULT, esccmd.SGR_BOLD])
def test_VT_ScrollsInTopBottomRegionStartingWithin(self): """VT scrolls when it hits the bottom region (starting within region).""" esccmd.DECSTBM(4, 5) esccmd.CUP(Point(2, 5)) escio.Write("x") esccmd.CUP(Point(2, 4)) escio.Write(VT) escio.Write(VT) AssertEQ(GetCursorPosition(), Point(2, 5)) AssertScreenCharsInRectEqual(Rect(2, 4, 2, 5), ["x", NUL])
def test_PM_8bit(self): escio.use8BitControls = True escio.Write(S8C1T) esccmd.PM() escio.Write("xyz") escio.Write(ST) escio.Write("A") escio.Write(S7C1T) escio.use8BitControls = False AssertScreenCharsInRectEqual(Rect(1, 1, 3, 1), ["A" + empty() * 2])
def test_RIS_ExitAltScreen(self): escio.Write("m") esccmd.DECSET(esccmd.ALTBUF) esccmd.CUP(Point(1, 1)) escio.Write("a") esccmd.RIS() AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), [empty()]) esccmd.DECSET(esccmd.ALTBUF) AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["a"])
def test_CR_MovesToLeftMarginWhenLeftOfLeftMarginInOriginMode(self): """In origin mode, always go to the left margin, even if the cursor starts left of it.""" esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) esccmd.DECSET(esccmd.DECOM) esccmd.CUP(Point(4, 1)) escio.Write(esc.CR) esccmd.DECRESET(esccmd.DECLRMM) escio.Write("x") esccmd.DECRESET(esccmd.DECOM) AssertScreenCharsInRectEqual(Rect(5, 1, 5, 1), ["x"])