Exemple #1
0
    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"])
Exemple #2
0
  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_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"])
Exemple #4
0
    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])
Exemple #5
0
    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!@"
        ])
Exemple #6
0
 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"])
Exemple #7
0
    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))
Exemple #8
0
 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])
Exemple #9
0
def reset():
    esccmd.DECSCL(60 + esc.vtLevel, 1)

    escio.use8BitControls = False
    esccmd.DECSTR()
    esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 25, 80)
    esccmd.DECRESET(esccmd.OPT_ALTBUF)  # Is this needed?
    esccmd.DECRESET(esccmd.OPT_ALTBUF_CURSOR)  # Is this needed?
    esccmd.DECRESET(esccmd.ALTBUF)  # Is this needed?
    esccmd.DECRESET(
        esccmd.DECLRMM
    )  # This can be removed when the bug revealed by test_DECSET_DECLRMM_ResetByDECSTR is fixed.
    esccmd.RM(esccmd.IRM)
    esccmd.RM(esccmd.LNM)
    # Technically, autowrap should be off by default (this is what the spec calls for).
    # However, xterm and iTerm2 turn it on by default. xterm has a comment that says:
    #   There are a couple of differences from real DEC VTxxx terminals (to avoid
    #   breaking applications which have come to rely on xterm doing
    #   this)...autowrap mode should be reset (instead it's reset to the resource
    #   default).
    esccmd.DECSET(esccmd.DECAWM)
    esccmd.DECRESET(esccmd.MoreFix)
    # Set and query title with utf-8
    esccmd.RM_Title(0, 1)
    esccmd.SM_Title(2, 3)
    esccmd.ED(2)

    # Pop the title stack just in case something got left on there
    for _ in xrange(5):
        esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE,
                            esccmd.WINOP_PUSH_TITLE_ICON_AND_WINDOW)

    # Clear tab stops and reset them at 1, 9, ...
    esccmd.TBC(3)
    width = escutil.GetScreenSize().width()
    x = 1
    while x <= width:
        esccmd.CUP(esctypes.Point(x, 1))
        esccmd.HTS()
        x += 8

    esccmd.CUP(esctypes.Point(1, 1))
    esccmd.XTERM_WINOPS(esccmd.WINOP_DEICONIFY)
    # Reset all colors.
    esccmd.ResetColor()

    # Work around a bug in reset colors where dynamic colors do not get reset.
    esccmd.ChangeDynamicColor("10", "#000")
    esccmd.ChangeDynamicColor("11", "#ffffff")
Exemple #10
0
 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))
Exemple #11
0
 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)
Exemple #12
0
 def test_BS_StopsAtLeftMargin(self):
     esccmd.DECSET(esccmd.DECLRMM)
     esccmd.DECSLRM(5, 10)
     esccmd.CUP(Point(5, 1))
     escio.Write(esc.BS)
     esccmd.DECRESET(esccmd.DECLRMM)
     AssertEQ(GetCursorPosition(), Point(5, 1))
Exemple #13
0
    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_SaveRestoreCursor_Wrap(self):
        """Test the position of the cursor after turning auto-wrap mode on and off.

    According to DEC STD 070 (see description on page 5-139 as well as
    pseudo-code on following pages), resetting auto-wrap mode resets the
    terminal's last-column flag, which tells the terminal if it is in the
    special wrap/last-column state.  Older versions of xterm did not
    save/restore the last-column flag in DECRC, causing the cursor to be the
    second column rather than the first when text is written "past" the
    wrapping point.
    """
        # Turn on wrap and save
        esccmd.DECSET(esccmd.DECAWM)
        self.saveCursor()

        # Turn off and restore
        esccmd.DECRESET(esccmd.DECAWM)
        self.restoreCursor()

        # See if we're wrapping.
        esccmd.CUP(Point(GetScreenSize().width() - 1, 1))
        escio.Write("abcd")
        if escargs.args.expected_terminal == "xterm":
            AssertEQ(GetCursorPosition().y(), 1)
        else:
            AssertEQ(GetCursorPosition().y(), 2)
Exemple #15
0
    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'])
Exemple #16
0
    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"])
Exemple #17
0
  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!@"])
Exemple #18
0
 def test_BS_MovesLeftWhenLeftOfLeftMargin(self):
     esccmd.DECSET(esccmd.DECLRMM)
     esccmd.DECSLRM(5, 10)
     esccmd.CUP(Point(4, 1))
     escio.Write(esc.BS)
     esccmd.DECRESET(esccmd.DECLRMM)
     AssertEQ(GetCursorPosition(), Point(3, 1))
Exemple #19
0
    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!@"
        ])
Exemple #20
0
 def test_CR_MovesToLeftMarginWhenRightOfLeftMargin(self):
     """Move the cursor to the left margin if it starts right of it."""
     esccmd.DECSET(esccmd.DECLRMM)
     esccmd.DECSLRM(5, 10)
     esccmd.CUP(Point(6, 1))
     escio.Write(esc.CR)
     esccmd.DECRESET(esccmd.DECLRMM)
     AssertEQ(GetCursorPosition(), Point(5, 1))
Exemple #21
0
 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(1, 2))
   esccmd.DECSET(esccmd.ReverseWraparound)
   esccmd.DECRESET(esccmd.DECAWM)
   escio.Write(BS)
   AssertEQ(GetCursorPosition().x(), 1)
Exemple #22
0
 def test_CR_MovesToLeftOfScreenWhenLeftOfLeftMargin(self):
     """Move the cursor to the left edge of the screen when it starts of left the margin."""
     esccmd.DECSET(esccmd.DECLRMM)
     esccmd.DECSLRM(5, 10)
     esccmd.CUP(Point(4, 1))
     escio.Write(esc.CR)
     esccmd.DECRESET(esccmd.DECLRMM)
     AssertEQ(GetCursorPosition(), Point(1, 1))
