termfeatures

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package termfeatures provides safe, cross-platform terminal feature detection and operations for window title management.

Index

Constants

This section is empty.

Variables

View Source
var ErrDumbTerminal = errors.New("dumb terminal: no escape sequence support")

ErrDumbTerminal indicates the terminal doesn't support escape sequences.

Functions

This section is empty.

Types

type Capabilities

type Capabilities struct {
	// Terminal identification
	Term        string // TERM environment variable
	TermProgram string // TERM_PROGRAM environment variable

	// Feature support
	WindowTitle FeatureSupport

	// Environment context
	IsSSH    bool
	IsTmux   bool
	IsScreen bool
	IsDumb   bool
}

Capabilities describes the terminal's feature support.

type FeatureSupport

type FeatureSupport int

FeatureSupport indicates the level of support for a terminal feature.

const (
	// FeatureUnsupported indicates the feature is not supported.
	FeatureUnsupported FeatureSupport = iota
	// FeatureNative indicates the feature is supported via escape sequences.
	FeatureNative
	// FeatureUnknown indicates the feature may work but is not confirmed.
	FeatureUnknown
)

func (FeatureSupport) String

func (f FeatureSupport) String() string

String returns a string representation of FeatureSupport.

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

Terminal provides safe terminal operations with automatic capability detection.

func New

func New() *Terminal

New creates a new Terminal with automatic capability detection.

func NewWithOutput

func NewWithOutput(output *termenv.Output) *Terminal

NewWithOutput creates a new Terminal with the specified termenv output.

func (*Terminal) Capabilities

func (t *Terminal) Capabilities() Capabilities

Capabilities returns the detected terminal capabilities.

func (*Terminal) ResetWindowTitle

func (t *Terminal) ResetWindowTitle() TitleResult

ResetWindowTitle restores the default window title. Implementation varies by terminal; may be no-op on some terminals.

func (*Terminal) SetWindowTitle

func (t *Terminal) SetWindowTitle(title string) TitleResult

SetWindowTitle sets the terminal window title. Safe to call even if unsupported (no-op).

func (*Terminal) SetWindowTitlef

func (t *Terminal) SetWindowTitlef(format string, args ...any) TitleResult

SetWindowTitlef sets the title with fmt.Sprintf formatting.

func (*Terminal) SupportsWindowTitle

func (t *Terminal) SupportsWindowTitle() bool

SupportsWindowTitle returns true if the terminal supports window title setting.

type TitleResult

type TitleResult struct {
	Success bool
	Method  string // "osc2", "none"
	Error   error
}

TitleResult contains information about a window title operation.

Jump to

Keyboard shortcuts

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