Skip to content

Commit

Permalink
Use stdio directly on "dumb" terminals
Browse files Browse the repository at this point in the history
Resolves pry#2303
  • Loading branch information
dgutov committed Mar 21, 2024
1 parent 0a948ae commit fbcec7c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/pry/config.rb
Original file line number Diff line number Diff line change
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,9 @@ def control_d_handler=(value)

private

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

require 'readline'
::Readline
rescue LoadError
Expand Down
11 changes: 11 additions & 0 deletions lib/pry/config/input_stdio_shim.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class Pry
# Readline replacement for low-capability terminals.
class InputStdioShim
def readline(prompt)
$stdout.print(prompt)
$stdin.gets
end
end
end

0 comments on commit fbcec7c

Please sign in to comment.