frog

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 4 Imported by: 0

README

Frog

Frog is the core TUI framework of the Pondworks ecosystem. It provides the runtime loop, renderer, input decoding, validation, and layout/style primitives for terminal apps in Go.

Installation

go get github.com/pondworks-lib/frog@latest

Quick Start

package main

import (
	"fmt"

	"github.com/pondworks-lib/frog"
)

type helloModel struct {
	count int
}

func (m helloModel) Init() frog.Cmd { return nil }

func (m helloModel) Update(msg frog.Msg) (frog.Model, frog.Cmd) {
	switch msg := msg.(type) {
	case frog.KeyMsg:
		if msg.String == "q" {
			return m, frog.Quit()
		}
		m.count++
	}
	return m, nil
}

func (m helloModel) View() string {
	return fmt.Sprintf("Hello Frog!\n\nKeys pressed: %d\n\nPress 'q' to quit.", m.count)
}

func main() {
	if err := frog.Run(helloModel{}); err != nil {
		panic(err)
	}
}

Features

  • MUV architecture: Model, Update, View.
  • Standard messages: KeyMsg, TickMsg, QuitMsg, ResizeMsg, MouseMsg, PasteMsg.
  • Commands: Cmd, Tick, Quit, Nil.
  • Renderer: ANSI renderer with diff mode and safe full repaint fallback on wrapped frames.
  • Input: raw mode, UTF-8 decoding, escape sequences, mouse, bracketed paste.
  • Styling: ANSI16, ANSI256, TrueColor, chained Style.
  • Layout: Center, PlaceBlock, Align*.
  • Sessions: Run, RunContext, NewApp, NewAppWithContext.
  • Runtime options: alt screen, mouse, bracketed paste, custom renderer, logger, non-interactive mode.
  • Validation: InspectModel, ValidateModel, structured FROG... issue codes.
  • Runtime errors: structured FROG2.. errors from the session loop.

Examples

Examples live in example/0.0.9. The set includes basics, input demos, rendering demos, app-style demos, and errors/ for validator testing.

Status

  • Frog is in pre-release stage (v0.0.9).
  • The goal of v0.0.9 is to make the current surface smaller, clearer, and much closer to the v0.1.0 freeze.

Toward v0.1.0

  • Stabilize the core runtime, renderer, input, validation and layout/style helpers.
  • Freeze the public API for frog at v0.1.0.
  • Build higher-level packages on top of the frozen core:
    • lily: widgets such as list, table, text input, form, progress.
    • ripple: event bus / reactive orchestration on top of Frog.
    • future packages only after the base API has stopped moving.

Notes

pad and splash were merged into Frog starting in v0.0.3. For now, layout and styling remain in this repository until the base API is frozen.

Documentation

Index

Constants

View Source
const (
	KeyUnknown   = core.KeyUnknown
	KeyRune      = core.KeyRune
	KeyEnter     = core.KeyEnter
	KeyBackspace = core.KeyBackspace
	KeyEsc       = core.KeyEsc
	KeyCtrlC     = core.KeyCtrlC
	KeyUp        = core.KeyUp
	KeyDown      = core.KeyDown
	KeyLeft      = core.KeyLeft
	KeyRight     = core.KeyRight
	KeyTab       = core.KeyTab
	KeySpace     = core.KeySpace
	KeyDelete    = core.KeyDelete
	KeyHome      = core.KeyHome
	KeyEnd       = core.KeyEnd
	KeyPgUp      = core.KeyPgUp
	KeyPgDn      = core.KeyPgDn
	KeyQ         = core.KeyQ
)

Key constants

View Source
const (
	MouseUnknown   = core.MouseUnknown
	MouseLeft      = core.MouseLeft
	MouseMiddle    = core.MouseMiddle
	MouseRight     = core.MouseRight
	MouseWheelUp   = core.MouseWheelUp
	MouseWheelDown = core.MouseWheelDown
)

Mouse constants

View Source
const (
	ErrNilModel       = core.ErrNilModel
	ErrNilRenderer    = core.ErrNilRenderer
	ErrRawMode        = core.ErrRawMode
	ErrInitFailed     = core.ErrInitFailed
	ErrViewFailed     = core.ErrViewFailed
	ErrUpdateFailed   = core.ErrUpdateFailed
	ErrCommandFailed  = core.ErrCommandFailed
	ErrNilUpdateModel = core.ErrNilUpdateModel
)

Runtime error codes

View Source
const (
	ValidationNilModel           = validate.CodeNilModel
	ValidationMissingView        = validate.CodeMissingView
	ValidationEmptyView          = validate.CodeEmptyView
	ValidationViewNotString      = validate.CodeViewNotString
	ValidationViewHasBadRunes    = validate.CodeViewHasBadRunes
	ValidationViewPanic          = validate.CodeViewPanic
	ValidationMissingUpdate      = validate.CodeMissingUpdate
	ValidationBadUpdateSignature = validate.CodeBadUpdateSignature
	ValidationMissingInit        = validate.CodeMissingInit
	ValidationBadInitSignature   = validate.CodeBadInitSignature
	ValidationUpdateNilModel     = validate.CodeUpdateNilModel
	ValidationViewVeryLarge      = validate.CodeViewVeryLarge
	ValidationViewSuspicious     = validate.CodeViewSuspicious
	ValidationNonExportedType    = validate.CodeNonExportedType
	ValidationSlowView           = validate.CodeSlowView
	ValidationSlowInit           = validate.CodeSlowInit
	ValidationHasNoMethods       = validate.CodeHasNoMethods
	ValidationUpdateNotMethod    = validate.CodeUpdateNotMethod
	ValidationViewNotMethod      = validate.CodeViewNotMethod
	ValidationReceiverMismatch   = validate.CodeReceiverMismatch
	ValidationViewControlCodes   = validate.CodeViewControlCodes
)

Validation issue codes

View Source
const (
	MousePress   = core.MousePress
	MouseRelease = core.MouseRelease
	MouseDrag    = core.MouseDrag
	MouseWheel   = core.MouseWheel
)
View Source
const (
	ColorAuto      = core.ColorAuto
	ColorNone      = core.ColorNone
	ColorANSI16    = core.ColorANSI16
	ColorANSI256   = core.ColorANSI256
	ColorTrueColor = core.ColorTrueColor
)

Color profile constants

View Source
const (
	AlignLeft   = core.AlignLeft
	AlignCenter = core.AlignCenter
	AlignRight  = core.AlignRight
	AlignTop    = core.AlignTop
	AlignMiddle = core.AlignMiddle
	AlignBottom = core.AlignBottom
)

Layout helpers.

Variables

View Source
var (
	ColorBlack         = core.ColorBlack
	ColorRed           = core.ColorRed
	ColorGreen         = core.ColorGreen
	ColorYellow        = core.ColorYellow
	ColorBlue          = core.ColorBlue
	ColorMagenta       = core.ColorMagenta
	ColorCyan          = core.ColorCyan
	ColorWhite         = core.ColorWhite
	ColorBrightBlack   = core.ColorBrightBlack
	ColorBrightRed     = core.ColorBrightRed
	ColorBrightGreen   = core.ColorBrightGreen
	ColorBrightYellow  = core.ColorBrightYellow
	ColorBrightBlue    = core.ColorBrightBlue
	ColorBrightMagenta = core.ColorBrightMagenta
	ColorBrightCyan    = core.ColorBrightCyan
	ColorBrightWhite   = core.ColorBrightWhite
)

Named colors (16-color)

View Source
var (
	NewStyle  = core.NewStyle
	ANSI256   = core.ANSI256
	RGB       = core.RGB
	Colorize  = core.Colorize
	StripANSI = core.StripANSI

	InspectModel  = validate.InspectModel
	ValidateModel = validate.ValidateModel
)

Style functions.

View Source
var (
	Tick               = core.Tick
	Quit               = core.Quit
	Nil                = core.Nil
	WithRenderer       = core.WithRenderer
	WithAltScreen      = core.WithAltScreen
	WithMsgBuffer      = core.WithMsgBuffer
	WithOut            = core.WithOut
	WithIn             = core.WithIn
	WithResizeInterval = core.WithResizeInterval
	WithNonInteractive = core.WithNonInteractive
	WithLogger         = core.WithLogger
	WithMouse          = core.WithMouse
	WithBracketedPaste = core.WithBracketedPaste
)

Session options

View Source
var (
	WithDiff         = core.WithDiff
	WithColorProfile = core.WithColorProfile
)
View Source
var (
	Center     = core.Center
	PlaceBlock = core.PlaceBlock
)

Functions

func NewRenderer added in v0.0.3

func NewRenderer(out io.Writer, opts ...RendererOption) core.Renderer

Renderer helpers.

func NewThrottledRenderer added in v0.0.9

func NewThrottledRenderer(out io.Writer, fps int, opts ...core.RendererOption) core.Renderer

FPS-throttled renderer.

func RenderKeyHelp added in v0.0.9

func RenderKeyHelp(km *core.KeyMap, width, height int) string

Help overlay.

func Run

func Run(m Model, opts ...Option) error

func RunContext added in v0.0.4

func RunContext(ctx context.Context, m Model, opts ...Option) error

Types

type AlignH added in v0.0.3

type AlignH = core.AlignH

Layout.

type AlignV added in v0.0.3

type AlignV = core.AlignV

type App

type App = core.Session

func NewApp

func NewApp(m Model, opts ...Option) *App

App functions.

func NewAppWithContext added in v0.0.4

func NewAppWithContext(ctx context.Context, m Model, opts ...Option) *App

Context-aware entrypoints.

type Cmd

type Cmd = core.Cmd

type Color added in v0.0.3

type Color = core.Color

type ColorProfile added in v0.0.3

type ColorProfile = core.ColorProfile

type Error added in v0.0.9

type Error = core.Error

Structured runtime and validation errors.

type ErrorCode added in v0.0.9

type ErrorCode = core.ErrorCode

type KeyMsg

type KeyMsg = core.KeyMsg

type KeyType added in v0.0.3

type KeyType = core.KeyType

type Logger added in v0.0.4

type Logger = core.Logger

Logger.

type Model

type Model = core.Model

Core types.

type MouseAction added in v0.0.5

type MouseAction = core.MouseAction

type MouseButton added in v0.0.5

type MouseButton = core.MouseButton

type MouseMsg added in v0.0.5

type MouseMsg = core.MouseMsg

Mouse and paste messages.

type Msg

type Msg = core.Msg

type Option

type Option = core.Option

type PasteMsg added in v0.0.5

type PasteMsg = core.PasteMsg

type QuitMsg

type QuitMsg = core.QuitMsg

type RendererOption added in v0.0.3

type RendererOption = core.RendererOption

Renderer options.

type ResizeMsg added in v0.0.3

type ResizeMsg = core.ResizeMsg

type Style added in v0.0.3

type Style = core.Style

Styling.

type TickMsg

type TickMsg = core.TickMsg

type ValidationCode added in v0.0.9

type ValidationCode = validate.Code

type ValidationIssue added in v0.0.9

type ValidationIssue = validate.Issue

type ValidationReport added in v0.0.9

type ValidationReport = validate.Report

type ValidationSeverity added in v0.0.9

type ValidationSeverity = validate.Severity

Directories

Path Synopsis
Package core implements Frog's terminal runtime.
Package core implements Frog's terminal runtime.
validate
Package validate inspects Frog models before runtime.
Package validate inspects Frog models before runtime.

Jump to

Keyboard shortcuts

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