aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authortomoya ishida <tomoyapenguin@gmail.com>2024-06-03 23:28:29 +0900
committergit <svn-admin@ruby-lang.org>2024-06-03 14:28:33 +0000
commitba01d15cf5db96933905d669c68f5cc0cd6910b8 (patch)
tree7de18b0edfdb5444248adc44300f8fcb16eee095 /lib
parent7aa1bca2c9d8f002b0cc6d6730318d726d20d52d (diff)
downloadruby-ba01d15cf5db96933905d669c68f5cc0cd6910b8.tar.gz
[ruby/reline] Reline::ANSI is general io. Reline::GeneralIO is not.
(https://github.com/ruby/reline/pull/659) Reline::ANSI has a partial non-tty supporting code. It should be a general io. Reline::Dumb should be only used in testing. https://github.com/ruby/reline/commit/2d6828473d
Diffstat (limited to 'lib')
-rw-r--r--lib/reline.rb16
-rw-r--r--lib/reline/io.rb6
-rw-r--r--lib/reline/io/ansi.rb10
3 files changed, 6 insertions, 26 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index 33a1cfc625..6bae469894 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -254,7 +254,6 @@ module Reline
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
end
- Reline.update_iogate
io_gate.with_raw_input do
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
end
@@ -277,7 +276,6 @@ module Reline
def readline(prompt = '', add_hist = false)
@mutex.synchronize do
- Reline.update_iogate
io_gate.with_raw_input do
inner_readline(prompt, add_hist, false)
end
@@ -461,7 +459,7 @@ module Reline
end
private def may_req_ambiguous_char_width
- @ambiguous_width = 2 if io_gate.dumb? or !STDOUT.tty?
+ @ambiguous_width = 2 if io_gate.dumb? || !STDIN.tty? || !STDOUT.tty?
return if defined? @ambiguous_width
io_gate.move_cursor_column(0)
begin
@@ -555,18 +553,6 @@ module Reline
def self.line_editor
core.line_editor
end
-
- def self.update_iogate
- return if core.config.test_mode
-
- # Need to change IOGate when `$stdout.tty?` change from false to true by `$stdout.reopen`
- # Example: rails/spring boot the application in non-tty, then run console in tty.
- if ENV['TERM'] != 'dumb' && core.io_gate.dumb? && $stdout.tty?
- require 'reline/io/ansi'
- remove_const(:IOGate)
- const_set(:IOGate, Reline::ANSI.new)
- end
- end
end
diff --git a/lib/reline/io.rb b/lib/reline/io.rb
index 7fca0c338a..c1dd1a56c8 100644
--- a/lib/reline/io.rb
+++ b/lib/reline/io.rb
@@ -19,11 +19,7 @@ module Reline
io
end
else
- if $stdout.tty?
- Reline::ANSI.new
- else
- Reline::Dumb.new
- end
+ Reline::ANSI.new
end
end
end
diff --git a/lib/reline/io/ansi.rb b/lib/reline/io/ansi.rb
index cf3c9965dd..aa8ff256e2 100644
--- a/lib/reline/io/ansi.rb
+++ b/lib/reline/io/ansi.rb
@@ -174,12 +174,10 @@ class Reline::ANSI < Reline::IO
Reline.core.line_editor.handle_signal
end
c = @input.getbyte
- (c == 0x16 && @input.raw(min: 0, time: 0, &:getbyte)) || c
+ (c == 0x16 && @input.tty? && @input.raw(min: 0, time: 0, &:getbyte)) || c
rescue Errno::EIO
# Maybe the I/O has been closed.
nil
- rescue Errno::ENOTTY
- nil
end
START_BRACKETED_PASTE = String.new("\e[200~", encoding: Encoding::ASCII_8BIT)
@@ -239,12 +237,12 @@ class Reline::ANSI < Reline::IO
def set_screen_size(rows, columns)
@input.winsize = [rows, columns]
self
- rescue Errno::ENOTTY
+ rescue Errno::ENOTTY, Errno::ENODEV
self
end
def cursor_pos
- begin
+ if @input.tty? && @output.tty?
res = +''
m = nil
@input.raw do |stdin|
@@ -263,7 +261,7 @@ class Reline::ANSI < Reline::IO
end
column = m[:column].to_i - 1
row = m[:row].to_i - 1
- rescue Errno::ENOTTY
+ else
begin
buf = @output.pread(@output.pos, 0)
row = buf.count("\n")