Skip to content

Commit

Permalink
Escape non-printing characters
Browse files Browse the repository at this point in the history
  • Loading branch information
xjunior committed Sep 6, 2020
1 parent b548784 commit 97be53b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/pry/helpers/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ module Text

COLORS.each_pair do |color, value|
define_method color do |text|
"\033[0;#{30 + value}m#{text}\033[0m"
"\001\033[0;#{30 + value}m\002#{text}\001\033[0m\002"
end

define_method "bright_#{color}" do |text|
"\033[1;#{30 + value}m#{text}\033[0m"
"\001\033[1;#{30 + value}m\002#{text}\001\033[0m\002"
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"
"\001\033[0;#{30 + value};#{40 + bg_value}m\002#{text}\001\033[0m\002"
end

define_method "bright_#{color}_on_#{bg_color}" do |text|
"\033[1;#{30 + value};#{40 + bg_value}m#{text}\033[0m"
"\001\033[1;#{30 + value};#{40 + bg_value}m\002#{text}\001\033[0m\002"
end
end
end
Expand All @@ -52,7 +52,7 @@ def strip_color(text)
# @param [String, #to_s] text
# @return [String] _text_
def bold(text)
"\e[1m#{text}\e[0m"
"\001\e[1m\002#{text}\001\e[0m\002"
end

# Returns `text` in the default foreground colour.
Expand Down

0 comments on commit 97be53b

Please sign in to comment.