diff --git a/main.go b/main.go index 33201d51f61a923765db9dcbc0976604801d8393..2aec244889062c0e591a44773faa6e3db55fc646 100644 --- a/main.go +++ b/main.go @@ -28,20 +28,18 @@ const ( ) type mainModel struct { - current tea.Model - previousModel tea.Model - cachedComposer *tui.Composer - config *config.Config - emails []fetcher.Email - emailsByAcct map[string][]fetcher.Email - inbox *tui.Inbox - width int - height int - err error + current tea.Model + previousModel tea.Model + config *config.Config + emails []fetcher.Email + emailsByAcct map[string][]fetcher.Email + inbox *tui.Inbox + width int + height int + err error } func newInitialModel(cfg *config.Config) *mainModel { - hasCache := config.HasEmailCache() initialModel := &mainModel{ emailsByAcct: make(map[string][]fetcher.Email), } @@ -49,7 +47,7 @@ func newInitialModel(cfg *config.Config) *mainModel { if cfg == nil || !cfg.HasAccounts() { initialModel.current = tui.NewLogin() } else { - initialModel.current = tui.NewChoice(hasCache) + initialModel.current = tui.NewChoice() initialModel.config = cfg } return initialModel @@ -81,7 +79,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case *tui.FilePicker: return m, func() tea.Msg { return tui.CancelFilePickerMsg{} } case *tui.Inbox, *tui.Login: - m.current = tui.NewChoice(m.cachedComposer != nil) + m.current = tui.NewChoice() return m, m.current.Init() } } @@ -90,12 +88,11 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.inbox != nil { m.current = m.inbox } else { - m.current = tui.NewChoice(m.cachedComposer != nil) + m.current = tui.NewChoice() } return m, nil case tui.DiscardDraftMsg: - m.cachedComposer = msg.ComposerState // Save draft to disk if msg.ComposerState != nil { draft := msg.ComposerState.ToDraft() @@ -105,17 +102,9 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } }() } - m.current = tui.NewChoice(true) + m.current = tui.NewChoice() return m, m.current.Init() - case tui.RestoreDraftMsg: - if m.cachedComposer != nil { - m.current = m.cachedComposer - m.cachedComposer.ResetConfirmation() - m.cachedComposer = nil - return m, m.current.Init() - } - case tui.Credentials: // Add new account or update existing account := config.Account{ @@ -157,7 +146,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Quit } - m.current = tui.NewChoice(m.cachedComposer != nil) + m.current = tui.NewChoice() return m, m.current.Init() case tui.GoToInboxMsg: @@ -324,7 +313,6 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, nil case tui.GoToSendMsg: - m.cachedComposer = nil if m.config != nil && len(m.config.Accounts) > 0 { firstAccount := m.config.GetFirstAccount() composer := tui.NewComposerWithAccounts(m.config.Accounts, firstAccount.ID, msg.To, msg.Subject, msg.Body) @@ -342,7 +330,6 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, m.current.Init() case tui.OpenDraftMsg: - m.cachedComposer = nil var accounts []config.Account if m.config != nil { accounts = m.config.Accounts @@ -377,7 +364,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, m.current.Init() case tui.GoToChoiceMenuMsg: - m.current = tui.NewChoice(m.cachedComposer != nil) + m.current = tui.NewChoice() return m, m.current.Init() case tui.DeleteAccountMsg: @@ -472,7 +459,6 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if composer, ok := m.current.(*tui.Composer); ok { draftID = composer.GetDraftID() } - m.cachedComposer = nil m.current = tui.NewStatus("Sending email...") // Get the account to send from @@ -505,7 +491,7 @@ func (m *mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Batch(m.current.Init(), sendEmail(account, msg)) case tui.EmailResultMsg: - m.current = tui.NewChoice(m.cachedComposer != nil) + m.current = tui.NewChoice() return m, m.current.Init() case tui.DeleteEmailMsg: diff --git a/matcha b/matcha index 01b45708c8ca43f0524d22ff729ef865d65b2f8e..4fbccad4a9b3bdeac26bd792de4305cae80135c0 100755 Binary files a/matcha and b/matcha differ diff --git a/tui/choice.go b/tui/choice.go index f2866dc0bffd10aa664b7465ae09c23196cfee67..a55adb29a0a97c380f545f9d3b3677e425e73699 100644 --- a/tui/choice.go +++ b/tui/choice.go @@ -13,31 +13,36 @@ import ( var ( docStyle = lipgloss.NewStyle().Margin(1, 2) titleStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#FFFDF5")).Background(lipgloss.Color("#25A065")).Padding(0, 1) + logoStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("42")) listHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("241")).PaddingBottom(1) itemStyle = lipgloss.NewStyle().PaddingLeft(2) selectedItemStyle = lipgloss.NewStyle().PaddingLeft(2).Foreground(lipgloss.Color("42")) ) +// ASCII logo for the start screen +const choiceLogo = ` + __ __ + ____ ___ ____ _/ /______/ /_ ____ _ + / __ '__ \/ __ '/ __/ ___/ __ \/ __ '/ + / / / / / / /_/ / /_/ /__/ / / / /_/ / +/_/ /_/ /_/\__,_/\__/\___/_/ /_/\__,_/ +` + type Choice struct { cursor int choices []string - hasCachedDraft bool hasSavedDrafts bool } -func NewChoice(hasCachedDraft bool) Choice { +func NewChoice() Choice { hasSavedDrafts := config.HasDrafts() choices := []string{"View Inbox", "Compose Email"} if hasSavedDrafts { choices = append(choices, "Drafts") } choices = append(choices, "Settings") - if hasCachedDraft { - choices = append(choices, "Restore Draft") - } return Choice{ choices: choices, - hasCachedDraft: hasCachedDraft, hasSavedDrafts: hasSavedDrafts, } } @@ -69,8 +74,6 @@ func (m Choice) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, func() tea.Msg { return GoToDraftsMsg{} } case "Settings": return m, func() tea.Msg { return GoToSettingsMsg{} } - case "Restore Draft": - return m, func() tea.Msg { return RestoreDraftMsg{} } } } } @@ -80,7 +83,8 @@ func (m Choice) Update(msg tea.Msg) (tea.Model, tea.Cmd) { func (m Choice) View() string { var b strings.Builder - b.WriteString(titleStyle.Render("Matcha") + "\n\n") + b.WriteString(logoStyle.Render(choiceLogo)) + b.WriteString("\n") b.WriteString(listHeader.Render("What would you like to do?")) b.WriteString("\n\n") diff --git a/tui/messages.go b/tui/messages.go index 8a2c94dbadaa885d0a81643db328e73a3d6dd20e..a659a572a38e00e3d72af5ab89fe7cd351655be6 100644 --- a/tui/messages.go +++ b/tui/messages.go @@ -127,9 +127,6 @@ type DiscardDraftMsg struct { ComposerState *Composer } -// RestoreDraftMsg signals that the cached draft should be restored. -type RestoreDraftMsg struct{} - type EmailBodyFetchedMsg struct { UID uint32 Body string