Fix bug with ansi escape sequence and add unitary test