Skip to content

Instantly share code, notes, and snippets.

@t9md
Created October 14, 2010 07:48
Show Gist options
  • Save t9md/625808 to your computer and use it in GitHub Desktop.
Save t9md/625808 to your computer and use it in GitHub Desktop.
eliminate ANSI_ESCAPE for terminal-table
require 'rubygems'
require 'colored'
require 'terminal-table/import'
class String
alias_method :to_s_orig, :to_s
def to_s
str = self.to_s_orig
if ::ELIMINATE_ANSI_ESCAPE
str = str.sub(/^\e\[[\[\e0-9;m]+m/, "")
str = str.sub(/(\e\[[\[\e0-9;m]+m)$/, "")
end
str
end
end
ELIMINATE_ANSI_ESCAPE = false
puts table(['a'.red, 'b'], [1, 2], [3, "c".blue], :separator, [4, 6])
puts
ELIMINATE_ANSI_ESCAPE = true
puts table(['a'.red, 'b'], [1, 2], [3, "c".blue], :separator, [4, 6])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment