Skip to content

Commit

Permalink
Implement repeat escape code
Browse files Browse the repository at this point in the history
  • Loading branch information
Moult committed Dec 23, 2024
1 parent 636b679 commit 135125e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
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

0 comments on commit 135125e

Please sign in to comment.