fix(bonfire): reroute only the owning console's lines to a live view

- the registered view keeps the console that started it; Println, Printf
  and status lines go above it only from that console, other consoles
  write to their own writers (bonfire.PrintAbove still reaches any view)
- runLive claims the single live slot by check and set under liveMu and
  reports when it could not, so the widget prints plain lines
- unregister, finish and wait run deferred, so a panic in work leaves no
  registration behind and still propagates (WR-02)
This commit is contained in:
Jakub Zych
2026-10-22 02:10:48 +02:00
parent b077dc3598
commit 86e4e270d3
6 changed files with 200 additions and 56 deletions

View File

@@ -26,13 +26,16 @@ func (c *console) Spinner(message string, fn func() error) error {
if c.globals.Quiet {
return fn()
}
if !c.live() {
c.Printf("[...] %s\n", message)
return fn()
if c.live() {
started, err := runLive(context.Background(), c.out, c, newSpinnerModel(c.palette, message), func(func(tea.Msg)) error {
return fn()
})
if started {
return err
}
}
return runLive(context.Background(), c.out, c, newSpinnerModel(c.palette, message), func(func(tea.Msg)) error {
return fn()
})
c.Printf("[...] %s\n", message)
return fn()
}
func (c *console) Progress(total int, fn func(Progress) error) error {
@@ -45,12 +48,15 @@ func (c *console) Progress(total int, fn func(Progress) error) error {
if c.globals.Quiet {
return fn(&quietProgress{c: c})
}
if !c.live() {
return fn(&progressBar{c: c, total: total, lastPct: -1})
if c.live() {
started, err := runLive(context.Background(), c.out, c, newProgressModel(c.palette, total), func(send func(tea.Msg)) error {
return fn(&liveProgress{send: send, total: total})
})
if started {
return err
}
}
return runLive(context.Background(), c.out, c, newProgressModel(c.palette, total), func(send func(tea.Msg)) error {
return fn(&liveProgress{send: send, total: total})
})
return fn(&progressBar{c: c, total: total, lastPct: -1})
}
// progressBar prints a line at every tenth of the work when widgets do not