Documentation
¶
Overview ¶
Package inlineedit owns the shared lifecycle of an inline tmux-PTY editor hosted inside a pane: session start bookkeeping, activation-epoch guards, stale-start cleanup, mouse/cursor coordinate translation, and the save/discard/cancel exit confirmation.
The package is deliberately host-agnostic. It never measures the host's layout: the host supplies its editor viewport and screen origin through the Host contract, so dimension drift is a host bug rather than a mirrored calculation inside here. It also never consults feature flags — gating inline edit is a host concern (filebrowser gates on features.TmuxInlineEdit; notes deliberately does not).
Index ¶
- Variables
- func Start(opts StartOptions) tea.Cmd
- type ExitedMsg
- type Host
- type Outcome
- type Session
- func (s *Session) Begin(name, editorCmd, path string) tea.Cmd
- func (s *Session) CleanupStale(name, editorCmd string) tea.Cmd
- func (s *Session) ClearPendingClick()
- func (s *Session) Cursor(hostWidth, hostHeight int) *tea.Cursor
- func (s *Session) EditingHeader(title string) string
- func (s *Session) Exit()
- func (s *Session) ForwardMouseDrag(col, row int) tea.Cmd
- func (s *Session) ForwardMousePress(col, row int) tea.Cmd
- func (s *Session) ForwardMouseRelease(col, row int) tea.Cmd
- func (s *Session) HandleConfirmKey(key string) (outcome Outcome, handled bool)
- func (s *Session) IsAlive() bool
- func (s *Session) IsModelActive() bool
- func (s *Session) MouseCoords(x, y int) (col, row int, ok bool)
- func (s *Session) MoveConfirmSelection(delta int)
- func (s *Session) NativeActive() bool
- func (s *Session) NextActivation() uint64
- func (s *Session) OwnsMessage(activation, epoch, currentEpoch uint64) bool
- func (s *Session) PreferredMouseMode(native bool) tea.MouseMode
- func (s *Session) RenderExitConfirm() string
- func (s *Session) Reopen() tea.Cmd
- func (s *Session) Reset()
- func (s *Session) ResizeToViewport() tea.Cmd
- func (s *Session) Route(m tea.Msg) (cmd tea.Cmd, alive bool)
- func (s *Session) SaveAndQuit()
- func (s *Session) SetPendingClick(region string, data interface{})
- func (s *Session) SizeIndicator() string
- func (s *Session) TakePendingClick() (string, interface{})
- func (s *Session) Target() tty.EditorSession
- func (s *Session) Viewport() (width, height int)
- type StartOptions
- type StartedMsg
Constants ¶
This section is empty.
Variables ¶
var ExitConfirmOptions = []string{"Save & Exit", "Exit without saving", "Cancel"}
ExitConfirmOptions are the choices offered before leaving a live session.
Functions ¶
func Start ¶
func Start(opts StartOptions) tea.Cmd
Start launches a tmux editor session for a pane leaf. It reports failures as toasts rather than errors: there is nowhere else in a pane to say them.
Types ¶
type Host ¶
type Host interface {
// EditorViewport reports the content cells available to the PTY.
EditorViewport() (width, height int)
// EditorOrigin reports the top-left cell of that content area in
// host-local coordinates. ok is false when the host has no usable rect.
EditorOrigin() (x, y int, ok bool)
}
Host is the contract a pane implements to host an inline editor.
type Session ¶
type Session struct {
Model *tty.Model
Host Host
// Redraw, when set, is batched after operations that change the editor's
// geometry so a host that caches its render can invalidate it.
Redraw func() tea.Cmd
Active bool // an inline edit session is current
Name string // tmux session name
Path string // file being edited
EditorCmd string // editor command (vim, nano, ...)
Activation uint64 // scopes async start/exit messages
Dragging bool // mouse drag in progress inside the editor
ShowExitConfirm bool
ConfirmSelection int // 0=Save&Exit, 1=Exit without saving, 2=Cancel
PendingClickRegion string
PendingClickData interface{}
}
Session holds the state shared by every inline-editor host.
func (*Session) Begin ¶
Begin records a freshly started tmux editor session and opens the tty model at the host's viewport.
func (*Session) CleanupStale ¶
CleanupStale kills the tmux session named by a stale start message, unless that name is the one the live model is currently driving (tmux reuses names).
func (*Session) ClearPendingClick ¶
func (s *Session) ClearPendingClick()
ClearPendingClick drops the click that triggered an exit confirmation.
func (*Session) Cursor ¶
Cursor exposes the editor's native cursor in host-local coordinates, clamped to the host rect.
func (*Session) EditingHeader ¶
EditingHeader renders the "Editing: <name>" header line with the exit hint and, when the tmux pane is larger than the viewport, the size indicator.
func (*Session) ForwardMouseDrag ¶
ForwardMouseDrag sends a drag/motion at 1-indexed editor coordinates.
func (*Session) ForwardMousePress ¶
ForwardMousePress sends a press at 1-indexed editor coordinates.
func (*Session) ForwardMouseRelease ¶
ForwardMouseRelease sends a release at 1-indexed editor coordinates.
func (*Session) HandleConfirmKey ¶
HandleConfirmKey drives the exit confirmation and reports what it decided. handled is false for keys the dialog does not own, so a host can swallow them itself rather than let them reach the surface behind a modal.
func (*Session) IsModelActive ¶
IsModelActive reports whether the underlying tty model is attached.
func (*Session) MouseCoords ¶
MouseCoords converts host-local screen coordinates to 1-indexed editor coordinates for the SGR mouse protocol. ok is false outside the content area.
func (*Session) MoveConfirmSelection ¶
MoveConfirmSelection moves the exit-confirmation cursor by delta, wrapping.
func (*Session) NativeActive ¶
NativeActive reports whether the embedded terminal owns input right now. Hosts AND this with their own conditions (focus, pane, modals).
func (*Session) NextActivation ¶
NextActivation bumps and returns the activation counter.
func (*Session) OwnsMessage ¶
OwnsMessage reports whether an async message belongs to the live session.
func (*Session) PreferredMouseMode ¶
PreferredMouseMode returns the terminal's preferred mouse mode when native is true, and all-motion hover otherwise.
func (*Session) RenderExitConfirm ¶
RenderExitConfirm renders the save/discard/cancel dialog body.
func (*Session) Reopen ¶
Reopen re-attaches the tty model to the session already recorded here, used when a host returns to a pane/tab that was left in edit mode.
func (*Session) Reset ¶
func (s *Session) Reset()
Reset clears session-scoped state and closes the tty model without killing the tmux session. Callers that own the session should use Exit.
func (*Session) ResizeToViewport ¶
ResizeToViewport re-sizes the PTY to the host's current viewport.
func (*Session) Route ¶
Route hands one message to the live tty model and reports whether the session is still attached afterwards. A host that gets alive=false owes its own exit bookkeeping — the editor quit on its own.
func (*Session) SaveAndQuit ¶
func (s *Session) SaveAndQuit()
SaveAndQuit asks the editor to write and quit.
func (*Session) SetPendingClick ¶
SetPendingClick records the click to replay once the editor exits.
func (*Session) SizeIndicator ¶
SizeIndicator reports what part of a larger tmux pane is hidden, if any.
func (*Session) TakePendingClick ¶
TakePendingClick returns and clears the pending click.
func (*Session) Target ¶
func (s *Session) Target() tty.EditorSession
Target describes the tmux session backing this editor.
type StartOptions ¶
type StartOptions struct {
Surface string
LeafID int
AbsPath string // file handed to the editor
Path string // path echoed back in StartedMsg
Line int // 1-indexed; 0 leaves the editor at the top
Width, Height int
Activation uint64
Epoch uint64
}
StartOptions is what a pane host must say to open an editor: which file, at what size, on behalf of which leaf.
type StartedMsg ¶
type StartedMsg struct {
Surface string
LeafID int
SessionName string
Editor string
Path string // the path the host knows the document by
Activation uint64
Epoch uint64
}
StartedMsg reports a tmux editor session started for a pane leaf. Surface distinguishes the two workspace projections, which both see every message.