Documentation
¶
Overview ¶
Package terminal defines the host environment context exposed by a Kite document. Terminal provides asynchronous Clipboard access, Window frame requests, Scheduler task queues, and terminal protocol capabilities including titles, the bell, progress reporting, program status, and program resume.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clipboard ¶
type Clipboard interface {
// ReadText returns the current text content of the clipboard. If the clipboard is
// empty or unavailable, it returns an empty string and an error.
//
// This call blocks until the clipboard content is available and fails
// after 100ms if the clipboard is unavailable or access is denied.
ReadText() *promise.Promise[string]
// WriteText replaces the clipboard's plain-text content.
WriteText(text string) *promise.Promise[struct{}]
// ListFormats returns a list of MIME types representing the formats currently available in
// the clipboard. If the clipboard is unavailable or access is denied, it returns an error.
ListFormats() *promise.Promise[[]string]
// Read returns the current content of the clipboard as a byte slice. If the clipboard is
// empty or unavailable, it returns an empty byte slice and an error.
//
// This call blocks until the clipboard content is available and fails
// after 100ms if the clipboard is unavailable or access is denied.
//
// E.g. Read("text/plain") returns the same content as ReadText() but as bytes.
// Read("image/png") would return PNG-encoded image data if the clipboard contains an image.
// Read("text/html") would return HTML content if the clipboard contains HTML.
// Read(mime string) ([]byte, error)
Read(mime string) *promise.Promise[[]byte]
// Write writes the given data to the clipboard with the specified MIME type. If the clipboard is unavailable or access is denied, it returns an error.
Write(mime string, data []byte) *promise.Promise[struct{}]
}
Clipboard provides asynchronous access to plain text and MIME-typed data.
type Cursor ¶
type Cursor interface {
// SetPosition places and shows the hardware cursor at physical terminal-cell coordinates.
SetPosition(x, y int)
// SetShape selects the hardware cursor visual shape.
SetShape(shape style.CursorShape)
// Hide explicitly hides the hardware cursor for the current frame.
Hide()
}
Cursor provides imperative per-frame control over the terminal's hardware cursor.
type ProgramResume ¶
type ProgramResume struct {
// Args is the command that resumes the program, starting with a bare
// command name or absolute path. Required.
Args []string
// Dir is the absolute working directory to resume the program in.
// When empty, the terminal chooses one.
Dir string
}
ProgramResume describes the command and working directory used by a supporting terminal to restore the process via the Program Resume Protocol (OSC 7577) after the terminal restarts.
type ProgramState ¶
type ProgramState string
ProgramState is the state of a program reported with the Program Status Protocol (OSC 7501).
const ( ProgramStateIdle ProgramState = "idle" ProgramStateWorking ProgramState = "working" ProgramStateDone ProgramState = "done" ProgramStateBlocked ProgramState = "blocked" ProgramStateError ProgramState = "error" ProgramStateClear ProgramState = "clear" )
type ProgramStatus ¶
type ProgramStatus struct {
// State is the program state. Required.
State ProgramState
// ID addresses a record. Empty means the root record.
ID string
// App is a stable machine-readable program name.
App string
// Kind says what a blocked program waits for. Only used with ProgramStateBlocked.
Kind ProgramStatusKind
// Progress is a percentage between 0 and 100.
Progress int
// HasProgress reports whether Progress is set.
HasProgress bool
// Title is a short human-readable label for the record.
Title string
// Message is one human-readable line describing the record.
Message string
}
ProgramStatus is a report for the Program Status Protocol (OSC 7501).
type ProgramStatusKind ¶
type ProgramStatusKind string
ProgramStatusKind says what a blocked program is waiting for.
const ( ProgramStatusKindPermission ProgramStatusKind = "permission" ProgramStatusKindQuestion ProgramStatusKind = "question" ProgramStatusKindAuth ProgramStatusKind = "auth" )
type ProgressBarState ¶
type ProgressBarState uint8
ProgressBarState selects the terminal progress indicator's appearance.
const ( ProgressBarHide ProgressBarState = iota ProgressBarNormal ProgressBarError ProgressBarIndeterminate ProgressBarPaused )
type Scheduler ¶
type Scheduler interface {
// RunBackground executes a task on a background worker pool.
// The provided context is managed by the scheduler.
RunBackground(task func(ctx context.Context))
// Spawn launches a long-lived or unbounded task in its own goroutine outside
// the fixed-size worker pool, while binding its context and shutdown lifecycle
// to the scheduler.
Spawn(task func(ctx context.Context))
// QueueMicrotask schedules a task to run as a microtask on the main thread.
QueueMicrotask(task func())
// QueueMacrotask schedules a task to run as a macrotask on the main thread.
QueueMacrotask(task func())
}
Scheduler runs background work and queues tasks for the main thread.
type Terminal ¶
type Terminal interface {
// ExecProcess suspends the terminal, runs cmd to completion, and resumes rendering.
ExecProcess(context.Context, *exec.Cmd) error
// Cursor provides hardware cursor control for the current frame.
Cursor() Cursor
// Clipboard returns the host clipboard provider.
Clipboard() Clipboard
// Window provides access to the rendering loop.
Window() Window
// Scheduler provides access to the host's task queues.
Scheduler() Scheduler
// SetTitle changes the terminal window title.
SetTitle(title string)
// Bell rings the terminal bell.
Bell()
// SetProgressBar updates the terminal progress indicator.
SetProgressBar(state ProgressBarState, percentage int)
// SetProgramStatus reports the program's current status.
SetProgramStatus(status *ProgramStatus)
// SetProgramResume configures how the terminal can resume the program.
SetProgramResume(resume *ProgramResume)
// OnClose registers a callback for host shutdown.
OnClose(fn func())
// IsClosed reports whether the host has shut down.
IsClosed() bool
}
Terminal exposes the host environment attached to a document.
type Window ¶
type Window interface {
// ColorScheme returns the detected colorschema.
ColorScheme() style.ColorScheme
// RequestFrame schedules a frame as soon as the rendering loop allows.
RequestFrame()
// RequestAnimationFrame schedules fn to run once at the start of the next frame,
// receiving the host frame timestamp. Calling the returned cancel function prevents
// fn from running if it has not executed yet. Safe to call from any goroutine.
RequestAnimationFrame(fn func(now time.Time)) (cancel func())
}
Window provides frame-scheduling access to the host rendering loop.