Private
Public Access
1
0

Update tui error handling

- Allow each view to position error banners where they choose
- Add global 'esc' key handler to dismiss errors
This commit is contained in:
2024-12-12 07:09:58 +00:00
parent d9d1b02ef3
commit 02228d65ac
6 changed files with 40 additions and 12 deletions

View File

@@ -245,7 +245,7 @@ func (m *Model) conversationMessagesView() string {
return sb.String()
}
func (m *Model) Content(width, height int) string {
func (m *Model) Content(width, height int, errors string) string {
// calculate clamped input height to accomodate input text
// minimum 4 lines, maximum half of content area
inputHeight := max(4, min(height/2, m.input.LineCount()))
@@ -255,7 +255,15 @@ func (m *Model) Content(width, height int) string {
// remaining height towards content
m.content.Width, m.content.Height = width, height-tuiutil.Height(input)
content := m.content.View()
return lipgloss.JoinVertical(lipgloss.Left, content, input)
var sections []string
if errors != "" {
sections = []string{content, errors, input}
} else {
sections = []string{content, input}
}
return lipgloss.JoinVertical(lipgloss.Left, sections...)
}
func (m *Model) Header(width int) string {