Class: IRB::ColoredFormatter
- Defined in:
- lib/irb/ext/colorize.rb
Defined Under Namespace
Modules: Color
Constant Summary collapse
- TYPE_ALIASES =
{ :on_comma => :comma, :refers => :operator, # Wirble compat :on_op => :operator, :on_lbrace => :open_hash, :on_rbrace => :close_hash, :on_lbracket => :open_array, :on_rbracket => :close_array, :on_ident => :symbol, :on_symbeg => :symbol_prefix, :on_tstring_beg => :open_string, :on_tstring_content => :string, :on_tstring_end => :close_string, :on_int => :number, :on_float => :number, :on_kw => :keyword, :on_const => :constant, :class => :constant # Wirble compat }
- COLOR_SCHEMES =
# object colors :open_object => :dark_gray, :object_class => :purple, :object_addr_prefix => :blue, :object_line_prefix => :blue, :close_object => :dark_gray,
{ :dark_background => { # :prompt => :green, # :result_prefix => :light_purple, :comma => :blue, :operator => :blue, :open_hash => :green, :close_hash => :green, :open_array => :green, :close_array => :green, :symbol_prefix => :yellow, # hmm ident... :symbol => :yellow, :open_string => :red, :string => :cyan, :close_string => :red, :number => :cyan, :keyword => :yellow, :constant => :light_green }, :light_background => { :comma => :purple, :operator => :blue, :open_hash => :red, :close_hash => :red, :open_array => :red, :close_array => :red, :symbol_prefix => :black, :symbol => :light_gray, :open_string => :blue, :string => :dark_gray, :close_string => :blue, :number => :black, :keyword => :brown, :constant => :red }, :fresh => { :prompt => :green, :result_prefix => :light_purple, :comma => :red, :operator => :red, :open_hash => :blue, :close_hash => :blue, :open_array => :green, :close_array => :green, :symbol_prefix => :yellow, :symbol => :yellow, :number => :cyan, :string => :cyan, :keyword => :white } }
Constants inherited from Formatter
Formatter::DEFAULT_PROMPT, Formatter::NO_PROMPT, Formatter::RESULT_PREFIX, Formatter::SIMPLE_PROMPT, Formatter::SOURCE_ROOT, Formatter::SYNTAX_ERROR
Instance Attribute Summary collapse
-
#color_scheme ⇒ Object
Returns the value of attribute color_scheme.
-
#colors ⇒ Object
readonly
Returns the value of attribute colors.
Attributes inherited from Formatter
#filter_from_backtrace, #inspect
Instance Method Summary collapse
- #color(type) ⇒ Object
- #colorize(str) ⇒ Object
- #colorize_token(type, token) ⇒ Object
-
#initialize ⇒ ColoredFormatter
constructor
A new instance of ColoredFormatter.
- #prompt(context) ⇒ Object
- #result(object) ⇒ Object
- #result_prefix ⇒ Object
Methods inherited from Formatter
#exception, #filter_backtrace, #inspect_object, #syntax_error
Constructor Details
#initialize ⇒ ColoredFormatter
Returns a new instance of ColoredFormatter.
145 146 147 148 |
# File 'lib/irb/ext/colorize.rb', line 145 def initialize super self.color_scheme = :dark_background end |
Instance Attribute Details
#color_scheme ⇒ Object
Returns the value of attribute color_scheme.
143 144 145 |
# File 'lib/irb/ext/colorize.rb', line 143 def color_scheme @color_scheme end |
#colors ⇒ Object (readonly)
Returns the value of attribute colors.
143 144 145 |
# File 'lib/irb/ext/colorize.rb', line 143 def colors @colors end |
Instance Method Details
#color(type) ⇒ Object
155 156 157 158 |
# File 'lib/irb/ext/colorize.rb', line 155 def color(type) type = TYPE_ALIASES[type] if TYPE_ALIASES.has_key?(type) @colors[type] end |
#colorize(str) ⇒ Object
168 169 170 |
# File 'lib/irb/ext/colorize.rb', line 168 def colorize(str) Ripper.lex(str).map { |_, type, token| colorize_token(type, token) }.join end |
#colorize_token(type, token) ⇒ Object
160 161 162 163 164 165 166 |
# File 'lib/irb/ext/colorize.rb', line 160 def colorize_token(type, token) if color = color(type) "#{Color.escape(color)}#{token}#{Color::CLEAR}" else token end end |
#prompt(context) ⇒ Object
172 173 174 |
# File 'lib/irb/ext/colorize.rb', line 172 def prompt(context) colorize_token(:prompt, super) end |
#result(object) ⇒ Object
180 181 182 |
# File 'lib/irb/ext/colorize.rb', line 180 def result(object) "#{result_prefix} #{colorize(inspect_object(object))}" end |
#result_prefix ⇒ Object
176 177 178 |
# File 'lib/irb/ext/colorize.rb', line 176 def result_prefix colorize_token(:result_prefix, Formatter::RESULT_PREFIX) end |