Permalink
Browse files

Fixed DECSTBM handling

  closes #61
  • Loading branch information...
1 parent c06027c commit d7c9071e27911df955985a1f2e6fc36ccef1868d @superbobry superbobry committed Nov 18, 2016
Showing with 21 additions and 20 deletions.
  1. +2 −0 CHANGES
  2. +18 −18 pyte/screens.py
  3. +1 −2 tests/test_screen.py
View
@@ -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
-------------
View
@@ -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):
@@ -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.
@@ -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():

0 comments on commit d7c9071

Please sign in to comment.