Skip to content

Commit

Permalink
Use raw mode while readmultiline
Browse files Browse the repository at this point in the history
  • Loading branch information
tompng committed Feb 7, 2023
1 parent 63ed5d4 commit a797eaa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
24 changes: 13 additions & 11 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,21 @@ def get_screen_size
Reline::DEFAULT_DIALOG_CONTEXT = Array.new

def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
end
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)
Reline::IOGate.with_raw_input do
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
end
inner_readline(prompt, add_hist, true, &confirm_multiline_termination)

whole_buffer = line_editor.whole_buffer.dup
whole_buffer.taint if RUBY_VERSION < '2.7'
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
Reline::HISTORY << whole_buffer
end
whole_buffer = line_editor.whole_buffer.dup
whole_buffer.taint if RUBY_VERSION < '2.7'
if add_hist and whole_buffer and whole_buffer.chomp("\n").size > 0
Reline::HISTORY << whole_buffer
end

line_editor.reset_line if line_editor.whole_buffer.nil?
whole_buffer
line_editor.reset_line if line_editor.whole_buffer.nil?
whole_buffer
end
end

def readline(prompt = '', add_hist = false)
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/ansi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ def self.output=(val)
@@output = val
end

def self.with_raw_input
@@input.raw { yield }
end

@@buf = []
def self.inner_getc
unless @@buf.empty?
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/general_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def self.input=(val)
@@input = val
end

def self.with_raw_input
yield
end

def self.getc
unless @@buf.empty?
return @@buf.shift
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/line_editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def rerender
new_lines = whole_lines
end
modify_lines(new_lines).each_with_index do |line, index|
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\n"
@output.write "#{prompt_list ? prompt_list[index] : prompt}#{line}\r\n"
Reline::IOGate.erase_after_cursor
end
@output.flush
Expand Down
4 changes: 4 additions & 0 deletions lib/reline/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ def self.check_input_event
end
end

def self.with_raw_input
yield
end

def self.getc
check_input_event
@@output_buf.shift
Expand Down

0 comments on commit a797eaa

Please sign in to comment.