summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xAB <0xAB@protonmail.com>2017-09-01 14:09:35 +0100
committer0xAB <0xAB@protonmail.com>2017-09-01 14:09:35 +0100
commit677928293a5a3a9d3043a06e166aa8b950ac9e44 (patch)
tree4a45a9a2a8e8957175335a867bac70183e827497
parenta7df6bc73467523c0328d18baaf62184f40a74b9 (diff)
downloadpry-677928293a5a3a9d3043a06e166aa8b950ac9e44.tar.gz
merge pry/master
-rw-r--r--lib/pry/helpers/colors.rb48
-rw-r--r--lib/pry/helpers/text.rb2
2 files changed, 27 insertions, 23 deletions
diff --git a/lib/pry/helpers/colors.rb b/lib/pry/helpers/colors.rb
index 51105b3b..29f0ad1c 100644
--- a/lib/pry/helpers/colors.rb
+++ b/lib/pry/helpers/colors.rb
@@ -13,6 +13,30 @@ module Pry::Helpers::Colors
"white" => 7
}
+ color_enabled = lambda do |pry|
+ (pry and pry.color) or (defined?(_pry_) and _pry_.color) or Pry.color
+ end
+
+ COLORS.each_pair do |color, value|
+ define_method(color) do |text, pry=nil|
+ instance_exec(pry, &color_enabled) ? "\033[0;#{30+value}m#{text}\033[0m" : text
+ end
+
+ define_method("bright_#{color}") do |text, pry=nil|
+ instance_exec(pry, &color_enabled) ? "\033[1;#{30+value}m#{text}\033[0m" : text
+ end
+
+ COLORS.each_pair do |bg_color, bg_value|
+ define_method "#{color}_on_#{bg_color}" do |text, pry=nil|
+ instance_exec(pry, &color_enabled) ? "\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m" : text
+ end
+
+ define_method "bright_#{color}_on_#{bg_color}" do |text, pry=nil|
+ instance_exec(pry, &color_enabled) ? "\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m" : text
+ end
+ end
+ end
+
#
# @example
#
@@ -34,32 +58,12 @@ module Pry::Helpers::Colors
public_send(effect, str) : str
end
- COLORS.each_pair do |color, value|
- define_method color do |text|
- "\033[0;#{30+value}m#{text}\033[0m"
- end
-
- define_method "bright_#{color}" do |text|
- "\033[1;#{30+value}m#{text}\033[0m"
- end
-
- COLORS.each_pair do |bg_color, bg_value|
- define_method "#{color}_on_#{bg_color}" do |text|
- "\033[0;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
- end
-
- define_method "bright_#{color}_on_#{bg_color}" do |text|
- "\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
- end
- end
- end
-
# Returns _text_ as bold text for use on a terminal.
#
# @param [String, #to_s] text
# @return [String] _text_
- def bold(text)
- "\e[1m#{text}\e[0m"
+ def bold text, pry=(defined?(_pry_) && _pry_) || Pry
+ (pry and pry.color) ? "\e[1m#{text}\e[0m" : text
end
# Remove any color codes from _text_.
diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb
index ee63ec8d..3d2dd0f9 100644
--- a/lib/pry/helpers/text.rb
+++ b/lib/pry/helpers/text.rb
@@ -10,7 +10,7 @@ class Pry
# Use this instead of "black" or "white" when you mean absence of colour.
#
# @deprecated
- # Please use {#strip_color} instead.
+ # Please use {Colors#strip_color} instead.
#
# @param [String, #to_s] text
# @return [String]