Here are my tries:
The last one worked, but it breaks copy-pasting (adding a lot of spaces when copied). Is there a better way?
Copyable text:
$ PS1='\['$'\x1b[0m\]$ '
$ echo -e "\x1b[41;37mWarning text\x1b[0m"; echo Normal text
Warning text
Normal text
$ echo -ne "\x1b[41;37mWarning text"$'\n'"\x1b[0m"; echo Normal text
Warning text
Normal text
$ echo -ne "\x1b[41;37mWarning text"$'\n'"\x1b[47;30m"; tr </dev/zero \\0 \ |head -c 80; echo -ne "\x1b[A"; echo Normal text
Warning text
Normal text
$
$ t="Warning text";echo -ne "\x1b[41;37m";echo -n "$t";{ tr </dev/zero \\0 \ |head -c $(bc <<<"$(stty -a <&3|grep -Po '(?<=columns )[0-9]+')-$(wc -c<<<"$t")+1"); } 3<&0;echo -e "\x1b[0m";echo "Normal text"
Warning text
Normal text
$
$
like that it is echo'ed to my terminal.