def test_XtermWinops_Fullscreen(self): original_size = GetScreenSize() display_size = GetDisplaySize() # Enter fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_ENTER) time.sleep(1) actual_size = GetScreenSize() AssertTrue(actual_size.width() >= display_size.width()) AssertTrue(actual_size.height() >= display_size.height()) AssertTrue(actual_size.width() >= original_size.width()) AssertTrue(actual_size.height() >= original_size.height()) # Exit fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_EXIT) AssertEQ(GetScreenSize(), original_size) # Toggle in esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) AssertTrue(actual_size.width() >= display_size.width()) AssertTrue(actual_size.height() >= display_size.height()) AssertTrue(actual_size.width() >= original_size.width()) AssertTrue(actual_size.height() >= original_size.height()) # Toggle out esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) AssertEQ(GetScreenSize(), original_size)
def test_XtermWinops_PushIconThenWindowThenPopBoth(self): """Push icon, then push window, then pop both.""" # Generate a uniqueish string string1 = "a" + str(time.time()) string2 = "b" + str(time.time()) # Set titles esccmd.ChangeWindowTitle(string1) esccmd.ChangeIconTitle(string2) # Push icon then window esccmd.XTERM_WINOPS(esccmd.WINOP_PUSH_TITLE, esccmd.WINOP_PUSH_TITLE_ICON) esccmd.XTERM_WINOPS(esccmd.WINOP_PUSH_TITLE, esccmd.WINOP_PUSH_TITLE_WINDOW) # Change both to known values. esccmd.ChangeWindowTitle("y") esccmd.ChangeIconTitle("z") # Pop both titles. esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_ICON_AND_WINDOW) AssertEQ(GetWindowTitle(), string1) AssertEQ(GetIconTitle(), string2)
def test_XtermWinops_ResizePixels_ZeroHeight(self): """Resize the window to a pixel size, setting one parameter to 0. The window should maximize in the direction of the 0 parameter.""" original_size = GetWindowSizePixels() # Set height and maximize width. desired_width = 400 esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, 0, desired_width) # Make sure the height changed as requested. max_error = 20 actual_size = GetWindowSizePixels() AssertTrue(abs(actual_size.width() - desired_width) < max_error) # See if the height is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.height() - screen_size.height()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_XtermWinops_Fullscreen(self): original_size = GetScreenSize() display_size = GetDisplaySize() # Enter fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_ENTER) self.DelayAfterResize() actual_size = GetScreenSize() self.CheckAnySize(display_size, actual_size, Size(3, 3)) self.CheckForShrinkage(original_size, actual_size) # Exit fullscreen esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_EXIT) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize()) # Toggle in esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize()) # Toggle out esccmd.XTERM_WINOPS(esccmd.WINOP_FULLSCREEN, esccmd.WINOP_FULLSCREEN_TOGGLE) self.DelayAfterResize() self.CheckForShrinkage(original_size, GetScreenSize())
def test_XtermWinops_PushIconAndWindow_PopWindow(self): """Push an icon & window title and pop just the window title.""" # Generate a uniqueish string string = str(time.time()) # Set the window and icon title, then push both. esccmd.ChangeWindowAndIconTitle(string) AssertEQ(GetWindowTitle(), string) AssertEQ(GetIconTitle(), string) esccmd.XTERM_WINOPS(esccmd.WINOP_PUSH_TITLE, esccmd.WINOP_PUSH_TITLE_ICON_AND_WINDOW) # Change to x, make sure it took. esccmd.ChangeWindowTitle("x") esccmd.ChangeIconTitle("x") AssertEQ(GetWindowTitle(), "x") AssertEQ(GetIconTitle(), "x") # Pop icon title, ensure correct. esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_WINDOW) AssertEQ(GetWindowTitle(), string) AssertEQ(GetIconTitle(), "x") # Try to pop the icon title; should do nothing. esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_ICON) AssertEQ(GetWindowTitle(), string) AssertEQ(GetIconTitle(), "x")
def test_XtermWinops_MoveToXY(self): esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 0, 0) self.DelayAfterMove() AssertEQ(GetWindowPosition(), Point(0, 0)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1, 1) self.DelayAfterMove() AssertEQ(GetWindowPosition(), Point(1, 1))
def test_XtermWinops_PushMultiplePopMultiple_Window(self): """Push two titles and pop twice.""" # Generate a uniqueish string string1 = "a" + str(time.time()) string2 = "b" + str(time.time()) for title in [ string1, string2 ]: # Set title esccmd.ChangeWindowTitle(title) # Push esccmd.XTERM_WINOPS(esccmd.WINOP_PUSH_TITLE, esccmd.WINOP_PUSH_TITLE_WINDOW) # Change to known values. esccmd.ChangeWindowTitle("z") # Pop esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_WINDOW) AssertEQ(GetWindowTitle(), string2) # Pop esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_WINDOW) AssertEQ(GetWindowTitle(), string1)
def test_XtermWinops_IconifyDeiconfiy(self): esccmd.XTERM_WINOPS(esccmd.WINOP_ICONIFY) self.DelayAfterIcon() AssertEQ(GetIsIconified(), True) esccmd.XTERM_WINOPS(esccmd.WINOP_DEICONIFY) self.DelayAfterIcon() AssertEQ(GetIsIconified(), False)
def GetWindowSizePixels(): """Returns a Size giving the window's size in pixels.""" if CanQueryShellSize() == 2: esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_SIZE_PIXELS, 2) else: esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_SIZE_PIXELS) params = escio.ReadCSI("t") AssertTrue(params[0] == 4) AssertTrue(len(params) >= 3) return Size(params[2], params[1])
def test_XtermWinops_MoveToXY(self): needsSleep = escargs.args.expected_terminal in [ "xterm" ] esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 0, 0) if needsSleep: time.sleep(0.1) AssertEQ(GetWindowPosition(), Point(0, 0)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1, 1) if needsSleep: time.sleep(0.1) AssertEQ(GetWindowPosition(), Point(1, 1))
def test_XtermWinops_IconifyDeiconfiy(self): needsSleep = escargs.args.expected_terminal in [ "xterm" ] esccmd.XTERM_WINOPS(esccmd.WINOP_ICONIFY) if needsSleep: time.sleep(1) AssertEQ(GetIsIconified(), True) esccmd.XTERM_WINOPS(esccmd.WINOP_DEICONIFY) if needsSleep: time.sleep(1) AssertEQ(GetIsIconified(), False)
def test_XtermWinops_ResizePixels_ZeroWidth(self): """Resize the window to a pixel size, setting one parameter to 0. The window should maximize in the direction of the 0 parameter.""" if escargs.args.expected_terminal == "xterm": maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() # Set height and maximize width. desired_size = Size(maximum_size.width(), self.AverageHeight(maximum_size, original_size)) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), 0) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) # See if the width is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.width() - screen_size.width()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize() else: original_size = GetWindowSizePixels() # Set height and maximize width. desired_height = 200 esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_height, 0) # Make sure the height changed as requested. max_error = 20 actual_size = GetWindowSizePixels() AssertTrue(abs(actual_size.height() - desired_height) < max_error) # See if the width is about as big as the display (only measurable in # characters, not pixels). display_size = GetDisplaySize() # In characters screen_size = GetScreenSize() # In characters max_error = 5 AssertTrue(abs(display_size.width() - screen_size.width()) < max_error) # Restore to original size. esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_XtermWinops_DECSLPP(self): """Resize to n lines of height.""" esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 10, 90) AssertEQ(GetScreenSize(), Size(90, 10)) esccmd.XTERM_WINOPS(24) AssertEQ(GetScreenSize(), Size(90, 24)) esccmd.XTERM_WINOPS(30) AssertEQ(GetScreenSize(), Size(90, 30))
def test_XtermWinops_MaximizeWindow_Vertically(self): desired_size = Size(GetScreenSize().width(), GetDisplaySize().height()) esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_V) self.DelayAfterResize() actual_size = GetScreenSize() esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_EXIT) self.DelayAfterResize() if escargs.args.expected_terminal == "xterm": error_limit = Size(0, 5) else: error_limit = Size(0, 0) self.CheckAnySize(desired_size, actual_size, Size(0, 5))
def test_XtermWinops_MaximizeWindow_HorizontallyAndVertically(self): esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_HV) self.DelayAfterResize() actual_size = GetScreenSize() desired_size = GetDisplaySize() esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_EXIT) self.DelayAfterResize() if escargs.args.expected_terminal == "xterm": error_limit = Size(3, 3) else: error_limit = Size(0, 0) self.CheckAnySize(desired_size, actual_size, error_limit)
def test_XtermWinops_MoveToXY_Defaults(self): """Default args are interpreted as 0s.""" esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1, 1) self.DelayAfterMove() AssertEQ(GetWindowPosition(), Point(1, 1)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1) self.DelayAfterMove() AssertEQ(GetWindowPosition(), Point(1, 0)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, None, 1) self.DelayAfterMove() AssertEQ(GetWindowPosition(), Point(0, 1))
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")
def GetWindowPosition(): """Returns a Point giving the window's origin in screen pixels.""" esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_POSITION) params = escio.ReadCSI("t") AssertTrue(params[0] == 3) AssertTrue(len(params) >= 3) return Point(params[1], params[2])
def GetWindowTitle(): if escargs.args.expected_terminal == "iTerm2": raise esctypes.InternalError( "iTerm2 uses L instead of l as initial char for window title reports." ) esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_WINDOW_TITLE) return escio.ReadOSC("l")
def test_XtermWinops_MaximizeWindow_Vertically(self): display_size = GetDisplaySize() original_size = GetScreenSize() expected_size = Size(width=original_size.width(), height=display_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_MAXIMIZE, esccmd.WINOP_MAXIMIZE_V) AssertEQ(GetScreenSize(), expected_size)
def test_XtermWinops_ResizeChars_DefaultWidth(self): size = GetScreenSize() desired_size = Size(size.width(), 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height()) AssertEQ(GetScreenSize(), desired_size)
def test_XtermWinops_ResizeChars_BothParameters(self): """Resize the window to a character size, giving both parameters.""" desired_size = Size(20, 21) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, desired_size.height(), desired_size.width()) AssertEQ(GetScreenSize(), desired_size)
def GetScreenSize(): """Return the terminal's screen-size in characters. The size is reported for the terminal's character-cell window, which is smaller than the shell-window.""" esccmd.XTERM_WINOPS(esccmd.WINOP_REPORT_TEXT_AREA_CHARS) params = escio.ReadCSI("t") return Size(params[2], params[1])
def test_XtermWinops_MoveToXY_Defaults(self): """Default args are interepreted as 0s.""" needsSleep = escargs.args.expected_terminal in [ "xterm" ] esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1, 1) if needsSleep: time.sleep(0.1) AssertEQ(GetWindowPosition(), Point(1, 1)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, 1) if needsSleep: time.sleep(0.1) AssertEQ(GetWindowPosition(), Point(1, 0)) esccmd.XTERM_WINOPS(esccmd.WINOP_MOVE, None, 1) if needsSleep: time.sleep(0.1) AssertEQ(GetWindowPosition(), Point(0, 1))
def test_XtermWinops_ResizePixels_BothParameters(self): """Resize the window to a pixel size, giving both parameters.""" maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() if escargs.args.expected_terminal == "xterm": desired_size = Size( self.AverageWidth(maximum_size, original_size), self.AverageHeight(maximum_size, original_size)) else: desired_size = Size(400, 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), desired_size.width()) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize()
def test_XtermWinops_PushWindow_PopWindow(self): """Push window title and then pop it.""" # Generate a uniqueish string string = str(time.time()) # Set the window and icon title, then push both. esccmd.ChangeIconTitle("x") esccmd.ChangeWindowTitle(string) esccmd.XTERM_WINOPS(esccmd.WINOP_PUSH_TITLE, esccmd.WINOP_PUSH_TITLE_WINDOW) # Change to x. esccmd.ChangeWindowTitle("y") # Pop window title, ensure correct. esccmd.XTERM_WINOPS(esccmd.WINOP_POP_TITLE, esccmd.WINOP_POP_TITLE_WINDOW) AssertEQ(GetIconTitle(), "x") AssertEQ(GetWindowTitle(), string)
def test_XtermWinops_ResizePixels_OmittedHeight(self): """Resize the window to a pixel size, omitting one parameter. The size should not change in the direction of the omitted parameter.""" maximum_size = GetScreenSizePixels() original_size = GetWindowSizePixels() if escargs.args.expected_terminal == "xterm": desired_size = Size(maximum_size.width(), original_size.height()) else: desired_size = Size(400, original_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, None, desired_size.width()) self.DelayAfterResize() self.CheckActualSizePixels(desired_size) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width()) self.DelayAfterResize()
def test_XtermWinops_ResizeChars_ZeroHeight(self): """Resize the window to a character size, setting one param to 0 (max size in that direction).""" max_size = GetDisplaySize() desired_size = Size(20, max_size.height()) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_CHARS, 0, desired_size.width()) AssertEQ(GetScreenSize(), desired_size)
def test_XtermWinops_ResizePixels_OmittedWidth(self): """Resize the window to a pixel size, omitting one parameter. The size should not change in the direction of the omitted parameter.""" original_size = GetWindowSizePixels() desired_size = Size(original_size.width(), 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height()) # See if we're within 20px of the desired size. It won't be exact because # most terminals snap to grid. actual_size = GetWindowSizePixels() error = Size(abs(actual_size.width() - desired_size.width()), abs(actual_size.height() - desired_size.height())) max_error = 20 AssertTrue(error.width() <= max_error) AssertTrue(error.height() <= max_error) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())
def test_XtermWinops_ResizePixels_BothParameters(self): """Resize the window to a pixel size, giving both parameters.""" original_size = GetWindowSizePixels() desired_size = Size(400, 200) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, desired_size.height(), desired_size.width()) # See if we're within 20px of the desired size on each dimension. It won't # be exact because most terminals snap to grid. actual_size = GetWindowSizePixels() error = Size(abs(actual_size.width() - desired_size.width()), abs(actual_size.height() - desired_size.height())) max_error = 20 AssertTrue(error.width() <= max_error) AssertTrue(error.height() <= max_error) esccmd.XTERM_WINOPS(esccmd.WINOP_RESIZE_PIXELS, original_size.height(), original_size.width())