Add color support to IRB.
Default Wirble color scheme.
Fruity testing colors.
Colorize the results of inspect
# File lib/wirble.rb, line 408 def self.colorize(str) begin ret, nocol = '', Color.escape(:nothing) Tokenizer.tokenize(str) do |tok, val| # c = Color.escape(colors[tok]) ret << colorize_string(val, colors[tok]) end ret rescue # catch any errors from the tokenizer (just in case) str end end
Return a string with the given color.
# File lib/wirble.rb, line 400 def self.colorize_string(str, color) col, nocol = [color, :nothing].map { |key| Color.escape(key) } col ? "#{col}#{str}#{nocol}" : str end
Get current color map
# File lib/wirble.rb, line 393 def self.colors @colors ||= {}.update(DEFAULT_COLORS) end
Set color map to hash
# File lib/wirble.rb, line 386 def self.colors=(hash) @colors = hash end
Disable colorized IRB results.
# File lib/wirble.rb, line 446 def self.disable ::IRB::Irb.class_eval do alias :output_value :non_color_output_value end end
Enable colorized IRB results.
# File lib/wirble.rb, line 425 def self.enable(custom_colors = nil) # if there's a better way to do this, I'm all ears. ::IRB::Irb.class_eval do alias :non_color_output_value :output_value def output_value if @context.inspect? val = Colorize.colorize(@context.last_value.inspect) printf @context.return_format, val else printf @context.return_format, @context.last_value end end end colors = custom_colors if custom_colors end
# File lib/wirble.rb, line 430 def output_value if @context.inspect? val = Colorize.colorize(@context.last_value.inspect) printf @context.return_format, val else printf @context.return_format, @context.last_value end end