Skip to content

Commit

Permalink
Fixed DECSTBM handling
Browse files Browse the repository at this point in the history
  closes #61
  • Loading branch information
superbobry committed Nov 18, 2016
1 parent c06027c commit d7c9071
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Version 0.6.0
Thanks to @shaform! See PR #55 on GitHub.
- Fixed ``Screen.display`` in the case of multicolumn characters. See
issue #52 on GitHub.
- Fixed DECSTBM handling in case of missing arguments. See issue #61 on
GitHub.

Version 0.5.2
-------------
Expand Down
36 changes: 18 additions & 18 deletions pyte/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def resize(self, lines=None, columns=None):
del line[columns:]

self.lines, self.columns = lines, columns
self.margins = Margins(0, self.lines - 1)
self.set_margins()
self.reset_mode(mo.DECOM)

def set_margins(self, top=None, bottom=None):
Expand All @@ -304,23 +304,23 @@ def set_margins(self, top=None, bottom=None):
:param int bottom: the biggest line number that is scrolled.
"""
if top is None or bottom is None:
return

# Arguments are 1-based, while :attr:`margins` are zero based --
# so we have to decrement them by one. We also make sure that
# both of them is bounded by [0, lines - 1].
top = max(0, min(top - 1, self.lines - 1))
bottom = max(0, min(bottom - 1, self.lines - 1))

# Even though VT102 and VT220 require DECSTBM to ignore regions
# of width less than 2, some programs (like aptitude for example)
# rely on it. Practicality beats purity.
if bottom - top >= 1:
self.margins = Margins(top, bottom)

# The cursor moves to the home position when the top and
# bottom margins of the scrolling region (DECSTBM) changes.
self.cursor_position()
self.margins = Margins(0, self.lines - 1)
else:
# Arguments are 1-based, while :attr:`margins` are zero
# based -- so we have to decrement them by one. We also
# make sure that both of them is bounded by [0, lines - 1].
top = max(0, min(top - 1, self.lines - 1))
bottom = max(0, min(bottom - 1, self.lines - 1))

# Even though VT102 and VT220 require DECSTBM to ignore
# regions of width less than 2, some programs (like aptitude
# for example) rely on it. Practicality beats purity.
if bottom - top >= 1:
self.margins = Margins(top, bottom)

# The cursor moves to the home position when the top and
# bottom margins of the scrolling region (DECSTBM) changes.
self.cursor_position()

def set_mode(self, *modes, **kwargs):
"""Sets (enables) a given list of modes.
Expand Down
3 changes: 1 addition & 2 deletions tests/test_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,7 @@ def test_set_margins():

# c) no margins provided
screen.set_margins()
assert screen.margins != (None, None)
assert screen.margins == (0, 4)
assert screen.margins == (0, screen.lines - 1)


def test_hide_cursor():
Expand Down

0 comments on commit d7c9071

Please sign in to comment.