core

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxArticleBodyBytes           int64 = 16 << 20
	MaxReadabilityElements              = 500_000
	MaxHARRequestBodyBytes        int64 = 16 << 20
	MaxHARResponseBodyBytes       int64 = 16 << 20
	MaxWebSocketMessageBytes      int64 = 16 << 20
	MaxWebSocketPipedTextLine     int64 = 16 << 20
	MaxWebSocketInteractiveEntry  int64 = 16 << 20
	MaxStreamingRecordBytes       int64 = 16 << 20
	MaxCompositeMaterialization   int64 = 16 << 20
	MaxGRPCMessageBytes           int64 = 64 << 20
	MaxReflectionMessages               = 128
	MaxReflectionBytes            int64 = 64 << 20
	MaxProtobufDescriptorSetBytes int64 = 64 << 20
	MaxProtocOutputBytes          int64 = 64 << 10
	MaxNestingDepth                     = 128
	MaxClipboardBytes             int64 = 1 << 20
	MaxFormatterNestingDepth            = 1024
	MaxDOHWireResponseBytes       int64 = 65_535
	MaxDOHJSONResponseBytes       int64 = 1 << 20
	MaxUpdaterReleaseMetadata     int64 = 1 << 20
	MaxUpdaterChecksumSidecar     int64 = 1 << 10
	MaxUpdaterArtifact            int64 = 128 << 20
	MaxUpdaterUnpackedData        int64 = 512 << 20
	MaxUpdaterArchiveEntries            = 128
	MaxDryRunBodyPreview          int64 = 1_024
	MaxRetries                          = 100
	MaxRetryAfter                       = 30 * time.Second
	MaxUpdateRedirects                  = 10
	DefaultDOHTimeout                   = 5 * time.Second
	DefaultProtocTimeout                = 10 * time.Second
)

Shared resource limits. Keep feature-specific limits here so callers and tests use the same security boundary instead of duplicating constants.

View Source
const (
	// MaxFormattedBodyBytes is the existing cap for complete response
	// formatting and clipboard capture.
	MaxFormattedBodyBytes = 1 << 20

	// Schema-less protobuf has no descriptor to provide structural bounds.
	// Keep recursive interpretation and aggregate field work bounded even when
	// the caller supplies a large protocol message.
	MaxSchemaLessProtobufFields = 1_000_000

	// Descriptive aliases keep call sites self-documenting while preserving
	// one canonical value for each limit.
	MaxCompositeMaterializationBytes = MaxCompositeMaterialization
	MaxUpdaterReleaseMetadataBytes   = MaxUpdaterReleaseMetadata
	MaxUpdaterChecksumSidecarBytes   = MaxUpdaterChecksumSidecar
	MaxUpdaterArtifactBytes          = MaxUpdaterArtifact
	MaxUpdaterUnpackedDataBytes      = MaxUpdaterUnpackedData
	MaxDryRunBodyPreviewBytes        = MaxDryRunBodyPreview
)
View Source
const InterruptedExitCode = 130

Variables

View Source
var (
	IsStdinTerm    bool
	IsStderrTerm   bool
	IsStdoutTerm   bool
	NoSelfUpdate   bool
	PackageManager string

	UserAgent string
	Version   string
)
View Source
var ErrLimitExceeded = errors.New("resource limit exceeded")

ErrLimitExceeded identifies an input that exceeded a bounded operation.

Functions

func AppendTerminalSafeBytes added in v0.28.0

func AppendTerminalSafeBytes(dst, src []byte) []byte

AppendTerminalSafeBytes appends src after escaping terminal control characters and invalid UTF-8. Newlines and tabs are retained. The destination can be reused by callers that sanitize a stream repeatedly.

func BuildTLSConfig added in v0.28.0

func BuildTLSConfig(options TLSConfigOptions) *tls.Config

BuildTLSConfig builds an independent TLS configuration using the platform verifier by default. Custom roots are added to, rather than substituted for, the system roots. The returned configuration can be used as a template and must be cloned before a connection-specific mutation.

func CheckedAddInt added in v0.28.0

func CheckedAddInt(a, b int) (int, bool)

CheckedAddInt returns false when a+b would overflow int.

func CheckedAddInt64 added in v0.28.0

func CheckedAddInt64(a, b int64) (int64, bool)

CheckedAddInt64 returns false when a+b would overflow int64.

func CheckedAddUint64 added in v0.28.0

func CheckedAddUint64(a, b uint64) (uint64, bool)

CheckedAddUint64 returns false when a+b would overflow uint64.

func CheckedInt64ToInt added in v0.28.0

func CheckedInt64ToInt(v int64) (int, bool)

CheckedInt64ToInt converts v only when it is representable as int.

func CheckedInt64ToUint64 added in v0.28.0

func CheckedInt64ToUint64(v int64) (uint64, bool)

CheckedInt64ToUint64 converts v only when it is non-negative.

func CheckedIntToInt64 added in v0.28.0

func CheckedIntToInt64(v int) (int64, bool)

CheckedIntToInt64 converts v only on platforms where int fits in int64.

func CheckedIntToUint64 added in v0.28.0

func CheckedIntToUint64(v int) (uint64, bool)

CheckedIntToUint64 converts v only when it is non-negative.

func CheckedMulInt added in v0.28.0

func CheckedMulInt(a, b int) (int, bool)

CheckedMulInt returns false when a*b would overflow int. Negative values are accepted so callers can use this helper for general size arithmetic.

func CheckedUint64ToInt added in v0.28.0

func CheckedUint64ToInt(v uint64) (int, bool)

CheckedUint64ToInt converts v only when it is representable as int.

func CheckedUint64ToInt64 added in v0.28.0

func CheckedUint64ToInt64(v uint64) (int64, bool)

CheckedUint64ToInt64 converts v only when it is representable as int64.

func CutTrimmed added in v0.20.0

func CutTrimmed(s, sep string) (string, string, bool)

CutTrimmed splits s around the first instance of sep, returning the trimmed text before and after sep.

func DetectContentType added in v0.14.0

func DetectContentType(r io.Reader, filename string) (io.Reader, string, error)

func GetBuildInfo

func GetBuildInfo(verbose ...bool) []byte

GetBuildInfo returns JSON encoded build information for the executable. Dependencies are included only when verbose is true. The variadic argument preserves the old internal call form while allowing metadata commands to match the concise and verbose build-info modes.

func GetTerminalCols added in v0.16.0

func GetTerminalCols() int

GetTerminalCols returns the number of columns in the terminal, or 0 if unavailable.

func GetVCSRevision added in v0.19.0

func GetVCSRevision() string

GetVCSRevision returns the git commit hash from Go's embedded build info.

func IsBrokenPipe added in v0.28.0

func IsBrokenPipe(err error) bool

IsBrokenPipe reports whether an output operation failed because its reader closed the pipe. Callers should treat this as successful early termination.

func IsSensitiveHeader added in v0.28.0

func IsSensitiveHeader(name string) bool

IsSensitiveHeader reports whether a header contains a credential or session value that must not be printed in diagnostics. In addition to the standard credential headers, a component-aware classifier covers user-defined names such as X-API-Key and X-ClientSecret without treating X-KeyboardLayout as a credential header merely because it contains the letters "key".

func IsSensitiveQueryKey added in v0.28.0

func IsSensitiveQueryKey(name string) bool

IsSensitiveQueryKey reports whether a query key is likely to contain a credential. Matching is case-insensitive and covers compound names such as api_key, access_token, clientSecret, and request-signature.

func JoinIPHostPort added in v0.28.0

func JoinIPHostPort(address net.IPAddr, port string) string

JoinIPHostPort formats an IP address without discarding its IPv6 zone.

