Commit eaaab835 authored by Vitaly Lipatov's avatar Vitaly Lipatov

common: add faketty() and stripcolors(), remove colorify()

faketty() runs command in a pseudo-tty via script(1) to preserve colored output through pipes. stripcolors() removes ANSI color codes and OSC 8 hyperlinks from input for clean log files. Removed colorify() which required csed and was less effective.
parent 2526283c
......@@ -23,17 +23,18 @@ subst()
fi
if which csed 2>/dev/null >/dev/null ; then
colorify()
# Run command in a fake tty to preserve colored output through pipes
# Usage: faketty "command with arguments"
faketty()
{
a= csed '/(warning|WARNING|Warning|предупреждение):/ p magenta,bold' '/(error|ERROR|Error|ошибка):/ p red,bold' '/(Command not found):/ p red,bold'
script -q -e -c "$*" /dev/null
}
else
colorify()
# Strip ANSI color codes and OSC 8 hyperlinks from input
stripcolors()
{
cat
sed -e $'s/\x1b\\[[0-9;]*[mK]//g' -e $'s/\x1b\\]8;;[^\x1b]*\x1b\\\\\\\\//g' -e $'s/\x1b\\]8;;[^\x07]*\x07//g'
}
fi
print_message()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment