fix(bonfire): strip control characters from error blocks, process views and tables

- bonfire.Sanitize (additive), moved from diary's console channel: tab
  kept, CR and LF to a space, every other control character dropped
- applied before styling to every error-block line (message,
  explanation, Try lines, -v chain), process-view item names and errors,
  the current item of spinner and progress, failure lines, and table
  headers and cells in both layouts
- diary's console handler calls bonfire.Sanitize; README and the
  writing-commands page say so (WR-05)
This commit is contained in:
Jakub Zych
2026-10-22 02:31:55 +02:00
parent 39677f1819
commit a9025c0d12
10 changed files with 181 additions and 51 deletions

View File

@@ -96,7 +96,7 @@ func (p *progressBar) Advance(step int) {
func (p *progressBar) Current(string) {}
func (p *progressBar) Fail(item string, err error) {
p.c.Error(failureLine(item, err))
p.c.Error(failureText(item, err))
}
// quietProgress prints nothing but failures (-q).
@@ -109,7 +109,7 @@ func (p *quietProgress) Advance(int) {}
func (p *quietProgress) Current(string) {}
func (p *quietProgress) Fail(item string, err error) {
p.c.Error(failureLine(item, err))
p.c.Error(failureText(item, err))
}
// liveProgress drives the live progress model.
@@ -135,7 +135,7 @@ func (p *liveProgress) Current(item string) {
func (p *liveProgress) Fail(item string, err error) {
p.send(itemMsg{done: p.current, total: p.total, item: item, err: err})
p.send(printLine(failureLine(item, err)))
p.send(printLine(failureText(item, err)))
}
func failureLine(item string, err error) string {
@@ -145,7 +145,14 @@ func failureLine(item string, err error) string {
return item + ": " + err.Error()
}
// failureText is the failure line as printed: one line without control
// characters.
func failureText(item string, err error) string {
return Sanitize(failureLine(item, err))
}
func (c *console) Table(headers []string, rows [][]string) {
headers = padRow(headers, len(headers))
if !c.tty {
c.Println(strings.Join(headers, "\t"))
for _, row := range rows {
@@ -171,11 +178,13 @@ func (c *console) Table(headers []string, rows [][]string) {
c.emit(c.out, t.String()+"\n")
}
// padRow returns n cells of row (missing cells empty), each passed through
// Sanitize so a cell cannot move the cursor or retitle the terminal.
func padRow(row []string, n int) []string {
out := make([]string, n)
for i := 0; i < n; i++ {
if i < len(row) {
out[i] = row[i]
out[i] = Sanitize(row[i])
}
}
return out