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_CHT_IgnoresScrollingRegion(self): """Test cursor forward tab (ECMA-48). CHT is just a parameterized tab. In DEC terminals (and compatible such as xterm), tabs stop at the right margin. ECMA-48 does not specify margins, so the behavior follows DEC. """ # Set a scroll region. esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 30) # Move to center of region esccmd.CUP(Point(7, 9)) # Ensure we can tab within the region esccmd.CHT(2) position = GetCursorPosition() AssertEQ(position.x(), 17) # Ensure that we can't tab out of the region esccmd.CHT(2) position = GetCursorPosition() AssertEQ(position.x(), 30) # Try again, starting before the region. esccmd.CUP(Point(1, 9)) esccmd.CHT(9) position = GetCursorPosition() AssertEQ(position.x(), 30)
def test_HPA_DefaultParams(self): """With no params, HPA moves to 1st column.""" esccmd.HPA(6) position = GetCursorPosition() AssertEQ(position.x(), 6) esccmd.HPA() position = GetCursorPosition() AssertEQ(position.x(), 1)
def test_HVP_ColumnOnly(self): """Default row is 1.""" esccmd.HVP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.HVP(col=2) position = GetCursorPosition() AssertEQ(position.x(), 2) AssertEQ(position.y(), 1)
def test_HVP_RowOnly(self): """Default column is 1.""" esccmd.HVP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.HVP(row=2) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 2)
def test_CUP_RowOnly(self): """Default column is 1.""" esccmd.CUP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.CUP(row=2) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 2)
def test_CUP_DefaultParams(self): """With no params, CUP moves to 1,1.""" esccmd.CUP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.CUP() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_CUP_ColumnOnly(self): """Default row is 1.""" esccmd.CUP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.CUP(col=2) position = GetCursorPosition() AssertEQ(position.x(), 2) AssertEQ(position.y(), 1)
def test_HVP_DefaultParams(self): """With no params, HVP moves to 1,1.""" esccmd.HVP(Point(6, 3)) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 3) esccmd.HVP() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_NEL_Basic(self): """Next Line moves the cursor down one line and to the start of the next line.""" esccmd.CUP(Point(5, 3)) esccmd.NEL() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 4)
def test_RI_Basic(self): """Reverse index moves the cursor up one line.""" esccmd.CUP(Point(5, 3)) esccmd.RI() position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 2)
def test_IND_Basic(self): """Index moves the cursor down one line.""" esccmd.CUP(Point(5, 3)) esccmd.IND() position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 4)
def test_CHA_DefaultParam(self): """CHA moves to first column of active line by default.""" esccmd.CUP(Point(5, 3)) esccmd.CHA() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_CUB_DefaultParam(self): """CUB moves the cursor left 1 with no parameter given.""" esccmd.CUP(Point(5, 3)) esccmd.CUB() position = GetCursorPosition() AssertEQ(position.x(), 4) AssertEQ(position.y(), 3)
def test_VT_Basic(self): """VT moves the cursor down one line.""" esccmd.CUP(Point(5, 3)) escio.Write(VT) position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 4)
def test_HPR_DefaultParams(self): """With no params, HPR moves right by 1.""" esccmd.CUP(Point(6, 1)) esccmd.HPR() position = GetCursorPosition() AssertEQ(position.x(), 7)
def test_CUP_ZeroIsTreatedAsOne(self): """Zero args are treated as 1.""" esccmd.CUP(Point(6, 3)) esccmd.CUP(col=0, row=0) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_HVP_ZeroIsTreatedAsOne(self): """Zero args are treated as 1.""" esccmd.HVP(Point(6, 3)) esccmd.HVP(col=0, row=0) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_CHA_ExplicitParam(self): """CHA moves to specified column of active line.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(10) position = GetCursorPosition() AssertEQ(position.x(), 10) AssertEQ(position.y(), 3)
def test_CPL_ExplicitParam(self): """CPL moves the cursor up by the passed-in number of lines.""" esccmd.CUP(Point(6, 5)) esccmd.CPL(2) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_CHA_ZeroParam(self): """CHA moves as far left as possible when given a zero parameter.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(0) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_CPL_DefaultParam(self): """CPL moves the cursor up 1 with no parameter given.""" esccmd.CUP(Point(5, 3)) esccmd.CPL() position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 2)
def test_CHA_OutOfBoundsLarge(self): """CHA moves as far as possible when given a too-large parameter.""" esccmd.CUP(Point(5, 3)) esccmd.CHA(9999) position = GetCursorPosition() width = GetScreenSize().width() AssertEQ(position.x(), width) AssertEQ(position.y(), 3)
def test_VPR_DoesNotChangeColumn(self): """VPR moves the specified row and does not change the column.""" esccmd.CUP(Point(5, 6)) esccmd.VPR(2) position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 8)
def test_HPA_DoesNotChangeRow(self): """HPA moves the specified column and does not change the row.""" esccmd.CUP(Point(5, 6)) esccmd.HPA(2) position = GetCursorPosition() AssertEQ(position.x(), 2) AssertEQ(position.y(), 6)
def test_CNL_StopsAtBottomLine(self): """CNL moves the cursor down, stopping at the last line.""" esccmd.CUP(Point(6, 3)) height = GetScreenSize().height() esccmd.CNL(height) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), height)
def test_HVP_OutOfBoundsParams(self): """With overly large parameters, HVP moves as far as possible down and right.""" size = GetScreenSize() esccmd.HVP(Point(size.width() + 10, size.height() + 10)) position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), size.height())
def test_VPA_DoesNotChangeColumn(self): """VPA moves the specified line and does not change the column.""" esccmd.CUP(Point(6, 5)) esccmd.VPA(2) position = GetCursorPosition() AssertEQ(position.x(), 6) AssertEQ(position.y(), 2)
def test_CPL_StopsAtTopLine(self): """CPL moves the cursor up, stopping at the last line.""" esccmd.CUP(Point(6, 3)) height = GetScreenSize().height() esccmd.CPL(height) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 1)
def test_HPR_DoesNotChangeRow(self): """HPR moves the specified column and does not change the row.""" esccmd.CUP(Point(5, 6)) esccmd.HPR(2) position = GetCursorPosition() AssertEQ(position.x(), 7) AssertEQ(position.y(), 6)
def test_CUP_OutOfBoundsParams(self): """With overly large parameters, CUP moves as far as possible down and right.""" size = GetScreenSize() esccmd.CUP(Point(size.width() + 10, size.height() + 10)) position = GetCursorPosition() AssertEQ(position.x(), size.width()) AssertEQ(position.y(), size.height())
def test_DECSET_SaveRestoreCursor(self): """Set saves the cursor position. Reset restores it.""" esccmd.CUP(Point(2, 3)) esccmd.DECSET(esccmd.SaveRestoreCursor) esccmd.CUP(Point(5, 5)) esccmd.DECRESET(esccmd.SaveRestoreCursor) cursor = GetCursorPosition() AssertEQ(cursor.x(), 2) AssertEQ(cursor.y(), 3)
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_CHA_IgnoresScrollRegion(self): """CHA ignores scroll regions.""" # Set a scroll region. esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 10) esccmd.CUP(Point(5, 3)) esccmd.CHA(1) position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 3)
def test_CBT_IgnoresRegion(self): # Set a scroll region. esccmd.DECSET(esccmd.DECLRMM) esccmd.DECSLRM(5, 30) # Move to center of region esccmd.CUP(Point(7, 9)) # Tab backwards out of the region. esccmd.CBT(2) position = GetCursorPosition() AssertEQ(position.x(), 1)
def test_HPA_IgnoresOriginMode(self): """HPA does not respect 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 2nd column esccmd.HPA(2) position = GetCursorPosition() AssertEQ(position.x(), 2)
def test_DECSTR_DECAWM(self): # Turn on autowrap esccmd.DECSET(esccmd.DECAWM) # Perform soft reset esccmd.DECSTR() # Make sure autowrap is still on esccmd.CUP(Point(GetScreenSize().width() - 1, 1)) escio.Write("xxx") position = GetCursorPosition() AssertEQ(position.x(), 2)
def test_RI_8bit(self): esccmd.CUP(Point(5, 3)) escio.use8BitControls = True escio.Write(S8C1T) esccmd.RI() escio.Write(S7C1T) escio.use8BitControls = False position = GetCursorPosition() AssertEQ(position.x(), 5) AssertEQ(position.y(), 2)
def test_NEL_8bit(self): esccmd.CUP(Point(5, 3)) escio.use8BitControls = True escio.Write(S8C1T) esccmd.NEL() escio.Write(S7C1T) escio.use8BitControls = False position = GetCursorPosition() AssertEQ(position.x(), 1) AssertEQ(position.y(), 4)
def doAltBuftest(self, code, altGetsClearedBeforeToMain, cursorSaved): """|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() 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), [NUL * 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", NUL * 3]) # Switch to alt before = GetCursorPosition() esccmd.DECSET(code) after = GetCursorPosition() AssertEQ(before.x(), after.x()) AssertEQ(before.y(), after.y()) if altGetsClearedBeforeToMain: AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [NUL * 3, NUL * 3, NUL * 3]) else: AssertScreenCharsInRectEqual(Rect(1, 1, 3, 3), [NUL * 3, "def", "def"])