highlight

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package highlight renders safe, line-oriented ANSI emphasis for terminal output.

It is deliberately a presentation-only layer. Callers retain the original terminal bytes in Session and pass a separate output stream to Renderer. Its WinTerm-inspired semantic theme adapts to the local terminal's TrueColor, 256-color, or 16-color capability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasBootloaderPromptPrefix added in v0.4.0

func HasBootloaderPromptPrefix(line []byte) bool

HasBootloaderPromptPrefix recognizes a plain line starting with "=> " or a name followed by "> ", including an already echoed command. Trailing prompt whitespace is required so an incomplete marker cannot trigger recognition. This is only a presentation heuristic, never evidence of device boot state. Timestamp and highlighting renderers share it to avoid buffering each other.

func HasInteractivePromptPrefix added in v0.4.2

func HasInteractivePromptPrefix(line []byte) bool

HasInteractivePromptPrefix recognizes prompts that must be emitted raw, without adding a shell timestamp. It is a local presentation heuristic, not evidence of boot state or permission to send input. Both presentation layers share this predicate so neither withholds a recognized interactive line.

Types

type Option

type Option func(*Renderer)

Option configures one Renderer.

func WithColorProfile

func WithColorProfile(profile termenv.Profile) Option

WithColorProfile selects the ANSI color capability used for generated presentation styles. Callers should select the profile from the local output terminal; it does not describe the remote terminal.

type Renderer

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

Renderer incrementally renders terminal text to one local output stream.

Renderer is not safe for concurrent use. One attached terminal client must own one Renderer and serialize Write and Flush calls around any unrelated local status output. ReleasePending must use the same serialization. It never modifies the caller's input slice.

func New

func New(output io.Writer, options ...Option) *Renderer

New creates a Renderer that writes styled terminal output to output. It uses TrueColor unless an Option selects another local color profile.

A nil output discards rendered bytes. It is useful for callers that need to exercise parser behavior without a local terminal writer.

func (*Renderer) Flush

func (r *Renderer) Flush() error

Flush writes any incomplete terminal line and ends prompt-echo state. Callers invoke it before local status output or orderly disconnect so later remote prompts are rendered independently and output remains ordered.

func (*Renderer) ReleasePending added in v0.4.2

func (r *Renderer) ReleasePending() error

ReleasePending emits an incomplete line raw and keeps subsequent bytes raw until newline. Interactive callers use it periodically so an unknown prompt never waits indefinitely for Enter. Unlike Flush, this does not establish a local status boundary or reset remote VT state. An empty buffer is a no-op.

func (*Renderer) Write

func (r *Renderer) Write(p []byte) (int, error)

Write accepts terminal bytes and forwards complete safe lines with ANSI emphasis. Unsafe line controls are forwarded unchanged. Remote escape sequences switch presentation to byte-transparent output until their line and any persistent SGR or alternate-screen state safely end.

A recognized shell or bootloader prompt is emitted before a newline so the remote console remains interactive. The following echoed command is forwarded unchanged until its newline.

Jump to

Keyboard shortcuts

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