osc

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 4 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 osc implements a streaming filter that removes OSC (Operating System Command) escape sequences from a job's output.

An OSC sequence runs from ESC ] to either BEL or ST (ESC \). These address the terminal rather than the reader — window titles, clipboard writes, hyperlinks, progress reports — and are noise in a journald log, so all of them are stripped.

Progress reports are additionally reported to the caller. They have the form

ESC ] 9 ; 4 ; <state> ; <progress> BEL

and orbit republishes them as systemd unit status text.

Only OSC sequences are touched. CSI sequences — colour, cursor movement and the rest of ESC [ … — pass through untouched, so coloured build output still reads correctly in the journal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// W receives the filtered output.
	W io.Writer
	// On, if non-nil, is called for each 9;4 progress sequence recognised. For
	// states other than StateNormal the percentage may not be meaningful.
	On func(state State, pct int)
	// contains filtered or unexported fields
}

Filter is an io.Writer that passes bytes through to W with OSC sequences removed, invoking On for each 9;4 progress report it finds.

The parser is resumable: a sequence split across consecutive Write calls is still recognised. This matters because reads from a PTY chop at arbitrary buffer boundaries, so a scan that only looked within a single Write would miss roughly one sequence per buffer's worth of output.

A Filter is not safe for concurrent use.

func (*Filter) Reset

func (f *Filter) Reset()

Reset discards any partially-buffered sequence and returns the parser to its initial state. Call it once the source stream has ended.

A sequence still open at end of stream is dropped rather than emitted, so no escape byte can reach the log. The bytes discarded are bounded by maxBody, and in the pathological case — a stray ESC ] shortly before the stream ends — that much ordinary text goes with it. A sequence that overruns maxBody mid-stream is emitted verbatim instead, so the loss is confined to whatever was in flight when the job stopped writing.

func (*Filter) Write

func (f *Filter) Write(data []byte) (int, error)

Write implements io.Writer. It always reports len(data) bytes consumed on success even though fewer reach W, since returning the smaller count would make io.Copy abort with ErrShortWrite.

type State

type State int

State is the progress state reported by an OSC 9;4 sequence.

const (
	// StateClear removes any progress indication.
	StateClear State = 0
	// StateNormal is ordinary progress, with a percentage of 0-100.
	StateNormal State = 1
	// StateError indicates the operation failed.
	StateError State = 2
	// StateIndeterminate is progress of unknown duration.
	StateIndeterminate State = 3
	// StateWarning indicates progress that is stalled or degraded.
	StateWarning State = 4
)

Jump to

Keyboard shortcuts

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