func LimitedReader added in v0.28.0

func LimitedReader(r io.Reader, max int64) io.Reader

LimitedReader returns a reader that permits at most max bytes plus one. The extra byte lets callers distinguish an exact-limit input from an overflow without reading unbounded input.

func NewCancelledError added in v0.28.0

func NewCancelledError(cause error) error

func NewCategoryError added in v0.28.0

func NewCategoryError(category ErrorCategory, cause error) error

func NewNetworkError added in v0.28.0

func NewNetworkError(cause error) error

func NewPartialError added in v0.28.0

func NewPartialError(cause error) error

func NewRemoteError added in v0.28.0

func NewRemoteError(cause error) error

func NewUpdateNoOpError added in v0.28.0

func NewUpdateNoOpError(cause error) error

func NewUsageError added in v0.28.0

func NewUsageError(cause error) error

func ParseSeconds added in v0.28.0

func ParseSeconds(value string) (time.Duration, error)

ParseSeconds parses a non-negative number of seconds into a duration. Zero means no timeout. Fractional seconds are truncated to nanoseconds; negative, NaN, infinite, and overflowing values are rejected.

func ReadAllLimited added in v0.28.0

func ReadAllLimited(r io.Reader, max int64, subsystem string) ([]byte, error)

ReadAllLimited reads up to max bytes and reports a LimitError if one more byte is available. It is intended for explicitly bounded materialization, not ordinary streaming response paths.

func RedactHeaderValue added in v0.28.0

func RedactHeaderValue(name, value string) string

RedactHeaderValue replaces sensitive header values with a stable marker.

func RedactedErrorText added in v0.28.0

func RedactedErrorText(err error) string

RedactedErrorText returns a terminal-safe error message with URLs carried by url.Error values redacted. Transport errors commonly include the complete request URL in their Error string, so sanitizing only the request metadata is not sufficient.

func RedactedQuery added in v0.28.0

func RedactedQuery(rawQuery string) string

RedactedQuery returns a query string with values for sensitive keys replaced while preserving the original key spelling, ordering, duplicate fields, and non-sensitive encoding. The classifier intentionally errs on the side of hiding values when a key contains a credential-related term.

func RedactedURL added in v0.28.0

func RedactedURL(u *url.URL) string

RedactedURL returns a terminal-safe URL with userinfo and sensitive query values removed. URL userinfo and query values are authentication sources that must not appear in diagnostics.

func SignalExitCode added in v0.28.0

func SignalExitCode(err error) (int, bool)

SignalExitCode returns the stable process status for a signal cause. Ctrl-C follows the conventional shell status 128+SIGINT; termination signals remain ordinary runtime failures.

func TLSVerificationName added in v0.28.0

func TLSVerificationName(host string) string

TLSVerificationName returns the certificate-verification name for a host. It removes URL brackets, IPv6 zone identifiers, and a DNS root dot. Go's TLS implementation uses an IP ServerName for SAN verification but omits that IP from the SNI extension.

func TerminalSafeBytes added in v0.28.0

func TerminalSafeBytes(src []byte) []byte

TerminalSafeBytes returns src when it is already safe, or a sanitized copy otherwise. It is the byte-oriented equivalent of TerminalSafeText.

func TerminalSafeText added in v0.28.0

func TerminalSafeText(s string) string

TerminalSafeText converts untrusted text into a representation that cannot inject terminal control sequences. Newlines and tabs are retained because they are useful diagnostic layout characters; all other C0/C1 controls and invalid UTF-8 are escaped.

func ValidateECHPolicy added in v0.28.0

func ValidateECHPolicy(mode ECHMode, httpVersion HTTPVersion, min, max uint16) error

ValidateTLSVersions validates the TLS bounds accepted by fetch. A zero minimum means the secure TLS 1.2 default, and a zero maximum means no cap. ValidateECHPolicy validates the ECH mode before any network operation. The mode is deliberately independent from the TLS handshake implementation so transports cannot silently weaken an explicit policy.

