[ruby/irb] Fix debug command in nomultiline mode
(https://github.com/ruby/irb/pull/1006) * Fix debug command in nomultiline mode * context.colorize_code -> context.colorize_input https://github.com/ruby/irb/commit/71f4d6bfb5
This commit is contained in:
parent
cf29594c03
commit
34e008d075
@ -649,6 +649,21 @@ module IRB
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def colorize_input(input, complete:)
|
||||||
|
if IRB.conf[:USE_COLORIZE] && IRB::Color.colorable?
|
||||||
|
lvars = local_variables || []
|
||||||
|
if parse_command(input)
|
||||||
|
name, sep, arg = input.split(/(\s+)/, 2)
|
||||||
|
arg = IRB::Color.colorize_code(arg, complete: complete, local_variables: lvars)
|
||||||
|
"#{IRB::Color.colorize(name, [:BOLD])}\e[m#{sep}#{arg}"
|
||||||
|
else
|
||||||
|
IRB::Color.colorize_code(input, complete: complete, local_variables: lvars)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Reline::Unicode.escape_for_print(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def inspect_last_value # :nodoc:
|
def inspect_last_value # :nodoc:
|
||||||
@inspect_method.inspect_value(@last_value)
|
@inspect_method.inspect_value(@last_value)
|
||||||
end
|
end
|
||||||
|
@ -57,22 +57,18 @@ module IRB
|
|||||||
DEBUGGER__::ThreadClient.prepend(SkipPathHelperForIRB)
|
DEBUGGER__::ThreadClient.prepend(SkipPathHelperForIRB)
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@output_modifier_defined && !DEBUGGER__::CONFIG[:no_hint]
|
if !DEBUGGER__::CONFIG[:no_hint] && irb.context.io.is_a?(RelineInputMethod)
|
||||||
irb_output_modifier_proc = Reline.output_modifier_proc
|
Reline.output_modifier_proc = proc do |input, complete:|
|
||||||
|
unless input.strip.empty?
|
||||||
Reline.output_modifier_proc = proc do |output, complete:|
|
cmd = input.split(/\s/, 2).first
|
||||||
unless output.strip.empty?
|
|
||||||
cmd = output.split(/\s/, 2).first
|
|
||||||
|
|
||||||
if !complete && DEBUGGER__.commands.key?(cmd)
|
if !complete && DEBUGGER__.commands.key?(cmd)
|
||||||
output = output.sub(/\n$/, " # debug command\n")
|
input = input.sub(/\n$/, " # debug command\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
irb_output_modifier_proc.call(output, complete: complete)
|
irb.context.colorize_input(input, complete: complete)
|
||||||
end
|
end
|
||||||
|
|
||||||
@output_modifier_defined = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -265,24 +265,9 @@ module IRB
|
|||||||
@completion_params = [preposing, target, postposing, bind]
|
@completion_params = [preposing, target, postposing, bind]
|
||||||
@completor.completion_candidates(preposing, target, postposing, bind: bind)
|
@completor.completion_candidates(preposing, target, postposing, bind: bind)
|
||||||
}
|
}
|
||||||
Reline.output_modifier_proc =
|
Reline.output_modifier_proc = proc do |input, complete:|
|
||||||
if IRB.conf[:USE_COLORIZE]
|
IRB.CurrentContext.colorize_input(input, complete: complete)
|
||||||
proc do |output, complete: |
|
end
|
||||||
next unless IRB::Color.colorable?
|
|
||||||
lvars = IRB.CurrentContext&.local_variables || []
|
|
||||||
if IRB.CurrentContext&.parse_command(output)
|
|
||||||
name, sep, arg = output.split(/(\s+)/, 2)
|
|
||||||
arg = IRB::Color.colorize_code(arg, complete: complete, local_variables: lvars)
|
|
||||||
"#{IRB::Color.colorize(name, [:BOLD])}\e[m#{sep}#{arg}"
|
|
||||||
else
|
|
||||||
IRB::Color.colorize_code(output, complete: complete, local_variables: lvars)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
proc do |output|
|
|
||||||
Reline::Unicode.escape_for_print(output)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Reline.dig_perfect_match_proc = ->(matched) { display_document(matched) }
|
Reline.dig_perfect_match_proc = ->(matched) { display_document(matched) }
|
||||||
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
|
Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
|
||||||
|
|
||||||
|
@ -507,6 +507,28 @@ class IRB::RenderingTest < Yamatanooroti::TestCase
|
|||||||
File.unlink(script) if script
|
File.unlink(script) if script
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_debug_integration_doesnt_hint_debugger_commands_in_nomultiline_mode
|
||||||
|
write_irbrc <<~'LINES'
|
||||||
|
IRB.conf[:USE_SINGLELINE] = true
|
||||||
|
LINES
|
||||||
|
script = Tempfile.create(["debug", ".rb"])
|
||||||
|
script.write <<~RUBY
|
||||||
|
puts 'start IRB'
|
||||||
|
binding.irb
|
||||||
|
RUBY
|
||||||
|
script.close
|
||||||
|
start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{script.to_path}}, startup_message: 'start IRB')
|
||||||
|
write("debug\n")
|
||||||
|
write("pp 1")
|
||||||
|
close
|
||||||
|
|
||||||
|
screen = result.join("\n").sub(/\n*\z/, "\n")
|
||||||
|
# submitted input shouldn't contain hint
|
||||||
|
assert_include(screen, "irb:rdbg(main):002> pp 1\n")
|
||||||
|
ensure
|
||||||
|
File.unlink(script) if script
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def write_irbrc(content)
|
def write_irbrc(content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user