From 5aca6d0d0e257098bec2b953225ea968022539d7 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 26 Apr 2022 17:38:25 -0400 Subject: [PATCH] feat: render error in app style --- ui/styles/styles.go | 3 +-- ui/ui.go | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ui/styles/styles.go b/ui/styles/styles.go index fbb0ba4384a11dabbed0def63aa50271c0754832..667a49705f9380a5b2dcd4367e0b9893e938cee7 100644 --- a/ui/styles/styles.go +++ b/ui/styles/styles.go @@ -237,8 +237,7 @@ func DefaultStyles() *Styles { s.ErrorBody = lipgloss.NewStyle(). Foreground(lipgloss.Color("252")). - MarginLeft(2). - Width(52) // for now + MarginLeft(2) s.AboutNoReadme = lipgloss.NewStyle(). MarginTop(1). diff --git a/ui/ui.go b/ui/ui.go index 1c298e18f012346b3c9f1c77bc0de968af9dfdd2..397996a6c724f27af2467f12737b5675ba140c4b 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -64,7 +64,12 @@ func (ui *UI) getMargins() (wm, hm int) { // ShortHelp implements help.KeyMap. func (ui *UI) ShortHelp() []key.Binding { b := make([]key.Binding, 0) - b = append(b, ui.pages[ui.activePage].ShortHelp()...) + switch ui.state { + case errorState: + b = append(b, ui.common.KeyMap.Back) + case loadedState: + b = append(b, ui.pages[ui.activePage].ShortHelp()...) + } b = append(b, ui.common.KeyMap.Quit) return b } @@ -72,7 +77,12 @@ func (ui *UI) ShortHelp() []key.Binding { // FullHelp implements help.KeyMap. func (ui *UI) FullHelp() [][]key.Binding { b := make([][]key.Binding, 0) - b = append(b, ui.pages[ui.activePage].FullHelp()...) + switch ui.state { + case errorState: + b = append(b, []key.Binding{ui.common.KeyMap.Back}) + case loadedState: + b = append(b, ui.pages[ui.activePage].FullHelp()...) + } b = append(b, []key.Binding{ui.common.KeyMap.Quit}) return b } @@ -168,7 +178,20 @@ func (ui *UI) View() string { case errorState: err := ui.common.Styles.ErrorTitle.Render("Bummer") err += ui.common.Styles.ErrorBody.Render(ui.error.Error()) - s.WriteString(err) + view := ui.common.Styles.ErrorBody.Copy(). + Width(ui.common.Width - + ui.common.Styles.App.GetHorizontalFrameSize() - + ui.common.Styles.ErrorBody.GetHorizontalFrameSize()). + Height(ui.common.Height - + ui.common.Styles.App.GetVerticalFrameSize() - + ui.common.Styles.Header.GetVerticalFrameSize() - 2). + Render(err) + s.WriteString(lipgloss.JoinVertical( + lipgloss.Bottom, + ui.header.View(), + view, + ui.footer.View(), + )) case loadedState: s.WriteString(lipgloss.JoinVertical( lipgloss.Bottom,