Documentation
¶
Overview ¶
Package editor provides the bubbletea TUI for editing a YAML file driven by a struct-based schema and a preset source.
Index ¶
- Constants
- Variables
- type AddEntry
- type AppendPreset
- type ApplyDocPreset
- type ApplyPreset
- type BlockAction
- type CommitBlock
- type Config
- type DeleteBlock
- type DeleteEntry
- type DocRedo
- type DocUndo
- type DrillIn
- type DrillOut
- type FieldMeta
- type Format
- type MetadataFunc
- type MetadataSource
- type ModelAction
- type NavigateEntry
- type OpenBlock
- type Redo
- type Reload
- type Result
- type Save
- type SyncYAML
- type ToggleField
- type ToggleHints
- type Trace
- type Undo
- type ValidationInput
- type Validator
- type ValidatorFunc
- type Violation
- type WiredValidators
Constants ¶
const ( GroupMutuallyExclusive = spec.GroupMutuallyExclusive GroupUnknownKeys = spec.GroupUnknownKeys GroupRules = spec.GroupRules )
Variables ¶
var ( FormatCIDR = spec.FormatCIDR FormatDate = spec.FormatDate FormatDirectoryPath = spec.FormatDirectoryPath FormatDuration = spec.FormatDuration FormatEmail = spec.FormatEmail FormatFQDN = spec.FormatFQDN FormatGitRef = spec.FormatGitRef FormatHost = spec.FormatHost FormatHostPort = spec.FormatHostPort FormatIP = spec.FormatIP FormatIPv4 = spec.FormatIPv4 FormatIPv6 = spec.FormatIPv6 FormatPort = spec.FormatPort FormatPrivateKey = spec.FormatPrivateKey FormatPublicKey = spec.FormatPublicKey FormatSemver = spec.FormatSemver FormatTerraformSource = spec.FormatTerraformSource FormatURL = spec.FormatURL FormatUUID = spec.FormatUUID )
Built-in formats, re-exported from spec.
var ( AllOrNone = validate.AllOrNone AllOrNoneNested = validate.AllOrNoneNested AtLeastOneOf = validate.AtLeastOneOf AtLeastOneOfNested = validate.AtLeastOneOfNested CountRange = validate.CountRange CrossFieldOrdered = validate.CrossFieldOrdered CrossFieldOrderedNested = validate.CrossFieldOrderedNested Deprecated = validate.Deprecated ExactlyOneOf = validate.ExactlyOneOf ExactlyOneOfNested = validate.ExactlyOneOfNested ForbiddenIf = validate.ForbiddenIf MutuallyExclusive = validate.MutuallyExclusive MutuallyExclusiveGroupsNested = validate.MutuallyExclusiveGroupsNested MutuallyExclusiveNested = validate.MutuallyExclusiveNested NoDuplicates = validate.NoDuplicates Required = validate.Required RequiredIf = validate.RequiredIf RequiredWith = validate.RequiredWith UniqueValues = validate.UniqueValues ValueHasLength = validate.ValueHasLength ValueHasPrefix = validate.ValueHasPrefix ValueHasSuffix = validate.ValueHasSuffix ValueInRange = validate.ValueInRange ValueMatches = validate.ValueMatches ValueMatchesFormat = validate.ValueMatchesFormat ValueNotOneOf = validate.ValueNotOneOf ValueOneOf = validate.ValueOneOf )
Explicit rules: operate directly on raw YAML via path strings.
var ( CountFromMetadata = validate.CountFromMetadata DeprecatedFromMetadata = validate.DeprecatedFromMetadata FormatFromMetadata = validate.FormatFromMetadata LengthFromMetadata = validate.LengthFromMetadata NotOneOfFromMetadata = validate.NotOneOfFromMetadata OneOfFromMetadata = validate.OneOfFromMetadata PatternFromMetadata = validate.PatternFromMetadata RangeFromMetadata = validate.RangeFromMetadata RequiredFromMetadata = validate.RequiredFromMetadata UniqueFromMetadata = validate.UniqueFromMetadata )
FromMetadata rules: driven by Config.Metadata, inert until wired.
var RunAll = validate.RunAll
RunAll executes all validators against raw/blocks. See validate.RunAll.
Functions ¶
This section is empty.
Types ¶
type AddEntry ¶ added in v0.22.0
type AddEntry struct{}
AddEntry appends a new entry to a collection-nav block.
type AppendPreset ¶ added in v0.40.0
type AppendPreset struct{ Name, Content string }
AppendPreset appends preset entries to a collection-nav block. Content is the already-fetched YAML so dispatch stays pure.
type ApplyDocPreset ¶ added in v0.39.0
type ApplyDocPreset struct{ Name, Content string }
type ApplyPreset ¶ added in v0.22.0
type ApplyPreset struct{ Name, Content string }
ApplyPreset replaces the block content with the named preset. Content is the already-fetched YAML so dispatch stays pure.
type BlockAction ¶ added in v0.22.0
type BlockAction interface {
// contains filtered or unexported methods
}
BlockAction is a pure synchronous mutation of blockEditState. Every block-editor mutation passes through blockEditState.dispatch.
type CommitBlock ¶ added in v0.22.0
type CommitBlock struct{}
type Config ¶
type Config struct {
Path string // YAML file to load; also the default save target when SavePath is empty
Schema any // non-nil struct pointer, typed as any because the editor uses reflection (e.g. &MyConfig{})
Title string // label shown in the TUI header
BlockPresets presets.Source // optional; nil disables the preset picker inside block editors
DocPresets presets.Source // optional; when set, p on the root list opens a whole-document template picker
EnableHints bool // show the Hint/Example panel; warns when Metadata is unset
Metadata MetadataSource // field metadata shown in the hint panel and enforced by the FromMetadata validators
Validators []Validator // rules evaluated before every save and on the validate shortcut
Hidden []string // top-level keys to omit from the UI entirely
PassthroughKeys []string // top-level keys preserved as-is: hidden from all sections and exempt from unknown-key validation
Theme theme.Theme // zero-value resolves to ThemePlain
NoDeleteConfirm bool // skip the "Remove block?" dialog; deletion is still undoable via ctrl+u
NoValidateOnSave bool // allow saving despite validator errors; a warning alert is shown but does not block
NoSaveConfirm bool // skip the "Save changes?" dialog; warning confirms are still shown
SavePath string // write here instead of Path, which is still used for loading
SchemaRecursionDepth int // extra levels a self-referential type expands; 0 uses the default (1)
AnimationDuration time.Duration // when > 0, the Hint/Example panel eases open and closed over this duration; 0 keeps the toggle instant and emits no timer messages
Trace Trace // session-observability hooks and the built-in Dump recorder
}
Config bundles everything the editor needs from the embedding application.
Schema must be a pointer to the Go type describing the YAML document's top level (e.g. &MyConfig{}), introspected through yedit/schema.
Validators run before every save and on the explicit "validate" shortcut. Use editor.MutuallyExclusive and editor.RequiredWith for the common cases.
Metadata populates each field's Hint/Example panel. FieldMeta values are used as-is; yedit never falls back to struct tags. FieldMeta.PreChecked lists sub-fields that start checked in a new block, and FieldMeta.Snippet is the YAML inserted when a sub-field is toggled on, defaulting to "<fieldName>: \n".
type DeleteBlock ¶ added in v0.22.0
type DeleteBlock struct{ Key string }
type DeleteEntry ¶ added in v0.22.0
type DeleteEntry struct{ SeqIdx int }
DeleteEntry removes the collection entry at SeqIdx.
type FieldMeta ¶ added in v0.16.0
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type Format ¶ added in v0.25.0
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type MetadataFunc ¶ added in v0.22.0
type MetadataFunc = spec.MetadataFunc
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type MetadataSource ¶ added in v0.22.0
type MetadataSource = spec.MetadataSource
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type ModelAction ¶ added in v0.22.0
type ModelAction interface {
// contains filtered or unexported methods
}
ModelAction is handled by model.dispatch and may produce a tea.Cmd only for tea.Quit.
type NavigateEntry ¶ added in v0.22.0
NavigateEntry moves the collection cursor to Idx (flush + load).
type Redo ¶ added in v0.22.0
type Redo struct{}
Redo re-applies the most recently undone block snapshot.
type Result ¶ added in v0.18.0
type Result struct {
// Saved is true when at least one save to disk succeeded during the
// session. It stays true even if the user keeps editing afterwards and
// quits with unsaved changes.
Saved bool
// DumpPath is the path of the session trace file, set when
// Config.Trace.Dump is true. Empty when Dump is false or the dump file
// could not be created.
DumpPath string
}
Result reports the outcome of an editor session.
func Run ¶
Run starts the editor TUI and blocks until the user quits. The Config must have Schema and Path set; everything else is optional.
Returns the session Result on a clean quit, or the underlying tea.Program error. A panic inside the editor is recovered and returned as an error instead of crashing the embedding program: Bubble Tea restores the terminal before the panic propagates here, so the host is left with a usable terminal and a normal error to handle.
func RunContext ¶ added in v0.18.0
RunContext is Run with a context: cancelling ctx shuts the editor down and makes RunContext return the context's error. Unsaved changes are discarded on cancellation, but Result.Saved still reports any save that completed before it.
type SyncYAML ¶ added in v0.22.0
SyncYAML advances be.node from new YAML content (parse-gated). Checkpoint saves an undo snapshot first: set it for pastes, not for single keystrokes.
type ToggleField ¶ added in v0.22.0
ToggleField checks or unchecks the field at NodeIdx in the tree.
type ToggleHints ¶ added in v0.22.0
type ToggleHints struct{}
type Trace ¶ added in v0.48.0
type Trace struct {
OnAction func(blockKey string, a BlockAction) // optional; called after every BlockAction, with the key of the block editor it applied to
OnModelAction func(ModelAction) // optional; called after every ModelAction
OnMsg func(where string, msg tea.Msg) // optional; called for every raw tea.Msg before it is routed. where describes the active pane/block/panel (e.g. "block:categories:tree:editing")
Dump bool // record every action and keystroke to a JSONL file, reported in Result.DumpPath; composes with the callbacks above
DumpPath string // explicit path for the Dump file; empty falls back to a timestamped file in the OS temp dir
}
Trace bundles the editor's session-observability hooks and the built-in Dump-to-JSONL recorder built on them. See docs/SESSION-TRACING.md.
type ValidationInput ¶ added in v0.20.0
type ValidationInput = spec.ValidationInput
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
func NewValidationInput ¶ added in v0.20.0
func NewValidationInput(raw []byte, blocks []document.Block) ValidationInput
NewValidationInput parses raw once and bundles it with blocks for a validation run. See spec.NewValidationInput.
type Validator ¶
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type ValidatorFunc ¶
type ValidatorFunc = spec.ValidatorFunc
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type Violation ¶ added in v0.18.0
These names live in yedit/spec so metadata, docgenerator, validate, and third-party rules can describe a field without importing the TUI. They are aliases, not new types, so consumer code keeps compiling.
type WiredValidators ¶ added in v0.38.0
type WiredValidators = validate.WiredValidators
WiredValidators is an opaque handle produced by Wire. See validate.WiredValidators.
func Wire ¶ added in v0.38.0
func Wire(validators []spec.Validator, cfg Config) WiredValidators
Wire prepares a validator slice for use with RunAll, discovering the schema tree from cfg so that FromMetadata validators can fire. It returns a handle where every FromMetadata validator carries the schema and MetadataSource; explicit validators are included as-is. The original slice is never modified.
cfg.Schema must be non-nil for FromMetadata validators to report anything; cfg.Metadata may be nil. Callers that already hold the discovered tree should use validate.WireWithSchema directly, so both sides see the same schema.
Source Files
¶
- actions.go
- blockedit.go
- blockedit_collection.go
- blockedit_follow.go
- blockedit_hint.go
- blockedit_presets.go
- blockedit_tree.go
- blockedit_undo.go
- breadcrumb.go
- collection_node.go
- config.go
- dispatch_block.go
- dispatch_model.go
- dump.go
- hint.go
- keymap.go
- legend.go
- list.go
- messages.go
- node_sync.go
- overlay_stack.go
- root.go
- root_keys.go
- root_layout.go
- root_preview.go
- root_save.go
- run.go
- sections.go
- statusbar.go
- theme_resolve.go
- tree.go
- tween.go
- validators_alias.go
- yaml.go