Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- exec 9<<-'EOF'
- # Convert compound ANSI to simple ANSI
- : 9
- s/\(\x1b\[\)\([^;]*\);/\1\2m\1/g
- t 9
- # Remove leading/implied zeroes
- s/\(\x1b\[\)0\([^m]\{0,\}m\)/\1\2/g
- # Translate ANSI to ESC-P2
- s/\[1m/P/g
- s/\[3m/4/g
- s/\[4m/-1/g
- s/\(\x1b\)\[m/\1F\15\1-0\1r\x0f\1r\x10/g
- # Strip remaining unconverted ANSI
- s/\x1b\[[0-9]\{1,\}m//g
- EOF
- ANSI2ESCP2=$( cat <&9 )
- if [ -t 0 -a $# -lt 1 ]; then
- script -aqt0 /dev/null
- else
- cat "$@"
- fi | sed -e "$ANSI2ESCP2"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement