Correct the allowed byte ranges of the APC, DCS, OSC, PM & SOS sequences. All but the SOS sequence allow additionally the bytes in the range `0x8 - 0xD` and SOS may be followed by any sequence of bytes except for SOS and ST (i.e. `\eX` & `\e\\`). Link: https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf#page=27
23 lines
743 B
Bash
Executable File
23 lines
743 B
Bash
Executable File
#!/bin/sh
|
|
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2025 Julian Prein
|
|
#
|
|
# Remove ANSI escape sequences.
|
|
#
|
|
# Additionally to the general form `\e[ -/]*[0-~]` this also tries to cover
|
|
# sequences that are followed by additional bytes (e.g. CSI, OSC). This script
|
|
# covers no C1 sequences.
|
|
#
|
|
# See:
|
|
# - https://en.wikipedia.org/wiki/ANSI_escape_code
|
|
# - https://www.ecma-international.org/wp-content/uploads/ECMA-35_6th_edition_december_1994.pdf
|
|
# - https://www.ecma-international.org/wp-content/uploads/ECMA-48_5th_edition_june_1991.pdf
|
|
|
|
env LC_ALL=C sed -E "$(printf "%b" \
|
|
's/' \
|
|
'\033\\[[0-?]*[ -/]*[@-~]' '|' \
|
|
'\033[]P^_][\010-\015 -~]*\033\\\\' '|' \
|
|
'\033X([^\033]|\033+[^\033X\\])*\033+\\\\' '|' \
|
|
'\033[ -/]*[0-~]' \
|
|
'//g')"
|