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_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_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_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_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 test_DECCRA_ignoresMargins(self): self.prepare() # Set margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 6) esccmd.DECSTBM(3, 6) esccmd.DECCRA(source_top=2, source_left=2, source_bottom=4, source_right=4, source_page=1, dest_top=5, dest_left=5, dest_page=1) # Remove margins esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() # Did it ignore the margins? AssertScreenCharsInRectEqual(Rect(1, 1, 8, 8), [ "abcdefgh", "ijklmnop", "qrstuvwx", "yz012345", "ABCDjklH", "IJKLrstP", "QRSTz01X", "YZ6789!@" ])
def test_DECSED_1_WithScrollRegion_Protection(self): """Erase after cursor with a scroll region present. The scroll region is ignored.""" esccmd.DECSCA(1) self.prepare_wide() # Write an X at 1,1 without protection esccmd.DECSCA(0) esccmd.CUP(Point(1, 1)) escio.Write("X") # Set margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) # Position cursor and do DECSED 1 esccmd.CUP(Point(3, 2)) esccmd.DECSED(1) # Remove margins esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), [blank() + "bcde", "fghij", "klmno"])
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_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 fillRectangle_ignoresMargins(self): self.prepare() # Set margins esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 6) esccmd.DECSTBM(3, 6) # Fill! self.fill(top=5, left=5, bottom=7, right=7) # Remove margins esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() # Did it ignore the margins? AssertScreenCharsInRectEqual(Rect(1, 1, 8, 8), ["abcdefgh", "ijklmnop", "qrstuvwx", "yz012345", "ABCD" + self.characters(Point(5, 5), 3) + "H", "IJKL" + self.characters(Point(5, 6), 3) + "P", "QRST" + self.characters(Point(5, 7), 3) + "X", "YZ6789!@"])
def test_DCH_DoesNothingOutsideTopBottomMargin(self): """DCH should do nothing outside top-bottom margins.""" escio.Write("abcde") esccmd.DECSTBM(2, 3) esccmd.CUP(Point(1, 1)) esccmd.DCH(99) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 1), ["abcde"])
def test_DCH_WorksOutsideTopBottomMargin(self): """Per Thomas Dickey, DCH should work outside scrolling margin (see xterm changelog for patch 316).""" escio.Write("abcde") esccmd.DECSTBM(2, 3) esccmd.CUP(Point(1, 1)) esccmd.DCH(99) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 1), [ NUL * 5 ])
def test_DL_InScrollRegion(self): """Test that DL does the right thing when the cursor is inside the scroll region.""" self.prepareForRegion() esccmd.DECSTBM(2, 4) esccmd.CUP(Point(3, 2)) esccmd.DL() esccmd.DECSTBM() expected_lines = ["abcde", "klmno", "pqrst", NUL * 5, "uvwxy"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_SU_RespectsTopBottomScrollRegion(self): """When the cursor is inside the scroll region, SU should scroll the contents of the scroll region only.""" self.prepare() esccmd.DECSTBM(2, 4) esccmd.CUP(Point(3, 2)) esccmd.SU(2) esccmd.DECSTBM() expected_lines = ["abcde", "pqrst", empty() * 5, empty() * 5, "uvwxy"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_SD_OutsideTopBottomScrollRegion(self): """When the cursor is outside the scroll region, SD should scroll the contents of the scroll region only.""" self.prepare() esccmd.DECSTBM(2, 4) esccmd.CUP(Point(1, 1)) esccmd.SD(2) esccmd.DECSTBM() expected_lines = ["abcde", NUL * 5, NUL * 5, "fghij", "uvwxy"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_ED_1_WithScrollRegion(self): """Erase before cursor with a scroll region present. The scroll region is ignored.""" self.prepare_wide() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.ED(1) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect( 1, 1, 5, 3), [NUL * 5, blank() * 3 + "ij", "klmno"])
def test_ED_2_WithScrollRegion(self): """Erase whole screen with a scroll region present. The scroll region is ignored.""" self.prepare_wide() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.ED(2) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), [NUL * 5, NUL * 5, NUL * 5])
def test_ED_0_WithScrollRegion(self): """Erase after cursor with a scroll region present. The scroll region is ignored.""" self.prepare_wide() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 3) esccmd.CUP(Point(3, 2)) esccmd.ED(0) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() AssertScreenCharsInRectEqual(Rect(1, 1, 5, 3), ["abcde", "fg" + NUL * 3, NUL * 5])
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_DECSTBM_DefaultRestores(self): """Default args restore to full screen scrolling.""" 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"]) position = GetCursorPosition() esccmd.DECSTBM() esccmd.CUP(position) escio.Write(CR + LF) AssertScreenCharsInRectEqual(Rect(1, 2, 1, 3), ["1", "2"]) AssertEQ(GetCursorPosition().y(), 4)
def test_DL_OutsideLeftRightAndTopBottomScrollRegion(self): """Test that DL does nothing outside left-right margins together with top-bottom.""" self.prepareForRegion() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 4) esccmd.CUP(Point(1, 1)) esccmd.DL() esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() expected_lines = ["abcde", "fghij", "klmno", "pqrst", "uvwxy"] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
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_DECFI_Scrolls(self): strings = [ "abcde", "fghij", "klmno", "pqrst", "uvwxy" ] y = 3 for s in strings: esccmd.CUP(Point(2, y)) escio.Write(s) y += 1 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 5) esccmd.DECSTBM(4, 6) esccmd.CUP(Point(5, 5)) esccmd.DECFI() # It is out of character for xterm to use NUL in the middle of the line, # but not terribly important, and not worth marking as a bug. I mentioned # it to TED. AssertScreenCharsInRectEqual(Rect(2, 3, 6, 7), [ "abcde", "fhi" + NUL + "j", "kmn" + NUL + "o", "prs" + NUL + "t", "uvwxy" ])
def test_DECBI_Scrolls(self): strings = [ "abcde", "fghij", "klmno", "pqrst", "uvwxy" ] y = 3 for s in strings: esccmd.CUP(Point(2, y)) escio.Write(s) y += 1 esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(3, 5) esccmd.DECSTBM(4, 6) esccmd.CUP(Point(3, 5)) esccmd.DECBI() AssertScreenCharsInRectEqual(Rect(2, 3, 6, 7), [ "abcde", "f" + blank() + "ghj", "k" + blank() + "lmo", "p" + blank() + "qrt", "uvwxy" ])
def test_SD_LeftRightAndTopBottomScrollRegion(self): """When the cursor is outside the scroll region, SD should scroll the contents of the scroll region only.""" self.prepare() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 4) esccmd.CUP(Point(1, 2)) esccmd.SD(2) esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) expected_lines = [ "abcde", "f" + NUL * 3 + "j", "k" + NUL * 3 + "o", "pghit", "uvwxy" ] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_SD_BigScrollLeftRightAndTopBottomScrollRegion(self): """Scroll a lr and tb scroll region by more than its height.""" self.prepare() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 4) esccmd.CUP(Point(1, 2)) esccmd.SD(99) esccmd.DECSTBM() esccmd.DECRESET(esccmd.DECLRMM) expected_lines = [ "abcde", "f" + NUL * 3 + "j", "k" + NUL * 3 + "o", "p" + NUL * 3 + "t", "uvwxy" ] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_FF_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(FF) # 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(FF) 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(FF) 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(FF) AssertEQ(GetCursorPosition(), Point(1, height)) AssertScreenCharsInRectEqual(Rect(3, 5, 3, 5), [ "x" ])
def test_DECALN_ClearsMargins(self): esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 3) esccmd.DECSTBM(4, 5) esccmd.DECALN() # Verify we can pass the top margin esccmd.CUP(Point(2, 4)) esccmd.CUU() AssertEQ(GetCursorPosition(), Point(2, 3)) # Verify we can pass the bottom margin esccmd.CUP(Point(2, 5)) esccmd.CUD() AssertEQ(GetCursorPosition(), Point(2, 6)) # Verify we can pass the left margin esccmd.CUP(Point(2, 4)) esccmd.CUB() AssertEQ(GetCursorPosition(), Point(1, 4)) # Verify we can pass the right margin esccmd.CUP(Point(3, 4)) esccmd.CUF() AssertEQ(GetCursorPosition(), Point(4, 4))
def test_DL_InLeftRightAndTopBottomScrollRegion(self): """Test that DL respects left-right margins together with top-bottom.""" self.prepareForRegion() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 4) esccmd.CUP(Point(3, 2)) esccmd.DL() esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() expected_lines = [ "abcde", "flmnj", "kqrso", "p" + NUL * 3 + "t", "uvwxy" ] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)
def test_DL_ClearOutLeftRightAndTopBottomScrollRegion(self): """Erase the whole scroll region with both kinds of margins.""" self.prepareForRegion() esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(2, 4) esccmd.DECSTBM(2, 4) esccmd.CUP(Point(3, 2)) esccmd.DL(99) esccmd.DECRESET(esccmd.DECLRMM) esccmd.DECSTBM() expected_lines = [ "abcde", "f" + NUL * 3 + "j", "k" + NUL * 3 + "o", "p" + NUL * 3 + "t", "uvwxy" ] AssertScreenCharsInRectEqual(Rect(1, 1, 5, 5), expected_lines)