MayFly LogoMayFly
Reference

Terminal UI (TUI) Engine

Architecture of MayFly's zero-dependency double-buffered 2D terminal interface and ANSI streaming parser.

MayFly features a complete, standalone Terminal User Interface (TUI) built 100% from scratch using only the Go standard library (os, syscall, bytes, unicode/utf8, io). It requires no third-party frameworks like Bubble Tea or tview.


TUI Architecture

┌─────────────────────────────────────────────────────────────┐
│                       os.Stdin                              │
└──────────────────────────────┬──────────────────────────────┘
                               │ Raw Byte Stream

┌─────────────────────────────────────────────────────────────┐
│            Streaming ANSI Parser (parser.go)                │
│   • Decodes Escape sequences (\x1b[A, \x1b[B, etc.)         │
│   • Assembles multi-byte UTF-8 runes                        │
│   • Dispatches typed KeyEvents (Up, Down, Enter, Esc)       │
└──────────────────────────────┬──────────────────────────────┘
                               │ Event Loop

┌─────────────────────────────────────────────────────────────┐
│                 View Router & State Machine                 │
│   • Card Grid View (Project selection)                      │
│   • Project Secrets Detail View                             │
│   • Input Modal & Confirmation Dialogs                      │
└──────────────────────────────┬──────────────────────────────┘
                               │ Draw() Frame

┌─────────────────────────────────────────────────────────────┐
│            Double-Buffered 2D Canvas (terminal.go)          │
│   • Front buffer & Back buffer comparison                   │
│   • Differential diff rendering to minimize flicker         │
│   • East Asian & Emoji cell width calculations              │
└──────────────────────────────┬──────────────────────────────┘
                               │ Flush()

┌─────────────────────────────────────────────────────────────┐
│              os.Stdout (ANSI SGR Escape Codes)              │
└─────────────────────────────────────────────────────────────┘

Core Components

1. Low-Level Terminal Discipline (raw_*.go)

Direct OS system calls place the terminal into raw non-canonical mode:

  • Linux/macOS: Direct syscall.SYS_IOCTL manipulating termios flags (TCGETS/TCSETS). Disables ECHO, ICANON, and signal processing.
  • Windows: Windows Console API (GetConsoleMode, SetConsoleMode) enabling ENABLE_VIRTUAL_TERMINAL_PROCESSING.

2. Double-Buffered 2D Canvas (terminal.go)

  • Maintains a 2D matrix of terminal cells containing character runes, foreground colors, background colors, and styling attributes (Bold, Dim, Reverse, Underline).
  • Renders frames to an in-memory bytes.Buffer before writing to os.Stdout in a single atomic flush, completely preventing screen tearing and flickering.

3. Streaming ANSI Parser (parser.go)

A finite-state machine that parses incoming bytes from os.Stdin:

  • Distinguishes between standalone Esc keys and escape sequence prefixes (\x1b[).
  • Decodes arrow keys (, , , ), function keys, PageUp/PageDown, Home/End, Tab, Shift-Tab, and Enter.
  • Assembles multi-byte UTF-8 runes on the fly.

4. ANSI OSC 52 System Clipboard (clipboard.go)

  • Copies secret values to the operating system clipboard by emitting standard ANSI OSC 52 escape sequences (\x1b]52;c;<base64>\x07) to standard output.
  • Supported natively in modern terminal emulators (iTerm2, Alacritty, Ghostty, Kitty, Windows Terminal, VS Code Terminal) with zero external binaries required.

Keyboard Shortcuts & Navigation

KeyGlobal ActionSecrets View Action
/ / / Navigate project cards gridNavigate secrets list
EnterOpen selected projectEdit secret value / Open detail
NInitialize new project directoryAdd new secret to current project
CCopy project pathCopy secret value to OS clipboard
VReveal / Mask secret value (••••••)
DDelete project registrationDelete selected secret
SRun plaintext credential scannerRun scanner on current project
AView cryptographic audit logView audit log
BExport encrypted vault backupExport project backup
Esc / QExit TUIBack to Project Cards Grid

Launch Modes

# Opens the full multi-project interactive dashboard from any folder
mf
# or
mayfly
# Opens directly into the secrets list for the current repository
mf c
# or
mf current

Next Steps