Documentation
¶
Overview ¶
Package jsoneditor is a small bubbletea component that edits a JSON document and shows a syntax-highlighted preview before committing. It is shared by the `cinc <noun> edit` commands (via Run, which drives it as a standalone program) and by the `cinc explore` TUI (which embeds the Model as a screen).
The editor is JSON-aware: by default it presents a structural cursor (Model in model.go) that selects and edits keys, scalar values, and whole {}/[] blocks, with a raw free-text mode a Tab away.
cinc ships its own editor rather than shelling out to $VISUAL / $EDITOR so the experience is consistent across systems and works in minimal environments without an editor on PATH.
Index ¶
- func Run(initial []byte, validate func([]byte) error) ([]byte, error)
- type Model
- func (m Model) Aborted() bool
- func (m Model) Committed() []byte
- func (m Model) ContentView() string
- func (m Model) Editing() bool
- func (m Model) Finished() bool
- func (m Model) Init() tea.Cmd
- func (m *Model) SetSize(width, height int)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) Value() []byte
- func (m Model) View() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the editor state. It is an embeddable bubbletea component: call New, then forward Update/View to it, and check Finished after each Update to learn when the user has committed or aborted. It does not quit the surrounding program — embedding code decides what to do when Finished reports true.
By default it opens in structural mode: a JSON-aware cursor selects a key, a scalar value, or a whole object/array block (highlighted as a unit) and edits it in place. Tab drops to the raw free-text textarea for bulk edits, and Tab returns to structural mode.
func New ¶
New returns an editor seeded with initial. validate is invoked on each save attempt; returning a non-nil error keeps the user editing with the message shown inline (no work lost). If initial is not valid JSON the editor opens in raw mode so the user can repair it.
func (Model) Committed ¶
Committed returns the canonical JSON the user confirmed, or nil if the edit was aborted or is still in progress.
func (Model) ContentView ¶
ContentView renders just the editor body for the current state, without the header line. Embedding code (e.g. the node-edit form) uses it to place the editor under its own label instead of the standalone header.
func (Model) Editing ¶
Editing reports whether the editor is in a transient sub-edit (editing a key/scalar inline or a whole block). Embedding code uses this to decide whether Esc should cancel that sub-edit or back out of the editor.
func (*Model) SetSize ¶
SetSize resizes the editor to fit the given terminal dimensions, reserving a few lines for the header.
func (Model) Update ¶
Update advances the editor. It returns the concrete Model (not tea.Model) so embedding code can call Finished/Committed without a type assertion.
func (Model) Value ¶
Value returns the document's current canonical JSON, reflecting in-progress edits without requiring a commit. It lets embedding code (e.g. a larger form) read the live document at any time. In raw mode it canonicalizes the textarea contents, falling back to the raw bytes if they are not yet valid JSON.