Refactor trace log display and handling

Truncate trace logs to improve GUI performance and prevent excessive
display. This change also introduces line length limits for individual
log entries, adding "..." for truncated lines. The display logic for
trace logs has been updated to use `egui::ScrollArea` for better user
experience.
This commit is contained in:
Michael Schimmel
2026-02-18 13:08:38 +01:00
parent 94fc6bf56d
commit 3630cb3c6c
2 changed files with 28 additions and 17 deletions
+2 -2
View File
@@ -146,7 +146,7 @@ impl Value {
Value::Function { .. } => StaticType::Any, // Dynamic function
Value::Object(o) => StaticType::Object(o.type_name()),
Value::Cell(c) => c.borrow().static_type(),
Value::TailCallRequest(_) => panic!("Internal VM state leaked: TailCallRequest"),
Value::TailCallRequest(_) => StaticType::Any, // Internal state, but typable as Any
}
}
}
@@ -181,7 +181,7 @@ impl fmt::Display for Value {
Value::Function(_) => write!(f, "<native fn>"),
Value::Object(o) => write!(f, "<{}>", o.type_name()),
Value::Cell(c) => write!(f, "{}", c.borrow()),
Value::TailCallRequest(_) => panic!("Internal VM state leaked: TailCallRequest"),
Value::TailCallRequest(_) => write!(f, "<tail call request>"),
}
}
}
+26 -15
View File
@@ -101,7 +101,24 @@ impl CompilerApp {
let mut vm = myc::ast::vm::VM::new(self.env.global_values.clone());
let mut observer = myc::ast::vm::TracingObserver::new();
let res = vm.run_with_observer(&mut observer, &linked);
self.trace_logs = observer.logs;
// Batch-truncate logs for GUI performance (once after execution)
let mut logs = observer.logs;
if logs.len() > 1000 {
logs.truncate(1000);
logs.push("... [Trace truncated to 1,000 entries] ...".to_string());
}
for line in &mut logs {
if line.len() > 255 {
if let Some((idx, _)) = line.char_indices().nth(255) {
line.truncate(idx);
line.push_str("...");
}
}
}
self.trace_logs = logs;
self.active_tab = AppTab::Trace;
res?
} else {
@@ -362,20 +379,14 @@ impl eframe::App for CompilerApp {
);
},
AppTab::Trace => {
let mut combined = self.trace_logs.join("\n");
let mut layouter = |ui: &egui::Ui, buffer: &dyn egui::TextBuffer, _wrap_width: f32| {
let layout_job = highlight_myc(ui.ctx(), buffer.as_str());
ui.painter().layout_job(layout_job)
};
ui.add_sized(
ui.available_size(),
egui::TextEdit::multiline(&mut combined)
.font(egui::TextStyle::Monospace)
.desired_width(f32::INFINITY)
.interactive(false)
.layouter(&mut layouter)
);
egui::ScrollArea::vertical()
.id_salt("trace_log_scroll")
.show(ui, |ui| {
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
for line in &self.trace_logs {
ui.label(line);
}
});
}
}
});