view

package
v0.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 21 Imported by: 0

README

view

The view package handles rendering email content for terminal display. It converts HTML email bodies into styled terminal text with support for inline images, hyperlinks, and quoted reply formatting.

Architecture

This package bridges raw email content (HTML/Markdown) and terminal output. It:

  • Parses HTML email bodies using goquery and converts them to styled terminal text
  • Renders hyperlinks using OSC 8 escape sequences (with fallback for unsupported terminals)
  • Supports inline image rendering via multiple terminal graphics protocols:
    • Kitty Graphics Protocol (Kitty, Ghostty, WezTerm, Wayst, Konsole)
    • iTerm2 Image Protocol (iTerm2, Warp)
  • Detects quoted reply sections (> prefixed lines and On DATE, EMAIL wrote: patterns) and renders them in styled quote boxes
  • Manages image lifecycle: fetching remote images, resolving CID references, caching, uploading to terminal memory (Kitty IDs), and calculating terminal row placement
  • Converts Markdown to HTML via Goldmark before processing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImageProtocolSupported added in v0.18.0

func ImageProtocolSupported() bool

ImageProtocolSupported checks if any supported image protocol terminal is detected.

func RenderImageToStdout added in v0.21.1

func RenderImageToStdout(placement *ImagePlacement, screenRow int)

RenderImageToStdout writes an image directly to stdout at the given screen row using cursor positioning. This bypasses bubbletea's cell-based renderer which cannot handle graphics protocol escape sequences.

For Kitty-protocol terminals, images are uploaded once and then displayed by ID on subsequent calls, making scroll rendering nearly instant.

Types

type ImagePlacement added in v0.21.1

type ImagePlacement struct {
	Line     int    // Line number in the processed body text where the image starts
	Base64   string // Base64-encoded image data (PNG)
	Rows     int    // Number of terminal rows the image occupies
	Uploaded bool   // Whether the image has been uploaded to the terminal via Kitty ID
	ID       uint32 // Kitty image ID for display-by-reference
}

ImagePlacement holds the data needed to render an image at a specific line in the email body. Images are rendered directly to stdout (bypassing bubbletea's cell-based renderer which cannot handle graphics protocols).

func ProcessBody

func ProcessBody(rawBody string, h1Style, h2Style, bodyStyle lipgloss.Style, disableImages bool) (string, []ImagePlacement, error)

ProcessBody takes a raw email body, decodes it, and formats it as plain text with terminal hyperlinks.

func ProcessBodyWithInline added in v0.11.0

func ProcessBodyWithInline(rawBody string, inline []InlineImage, h1Style, h2Style, bodyStyle lipgloss.Style, disableImages bool) (string, []ImagePlacement, error)

ProcessBodyWithInline renders the body and resolves CID inline images when provided. Returns the rendered body text, image placements for out-of-band rendering, and any error.

type InlineImage added in v0.11.0

type InlineImage struct {
	CID    string
	Base64 string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL