Revert "Revert "[ruby/reline] Reline::ANSI is general io. Reline::GeneralIO is not.""
This reverts commit 6e84ac2359c8fc8cb686ef4644b9cae26cd5ab9e. Now that the rubygems spec change has been merged, let's try reverting this and fixing it with tompng's new patch.
This commit is contained in:
parent
40a9e806f2
commit
5ea843f9b2
@ -254,7 +254,6 @@ module Reline
|
|||||||
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
|
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
|
||||||
end
|
end
|
||||||
|
|
||||||
Reline.update_iogate
|
|
||||||
io_gate.with_raw_input do
|
io_gate.with_raw_input do
|
||||||
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
|
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
|
||||||
end
|
end
|
||||||
@ -277,7 +276,6 @@ module Reline
|
|||||||
|
|
||||||
def readline(prompt = '', add_hist = false)
|
def readline(prompt = '', add_hist = false)
|
||||||
@mutex.synchronize do
|
@mutex.synchronize do
|
||||||
Reline.update_iogate
|
|
||||||
io_gate.with_raw_input do
|
io_gate.with_raw_input do
|
||||||
inner_readline(prompt, add_hist, false)
|
inner_readline(prompt, add_hist, false)
|
||||||
end
|
end
|
||||||
@ -461,7 +459,7 @@ module Reline
|
|||||||
end
|
end
|
||||||
|
|
||||||
private def may_req_ambiguous_char_width
|
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
|
return if defined? @ambiguous_width
|
||||||
io_gate.move_cursor_column(0)
|
io_gate.move_cursor_column(0)
|
||||||
begin
|
begin
|
||||||
@ -555,18 +553,6 @@ module Reline
|
|||||||
def self.line_editor
|
def self.line_editor
|
||||||
core.line_editor
|
core.line_editor
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,11 +19,7 @@ module Reline
|
|||||||
io
|
io
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if $stdout.tty?
|
|
||||||
Reline::ANSI.new
|
Reline::ANSI.new
|
||||||
else
|
|
||||||
Reline::Dumb.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -174,12 +174,10 @@ class Reline::ANSI < Reline::IO
|
|||||||
Reline.core.line_editor.handle_signal
|
Reline.core.line_editor.handle_signal
|
||||||
end
|
end
|
||||||
c = @input.getbyte
|
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
|
rescue Errno::EIO
|
||||||
# Maybe the I/O has been closed.
|
# Maybe the I/O has been closed.
|
||||||
nil
|
nil
|
||||||
rescue Errno::ENOTTY
|
|
||||||
nil
|
|
||||||
end
|
end
|
||||||
|
|
||||||
START_BRACKETED_PASTE = String.new("\e[200~", encoding: Encoding::ASCII_8BIT)
|
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)
|
def set_screen_size(rows, columns)
|
||||||
@input.winsize = [rows, columns]
|
@input.winsize = [rows, columns]
|
||||||
self
|
self
|
||||||
rescue Errno::ENOTTY
|
rescue Errno::ENOTTY, Errno::ENODEV
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def cursor_pos
|
def cursor_pos
|
||||||
begin
|
if @input.tty? && @output.tty?
|
||||||
res = +''
|
res = +''
|
||||||
m = nil
|
m = nil
|
||||||
@input.raw do |stdin|
|
@input.raw do |stdin|
|
||||||
@ -263,7 +261,7 @@ class Reline::ANSI < Reline::IO
|
|||||||
end
|
end
|
||||||
column = m[:column].to_i - 1
|
column = m[:column].to_i - 1
|
||||||
row = m[:row].to_i - 1
|
row = m[:row].to_i - 1
|
||||||
rescue Errno::ENOTTY
|
else
|
||||||
begin
|
begin
|
||||||
buf = @output.pread(@output.pos, 0)
|
buf = @output.pread(@output.pos, 0)
|
||||||
row = buf.count("\n")
|
row = buf.count("\n")
|
||||||
|
@ -969,6 +969,18 @@ begin
|
|||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nontty
|
||||||
|
omit if Reline.core.io_gate.win?
|
||||||
|
cmd = %Q{ruby -e 'puts(%Q{ello\C-ah\C-e})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })' | ruby -e 'print STDIN.read'}
|
||||||
|
start_terminal(40, 50, ['bash', '-c', cmd])
|
||||||
|
sleep 1
|
||||||
|
close rescue nil
|
||||||
|
assert_screen(<<~'EOC')
|
||||||
|
> hello
|
||||||
|
"hello"
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
def test_eof_with_newline
|
def test_eof_with_newline
|
||||||
omit if Reline.core.io_gate.win?
|
omit if Reline.core.io_gate.win?
|
||||||
cmd = %Q{ruby -e 'print(%Q{abc def \\e\\r})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
|
cmd = %Q{ruby -e 'print(%Q{abc def \\e\\r})' | ruby -I#{@pwd}/lib -rreline -e 'p Reline.readline(%{> })'}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user