Skip to content

Commit

Permalink
Add --no-multiline options to disable multiline with Reline
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Oct 15, 2024
1 parent 2615de7 commit 6716d16
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
4 changes: 4 additions & 0 deletions lib/pry/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/pry/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
46 changes: 24 additions & 22 deletions lib/pry/repl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 reline_available? && pry.config.multiline
input_readmultiline(current_prompt)
elsif readline_available?
set_readline_output
input_readline(current_prompt, false) # false since we'll add it manually
Expand All @@ -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) ||
Expand Down

0 comments on commit 6716d16

Please sign in to comment.