package termtest

import "github.com/dotcloud/docker/integration/internal/termtest"

Index

Functions

func StripANSICommands

func StripANSICommands(s string, opts ...ansiterm.Option) (string, error)

StripANSICommands attempts to strip ANSI console escape and control sequences from s, returning a string containing only the final printed characters which would be visible onscreen if the string was to be processed by a terminal emulator. Basic cursor positioning and screen erase control sequences are parsed and processed such that the output of simple CLI commands passed through a Windows Pseudoterminal and then this function yields the same string as if the output of those commands was redirected to a file.

The only correct way to represent the result of processing ANSI console output would be a two-dimensional array of an emulated terminal's display buffer. That would be awkward to test against, so this function instead attempts to render to a one-dimensional string without extra padding. This is an inherently lossy process, and any attempts to render a string containing many cursor positioning commands are unlikely to yield satisfactory results. Handlers for several ANSI control sequences are also unimplemented; attempts to parse a string containing one will panic.

Source Files

stripansi.go

Version
v28.1.1+incompatible (latest)
Published
Apr 18, 2025
Platform
linux/amd64
Imports
2 packages
Last checked
6 hours ago

Tools for package owners.