ls output colors can be configured using, e.g Pry.config.ls.local_var_color = :red.

This commit is contained in:
John Mair 2011-09-08 03:39:22 +12:00
parent 0eca0f1aa9
commit 740e2d0773
3 changed files with 25 additions and 26 deletions

View File

@ -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 File

@ -22,18 +22,18 @@ class Pry
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 @@ Shows local and instance variables by default.
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 File

@ -95,17 +95,6 @@ class Pry
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 @@ class Pry
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 @@ class Pry
config.plugins ||= OpenStruct.new
config.plugins.enabled = true
config.plugins.strict_loading = true
config.requires ||= []
config.should_load_requires = true
@ -212,6 +200,15 @@ class Pry
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