A zero TLS bound means that the caller did not set that bound. In that case ECH may raise the effective minimum to TLS 1.3. An explicit TLS 1.2 bound is a configuration conflict because it permits a handshake that cannot carry ECH.

func ValidateTLSVersions added in v0.28.0

func ValidateTLSVersions(min, max uint16) error

func WriteErrorMsg added in v0.7.4

func WriteErrorMsg(p *Printer, err error)

WriteErrorMsg writes the provided error to the printer.

func WriteErrorMsgNoFlush added in v0.7.4

func WriteErrorMsgNoFlush(p *Printer, err error)

WriteErrorMsgNoFlush writes the provided error msg to the printer, but does not flush the printer.

func WriteInfoMsg added in v0.7.4

func WriteInfoMsg(p *Printer, msg string)

WriteInfoMsg writes the provided info msg to the printer.

func WriteWarningMsg added in v0.7.4

func WriteWarningMsg(p *Printer, msg string)

WriteWarningMsg writes the provided warning msg to the printer.

func WriteWarningMsgIf added in v0.28.0

func WriteWarningMsgIf(p *Printer, msg string, silent bool)

WriteWarningMsgIf writes a warning unless silent mode is enabled.

Types

type BoundedBuffer added in v0.28.0

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

BoundedBuffer is an io.Writer that never retains more than max bytes.

func NewBoundedBuffer added in v0.28.0

func NewBoundedBuffer(max int64, subsystem string) *BoundedBuffer

func (*BoundedBuffer) Bytes added in v0.28.0

func (b *BoundedBuffer) Bytes() []byte

func (*BoundedBuffer) Len added in v0.28.0

func (b *BoundedBuffer) Len() int

func (*BoundedBuffer) Reset added in v0.28.0

func (b *BoundedBuffer) Reset()

func (*BoundedBuffer) Write added in v0.28.0

func (b *BoundedBuffer) Write(p []byte) (int, error)

type Budget added in v0.28.0

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

Budget is an immutable wall-clock budget. A zero duration is unlimited; every finite child operation observes the same absolute deadline.

func NewBudget added in v0.28.0

func NewBudget(timeout time.Duration) (Budget, error)

NewBudget creates a budget starting at the current wall-clock time.

func NewBudgetAt added in v0.28.0

func NewBudgetAt(timeout time.Duration, start time.Time) (Budget, error)

NewBudgetAt creates a budget with an injectable start time for deterministic tests. Negative durations are invalid; zero means no deadline.

func NewBudgetFromOptional added in v0.28.0

func NewBudgetFromOptional(timeout *time.Duration) (Budget, error)

NewBudgetFromOptional treats nil as an unlimited budget. It is convenient for configuration fields where absence and an explicit zero both disable a timeout.

func NewBudgetFromOptionalAt added in v0.28.0

func NewBudgetFromOptionalAt(timeout *time.Duration, start time.Time) (Budget, error)

NewBudgetFromOptionalAt is the injectable-clock form of NewBudgetFromOptional.

func (Budget) Check added in v0.28.0

func (b Budget) Check(phase string) error

Check reports a timeout when the budget is exhausted. It is an explicit checkpoint for operations that do not yet derive a context.

func (Budget) Child added in v0.28.0

func (b Budget) Child(phase string) BudgetChild

Child returns a budget view with the same immutable deadline. The phase is used only when the child derives a context or reports its timeout.

func (Budget) ConnectionTimeoutError added in v0.28.0

func (b Budget) ConnectionTimeoutError(phase string) error

ConnectionTimeoutError returns the connection-scoped form of the budget error while retaining the same absolute deadline.

func (Budget) Deadline added in v0.28.0

func (b Budget) Deadline() (time.Time, bool)

Deadline returns the absolute deadline, if this budget is finite.

