#!/bin/sh
# capture output in terminal of same size using:
# TERM=xterm-256color script -q -c 'tmux attach -t 0 \; detach' outputfile
# todo: obtain correct size from tmux and fake it
# note: \x1b in sed is a GNU extension and not posix-compliant
sed '
## strip everyting before jump to first column (titlebar escapes etc.)
s|^.*\x1b\[1;1H||;
## convert cursor jumps into newlines (happen at fully filled lines)
s|\x1b\[[0-9]\+;[0-9]\+H|\n|g;
## some stuff left at the end (cursor position etc.)
s|\x1b\[[0-9]\+;[0-9]\+r||g;
s|\x1b\[H||g;
# s|\x1b\[\?[0-9]\+l||;
# s|\x1b\[\?[0-9]\+g||;
' | ansifilter -e utf8 -H | \
sed 's/<body>/<body style="color: silver; background-color:black;">/'