-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecution_manager.go
50 lines (43 loc) · 994 Bytes
/
execution_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package prompt
import (
"github.com/aschey/bubbleprompt/executor"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
)
type ExecutorFinishedMsg tea.Model
type executionManager struct {
inner tea.Model
errorTextStyle lipgloss.Style
err error
}
func newExecutorManager(
inner tea.Model,
errorTextStyle lipgloss.Style,
err error,
) *executionManager {
return &executionManager{
inner: inner,
errorTextStyle: errorTextStyle,
err: err,
}
}
func (m executionManager) Init() tea.Cmd {
return m.inner.Init()
}
func (m executionManager) Update(msg tea.Msg) (executionManager, tea.Cmd) {
inner, cmd := m.inner.Update(msg)
m.inner = inner
if msg, ok := msg.(executor.ErrorMsg); ok {
m.err = error(msg)
return m, tea.Quit
} else {
return m, cmd
}
}
func (m executionManager) View() string {
if m.err != nil {
return m.errorTextStyle.Render(m.err.Error()) + "\n"
} else {
return m.inner.View()
}
}