refactor(diary): share the console types through internal/consolekit so diary no longer links bonfire (IN-07, quick-261028-rqd)

This commit is contained in:
Jakub Zych
2026-10-28 20:46:32 +01:00
parent 3520d5d480
commit f3f87f3cc4
14 changed files with 364 additions and 169 deletions

View File

@@ -6,10 +6,9 @@ import (
"os"
"path/filepath"
"strings"
"unicode"
"unicode/utf8"
"git.golem15.com/golem15/summercms/internal/argmask"
"git.golem15.com/golem15/summercms/internal/consolekit"
"git.golem15.com/golem15/summercms/modules/sunscreen"
"github.com/charmbracelet/colorprofile"
"github.com/spf13/cobra"
@@ -134,30 +133,7 @@ func Reported(err error) error {
// as 0x9b, CSI) cannot reach a terminal that honours it, and the result is
// always valid UTF-8. A clean, valid string is returned unchanged.
func Sanitize(s string) string {
clean := utf8.ValidString(s)
if clean {
for _, r := range s {
if r != '\t' && unicode.IsControl(r) {
clean = false
break
}
}
}
if clean {
return s
}
s = strings.ToValidUTF8(s, "\uFFFD")
var b strings.Builder
for _, r := range s {
switch {
case r == '\n' || r == '\r':
b.WriteByte(' ')
case r != '\t' && unicode.IsControl(r):
default:
b.WriteRune(r)
}
}
return b.String()
return consolekit.Sanitize(s)
}
// sanitizeLines applies Sanitize to every line of s, keeping the line