lost of ansi codes in log view #12
Labels
No labels
prio_critical
prio_low
type_bug
type_contact
type_issue
type_lead
type_question
type_story
type_task
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
lhumina_code/hero_proc#12
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
fix
use mcp browser to test
Implementation Spec for Issue #12 — ANSI Escape Code Rendering in Log View
Objective
ANSI escape codes (color sequences like
\x1b[32mtext\x1b[0m) that programs emit to stdout/stderr are stored verbatim in the SQLite log database and then passed throughescapeHtml()before being inserted into the DOM. This causes the raw escape sequences to appear as garbled text in every log view instead of being rendered as colored output.The fix is to add a client-side ANSI-to-HTML conversion step in all three log rendering sites in
dashboard.js, using theansi_upJavaScript library.Files to Modify / Create
crates/hero_proc_ui/static/js/ansi_up.min.js— Create: vendor the ansi_up UMD librarycrates/hero_proc_ui/static/js/dashboard.js— Modify: replaceescapeHtml()withansiToHtml()in 3 log rendering sitescrates/hero_proc_ui/templates/base.html— Modify: add<script>tag for ansi_up before dashboard.jsImplementation Plan
Step 1 — Vendor the
ansi_uplibraryDownload ansi_up UMD minified build and save as
crates/hero_proc_ui/static/js/ansi_up.min.js.Dependencies: none.
Step 2 — Add
<script>tag tobase.htmlAdd
<script src="{{ base_path }}/static/js/ansi_up.min.js"></script>before the dashboard.js script tag.Dependencies: Step 1.
Step 3 — Add
ansiToHtmlhelper indashboard.jsAdd a shared
AnsiUpinstance and wrapper function near theescapeHtmlutility.Dependencies: Step 2.
Step 4 — Fix Logs tab (
loadLogs~line 2011)Replace
escapeHtml(l.content)withansiToHtml(l.content)in the log line renderer.Dependencies: Step 3.
Step 5 — Fix Job detail side panel (
viewJob~line 773)Replace
escapeHtml(l.line || l.content)withansiToHtml(l.line || l.content).Dependencies: Step 3.
Step 6 — Fix Job detail modal (
showJobModal~line 2050)Replace
escapeHtml(l.line || l.content)withansiToHtml(l.line || l.content).Dependencies: Step 3.
Acceptance Criteria
<,>,&) still escaped correctly (XSS safe)cargo build -p hero_proc_uisucceedsNotes
ansi_upHTML-escapes content internally — do NOT callescapeHtml()on log content beforeansiToHtml().Test Results
Build: ✅ Success
Tests:
All test suites passed with zero failures. Breakdown by crate:
hero_proc_lib: 86 passedhero_proc_sdk: 137 passed15 tests were intentionally ignored (doc-tests requiring live DB connections).
Tested on branch
development@7c82494Implementation Complete
Changes Made
New file:
crates/hero_proc_ui/static/js/ansi_up.min.js— vendored ansi_up v6 UMD library (~22 KB), embedded via rust-embed like other vendor libs (xterm.min.js, marked.min.js, etc.)Modified files:
crates/hero_proc_ui/templates/base.html— added<script>tag foransi_up.min.jsbeforedashboard.jscrates/hero_proc_ui/static/js/dashboard.js:AnsiUpinstance andansiToHtml()helper function (afterescapeHtml)escapeHtml(l.content)withansiToHtml(l.content)inloadLogs(Logs tab)escapeHtml(l.line || l.content)withansiToHtml(...)inviewJob(Job detail panel)escapeHtml(l.line || l.content)withansiToHtml(...)inshowJobModal(Job detail modal)How It Works
ANSI escape codes (e.g.
\x1b[32mGREEN\x1b[0m) are now processed byansi_upwhich converts them to<span style="color:rgb(...)">elements instead of being displayed as raw text. Theansi_uplibrary handles HTML-escaping internally, maintaining XSS safety. Plain text logs (no ANSI codes) continue to display identically to before.Test Results
cargo build -p hero_proc_ui)Implementation committed:
fab276ccf9cd873772b19a51137d7ff96bed36c2— feat(ui): add log source tree view with multi-select filtering (includes ANSI rendering)19e92cc00f57d22a12d0701998b2555d0d39edfa— feat(ui): render ANSI colors in log view and add source tree sidebar (adds vendored ansi_up.min.js)Browse:
19e92cc00f