ruby - Remove ansi-escape-sequences from string while still honoring them -


if have string ansi escape sequences, when print them terminal can move cursor around me end following:

puts "xxx\nxxx\nxxx\n\e[2fbe\e[2e"  # terminal sees xxx bex xxx  ##     # breakdown of "xxx\nxxx\nxxx\n\e[2fbe\e[2e"  # 1st, "xxx\nxxx\nxxx\n" printed xxx xxx xxx *  # `\e[2f` cursor moved 2 lines xxx *xx   # `be` printed xxx bex  # cursor returned bottom `\e[2f` xxx bex xxx * 

how write method encode string final output. method needs more sophisticated stripping escape sequences out - need have effect on final string.

in other words, how write some_magic give me kind of output arbitrary input string.

x = my_method(""xxx\nxxx\nxxx\n\e[2fbe\e[2e"") #=> "xxx\nbex\nxxx" 


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -