editor

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(oldText, newText string) string

Diff renders a unified line-by-line diff of oldText vs newText. Context lines are prefixed with a space, deletions with `-` (error color) and additions with `+` (success color).

func HighlightJSON

func HighlightJSON(line string) string

HighlightJSON applies syntax highlighting to a single line of (already pretty-printed) JSON. It is line-based so it composes with soft-wrapping and line numbering. Non-JSON input is returned styled as plain text.

Types

type DiffView

type DiffView struct {
	core.BaseComponent
	// contains filtered or unexported fields
}

DiffView is a scrollable component wrapping a rendered unified diff.

func NewDiffView

func NewDiffView(oldText, newText string) *DiffView

NewDiffView creates a diff view for oldText vs newText.

func (*DiffView) SetContent

func (d *DiffView) SetContent(oldText, newText string)

SetContent recomputes the diff for new inputs.

func (*DiffView) SetDimensions

func (d *DiffView) SetDimensions(width, height int)

SetDimensions sizes the diff view.

func (*DiffView) Update

func (d *DiffView) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update forwards messages to the viewport for scrolling.

func (*DiffView) View

func (d *DiffView) View() string

View renders the diff view.

type Editor

type Editor struct {
	core.BaseComponent
	// contains filtered or unexported fields
}

Editor is an editable text component (schema/config/query text) built on bubbles/textarea.

func NewEditor

func NewEditor(content string) *Editor

NewEditor creates an editor pre-filled with content and ready for input.

func (*Editor) Blur

func (e *Editor) Blur()

Blur removes focus from the editor.

func (*Editor) Focus

func (e *Editor) Focus() tea.Cmd

Focus focuses the editor for input.

func (*Editor) Init

func (e *Editor) Init() tea.Cmd

Init implements core.Component.

func (*Editor) SetDimensions

func (e *Editor) SetDimensions(width, height int)

SetDimensions sizes the underlying textarea.

func (*Editor) SetValue

func (e *Editor) SetValue(s string)

SetValue replaces the editor text.

func (*Editor) Update

func (e *Editor) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update forwards messages to the textarea.

func (*Editor) Value

func (e *Editor) Value() string

Value returns the current editor text.

func (*Editor) View

func (e *Editor) View() string

View renders the editor.

type Viewer

type Viewer struct {
	core.BaseComponent
	// contains filtered or unexported fields
}

Viewer is a read-only content viewer with line numbers, a soft-wrap toggle and in-content `/` search with n/N match navigation. It generalizes the older JSONContentView: pass Highlight to colorize JSON content.

func NewViewer

func NewViewer(content string) *Viewer

NewViewer creates a read-only viewer for the given content.

func (*Viewer) MatchCount

func (v *Viewer) MatchCount() int

MatchCount returns the number of lines matching the current query.

func (*Viewer) MatchIndex

func (v *Viewer) MatchIndex() int

MatchIndex returns the index of the active match, or -1 if there is none.

func (*Viewer) MatchLine

func (v *Viewer) MatchLine() int

MatchLine returns the line index (0-based) of the active match, or -1.

func (*Viewer) NextMatch

func (v *Viewer) NextMatch()

NextMatch advances to the next search match (wraps around).

func (*Viewer) PrevMatch

func (v *Viewer) PrevMatch()

PrevMatch moves to the previous search match (wraps around).

func (*Viewer) Search

func (v *Viewer) Search(query string)

Search sets the active query, computes matching lines and jumps to the first match. An empty query clears the search.

func (*Viewer) Searching

func (v *Viewer) Searching() bool

Searching reports whether the in-content `/` search prompt is currently open. Callers that add their own single-key hotkeys should defer to the viewer while this is true so keystrokes reach the search field unmodified.

func (*Viewer) SetContent

func (v *Viewer) SetContent(content string)

SetContent replaces the viewed content and resets search state.

func (*Viewer) SetDimensions

func (v *Viewer) SetDimensions(width, height int)

SetDimensions sets the viewer size.

func (*Viewer) SetHighlight

func (v *Viewer) SetHighlight(on bool)

SetHighlight enables or disables JSON syntax highlighting.

func (*Viewer) ToggleWrap

func (v *Viewer) ToggleWrap()

ToggleWrap flips soft-wrapping of long lines.

func (*Viewer) Update

func (v *Viewer) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles key input: `/` opens search, enter runs it, esc cancels, n/N navigate matches, w toggles wrap. Other keys scroll the viewport.

func (*Viewer) View

func (v *Viewer) View() string

View renders the viewer, appending the search prompt or match count.

func (*Viewer) Wrapped

func (v *Viewer) Wrapped() bool

Wrapped reports whether soft-wrap is currently on.

Jump to

Keyboard shortcuts

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