-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
import re | ||
|
||
from __future__ import annotations | ||
|
||
SEQ = re.compile(r'\x1b(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') | ||
NEWLINE = re.compile(r'\x1b\[\d+\;1H') | ||
import re | ||
import typing | ||
|
||
def strip_ansi_escape_sequences(string): | ||
return SEQ.sub('', string) | ||
if typing.TYPE_CHECKING: | ||
from .terminal import Terminal | ||
|
||
def replace_newline(string): | ||
return NEWLINE.sub('\n', string) | ||
class OutputParser: | ||
def __init__(self, terminal:Terminal): | ||
self.terminal = terminal | ||
|
||
def parse(self, buf: str): | ||
display_text = "" | ||
i = 0 | ||
while i < len(buf): | ||
match buf[i]: | ||
case '\x07': | ||
# bell | ||
... | ||
case '\x08': | ||
# backspace | ||
... | ||
case '\x09': | ||
# tab | ||
... | ||
case '\x0a': | ||
# newline | ||
# self.terminal._newline() | ||
... | ||
case '\x0d': | ||
# carriage return | ||
... | ||
case '\x1b': | ||
# parse escape sequence | ||
... | ||
case _: | ||
display_text += buf[i] | ||
i += 1 | ||
|
||
return display_text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters