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

🪲 displays tf history correctly #79

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Changes from 1 commit
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
28 changes: 22 additions & 6 deletions opencodeblocks/graphics/blocks/codeblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, **kwargs):
self.source_editor = self.init_source_editor()
self.output_panel = self.init_output_panel()
self.run_button = self.init_run_button()
self.previous_stdout = ""
self.stdout = ""
self.image = ""
self.title_left_offset = 3 * self.edge_size
Expand Down Expand Up @@ -82,13 +83,26 @@ def stdout(self) -> str:
@stdout.setter
def stdout(self, value: str):
self._stdout = value
if hasattr(self, 'source_editor'):
# If there is a text output, erase the image output and display the
# text output
self.image = ""
# If there is a new line
# Save every line but the last one
if value.find('\n') != -1:
lines = value.split('\n')
self.previous_stdout += '\n'.join(lines[:-1]) + '\n'
value = lines[-1]

# Update the last line only
if hasattr(self, 'previous_stdout'):
MathisFederico marked this conversation as resolved.
Show resolved Hide resolved
to_display = self.previous_stdout + value
else:
to_display = value

# If there is a text output, erase the image output
self.image = ""

# Remove ANSI backspaces
text = value.replace("\x08", "")
if hasattr(self, 'output_panel'):
# Remove carriage returns and backspaces
text = to_display.replace("\x08", "")
text = text.replace("\r", "")
# Convert ANSI escape codes to HTML
text = conv.convert(text)
# Replace background color
Expand Down Expand Up @@ -141,6 +155,8 @@ def init_run_button(self):

def run_code(self):
"""Run the code in the block"""
# Erase previous output
self.previous_stdout = ""
code = self.source_editor.text()
self.source = code
# Create a worker to handle execution
Expand Down