Skip to content

Commit 1943e75

Browse files
less hacky stdout mess
1 parent 9d15dbe commit 1943e75

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

gdrepl/gdserverv4.gd

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,14 @@ class Session:
112112
local_scope_lock = false
113113
for line in lines.slice(0, len(lines)-1):
114114
var has_keyword = check_scope(line, i)
115-
var line_stripped = line.strip_edges()
116115

117-
# Replace print statements from previous executions with pass to avoid repeated output
118-
# while keeping control structure bodies valid
119-
var is_print_call = line_stripped.begins_with("print(") or line_stripped.begins_with("printerr(")
120-
121-
# Inject stdout marker at the last scope index
122116
if i == last_index:
123117
var identation = " ".repeat(len(line.rstrip(" ")) - len(line.rstrip(" ").lstrip(" ")))
124118
_local += " " + identation + "print(\"" + STDOUT_MARKER_START + "\")" + "\n"
125119

126-
if is_print_call and i < last_index:
127-
# Replace with pass to avoid repeated output from previous executions
128-
var indentation = " ".repeat(len(line) - len(line.lstrip(" \t")))
129-
_local += " " + indentation + "pass\n"
130-
else:
131-
_local += " " + line + "\n"
132-
120+
_local += " " + line + "\n"
133121
i += 1
134122

135-
# Inject stdout marker before the last line
136123
if i == last_index:
137124
_local += " " + "print(\"" + STDOUT_MARKER_START + "\")" + "\n"
138125

gdrepl/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,15 @@ def wait_for_output(server, timeout):
8888
try:
8989
server.expect(STDOUT_MARKER_END, timeout=timeout)
9090
output = server.before.decode()
91-
# Remove any stdout markers from the output
91+
92+
# Only show output after the last marker (new execution scope)
93+
last_marker_pos = output.rfind(STDOUT_MARKER_START)
94+
if last_marker_pos != -1:
95+
output = output[last_marker_pos + len(STDOUT_MARKER_START) :]
96+
9297
output = output.replace(STDOUT_MARKER_START, "")
9398
output = output.replace(STDOUT_MARKER_END, "")
99+
94100
# Filter out void return errors (these are handled by retry logic)
95101
lines = output.split("\n")
96102
filtered_lines = []

tests/test_e2e.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,33 @@ def test_multiple_prints_in_loop(self, repl):
281281
# (the 'before' buffer should only contain "-> 99" and not "0", "1", "2", "and")
282282
assert repl.before.count("and") == 0, "Loop output should not repeat"
283283

284+
def test_various_output_functions(self, repl):
285+
"""Test that various GDScript output functions work (not just print)."""
286+
# Test printerr - should show output
287+
repl.sendline("printerr('error message')")
288+
repl.expect("error message", timeout=10)
289+
repl.expect(">>>", timeout=10)
290+
291+
# Test push_warning - should show output
292+
repl.sendline("push_warning('warning message')")
293+
repl.expect(">>>", timeout=10)
294+
295+
# Test push_error - should show output
296+
repl.sendline("push_error('error test')")
297+
repl.expect(">>>", timeout=10)
298+
299+
# Test that print_rich works (if available in Godot 4)
300+
repl.sendline("print_rich('[color=red]colored text[/color]')")
301+
repl.expect(">>>", timeout=10)
302+
303+
# Now test that these don't repeat when we add new code
304+
repl.sendline("42")
305+
repl.expect(r"-> 42", timeout=10)
306+
repl.expect(">>>", timeout=10)
307+
308+
# The old messages should not repeat
309+
assert repl.before.count("error message") == 0, "printerr output should not repeat"
310+
284311

285312
@pytest.mark.slow
286313
class TestREPLPersistence:

0 commit comments

Comments
 (0)