mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
feat(ui): implement StepErrorEvent handling in AppModel
Render step errors above the BT region via tea.Println() using the existing RenderErrorMessage() renderers, mirroring the StepCompleteEvent pattern. Reset stream state and transition back to stateInput on error.
This commit is contained in:
+24
-3
@@ -354,10 +354,12 @@ func (m *AppModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.canceling = false
|
||||
|
||||
case app.StepErrorEvent:
|
||||
// Render the error inline in the stream area, then return to input.
|
||||
// Render the error above the BT region via tea.Println, reset stream, return to input.
|
||||
if msg.Err != nil {
|
||||
cmds = append(cmds, m.printErrorResponse(msg))
|
||||
}
|
||||
if m.stream != nil {
|
||||
_, cmd := m.stream.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
m.stream.Reset()
|
||||
}
|
||||
m.state = stateInput
|
||||
m.canceling = false
|
||||
@@ -484,6 +486,25 @@ func (m *AppModel) printCompletedResponse(evt app.StepCompleteEvent) tea.Cmd {
|
||||
return tea.Println(rendered)
|
||||
}
|
||||
|
||||
// printErrorResponse builds a tea.Cmd that emits a styled error message above
|
||||
// the BT-managed region using tea.Println. This is used on StepErrorEvent.
|
||||
func (m *AppModel) printErrorResponse(evt app.StepErrorEvent) tea.Cmd {
|
||||
if evt.Err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var rendered string
|
||||
if m.compactMode {
|
||||
msg := m.compactRdr.RenderErrorMessage(evt.Err.Error(), time.Now())
|
||||
rendered = msg.Content
|
||||
} else {
|
||||
msg := m.renderer.RenderErrorMessage(evt.Err.Error(), time.Now())
|
||||
rendered = msg.Content
|
||||
}
|
||||
|
||||
return tea.Println(rendered)
|
||||
}
|
||||
|
||||
// distributeHeight recalculates child component heights after a window resize.
|
||||
// The input region has a fixed height; the stream region gets the remainder.
|
||||
func (m *AppModel) distributeHeight() {
|
||||
|
||||
Reference in New Issue
Block a user