Documentation
¶
Overview ¶
Package framebuffer provides Mosh-style terminal state diffing.
This package implements the core State Synchronization Protocol (SSP) algorithm inspired by Mosh (Mobile Shell). Instead of sending complete terminal states, it generates minimal ANSI escape sequences that transform an old framebuffer state into a new one.
Key Design Principles (from Mosh):
- Generate minimal escape sequences, not cell-by-cell diffs
- Use smart cursor positioning (relative vs absolute)
- Batch consecutive cells with the same style
- Skip unchanged rows entirely (fast pointer comparison first)
- Preserve correctness over any terminal emulator (pure ANSI output)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiffGenerator ¶
type DiffGenerator struct {
// contains filtered or unexported fields
}
DiffGenerator generates minimal ANSI diffs between terminal states
func NewDiffGenerator ¶
func NewDiffGenerator() *DiffGenerator
NewDiffGenerator creates a new diff generator
func (*DiffGenerator) GenerateDiff ¶
func (g *DiffGenerator) GenerateDiff(old, new *session.TerminalState) *DiffResult
GenerateDiff generates minimal ANSI escape sequences to transform old state to new state. This is the main entry point for Mosh-style state synchronization.
Algorithm overview:
- Handle dimension changes (requires full redraw)
- Compare row by row using fast generation counter check
- For changed rows, find contiguous changed segments
- Emit minimal cursor movements and character writes
- Position cursor at final location and set visibility
type DiffResult ¶
type DiffResult struct {
// DiffBytes contains the minimal ANSI escape sequences to transform old → new
DiffBytes []byte
// FromSequence is the sequence number of the old state
FromSequence uint64
// ToSequence is the sequence number of the new state
ToSequence uint64
// FullRedraw indicates this is a complete redraw (no dependency on old state)
FullRedraw bool
// ChangedCells is the count of cells that changed (for metrics)
ChangedCells int
// UnchangedCells is the count of cells that didn't change (for metrics)
UnchangedCells int
}
DiffResult contains the generated diff and metadata