Skip to content

Commit

Permalink
Use a simple STDIO for when input defaults to Reline and TERM=dumb
Browse files Browse the repository at this point in the history
  • Loading branch information
andrehjr committed Mar 23, 2024
1 parent fbcec7c commit f1f5f93
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/pry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
require 'pry/config/lazy_value'
require 'pry/config'

require 'pry/input/simple_stdio'

require 'pry/pry_class'
require 'pry/pry_instance'
require 'pry/inspector'
Expand Down
10 changes: 9 additions & 1 deletion lib/pry/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,16 @@ def control_d_handler=(value)
private

def choose_input
return InputStdioShim.new if Pry::Env['TERM'] == 'dumb'
input = load_readline

if Pry::Env['TERM'] == 'dumb' && (defined?(Reline) && input == Reline)
input = Pry::Input::SimpleStdio
end

input
end

def load_readline
require 'readline'
::Readline
rescue LoadError
Expand Down
2 changes: 1 addition & 1 deletion lib/pry/config/input_stdio_shim.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Pry
# Readline replacement for low-capability terminals.
class InputStdioShim
class StdioInput
def readline(prompt)
$stdout.print(prompt)
$stdin.gets
Expand Down
20 changes: 20 additions & 0 deletions spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,26 @@
end
end

describe "#input" do
context "when TERM=dumb" do
around do |example|
old_term = ENV['TERM']
ENV['TERM'] = 'dumb'

example.run
ENV['TERM'] = old_term
end

it "configures input with SimpleStdio" do
expect(subject.input).to eql(Pry::Input::SimpleStdio)
end
end

it "configures input with SimpleStdio" do
expect(subject.input).to eql(Readline)
end
end

describe "#method_missing" do
context "when invoked method ends with =" do
it "assigns a new custom option" do
Expand Down

0 comments on commit f1f5f93

Please sign in to comment.