diff --git a/lib/pry/config.rb b/lib/pry/config.rb index ebaf31d31..1ed725d74 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -68,7 +68,7 @@ class Config attribute :pager # @return [Boolean] - attribute :escape_headers + attribute :escape_prompt # @return [Boolean] whether the global ~/.pryrc should be loaded attribute :should_load_rc @@ -180,7 +180,7 @@ def initialize hooks: Pry::Hooks.default, pager: true, - escape_headers: true, + escape_prompt: true, system: Pry::SystemCommandHandler.method(:default), color: Pry::Helpers::BaseHelpers.use_ansi_codes?, default_window_size: 5, diff --git a/lib/pry/helpers/text.rb b/lib/pry/helpers/text.rb index 66f226d69..867eac3c8 100644 --- a/lib/pry/helpers/text.rb +++ b/lib/pry/helpers/text.rb @@ -7,9 +7,6 @@ module Helpers module Text extend self - HEADER_START = "\001" - HEADER_END = "\002" - DECORATIONS = { "bold" => '1', "faint" => '2', @@ -65,15 +62,7 @@ module Text # @param text [String] # @return [String] def escape_text(color_code, text) - - header_start = nil - header_end = nil - if Pry.config.escape_headers - header_start = HEADER_START - header_end = HEADER_END - end - - "#{header_start}\e[#{color_code}m#{header_end}#{text}#{header_start}\e[0m#{header_end}" + "\e[#{color_code}m#{text}\e[0m" end # Remove any color codes from _text_. @@ -81,7 +70,7 @@ def escape_text(color_code, text) # @param [String, #to_s] text # @return [String] _text_ stripped of any color codes. def strip_color(text) - text.to_s.gsub(/(\001)?(\e\[(\d[;\d]?)*m)(\002)?/, '') + text.to_s.gsub(/\001|\002|\e\[[\d;]+m/, '') end # Returns `text` in the default foreground colour. diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 963758a6f..279f2a322 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -391,7 +391,6 @@ def module_nesting # # @return [String] correctly indented line def correct_indentation(prompt, code, overhang = 0) - prompt = prompt.delete("\001\002") line_to_measure = Pry::Helpers::Text.strip_color(prompt) << code whitespace = ' ' * overhang diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb index c32be6247..656e4e2e3 100644 --- a/lib/pry/prompt.rb +++ b/lib/pry/prompt.rb @@ -177,7 +177,7 @@ def [](key) add( :nav, "A prompt that displays the binding stack as a path and includes information \n" \ - "about '_in_' and '_out_'.", + "about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.", %w[> *] ) do |_context, _nesting, pry_instance, sep| tree = pry_instance.binding_stack.map { |b| Pry.view_clip(b.eval('self')) } diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index d1de5c4d5..95f790010 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -685,6 +685,7 @@ def ensure_correct_encoding!(val) end end + # @return [String] def generate_prompt(prompt_proc, conf) if prompt_proc.arity == 1 prompt_proc.call(conf) diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index ba032c7f1..0072e7699 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -92,7 +92,10 @@ def epilogue # @return [:no_more_input] On EOF. def read @indent.reset if pry.eval_string.empty? + current_prompt = pry.select_prompt + current_prompt = current_prompt.gsub(/(\e\[[\d;]+m)/, "\001\\1\002") if pry.config.escape_prompt + indentation = pry.config.auto_indent ? @indent.current_prefix : '' val = read_line("#{current_prompt}#{indentation}") diff --git a/spec/commands/wtf_spec.rb b/spec/commands/wtf_spec.rb index c4af0cc52..52ad02514 100644 --- a/spec/commands/wtf_spec.rb +++ b/spec/commands/wtf_spec.rb @@ -38,7 +38,7 @@ it "prints only a part of the exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -55,7 +55,7 @@ it "prints full exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -73,7 +73,7 @@ it "prints more of backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -116,14 +116,14 @@ it "prints parts of both original and nested exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: outer\n" \ + "\e[1mException:\e[0m RuntimeError: outer\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ "2: /bin/pry:23:in `
'\n" \ "3: /bin/pry:23:in `
'\n" \ "4: /bin/pry:23:in `
'\n" \ - "\001\e[1m\002Caused by:\001\e[0m\002 RuntimeError: inner\n" \ + "\e[1mCaused by:\e[0m RuntimeError: inner\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -140,7 +140,7 @@ it "prints both original and nested exception backtrace" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: outer\n" \ + "\e[1mException:\e[0m RuntimeError: outer\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -148,7 +148,7 @@ "3: /bin/pry:23:in `
'\n" \ "4: /bin/pry:23:in `
'\n" \ "5: /bin/pry:23:in `
'\n" \ - "\001\e[1m\002Caused by:\001\e[0m\002 RuntimeError: inner\n" \ + "\e[1mCaused by:\e[0m RuntimeError: inner\n" \ "--\n" \ "0: /bin/pry:23:in `
'\n" \ "1: /bin/pry:23:in `
'\n" \ @@ -177,17 +177,17 @@ it "prints lines of code that exception frame references" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ - "0: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ + "0: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `
'\" }\n" \ - "1: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ + "1: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `
'\" }\n" \ - "2: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ + "2: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `
'\" }\n" \ - "3: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ + "3: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `
'\" }\n" \ - "4: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ + "4: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ " Array.new(6) { \"\#{__FILE__}:\#{__LINE__}:in `
'\" }\n" ) end @@ -200,13 +200,13 @@ it "skips code and prints only the backtrace frame" do subject.process expect(subject.output.string).to eq( - "\001\e[1m\002Exception:\001\e[0m\002 RuntimeError: oops\n" \ + "\e[1mException:\e[0m RuntimeError: oops\n" \ "--\n" \ - "0: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ - "1: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ - "2: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ - "3: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" \ - "4: \001\e[1m\002#{__FILE__}:168:in `
'\001\e[0m\002\n" + "0: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ + "1: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ + "2: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ + "3: \e[1m#{__FILE__}:168:in `
'\e[0m\n" \ + "4: \e[1m#{__FILE__}:168:in `
'\e[0m\n" ) end end diff --git a/spec/config_spec.rb b/spec/config_spec.rb index dd9423ca5..3bf1803ce 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -13,7 +13,7 @@ specify { expect(subject.unrescued_exceptions).to be_an(Array) } specify { expect(subject.hooks).to be_a(Pry::Hooks) } specify { expect(subject.pager).to be(true).or be(false) } - specify { expect(subject.escape_headers).to be(true).or be(false) } + specify { expect(subject.escape_prompt).to be(true).or be(false) } specify { expect(subject.system).to be_a(Method) } specify { expect(subject.color).to be(true).or be(false) } specify { expect(subject.default_window_size).to be_a(Numeric) }