#!/usr/bin/ruby escape = nil buffer = "" ARGF.each_char{|c| buffer += c if escape # Maybe terminate escape sequence. Note that escape sequence will # be flushed together with the next character. Consecutive escape # sequences will be flushed together. escape = (u = c.upcase) < "A" || u > "Z" elsif c == "\e" # Start buffering escape sequence escape = 1 else # Flush buffered sequence print buffer sleep 0.1 buffer = "" end } # Flush leftover text print buffer if buffer != ""