Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement scroll up and down sequences #188

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyte/escape.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@

#: *Horizontal position adjust*: Same as :data:`CHA`.
HPA = "'"

#: *Scroll up*: scroll up
SU = "S"

#: *Scroll down*: scroll up
SD = "T"
36 changes: 36 additions & 0 deletions pyte/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,28 @@ def reverse_index(self) -> None:
else:
self.cursor_up()

def scroll_up(self, count: Optional[int] = None) -> None:
"""Scroll the screen up # lines. Cursor does not move.
"""
for _ in range(count or 1):
top, bottom = self.margins or Margins(0, self.lines - 1)
# TODO: mark only the lines within margins?
self.dirty.update(range(self.lines))
for y in range(top, bottom):
self.buffer[y] = self.buffer[y + 1]
self.buffer.pop(bottom, None)

def scroll_down(self, count: Optional[int] = None) -> None:
"""Scroll the screen down # lines. Cursor does not move.
"""
for _ in range(count or 1):
top, bottom = self.margins or Margins(0, self.lines - 1)
# TODO: mark only the lines within margins?
self.dirty.update(range(self.lines))
for y in range(bottom, top, -1):
self.buffer[y] = self.buffer[y - 1]
self.buffer.pop(top, None)

def linefeed(self) -> None:
"""Perform an index and, if :data:`~pyte.modes.LNM` is set, a
carriage return.
Expand Down Expand Up @@ -1230,6 +1252,20 @@ def reverse_index(self) -> None:

super(HistoryScreen, self).reverse_index()

def scroll_up(self, count: Optional[int] = None) -> None:
"""Overloaded to update top history with the removed lines."""
for _ in range(count or 1):
top, bottom = self.margins or Margins(0, self.lines - 1)
self.history.top.append(self.buffer[top])
super(HistoryScreen, self).scroll_up()

def scroll_down(self, count: Optional[int] = None) -> None:
"""Overloaded to update bottom history with the removed lines."""
for _ in range(count or 1):
top, bottom = self.margins or Margins(0, self.lines - 1)
self.history.bottom.append(self.buffer[bottom])
super(HistoryScreen, self).scroll_down()

def prev_page(self) -> None:
"""Move the screen page up through the history buffer. Page
size is defined by ``history.ratio``, so for instance
Expand Down
4 changes: 3 additions & 1 deletion pyte/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class Stream:
esc.SGR: "select_graphic_rendition",
esc.DSR: "report_device_status",
esc.DECSTBM: "set_margins",
esc.HPA: "cursor_to_column"
esc.HPA: "cursor_to_column",
esc.SU: "scroll_up",
esc.SD: "scroll_down"
}

#: A set of all events dispatched by the stream.
Expand Down
Loading