mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
feat: tea.Wait (#722)
* feat: tea.Wait wait for the underlying context to finish. extract from #352 * fix: wait til the end of shutdown Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com> --------- Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
29254a08f1
commit
9cc3861bab
8
tea.go
8
tea.go
@@ -99,6 +99,7 @@ type Program struct {
|
|||||||
|
|
||||||
msgs chan Msg
|
msgs chan Msg
|
||||||
errs chan error
|
errs chan error
|
||||||
|
finished chan struct{}
|
||||||
|
|
||||||
// where to send output, this will usually be os.Stdout.
|
// where to send output, this will usually be os.Stdout.
|
||||||
output *termenv.Output
|
output *termenv.Output
|
||||||
@@ -366,6 +367,7 @@ func (p *Program) Run() (Model, error) {
|
|||||||
handlers := handlers{}
|
handlers := handlers{}
|
||||||
cmds := make(chan Cmd)
|
cmds := make(chan Cmd)
|
||||||
p.errs = make(chan error)
|
p.errs = make(chan error)
|
||||||
|
p.finished = make(chan struct{}, 1)
|
||||||
|
|
||||||
defer p.cancel()
|
defer p.cancel()
|
||||||
|
|
||||||
@@ -555,6 +557,11 @@ func (p *Program) Kill() {
|
|||||||
p.cancel()
|
p.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wait waits/blocks until the underlying Program finished shutting down.
|
||||||
|
func (p *Program) Wait() {
|
||||||
|
<-p.finished
|
||||||
|
}
|
||||||
|
|
||||||
// shutdown performs operations to free up resources and restore the terminal
|
// shutdown performs operations to free up resources and restore the terminal
|
||||||
// to its original state.
|
// to its original state.
|
||||||
func (p *Program) shutdown(kill bool) {
|
func (p *Program) shutdown(kill bool) {
|
||||||
@@ -570,6 +577,7 @@ func (p *Program) shutdown(kill bool) {
|
|||||||
if p.restoreOutput != nil {
|
if p.restoreOutput != nil {
|
||||||
_ = p.restoreOutput()
|
_ = p.restoreOutput()
|
||||||
}
|
}
|
||||||
|
p.finished <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReleaseTerminal restores the original terminal state and cancels the input
|
// ReleaseTerminal restores the original terminal state and cancels the input
|
||||||
|
|||||||
Reference in New Issue
Block a user