Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor completion #622

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,23 @@ def get_screen_size

Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() {
# autocomplete
return nil unless config.autocompletion
if just_cursor_moving and completion_journey_data.nil?
return unless config.autocompletion

journey_data = completion_journey_data
if just_cursor_moving and journey_data.nil?
# Auto complete starts only when edited
return nil
end
pre, target, post = retrieve_completion_block(true)
if target.nil? or target.empty? or (completion_journey_data&.pointer == -1 and target.size <= 3)
return nil
return
end
if completion_journey_data and completion_journey_data.list
result = completion_journey_data.list.dup
result.shift
pointer = completion_journey_data.pointer - 1
if journey_data
result = journey_data.list.drop(1)
pointer = journey_data.pointer - 1
target = journey_data.list[journey_data.pointer]
else
pre, target, post = retrieve_completion_block(true)
return if target.nil? || target.empty?

result = call_completion_proc_with_checking_args(pre, target, post)
pointer = nil
end
if result and result.size == 1 and result[0] == target and pointer != 0
result = nil
return if result and result.size == 1 and result[0] == target
end
target_width = Reline::Unicode.calculate_width(target)
x = cursor_pos.x - target_width
Expand Down Expand Up @@ -278,8 +276,12 @@ def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
Reline::HISTORY << whole_buffer
end

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

Expand Down Expand Up @@ -326,7 +328,7 @@ def readline(prompt = '', add_hist = false)
line_editor.prompt_proc = prompt_proc
line_editor.auto_indent_proc = auto_indent_proc
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
line_editor.pre_input_hook = pre_input_hook
pre_input_hook&.call
@dialog_proc_list.each_pair do |name_sym, d|
line_editor.add_dialog_proc(name_sym, d.dialog_proc, d.context)
end
Expand All @@ -337,6 +339,7 @@ def readline(prompt = '', add_hist = false)
io_gate.set_default_key_bindings(config)
end

line_editor.print_nomultiline_prompt(prompt)
line_editor.rerender

begin
Expand All @@ -346,10 +349,8 @@ def readline(prompt = '', add_hist = false)
prev_pasting_state = io_gate.in_pasting?
read_io(config.keyseq_timeout) { |inputs|
line_editor.set_pasting_state(io_gate.in_pasting?)
inputs.each { |c|
line_editor.input_key(c)
line_editor.rerender
}
inputs.each { |c| line_editor.update(c) }
line_editor.rerender
if @bracketed_paste_finished
line_editor.rerender_all
@bracketed_paste_finished = false
Expand Down
2 changes: 1 addition & 1 deletion lib/reline/general_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.ungetc(c)
end

def self.get_screen_size
[1, 1]
[24, 80]
end

def self.cursor_pos
Expand Down
Loading
Loading