def test_DECCRA_respectsOriginMode(self): self.prepare() # Set margins at 2, 2 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 9) esccmd.DECSTBM(2, 9) # Turn on origin mode esccmd.DECSET(esccmd.DECOM) # Copy from 1,1 to 4,4 - with origin mode, that's 2,2 to 5,5 esccmd.DECCRA(source_top=1, source_left=1, source_bottom=3, source_right=3, source_page=1, dest_top=4, dest_left=4, dest_page=1) # Turn off margins and origin mode esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECOM) # See what happened. AssertScreenCharsInRectEqual(Rect(1, 1, 8, 8), [ "abcdefgh", "ijklmnop", "qrstuvwx", "yz012345", "ABCDjklH", "IJKLrstP", "QRSTz01X", "YZ6789!@" ])
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' + empty(), empty() * 2, empty() + 'Y'])
def test_SaveRestoreCursor_ResetsOriginMode(self): esccmd.CUP(Point(5, 6)) self.saveCursor() # Set up margins. esccmd.DECSTBM(5, 7) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 7) # Enter origin mode. esccmd.DECSET(esccmd.DECOM) # Do DECRC, which should reset origin mode. self.restoreCursor() # Move home esccmd.CUP(Point(1, 1)) # Place an X at cursor, which should be at (1, 1) if DECOM was reset. escio.Write("X") # Remove margins and ensure origin mode is off for valid test. esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECOM) # Ensure the X was placed at the true origin AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["X"])
def test_CUP_RespectsOriginMode(self): """CUP is relative to margins in origin mode.""" # Set a scroll region. esccmd.DECSTBM(6, 11) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) # Move to center of region esccmd.CUP(Point(7, 9)) position = GetCursorPosition() AssertEQ(position.x(), 7) AssertEQ(position.y(), 9) # Turn on origin mode. esccmd.DECSET(esccmd.DECOM) # Move to top-left esccmd.CUP(Point(1, 1)) # Check relative position while still in origin mode. position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1) escio.Write("X") # Turn off origin mode. This moves the cursor. esccmd.DECRESET(esccmd.DECOM) # Turn off scroll regions so checksum can work. esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) # Make sure there's an X at 5,6 AssertScreenCharsInRectEqual(Rect(5, 6, 5, 6), ["X"])
def fillRectangle_respectsOriginMode(self): self.prepare() # Set margins starting at 2 and 2 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 9) esccmd.DECSTBM(2, 9) # Turn on origin mode esccmd.DECSET(esccmd.DECOM) # Fill from 1,1 to 3,3 - with origin mode, that's 2,2 to 4,4 self.fill(top=1, left=1, bottom=3, right=3) # Turn off margins and origin mode esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECOM) # See what happened. AssertScreenCharsInRectEqual(Rect(1, 1, 8, 8), ["abcdefgh", "i" + self.characters(Point(2, 2), 3) + "mnop", "q" + self.characters(Point(2, 3), 3) + "uvwx", "y" + self.characters(Point(2, 4), 3) + "2345", "ABCDEFGH", "IJKLMNOP", "QRSTUVWX", "YZ6789!@"])
def test_DECSTR_DECOM(self): # Define a scroll region esccmd.DECSTBM(3, 4) # Turn on origin mode esccmd.DECSET(esccmd.DECOM) # Perform soft reset esccmd.DECSTR() # Define scroll region again esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 4) esccmd.DECSTBM(4, 5) # Move to 1,1 (or 3,4 if origin mode is still on) and write an X esccmd.CUP(Point(1, 1)) escio.Write("X") # Turn off origin mode esccmd.DECRESET(esccmd.DECOM) # Make sure the X was at 1, 1, implying origin mode was off. esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) AssertScreenCharsInRectEqual(Rect( 1, 1, 3, 4), ["X" + NUL * 2, NUL * 3, NUL * 3, NUL * 3])
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), [NUL + "X" + NUL * 2 + "Y"])
def test_BS_WrapsInWraparoundMode(self): esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) size = GetScreenSize() AssertEQ(GetCursorPosition(), Point(size.width(), 2))
def test_BS_ReverseWrapWontPassTop(self): esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSTBM(2, 5) esccmd.CUP(Point(1, 2)) escio.Write(esc.BS) AssertEQ(GetCursorPosition(), Point(1, 2))
def test_RIS_ResetDECCOLM(self): esccmd.DECSET(esccmd.Allow80To132) esccmd.DECSET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 132) esccmd.RIS() AssertEQ(GetScreenSize().width(), 80)
def test_BS_ReverseWrapWithLeftRight(self): esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) esccmd.CUP(Point(5, 3)) escio.Write(esc.BS) AssertEQ(GetCursorPosition(), Point(10, 2))
def test_DECSET_ReverseWraparound_Multi(self): size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("abcd") esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUB(4) AssertEQ(GetCursorPosition().x(), size.width() - 1)
def test_DECSET_ReverseWraparound_BS(self): """xterm supports DECSET 45 to toggle 'reverse wraparound'. Both DECAWM and 45 must be set.""" # iTerm2 turns reverse wraparound on by default, while xterm does not. esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) esccmd.CUP(Point(1, 2)) escio.Write(BS) AssertEQ(GetCursorPosition().x(), GetScreenSize().width())
def test_DECSET_DECAWM_OnRespectsLeftRightMargin(self): """Auto-wrap mode on respects left-right margins.""" esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 9) esccmd.DECSTBM(5, 9) esccmd.CUP(Point(8, 9)) esccmd.DECSET(esccmd.DECAWM) escio.Write("abcdef") AssertScreenCharsInRectEqual(Rect(5, 8, 9, 9), [empty() * 3 + "ab", "cdef" + empty()])
def test_BS_ReversewrapFromLeftEdgeToRightMargin(self): """If cursor starts at left edge of screen, left of left margin, backspace takes it to the right margin.""" esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) AssertEQ(GetCursorPosition(), Point(10, 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_DECSET_DECLRMM_ResetByDECSTR(self): """DECSTR should turn off DECLRMM.""" esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSTR() esccmd.DECSET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.CUP(Point(GetScreenSize().width() - 1, 1)) escio.Write("abc") # Reverse wraparound is disabled (at least in iTerm2) when a scroll region is present. escio.Write(BS * 3) AssertEQ(GetCursorPosition().y(), 1)
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"])
def test_DECSCL_Level5_SupportsDECNCSM(self): # Set level 5 conformance esccmd.DECSCL(65, 1) # Set DECNCSM, Set column mode. Screen should not be cleared. esccmd.DECRESET(esccmd.DECCOLM) esccmd.DECSET(esccmd.DECNCSM) esccmd.CUP(Point(1, 1)) escio.Write("1") esccmd.DECSET(esccmd.DECCOLM) AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["1"])
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_BS_ReverseWrapRequiresDECAWM(self): esccmd.DECRESET(esccmd.DECAWM) esccmd.DECSET(esccmd.ReverseWraparound) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) AssertEQ(GetCursorPosition(), Point(1, 3)) esccmd.DECSET(esccmd.DECAWM) esccmd.DECRESET(esccmd.ReverseWraparound) esccmd.CUP(Point(1, 3)) escio.Write(esc.BS) AssertEQ(GetCursorPosition(), Point(1, 3))
def test_DECSET_DECOM_DECRQCRA(self): """DECRQCRA should be relative to the origin in origin mode. DECRQCRA doesn't have its own test so this is tested here instead.""" esccmd.CUP(Point(5, 5)) escio.Write("X") esccmd.DECSTBM(5, 7) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 7) esccmd.DECSET(esccmd.DECOM) AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["X"])
def test_DECSET_DECOM_SoftReset(self): """Soft reset turns off DECOM.""" esccmd.DECSTBM(5, 7) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 7) esccmd.DECSET(esccmd.DECOM) esccmd.DECSTR() esccmd.CHA(1) esccmd.VPA(1) escio.Write("X") AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["X"])
def doModifiableDecTest(self, mode): before = self.requestDECMode(mode) if before[1] == 2: esccmd.DECSET(mode) AssertEQ(self.requestDECMode(mode), [mode, 1]) esccmd.DECRESET(mode) AssertEQ(self.requestDECMode(mode), [mode, 2]) else: esccmd.DECRESET(mode) AssertEQ(self.requestDECMode(mode), [mode, 2]) esccmd.DECSET(mode) AssertEQ(self.requestDECMode(mode), [mode, 1])
def test_DECSET_ReverseWraparoundLastCol_BS(self): """If the cursor is in the last column and a character was just output and reverse-wraparound is on then backspace by 1 has no effect.""" esccmd.DECSET(esccmd.ReverseWraparound) esccmd.DECSET(esccmd.DECAWM) size = GetScreenSize() esccmd.CUP(Point(size.width() - 1, 1)) escio.Write("a") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write("b") AssertEQ(GetCursorPosition().x(), size.width()) escio.Write(BS) AssertEQ(GetCursorPosition().x(), size.width())
def test_RIS_ResetDECOM(self): esccmd.DECSTBM(5, 7) esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 7) esccmd.DECSET(esccmd.DECOM) esccmd.RIS() esccmd.CUP(Point(1, 1)) escio.Write("X") esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 1, 1), ["X"])
def test_RIS_ResetDECCOLM(self): """Test whether RIS resets DECCOLM. The control sequence allowing 80/132 switching is an xterm feature not found in DEC terminals. When doing a full reset, xterm checks that, as well as checking if the terminal is currently in 132-column mode. Older versions of xterm would reset the 132-column mode before checking if it was enabled, failing this test.""" esccmd.DECSET(esccmd.Allow80To132) esccmd.DECSET(esccmd.DECCOLM) AssertEQ(GetScreenSize().width(), 132) esccmd.RIS() AssertEQ(GetScreenSize().width(), 80)
def test_DECSET_DECLRMM_MarginsResetByDECSTR(self): esccmd.DECSLRM(2, 4) esccmd.DECSTR() esccmd.DECSET(esccmd.DECLRMM) esccmd.CUP(Point(3, 3)) escio.Write("abc") AssertEQ(GetCursorPosition().x(), 6)
def test_CR_StaysPutWhenAtLeftMargin(self): esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) esccmd.CUP(Point(5, 1)) escio.Write(esc.CR) esccmd.DECRESET(esccmd.DECLRMM) AssertEQ(GetCursorPosition(), Point(5, 1))
def test_DECRQM_DEC_DECCOLM(self): needsPermission = escargs.args.expected_terminal in ["xterm", "iTerm2"] if needsPermission: esccmd.DECSET(esccmd.Allow80To132) self.doModifiableDecTest(esccmd.DECCOLM) if needsPermission: esccmd.DECRESET(esccmd.Allow80To132)