'Resize the screen to the given dimensions.
If the requested screen size has more lines than the existing
screen, lines will be added at the bottom. If the requested
size has less lines than the existing screen lines will be
clipped at the top of the screen. Similarly, if the existing
screen has less columns than the requested screen, columns will
be added at the right, and if it has more -- columns will be
clipped at the right.
.. note:: According to `xterm`, we should also reset origin
mode and screen margins, see ``xterm/screen.c:1761``.
:param int lines: number of lines in the new screen.
:param int columns: number of columns in the new screen.'

def resize(self, lines=None, columns=None):

    lines = (lines or self.lines)
    columns = (columns or self.columns)
    diff = (self.lines - lines)
    if (diff < 0):
        self.buffer.extend((take(self.columns, self.default_line) for _ in range(diff, 0)))
    elif (diff > 0):
        self.buffer[:diff] = ()
    diff = (self.columns - columns)
    if (diff < 0):
        for y in range(lines):
            self.buffer[y].extend(take(abs(diff), self.default_line))
    elif (diff > 0):
        for line in self.buffer:
            del line[columns:]
    (self.lines, self.columns) = (lines, columns)
    self.margins = Margins(0, (self.lines - 1))
    self.reset_mode(mo.DECOM)
