This commit is contained in:
2026-03-08 23:24:33 -04:00
parent bfbcfcc2af
commit fde0f29e72
16 changed files with 348 additions and 88 deletions

View File

@@ -202,10 +202,10 @@ class App:
self.text_viewer_title = label
self.text_viewer_content = content
def _render_heavy_text(self, label: str, content: str) -> None:
def _render_heavy_text(self, label: str, content: str, id_suffix: str = "") -> None:
imgui.text_colored(C_LBL, f"{label}:")
imgui.same_line()
if imgui.button("[+]##" + label):
if imgui.button("[+]##" + label + id_suffix):
self.show_text_viewer = True
self.text_viewer_title = label
self.text_viewer_content = content
@@ -214,13 +214,21 @@ class App:
imgui.text_disabled("(empty)")
return
is_md = label in ("message", "text", "content")
ctx_id = f"heavy_{label}_{id_suffix}"
if len(content) > COMMS_CLAMP_CHARS:
# Use a fixed-height child window with unformatted text for large text to avoid expensive frame-by-frame wrapping or input_text_multiline overhead
imgui.begin_child(f"heavy_text_child_{label}_{hash(content)}", imgui.ImVec2(0, 80), True)
self._render_selectable_label(f'heavy_val_{label}_{hash(content)}', content, width=-1, multiline=True, height=80)
imgui.begin_child(f"heavy_text_child_{label}_{id_suffix}", imgui.ImVec2(0, 80), True)
if is_md:
markdown_helper.render(content, context_id=ctx_id)
else:
markdown_helper.render_code(content, context_id=ctx_id)
imgui.end_child()
else:
self._render_selectable_label(f'heavy_val_{label}_{hash(content)}', content, width=-1, multiline=self.ui_word_wrap, height=0)
if is_md:
markdown_helper.render(content, context_id=ctx_id)
else:
markdown_helper.render_code(content, context_id=ctx_id)
# ---------------------------------------------------------------- gui
@@ -521,13 +529,6 @@ class App:
if self.show_windows.get("Diagnostics", False):
self._render_diagnostics_panel()
if self.show_windows.get("Markdown Test", False):
exp, opened = imgui.begin("Markdown Test", self.show_windows["Markdown Test"])
self.show_windows["Markdown Test"] = bool(opened)
if exp:
self._render_markdown_test()
imgui.end()
self.perf_monitor.end_frame()
# ---- Modals / Popups
with self._pending_dialog_lock:
@@ -1387,7 +1388,7 @@ def hello():
if len(content) > 80: preview += "..."
imgui.text_colored(vec4(180, 180, 180), preview)
else:
self._render_selectable_label(f'prior_content_val_{idx}', content, width=-1, multiline=True, height=150)
markdown_helper.render(content, context_id=f'prior_disc_{idx}')
imgui.separator()
imgui.pop_id()
@@ -1546,14 +1547,14 @@ def hello():
pattern = re.compile(r"\[Definition: (.*?) from (.*?) \(line (\d+)\)\](\s+```[\s\S]*?```)?")
matches = list(pattern.finditer(content))
if not matches:
self._render_selectable_label(f'read_content_{i}', content, width=-1, multiline=True, height=150)
markdown_helper.render(content, context_id=f'disc_{i}')
else:
imgui.begin_child("read_content", imgui.ImVec2(0, 150), True)
imgui.begin_child(f"read_content_{i}", imgui.ImVec2(0, 150), True)
if self.ui_word_wrap: imgui.push_text_wrap_pos(imgui.get_content_region_avail().x)
last_idx = 0
for m_idx, match in enumerate(matches):
before = content[last_idx:match.start()]
if before: self._render_selectable_label(f'read_before_{i}_{m_idx}', before, width=-1, multiline=True, height=0)
if before: markdown_helper.render(before, context_id=f'disc_{i}_b_{m_idx}')
header_text = match.group(0).split("\n")[0].strip()
path = match.group(2)
code_block = match.group(4)
@@ -1565,16 +1566,11 @@ def hello():
self.text_viewer_content = res
self.show_text_viewer = True
if code_block:
code_content = code_block.strip()
if code_content.count("\n") + 1 > 50:
imgui.begin_child(f"code_{i}_{match.start()}", imgui.ImVec2(0, 200), True)
imgui.text(code_content)
imgui.end_child()
else:
imgui.text(code_content)
# Render code block with highlighting
markdown_helper.render(code_block, context_id=f'disc_{i}_c_{m_idx}')
last_idx = match.end()
after = content[last_idx:]
if after: self._render_selectable_label(f'read_after_{i}_{last_idx}', after, width=-1, multiline=True, height=0)
if after: markdown_helper.render(after, context_id=f'disc_{i}_a')
if self.ui_word_wrap: imgui.pop_text_wrap_pos()
imgui.end_child()
else:
@@ -1892,7 +1888,7 @@ def hello():
# --- Always Render Content ---
imgui.begin_child("response_scroll_area", imgui.ImVec2(0, -40), True)
imgui.input_text_multiline("##ai_out", self.ai_response, imgui.ImVec2(-1, -1), imgui.InputTextFlags_.read_only)
markdown_helper.render(self.ai_response, context_id="response")
imgui.end_child()
imgui.separator()
@@ -1981,24 +1977,25 @@ def hello():
imgui.text_colored(C_SUB, f"[{tier}]")
# Optimized content rendering using _render_heavy_text logic
idx_str = str(i)
if kind == "request":
self._render_heavy_text("message", payload.get("message", ""))
self._render_heavy_text("message", payload.get("message", ""), idx_str)
if payload.get("system"):
self._render_heavy_text("system", payload.get("system", ""))
self._render_heavy_text("system", payload.get("system", ""), idx_str)
elif kind == "response":
r = payload.get("round", 0)
sr = payload.get("stop_reason", "STOP")
imgui.text_colored(C_LBL, f"round: {r} stop_reason: {sr}")
self._render_heavy_text("text", payload.get("text", ""))
self._render_heavy_text("text", payload.get("text", ""), idx_str)
tcs = payload.get("tool_calls", [])
if tcs:
self._render_heavy_text("tool_calls", json.dumps(tcs, indent=1))
self._render_heavy_text("tool_calls", json.dumps(tcs, indent=1), idx_str)
elif kind == "tool_call":
self._render_heavy_text(payload.get("name", "call"), payload.get("script") or json.dumps(payload.get("args", {}), indent=1))
self._render_heavy_text(payload.get("name", "call"), payload.get("script") or json.dumps(payload.get("args", {}), indent=1), idx_str)
elif kind == "tool_result":
self._render_heavy_text(payload.get("name", "result"), payload.get("output", ""))
self._render_heavy_text(payload.get("name", "result"), payload.get("output", ""), idx_str)
else:
self._render_heavy_text("data", str(payload))
self._render_heavy_text("data", str(payload), idx_str)
imgui.separator()
imgui.pop_id()