-
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.
Added pyte to handle terminal schenanigans
- Loading branch information
Showing
5 changed files
with
25 additions
and
3 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
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,2 +1,4 @@ | ||
from .language import Language, languages, language_ | ||
from .agent import Agent | ||
from .terminal import Terminal | ||
from .program import Program |
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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import pyte | ||
|
||
class Terminal: | ||
def __init__(self, rows=24, cols=80): | ||
self.screen = pyte.Screen(cols, rows) | ||
self.stream = pyte.Stream(self.screen) | ||
|
||
def emulate(self, raw_output, clean=True): | ||
self.stream.feed(raw_output) | ||
|
||
lines = self.screen.display | ||
self.screen.reset() | ||
|
||
if clean: | ||
lines = (line.rstrip() for line in lines) | ||
lines = (line for line in lines if line) | ||
|
||
return lines |
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