Help us shape the future of Go! Take the 2026 Go Developer Survey

occupied

package
v0.0.205 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package occupied classifies live composer occupancy by injecting a space and comparing before/after snapshots.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExactlyOneMoreSpace

func ExactlyOneMoreSpace(before, after []byte) bool

ExactlyOneMoreSpace reports whether after is before with exactly one ASCII space (0x20) inserted. Both sides are newline-stripped first, then compared byte-by-byte.

Occupied when: len(after)==len(before)+1, the extra byte is ' ', and removing that byte yields before. Empty before is never occupied.

func StripNewlines

func StripNewlines(b []byte) []byte

StripNewlines removes \n and \r so compares ignore line breaks.

Types

type IO

type IO struct {
	Snapshot func() (string, error)
	Inject   func(text string) error // no-submit; Probe sends " " then "\x7f"
	// Before is an optional resting snapshot. When non-empty, Probe skips the
	// first Snapshot call (avoids a duplicate SnapshotText under idle Tick).
	Before string
	// Settle is how long to wait after injecting the space before reading
	// after, and between post-DEL stabilize polls (0 → defaultProbeSettle).
	Settle time.Duration
}

IO is the injectable snapshot/inject surface for Probe.

type Status

type Status string

Status is composer occupancy from a space probe.

const (
	Empty    Status = "empty"
	Occupied Status = "occupied"
	Unknown  Status = "unknown"
)

func Probe

func Probe(io IO) Status

Probe types one space, waits Settle, snapshots, classifies with ExactlyOneMoreSpace, then always DELs the space and waits until Snapshot matches the pre-probe resting text again (or attempts are exhausted).

exactly +1 draft space → Occupied any other / no change → Empty snapshot fail → Unknown inject fail → Empty (cannot prove occupancy; callers that need a hard hold should check Ready/writable separately)

func (Status) String

func (s Status) String() string

Jump to

Keyboard shortcuts

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