Problem
Output written to __terminal__ cannot be cleared. Clearing the target element from application code removes the rendered text only. The next print puts everything back.
Cause
__Terminal__ keeps the output history in self.buffer and rewrites the whole element from that buffer on every call:
|
def print (self, *args, sep = ' ', end = '\n'): |
|
self.buffer = '{}{}{}'.format (self.buffer, sep.join ([str (arg) for arg in args]), end) [-4096 : ] |
|
|
|
if self.element: |
|
self.element.innerHTML = self.buffer.replace ('\n', '<br>') .replace (' ', ' ') |
The class offers no method to reset self.buffer. Replacing the module-level instance does not help either, because print and input are bound to the original instance when the runtime module is loaded:
|
__terminal__ = __Terminal__ () |
|
|
|
print = __terminal__.print |
|
input = __terminal__.input |
Proposed fix
Add a clear() method that resets buffer and element together, so the buffer cannot restore stale output:
def clear (self):
self.buffer = ''
if self.element:
self.element.innerHTML = '_'
'_' is the initial content written by __init__, so clear() returns the terminal to its start state.
Workaround
Reset both parts by hand:
__terminal__.buffer = ''
__terminal__.element.innerHTML = ''
Version
Transcrypt 3.9.5
Contribution
I am happy to write the pull request for this change if the proposed approach is acceptable.
Problem
Output written to
__terminal__cannot be cleared. Clearing the target element from application code removes the rendered text only. The nextprintputs everything back.Cause
__Terminal__keeps the output history inself.bufferand rewrites the whole element from that buffer on every call:Transcrypt/transcrypt/modules/org/transcrypt/__runtime__.py
Lines 284 to 288 in 32b216b
The class offers no method to reset
self.buffer. Replacing the module-level instance does not help either, becauseprintandinputare bound to the original instance when the runtime module is loaded:Transcrypt/transcrypt/modules/org/transcrypt/__runtime__.py
Lines 301 to 304 in 32b216b
Proposed fix
Add a
clear()method that resets buffer and element together, so the buffer cannot restore stale output:'_'is the initial content written by__init__, soclear()returns the terminal to its start state.Workaround
Reset both parts by hand:
Version
Transcrypt 3.9.5
Contribution
I am happy to write the pull request for this change if the proposed approach is acceptable.