wip: fix errorview margin

Ayman Bagabas created

Change summary

ui/common/common.go             | 2 ++
ui/pages/selection/selection.go | 3 ++-
ui/ui.go                        | 6 +++---
3 files changed, 7 insertions(+), 4 deletions(-)

Detailed changes

ui/common/common.go 🔗

@@ -5,6 +5,7 @@ import (
 	"github.com/charmbracelet/soft-serve/ui/styles"
 )
 
+// Common is a struct all components should embed.
 type Common struct {
 	Styles *styles.Styles
 	Keymap *keymap.KeyMap
@@ -12,6 +13,7 @@ type Common struct {
 	Height int
 }
 
+// SetSize sets the width and height of the common struct.
 func (c *Common) SetSize(width, height int) {
 	c.Width = width
 	c.Height = height

ui/pages/selection/selection.go 🔗

@@ -114,6 +114,7 @@ func (s *Selection) Init() tea.Cmd {
 	session := s.s.Session()
 	environ := session.Environ()
 	termExists := false
+	// Add TERM using pty.Term if it's not already set.
 	for _, env := range environ {
 		if strings.HasPrefix(env, "TERM=") {
 			termExists = true
@@ -188,7 +189,7 @@ func (s *Selection) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		}
 	case selector.ActiveMsg:
 		cmds = append(cmds, s.changeActive(msg))
-		// reset readme position
+		// reset readme position when active item change
 		s.readme.GotoTop()
 	case tea.KeyMsg:
 		switch {

ui/ui.go 🔗

@@ -142,11 +142,11 @@ func (ui *UI) View() string {
 	s := strings.Builder{}
 	switch ui.state {
 	case startState:
-		return "\n Loading..."
+		s.WriteString("Loading...")
 	case errorState:
 		err := ui.common.Styles.ErrorTitle.Render("Bummer")
 		err += ui.common.Styles.ErrorBody.Render(ui.error.Error())
-		return err
+		s.WriteString(err)
 	case loadedState:
 		s.WriteString(lipgloss.JoinVertical(
 			lipgloss.Bottom,
@@ -155,7 +155,7 @@ func (ui *UI) View() string {
 			ui.footer.View(),
 		))
 	default:
-		return "\n Unknown state :/ this is a bug!"
+		s.WriteString("Unknown state :/ this is a bug!")
 	}
 	return ui.common.Styles.App.Render(s.String())
 }