From cfd1904f0a9a5690dd190d91d28b7c3901cbc809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?= Date: Tue, 15 Oct 2024 09:21:07 -0300 Subject: [PATCH] Add --no-multiline options to disable multiline with Reline --- lib/pry/cli.rb | 4 ++++ lib/pry/config.rb | 4 ++++ lib/pry/repl.rb | 52 ++++++++++++++++++++++++++--------------------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/lib/pry/cli.rb b/lib/pry/cli.rb index f20c10fac..f783860dd 100644 --- a/lib/pry/cli.rb +++ b/lib/pry/cli.rb @@ -145,6 +145,10 @@ def start(opts) Pry.config.color = false end + on "no-multiline", "Disables multiline (defaults to true with Reline)" do + Pry.config.multiline = false + end + on :f, "Suppress loading of pryrc" do Pry.config.should_load_rc = false Pry.config.should_load_local_rc = false diff --git a/lib/pry/config.rb b/lib/pry/config.rb index f594c503d..0b178bbcd 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -61,6 +61,9 @@ class Config # @return [Boolean] attribute :pager + # @return [Boolean] + attribute :multiline + # @return [Boolean] whether the global ~/.pryrc should be loaded attribute :should_load_rc @@ -164,6 +167,7 @@ def initialize hooks: Pry::Hooks.default, pager: true, system: Pry::SystemCommandHandler.method(:default), + multiline: true, color: Pry::Helpers::BaseHelpers.use_ansi_codes?, default_window_size: 5, editor: Pry::Editor.default, diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index 540e56ec6..d0a4f17fe 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -100,7 +100,7 @@ def read # Return nil for EOF, :no_more_input for error, or :control_c for return val unless val.is_a?(String) - if pry.config.auto_indent && !reline_available? + if pry.config.auto_indent && !input_multiline? original_val = "#{indentation}#{val}" indented_val = @indent.indent(val) @@ -180,7 +180,29 @@ def read_line(current_prompt) end if reline_available? - input_reline(current_prompt) + Reline.output_modifier_proc = lambda do |text, _| + if pry.color + SyntaxHighlighter.highlight(text) + else + text + end + end + + if pry.config.auto_indent + Reline.auto_indent_proc = lambda do |lines, line_index, _byte_ptr, _newline| + if line_index == 0 + 0 + else + pry_indentation = Pry::Indent.new + pry_indentation.indent(lines.join("\n")) + pry_indentation.last_indent_level.length + end + end + end + end + + if input_multiline? + input_readmultiline(current_prompt) elsif readline_available? set_readline_output input_readline(current_prompt, false) # false since we'll add it manually @@ -194,27 +216,7 @@ def read_line(current_prompt) end end - def input_reline(*args) - Reline.output_modifier_proc = lambda do |text, _| - if pry.color - SyntaxHighlighter.highlight(text) - else - text - end - end - - if pry.config.auto_indent - Reline.auto_indent_proc = lambda do |lines, line_index, _byte_pointer, _newline| - if line_index == 0 - 0 - else - pry_indentation = Pry::Indent.new - pry_indentation.indent(lines.join("\n")) - pry_indentation.last_indent_level.length - end - end - end - + def input_readmultiline(*args) Pry::InputLock.for(:all).interruptible_region do input.readmultiline(*args) do |multiline_input| Pry.commands.find_command(multiline_input) || @@ -229,6 +231,10 @@ def input_readline(*args) end end + def input_multiline? + !!pry.config.multiline && reline_available? + end + def reline_available? defined?(Reline) && input == Reline && prism_available? end