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.
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 )