settings_general.go

  1package tui
  2
  3import (
  4	"fmt"
  5	"strings"
  6
  7	tea "charm.land/bubbletea/v2"
  8	"github.com/floatpane/matcha/config"
  9)
 10
 11func (m *Settings) updateGeneral(msg tea.KeyPressMsg) (tea.Model, tea.Cmd) {
 12	switch msg.String() {
 13	case "up", "k":
 14		if m.generalCursor > 0 {
 15			m.generalCursor--
 16		}
 17	case "down", "j":
 18		if m.generalCursor < 4 {
 19			m.generalCursor++
 20		}
 21	case "enter", "space", "right", "l":
 22		switch m.generalCursor {
 23		case 0: // Image Display
 24			m.cfg.DisableImages = !m.cfg.DisableImages
 25			_ = config.SaveConfig(m.cfg)
 26		case 1: // Contextual Tips
 27			m.cfg.HideTips = !m.cfg.HideTips
 28			_ = config.SaveConfig(m.cfg)
 29		case 2: // Desktop Notifications
 30			m.cfg.DisableNotifications = !m.cfg.DisableNotifications
 31			_ = config.SaveConfig(m.cfg)
 32		case 3: // Date Format
 33			switch m.cfg.DateFormat {
 34			case config.DateFormatEU:
 35				m.cfg.DateFormat = config.DateFormatUS
 36			case config.DateFormatUS:
 37				m.cfg.DateFormat = config.DateFormatISO
 38			default: // or ISO
 39				m.cfg.DateFormat = config.DateFormatEU
 40			}
 41			_ = config.SaveConfig(m.cfg)
 42		case 4: // Edit Signature
 43			if msg.String() == "enter" || msg.String() == "right" || msg.String() == "l" {
 44				return m, func() tea.Msg { return GoToSignatureEditorMsg{} }
 45			}
 46		}
 47	}
 48	return m, nil
 49}
 50
 51func (m *Settings) viewGeneral() string {
 52	var b strings.Builder
 53
 54	b.WriteString(titleStyle.Render("General Settings") + "\n\n")
 55
 56	options := []struct {
 57		label string
 58		value string
 59		tip   string
 60	}{
 61		{"Disable Image Display", onOff(m.cfg.DisableImages), "Prevent images from loading automatically in emails."},
 62		{"Hide Contextual Tips", onOff(m.cfg.HideTips), "Hide helpful hints displayed at the bottom of the screen."},
 63		{"Disable Notifications", onOff(m.cfg.DisableNotifications), "Turn off desktop notifications for new mail."},
 64		{"Date Format", getDateFormatLabel(m.cfg.DateFormat), "Change how dates and times are displayed."},
 65		{"Signature", getSignatureStatus(), "Configure the signature appended to your outgoing emails."},
 66	}
 67
 68	for i, opt := range options {
 69		cursor := "  "
 70		style := accountItemStyle
 71		if m.generalCursor == i {
 72			cursor = "> "
 73			style = selectedAccountItemStyle
 74		}
 75
 76		text := fmt.Sprintf("%s: %s", opt.label, opt.value)
 77		if opt.label == "Signature" {
 78			text = fmt.Sprintf("Edit Signature (%s)", opt.value)
 79		}
 80
 81		b.WriteString(style.Render(cursor+text) + "\n")
 82	}
 83
 84	b.WriteString("\n\n")
 85
 86	if !m.cfg.HideTips && m.generalCursor < len(options) {
 87		b.WriteString(TipStyle.Render("Tip: " + options[m.generalCursor].tip))
 88	}
 89
 90	return b.String()
 91}
 92
 93func onOff(b bool) string {
 94	if b {
 95		return "ON"
 96	}
 97	return "OFF"
 98}
 99
100func getDateFormatLabel(f string) string {
101	if f == "" {
102		f = config.DateFormatEU
103	}
104	switch f {
105	case config.DateFormatUS:
106		return "US (MM/DD/YYYY hh:MM AM)"
107	case config.DateFormatISO:
108		return "ISO (YYYY-MM-DD HH:MM)"
109	default:
110		return "EU (DD/MM/YYYY HH:MM)"
111	}
112}
113
114func getSignatureStatus() string {
115	if config.HasSignature() {
116		return "configured"
117	}
118	return "not configured"
119}