func (Budget) Err added in v0.28.0

func (b Budget) Err() error

Err returns nil while the budget remains available, or its stable timeout error after exhaustion.

func (Budget) ErrAt added in v0.28.0

func (b Budget) ErrAt(now time.Time, phase string) error

ErrAt is Err with an injected clock and optional phase label.

func (Budget) Expired added in v0.28.0

func (b Budget) Expired() bool

Expired reports whether a finite budget has elapsed.

func (Budget) Limited added in v0.28.0

func (b Budget) Limited() bool

Limited reports whether this budget has a finite deadline.

func (Budget) Remaining added in v0.28.0

func (b Budget) Remaining() (time.Duration, bool)

Remaining returns the time left and whether the budget is finite. An exhausted finite budget returns zero and true; an unlimited budget returns zero and false.

func (Budget) RemainingAt added in v0.28.0

func (b Budget) RemainingAt(now time.Time) (time.Duration, bool)

RemainingAt is Remaining with an injected clock for deterministic tests.

func (Budget) TimeoutError added in v0.28.0

func (b Budget) TimeoutError(phase string) error

TimeoutError returns the stable error for an exhausted budget.

func (Budget) WithConnectionContext added in v0.28.0

func (b Budget) WithConnectionContext(parent context.Context, phase string) (context.Context, context.CancelFunc)

WithConnectionContext derives a context whose timeout is reported as a connection timeout. It shares the same absolute deadline as WithContext.

func (Budget) WithContext added in v0.28.0

func (b Budget) WithContext(parent context.Context, phase string) (context.Context, context.CancelFunc)

WithContext derives a cancellable context that observes this budget. If a parent deadline is earlier, it is preserved rather than being reset.

type BudgetChild added in v0.28.0

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

BudgetChild associates a diagnostic phase with an existing budget without creating a new deadline.

func (BudgetChild) Err added in v0.28.0

func (c BudgetChild) Err() error

func (BudgetChild) Remaining added in v0.28.0

func (c BudgetChild) Remaining() (time.Duration, bool)

func (BudgetChild) WithContext added in v0.28.0

func (c BudgetChild) WithContext(parent context.Context) (context.Context, context.CancelFunc)

type CategoryError added in v0.28.0

type CategoryError struct {
	Category ErrorCategory
	Err      error
}

CategoryError adds stable classification while preserving the underlying error for errors.Is/errors.As and for useful diagnostics.

func (CategoryError) Error added in v0.28.0

func (err CategoryError) Error() string

func (CategoryError) Is added in v0.28.0

func (err CategoryError) Is(target error) bool

func (CategoryError) Unwrap added in v0.28.0

func (err CategoryError) Unwrap() error

type Color

type Color int

Color represents the options for enabling or disabling color output.

const (
	ColorUnknown Color = iota
	ColorAuto
	ColorOn
	ColorOff
)

type CompressionMode added in v0.28.0

type CompressionMode int

CompressionMode controls request content-encoding negotiation and response decoding. Unknown means no explicit setting was supplied.

const (
	CompressionUnknown CompressionMode = iota
	CompressionAuto
	CompressionBrotli
	CompressionGzip
	CompressionZstd
	CompressionOff
)

type ECHMode added in v0.28.0

type ECHMode int

ECHMode controls Encrypted ClientHello discovery and use.

const (
	ECHUnknown ECHMode = iota
	ECHAuto
	ECHOn
	ECHOff
)

type ErrConnectionTimedOut added in v0.28.0

type ErrConnectionTimedOut struct {
	Timeout time.Duration
}

ErrConnectionTimedOut represents an exhausted connection-establishment budget. It intentionally has a separate top-level message from request body/response timeouts.

func (ErrConnectionTimedOut) Error added in v0.28.0

func (err ErrConnectionTimedOut) Error() string

type ErrRequestTimedOut

type ErrRequestTimedOut struct {
	Timeout time.Duration
}

