1# tui
2
3The `tui` package contains all terminal user interface components built with the [Bubble Tea](https://github.com/charmbracelet/bubbletea) framework. Each file implements a self-contained view or component following the Bubble Tea Model-View-Update (MVU) pattern.
4
5## Architecture
6
7The TUI layer is the interactive frontend of Matcha. Each view implements the `tea.Model` interface (`Init`, `Update`, `View`) and communicates with other views through typed messages. The main application (`main.go`) orchestrates navigation between views by swapping the active model.
8
9### Views
10
11| File | Description |
12|------|-------------|
13| `inbox.go` | Email inbox list with multi-account tab support. Handles pagination, keyboard navigation, and renders email items with sender, subject, and date. Supports different mailbox types (inbox, sent, trash, archive) and both multi-account and single-account modes. |
14| `email_view.go` | Full email display in a scrollable viewport. Shows headers (from, to, subject, date), rendered body content, attachment list, and S/MIME verification status. Manages inline image rendering through out-of-band stdout writes. |
15| `composer.go` | Email composition form with fields for To, CC, BCC, Subject, and Body. Features contact autocomplete, file attachment picker, signature insertion, account selection dropdown, and draft auto-saving. Supports reply mode with pre-filled headers and quoted text. |
16| `drafts.go` | Draft email list view. Displays saved drafts with subject, recipient, and timestamp. Allows opening drafts in the composer or deleting them. |
17| `folder_inbox.go` | Folder navigation sidebar with an email list. Displays IMAP folders in a left panel and the selected folder's emails in the main area. Handles folder selection and email loading per folder. |
18| `trash_archive.go` | Combined trash and archive view with tab-based switching between the two. Shares the inbox component structure but targets trash/archive mailboxes. |
19| `login.go` | Account login form supporting Gmail, iCloud, and custom IMAP/SMTP providers. Collects credentials, server settings, and optionally S/MIME certificate paths. Validates input before submission. |
20| `settings.go` | Settings panel for managing accounts (add/remove), configuring mailing lists, editing signatures, toggling image display, managing tips visibility, and setting up S/MIME certificates. |
21| `mailing_list.go` | Editor for creating and modifying mailing list groups (name + comma-separated email addresses). |
22| `choice.go` | Main menu / start screen. Presents account selection, navigation to inbox, compose, drafts, marketplace, sent, folders, trash/archive, and settings. |
23| `marketplace.go` | Plugin marketplace browser. Fetches the plugin registry from GitHub, displays a scrollable list with install status badges, and installs plugins on selection. Can run standalone (`matcha marketplace`) or from the main menu. |
24| `filepicker.go` | File browser for selecting email attachments. Navigates the filesystem with directory listing and file selection. |
25
26### Supporting Files
27
28| File | Description |
29|------|-------------|
30| `styles.go` | Global Lip Gloss style definitions used across all views (dialog boxes, help text, tips, headings, body text). Also defines the `Status` component for spinner-based loading messages. |
31| `theme.go` | `RebuildStyles` function that updates all package-level style variables when the active theme changes, ensuring consistent colors across the UI. |
32| `messages.go` | Shared message types for inter-component communication: `ViewEmailMsg`, `SendEmailMsg`, `Credentials`, `ChooseServiceMsg`, `EmailResultMsg`, `ClearStatusMsg`, `GoToMarketplaceMsg`, and the `MailboxKind` enum. |
33| `signature.go` | Textarea-based editor for composing and saving email signatures. |
34
35### Test Files
36
37| File | Description |
38|------|-------------|
39| `inbox_test.go` | Tests for inbox rendering and behavior. |
40| `email_view_test.go` | Tests for email view rendering. |
41| `composer_test.go` | Tests for email composition logic. |
42| `trash_archive_test.go` | Tests for trash/archive view behavior. |