Skip to content
Browse files

ls output colors can be configured using, e.g Pry.config.ls.local_var…

…_color = :red.
  • Loading branch information...
1 parent 0eca0f1 commit 740e2d0773f3a1490f5a5bed1226e7320dabf94d @banister banister committed Sep 8, 2011
Showing with 25 additions and 26 deletions.
  1. +2 −0 CHANGELOG
  2. +13 −13 lib/pry/default_commands/ls.rb
  3. +10 −13 lib/pry/pry_class.rb
View
2 CHANGELOG
@@ -32,6 +32,8 @@
* cd command now supports complex syntax: cd ../@y/y/../z
* JRuby is no longer a 2nd class citizen, almost full JRuby support, passing 100% tests
* added Pry::NAV_PROMPT (great new navigation prompt, per robgleeson) and Pry::SIMPLE_PRINT for simple (IRB-style) print output (just using inspect)
+* _pry_ now passed as 3rd parameter to :before_session hook
+* ls colors now configurable via Pry.config.ls.local_var_color = :bright_red etc
*/7/2011 version 0.9.3
* cat --ex (cats 5 lines above and below line in file where exception was raised)
View
26 lib/pry/default_commands/ls.rb
@@ -22,18 +22,18 @@ def trim_methods(target, options, visibility)
def ls_color_map
{
- "local variables" => :bright_red,
- "instance variables" => :bright_blue,
- "class variables" => :blue,
- "global variables" => :bright_magenta,
- "just singleton methods" => :green,
- "public methods" => :green,
- "private methods" => :green,
- "protected methods" => :green,
- "public instance methods" => :bright_green,
- "private instance methods" => :bright_green,
- "protected instance methods" => :bright_green,
- "constants" => :red
+ "local variables" => Pry.config.ls.local_var_color,
+ "instance variables" => Pry.config.ls.instance_var_color,
+ "class variables" => Pry.config.ls.class_var_color,
+ "global variables" => Pry.config.ls.global_var_color,
+ "just singleton methods" => Pry.config.ls.method_color,
+ "public methods" => Pry.config.ls.method_color,
+ "private methods" => Pry.config.ls.method_color,
+ "protected methods" => Pry.config.ls.method_color,
+ "public instance methods" => Pry.config.ls.instance_method_color,
+ "private instance methods" => Pry.config.ls.instance_method_color,
+ "protected instance methods" => Pry.config.ls.instance_method_color,
+ "constants" => Pry.config.ls.constant_color
}
end
end
@@ -198,7 +198,7 @@ def ls_color_map
if !v.first.empty?
text << "#{k}:\n--\n"
filtered_list = v.first.grep options[:grep]
- text << text().bright_green(filtered_list.join(" "))
+ text << text().send(ls_color_map[k], (filtered_list.join(" ")))
text << "\n\n"
end
end
View
23 lib/pry/pry_class.rb
@@ -95,17 +95,6 @@ def self.start(target=TOPLEVEL_BINDING, options={})
new(options).repl(target)
end
- # A custom version of `Kernel#pretty_inspect`.
- # This method should not need to be accessed directly.
- # @param obj The object to view.
- # @return [String] The string representation of `obj`.
- def self.view(obj)
- obj.pretty_inspect
-
- rescue NoMethodError
- "unknown"
- end
-
# A version of `Pry.view` that clips the output to `max_size` chars.
# In case of > `max_size` chars the `#<Object...> notation is used.
# @param obj The object to view.
@@ -116,7 +105,7 @@ def self.view_clip(obj, max_length = 60)
obj.name.to_s
elsif obj.inspect.length <= max_length
obj.inspect
- else
+ else
"#<#{obj.class}:%#x>" % (obj.object_id << 1)
end
@@ -199,7 +188,6 @@ def self.set_config_defaults
config.plugins ||= OpenStruct.new
config.plugins.enabled = true
- config.plugins.strict_loading = true
config.requires ||= []
config.should_load_requires = true
@@ -212,6 +200,15 @@ def self.set_config_defaults
config.control_d_handler = DEFAULT_CONTROL_D_HANDLER
config.memory_size = 100
+
+ Pry.config.ls ||= OpenStruct.new
+ Pry.config.ls.local_var_color = :bright_red
+ Pry.config.ls.instance_var_color = :bright_blue
+ Pry.config.ls.class_var_color = :blue
+ Pry.config.ls.global_var_color = :bright_magenta
+ Pry.config.ls.method_color = :green
+ Pry.config.ls.instance_method_color = :bright_green
+ Pry.config.ls.constant_color = :yellow
end
# Set all the configurable options back to their default values

0 comments on commit 740e2d0

Please sign in to comment.
Something went wrong with that request. Please try again.