diff --git a/tui/email_view.go b/tui/email_view.go index 6ba73fc..3a519eb 100644 --- a/tui/email_view.go +++ b/tui/email_view.go @@ -3,6 +3,7 @@ package tui import ( "encoding/base64" "fmt" + "os" "strings" "github.com/charmbracelet/bubbles/viewport" @@ -12,6 +13,13 @@ import ( "github.com/floatpane/matcha/view" ) +// clearKittyGraphics sends the Kitty graphics protocol delete command directly to stdout +func clearKittyGraphics() { + // Delete all images: a=d (action=delete), d=A (delete all) + os.Stdout.WriteString("\x1b_Ga=d,d=A\x1b\\") + os.Stdout.Sync() +} + var ( emailHeaderStyle = lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).BorderBottom(true).Padding(0, 1) attachmentBoxStyle = lipgloss.NewStyle().Border(lipgloss.NormalBorder(), false, false, false, true).PaddingLeft(2).MarginTop(1) @@ -74,7 +82,8 @@ func (m *EmailView) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.focusOnAttachments = false return m, nil } - m.viewport.SetContent("\x1b_Ga=d\x1b\\") + // Clear Kitty graphics before returning to mailbox + clearKittyGraphics() return m, func() tea.Msg { return BackToMailboxMsg{Mailbox: m.mailbox} } } @@ -110,16 +119,22 @@ func (m *EmailView) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } else { switch msg.String() { case "r": + // Clear Kitty graphics before opening composer + clearKittyGraphics() return m, func() tea.Msg { return ReplyToEmailMsg{Email: m.email} } case "d": accountID := m.accountID uid := m.email.UID + // Clear Kitty graphics before transitioning + clearKittyGraphics() return m, func() tea.Msg { return DeleteEmailMsg{UID: uid, AccountID: accountID, Mailbox: m.mailbox} } case "a": accountID := m.accountID uid := m.email.UID + // Clear Kitty graphics before transitioning + clearKittyGraphics() return m, func() tea.Msg { return ArchiveEmailMsg{UID: uid, AccountID: accountID, Mailbox: m.mailbox} }