Documentation
¶
Overview ¶
Package terminal contains shared terminal behavior and platform adapters.
Index ¶
- func AutomaticPresentation(format string, terminal bool, getenv func(string) string) bool
- func CloseFrame(output FrameOutput, frame string, interrupted bool) error
- func ColorProfile(w io.Writer, environ []string, terminal bool) colorprofile.Profile
- func DarkBackground(colorfgbg string) bool
- func DetachedOutputContext(ctx context.Context) context.Context
- func FishQuote(value string) string
- func FitPrompt(text string, width int) string
- func FormatCommand(args []string, shell string) string
- func GoCallerName(pid int) (string, error)
- func InlineFrame(content string, width int) string
- func IsWriterTerminal(w io.Writer) bool
- func OpenBrowser(ctx context.Context, url string) error
- func OutputCommand() *cli.Command
- func ParentProcessName() (string, error)
- func ParentShell(ctx context.Context) string
- func PowerShellQuote(value string) string
- func QuoteProperties(value string) (plain, control bool)
- func SectionDivider(width int, colors bool, fill, edge, secondary string) string
- func Sequence(text string) (sequence string, cells, read int)
- func ShellName(name string) string
- func ShellQuote(value string) string
- func ShellQuoter(shell string) func(string) string
- type BorrowedWriter
- type FrameOutput
- type FramePainter
- type Output
- type Painter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutomaticPresentation ¶
AutomaticPresentation permits terminal presentation only in automatic mode on a usable terminal outside CI. It does not query terminal state or input.
func CloseFrame ¶
func CloseFrame(output FrameOutput, frame string, interrupted bool) error
CloseFrame bounds the final cleanup write when a terminal stops accepting output. Callers remain responsible for restoring native input/output modes.
func ColorProfile ¶
ColorProfile picks the color profile for --format pretty output written to w. Lipgloss v2 styles always render full color escapes, so the output must be downsampled for its destination. This matches the lipgloss v1 behavior the CLI had before: plain text when w is not a terminal or NO_COLOR is set, and color on a terminal. Color overrides never decorate pipes or files. Callers supply terminal detection so wrapped output keeps its destination identity without exposing feature-specific writer types to this package.
func DarkBackground ¶
DarkBackground reads the explicit COLORFGBG background, defaulting to dark without querying the terminal.
func DetachedOutputContext ¶
DetachedOutputContext opts the output helper into a separate session on supported platforms, so image diagnostics survive foreground-group signals.
func FormatCommand ¶
FormatCommand formats an openai invocation. An empty result means the shell is unsupported.
func GoCallerName ¶ added in v1.40.3
GoCallerName returns the immediate caller of a Go launcher process. The caller must first verify that pid identifies its Go launcher. It does not search older ancestors or use shell configuration.
func InlineFrame ¶
InlineFrame renders content as one soft-wrapped logical terminal line.
func IsWriterTerminal ¶ added in v1.39.1
IsWriterTerminal recognizes the file and borrowed-file writers used by CLI output.
func OpenBrowser ¶
OpenBrowser opens a trusted URL with the platform browser handler. Callers select the destination and bound the context; the launcher uses direct arguments, filters the child environment, and discards handler diagnostics.
func OutputCommand ¶
OutputCommand serves the private output protocol. Assembly must register it under tokenizer to preserve the existing helper invocation used by NewOutput.
func ParentProcessName ¶
ParentProcessName returns the immediate parent process name.
func ParentShell ¶
ParentShell identifies the immediate caller. The login shell in SHELL can differ from an interactive subshell, so it is not a fallback here.
func PowerShellQuote ¶
PowerShellQuote quotes one argument for PowerShell 7.
func QuoteProperties ¶
QuoteProperties reports whether a value is shell-safe without quotes and contains controls.
func SectionDivider ¶ added in v1.45.1
SectionDivider renders the Batch browser's thin, center-bright rule.
func Sequence ¶
Sequence counts a complete printable cluster, including ASCII-led keycap emoji. text must be nonempty. ANSI's sequence decoder alone treats the leading digit as a separate byte. Taking the larger width covers both scalar and grapheme-aware terminal presentation.
func ShellQuote ¶
ShellQuote quotes one argument for Bash or zsh.
func ShellQuoter ¶
ShellQuoter returns the argument quoter for a supported shell, or nil.
Types ¶
type BorrowedWriter ¶
BorrowedWriter redirects writes while preserving a borrowed terminal's identity. Closing the adapter never closes the caller's file.
func (BorrowedWriter) Close ¶
func (w BorrowedWriter) Close() error
func (BorrowedWriter) Fd ¶
func (w BorrowedWriter) Fd() uintptr
type FrameOutput ¶
FrameOutput writes terminal frames with cancellation support.
type FramePainter ¶
FramePainter queues ordered controls and replaceable complete frames.
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output isolates terminal writes in one disposable process. The original terminal remains borrowed for geometry and mode restoration.
type Painter ¶
type Painter struct {
// contains filtered or unexported fields
}
Painter keeps terminal backpressure outside the editor's event loop. Initialization controls retain order; only a superseded complete frame can be discarded.
func NewPainter ¶
func NewPainter(output FrameOutput, onFailure context.CancelFunc) *Painter
NewPainter starts a painter that invokes onFailure when output fails.