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 repeat escape code #187

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
3 changes: 3 additions & 0 deletions pyte/escape.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@
#: *Horizontal position relative*: Same as :data:`CUF`.
HPR = "a"

#: *Repeat*: Repeat the preceding graphic character # times
REP = "b"

#: *Device Attributes*.
DA = "c"

Expand Down
10 changes: 10 additions & 0 deletions pyte/screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def __init__(self, columns: int, lines: int) -> None:
self.reset()
self.mode = _DEFAULT_MODE.copy()
self.margins: Optional[Margins] = None
self.last_char: str = ""

def __repr__(self) -> str:
return ("{0}({1}, {2})".format(self.__class__.__name__,
Expand Down Expand Up @@ -479,6 +480,7 @@ def draw(self, data: str) -> None:
self.g1_charset if self.charset else self.g0_charset)

for char in data:
self.last_char = char
char_width = wcwidth(char)

# If this was the last column in a line and auto wrap mode is
Expand Down Expand Up @@ -698,6 +700,14 @@ def insert_characters(self, count: Optional[int] = None) -> None:
line[x + count] = line[x]
line.pop(x, None)

def repeat_character(self, count: Optional[int] = None) -> None:
"""Repeat drawing the last drawn character # times.

:param int count: number of characters to insert.
"""
if self.last_char:
self.draw(self.last_char * (count or 1))

def delete_characters(self, count: Optional[int] = None) -> None:
"""Delete the indicated # of characters, starting with the
character at cursor position. When a character is deleted, all
Expand Down
1 change: 1 addition & 0 deletions pyte/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Stream:
esc.DCH: "delete_characters",
esc.ECH: "erase_characters",
esc.HPR: "cursor_forward",
esc.REP: "repeat_character",
esc.DA: "report_device_attributes",
esc.VPA: "cursor_to_line",
esc.VPR: "cursor_down",
Expand Down
Loading