crash: render ANSI colors on crash page

Could not for the life of me get any regex to properly strip the ANSI
escape sequences, so the text log will have to suffer with them, but the
ansihtml library is now used to render them into HTML.
This commit is contained in:
Harvey Tindall
2023-06-12 15:48:07 +01:00
parent dc60e97415
commit 73202e1483
3 changed files with 14 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ import (
"runtime/debug"
"strings"
"time"
"github.com/robert-nix/ansihtml"
)
// https://gist.github.com/swdunlop/9629168
@@ -84,6 +86,12 @@ func Exit(err interface{}) {
log.Fatalf("Failed to write crash dump file: %v", err2)
}
log.Printf("\n------\nA crash report has been saved to \"%s\".\n------", fpath+".txt")
// Render ANSI colors to HTML
data["Log"] = template.HTML(string(ansihtml.ConvertToHTML([]byte(data["Log"].(string)))))
data["SanitizedLog"] = template.HTML(string(ansihtml.ConvertToHTML([]byte(data["SanitizedLog"].(string)))))
data["Err"] = template.HTML(string(ansihtml.ConvertToHTML([]byte(data["Err"].(string)))))
f, err2 := os.OpenFile(fpath+".html", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err2 != nil {
log.Fatalf("Failed to open crash dump file: %v", err2)