Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use stdio directly on "dumb" terminals #2304

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/pry.rb
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
14 changes: 12 additions & 2 deletions lib/pry/config.rb
Expand Up @@ -153,7 +153,7 @@ class Config

def initialize
merge!(
input: MemoizedValue.new { lazy_readline },
input: MemoizedValue.new { choose_input },
output: $stdout.tap { |out| out.sync = true },
commands: Pry::Commands,
prompt_name: 'pry',
Expand Down Expand Up @@ -286,7 +286,17 @@ def control_d_handler=(value)

private

def lazy_readline
def choose_input
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
13 changes: 13 additions & 0 deletions lib/pry/input/simple_stdio.rb
@@ -0,0 +1,13 @@
# frozen_string_literal: true

class Pry
module Input
# Readline replacement for low-capability terminals.
class SimpleStdio
def self.readline(prompt)
Pry.config.output.print(prompt)
$stdin.gets
end
end
end
end
22 changes: 22 additions & 0 deletions spec/config_spec.rb
Expand Up @@ -172,6 +172,28 @@
end
end

if defined?(Reline)
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
end

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