feat: settings menu (#8)

drew created

Change summary

main.go         |  7 ++++++-
tui/choice.go   | 11 +++++++----
tui/composer.go |  2 +-
tui/login.go    |  6 +++---
tui/messages.go |  5 ++++-
5 files changed, 21 insertions(+), 10 deletions(-)

Detailed changes

main.go 🔗

@@ -66,7 +66,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 			case *tui.EmailView:
 				m.current = m.inbox // Go back to the cached inbox
 				return m, nil
-			case *tui.Inbox, *tui.Composer:
+			case *tui.Inbox, *tui.Composer, *tui.Login:
 				m.current = tui.NewChoice() // Go back to the main menu
 				return m, m.current.Init()
 			}
@@ -106,6 +106,11 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 		m.current = tui.NewComposer(m.config.Email)
 		m.current, _ = m.current.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height})
 		cmds = append(cmds, m.current.Init())
+	
+	case tui.GoToSettingsMsg:
+		m.current = tui.NewLogin()
+		m.current, _ = m.current.Update(tea.WindowSizeMsg{Width: m.width, Height: m.height})
+		cmds = append(cmds, m.current.Init())
 
 	case tui.ViewEmailMsg:
 		emailView := tui.NewEmailView(m.emails[msg.Index], m.width, m.height)

tui/choice.go 🔗

@@ -51,14 +51,17 @@ func (m Choice) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 				m.cursor--
 			}
 		case "down", "j":
-			if m.cursor < 1 { // We have two choices
+			if m.cursor < 2 { // We have three choices now
 				m.cursor++
 			}
 		case "enter":
-			if m.cursor == 0 {
+			switch m.cursor {
+			case 0:
 				return m, func() tea.Msg { return GoToInboxMsg{} }
-			} else if m.cursor == 1 {
+			case 1:
 				return m, func() tea.Msg { return GoToSendMsg{} }
+			case 2:
+				return m, func() tea.Msg { return GoToSettingsMsg{} }
 			}
 		}
 	}
@@ -76,7 +79,7 @@ func (m Choice) View() string {
 	b.WriteString("\n\n")
 
 	// Choices
-	choices := []string{"View Inbox", "Compose Email"}
+	choices := []string{"View Inbox", "Compose Email", "Settings"}
 	for i, choice := range choices {
 		if m.cursor == i {
 			b.WriteString(selectedItemStyle.Render(fmt.Sprintf("> %s", choice)))

tui/composer.go 🔗

@@ -145,6 +145,6 @@ func (m *Composer) View() string {
 		m.subjectInput.View(),
 		m.bodyInput.View(),
 		*button,
-		helpStyle.Render("tab: next field • esc: back to menu"),
+		helpStyle.Render("tab: next field • esc: back to menu • enter: send"),
 	)
 }

tui/login.go 🔗

@@ -107,12 +107,12 @@ func (m Login) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 // View renders the login form.
 func (m Login) View() string {
 	return lipgloss.JoinVertical(lipgloss.Left,
-		titleStyle.Render("Welcome to Email CLI"),
-		"Please enter your credentials.",
+		titleStyle.Render("Account Settings"),
+		"Update your credentials.",
 		m.inputs[0].View(),
 		m.inputs[1].View(),
 		m.inputs[2].View(),
 		m.inputs[3].View(),
-		helpStyle.Render("\nenter: submit • tab: next field • esc: quit"),
+		helpStyle.Render("\nenter: save • tab: next field • esc: back to menu"),
 	)
 }

tui/messages.go 🔗

@@ -48,4 +48,7 @@ type FetchErr error
 type GoToInboxMsg struct{}
 
 // A message to navigate to the composer view.
-type GoToSendMsg struct{}
+type GoToSendMsg struct{}
+
+// A message to navigate to the settings view.
+type GoToSettingsMsg struct{}