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

@@ -14,7 +14,7 @@ import (
"time"
"charm.land/lipgloss/v2"
"git.golem15.com/golem15/summercms/modules/bonfire"
"git.golem15.com/golem15/summercms/internal/consolekit"
"github.com/charmbracelet/colorprofile"
"golang.org/x/term"
)
@@ -60,7 +60,7 @@ func newConsoleHandler(w io.Writer, opts ConsoleOptions, source *atomic.Bool) *c
mu: new(sync.Mutex),
level: level,
source: source,
palette: bonfire.DefaultPalette(),
palette: consolekit.DefaultPalette(),
}
}
@@ -74,7 +74,7 @@ type consoleHandler struct {
mu *sync.Mutex
level slog.Leveler
source *atomic.Bool
palette bonfire.Palette
palette consolekit.Palette
// terminal is true when the handler's writer is a terminal, checked
// once when the handler is built: only then are HideOnTTY records
// skipped.
@@ -148,12 +148,12 @@ func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
label, style := levelLabel(r.Level, p)
b.WriteString(style.Render(label))
b.WriteString(strings.Repeat(" ", max(0, 5-len(label))+1))
name := bonfire.Sanitize(component)
name := consolekit.Sanitize(component)
if name != "" {
b.WriteString(p.Header.Render(name))
}
b.WriteString(strings.Repeat(" ", max(0, componentWidth-len(name))+1))
b.WriteString(bonfire.Sanitize(r.Message))
b.WriteString(consolekit.Sanitize(r.Message))
for _, list := range [][]consoleAttr{h.attrs, recAttrs} {
for _, a := range list {
b.WriteByte(' ')
@@ -170,7 +170,7 @@ func (h *consoleHandler) Handle(ctx context.Context, r slog.Record) error {
}
// While a bonfire live view (spinner, progress, process view) runs,
// the line prints above it instead of tearing it.
if bonfire.PrintAbove(b.String()) {
if consolekit.PrintAbove(b.String()) {
return nil
}
b.WriteByte('\n')
@@ -212,7 +212,7 @@ func isTerminal(w io.Writer) bool {
return ok && term.IsTerminal(int(f.Fd()))
}
func levelLabel(l slog.Level, p bonfire.Palette) (string, lipgloss.Style) {
func levelLabel(l slog.Level, p consolekit.Palette) (string, lipgloss.Style) {
switch {
case l < slog.LevelInfo:
return l.String(), p.Muted
@@ -254,7 +254,7 @@ func appendAttr(out []consoleAttr, prefix string, a slog.Attr) []consoleAttr {
}
return out
}
return append(out, consoleAttr{key: bonfire.Sanitize(prefix + a.Key), value: formatValue(a.Value)})
return append(out, consoleAttr{key: consolekit.Sanitize(prefix + a.Key), value: formatValue(a.Value)})
}
func formatValue(v slog.Value) string {
@@ -273,7 +273,7 @@ func formatValue(v slog.Value) string {
default:
s = v.String()
}
s = bonfire.Sanitize(s)
s = consolekit.Sanitize(s)
if s == "" || strings.ContainsAny(s, " \t\"=") {
return strconv.Quote(s)
}