ErrRequestTimedOut represents the error when the request times out.

func (ErrRequestTimedOut) Error

func (err ErrRequestTimedOut) Error() string

type ErrorCategory added in v0.28.0

type ErrorCategory uint8

ErrorCategory identifies the stable class of an operation failure.

const (
	CategoryUnknown ErrorCategory = iota
	CategoryUsage
	CategoryNetwork
	CategoryRemote
	CategoryPartial
	CategoryCancelled
	CategoryUpdateNoOp
)

func CategoryOf added in v0.28.0

func CategoryOf(err error) ErrorCategory

func (ErrorCategory) String added in v0.28.0

func (category ErrorCategory) String() string

type FileNotExistsError added in v0.11.0

type FileNotExistsError string

func (FileNotExistsError) Error added in v0.11.0

func (err FileNotExistsError) Error() string

func (FileNotExistsError) PrintTo added in v0.11.0

func (err FileNotExistsError) PrintTo(p *Printer)

type Format

type Format int

Format represents the options for enabling or disabling formatting.

const (
	FormatUnknown Format = iota
	FormatAuto
	FormatOff
	FormatOn
)

type HTTPVersion

type HTTPVersion int

HTTPVersion represents the options for the maximum allowed HTTP version.

const (
	HTTPDefault HTTPVersion = iota
	HTTP1
	HTTP2
	HTTP3
)

func (HTTPVersion) String added in v0.19.0

func (v HTTPVersion) String() string

String returns the HTTP version string (e.g. "HTTP/1.1").

type Handle

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

Handle represents a handle for stderr and stdout Printers.

func NewHandle

func NewHandle(c Color) *Handle

NewHandle returns a new Handle given the provided color configuration.

func (*Handle) Stderr

func (h *Handle) Stderr() *Printer

Stderr returns the Printer for stderr.

func (*Handle) Stdout

func (h *Handle) Stdout() *Printer

Stdout returns the Printer for stdout.

type ImageSetting added in v0.8.0

type ImageSetting int

ImageSetting represents the options for displaying images.

const (
	ImageUnknown ImageSetting = iota
	ImageAuto
	ImageNative
	ImageExternal
	ImageOff
)

type KeyVal

type KeyVal[T any] struct {
	Key string
	Val T
}

KeyVal represents a generic key & value struct.

type LimitError added in v0.28.0

type LimitError struct {
	Subsystem string
	Limit     int64
}

LimitError reports a bounded operation that exceeded its configured limit. The subsystem is included in the message so a user can identify which operation needs a smaller input or a streaming path.

func (LimitError) Error added in v0.28.0

func (err LimitError) Error() string

func (LimitError) Unwrap added in v0.28.0

func (err LimitError) Unwrap() error

type PagerMode added in v0.28.0

type PagerMode int

PagerMode controls whether formatted terminal output may use a pager.

const (
	PagerUnknown PagerMode = iota
	PagerAuto
	PagerOn
	PagerOff
)

type Printer

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

Printer allows for writing data with optional ANSI escape sequences based on the color settings for a target.

func TestPrinter added in v0.20.0

func TestPrinter(useColor bool) *Printer

TestPrinter returns a Printer suitable for testing. All output, including flushed data, is captured and accessible via Bytes.

func TestTerminalPrinter added in v0.28.0

func TestTerminalPrinter(useColor bool) *Printer

TestTerminalPrinter returns a Printer that behaves like a terminal. It is useful for testing terminal-only presentation such as OSC 8 hyperlinks.

func (*Printer) Bytes

func (p *Printer) Bytes() []byte

Bytes returns the current contents of the buffer. For test printers created with TestPrinter, this also includes previously flushed data.

func (*Printer) Discard added in v0.19.0

func (p *Printer) Discard()

Discard clears the buffer without writing to the underlying file. A bounded printer also starts a new bounded transaction.

