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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user