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:
@@ -60,6 +60,14 @@ func (m *Model) Init() tea.Cmd {
|
||||
}
|
||||
|
||||
func (m *Model) handleGlobalInput(msg tea.KeyMsg) tea.Cmd {
|
||||
switch msg.String() {
|
||||
case "esc":
|
||||
if len(m.errs) > 0 {
|
||||
m.errs = m.errs[1:]
|
||||
return shared.KeyHandled(msg)
|
||||
}
|
||||
}
|
||||
|
||||
view, cmd := m.views[m.activeView].Update(msg)
|
||||
m.views[m.activeView] = view
|
||||
if cmd != nil {
|
||||
@@ -108,10 +116,16 @@ func (m *Model) View() string {
|
||||
errBanners := make([]string, len(m.errs))
|
||||
for idx, err := range m.errs {
|
||||
errBanners[idx] = tuiutil.ErrorBanner(err, m.width)
|
||||
fixedUIHeight += tuiutil.Height(errBanners[idx])
|
||||
}
|
||||
var errors string
|
||||
if len(errBanners) > 0 {
|
||||
errors = lipgloss.JoinVertical(lipgloss.Left, errBanners...)
|
||||
} else {
|
||||
errors = ""
|
||||
}
|
||||
fixedUIHeight += tuiutil.Height(errors)
|
||||
|
||||
content := m.views[m.activeView].Content(m.width, m.height-fixedUIHeight)
|
||||
content := m.views[m.activeView].Content(m.width, m.height-fixedUIHeight, errors)
|
||||
|
||||
sections := make([]string, 0, 4)
|
||||
if header != "" {
|
||||
@@ -123,9 +137,6 @@ func (m *Model) View() string {
|
||||
if footer != "" {
|
||||
sections = append(sections, footer)
|
||||
}
|
||||
for _, errBanner := range errBanners {
|
||||
sections = append(sections, errBanner)
|
||||
}
|
||||
return lipgloss.JoinVertical(lipgloss.Left, sections...)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user