func (p *Printer) EndHyperlink()

EndHyperlink closes the most recently started OSC 8 terminal hyperlink.

func (*Printer) Err added in v0.28.0

func (p *Printer) Err() error

Err returns the first limit error recorded by a bounded printer.

func (*Printer) Flush

func (p *Printer) Flush() error

Flush writes any buffered data to the underlying file.

func (*Printer) IsTerminal added in v0.28.0

func (p *Printer) IsTerminal() bool

IsTerminal reports whether this printer targets a terminal. Formatting code can use this to select presentation that should not appear in pipes or files.

func (*Printer) NewBoundedWriter added in v0.28.0

func (p *Printer) NewBoundedWriter(w io.Writer, max int64, subsystem string) *Printer

NewBoundedWriter returns a printer that accepts at most max bytes in total. Writes after the limit are discarded and Err reports the limit error. It is useful for formatters that must materialize output before appending it atomically to another printer.

func (*Printer) NewWriter added in v0.28.0

func (p *Printer) NewWriter(w io.Writer) *Printer

NewWriter returns a printer with the same color policy as p and a different output writer. It is useful for streaming formatters that must write through an intermediate sink, such as a pager, without buffering the response.

func (*Printer) Read

func (p *Printer) Read(b []byte) (int, error)

Read reads from the buffer.

func (*Printer) Reset

func (p *Printer) Reset()

Reset resets any active escape sequences.

func (*Printer) Set

func (p *Printer) Set(s Sequence)

Set writes the provided Sequence.

func (p *Printer) StartHyperlink(url string) bool

StartHyperlink begins an OSC 8 terminal hyperlink for url. It returns true when a hyperlink was emitted. URLs containing terminal controls are rejected so untrusted Markdown cannot inject an OSC sequence.

func (*Printer) Write

func (p *Printer) Write(b []byte) (int, error)

Write writes the provided data to the buffer.

func (*Printer) WriteInfoPrefix added in v0.19.0

func (p *Printer) WriteInfoPrefix()

WriteInfoPrefix writes a dim "* " prefix for informational lines.

func (*Printer) WriteRequestPrefix added in v0.19.0

func (p *Printer) WriteRequestPrefix()

WriteRequestPrefix writes a dim "> " prefix for request lines.

func (*Printer) WriteResponsePrefix added in v0.19.0

func (p *Printer) WriteResponsePrefix()

WriteResponsePrefix writes a dim "< " prefix for response lines.

func (*Printer) WriteRune

func (p *Printer) WriteRune(r rune) (int, error)

WriteRune writes the provided rune to the buffer.

func (*Printer) WriteString

func (p *Printer) WriteString(s string) (int, error)

WriteString writes trusted string data to the buffer.

func (*Printer) WriteStringUntrusted added in v0.28.0

func (p *Printer) WriteStringUntrusted(s string) (int, error)

WriteStringUntrusted writes a string after escaping terminal control characters. Newlines and tabs are retained.

func (*Printer) WriteTo

func (p *Printer) WriteTo(w io.Writer) (int64, error)

WriteTo writes the buffered data to the provided io.Writer.

func (*Printer) WriteUntrusted added in v0.28.0

func (p *Printer) WriteUntrusted(b []byte) (int, error)

WriteUntrusted writes bytes after escaping terminal control characters.

type PrinterTo

type PrinterTo interface {
	PrintTo(*Printer)
}

PrinterTo represents the interface for printing to a Printer.

type Sequence

type Sequence string

Sequence represents an ANSI escape sequence.

const (
	Bold      Sequence = "1"
	Dim       Sequence = "2"
	Italic    Sequence = "3"
	Underline Sequence = "4"

	Black   Sequence = "30"
	Red     Sequence = "31"
	Green   Sequence = "32"
	Yellow  Sequence = "33"
	Blue    Sequence = "34"
	Magenta Sequence = "35"
	Cyan    Sequence = "36"
	White   Sequence = "37"
	Default Sequence = "39"
)

