mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Change LineEditor instance in Reline to class var
This commit is contained in:
parent
fc57e10569
commit
aaaede8bcf
2 changed files with 25 additions and 22 deletions
|
@ -30,8 +30,10 @@ module Reline
|
||||||
attr_writer :output
|
attr_writer :output
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@config = Reline::Config.new
|
||||||
|
@@config.read
|
||||||
|
@@line_editor = Reline::LineEditor.new(@@config)
|
||||||
@@ambiguous_width = nil
|
@@ambiguous_width = nil
|
||||||
@@config = nil
|
|
||||||
|
|
||||||
@basic_quote_characters = '"\''
|
@basic_quote_characters = '"\''
|
||||||
# TODO implement below
|
# TODO implement below
|
||||||
|
@ -109,42 +111,43 @@ module Reline
|
||||||
inner_readline(prompt, add_hist, true)
|
inner_readline(prompt, add_hist, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
if add_hist and @line_editor.whole_buffer and @line_editor.whole_buffer.chomp.size > 0
|
whole_buffer = @@line_editor.whole_buffer.dup
|
||||||
Reline::HISTORY << @line_editor.whole_buffer
|
whole_buffer.taint
|
||||||
|
if add_hist and whole_buffer and whole_buffer.chomp.size > 0
|
||||||
|
Reline::HISTORY << whole_buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
@line_editor.whole_buffer
|
whole_buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
def readline(prompt = '', add_hist = false)
|
def readline(prompt = '', add_hist = false)
|
||||||
inner_readline(prompt, add_hist, false)
|
inner_readline(prompt, add_hist, false)
|
||||||
|
|
||||||
if add_hist and @line_editor.line and @line_editor.line.chomp.size > 0
|
line = @@line_editor.line.dup
|
||||||
Reline::HISTORY << @line_editor.line.chomp
|
line.taint
|
||||||
|
if add_hist and line and line.chomp.size > 0
|
||||||
|
Reline::HISTORY << line.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
@line_editor.line
|
line
|
||||||
end
|
end
|
||||||
|
|
||||||
def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
|
def inner_readline(prompt, add_hist, multiline, &confirm_multiline_termination)
|
||||||
if @@config.nil?
|
|
||||||
@@config = Reline::Config.new
|
|
||||||
@@config.read
|
|
||||||
end
|
|
||||||
otio = prep
|
otio = prep
|
||||||
|
|
||||||
may_req_ambiguous_char_width
|
may_req_ambiguous_char_width
|
||||||
@line_editor = Reline::LineEditor.new(@@config, prompt)
|
|
||||||
if multiline
|
if multiline
|
||||||
@line_editor.multiline_on
|
@@line_editor.multiline_on
|
||||||
if block_given?
|
if block_given?
|
||||||
@line_editor.confirm_multiline_termination_proc = confirm_multiline_termination
|
@@line_editor.confirm_multiline_termination_proc = confirm_multiline_termination
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
@@line_editor.multiline_off
|
||||||
end
|
end
|
||||||
@line_editor.completion_proc = @@completion_proc
|
@@line_editor.completion_proc = @@completion_proc
|
||||||
@line_editor.dig_perfect_match_proc = @@dig_perfect_match_proc
|
@@line_editor.dig_perfect_match_proc = @@dig_perfect_match_proc
|
||||||
@line_editor.retrieve_completion_block = method(:retrieve_completion_block)
|
@@line_editor.retrieve_completion_block = method(:retrieve_completion_block)
|
||||||
@line_editor.rerender
|
@@line_editor.rerender
|
||||||
|
|
||||||
if IS_WINDOWS
|
if IS_WINDOWS
|
||||||
config = {
|
config = {
|
||||||
|
@ -171,11 +174,11 @@ module Reline
|
||||||
while c = getc
|
while c = getc
|
||||||
key_stroke.input_to!(c)&.then { |inputs|
|
key_stroke.input_to!(c)&.then { |inputs|
|
||||||
inputs.each { |c|
|
inputs.each { |c|
|
||||||
@line_editor.input_key(c)
|
@@line_editor.input_key(c)
|
||||||
@line_editor.rerender
|
@@line_editor.rerender
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break if @line_editor.finished?
|
break if @@line_editor.finished?
|
||||||
end
|
end
|
||||||
Reline.move_cursor_column(0)
|
Reline.move_cursor_column(0)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Reline::LineEditor
|
||||||
CompletionJourneyData = Struct.new('CompletionJourneyData', :preposing, :postposing, :list, :pointer)
|
CompletionJourneyData = Struct.new('CompletionJourneyData', :preposing, :postposing, :list, :pointer)
|
||||||
MenuInfo = Struct.new('MenuInfo', :target, :list)
|
MenuInfo = Struct.new('MenuInfo', :target, :list)
|
||||||
|
|
||||||
def initialize(config, prompt, encoding = Encoding.default_external)
|
def initialize(config, prompt = '', encoding = Encoding.default_external)
|
||||||
@config = config
|
@config = config
|
||||||
@prompt = prompt
|
@prompt = prompt
|
||||||
@prompt_width = calculate_width(@prompt)
|
@prompt_width = calculate_width(@prompt)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue