Documentation
¶
Overview ¶
Package core implements Frog's terminal runtime.
Index ¶
- Variables
- func Center(block string, boxW, boxH int) string
- func Colorize(text string, fg *Color, bg *Color, bold bool) string
- func PlaceBlock(block string, boxW, boxH int, h AlignH, v AlignV) string
- func RenderHelpOverlay(km *KeyMap, width, height int) string
- func StripANSI(s string) string
- type AlignH
- type AlignV
- type Cmd
- type Color
- type ColorProfile
- type Error
- type ErrorCode
- type KeyBinding
- type KeyMap
- type KeyMsg
- type KeyType
- type Logger
- type Model
- type MouseAction
- type MouseButton
- type MouseMsg
- type Msg
- type NamedColor
- type Option
- func WithAltScreen() Option
- func WithBracketedPaste() Option
- func WithIn(r io.Reader) Option
- func WithLogger(l Logger) Option
- func WithMouse() Option
- func WithMsgBuffer(n int) Option
- func WithNonInteractive() Option
- func WithOut(w io.Writer) Option
- func WithRenderer(r Renderer) Option
- func WithResizeInterval(d time.Duration) Option
- type PasteMsg
- type QuitMsg
- type Renderer
- type RendererOption
- type ResizeMsg
- type Session
- type Style
- func (s Style) Bg(c Color) Style
- func (s Style) Blinking() Style
- func (s Style) Bolded() Style
- func (s Style) Fainted() Style
- func (s Style) Fg(c Color) Style
- func (s Style) Italicized() Style
- func (s Style) Render(text string) string
- func (s Style) Reversed() Style
- func (s Style) Struck() Style
- func (s Style) Underlined() Style
- type TickMsg
Constants ¶
This section is empty.
Variables ¶
var ( ColorBlack = Ansi16(NamedBlack, false) ColorRed = Ansi16(NamedRed, false) ColorGreen = Ansi16(NamedGreen, false) ColorYellow = Ansi16(NamedYellow, false) ColorBlue = Ansi16(NamedBlue, false) ColorMagenta = Ansi16(NamedMagenta, false) ColorCyan = Ansi16(NamedCyan, false) ColorWhite = Ansi16(NamedWhite, false) ColorBrightBlack = Ansi16(NamedBlack, true) ColorBrightRed = Ansi16(NamedRed, true) ColorBrightGreen = Ansi16(NamedGreen, true) ColorBrightYellow = Ansi16(NamedYellow, true) ColorBrightBlue = Ansi16(NamedBlue, true) ColorBrightMagenta = Ansi16(NamedMagenta, true) ColorBrightCyan = Ansi16(NamedCyan, true) ColorBrightWhite = Ansi16(NamedWhite, true) )
Functions ¶
func PlaceBlock ¶ added in v0.0.3
PlaceBlock aligns a multi-line block inside a virtual box.
func RenderHelpOverlay ¶ added in v0.0.9
RenderHelpOverlay renders a centered help legend.
Types ¶
type Cmd ¶ added in v0.0.2
type Cmd func() Msg
Cmd represents an async action that eventually returns a Msg.
type Color ¶ added in v0.0.3
type Color struct {
// contains filtered or unexported fields
}
func Ansi16 ¶ added in v0.0.3
func Ansi16(name NamedColor, bright bool) Color
type ColorProfile ¶ added in v0.0.3
type ColorProfile int
const ( ColorAuto ColorProfile = iota ColorNone ColorANSI16 ColorANSI256 ColorTrueColor )
type ErrorCode ¶ added in v0.0.9
type ErrorCode string
ErrorCode identifies a runtime failure in Frog's core loop.
const ( ErrNilModel ErrorCode = "FROG201" ErrNilRenderer ErrorCode = "FROG202" ErrRawMode ErrorCode = "FROG203" ErrInitFailed ErrorCode = "FROG204" ErrViewFailed ErrorCode = "FROG205" ErrUpdateFailed ErrorCode = "FROG206" ErrCommandFailed ErrorCode = "FROG207" ErrNilUpdateModel ErrorCode = "FROG208" )
type KeyBinding ¶ added in v0.0.9
type KeyBinding struct {
Keys []string // canonical key strings (case-insensitive)
Help string // short action label shown in help overlay
}
KeyBinding maps one or more keys to a help label.
type KeyMap ¶ added in v0.0.9
type KeyMap struct {
Bindings []KeyBinding
}
KeyMap is a flat list of key bindings.
type KeyMsg ¶ added in v0.0.2
type KeyMsg struct {
Type KeyType
Rune rune // valid when Type == KeyRune
String string // best-effort textual/escape representation
Alt bool // true if input decoder detected Alt/Meta
Ctrl bool // true if control modifier was involved (e.g., Ctrl+C)
}
KeyMsg represents a keyboard event. For KeyRune, Rune and String are set. For non-printable keys, String holds the raw escape sequence (when available).
type KeyType ¶ added in v0.0.3
type KeyType int
KeyType enumerates high-level keys recognized by the input decoder. For printable runes, Type is KeyRune and the Rune field is set.
type Logger ¶ added in v0.0.3
type Logger interface {
Debugf(format string, args ...any)
Infof(format string, args ...any)
Warnf(format string, args ...any)
Errorf(format string, args ...any)
}
Logger is the leveled logging interface used across the core runtime. It is intentionally minimal to keep call sites lightweight and mock-friendly.
type Model ¶ added in v0.0.2
Update processes a Msg and returns the next state plus an optional Cmd. View must be side-effect free and return the current UI as a string.
Tip: Use a consistent receiver style (pointer or value) across all methods to avoid FROG109 warnings from the validator.
type MouseAction ¶ added in v0.0.5
type MouseAction int
MouseAction identifies the action associated with a mouse event.
const ( MousePress MouseAction = iota MouseRelease MouseDrag MouseWheel )
func (MouseAction) String ¶ added in v0.0.9
func (a MouseAction) String() string
String returns a stable textual name for the action.
type MouseButton ¶ added in v0.0.5
type MouseButton int
MouseButton identifies the logical mouse button or wheel direction.
const ( MouseUnknown MouseButton = iota MouseLeft MouseMiddle MouseRight MouseWheelUp MouseWheelDown )
func (MouseButton) String ¶ added in v0.0.9
func (b MouseButton) String() string
String returns a stable textual name for the button.
type MouseMsg ¶ added in v0.0.5
type MouseMsg struct {
Button MouseButton
Action MouseAction
X, Y int // 1-based terminal coords (col=X, row=Y)
Alt bool
Ctrl bool
Shift bool
}
MouseMsg represents a mouse event using SGR reporting (1006). X/Y are 1-based terminal coordinates (column/row).
type Msg ¶ added in v0.0.2
type Msg interface{}
Msg is a marker interface for all messages delivered to a Model's Update. Any concrete type can be a message. The framework ships a standard set: - KeyMsg: keyboard input (including special keys) - MouseMsg: mouse input via SGR - PasteMsg: bracketed paste payload - TickMsg: time-based trigger - ResizeMsg: terminal size changes - QuitMsg: request to terminate the app
type NamedColor ¶ added in v0.0.3
type NamedColor uint8
const ( NamedBlack NamedColor = iota NamedRed NamedGreen NamedYellow NamedBlue NamedMagenta NamedCyan NamedWhite )
type Option ¶ added in v0.0.2
type Option func(*Session)
Option configures a Session at construction time.
func WithAltScreen ¶ added in v0.0.3
func WithAltScreen() Option
WithAltScreen enables the alternate terminal screen.
func WithBracketedPaste ¶ added in v0.0.5
func WithBracketedPaste() Option
WithBracketedPaste enables bracketed paste (ESC[200~ .. ESC[201~]).
func WithMouse ¶ added in v0.0.5
func WithMouse() Option
WithMouse enables SGR mouse reporting (1000/1002/1006 modes).
func WithMsgBuffer ¶ added in v0.0.3
WithMsgBuffer sets the size of the internal message channel buffer (default 64).
func WithNonInteractive ¶ added in v0.0.4
func WithNonInteractive() Option
WithNonInteractive disables raw mode and the input loop.
func WithRenderer ¶ added in v0.0.2
WithRenderer sets a custom renderer.
func WithResizeInterval ¶ added in v0.0.4
WithResizeInterval sets the polling interval for terminal size changes (default 150ms).
type PasteMsg ¶ added in v0.0.5
type PasteMsg struct {
Text string
}
PasteMsg is emitted when bracketed paste is enabled and a paste operation completes. Text contains the full pasted payload (up to an internal cap).
type QuitMsg ¶ added in v0.0.2
type QuitMsg struct{}
QuitMsg requests the app to terminate. Models can emit this to exit cleanly.
type Renderer ¶ added in v0.0.2
type Renderer interface {
// Clear clears the target before rendering.
Clear()
// Render writes a frame to the target.
Render(s string)
// Close restores terminal state and releases resources.
Close()
}
Renderer renders frames to an output target.
func NewRenderer ¶ added in v0.0.3
func NewRenderer(out io.Writer, opts ...RendererOption) Renderer
NewRenderer returns an ANSI renderer bound to out.
func NewThrottledRenderer ¶ added in v0.0.9
func NewThrottledRenderer(out io.Writer, fps int, opts ...RendererOption) Renderer
NewThrottledRenderer returns a Renderer with FPS cap. If fps <= 0 the base renderer is returned as-is.
type RendererOption ¶ added in v0.0.3
type RendererOption func(*ansiRenderer)
RendererOption configures an ANSI renderer.
func WithColorProfile ¶ added in v0.0.3
func WithColorProfile(p ColorProfile) RendererOption
WithColorProfile forces a color profile.
func WithDiff ¶ added in v0.0.3
func WithDiff(enabled bool) RendererOption
WithDiff enables or disables line diffing.
type ResizeMsg ¶ added in v0.0.2
type ResizeMsg struct {
Width, Height int
}
ResizeMsg is emitted when the terminal size changes. Coordinates are in cells.
type Session ¶ added in v0.0.2
type Session struct {
// contains filtered or unexported fields
}
Session runs a Model, coordinating input, rendering and lifecycle.
func NewSession ¶ added in v0.0.2
NewSession creates a session with a background context.
func NewSessionWithContext ¶ added in v0.0.4
NewSessionWithContext creates a session bound to ctx.
func (*Session) Quit ¶ added in v0.0.3
func (p *Session) Quit()
Quit requests a graceful shutdown by sending a QuitMsg into the event loop.
type Style ¶ added in v0.0.3
type Style struct {
Bold bool
Faint bool
Italic bool
Underline bool
Blink bool
Reverse bool
Strike bool
// contains filtered or unexported fields
}