type SignalError

type SignalError string

SignalError represents the error when a signal is caught.

func (SignalError) Error

func (err SignalError) Error() string

type TLSConfigOptions added in v0.28.0

type TLSConfigOptions struct {
	Base       *tls.Config
	CACerts    []*x509.Certificate
	ClientCert *tls.Certificate
	Insecure   bool
	TLSMax     uint16
	TLSMin     uint16
	ServerName string
	NextProtos []string
}

TLSConfigOptions contains the settings shared by every TLS client in fetch. Base is cloned before any option is applied, so callers can safely reuse the returned configuration as a template for a connection.

type TerminalSize added in v0.16.0

type TerminalSize struct {
	Cols     int // Number of columns (characters)
	Rows     int // Number of rows (characters)
	WidthPx  int // Width in pixels (0 if unavailable)
	HeightPx int // Height in pixels (0 if unavailable)
}

TerminalSize represents the dimensions of the terminal.

func GetTerminalSize added in v0.16.0

func GetTerminalSize() (TerminalSize, error)

GetTerminalSize returns the terminal size, or an error if unavailable.

type TimeoutError added in v0.28.0

type TimeoutError struct {
	Duration   time.Duration
	Phase      string
	Connection bool
}

TimeoutError is the common budget timeout error. It unwraps to the legacy timeout type so existing retry and presentation code remains compatible.

func (TimeoutError) Error added in v0.28.0

func (err TimeoutError) Error() string

func (TimeoutError) Temporary added in v0.28.0

func (err TimeoutError) Temporary() bool

func (TimeoutError) Timeout added in v0.28.0

func (err TimeoutError) Timeout() bool

func (TimeoutError) Unwrap added in v0.28.0

func (err TimeoutError) Unwrap() error

type ValueError

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

func NewValueError

func NewValueError(option, value, usage string, isFile bool) *ValueError

func (*ValueError) Error

func (err *ValueError) Error() string

func (*ValueError) PrintTo

func (err *ValueError) PrintTo(p *Printer)

type Verbosity

type Verbosity int

Verbosity represents how verbose the output should be.

const (
	VSilent Verbosity = iota
	VNormal
	VVerbose
	VExtraVerbose
	VDebug
)

type WSInteractiveMode added in v0.23.1

type WSInteractiveMode int

WSInteractiveMode represents WebSocket terminal prompt behavior.

const (
	WSInteractiveAuto WSInteractiveMode = iota
	WSInteractiveOn
	WSInteractiveOff
)

type WSMessageMode added in v0.28.0

type WSMessageMode int

WSMessageMode controls how WebSocket payloads are interpreted.

const (
	WSMessageAuto WSMessageMode = iota
	WSMessageText
	WSMessageBinary
)

func (WSMessageMode) String added in v0.28.0

func (m WSMessageMode) String() string

String returns the user-facing WebSocket message mode name.

type WarningWriter added in v0.28.0

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

WarningWriter is the shared warning path for operations that may emit warnings alongside streamed output. It suppresses nonessential warnings in silent mode and guarantees one trailing newline per warning.

func NewWarningWriter added in v0.28.0

func NewWarningWriter(p *Printer, silent bool) *WarningWriter

NewWarningWriter creates a warning writer for p.

func (*WarningWriter) AfterBody added in v0.28.0

func (w *WarningWriter) AfterBody() error

AfterBody terminates a body line before a following warning or diagnostic.

func (*WarningWriter) BeforeBody added in v0.28.0

func (w *WarningWriter) BeforeBody() error

BeforeBody separates diagnostics from body output when both are written to the same presentation stream.

func (*WarningWriter) Write added in v0.28.0

func (w *WarningWriter) Write(msg string) error

Write emits a terminal-safe warning unless silent mode is enabled.

Jump to

Keyboard shortcuts

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