Exemple #23
0
  def test_DECSET_DECCOLM(self):
    """DECNCSM - No Clearing Screen On Column Change"""
    # Ensure this is reset from other tests.  Otherwise DECCOLM will not
    # erase the screen.
    esccmd.DECRESET(esccmd.DECNCSM)

    """Set 132 column mode."""
    # From the docs:
    # When the terminal receives the sequence, the screen is erased and the
    # cursor moves to the home position. This also sets the scrolling region
    # for full screen

    # Enable DECCOLM.
    esccmd.DECSET(esccmd.Allow80To132)

    # Write something to verify that it gets erased
    esccmd.CUP(Point(5, 5))
    escio.Write("xyz")

    # Set left-right and top-bottom margins to ensure they're removed.
    esccmd.DECSTBM(1, 2)
    esccmd.DECSET(esccmd.DECLRMM)
    esccmd.DECSLRM(1, 2)

    # Enter 132-column mode.
    esccmd.DECSET(esccmd.DECCOLM)

    # Check that the screen got resized
    AssertEQ(GetScreenSize().width(), 132)

    # Make sure the cursor is at the origin
    position = GetCursorPosition()
    AssertEQ(position.x(), 1)
    AssertEQ(position.y(), 1)

    # Write to make sure the scroll regions are gone
    escio.Write(CR + LF)
    escio.Write("Hello")
    escio.Write(CR + LF)
    escio.Write("World")

    esccmd.DECSTBM()
    esccmd.DECRESET(esccmd.DECLRMM)
    AssertScreenCharsInRectEqual(Rect(1, 2, 5, 3), ["Hello", "World"])
    AssertScreenCharsInRectEqual(Rect(5, 5, 5, 5), [empty()])
Exemple #24
0
 def test_DECSEL_IgnoresScrollRegion(self):
     """Should erase whole line."""
     self.prepare()
     esccmd.DECSET(esccmd.DECLRMM)
     esccmd.DECSLRM(2, 4)
     esccmd.CUP(Point(5, 1))
     esccmd.DECSEL(2)
     esccmd.DECRESET(esccmd.DECLRMM)
     AssertScreenCharsInRectEqual(Rect(1, 1, 10, 1), [10 * empty()])
Exemple #25
0
 def test_DECSET_ResetReverseWraparoundDisablesIt(self):
   """DECRESET of reverse wraparound prevents it from happening."""
   # Note that iTerm disregards the value of ReverseWraparound when there's a
   # soft EOL on the preceding line and always wraps.
   esccmd.DECRESET(esccmd.ReverseWraparound)
   esccmd.DECSET(esccmd.DECAWM)
   esccmd.CUP(Point(1, 2))
   escio.Write(BS)
   AssertEQ(GetCursorPosition().x(), 1)
Exemple #26
0
 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)
Exemple #27
0
 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)
Exemple #28
0
  def test_DCH_DeleteAllWithMargins(self):
    """Delete all characters up to right margin."""
    escio.Write("abcde")
    esccmd.DECSET(esccmd.DECLRMM)
    esccmd.DECSLRM(2, 4)
    esccmd.CUP(Point(3, 1))
    esccmd.DCH(99)
    esccmd.DECRESET(esccmd.DECLRMM)

    AssertScreenCharsInRectEqual(Rect(1, 1, 5, 1), [ "ab" + NUL * 2 + "e" ]);
Exemple #29
0
  def test_DCH_DoesNothingOutsideLeftRightMargin(self):
    """DCH should do nothing outside left-right margins."""
    escio.Write("abcde")
    esccmd.DECSET(esccmd.DECLRMM)
    esccmd.DECSLRM(2, 4)
    esccmd.CUP(Point(1, 1))
    esccmd.DCH(99)
    esccmd.DECRESET(esccmd.DECLRMM)

    AssertScreenCharsInRectEqual(Rect(1, 1, 5, 1), [ "abcde" ])
Exemple #30
0
  def test_DECSET_Allow80To132(self):
    """DECCOLM only has an effect if Allow80To132 is on."""
    # There are four tests:
    #          Allowed   Not allowed
    # 80->132  1         3
    # 132->80  2         4

    # Test 1: 80->132, allowed
    # Allow 80 to 132.
    esccmd.DECSET(esccmd.Allow80To132)
    if GetScreenSize().width() == 132:
      # Enter 80 columns so the test can proceed.
      esccmd.DECRESET(esccmd.DECCOLM)
      AssertEQ(GetScreenSize().width(), 80)

    # Enter 132
    esccmd.DECSET(esccmd.DECCOLM)
    AssertEQ(GetScreenSize().width(), 132)

    # Test 2: 132->80, allowed
    esccmd.DECRESET(esccmd.DECCOLM)
    AssertEQ(GetScreenSize().width(), 80)

    # Test 3: 80->132
    # Disallow 80 to 132
    esccmd.DECRESET(esccmd.Allow80To132)
    # Try to enter 132 - should do nothing.
    esccmd.DECSET(esccmd.DECCOLM)
    AssertEQ(GetScreenSize().width(), 80)

    # Allow 80 to 132
    esccmd.DECSET(esccmd.Allow80To132)

    # Enter 132
    esccmd.DECSET(esccmd.DECCOLM)
    AssertEQ(GetScreenSize().width(), 132)

    # Disallow 80 to 132
    esccmd.DECRESET(esccmd.Allow80To132)

    # Try to enter 80 - should do nothing.
    esccmd.DECRESET(esccmd.DECCOLM)
    AssertEQ(GetScreenSize().width(), 132)